VirtualBox

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

Last change on this file was 104251, checked in by vboxsync, 8 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the manager UI classes.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use