Skip to content

Commit

Permalink
Adopt Update dialogs to the new modal widget experience
Browse files Browse the repository at this point in the history
Fixes: #11593
  • Loading branch information
erikjv committed May 3, 2024
1 parent 9dd56a3 commit 66e5494
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 105 deletions.
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
nourlwidget.cpp
nourlwidget.h
nourlwidget.ui
updateinfo.cpp
updateinfo.h
updater.cpp
Expand Down
59 changes: 59 additions & 0 deletions src/gui/updater/nourlwidget.cpp
@@ -0,0 +1,59 @@
/*
* 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 "nourlwidget.h"
#include "theme.h"
#include "ui_nourlwidget.h"

#include <QDialogButtonBox>
#include <QPushButton>

namespace OCC {

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

_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, &NoUrlWidget::skipVersion);
connect(rejectButton, &QAbstractButton::clicked, this, &NoUrlWidget::notNow);
connect(getUpdateButton, &QAbstractButton::clicked, this, &NoUrlWidget::getUpdate);
}

void NoUrlWidget::skipVersion()
{
close();
Q_EMIT versionSkipped();
}

void NoUrlWidget::notNow()
{
close();
Q_EMIT noUpdateNow();
}

void NoUrlWidget::getUpdate()
{
close();
Q_EMIT updateNow();
}

} // OCC namespace
47 changes: 47 additions & 0 deletions src/gui/updater/nourlwidget.h
@@ -0,0 +1,47 @@
/*
* 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_NoUrlWidget;
}

namespace OCC {

class NoUrlWidget : public QWidget
{
Q_OBJECT

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

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

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

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

}
95 changes: 95 additions & 0 deletions src/gui/updater/nourlwidget.ui
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Ui::NoUrlWidget</class>
<widget class="QWidget" name="Ui::NoUrlWidget">
<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="maximumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../resources/client.qrc">:/client/resources/light/states/information.svg</pixmap>
</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>
<include location="../../resources/client.qrc"/>
</resources>
<connections/>
</ui>
44 changes: 6 additions & 38 deletions src/gui/updater/ocupdater.cpp
Expand Up @@ -22,6 +22,7 @@

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

Expand Down Expand Up @@ -376,50 +377,17 @@ void WindowsUpdater::versionInfoArrived(const UpdateInfo &info)
void WindowsUpdater::showNoUrlDialog(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 NoUrlWidget(ocApp()->gui()->settingsDialog(), txt);
widget->setAttribute(Qt::WA_DeleteOnClose);

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

hlayout->addWidget(ico);
hlayout->addWidget(lbl);
connect(widget, &NoUrlWidget::versionSkipped, this, &WindowsUpdater::slotSetPreviouslySkippedVersion);
connect(widget, &NoUrlWidget::updateNow, this, &WindowsUpdater::slotOpenUpdateUrl);

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
15 changes: 10 additions & 5 deletions src/gui/updater/updatedownloadeddialog.cpp
Expand Up @@ -22,7 +22,7 @@
namespace OCC {

UpdateDownloadedDialog::UpdateDownloadedDialog(QWidget *parent, const QString &statusMessage)
: QDialog(parent)
: QWidget(parent)
, _ui(new ::Ui::UpdateDownloadedDialog)
{
_ui->setupUi(this);
Expand All @@ -32,8 +32,8 @@ UpdateDownloadedDialog::UpdateDownloadedDialog(QWidget *parent, const QString &s

_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();
close();
}

void UpdateDownloadedDialog::reject()
{
close();
}
} // OCC namespace
15 changes: 11 additions & 4 deletions src/gui/updater/updatedownloadeddialog.h
Expand Up @@ -14,24 +14,31 @@

#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();

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

}

0 comments on commit 66e5494

Please sign in to comment.