Skip to content

Commit

Permalink
Reduce the usage of modal dialogs
Browse files Browse the repository at this point in the history
Fixes: #11304
Fixes: #11032
Fixes: #11208
  • Loading branch information
TheOneRing committed Jan 17, 2024
1 parent 6962d1f commit db1c960
Show file tree
Hide file tree
Showing 20 changed files with 376 additions and 307 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/11304
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Use less modal dialogs

As the rather high number of modal dialogs we used caused different issues on different platforms,
we decided to use them less often and try other concepts.

https://github.com/owncloud/client/issues/11304
https://github.com/owncloud/client/issues/11032
https://github.com/owncloud/client/issues/11208
1 change: 0 additions & 1 deletion src/gui/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ AboutDialog::AboutDialog(QWidget *parent)
, ui(new Ui::AboutDialog)
{
ui->setupUi(this);
setWindowTitle(tr("About %1").arg(Theme::instance()->appNameGUI()));
ui->aboutText->setText(Theme::instance()->about());
ui->icon->setPixmap(Theme::instance()->aboutIcon().pixmap(256));
ui->versionInfo->setText(Theme::instance()->aboutVersions(Theme::VersionFormat::RichText));
Expand Down
66 changes: 54 additions & 12 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


#include "accountsettings.h"
#include "scheduling/syncscheduler.h"
#include "ui_accountsettings.h"


#include "account.h"
#include "accountmanager.h"
#include "accountstate.h"
Expand All @@ -28,18 +28,22 @@
#include "folderman.h"
#include "folderstatusdelegate.h"
#include "folderstatusmodel.h"
#include "folderwizard/folderwizard.h"
#include "gui/models/models.h"
#include "guiutility.h"
#include "loginrequireddialog.h"
#include "oauthloginwidget.h"
#include "quotainfo.h"
#include "scheduling/syncscheduler.h"
#include "settingsdialog.h"
#include "theme.h"
#include "tooltipupdater.h"

#include "folderwizard/folderwizard.h"

#include <QAction>
#include <QClipboard>
#include <QDesktopServices>
#include <QDir>
#include <QGroupBox>
#include <QIcon>
#include <QKeySequence>
#include <QMessageBox>
Expand All @@ -49,9 +53,10 @@
#include <QToolTip>
#include <QTreeView>

#include "gui/models/models.h"
#include "loginrequireddialog.h"
#include "oauthloginwidget.h"

namespace {
constexpr auto modalWidgetStretchedMarginC = 50;
}

namespace OCC {

Expand Down Expand Up @@ -421,17 +426,16 @@ void AccountSettings::slotAddFolder()
{
FolderMan::instance()->setSyncEnabled(false); // do not start more syncs.

FolderWizard *folderWizard = new FolderWizard(_accountState, ocApp()->gui()->settingsDialog());
FolderWizard *folderWizard = new FolderWizard(_accountState, this);
folderWizard->setAttribute(Qt::WA_DeleteOnClose);
folderWizard->resize(ocApp()->gui()->settingsDialog()->sizeHintForChild());

connect(folderWizard, &QDialog::accepted, this, &AccountSettings::slotFolderWizardAccepted);
connect(folderWizard, &QDialog::rejected, this, [] {
qCInfo(lcAccountSettings) << "Folder wizard cancelled";
FolderMan::instance()->setSyncEnabled(true);
});
folderWizard->open();
ocApp()->gui()->raiseDialog(folderWizard);

addModalWidget(folderWizard, AccountSettings::ModalWidgetSizePolicy::Expanding);
}


Expand Down Expand Up @@ -486,7 +490,6 @@ void AccountSettings::slotRemoveCurrentFolder()
}
});
messageBox->open();
ownCloudGui::raiseDialog(messageBox);
}
}

Expand Down Expand Up @@ -638,8 +641,8 @@ void AccountSettings::slotForceSyncCurrentFolder()
QMessageBox::Yes | QMessageBox::No, ocApp()->gui()->settingsDialog());
messageBox->setAttribute(Qt::WA_DeleteOnClose);
connect(messageBox, &QMessageBox::accepted, this, [this, selectedFolder] { doForceSyncCurrentFolder(selectedFolder); });
ownCloudGui::raise();
messageBox->open();
ownCloudGui::raiseDialog(messageBox);
} else {
doForceSyncCurrentFolder(selectedFolder);
}
Expand Down Expand Up @@ -805,9 +808,48 @@ void AccountSettings::slotLinkActivated(const QString &link)

AccountSettings::~AccountSettings()
{
_goingDown = true;
delete ui;
}

void AccountSettings::addModalWidget(QWidget *widget, ModalWidgetSizePolicy sizePolicy)
{
// create a widget filling the stacked widget
// this widget contains a wrapping group box with widget as content
auto *outerWidget = new QWidget;
auto *groupBox = new QGroupBox;

switch (sizePolicy) {
case ModalWidgetSizePolicy::Expanding: {
auto *outerLayout = new QHBoxLayout(outerWidget);
outerLayout->setContentsMargins(modalWidgetStretchedMarginC, modalWidgetStretchedMarginC, modalWidgetStretchedMarginC, modalWidgetStretchedMarginC);
outerLayout->addWidget(groupBox);
auto *layout = new QHBoxLayout(groupBox);
layout->addWidget(widget);
} break;
case ModalWidgetSizePolicy::Minimum: {
auto *outerLayout = new QGridLayout(outerWidget);
outerLayout->addWidget(groupBox, 0, 0, Qt::AlignCenter);
auto *layout = new QHBoxLayout(groupBox);
layout->addWidget(widget);
} break;
}
groupBox->setTitle(widget->windowTitle());

ui->stackedWidget->addWidget(outerWidget);
ui->stackedWidget->setCurrentWidget(outerWidget);

// the widget is supposed to behave like a dialog and we connect to its destuction
Q_ASSERT(widget->testAttribute(Qt::WA_DeleteOnClose));
connect(widget, &QWidget::destroyed, this, [this, outerWidget] {
outerWidget->deleteLater();
if (!_goingDown) {
ocApp()->gui()->settingsDialog()->ceaseModality(_accountState->account().get());
}
});
ocApp()->gui()->settingsDialog()->requestModality(_accountState->account().get());
}

void AccountSettings::refreshSelectiveSyncStatus()
{
QString msg;
Expand Down
7 changes: 7 additions & 0 deletions src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ class AccountSettings : public QWidget
Q_PROPERTY(AccountStatePtr accountState MEMBER _accountState)

public:
enum class ModalWidgetSizePolicy { Minimum = QSizePolicy::Minimum, Expanding = QSizePolicy::Expanding };
Q_ENUM(ModalWidgetSizePolicy);

explicit AccountSettings(const AccountStatePtr &accountState, QWidget *parent = nullptr);
~AccountSettings() override;

AccountStatePtr accountsState() const { return _accountState; }

void addModalWidget(QWidget *widget, ModalWidgetSizePolicy sizePolicy);

signals:
void folderChanged();
void showIssuesList();
Expand Down Expand Up @@ -103,6 +108,8 @@ protected slots:
AccountStatePtr _accountState;
QAction *_toggleSignInOutAction;
QAction *_toggleReconnect;
// are we already in the destructor
bool _goingDown = false;
};

} // namespace OCC
Expand Down
Loading

0 comments on commit db1c960

Please sign in to comment.