VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h@ 76553

Last change on this file since 76553 was 76553, checked in by vboxsync, 5 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: UIProgressDialog.h 76553 2019-01-01 01:45:53Z 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 ___UIProgressDialog_h___
19#define ___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: */
30class QLabel;
31class QProgressBar;
32class QILabel;
33class UIMiniCancelButton;
34class UIProgressEventHandler;
35class 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. */
44class SHARED_LIBRARY_STUFF UIProgressDialog : public QIWithRetranslateUI2<QIDialog>
45{
46 Q_OBJECT;
47
48signals:
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
58public:
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
73public slots:
74
75 /** Shows progress-dialog if it's not yet shown. */
76 void show();
77
78protected:
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
91private 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
104private:
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 whether progress cancel is enabled. */
158 bool m_fCancelEnabled;
159 /** Holds whether the progress has ended. */
160 bool m_fEnded;
161
162 /** Holds the progress event handler instance. */
163 UIProgressEventHandler *m_pEventHandler;
164
165 /** Holds the operation description template. */
166 static const char *m_spcszOpDescTpl;
167};
168
169
170/** QObject reimplementation allowing to effectively track the CProgress object completion
171 * (w/o using CProgress::waitForCompletion() and w/o blocking the calling thread in any other way for too long).
172 * @note The CProgress instance is passed as a non-const reference to the constructor
173 * (to memorize COM errors if they happen), and therefore must not be destroyed
174 * before the created UIProgress instance is destroyed.
175 * @todo To be moved to separate files. */
176class SHARED_LIBRARY_STUFF UIProgress : public QObject
177{
178 Q_OBJECT;
179
180signals:
181
182 /** Notifies listeners about wrapped CProgress change.
183 * @param iOperations Brings the number of operations CProgress have.
184 * @param strOperation Brings the description of the current CProgress operation.
185 * @param iOperation Brings the index of the current CProgress operation.
186 * @param iPercent Brings the percentage of the current CProgress operation. */
187 void sigProgressChange(ulong iOperations, QString strOperation,
188 ulong iOperation, ulong iPercent);
189
190 /** Notifies listeners about particular COM error.
191 * @param strErrorInfo holds the details of the error happened. */
192 void sigProgressError(QString strErrorInfo);
193
194public:
195
196 /** Constructs progress handler passing @a pParent to the base-class.
197 * @param comProgress Brings the progress reference. */
198 UIProgress(CProgress &comProgress, QObject *pParent = 0);
199
200 /** Executes the progress-handler within its loop with passed @a iRefreshInterval. */
201 void run(int iRefreshInterval);
202
203private:
204
205 /** Handles timer @a pEvent. */
206 virtual void timerEvent(QTimerEvent *pEvent) /* override */;
207
208 /** Holds the progress reference. */
209 CProgress &m_comProgress;
210
211 /** Holds the amount of operations. */
212 const ulong m_cOperations;
213 /** Holds whether the progress has ended. */
214 bool m_fEnded;
215
216 /** Holds the personal event-loop instance. */
217 QPointer<QEventLoop> m_pEventLoop;
218};
219
220
221#endif /* !___UIProgressDialog_h___ */
222
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use