VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.cpp@ 103977

Last change on this file since 103977 was 100590, checked in by vboxsync, 17 months ago

FE/Qt: bugref:10323: Runtime UI: Close downloaders such as GA, ExtPack and UserManual on completion; Similar to what we do with other types of progresses.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/* $Id: UINotificationObject.cpp 100590 2023-07-14 17:02:43Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UINotificationObject class implementation.
4 */
5
6/*
7 * Copyright (C) 2021-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/* GUI includes: */
29#include "UIExtraDataManager.h"
30#include "UINotificationObject.h"
31#include "UINotificationProgressTask.h"
32#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
33# include "UIDownloader.h"
34# include "UINewVersionChecker.h"
35#endif
36
37
38/*********************************************************************************************************************************
39* Class UINotificationObject implementation. *
40*********************************************************************************************************************************/
41
42UINotificationObject::UINotificationObject()
43{
44}
45
46void UINotificationObject::dismiss()
47{
48 emit sigAboutToClose(true);
49}
50
51void UINotificationObject::close()
52{
53 emit sigAboutToClose(false);
54}
55
56
57/*********************************************************************************************************************************
58* Class UINotificationSimple implementation. *
59*********************************************************************************************************************************/
60
61UINotificationSimple::UINotificationSimple(const QString &strName,
62 const QString &strDetails,
63 const QString &strInternalName,
64 const QString &strHelpKeyword,
65 bool fCritical /* = true */)
66 : m_strName(strName)
67 , m_strDetails(strDetails)
68 , m_strInternalName(strInternalName)
69 , m_strHelpKeyword(strHelpKeyword)
70 , m_fCritical(fCritical)
71{
72}
73
74bool UINotificationSimple::isCritical() const
75{
76 return m_fCritical;
77}
78
79bool UINotificationSimple::isDone() const
80{
81 return true;
82}
83
84QString UINotificationSimple::name() const
85{
86 return m_strName;
87}
88
89QString UINotificationSimple::details() const
90{
91 return m_strDetails;
92}
93
94QString UINotificationSimple::internalName() const
95{
96 return m_strInternalName;
97}
98
99QString UINotificationSimple::helpKeyword() const
100{
101 return m_strHelpKeyword;
102}
103
104void UINotificationSimple::handle()
105{
106}
107
108/* static */
109bool UINotificationSimple::isSuppressed(const QString &strInternalName)
110{
111 /* Sanity check: */
112 if (strInternalName.isEmpty())
113 return false;
114
115 /* Acquire and check suppressed message names: */
116 const QStringList suppressedMessages = gEDataManager->suppressedMessages();
117 return suppressedMessages.contains(strInternalName)
118 || suppressedMessages.contains("all");
119}
120
121
122/*********************************************************************************************************************************
123* Class UINotificationProgress implementation. *
124*********************************************************************************************************************************/
125
126UINotificationProgress::UINotificationProgress()
127 : m_pTask(0)
128 , m_uPercent(0)
129 , m_fDone(false)
130{
131}
132
133UINotificationProgress::~UINotificationProgress()
134{
135 delete m_pTask;
136 m_pTask = 0;
137}
138
139ulong UINotificationProgress::percent() const
140{
141 return m_uPercent;
142}
143
144bool UINotificationProgress::isCancelable() const
145{
146 return m_pTask ? m_pTask->isCancelable() : false;
147}
148
149QString UINotificationProgress::error() const
150{
151 return m_pTask ? m_pTask->errorMessage() : QString();
152}
153
154bool UINotificationProgress::isCritical() const
155{
156 return true;
157}
158
159bool UINotificationProgress::isDone() const
160{
161 return m_fDone;
162}
163
164QString UINotificationProgress::internalName() const
165{
166 return QString();
167}
168
169QString UINotificationProgress::helpKeyword() const
170{
171 return QString();
172}
173
174void UINotificationProgress::handle()
175{
176 /* Prepare task: */
177 m_pTask = new UINotificationProgressTask(this);
178 if (m_pTask)
179 {
180 connect(m_pTask, &UIProgressTask::sigProgressStarted,
181 this, &UINotificationProgress::sigProgressStarted);
182 connect(m_pTask, &UIProgressTask::sigProgressChange,
183 this, &UINotificationProgress::sltHandleProgressChange);
184 connect(m_pTask, &UIProgressTask::sigProgressCanceled,
185 this, &UINotificationProgress::sigProgressFinished);
186 connect(m_pTask, &UIProgressTask::sigProgressFinished,
187 this, &UINotificationProgress::sltHandleProgressFinished);
188
189 /* And start it finally: */
190 m_pTask->start();
191 }
192}
193
194void UINotificationProgress::close()
195{
196 /* Cancel task: */
197 if (m_pTask)
198 m_pTask->cancel();
199 /* Call to base-class: */
200 UINotificationObject::close();
201}
202
203void UINotificationProgress::sltHandleProgressChange(ulong uPercent)
204{
205 m_uPercent = uPercent;
206 emit sigProgressChange(uPercent);
207}
208
209void UINotificationProgress::sltHandleProgressFinished()
210{
211 m_uPercent = 100;
212 m_fDone = true;
213 emit sigProgressFinished();
214
215 /* If there was no error and no reason to keep progress alive, - finish him! */
216 if ( error().isEmpty()
217#ifdef VBOX_NOTIFICATION_CENTER_WITH_KEEP_BUTTON
218 && !gEDataManager->keepSuccessfullNotificationProgresses()
219#endif
220 )
221 close();
222}
223
224
225#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
226
227
228/*********************************************************************************************************************************
229* Class UINotificationDownloader implementation. *
230*********************************************************************************************************************************/
231
232UINotificationDownloader::UINotificationDownloader()
233 : m_pDownloader(0)
234 , m_uPercent(0)
235 , m_fDone(false)
236{
237}
238
239UINotificationDownloader::~UINotificationDownloader()
240{
241 delete m_pDownloader;
242 m_pDownloader = 0;
243}
244
245ulong UINotificationDownloader::percent() const
246{
247 return m_uPercent;
248}
249
250QString UINotificationDownloader::error() const
251{
252 return m_strError;
253}
254
255bool UINotificationDownloader::isCritical() const
256{
257 return true;
258}
259
260bool UINotificationDownloader::isDone() const
261{
262 return m_fDone;
263}
264
265QString UINotificationDownloader::internalName() const
266{
267 return QString();
268}
269
270QString UINotificationDownloader::helpKeyword() const
271{
272 return QString();
273}
274
275void UINotificationDownloader::handle()
276{
277 /* Prepare downloader: */
278 m_pDownloader = createDownloader();
279 if (m_pDownloader)
280 {
281 connect(m_pDownloader, &UIDownloader::sigToStartAcknowledging,
282 this, &UINotificationDownloader::sigProgressStarted);
283 connect(m_pDownloader, &UIDownloader::sigToStartDownloading,
284 this, &UINotificationDownloader::sigProgressStarted);
285 connect(m_pDownloader, &UIDownloader::sigToStartVerifying,
286 this, &UINotificationDownloader::sigProgressStarted);
287 connect(m_pDownloader, &UIDownloader::sigProgressChange,
288 this, &UINotificationDownloader::sltHandleProgressChange);
289 connect(m_pDownloader, &UIDownloader::sigProgressFailed,
290 this, &UINotificationDownloader::sltHandleProgressFailed);
291 connect(m_pDownloader, &UIDownloader::sigProgressCanceled,
292 this, &UINotificationDownloader::sltHandleProgressCanceled);
293 connect(m_pDownloader, &UIDownloader::sigProgressFinished,
294 this, &UINotificationDownloader::sltHandleProgressFinished);
295
296 /* And start it finally: */
297 m_pDownloader->start();
298 }
299}
300
301void UINotificationDownloader::close()
302{
303 /* Cancel downloader: */
304 if (m_pDownloader)
305 m_pDownloader->cancel();
306 /* Call to base-class: */
307 UINotificationObject::close();
308}
309
310void UINotificationDownloader::sltHandleProgressChange(ulong uPercent)
311{
312 m_uPercent = uPercent;
313 emit sigProgressChange(uPercent);
314}
315
316void UINotificationDownloader::sltHandleProgressFailed(const QString &strError)
317{
318 delete m_pDownloader;
319 m_pDownloader = 0;
320 m_strError = strError;
321 m_fDone = true;
322 emit sigProgressFailed();
323}
324
325void UINotificationDownloader::sltHandleProgressCanceled()
326{
327 delete m_pDownloader;
328 m_pDownloader = 0;
329 m_fDone = true;
330 emit sigProgressCanceled();
331}
332
333void UINotificationDownloader::sltHandleProgressFinished()
334{
335 delete m_pDownloader;
336 m_pDownloader = 0;
337 m_fDone = true;
338 emit sigProgressFinished();
339
340 /* If there was no error and no reason to keep progress alive, - finish him! */
341 if ( error().isEmpty()
342#ifdef VBOX_NOTIFICATION_CENTER_WITH_KEEP_BUTTON
343 && !gEDataManager->keepSuccessfullNotificationProgresses()
344#endif
345 )
346 close();
347}
348
349#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette