Make the folders network state aware

This commit is contained in:
Duncan Mac-Vicar P 2011-04-06 15:57:18 +02:00
parent 65c41b6368
commit a4c5996f47
3 changed files with 37 additions and 11 deletions

View file

@ -141,9 +141,6 @@ void Application::slotAddFolder()
settings.setValue("folder/onlyThisLAN", onlyThisLAN);
if (onlyThisLAN) {
settings.setValue("folder/onlyOnline", true);
if (_folderWizard->field("onlyThisLAN?").toBool()) {
}
}
}
}
@ -209,8 +206,8 @@ void Application::setupFolderFromConfigFile(const QString &file) {
return;
}
}
folder->setOnlyOnlineEnabled(settings.value("folder/onlyOnline").toBool());
folder->setOnlyThisLANEnabled(settings.value("folder/onlyThisLAN").toBool());
folder->setOnlyOnlineEnabled(settings.value("folder/onlyOnline", false).toBool());
folder->setOnlyThisLANEnabled(settings.value("folder/onlyThisLAN", false).toBool());
_folderMap[file] = folder;
QObject::connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));

View file

@ -35,7 +35,8 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
_pollInterval(DEFAULT_POLL_INTERVAL_SEC),
_alias(alias),
_onlyOnlineEnabled(false),
_onlyThisLANEnabled(false)
_onlyThisLANEnabled(false),
_online(false)
{
_openAction = new QAction(QIcon::fromTheme(FOLDER_ICON), path, this);
_openAction->setIconVisibleInMenu(true);
@ -57,6 +58,9 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
QObject::connect(this, SIGNAL(syncFinished()),
SLOT(slotSyncFinished()));
_online = _networkMgr.isOnline();
QObject::connect(&_networkMgr, SIGNAL(onlineStateChanged(bool)), SLOT(slotOnlineChanged(bool)));
}
QAction * Folder::openAction() const
@ -108,18 +112,33 @@ void Folder::setPollInterval(int seconds)
_pollInterval = seconds;
}
void Folder::evaluateSync(const QStringList &pathList)
{
if (!_online && onlyOnlineEnabled()) {
qDebug() << "*" << alias() << "sync skipped, not online";
return;
}
startSync(pathList);
}
void Folder::slotPollTimerTimeout()
{
qDebug() << "* Polling" << alias() << "for changes. Ignoring all pending events until now";
_watcher->clearPendingEvents();
qDebug() << "* " << path() << "Poll timer disabled";
qDebug() << "* " << alias() << "Poll timer disabled";
_pollTimer->stop();
startSync(QStringList());
evaluateSync(QStringList());
}
void Folder::slotOnlineChanged(bool online)
{
qDebug() << "* " << alias() << "is" << (online ? "now online" : "no longer online");
_online = online;
}
void Folder::slotChanged(const QStringList &pathList)
{
startSync(pathList);
evaluateSync(pathList);
}
void Folder::slotOpenFolder()
@ -139,7 +158,7 @@ void Folder::slotSyncFinished()
_watcher->setEventsEnabled(true);
_openAction->setIcon(QIcon::fromTheme(FOLDER_ICON));
// reenable the poll timer
qDebug() << "* " << path() << "Poll timer enabled";
qDebug() << "* " << alias() << "Poll timer enabled";
_pollTimer->start();
}

View file

@ -15,6 +15,7 @@
#ifndef MIRALL_FOLDER_H
#define MIRALL_FOLDER_H
#include <QNetworkConfigurationManager>
#include <QObject>
#include <QString>
#include <QStringList>
@ -108,6 +109,12 @@ protected:
private:
/**
* Starts a sync (calling startSync)
* if the policies allow for it
*/
void evaluateSync(const QStringList &pathList);
QString _path;
QAction *_openAction;
// poll timer for remote syncs
@ -116,9 +123,12 @@ private:
QString _alias;
bool _onlyOnlineEnabled;
bool _onlyThisLANEnabled;
QNetworkConfigurationManager _networkMgr;
bool _online;
protected slots:
void slotOnlineChanged(bool online);
void slotPollTimerTimeout();
/* called when the watcher detect a list of changed