diff --git a/kpdf/TODO b/kpdf/TODO
index 82992f10f9673b1f3dba057f574f3d561bc54496..2ef06b9b52f3b55dab19fb2aba7dae50da09d993 100644
--- a/kpdf/TODO
+++ b/kpdf/TODO
@@ -52,6 +52,7 @@ More items (first items will enter 'In progress list' first):
-> fullscreen pdf view (presentations-like) with some gfx tools
Done (newest feature comes firts):
+-> ADD: Watch File option (Albert)
-> ADD: import Marco Martin's "another kpdf icon" (kde-look: 16146) (Albert)
-> ADD: dynamic zoom with mid mouse button (click and drag up-down to zoom in-out)
-> FIX: merge select text & select gfx, two sections on the same pop-up menu
diff --git a/kpdf/conf/kpdf.kcfg b/kpdf/conf/kpdf.kcfg
index cf2f6318fb5897de33750643b9146aef6213e374..9d44c3b2168b810834a2b04af10aba504b358fb9 100644
--- a/kpdf/conf/kpdf.kcfg
+++ b/kpdf/conf/kpdf.kcfg
@@ -56,6 +56,9 @@
false
+
+ true
+
diff --git a/kpdf/kpdf_part.cpp b/kpdf/kpdf_part.cpp
index b994ee1732c186fe330d571b0f57a3a485399e02..0aa44d5192bcae91601cc8c0564688387a759d68 100644
--- a/kpdf/kpdf_part.cpp
+++ b/kpdf/kpdf_part.cpp
@@ -31,6 +31,7 @@
#include
#include
+#include
#include
#include
#include
@@ -96,6 +97,8 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_splitter = new QSplitter( parentWidget, widgetName );
m_splitter->setOpaqueResize( true );
setWidget( m_splitter );
+ m_watchFile = new KToggleAction( i18n( "&Watch File" ), 0, this, SLOT( slotWatchFile() ), actionCollection(), "watch_file" );
+ m_watchFile->setChecked( Settings::watchFile() );
// widgets: [left toolbox] | []
m_toolBox = new QToolBox( m_splitter );
@@ -173,9 +176,15 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_splitter->setSizes( Settings::splitterSizes() );
slotNewConfig();
+ 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
setXMLFile("kpdf_part.rc");
updateActions();
+ slotWatchFile();
}
Part::~Part()
@@ -226,6 +235,7 @@ KAboutData* Part::createAboutData()
bool Part::openFile()
{
bool ok = m_document->openDocument( m_file );
+ if ( ok && !m_watcher->contains(m_file)) m_watcher->addFile(m_file);
m_find->setEnabled( ok );
return ok;
}
@@ -243,8 +253,47 @@ bool Part::openURL(const KURL &url)
return b;
}
+void
+Part::slotWatchFile()
+{
+ Settings::setWatchFile(m_watchFile->isChecked());
+ 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()
+{
+ uint p = m_document->currentPage() + 1;
+ if (openFile())
+ {
+ if (p > m_document->pages()) p = m_document->pages();
+ goToPage(p);
+ }
+}
+
bool Part::closeURL()
{
+ if (!m_file.isEmpty()) m_watcher->removeFile(m_file);
m_document->closeDocument();
return KParts::ReadOnlyPart::closeURL();
}
diff --git a/kpdf/kpdf_part.h b/kpdf/kpdf_part.h
index 67fa1511bcc79cb7153d6f1c3d2ed596f43cc48c..950b637468f0a4d828c8a43e0e5479f26800b7e1 100644
--- a/kpdf/kpdf_part.h
+++ b/kpdf/kpdf_part.h
@@ -29,6 +29,7 @@ class QToolBox;
class KURL;
class KAction;
class KConfig;
+class KDirWatch;
class KToggleAction;
class KSelectAction;
class KAboutData;
@@ -101,8 +102,11 @@ protected slots:
public slots:
// connected to Shell action (and browserExtension), not local one
void slotPrint();
- void restoreDocument(const KURL &url, int page);
- void saveDocumentRestoreInfo(KConfig* config);
+ void restoreDocument(const KURL &url, int page);
+ void saveDocumentRestoreInfo(KConfig* config);
+ void slotWatchFile();
+ void slotFileDirty( const QString& );
+ void slotDoFileDirty();
private:
void doPrint( KPrinter& printer );
@@ -119,6 +123,9 @@ private:
// static instances counter
static unsigned int m_count;
+
+ KDirWatch *m_watcher;
+ QTimer *m_dirtyHandler;
// actions
KAction *m_gotoPage;
@@ -128,6 +135,7 @@ private:
KAction *m_lastPage;
KAction *m_find;
KAction *m_findNext;
+ KToggleAction* m_watchFile;
};
diff --git a/kpdf/kpdf_part.rc b/kpdf/kpdf_part.rc
index 4721dc4be377105c9f78bdfdf7fc71a58bcee919..a2b6b7c0c9a8c4d8fab5b40f9bf4d4f953855a63 100644
--- a/kpdf/kpdf_part.rc
+++ b/kpdf/kpdf_part.rc
@@ -30,6 +30,7 @@