/**********************************************************************

	--- Qt Architect generated file ---

	File: gsSetupDlg.cpp
	Last generated: Sun Jul 26 14:55:43 1998

	DO NOT EDIT!!!  This file will be automatically
	regenerated by qtarch.  All changes will be lost.

 *********************************************************************/

#include "gsSetupDlg.h"
#include "gsSetupDlg.moc"

#define Inherited QDialog

#include <qlabel.h>
#include <qchkbox.h>
#include <qpushbt.h>
#include <qlined.h>
#include <qgrpbox.h>
#include <qcombo.h>

gsSetupDlg::gsSetupDlg
(
	QWidget* parent,
	const char* name
)
	:
	Inherited( parent, name, TRUE, 0 )
{
	QGroupBox* dlgedit_GroupBox_4;
	dlgedit_GroupBox_4 = new QGroupBox( this, "GroupBox_4" );
	dlgedit_GroupBox_4->setGeometry( 10, 170, 180, 60 );
	dlgedit_GroupBox_4->setMinimumSize( 10, 10 );
	dlgedit_GroupBox_4->setMaximumSize( 32767, 32767 );
	dlgedit_GroupBox_4->setFrameStyle( 49 );
	dlgedit_GroupBox_4->setTitle( "Papersize" );
	dlgedit_GroupBox_4->setAlignment( 1 );

	QGroupBox* dlgedit_GroupBox_2;
	dlgedit_GroupBox_2 = new QGroupBox( this, "GroupBox_2" );
	dlgedit_GroupBox_2->setGeometry( 10, 110, 180, 60 );
	dlgedit_GroupBox_2->setMinimumSize( 10, 10 );
	dlgedit_GroupBox_2->setMaximumSize( 32767, 32767 );
	dlgedit_GroupBox_2->setFrameStyle( 49 );
	dlgedit_GroupBox_2->setTitle( "Resolution" );
	dlgedit_GroupBox_2->setAlignment( 1 );

	QGroupBox* dlgedit_GroupBox_1;
	dlgedit_GroupBox_1 = new QGroupBox( this, "GroupBox_1" );
	dlgedit_GroupBox_1->setGeometry( 10, 10, 180, 100 );
	dlgedit_GroupBox_1->setMinimumSize( 10, 10 );
	dlgedit_GroupBox_1->setMaximumSize( 32767, 32767 );
	dlgedit_GroupBox_1->setFrameStyle( 49 );
	dlgedit_GroupBox_1->setTitle( "Devices" );
	dlgedit_GroupBox_1->setAlignment( 1 );

	dlgedit_ComboBox_1 = new QComboBox( FALSE, this, "ComboBox_1" );
	dlgedit_ComboBox_1->setGeometry( 70, 70, 100, 30 );
	dlgedit_ComboBox_1->setMinimumSize( 10, 10 );
	dlgedit_ComboBox_1->setMaximumSize( 32767, 32767 );
	dlgedit_ComboBox_1->setSizeLimit( 10 );
	dlgedit_ComboBox_1->setAutoResize( FALSE );
	dlgedit_ComboBox_1->insertItem( "ljet4" );

	QLabel* dlgedit_Label_3;
	dlgedit_Label_3 = new QLabel( this, "Label_3" );
	dlgedit_Label_3->setGeometry( 20, 70, 40, 30 );
	dlgedit_Label_3->setMinimumSize( 10, 10 );
	dlgedit_Label_3->setMaximumSize( 32767, 32767 );
	dlgedit_Label_3->setText( "Output" );
	dlgedit_Label_3->setAlignment( 290 );
	dlgedit_Label_3->setMargin( -1 );

	QComboBox* dlgedit_ComboBox_2;
	dlgedit_ComboBox_2 = new QComboBox( FALSE, this, "ComboBox_2" );
	dlgedit_ComboBox_2->setGeometry( 70, 30, 100, 30 );
	dlgedit_ComboBox_2->setMinimumSize( 10, 10 );
	dlgedit_ComboBox_2->setMaximumSize( 32767, 32767 );
	dlgedit_ComboBox_2->setSizeLimit( 10 );
	dlgedit_ComboBox_2->setAutoResize( FALSE );
	dlgedit_ComboBox_2->insertItem( "stdin" );

	QLabel* dlgedit_Label_4;
	dlgedit_Label_4 = new QLabel( this, "Label_4" );
	dlgedit_Label_4->setGeometry( 20, 30, 40, 30 );
	dlgedit_Label_4->setMinimumSize( 10, 10 );
	dlgedit_Label_4->setMaximumSize( 32767, 32767 );
	dlgedit_Label_4->setText( "Input" );
	dlgedit_Label_4->setAlignment( 290 );
	dlgedit_Label_4->setMargin( -1 );

	QLineEdit* dlgedit_LineEdit_2;
	dlgedit_LineEdit_2 = new QLineEdit( this, "LineEdit_2" );
	dlgedit_LineEdit_2->setGeometry( 10, 240, 310, 30 );
	dlgedit_LineEdit_2->setMinimumSize( 10, 10 );
	dlgedit_LineEdit_2->setMaximumSize( 32767, 32767 );
	dlgedit_LineEdit_2->setText( "gs -q -Dsafe" );
	dlgedit_LineEdit_2->setMaxLength( 32767 );
	dlgedit_LineEdit_2->setEchoMode( QLineEdit::Normal );
	dlgedit_LineEdit_2->setFrame( TRUE );

	QCheckBox* dlgedit_CheckBox_1;
	dlgedit_CheckBox_1 = new QCheckBox( this, "CheckBox_1" );
	dlgedit_CheckBox_1->setGeometry( 200, 10, 60, 30 );
	dlgedit_CheckBox_1->setMinimumSize( 10, 10 );
	dlgedit_CheckBox_1->setMaximumSize( 32767, 32767 );
	dlgedit_CheckBox_1->setText( "quiet" );
	dlgedit_CheckBox_1->setAutoRepeat( FALSE );
	dlgedit_CheckBox_1->setAutoResize( FALSE );

	QCheckBox* dlgedit_CheckBox_2;
	dlgedit_CheckBox_2 = new QCheckBox( this, "CheckBox_2" );
	dlgedit_CheckBox_2->setGeometry( 200, 130, 120, 30 );
	dlgedit_CheckBox_2->setMinimumSize( 10, 10 );
	dlgedit_CheckBox_2->setMaximumSize( 32767, 32767 );
	dlgedit_CheckBox_2->setText( "No Platform Fonts" );
	dlgedit_CheckBox_2->setAutoRepeat( FALSE );
	dlgedit_CheckBox_2->setAutoResize( FALSE );

	QCheckBox* dlgedit_CheckBox_3;
	dlgedit_CheckBox_3 = new QCheckBox( this, "CheckBox_3" );
	dlgedit_CheckBox_3->setGeometry( 200, 160, 90, 30 );
	dlgedit_CheckBox_3->setMinimumSize( 10, 10 );
	dlgedit_CheckBox_3->setMaximumSize( 32767, 32767 );
	dlgedit_CheckBox_3->setText( "No Cache" );
	dlgedit_CheckBox_3->setAutoRepeat( FALSE );
	dlgedit_CheckBox_3->setAutoResize( FALSE );

	QPushButton* dlgedit_PushButton_1;
	dlgedit_PushButton_1 = new QPushButton( this, "PushButton_1" );
	dlgedit_PushButton_1->setGeometry( 220, 280, 100, 30 );
	dlgedit_PushButton_1->setMinimumSize( 10, 10 );
	dlgedit_PushButton_1->setMaximumSize( 32767, 32767 );
	dlgedit_PushButton_1->setText( "Cancel" );
	dlgedit_PushButton_1->setAutoRepeat( FALSE );
	dlgedit_PushButton_1->setAutoResize( FALSE );

	QPushButton* dlgedit_PushButton_2;
	dlgedit_PushButton_2 = new QPushButton( this, "PushButton_2" );
	dlgedit_PushButton_2->setGeometry( 120, 280, 100, 30 );
	dlgedit_PushButton_2->setMinimumSize( 10, 10 );
	dlgedit_PushButton_2->setMaximumSize( 32767, 32767 );
	dlgedit_PushButton_2->setText( "OK" );
	dlgedit_PushButton_2->setAutoRepeat( FALSE );
	dlgedit_PushButton_2->setAutoResize( FALSE );

	QComboBox* dlgedit_ComboBox_3;
	dlgedit_ComboBox_3 = new QComboBox( FALSE, this, "ComboBox_3" );
	dlgedit_ComboBox_3->setGeometry( 50, 190, 100, 30 );
	dlgedit_ComboBox_3->setMinimumSize( 10, 10 );
	dlgedit_ComboBox_3->setMaximumSize( 32767, 32767 );
	dlgedit_ComboBox_3->setSizeLimit( 10 );
	dlgedit_ComboBox_3->setAutoResize( FALSE );
	dlgedit_ComboBox_3->insertItem( "A4" );

	QLineEdit* dlgedit_LineEdit_3;
	dlgedit_LineEdit_3 = new QLineEdit( this, "LineEdit_3" );
	dlgedit_LineEdit_3->setGeometry( 50, 130, 40, 30 );
	dlgedit_LineEdit_3->setMinimumSize( 10, 10 );
	dlgedit_LineEdit_3->setMaximumSize( 32767, 32767 );
	dlgedit_LineEdit_3->setText( "3600" );
	dlgedit_LineEdit_3->setMaxLength( 32767 );
	dlgedit_LineEdit_3->setEchoMode( QLineEdit::Normal );
	dlgedit_LineEdit_3->setFrame( TRUE );

	QLineEdit* dlgedit_LineEdit_4;
	dlgedit_LineEdit_4 = new QLineEdit( this, "LineEdit_4" );
	dlgedit_LineEdit_4->setGeometry( 120, 130, 40, 30 );
	dlgedit_LineEdit_4->setMinimumSize( 10, 10 );
	dlgedit_LineEdit_4->setMaximumSize( 32767, 32767 );
	dlgedit_LineEdit_4->setText( "3600" );
	dlgedit_LineEdit_4->setMaxLength( 32767 );
	dlgedit_LineEdit_4->setEchoMode( QLineEdit::Normal );
	dlgedit_LineEdit_4->setFrame( TRUE );

	QLabel* dlgedit_Label_6;
	dlgedit_Label_6 = new QLabel( this, "Label_6" );
	dlgedit_Label_6->setGeometry( 100, 130, 10, 30 );
	dlgedit_Label_6->setMinimumSize( 10, 10 );
	dlgedit_Label_6->setMaximumSize( 32767, 32767 );
	dlgedit_Label_6->setText( "Y" );
	dlgedit_Label_6->setAlignment( 289 );
	dlgedit_Label_6->setMargin( -1 );

	QLabel* dlgedit_Label_7;
	dlgedit_Label_7 = new QLabel( this, "Label_7" );
	dlgedit_Label_7->setGeometry( 30, 130, 10, 30 );
	dlgedit_Label_7->setMinimumSize( 10, 10 );
	dlgedit_Label_7->setMaximumSize( 32767, 32767 );
	dlgedit_Label_7->setText( "X" );
	dlgedit_Label_7->setAlignment( 289 );
	dlgedit_Label_7->setMargin( -1 );

	QCheckBox* dlgedit_CheckBox_4;
	dlgedit_CheckBox_4 = new QCheckBox( this, "CheckBox_4" );
	dlgedit_CheckBox_4->setGeometry( 200, 70, 80, 30 );
	dlgedit_CheckBox_4->setMinimumSize( 10, 10 );
	dlgedit_CheckBox_4->setMaximumSize( 32767, 32767 );
	dlgedit_CheckBox_4->setText( "No Pause" );
	dlgedit_CheckBox_4->setAutoRepeat( FALSE );
	dlgedit_CheckBox_4->setAutoResize( FALSE );

	QCheckBox* dlgedit_CheckBox_5;
	dlgedit_CheckBox_5 = new QCheckBox( this, "CheckBox_5" );
	dlgedit_CheckBox_5->setGeometry( 200, 40, 80, 30 );
	dlgedit_CheckBox_5->setMinimumSize( 10, 10 );
	dlgedit_CheckBox_5->setMaximumSize( 32767, 32767 );
	dlgedit_CheckBox_5->setText( "Batch" );
	dlgedit_CheckBox_5->setAutoRepeat( FALSE );
	dlgedit_CheckBox_5->setAutoResize( FALSE );

	QCheckBox* dlgedit_CheckBox_6;
	dlgedit_CheckBox_6 = new QCheckBox( this, "CheckBox_6" );
	dlgedit_CheckBox_6->setGeometry( 200, 100, 80, 30 );
	dlgedit_CheckBox_6->setMinimumSize( 10, 10 );
	dlgedit_CheckBox_6->setMaximumSize( 32767, 32767 );
	dlgedit_CheckBox_6->setText( "Safer" );
	dlgedit_CheckBox_6->setAutoRepeat( FALSE );
	dlgedit_CheckBox_6->setAutoResize( FALSE );

	resize( 330,320 );
	setMinimumSize( 0, 0 );
	setMaximumSize( 32767, 32767 );
	setCaption("Ghostscript Setup");
	bing();
}
void  
gsSetupDlg::bing()
{
  gsbuf = (char *) malloc (8192);
  gsbufrun = gsbuf;

  gs = new KProcess;

  gs->clearArguments();
  *gs << "gs";
  connect (gs, SIGNAL (receivedStdout (KProcess *, char *, int)),
	   this, SLOT (gsReadStdout (KProcess *, char *, int)));
  connect (gs, SIGNAL (processExited (KProcess *)),
	   this, SLOT (gsProcessExited (KProcess *)));

  *gs << "-h";
  if (gs->start (KProcess::Block, KProcess::Stdout)) {
  }

}
void 
gsSetupDlg::gsReadStdout( KProcess *, char *buffer, int len)
{
/* There is a timing problem here. When this routine is executed
 *  too long ->SEGFAULT
 */
	/* Copy lightining fast :) */
	strncpy(gsbufrun, buffer, len);
	gsbufrun+=len;
}
void 
gsSetupDlg::gsProcessExited(KProcess *) 
{
  *gsbufrun = 0;
  gsbufrun = gsbuf;

 // printf("%s\n",gsbuf);

  /* Find available Printing devices 
   * Read everything between "Available devices:" and "Search path:"
   */

  char *tmp1, *tmp2;
  tmp1 = strstr (gsbuf, (char *) "Available devices:");
  tmp2 = strstr (gsbuf, (char *) "Search path:");

  char buffer[8192];
  if (tmp1 != 0L && tmp2 != 0L) {
    tmp1 += strlen ("Available devices:");
    strncpy ((char *) &buffer, tmp1, tmp2 - tmp1);
    buffer[tmp2 - tmp1] = 0;  // 0 Terminate buffer strncpy does not do this!
  int i=0;
    
    // Throw out all Linefeeds 
    while (buffer[i] != 0)
    {
	if ( buffer[i] == 10 ) buffer[i]= ' '; 
	i++;
    }

    /* Morgen geht die Bombe hoch und wir gehen alle mit 
     */
    i=0;
    int z=0;
    char dest[128];
    while (buffer[i++] != 0)
    {
    	if ( buffer[i] != ' ' ) 
	{
		while ( buffer[i] != ' ' && buffer[i] != 0 )
			{dest[z++]=buffer[i++];}
		dest[z]=0;
		printf("%s\n",dest);
		dlgedit_ComboBox_1->insertItem( dest );
		z=0;
	}
    }

  
  }

  delete gs;
  free (gsbuf);
}		

    
gsSetupDlg::~gsSetupDlg()
{
}
