[Kst] branches/work/kst/portto4/kst/src
Mike Fenton
mike at staikos.net
Thu May 8 16:07:05 CEST 2008
SVN commit 805409 by fenton:
Add File System watching for DataSource updates.
M +1 -2 datasources/ascii/ascii.cpp
M +16 -4 libkst/datasource.cpp
M +5 -1 libkst/datasource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.cpp #805408:805409
@@ -33,7 +33,6 @@
#include <qtextdocument.h>
#include <QXmlStreamWriter>
#include <QXmlStreamAttributes>
-#include <QFileSystemWatcher>
#include <math_kst.h>
#include "ascii.h"
@@ -171,7 +170,7 @@
AsciiSource::AsciiSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e)
-: Kst::DataSource(store, cfg, filename, type), _rowIndex(0L), _config(0L), _tmpBuf(0L), _tmpBufSize(0) {
+: Kst::DataSource(store, cfg, filename, type, File), _rowIndex(0L), _config(0L), _tmpBuf(0L), _tmpBufSize(0) {
_valid = false;
_haveHeader = false;
_fieldListComplete = false;
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #805408:805409
@@ -30,6 +30,7 @@
#include <QUrl>
#include <QXmlStreamWriter>
#include <QTimer>
+#include <QFileSystemWatcher>
#include "kst_i18n.h"
#include "datacollection.h"
@@ -42,6 +43,8 @@
#include "dataplugin.h"
+#define DATASOURCE_UPDATE_TIMER_LENGTH 1000
+
namespace Kst {
const QString DataSource::staticTypeString = I18N_NOOP("Data Source");
@@ -474,8 +477,8 @@
}
-DataSource::DataSource(ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type)
- : Object(), _filename(filename), _cfg(cfg) {
+DataSource::DataSource(ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const UpdateCheckType updateType)
+ : Object(), _filename(filename), _cfg(cfg), _updateCheckType(updateType) {
Q_UNUSED(type)
_valid = false;
_reusable = true;
@@ -499,7 +502,14 @@
_numFramesScalar = store->createObject<Scalar>(ObjectTag("frames", tag()));
// Don't set provider - this is always up-to-date
- QTimer::singleShot(1000, this, SLOT(checkUpdate()));
+ if (_updateCheckType == Timer) {
+ QTimer::singleShot(DATASOURCE_UPDATE_TIMER_LENGTH, this, SLOT(checkUpdate()));
+ } else {
+ QFileSystemWatcher *watcher = new QFileSystemWatcher();
+ watcher->addPath(_filename);
+ connect(watcher, SIGNAL(fileChanged ( const QString & )), this, SLOT(checkUpdate()));
+ connect(watcher, SIGNAL(directoryChanged ( const QString & )), this, SLOT(checkUpdate()));
+ }
}
@@ -516,7 +526,9 @@
UpdateManager::self()->requestUpdate(this);
}
- QTimer::singleShot(1000, this, SLOT(checkUpdate()));
+ if (_updateCheckType == Timer) {
+ QTimer::singleShot(DATASOURCE_UPDATE_TIMER_LENGTH, this, SLOT(checkUpdate()));
+ }
}
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #805408:805409
@@ -61,6 +61,8 @@
Q_OBJECT
public:
+ enum UpdateCheckType { Timer, File };
+
static void setupOnStartup(QSettings*);
static void cleanupForExit();
@@ -81,7 +83,7 @@
static bool supportsTime(const QString& plugin, const QString& type = QString::null);
- DataSource(ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type);
+ DataSource(ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const UpdateCheckType updateType = File);
virtual ~DataSource();
virtual const QString& typeString() const;
@@ -265,6 +267,8 @@
ScalarPtr _numFramesScalar;
+ UpdateCheckType _updateCheckType;
+
virtual QString _automaticDescriptiveName();
// NOTE: You must bump the version key if you add new member variables
More information about the Kst
mailing list