From 09911ffa99c5bd60a6766f5ae0a023c1f6b0b84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Mon, 7 May 2012 12:52:03 +0000 Subject: [PATCH] added a test that watches test/testfile which can be given the browser as bookmark file - it work's; refs https://dev.swisssign.com/projects/swissstick/ticket/980; refs #150 --- configure.in | 3 ++- src/qbrowserlib/filestorage.hxx | 10 ++++++++-- test/filewatch.cxx | 16 ++++++++++++++++ test/filewatch.hxx | 24 ++++++++++++++++++++++++ test/makefile.am | 30 ++++++++++++++++++++++++++++++ test/qmake.pro.in | 11 +++++++++++ 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 test/filewatch.cxx create mode 100644 test/filewatch.hxx create mode 100644 test/makefile.am create mode 100644 test/qmake.pro.in diff --git a/configure.in b/configure.in index 155980b..82ed838 100644 --- a/configure.in +++ b/configure.in @@ -17,7 +17,7 @@ dnl refers to ${prefix}. Thus we have to use `eval' twice. AC_INIT([README]) SRC_DIR=src -TST_DIR= +TST_DIR=test DOC_DIR=doc m4_define(x_packagename, swissbrowser) @@ -43,6 +43,7 @@ AM_INIT_AUTOMAKE($PACKAGENAME, $MAJOR.$MINOR.$LEAST, [marc.waeckerlin@tech.swiss # files to create AC_CONFIG_FILES([makefile ${PACKAGENAME}.spec src/version.cxx + test/makefile test/qmake.pro src/makefile src/qmake.pro src/languages.qrc src/qbrowserlib/makefile diff --git a/src/qbrowserlib/filestorage.hxx b/src/qbrowserlib/filestorage.hxx index 35ecb54..f4a93be 100644 --- a/src/qbrowserlib/filestorage.hxx +++ b/src/qbrowserlib/filestorage.hxx @@ -81,8 +81,14 @@ class FileStorage: public Storage { } private Q_SLOTS: void setupWatcher() { - _watcher.removePaths(_watcher.files()); - if (readable()) _watcher.addPath(_file.fileName()); + bool watching(_watcher.files().size()); + if (watching) // remove watchlist if already existent + _watcher.removePaths(_watcher.files()); + if (readable()) { // add file to watchlist + _watcher.addPath(_file.fileName()); + if (!watching) // send change event if file is initially created + changed(); + } } private: QFile _file; diff --git a/test/filewatch.cxx b/test/filewatch.cxx new file mode 100644 index 0000000..3256f24 --- /dev/null +++ b/test/filewatch.cxx @@ -0,0 +1,16 @@ +/*! @file + + @id $Id$ +*/ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +#include + +#include + +int main(int argc, char** argv) { + QCoreApplication app(argc, argv); + TestFileWatch test("testfile"); + return app.exec(); +} diff --git a/test/filewatch.hxx b/test/filewatch.hxx new file mode 100644 index 0000000..b9b2cf5 --- /dev/null +++ b/test/filewatch.hxx @@ -0,0 +1,24 @@ +/*! @file + + @id $Id$ +*/ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +#include + +#include + +class TestFileWatch: public QObject { + Q_OBJECT; + public: + TestFileWatch(QString file): _storage(file) { + assert(connect(&_storage, SIGNAL(changed()), SLOT(changed()))); + } + private Q_SLOTS: + void changed() { + qDebug()<<"File has changed: "<<_storage.read().join("; "); + } + private: + FileStorage _storage; +}; diff --git a/test/makefile.am b/test/makefile.am new file mode 100644 index 0000000..06f1617 --- /dev/null +++ b/test/makefile.am @@ -0,0 +1,30 @@ +## @id $Id$ + +## 1 2 3 4 5 6 7 8 +## 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +# noinst_PROGRAMS = filewatch + +# filewatch_SOURCES = filewatch.cxx +# filewatch_CPPFLAGS = -I${top_srcdir}/src +# filewatch_LDFLAGS = -L${top_builddir}/src/qbrowserlib +# filewatch_LDADD = -lqbrowserlib + +QMAKE_TARGETS = filewatch +QMAKE_PROJECT = qmake.pro +QMAKE_MAKEFILE = makefile.qmake +TARGETS = ${QMAKE_TARGETS} + +all: ${TARGETS} + +${QMAKE_MAKEFILE}: ${QMAKE_PROJECT} ${ALL_SRC} + ${QMAKE} -o $@ $< + +${QMAKE_TARGETS}: ${QMAKE_MAKEFILE} ${ALL_SRC} $(LANGS:%=@PACKAGENAME@_%.qm) + make -f ${QMAKE_MAKEFILE} + +CLEANFILES = ${TARGETS} ${TARGETS:%=%.exe} \ + *.o *.obj qrc_*.cpp ui_*.h moc_*.cpp \ + ${QMAKE_TARGETS} .deps +MAINTAINERCLEANFILES = makefile.in ${QMAKE_MAKEFILE} + diff --git a/test/qmake.pro.in b/test/qmake.pro.in new file mode 100644 index 0000000..38fa994 --- /dev/null +++ b/test/qmake.pro.in @@ -0,0 +1,11 @@ +QMAKE_INCDIR += @top_srcdir@/src +QMAKE_LIBDIR += @top_builddir@/src/qbrowserlib +QMAKE_LIBDIR += @top_builddir@/src/qbrowserlib/release +QMAKE_LIBS += -lqbrowserlib + +HEADERS = @srcdir@/filewatch.hxx + +SOURCES = @srcdir@/filewatch.cxx + +TARGET = filewatch +