VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp@ 103977

Last change on this file since 103977 was 103710, checked in by vboxsync, 9 months ago

FE/Qt: Get rid of unwanted UICommon includes across whole the GUI.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.8 KB
Line 
1/* $Id: UIVirtualMachineItemCloud.cpp 103710 2024-03-06 16:53:27Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVirtualMachineItemCloud class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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 <QPointer>
30#include <QTimer>
31
32/* GUI includes: */
33#include "UICloudNetworkingStuff.h"
34#include "UIConverter.h"
35#include "UIErrorString.h"
36#include "UIIconPool.h"
37#include "UINotificationCenter.h"
38#include "UIProgressTask.h"
39#include "UIThreadPool.h"
40#include "UIVirtualMachineItemCloud.h"
41
42/* COM includes: */
43#include "CProgress.h"
44#include "CVirtualBoxErrorInfo.h"
45#include <VBox/com/VirtualBox.h> /* For GUEST_OS_ID_STR_X86. */
46
47
48/** UIProgressTask extension performing cloud machine refresh task.
49 * @todo rework this task to be a part of notification-center. */
50class UIProgressTaskRefreshCloudMachine : public UIProgressTask
51{
52 Q_OBJECT;
53
54public:
55
56 /** Constructs @a comCloudMachine refresh task passing @a pParent to the base-class. */
57 UIProgressTaskRefreshCloudMachine(QObject *pParent, const CCloudMachine &comCloudMachine);
58
59protected:
60
61 /** Creates and returns started progress-wrapper required to init UIProgressObject. */
62 virtual CProgress createProgress() RT_OVERRIDE;
63 /** Handles finished @a comProgress wrapper. */
64 virtual void handleProgressFinished(CProgress &comProgress) RT_OVERRIDE;
65
66private:
67
68 /** Holds the cloud machine wrapper. */
69 CCloudMachine m_comCloudMachine;
70};
71
72
73/*********************************************************************************************************************************
74* Class UIProgressTaskRefreshCloudMachine implementation. *
75*********************************************************************************************************************************/
76
77UIProgressTaskRefreshCloudMachine::UIProgressTaskRefreshCloudMachine(QObject *pParent, const CCloudMachine &comCloudMachine)
78 : UIProgressTask(pParent)
79 , m_comCloudMachine(comCloudMachine)
80{
81}
82
83CProgress UIProgressTaskRefreshCloudMachine::createProgress()
84{
85 /* Prepare resulting progress-wrapper: */
86 CProgress comResult;
87
88 /* Initialize actual progress-wrapper: */
89 CProgress comProgress = m_comCloudMachine.Refresh();
90 if (!m_comCloudMachine.isOk())
91 UINotificationMessage::cannotRefreshCloudMachine(m_comCloudMachine);
92 else
93 comResult = comProgress;
94
95 /* Return progress-wrapper in any case: */
96 return comResult;
97}
98
99void UIProgressTaskRefreshCloudMachine::handleProgressFinished(CProgress &comProgress)
100{
101 /* Handle progress-wrapper errors: */
102 if (comProgress.isNotNull() && !comProgress.GetCanceled() && (!comProgress.isOk() || comProgress.GetResultCode() != 0))
103 UINotificationMessage::cannotRefreshCloudMachine(comProgress);
104}
105
106
107/*********************************************************************************************************************************
108* Class UIVirtualMachineItemCloud implementation. *
109*********************************************************************************************************************************/
110
111UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(UIFakeCloudVirtualMachineItemState enmState)
112 : UIVirtualMachineItem(UIVirtualMachineItemType_CloudFake)
113 , m_enmMachineState(KCloudMachineState_Invalid)
114 , m_enmFakeCloudItemState(enmState)
115 , m_fUpdateRequiredByGlobalReason(false)
116 , m_fUpdateRequiredByLocalReason(false)
117 , m_pProgressTaskRefresh(0)
118{
119 prepare();
120}
121
122UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(const CCloudMachine &comCloudMachine)
123 : UIVirtualMachineItem(UIVirtualMachineItemType_CloudReal)
124 , m_comCloudMachine(comCloudMachine)
125 , m_enmMachineState(KCloudMachineState_Invalid)
126 , m_enmFakeCloudItemState(UIFakeCloudVirtualMachineItemState_NotApplicable)
127 , m_fUpdateRequiredByGlobalReason(false)
128 , m_fUpdateRequiredByLocalReason(false)
129 , m_pProgressTaskRefresh(0)
130{
131 prepare();
132}
133
134UIVirtualMachineItemCloud::~UIVirtualMachineItemCloud()
135{
136 cleanup();
137}
138
139void UIVirtualMachineItemCloud::setFakeCloudItemState(UIFakeCloudVirtualMachineItemState enmState)
140{
141 m_enmFakeCloudItemState = enmState;
142 recache();
143}
144
145void UIVirtualMachineItemCloud::setFakeCloudItemErrorMessage(const QString &strErrorMessage)
146{
147 m_strFakeCloudItemErrorMessage = strErrorMessage;
148 recache();
149}
150
151void UIVirtualMachineItemCloud::setUpdateRequiredByGlobalReason(bool fRequired)
152{
153 m_fUpdateRequiredByGlobalReason = fRequired;
154}
155
156void UIVirtualMachineItemCloud::setUpdateRequiredByLocalReason(bool fRequired)
157{
158 m_fUpdateRequiredByLocalReason = fRequired;
159}
160
161void UIVirtualMachineItemCloud::updateInfoAsync(bool fDelayed)
162{
163 /* Ignore refresh request if progress-task is absent: */
164 if (!m_pProgressTaskRefresh)
165 return;
166
167 /* Schedule refresh request in a 10 or 0 seconds
168 * if progress-task isn't already scheduled or running: */
169 if ( !m_pProgressTaskRefresh->isScheduled()
170 && !m_pProgressTaskRefresh->isRunning())
171 m_pProgressTaskRefresh->schedule(fDelayed ? 10000 : 0);
172}
173
174void UIVirtualMachineItemCloud::waitForAsyncInfoUpdateFinished()
175{
176 /* Ignore cancel request if progress-task is absent: */
177 if (!m_pProgressTaskRefresh)
178 return;
179
180 /* Mark update canceled in any case: */
181 m_fUpdateRequiredByGlobalReason = false;
182 m_fUpdateRequiredByLocalReason = false;
183
184 /* Cancel refresh request
185 * if progress-task already running: */
186 if (m_pProgressTaskRefresh->isRunning())
187 m_pProgressTaskRefresh->cancel();
188}
189
190void UIVirtualMachineItemCloud::recache()
191{
192 switch (itemType())
193 {
194 case UIVirtualMachineItemType_CloudFake:
195 {
196 /* Make sure cloud VM is NOT set: */
197 AssertReturnVoid(m_comCloudMachine.isNull());
198
199 /* Determine ID/name: */
200 m_uId = QUuid();
201 m_strName = QString();
202
203 /* Determine whether VM is accessible: */
204 m_fAccessible = m_strFakeCloudItemErrorMessage.isNull();
205 m_strAccessError = m_strFakeCloudItemErrorMessage;
206
207 /* Determine VM OS type: */
208 m_strOSTypeId = GUEST_OS_ID_STR_X86("Other");
209
210 /* Determine VM states: */
211 m_enmMachineState = KCloudMachineState_Stopped;
212 switch (m_enmFakeCloudItemState)
213 {
214 case UIFakeCloudVirtualMachineItemState_Loading:
215 m_machineStateIcon = UIIconPool::iconSet(":/state_loading_16px.png");
216 break;
217 case UIFakeCloudVirtualMachineItemState_Done:
218 m_machineStateIcon = UIIconPool::iconSet(":/vm_new_16px.png");
219 break;
220 default:
221 break;
222 }
223
224 /* Determine configuration access level: */
225 m_enmConfigurationAccessLevel = ConfigurationAccessLevel_Null;
226
227 /* Determine whether we should show this VM details: */
228 m_fHasDetails = true;
229
230 break;
231 }
232 case UIVirtualMachineItemType_CloudReal:
233 {
234 /* Make sure cloud VM is set: */
235 AssertReturnVoid(m_comCloudMachine.isNotNull());
236
237 /* Determine ID/name: */
238 m_uId = m_comCloudMachine.GetId();
239 m_strName = m_comCloudMachine.GetName();
240
241 /* Determine whether VM is accessible: */
242 m_fAccessible = m_comCloudMachine.GetAccessible();
243 m_strAccessError = !m_fAccessible ? UIErrorString::formatErrorInfo(m_comCloudMachine.GetAccessError()) : QString();
244
245 /* Determine VM OS type: */
246 m_strOSTypeId = m_fAccessible ? m_comCloudMachine.GetOSTypeId() : GUEST_OS_ID_STR_X86("Other");
247
248 /* Determine VM states: */
249 m_enmMachineState = m_fAccessible ? m_comCloudMachine.GetState() : KCloudMachineState_Stopped;
250 m_machineStateIcon = gpConverter->toIcon(m_enmMachineState);
251
252 /* Determine configuration access level: */
253 m_enmConfigurationAccessLevel = m_fAccessible ? ConfigurationAccessLevel_Full : ConfigurationAccessLevel_Null;
254
255 /* Determine whether we should show this VM details: */
256 m_fHasDetails = true;
257
258 break;
259 }
260 default:
261 {
262 AssertFailed();
263 break;
264 }
265 }
266
267 /* Recache item pixmap: */
268 recachePixmap();
269
270 /* Retranslate finally: */
271 retranslateUi();
272}
273
274void UIVirtualMachineItemCloud::recachePixmap()
275{
276 /* We are using icon corresponding to cached guest OS type: */
277 if ( itemType() == UIVirtualMachineItemType_CloudFake
278 && fakeCloudItemState() == UIFakeCloudVirtualMachineItemState_Loading)
279 m_pixmap = generalIconPool().guestOSTypePixmapDefault("Cloud", &m_logicalPixmapSize);
280 else
281 m_pixmap = generalIconPool().guestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize);
282}
283
284bool UIVirtualMachineItemCloud::isItemEditable() const
285{
286 return accessible()
287 && itemType() == UIVirtualMachineItemType_CloudReal;
288}
289
290bool UIVirtualMachineItemCloud::isItemRemovable() const
291{
292 return accessible()
293 && itemType() == UIVirtualMachineItemType_CloudReal;
294}
295
296bool UIVirtualMachineItemCloud::isItemSaved() const
297{
298 return accessible()
299 && itemType() == UIVirtualMachineItemType_CloudReal
300 && ( machineState() == KCloudMachineState_Stopped
301 || machineState() == KCloudMachineState_Running);
302}
303
304bool UIVirtualMachineItemCloud::isItemPoweredOff() const
305{
306 return accessible()
307 && ( machineState() == KCloudMachineState_Stopped
308 || machineState() == KCloudMachineState_Terminated);
309}
310
311bool UIVirtualMachineItemCloud::isItemStarted() const
312{
313 return isItemRunning()
314 || isItemPaused();
315}
316
317bool UIVirtualMachineItemCloud::isItemRunning() const
318{
319 return accessible()
320 && machineState() == KCloudMachineState_Running;
321}
322
323bool UIVirtualMachineItemCloud::isItemRunningHeadless() const
324{
325 return isItemRunning();
326}
327
328bool UIVirtualMachineItemCloud::isItemPaused() const
329{
330 return false;
331}
332
333bool UIVirtualMachineItemCloud::isItemStuck() const
334{
335 return false;
336}
337
338bool UIVirtualMachineItemCloud::isItemCanBeSwitchedTo() const
339{
340 return false;
341}
342
343void UIVirtualMachineItemCloud::retranslateUi()
344{
345 /* If machine is accessible: */
346 if (accessible())
347 {
348 if (itemType() == UIVirtualMachineItemType_CloudFake)
349 {
350 /* Update fake machine state name: */
351 switch (m_enmFakeCloudItemState)
352 {
353 case UIFakeCloudVirtualMachineItemState_Loading:
354 m_strMachineStateName = tr("Loading ...");
355 break;
356 case UIFakeCloudVirtualMachineItemState_Done:
357 m_strMachineStateName = tr("Empty");
358 break;
359 default:
360 break;
361 }
362
363 /* Update tool-tip: */
364 m_strToolTipText = m_strMachineStateName;
365 }
366 else
367 {
368 /* Update real machine state name: */
369 m_strMachineStateName = gpConverter->toString(m_enmMachineState);
370
371 /* Update tool-tip: */
372 m_strToolTipText = QString("<nobr><b>%1</b></nobr><br>"
373 "<nobr>%2</nobr>")
374 .arg(m_strName)
375 .arg(gpConverter->toString(m_enmMachineState));
376 }
377 }
378 /* Otherwise: */
379 else
380 {
381 /* We have our own translation for Null states: */
382 m_strMachineStateName = tr("Inaccessible", "VM");
383
384 /* Update tool-tip: */
385 m_strToolTipText = tr("<nobr><b>%1</b></nobr><br>"
386 "<nobr>Inaccessible</nobr>",
387 "Inaccessible VM tooltip (name)")
388 .arg(m_strName);
389 }
390}
391
392void UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone()
393{
394 /* Recache: */
395 recache();
396
397 /* Notify listeners: */
398 emit sigRefreshFinished();
399
400 /* Refresh again if required: */
401 if ( m_fUpdateRequiredByGlobalReason
402 || m_fUpdateRequiredByLocalReason)
403 updateInfoAsync(true /* delayed? */);
404}
405
406void UIVirtualMachineItemCloud::prepare()
407{
408 /* Prepare progress-task if necessary: */
409 if (itemType() == UIVirtualMachineItemType_CloudReal)
410 {
411 m_pProgressTaskRefresh = new UIProgressTaskRefreshCloudMachine(this, machine());
412 if (m_pProgressTaskRefresh)
413 {
414 connect(m_pProgressTaskRefresh, &UIProgressTaskRefreshCloudMachine::sigProgressStarted,
415 this, &UIVirtualMachineItemCloud::sigRefreshStarted);
416 connect(m_pProgressTaskRefresh, &UIProgressTaskRefreshCloudMachine::sigProgressFinished,
417 this, &UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone);
418 }
419 }
420
421 /* Recache finally: */
422 recache();
423}
424
425void UIVirtualMachineItemCloud::cleanup()
426{
427 /* Cleanup progress-task: */
428 delete m_pProgressTaskRefresh;
429 m_pProgressTaskRefresh = 0;
430}
431
432
433#include "UIVirtualMachineItemCloud.moc"
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