diff options
author | Daniel Molkentin <danimo@owncloud.com> | 2014-07-11 02:31:24 +0400 |
---|---|---|
committer | Daniel Molkentin <danimo@owncloud.com> | 2014-07-11 13:07:31 +0400 |
commit | df3c3bca025a7cdb5f20e55fc2ecc37618e7cc8d (patch) | |
tree | 22fa58b5a09ec9f93ad376dce2edd6272483fc1a /src/gui/folderwatcher.h | |
parent | d1b991e1984ef0c4ed803c5c5ead1ce3bfe00266 (diff) |
Split into three separate projects: library, gui and cmd
Diffstat (limited to 'src/gui/folderwatcher.h')
-rw-r--r-- | src/gui/folderwatcher.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/gui/folderwatcher.h b/src/gui/folderwatcher.h new file mode 100644 index 000000000..bcdb5f0ee --- /dev/null +++ b/src/gui/folderwatcher.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) by Klaas Freitag <freitag@owncloud.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef MIRALL_FOLDERWATCHER_H +#define MIRALL_FOLDERWATCHER_H + +#include "config.h" + +#include <QList> +#include <QObject> +#include <QString> +#include <QStringList> +#include <QTime> +#include <QHash> +#include <QScopedPointer> +#include <QSet> + +class QTimer; + +namespace Mirall { + +class FolderWatcherPrivate; + +/* + * Folder Watcher monitors a directory and its sub directories + * for changes in the local file system. Changes are signalled + * through the folderChanged() signal. + * + * Note that if new folders are created, this folderwatcher class + * does not automatically adds them to the list of monitored + * dirs. That is the responsibility of the user of this class to + * call addPath() with the new dir. + */ + +class FolderWatcher : public QObject +{ + Q_OBJECT +public: + /** + * @param root Path of the root of the folder + */ + FolderWatcher(const QString &root, QObject *parent = 0L); + virtual ~FolderWatcher(); + + /** + * Set a file name to load a file with ignore patterns. + * + * Valid entries do not start with a hash sign (#) + * and may contain wildcards + */ + void addIgnoreListFile( const QString& ); + + QStringList ignores() const; + + /** + * Not all backends are recursive by default. + * Those need to be notified when a directory is added or removed while the watcher is disabled. + * This is a no-op for backend that are recursive + */ + void addPath(const QString&); + void removePath(const QString&); + + /* Check if the path is ignored. */ + bool pathIsIgnored( const QString& path ); + +signals: + /** Emitted when one of the paths is changed */ + void folderChanged(const QString &path); + + /** Emitted if an error occurs */ + void error(const QString& error); + +protected slots: + // called from the implementations to indicate a change in path + void changeDetected( const QString& path); + void changeDetected( const QStringList& paths); + +protected: + QHash<QString, int> _pendingPathes; + +private: + QScopedPointer<FolderWatcherPrivate> _d; + QStringList _ignores; + QTime _timer; + QSet<QString> _lastPaths; + + friend class FolderWatcherPrivate; +}; + +} + +#endif |