[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdegraphics/kpdf/kpdf
From: Albert Astals Cid <tsdgeos () terra ! es>
Date: 2004-11-30 23:27:02
Message-ID: 20041130232702.D4A7B1B303 () office ! kde ! org
[Download RAW message or body]
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 <kapplication.h>
#include <kdebug.h>
+#include <kdirwatch.h>
#include <kinstance.h>
#include <kprinter.h>
@@ -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 @@
<Menu name="settings"><text>&Settings</text>
<Action name="show_scrollbars" group="show_merge"/>
+ <Action name="watch_file" group="show_merge"/>
<Action name="show_toc" group="show_merge"/>
<Action name="show_page_list" group="show_merge"/>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic