Skip to content

Commit cfe49d1

Browse files
committed
move taskbar control into update controller
1 parent 6222f72 commit cfe49d1

File tree

6 files changed

+76
-51
lines changed

6 files changed

+76
-51
lines changed

examples/autoupdatergui/WidgetsUpdater/mainwindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void MainWindow::on_activeBox_toggled(bool checked)
8282
controller = new QtAutoUpdater::UpdateController(ui->maintenanceToolLineEdit->text(), this, qApp);
8383
else
8484
controller = new QtAutoUpdater::UpdateController(ui->maintenanceToolLineEdit->text(), qApp);
85+
controller->setDesktopFileName(QStringLiteral("WidgetsUpdater"));
8586
controller->setDetailedUpdateInfo(ui->detailedInfoDialogCheckBox->isChecked());
8687
QAction *a = controller->createUpdateAction(this);
8788
a->setIconVisibleInMenu(false);

src/autoupdatergui/progressdialog.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ using namespace QtAutoUpdater;
88

99
ProgressDialog::ProgressDialog(QWidget *parent) :
1010
QDialog{parent},
11-
ui{new Ui::ProgressDialog},
12-
taskbar{new QTaskbarControl{this}}
11+
ui{new Ui::ProgressDialog}
1312
{
1413
ui->setupUi(this);
1514
DialogMaster::masterDialog(this, true, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint);
16-
17-
taskbar->setProgress(-1.0);
18-
taskbar->setProgressVisible(true);
1915
}
2016

2117
ProgressDialog::~ProgressDialog() = default;
@@ -26,30 +22,6 @@ void ProgressDialog::setCanceled()
2622
ui->buttonBox->setEnabled(false);
2723
}
2824

29-
void ProgressDialog::hide(QMessageBox::Icon hideType)
30-
{
31-
taskbar->setProgress(1.0);
32-
switch (hideType) {
33-
case QMessageBox::Information:
34-
taskbar->setAttribute(QTaskbarControl::WindowsProgressState, QTaskbarControl::Running);
35-
taskbar->setProgressVisible(true);
36-
break;
37-
case QMessageBox::Warning:
38-
taskbar->setAttribute(QTaskbarControl::WindowsProgressState, QTaskbarControl::Paused);
39-
taskbar->setProgressVisible(true);
40-
break;
41-
case QMessageBox::Critical:
42-
taskbar->setAttribute(QTaskbarControl::WindowsProgressState, QTaskbarControl::Stopped);
43-
taskbar->setProgressVisible(true);
44-
break;
45-
default:
46-
taskbar->setProgressVisible(false);
47-
break;
48-
}
49-
50-
QDialog::hide();
51-
}
52-
5325
void ProgressDialog::closeEvent(QCloseEvent *event)
5426
{
5527
event->ignore();

src/autoupdatergui/progressdialog_p.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#include <functional>
1212

13-
#include <qtaskbarcontrol.h>
14-
1513
namespace Ui {
1614
class ProgressDialog;
1715
}
@@ -41,8 +39,6 @@ public Q_SLOTS:
4139
void accept() override {}
4240
void reject() override {}
4341

44-
void hide(QMessageBox::Icon hideType);
45-
4642
Q_SIGNALS:
4743
void canceled();
4844

@@ -51,7 +47,6 @@ public Q_SLOTS:
5147

5248
private:
5349
QScopedPointer<Ui::ProgressDialog> ui;
54-
QTaskbarControl *taskbar;
5550
};
5651

5752
}

src/autoupdatergui/updatecontroller.cpp

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,24 @@ bool UpdateController::isDetailedUpdateInfo() const
114114
return d->detailedInfo;
115115
}
116116

117+
QString UpdateController::desktopFileName() const
118+
{
119+
return d->taskbar ?
120+
d->taskbar->attribute(QTaskbarControl::LinuxDesktopFile).toString() :
121+
QString{};
122+
}
123+
117124
void UpdateController::setDetailedUpdateInfo(bool detailedUpdateInfo)
118125
{
119126
d->detailedInfo = detailedUpdateInfo;
120127
}
121128

129+
void UpdateController::setDesktopFileName(const QString &desktopFileName)
130+
{
131+
if(d->taskbar)
132+
d->taskbar->setAttribute(QTaskbarControl::LinuxDesktopFile, desktopFileName);
133+
}
134+
122135
Updater *UpdateController::updater() const
123136
{
124137
return d->mainUpdater;
@@ -155,8 +168,10 @@ bool UpdateController::start(DisplayLevel displayLevel)
155168
return false;
156169
} else {
157170
if(d->displayLevel >= ExtendedInfoLevel) {
158-
d->checkUpdatesProgress = new ProgressDialog(d->window);
159171
if(d->displayLevel >= ProgressLevel) {
172+
d->taskbar->setProgress(-1.0);
173+
d->taskbar->setProgressVisible(true);
174+
d->checkUpdatesProgress = new ProgressDialog{d->window};
160175
connect(d->checkUpdatesProgress.data(), &ProgressDialog::canceled, this, [this](){
161176
d->wasCanceled = true;
162177
});
@@ -202,61 +217,65 @@ void UpdateController::cancelScheduledUpdate(int taskId)
202217
void UpdateController::checkUpdatesDone(bool hasUpdates, bool hasError)
203218
{
204219
if(d->displayLevel >= ExtendedInfoLevel) {
205-
auto iconType = QMessageBox::NoIcon;
206-
if(hasUpdates)
207-
iconType = QMessageBox::Information;
208-
else {
209-
if(d->wasCanceled || !d->mainUpdater->exitedNormally())
210-
iconType = QMessageBox::Warning;
211-
else
212-
iconType = QMessageBox::Critical;
213-
}
214-
215220
if(d->checkUpdatesProgress) {
216-
d->checkUpdatesProgress->hide(iconType);
221+
d->checkUpdatesProgress->hide();
217222
d->checkUpdatesProgress->deleteLater();
218223
d->checkUpdatesProgress = nullptr;
219224
}
220225
}
221226

222227
if(d->wasCanceled) {
223228
if(d->displayLevel >= ExtendedInfoLevel) {
229+
d->setTaskbarState(QTaskbarControl::Paused);
224230
DialogMaster::warningT(d->window,
225231
tr("Check for Updates"),
226232
tr("Checking for updates was canceled!"));
227233
}
228234
} else {
229235
if(hasUpdates) {
230236
if(d->displayLevel >= InfoLevel) {
237+
const auto updateInfos = d->mainUpdater->updateInfo();
238+
d->setTaskbarState(QTaskbarControl::Running);
239+
if(d->taskbar) {
240+
if(updateInfos.size() > 0) {
241+
d->taskbar->setCounter(updateInfos.size());
242+
d->taskbar->setCounterVisible(true);
243+
} else
244+
d->taskbar->setCounterVisible(false);
245+
}
246+
247+
231248
auto shouldShutDown = false;
232249
const auto oldRunAdmin = d->runAdmin;
233-
const auto res = UpdateInfoDialog::showUpdateInfo(d->mainUpdater->updateInfo(),
250+
const auto res = UpdateInfoDialog::showUpdateInfo(updateInfos,
234251
d->runAdmin,
235252
d->adminUserEdit,
236253
d->detailedInfo,
237254
d->window);
255+
d->clearTaskbar();
256+
238257
if(d->runAdmin != oldRunAdmin)
239258
emit runAsAdminChanged(d->runAdmin);
240259

241-
QT_WARNING_PUSH
242-
QT_WARNING_DISABLE_GCC("-Wimplicit-fallthrough")
243260
switch(res) {
244261
case UpdateInfoDialog::InstallNow:
245262
shouldShutDown = true;
263+
Q_FALLTHROUGH();
246264
case UpdateInfoDialog::InstallLater:
247265
d->mainUpdater->runUpdaterOnExit(d->runAdmin ? new AdminAuthorization() : nullptr);
248266
if(shouldShutDown)
249267
qApp->quit();
268+
break;
250269
case UpdateInfoDialog::NoInstall:
251270
break;
252271
default:
253272
Q_UNREACHABLE();
254273
}
255-
QT_WARNING_POP
256274

257275
} else {
258276
d->mainUpdater->runUpdaterOnExit(d->runAdmin ? new AdminAuthorization() : nullptr);
259277
if(d->displayLevel == ExitLevel) {
278+
d->setTaskbarState(QTaskbarControl::Running);
260279
DialogMaster::informationT(d->window,
261280
tr("Install Updates"),
262281
tr("New updates are available. The maintenance tool will be "
@@ -274,10 +293,12 @@ void UpdateController::checkUpdatesDone(bool hasUpdates, bool hasError)
274293

275294
if(d->displayLevel >= ExtendedInfoLevel) {
276295
if(d->mainUpdater->exitedNormally()) {
296+
d->setTaskbarState(QTaskbarControl::Stopped);
277297
DialogMaster::criticalT(d->window,
278298
tr("Check for Updates"),
279299
tr("No new updates available!"));
280300
} else {
301+
d->setTaskbarState(QTaskbarControl::Paused);
281302
DialogMaster::warningT(d->window,
282303
tr("Check for Updates"),
283304
tr("The update process crashed!"));
@@ -286,6 +307,7 @@ void UpdateController::checkUpdatesDone(bool hasUpdates, bool hasError)
286307
}
287308
}
288309

310+
d->clearTaskbar();
289311
d->running = false;
290312
emit runningChanged(false);
291313
}
@@ -311,7 +333,8 @@ UpdateControllerPrivate::UpdateControllerPrivate(UpdateController *q_ptr, const
311333
q{q_ptr},
312334
window{window},
313335
mainUpdater{toolPath.isEmpty() ? new Updater{q_ptr} : new Updater{toolPath, q_ptr}},
314-
scheduler{new SimpleScheduler{q_ptr}}
336+
taskbar{window ? new QTaskbarControl{window} : nullptr},
337+
scheduler{new SimpleScheduler{q_ptr}}
315338
{
316339
QObject::connect(mainUpdater, &Updater::checkUpdatesDone,
317340
q, &UpdateController::checkUpdatesDone,
@@ -333,4 +356,29 @@ UpdateControllerPrivate::~UpdateControllerPrivate()
333356

334357
if(checkUpdatesProgress)
335358
checkUpdatesProgress->deleteLater();
359+
360+
clearTaskbar();
361+
}
362+
363+
void UpdateControllerPrivate::setTaskbarState(QTaskbarControl::WinProgressState state)
364+
{
365+
if(taskbar) {
366+
taskbar->setProgress(1.0);
367+
taskbar->setAttribute(QTaskbarControl::WindowsProgressState, state);
368+
#ifdef Q_OS_WIN
369+
taskbar->setProgressVisible(true);
370+
#else
371+
taskbar->setProgressVisible(false);
372+
#endif
373+
}
374+
}
375+
376+
377+
void UpdateControllerPrivate::clearTaskbar()
378+
{
379+
if(taskbar) {
380+
taskbar->setCounterVisible(false);
381+
taskbar->setProgressVisible(false);
382+
taskbar->deleteLater();
383+
}
336384
}

src/autoupdatergui/updatecontroller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Q_AUTOUPDATERGUI_EXPORT UpdateController : public QObject
3232
Q_PROPERTY(QStringList updateRunArgs READ updateRunArgs WRITE setUpdateRunArgs RESET resetUpdateRunArgs)
3333
//! Specifies whether the update infos should be detailed or not
3434
Q_PROPERTY(bool detailedUpdateInfo READ isDetailedUpdateInfo WRITE setDetailedUpdateInfo)
35+
Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName)
3536

3637
public:
3738
//! Defines the different display-levels of the dialog
@@ -74,6 +75,7 @@ class Q_AUTOUPDATERGUI_EXPORT UpdateController : public QObject
7475
QStringList updateRunArgs() const;
7576
//! @readAcFn{UpdateController::detailedUpdateInfo}
7677
bool isDetailedUpdateInfo() const;
78+
QString desktopFileName() const;
7779

7880
//! Returns the Updater object used by the controller
7981
Updater *updater() const;
@@ -89,6 +91,7 @@ public Q_SLOTS:
8991
void resetUpdateRunArgs();
9092
//! @writeAcFn{UpdateController::detailedUpdateInfo}
9193
void setDetailedUpdateInfo(bool detailedUpdateInfo);
94+
void setDesktopFileName(const QString &desktopFileName);
9295

9396
//! Starts the controller with the specified display level
9497
bool start(DisplayLevel displayLevel = InfoLevel);

src/autoupdatergui/updatecontroller_p.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include <QtCore/QPointer>
1313

14+
#include <qtaskbarcontrol.h>
15+
1416
namespace QtAutoUpdater
1517
{
1618

@@ -34,6 +36,7 @@ class Q_AUTOUPDATERGUI_EXPORT UpdateControllerPrivate
3436
QStringList runArgs {QStringLiteral("--updater")};
3537
bool detailedInfo = true;
3638

39+
QPointer<QTaskbarControl> taskbar;
3740
QPointer<ProgressDialog> checkUpdatesProgress;
3841
bool wasCanceled = false;
3942

@@ -42,6 +45,9 @@ class Q_AUTOUPDATERGUI_EXPORT UpdateControllerPrivate
4245
UpdateControllerPrivate(UpdateController *q_ptr, QWidget *window);
4346
UpdateControllerPrivate(UpdateController *q_ptr, const QString &toolPath, QWidget *window);
4447
~UpdateControllerPrivate();
48+
49+
void setTaskbarState(QTaskbarControl::WinProgressState state);
50+
void clearTaskbar();
4551
};
4652

4753
}

0 commit comments

Comments
 (0)