Changeset 86656 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Oct 20, 2020 3:58:07 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r86654 r86656 67 67 , m_iScrollingTokenSize(30) 68 68 , m_fIsScrollingInProgress(false) 69 , m_fPreventCloudProfileUpdate(false) 70 , m_pTimerCloudProfileUpdate(0) 69 71 { 70 72 prepare(); … … 1238 1240 1239 1241 /* Rebuild tree for main root: */ 1242 m_fPreventCloudProfileUpdate = true; 1240 1243 buildTreeForMainRoot(true /* preserve selection */); 1244 m_fPreventCloudProfileUpdate = false; 1245 1246 /* Restart cloud profile update timer: */ 1247 m_pTimerCloudProfileUpdate->start(10000); 1241 1248 } 1242 1249 … … 1305 1312 } 1306 1313 1314 void UIChooserModel::sltUpdateSelectedCloudProfiles() 1315 { 1316 /* Ignore if cloud profile update is restricted: */ 1317 if (m_fPreventCloudProfileUpdate) 1318 return; 1319 1320 /* For every selected item: */ 1321 QSet<UICloudAccountKey> selectedCloudAccountKeys; 1322 foreach (UIChooserItem *pSelectedItem, selectedItems()) 1323 { 1324 /* Enumerate cloud account keys to update: */ 1325 switch (pSelectedItem->type()) 1326 { 1327 case UIChooserNodeType_Group: 1328 { 1329 UIChooserItemGroup *pGroupItem = pSelectedItem->toGroupItem(); 1330 AssertPtrReturnVoid(pGroupItem); 1331 switch (pGroupItem->groupType()) 1332 { 1333 case UIChooserNodeGroupType_Provider: 1334 { 1335 const QString strProviderShortName = pSelectedItem->name(); 1336 foreach (UIChooserItem *pChildItem, pSelectedItem->items(UIChooserNodeType_Group)) 1337 { 1338 const QString strProfileName = pChildItem->name(); 1339 const UICloudAccountKey cloudAccountKey = qMakePair(strProviderShortName, strProfileName); 1340 if (!selectedCloudAccountKeys.contains(cloudAccountKey)) 1341 selectedCloudAccountKeys.insert(cloudAccountKey); 1342 } 1343 break; 1344 } 1345 case UIChooserNodeGroupType_Profile: 1346 { 1347 const QString strProviderShortName = pSelectedItem->parentItem()->name(); 1348 const QString strProfileName = pSelectedItem->name(); 1349 const UICloudAccountKey cloudAccountKey = qMakePair(strProviderShortName, strProfileName); 1350 if (!selectedCloudAccountKeys.contains(cloudAccountKey)) 1351 selectedCloudAccountKeys.insert(cloudAccountKey); 1352 break; 1353 } 1354 default: 1355 break; 1356 } 1357 break; 1358 } 1359 case UIChooserNodeType_Machine: 1360 { 1361 UIChooserItemMachine *pMachineItem = pSelectedItem->toMachineItem(); 1362 AssertPtrReturnVoid(pMachineItem); 1363 if ( pMachineItem->cacheType() == UIVirtualMachineItemType_CloudFake 1364 || pMachineItem->cacheType() == UIVirtualMachineItemType_CloudReal) 1365 { 1366 const QString strProviderShortName = pMachineItem->parentItem()->parentItem()->name(); 1367 const QString strProfileName = pMachineItem->parentItem()->name(); 1368 const UICloudAccountKey cloudAccountKey = qMakePair(strProviderShortName, strProfileName); 1369 if (!selectedCloudAccountKeys.contains(cloudAccountKey)) 1370 selectedCloudAccountKeys.insert(cloudAccountKey); 1371 } 1372 break; 1373 } 1374 } 1375 } 1376 1377 /* Restart List Cloud Machines task for selected account keys: */ 1378 foreach (const UICloudAccountKey &cloudAccountKey, selectedCloudAccountKeys) 1379 { 1380 /* Skip cloud account keys already being updated: */ 1381 if (containsCloudAccountKey(cloudAccountKey)) 1382 continue; 1383 insertCloudAccountKey(cloudAccountKey); 1384 1385 /* Create a task for particular cloud account key: */ 1386 UITaskCloudListMachines *pTask = new UITaskCloudListMachines(cloudAccountKey.first /* short provider name */, 1387 cloudAccountKey.second /* profile name */, 1388 false /* with refresh? */); 1389 AssertPtrReturnVoid(pTask); 1390 uiCommon().threadPoolCloud()->enqueueTask(pTask); 1391 } 1392 } 1393 1307 1394 void UIChooserModel::prepare() 1308 1395 { … … 1310 1397 prepareContextMenu(); 1311 1398 prepareHandlers(); 1399 prepareCloudUpdateTimer(); 1400 prepareConnections(); 1312 1401 } 1313 1402 … … 1463 1552 } 1464 1553 1554 void UIChooserModel::prepareCloudUpdateTimer() 1555 { 1556 m_pTimerCloudProfileUpdate = new QTimer; 1557 if (m_pTimerCloudProfileUpdate) 1558 m_pTimerCloudProfileUpdate->setSingleShot(true); 1559 } 1560 1561 void UIChooserModel::prepareConnections() 1562 { 1563 connect(this, &UIChooserModel::sigSelectionChanged, 1564 this, &UIChooserModel::sltUpdateSelectedCloudProfiles); 1565 connect(m_pTimerCloudProfileUpdate, &QTimer::timeout, 1566 this, &UIChooserModel::sltUpdateSelectedCloudProfiles); 1567 } 1568 1465 1569 void UIChooserModel::loadLastSelectedItem() 1466 1570 { … … 1493 1597 } 1494 1598 1599 void UIChooserModel::cleanupConnections() 1600 { 1601 disconnect(this, &UIChooserModel::sigSelectionChanged, 1602 this, &UIChooserModel::sltUpdateSelectedCloudProfiles); 1603 disconnect(m_pTimerCloudProfileUpdate, &QTimer::timeout, 1604 this, &UIChooserModel::sltUpdateSelectedCloudProfiles); 1605 } 1606 1607 void UIChooserModel::cleanupCloudUpdateTimer() 1608 { 1609 delete m_pTimerCloudProfileUpdate; 1610 m_pTimerCloudProfileUpdate = 0; 1611 } 1612 1495 1613 void UIChooserModel::cleanupHandlers() 1496 1614 { … … 1517 1635 void UIChooserModel::cleanup() 1518 1636 { 1637 cleanupConnections(); 1638 cleanupCloudUpdateTimer(); 1519 1639 cleanupHandlers(); 1520 1640 cleanupContextMenu(); … … 1800 1920 machines << pMachineItem->cache()->toCloud()->machine(); 1801 1921 1922 /* Stop cloud update prematurely: */ 1923 m_pTimerCloudProfileUpdate->stop(); 1924 1802 1925 /* Confirm machine removal: */ 1803 1926 const int iResultCode = msgCenter().confirmCloudMachineRemoval(machines); 1804 1927 if (iResultCode == AlertButton_Cancel) 1928 { 1929 /* Resume cloud update if cancelled: */ 1930 m_pTimerCloudProfileUpdate->start(10000); 1805 1931 return; 1932 } 1806 1933 1807 1934 /* For every selected machine-item: */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h
r86649 r86656 330 330 /** @} */ 331 331 332 /** @name Cloud stuff. 333 * @{ */ 334 /** Updates selected cloud profiles. */ 335 void sltUpdateSelectedCloudProfiles(); 336 /** @} */ 337 332 338 private: 333 339 … … 342 348 /** Prepares handlers. */ 343 349 void prepareHandlers(); 350 /** Prepares cloud update timer. */ 351 void prepareCloudUpdateTimer(); 352 /** Prepares connections. */ 353 void prepareConnections(); 344 354 /** Loads last selected-items. */ 345 355 void loadLastSelectedItem(); … … 347 357 /** Saves last selected-items. */ 348 358 void saveLastSelectedItem(); 359 /** Cleanups connections. */ 360 void cleanupConnections(); 361 /** Cleanups cloud update timer.*/ 362 void cleanupCloudUpdateTimer(); 349 363 /** Cleanups handlers. */ 350 364 void cleanupHandlers(); … … 443 457 bool m_fIsScrollingInProgress; 444 458 /** @} */ 459 460 /** @name Cloud stuff. 461 * @{ */ 462 /** Holds whether cloud profile update is restricted. */ 463 bool m_fPreventCloudProfileUpdate; 464 /** Holds cloud profile update timer instance. */ 465 QTimer *m_pTimerCloudProfileUpdate; 466 /** @} */ 445 467 }; 446 468
Note:
See TracChangeset
for help on using the changeset viewer.