From c2957b00ad049b1839ff369b0ff4940c51e25b20 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Sun, 18 Jan 2015 02:28:22 +0100 Subject: [PATCH] WiP Introduce a global pause state Addresses #1971 --- src/gui/folderman.cpp | 20 ++++++++++++++++++-- src/gui/folderman.h | 4 ++++ src/gui/owncloudgui.cpp | 23 ++++++++++++++++++++--- src/gui/owncloudgui.h | 2 ++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index cdf87f21a7b..1570df7d2c9 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -51,8 +51,9 @@ FolderMan* FolderMan::_instance = 0; static int msBetweenRequestAndSync = 2000; FolderMan::FolderMan(QObject *parent) : - QObject(parent), - _syncEnabled( true ) + QObject(parent) + , _syncEnabled( true ) + , _allPaused( false ) { _folderChangeSignalMapper = new QSignalMapper(this); connect(_folderChangeSignalMapper, SIGNAL(mapped(const QString &)), @@ -665,6 +666,21 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& ) QTimer::singleShot(200, this, SLOT(slotStartScheduledFolderSync())); } +void FolderMan::slotSetAllPaused(bool paused) +{ + foreach (Folder *f, _folderMap.values()) { + f->slotTerminateSync(); + } + setSyncEnabled(false); + _allPaused = paused; +} + +bool FolderMan::isAllPaused() const +{ + return _allPaused; +} + + bool FolderMan::addFolderDefinition(const QString& alias, const QString& sourceFolder, const QString& targetPath, const QStringList& selectiveSyncBlackList) { diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 21472b1d448..f5fdddd6c3f 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -96,6 +96,8 @@ class FolderMan : public QObject SocketApi *socketApi(); + bool isAllPaused() const; + signals: /** * signal to indicate a folder named by alias has changed its sync state. @@ -113,6 +115,7 @@ public slots: void slotFolderSyncStarted(); void slotFolderSyncFinished( const SyncResult& ); + void slotSetAllPaused(bool paused); /** * Terminates the current folder sync. @@ -170,6 +173,7 @@ private slots: QMap _folderWatchers; QPointer _socketApi; + bool _allPaused; /** The aliases of folders that shall be synced. */ QQueue _scheduleQueue; diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 93afcc0884a..fbcfe50ca0f 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -45,7 +45,6 @@ namespace OCC { ownCloudGui::ownCloudGui(Application *parent) : QObject(parent), - _tray(0), #if defined(Q_OS_MAC) _settingsDialog(new SettingsDialogMac(this)), #else @@ -57,7 +56,7 @@ ownCloudGui::ownCloudGui(Application *parent) : _recentItemsMapper(new QSignalMapper(this)), _app(parent) { - _tray = new Systray(); + _tray = new Systray; _tray->setParent(this); // for the beginning, set the offline icon until the account was verified @@ -237,6 +236,12 @@ void ownCloudGui::slotComputeOverallSyncStatus() if( !_settingsDialog.isNull() ) _settingsDialog->setGeneralErrors( _startupFails ); + if (folderMan->isAllPaused()) { + _tray->setIcon(Theme::instance()->syncStateIcon( SyncResult::Paused )); + _tray->setToolTip(tr("Syncing has been paused")); + return; + } + if( !_startupFails.isEmpty() ) { trayMessage = _startupFails.join(QLatin1String("\n")); QIcon statusIcon; @@ -341,6 +346,8 @@ void ownCloudGui::setupContextMenu() _contextMenu->addAction(_actionStatus); _contextMenu->addMenu(_recentActionsMenu); _contextMenu->addSeparator(); + _contextMenu->addAction(_actionPause); + _contextMenu->addSeparator(); } _contextMenu->addAction(_actionSettings); if (!Theme::instance()->helpUrl().isEmpty()) { @@ -412,8 +419,13 @@ void ownCloudGui::setupActions() _actionSettings = new QAction(tr("Settings..."), this); _actionRecent = new QAction(tr("Details..."), this); _actionRecent->setEnabled( true ); + _actionPause = new QAction("Pause syncing", this); + _actionPause->setEnabled( true ); + _actionPause->setCheckable(true); + _actionPause->setChecked(FolderMan::instance()->isAllPaused()); QObject::connect(_actionRecent, SIGNAL(triggered(bool)), SLOT(slotShowSyncProtocol())); + QObject::connect(_actionPause, SIGNAL(triggered(bool)), SLOT(slotSetAllPaused(bool))); QObject::connect(_actionSettings, SIGNAL(triggered(bool)), SLOT(slotShowSettings())); _actionHelp = new QAction(tr("Help"), this); QObject::connect(_actionHelp, SIGNAL(triggered(bool)), SLOT(slotHelp())); @@ -563,7 +575,6 @@ void ownCloudGui::slotShowSyncProtocol() _settingsDialog->showActivityPage(); } - void ownCloudGui::slotShutdown() { // those do delete on close @@ -645,5 +656,11 @@ void ownCloudGui::slotShowShareDialog(const QString &path) w->show(); } +void ownCloudGui::slotSetAllPaused(bool paused) +{ + FolderMan::instance()->slotSetAllPaused(paused); + slotComputeOverallSyncStatus(); +} + } // end namespace diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index f3f0c846836..f7bd6a4746d 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -71,6 +71,7 @@ public slots: void slotOpenPath(const QString& path); void slotAccountStateChanged(); void slotShowShareDialog(const QString &path); + void slotSetAllPaused(bool paused); private slots: void slotDisplayIdle(); @@ -98,6 +99,7 @@ private slots: QAction *_actionStatus; QAction *_actionEstimate; QAction *_actionRecent; + QAction *_actionPause; QAction *_actionHelp; QAction *_actionQuit; QAction *_actionCrash;