use timer to check filesystem; refs #155
This commit is contained in:
@@ -60,7 +60,7 @@ class FileStorage: public Storage {
|
|||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
public:
|
public:
|
||||||
/*! @param file full path to storage file */
|
/*! @param file full path to storage file */
|
||||||
FileStorage(QString file, int msec=1000): _file(file), _fileInfo(_file) {
|
FileStorage(QString file, int msec=1000): _file(file) {
|
||||||
TRC; LOG<<"file: "<<file;
|
TRC; LOG<<"file: "<<file;
|
||||||
assert(connect(&_timer, SIGNAL(timeout()), SLOT(check())));
|
assert(connect(&_timer, SIGNAL(timeout()), SLOT(check())));
|
||||||
_timer.setInterval(msec);
|
_timer.setInterval(msec);
|
||||||
@@ -70,12 +70,12 @@ class FileStorage: public Storage {
|
|||||||
return _file.fileName();
|
return _file.fileName();
|
||||||
}
|
}
|
||||||
bool readable() {
|
bool readable() {
|
||||||
return _fileInfo.exists();
|
return QFileInfo(_file).exists();
|
||||||
}
|
}
|
||||||
bool writeable() {
|
bool writeable() {
|
||||||
return readable() ||
|
return readable() ||
|
||||||
(!_file.fileName().isEmpty() &&
|
(!_file.fileName().isEmpty() &&
|
||||||
_fileInfo.absoluteDir().exists());
|
QFileInfo(_file).absoluteDir().exists());
|
||||||
}
|
}
|
||||||
QStringList read() {
|
QStringList read() {
|
||||||
TRC;
|
TRC;
|
||||||
@@ -99,16 +99,15 @@ class FileStorage: public Storage {
|
|||||||
}
|
}
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void check() {
|
void check() {
|
||||||
TRC;
|
if (_modified!=QFileInfo(_file).lastModified()) {
|
||||||
if (_modified!=_fileInfo.lastModified()) {
|
TRC;
|
||||||
LOG<<"file has been modified";
|
_modified = QFileInfo(_file).lastModified();
|
||||||
_modified = _fileInfo.lastModified();
|
LOG<<"file has been modified"<<_modified.toString();
|
||||||
emitChanged();
|
emitChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
QFile _file;
|
QFile _file;
|
||||||
QFileInfo _fileInfo;
|
|
||||||
QDateTime _modified;
|
QDateTime _modified;
|
||||||
QTimer _timer;
|
QTimer _timer;
|
||||||
};
|
};
|
||||||
|
@@ -8,9 +8,10 @@
|
|||||||
#ifndef QBROWSERLIB_LOG
|
#ifndef QBROWSERLIB_LOG
|
||||||
#define QBROWSERLIB_LOG
|
#define QBROWSERLIB_LOG
|
||||||
|
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
#include <qbrowserlib/ui_log.h>
|
#include <qbrowserlib/ui_log.h>
|
||||||
|
|
||||||
#include <QtGui/QDialog>
|
#include <QtGui/QDialog>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -82,15 +83,23 @@ namespace qbrowserlib {
|
|||||||
unsigned long _line;
|
unsigned long _line;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LogDialog: public QDialog, public Ui::LogDialog {
|
class LogDialog:
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
|
public QDialog, public Ui::LogDialog
|
||||||
|
#else
|
||||||
|
public QObject
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LogDialog(QWidget* p): QDialog(p) {
|
#ifdef QT_GUI_LIB
|
||||||
|
LogDialog(QWidget* p=0): QDialog(p) {
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename TYPE> LogDialog& append(const Log& log, TYPE* arg) {
|
template<typename TYPE> LogDialog& append(const Log& log, TYPE* arg) {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
@@ -99,6 +108,7 @@ namespace qbrowserlib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TYPE> LogDialog& append(const Log& log, TYPE arg) {
|
template<typename TYPE> LogDialog& append(const Log& log, TYPE arg) {
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
int pos(_logs->rowCount());
|
int pos(_logs->rowCount());
|
||||||
_logs->insertRow(pos);
|
_logs->insertRow(pos);
|
||||||
_logs->setItem
|
_logs->setItem
|
||||||
@@ -116,11 +126,13 @@ namespace qbrowserlib {
|
|||||||
_logs->setItem
|
_logs->setItem
|
||||||
(pos, MESSAGE,
|
(pos, MESSAGE,
|
||||||
new QTableWidgetItem(QVariant(arg).toString()));
|
new QTableWidgetItem(QVariant(arg).toString()));
|
||||||
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
|
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
void on__fileLine_toggled(bool checked) {
|
void on__fileLine_toggled(bool checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
_logs->showColumn(FILE);
|
_logs->showColumn(FILE);
|
||||||
@@ -166,6 +178,7 @@ namespace qbrowserlib {
|
|||||||
if (!items.isEmpty()) _logs->scrollToItem(items[0]);
|
if (!items.isEmpty()) _logs->scrollToItem(items[0]);
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -181,7 +194,7 @@ namespace qbrowserlib {
|
|||||||
init(ss);
|
init(ss);
|
||||||
indent(ss)<<" → "<<arg;
|
indent(ss)<<" → "<<arg;
|
||||||
std::clog<<close(ss).str()<<std::endl;
|
std::clog<<close(ss).str()<<std::endl;
|
||||||
if (!_dialog) _dialog = new LogDialog(0);
|
if (!_dialog) _dialog = new LogDialog;
|
||||||
_dialog->append(*this, arg);
|
_dialog->append(*this, arg);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
qbrowserlib::Log::DEBUG = true;
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
TestFileWatch test("testfile");
|
TestFileWatch test("testfile");
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@@ -3,6 +3,9 @@ QMAKE_LIBDIR += @top_builddir@/src/qbrowserlib
|
|||||||
QMAKE_LIBDIR += @top_builddir@/src/qbrowserlib/release
|
QMAKE_LIBDIR += @top_builddir@/src/qbrowserlib/release
|
||||||
QMAKE_LIBS += -lqbrowserlib
|
QMAKE_LIBS += -lqbrowserlib
|
||||||
|
|
||||||
|
QT = core
|
||||||
|
CONFIG += debug
|
||||||
|
|
||||||
macx {
|
macx {
|
||||||
CONFIG += x86
|
CONFIG += x86
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user