mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-23 12:55:44 +03:00
Merge pull request #2531 from nextcloud/bring_back_systray_menu_pause_sync_action
Bring back the "Pause sync" action in the systray context menu
This commit is contained in:
commit
2e97a7fb74
4 changed files with 62 additions and 44 deletions
|
@ -76,12 +76,6 @@ ownCloudGui::ownCloudGui(Application *parent)
|
|||
connect(_tray.data(), &QSystemTrayIcon::activated,
|
||||
this, &ownCloudGui::slotTrayClicked);
|
||||
|
||||
connect(_tray.data(), &Systray::pauseSync,
|
||||
this, &ownCloudGui::slotPauseAllFolders);
|
||||
|
||||
connect(_tray.data(), &Systray::resumeSync,
|
||||
this, &ownCloudGui::slotUnpauseAllFolders);
|
||||
|
||||
connect(_tray.data(), &Systray::openHelp,
|
||||
this, &ownCloudGui::slotHelp);
|
||||
|
||||
|
@ -507,41 +501,11 @@ void ownCloudGui::slotLogout()
|
|||
}
|
||||
}
|
||||
|
||||
void ownCloudGui::slotUnpauseAllFolders()
|
||||
{
|
||||
setPauseOnAllFoldersHelper(false);
|
||||
}
|
||||
|
||||
void ownCloudGui::slotPauseAllFolders()
|
||||
{
|
||||
setPauseOnAllFoldersHelper(true);
|
||||
}
|
||||
|
||||
void ownCloudGui::slotNewAccountWizard()
|
||||
{
|
||||
OwncloudSetupWizard::runWizard(qApp, SLOT(slotownCloudWizardDone(int)));
|
||||
}
|
||||
|
||||
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);
|
||||
if (pause) {
|
||||
f->slotTerminateSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ownCloudGui::slotShowGuiMessage(const QString &title, const QString &message)
|
||||
{
|
||||
auto *msgBox = new QMessageBox;
|
||||
|
|
|
@ -108,13 +108,9 @@ public slots:
|
|||
private slots:
|
||||
void slotLogin();
|
||||
void slotLogout();
|
||||
void slotUnpauseAllFolders();
|
||||
void slotPauseAllFolders();
|
||||
void slotNewAccountWizard();
|
||||
|
||||
private:
|
||||
void setPauseOnAllFoldersHelper(bool pause);
|
||||
|
||||
QPointer<Systray> _tray;
|
||||
QPointer<SettingsDialog> _settingsDialog;
|
||||
QPointer<LogBrowser> _logBrowser;
|
||||
|
|
|
@ -93,9 +93,28 @@ Systray::Systray()
|
|||
} else {
|
||||
contextMenu->addAction(tr("Open main dialog"), this, &Systray::openMainDialog);
|
||||
}
|
||||
|
||||
auto pauseAction = contextMenu->addAction(tr("Pause sync"), this, &Systray::slotPauseAllFolders);
|
||||
auto resumeAction = contextMenu->addAction(tr("Resume sync"), this, &Systray::slotUnpauseAllFolders);
|
||||
contextMenu->addAction(tr("Settings"), this, &Systray::openSettings);
|
||||
contextMenu->addAction(tr("Exit %1").arg(Theme::instance()->appNameGUI()), this, &Systray::shutdown);
|
||||
setContextMenu(contextMenu);
|
||||
|
||||
connect(contextMenu, &QMenu::aboutToShow, [=] {
|
||||
const auto folders = FolderMan::instance()->map();
|
||||
|
||||
const auto allPaused = std::all_of(std::cbegin(folders), std::cend(folders), [](Folder *f) { return f->syncPaused(); });
|
||||
const auto pauseText = folders.size() > 1 ? tr("Pause sync for all") : tr("Pause sync");
|
||||
pauseAction->setText(pauseText);
|
||||
pauseAction->setVisible(!allPaused);
|
||||
pauseAction->setEnabled(!allPaused);
|
||||
|
||||
const auto anyPaused = std::any_of(std::cbegin(folders), std::cend(folders), [](Folder *f) { return f->syncPaused(); });
|
||||
const auto resumeText = folders.size() > 1 ? tr("Resume sync for all") : tr("Resume sync");
|
||||
resumeAction->setText(resumeText);
|
||||
resumeAction->setVisible(anyPaused);
|
||||
resumeAction->setEnabled(anyPaused);
|
||||
});
|
||||
#endif
|
||||
|
||||
connect(UserModel::instance(), &UserModel::newUserSelected,
|
||||
|
@ -136,6 +155,41 @@ void Systray::slotNewUserSelected()
|
|||
UserAppsModel::instance()->buildAppList();
|
||||
}
|
||||
|
||||
void Systray::slotUnpauseAllFolders()
|
||||
{
|
||||
setPauseOnAllFoldersHelper(false);
|
||||
}
|
||||
|
||||
void Systray::slotPauseAllFolders()
|
||||
{
|
||||
setPauseOnAllFoldersHelper(true);
|
||||
}
|
||||
|
||||
void Systray::setPauseOnAllFoldersHelper(bool pause)
|
||||
{
|
||||
// For some reason we get the raw pointer from Folder::accountState()
|
||||
// that's why we need a list of raw pointers for the call to contains
|
||||
// later on...
|
||||
const auto accounts = [=] {
|
||||
const auto ptrList = AccountManager::instance()->accounts();
|
||||
auto result = QList<AccountState *>();
|
||||
result.reserve(ptrList.size());
|
||||
std::transform(std::cbegin(ptrList), std::cend(ptrList), std::back_inserter(result), [](const AccountStatePtr &account) {
|
||||
return account.data();
|
||||
});
|
||||
return result;
|
||||
}();
|
||||
const auto folders = FolderMan::instance()->map();
|
||||
for (auto f : folders) {
|
||||
if (accounts.contains(f->accountState())) {
|
||||
f->setSyncPaused(pause);
|
||||
if (pause) {
|
||||
f->slotTerminateSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Systray::isOpen()
|
||||
{
|
||||
return _isOpen;
|
||||
|
@ -187,10 +241,10 @@ void Systray::pauseResumeSync()
|
|||
{
|
||||
if (_syncIsPaused) {
|
||||
_syncIsPaused = false;
|
||||
emit resumeSync();
|
||||
slotUnpauseAllFolders();
|
||||
} else {
|
||||
_syncIsPaused = true;
|
||||
emit pauseSync();
|
||||
slotPauseAllFolders();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,8 +66,6 @@ signals:
|
|||
void openSettings();
|
||||
void openHelp();
|
||||
void shutdown();
|
||||
void pauseSync();
|
||||
void resumeSync();
|
||||
|
||||
Q_INVOKABLE void hideWindow();
|
||||
Q_INVOKABLE void showWindow();
|
||||
|
@ -76,7 +74,13 @@ signals:
|
|||
public slots:
|
||||
void slotNewUserSelected();
|
||||
|
||||
private slots:
|
||||
void slotUnpauseAllFolders();
|
||||
void slotPauseAllFolders();
|
||||
|
||||
private:
|
||||
void setPauseOnAllFoldersHelper(bool pause);
|
||||
|
||||
static Systray *_instance;
|
||||
Systray();
|
||||
|
||||
|
|
Loading…
Reference in a new issue