Skip to content

Commit 9cf71d2

Browse files
committed
added "simple" dialog as option instead of "details"
1 parent aebd6a9 commit 9cf71d2

File tree

8 files changed

+126
-30
lines changed

8 files changed

+126
-30
lines changed

AutoUpdaterGui/updatecontroller.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ void UpdateController::resetUpdateRunArgs()
118118
d->runArgs = QStringList(QStringLiteral("--updater"));
119119
}
120120

121+
bool UpdateController::isDetailedUpdateInfo() const
122+
{
123+
const Q_D(UpdateController);
124+
return d->detailedInfo;
125+
}
126+
127+
void UpdateController::setDetailedUpdateInfo(bool detailedUpdateInfo)
128+
{
129+
Q_D(UpdateController);
130+
d->detailedInfo = detailedUpdateInfo;
131+
}
132+
121133
const Updater * UpdateController::getUpdater() const
122134
{
123135
const Q_D(UpdateController);
@@ -249,6 +261,7 @@ void UpdateController::checkUpdatesDone(bool hasUpdates, bool hasError)
249261
UpdateInfoDialog::DialogResult res = UpdateInfoDialog::showUpdateInfo(d->mainUpdater->updateInfo(),
250262
d->runAdmin,
251263
d->adminUserEdit,
264+
d->detailedInfo,
252265
d->window);
253266
if(d->runAdmin != oldRunAdmin)
254267
emit runAsAdminChanged(d->runAdmin);
@@ -328,6 +341,7 @@ UpdateControllerPrivate::UpdateControllerPrivate(UpdateController *q_ptr, const
328341
runAdmin(true),
329342
adminUserEdit(true),
330343
runArgs(QStringLiteral("--updater")),
344+
detailedInfo(true),
331345
checkUpdatesProgress(NULL),
332346
wasCanceled(false),
333347
updateTasks()

AutoUpdaterGui/updatecontroller.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace QtAutoUpdater
2424
Q_PROPERTY(bool runAsAdmin READ runAsAdmin WRITE setRunAsAdmin NOTIFY runAsAdminChanged)
2525
//! Holds the arguments to invoke the updater with
2626
Q_PROPERTY(QStringList updateRunArgs READ updateRunArgs WRITE setUpdateRunArgs RESET resetUpdateRunArgs)
27+
//! Specifies whether the update infos should be detailed or not
28+
Q_PROPERTY(bool detailedUpdateInfo READ isDetailedUpdateInfo WRITE setDetailedUpdateInfo)
2729

2830
public:
2931
//! Defines the different display-levels of the dialog
@@ -71,6 +73,10 @@ namespace QtAutoUpdater
7173
void setUpdateRunArgs(QStringList updateRunArgs);
7274
//! RESET-Accessor for UpdateController::updateRunArgs
7375
void resetUpdateRunArgs();
76+
//! READ-Accessor for UpdateController::detailedUpdateInfo
77+
bool isDetailedUpdateInfo() const;
78+
//! WRITE-Accessor for UpdateController::detailedUpdateInfo
79+
void setDetailedUpdateInfo(bool detailedUpdateInfo);
7480

7581
//! Returns the Updater object used by the controller
7682
const Updater * getUpdater() const;

AutoUpdaterGui/updatecontroller_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace QtAutoUpdater
2121
bool runAdmin;
2222
bool adminUserEdit;
2323
QStringList runArgs;
24+
bool detailedInfo;
2425

2526
ProgressDialog *checkUpdatesProgress;
2627
bool wasCanceled;

AutoUpdaterGui/updateinfodialog.cpp

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "updateinfodialog.h"
22
#include "ui_updateinfodialog.h"
33
#include <QGuiApplication>
4-
#include <QScreen>
4+
#include <QMessageBox>
55
#include "messagemaster.h"
66
using namespace QtAutoUpdater;
77

@@ -44,28 +44,79 @@ UpdateInfoDialog::~UpdateInfoDialog()
4444
delete ui;
4545
}
4646

47-
UpdateInfoDialog::DialogResult UpdateInfoDialog::showUpdateInfo(QList<Updater::UpdateInfo> updates, bool &runAsAdmin, bool editable, QWidget *parent)
47+
UpdateInfoDialog::DialogResult UpdateInfoDialog::showUpdateInfo(QList<Updater::UpdateInfo> updates, bool &runAsAdmin, bool editable, bool detailed, QWidget *parent)
4848
{
49-
UpdateInfoDialog dialog(parent);
50-
51-
for(Updater::UpdateInfo info : updates) {
52-
QTreeWidgetItem *item = new QTreeWidgetItem(dialog.ui->updateListTreeWidget);
53-
item->setText(0, info.name);
54-
item->setText(1, info.version.toString());
55-
item->setText(2, getByteText(info.size));
56-
item->setToolTip(2, tr("%L1 Bytes").arg(info.size));
57-
}
58-
dialog.ui->updateListTreeWidget->resizeColumnToContents(0);
59-
dialog.ui->updateListTreeWidget->resizeColumnToContents(1);
60-
dialog.ui->updateListTreeWidget->resizeColumnToContents(2);
49+
if(!detailed) {
50+
QMessageBox mBox(parent);
51+
mBox.setWindowModality(parent ? Qt::WindowModal : Qt::ApplicationModal);//TODO master dialog
52+
mBox.setWindowFlags(mBox.windowFlags() & ~Qt::WindowContextHelpButtonHint);
53+
mBox.setIcon(QMessageBox::Information);
54+
mBox.setWindowTitle(tr("Check for Updates"));
55+
mBox.setWindowIcon(QIcon(QStringLiteral(":/updaterIcons/update.ico")));
56+
mBox.setText(QStringLiteral("<b>") +
57+
tr("Updates for %1 are available!")
58+
.arg(QGuiApplication::applicationDisplayName()) +
59+
QStringLiteral("</b>"));
60+
mBox.setInformativeText(tr("There are new updates available! You can install them now or later."));
61+
QStringList details;
62+
for(Updater::UpdateInfo info : updates) {
63+
details << tr("%1 v%2 — %3")
64+
.arg(info.name)
65+
.arg(info.version.toString())
66+
.arg(getByteText(info.size));
67+
}
68+
mBox.setDetailedText(details.join(QLatin1Char('\n')));
69+
70+
QCheckBox *cBox = new QCheckBox(tr("Run with &elevated rights"), &mBox);
71+
cBox->setEnabled(editable);
72+
cBox->setChecked(runAsAdmin);
73+
mBox.setCheckBox(cBox);
74+
75+
mBox.setDefaultButton(mBox.addButton(tr("Install Now"), QMessageBox::AcceptRole));
76+
mBox.addButton(tr("Install On Exit"), QMessageBox::ActionRole);
77+
mBox.setEscapeButton(mBox.addButton(tr("Install later"), QMessageBox::RejectRole));
78+
79+
DialogResult res;
80+
mBox.exec();
81+
switch (mBox.buttonRole(mBox.clickedButton())) {
82+
case QMessageBox::AcceptRole:
83+
res = InstallNow;
84+
break;
85+
case QMessageBox::ActionRole:
86+
res = InstallLater;
87+
break;
88+
case QMessageBox::RejectRole:
89+
res = NoInstall;
90+
break;
91+
default:
92+
Q_UNREACHABLE();
93+
}
6194

62-
dialog.ui->runAdminCheckBox->setEnabled(editable);
63-
dialog.ui->runAdminCheckBox->setChecked(runAsAdmin);
95+
if(editable && res != NoInstall)
96+
runAsAdmin = cBox->isChecked();
97+
return res;
98+
} else {
99+
UpdateInfoDialog dialog(parent);
64100

65-
DialogResult res = (DialogResult)dialog.exec();
66-
if(editable && res != NoInstall)
67-
runAsAdmin = dialog.ui->runAdminCheckBox->isChecked();
68-
return res;
101+
for(Updater::UpdateInfo info : updates) {
102+
QTreeWidgetItem *item = new QTreeWidgetItem(dialog.ui->updateListTreeWidget);
103+
item->setText(0, info.name);
104+
item->setText(1, info.version.toString());
105+
item->setText(2, getByteText(info.size));
106+
item->setToolTip(2, tr("%L1 Bytes").arg(info.size));
107+
}
108+
dialog.ui->updateListTreeWidget->resizeColumnToContents(0);
109+
dialog.ui->updateListTreeWidget->resizeColumnToContents(1);
110+
dialog.ui->updateListTreeWidget->resizeColumnToContents(2);
111+
112+
dialog.ui->runAdminCheckBox->setEnabled(editable);
113+
dialog.ui->runAdminCheckBox->setChecked(runAsAdmin);
114+
115+
DialogResult res = (DialogResult)dialog.exec();
116+
if(editable && res != NoInstall)
117+
runAsAdmin = dialog.ui->runAdminCheckBox->isChecked();
118+
return res;
119+
}
69120
}
70121

71122
void QtAutoUpdater::UpdateInfoDialog::on_acceptButton_clicked()

AutoUpdaterGui/updateinfodialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace QtAutoUpdater
2424
static DialogResult showUpdateInfo(QList<Updater::UpdateInfo> updates,
2525
bool &runAsAdmin,
2626
bool editable,
27+
bool detailed,
2728
QWidget *parent);
2829

2930
private slots:

Tests/WidgetsTest/mainwindow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ MainWindow::MainWindow(QWidget *parent) :
1717
this->ui->maintenanceToolLineEdit->setText(settings.value("path").toString());
1818
this->ui->hasParentWindowCheckBox->setChecked(settings.value("hasParent", true).toBool());
1919
this->ui->displayLevelComboBox->setCurrentIndex((QtAutoUpdater::UpdateController::DisplayLevel)settings.value("level", QtAutoUpdater::UpdateController::ProgressLevel).toInt());
20+
this->ui->detailedInfoDialogCheckBox->setChecked(settings.value("detailed", true).toBool());
2021
this->ui->adminCheckBox->setChecked(settings.value("admin", true).toBool());
2122
this->ui->userChangecheckBox->setChecked(settings.value("adminChangable", true).toBool());
2223
}
@@ -27,6 +28,7 @@ MainWindow::~MainWindow()
2728
settings.setValue("path", this->ui->maintenanceToolLineEdit->text());
2829
settings.setValue("hasParent", this->ui->hasParentWindowCheckBox->isChecked());
2930
settings.setValue("level", this->ui->displayLevelComboBox->currentIndex());
31+
settings.setValue("detailed", this->ui->detailedInfoDialogCheckBox->isChecked());
3032
settings.setValue("admin", this->ui->adminCheckBox->isChecked());
3133
settings.setValue("adminChangable", this->ui->userChangecheckBox->isChecked());
3234
delete ui;
@@ -78,6 +80,7 @@ void MainWindow::on_activeBox_toggled(bool checked)
7880
this->controller = new QtAutoUpdater::UpdateController(this->ui->maintenanceToolLineEdit->text(), this);
7981
else
8082
this->controller = new QtAutoUpdater::UpdateController(this->ui->maintenanceToolLineEdit->text(), (QObject*)this);
83+
this->controller->setDetailedUpdateInfo(this->ui->detailedInfoDialogCheckBox->isChecked());
8184
this->ui->menuHelp->addAction(this->controller->createUpdateAction(this));
8285
this->ui->mainToolBar->addAction(this->controller->createUpdateAction(this));
8386
connect(this->controller, &QtAutoUpdater::UpdateController::runningChanged, this, [this](bool running){
@@ -100,3 +103,9 @@ void MainWindow::on_hasParentWindowCheckBox_clicked(bool checked)
100103
this->controller->setParent((QObject*)this);
101104
}
102105
}
106+
107+
void MainWindow::on_detailedInfoDialogCheckBox_clicked(bool checked)
108+
{
109+
if(this->controller)
110+
this->controller->setDetailedUpdateInfo(checked);
111+
}

Tests/WidgetsTest/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ private slots:
2121
void on_checkUpdatesButton_clicked();
2222
void on_cancelButton_clicked();
2323
void on_activeBox_toggled(bool checked);
24-
2524
void on_hasParentWindowCheckBox_clicked(bool checked);
25+
void on_detailedInfoDialogCheckBox_clicked(bool checked);
2626

2727
private:
2828
Ui::MainWindow *ui;

Tests/WidgetsTest/mainwindow.ui

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
</item>
9393
</widget>
9494
</item>
95-
<item row="5" column="0">
95+
<item row="6" column="0">
9696
<spacer name="horizontalSpacer">
9797
<property name="orientation">
9898
<enum>Qt::Horizontal</enum>
@@ -105,7 +105,7 @@
105105
</property>
106106
</spacer>
107107
</item>
108-
<item row="5" column="1">
108+
<item row="6" column="1">
109109
<layout class="QVBoxLayout" name="buttonLayout">
110110
<item>
111111
<widget class="QCommandLinkButton" name="checkUpdatesButton">
@@ -129,14 +129,14 @@
129129
</item>
130130
</layout>
131131
</item>
132-
<item row="3" column="0">
132+
<item row="4" column="0">
133133
<widget class="QLabel" name="adminLabel">
134134
<property name="text">
135-
<string>Admin</string>
135+
<string>Admin:</string>
136136
</property>
137137
</widget>
138138
</item>
139-
<item row="3" column="1">
139+
<item row="4" column="1">
140140
<layout class="QVBoxLayout" name="verticalLayout_2">
141141
<item>
142142
<widget class="QCheckBox" name="adminCheckBox">
@@ -166,7 +166,7 @@
166166
</item>
167167
</layout>
168168
</item>
169-
<item row="4" column="1">
169+
<item row="5" column="1">
170170
<widget class="QDateTimeEdit" name="scheduleUpdateDateTimeEdit">
171171
<property name="enabled">
172172
<bool>false</bool>
@@ -185,17 +185,17 @@
185185
</property>
186186
</widget>
187187
</item>
188-
<item row="4" column="0">
188+
<item row="5" column="0">
189189
<widget class="QCheckBox" name="scheduleUpdateDateCheckBox">
190190
<property name="text">
191-
<string>Schedule Update</string>
191+
<string>Schedule Update:</string>
192192
</property>
193193
</widget>
194194
</item>
195195
<item row="1" column="0">
196196
<widget class="QLabel" name="hasParentWindowLabel">
197197
<property name="text">
198-
<string>Has Parent Window</string>
198+
<string>Has Parent Window:</string>
199199
</property>
200200
</widget>
201201
</item>
@@ -206,6 +206,20 @@
206206
</property>
207207
</widget>
208208
</item>
209+
<item row="3" column="0">
210+
<widget class="QLabel" name="detailedInfoDialogLabel">
211+
<property name="text">
212+
<string>Detailed InfoDialog:</string>
213+
</property>
214+
</widget>
215+
</item>
216+
<item row="3" column="1">
217+
<widget class="QCheckBox" name="detailedInfoDialogCheckBox">
218+
<property name="checked">
219+
<bool>true</bool>
220+
</property>
221+
</widget>
222+
</item>
209223
</layout>
210224
</item>
211225
</layout>

0 commit comments

Comments
 (0)