1 | /* $Id: UIProgressObject.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIProgressObject 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_globals_UIProgressObject_h
|
---|
29 | #define FEQT_INCLUDED_SRC_globals_UIProgressObject_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QEventLoop>
|
---|
36 | #include <QObject>
|
---|
37 | #include <QPointer>
|
---|
38 |
|
---|
39 | /* GUI includes: */
|
---|
40 | #include "UILibraryDefs.h"
|
---|
41 |
|
---|
42 | /* Forward declarations: */
|
---|
43 | class UIProgressEventHandler;
|
---|
44 | class CProgress;
|
---|
45 |
|
---|
46 | /** QObject reimplementation allowing to effectively track the CProgress object completion
|
---|
47 | * (w/o using CProgress::waitForCompletion() and w/o blocking the calling thread in any other way for too long).
|
---|
48 | * @note The CProgress instance is passed as a non-const reference to the constructor
|
---|
49 | * (to memorize COM errors if they happen), and therefore must not be destroyed
|
---|
50 | * before the created UIProgressObject instance is destroyed. */
|
---|
51 | class SHARED_LIBRARY_STUFF UIProgressObject : public QObject
|
---|
52 | {
|
---|
53 | Q_OBJECT;
|
---|
54 |
|
---|
55 | signals:
|
---|
56 |
|
---|
57 | /** Notifies listeners about wrapped CProgress change.
|
---|
58 | * @param iOperations Brings the number of operations CProgress have.
|
---|
59 | * @param strOperation Brings the description of the current CProgress operation.
|
---|
60 | * @param iOperation Brings the index of the current CProgress operation.
|
---|
61 | * @param iPercent Brings the percentage of the current CProgress operation. */
|
---|
62 | void sigProgressChange(ulong iOperations, QString strOperation,
|
---|
63 | ulong iOperation, ulong iPercent);
|
---|
64 |
|
---|
65 | /** Notifies listeners about particular COM error.
|
---|
66 | * @param strErrorInfo holds the details of the error happened. */
|
---|
67 | void sigProgressError(QString strErrorInfo);
|
---|
68 |
|
---|
69 | /** Notifies listeners about wrapped CProgress complete. */
|
---|
70 | void sigProgressComplete();
|
---|
71 |
|
---|
72 | /** Notifies listeners about CProgress event handling finished. */
|
---|
73 | void sigProgressEventHandlingFinished();
|
---|
74 |
|
---|
75 | public:
|
---|
76 |
|
---|
77 | /** Constructs progress-object passing @a pParent to the base-class.
|
---|
78 | * @param comProgress Brings the progress reference. */
|
---|
79 | UIProgressObject(CProgress &comProgress, QObject *pParent = 0);
|
---|
80 | /** Destructs progress handler. */
|
---|
81 | virtual ~UIProgressObject() RT_OVERRIDE;
|
---|
82 |
|
---|
83 | /** Returns whether progress is cancelable. */
|
---|
84 | bool isCancelable() const { return m_fCancelable; }
|
---|
85 |
|
---|
86 | /** Executes the progress within local event-loop. */
|
---|
87 | void exec();
|
---|
88 | /** Cancels the progress within local event-loop. */
|
---|
89 | void cancel();
|
---|
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 | private:
|
---|
99 |
|
---|
100 | /** Prepares all. */
|
---|
101 | void prepare();
|
---|
102 | /** Cleanups all. */
|
---|
103 | void cleanup();
|
---|
104 |
|
---|
105 | /** Holds the progress reference. */
|
---|
106 | CProgress &m_comProgress;
|
---|
107 |
|
---|
108 | /** Holds whether progress is cancelable. */
|
---|
109 | bool m_fCancelable;
|
---|
110 |
|
---|
111 | /** Holds the progress event handler instance. */
|
---|
112 | UIProgressEventHandler *m_pEventHandler;
|
---|
113 |
|
---|
114 | /** Holds the exec event-loop instance. */
|
---|
115 | QPointer<QEventLoop> m_pEventLoopExec;
|
---|
116 | /** Holds the cancel event-loop instance. */
|
---|
117 | QPointer<QEventLoop> m_pEventLoopCancel;
|
---|
118 | };
|
---|
119 |
|
---|
120 | #endif /* !FEQT_INCLUDED_SRC_globals_UIProgressObject_h */
|
---|