------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is. http://bugs.kde.org/show_bug.cgi?id=94016 tsdgeos terra es changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |FIXED ------- Additional Comments From tsdgeos terra es 2004-12-01 00:27 ------- CVS commit by aacid: Watch files as kghostview does (use the very same code :-D) Will be available in KDE 3.4 FEATURE: 94016 M +51 -1 kpdf_part.cpp 1.93 M +10 -4 kpdf_part.h 1.42 M +1 -0 kpdf_part.rc 1.21 --- kdegraphics/kpdf/kpdf/kpdf_part.cpp #1.92:1.93 @ -33,4 +33,5 @ #include #include +#include #include #include @ -100,4 +101,5 @ Part::Part(QWidget *parentWidget, const setWidget(pdfpartview); + m_watchFile = new KToggleAction( i18n( "&Watch File" ), 0, this, SLOT( slotWatchFile() ), actionCollection(), "watch_file" ); m_showScrollBars = new KToggleAction( i18n( "Show &Scrollbars" ), 0, @ -186,4 +188,10 @ Part::Part(QWidget *parentWidget, const m_zoomTo->setCurrentItem( idx ); + m_watcher = new KDirWatch( this ); + connect( m_watcher, SIGNAL( dirty( const QString& ) ), this, SLOT( slotFileDirty( const QString& ) ) ); + m_dirtyHandler = new QTimer( this ); + connect( m_dirtyHandler, SIGNAL( timeout() ),this, SLOT( slotDoFileDirty() ) ); + + // set our XML-UI resource file @ -304,4 +312,5 @ void Part::writeSettings() general.writeEntry( "ShowTOC", m_showTOC->isChecked() ); general.writeEntry( "ShowPageList", m_showPageList->isChecked() ); + general.writeEntry( "WatchFile", m_watchFile->isChecked() ); general.sync(); } @ -316,4 +325,6 @ void Part::readSettings() m_showPageList->setChecked( general.readBoolEntry( "ShowPageList", true ) ); showMarkList( m_showPageList->isChecked() ); + m_watchFile->setChecked( general.readBoolEntry( "WatchFile", true ) ); + slotWatchFile(); } @ -392,7 +403,46 @ Part::createAboutData() } + void +Part::slotWatchFile() +{ + if( m_watchFile->isChecked() ) + m_watcher->startScan(); + else + { + m_dirtyHandler->stop(); + m_watcher->stopScan(); + } +} + + void +Part::slotFileDirty( const QString& fileName ) +{ + // The beauty of this is that each start cancels the previous one. + // This means that timeout() is only fired when there have + // no changes to the file for the last 750 milisecs. + // This is supposed to ensure that we don't update on every other byte + // that gets written to the file. + if ( fileName == m_file ) + { + m_dirtyHandler->start( 750, true ); + } +} + + void +Part::slotDoFileDirty() +{ + int p = m_currentPage; + if (openFile()) + { + if (p > m_doc->getNumPages()) p = m_doc->getNumPages(); + goToPage(p); + } +} + + bool Part::closeURL() { + if (!m_file.isEmpty()) m_watcher->removeFile(m_file); pdfpartview->stopThumbnailGeneration(); delete m_doc; @ -461,6 +511,6 @ Part::openFile() m_outputDev->setPDFDocument(m_doc); goToPage(1); - } + if (!m_watcher->contains(m_file)) m_watcher->addFile(m_file); return true; --- kdegraphics/kpdf/kpdf/kpdf_part.h #1.41:1.42 @ -27,4 +27,5 @ class KAboutData; class KAction; class KConfig; +class KDirWatch; class KURL; class KToggleAction; @ -141,4 +142,5 @ namespace KPDF KAction* m_nextPage; KAction *m_gotoPage; + KToggleAction* m_watchFile; KToggleAction* m_showScrollBars; KToggleAction* m_showPageList; @ -148,5 +150,6 @ namespace KPDF KAction *m_find; KAction *m_findNext; - + KDirWatch *m_watcher; + QTimer *m_dirtyHandler; QString m_findText; @ -165,4 +168,7 @ namespace KPDF void pageClicked ( int ); void fileSaveAs(); + void slotWatchFile(); + void slotFileDirty( const QString& ); + void slotDoFileDirty(); }; --- kdegraphics/kpdf/kpdf/kpdf_part.rc #1.20:1.21 @ -28,4 +28,5 @ &Settings +