Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare AccountModalWidget to allow more schenarios #11564

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 53 additions & 1 deletion src/gui/accountmodalwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,54 @@
#include "accountmodalwidget.h"
#include "ui_accountmodalwidget.h"

#include "resources/resources.h"

#include <QMessageBox>
#include <QPushButton>
#include <QQuickWidget>

namespace OCC {
AccountModalWidget::AccountModalWidget(const QString &title, QWidget *widget, QWidget *parent)

namespace {
auto *createQmlWidget(const QUrl &url, const QList<QQmlContext::PropertyPair> &properties)
{
auto *widget = new QQuickWidget;
widget->engine()->rootContext()->setContextProperties(properties);
widget->engine()->addImageProvider(QStringLiteral("ownCloud"), new Resources::CoreImageProvider());
widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
widget->setSource(url);
if (!widget->errors().isEmpty()) {
auto box = new QMessageBox(QMessageBox::Critical, QStringLiteral("QML Error"), QDebug::toString(widget->errors()));
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
qFatal("A qml error occured %s", qPrintable(QDebug::toString(widget->errors())));
}
return widget;
}
}

AccountModalWidget::AccountModalWidget(
const QString &title, const QUrl &qmlSrc, const QList<QQmlContext::PropertyPair> &properties, const QList<Button> &buttons, QWidget *parent)
: AccountModalWidget(title, createQmlWidget(qmlSrc, properties), buttons, parent)
{
}


AccountModalWidget::AccountModalWidget(const QString &title, QWidget *widget, const QList<Button> &buttons, QWidget *parent)
: QWidget(parent)
, ui(new Ui::AccountModalWidget)
{
ui->setupUi(this);
ui->groupBox->setTitle(title);
ui->groupBox->layout()->addWidget(widget);

if (!buttons.isEmpty()) {
ui->buttonBox->clear();
for (auto [button, role] : buttons) {
ui->buttonBox->addButton(button, role);
}
}

connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [this] {
Q_EMIT accepted();
Q_EMIT finished();
Expand All @@ -32,5 +71,18 @@ AccountModalWidget::AccountModalWidget(const QString &title, QWidget *widget, QW
Q_EMIT rejected();
Q_EMIT finished();
});

connect(ui->buttonBox, &QDialogButtonBox::clicked, this, [this](auto *button) { _clickedButton = button; });
}

QDialogButtonBox *AccountModalWidget::buttons()
{
return ui->buttonBox;
}

QAbstractButton *AccountModalWidget::clickedButton() const
{
return _clickedButton;
}

} // OCC
15 changes: 14 additions & 1 deletion src/gui/accountmodalwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
*/

#pragma once

#include <QDialogButtonBox>
#include <QQmlContext>
#include <QWidget>


namespace OCC {

namespace Ui {
Expand All @@ -25,7 +29,15 @@ class AccountModalWidget : public QWidget
{
Q_OBJECT
public:
AccountModalWidget(const QString &title, QWidget *widget, QWidget *parent);
using Button = QPair<QPushButton *, QDialogButtonBox::ButtonRole>;

AccountModalWidget(const QString &title, const QUrl &qmlSrc, const QList<QQmlContext::PropertyPair> &properties, const QList<Button> &buttons = {},
QWidget *parent = nullptr);
AccountModalWidget(const QString &title, QWidget *widget, const QList<Button> &buttons = {}, QWidget *parent = nullptr);

QDialogButtonBox *buttons();

QAbstractButton *clickedButton() const;

Q_SIGNALS:
void accepted();
Expand All @@ -34,6 +46,7 @@ class AccountModalWidget : public QWidget

private:
Ui::AccountModalWidget *ui;
QAbstractButton *_clickedButton = nullptr;
};

} // OCC
2 changes: 1 addition & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void AccountSettings::showSelectiveSyncDialog(Folder *folder)
folder->remotePath(), folder->displayName(), folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok));
Q_ASSERT(ok);

auto *modalWidget = new AccountModalWidget(tr("Choose what to sync"), selectiveSync, this);
auto *modalWidget = new AccountModalWidget(tr("Choose what to sync"), selectiveSync, {}, this);
connect(modalWidget, &AccountModalWidget::accepted, this, [selectiveSync, folder, this] {
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, selectiveSync->createBlackList());
Q_EMIT folderChanged();
Expand Down