Skip to content

Commit a12020d

Browse files
committed
Remove accounts from system tray and simplify the menu even more
Fixes: #129
1 parent d966496 commit a12020d

File tree

4 files changed

+38
-82
lines changed

4 files changed

+38
-82
lines changed

src/gui/owncloudgui.cpp

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -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

122117
ownCloudGui::~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-
506447
void ownCloudGui::slotShowSettings()
507448
{
508449
raise();

src/gui/owncloudgui.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public Q_SLOTS:
7676
void slotTrayMessageIfServerUnsupported(Account *account);
7777

7878
private:
79-
void setPauseOnAllFoldersHelper(const QList<AccountStatePtr> &accounts, bool pause);
80-
81-
void updateContextMenu();
79+
void setContextMenu();
8280

8381
Systray *_tray;
8482
SettingsDialog *_settingsDialog;

src/gui/scheduling/syncscheduler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,34 @@ void SyncScheduler::start()
193193
{
194194
_running = true;
195195
startNext();
196+
Q_EMIT isRunningChanged();
196197
}
197198

198199
void SyncScheduler::stop()
199200
{
200201
_running = false;
202+
Q_EMIT isRunningChanged();
201203
}
202204

203205
bool SyncScheduler::hasCurrentRunningSyncRunning() const
204206
{
205207
return _currentSync;
206208
}
207209

210+
Folder *SyncScheduler::currentSync()
211+
{
212+
return _currentSync;
213+
}
214+
208215
void SyncScheduler::setPauseSyncWhenMetered(bool pauseSyncWhenMetered)
209216
{
210217
_pauseSyncWhenMetered = pauseSyncWhenMetered;
211218
if (!pauseSyncWhenMetered) {
212219
startNext();
213220
}
214221
}
222+
223+
bool SyncScheduler::isRunning() const
224+
{
225+
return _running;
226+
}

src/gui/scheduling/syncscheduler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ class SyncScheduler : public QObject
5555
void stop();
5656

5757
bool hasCurrentRunningSyncRunning() const;
58+
Folder *currentSync();
5859

5960
void setPauseSyncWhenMetered(bool pauseSyncWhenMetered);
6061

62+
bool isRunning() const;
63+
64+
Q_SIGNALS:
65+
void isRunningChanged();
6166

6267
private:
6368
void startNext();

0 commit comments

Comments
 (0)