nextcloud-desktop/src/mirall/folderwatcher.h

103 lines
2.6 KiB
C
Raw Normal View History

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
2014-01-13 19:16:19 +04:00
* the Free Software Foundation; version 2 of the License.
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-02-17 02:21:45 +03:00
#ifndef MIRALL_FOLDERWATCHER_H
#define MIRALL_FOLDERWATCHER_H
#include "config.h"
#include <QList>
2011-02-17 02:21:45 +03:00
#include <QObject>
#include <QString>
#include <QStringList>
#include <QTime>
2012-02-16 01:36:52 +04:00
#include <QHash>
#include <QScopedPointer>
#include <QSet>
2011-02-17 02:21:45 +03:00
class QTimer;
2012-05-21 18:48:49 +04:00
namespace Mirall {
2012-12-04 21:15:37 +04:00
class FolderWatcherPrivate;
2011-02-17 02:21:45 +03:00
/*
* Folder Watcher monitors a directory and its sub directories
* for changes in the local file system. Changes are signalled
* through the folderChanged() signal.
2014-02-03 14:58:37 +04:00
*
* 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.
2011-03-21 00:17:23 +03:00
*/
2011-02-17 02:21:45 +03:00
class FolderWatcher : public QObject
{
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
*/
FolderWatcher(const QString &root, QObject *parent = 0L);
virtual ~FolderWatcher();
2011-03-21 00:18:38 +03:00
/**
* 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 );
2011-02-17 02:21:45 +03:00
signals:
/** Emitted when one of the paths is changed */
void folderChanged(const QString &path);
/** 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:
// 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;
2012-12-04 20:46:44 +04:00
2011-02-17 02:21:45 +03:00
private:
QScopedPointer<FolderWatcherPrivate> _d;
QStringList _ignores;
QTime _timer;
QSet<QString> _lastPaths;
friend class FolderWatcherPrivate;
2011-02-17 02:21:45 +03:00
};
}
#endif