2011-04-06 13:48:02 +04:00
|
|
|
/*
|
2014-01-13 19:16:19 +04:00
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
2011-04-06 13:48:02 +04:00
|
|
|
*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2011-04-06 13:48:02 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-03-16 16:50:34 +03:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
#ifndef MIRALL_FOLDERWATCHER_H
|
|
|
|
#define MIRALL_FOLDERWATCHER_H
|
|
|
|
|
2012-07-20 19:13:23 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-04-04 20:41:14 +04:00
|
|
|
#include <QList>
|
2011-02-17 02:21:45 +03:00
|
|
|
#include <QObject>
|
2011-03-21 00:38:33 +03:00
|
|
|
#include <QString>
|
2011-03-23 01:03:43 +03:00
|
|
|
#include <QStringList>
|
2011-03-21 00:38:33 +03:00
|
|
|
#include <QTime>
|
2012-02-16 01:36:52 +04:00
|
|
|
#include <QHash>
|
2014-01-11 23:35:58 +04:00
|
|
|
#include <QScopedPointer>
|
2014-02-18 03:36:41 +04:00
|
|
|
#include <QSet>
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2011-03-23 01:03:43 +03:00
|
|
|
class QTimer;
|
2012-05-21 18:48:49 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2012-05-21 18:48:49 +04:00
|
|
|
|
2012-12-04 21:15:37 +04:00
|
|
|
class FolderWatcherPrivate;
|
2015-10-02 10:40:44 +03:00
|
|
|
class Folder;
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
2015-10-05 07:21:19 +03:00
|
|
|
* @brief Monitors a directory recursively for changes
|
2015-06-26 18:07:47 +03:00
|
|
|
*
|
2014-01-11 23:35:58 +04:00
|
|
|
* Folder Watcher monitors a directory and its sub directories
|
|
|
|
* for changes in the local file system. Changes are signalled
|
2014-11-07 12:53:41 +03:00
|
|
|
* through the pathChanged() signal.
|
2014-02-03 14:58:37 +04:00
|
|
|
*
|
|
|
|
* Note that if new folders are created, this folderwatcher class
|
2015-10-05 07:21:19 +03:00
|
|
|
* does not automatically add them to the list of monitored
|
2014-02-03 14:58:37 +04:00
|
|
|
* dirs. That is the responsibility of the user of this class to
|
|
|
|
* call addPath() with the new dir.
|
2015-06-26 18:07:47 +03:00
|
|
|
*
|
2015-06-29 19:56:09 +03:00
|
|
|
* @ingroup gui
|
2011-03-21 00:17:23 +03:00
|
|
|
*/
|
2014-01-11 23:35:58 +04:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
class FolderWatcher : public QObject
|
|
|
|
{
|
2013-08-07 16:59:41 +04:00
|
|
|
Q_OBJECT
|
2011-02-17 02:21:45 +03:00
|
|
|
public:
|
2011-03-21 00:17:23 +03:00
|
|
|
/**
|
|
|
|
* @param root Path of the root of the folder
|
|
|
|
*/
|
2015-10-02 10:40:44 +03:00
|
|
|
FolderWatcher(const QString &root, Folder* folder = 0L);
|
2014-01-27 15:31:54 +04:00
|
|
|
virtual ~FolderWatcher();
|
2011-03-21 00:18:38 +03:00
|
|
|
|
2013-08-19 19:41:42 +04:00
|
|
|
/**
|
|
|
|
* Not all backends are recursive by default.
|
|
|
|
* Those need to be notified when a directory is added or removed while the watcher is disabled.
|
2015-10-05 07:21:19 +03:00
|
|
|
* This is a no-op for backends that are recursive
|
2013-08-19 19:41:42 +04:00
|
|
|
*/
|
|
|
|
void addPath(const QString&);
|
|
|
|
void removePath(const QString&);
|
|
|
|
|
2014-01-13 18:23:38 +04:00
|
|
|
/* Check if the path is ignored. */
|
|
|
|
bool pathIsIgnored( const QString& path );
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
signals:
|
2014-11-07 12:53:41 +03:00
|
|
|
/** Emitted when one of the watched directories or one
|
|
|
|
* of the contained files is changed. */
|
|
|
|
void pathChanged(const QString &path);
|
2014-01-11 23:35:58 +04:00
|
|
|
|
2013-08-07 16:59:41 +04:00
|
|
|
/** Emitted if an error occurs */
|
|
|
|
void error(const QString& error);
|
2011-03-21 00:17:23 +03:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
protected slots:
|
2014-01-11 23:35:58 +04:00
|
|
|
// called from the implementations to indicate a change in path
|
|
|
|
void changeDetected( const QString& path);
|
2014-02-18 03:36:41 +04:00
|
|
|
void changeDetected( const QStringList& paths);
|
2011-04-04 20:41:14 +04:00
|
|
|
|
2012-12-05 21:23:35 +04:00
|
|
|
protected:
|
|
|
|
QHash<QString, int> _pendingPathes;
|
2012-12-04 20:46:44 +04:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
private:
|
2014-01-11 23:35:58 +04:00
|
|
|
QScopedPointer<FolderWatcherPrivate> _d;
|
2014-01-13 18:23:38 +04:00
|
|
|
QTime _timer;
|
2014-02-18 03:36:41 +04:00
|
|
|
QSet<QString> _lastPaths;
|
2015-10-02 10:40:44 +03:00
|
|
|
Folder* _folder;
|
2012-12-05 21:30:40 +04:00
|
|
|
|
|
|
|
friend class FolderWatcherPrivate;
|
2011-02-17 02:21:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|