VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* $Id: UINotificationObject.cpp 98103 2023-01-17 14:15:46Z 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 && !gEDataManager->keepSuccessfullNotificationProgresses())
218 close();
219}
220
221
222#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
223
224
225/*********************************************************************************************************************************
226* Class UINotificationDownloader implementation. *
227*********************************************************************************************************************************/
228
229UINotificationDownloader::UINotificationDownloader()
230 : m_pDownloader(0)
231 , m_uPercent(0)
232 , m_fDone(false)
233{
234}
235
236UINotificationDownloader::~UINotificationDownloader()
237{
238 delete m_pDownloader;
239 m_pDownloader = 0;
240}
241
242ulong UINotificationDownloader::percent() const
243{
244 return m_uPercent;
245}
246
247QString UINotificationDownloader::error() const
248{
249 return m_strError;
250}
251
252bool UINotificationDownloader::isCritical() const
253{
254 return true;
255}
256
257bool UINotificationDownloader::isDone() const
258{
259 return m_fDone;
260}
261
262QString UINotificationDownloader::internalName() const
263{
264 return QString();
265}
266
267QString UINotificationDownloader::helpKeyword() const
268{
269 return QString();
270}
271
272void UINotificationDownloader::handle()
273{
274 /* Prepare downloader: */
275 m_pDownloader = createDownloader();
276 if (m_pDownloader)
277 {
278 connect(m_pDownloader, &UIDownloader::sigToStartAcknowledging,
279 this, &UINotificationDownloader::sigProgressStarted);
280 connect(m_pDownloader, &UIDownloader::sigToStartDownloading,
281 this, &UINotificationDownloader::sigProgressStarted);
282 connect(m_pDownloader, &UIDownloader::sigToStartVerifying,
283 this, &UINotificationDownloader::sigProgressStarted);
284 connect(m_pDownloader, &UIDownloader::sigProgressChange,
285 this, &UINotificationDownloader::sltHandleProgressChange);
286 connect(m_pDownloader, &UIDownloader::sigProgressFailed,
287 this, &UINotificationDownloader::sltHandleProgressFailed);
288 connect(m_pDownloader, &UIDownloader::sigProgressCanceled,
289 this, &UINotificationDownloader::sltHandleProgressCanceled);
290 connect(m_pDownloader, &UIDownloader::sigProgressFinished,
291 this, &UINotificationDownloader::sltHandleProgressFinished);
292
293 /* And start it finally: */
294 m_pDownloader->start();
295 }
296}
297
298void UINotificationDownloader::close()
299{
300 /* Cancel downloader: */
301 if (m_pDownloader)
302 m_pDownloader->cancel();
303 /* Call to base-class: */
304 UINotificationObject::close();
305}
306
307void UINotificationDownloader::sltHandleProgressChange(ulong uPercent)
308{
309 m_uPercent = uPercent;
310 emit sigProgressChange(uPercent);
311}
312
313void UINotificationDownloader::sltHandleProgressFailed(const QString &strError)
314{
315 delete m_pDownloader;
316 m_pDownloader = 0;
317 m_strError = strError;
318 m_fDone = true;
319 emit sigProgressFailed();
320}
321
322void UINotificationDownloader::sltHandleProgressCanceled()
323{
324 delete m_pDownloader;
325 m_pDownloader = 0;
326 m_fDone = true;
327 emit sigProgressCanceled();
328}
329
330void UINotificationDownloader::sltHandleProgressFinished()
331{
332 delete m_pDownloader;
333 m_pDownloader = 0;
334 m_fDone = true;
335 emit sigProgressFinished();
336}
337
338#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