Source Code (Use browser search to find items of interest.)

Class Index

kghostview'KGhostview (./kdegraphics/kghostview/kghostview.h:61)

class KGhostview : public KTMainWindow
{
    Q_OBJECT

      enum Orientation {Portrait=1, Landscape=3,
			UpsideDown=2, Seascape=4};
    enum ComboOrientation {CombPortrait=0, CombLandscape=1,
			   CombUpsideDown=2, CombSeascape=3};
public:
	KGhostview( QWidget *parent=0, char *name=0 );
	~KGhostview();

	// Tells us what kind of job kghostview is waiting for.
    
	KAccel *keys;
	
	enum action { GET, PUT };
	void openNetFile( const KURL &u );

	static QList <KGhostview> windowList;

	bool setup();
	void show_page(int number);
	void build_pagemedia_menu();
	void set_magstep(unsigned int new_magstep);
	void magnify(float *dpi, unsigned int magstep);
	void new_file(int number);
	void openFile( QString name );
	bool same_document_media();
	/**
	 * If force_orientation==true, then you may pass zero.
	 **/
	bool set_new_pagemedia( int number =0);
	bool set_new_magstep();
	bool setOrientation (Orientation _orientation);
	void writeSettings();
	void writeFileSettings();
	void readSettings();
	
	void createActions();
	void createToolbar();
	void createViewToolBar();
	void createStatusbar();
	
	void setName();
	
	
	QFrame *mainFrame;
	QFrame *divider;
	MarkList *marklist;
	KPSWidget *page;
	
	//ViewControl *vc;
	PrintDialog *pd;
	InfoDialog *infoDialog;

	bool force_pagemedia;
	bool force_orientation;
	int orientation;
		
	void printStart( int mode, bool reverseOrder, bool toFile, 
					QString printerName, QString spoolerCommmand,
					QString printerVariable,
					int pgStart, int pgEnd );
				
	/**
	 * Passing 0 for @p ml means print all.
	 **/
	QString printToFile( QStrList *ml=0  );
				
	QString printToPrinter( QString printerName, 
				QString spoolerCommand, QString printerVariable,
				bool allMode, QStrList *ml  );
	
	void psCopyDoc( FILE *fp, QStrList *ml );
	
	void bindKeys();
	void changeMenuAccel( QPopupMenu *menu, int id, const char *functionName );
	void updateMenuAccel();
	void changeFileRecord();
	
	FILE		*psfile;
	QString 	filename;	
	QString		oldfilename;	
	int			current_page;
	int 		pages_in_part[10];
	int 		num_parts;
	time_t		mtime;	
	struct 		document *doc;	
	struct 		document *olddoc;
	
	QStrList lastOpened;
	
public slots:
	//void pageActivated( const char * text); // Dutta 16/3/98
	void pageActivated( int pg );	// Dutta 16/3/98
        void saveAs();
	void scrollDown();
	void scrollUp();
	void scrollLeft();
	void scrollRight();
	void about();
	void help();
	void dummy();
	//void viewControl();			
	void nextPage();
	void prevPage();
	void goToPage();
	void goToStart();
	void goToEnd();
	void readDown();
	void print();
	void openNewFile();
	void zoomIn();
	void zoomOut();
	void optionsMenuActivated( int item );
	void markPage();
	void configureKeybindings();
	void slotFitToPageWidth ();
	/**
	 * Shrinking the window makes a mess in general,
	 *  so, by default, we only resize when expanding.
	 **/
	void shrinkWrap(bool onlyiftoosmall=true);
	void redisplay();
	void newWindow();
	void closeWindow();
	void info();
	void copyright();
	void configureGhostscript();
	void openRecent( int id );
	
	void slotIOJobFinished( int );
     
	void viewToolBarZoom (int i);
	void viewToolBarOrient (int i);
	void viewToolBarMedia (int i);
protected:

	KToolBar *viewtoolbar;
	QTimer *watch;

	void paletteChange( const QPalette & );
	void closeEvent( QCloseEvent * );
	void dropEvent( QDropEvent * event );
	void startWatch ();
	void stopWatch ();

protected slots:
	void updateRects();
        void slotWatch(); 
   
private:

	QPopupMenu *m_file;
	QPopupMenu *m_recent;
	QPopupMenu *m_view;
	QPopupMenu *m_go;
	QPopupMenu *m_pagemarks;
	QPopupMenu *m_options;
	QPopupMenu *m_help;
	
	KToolBar *toolbar;
	KStatusBar *statusbar;
	
	int topOffset, bottomOffset;
	
	//int viewControlID;
	int pgsetupID;
	int printID;
	int openID;
	//	int newID;
	int closeID;
	int saveAsID;
	int quitID;
	int zoomInID;
	int zoomOutID;
	int nextID;
	int prevID;
	int goToPageID;
	int goToStartID;
	int goToEndID;
	int readDownID;
	int messagesID;
	int helpID;
	int shrinkWrapID;
	int redisplayID;
	int infoID;
	int markCurrentID;
	int markAllID;
	int markEvenID;
	int markOddID;
	int toggleMarksID;
	int removeMarksID;

	QString printerName;
	int printSelection;
	bool isNetFile;
	bool hide_toolbar;
	bool hide_statusbar;
	bool hide_pagelist;
	bool fitWindow;
	int options_width;
	int options_height;
	unsigned int shrink_magsteps, expand_magsteps, magstep,
current_magstep;
	bool	force_document_media;	
	int	base_papersize;
	bool	toc_text;
	int	toc_length;
	int	toc_entry_length;
	char page_total_label[20];
	char part_total_label[20];
	QString part_string;
	QString page_string;
	QString page_label_text;
	QString part_label_text;
	QString position_label;
	float default_xdpi, default_ydpi;
	int current_llx;
	int current_lly;
	int current_urx;
	int current_ury;
	int current_pagemedia, default_pagemedia, document_media;
	int current_orientation;
	bool changed;

	
	/**
	 * @see setOrientation()
	 **/
	bool set_new_orientation(int number);
	
    /**
      Only one KIOJob should be opened at once. Otherwise kgv could get
      confused. If this is 0L, you may create a new iojob.
      */
    KIO::Job * iojob;
    
    /// Temporary file for internet purposes
    /**
      If kgv is waiting for some internet task to finish, this is the
      file that is involved. Mention that it is a complete URL like
      "file:/tmp/mist.txt".
      */
    QString tmpFile;

    /// If we load a file from the net this is the corresponding URL
    QString netFile;
    
    /// Tells us what kfm is right now doing for us
    /**
      If this is for example GET, then KFM loads a file from the net
      to the local file system.
      */
    action kfmAction;
    
    /// The open mode for a net file
    /**
      If kgv is waiting for an internet file, this is the mode in which
      it should open the file.
      */
    int openMode;


    /**
     * Call this whenever you change the zoom factor (magstep)
     *  to update the display.
     **/
    void updateMagstepDisplay();

    /**
     * Call this whenever you change the orientation
     *  to update the display.
     **/
    void updateOrientationDisplay();
};

kghostview'KGhostview::KGhostview() (./kdegraphics/kghostview/kghostview.cpp:114)

KGhostview::KGhostview( QWidget *, char *name )
	: KTMainWindow( name )
{   
    windowList.append( this );
    
    // Initialise all the variables declared in this class.
    // I usually forget to do a few resulting in nasty seg. faults !
    
    iojob = 0L;
    
    watch = 0L;
    isNetFile = false;
    
    oldfilename = "";
    filename = "";
    psfile=0;
    doc=0;
    olddoc=0;
    
    current_page=0;
    num_parts=0;
    for(int part_count=0;part_count<10;part_count++) {
    	pages_in_part[part_count]=0;
    }
    
    shrink_magsteps = 10; //0% - 100%
    current_magstep = magstep = 10;
    expand_magsteps = 10;
    default_xdpi = 75.0;
    default_ydpi = 75.0;
    default_pagemedia = 1;
    base_papersize=0;
    orientation = 1;
    force_orientation = false;
    force_pagemedia = false;
    current_llx = 0;
    current_lly = 0;
    current_urx = 0;
    current_ury = 0;
    viewtoolbar = 0;
    hide_toolbar = false;
    hide_statusbar = false;
    
    int nRecent = 5;
    QString s;
    for( int i = 1; i <= nRecent; i++ ) {
        s.sprintf( "%d              ", i);
        lastOpened.append( s );
    }
	
    //
    // MAIN WINDOW
    //
    
	mainFrame = new QFrame( this );
	CHECK_PTR( mainFrame );
	
	mainFrame->setFrameStyle( QFrame::NoFrame );
	
	marklist = new MarkList( mainFrame );
	CHECK_PTR( marklist );
	
	divider = new QFrame( mainFrame );
	CHECK_PTR( divider );
	
	divider->setFrameStyle( QFrame::Panel | QFrame::Raised );
	divider->setLineWidth( 1 );
	
	marklist->setSelectColors( colorGroup().highlight(), 
                                   colorGroup().highlightedText() );
	
	connect( marklist, SIGNAL(selected( int )), 
		SLOT(pageActivated( int )) ); // Duda 16/3/98
	
	
    //printf("Done toolbar - Create KPSWidget\n");
    
    page = new KPSWidget( mainFrame );
    CHECK_PTR( page );
    
    //printf("Done pswidget - Create statusbar\n");
    
    //
    // MENUBAR
    //
    
    //    createMenubar();
    
    createActions();

    //
    // TOOLBARS
    //
    
    createToolbar();
    createViewToolBar();
	
    //
    // STATUSBAR
    //
    
    createStatusbar();



    //"What's this?" help
    QWhatsThis::add( marklist, 
		     i18n("Select page to view by clicking the numbers,\n"
			  "and mark pages for printing by clicking\n"
			  "the dots to the left of the numbers.") );
	
    // Register with KTMainWindow geometry manager
    

    setView( mainFrame, false );
    
    //
    //	PRINTING DEFAULTS
    //
    
    printSelection = 1;
    printerName = "lp0";
    
    // Build the combo box menu for magnification steps.
    
    unsigned int i;
    char buf[16];
    for (i = 1; i <= shrink_magsteps; i++)
      sprintf(buf, "%d %%", (int)(100*i/(shrink_magsteps)));
    for (i = 1; i <= expand_magsteps; i++)
      sprintf(buf, "%d %%", (int)(100+200*i/(expand_magsteps)));
    
    //
    //	READ SETTINGS AND SET OPTIONS MENU, SET LAST OPENED FILES
    //
    
    readSettings();
    
    if ( hide_toolbar )	
      m_options->setItemChecked( ID_TOOLBAR, false );
    else
      m_options->setItemChecked( ID_TOOLBAR, true );
    
    if ( hide_statusbar )
      m_options->setItemChecked(  ID_STATUSBAR, false );
    else
      m_options->setItemChecked( ID_STATUSBAR, true );
    
    if ( hide_pagelist )
      m_options->setItemChecked(  ID_PAGELIST, false );
    else
      m_options->setItemChecked( ID_PAGELIST, true );
    
    changeFileRecord();
    
    setAcceptDrops(true);
    
    //
    //	RESIZE AND DISPLAY
    //
    
    setMinimumSize( 250, 250 );
    setName();
    bindKeys();
    updateMenuAccel();
    
    resize( options_width, options_height );
    show();
    
    if (psfile)
      {
	setup();
	if (m_options->isItemChecked (ID_WATCHFILE))
	  startWatch();
	//show_page( 0 );
	//marklist->select( 0 );
      }
}

//void KGhostview::pageActivated( const char * text) // Duda 16/3/98
//{
//	int pg = QString( text ).toInt();
//	show_page(pg-1);
//}


kghostview'KGhostview::pageActivated() (./kdegraphics/kghostview/kghostview.cpp:299)

void KGhostview::pageActivated( int pg ) // Duda 16/3/98
{
//	printf("KGhostview::pageActivated\n");
	show_page(pg);
}


kghostview'KGhostview::updateRects() (./kdegraphics/kghostview/kghostview.cpp:305)

void KGhostview::updateRects()
{	
	//printf("KTMainWindow::updateRects()\n");
	
	KTMainWindow::updateRects();
	
	//printf("KTMainWindow::updateRects() returned\n");

	marklist->setGeometry( 0, 0,
		PAGELIST_WIDTH-1,
		mainFrame->height());
		
	divider->setGeometry( PAGELIST_WIDTH, 0, PAGELIST_WIDTH+3,
		mainFrame->height());

	if( marklist->isVisible() ) {
		page->setGeometry( PAGELIST_WIDTH+3, 0,
			mainFrame->width()-PAGELIST_WIDTH-3,
			mainFrame->height() );
		
	} else {
		page->setGeometry( 0, 0,
			mainFrame->width(),
			mainFrame->height() );
	}
}


kghostview'KGhostview::~KGhostview() (./kdegraphics/kghostview/kghostview.cpp:332)

KGhostview::~KGhostview()
{
	//printf("KGhostview::~KGhostview()\n");
	
	//windowList.removeRef(this);
	
	//delete menubar;
	//delete toolbar;
}


kghostview'KGhostview::bindKeys() (./kdegraphics/kghostview/kghostview.cpp:342)

void KGhostview::bindKeys()
{    
  // create the KAccel object
  
  keys = new KAccel( this );
  
  // create functionName/keyCode association
  
  //keys->insertItem(i18n("Quit"), "CTRL+Q");
  keys->insertStdItem( KStdAccel::Quit );
  keys->insertStdItem( KStdAccel::Open );
  keys->insertStdItem( KStdAccel::New );
  keys->insertStdItem( KStdAccel::Close );
  keys->insertStdItem( KStdAccel::Print );
  keys->insertStdItem( KStdAccel::Help );
  
  //	keys->insertItem(i18n("View Control"), "View Control", "CTRL+L");
  keys->insertItem(i18n("Go To Page"), "Go To Page", "CTRL+G");
  keys->insertStdItem( KStdAccel::ZoomIn );     
  keys->insertStdItem( KStdAccel::ZoomOut ); 
  keys->insertItem(i18n("Next Page"),"Next Page" ,"Next");
  keys->insertItem(i18n("Prev Page"),"Prev Page" ,"Prior");
  keys->insertItem(i18n("Scroll Up"),"Scroll Up" ,"Up");
  keys->insertItem(i18n("Scroll Down"),"Scroll Down" ,"Down");
  keys->insertItem(i18n("Scroll Left"),"Scroll Left" ,"Left");
  keys->insertItem(i18n("Scroll Right"), "Scroll Right","Right");
  //  keys->insertItem(i18n("Top of Page"), "Top of Page", "Home");
  //  keys->insertItem(i18n("Bottom of Page"), "Bottom of Page", "End");
  keys->insertItem(i18n("Redisplay"), "Redisplay","CTRL+R");
  keys->insertItem(i18n("Information"), "Information","CTRL+I");
  
  //keys->readSettings();
  
  keys->connectItem( KStdAccel::Quit, qApp, SLOT( quit() ) );
  keys->connectItem( KStdAccel::Open, this, SLOT( openNewFile() ) );
  keys->connectItem( KStdAccel::New,	this, SLOT( newWindow() ) );
  keys->connectItem( KStdAccel::Close, this, SLOT( closeWindow() ) );
  keys->connectItem( KStdAccel::Print, this, SLOT( print() ) );
  keys->connectItem( KStdAccel::Help, this, SLOT( help() ) );
  //	keys->connectItem( "View Control", this, SLOT( viewControl() ) );
  keys->connectItem( "Go To Page", this, SLOT( goToPage() ) );
  keys->connectItem( KStdAccel::ZoomIn, this, SLOT( zoomIn() ) );
  keys->connectItem( KStdAccel::ZoomOut, this, SLOT( zoomOut() ) );
  keys->connectItem( "Next Page", this, SLOT( nextPage() ) );
  keys->connectItem( "Prev Page", this, SLOT( prevPage() ) );
  keys->connectItem( "Scroll Up", this, SLOT( scrollUp() ) );
  keys->connectItem( "Scroll Down", this, SLOT( scrollDown() ) );
  keys->connectItem( "Scroll Left", this, SLOT( scrollLeft() ) );
  keys->connectItem( "Scroll Right", this, SLOT( scrollRight() ) );
  keys->connectItem( "Redisplay", this, SLOT( redisplay() ) );
  keys->connectItem( "Information", this, SLOT( info() ) );
  
  keys->readSettings();
}


kghostview'KGhostview::copyright() (./kdegraphics/kghostview/kghostview.cpp:397)

void KGhostview::copyright()
{
  CopyrightDialog *cd = new CopyrightDialog( 0, "copyright" );
  cd->exec();
}


kghostview'KGhostview::info() (./kdegraphics/kghostview/kghostview.cpp:403)

void KGhostview::info()
{  
  QString ftitle, fdate;
  if(doc) {
    ftitle = doc->title;
    fdate = doc->date;
  } else {
    ftitle = i18n("Not known");
    fdate = ftitle;
  }

  infoDialog = 
    new InfoDialog(filename,
		   ftitle.data(), fdate.data(),
		   this, 0);

  infoDialog->exec();
  delete infoDialog;
}


kghostview'KGhostview::configureGhostscript() (./kdegraphics/kghostview/kghostview.cpp:423)

void KGhostview::configureGhostscript()
{
  page->intConfig->setCaption(i18n("Configure interpreter"));
  page->intConfig->init();
  
  if( page->intConfig->exec() ) {
  }
}


kghostview'KGhostview::configureKeybindings() (./kdegraphics/kghostview/kghostview.cpp:432)

void KGhostview::configureKeybindings()
{
  if( KKeyDialog::configureKeys( keys,false ) ) {
    updateMenuAccel();
  }
}


kghostview'KGhostview::updateMenuAccel() (./kdegraphics/kghostview/kghostview.cpp:439)

void KGhostview::updateMenuAccel()
{
  changeMenuAccel( m_file, printID, i18n("Print") );
  changeMenuAccel( m_file, openID, i18n("Open") );
  //  changeMenuAccel( m_file, newID, i18n("New") );
  changeMenuAccel( m_file, redisplayID, i18n("Redisplay") );
  changeMenuAccel( m_file, closeID, i18n("Close") );
  changeMenuAccel( m_file, quitID, i18n("Quit") );
  changeMenuAccel( m_view, zoomInID, i18n("Zoom In") );
  changeMenuAccel( m_view, zoomOutID, i18n("Zoom Out") );
  //	changeMenuAccel( m_view, viewControlID, i18n("View Control") );
  changeMenuAccel( m_view, infoID, i18n("Information") );
  changeMenuAccel( m_go, nextID, i18n("Next Page") );
  changeMenuAccel( m_go, prevID, i18n("Prev Page") );
  changeMenuAccel( m_go, goToPageID, i18n("Go To Page") );
  //  changeMenuAccel( m_help, helpID, i18n("Help") );

}


kghostview'KGhostview::changeMenuAccel() (./kdegraphics/kghostview/kghostview.cpp:458)

void KGhostview::changeMenuAccel ( QPopupMenu *menu, int id,
	const char *functionName )
{
	QString s = menu->text( id );
	if ( !s ) return;
	
	int i = s.find('\t');
	
	QString k = KAccel::keyToString( keys->currentKey( functionName ) );
	if( !k ) return;
	
	if ( i >= 0 )
		s.replace( i+1, s.length()-i, k );
	else {
		s += '\t';
		s += k;
	}
	
	menu->changeItem( s, id );
}





kghostview'KGhostview::createActions() (./kdegraphics/kghostview/kghostview.cpp:482)

void KGhostview::createActions()
{
  m_recent = new QPopupMenu;
  CHECK_PTR( m_recent );
  


  int i = 0;
  
  
  QStrListIterator it( lastOpened );
  for( ; it.current(); ++it ) {
    m_recent->insertItem( it.current(), i );
    i++;
  }


  connect( m_recent, SIGNAL( activated( int ) ),	   SLOT( openRecent( int ) ) );
  


  m_file = new QPopupMenu;
  CHECK_PTR( m_file );
  //    newID =      m_file->insertItem( i18n("&New"), this, SLOT( newWindow() ) );
  openID =      m_file->insertItem( i18n("&Open..."), this, SLOT( openNewFile() ) );
  m_file->insertItem( i18n("Open &recent"),	m_recent );
  saveAsID = 
    m_file->insertItem( i18n("Save &As..."), this, SLOT (saveAs()));
  closeID =
    m_file->insertItem( i18n("&Close"), this, SLOT( closeWindow() ) );
  m_file->insertSeparator();
  redisplayID =
    m_file->insertItem( i18n("&Reload"), this, SLOT( redisplay() ) );
  m_file->insertSeparator();
  
  //    pgsetupID =      m_file->insertItem( i18n("Page Set&up..."), this, SLOT( viewControl() ) );
  
  printID =
    m_file->insertItem( i18n("&Print..."), this, SLOT( print() ) );
  m_file->insertSeparator();
  quitID =
    m_file->insertItem( i18n("&Quit"), kapp, SLOT(closeAllWindows()));
			//qApp, SLOT( quit() ) );
    


    m_view = new QPopupMenu;
    CHECK_PTR( m_view );
    zoomInID =
      m_view->insertItem( i18n("Zoom &in"), this, SLOT( zoomIn()) );
    zoomOutID =
      m_view->insertItem( i18n("Zoom &out"), this, SLOT( zoomOut() ) );

    //    viewControlID =
    //      m_view->insertItem( i18n("&View Control..."), this, SLOT( viewControl() ) );


    m_view->insertSeparator();
    shrinkWrapID = 
      m_view->insertItem( i18n("&Fit to page width"), 
			  this, SLOT( slotFitToPageWidth()) );
    infoID =
      m_view->insertItem( i18n("&Info..."), this, SLOT( info() ) );


    
    m_go = new QPopupMenu;
    CHECK_PTR( m_go );
    prevID =
      m_go->insertItem( i18n("&Previous Page"), this, SLOT( prevPage() ) );
    nextID =
      m_go->insertItem( i18n("&Next page"), this, SLOT( nextPage() ) );
    goToPageID =
      m_go->insertItem( i18n("&Go to page..."), this, SLOT( goToPage() ) );
    m_go->insertSeparator();
    goToStartID =
      m_go->insertItem( i18n("Go to &start"), this, SLOT( goToStart() ) );
    goToEndID =
      m_go->insertItem( i18n("Go to &end"), this, SLOT( goToEnd() ) );
    readDownID =
      m_go->insertItem( i18n("&Read down"), this, SLOT( readDown() ) );

    
    m_pagemarks = new QPopupMenu;
    CHECK_PTR( m_pagemarks );
    markCurrentID =
      m_pagemarks->insertItem( i18n("Mark ¤t page"), this, 
			       SLOT( markPage() ) );
    markAllID =
      m_pagemarks->insertItem( i18n("Mark &all pages"), marklist, SLOT( markAll() ) );
    markEvenID =
      m_pagemarks->insertItem( i18n("Mark &even pages"), marklist, SLOT( markEven() ) );
    markOddID =
      m_pagemarks->insertItem( i18n("Mark &odd pages"), marklist, SLOT( markOdd() ) );
    m_pagemarks->insertSeparator();
    toggleMarksID =
      m_pagemarks->insertItem( i18n("&Toggle page marks"), marklist, SLOT(
									  toggleMarks() ) );
    removeMarksID =
      m_pagemarks->insertItem( i18n("&Remove page marks"), marklist, SLOT(
									  removeMarks() ) );
    
  
    m_options = new QPopupMenu;
    CHECK_PTR( m_options );
    
    // I make the options menu here but don't set the entries until
    // I've read the config file.
    
    m_options->setCheckable( true );
    m_options->insertItem(i18n("Show &tool bar"), ID_TOOLBAR);
    m_options->insertItem(i18n("Show st&atus bar"), ID_STATUSBAR);
    m_options->insertItem(i18n("Show &page list"), ID_PAGELIST);
    m_options->insertItem(i18n("&Watch file"), ID_WATCHFILE);
    m_options->insertSeparator();
    m_options->insertItem(i18n("Configure &interpreter..."), ID_GHOSTSCRIPT);
    m_options->insertItem(i18n("Configure &key bindings..."), ID_CONFIGURE);
    m_options->insertSeparator();
    m_options->insertItem(i18n("&Save options"), ID_SAVE);
    connect( m_options, SIGNAL( activated(int) ),
	     SLOT( optionsMenuActivated(int) ) );



    menuBar()->insertItem( i18n("&File"), m_file );
    menuBar()->insertItem( i18n("&View"), m_view );
    menuBar()->insertItem( i18n("&Go"), m_go );
    menuBar()->insertItem( i18n("&Pagemarks"), m_pagemarks );
    menuBar()->insertItem( i18n("&Options"), m_options);
	
    menuBar()->insertSeparator();

    KHelpMenu *m_helpmenu = new KHelpMenu (this, instance()->aboutData(), true);
    connect( m_helpmenu, SIGNAL(showAboutApplication()),
             this, SLOT(showAboutApplication()));
	     m_help = m_helpmenu->menu();
    menuBar()->insertItem (i18n("&Help"), m_help );


    m_file->setItemEnabled(printID, false);
    m_file->setItemEnabled(saveAsID, false);
    m_go->setItemEnabled(nextID, false);
    m_go->setItemEnabled(prevID, false);
    m_go->setItemEnabled(goToPageID, false);
    m_go->setItemEnabled(goToStartID, false);
    m_go->setItemEnabled(goToEndID, false);
    m_go->setItemEnabled(readDownID, false);
    m_pagemarks->setItemEnabled(markCurrentID, false);
    m_pagemarks->setItemEnabled(markAllID, false);
    m_pagemarks->setItemEnabled(markEvenID, false);
    m_pagemarks->setItemEnabled(markOddID, false);
    m_pagemarks->setItemEnabled(toggleMarksID, false);
    m_pagemarks->setItemEnabled(removeMarksID, false);
    //    m_view->setItemEnabled(viewControlID, false);
    m_view->setItemEnabled(zoomInID, false);
    m_view->setItemEnabled(zoomOutID, false);
    m_view->setItemEnabled(shrinkWrapID, false);
    m_file->setItemEnabled(redisplayID, false);
    m_view->setItemEnabled(infoID, false);	

}

void

kghostview'KGhostview::createToolbar() (./kdegraphics/kghostview/kghostview.cpp:645)

KGhostview::createToolbar()
{
  
  // Create the toolbar
  
  QPixmap pixmap;
  //toolbar = new KToolBar( this );
  toolbar = toolBar();
  
  //  pixmap = BarIcon( "filenew" );
  //  toolbar->insertButton(pixmap, ID_NEW, SIGNAL(clicked()), this,                        SLOT(newWindow()), true, i18n("New window..."));
  
  //  pixmap = BarIcon( "fileopen" );  toolbar->insertButton(pixmap, ID_OPEN, SIGNAL(clicked()), this,                        SLOT(openNewFile()), true, i18n("Open"));
  
  //  pixmap = BarIcon( "reload" );  toolbar->insertButton(pixmap, ID_RELOAD, SIGNAL(clicked()), this,                        SLOT(redisplay()), false, i18n("Reload"));
  
  toolbar->insertSeparator();
  
  pixmap = BarIcon( "fileprint" );
  toolbar->insertButton(pixmap, ID_PRINT, SIGNAL(clicked()), this,
                        SLOT(print()), false, i18n("Print"));
  
  toolbar->insertSeparator();
  
  pixmap = BarIcon( "viewmag+" );
  toolbar->insertButton(pixmap, ID_ZOOM_IN, SIGNAL(clicked()), this,
                        SLOT(zoomIn()), false, i18n("Zoom in"));
  
  pixmap = BarIcon( "viewmag-" );
  toolbar->insertButton(pixmap, ID_ZOOM_OUT, SIGNAL(clicked()), this,
                        SLOT(zoomOut()), false, i18n("Zoom out"));
  
  toolbar->insertSeparator();
  
  pixmap = BarIcon( "back" );
  toolbar->insertButton(pixmap, ID_PREV, SIGNAL(clicked()), this,
                        SLOT(prevPage()), false, i18n("Back"));
  
  pixmap = BarIcon( "forward" );
  toolbar->insertButton(pixmap, ID_NEXT, SIGNAL(clicked()), this,
                        SLOT(nextPage()), false, i18n("Forward"));
  
  pixmap = BarIcon( "page" );
  toolbar->insertButton(pixmap, ID_PAGE, SIGNAL(clicked()), this,
                        SLOT(goToPage()), false, i18n("Go to"));
  
  toolbar->insertSeparator();
  
  //Are start and finish really used very often?
  /*  pixmap = BarIcon( "start" );
  toolbar->insertButton(pixmap, ID_START, SIGNAL(clicked()), this,
                        SLOT(goToStart()), false, i18n("Start"));
  
  pixmap = BarIcon( "finish" );
  toolbar->insertButton(pixmap, ID_END, SIGNAL(clicked()), this,
                        SLOT(goToEnd()), false, i18n("End"));
  */
  pixmap = BarIcon( "next" );
  toolbar->insertButton(pixmap, ID_READ, SIGNAL(clicked()), this,
                        SLOT(readDown()), false, i18n("Read down"));
  


  //  toolbar->insertSeparator();
  
  //  pixmap = BarIcon( "flag" );  toolbar->insertButton(pixmap, ID_MARK, SIGNAL(clicked()), this,                        SLOT(markPage()), false, i18n("Toggle mark")); //Don't need this button, just click on the flag now.
  
}




kghostview'KGhostview::createStatusbar() (./kdegraphics/kghostview/kghostview.cpp:716)

void KGhostview::createStatusbar()
{   
    //printf("KGhostview::createStatusbar\n");
    
    statusbar = statusBar();
    statusbar->insertItem(i18n("Sc.100 of 100  P.100 of 100"), ID_LOCATION);
    statusbar->insertItem(i18n("100 %"), ID_MAGSTEP);
    statusbar->insertItem(i18n("Upside Down"), ID_ORIENTATION);
    statusbar->insertItem("", ID_FILENAME);
    
    statusbar->changeItem("", ID_LOCATION);
    statusbar->changeItem("", ID_MAGSTEP);
    statusbar->changeItem("", ID_ORIENTATION);
}


kghostview'KGhostview::openNetFile() (./kdegraphics/kghostview/kghostview.cpp:731)

void KGhostview::openNetFile( const KURL &u )
{
  if ( u.isMalformed() ) {
    KMessageBox::sorry (0, i18n("Malformed URL."));
    return;
  }
  
  // Just a usual file ?
  if ( u.isLocalFile() ) {
    openFile( u.path() );
    return;
  }
  
  if ( iojob != 0L ) {
    KMessageBox::sorry(0, i18n("Already waiting\n"\
			       "for an internet job to finish.\n"\
			       "Please wait until it has finished.\n"\
			       "Alternatively stop the running one."));
    return;
  }
  
  
  
  tmpFile.sprintf( "file:"_PATH_TMP"/kghostview%i", (int)time( 0L ) );
  connect( iojob, SIGNAL( sigFinished( int ) ), this, SLOT( slotIOJobFinished( int ) ) );
  iojob = KIO::copy( netFile, tmpFile );
  //	iojob->copy( netFile.data(), tmpFile.data() );
  kfmAction = KGhostview::GET;
  openMode = 0;
}


kghostview'KGhostview::slotIOJobFinished() (./kdegraphics/kghostview/kghostview.cpp:762)

void KGhostview::slotIOJobFinished( int )
{
  if ( kfmAction == KGhostview::GET ) {
    KURL u( tmpFile.data() );
    isNetFile = true;
    openFile( u.path() );
    
    // Clean up
    unlink( tmpFile.data() );
    iojob = 0L;
  }
}


kghostview'KGhostview::dropEvent() (./kdegraphics/kghostview/kghostview.cpp:775)

void KGhostview::dropEvent( QDropEvent * event )
{
    QStrList list;
    QUriDrag::decode(event, list);
    
    const char *s;

    for ( s = list.first(); s != 0L; s = list.next() )
    {
        // Load the first file in this window
	if ( s == list.getFirst() ) 
        {
           QString n = s;
           openNetFile( n );
        } 
        else 
        {
           KGhostview *kg = new KGhostview();
           kg->show ();
           //windowList.append( kg );
           QString n = s;
           kg->openNetFile( n );
        }
    }
}



kghostview'KGhostview::readSettings() (./kdegraphics/kghostview/kghostview.cpp:802)

void KGhostview::readSettings()
{
  //printf("KGhostview::readSettings\n");
  
  QString str;
  
  KConfig *config = KApplication::kApplication()->config();
  
  config->setGroup( "General" );
  
  str = config->readEntry( "Antialiasing" );
  if ( !str.isNull() && str.find( "on" ) == 0 )
    page->intConfig->antialias = true;
  else
    page->intConfig->antialias = false;
  
  str = config->readEntry( "Palette" );
  if ( !str.isNull() && str.find( "mono" ) == 0 )
    page->intConfig->paletteOpt = MONO_PALETTE;
  else if ( !str.isNull() && str.find( "gray" ) == 0 )
    page->intConfig->paletteOpt = GRAY_PALETTE;
  else
    page->intConfig->paletteOpt = COLOR_PALETTE;
  
  str = config->readEntry( "Backing" );
  if ( !str.isNull() && str.find( "store" ) == 0 )
    page->intConfig->backingOpt = STORE_BACKING;
  else
    page->intConfig->backingOpt = PIX_BACKING;
  
  str = config->readEntry( "Messages" );
  if ( !str.isNull() && str.find( "on" ) == 0 )
    page->intConfig->show_messages = true;
  else
    page->intConfig->show_messages = false;
  
  str = config->readEntry( "Statusbar" );
  if ( !str.isNull() && str.find( "off" ) == 0 ) {
    hide_statusbar = true;
    enableStatusBar( KStatusBar::Hide );
  } else {
    hide_statusbar = false;
    enableStatusBar( KStatusBar::Show );
  }
  
  str = config->readEntry( "Toolbar" );
  if ( !str.isNull() && str.find( "off" ) == 0 ) {
    hide_toolbar = true;
    enableToolBar( KToolBar::Hide, toolbar1 );
  } else {
    hide_toolbar = false;
    enableToolBar( KToolBar::Show, toolbar1 );
  }
  
  str = config->readEntry( "Page list" );
  if ( !str.isNull() && str.find( "off" ) == 0 ) {
    hide_pagelist = true;
    marklist->hide();
  } else {
    hide_pagelist = false;
    marklist->show();
  }
  
  str = config->readEntry( "Width" );
  if ( !str.isNull() )
    options_width = atoi( str );
  else
    options_width = 600;
  
  str = config->readEntry( "Height" );
  if ( !str.isNull() )
    options_height = atoi( str );
  else
    options_height = 400;
  
  str = config->readEntry( "Magstep" );
  if ( !str.isNull() ) {
    int i = atoi( str );
    if( i<20 && i>0 ) { 
      magstep = i;
      set_new_magstep( );
    }
  }
  updateMagstepDisplay();
  
  str = config->readEntry( "Orientation" );
  if ( !str.isNull() ) {
    int i = atoi( str );
    if( i<4 && i>0 ) { 
      set_new_orientation(i);
    }
  }
  updateOrientationDisplay();
  
  str = config->readEntry( "Toolbar position" );
  if ( !str.isNull() ) {
    if( str == "Left" ) {
      toolbar->setBarPos( KToolBar::Left );
    } else if( str == "Right" ) {
      toolbar->setBarPos( KToolBar::Right );
    } else if( str == "Bottom" ) {
      toolbar->setBarPos( KToolBar::Bottom );
    } else
      toolbar->setBarPos( KToolBar::Top );
  }
  
  str = config->readEntry( "View-Control Toolbar position" );
  if ( !str.isNull() ) {
    if( str == "Left" ) {
      viewtoolbar->setBarPos( KToolBar::Left );
    } else if( str == "Right" ) {
      viewtoolbar->setBarPos( KToolBar::Right );
    } else if( str == "Bottom" ) {
      viewtoolbar->setBarPos( KToolBar::Bottom );
    } else
      viewtoolbar->setBarPos( KToolBar::Top );
  }
  
  m_options->setItemChecked ( ID_WATCHFILE,
			      config->readBoolEntry ("WatchFile") );
   
  unsigned int m = config->readUnsignedNumEntry ( "Zoom");
  if (m!=0)
    magstep = current_magstep = m;
  
  config->setGroup( "Last Opened" );
  config->readListEntry( "FileList", lastOpened );
}



kghostview'KGhostview::slotFitToPageWidth() (./kdegraphics/kghostview/kghostview.cpp:932)

void KGhostview::slotFitToPageWidth ()
{
  shrinkWrap(false);
}


kghostview'KGhostview::shrinkWrap() (./kdegraphics/kghostview/kghostview.cpp:937)

void KGhostview::shrinkWrap( bool bonlyiftoosmall)
{
	int new_width=0;
	
	if ( !psfile ) return;
	
	new_width=page->fullView->width()+(x()+width()-mainViewGeometry().right())+(mainViewGeometry().left()-x());//+2;
	
	if( page->vertScrollBar->isVisible() )
		new_width+=page->vertScrollBar->width();
		
	if( marklist->isVisible() )
		new_width+=PAGELIST_WIDTH+3;
		
	if (bonlyiftoosmall)
	  if (! (new_width > width()) )
	      return;
	    
	QWidget *d = QApplication::desktop();
	int w=d->width()-10; 	
	if( new_width > w )
		new_width = w;
			
	resize( new_width, height() );
}


kghostview'KGhostview::paletteChange() (./kdegraphics/kghostview/kghostview.cpp:963)

void KGhostview::paletteChange( const QPalette & )
{
	marklist->setSelectColors( colorGroup().highlight(), 
                                   colorGroup().highlightedText() );
	
	if( psfile )
		redisplay();
}


kghostview'KGhostview::setName() (./kdegraphics/kghostview/kghostview.cpp:972)

void KGhostview::setName()
{
	QString s( kapp->caption() );
	
	if( psfile ) {	
		s.prepend(" - ");
		if ( isNetFile ) {
			int cutoff = netFile.findRev( "/", netFile.length() );
			if ( cutoff != -1 ) 
				s.prepend(netFile.right( netFile.length() - 1 - cutoff ));
			else
				s.prepend(netFile);
		} else
			s.prepend(QFileInfo( filename ).fileName());
	}
	QWidget::setCaption( s );
}


kghostview'KGhostview::newWindow() (./kdegraphics/kghostview/kghostview.cpp:990)

void KGhostview::newWindow()
{
  //	KGhostview *kg = new KGhostview ();

	//kg->resize(width(), height());
	
	//windowList.append( kg );

	//kg->setMinimumSize( 250, 250 );
	//kg->setName();
	//kg->bindKeys();
	//kg->updateMenuAccel();
}


kghostview'KGhostview::closeEvent() (./kdegraphics/kghostview/kghostview.cpp:1004)

void KGhostview::closeEvent( QCloseEvent * )
{
	//printf("%d windows\n", windowList.count());
	
  if ( windowList.count() > 1 )
    {
      windowList.remove( this );
      page->disableInterpreter();
      //debug("Disable interpreter");
      delete toolbar;
      //debug("Delete toolbar");
      //		delete menubar;
      //debug("Delete menubar");
      delete this;
      //debug("Delete this");
      for ( KGhostview *kg = windowList.first(); kg!=0;
	    kg = windowList.next() )
	kg->page->disableInterpreter();
      //debug("Disable interpreter");
    }
  else
    qApp->quit();
}


kghostview'KGhostview::closeWindow() (./kdegraphics/kghostview/kghostview.cpp:1028)

void KGhostview::closeWindow()
{
  close();
}


kghostview'KGhostview::slotWatch() (./kdegraphics/kghostview/kghostview.cpp:1033)

void KGhostview::slotWatch()
{
  unsigned int savepage=current_page;
  
  struct stat sbuf;
  stat( filename, &sbuf );
  if (sbuf.st_mtime > mtime)
    {
      openFile (filename);
      
      if (doc->numpages >= savepage)
	show_page( savepage );
    }

}

kghostview'KGhostview::redisplay() (./kdegraphics/kghostview/kghostview.cpp:1048)

void KGhostview::redisplay()
{
  page->disableInterpreter();
  show_page( current_page );
}


kghostview'KGhostview::writeFileSettings() (./kdegraphics/kghostview/kghostview.cpp:1054)

void KGhostview::writeFileSettings()
{
  //printf("KGhostview::writeFileSettings\n");
  
  KConfig *config = KApplication::kApplication()->config();
  config->setGroup( "Last Opened" );
  config->writeEntry( "FileList", lastOpened );
}


kghostview'KGhostview::writeSettings() (./kdegraphics/kghostview/kghostview.cpp:1063)

void KGhostview::writeSettings()
{
  //printf("KGhostview::writeSettings\n");
  
  keys->writeSettings();
  
  KConfig *config = KApplication::kApplication()->config();
  
  config->setGroup( "General" );
  
  QString s;
  s.setNum( width() );
  config->writeEntry( "Width", s );
  s.setNum( height() );
  config->writeEntry( "Height", s );
  config->writeEntry( "Antialiasing", page->intConfig->antialias ? "on" : "off" );
  config->writeEntry( "Platform fonts", page->intConfig->platform_fonts ? "on" : "off" );
  config->writeEntry( "Statusbar", hide_statusbar ? "off" : "on" );
  config->writeEntry( "Toolbar", hide_toolbar ? "off" : "on" );
  config->writeEntry( "Page list", hide_pagelist ? "off" : "on" );
  config->writeEntry( "Messages", page->intConfig->show_messages ? "on" : "off" );
  
  if( page->intConfig->paletteOpt == COLOR_PALETTE )
    s = "color";
  else if( page->intConfig->paletteOpt == GRAY_PALETTE )
    s = "grayscale";
  else
    s = "monochrome";
  config->writeEntry( "Palette", s );
  
  if( page->intConfig->backingOpt == PIX_BACKING )
    s = "pixmap";
  else
    s = "store";
  config->writeEntry( "Backing", s );
  
  s.setNum( magstep );
  config->writeEntry( "Magstep", s );
  s.setNum( orientation );
  config->writeEntry( "Orientation", s );
  
  if ( toolbar->barPos() == KToolBar::Left )
    s = "Left";
  else if ( toolbar->barPos() == KToolBar::Right )
    s = "Right";
  else if ( toolbar->barPos() == KToolBar::Bottom )
    s = "Bottom";
  else
    s = "Top";
  
  config->writeEntry( "Toolbar position", s );
  
  config->writeEntry( "Zoom", current_magstep);

  config->writeEntry( "WatchFile", m_options->isItemChecked (ID_WATCHFILE) );
  
  changed = false;
}


//
//	SLOTS UP NEXT
//



kghostview'KGhostview::markPage() (./kdegraphics/kghostview/kghostview.cpp:1128)

void KGhostview::markPage()
{
	marklist->markSelected();
}


kghostview'KGhostview::readDown() (./kdegraphics/kghostview/kghostview.cpp:1133)

void KGhostview::readDown()
{
	if( !page->readDown() )
		nextPage();
}


kghostview'KGhostview::scrollUp() (./kdegraphics/kghostview/kghostview.cpp:1139)

void KGhostview::scrollUp()
{
	page->scrollUp();
}


kghostview'KGhostview::scrollDown() (./kdegraphics/kghostview/kghostview.cpp:1144)

void KGhostview::scrollDown()
{
	page->scrollDown();
}


kghostview'KGhostview::scrollLeft() (./kdegraphics/kghostview/kghostview.cpp:1149)

void KGhostview::scrollLeft()
{
	page->scrollLeft();
}


kghostview'KGhostview::scrollRight() (./kdegraphics/kghostview/kghostview.cpp:1154)

void KGhostview::scrollRight()
{
	page->scrollRight();
}


kghostview'KGhostview::help() (./kdegraphics/kghostview/kghostview.cpp:1159)

void KGhostview::help()
{
    // Torben
    kapp->invokeHTMLHelp( "", "" );
}



kghostview'KGhostview::goToPage() (./kdegraphics/kghostview/kghostview.cpp:1166)

void KGhostview::goToPage()
{
    //printf("KGhostview::goToPage\n");

  GoTo gt(this, "Go to");
  gt.setCaption(i18n("Go to..."));
  gt.current_page=current_page;
  gt.num_parts=num_parts;
  for( int j=0; j < 10; j++ ) {
    
    gt.pages_in_part[j]=pages_in_part[j];
  }
  gt.init();
  if( gt.exec() ) {
    current_page=gt.current_page;
    
    marklist->select(current_page);
    //show_page(current_page);
  }
}


kghostview'KGhostview::print() (./kdegraphics/kghostview/kghostview.cpp:1187)

void KGhostview::print()
{
  //printf("KGhostview::print\n");
  
  pd = new PrintDialog( this, "print dialog", doc->numpages, 
			( marklist->markList()->count() > 0 ) );
  pd->setCaption(i18n("Print"));
  
  
  if( pd->exec() )
    {
      printStart( pd->pgMode, pd->cbOrder->isChecked(),
		  pd->cbFile->isChecked(),
		  pd->printerName, pd->spoolerCommand,
		  pd->printerVariable,
		  QString( pd->leStart->text() ).toInt(),
		  QString( pd->leEnd->text() ).toInt() );
    }
  
}

/*
void
KGhostview::viewControl()
{
  vc->magComboBox->setCurrentItem(magstep-1);
  
  if( !vc->isVisible() )
    {
      vc->show();
      //vc->orientComboBox->setFocus();
    }
}
*/
void

kghostview'KGhostview::zoomIn() (./kdegraphics/kghostview/kghostview.cpp:1222)

KGhostview::zoomIn()
{
  unsigned int i;
  
  i = magstep + 1;
  if (i <= shrink_magsteps+expand_magsteps)
    set_magstep(i);

}


kghostview'KGhostview::zoomOut() (./kdegraphics/kghostview/kghostview.cpp:1232)

void KGhostview::zoomOut()
{
  int i;
  
  i = magstep - 1;
  if (i >= 1)
    set_magstep((unsigned int) i);

}



kghostview'KGhostview::nextPage() (./kdegraphics/kghostview/kghostview.cpp:1243)

void KGhostview::nextPage()
{
    //printf("KGhostview::nextPage\n");

    int new_page = 0;

    if (toc_text) {
	    new_page = current_page + 1;
		if ((unsigned int) new_page >= doc->numpages)
			return;
    }
	marklist->select(new_page);
    //show_page(new_page);
    page->scrollTop();
}


kghostview'KGhostview::goToStart() (./kdegraphics/kghostview/kghostview.cpp:1259)

void KGhostview::goToStart()
{
    //printf("KGhostview::goToStart\n");

    int new_page = 0;
    
	marklist->select(new_page);
    //show_page(new_page);
    page->scrollTop();
}


kghostview'KGhostview::goToEnd() (./kdegraphics/kghostview/kghostview.cpp:1270)

void KGhostview::goToEnd()
{
    //printf("KGhostview::goToEnd\n");

    int new_page = 0;

    if (toc_text) {
	    new_page = doc->numpages-1;
    }
    
	marklist->select(new_page);
    //show_page(new_page);
    page->scrollTop();
}



kghostview'KGhostview::prevPage() (./kdegraphics/kghostview/kghostview.cpp:1286)

void KGhostview::prevPage()
{
    //printf("KGhostview::prevPage\n");

    int new_page = 0;
	
    if (toc_text) {
	    new_page = current_page - 1;
		if (new_page < 0)
			return;
    }
	
	marklist->select(new_page);
    //show_page(new_page);
    page->scrollTop();
}


kghostview'KGhostview::openNewFile() (./kdegraphics/kghostview/kghostview.cpp:1303)

void KGhostview::openNewFile()
{
  //printf("KGhostview::openNewFile\n");
  
  QString d;
  if ( filename && psfile )
    d = QFileInfo( filename ).dirPath();
  else
    d = QDir::currentDirPath();
  
  //openNetFile() really opens either network or local file.
  openNetFile (KFileDialog::getOpenURL( d.data(), "*.ps *.eps *.pdf"));

  if (psfile && m_options->isItemChecked (ID_WATCHFILE))
    startWatch();
}



kghostview'KGhostview::optionsMenuActivated() (./kdegraphics/kghostview/kghostview.cpp:1321)

void KGhostview::optionsMenuActivated( int item )
{
    //printf("KGhostview::optionsMenuActivated\n");
    //printf("item= %d\n", item);

	switch (item){
  		/*case ID_ANTIALIAS:
  			if(page->intConfig->antialias) {
  				page->intConfig->antialias = false;
  				m_options->changeItem(i18n("Turn antialiasing on"), item);
  			} else {
  				m_options->changeItem(i18n("Turn antialiasing off"), item);
  				page->intConfig->antialias = true;
  			}
			page->disableInterpreter();
			if( psfile )
				show_page(current_page);
			break;

		case ID_MESSAGES:
			if(page->intConfig->show_messages) {
  				page->intConfig->show_messages = false;
  				m_options->changeItem(i18n("Show Ghostscript messages"), item);
  			} else {
  				m_options->changeItem(i18n("Hide Ghostscript messages"), item);
  				page->intConfig->show_messages = true;
  			}
			break;*/
			
		case ID_TOOLBAR:
			if(hide_toolbar) {
				hide_toolbar=false;
				enableToolBar( KToolBar::Toggle, toolbar1 );
				//resize( width(), height() );
				m_options->setItemChecked( item, true );
			} else {
				hide_toolbar=true;
				enableToolBar( KToolBar::Toggle, toolbar1 );
				//resize( width(), height() );
				m_options->setItemChecked( item, false );
			}
			break;
			
		case ID_PAGELIST:
			if(hide_pagelist) {
				hide_pagelist=false;
				marklist->show();
				//resize( width(), height() );
				//resizeEvent( 0 );
				shrinkWrap();
				m_options->setItemChecked( item, true );
			} else {
				hide_pagelist=true;
				marklist->hide();
				//resize( width(), height() );
				//resizeEvent( 0 );
				shrinkWrap();
				m_options->setItemChecked( item, false );
			}
			break;
			
		case ID_STATUSBAR:
			if(hide_statusbar) {
				hide_statusbar=false;
				enableStatusBar( KStatusBar::Toggle );
				//resize( width(), height() );
				m_options->setItemChecked( item, true );
			} else {
				hide_statusbar=true;
				enableStatusBar( KStatusBar::Toggle );
				//resize( width(), height() );
				m_options->setItemChecked( item, false );
			}
			break;
	case ID_WATCHFILE:
	  if (m_options->isItemChecked (item))
	    stopWatch();
	  else
	    startWatch();
	  m_options->setItemChecked
	    (item, !m_options->isItemChecked(item));
	  break;
	case ID_CONFIGURE:
	  configureKeybindings();
	  break;
			
		case ID_GHOSTSCRIPT:
			configureGhostscript();
			break;
			
		case ID_SAVE:
			writeSettings();
	}
}		


kghostview'KGhostview::startWatch() (./kdegraphics/kghostview/kghostview.cpp:1416)

void KGhostview::startWatch()
{
  if (!psfile)
    return;

  if (watch!=0L)
    delete watch;

  watch = new QTimer;

  connect ( watch, SIGNAL (timeout()),
	    this, SLOT (slotWatch()) );

  watch->start (500);
}


kghostview'KGhostview::stopWatch() (./kdegraphics/kghostview/kghostview.cpp:1432)

void KGhostview::stopWatch()
{
  if (watch!=0L)
    delete watch;
}


kghostview'KGhostview::dummy() (./kdegraphics/kghostview/kghostview.cpp:1438)

void KGhostview::dummy()
{
  KMessageBox::sorry(0, i18n("Sorry, not ready yet"),
			i18n("Version 0.6"));
}


kghostview'KGhostview::about() (./kdegraphics/kghostview/kghostview.cpp:1444)

void KGhostview::about()
{
  KMessageBox::about(0, i18n("Version: 0.6 alpha\nAuthor: Mark Donohoe\nMail: donohoe@kde.org"),
			i18n("About kghostview"));
}


kghostview'KGhostview::printStart() (./kdegraphics/kghostview/kghostview.cpp:1450)

void KGhostview::printStart( int mode, bool reverseOrder, 
			     bool toFile,
			     QString printerName, QString spoolerCommand,
			     QString printerVariable,
			     int pgStart, int pgEnd )
{
  QStrList *ml = new QStrList;
  
  switch( mode ) {
  case PrintDialog::All:
    break;
    
  case PrintDialog::Current:
    ml->append( marklist->text( current_page ) );
    break;
    
  case PrintDialog::Marked:
    ml = marklist->markList();
    break;
    
  case PrintDialog::Range:
    if ( pgStart <= pgEnd )
      for( int j = pgStart-1; j< pgEnd; j++ )
	ml->append( marklist->text( j ) );
    else 
      for( int j = pgEnd-1; j< pgStart; j++ )
	ml->append( marklist->text( j ) );
    break;
  }
  
  if ( reverseOrder ) {
    QStrList *sl = new QStrList;
    for( ml->last(); ml->current(); ml->prev() )
      sl->append( ml->current() );
    *ml = *sl;
    delete sl;
  }
  
  QString error;
  
  if ( toFile ) {
    error = printToFile( ml );
  } else { 
    error = printToPrinter( printerName, spoolerCommand, printerVariable,
			    ( mode == PrintDialog::All ), ml );
  }
  
  if ( !error.isNull() )
    KMessageBox::error( 0, error, i18n( "Error printing" ));
  
  delete ml;
}

void

kghostview'KGhostview::saveAs() (./kdegraphics/kghostview/kghostview.cpp:1504)

KGhostview::saveAs ()
{
  printToFile ();
}


kghostview'KGhostview::printToFile() (./kdegraphics/kghostview/kghostview.cpp:1509)

QString KGhostview::printToFile( QStrList *ml )
{
  FILE *pswrite;
  bool bdeleteml=false;
  
  if (ml==0L)
    {
      ml = new QStrList;
      bdeleteml=true;
      for( unsigned int j = 0; j< doc->numpages; j++ )
	ml->append( marklist->text( j ) );
    }
  
  /*	
	//No!  Printing all to a file is a desirable,
	  often-requested feature.  (Think: web browsing, print preview)
	
	if ( allMode ) {
	QString buf( i18n(	"You chose to print all pages to a file.\n"
	"This would produce a document identical to\n"
	"that currently loaded into the viewer.\n"
	"There is no need to print all pages into a new file.") );
	return buf;
	}*/
  
  QString dir;
  if ( filename )
    dir = QFileInfo( filename ).dirPath();	
  
  QString s = QFileDialog::getSaveFileName( dir, "*.*ps*", this);
  if ( s.isNull() ) 
    {
      QString buf( i18n( "No file name was given so\n"\
			 "nothing could be printed to a file.\n") );
      if (bdeleteml)
	delete ml;
      return buf;
    }
  
  if ( ( pswrite = fopen( s.data(), "w" ) ) == 0L )
    {
      QString buf;
      buf = i18n("Attempt to open file for writing failed.\n\n"
		 "Error: %1\n")
	.arg( strerror(errno) );
      if (bdeleteml)
	delete ml;
      return buf;
    }
  else
    {
      psCopyDoc( pswrite, ml );
      fclose( pswrite );
      if (bdeleteml)
	delete ml;
      return QString::null;
    }

  if (bdeleteml)
    delete ml;
  
}


kghostview'KGhostview::printToPrinter() (./kdegraphics/kghostview/kghostview.cpp:1572)

QString KGhostview::printToPrinter( QString printerName, QString spoolerCommand,
						QString printerVariable, bool allMode, QStrList *ml )
{
//    printf("KGhostview::print_file\n");

    FILE *printer;
    SIGVAL (*oldsig) (int);
    int bytes = 0;
    char buf[ BUFSIZ ];
    bool failed;
    QString ret_val;

	page->disableInterpreter();

	// For SYSV, SVR4, USG printer variable="LPDEST", print command=lp
	// Other systems printer variable="PRINTER", print command=lpr
	
        // Why add double quotes ? It breaks setenv... David Faure.
	// printerVariable.append("\"");
	// printerVariable.prepend("\"");

    if ( !printerName.isEmpty() ) {
        if ( !printerVariable.isEmpty() ) {
                setenv( printerVariable.data(), printerName.data(), true );
        } else return( QString( i18n( "Set Environment variable (to PRINTER or LPDEST for instance)"
                                      "for Printer name to be taken into account." ) ) );
    }
    oldsig = signal( SIGPIPE, SIG_IGN );
    printer = popen( spoolerCommand.data(), "w" );
	
    if ( toc_text && !allMode ) {
		psCopyDoc( printer, ml );
    } else {
		FILE *tmpfile = ::fopen( filename, "r" );

		while ( ( bytes = ::read( fileno(tmpfile), buf, BUFSIZ ) ) ) {
	   		bytes = ::write( fileno(printer), buf, bytes);
	   	}
		::fclose( tmpfile );
    }
	
    failed = ( pclose( printer ) != 0 );
	
    ret_val = failed?i18n("Print failure: %1").arg(spoolerCommand):QString::null;
	
    signal( SIGPIPE, oldsig );
    return( ret_val );
}

// length calculates string length at compile time
// can only be used with character constants


kghostview'KGhostview::psCopyDoc() (./kdegraphics/kghostview/kghostview.cpp:1628)

void KGhostview::psCopyDoc( FILE *fp, QStrList *ml )
{
//    printf("KGhostview::pscopydoc\n");

    FILE *psfile;
    char text[ PSLINELENGTH ];
    char *comment;
    bool pages_written = false;
    bool pages_atend = false;
    int pages = 0;
    int page = 1;
    unsigned int i;
    long here;

    psfile = fopen( filename, "r" );
    
    pages = ml->count();
    if ( pages == 0 ) {
      KMessageBox::error( 0,
			  i18n( "Printing failed because the list of\n"
				"pages to be printed was empty.\n" ),
			  i18n( "Error printing" ));
      return;
    }
    
    here = doc->beginheader;
    while ( ( comment = pscopyuntil( psfile, fp, here,
				     doc->endheader, "%%Pages:" ) ) ) {
      here = ftell( psfile );
      if ( pages_written || pages_atend ) {
	free( comment );
	continue;
      }
      sscanf( comment + length("%%Pages:" ), "%s", text );
      if ( strcmp( text, "(atend)" ) == 0 ) {
	fputs( comment, fp );
	pages_atend = true;
      } else {
	switch ( sscanf( comment + length( "%%Pages:" ), "%*d %d", &i ) ) {
	case 1:
	  fprintf( fp, "%%%%Pages: %d %d\n", pages, i );
	  break;
	default:
	  fprintf( fp, "%%%%Pages: %d\n", pages );
	  break;
	}
	pages_written = true;
      }
      free(comment);
    }
    pscopy( psfile, fp, doc->beginpreview, doc->endpreview );
    pscopy( psfile, fp, doc->begindefaults, doc->enddefaults );
    pscopy( psfile, fp, doc->beginprolog, doc->endprolog );
    pscopy( psfile, fp, doc->beginsetup, doc->endsetup );
	
	QStrListIterator it( *ml );
	
	for(; it.current(); ++it ) {
		
		i = QString( it.current() ).toInt() - 1;
	
	    comment = pscopyuntil( psfile, fp, doc->pages[i].begin,
				  					doc->pages[i].end, "%%Page:" );
	    
		fprintf( fp, "%%%%Page: %s %d\n",
		    		doc->pages[i].label, page++ );
	    
		free( comment );
	    pscopy( psfile, fp, -1, doc->pages[i].end );
	}

    here = doc->begintrailer;
    while ( ( comment = pscopyuntil(psfile, fp, here,
				 			doc->endtrailer, "%%Pages:" ) ) ) {
		here = ftell( psfile );
		if ( pages_written ) {
	    	free( comment );
	    	continue;
		}
		switch ( sscanf( comment + length( "%%Pages:" ), "%*d %d", &i ) ) {
	    	case 1:
			fprintf( fp, "%%%%Pages: %d %d\n", pages, i );
			break;
	    	default:
			fprintf( fp, "%%%%Pages: %d\n", pages );
			break;
		}
		pages_written = true;
		free( comment );
    }
    fclose( psfile );
}


kghostview'KGhostview::same_document_media() (./kdegraphics/kghostview/kghostview.cpp:1730)

bool KGhostview::same_document_media()
{
    //printf("KGhostview::same_document_media\n");

    unsigned int j;

    if (olddoc == 0 && doc == 0) {
    	//printf("	0 olddoc and doc\n");
    	return true;
    }
    if (olddoc == 0 || doc == 0) return false;
    if (olddoc->nummedia != doc->nummedia) return false;
    // Exclusive OR old document was EPS and new document is EPS
    if ((olddoc->epsf || doc->epsf) && !(olddoc->epsf && doc->epsf)) {
    	//fprintf(stderr, "Old document was EPS and this isn't or vice versa\n");
    	return false;
    }
    for (j = 0; j < doc->nummedia; j++)
		if (strcmp(olddoc->media[j].name, doc->media[j].name)) return false;
	
    return false;
}


kghostview'KGhostview::openFile() (./kdegraphics/kghostview/kghostview.cpp:1753)

void KGhostview::openFile( QString name )
{
  //    printf("KGhostview::openFile\n");
  
  FILE *fp;
  struct stat sbuf;
  
  if ( name.isNull() ) {
    KMessageBox::error(0,
		       i18n("No file name was specified.\n"
			    "No document was loaded.\n"),
		       i18n("Error opening file"));
    return;
  }
  
  if (strcmp(name, "-")) {
    
    if ( ( fp = fopen(name, "r") ) == 0 ) {
      
      QString s;
      s = i18n("The document could not be opened.\n"
	       "No document has been loaded.\n\n"
	       "%1\nError: %2")
	.arg( name )
	.arg( strerror(errno) );
      
      KMessageBox::error(0, s, i18n("Error opening file"));
      
      return ;
      
    } else {
      
      oldfilename = filename;
      filename = name;
      if ( psfile ) {
	fclose( psfile );
      }
      psfile = fp;
      stat( filename, &sbuf );
      mtime = sbuf.st_mtime;
      
      new_file( 0 );
      setName();
  
      isNetFile=false; //DS 2/22/2000
      //marklist->select(0);
      //show_page(0);
      if (m_options->isItemChecked (ID_WATCHFILE))
	startWatch();

      return;
    }
    
  } else {
    
    oldfilename = filename;
    filename = name;
    if ( psfile )
      fclose( psfile );
    psfile = 0;
    
    new_file(0);
    
    setName();
    if (m_options->isItemChecked (ID_WATCHFILE))
      startWatch();
    //marklist->select(0);
    
    return;
  }
}

bool

kghostview'KGhostview::setOrientation() (./kdegraphics/kghostview/kghostview.cpp:1826)

KGhostview::setOrientation (Orientation _orientation)
{
  //Work around undiscovered bug (sorry!)  -- dsweet
    {
      switch (_orientation)
	{
	case Portrait:
	  orientation=Landscape;
	  break;
	case Landscape:
	  orientation=UpsideDown;
	  break;
	case UpsideDown:
	  orientation=Seascape;
	  break;
	case Seascape:
	  orientation=Portrait;
	  break;
	}
      force_orientation=true;
      set_new_orientation(0);
      page->layout();
      show_page(current_page);
      shrinkWrap();
    }


    //Now set the REQUESTED orientation.
  orientation = _orientation;
  force_orientation=true;
  if (!set_new_orientation (0))
    return false;

  page->layout();
  show_page(current_page);
  shrinkWrap();

  return true;
}


kghostview'KGhostview::set_new_orientation() (./kdegraphics/kghostview/kghostview.cpp:1866)

bool KGhostview::set_new_orientation(int number)
{
    //printf("KGhostview::set_new_orientation\n");

    bool changed = false;
    bool from_doc = false;
    int new_orientation;

	//printf("******	Set new orientation\n");

    if (force_orientation) {
	new_orientation = orientation;
    } else {
	if (doc) {
	    if (toc_text && doc->pages[number].orientation != NONE) {
		new_orientation = doc->pages[number].orientation;
		from_doc = true;
	    } else if (doc->default_page_orientation != NONE) {
		new_orientation = doc->default_page_orientation;
		from_doc = true;
	    } else if (doc->orientation != NONE) {
		new_orientation = doc->orientation;
		from_doc = true;
	    } else {
		new_orientation = orientation;
	    }
	} else {
	    new_orientation = orientation;
	}
    }

    /* If orientation changed,
     * stop interpreter and setup for new orientation. */
    if (new_orientation != current_orientation)
      {
	//printf("New orientation\n");
	page->disableInterpreter();
	page->orientation =  new_orientation;
	current_orientation = new_orientation;
	changed = true;
	updateOrientationDisplay();
      } 
    
    return changed;
}

// Set new pagemedia

kghostview'KGhostview::set_new_pagemedia() (./kdegraphics/kghostview/kghostview.cpp:1913)

bool KGhostview::set_new_pagemedia( int number )
{
    //printf("KGhostview::set_new_pagemedia\n");

    int new_pagemedia=0;
    int new_llx=0;
    int new_lly=0;
    int new_urx=0;
    int new_ury=0;
    bool changed = false;
    bool from_doc = false;

    //printf("******	Set new media\n");
    
    if (force_document_media)
      {
	new_pagemedia = document_media;
      }
    else if (force_pagemedia)
      {
	new_pagemedia = default_pagemedia;
      } 
    else
      {
	if (doc) {
	  if (toc_text && doc->pages[number].media != 0) {
	    new_pagemedia = doc->pages[number].media - doc->media;
	    from_doc = true;
	  } else if (doc->default_page_media != 0) {
	    new_pagemedia = doc->default_page_media - doc->media;
	    from_doc = true;
	  } else {
	    new_pagemedia = default_pagemedia;
	  }
	} else {
	  new_pagemedia = default_pagemedia;
	}
      }
    
    // If pagemedia changed, remove the old marker.
    //    if (new_pagemedia != current_pagemedia)
      //      {
    //fprintf(stderr, "New media\n");
	
	current_pagemedia = new_pagemedia;
	//    } 
    
    // Compute bounding box
	if (   !force_document_media &&
    		!force_pagemedia &&
			doc && doc->epsf &&
			/* Ignore malformed bounding boxes */
			(doc->boundingbox[URX] > doc->boundingbox[LLX]) &&
			(doc->boundingbox[URY] > doc->boundingbox[LLY])
	) {
		new_llx = doc->boundingbox[LLX];
		new_lly = doc->boundingbox[LLY];
		new_urx = doc->boundingbox[URX];
		new_ury = doc->boundingbox[URY];
		//text=XmStringCreateLtoR("EPS box", XmFONTLIST_DEFAULT_TAG);
		//printf("EPS box\n");
    } else {
    	//printf("Trying to compute size ! base papersize = %d\n",
    	//base_papersize);
		new_llx = new_lly = 0;
		if (new_pagemedia < base_papersize) {
	    	new_urx = doc->media[new_pagemedia].width;
	    	new_ury = doc->media[new_pagemedia].height;
	    	//printf("%s\n", doc->media[new_pagemedia].name);
		   // text=XmStringCreateLtoR(doc->media[new_pagemedia].name
	    	//	, XmFONTLIST_DEFAULT_TAG);
		} else {
	    	new_urx = papersizes[new_pagemedia-base_papersize].width;
	    	new_ury = papersizes[new_pagemedia-base_papersize].height;
	    	//printf("%s\n", papersizes[new_pagemedia-base_papersize].name);
		   // text=XmStringCreateLtoR(
		   // 	papersizes[new_pagemedia-base_papersize].name
		   // 	, XmFONTLIST_DEFAULT_TAG);
		}
    }
	
	//printf("new width = %d, current width = %d\n", new_urx, current_urx);
	//printf("new h = %d, current h = %d\n", new_ury, current_ury);
	
	//printf("new x offset %d : new y offset %d\n", new_llx, new_lly);
	
    // If bounding box changed, setup for new size.
    if ((new_llx != current_llx) || (new_lly != current_lly) ||
	(new_urx != current_urx) || (new_ury != current_ury)) {
      //printf("Change media\n");
		page->disableInterpreter();
		changed = true;
		current_llx = new_llx;
		current_lly = new_lly;
		current_urx = new_urx;
		current_ury = new_ury;
		page->llx = current_llx;
		page->lly = current_lly;
		page->urx = current_urx;
		page->ury = current_ury;
    }
	
	/* XtSetArg(args[0], XmNselectedItem, text);
	//XtSetValues(viewControlMediaCombo, args, ONE); */


    
    if (viewtoolbar != 0)
      {
	if ( !force_document_media && !force_pagemedia )
	  {
	    int i;
	    for (i = 0; i < viewtoolbar->getCombo(ID_VT_MEDIA)->count(); i++)
	      {
		if (viewtoolbar->getComboItem(ID_VT_MEDIA, i) ==
		    QString (doc->media[new_pagemedia].name))
		  {
		    viewtoolbar->setCurrentComboItem (ID_VT_MEDIA, i);
		    break;
		  }
	      }
	  }
      }
    

  return changed;
}



kghostview'KGhostview::build_pagemedia_menu() (./kdegraphics/kghostview/kghostview.cpp:2042)

void KGhostview::build_pagemedia_menu()
{
    //printf("KGhostview::build_pagemedia_menu\n");

    unsigned int i;
    int offset;

    if (same_document_media()) {
    	//printf("Same document media\n");
    	return;
    }
    force_document_media = false;

    /* Build the Page Media menu */
    /* the Page media menu has two parts.
     *  - the document defined page medias
     *  - the standard page media defined from Adobe's PPD
     */

    base_papersize = 0;
    if (doc)
      base_papersize = doc->nummedia;
    for (i = 0; papersizes[i].name; i++) {}	// Count the standard entries
    i += base_papersize;


	// if you've got an eps file need bounding box in menu too
	
	if(doc && doc->epsf) {
	  //		vc->mediaComboBox->insertItem("EPS Box");
		 offset=2;
	} else {
		offset=1;
	}
	

    if (doc && doc->nummedia) {
		for (i = 0; i < doc->nummedia; i++) {
		  //			vc->mediaComboBox->insertItem(doc->media[i].name);
			//printf("%s  ", doc->media[i].name);
		}
    }
    for (i = 0; papersizes[i].name; i++) {
		if (i > 0) {
	    	// Skip over same paper size with small imageable area
	    	if ((papersizes[i].width == papersizes[i-1].width) &&
			(papersizes[i].height == papersizes[i-1].height)) {
			continue;
	    	}
		}
		//		vc->mediaComboBox->insertItem(papersizes[i].name);
		//printf("%s  ", papersizes[i].name);
    }
    //printf("\n");
}



kghostview'KGhostview::setup() (./kdegraphics/kghostview/kghostview.cpp:2101)

KGhostview::setup()
{
//    printf("KGhostview::setup\n");

    int oldtoc_entry_length;
    int k;
    int this_page, last_page=0;
    //char temp_text[20];
    
    
    if ( ! filename ) return false;
    
    //printf("Gone into setup\n");
    // Reset to a known state.
    psfree( olddoc );
    //printf("Freed olddoc\n");
    olddoc = doc;
    doc = 0;
    current_page = -1;
    toc_text = 0;
    oldtoc_entry_length = toc_entry_length;
    //printf("Next - pages in part\n");
    for(k=0;k<10;k++) pages_in_part[k]=0;
    num_parts=0;
	
    marklist->setAutoUpdate( false );
    //marklist->select(0);
    marklist->clear();
	
	//printf("Reset state\n");
	
    // Scan document and start setting things up
    if (psfile) {
      //printf ("Scan file -");
      //doc = psscan(psfile); // 18/3/98 Jake Hamby patch
      
      // 18/3/98 Jake Hamby patch
      
      char *filename_dscP = 0;
      char *filename_uncP = 0;
      const char *cmd_scan_pdf = "gs -dNODISPLAY -dQUIET -sPDFname=%s -sDSCname=%s pdf2dsc.ps -c quit";
      const char *cmd_uncompress = "gzip -d -c %s > %s";
      doc = psscan(&psfile, filename, _PATH_TMP"/kghostview", &filename_dscP,
		   cmd_scan_pdf, &filename_uncP, cmd_uncompress);
      
      // UNIX won't delete these files until the last reference is closed,
      // so we can unlink() them now
      
      if(filename_dscP) {
	unlink(filename_dscP);
	free(filename_dscP);
      }
      
      if (filename_uncP) {
	unlink(filename_uncP);
	free(filename_uncP);
      }
      
      // end of patch
      
      //if (doc == 0) //printf(" 0 FILE - ");
      //printf ("scanned\n");
    }

    
    //
    // Build table of contents
    // Well, that's what it used to be called !!
    //
    if (doc && (!doc->epsf && doc->numpages > 0 ||
		 doc->epsf && doc->numpages > 1)) {
		int maxlen = 0;
		unsigned int i, j;
		useful_page_labels = false;

		if (doc->numpages == 1) useful_page_labels = true;
		for (i = 1; i < doc->numpages; i++)
			if ( (useful_page_labels = (useful_page_labels ||
				strcmp(doc->pages[i-1].label, doc->pages[i].label)))) break;
		if (useful_page_labels) {
			for (i = 0; i < doc->numpages; i++) 
			if((unsigned int)maxlen<strlen(doc->pages[i].label))
				maxlen=strlen(doc->pages[i].label);
		} else {
			double x;
			x = doc->numpages;
			maxlen = (int)( log10(x) + 1 );
		}
		toc_entry_length = maxlen + 3;
		toc_length = doc->numpages * toc_entry_length - 1;
		toc_text = 1;

		for (i = 0; i < doc->numpages;
			 i++) {
			if (useful_page_labels) {
			if (doc->pageorder == DESCEND) {
				j = (doc->numpages - 1) - i;
			} else {
				j = i;
			}
				this_page=atoi(doc->pages[j].label);
				if(last_page>this_page) {
					num_parts++;
				}
				if (num_parts<10) pages_in_part[num_parts]++;
			
				last_page=this_page;
			} else {
			}
		}
		page->filename = QString::null;
		//printf("Set 0 filename for gs -- use pipe\n");
		
		QString s;
		// finally set maked list
		for ( i = 1; i <= doc->numpages;
			 i++) {
			 j = doc->numpages-i;
			 s = doc->pages[j].label;
			marklist->insertItem( s, 0 );
		}
		
    } else {
		toc_length = 0;
		toc_entry_length = 3;
		page->filename = filename;
		//printf("Set filename -- gs will open this file\n");
		QString s("1");
		marklist->insertItem( s, 0 );
    }
	//printf("Parsed document structure\n");
	
	marklist->setAutoUpdate( true );
	//marklist->select(0);
	marklist->update();

	
	//printf("number of parts %d\n", num_parts);
	if (doc) {
		 if (num_parts>10 || (unsigned int)num_parts==doc->numpages) {
			num_parts=0;
			pages_in_part[0]=doc->numpages;
		}
		if(num_parts==0) {
			if(doc->numpages==0) {
				sprintf(page_total_label, i18n("of 1    "));
			} else if(doc->numpages>0 && doc->numpages<10) {
				sprintf(page_total_label, i18n("of %d    "), doc->numpages);
			} else if (doc->numpages<100) {
				sprintf(page_total_label, i18n("of %d  "), doc->numpages);
			} else if (doc) {
				sprintf(page_total_label, i18n("of %d"), doc->numpages);
			} else {
				sprintf(page_total_label, "         ");
			}
		} else {
			if(pages_in_part[0]==0) {
				sprintf(page_total_label, i18n("of 1    "));
			} else if(pages_in_part[0]>0 && pages_in_part[0]<10) {
				sprintf(page_total_label, i18n("of %d    "), pages_in_part[0]);
			} else if (pages_in_part[0]<100) {
				sprintf(page_total_label, i18n("of %d  "), pages_in_part[0]);
			} else if (doc) {
				sprintf(page_total_label, i18n("of %d"), pages_in_part[0]);
			} else {
				sprintf(page_total_label, "         ");
			}

			sprintf(part_total_label, i18n("of %d"), num_parts+1);
		}
	}
	//printf("Made table of contents\n");
	
	build_pagemedia_menu();
	//printf("Built pagemedia menu\n");
	
	// Reset ghostscript and output messages popup
    if (
    	!doc || !olddoc ||
		strcmp(oldfilename, filename) ||
		olddoc->beginprolog != doc->beginprolog ||
		olddoc->endprolog != doc->endprolog ||
		olddoc->beginsetup != doc->beginsetup ||
		olddoc->endsetup != doc->endsetup
	) {
		//printf("reset messages\n");

		page->disableInterpreter();
		//printf("Disabled Interpreter\n");
		
			/**************************************************************
			 *	XtUnmanageChild(infopopup);
			 *	XmTextReplace(infotext, 0, output_position, 0_string);
			 *	info_up = false;
			 *	XtSetArg(args[0], XmNcursorPosition, 0);
			 *	XtSetValues(infotext, args, ONE);
			 *	output_position=0;
			 **************************************************************/
    }
	
	if(current_page==-1) current_page=0;
	
	toolbar->setItemEnabled(ID_ZOOM_IN, true);
	toolbar->setItemEnabled(ID_ZOOM_OUT, true);
	//	toolbar->setItemEnabled(ID_RELOAD, true);
    toolbar->setItemEnabled(ID_PRINT, true);
    toolbar->setItemEnabled(ID_MARK, true);
    m_file->setItemEnabled(printID, true);
    m_file->setItemEnabled(saveAsID, true);
    
	if(toc_text) {
		if( (unsigned int)current_page+1<doc->numpages ) {
			m_go->setItemEnabled(nextID, true);
			toolbar->setItemEnabled(ID_NEXT, true);
		}
		if( current_page-1>=0 ) {
			m_go->setItemEnabled(prevID, true);
			toolbar->setItemEnabled(ID_PREV, true);
		}
		m_go->setItemEnabled(goToPageID, true);
		m_go->setItemEnabled(goToStartID, true);
		m_go->setItemEnabled(goToEndID, true);
		m_go->setItemEnabled(readDownID, true);
		toolbar->setItemEnabled(ID_PAGE, true);
		toolbar->setItemEnabled(ID_START, true);
		toolbar->setItemEnabled(ID_END, true);
		toolbar->setItemEnabled(ID_READ, true);
	}
	//	m_view->setItemEnabled(viewControlID, true);
	m_view->setItemEnabled(zoomInID, true);
	m_view->setItemEnabled(zoomOutID, true);
	m_view->setItemEnabled(shrinkWrapID, true);
	m_file->setItemEnabled(redisplayID, true);
	m_view->setItemEnabled(infoID, true);
	m_pagemarks->setItemEnabled(markCurrentID, true);
	m_pagemarks->setItemEnabled(markAllID, true);
	m_pagemarks->setItemEnabled(markEvenID, true);
	m_pagemarks->setItemEnabled(markOddID, true);
	m_pagemarks->setItemEnabled(toggleMarksID, true);
	m_pagemarks->setItemEnabled(removeMarksID, true);
	viewtoolbar->setItemEnabled (ID_VT_MAG, true);
	viewtoolbar->setItemEnabled (ID_VT_ORIENT, true);
	viewtoolbar->setItemEnabled (ID_VT_MEDIA, true);
  

	statusbar->changeItem( filename.data(), ID_FILENAME );

	switch (doc->orientation)
	  {
	  case PORTRAIT:
	    orientation = Portrait;
	    break;
	  case LANDSCAPE:
	    orientation = Landscape;
	    break;
	  default:
	    orientation = Portrait;
	  }

	marklist->setAutoUpdate( true );
	marklist->update();
	marklist->select(0);

	setOrientation ((Orientation) orientation);
	updateMagstepDisplay();

    //printf("Setup finished\n");
    return oldtoc_entry_length != toc_entry_length;
}

void

kghostview'KGhostview::updateOrientationDisplay() (./kdegraphics/kghostview/kghostview.cpp:2372)

KGhostview::updateOrientationDisplay()
{
  int vtorient=0;

  switch(orientation)
    {
    case Portrait:
      statusbar->changeItem( i18n("Portrait"), ID_ORIENTATION );
      vtorient=CombPortrait;
      break;
    case Landscape:
      statusbar->changeItem( i18n("Landscape"), ID_ORIENTATION );
      vtorient=CombLandscape;
      break;
    case UpsideDown:
      statusbar->changeItem( i18n("Upside down"), ID_ORIENTATION );
      vtorient=CombUpsideDown;
      break;
    case Seascape:
      statusbar->changeItem( i18n("Seascape"), ID_ORIENTATION );
      vtorient=CombSeascape;
      break;
    }

  if (viewtoolbar != 0)
    viewtoolbar->setCurrentComboItem (ID_VT_ORIENT, vtorient);
}

void

kghostview'KGhostview::updateMagstepDisplay() (./kdegraphics/kghostview/kghostview.cpp:2401)

KGhostview::updateMagstepDisplay()
{
  QString qs;

  qs.sprintf("%d%%", (int)(100*page->xdpi/default_xdpi));
  statusbar->changeItem( qs, ID_MAGSTEP );

  if (viewtoolbar != 0)
    viewtoolbar->setCurrentComboItem (ID_VT_MAG, magstep-1);

}


kghostview'KGhostview::changeFileRecord() (./kdegraphics/kghostview/kghostview.cpp:2413)

void KGhostview::changeFileRecord()
{
	QString s;
	
	int i = 1;
	
	QStrListIterator it( lastOpened );
	
	for( ; it.current(); ++it ) {
		s.sprintf("&%d. ", i);
		s += it.current();
		m_recent->changeItem(s, i-1);

		i++;
	}
}


kghostview'KGhostview::openRecent() (./kdegraphics/kghostview/kghostview.cpp:2430)

void KGhostview::openRecent( int id )
{
	KURL u( lastOpened.at( id ) );
	
	if ( !u.isLocalFile() )
		openNetFile( u );
	else {
		isNetFile = false;
		openFile( u.path() );
	}
}


kghostview'KGhostview::new_file() (./kdegraphics/kghostview/kghostview.cpp:2442)

void KGhostview::new_file( int number )
{
    //printf("KGhostview::new_file\n");
	
  bool ADD_THIS = true;	
  QStrListIterator it( lastOpened );
  
  QString s;
  
  if ( isNetFile ) {
    KURL u( netFile );
    if ( strcmp( u.protocol(), "file" ) == 0 )
      s = u.path();
    else s = netFile;
  } else s = filename;
  
  for( ; it.current(); ++it ) {
    if( s == it.current() ) {
      ADD_THIS = false;
    }
  }
  
  if( ADD_THIS) {
    lastOpened.removeLast();
    lastOpened.insert( 0, s );
    changeFileRecord();
    writeFileSettings();
  }
  
  bool layout_changed = false;
  
  //page->disableInterpreter();
  if (setup()) 
    layout_changed = true;
  
  // Coerce page number to fall in range
  if (toc_text) {
    if ((unsigned int)number >= doc->numpages) number = doc->numpages - 1;
    if (number < 0) number = 0;
  }
  
  if (set_new_orientation(number))
    layout_changed = true;
  if (set_new_pagemedia(number))
    layout_changed = true;
  if (layout_changed) {
    //printf("Layout should change -- call KPS method\n");
    page->layout();
    shrinkWrap();
  }

}


kghostview'KGhostview::show_page() (./kdegraphics/kghostview/kghostview.cpp:2495)

void KGhostview::show_page(int number)
{
//    printf("KGhostview::show_page\n");

    struct stat sbuf;
    bool new_orient = false, new_media = false;

    if ( ! filename ) {
    	//printf("No file !\n");
    	return;
    }

    if (psfile) {
    	//printf("Oh does it go into psfile ?\n");
    	if (!stat(filename, &sbuf) && mtime != sbuf.st_mtime) {
			fclose(psfile);
			psfile = fopen(filename, "r");
			mtime = sbuf.st_mtime;
			oldfilename = filename;
			new_file(number);
		}
    }
    
    // Coerce page number to fall in range - Duh, what does that mean ?
    if (toc_text) {
		if ((unsigned int)number >= doc->numpages) number = doc->numpages - 1;
		if (number < 0) number = 0;
    }
    
    //printf("Hmm shouldn't this whole thing be inside the if(psfile) ?\n");
    
    new_orient=set_new_orientation(number);
    new_media=set_new_pagemedia(number);
    
    //printf("new_orient %d, new_media %d\n", new_orient, new_media);
    
    if (new_orient || new_media)
      {
	page->layout();
      };
    
    if (toc_text) {
		current_page = number;
		if ( page->isInterpreterReady() ) {
			//printf("Interpreter ready - Fire off next page\n");
			page->nextPage();
			
		} else {
			//printf("Start interpreter and send preamble\n");
			page->enableInterpreter();
			page->sendPS(psfile, doc->beginprolog,
				doc->lenprolog, false);
			page->sendPS(psfile, doc->beginsetup,
				doc->lensetup, false);
				
		}
		//printf("Send page %d\n", current_page);
		page->sendPS(psfile, doc->pages[current_page].begin,
			doc->pages[current_page].len, false);

  } else {
	if ( !page->isInterpreterRunning() ) {
		//printf("This is not a structured document -- start int.\n");
	    page->enableInterpreter();
	    
	} else if ( page->isInterpreterReady() ) {
	    page->nextPage();
	    
	} else XBell(page->x11Display(), 0);
	    
  }
  
  //
  // Well that takes care of sending the postscript.
  // Now update the page label on the status line
  //
  
  if(toc_text) {
		if(num_parts==0) {
			part_string = i18n("Sc.1 ");
			sprintf(part_total_label, i18n("of 1    "));
			if(number==-1)
				page_string = i18n("P.1 ");
			else
				page_string = i18n("P.%1 ").arg(number+1);
		} else {
			int cumulative_pages=0;
			int k, part;


			for(k=0;k<10;k++) {
  				cumulative_pages+=pages_in_part[k];
  				if(cumulative_pages>number) break;
			}
			cumulative_pages-=pages_in_part[k];
			part=k-1;

			page_string = i18n("P.%1 ").arg(number+1-cumulative_pages);

			part_string = i18n("Sc.%1 ").arg(part+2);

			part=k;
			if(pages_in_part[part]==0) {
				sprintf(page_total_label, i18n("of 1    "));
			} else if(pages_in_part[part]>0 && pages_in_part[part]<10) {
				sprintf(page_total_label, i18n("of %d    "), pages_in_part[part]);
			} else if (pages_in_part[part]<100) {
				sprintf(page_total_label, i18n("of %d  "), pages_in_part[part]);
			} else if (doc) {
				sprintf(page_total_label, i18n("of %d"), pages_in_part[part]);
			} else {
				sprintf(page_total_label, "         ");
			}

			sprintf(part_total_label, i18n("of %d  "), num_parts+1);
		}

		part_label_text=operator+(part_string, part_total_label);
		page_label_text=operator+(page_string, page_total_label);
		position_label=operator+(part_label_text, page_label_text);
		statusbar->changeItem( position_label.data(), ID_LOCATION );

		if (current_page-1< 0) {
			toolbar->setItemEnabled(ID_PREV, false);
			m_go->setItemEnabled(prevID, false);
		} else {
			toolbar->setItemEnabled(ID_PREV, true);
			m_go->setItemEnabled(prevID, true);
		}
		if ((unsigned int)current_page+1 >= doc->numpages) {
			toolbar->setItemEnabled(ID_NEXT, false);
			m_go->setItemEnabled(nextID, false);
		} else {
			toolbar->setItemEnabled(ID_NEXT, true);
			m_go->setItemEnabled(nextID, true);
		}
	}
	else {
		statusbar->changeItem( "", ID_LOCATION );
	}
}


kghostview'KGhostview::set_magstep() (./kdegraphics/kghostview/kghostview.cpp:2637)

void KGhostview::set_magstep(unsigned int new_magstep)
{
  magstep = new_magstep;
  if (set_new_magstep())
    {
      page->layout();
      page->resize(page->width(), page->height());
      page->repaint();
      show_page(current_page);
      shrinkWrap();
      updateMagstepDisplay();
    }
}

bool

kghostview'KGhostview::set_new_magstep() (./kdegraphics/kghostview/kghostview.cpp:2652)

KGhostview::set_new_magstep()
{
  unsigned int new_magstep;
  bool changed = false;
  float xdpi, ydpi;
  
  new_magstep = magstep;
  
  if (new_magstep != current_magstep)
    {
      //printf("	new_magstep != current_magstep\n");
      page->disableInterpreter();
      changed = true;
      xdpi = default_xdpi;
      ydpi = default_ydpi;
      magnify(&xdpi, new_magstep);
      magnify(&ydpi, new_magstep);
      page->xdpi=xdpi;
      page->ydpi=ydpi;
      current_magstep = new_magstep;
    }
 
  return changed;
}

void

kghostview'KGhostview::magnify() (./kdegraphics/kghostview/kghostview.cpp:2678)

KGhostview::magnify(float *dpi, unsigned int magstep)
{
  if (magstep < shrink_magsteps)
    {
      *dpi = (int)((* dpi)*magstep/(shrink_magsteps));
    }
  else
    {
      *dpi = (int)((* dpi)+2*(* dpi)*(magstep-shrink_magsteps)/(expand_magsteps));
    }
}



//// View control is now a toolbar



void

kghostview'KGhostview::createViewToolBar() (./kdegraphics/kghostview/kghostview.cpp:2697)

KGhostview::createViewToolBar()
{
  // Create the toolbar
  
  QPixmap pixmap;
  viewtoolbar = toolBar(1);
  
  QStrList strlist;
  unsigned int i;
  QString qs;


  for (i = 1; i <= shrink_magsteps; i++)
    {      
      qs.setNum ( (int)(100*i/(shrink_magsteps)) );
      qs += "%";
      strlist.append( (const char *) qs);
    }
	
  for (i = 1; i <= expand_magsteps; i++)
    { 
      qs.setNum ( (int)(100+200*i/(expand_magsteps)) );
      qs += "%";
      strlist.append( (const char *) qs);
    }
  
  viewtoolbar->insertCombo (&strlist, ID_VT_MAG, false, 
			    SIGNAL (activated (int)), this, 
			    SLOT (viewToolBarZoom (int)), true,
			    "Change Zoom");

  // Orientation

  strlist.clear();
  strlist.append(i18n("Portrait"));
  strlist.append(i18n("Landscape"));
  strlist.append(i18n("Upside Down"));
  strlist.append(i18n("Seascape"));

  viewtoolbar->insertCombo (&strlist, ID_VT_ORIENT, false, 
			    SIGNAL (activated (int)), this, 
			    SLOT (viewToolBarOrient (int)), true,
			    "Change Paper Orientation");


  // Media
  strlist.clear();
  // if you've got an eps file need bounding box in menu too

  if(doc && doc->epsf)
    strlist.append ("EPS Bounding Box");
  
  if (doc && doc->nummedia)
    for (i = 0; i < doc->nummedia; i++)
      strlist.append (doc->media[i].name);

  for (i = 0; papersizes[i].name; i++)
    {
      if (i > 0)
	{
	  // Skip over same paper size with small imageable area
	  if ((papersizes[i].width == papersizes[i-1].width) &&
	      (papersizes[i].height == papersizes[i-1].height))
	    continue;
	}
      strlist.append (papersizes[i].name);
    }

  viewtoolbar->insertCombo (&strlist, ID_VT_MEDIA, false, 
			    SIGNAL (activated (int)), this, 
			    SLOT (viewToolBarMedia (int)), true,
			    "Change Paper Type");


  viewtoolbar->setItemEnabled (ID_VT_MAG, false);
  viewtoolbar->setItemEnabled (ID_VT_ORIENT, false);
  viewtoolbar->setItemEnabled (ID_VT_MEDIA, false);


  QWhatsThis::
    add( viewtoolbar->
	 getWidget (ID_VT_MAG),
	 i18n ("Zoom in or out on the page."));
  QWhatsThis::
    add( viewtoolbar->
	 getWidget (ID_VT_ORIENT), 
	 i18n ("Change the orientation of the document."));
  QWhatsThis::
    add( viewtoolbar->
	 getWidget (ID_VT_MEDIA),
	 i18n ("Set the type of paper on which "
	       "this document will be printed."));
					   


}

void

kghostview'KGhostview::viewToolBarZoom() (./kdegraphics/kghostview/kghostview.cpp:2795)

KGhostview::viewToolBarZoom (int i)
{
  //  QComboBox *magcombo = viewtoolbar->getCombo (ID_VT_MAG);
  //  printf ("zoom = (%s)\n", magcombo->text(i).ascii());

  set_magstep((unsigned int) i+1);
}

void

kghostview'KGhostview::viewToolBarOrient() (./kdegraphics/kghostview/kghostview.cpp:2804)

KGhostview::viewToolBarOrient (int i)
{
  Orientation o=Portrait;

  printf ("i=  %d\n",i);
  switch(i)
    {
    case CombPortrait:
      o=Portrait;
      break;
    case CombLandscape:
      o=Landscape;
      break;
    case CombUpsideDown:
      o=UpsideDown;
      break;
    case CombSeascape:
      o=Seascape;
      break;
    }
  printf ("o=%d\n",o);

  setOrientation(o);

}

void

kghostview'KGhostview::viewToolBarMedia() (./kdegraphics/kghostview/kghostview.cpp:2831)

KGhostview::viewToolBarMedia (int i)
{
  i++;

  if(doc->epsf && i==1) {
    force_pagemedia = false;
    force_document_media = false;
  } else if (i >= base_papersize) {
    default_pagemedia = i;
    force_pagemedia = true;
  } else {
    document_media = i;
    force_document_media = true;
  }
  
  if (set_new_pagemedia(current_page))
    {
      page->layout();
      show_page(current_page);
      shrinkWrap();
    }
}