nextcloud-desktop/src/mirall/folder.cpp

113 lines
2.5 KiB
C++
Raw Normal View History

2011-02-17 02:21:45 +03:00
#include <QAction>
#include <QDebug>
#include <QDesktopServices>
#include <QIcon>
#include <QMutexLocker>
#include <QTimer>
2011-02-17 02:21:45 +03:00
#include <QUrl>
#include "mirall/constants.h"
#include "mirall/folder.h"
#include "mirall/folderwatcher.h"
#define DEFAULT_POLL_INTERVAL_SEC 30
2011-02-17 02:21:45 +03:00
namespace Mirall {
2011-04-06 11:52:02 +04:00
Folder::Folder(const QString &alias, const QString &path, QObject *parent)
2011-02-17 02:21:45 +03:00
: QObject(parent),
_path(path),
_pollTimer(new QTimer(this)),
2011-04-06 11:52:02 +04:00
_pollInterval(DEFAULT_POLL_INTERVAL_SEC),
_alias(alias)
2011-02-17 02:21:45 +03:00
{
_openAction = new QAction(QIcon(FOLDER_ICON), path, this);
_openAction->setIconVisibleInMenu(true);
_openAction->setIcon(QIcon(FOLDER_ICON));
QObject::connect(_openAction, SIGNAL(triggered(bool)), SLOT(slotOpenFolder()));
2011-02-17 02:21:45 +03:00
_pollTimer->setSingleShot(true);
_pollTimer->setInterval(pollInterval() * 1000);
QObject::connect(_pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerTimeout()));
_pollTimer->start();
2011-02-17 02:21:45 +03:00
_watcher = new Mirall::FolderWatcher(path, this);
QObject::connect(_watcher, SIGNAL(folderChanged(const QStringList &)),
SLOT(slotChanged(const QStringList &)));
QObject::connect(this, SIGNAL(syncStarted()),
SLOT(slotSyncStarted()));
QObject::connect(this, SIGNAL(syncFinished()),
SLOT(slotSyncFinished()));
2011-02-17 02:21:45 +03:00
}
QAction * Folder::openAction() const
2011-02-17 02:21:45 +03:00
{
return _openAction;
2011-02-17 02:21:45 +03:00
}
Folder::~Folder()
{
}
2011-04-06 11:52:02 +04:00
QString Folder::alias() const
{
return _alias;
}
QString Folder::path() const
{
return _path;
}
int Folder::pollInterval() const
{
return _pollInterval;
}
void Folder::setPollInterval(int seconds)
{
_pollInterval = seconds;
}
void Folder::slotPollTimerTimeout()
{
qDebug() << "* Polling" << alias() << "for changes. Ignoring all pending events until now";
_watcher->clearPendingEvents();
qDebug() << "* " << root() << "Poll timer disabled";
_pollTimer->stop();
startSync(QStringList());
}
void Folder::slotChanged(const QStringList &pathList)
2011-02-17 02:21:45 +03:00
{
startSync(pathList);
2011-02-17 02:21:45 +03:00
}
void Folder::slotOpenFolder()
{
QDesktopServices::openUrl(QUrl(_path));
}
void Folder::slotSyncStarted()
{
// disable events until syncing is done
_watcher->setEventsEnabled(false);
_openAction->setIcon(QIcon(FOLDER_SYNC_ICON));
}
void Folder::slotSyncFinished()
{
_watcher->setEventsEnabled(true);
_openAction->setIcon(QIcon(FOLDER_ICON));
// reenable the poll timer
qDebug() << "* " << root() << "Poll timer enabled";
_pollTimer->start();
}
2011-02-17 02:21:45 +03:00
} // namespace Mirall
#include "folder.moc"