nextcloud-desktop/src/mirall/folderwatcher.h

131 lines
2.9 KiB
C
Raw Normal View History

2011-04-06 13:48:02 +04:00
/*
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 <QList>
2011-02-17 02:21:45 +03:00
#include <QObject>
#include <QString>
#include <QStringList>
#include <QTime>
2011-02-17 02:21:45 +03:00
class QTimer;
class INotify;
2011-02-17 02:21:45 +03:00
namespace Mirall {
2011-03-21 00:17:23 +03:00
/**
* Watches a folder and sub folders for changes
*
* Will notify changed files relative to the root()
* directory.
*
* If too many changes happen in a short time interval,
* it will accumulate and be fired together later.
2011-03-21 00:17:23 +03:00
*/
2011-02-17 02:21:45 +03:00
class FolderWatcher : public QObject
{
Q_OBJECT
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);
2011-02-17 02:21:45 +03:00
~FolderWatcher();
2011-03-21 00:17:23 +03:00
/**
* All watched folders and subfolders
*/
QStringList folders() const;
2011-03-21 00:18:38 +03:00
/**
* Root path being monitored
*/
QString root() const;
2011-03-21 00:18:38 +03:00
/**
* Add an ignore pattern that will not be
* notified
*
* You can use wildcards
*/
void addIgnore(const QString &pattern);
/**
* If true, folderChanged() events are sent
* at least as often as eventInterval() seconds.
*/
bool eventsEnabled() const;
/**
* Enabled or disables folderChanged() events.
* If disabled, events are accumulated and emptied
* the next time a folderChanged() event happens.
*/
void setEventsEnabled(bool enabled);
/**
* Clear all pending events
*/
void clearPendingEvents();
/**
* The minimum amounts of seconds that will separate
* folderChanged() intervals
*/
int eventInterval() const;
/**
* Sets minimum amounts of seconds that will separate
* folderChanged() intervals
*/
void setEventInterval(int seconds);
2011-02-17 02:21:45 +03:00
signals:
2011-03-21 00:17:23 +03:00
/**
* Emitted when one of the paths is changed
*/
void folderChanged(const QStringList &pathList);
2011-03-21 00:17:23 +03:00
protected:
void setProcessTimer();
2011-02-17 02:21:45 +03:00
protected slots:
void slotINotifyEvent(int mask, int cookie, const QString &path);
void slotAddFolderRecursive(const QString &path);
// called when the manually process timer triggers
void slotProcessTimerTimeout();
2011-02-17 02:21:45 +03:00
private:
bool _eventsEnabled;
int _eventInterval;
INotify *_inotify;
QString _root;
// paths pending to notified
QStringList _pendingPaths;
QTimer *_processTimer;
// to cancel events that belong to the same action
int _lastMask;
QString _lastPath;
QStringList _ignores;
2011-02-17 02:21:45 +03:00
};
}
#endif