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

Adopt Update dialogs to the new modal widget experience #11617

Merged
merged 1 commit into from May 22, 2024
Merged
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
3 changes: 3 additions & 0 deletions src/gui/updater/CMakeLists.txt
Expand Up @@ -10,6 +10,9 @@ endif()
target_sources(owncloudGui PRIVATE
ocupdater.cpp
ocupdater.h
newversionavailabledialog.cpp
newversionavailabledialog.h
newversionavailabledialog.ui
updateinfo.cpp
updateinfo.h
updater.cpp
Expand Down
60 changes: 60 additions & 0 deletions src/gui/updater/newversionavailabledialog.cpp
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2023 by Erik Verbruggen <erik@verbruggen.consulting>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include "newversionavailabledialog.h"
#include "theme.h"
#include "ui_newversionavailabledialog.h"

#include <QDialogButtonBox>
#include <QPushButton>

namespace OCC {

NewVersionAvailableDialog::NewVersionAvailableDialog(QWidget *parent, const QString &statusMessage)
: QWidget(parent)
, _ui(new ::Ui::Ui_NewVersionAvailableDialog)
{
_ui->setupUi(this);

_ui->icon->setPixmap(Theme::instance()->applicationIcon().pixmap(128, 128));
_ui->label->setText(statusMessage);

QPushButton *skipButton = _ui->buttonBox->addButton(tr("Skip this version"), QDialogButtonBox::ResetRole);
QPushButton *getUpdateButton = _ui->buttonBox->addButton(tr("Get update"), QDialogButtonBox::AcceptRole);
QPushButton *rejectButton = _ui->buttonBox->addButton(tr("Skip this time"), QDialogButtonBox::AcceptRole);

connect(skipButton, &QAbstractButton::clicked, this, &NewVersionAvailableDialog::skipVersion);
connect(rejectButton, &QAbstractButton::clicked, this, &NewVersionAvailableDialog::notNow);
connect(getUpdateButton, &QAbstractButton::clicked, this, &NewVersionAvailableDialog::getUpdate);
}

void NewVersionAvailableDialog::skipVersion()
{
Q_EMIT versionSkipped();
Q_EMIT finished();
}

void NewVersionAvailableDialog::notNow()
{
Q_EMIT noUpdateNow();
Q_EMIT finished();
}

void NewVersionAvailableDialog::getUpdate()
{
Q_EMIT updateNow();
Q_EMIT finished();
}

} // OCC namespace
48 changes: 48 additions & 0 deletions src/gui/updater/newversionavailabledialog.h
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 by Fabian Müller <fmueller@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#pragma once

#include <QScopedPointer>
#include <QWidget>

namespace Ui {
class Ui_NewVersionAvailableDialog;
}

namespace OCC {

class NewVersionAvailableDialog : public QWidget
{
Q_OBJECT

public:
explicit NewVersionAvailableDialog(QWidget *parent, const QString &statusMessage);

private Q_SLOTS:
void skipVersion();
void notNow();
void getUpdate();

Q_SIGNALS:
void versionSkipped();
void noUpdateNow();
void updateNow();
void finished();

private:
QScopedPointer<::Ui::Ui_NewVersionAvailableDialog> _ui;
};

}
96 changes: 96 additions & 0 deletions src/gui/updater/newversionavailabledialog.ui
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Ui::NewVersionAvailableDialog</class>
<widget class="QWidget" name="Ui::NewVersionAvailableDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="icon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
50 changes: 9 additions & 41 deletions src/gui/updater/ocupdater.cpp
Expand Up @@ -22,6 +22,7 @@

#include "settingsdialog.h"
#include "updatedownloadeddialog.h"
#include "updater/newversionavailabledialog.h"
#include "updater/ocupdater.h"
#include "updater/updater_private.h"

Expand Down Expand Up @@ -52,10 +53,10 @@ UpdaterScheduler::UpdaterScheduler(Application *app, QObject *parent)
// prevent dialog from being displayed twice (rather unlikely, but it won't hurt)
if (_updateDownloadedDialog == nullptr) {
_updateDownloadedDialog = new UpdateDownloadedDialog(app->gui()->settingsDialog(), updater->statusString());
_updateDownloadedDialog->setAttribute(Qt::WA_DeleteOnClose);
ocApp()->gui()->settingsDialog()->addModalWidget(_updateDownloadedDialog);

connect(_updateDownloadedDialog, &UpdateDownloadedDialog::accepted, this, []() { RestartManager::requestRestart(); });
connect(_updateDownloadedDialog, &UpdateDownloadedDialog::finished, this, [this]() { delete _updateDownloadedDialog.data(); });
}
});

Expand Down Expand Up @@ -353,7 +354,7 @@ void WindowsUpdater::versionInfoArrived(const UpdateInfo &info)
} else {
const QString url = info.downloadUrl();
if (url.isEmpty()) {
showNoUrlDialog(info);
showNewVersionAvailableDialog(info);
} else {
_targetFile = ConfigFile::configPath() + url.mid(url.lastIndexOf(QLatin1Char('/')) + 1);
if (QFile::exists(_targetFile)) {
Expand All @@ -373,53 +374,20 @@ void WindowsUpdater::versionInfoArrived(const UpdateInfo &info)
}
}

void WindowsUpdater::showNoUrlDialog(const UpdateInfo &info)
void WindowsUpdater::showNewVersionAvailableDialog(const UpdateInfo &info)
{
// if the version tag is set, there is a newer version.
QDialog *msgBox = new QDialog;
msgBox->setAttribute(Qt::WA_DeleteOnClose);

QIcon infoIcon = msgBox->style()->standardIcon(QStyle::SP_MessageBoxInformation);
int iconSize = msgBox->style()->pixelMetric(QStyle::PM_MessageBoxIconSize);

msgBox->setWindowIcon(infoIcon);

QVBoxLayout *layout = new QVBoxLayout(msgBox);
QHBoxLayout *hlayout = new QHBoxLayout;
layout->addLayout(hlayout);

msgBox->setWindowTitle(tr("New Version Available"));

QLabel *ico = new QLabel;
ico->setFixedSize(iconSize, iconSize);
ico->setPixmap(infoIcon.pixmap(iconSize));
QLabel *lbl = new QLabel;
QString txt = tr("<p>A new version of the %1 Client is available.</p>"
"<p><b>%2</b> is available for download. The installed version is %3.</p>")
.arg(Utility::escape(Theme::instance()->appNameGUI()),
Utility::escape(info.versionString()), Utility::escape(Version::versionWithBuildNumber().toString()));
auto *widget = new NewVersionAvailableDialog(ocApp()->gui()->settingsDialog(), txt);

lbl->setText(txt);
lbl->setTextFormat(Qt::RichText);
lbl->setWordWrap(true);

hlayout->addWidget(ico);
hlayout->addWidget(lbl);
connect(widget, &NewVersionAvailableDialog::versionSkipped, this, &WindowsUpdater::slotSetPreviouslySkippedVersion);
connect(widget, &NewVersionAvailableDialog::updateNow, this, &WindowsUpdater::slotOpenUpdateUrl);
connect(widget, &NewVersionAvailableDialog::finished, this, [widget]() { delete widget; });

QDialogButtonBox *bb = new QDialogButtonBox;
QPushButton *skip = bb->addButton(tr("Skip this version"), QDialogButtonBox::ResetRole);
QPushButton *reject = bb->addButton(tr("Skip this time"), QDialogButtonBox::AcceptRole);
QPushButton *getupdate = bb->addButton(tr("Get update"), QDialogButtonBox::AcceptRole);

connect(skip, &QAbstractButton::clicked, msgBox, &QDialog::reject);
connect(reject, &QAbstractButton::clicked, msgBox, &QDialog::reject);
connect(getupdate, &QAbstractButton::clicked, msgBox, &QDialog::accept);

connect(skip, &QAbstractButton::clicked, this, &WindowsUpdater::slotSetPreviouslySkippedVersion);
connect(getupdate, &QAbstractButton::clicked, this, &WindowsUpdater::slotOpenUpdateUrl);

layout->addWidget(bb);
ocApp()->gui()->settingsDialog()->addModalWidget(msgBox);
ocApp()->gui()->settingsDialog()->addModalWidget(widget);
}

void WindowsUpdater::showUpdateErrorDialog(const QString &targetVersion)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/updater/ocupdater.h
Expand Up @@ -186,7 +186,7 @@ private Q_SLOTS:

private:
void wipeUpdateData();
void showNoUrlDialog(const UpdateInfo &info);
void showNewVersionAvailableDialog(const UpdateInfo &info);
void showUpdateErrorDialog(const QString &targetVersion);
void versionInfoArrived(const UpdateInfo &info) override;
QScopedPointer<QTemporaryFile> _file;
Expand Down
17 changes: 11 additions & 6 deletions src/gui/updater/updatedownloadeddialog.cpp
Expand Up @@ -22,18 +22,18 @@
namespace OCC {

UpdateDownloadedDialog::UpdateDownloadedDialog(QWidget *parent, const QString &statusMessage)
: QDialog(parent)
: QWidget(parent)
, _ui(new ::Ui::UpdateDownloadedDialog)
{
_ui->setupUi(this);

_ui->iconLabel->setPixmap(Theme::instance()->aboutIcon().pixmap(96, 96));
_ui->iconLabel->setPixmap(Theme::instance()->applicationIcon().pixmap(128, 128));
_ui->iconLabel->setText(QString());

_ui->descriptionLabel->setText(statusMessage);

connect(_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(_ui->buttonBox, &QDialogButtonBox::rejected, this, &UpdateDownloadedDialog::reject);
connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &UpdateDownloadedDialog::accept);

const auto noButton = _ui->buttonBox->button(QDialogButtonBox::No);
const auto yesButton = _ui->buttonBox->button(QDialogButtonBox::Yes);
Expand All @@ -44,9 +44,14 @@ UpdateDownloadedDialog::UpdateDownloadedDialog(QWidget *parent, const QString &s
yesButton->setDefault(true);
}

UpdateDownloadedDialog::~UpdateDownloadedDialog()
void UpdateDownloadedDialog::accept()
{
delete _ui;
Q_EMIT accepted();
Q_EMIT finished();
}

void UpdateDownloadedDialog::reject()
{
Q_EMIT finished();
}
} // OCC namespace
16 changes: 12 additions & 4 deletions src/gui/updater/updatedownloadeddialog.h
Expand Up @@ -14,24 +14,32 @@

#pragma once

#include <QDialog>
#include <QScopedPointer>
#include <QWidget>

namespace Ui {
class UpdateDownloadedDialog;
}

namespace OCC {

class UpdateDownloadedDialog : public QDialog
class UpdateDownloadedDialog : public QWidget
{
Q_OBJECT

public:
explicit UpdateDownloadedDialog(QWidget *parent, const QString &statusMessage);
~UpdateDownloadedDialog() override;

public Q_SLOTS:
void accept();
void reject();

Q_SIGNALS:
void accepted();
void finished();

private:
::Ui::UpdateDownloadedDialog *_ui;
QScopedPointer<::Ui::UpdateDownloadedDialog> _ui;
};

}