From b7279a5eab8c88ea1fd1f96fe27e868a1ee3a19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 18 Apr 2012 11:33:57 +0000 Subject: [PATCH] documented; refs #116 --- src/qbrowserlib/filestorage.hxx | 34 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/qbrowserlib/filestorage.hxx b/src/qbrowserlib/filestorage.hxx index b29f7f7..35ecb54 100644 --- a/src/qbrowserlib/filestorage.hxx +++ b/src/qbrowserlib/filestorage.hxx @@ -14,29 +14,44 @@ #include +//! Store string lists. +/** Abstract storage interface to string lists, such as bookmarks. */ class Storage: public QObject { Q_OBJECT; Q_SIGNALS: + //! Emitted if file content has changed. void changed(); public: Storage() {} + /*! @return true if readable or writable */ bool valid() { return readable() || writeable(); } + /*! @return true if valid */ operator bool() { return valid(); } + /*! @return true if storage object already exists */ virtual bool readable() = 0; + /*! @return true if storage object exists or could be created */ virtual bool writeable() = 0; + /*! @return storage content as string list */ virtual QStringList read() = 0; + //! Writes storage content from string list. virtual bool write(const QStringList& out) = 0; }; +//! Implement @ref Storage for files. class FileStorage: public Storage { Q_OBJECT; public: + /*! @param file full path to storage file */ FileStorage(QString file): _file(file) { - if (valid()) setupWatcher(); + _watcher.addPath(QFileInfo(_file).absolutePath()); + assert(connect(&_watcher, SIGNAL(directoryChanged(const QString&)), + SLOT(setupWatcher()))); + assert(connect(&_watcher, SIGNAL(fileChanged(const QString&)), + SIGNAL(changed()))); } bool readable() { return QFileInfo(_file).exists(); @@ -66,21 +81,10 @@ class FileStorage: public Storage { } private Q_SLOTS: void setupWatcher() { - if (!_watcher) { - _watcher = new QFileSystemWatcher(this); - _watcher->addPath(QFileInfo(_file).absolutePath()); - assert(connect(_watcher, SIGNAL(directoryChanged(const QString&)), - SLOT(setupWatcher()))); - assert(connect(_watcher, SIGNAL(fileChanged(const QString&)), - SIGNAL(changed()))); - } - if (readable()) { - _watcher->removePaths(_watcher->files()); - _watcher->addPath(_file.fileName()); - } + _watcher.removePaths(_watcher.files()); + if (readable()) _watcher.addPath(_file.fileName()); } private: QFile _file; - QFileSystemWatcher* _watcher; + QFileSystemWatcher _watcher; }; -