VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: UIProgressDialog.h 104358 2024-04-18 05:33:40Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIProgressDialog class declaration.
4 */
5
6/*
7 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef FEQT_INCLUDED_SRC_widgets_UIProgressDialog_h
29#define FEQT_INCLUDED_SRC_widgets_UIProgressDialog_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* GUI includes: */
35#include "QIDialog.h"
36#include "UILibraryDefs.h"
37
38/* Forward declarations: */
39class QLabel;
40class QProgressBar;
41class QILabel;
42class UIMiniCancelButton;
43class UIProgressEventHandler;
44class CProgress;
45
46/** QProgressDialog enhancement that allows to:
47 * 1) prevent closing the dialog when it has no cancel button;
48 * 2) effectively track the IProgress object completion (w/o using
49 * IProgress::waitForCompletion() and w/o blocking the UI thread in any other way for too long).
50 * @note The CProgress instance is passed as a non-const reference to the constructor (to memorize COM errors if they happen),
51 * and therefore must not be destroyed before the created UIProgressDialog instance is destroyed. */
52class SHARED_LIBRARY_STUFF UIProgressDialog : public QIDialog
53{
54 Q_OBJECT;
55
56signals:
57
58 /** Notifies listeners about wrapped CProgress change.
59 * @param iOperations Brings the number of operations CProgress have.
60 * @param strOperation Brings the description of the current CProgress operation.
61 * @param iOperation Brings the index of the current CProgress operation.
62 * @param iPercent Brings the percentage of the current CProgress operation. */
63 void sigProgressChange(ulong iOperations, QString strOperation,
64 ulong iOperation, ulong iPercent);
65
66public:
67
68 /** Constructs progress-dialog passing @a pParent to the base-class.
69 * @param comProgress Brings the progress reference.
70 * @param strTitle Brings the progress-dialog title.
71 * @param pImage Brings the progress-dialog image.
72 * @param cMinDuration Brings the minimum duration before the progress-dialog is shown. */
73 UIProgressDialog(CProgress &comProgress, const QString &strTitle,
74 QPixmap *pImage = 0, int cMinDuration = 2000, QWidget *pParent = 0);
75 /** Destructs progress-dialog. */
76 virtual ~UIProgressDialog() RT_OVERRIDE;
77
78 /** Executes the progress-dialog within its loop with passed @a iRefreshInterval. */
79 int run(int iRefreshInterval);
80
81public slots:
82
83 /** Shows progress-dialog if it's not yet shown. */
84 void show();
85
86protected:
87
88 /** Rejects dialog. */
89 virtual void reject() RT_OVERRIDE;
90
91 /** Handles timer @a pEvent. */
92 virtual void timerEvent(QTimerEvent *pEvent) RT_OVERRIDE;
93 /** Handles close @a pEvent. */
94 virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
95
96private slots:
97
98 /** Handles percentage changed event for progress with @a uProgressId to @a iPercent. */
99 void sltHandleProgressPercentageChange(const QUuid &uProgressId, const int iPercent);
100 /** Handles task completed event for progress with @a uProgressId. */
101 void sltHandleProgressTaskComplete(const QUuid &uProgressId);
102
103 /** Handles window stack changed signal. */
104 void sltHandleWindowStackChange();
105
106 /** Handles request to cancel operation. */
107 void sltCancelOperation();
108
109 /** Handles translation event. */
110 void sltRetranslateUI();
111
112private:
113
114 /** Prepares all. */
115 void prepare();
116 /** Prepares event handler. */
117 void prepareEventHandler();
118 /** Prepares widgets. */
119 void prepareWidgets();
120 /** Cleanups widgets. */
121 void cleanupWidgets();
122 /** Cleanups event handler. */
123 void cleanupEventHandler();
124 /** Cleanups all. */
125 void cleanup();
126
127 /** Updates progress-dialog state. */
128 void updateProgressState();
129 /** Updates progress-dialog percentage. */
130 void updateProgressPercentage(int iPercent = -1);
131
132 /** Closes progress dialog (if possible). */
133 void closeProgressDialog();
134
135 /** Performes timer event handling. */
136 void handleTimerEvent();
137
138 /** Holds the progress reference. */
139 CProgress &m_comProgress;
140 /** Holds the progress-dialog title. */
141 QString m_strTitle;
142 /** Holds the dialog image. */
143 QPixmap *m_pImage;
144 /** Holds the minimum duration before the progress-dialog is shown. */
145 int m_cMinDuration;
146
147 /** Holds whether legacy handling is requested for this progress. */
148 bool m_fLegacyHandling;
149
150 /** Holds the image label instance. */
151 QLabel *m_pLabelImage;
152 /** Holds the description label instance. */
153 QILabel *m_pLabelDescription;
154 /** Holds the progress-bar instance. */
155 QProgressBar *m_pProgressBar;
156 /** Holds the cancel button instance. */
157 UIMiniCancelButton *m_pButtonCancel;
158 /** Holds the ETA label instance. */
159 QILabel *m_pLabelEta;
160
161 /** Holds the amount of operations. */
162 const ulong m_cOperations;
163 /** Holds the number of current operation. */
164 ulong m_uCurrentOperation;
165 /** Holds the weight of current operation. */
166 ulong m_uCurrentOperationWeight;
167 /** Holds whether progress cancel is enabled. */
168 bool m_fCancelEnabled;
169 /** Holds whether the progress has ended. */
170 bool m_fEnded;
171
172 /** Holds the progress event handler instance. */
173 UIProgressEventHandler *m_pEventHandler;
174
175 /** Holds the operation description template. */
176 static const char *m_spcszOpDescTpl;
177};
178
179#endif /* !FEQT_INCLUDED_SRC_widgets_UIProgressDialog_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use