From 88cd5421bfcfafa9f4aaa46cff6166dfce1f516d Mon Sep 17 00:00:00 2001 From: ckamm Date: Mon, 15 Aug 2016 13:42:56 +0200 Subject: [PATCH] Tray menu: Update only on demand #4990 #4985 (#5072) The tray menu is now only updated when it becomes visible or while it is visible. --- src/gui/owncloudgui.cpp | 29 ++++++++++++++++++++++------- src/gui/owncloudgui.h | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 5b32d729f6..e98ae1cc66 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -92,9 +92,9 @@ ownCloudGui::ownCloudGui(Application *parent) : this,SLOT(slotSyncStateChange(Folder*))); connect( AccountManager::instance(), SIGNAL(accountAdded(AccountState*)), - SLOT(setupContextMenu())); + SLOT(setupContextMenuIfVisible())); connect( AccountManager::instance(), SIGNAL(accountRemoved(AccountState*)), - SLOT(setupContextMenu())); + SLOT(setupContextMenuIfVisible())); connect( Logger::instance(), SIGNAL(guiLog(QString,QString)), SLOT(slotShowTrayMessage(QString,QString))); @@ -193,7 +193,7 @@ void ownCloudGui::slotTrayClicked( QSystemTrayIcon::ActivationReason reason ) void ownCloudGui::slotSyncStateChange( Folder* folder ) { slotComputeOverallSyncStatus(); - setupContextMenu(); + setupContextMenuIfVisible(); if( !folder ) { return; // Valid, just a general GUI redraw was needed. @@ -215,7 +215,7 @@ void ownCloudGui::slotSyncStateChange( Folder* folder ) void ownCloudGui::slotFoldersChanged() { slotComputeOverallSyncStatus(); - setupContextMenu(); + setupContextMenuIfVisible(); } void ownCloudGui::slotOpenPath(const QString &path) @@ -225,7 +225,7 @@ void ownCloudGui::slotOpenPath(const QString &path) void ownCloudGui::slotAccountStateChanged() { - setupContextMenu(); + setupContextMenuIfVisible(); slotComputeOverallSyncStatus(); } @@ -450,9 +450,13 @@ void ownCloudGui::setupContextMenu() _tray->hide(); } _contextMenu->clear(); - slotRebuildRecentMenus(); } else { _contextMenu.reset(new QMenu()); + + // Update the context menu whenever we're about to show it + // to the user. + connect(_contextMenu.data(), SIGNAL(aboutToShow()), SLOT(setupContextMenu())); + _recentActionsMenu = new QMenu(tr("Recent Changes"), _contextMenu.data()); // this must be called only once after creating the context menu, or // it will trigger a bug in Ubuntu's SNI bridge patch (11.10, 12.04). @@ -477,6 +481,8 @@ void ownCloudGui::setupContextMenu() #endif } _contextMenu->setTitle(Theme::instance()->appNameGUI() ); + slotRebuildRecentMenus(); + // We must call deleteLater because we might be called from the press in one of the actions. foreach (auto menu, _accountMenus) { menu->deleteLater(); } _accountMenus.clear(); @@ -552,6 +558,11 @@ void ownCloudGui::setupContextMenu() } } +void ownCloudGui::setupContextMenuIfVisible() +{ + if (_contextMenu && _contextMenu->isVisible()) + setupContextMenu(); +} void ownCloudGui::slotShowTrayMessage(const QString &title, const QString &msg) { @@ -711,7 +722,11 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const ProgressInfo& } _recentItemsActions.append(action); - slotRebuildRecentMenus(); + // Update the "Recent" menu if the context menu is being shown, + // otherwise it'll be updated later, when the context menu is opened. + if (_contextMenu && _contextMenu->isVisible()) { + slotRebuildRecentMenus(); + } } if (progress.isUpdatingEstimates() diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 74f658ba2f..982b4825b1 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -57,6 +57,7 @@ signals: public slots: void setupContextMenu(); + void setupContextMenuIfVisible(); void slotComputeOverallSyncStatus(); void slotShowTrayMessage(const QString &title, const QString &msg); void slotShowOptionalTrayMessage(const QString &title, const QString &msg);