VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIProgressTask.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: UIProgressTask.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIProgressTask class implementation.
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/* Qt includes: */
29#include <QTimer>
30
31/* GUI includes: */
32#include "UIProgressTask.h"
33
34
35UIProgressTask::UIProgressTask(QObject *pParent)
36 : QObject(pParent)
37 , m_pTimer(0)
38{
39 prepare();
40}
41
42UIProgressTask::~UIProgressTask()
43{
44 cleanup();
45}
46
47bool UIProgressTask::isScheduled() const
48{
49 AssertPtrReturn(m_pTimer, false);
50 return m_pTimer->isActive();
51}
52
53bool UIProgressTask::isRunning() const
54{
55 return m_pProgressObject;
56}
57
58bool UIProgressTask::isCancelable() const
59{
60 return m_pProgressObject ? m_pProgressObject->isCancelable() : false;
61}
62
63void UIProgressTask::schedule(int iMsec)
64{
65 AssertPtrReturnVoid(m_pTimer);
66 m_pTimer->setInterval(iMsec);
67 m_pTimer->start();
68}
69
70void UIProgressTask::start()
71{
72 /* Ignore request if already running: */
73 if (isRunning())
74 return;
75
76 /* Call for a virtual stuff to create progress-wrapper itself: */
77 m_comProgress = createProgress();
78
79 /* Make sure progress valid: */
80 if ( m_comProgress.isNull()
81 || m_comProgress.GetCompleted())
82 {
83 /* Notify external listeners: */
84 emit sigProgressStarted();
85 sltHandleProgressEventHandlingFinished();
86 }
87 else
88 {
89 /* Prepare progress-object: */
90 m_pProgressObject = new UIProgressObject(m_comProgress, this);
91 if (m_pProgressObject)
92 {
93 /* Setup connections: */
94 connect(m_pProgressObject.data(), &UIProgressObject::sigProgressChange,
95 this, &UIProgressTask::sltHandleProgressChange);
96 connect(m_pProgressObject.data(), &UIProgressObject::sigProgressEventHandlingFinished,
97 this, &UIProgressTask::sltHandleProgressEventHandlingFinished);
98
99 /* Notify external listeners: */
100 emit sigProgressStarted();
101 if (m_comProgress.GetCompleted())
102 sltHandleProgressEventHandlingFinished();
103 }
104 }
105}
106
107void UIProgressTask::cancel()
108{
109 if (m_pProgressObject)
110 {
111 m_pProgressObject->cancel();
112 /* Notify external listeners: */
113 emit sigProgressCanceled();
114 }
115}
116
117void UIProgressTask::sltHandleProgressChange(ulong /*uOperations*/, QString /*strOperation*/,
118 ulong /*uOperation*/, ulong uPercent)
119{
120 /* Notify external listeners: */
121 emit sigProgressChange(uPercent);
122}
123
124void UIProgressTask::sltHandleProgressEventHandlingFinished()
125{
126 /* Call for a virtual stuff to let sub-class handle result: */
127 handleProgressFinished(m_comProgress);
128
129 /* Cleanup progress-object and progress-wrapper: */
130 delete m_pProgressObject;
131 m_comProgress = CProgress();
132
133 /* Notify external listeners: */
134 emit sigProgressFinished();
135}
136
137void UIProgressTask::prepare()
138{
139 /* Prepare schedule-timer: */
140 m_pTimer = new QTimer(this);
141 if (m_pTimer)
142 {
143 m_pTimer->setSingleShot(true);
144 connect(m_pTimer, &QTimer::timeout,
145 this, &UIProgressTask::start);
146 }
147}
148
149void UIProgressTask::cleanup()
150{
151 /* Cleanup progress-object and progress-wrapper: */
152 delete m_pProgressObject;
153 m_comProgress = CProgress();
154
155 /* Cleanup schedule-timer: */
156 delete m_pTimer;
157 m_pTimer = 0;
158}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use