1 | /* $Id: UIProgressTask.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIProgressTask class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-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_UIProgressTask_h
|
---|
29 | #define FEQT_INCLUDED_SRC_globals_UIProgressTask_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QObject>
|
---|
36 | #include <QPointer>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 | #include "UIProgressObject.h"
|
---|
41 |
|
---|
42 | /* COM includes: */
|
---|
43 | #include "CProgress.h"
|
---|
44 |
|
---|
45 | /* Forward declarations: */
|
---|
46 | class QTimer;
|
---|
47 |
|
---|
48 | /** QObject-based interface allowing to plan UIProgressObject-based tasks
|
---|
49 | * to be seamlessly and asynchronously scheduled (in time) and executed. */
|
---|
50 | class SHARED_LIBRARY_STUFF UIProgressTask : public QObject
|
---|
51 | {
|
---|
52 | Q_OBJECT;
|
---|
53 |
|
---|
54 | signals:
|
---|
55 |
|
---|
56 | /** Notifies listeners about progress has started. */
|
---|
57 | void sigProgressStarted();
|
---|
58 | /** Notifies listeners about progress has changed.
|
---|
59 | * @param uPercent Brings the progress percentage. */
|
---|
60 | void sigProgressChange(ulong uPercent);
|
---|
61 | /** Notifies listeners about progress was canceled. */
|
---|
62 | void sigProgressCanceled();
|
---|
63 | /** Notifies listeners about progress has finished. */
|
---|
64 | void sigProgressFinished();
|
---|
65 |
|
---|
66 | public:
|
---|
67 |
|
---|
68 | /** Creates progress task passing @a pParent to the base-class. */
|
---|
69 | UIProgressTask(QObject *pParent);
|
---|
70 | /** Creates progress task passing @a pParent to the base-class. */
|
---|
71 | virtual ~UIProgressTask() RT_OVERRIDE;
|
---|
72 |
|
---|
73 | /** Returns whether task is scheduled. */
|
---|
74 | bool isScheduled() const;
|
---|
75 |
|
---|
76 | /** Returns whether task is running. */
|
---|
77 | bool isRunning() const;
|
---|
78 |
|
---|
79 | /** Returns whether task is cancelable. */
|
---|
80 | bool isCancelable() const;
|
---|
81 |
|
---|
82 | public slots:
|
---|
83 |
|
---|
84 | /** Schedules task to be executed in @a iMsec. */
|
---|
85 | void schedule(int iMsec);
|
---|
86 |
|
---|
87 | /** Starts the task directly.
|
---|
88 | * @note It will also be started automatically if scheduled. */
|
---|
89 | void start();
|
---|
90 | /** Cancels the task directly. */
|
---|
91 | void cancel();
|
---|
92 |
|
---|
93 | protected:
|
---|
94 |
|
---|
95 | /** Creates and returns started progress-wrapper required to init UIProgressObject. */
|
---|
96 | virtual CProgress createProgress() = 0;
|
---|
97 | /** Allows sub-class to handle finished @a comProgress wrapper. */
|
---|
98 | virtual void handleProgressFinished(CProgress &comProgress) = 0;
|
---|
99 |
|
---|
100 | private slots:
|
---|
101 |
|
---|
102 | /** Handles progress change.
|
---|
103 | * @param iOperations Brings the number of operations CProgress have.
|
---|
104 | * @param strOperation Brings the description of the current CProgress operation.
|
---|
105 | * @param iOperation Brings the index of the current CProgress operation.
|
---|
106 | * @param iPercent Brings the percentage of the current CProgress operation. */
|
---|
107 | void sltHandleProgressChange(ulong uOperations, QString strOperation,
|
---|
108 | ulong uOperation, ulong uPercent);
|
---|
109 | /** Handles progress event handling finished signal. */
|
---|
110 | void sltHandleProgressEventHandlingFinished();
|
---|
111 |
|
---|
112 | private:
|
---|
113 |
|
---|
114 | /** Prepares all. */
|
---|
115 | void prepare();
|
---|
116 | /** Cleanups all. */
|
---|
117 | void cleanup();
|
---|
118 |
|
---|
119 | /** Holds the schedule timer instance. */
|
---|
120 | QTimer *m_pTimer;
|
---|
121 | /** Holds the progress-wrapper instance. */
|
---|
122 | CProgress m_comProgress;
|
---|
123 | /** Holds the progress-object instance. */
|
---|
124 | QPointer<UIProgressObject> m_pProgressObject;
|
---|
125 | };
|
---|
126 |
|
---|
127 | #endif /* !FEQT_INCLUDED_SRC_globals_UIProgressTask_h */
|
---|