Skip to content

Commit 64ab4e8

Browse files
committed
fixed some todos, made updater window changable
1 parent de2f174 commit 64ab4e8

File tree

11 files changed

+86
-15
lines changed

11 files changed

+86
-15
lines changed

AutoUpdater/updater.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
#include "updatescheduler.h"
44
using namespace QtAutoUpdater;
55

6+
#ifdef Q_OS_OSX
7+
#define TOOL_PATH QStringLiteral("../../maintenancetool")//TODO test if ok...
8+
#else
9+
#define TOOL_PATH QStringLiteral("./maintenancetool")
10+
#endif
11+
612
Updater::Updater(QObject *parent) :
7-
Updater(QStringLiteral("./maintenancetool"), parent)//TODO path on mac...
13+
Updater(TOOL_PATH, parent)
814
{}
915

1016
Updater::Updater(const QString &maintenanceToolPath, QObject *parent) :

AutoUpdater/updater_p.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ bool UpdaterPrivate::startUpdateCheck()
104104
this->lastErrorCode = EXIT_SUCCESS;
105105
this->lastErrorLog.clear();
106106

107-
//TODO change on mac
108107
QFileInfo toolInfo(getWorkingDir(QCoreApplication::applicationDirPath()), this->toolPath);
109108
this->mainProcess = new QProcess(this);
110109
this->mainProcess->setProgram(toolInfo.absoluteFilePath());
@@ -252,7 +251,6 @@ void UpdaterPrivate::taskDone(int taskID)
252251
void UpdaterPrivate::appAboutToExit()
253252
{
254253
if(this->runOnExit) {
255-
//TODO change on mac
256254
QFileInfo toolInfo(getWorkingDir(QCoreApplication::applicationDirPath()), this->toolPath);
257255
bool ok = false;
258256
if(this->adminAuth && !this->adminAuth->hasAdminRights()) {

AutoUpdaterWidgets/updatecontroller.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ bool UpdateController::isRunning() const
6868
return d->running;
6969
}
7070

71+
QWidget *UpdateController::parentWindow() const
72+
{
73+
const Q_D(UpdateController);
74+
return d->window;
75+
}
76+
77+
void UpdateController::setParentWindow(QWidget *parentWindow)
78+
{
79+
Q_D(UpdateController);
80+
d->window = parentWindow;
81+
d->infoDialog->setNewParent(parentWindow);
82+
}
83+
7184
bool UpdateController::runAsAdmin() const
7285
{
7386
const Q_D(UpdateController);
@@ -307,8 +320,12 @@ UpdateControllerPrivate::UpdateControllerPrivate(UpdateController *q_ptr, const
307320

308321
UpdateControllerPrivate::~UpdateControllerPrivate()
309322
{
323+
if(this->running) {
324+
qWarning("UpdaterController destroyed while still running! "
325+
"This may crash your application!");
326+
}
327+
328+
this->infoDialog->deleteLater();
310329
for(int taskID : this->updateTasks.keys())
311330
UpdateScheduler::instance()->cancelTask(taskID);
312-
313-
delete this->mainUpdater;
314331
}

AutoUpdaterWidgets/updatecontroller.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
@image html ./doc/images/win/action.png "Update action inside a menu and a toolbar"<br>
2222

2323
## Mac - OsX 10.11
24+
The following pictures show the controller with a parent windows. Thus, all dialogs
25+
are shown as "sheets" to that window. If you create the UpdateController without a widget,
26+
they will show as normal toplevel windows instead.
27+
2428
#### The Updater Elements
2529
@image html ./doc/images/mac/dialog_ask.png "Ask Dialog"<br>
2630
@image html ./doc/images/mac/dialog_progress.png "Progress Dialog"<br>

AutoUpdaterWidgets/updatecontroller.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace QtAutoUpdater
2020
Q_PROPERTY(QString maintenanceToolPath READ maintenanceToolPath CONSTANT)
2121
//! Specifies whether the controller is currently active or not
2222
Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged)
23+
//! Holds the window to be used as parent for all dialogs
24+
Q_PROPERTY(QWidget* parentWindow READ parentWindow WRITE setParentWindow)
2325
//! Specifies whether the controller should run the updater as admin or not
2426
Q_PROPERTY(bool runAsAdmin READ runAsAdmin WRITE setRunAsAdmin)
2527
//! Holds the arguments to invoke the updater with
@@ -59,6 +61,10 @@ namespace QtAutoUpdater
5961
DisplayLevel currentDisplayLevel() const;
6062
//! READ-Accessor for UpdateController::running
6163
bool isRunning() const;
64+
//! READ-Accessor for UpdateController::parentWindow
65+
QWidget* parentWindow() const;
66+
//! WRITE-Accessor for UpdateController::parentWindow
67+
void setParentWindow(QWidget* parentWindow);
6268
//! READ-Accessor for UpdateController::runAsAdmin
6369
bool runAsAdmin() const;
6470
//! WRITE-Accessor for UpdateController::runAsAdmin

AutoUpdaterWidgets/updateinfodialog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ UpdateInfoDialog::~UpdateInfoDialog()
3434
delete ui;
3535
}
3636

37+
void UpdateInfoDialog::setNewParent(QWidget *parent)
38+
{
39+
this->setParent(parent);
40+
if(parent)
41+
this->setWindowModality(Qt::WindowModal);
42+
else
43+
this->setWindowModality(Qt::ApplicationModal);
44+
}
45+
3746
UpdateInfoDialog::DialogResult UpdateInfoDialog::showUpdateInfo(QList<Updater::UpdateInfo> updates, bool &runAsAdmin, bool editable)
3847
{
3948
this->ui->headerLabel->setText(tr("Updates for %1 are available!")

AutoUpdaterWidgets/updateinfodialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace QtAutoUpdater
2424
explicit UpdateInfoDialog(QWidget *parent = 0);
2525
~UpdateInfoDialog();
2626

27+
void setNewParent(QWidget *parent);
28+
2729
DialogResult showUpdateInfo(QList<Updater::UpdateInfo> updates, bool &runAsAdmin, bool editable);
2830

2931
private slots:

Tests/UpdaterTest/tst_updatertest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void UpdaterTest::testUpdaterInitState()
9191
#if defined(Q_OS_WIN32)
9292
QCOMPARE(this->updater->maintenanceToolPath(), QStringLiteral("./maintenancetool.exe"));
9393
#elif defined(Q_OS_OSX)
94-
QCOMPARE(this->updater->maintenanceToolPath(), QStringLiteral("./maintenancetool.app/Contents/MacOS/maintenancetool"));
94+
QCOMPARE(this->updater->maintenanceToolPath(), QStringLiteral("../../maintenancetool.app/Contents/MacOS/maintenancetool"));
9595
#elif defined(Q_OS_UNIX)
9696
QCOMPARE(this->updater->maintenanceToolPath(), QStringLiteral("./maintenancetool"));
9797
#endif

Tests/WidgetsTest/mainwindow.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ MainWindow::MainWindow(QWidget *parent) :
1515

1616
QSettings settings("./set.ini", QSettings::IniFormat);
1717
this->ui->maintenanceToolLineEdit->setText(settings.value("path").toString());
18+
this->ui->hasParentWindowCheckBox->setChecked(settings.value("hasParent", true).toBool());
1819
this->ui->displayLevelComboBox->setCurrentIndex((QtAutoUpdater::UpdateController::DisplayLevel)settings.value("level", QtAutoUpdater::UpdateController::ProgressLevel).toInt());
20+
this->ui->adminCheckBox->setChecked(settings.value("admin", true).toBool());
21+
this->ui->userChangecheckBox->setChecked(settings.value("adminChangable", true).toBool());
1922
}
2023

2124
MainWindow::~MainWindow()
2225
{
2326
QSettings settings("./set.ini", QSettings::IniFormat);
2427
settings.setValue("path", this->ui->maintenanceToolLineEdit->text());
28+
settings.setValue("hasParent", this->ui->hasParentWindowCheckBox->isChecked());
2529
settings.setValue("level", this->ui->displayLevelComboBox->currentIndex());
30+
settings.setValue("admin", this->ui->adminCheckBox->isChecked());
31+
settings.setValue("adminChangable", this->ui->userChangecheckBox->isChecked());
2632
delete ui;
2733
}
2834

@@ -68,7 +74,8 @@ void MainWindow::on_cancelButton_clicked()
6874
void MainWindow::on_activeBox_toggled(bool checked)
6975
{
7076
if(checked) {
71-
this->controller = new QtAutoUpdater::UpdateController(this->ui->maintenanceToolLineEdit->text(), this);
77+
this->controller = new QtAutoUpdater::UpdateController(this->ui->maintenanceToolLineEdit->text(),
78+
this->ui->hasParentWindowCheckBox->isChecked() ? this : NULL);
7279
this->ui->menuHelp->addAction(this->controller->getUpdateAction());
7380
this->ui->mainToolBar->addAction(this->controller->getUpdateAction());
7481
connect(this->controller, &QtAutoUpdater::UpdateController::runningChanged, this, [this](bool running){
@@ -81,3 +88,9 @@ void MainWindow::on_activeBox_toggled(bool checked)
8188
this->statusBar()->showMessage("not running");
8289
}
8390
}
91+
92+
void MainWindow::on_hasParentWindowCheckBox_clicked(bool checked)
93+
{
94+
if(this->controller)
95+
this->controller->setParentWindow(checked ? this : NULL);
96+
}

Tests/WidgetsTest/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ private slots:
2222
void on_cancelButton_clicked();
2323
void on_activeBox_toggled(bool checked);
2424

25+
void on_hasParentWindowCheckBox_clicked(bool checked);
26+
2527
private:
2628
Ui::MainWindow *ui;
2729
QtAutoUpdater::UpdateController *controller;

0 commit comments

Comments
 (0)