[Pkg-owncloud-commits] [owncloud-client] 86/470: Add 'pause all' tray menu entry #3829
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu May 12 16:24:47 UTC 2016
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 10e8f03ea4e1bbc63a99526b7c56f777c3a81c67
Author: Christian Kamm <mail at ckamm.de>
Date: Tue Mar 1 16:07:11 2016 +0100
Add 'pause all' tray menu entry #3829
---
src/gui/accountstate.cpp | 5 +++
src/gui/accountstate.h | 3 ++
src/gui/folder.cpp | 6 ++-
src/gui/folder.h | 2 +-
src/gui/folderman.cpp | 2 +-
src/gui/folderstatusmodel.cpp | 4 +-
src/gui/owncloudgui.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++-
src/gui/owncloudgui.h | 3 ++
8 files changed, 106 insertions(+), 9 deletions(-)
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 7a14b2d..0d562db 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 936a6e0..61a8dc1 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 0110394..ce9ab60 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 b450e89..510fd0f 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 8f812f2..37e0b1b 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 d7185c3..f36a701 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 b97a637..ed41fb5 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<AccountStatePtr> 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<AccountStatePtr>(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<AccountState*> accounts;
+ if (auto account = qvariant_cast<AccountStatePtr>(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 0b5395b..e5c8f20 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);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list