Commit a461a21b authored by Albert Astals Cid's avatar Albert Astals Cid

Add watch file option.

Enrico, i've added it in the menu, do you prefer it to be in the configuration dialog?
CCMAIL: rosenric@dei.unipd.it

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=367732
parent e7b59fbb
...@@ -52,6 +52,7 @@ More items (first items will enter 'In progress list' first): ...@@ -52,6 +52,7 @@ More items (first items will enter 'In progress list' first):
-> fullscreen pdf view (presentations-like) with some gfx tools -> fullscreen pdf view (presentations-like) with some gfx tools
Done (newest feature comes firts): Done (newest feature comes firts):
-> ADD: Watch File option (Albert)
-> ADD: import Marco Martin's "another kpdf icon" (kde-look: 16146) (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) -> 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 -> FIX: merge select text & select gfx, two sections on the same pop-up menu
......
...@@ -56,6 +56,9 @@ ...@@ -56,6 +56,9 @@
<entry key="HideOSD" type="Bool" > <entry key="HideOSD" type="Bool" >
<default>false</default> <default>false</default>
</entry> </entry>
<entry key="WatchFile" type="Bool" >
<default>true</default>
</entry>
</group> </group>
<group name="MainView" > <group name="MainView" >
<entry key="SplitterSizes" type="IntList" /> <entry key="SplitterSizes" type="IntList" />
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <dcopobject.h> #include <dcopobject.h>
#include <kaction.h> #include <kaction.h>
#include <kdirwatch.h>
#include <kinstance.h> #include <kinstance.h>
#include <kprinter.h> #include <kprinter.h>
#include <kstdaction.h> #include <kstdaction.h>
...@@ -96,6 +97,8 @@ Part::Part(QWidget *parentWidget, const char *widgetName, ...@@ -96,6 +97,8 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_splitter = new QSplitter( parentWidget, widgetName ); m_splitter = new QSplitter( parentWidget, widgetName );
m_splitter->setOpaqueResize( true ); m_splitter->setOpaqueResize( true );
setWidget( m_splitter ); 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] | [] // widgets: [left toolbox] | []
m_toolBox = new QToolBox( m_splitter ); m_toolBox = new QToolBox( m_splitter );
...@@ -173,9 +176,15 @@ Part::Part(QWidget *parentWidget, const char *widgetName, ...@@ -173,9 +176,15 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_splitter->setSizes( Settings::splitterSizes() ); m_splitter->setSizes( Settings::splitterSizes() );
slotNewConfig(); 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 // set our XML-UI resource file
setXMLFile("kpdf_part.rc"); setXMLFile("kpdf_part.rc");
updateActions(); updateActions();
slotWatchFile();
} }
Part::~Part() Part::~Part()
...@@ -226,6 +235,7 @@ KAboutData* Part::createAboutData() ...@@ -226,6 +235,7 @@ KAboutData* Part::createAboutData()
bool Part::openFile() bool Part::openFile()
{ {
bool ok = m_document->openDocument( m_file ); bool ok = m_document->openDocument( m_file );
if ( ok && !m_watcher->contains(m_file)) m_watcher->addFile(m_file);
m_find->setEnabled( ok ); m_find->setEnabled( ok );
return ok; return ok;
} }
...@@ -243,8 +253,47 @@ bool Part::openURL(const KURL &url) ...@@ -243,8 +253,47 @@ bool Part::openURL(const KURL &url)
return b; 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() bool Part::closeURL()
{ {
if (!m_file.isEmpty()) m_watcher->removeFile(m_file);
m_document->closeDocument(); m_document->closeDocument();
return KParts::ReadOnlyPart::closeURL(); return KParts::ReadOnlyPart::closeURL();
} }
......
...@@ -29,6 +29,7 @@ class QToolBox; ...@@ -29,6 +29,7 @@ class QToolBox;
class KURL; class KURL;
class KAction; class KAction;
class KConfig; class KConfig;
class KDirWatch;
class KToggleAction; class KToggleAction;
class KSelectAction; class KSelectAction;
class KAboutData; class KAboutData;
...@@ -103,6 +104,9 @@ public slots: ...@@ -103,6 +104,9 @@ public slots:
void slotPrint(); void slotPrint();
void restoreDocument(const KURL &url, int page); void restoreDocument(const KURL &url, int page);
void saveDocumentRestoreInfo(KConfig* config); void saveDocumentRestoreInfo(KConfig* config);
void slotWatchFile();
void slotFileDirty( const QString& );
void slotDoFileDirty();
private: private:
void doPrint( KPrinter& printer ); void doPrint( KPrinter& printer );
...@@ -120,6 +124,9 @@ private: ...@@ -120,6 +124,9 @@ private:
// static instances counter // static instances counter
static unsigned int m_count; static unsigned int m_count;
KDirWatch *m_watcher;
QTimer *m_dirtyHandler;
// actions // actions
KAction *m_gotoPage; KAction *m_gotoPage;
KAction *m_prevPage; KAction *m_prevPage;
...@@ -128,6 +135,7 @@ private: ...@@ -128,6 +135,7 @@ private:
KAction *m_lastPage; KAction *m_lastPage;
KAction *m_find; KAction *m_find;
KAction *m_findNext; KAction *m_findNext;
KToggleAction* m_watchFile;
}; };
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
<Action name="goto_page"/> <Action name="goto_page"/>
</Menu> </Menu>
<Menu name="settings"><text>&amp;Settings</text> <Menu name="settings"><text>&amp;Settings</text>
<Action name="watch_file" group="show_merge"/>
<Action name="preferences"/> <Action name="preferences"/>
</Menu> </Menu>
</MenuBar> </MenuBar>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment