Move pause/unpause helpers to Systray

We had signals just to call those backs in ownCloudGui, they were
otherwise unused. So let's move them inside of Systray since it's
specific to it anyway.

Also fix the dangerous call to sender(). We can call this function
without going through a signal/slot connection and also it's never
connected to an AccountState.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
Kevin Ottens 2020-10-08 16:32:10 +02:00 committed by Camila (Rebase PR Action)
parent 3ffc699058
commit 1288ee0437
4 changed files with 43 additions and 44 deletions

View file

@ -76,12 +76,6 @@ ownCloudGui::ownCloudGui(Application *parent)
connect(_tray.data(), &QSystemTrayIcon::activated, connect(_tray.data(), &QSystemTrayIcon::activated,
this, &ownCloudGui::slotTrayClicked); this, &ownCloudGui::slotTrayClicked);
connect(_tray.data(), &Systray::pauseSync,
this, &ownCloudGui::slotPauseAllFolders);
connect(_tray.data(), &Systray::resumeSync,
this, &ownCloudGui::slotUnpauseAllFolders);
connect(_tray.data(), &Systray::openHelp, connect(_tray.data(), &Systray::openHelp,
this, &ownCloudGui::slotHelp); this, &ownCloudGui::slotHelp);
@ -507,41 +501,11 @@ void ownCloudGui::slotLogout()
} }
} }
void ownCloudGui::slotUnpauseAllFolders()
{
setPauseOnAllFoldersHelper(false);
}
void ownCloudGui::slotPauseAllFolders()
{
setPauseOnAllFoldersHelper(true);
}
void ownCloudGui::slotNewAccountWizard() void ownCloudGui::slotNewAccountWizard()
{ {
OwncloudSetupWizard::runWizard(qApp, SLOT(slotownCloudWizardDone(int))); 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) void ownCloudGui::slotShowGuiMessage(const QString &title, const QString &message)
{ {
auto *msgBox = new QMessageBox; auto *msgBox = new QMessageBox;

View file

@ -108,13 +108,9 @@ public slots:
private slots: private slots:
void slotLogin(); void slotLogin();
void slotLogout(); void slotLogout();
void slotUnpauseAllFolders();
void slotPauseAllFolders();
void slotNewAccountWizard(); void slotNewAccountWizard();
private: private:
void setPauseOnAllFoldersHelper(bool pause);
QPointer<Systray> _tray; QPointer<Systray> _tray;
QPointer<SettingsDialog> _settingsDialog; QPointer<SettingsDialog> _settingsDialog;
QPointer<LogBrowser> _logBrowser; QPointer<LogBrowser> _logBrowser;

View file

@ -136,6 +136,41 @@ void Systray::slotNewUserSelected()
UserAppsModel::instance()->buildAppList(); 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() bool Systray::isOpen()
{ {
return _isOpen; return _isOpen;
@ -187,10 +222,10 @@ void Systray::pauseResumeSync()
{ {
if (_syncIsPaused) { if (_syncIsPaused) {
_syncIsPaused = false; _syncIsPaused = false;
emit resumeSync(); slotUnpauseAllFolders();
} else { } else {
_syncIsPaused = true; _syncIsPaused = true;
emit pauseSync(); slotPauseAllFolders();
} }
} }

View file

@ -66,8 +66,6 @@ signals:
void openSettings(); void openSettings();
void openHelp(); void openHelp();
void shutdown(); void shutdown();
void pauseSync();
void resumeSync();
Q_INVOKABLE void hideWindow(); Q_INVOKABLE void hideWindow();
Q_INVOKABLE void showWindow(); Q_INVOKABLE void showWindow();
@ -76,7 +74,13 @@ signals:
public slots: public slots:
void slotNewUserSelected(); void slotNewUserSelected();
private slots:
void slotUnpauseAllFolders();
void slotPauseAllFolders();
private: private:
void setPauseOnAllFoldersHelper(bool pause);
static Systray *_instance; static Systray *_instance;
Systray(); Systray();