1 | /* $Id: UINotificationObject.cpp 90556 2021-08-06 16:08:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINotificationObject class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2021 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* GUI includes: */
|
---|
19 | #include "UIDownloader.h"
|
---|
20 | #include "UINotificationObject.h"
|
---|
21 | #include "UINotificationProgressTask.h"
|
---|
22 |
|
---|
23 |
|
---|
24 | /*********************************************************************************************************************************
|
---|
25 | * Class UINotificationObject implementation. *
|
---|
26 | *********************************************************************************************************************************/
|
---|
27 |
|
---|
28 | UINotificationObject::UINotificationObject()
|
---|
29 | {
|
---|
30 | }
|
---|
31 |
|
---|
32 | void UINotificationObject::close()
|
---|
33 | {
|
---|
34 | emit sigAboutToClose();
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Class UINotificationProgress implementation. *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 |
|
---|
42 | UINotificationProgress::UINotificationProgress()
|
---|
43 | : m_pTask(0)
|
---|
44 | , m_uPercent(0)
|
---|
45 | {
|
---|
46 | }
|
---|
47 |
|
---|
48 | UINotificationProgress::~UINotificationProgress()
|
---|
49 | {
|
---|
50 | delete m_pTask;
|
---|
51 | m_pTask = 0;
|
---|
52 | }
|
---|
53 |
|
---|
54 | ulong UINotificationProgress::percent() const
|
---|
55 | {
|
---|
56 | return m_uPercent;
|
---|
57 | }
|
---|
58 |
|
---|
59 | bool UINotificationProgress::isCancelable() const
|
---|
60 | {
|
---|
61 | return m_pTask ? m_pTask->isCancelable() : false;
|
---|
62 | }
|
---|
63 |
|
---|
64 | QString UINotificationProgress::error() const
|
---|
65 | {
|
---|
66 | return m_pTask ? m_pTask->errorMessage() : QString();
|
---|
67 | }
|
---|
68 |
|
---|
69 | void UINotificationProgress::handle()
|
---|
70 | {
|
---|
71 | /* Prepare task: */
|
---|
72 | m_pTask = new UINotificationProgressTask(this);
|
---|
73 | if (m_pTask)
|
---|
74 | {
|
---|
75 | connect(m_pTask, &UIProgressTask::sigProgressStarted,
|
---|
76 | this, &UINotificationProgress::sigProgressStarted);
|
---|
77 | connect(m_pTask, &UIProgressTask::sigProgressChange,
|
---|
78 | this, &UINotificationProgress::sltHandleProgressChange);
|
---|
79 | connect(m_pTask, &UIProgressTask::sigProgressFinished,
|
---|
80 | this, &UINotificationProgress::sltHandleProgressFinished);
|
---|
81 |
|
---|
82 | /* And start it finally: */
|
---|
83 | m_pTask->start();
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | void UINotificationProgress::close()
|
---|
88 | {
|
---|
89 | /* Cancel task: */
|
---|
90 | if (m_pTask)
|
---|
91 | m_pTask->cancel();
|
---|
92 | /* Call to base-class: */
|
---|
93 | UINotificationObject::close();
|
---|
94 | }
|
---|
95 |
|
---|
96 | void UINotificationProgress::sltHandleProgressChange(ulong uPercent)
|
---|
97 | {
|
---|
98 | m_uPercent = uPercent;
|
---|
99 | emit sigProgressChange(uPercent);
|
---|
100 | }
|
---|
101 |
|
---|
102 | void UINotificationProgress::sltHandleProgressFinished()
|
---|
103 | {
|
---|
104 | m_uPercent = 100;
|
---|
105 | emit sigProgressFinished();
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | /*********************************************************************************************************************************
|
---|
110 | * Class UINotificationDownloader implementation. *
|
---|
111 | *********************************************************************************************************************************/
|
---|
112 |
|
---|
113 | UINotificationDownloader::UINotificationDownloader()
|
---|
114 | {
|
---|
115 | }
|
---|
116 |
|
---|
117 | UINotificationDownloader::~UINotificationDownloader()
|
---|
118 | {
|
---|
119 | delete m_pDownloader;
|
---|
120 | }
|
---|
121 |
|
---|
122 | ulong UINotificationDownloader::percent() const
|
---|
123 | {
|
---|
124 | return m_uPercent;
|
---|
125 | }
|
---|
126 |
|
---|
127 | QString UINotificationDownloader::error() const
|
---|
128 | {
|
---|
129 | return m_strError;
|
---|
130 | }
|
---|
131 |
|
---|
132 | void UINotificationDownloader::handle()
|
---|
133 | {
|
---|
134 | /* Prepare downloader: */
|
---|
135 | m_pDownloader = createDownloader();
|
---|
136 | if (m_pDownloader)
|
---|
137 | {
|
---|
138 | connect(m_pDownloader, &UIDownloader::sigToStartAcknowledging,
|
---|
139 | this, &UINotificationDownloader::sigProgressStarted);
|
---|
140 | connect(m_pDownloader, &UIDownloader::sigToStartDownloading,
|
---|
141 | this, &UINotificationDownloader::sigProgressStarted);
|
---|
142 | connect(m_pDownloader, &UIDownloader::sigToStartVerifying,
|
---|
143 | this, &UINotificationDownloader::sigProgressStarted);
|
---|
144 | connect(m_pDownloader, &UIDownloader::sigProgressChange,
|
---|
145 | this, &UINotificationDownloader::sltHandleProgressChange);
|
---|
146 | connect(m_pDownloader, &UIDownloader::sigProgressFailed,
|
---|
147 | this, &UINotificationDownloader::sltHandleProgressFailed);
|
---|
148 | connect(m_pDownloader, &UIDownloader::sigProgressCanceled,
|
---|
149 | this, &UINotificationDownloader::sigProgressCanceled);
|
---|
150 | connect(m_pDownloader, &UIDownloader::sigProgressFinished,
|
---|
151 | this, &UINotificationDownloader::sigProgressFinished);
|
---|
152 | connect(m_pDownloader, &UIDownloader::destroyed,
|
---|
153 | this, &UINotificationDownloader::sigDownloaderDestroyed);
|
---|
154 |
|
---|
155 | /* And start it finally: */
|
---|
156 | m_pDownloader->start();
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | void UINotificationDownloader::close()
|
---|
161 | {
|
---|
162 | /* Cancel downloader: */
|
---|
163 | if (m_pDownloader)
|
---|
164 | m_pDownloader->cancel();
|
---|
165 | /* Call to base-class: */
|
---|
166 | UINotificationObject::close();
|
---|
167 | }
|
---|
168 |
|
---|
169 | void UINotificationDownloader::sltHandleProgressChange(ulong uPercent)
|
---|
170 | {
|
---|
171 | m_uPercent = uPercent;
|
---|
172 | emit sigProgressChange(uPercent);
|
---|
173 | }
|
---|
174 |
|
---|
175 | void UINotificationDownloader::sltHandleProgressFailed(const QString &strError)
|
---|
176 | {
|
---|
177 | m_strError = strError;
|
---|
178 | emit sigProgressFailed();
|
---|
179 | }
|
---|