Changeset 83107 in vbox
- Timestamp:
- Feb 18, 2020 3:00:50 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 136168
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r83097 r83107 1063 1063 src/hostnetwork/UIHostNetworkUtils.cpp \ 1064 1064 src/manager/UICloudMachine.cpp \ 1065 src/manager/UICloudNetworkingStuff.cpp \ 1065 1066 src/manager/UIErrorPane.cpp \ 1066 1067 src/manager/UITaskCloudAcquireInstances.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UICloudNetworkingStuff.cpp
r83095 r83107 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI VirtualMachineItemCloud classimplementation.3 * VBox Qt GUI - UICloudNetworkingStuff namespace implementation. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 20 06-2020 Oracle Corporation7 * Copyright (C) 2020 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 /* Qt includes: */19 #include <QTimer>20 21 18 /* GUI includes: */ 22 #include "UICloud Machine.h"19 #include "UICloudNetworkingStuff.h" 23 20 #include "UICommon.h" 24 #include "UIConverter.h"25 #include "UIIconPool.h"26 21 #include "UIMessageCenter.h" 27 #include "UITask.h"28 #include "UIThreadPool.h"29 #include "UIVirtualMachineItemCloud.h"30 22 31 23 /* COM includes: */ … … 35 27 36 28 37 /** GetInstanceInfo namespace. */ 38 namespace GetInstanceInfo 39 { 40 /** Acquires instance info of certain @a enmType. 41 * @param comCloudClient Brings cloud client object. 42 * @param strId Brings cloud VM id. 43 * @param pWidget Brings parent widget to show messages according to. */ 44 QString getInstanceInfo(KVirtualSystemDescriptionType enmType, 45 const CCloudClient &comCloudClient, 46 const QString &strId, 47 QWidget *pParent = 0); 48 } 49 50 /* Using across module: */ 51 using namespace GetInstanceInfo; 52 53 54 /** UITask extension used to get cloud instance state async way. */ 55 class UITaskGetCloudInstanceState : public UITask 56 { 57 Q_OBJECT; 58 59 public: 60 61 /** Constructs task taking @a comCloudClient and @a strId as data. 62 * @param comCloudClient Brings the cloud client object. 63 * @param strId Brings the cloud VM id. */ 64 UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId); 65 66 /** Returns the task result. */ 67 QString result() const; 68 69 protected: 70 71 /** Contains the task body. */ 72 virtual void run() /* override */; 73 74 private: 75 76 /** Holds the mutex to access result. */ 77 mutable QMutex m_mutex; 78 79 /** Holds the cloud client object. */ 80 CCloudClient m_comCloudClient; 81 /** Holds the cloud VM id. */ 82 QString m_strId; 83 84 /** Holds the error info object. */ 85 CVirtualBoxErrorInfo m_comErrorInfo; 86 87 /** Holds the task result. */ 88 QString m_strResult; 89 }; 90 91 92 /********************************************************************************************************************************* 93 * Namespace GetInstanceInfo implementation. * 94 *********************************************************************************************************************************/ 95 96 QString GetInstanceInfo::getInstanceInfo(KVirtualSystemDescriptionType enmType, 97 const CCloudClient &comCloudClient, 98 const QString &strId, 99 QWidget *pParent /* = 0 */) 29 QString UICloudNetworkingStuff::getInstanceInfo(KVirtualSystemDescriptionType enmType, 30 const CCloudClient &comCloudClient, 31 const QString &strId, 32 QWidget *pParent /* = 0 */) 100 33 { 101 34 /* Get VirtualBox object: */ … … 179 112 return QString(); 180 113 } 181 182 183 /*********************************************************************************************************************************184 * Class UITaskGetCloudInstanceState implementation. *185 *********************************************************************************************************************************/186 187 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId)188 : UITask(Type_GetCloudInstanceState)189 , m_comCloudClient(comCloudClient)190 , m_strId(strId)191 {192 }193 194 QString UITaskGetCloudInstanceState::result() const195 {196 m_mutex.lock();197 const QString strResult = m_strResult;198 m_mutex.unlock();199 return strResult;200 }201 202 void UITaskGetCloudInstanceState::run()203 {204 m_mutex.lock();205 m_strResult = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, m_comCloudClient, m_strId);206 m_mutex.unlock();207 }208 209 210 /*********************************************************************************************************************************211 * Class UIVirtualMachineItemCloud implementation. *212 *********************************************************************************************************************************/213 214 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud()215 : UIVirtualMachineItem(ItemType_CloudFake)216 , m_pCloudMachine(0)217 , m_enmFakeCloudItemState(FakeCloudItemState_Loading)218 , m_pTask(0)219 {220 recache();221 }222 223 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(const UICloudMachine &guiCloudMachine)224 : UIVirtualMachineItem(ItemType_CloudReal)225 , m_pCloudMachine(new UICloudMachine(guiCloudMachine))226 , m_enmFakeCloudItemState(FakeCloudItemState_NotApplicable)227 , m_pTask(0)228 {229 recache();230 }231 232 UIVirtualMachineItemCloud::~UIVirtualMachineItemCloud()233 {234 delete m_pCloudMachine;235 }236 237 void UIVirtualMachineItemCloud::updateState(QWidget *pParent)238 {239 /* Make sure item is of real cloud type and is initialized: */240 AssertReturnVoid(itemType() == ItemType_CloudReal);241 AssertPtrReturnVoid(m_pCloudMachine);242 243 /* Acquire state: */244 const QString strState = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState,245 m_pCloudMachine->client(),246 m_strId,247 pParent);248 249 /* Update state: */250 updateState(strState);251 }252 253 void UIVirtualMachineItemCloud::updateStateAsync(bool fDelayed)254 {255 QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceStateTask()));256 }257 258 void UIVirtualMachineItemCloud::pause(QWidget *pParent)259 {260 pauseOrResume(true /* pause? */, pParent);261 }262 263 void UIVirtualMachineItemCloud::resume(QWidget *pParent)264 {265 pauseOrResume(false /* pause? */, pParent);266 }267 268 void UIVirtualMachineItemCloud::pauseOrResume(bool fPause, QWidget *pParent)269 {270 /* Acquire cloud client: */271 CCloudClient comCloudClient = m_pCloudMachine->client();272 273 /* Now execute async method: */274 CProgress comProgress;275 if (fPause)276 comProgress = comCloudClient.PauseInstance(m_strId);277 else278 comProgress = comCloudClient.StartInstance(m_strId);279 if (!comCloudClient.isOk())280 msgCenter().cannotAcquireCloudClientParameter(comCloudClient);281 else282 {283 /* Show progress: */284 /// @todo use proper pause icon285 if (fPause)286 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Pause instance ..."),287 ":/progress_reading_appliance_90px.png", pParent, 0);288 else289 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Start instance ..."),290 ":/progress_start_90px.png", pParent, 0);291 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)292 msgCenter().cannotAcquireCloudClientParameter(comProgress);293 else294 updateStateAsync(false /* delayed? */);295 }296 }297 298 void UIVirtualMachineItemCloud::recache()299 {300 /* Determine attributes which are always available: */301 if (itemType() == ItemType_CloudReal)302 {303 AssertPtrReturnVoid(m_pCloudMachine);304 m_strId = m_pCloudMachine->id();305 m_strName = m_pCloudMachine->name();306 }307 308 /* Now determine whether VM is accessible: */309 m_fAccessible = true;310 if (m_fAccessible)311 {312 /* Reset last access error information: */313 m_comAccessError = CVirtualBoxErrorInfo();314 315 /* Determine own VM attributes: */316 m_strOSTypeId = "Other";317 318 /* Determine VM states: */319 if ( itemType() == ItemType_CloudFake320 || m_enmMachineState == KMachineState_Null)321 m_enmMachineState = KMachineState_PoweredOff;322 m_strMachineStateName = gpConverter->toString(m_enmMachineState);323 if (itemType() == ItemType_CloudFake)324 {325 switch (m_enmFakeCloudItemState)326 {327 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:328 m_machineStateIcon = UIIconPool::iconSet(":/state_loading_16px.png");329 break;330 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:331 m_machineStateIcon = UIIconPool::iconSet(":/vm_new_16px.png");332 break;333 default:334 break;335 }336 }337 else338 m_machineStateIcon = gpConverter->toIcon(m_enmMachineState);339 340 /* Determine configuration access level: */341 m_enmConfigurationAccessLevel = ConfigurationAccessLevel_Null;342 343 /* Determine whether we should show this VM details: */344 m_fHasDetails = false;345 }346 else347 {348 /// @todo handle inaccessible cloud VM349 }350 351 /* Recache item pixmap: */352 recachePixmap();353 354 /* Retranslate finally: */355 retranslateUi();356 }357 358 void UIVirtualMachineItemCloud::recachePixmap()359 {360 /* If machine is accessible: */361 if (m_fAccessible)362 {363 /* We are using icon corresponding to cached guest OS type: */364 if ( itemType() == ItemType_CloudFake365 && fakeCloudItemState() == FakeCloudItemState_Loading)366 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault("Cloud", &m_logicalPixmapSize);367 else368 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize);369 }370 /* Otherwise: */371 else372 {373 /// @todo handle inaccessible cloud VM374 }375 }376 377 bool UIVirtualMachineItemCloud::isItemEditable() const378 {379 return accessible();380 }381 382 bool UIVirtualMachineItemCloud::isItemSaved() const383 {384 return accessible()385 && machineState() == KMachineState_Saved;386 }387 388 bool UIVirtualMachineItemCloud::isItemPoweredOff() const389 {390 return accessible()391 && ( machineState() == KMachineState_PoweredOff392 || machineState() == KMachineState_Saved393 || machineState() == KMachineState_Teleported394 || machineState() == KMachineState_Aborted);395 }396 397 bool UIVirtualMachineItemCloud::isItemStarted() const398 {399 return isItemRunning()400 || isItemPaused();401 }402 403 bool UIVirtualMachineItemCloud::isItemRunning() const404 {405 return accessible()406 && ( machineState() == KMachineState_Running407 || machineState() == KMachineState_Teleporting408 || machineState() == KMachineState_LiveSnapshotting);409 }410 411 bool UIVirtualMachineItemCloud::isItemRunningHeadless() const412 {413 return isItemRunning();414 }415 416 bool UIVirtualMachineItemCloud::isItemPaused() const417 {418 return accessible()419 && ( machineState() == KMachineState_Paused420 || machineState() == KMachineState_TeleportingPausedVM);421 }422 423 bool UIVirtualMachineItemCloud::isItemStuck() const424 {425 return accessible()426 && machineState() == KMachineState_Stuck;427 }428 429 void UIVirtualMachineItemCloud::retranslateUi()430 {431 /* If machine is accessible: */432 if (m_fAccessible)433 {434 if (itemType() == ItemType_CloudFake)435 {436 /* Update machine/state name: */437 switch (m_enmFakeCloudItemState)438 {439 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:440 m_strMachineStateName = tr("Loading ...");441 break;442 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:443 m_strMachineStateName = tr("Up-To-Date");444 break;445 default:446 break;447 }448 449 /* Update tool-tip: */450 m_strToolTipText = m_strMachineStateName;451 }452 else453 {454 /* Update tool-tip: */455 m_strToolTipText = QString("<nobr><b>%1</b></nobr><br>"456 "<nobr>%2</nobr>")457 .arg(m_strName)458 .arg(gpConverter->toString(m_enmMachineState));459 460 }461 }462 /* Otherwise: */463 else464 {465 /* Update tool-tip: */466 m_strToolTipText = tr("<nobr><b>%1</b></nobr><br>"467 "<nobr>Inaccessible</nobr>",468 "Inaccessible VM tooltip (name)")469 .arg(m_strName);470 471 /* We have our own translation for Null states: */472 m_strMachineStateName = tr("Inaccessible");473 }474 }475 476 void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceStateTask()477 {478 /* Make sure item is of real cloud type and is initialized: */479 AssertReturnVoid(itemType() == ItemType_CloudReal);480 AssertPtrReturnVoid(m_pCloudMachine);481 482 /* Create and start task to acquire state async way only if there is no task yet: */483 if (!m_pTask)484 {485 m_pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId);486 connect(m_pTask, &UITask::sigComplete,487 this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone);488 uiCommon().threadPool()->enqueueTask(m_pTask);489 }490 }491 492 void UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone(UITask *pTask)493 {494 /* Skip unrelated tasks: */495 if (!m_pTask || pTask != m_pTask)496 return;497 498 /* Mark our task handled: */499 m_pTask = 0;500 501 /* Cast task to corresponding sub-class: */502 UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask);503 504 /* Update state: */505 updateState(pStateTask->result());506 }507 508 void UIVirtualMachineItemCloud::updateState(const QString &strState)509 {510 /* Prepare a map of known states: */511 QMap<QString, KMachineState> states;512 states["RUNNING"] = KMachineState_Running;513 states["STOPPED"] = KMachineState_Paused;514 states["STOPPING"] = KMachineState_Stopping;515 states["STARTING"] = KMachineState_Starting;516 517 /* Update our state value: */518 m_enmMachineState = states.value(strState, KMachineState_PoweredOff);519 520 /* Recache: */521 recache();522 523 /* Notify listeners finally: */524 emit sigStateChange();525 }526 527 528 #include "UIVirtualMachineItemCloud.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UICloudNetworkingStuff.h
r83095 r83107 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI VirtualMachineItemCloud class implementation.3 * VBox Qt GUI - UICloudNetworkingStuff namespace declaration. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 20 06-2020 Oracle Corporation7 * Copyright (C) 2020 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 /* Qt includes: */ 19 #include <QTimer> 20 21 /* GUI includes: */ 22 #include "UICloudMachine.h" 23 #include "UICommon.h" 24 #include "UIConverter.h" 25 #include "UIIconPool.h" 26 #include "UIMessageCenter.h" 27 #include "UITask.h" 28 #include "UIThreadPool.h" 29 #include "UIVirtualMachineItemCloud.h" 18 #ifndef FEQT_INCLUDED_SRC_manager_UICloudNetworkingStuff_h 19 #define FEQT_INCLUDED_SRC_manager_UICloudNetworkingStuff_h 20 #ifndef RT_WITHOUT_PRAGMA_ONCE 21 # pragma once 22 #endif 30 23 31 24 /* COM includes: */ 32 #include "CAppliance.h" 33 #include "CVirtualBox.h" 34 #include "CVirtualSystemDescription.h" 25 #include "COMEnums.h" 26 #include "CCloudClient.h" 35 27 28 /* Forward declarations: */ 29 class QString; 30 class QWidget; 36 31 37 /** GetInstanceInfonamespace. */38 namespace GetInstanceInfo32 /** Cloud networking stuff namespace. */ 33 namespace UICloudNetworkingStuff 39 34 { 40 35 /** Acquires instance info of certain @a enmType. … … 48 43 } 49 44 50 /* Using across module: */51 using namespace GetInstanceInfo;45 /* Using across any module who included us: */ 46 using namespace UICloudNetworkingStuff; 52 47 53 54 /** UITask extension used to get cloud instance state async way. */ 55 class UITaskGetCloudInstanceState : public UITask 56 { 57 Q_OBJECT; 58 59 public: 60 61 /** Constructs task taking @a comCloudClient and @a strId as data. 62 * @param comCloudClient Brings the cloud client object. 63 * @param strId Brings the cloud VM id. */ 64 UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId); 65 66 /** Returns the task result. */ 67 QString result() const; 68 69 protected: 70 71 /** Contains the task body. */ 72 virtual void run() /* override */; 73 74 private: 75 76 /** Holds the mutex to access result. */ 77 mutable QMutex m_mutex; 78 79 /** Holds the cloud client object. */ 80 CCloudClient m_comCloudClient; 81 /** Holds the cloud VM id. */ 82 QString m_strId; 83 84 /** Holds the error info object. */ 85 CVirtualBoxErrorInfo m_comErrorInfo; 86 87 /** Holds the task result. */ 88 QString m_strResult; 89 }; 90 91 92 /********************************************************************************************************************************* 93 * Namespace GetInstanceInfo implementation. * 94 *********************************************************************************************************************************/ 95 96 QString GetInstanceInfo::getInstanceInfo(KVirtualSystemDescriptionType enmType, 97 const CCloudClient &comCloudClient, 98 const QString &strId, 99 QWidget *pParent /* = 0 */) 100 { 101 /* Get VirtualBox object: */ 102 CVirtualBox comVBox = uiCommon().virtualBox(); 103 104 /* Create appliance: */ 105 CAppliance comAppliance = comVBox.CreateAppliance(); 106 if (!comVBox.isOk()) 107 { 108 if (pParent) 109 msgCenter().cannotCreateAppliance(comVBox, pParent); 110 else 111 { 112 /// @todo fetch error info 113 } 114 } 115 else 116 { 117 /* Append it with one (1) description we need: */ 118 comAppliance.CreateVirtualSystemDescriptions(1); 119 if (!comAppliance.isOk()) 120 { 121 if (pParent) 122 msgCenter().cannotCreateVirtualSystemDescription(comAppliance, pParent); 123 else 124 { 125 /// @todo fetch error info 126 } 127 } 128 else 129 { 130 /* Get received description: */ 131 QVector<CVirtualSystemDescription> descriptions = comAppliance.GetVirtualSystemDescriptions(); 132 AssertReturn(!descriptions.isEmpty(), QString()); 133 CVirtualSystemDescription comDescription = descriptions.at(0); 134 135 /* Now execute GetInstanceInfo async method: */ 136 CProgress comProgress = comCloudClient.GetInstanceInfo(strId, comDescription); 137 if (!comCloudClient.isOk()) 138 { 139 if (pParent) 140 msgCenter().cannotAcquireCloudClientParameter(comCloudClient, pParent); 141 else 142 { 143 /// @todo fetch error info 144 } 145 } 146 else 147 { 148 /* Show "Acquire instance info" progress: */ 149 if (pParent) 150 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Acquire instance info ..."), 151 ":/progress_reading_appliance_90px.png", pParent, 0); 152 else 153 comProgress.WaitForCompletion(-1); 154 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 155 { 156 if (pParent) 157 msgCenter().cannotAcquireCloudClientParameter(comProgress, pParent); 158 else 159 { 160 /// @todo fetch error info 161 } 162 } 163 else 164 { 165 /* Now acquire description of certain type: */ 166 QVector<KVirtualSystemDescriptionType> types; 167 QVector<QString> refs, origValues, configValues, extraConfigValues; 168 comDescription.GetDescriptionByType(enmType, types, refs, origValues, configValues, extraConfigValues); 169 170 /* Return first config value if we have one: */ 171 AssertReturn(!configValues.isEmpty(), QString()); 172 return configValues.at(0); 173 } 174 } 175 } 176 } 177 178 /* Return null string by default: */ 179 return QString(); 180 } 181 182 183 /********************************************************************************************************************************* 184 * Class UITaskGetCloudInstanceState implementation. * 185 *********************************************************************************************************************************/ 186 187 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId) 188 : UITask(Type_GetCloudInstanceState) 189 , m_comCloudClient(comCloudClient) 190 , m_strId(strId) 191 { 192 } 193 194 QString UITaskGetCloudInstanceState::result() const 195 { 196 m_mutex.lock(); 197 const QString strResult = m_strResult; 198 m_mutex.unlock(); 199 return strResult; 200 } 201 202 void UITaskGetCloudInstanceState::run() 203 { 204 m_mutex.lock(); 205 m_strResult = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, m_comCloudClient, m_strId); 206 m_mutex.unlock(); 207 } 208 209 210 /********************************************************************************************************************************* 211 * Class UIVirtualMachineItemCloud implementation. * 212 *********************************************************************************************************************************/ 213 214 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud() 215 : UIVirtualMachineItem(ItemType_CloudFake) 216 , m_pCloudMachine(0) 217 , m_enmFakeCloudItemState(FakeCloudItemState_Loading) 218 , m_pTask(0) 219 { 220 recache(); 221 } 222 223 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(const UICloudMachine &guiCloudMachine) 224 : UIVirtualMachineItem(ItemType_CloudReal) 225 , m_pCloudMachine(new UICloudMachine(guiCloudMachine)) 226 , m_enmFakeCloudItemState(FakeCloudItemState_NotApplicable) 227 , m_pTask(0) 228 { 229 recache(); 230 } 231 232 UIVirtualMachineItemCloud::~UIVirtualMachineItemCloud() 233 { 234 delete m_pCloudMachine; 235 } 236 237 void UIVirtualMachineItemCloud::updateState(QWidget *pParent) 238 { 239 /* Make sure item is of real cloud type and is initialized: */ 240 AssertReturnVoid(itemType() == ItemType_CloudReal); 241 AssertPtrReturnVoid(m_pCloudMachine); 242 243 /* Acquire state: */ 244 const QString strState = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, 245 m_pCloudMachine->client(), 246 m_strId, 247 pParent); 248 249 /* Update state: */ 250 updateState(strState); 251 } 252 253 void UIVirtualMachineItemCloud::updateStateAsync(bool fDelayed) 254 { 255 QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceStateTask())); 256 } 257 258 void UIVirtualMachineItemCloud::pause(QWidget *pParent) 259 { 260 pauseOrResume(true /* pause? */, pParent); 261 } 262 263 void UIVirtualMachineItemCloud::resume(QWidget *pParent) 264 { 265 pauseOrResume(false /* pause? */, pParent); 266 } 267 268 void UIVirtualMachineItemCloud::pauseOrResume(bool fPause, QWidget *pParent) 269 { 270 /* Acquire cloud client: */ 271 CCloudClient comCloudClient = m_pCloudMachine->client(); 272 273 /* Now execute async method: */ 274 CProgress comProgress; 275 if (fPause) 276 comProgress = comCloudClient.PauseInstance(m_strId); 277 else 278 comProgress = comCloudClient.StartInstance(m_strId); 279 if (!comCloudClient.isOk()) 280 msgCenter().cannotAcquireCloudClientParameter(comCloudClient); 281 else 282 { 283 /* Show progress: */ 284 /// @todo use proper pause icon 285 if (fPause) 286 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Pause instance ..."), 287 ":/progress_reading_appliance_90px.png", pParent, 0); 288 else 289 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Start instance ..."), 290 ":/progress_start_90px.png", pParent, 0); 291 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 292 msgCenter().cannotAcquireCloudClientParameter(comProgress); 293 else 294 updateStateAsync(false /* delayed? */); 295 } 296 } 297 298 void UIVirtualMachineItemCloud::recache() 299 { 300 /* Determine attributes which are always available: */ 301 if (itemType() == ItemType_CloudReal) 302 { 303 AssertPtrReturnVoid(m_pCloudMachine); 304 m_strId = m_pCloudMachine->id(); 305 m_strName = m_pCloudMachine->name(); 306 } 307 308 /* Now determine whether VM is accessible: */ 309 m_fAccessible = true; 310 if (m_fAccessible) 311 { 312 /* Reset last access error information: */ 313 m_comAccessError = CVirtualBoxErrorInfo(); 314 315 /* Determine own VM attributes: */ 316 m_strOSTypeId = "Other"; 317 318 /* Determine VM states: */ 319 if ( itemType() == ItemType_CloudFake 320 || m_enmMachineState == KMachineState_Null) 321 m_enmMachineState = KMachineState_PoweredOff; 322 m_strMachineStateName = gpConverter->toString(m_enmMachineState); 323 if (itemType() == ItemType_CloudFake) 324 { 325 switch (m_enmFakeCloudItemState) 326 { 327 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading: 328 m_machineStateIcon = UIIconPool::iconSet(":/state_loading_16px.png"); 329 break; 330 case UIVirtualMachineItemCloud::FakeCloudItemState_Done: 331 m_machineStateIcon = UIIconPool::iconSet(":/vm_new_16px.png"); 332 break; 333 default: 334 break; 335 } 336 } 337 else 338 m_machineStateIcon = gpConverter->toIcon(m_enmMachineState); 339 340 /* Determine configuration access level: */ 341 m_enmConfigurationAccessLevel = ConfigurationAccessLevel_Null; 342 343 /* Determine whether we should show this VM details: */ 344 m_fHasDetails = false; 345 } 346 else 347 { 348 /// @todo handle inaccessible cloud VM 349 } 350 351 /* Recache item pixmap: */ 352 recachePixmap(); 353 354 /* Retranslate finally: */ 355 retranslateUi(); 356 } 357 358 void UIVirtualMachineItemCloud::recachePixmap() 359 { 360 /* If machine is accessible: */ 361 if (m_fAccessible) 362 { 363 /* We are using icon corresponding to cached guest OS type: */ 364 if ( itemType() == ItemType_CloudFake 365 && fakeCloudItemState() == FakeCloudItemState_Loading) 366 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault("Cloud", &m_logicalPixmapSize); 367 else 368 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize); 369 } 370 /* Otherwise: */ 371 else 372 { 373 /// @todo handle inaccessible cloud VM 374 } 375 } 376 377 bool UIVirtualMachineItemCloud::isItemEditable() const 378 { 379 return accessible(); 380 } 381 382 bool UIVirtualMachineItemCloud::isItemSaved() const 383 { 384 return accessible() 385 && machineState() == KMachineState_Saved; 386 } 387 388 bool UIVirtualMachineItemCloud::isItemPoweredOff() const 389 { 390 return accessible() 391 && ( machineState() == KMachineState_PoweredOff 392 || machineState() == KMachineState_Saved 393 || machineState() == KMachineState_Teleported 394 || machineState() == KMachineState_Aborted); 395 } 396 397 bool UIVirtualMachineItemCloud::isItemStarted() const 398 { 399 return isItemRunning() 400 || isItemPaused(); 401 } 402 403 bool UIVirtualMachineItemCloud::isItemRunning() const 404 { 405 return accessible() 406 && ( machineState() == KMachineState_Running 407 || machineState() == KMachineState_Teleporting 408 || machineState() == KMachineState_LiveSnapshotting); 409 } 410 411 bool UIVirtualMachineItemCloud::isItemRunningHeadless() const 412 { 413 return isItemRunning(); 414 } 415 416 bool UIVirtualMachineItemCloud::isItemPaused() const 417 { 418 return accessible() 419 && ( machineState() == KMachineState_Paused 420 || machineState() == KMachineState_TeleportingPausedVM); 421 } 422 423 bool UIVirtualMachineItemCloud::isItemStuck() const 424 { 425 return accessible() 426 && machineState() == KMachineState_Stuck; 427 } 428 429 void UIVirtualMachineItemCloud::retranslateUi() 430 { 431 /* If machine is accessible: */ 432 if (m_fAccessible) 433 { 434 if (itemType() == ItemType_CloudFake) 435 { 436 /* Update machine/state name: */ 437 switch (m_enmFakeCloudItemState) 438 { 439 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading: 440 m_strMachineStateName = tr("Loading ..."); 441 break; 442 case UIVirtualMachineItemCloud::FakeCloudItemState_Done: 443 m_strMachineStateName = tr("Up-To-Date"); 444 break; 445 default: 446 break; 447 } 448 449 /* Update tool-tip: */ 450 m_strToolTipText = m_strMachineStateName; 451 } 452 else 453 { 454 /* Update tool-tip: */ 455 m_strToolTipText = QString("<nobr><b>%1</b></nobr><br>" 456 "<nobr>%2</nobr>") 457 .arg(m_strName) 458 .arg(gpConverter->toString(m_enmMachineState)); 459 460 } 461 } 462 /* Otherwise: */ 463 else 464 { 465 /* Update tool-tip: */ 466 m_strToolTipText = tr("<nobr><b>%1</b></nobr><br>" 467 "<nobr>Inaccessible</nobr>", 468 "Inaccessible VM tooltip (name)") 469 .arg(m_strName); 470 471 /* We have our own translation for Null states: */ 472 m_strMachineStateName = tr("Inaccessible"); 473 } 474 } 475 476 void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceStateTask() 477 { 478 /* Make sure item is of real cloud type and is initialized: */ 479 AssertReturnVoid(itemType() == ItemType_CloudReal); 480 AssertPtrReturnVoid(m_pCloudMachine); 481 482 /* Create and start task to acquire state async way only if there is no task yet: */ 483 if (!m_pTask) 484 { 485 m_pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId); 486 connect(m_pTask, &UITask::sigComplete, 487 this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone); 488 uiCommon().threadPool()->enqueueTask(m_pTask); 489 } 490 } 491 492 void UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone(UITask *pTask) 493 { 494 /* Skip unrelated tasks: */ 495 if (!m_pTask || pTask != m_pTask) 496 return; 497 498 /* Mark our task handled: */ 499 m_pTask = 0; 500 501 /* Cast task to corresponding sub-class: */ 502 UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask); 503 504 /* Update state: */ 505 updateState(pStateTask->result()); 506 } 507 508 void UIVirtualMachineItemCloud::updateState(const QString &strState) 509 { 510 /* Prepare a map of known states: */ 511 QMap<QString, KMachineState> states; 512 states["RUNNING"] = KMachineState_Running; 513 states["STOPPED"] = KMachineState_Paused; 514 states["STOPPING"] = KMachineState_Stopping; 515 states["STARTING"] = KMachineState_Starting; 516 517 /* Update our state value: */ 518 m_enmMachineState = states.value(strState, KMachineState_PoweredOff); 519 520 /* Recache: */ 521 recache(); 522 523 /* Notify listeners finally: */ 524 emit sigStateChange(); 525 } 526 527 528 #include "UIVirtualMachineItemCloud.moc" 48 #endif /* !FEQT_INCLUDED_SRC_manager_UICloudNetworkingStuff_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp
r83095 r83107 21 21 /* GUI includes: */ 22 22 #include "UICloudMachine.h" 23 #include "UICloudNetworkingStuff.h" 23 24 #include "UICommon.h" 24 25 #include "UIConverter.h" … … 30 31 31 32 /* COM includes: */ 32 #include "CAppliance.h" 33 #include "CVirtualBox.h" 34 #include "CVirtualSystemDescription.h" 35 36 37 /** GetInstanceInfo namespace. */ 38 namespace GetInstanceInfo 39 { 40 /** Acquires instance info of certain @a enmType. 41 * @param comCloudClient Brings cloud client object. 42 * @param strId Brings cloud VM id. 43 * @param pWidget Brings parent widget to show messages according to. */ 44 QString getInstanceInfo(KVirtualSystemDescriptionType enmType, 45 const CCloudClient &comCloudClient, 46 const QString &strId, 47 QWidget *pParent = 0); 48 } 49 50 /* Using across module: */ 51 using namespace GetInstanceInfo; 33 #include "CProgress.h" 52 34 53 35 … … 88 70 QString m_strResult; 89 71 }; 90 91 92 /*********************************************************************************************************************************93 * Namespace GetInstanceInfo implementation. *94 *********************************************************************************************************************************/95 96 QString GetInstanceInfo::getInstanceInfo(KVirtualSystemDescriptionType enmType,97 const CCloudClient &comCloudClient,98 const QString &strId,99 QWidget *pParent /* = 0 */)100 {101 /* Get VirtualBox object: */102 CVirtualBox comVBox = uiCommon().virtualBox();103 104 /* Create appliance: */105 CAppliance comAppliance = comVBox.CreateAppliance();106 if (!comVBox.isOk())107 {108 if (pParent)109 msgCenter().cannotCreateAppliance(comVBox, pParent);110 else111 {112 /// @todo fetch error info113 }114 }115 else116 {117 /* Append it with one (1) description we need: */118 comAppliance.CreateVirtualSystemDescriptions(1);119 if (!comAppliance.isOk())120 {121 if (pParent)122 msgCenter().cannotCreateVirtualSystemDescription(comAppliance, pParent);123 else124 {125 /// @todo fetch error info126 }127 }128 else129 {130 /* Get received description: */131 QVector<CVirtualSystemDescription> descriptions = comAppliance.GetVirtualSystemDescriptions();132 AssertReturn(!descriptions.isEmpty(), QString());133 CVirtualSystemDescription comDescription = descriptions.at(0);134 135 /* Now execute GetInstanceInfo async method: */136 CProgress comProgress = comCloudClient.GetInstanceInfo(strId, comDescription);137 if (!comCloudClient.isOk())138 {139 if (pParent)140 msgCenter().cannotAcquireCloudClientParameter(comCloudClient, pParent);141 else142 {143 /// @todo fetch error info144 }145 }146 else147 {148 /* Show "Acquire instance info" progress: */149 if (pParent)150 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Acquire instance info ..."),151 ":/progress_reading_appliance_90px.png", pParent, 0);152 else153 comProgress.WaitForCompletion(-1);154 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)155 {156 if (pParent)157 msgCenter().cannotAcquireCloudClientParameter(comProgress, pParent);158 else159 {160 /// @todo fetch error info161 }162 }163 else164 {165 /* Now acquire description of certain type: */166 QVector<KVirtualSystemDescriptionType> types;167 QVector<QString> refs, origValues, configValues, extraConfigValues;168 comDescription.GetDescriptionByType(enmType, types, refs, origValues, configValues, extraConfigValues);169 170 /* Return first config value if we have one: */171 AssertReturn(!configValues.isEmpty(), QString());172 return configValues.at(0);173 }174 }175 }176 }177 178 /* Return null string by default: */179 return QString();180 }181 72 182 73
Note:
See TracChangeset
for help on using the changeset viewer.