@@ -110,13 +110,8 @@ ownCloudGui::ownCloudGui(Application *parent)
110110
111111 // init systray
112112 slotComputeOverallSyncStatus ();
113- updateContextMenu ();
113+ setContextMenu ();
114114 _tray->show ();
115-
116- connect (FolderMan::instance (), &FolderMan::folderSyncStateChange, this , &ownCloudGui::slotComputeOverallSyncStatus);
117- connect (FolderMan::instance (), &FolderMan::folderSyncStateChange, this , &ownCloudGui::updateContextMenu);
118- connect (FolderMan::instance (), &FolderMan::folderListChanged, this , &ownCloudGui::updateContextMenu);
119- connect (AccountManager::instance (), &AccountManager::accountsChanged, this , &ownCloudGui::updateContextMenu);
120115}
121116
122117ownCloudGui::~ownCloudGui ()
@@ -250,73 +245,29 @@ void ownCloudGui::hideAndShowTray()
250245 _tray->show ();
251246}
252247
253- void ownCloudGui::updateContextMenu ()
248+ void ownCloudGui::setContextMenu ()
254249{
255- qDebug () << " updateContextMenu" ;
256- if (auto *menu = _tray->contextMenu ()) {
257- menu->deleteLater ();
258- }
250+ Q_ASSERT (!_tray->contextMenu ());
259251 auto *menu = new QMenu (Theme::instance ()->appNameGUI ());
260252
261- const auto &accountList = AccountManager::instance ()->accounts ();
262-
263- bool atLeastOnePaused = false ;
264-
265- for (auto *f : FolderMan::instance ()->folders ()) {
266- if (f->isSyncPaused ()) {
267- atLeastOnePaused = true ;
268- }
269- }
270-
271253 menu->addAction (Theme::instance ()->applicationIcon (), tr (" Show %1" ).arg (Theme::instance ()->appNameGUI ()), this , &ownCloudGui::slotShowSettings);
272- menu->addSeparator ();
273-
274- if (accountList.isEmpty ()) {
275- menu->addAction (tr (" Create a new account" ), this , &ownCloudGui::runNewAccountWizard);
276- } else {
277- if (atLeastOnePaused) {
278- menu->addAction (tr (" Resume synchronization" ), this , [this ] { setPauseOnAllFoldersHelper (AccountManager::instance ()->accounts (), false ); });
279- } else {
280- menu->addAction (tr (" Stop synchronization" ), this , [this ] { setPauseOnAllFoldersHelper (AccountManager::instance ()->accounts (), true ); });
281- }
282- menu->addSeparator ();
283-
284- // submenus for accounts
285- for (const auto &account : accountList) {
286- auto *accountMenu = menu->addMenu (account->account ()->displayNameWithHost ());
287- accountMenu->addAction (CommonStrings::showInWebBrowser (), this , [account] { QDesktopServices::openUrl (account->account ()->url ()); });
288-
289- FolderMan *folderMan = FolderMan::instance ();
290- const auto &map = folderMan->folders ();
291- bool onePaused = false ;
292- for (auto *folder : map) {
293- if (folder->accountState () != account.data ()) {
294- continue ;
295- }
296-
297- if (folder->isSyncPaused ()) {
298- onePaused = true ;
299- }
300- accountMenu->addAction (CommonStrings::showInFileBrowser (folder->path ()), this , [folder] {
301- qCInfo (lcApplication) << " opening local URL " << folder->path ();
302- QDesktopServices::openUrl (QUrl::fromLocalFile (folder->path ()));
303- });
304- }
305-
306- accountMenu->addSeparator ();
307- if (onePaused) {
308- accountMenu->addAction (tr (" Resume synchronization" ), this , [account, this ] { setPauseOnAllFoldersHelper ({account}, false ); });
309- } else {
310- accountMenu->addAction (tr (" Stop synchronization" ), this , [account, this ] { setPauseOnAllFoldersHelper ({account}, true ); });
311- }
312-
313- if (account->isSignedOut ()) {
314- accountMenu->addAction (tr (" Log in..." ), this , [account] { account->signIn (); });
315- } else {
316- accountMenu->addAction (tr (" Log out" ), this , [account] { account->signOutByUi (); });
254+ auto *pauseResume = new QAction (menu);
255+ auto updatePauseResumeAction = [pauseResume] {
256+ pauseResume->setText (FolderMan::instance ()->scheduler ()->isRunning () ? tr (" Pause synchronizations" ) : tr (" Resume synchronizations" ));
257+ };
258+ connect (pauseResume, &QAction::triggered, FolderMan::instance ()->scheduler (), [] {
259+ if (FolderMan::instance ()->scheduler ()->isRunning ()) {
260+ if (auto *currentSync = FolderMan::instance ()->scheduler ()->currentSync ()) {
261+ currentSync->slotTerminateSync (tr (" Synchronization paused" ));
317262 }
263+ FolderMan::instance ()->scheduler ()->stop ();
264+ } else {
265+ FolderMan::instance ()->scheduler ()->start ();
318266 }
319- }
267+ });
268+ connect (FolderMan::instance ()->scheduler (), &SyncScheduler::isRunningChanged, pauseResume, updatePauseResumeAction);
269+ menu->addAction (pauseResume);
270+ updatePauseResumeAction ();
320271
321272 if (_app->debugMode ()) {
322273 menu->addSeparator ();
@@ -336,6 +287,8 @@ void ownCloudGui::updateContextMenu()
336287 captivePortalCheckbox->setCheckable (true );
337288 captivePortalCheckbox->setChecked (NetworkInformation::instance ()->isForcedCaptivePortal ());
338289 connect (captivePortalCheckbox, &QAction::triggered, this , [](bool checked) { NetworkInformation::instance ()->setForcedCaptivePortal (checked); });
290+ connect (NetworkInformation::instance (), &NetworkInformation::isBehindCaptivePortalChanged, captivePortalCheckbox,
291+ [captivePortalCheckbox] { captivePortalCheckbox->setChecked (NetworkInformation::instance ()->isForcedCaptivePortal ()); });
339292 }
340293
341294 menu->addSeparator ();
@@ -491,18 +444,6 @@ void ownCloudGui::runNewAccountWizard()
491444 }
492445}
493446
494- void ownCloudGui::setPauseOnAllFoldersHelper (const QList<AccountStatePtr> &accounts, bool pause)
495- {
496- for (auto *f : FolderMan::instance ()->folders ()) {
497- if (accounts.contains (f->accountState ())) {
498- f->setSyncPaused (pause);
499- if (pause) {
500- f->slotTerminateSync (tr (" User paused sync for account '%1'" ).arg (f->accountState ()->account ()->displayNameWithHost ()));
501- }
502- }
503- }
504- }
505-
506447void ownCloudGui::slotShowSettings ()
507448{
508449 raise ();
0 commit comments