From: Christian Kamm Date: Tue, 1 Mar 2016 15:07:11 +0000 (+0100) Subject: Add 'pause all' tray menu entry #3829 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~1336^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=10e8f03ea4e1bbc63a99526b7c56f777c3a81c67;p=nextcloud-desktop.git Add 'pause all' tray menu entry #3829 --- diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 7a14b2d5d..0d562db4c 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -139,6 +139,11 @@ bool AccountState::isConnectedOrTemporarilyUnavailable() const return isConnected() || _state == ServiceUnavailable; } +bool AccountState::canSync() const +{ + return isConnected(); +} + void AccountState::tagLastSuccessfullETagRequest() { _timeSinceLastETagCheck.restart(); diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 936a6e01b..61a8dc1fb 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -88,6 +88,9 @@ public: bool isConnected() const; bool isConnectedOrTemporarilyUnavailable() const; + /// Returns whether sync actions are allowed to run. + bool canSync() const; + /// Triggers a ping to the server to update state and /// connection status and errors. void checkConnectivity(); diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 011039431..ce9ab60d6 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -260,7 +260,7 @@ bool Folder::syncPaused() const bool Folder::canSync() const { - return !syncPaused() && accountState()->isConnected(); + return !syncPaused() && accountState()->canSync(); } void Folder::setSyncPaused( bool paused ) @@ -272,12 +272,14 @@ void Folder::setSyncPaused( bool paused ) if( !paused ) { // qDebug() << "Syncing enabled on folder " << name(); + setSyncState(SyncResult::NotYetStarted); } else { // do not stop or start the watcher here, that is done internally by // folder class. Even if the watcher fires, the folder does not // schedule itself because it checks the var. _enabled before. setSyncState(SyncResult::Paused); } + emit syncStateChange(); } void Folder::setSyncState(SyncResult::Status state) @@ -312,7 +314,7 @@ void Folder::slotRunEtagJob() return; } - if (_definition.paused || !_accountState->isConnected()) { + if (!canSync()) { qDebug() << "Not syncing. :" << remoteUrl().toString() << _definition.paused << AccountState::stateString(_accountState->state()); return; } diff --git a/src/gui/folder.h b/src/gui/folder.h index b450e8994..510fd0f20 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -143,7 +143,7 @@ public: /** * Returns true when the folder may sync. * - * !syncPaused() && accountState->isConnected(). + * !syncPaused() && accountState->canSync(). */ bool canSync() const; diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 8f812f20b..37e0b1be2 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -554,7 +554,7 @@ void FolderMan::slotAccountStateChanged() } QString accountName = accountState->account()->displayName(); - if (accountState->isConnected()) { + if (accountState->canSync()) { qDebug() << "Account" << accountName << "connected, scheduling its folders"; foreach (Folder *f, _folderMap.values()) { diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index d7185c354..f36a701c0 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -995,9 +995,7 @@ void FolderStatusModel::slotFolderSyncStateChange(Folder *f) void FolderStatusModel::slotFolderScheduleQueueChanged() { // Update messages on waiting folders. - // It's ok to only update folders currently in the queue, because folders - // are only removed from the queue if they are deleted. - foreach (Folder* f, FolderMan::instance()->scheduleQueue()) { + foreach (Folder* f, FolderMan::instance()->map()) { slotFolderSyncStateChange(f); } } diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index b97a637f7..ed41fb57f 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -192,6 +192,7 @@ void ownCloudGui::slotTrayClicked( QSystemTrayIcon::ActivationReason reason ) void ownCloudGui::slotSyncStateChange( Folder* folder ) { slotComputeOverallSyncStatus(); + setupContextMenu(); if( !folder ) { return; // Valid, just a general GUI redraw was needed. @@ -230,6 +231,7 @@ void ownCloudGui::slotAccountStateChanged() void ownCloudGui::slotComputeOverallSyncStatus() { bool allSignedOut = true; + bool allPaused = true; QVector problemAccounts; foreach (auto a, AccountManager::instance()->accounts()) { if (!a->isSignedOut()) { @@ -239,6 +241,11 @@ void ownCloudGui::slotComputeOverallSyncStatus() problemAccounts.append(a); } } + foreach (Folder* f, FolderMan::instance()->map()) { + if (!f->syncPaused()) { + allPaused = false; + } + } if (!problemAccounts.empty()) { _tray->setIcon(Theme::instance()->folderOfflineIcon(true)); @@ -271,6 +278,10 @@ void ownCloudGui::slotComputeOverallSyncStatus() _tray->setIcon(Theme::instance()->folderOfflineIcon(true)); _tray->setToolTip(tr("Please sign in")); return; + } else if (allPaused) { + _tray->setIcon(Theme::instance()->syncStateIcon(SyncResult::Paused, true)); + _tray->setToolTip(tr("Account synchronization is disabled")); + return; } // display the info of the least successful sync (eg. do not just display the result of the latest sync) @@ -324,11 +335,19 @@ void ownCloudGui::addAccountContextMenu(AccountStatePtr accountState, QMenu *men FolderMan *folderMan = FolderMan::instance(); bool firstFolder = true; bool singleSyncFolder = folderMan->map().size() == 1 && Theme::instance()->singleSyncFolder(); + bool onePaused = false; + bool allPaused = true; foreach (Folder* folder, folderMan->map()) { if (folder->accountState() != accountState) { continue; } + if (folder->syncPaused()) { + onePaused = true; + } else { + allPaused = false; + } + if (firstFolder && !singleSyncFolder) { firstFolder = false; menu->addSeparator(); @@ -343,6 +362,17 @@ void ownCloudGui::addAccountContextMenu(AccountStatePtr accountState, QMenu *men menu->addSeparator(); if (separateMenu) { + if (onePaused) { + QAction* enable = menu->addAction(tr("Unpause all folders")); + enable->setProperty(propertyAccountC, QVariant::fromValue(accountState)); + connect(enable, SIGNAL(triggered(bool)), SLOT(slotUnpauseAllFolders())); + } + if (!allPaused) { + QAction* enable = menu->addAction(tr("Pause all folders")); + enable->setProperty(propertyAccountC, QVariant::fromValue(accountState)); + connect(enable, SIGNAL(triggered(bool)), SLOT(slotPauseAllFolders())); + } + if (accountState->isSignedOut()) { QAction* signin = menu->addAction(tr("Log in...")); signin->setProperty(propertyAccountC, QVariant::fromValue(accountState)); @@ -364,16 +394,25 @@ void ownCloudGui::setupContextMenu() bool atLeastOneConnected = false; bool atLeastOneSignedOut = false; bool atLeastOneSignedIn = false; + bool atLeastOnePaused = false; + bool atLeastOneNotPaused = false; foreach (auto a, accountList) { if (a->isConnected()) { atLeastOneConnected = true; } - if (a->isSignedOut()){ + if (a->isSignedOut()) { atLeastOneSignedOut = true; } else { atLeastOneSignedIn = true; } } + foreach (auto f, FolderMan::instance()->map()) { + if (f->syncPaused()) { + atLeastOnePaused = true; + } else { + atLeastOneNotPaused = true; + } + } if ( _contextMenu ) { if (_qdbusmenuWorkaround) { @@ -439,6 +478,26 @@ void ownCloudGui::setupContextMenu() } _contextMenu->addSeparator(); + if (atLeastOnePaused) { + QString text; + if (accountList.count() > 1) { + text = tr("Unpause all synchronization"); + } else { + text = tr("Unpause synchronization"); + } + QAction* action = _contextMenu->addAction(text); + connect(action, SIGNAL(triggered(bool)), SLOT(slotUnpauseAllFolders())); + } + if (atLeastOneNotPaused) { + QString text; + if (accountList.count() > 1) { + text = tr("Pause all synchronization"); + } else { + text = tr("Pause synchronization"); + } + QAction* action = _contextMenu->addAction(text); + connect(action, SIGNAL(triggered(bool)), SLOT(slotPauseAllFolders())); + } if (atLeastOneSignedIn) { if (accountList.count() > 1) { _actionLogout->setText(tr("Log out of all accounts")); @@ -627,10 +686,10 @@ void ownCloudGui::slotDisplayIdle() void ownCloudGui::slotLogin() { - auto list = AccountManager::instance()->accounts(); if (auto account = qvariant_cast(sender()->property(propertyAccountC))) { account->signIn(); } else { + auto list = AccountManager::instance()->accounts(); foreach (const auto &a, list) { a->signIn(); } @@ -650,6 +709,33 @@ void ownCloudGui::slotLogout() } } +void ownCloudGui::slotUnpauseAllFolders() +{ + setPauseOnAllFoldersHelper(false); +} + +void ownCloudGui::slotPauseAllFolders() +{ + setPauseOnAllFoldersHelper(true); +} + +void ownCloudGui::setPauseOnAllFoldersHelper(bool pause) +{ + QList accounts; + if (auto account = qvariant_cast(sender()->property(propertyAccountC))) { + accounts.append(account.data()); + } else { + foreach (auto a, AccountManager::instance()->accounts()) { + accounts.append(a.data()); + } + } + foreach (Folder* f, FolderMan::instance()->map()) { + if (accounts.contains(f->accountState())) { + f->setSyncPaused(pause); + } + } +} + void ownCloudGui::slotShowGuiMessage(const QString &title, const QString &message) { QMessageBox *msgBox = new QMessageBox; diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 0b5395b89..e5c8f2013 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -84,8 +84,11 @@ private slots: void slotDisplayIdle(); void slotLogin(); void slotLogout(); + void slotUnpauseAllFolders(); + void slotPauseAllFolders(); private: + void setPauseOnAllFoldersHelper(bool pause); void setupActions(); void addAccountContextMenu(AccountStatePtr accountState, QMenu* menu, bool separateMenu);