- Timestamp:
- Feb 18, 2020 3:29:54 PM (5 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 5 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r83107 r83108 617 617 src/manager/UIErrorPane.h \ 618 618 src/manager/UITaskCloudAcquireInstances.h \ 619 src/manager/UITaskCloudGetInstanceState.h \ 619 620 src/manager/UIToolPaneGlobal.h \ 620 621 src/manager/UIToolPaneMachine.h \ … … 956 957 VirtualBox_QT_MOCSRCS = \ 957 958 src/hostnetwork/UIHostNetworkManager.cpp \ 958 src/manager/UIVirtualMachineItemCloud.cpp \959 959 src/manager/UIWelcomePane.cpp \ 960 960 src/snapshots/UISnapshotDetailsWidget.cpp \ … … 1066 1066 src/manager/UIErrorPane.cpp \ 1067 1067 src/manager/UITaskCloudAcquireInstances.cpp \ 1068 src/manager/UITaskCloudGetInstanceState.cpp \ 1068 1069 src/manager/UIToolPaneGlobal.cpp \ 1069 1070 src/manager/UIToolPaneMachine.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UITask.h
r83094 r83108 47 47 Type_DetailsPopulation = 2, 48 48 Type_CloudAcquireInstances = 3, 49 Type_ GetCloudInstanceState = 4,49 Type_CloudGetInstanceState = 4, 50 50 }; 51 51 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UITaskCloudGetInstanceState.cpp
r83107 r83108 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI VirtualMachineItemCloudclass implementation.3 * VBox Qt GUI - UITaskCloudGetInstanceState class 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 "UICloudMachine.h"23 19 #include "UICloudNetworkingStuff.h" 24 #include "UICommon.h" 25 #include "UIConverter.h" 26 #include "UIIconPool.h" 27 #include "UIMessageCenter.h" 28 #include "UITask.h" 29 #include "UIThreadPool.h" 30 #include "UIVirtualMachineItemCloud.h" 31 32 /* COM includes: */ 33 #include "CProgress.h" 20 #include "UITaskCloudGetInstanceState.h" 34 21 35 22 36 /** UITask extension used to get cloud instance state async way. */ 37 class UITaskGetCloudInstanceState : public UITask 38 { 39 Q_OBJECT; 40 41 public: 42 43 /** Constructs task taking @a comCloudClient and @a strId as data. 44 * @param comCloudClient Brings the cloud client object. 45 * @param strId Brings the cloud VM id. */ 46 UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId); 47 48 /** Returns the task result. */ 49 QString result() const; 50 51 protected: 52 53 /** Contains the task body. */ 54 virtual void run() /* override */; 55 56 private: 57 58 /** Holds the mutex to access result. */ 59 mutable QMutex m_mutex; 60 61 /** Holds the cloud client object. */ 62 CCloudClient m_comCloudClient; 63 /** Holds the cloud VM id. */ 64 QString m_strId; 65 66 /** Holds the error info object. */ 67 CVirtualBoxErrorInfo m_comErrorInfo; 68 69 /** Holds the task result. */ 70 QString m_strResult; 71 }; 72 73 74 /********************************************************************************************************************************* 75 * Class UITaskGetCloudInstanceState implementation. * 76 *********************************************************************************************************************************/ 77 78 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId) 79 : UITask(Type_GetCloudInstanceState) 23 UITaskCloudGetInstanceState::UITaskCloudGetInstanceState(const CCloudClient &comCloudClient, const QString &strId) 24 : UITask(Type_CloudGetInstanceState) 80 25 , m_comCloudClient(comCloudClient) 81 26 , m_strId(strId) … … 83 28 } 84 29 85 QString UITask GetCloudInstanceState::result() const30 QString UITaskCloudGetInstanceState::result() const 86 31 { 87 32 m_mutex.lock(); … … 91 36 } 92 37 93 void UITaskGetCloudInstanceState::run() 38 CVirtualBoxErrorInfo UITaskCloudGetInstanceState::errorInfo() 39 { 40 m_mutex.lock(); 41 CVirtualBoxErrorInfo comErrorInfo = m_comErrorInfo; 42 m_mutex.unlock(); 43 return comErrorInfo; 44 } 45 46 void UITaskCloudGetInstanceState::run() 94 47 { 95 48 m_mutex.lock(); … … 97 50 m_mutex.unlock(); 98 51 } 99 100 101 /*********************************************************************************************************************************102 * Class UIVirtualMachineItemCloud implementation. *103 *********************************************************************************************************************************/104 105 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud()106 : UIVirtualMachineItem(ItemType_CloudFake)107 , m_pCloudMachine(0)108 , m_enmFakeCloudItemState(FakeCloudItemState_Loading)109 , m_pTask(0)110 {111 recache();112 }113 114 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(const UICloudMachine &guiCloudMachine)115 : UIVirtualMachineItem(ItemType_CloudReal)116 , m_pCloudMachine(new UICloudMachine(guiCloudMachine))117 , m_enmFakeCloudItemState(FakeCloudItemState_NotApplicable)118 , m_pTask(0)119 {120 recache();121 }122 123 UIVirtualMachineItemCloud::~UIVirtualMachineItemCloud()124 {125 delete m_pCloudMachine;126 }127 128 void UIVirtualMachineItemCloud::updateState(QWidget *pParent)129 {130 /* Make sure item is of real cloud type and is initialized: */131 AssertReturnVoid(itemType() == ItemType_CloudReal);132 AssertPtrReturnVoid(m_pCloudMachine);133 134 /* Acquire state: */135 const QString strState = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState,136 m_pCloudMachine->client(),137 m_strId,138 pParent);139 140 /* Update state: */141 updateState(strState);142 }143 144 void UIVirtualMachineItemCloud::updateStateAsync(bool fDelayed)145 {146 QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceStateTask()));147 }148 149 void UIVirtualMachineItemCloud::pause(QWidget *pParent)150 {151 pauseOrResume(true /* pause? */, pParent);152 }153 154 void UIVirtualMachineItemCloud::resume(QWidget *pParent)155 {156 pauseOrResume(false /* pause? */, pParent);157 }158 159 void UIVirtualMachineItemCloud::pauseOrResume(bool fPause, QWidget *pParent)160 {161 /* Acquire cloud client: */162 CCloudClient comCloudClient = m_pCloudMachine->client();163 164 /* Now execute async method: */165 CProgress comProgress;166 if (fPause)167 comProgress = comCloudClient.PauseInstance(m_strId);168 else169 comProgress = comCloudClient.StartInstance(m_strId);170 if (!comCloudClient.isOk())171 msgCenter().cannotAcquireCloudClientParameter(comCloudClient);172 else173 {174 /* Show progress: */175 /// @todo use proper pause icon176 if (fPause)177 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Pause instance ..."),178 ":/progress_reading_appliance_90px.png", pParent, 0);179 else180 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Start instance ..."),181 ":/progress_start_90px.png", pParent, 0);182 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)183 msgCenter().cannotAcquireCloudClientParameter(comProgress);184 else185 updateStateAsync(false /* delayed? */);186 }187 }188 189 void UIVirtualMachineItemCloud::recache()190 {191 /* Determine attributes which are always available: */192 if (itemType() == ItemType_CloudReal)193 {194 AssertPtrReturnVoid(m_pCloudMachine);195 m_strId = m_pCloudMachine->id();196 m_strName = m_pCloudMachine->name();197 }198 199 /* Now determine whether VM is accessible: */200 m_fAccessible = true;201 if (m_fAccessible)202 {203 /* Reset last access error information: */204 m_comAccessError = CVirtualBoxErrorInfo();205 206 /* Determine own VM attributes: */207 m_strOSTypeId = "Other";208 209 /* Determine VM states: */210 if ( itemType() == ItemType_CloudFake211 || m_enmMachineState == KMachineState_Null)212 m_enmMachineState = KMachineState_PoweredOff;213 m_strMachineStateName = gpConverter->toString(m_enmMachineState);214 if (itemType() == ItemType_CloudFake)215 {216 switch (m_enmFakeCloudItemState)217 {218 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:219 m_machineStateIcon = UIIconPool::iconSet(":/state_loading_16px.png");220 break;221 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:222 m_machineStateIcon = UIIconPool::iconSet(":/vm_new_16px.png");223 break;224 default:225 break;226 }227 }228 else229 m_machineStateIcon = gpConverter->toIcon(m_enmMachineState);230 231 /* Determine configuration access level: */232 m_enmConfigurationAccessLevel = ConfigurationAccessLevel_Null;233 234 /* Determine whether we should show this VM details: */235 m_fHasDetails = false;236 }237 else238 {239 /// @todo handle inaccessible cloud VM240 }241 242 /* Recache item pixmap: */243 recachePixmap();244 245 /* Retranslate finally: */246 retranslateUi();247 }248 249 void UIVirtualMachineItemCloud::recachePixmap()250 {251 /* If machine is accessible: */252 if (m_fAccessible)253 {254 /* We are using icon corresponding to cached guest OS type: */255 if ( itemType() == ItemType_CloudFake256 && fakeCloudItemState() == FakeCloudItemState_Loading)257 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault("Cloud", &m_logicalPixmapSize);258 else259 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize);260 }261 /* Otherwise: */262 else263 {264 /// @todo handle inaccessible cloud VM265 }266 }267 268 bool UIVirtualMachineItemCloud::isItemEditable() const269 {270 return accessible();271 }272 273 bool UIVirtualMachineItemCloud::isItemSaved() const274 {275 return accessible()276 && machineState() == KMachineState_Saved;277 }278 279 bool UIVirtualMachineItemCloud::isItemPoweredOff() const280 {281 return accessible()282 && ( machineState() == KMachineState_PoweredOff283 || machineState() == KMachineState_Saved284 || machineState() == KMachineState_Teleported285 || machineState() == KMachineState_Aborted);286 }287 288 bool UIVirtualMachineItemCloud::isItemStarted() const289 {290 return isItemRunning()291 || isItemPaused();292 }293 294 bool UIVirtualMachineItemCloud::isItemRunning() const295 {296 return accessible()297 && ( machineState() == KMachineState_Running298 || machineState() == KMachineState_Teleporting299 || machineState() == KMachineState_LiveSnapshotting);300 }301 302 bool UIVirtualMachineItemCloud::isItemRunningHeadless() const303 {304 return isItemRunning();305 }306 307 bool UIVirtualMachineItemCloud::isItemPaused() const308 {309 return accessible()310 && ( machineState() == KMachineState_Paused311 || machineState() == KMachineState_TeleportingPausedVM);312 }313 314 bool UIVirtualMachineItemCloud::isItemStuck() const315 {316 return accessible()317 && machineState() == KMachineState_Stuck;318 }319 320 void UIVirtualMachineItemCloud::retranslateUi()321 {322 /* If machine is accessible: */323 if (m_fAccessible)324 {325 if (itemType() == ItemType_CloudFake)326 {327 /* Update machine/state name: */328 switch (m_enmFakeCloudItemState)329 {330 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:331 m_strMachineStateName = tr("Loading ...");332 break;333 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:334 m_strMachineStateName = tr("Up-To-Date");335 break;336 default:337 break;338 }339 340 /* Update tool-tip: */341 m_strToolTipText = m_strMachineStateName;342 }343 else344 {345 /* Update tool-tip: */346 m_strToolTipText = QString("<nobr><b>%1</b></nobr><br>"347 "<nobr>%2</nobr>")348 .arg(m_strName)349 .arg(gpConverter->toString(m_enmMachineState));350 351 }352 }353 /* Otherwise: */354 else355 {356 /* Update tool-tip: */357 m_strToolTipText = tr("<nobr><b>%1</b></nobr><br>"358 "<nobr>Inaccessible</nobr>",359 "Inaccessible VM tooltip (name)")360 .arg(m_strName);361 362 /* We have our own translation for Null states: */363 m_strMachineStateName = tr("Inaccessible");364 }365 }366 367 void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceStateTask()368 {369 /* Make sure item is of real cloud type and is initialized: */370 AssertReturnVoid(itemType() == ItemType_CloudReal);371 AssertPtrReturnVoid(m_pCloudMachine);372 373 /* Create and start task to acquire state async way only if there is no task yet: */374 if (!m_pTask)375 {376 m_pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId);377 connect(m_pTask, &UITask::sigComplete,378 this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone);379 uiCommon().threadPool()->enqueueTask(m_pTask);380 }381 }382 383 void UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone(UITask *pTask)384 {385 /* Skip unrelated tasks: */386 if (!m_pTask || pTask != m_pTask)387 return;388 389 /* Mark our task handled: */390 m_pTask = 0;391 392 /* Cast task to corresponding sub-class: */393 UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask);394 395 /* Update state: */396 updateState(pStateTask->result());397 }398 399 void UIVirtualMachineItemCloud::updateState(const QString &strState)400 {401 /* Prepare a map of known states: */402 QMap<QString, KMachineState> states;403 states["RUNNING"] = KMachineState_Running;404 states["STOPPED"] = KMachineState_Paused;405 states["STOPPING"] = KMachineState_Stopping;406 states["STARTING"] = KMachineState_Starting;407 408 /* Update our state value: */409 m_enmMachineState = states.value(strState, KMachineState_PoweredOff);410 411 /* Recache: */412 recache();413 414 /* Notify listeners finally: */415 emit sigStateChange();416 }417 418 419 #include "UIVirtualMachineItemCloud.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UITaskCloudGetInstanceState.h
r83107 r83108 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI VirtualMachineItemCloud class implementation.3 * VBox Qt GUI - UITaskCloudGetInstanceState class 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 #ifndef FEQT_INCLUDED_SRC_manager_UITaskCloudGetInstanceState_h 19 #define FEQT_INCLUDED_SRC_manager_UITaskCloudGetInstanceState_h 20 #ifndef RT_WITHOUT_PRAGMA_ONCE 21 # pragma once 22 #endif 23 18 24 /* Qt includes: */ 19 #include <Q Timer>25 #include <QMutex> 20 26 21 27 /* GUI includes: */ 22 #include "UICloudMachine.h"23 #include "UICloudNetworkingStuff.h"24 #include "UICommon.h"25 #include "UIConverter.h"26 #include "UIIconPool.h"27 #include "UIMessageCenter.h"28 28 #include "UITask.h" 29 #include "UIThreadPool.h"30 #include "UIVirtualMachineItemCloud.h"31 29 32 30 /* COM includes: */ 33 #include "CProgress.h" 31 #include "COMEnums.h" 32 #include "CCloudClient.h" 33 #include "CVirtualBoxErrorInfo.h" 34 34 35 35 36 /** UITask extension used to get cloud instance state async way. */37 class UITask GetCloudInstanceState : public UITask36 /** UITask extension used to get cloud instance state. */ 37 class UITaskCloudGetInstanceState : public UITask 38 38 { 39 39 Q_OBJECT; … … 44 44 * @param comCloudClient Brings the cloud client object. 45 45 * @param strId Brings the cloud VM id. */ 46 UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId); 46 UITaskCloudGetInstanceState(const CCloudClient &comCloudClient, const QString &strId); 47 48 /** Returns error info. */ 49 CVirtualBoxErrorInfo errorInfo(); 47 50 48 51 /** Returns the task result. */ … … 71 74 }; 72 75 73 74 /********************************************************************************************************************************* 75 * Class UITaskGetCloudInstanceState implementation. * 76 *********************************************************************************************************************************/ 77 78 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId) 79 : UITask(Type_GetCloudInstanceState) 80 , m_comCloudClient(comCloudClient) 81 , m_strId(strId) 82 { 83 } 84 85 QString UITaskGetCloudInstanceState::result() const 86 { 87 m_mutex.lock(); 88 const QString strResult = m_strResult; 89 m_mutex.unlock(); 90 return strResult; 91 } 92 93 void UITaskGetCloudInstanceState::run() 94 { 95 m_mutex.lock(); 96 m_strResult = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, m_comCloudClient, m_strId); 97 m_mutex.unlock(); 98 } 99 100 101 /********************************************************************************************************************************* 102 * Class UIVirtualMachineItemCloud implementation. * 103 *********************************************************************************************************************************/ 104 105 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud() 106 : UIVirtualMachineItem(ItemType_CloudFake) 107 , m_pCloudMachine(0) 108 , m_enmFakeCloudItemState(FakeCloudItemState_Loading) 109 , m_pTask(0) 110 { 111 recache(); 112 } 113 114 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(const UICloudMachine &guiCloudMachine) 115 : UIVirtualMachineItem(ItemType_CloudReal) 116 , m_pCloudMachine(new UICloudMachine(guiCloudMachine)) 117 , m_enmFakeCloudItemState(FakeCloudItemState_NotApplicable) 118 , m_pTask(0) 119 { 120 recache(); 121 } 122 123 UIVirtualMachineItemCloud::~UIVirtualMachineItemCloud() 124 { 125 delete m_pCloudMachine; 126 } 127 128 void UIVirtualMachineItemCloud::updateState(QWidget *pParent) 129 { 130 /* Make sure item is of real cloud type and is initialized: */ 131 AssertReturnVoid(itemType() == ItemType_CloudReal); 132 AssertPtrReturnVoid(m_pCloudMachine); 133 134 /* Acquire state: */ 135 const QString strState = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, 136 m_pCloudMachine->client(), 137 m_strId, 138 pParent); 139 140 /* Update state: */ 141 updateState(strState); 142 } 143 144 void UIVirtualMachineItemCloud::updateStateAsync(bool fDelayed) 145 { 146 QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceStateTask())); 147 } 148 149 void UIVirtualMachineItemCloud::pause(QWidget *pParent) 150 { 151 pauseOrResume(true /* pause? */, pParent); 152 } 153 154 void UIVirtualMachineItemCloud::resume(QWidget *pParent) 155 { 156 pauseOrResume(false /* pause? */, pParent); 157 } 158 159 void UIVirtualMachineItemCloud::pauseOrResume(bool fPause, QWidget *pParent) 160 { 161 /* Acquire cloud client: */ 162 CCloudClient comCloudClient = m_pCloudMachine->client(); 163 164 /* Now execute async method: */ 165 CProgress comProgress; 166 if (fPause) 167 comProgress = comCloudClient.PauseInstance(m_strId); 168 else 169 comProgress = comCloudClient.StartInstance(m_strId); 170 if (!comCloudClient.isOk()) 171 msgCenter().cannotAcquireCloudClientParameter(comCloudClient); 172 else 173 { 174 /* Show progress: */ 175 /// @todo use proper pause icon 176 if (fPause) 177 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Pause instance ..."), 178 ":/progress_reading_appliance_90px.png", pParent, 0); 179 else 180 msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Start instance ..."), 181 ":/progress_start_90px.png", pParent, 0); 182 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 183 msgCenter().cannotAcquireCloudClientParameter(comProgress); 184 else 185 updateStateAsync(false /* delayed? */); 186 } 187 } 188 189 void UIVirtualMachineItemCloud::recache() 190 { 191 /* Determine attributes which are always available: */ 192 if (itemType() == ItemType_CloudReal) 193 { 194 AssertPtrReturnVoid(m_pCloudMachine); 195 m_strId = m_pCloudMachine->id(); 196 m_strName = m_pCloudMachine->name(); 197 } 198 199 /* Now determine whether VM is accessible: */ 200 m_fAccessible = true; 201 if (m_fAccessible) 202 { 203 /* Reset last access error information: */ 204 m_comAccessError = CVirtualBoxErrorInfo(); 205 206 /* Determine own VM attributes: */ 207 m_strOSTypeId = "Other"; 208 209 /* Determine VM states: */ 210 if ( itemType() == ItemType_CloudFake 211 || m_enmMachineState == KMachineState_Null) 212 m_enmMachineState = KMachineState_PoweredOff; 213 m_strMachineStateName = gpConverter->toString(m_enmMachineState); 214 if (itemType() == ItemType_CloudFake) 215 { 216 switch (m_enmFakeCloudItemState) 217 { 218 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading: 219 m_machineStateIcon = UIIconPool::iconSet(":/state_loading_16px.png"); 220 break; 221 case UIVirtualMachineItemCloud::FakeCloudItemState_Done: 222 m_machineStateIcon = UIIconPool::iconSet(":/vm_new_16px.png"); 223 break; 224 default: 225 break; 226 } 227 } 228 else 229 m_machineStateIcon = gpConverter->toIcon(m_enmMachineState); 230 231 /* Determine configuration access level: */ 232 m_enmConfigurationAccessLevel = ConfigurationAccessLevel_Null; 233 234 /* Determine whether we should show this VM details: */ 235 m_fHasDetails = false; 236 } 237 else 238 { 239 /// @todo handle inaccessible cloud VM 240 } 241 242 /* Recache item pixmap: */ 243 recachePixmap(); 244 245 /* Retranslate finally: */ 246 retranslateUi(); 247 } 248 249 void UIVirtualMachineItemCloud::recachePixmap() 250 { 251 /* If machine is accessible: */ 252 if (m_fAccessible) 253 { 254 /* We are using icon corresponding to cached guest OS type: */ 255 if ( itemType() == ItemType_CloudFake 256 && fakeCloudItemState() == FakeCloudItemState_Loading) 257 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault("Cloud", &m_logicalPixmapSize); 258 else 259 m_pixmap = uiCommon().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize); 260 } 261 /* Otherwise: */ 262 else 263 { 264 /// @todo handle inaccessible cloud VM 265 } 266 } 267 268 bool UIVirtualMachineItemCloud::isItemEditable() const 269 { 270 return accessible(); 271 } 272 273 bool UIVirtualMachineItemCloud::isItemSaved() const 274 { 275 return accessible() 276 && machineState() == KMachineState_Saved; 277 } 278 279 bool UIVirtualMachineItemCloud::isItemPoweredOff() const 280 { 281 return accessible() 282 && ( machineState() == KMachineState_PoweredOff 283 || machineState() == KMachineState_Saved 284 || machineState() == KMachineState_Teleported 285 || machineState() == KMachineState_Aborted); 286 } 287 288 bool UIVirtualMachineItemCloud::isItemStarted() const 289 { 290 return isItemRunning() 291 || isItemPaused(); 292 } 293 294 bool UIVirtualMachineItemCloud::isItemRunning() const 295 { 296 return accessible() 297 && ( machineState() == KMachineState_Running 298 || machineState() == KMachineState_Teleporting 299 || machineState() == KMachineState_LiveSnapshotting); 300 } 301 302 bool UIVirtualMachineItemCloud::isItemRunningHeadless() const 303 { 304 return isItemRunning(); 305 } 306 307 bool UIVirtualMachineItemCloud::isItemPaused() const 308 { 309 return accessible() 310 && ( machineState() == KMachineState_Paused 311 || machineState() == KMachineState_TeleportingPausedVM); 312 } 313 314 bool UIVirtualMachineItemCloud::isItemStuck() const 315 { 316 return accessible() 317 && machineState() == KMachineState_Stuck; 318 } 319 320 void UIVirtualMachineItemCloud::retranslateUi() 321 { 322 /* If machine is accessible: */ 323 if (m_fAccessible) 324 { 325 if (itemType() == ItemType_CloudFake) 326 { 327 /* Update machine/state name: */ 328 switch (m_enmFakeCloudItemState) 329 { 330 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading: 331 m_strMachineStateName = tr("Loading ..."); 332 break; 333 case UIVirtualMachineItemCloud::FakeCloudItemState_Done: 334 m_strMachineStateName = tr("Up-To-Date"); 335 break; 336 default: 337 break; 338 } 339 340 /* Update tool-tip: */ 341 m_strToolTipText = m_strMachineStateName; 342 } 343 else 344 { 345 /* Update tool-tip: */ 346 m_strToolTipText = QString("<nobr><b>%1</b></nobr><br>" 347 "<nobr>%2</nobr>") 348 .arg(m_strName) 349 .arg(gpConverter->toString(m_enmMachineState)); 350 351 } 352 } 353 /* Otherwise: */ 354 else 355 { 356 /* Update tool-tip: */ 357 m_strToolTipText = tr("<nobr><b>%1</b></nobr><br>" 358 "<nobr>Inaccessible</nobr>", 359 "Inaccessible VM tooltip (name)") 360 .arg(m_strName); 361 362 /* We have our own translation for Null states: */ 363 m_strMachineStateName = tr("Inaccessible"); 364 } 365 } 366 367 void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceStateTask() 368 { 369 /* Make sure item is of real cloud type and is initialized: */ 370 AssertReturnVoid(itemType() == ItemType_CloudReal); 371 AssertPtrReturnVoid(m_pCloudMachine); 372 373 /* Create and start task to acquire state async way only if there is no task yet: */ 374 if (!m_pTask) 375 { 376 m_pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId); 377 connect(m_pTask, &UITask::sigComplete, 378 this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone); 379 uiCommon().threadPool()->enqueueTask(m_pTask); 380 } 381 } 382 383 void UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone(UITask *pTask) 384 { 385 /* Skip unrelated tasks: */ 386 if (!m_pTask || pTask != m_pTask) 387 return; 388 389 /* Mark our task handled: */ 390 m_pTask = 0; 391 392 /* Cast task to corresponding sub-class: */ 393 UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask); 394 395 /* Update state: */ 396 updateState(pStateTask->result()); 397 } 398 399 void UIVirtualMachineItemCloud::updateState(const QString &strState) 400 { 401 /* Prepare a map of known states: */ 402 QMap<QString, KMachineState> states; 403 states["RUNNING"] = KMachineState_Running; 404 states["STOPPED"] = KMachineState_Paused; 405 states["STOPPING"] = KMachineState_Stopping; 406 states["STARTING"] = KMachineState_Starting; 407 408 /* Update our state value: */ 409 m_enmMachineState = states.value(strState, KMachineState_PoweredOff); 410 411 /* Recache: */ 412 recache(); 413 414 /* Notify listeners finally: */ 415 emit sigStateChange(); 416 } 417 418 419 #include "UIVirtualMachineItemCloud.moc" 76 #endif /* !FEQT_INCLUDED_SRC_manager_UITaskCloudGetInstanceState_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp
r83107 r83108 26 26 #include "UIIconPool.h" 27 27 #include "UIMessageCenter.h" 28 #include "UITask .h"28 #include "UITaskCloudGetInstanceState.h" 29 29 #include "UIThreadPool.h" 30 30 #include "UIVirtualMachineItemCloud.h" … … 33 33 #include "CProgress.h" 34 34 35 36 /** UITask extension used to get cloud instance state async way. */37 class UITaskGetCloudInstanceState : public UITask38 {39 Q_OBJECT;40 41 public:42 43 /** Constructs task taking @a comCloudClient and @a strId as data.44 * @param comCloudClient Brings the cloud client object.45 * @param strId Brings the cloud VM id. */46 UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId);47 48 /** Returns the task result. */49 QString result() const;50 51 protected:52 53 /** Contains the task body. */54 virtual void run() /* override */;55 56 private:57 58 /** Holds the mutex to access result. */59 mutable QMutex m_mutex;60 61 /** Holds the cloud client object. */62 CCloudClient m_comCloudClient;63 /** Holds the cloud VM id. */64 QString m_strId;65 66 /** Holds the error info object. */67 CVirtualBoxErrorInfo m_comErrorInfo;68 69 /** Holds the task result. */70 QString m_strResult;71 };72 73 74 /*********************************************************************************************************************************75 * Class UITaskGetCloudInstanceState implementation. *76 *********************************************************************************************************************************/77 78 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId)79 : UITask(Type_GetCloudInstanceState)80 , m_comCloudClient(comCloudClient)81 , m_strId(strId)82 {83 }84 85 QString UITaskGetCloudInstanceState::result() const86 {87 m_mutex.lock();88 const QString strResult = m_strResult;89 m_mutex.unlock();90 return strResult;91 }92 93 void UITaskGetCloudInstanceState::run()94 {95 m_mutex.lock();96 m_strResult = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, m_comCloudClient, m_strId);97 m_mutex.unlock();98 }99 100 101 /*********************************************************************************************************************************102 * Class UIVirtualMachineItemCloud implementation. *103 *********************************************************************************************************************************/104 35 105 36 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud() … … 374 305 if (!m_pTask) 375 306 { 376 m_pTask = new UITask GetCloudInstanceState(m_pCloudMachine->client(), m_strId);307 m_pTask = new UITaskCloudGetInstanceState(m_pCloudMachine->client(), m_strId); 377 308 connect(m_pTask, &UITask::sigComplete, 378 309 this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone); … … 391 322 392 323 /* Cast task to corresponding sub-class: */ 393 UITask GetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask);324 UITaskCloudGetInstanceState *pStateTask = static_cast<UITaskCloudGetInstanceState*>(pTask); 394 325 395 326 /* Update state: */ … … 415 346 emit sigStateChange(); 416 347 } 417 418 419 #include "UIVirtualMachineItemCloud.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.h
r83095 r83108 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIVirtualMachineItemCloud class declaration s.3 * VBox Qt GUI - UIVirtualMachineItemCloud class declaration. 4 4 */ 5 5 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemLocal.h
r82944 r83108 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIVirtualMachineItemLocal class declaration s.3 * VBox Qt GUI - UIVirtualMachineItemLocal class declaration. 4 4 */ 5 5
Note:
See TracChangeset
for help on using the changeset viewer.