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):
-> 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
......
......@@ -56,6 +56,9 @@
<entry key="HideOSD" type="Bool" >
<default>false</default>
</entry>
<entry key="WatchFile" type="Bool" >
<default>true</default>
</entry>
</group>
<group name="MainView" >
<entry key="SplitterSizes" type="IntList" />
......
......@@ -31,6 +31,7 @@
#include <dcopobject.h>
#include <kaction.h>
#include <kdirwatch.h>
#include <kinstance.h>
#include <kprinter.h>
#include <kstdaction.h>
......@@ -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();
}
......
......@@ -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;
};
......
......@@ -30,6 +30,7 @@
<Action name="goto_page"/>
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="watch_file" group="show_merge"/>
<Action name="preferences"/>
</Menu>
</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