mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
Make the folders network state aware
This commit is contained in:
parent
65c41b6368
commit
a4c5996f47
3 changed files with 37 additions and 11 deletions
|
@ -141,9 +141,6 @@ void Application::slotAddFolder()
|
||||||
settings.setValue("folder/onlyThisLAN", onlyThisLAN);
|
settings.setValue("folder/onlyThisLAN", onlyThisLAN);
|
||||||
if (onlyThisLAN) {
|
if (onlyThisLAN) {
|
||||||
settings.setValue("folder/onlyOnline", true);
|
settings.setValue("folder/onlyOnline", true);
|
||||||
if (_folderWizard->field("onlyThisLAN?").toBool()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,8 +206,8 @@ void Application::setupFolderFromConfigFile(const QString &file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
folder->setOnlyOnlineEnabled(settings.value("folder/onlyOnline").toBool());
|
folder->setOnlyOnlineEnabled(settings.value("folder/onlyOnline", false).toBool());
|
||||||
folder->setOnlyThisLANEnabled(settings.value("folder/onlyThisLAN").toBool());
|
folder->setOnlyThisLANEnabled(settings.value("folder/onlyThisLAN", false).toBool());
|
||||||
|
|
||||||
_folderMap[file] = folder;
|
_folderMap[file] = folder;
|
||||||
QObject::connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
|
QObject::connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
|
||||||
|
|
|
@ -35,7 +35,8 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
|
||||||
_pollInterval(DEFAULT_POLL_INTERVAL_SEC),
|
_pollInterval(DEFAULT_POLL_INTERVAL_SEC),
|
||||||
_alias(alias),
|
_alias(alias),
|
||||||
_onlyOnlineEnabled(false),
|
_onlyOnlineEnabled(false),
|
||||||
_onlyThisLANEnabled(false)
|
_onlyThisLANEnabled(false),
|
||||||
|
_online(false)
|
||||||
{
|
{
|
||||||
_openAction = new QAction(QIcon::fromTheme(FOLDER_ICON), path, this);
|
_openAction = new QAction(QIcon::fromTheme(FOLDER_ICON), path, this);
|
||||||
_openAction->setIconVisibleInMenu(true);
|
_openAction->setIconVisibleInMenu(true);
|
||||||
|
@ -57,6 +58,9 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
|
||||||
QObject::connect(this, SIGNAL(syncFinished()),
|
QObject::connect(this, SIGNAL(syncFinished()),
|
||||||
SLOT(slotSyncFinished()));
|
SLOT(slotSyncFinished()));
|
||||||
|
|
||||||
|
_online = _networkMgr.isOnline();
|
||||||
|
QObject::connect(&_networkMgr, SIGNAL(onlineStateChanged(bool)), SLOT(slotOnlineChanged(bool)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction * Folder::openAction() const
|
QAction * Folder::openAction() const
|
||||||
|
@ -108,18 +112,33 @@ void Folder::setPollInterval(int seconds)
|
||||||
_pollInterval = seconds;
|
_pollInterval = seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Folder::evaluateSync(const QStringList &pathList)
|
||||||
|
{
|
||||||
|
if (!_online && onlyOnlineEnabled()) {
|
||||||
|
qDebug() << "*" << alias() << "sync skipped, not online";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
startSync(pathList);
|
||||||
|
}
|
||||||
|
|
||||||
void Folder::slotPollTimerTimeout()
|
void Folder::slotPollTimerTimeout()
|
||||||
{
|
{
|
||||||
qDebug() << "* Polling" << alias() << "for changes. Ignoring all pending events until now";
|
qDebug() << "* Polling" << alias() << "for changes. Ignoring all pending events until now";
|
||||||
_watcher->clearPendingEvents();
|
_watcher->clearPendingEvents();
|
||||||
qDebug() << "* " << path() << "Poll timer disabled";
|
qDebug() << "* " << alias() << "Poll timer disabled";
|
||||||
_pollTimer->stop();
|
_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)
|
void Folder::slotChanged(const QStringList &pathList)
|
||||||
{
|
{
|
||||||
startSync(pathList);
|
evaluateSync(pathList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Folder::slotOpenFolder()
|
void Folder::slotOpenFolder()
|
||||||
|
@ -139,7 +158,7 @@ void Folder::slotSyncFinished()
|
||||||
_watcher->setEventsEnabled(true);
|
_watcher->setEventsEnabled(true);
|
||||||
_openAction->setIcon(QIcon::fromTheme(FOLDER_ICON));
|
_openAction->setIcon(QIcon::fromTheme(FOLDER_ICON));
|
||||||
// reenable the poll timer
|
// reenable the poll timer
|
||||||
qDebug() << "* " << path() << "Poll timer enabled";
|
qDebug() << "* " << alias() << "Poll timer enabled";
|
||||||
_pollTimer->start();
|
_pollTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef MIRALL_FOLDER_H
|
#ifndef MIRALL_FOLDER_H
|
||||||
#define MIRALL_FOLDER_H
|
#define MIRALL_FOLDER_H
|
||||||
|
|
||||||
|
#include <QNetworkConfigurationManager>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
@ -108,6 +109,12 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a sync (calling startSync)
|
||||||
|
* if the policies allow for it
|
||||||
|
*/
|
||||||
|
void evaluateSync(const QStringList &pathList);
|
||||||
|
|
||||||
QString _path;
|
QString _path;
|
||||||
QAction *_openAction;
|
QAction *_openAction;
|
||||||
// poll timer for remote syncs
|
// poll timer for remote syncs
|
||||||
|
@ -116,9 +123,12 @@ private:
|
||||||
QString _alias;
|
QString _alias;
|
||||||
bool _onlyOnlineEnabled;
|
bool _onlyOnlineEnabled;
|
||||||
bool _onlyThisLANEnabled;
|
bool _onlyThisLANEnabled;
|
||||||
|
QNetworkConfigurationManager _networkMgr;
|
||||||
|
bool _online;
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|
||||||
|
void slotOnlineChanged(bool online);
|
||||||
|
|
||||||
void slotPollTimerTimeout();
|
void slotPollTimerTimeout();
|
||||||
|
|
||||||
/* called when the watcher detect a list of changed
|
/* called when the watcher detect a list of changed
|
||||||
|
|
Loading…
Reference in a new issue