1 | /* $Id: UIProgressDialog.h 78969 2019-06-04 14:59:37Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIProgressDialog class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_widgets_UIProgressDialog_h
|
---|
19 | #define FEQT_INCLUDED_SRC_widgets_UIProgressDialog_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* GUI includes: */
|
---|
25 | #include "QIDialog.h"
|
---|
26 | #include "QIWithRetranslateUI.h"
|
---|
27 | #include "UILibraryDefs.h"
|
---|
28 |
|
---|
29 | /* Forward declarations: */
|
---|
30 | class QLabel;
|
---|
31 | class QProgressBar;
|
---|
32 | class QILabel;
|
---|
33 | class UIMiniCancelButton;
|
---|
34 | class UIProgressEventHandler;
|
---|
35 | class CProgress;
|
---|
36 |
|
---|
37 |
|
---|
38 | /** QProgressDialog enhancement that allows to:
|
---|
39 | * 1) prevent closing the dialog when it has no cancel button;
|
---|
40 | * 2) effectively track the IProgress object completion (w/o using
|
---|
41 | * IProgress::waitForCompletion() and w/o blocking the UI thread in any other way for too long).
|
---|
42 | * @note The CProgress instance is passed as a non-const reference to the constructor (to memorize COM errors if they happen),
|
---|
43 | * and therefore must not be destroyed before the created UIProgressDialog instance is destroyed. */
|
---|
44 | class SHARED_LIBRARY_STUFF UIProgressDialog : public QIWithRetranslateUI2<QIDialog>
|
---|
45 | {
|
---|
46 | Q_OBJECT;
|
---|
47 |
|
---|
48 | signals:
|
---|
49 |
|
---|
50 | /** Notifies listeners about wrapped CProgress change.
|
---|
51 | * @param iOperations Brings the number of operations CProgress have.
|
---|
52 | * @param strOperation Brings the description of the current CProgress operation.
|
---|
53 | * @param iOperation Brings the index of the current CProgress operation.
|
---|
54 | * @param iPercent Brings the percentage of the current CProgress operation. */
|
---|
55 | void sigProgressChange(ulong iOperations, QString strOperation,
|
---|
56 | ulong iOperation, ulong iPercent);
|
---|
57 |
|
---|
58 | public:
|
---|
59 |
|
---|
60 | /** Constructs progress-dialog passing @a pParent to the base-class.
|
---|
61 | * @param comProgress Brings the progress reference.
|
---|
62 | * @param strTitle Brings the progress-dialog title.
|
---|
63 | * @param pImage Brings the progress-dialog image.
|
---|
64 | * @param cMinDuration Brings the minimum duration before the progress-dialog is shown. */
|
---|
65 | UIProgressDialog(CProgress &comProgress, const QString &strTitle,
|
---|
66 | QPixmap *pImage = 0, int cMinDuration = 2000, QWidget *pParent = 0);
|
---|
67 | /** Destructs progress-dialog. */
|
---|
68 | virtual ~UIProgressDialog() /* override */;
|
---|
69 |
|
---|
70 | /** Executes the progress-dialog within its loop with passed @a iRefreshInterval. */
|
---|
71 | int run(int iRefreshInterval);
|
---|
72 |
|
---|
73 | public slots:
|
---|
74 |
|
---|
75 | /** Shows progress-dialog if it's not yet shown. */
|
---|
76 | void show();
|
---|
77 |
|
---|
78 | protected:
|
---|
79 |
|
---|
80 | /** Handles translation event. */
|
---|
81 | virtual void retranslateUi() /* override */;
|
---|
82 |
|
---|
83 | /** Rejects dialog. */
|
---|
84 | virtual void reject() /* override */;
|
---|
85 |
|
---|
86 | /** Handles timer @a pEvent. */
|
---|
87 | virtual void timerEvent(QTimerEvent *pEvent) /* override */;
|
---|
88 | /** Handles close @a pEvent. */
|
---|
89 | virtual void closeEvent(QCloseEvent *pEvent) /* override */;
|
---|
90 |
|
---|
91 | private slots:
|
---|
92 |
|
---|
93 | /** Handles percentage changed event for progress with @a uProgressId to @a iPercent. */
|
---|
94 | void sltHandleProgressPercentageChange(const QUuid &uProgressId, const int iPercent);
|
---|
95 | /** Handles task completed event for progress with @a uProgressId. */
|
---|
96 | void sltHandleProgressTaskComplete(const QUuid &uProgressId);
|
---|
97 |
|
---|
98 | /** Handles window stack changed signal. */
|
---|
99 | void sltHandleWindowStackChange();
|
---|
100 |
|
---|
101 | /** Handles request to cancel operation. */
|
---|
102 | void sltCancelOperation();
|
---|
103 |
|
---|
104 | private:
|
---|
105 |
|
---|
106 | /** Prepares all. */
|
---|
107 | void prepare();
|
---|
108 | /** Prepares event handler. */
|
---|
109 | void prepareEventHandler();
|
---|
110 | /** Prepares widgets. */
|
---|
111 | void prepareWidgets();
|
---|
112 | /** Cleanups widgets. */
|
---|
113 | void cleanupWidgets();
|
---|
114 | /** Cleanups event handler. */
|
---|
115 | void cleanupEventHandler();
|
---|
116 | /** Cleanups all. */
|
---|
117 | void cleanup();
|
---|
118 |
|
---|
119 | /** Updates progress-dialog state. */
|
---|
120 | void updateProgressState();
|
---|
121 | /** Updates progress-dialog percentage. */
|
---|
122 | void updateProgressPercentage(int iPercent = -1);
|
---|
123 |
|
---|
124 | /** Closes progress dialog (if possible). */
|
---|
125 | void closeProgressDialog();
|
---|
126 |
|
---|
127 | /** Performes timer event handling. */
|
---|
128 | void handleTimerEvent();
|
---|
129 |
|
---|
130 | /** Holds the progress reference. */
|
---|
131 | CProgress &m_comProgress;
|
---|
132 | /** Holds the progress-dialog title. */
|
---|
133 | QString m_strTitle;
|
---|
134 | /** Holds the dialog image. */
|
---|
135 | QPixmap *m_pImage;
|
---|
136 | /** Holds the minimum duration before the progress-dialog is shown. */
|
---|
137 | int m_cMinDuration;
|
---|
138 |
|
---|
139 | /** Holds whether legacy handling is requested for this progress. */
|
---|
140 | bool m_fLegacyHandling;
|
---|
141 |
|
---|
142 | /** Holds the image label instance. */
|
---|
143 | QLabel *m_pLabelImage;
|
---|
144 | /** Holds the description label instance. */
|
---|
145 | QILabel *m_pLabelDescription;
|
---|
146 | /** Holds the progress-bar instance. */
|
---|
147 | QProgressBar *m_pProgressBar;
|
---|
148 | /** Holds the cancel button instance. */
|
---|
149 | UIMiniCancelButton *m_pButtonCancel;
|
---|
150 | /** Holds the ETA label instance. */
|
---|
151 | QILabel *m_pLabelEta;
|
---|
152 |
|
---|
153 | /** Holds the amount of operations. */
|
---|
154 | const ulong m_cOperations;
|
---|
155 | /** Holds the number of current operation. */
|
---|
156 | ulong m_uCurrentOperation;
|
---|
157 | /** Holds the weight of current operation. */
|
---|
158 | ulong m_uCurrentOperationWeight;
|
---|
159 | /** Holds whether progress cancel is enabled. */
|
---|
160 | bool m_fCancelEnabled;
|
---|
161 | /** Holds whether the progress has ended. */
|
---|
162 | bool m_fEnded;
|
---|
163 |
|
---|
164 | /** Holds the progress event handler instance. */
|
---|
165 | UIProgressEventHandler *m_pEventHandler;
|
---|
166 |
|
---|
167 | /** Holds the operation description template. */
|
---|
168 | static const char *m_spcszOpDescTpl;
|
---|
169 | };
|
---|
170 |
|
---|
171 |
|
---|
172 | /** QObject reimplementation allowing to effectively track the CProgress object completion
|
---|
173 | * (w/o using CProgress::waitForCompletion() and w/o blocking the calling thread in any other way for too long).
|
---|
174 | * @note The CProgress instance is passed as a non-const reference to the constructor
|
---|
175 | * (to memorize COM errors if they happen), and therefore must not be destroyed
|
---|
176 | * before the created UIProgress instance is destroyed.
|
---|
177 | * @todo To be moved to separate files. */
|
---|
178 | class SHARED_LIBRARY_STUFF UIProgress : public QObject
|
---|
179 | {
|
---|
180 | Q_OBJECT;
|
---|
181 |
|
---|
182 | signals:
|
---|
183 |
|
---|
184 | /** Notifies listeners about wrapped CProgress change.
|
---|
185 | * @param iOperations Brings the number of operations CProgress have.
|
---|
186 | * @param strOperation Brings the description of the current CProgress operation.
|
---|
187 | * @param iOperation Brings the index of the current CProgress operation.
|
---|
188 | * @param iPercent Brings the percentage of the current CProgress operation. */
|
---|
189 | void sigProgressChange(ulong iOperations, QString strOperation,
|
---|
190 | ulong iOperation, ulong iPercent);
|
---|
191 |
|
---|
192 | /** Notifies listeners about particular COM error.
|
---|
193 | * @param strErrorInfo holds the details of the error happened. */
|
---|
194 | void sigProgressError(QString strErrorInfo);
|
---|
195 |
|
---|
196 | public:
|
---|
197 |
|
---|
198 | /** Constructs progress handler passing @a pParent to the base-class.
|
---|
199 | * @param comProgress Brings the progress reference. */
|
---|
200 | UIProgress(CProgress &comProgress, QObject *pParent = 0);
|
---|
201 |
|
---|
202 | /** Executes the progress-handler within its loop with passed @a iRefreshInterval. */
|
---|
203 | void run(int iRefreshInterval);
|
---|
204 |
|
---|
205 | private:
|
---|
206 |
|
---|
207 | /** Handles timer @a pEvent. */
|
---|
208 | virtual void timerEvent(QTimerEvent *pEvent) /* override */;
|
---|
209 |
|
---|
210 | /** Holds the progress reference. */
|
---|
211 | CProgress &m_comProgress;
|
---|
212 |
|
---|
213 | /** Holds the amount of operations. */
|
---|
214 | const ulong m_cOperations;
|
---|
215 | /** Holds whether the progress has ended. */
|
---|
216 | bool m_fEnded;
|
---|
217 |
|
---|
218 | /** Holds the personal event-loop instance. */
|
---|
219 | QPointer<QEventLoop> m_pEventLoop;
|
---|
220 | };
|
---|
221 |
|
---|
222 |
|
---|
223 | #endif /* !FEQT_INCLUDED_SRC_widgets_UIProgressDialog_h */
|
---|
224 |
|
---|