Skip to content

Commit a86a9be

Browse files
committed
WIP controller doc
1 parent a4cd7b0 commit a86a9be

File tree

7 files changed

+221
-21
lines changed

7 files changed

+221
-21
lines changed

AutoUpdater/updater.dox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ See Updater::maintenanceToolPath for more details.
156156
@fn QtAutoUpdater::Updater::Updater(const QString &, QObject *)
157157

158158
@overload
159-
@param maintenanceToolPath The path to the maintenancetool executable
159+
@param maintenanceToolPath The path to the maintenancetool
160160
@param parent The object parent for QObject
161161

162162
The maintenancetool path will be set to the given one (and cannot be changed).

AutoUpdaterWidgets/updatecontroller.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ UpdateController::UpdateController(QObject *parent) :
1919
d_ptr(new UpdateControllerPrivate(this, NULL))
2020
{}
2121

22-
UpdateController::UpdateController(QWidget *parentWindow) :
23-
QObject(parentWindow),
24-
d_ptr(new UpdateControllerPrivate(this, parentWindow))
22+
UpdateController::UpdateController(QWidget *parentWidget) :
23+
QObject(parentWidget),
24+
d_ptr(new UpdateControllerPrivate(this, parentWidget))
2525
{}
2626

2727
UpdateController::UpdateController(const QString &maintenanceToolPath, QObject *parent) :
2828
QObject(parent),
2929
d_ptr(new UpdateControllerPrivate(this, maintenanceToolPath, NULL))
3030
{}
3131

32-
UpdateController::UpdateController(const QString &maintenanceToolPath, QWidget *parentWindow) :
33-
QObject(parentWindow),
34-
d_ptr(new UpdateControllerPrivate(this, maintenanceToolPath, parentWindow))
32+
UpdateController::UpdateController(const QString &maintenanceToolPath, QWidget *parentWidget) :
33+
QObject(parentWidget),
34+
d_ptr(new UpdateControllerPrivate(this, maintenanceToolPath, parentWidget))
3535
{}
3636

3737
UpdateController::~UpdateController()
@@ -81,6 +81,7 @@ void UpdateController::setRunAsAdmin(bool runAsAdmin, bool userEditable)
8181
d->runAdmin = runAsAdmin;
8282
if(d->mainUpdater->willRunOnExit())
8383
d->mainUpdater->runUpdaterOnExit(d->runAdmin ? new AdminAuthorization() : NULL);
84+
emit runAsAdminChanged(runAsAdmin);
8485
}
8586
d->adminUserEdit = userEditable;
8687
}
@@ -222,7 +223,14 @@ void UpdateController::checkUpdatesDone(bool hasUpdates, bool hasError)
222223
if(hasUpdates) {
223224
if(d->displayLevel >= InfoLevel) {
224225
bool shouldShutDown = false;
225-
switch(d->infoDialog->showUpdateInfo(d->mainUpdater->updateInfo(), d->runAdmin, d->adminUserEdit)) {
226+
bool oldRunAdmin = d->runAdmin;
227+
UpdateInfoDialog::DialogResult res = d->infoDialog->showUpdateInfo(d->mainUpdater->updateInfo(),
228+
d->runAdmin,
229+
d->adminUserEdit);
230+
if(d->runAdmin != oldRunAdmin)
231+
emit runAsAdminChanged(d->runAdmin);
232+
233+
switch(res) {
226234
case UpdateInfoDialog::InstallNow:
227235
shouldShutDown = true;
228236
case UpdateInfoDialog::InstallLater:

AutoUpdaterWidgets/updatecontroller.dox

Lines changed: 184 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ int main(int argc, char *argv[])
118118
@endcode
119119
*/
120120

121+
/*!
122+
@enum QtAutoUpdater::UpdateController::DisplayLevel
123+
124+
The display level controlls the kind of dialogs shown to the user. Levels are ranked from
125+
the lowest (`AutomaticLevel = 0`) to the highest (`AskLevel = 5`). Each Level includes all
126+
levels with a smaller value, i.e. using the `AskLevel` will add the ask dialog to everything
127+
shown with `ProgressLevel`, but not less.
128+
129+
@sa @ref image_page "Image Page"
130+
*/
131+
121132
/*!
122133
@property QtAutoUpdater::UpdateController::maintenanceToolPath
123134

@@ -136,7 +147,7 @@ documentation of that property for more details.
136147
*/
137148

138149
/*!
139-
@property QtAutoUpdater::Updater::running
150+
@property QtAutoUpdater::UpdateController::running
140151

141152
@default{`false`}
142153

@@ -154,7 +165,7 @@ property of the attached updater can return `false` while this one returns `true
154165
*/
155166

156167
/*!
157-
@property QtAutoUpdater::Updater::runAsAdmin
168+
@property QtAutoUpdater::UpdateController::runAsAdmin
158169

159170
@default{`true`}
160171

@@ -169,7 +180,177 @@ the write accessor function of this property.
169180
@accessors{
170181
@readAc{runAsAdmin()}
171182
@writeAc{setRunAsAdmin()}
183+
@notifyAc{runAsAdminChanged()}
172184
}
173185

174-
@sa UpdateController::getUpdater, UpdateController::start, UpdateController::cancelUpdate
186+
@sa UpdateController::setRunAsAdmin, UpdateController::updateRunArgs
187+
*/
188+
189+
/*!
190+
@property QtAutoUpdater::UpdateController::updateRunArgs
191+
192+
@default{`{"--updater"}`}
193+
194+
These arguments will be used to invoke the updater with it on exit (if updates are
195+
available). See Updater::runUpdaterOnExit(AdminAuthoriser *) for more details about
196+
"running on exit". If UpdateController::runAsAdmin is set to `true`, the maintenancetool
197+
will be run with elevated rights.
198+
199+
@accessors{
200+
@readAc{updateRunArgs()}
201+
@writeAc{setUpdateRunArgs()}
202+
@resetAc{resetUpdateRunArgs()}
203+
}
204+
205+
@sa UpdateController::runAsAdmin, Updater::runUpdaterOnExit(AdminAuthoriser *)
206+
*/
207+
208+
/*!
209+
@fn QtAutoUpdater::UpdateController::UpdateController(QObject *)
210+
211+
@overload
212+
@param parent The parent object. Will serve as parent for the controller
213+
214+
The created controller will not be bound to a specific window. Instead, all it's dialogs
215+
will be top-level windows without a parent and application modal.
216+
217+
@note If you set `parent` to anything but `NULL`, make shure the parent object lives long
218+
enough for the controller to receive the QCoreApplication::aboutToQuit signal, since thats
219+
required for the updater to show the maintenancetool as updater.
220+
221+
@overloads{
222+
@povElem{UpdateController(QObject *)}
223+
@povElem{UpdateController(QWidget *)}
224+
@ovElem{UpdateController(const QString &, QObject *)}
225+
@ovElem{UpdateController(const QString &, QWidget *)}
226+
}
227+
228+
@sa QObject::parent, UpdateController::setParent(QObject *)
229+
*/
230+
231+
/*!
232+
@fn QtAutoUpdater::UpdateController::UpdateController(QWidget *)
233+
234+
@overload
235+
@param parentWidget The parent widget. Will serve as parent for the controller and windows
236+
237+
The created controller will be bound to the widget. This means all dialogs will be child
238+
windows of the widgets window. On Mac, dialogs will be shown as "Sheets" of the parent
239+
window.
240+
241+
@note If you set `parent` to anything but `NULL`, make shure the parent object lives long
242+
enough for the controller to receive the QCoreApplication::aboutToQuit signal, since thats
243+
required for the updater to show the maintenancetool as updater.
244+
245+
@overloads{
246+
@povElem{UpdateController(QObject *)}
247+
@povElem{UpdateController(QWidget *)}
248+
@ovElem{UpdateController(const QString &, QObject *)}
249+
@ovElem{UpdateController(const QString &, QWidget *)}
250+
}
251+
252+
@sa UpdateController::parentWidget, UpdateController::setParent(QWidget *)
253+
*/
254+
255+
/*!
256+
@fn QtAutoUpdater::UpdateController::UpdateController(const QString &, QObject *)
257+
258+
@overload
259+
@param maintenanceToolPath The path to the maintenancetool
260+
@param parent The parent object. Will serve as parent for the controller
261+
262+
The maintenancetool path will be set to the given one (and cannot be changed). See
263+
UpdateController::maintenanceToolPath for more details.
264+
265+
@overloads{
266+
@povElem{UpdateController(QObject *)}
267+
@povElem{UpdateController(QWidget *)}
268+
@ovElem{UpdateController(const QString &, QObject *)}
269+
@ovElem{UpdateController(const QString &, QWidget *)}
270+
}
271+
272+
@sa QObject::parent, UpdateController::setParent(QObject *), UpdateController::maintenanceToolPath
273+
*/
274+
275+
/*!
276+
@fn QtAutoUpdater::UpdateController::UpdateController(const QString &, QWidget *)
277+
278+
@overload
279+
@param maintenanceToolPath The path to the maintenancetool
280+
@param parentWidget The parent widget. Will serve as parent for the controller and windows
281+
282+
The maintenancetool path will be set to the given one (and cannot be changed). See
283+
UpdateController::maintenanceToolPath for more details.
284+
285+
@overloads{
286+
@povElem{UpdateController(QObject *)}
287+
@povElem{UpdateController(QWidget *)}
288+
@ovElem{UpdateController(const QString &, QObject *)}
289+
@ovElem{UpdateController(const QString &, QWidget *)}
290+
}
291+
292+
@sa UpdateController::parentWidget, UpdateController::setParent(QWidget *), UpdateController::maintenanceToolPath
293+
*/
294+
295+
/*!
296+
@fn QtAutoUpdater::UpdateController::getUpdateAction
297+
298+
@returns The action associated with this controller
299+
300+
The action will automatically start the controller with the display-level
301+
`UpdateController::ProgressLevel`. In addition to that, the action will be automatically
302+
disabled if the controller is already running. For images check the
303+
@ref image_page "Image Page".
304+
305+
The action has a text, an icon and a tooltip. The icon is set to be only visibile in a
306+
toolbar, not in a menu. On Mac, the action will be place in the Applications menu if
307+
added to the Menubar.
308+
309+
@attention This function will always return the same QAction object for each controller.
310+
Thus, you may never delete the action. It will be deleted on destruction of the the
311+
controller. Take in mind that any change you make to this action (for example change the
312+
icon) will thus be that way for *all* components that use this action.
313+
314+
@sa UpdateController::createUpdatePanel, @ref image_page "Image Page"
315+
*/
316+
317+
/*!
318+
@fn QtAutoUpdater::UpdateController::createUpdatePanel
319+
320+
@param parentWidget The parent widget of the update panel widget
321+
@returns The action associated with this controller
322+
323+
The UpdatePanel is a ready-made "button" to check for updates. It is connected to this
324+
controller and thus will automatically start checking for updates with the level
325+
`UpdateController::ExtendedInfoLevel`. Since the panel itself shows a progress, no progress
326+
dialog is needed here. For images check the @ref image_page "Image Page".
327+
328+
The panel will represent the controllers state and automatically enable/disable itself to
329+
avoid start beeing called twice. In addition to that, the whole panel widget will be disabled
330+
if the controller gets deleted while the panel is still existings. (Even if it wasn't,
331+
it will not crash if the button is clicked).
332+
333+
@note The UpdatePanel class itself is an internal class. Reason: It directly derives from
334+
QWidget and does not add any new public accessible functions. Thus, even if the class would
335+
be returned, there would be no difference to a QWidget except of the pointer type.
336+
337+
@sa UpdateController::getUpdateAction, @ref image_page "Image Page"
338+
*/
339+
340+
/*!
341+
@fn QtAutoUpdater::UpdateController::setRunAsAdmin
342+
343+
<b>Property: UpdateController::runAsAdmin</b>
344+
345+
@param runAsAdmin `true`, if the maintenancetool should be run as admin/root, `false` to
346+
run it with the rights of the current user
347+
@param userEditable If set to `true`, the user can change this value in the info dialog.
348+
If set to `false`, he will not be able to do so
349+
350+
The second parameter allows you to disable the change of this property by the user. If
351+
`userEditable` is true, the user can check/uncheck a checkbox in the info dialog. If
352+
`false`, this checkbox will be disabled. (The user can see the required rights, but not
353+
change them)
354+
355+
@sa UpdateController::runAsAdmin
175356
*/

AutoUpdaterWidgets/updatecontroller.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,32 @@ namespace QtAutoUpdater
2121
//! Specifies whether the controller is currently active or not
2222
Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged)
2323
//! Specifies whether the controller should run the updater as admin or not
24-
Q_PROPERTY(bool runAsAdmin READ runAsAdmin WRITE setRunAsAdmin)
24+
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)
2727

2828
public:
2929
//! Defines the different display-levels of the dialog
3030
enum DisplayLevel {
3131
AutomaticLevel = 0,//!< The lowest level. Nothing will be displayed at all.
32-
ExitLevel = 1,//!< The whole updating works completly automatically. Only a notification that updates are ready to install will be shown.
33-
InfoLevel = 2,//!< Will show information about updates if available, nothing otherwise
34-
ExtendedInfoLevel = 3,//!< Will shwo information about the update result, for both cases, updates and no updates
35-
ProgressLevel = 4,//!< Shows a (modal) progress dialog while checking for updates
36-
AskLevel = 5//!< The highest level. Will ask the user if he wants to check for updates before actually checking
32+
ExitLevel = 1,/*!< The whole updating works completly automatically without displaying anything. Only
33+
* a notification that updates are ready to install will be shown if updates are available.
34+
*/
35+
InfoLevel = 2,//!< Will show information about updates if available, nothing otherwise.
36+
ExtendedInfoLevel = 3,//!< Will show information about the update result, for both cases, updates and no updates.
37+
ProgressLevel = 4,//!< Shows a (modal) progress dialog while checking for updates.
38+
AskLevel = 5//!< The highest level. Will ask the user if he wants to check for updates before actually checking.
3739
};
3840
Q_ENUM(DisplayLevel)
3941

4042
//! Constructs a new controller with a parent. Will be application modal
4143
explicit UpdateController(QObject *parent = NULL);
4244
//! Constructs a new controller with a parent. Will modal to the parent window
43-
explicit UpdateController(QWidget *parentWindow);
45+
explicit UpdateController(QWidget *parentWidget);
4446
//! Constructs a new controller with an explicitly set path and a parent. Will modal to the parent window
4547
explicit UpdateController(const QString &maintenanceToolPath, QObject *parent = NULL);
4648
//! Constructs a new controller with an explicitly set path and a parent. Will be application modal
47-
explicit UpdateController(const QString &maintenanceToolPath, QWidget *parentWindow);
49+
explicit UpdateController(const QString &maintenanceToolPath, QWidget *parentWidget);
4850
//! Destructor
4951
~UpdateController();
5052

@@ -102,6 +104,8 @@ namespace QtAutoUpdater
102104
signals:
103105
//! NOTIFY-Accessor for UpdateController::running
104106
void runningChanged(bool running);
107+
//! NOTIFY-Accessor for UpdateController::runAsAdmin
108+
void runAsAdminChanged(bool runAsAdmin);
105109

106110
private slots:
107111
void checkUpdatesDone(bool hasUpdates, bool hasError);

AutoUpdaterWidgets/updateinfodialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace QtAutoUpdater
2626

2727
void setNewParent(QWidget *parent);
2828

29+
//TODO make static
2930
DialogResult showUpdateInfo(QList<Updater::UpdateInfo> updates, bool &runAsAdmin, bool editable);
3031

3132
private slots:

AutoUpdaterWidgets/updatepanel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ UpdatePanel::UpdatePanel(UpdateController *controller, QWidget *parent) :
2626
this, &UpdatePanel::changeUpdaterState);
2727
connect(this->controller->getUpdater(), &Updater::checkUpdatesDone,
2828
this, &UpdatePanel::updatesReady);
29+
connect(this->controller, &UpdateController::destroyed,
30+
this, [this](){
31+
this->setDisabled(true);
32+
});
2933
}
3034

3135
UpdatePanel::~UpdatePanel()
@@ -35,7 +39,8 @@ UpdatePanel::~UpdatePanel()
3539

3640
void UpdatePanel::startUpdate()
3741
{
38-
this->controller->start(UpdateController::ExtendedInfoLevel);
42+
if(!this->controller.isNull())
43+
this->controller->start(UpdateController::ExtendedInfoLevel);
3944
}
4045

4146
void UpdatePanel::changeUpdaterState(bool isRunning)

AutoUpdaterWidgets/updatepanel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define UPDATEPANEL_H
33

44
#include <QWidget>
5+
#include <QPointer>
56
#include <QMovie>
67

78
namespace Ui {
@@ -25,7 +26,7 @@ namespace QtAutoUpdater
2526
void updatesReady(bool hasUpdate, bool);
2627

2728
private:
28-
UpdateController *controller;
29+
QPointer<UpdateController> controller;
2930
Ui::UpdatePanel *ui;
3031
QMovie *loadingGif;
3132
};

0 commit comments

Comments
 (0)