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-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"
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
#include "mirall/folder.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>
|
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
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
2012-12-04 21:15:37 +04:00
|
|
|
class FolderWatcherPrivate;
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2011-03-21 00:17:23 +03:00
|
|
|
/**
|
|
|
|
* Watches a folder and sub folders for changes
|
2011-03-25 20:25:56 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
{
|
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
|
|
|
|
*/
|
2011-03-18 15:54:32 +03:00
|
|
|
FolderWatcher(const QString &root, QObject *parent = 0L);
|
2011-02-17 02:21:45 +03:00
|
|
|
~FolderWatcher();
|
2011-03-18 03:14:45 +03:00
|
|
|
|
2011-03-21 00:18:38 +03:00
|
|
|
/**
|
|
|
|
* Root path being monitored
|
|
|
|
*/
|
2011-03-21 00:38:33 +03:00
|
|
|
QString root() const;
|
2011-03-21 00:18:38 +03:00
|
|
|
|
2012-03-28 14:23:34 +04:00
|
|
|
/**
|
|
|
|
* Set a file name to load a file with ignore patterns.
|
2013-07-22 23:39:13 +04:00
|
|
|
*
|
|
|
|
* Valid entries do not start with a hash sign (#)
|
|
|
|
* and may contain wildcards
|
2012-03-28 14:23:34 +04:00
|
|
|
*/
|
2013-07-05 18:54:11 +04:00
|
|
|
void addIgnoreListFile( const QString& );
|
2012-03-28 14:23:34 +04:00
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
/**
|
|
|
|
* If true, folderChanged() events are sent
|
|
|
|
* at least as often as eventInterval() seconds.
|
|
|
|
*/
|
|
|
|
bool eventsEnabled() const;
|
|
|
|
|
2011-04-05 14:16:24 +04:00
|
|
|
/**
|
|
|
|
* Clear all pending events
|
|
|
|
*/
|
|
|
|
void clearPendingEvents();
|
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2012-12-05 21:23:35 +04:00
|
|
|
QStringList ignores() const;
|
2012-12-06 21:38:45 +04:00
|
|
|
public slots:
|
|
|
|
/**
|
|
|
|
* Enabled or disables folderChanged() events.
|
|
|
|
* If disabled, events are accumulated and emptied
|
|
|
|
* the next time a folderChanged() event happens.
|
|
|
|
*/
|
|
|
|
void setEventsEnabled(bool enabled=true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief setEventsEnabledDelayed - start event logging after a while
|
|
|
|
* @param delay - delay time in milliseconds
|
|
|
|
* @param enabled - enable the events.
|
|
|
|
*/
|
|
|
|
void setEventsEnabledDelayed( int );
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
signals:
|
2013-08-07 16:59:41 +04:00
|
|
|
/** Emitted when one of the paths is changed */
|
2011-03-23 01:03:43 +03:00
|
|
|
void folderChanged(const QStringList &pathList);
|
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-03-28 01:29:45 +04:00
|
|
|
protected:
|
|
|
|
void setProcessTimer();
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
protected slots:
|
2011-03-28 01:29:45 +04:00
|
|
|
// called when the manually process timer triggers
|
|
|
|
void slotProcessTimerTimeout();
|
2012-12-06 19:26:27 +04:00
|
|
|
void changeDetected(const QString &f);
|
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:
|
2011-03-27 04:26:41 +04:00
|
|
|
bool _eventsEnabled;
|
|
|
|
int _eventInterval;
|
2012-12-04 21:15:37 +04:00
|
|
|
FolderWatcherPrivate *_d;
|
2011-03-18 15:54:32 +03:00
|
|
|
QString _root;
|
2011-03-23 01:03:43 +03:00
|
|
|
// paths pending to notified
|
2012-02-16 01:36:52 +04:00
|
|
|
// QStringList _pendingPaths;
|
2011-03-23 01:03:43 +03:00
|
|
|
QTimer *_processTimer;
|
2011-04-04 20:41:14 +04:00
|
|
|
QStringList _ignores;
|
2012-12-05 21:30:40 +04:00
|
|
|
|
|
|
|
friend class FolderWatcherPrivate;
|
2011-02-17 02:21:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|