diff options
-rw-r--r-- | src/gui/accountsettings.cpp | 107 | ||||
-rw-r--r-- | src/gui/accountsettings.h | 2 | ||||
-rw-r--r-- | src/gui/wizard/owncloudadvancedsetuppage.cpp | 55 |
3 files changed, 77 insertions, 87 deletions
diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 334f8e10a..49319cc41 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -479,8 +479,7 @@ void AccountSettings::slotFolderWizardRejected() void AccountSettings::slotRemoveCurrentFolder() { - FolderMan *folderMan = FolderMan::instance(); - auto folder = folderMan->folder(selectedFolderAlias()); + auto folder = FolderMan::instance()->folder(selectedFolderAlias()); QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); if (selected.isValid() && folder) { int row = selected.row(); @@ -488,28 +487,27 @@ void AccountSettings::slotRemoveCurrentFolder() qCInfo(lcAccountSettings) << "Remove Folder alias " << folder->alias(); QString shortGuiLocalPath = folder->shortGuiLocalPath(); - QMessageBox messageBox(QMessageBox::Question, + auto messageBox = new QMessageBox(QMessageBox::Question, tr("Confirm Folder Sync Connection Removal"), tr("<p>Do you really want to stop syncing the folder <i>%1</i>?</p>" "<p><b>Note:</b> This will <b>not</b> delete any files.</p>") .arg(shortGuiLocalPath), QMessageBox::NoButton, this); + messageBox->setAttribute(Qt::WA_DeleteOnClose); QPushButton *yesButton = - messageBox.addButton(tr("Remove Folder Sync Connection"), QMessageBox::YesRole); - messageBox.addButton(tr("Cancel"), QMessageBox::NoRole); - - messageBox.exec(); - if (messageBox.clickedButton() != yesButton) { - return; - } - - folderMan->removeFolder(folder); - _model->removeRow(row); - - // single folder fix to show add-button and hide remove-button - - emit folderChanged(); + messageBox->addButton(tr("Remove Folder Sync Connection"), QMessageBox::YesRole); + messageBox->addButton(tr("Cancel"), QMessageBox::NoRole); + connect(messageBox, &QMessageBox::finished, this, [messageBox, yesButton, folder, row, this]{ + if (messageBox->clickedButton() == yesButton) { + FolderMan::instance()->removeFolder(folder); + _model->removeRow(row); + + // single folder fix to show add-button and hide remove-button + emit folderChanged(); + } + }); + messageBox->open(); } } @@ -692,7 +690,7 @@ void AccountSettings::showConnectionLabel(const QString &message, QStringList er ui->accountStatus->setVisible(!message.isEmpty()); } -void AccountSettings::slotEnableCurrentFolder() +void AccountSettings::slotEnableCurrentFolder(bool terminate) { auto alias = selectedFolderAlias(); @@ -700,7 +698,6 @@ void AccountSettings::slotEnableCurrentFolder() FolderMan *folderMan = FolderMan::instance(); qCInfo(lcAccountSettings) << "Application: enable folder with alias " << alias; - bool terminate = false; bool currentlyPaused = false; // this sets the folder status to disabled but does not interrupt it. @@ -709,25 +706,19 @@ void AccountSettings::slotEnableCurrentFolder() return; } currentlyPaused = f->syncPaused(); - if (!currentlyPaused) { + if (!currentlyPaused && !terminate) { // check if a sync is still running and if so, ask if we should terminate. if (f->isBusy()) { // its still running -#if defined(Q_OS_MAC) - QWidget *parent = this; - Qt::WindowFlags flags = Qt::Sheet; -#else - QWidget *parent = nullptr; - Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint; // default flags -#endif - QMessageBox msgbox(QMessageBox::Question, tr("Sync Running"), + auto msgbox = new QMessageBox(QMessageBox::Question, tr("Sync Running"), tr("The syncing operation is running.<br/>Do you want to terminate it?"), - QMessageBox::Yes | QMessageBox::No, parent, flags); - msgbox.setDefaultButton(QMessageBox::Yes); - int reply = msgbox.exec(); - if (reply == QMessageBox::Yes) - terminate = true; - else - return; // do nothing + QMessageBox::Yes | QMessageBox::No, this); + msgbox->setAttribute(Qt::WA_DeleteOnClose); + msgbox->setDefaultButton(QMessageBox::Yes); + connect(msgbox, &QMessageBox::accepted, this, [this]{ + slotEnableCurrentFolder(true); + }); + msgbox->open(); + return; } } @@ -1046,33 +1037,27 @@ void AccountSettings::slotDeleteAccount() { // Deleting the account potentially deletes 'this', so // the QMessageBox should be destroyed before that happens. - { - QMessageBox messageBox(QMessageBox::Question, - tr("Confirm Account Removal"), - tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>" - "<p><b>Note:</b> This will <b>not</b> delete any files.</p>") - .arg(_accountState->account()->displayName()), - QMessageBox::NoButton, - this); - QPushButton *yesButton = - messageBox.addButton(tr("Remove connection"), QMessageBox::YesRole); - messageBox.addButton(tr("Cancel"), QMessageBox::NoRole); - - messageBox.exec(); - if (messageBox.clickedButton() != yesButton) { - return; + auto messageBox = new QMessageBox(QMessageBox::Question, + tr("Confirm Account Removal"), + tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>" + "<p><b>Note:</b> This will <b>not</b> delete any files.</p>") + .arg(_accountState->account()->displayName()), + QMessageBox::NoButton, + this); + auto yesButton = messageBox->addButton(tr("Remove connection"), QMessageBox::YesRole); + messageBox->addButton(tr("Cancel"), QMessageBox::NoRole); + messageBox->setAttribute(Qt::WA_DeleteOnClose); + connect(messageBox, &QMessageBox::finished, this, [this, messageBox, yesButton]{ + if (messageBox->clickedButton() == yesButton) { + // Else it might access during destruction. This should be better handled by it having a QSharedPointer + _model->setAccountState(nullptr); + + auto manager = AccountManager::instance(); + manager->deleteAccount(_accountState); + manager->save(); } - } - - // Else it might access during destruction. This should be better handled by it having a QSharedPointer - _model->setAccountState(nullptr); - - auto manager = AccountManager::instance(); - manager->deleteAccount(_accountState); - manager->save(); - - // IMPORTANT: "this" is deleted from this point on. We should probably remove this synchronous - // .exec() QMessageBox magic above as it recurses into the event loop. + }); + messageBox->open(); } bool AccountSettings::event(QEvent *e) diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index b768d180e..a791101c7 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -70,7 +70,7 @@ public slots: protected slots: void slotAddFolder(); - void slotEnableCurrentFolder(); + void slotEnableCurrentFolder(bool terminate = false); void slotScheduleCurrentFolder(); void slotScheduleCurrentFolderForceFullDiscovery(); void slotForceSyncCurrentFolder(); diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp index d24a84680..26aa6fc39 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.cpp +++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp @@ -351,36 +351,41 @@ void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked() { AccountPtr acc = static_cast<OwncloudWizard *>(wizard())->account(); SelectiveSyncDialog *dlg = new SelectiveSyncDialog(acc, _remoteFolder, _selectiveSyncBlacklist, this); + dlg->setAttribute(Qt::WA_DeleteOnClose); + + connect(dlg, &SelectiveSyncDialog::finished, this, [this, dlg]{ + const int result = dlg->result(); + bool updateBlacklist = false; + + // We need to update the selective sync blacklist either when the dialog + // was accepted in that + // case the stub blacklist of / was expanded to the actual list of top + // level folders by the selective sync dialog. + if (result == QDialog::Accepted) { + _selectiveSyncBlacklist = dlg->createBlackList(); + updateBlacklist = true; + } else if (result == QDialog::Rejected && _selectiveSyncBlacklist == QStringList("/")) { + _selectiveSyncBlacklist = dlg->oldBlackList(); + updateBlacklist = true; + } - const int result = dlg->exec(); - bool updateBlacklist = false; - - // We need to update the selective sync blacklist either when the dialog - // was accepted in that - // case the stub blacklist of / was expanded to the actual list of top - // level folders by the selective sync dialog. - if (result == QDialog::Accepted) { - _selectiveSyncBlacklist = dlg->createBlackList(); - updateBlacklist = true; - } else if (result == QDialog::Rejected && _selectiveSyncBlacklist == QStringList("/")) { - _selectiveSyncBlacklist = dlg->oldBlackList(); - updateBlacklist = true; - } - - if (updateBlacklist) { - if (!_selectiveSyncBlacklist.isEmpty()) { - auto s = dlg->estimatedSize(); - if (s > 0) { - _ui.lSelectiveSyncSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(s))); + if (updateBlacklist) { + if (!_selectiveSyncBlacklist.isEmpty()) { + auto s = dlg->estimatedSize(); + if (s > 0) { + _ui.lSelectiveSyncSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(s))); + } else { + _ui.lSelectiveSyncSizeLabel->setText(QString()); + } } else { + setRadioChecked(_ui.rSyncEverything); _ui.lSelectiveSyncSizeLabel->setText(QString()); } - } else { - setRadioChecked(_ui.rSyncEverything); - _ui.lSelectiveSyncSizeLabel->setText(QString()); + wizard()->setProperty("blacklist", _selectiveSyncBlacklist); } - wizard()->setProperty("blacklist", _selectiveSyncBlacklist); - } + + }); + dlg->open(); } void OwncloudAdvancedSetupPage::slotVirtualFileSyncClicked() |