pimpl folderwatcher

This commit is contained in:
Daniel Molkentin 2012-12-04 18:15:37 +01:00
parent b74cfcfec5
commit 214261e764
6 changed files with 43 additions and 18 deletions

View file

@ -50,6 +50,7 @@ namespace Mirall {
FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
: QObject(parent),
_d(new FolderWatcherPrivate),
_eventsEnabled(true),
_eventInterval(DEFAULT_EVENT_INTERVAL_MSEC),
_root(root),
@ -65,7 +66,7 @@ FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
FolderWatcher::~FolderWatcher()
{
delete _d;
}
QString FolderWatcher::root() const

View file

@ -30,9 +30,7 @@ class QTimer;
namespace Mirall {
#ifdef USE_INOTIFY
class INotify;
#endif
class FolderWatcherPrivate;
/**
* Watches a folder and sub folders for changes
@ -127,9 +125,7 @@ private:
private:
bool _eventsEnabled;
int _eventInterval;
#ifdef USE_INOTIFY
INotify *_inotify;
#endif
FolderWatcherPrivate *_d;
QString _root;
// paths pending to notified
// QStringList _pendingPaths;

View file

@ -20,6 +20,11 @@
namespace Mirall {
class FolderWatcherPrivate {
public:
INotify *inotify;
};
static const uint32_t standard_event_mask =
IN_CLOSE_WRITE | IN_ATTRIB | IN_MOVE |
IN_CREATE |IN_DELETE | IN_DELETE_SELF |
@ -29,16 +34,16 @@ static const uint32_t standard_event_mask =
void FolderWatcher::setupBackend() {
_processTimer->setSingleShot(true);
QObject::connect(_processTimer, SIGNAL(timeout()), this, SLOT(slotProcessTimerTimeout()));
_inotify = new INotify(standard_event_mask);
_d = new FolderWatcherPrivate;
_d->inotify = new INotify(this, standard_event_mask);
slotAddFolderRecursive(_root);
QObject::connect(_inotify, SIGNAL(notifyEvent(int, int, const QString &)),
QObject::connect(_d->inotify, SIGNAL(notifyEvent(int, int, const QString &)),
this, SLOT(slotINotifyEvent(int, int, const QString &)));
}
QStringList FolderWatcher::folders() const
{
return _inotify->directories();
return _d->inotify->directories();
}
void FolderWatcher::slotAddFolderRecursive(const QString &path)
@ -46,8 +51,8 @@ void FolderWatcher::slotAddFolderRecursive(const QString &path)
int subdirs = 0;
qDebug() << "(+) Watcher:" << path;
_inotify->addPath(path);
QStringList watchedFolders(_inotify->directories());
_d->inotify->addPath(path);
QStringList watchedFolders(_d->inotify->directories());
// qDebug() << "currently watching " << watchedFolders;
QStringListIterator subfoldersIt(FileUtils::subFoldersList(path, FileUtils::SubFolderRecursive));
while (subfoldersIt.hasNext()) {
@ -66,7 +71,7 @@ void FolderWatcher::slotAddFolderRecursive(const QString &path)
}
}
_inotify->addPath(folder.path());
_d->inotify->addPath(folder.path());
}
else
qDebug() << " `-> discarded:" << folder.path();
@ -110,9 +115,9 @@ void FolderWatcher::slotINotifyEvent(int mask, int cookie, const QString &path)
}
else if (mask & IN_DELETE) {
//qDebug() << cookie << " DELETE: " << path;
if ( QFileInfo(path).isDir() && _inotify->directories().contains(path) ) {
if ( QFileInfo(path).isDir() && _d->inotify->directories().contains(path) ) {
qDebug() << "(-) Watcher:" << path;
_inotify->removePath(path);
_d->inotify->removePath(path);
}
}
else if (mask & IN_CLOSE_WRITE) {

View file

@ -0,0 +1,21 @@
/*
* Copyright (C) by Daniel Molkentin <danimo@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; 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.
*/
#include "mirall/folderwatcher.h"
namespace Mirall {
}

View file

@ -36,7 +36,9 @@
namespace Mirall {
INotify::INotify(int mask) : _mask(mask)
INotify::INotify(QObject *parent, int mask)
: QObject(parent),
_mask(mask)
{
_fd = inotify_init();
_notifier = new QSocketNotifier(_fd, QSocketNotifier::Read);

View file

@ -35,7 +35,7 @@ class INotify : public QObject
public:
INotify(int mask);
INotify(QObject *parent, int mask);
~INotify();
static void initialize();