Changeset 96660 in vbox
- Timestamp:
- Sep 8, 2022 1:26:20 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 153542
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/snapshots
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp
r96658 r96660 89 89 UISnapshotItem(UISnapshotPane *pSnapshotWidget, 90 90 QITreeWidget *pTreeWidget, 91 const CSnapshot &comSnapshot); 91 const CSnapshot &comSnapshot, 92 bool fExtendedNameRequired); 92 93 /** Constructs normal snapshot item (child of tree-widget-item). */ 93 94 UISnapshotItem(UISnapshotPane *pSnapshotWidget, … … 98 99 UISnapshotItem(UISnapshotPane *pSnapshotWidget, 99 100 QITreeWidget *pTreeWidget, 100 const CMachine &comMachine); 101 const CMachine &comMachine, 102 bool fExtendedNameRequired); 101 103 /** Constructs "current state" item (child of tree-widget-item). */ 102 104 UISnapshotItem(UISnapshotPane *pSnapshotWidget, … … 106 108 /** Returns item machine. */ 107 109 CMachine machine() const { return m_comMachine; } 110 /** Returns item machine ID. */ 111 QUuid machineID() const { return m_uMachineID; } 108 112 /** Returns item snapshot. */ 109 113 CSnapshot snapshot() const { return m_comSnapshot; } … … 140 144 private: 141 145 146 /** Holds whether this item requires extended name. */ 147 bool m_fExtendedNameRequired; 148 142 149 /** Holds the pointer to the snapshot-widget this item belongs to. */ 143 150 QPointer<UISnapshotPane> m_pSnapshotWidget; … … 153 160 CMachine m_comMachine; 154 161 162 /** Holds the machine ID. */ 163 QUuid m_uMachineID; 155 164 /** Holds the "current snapshot" ID. */ 156 165 QUuid m_uSnapshotID; … … 210 219 UISnapshotItem::UISnapshotItem(UISnapshotPane *pSnapshotWidget, 211 220 QITreeWidget *pTreeWidget, 212 const CSnapshot &comSnapshot) 221 const CSnapshot &comSnapshot, 222 bool fExtendedNameRequired) 213 223 : QITreeWidgetItem(pTreeWidget) 224 , m_fExtendedNameRequired(fExtendedNameRequired) 214 225 , m_pSnapshotWidget(pSnapshotWidget) 215 226 , m_fCurrentStateItem(false) … … 226 237 const CSnapshot &comSnapshot) 227 238 : QITreeWidgetItem(pRootItem) 239 , m_fExtendedNameRequired(false) 228 240 , m_pSnapshotWidget(pSnapshotWidget) 229 241 , m_fCurrentStateItem(false) … … 238 250 UISnapshotItem::UISnapshotItem(UISnapshotPane *pSnapshotWidget, 239 251 QITreeWidget *pTreeWidget, 240 const CMachine &comMachine) 252 const CMachine &comMachine, 253 bool fExtendedNameRequired) 241 254 : QITreeWidgetItem(pTreeWidget) 255 , m_fExtendedNameRequired(fExtendedNameRequired) 242 256 , m_pSnapshotWidget(pSnapshotWidget) 243 257 , m_fCurrentStateItem(true) … … 262 276 const CMachine &comMachine) 263 277 : QITreeWidgetItem(pRootItem) 278 , m_fExtendedNameRequired(false) 264 279 , m_pSnapshotWidget(pSnapshotWidget) 265 280 , m_fCurrentStateItem(true) … … 314 329 /* Fetch machine information: */ 315 330 AssertReturnVoid(m_comMachine.isNotNull()); 331 m_uMachineID = m_comMachine.GetId(); 316 332 m_fCurrentStateModified = m_comMachine.GetCurrentStateModified(); 317 333 m_strName = m_fCurrentStateModified 318 334 ? tr("Current State (changed)", "Current State (Modified)") 319 335 : tr("Current State", "Current State (Unmodified)"); 320 setText(Column_Name, m_strName); 336 const QString strFinalName = m_fExtendedNameRequired 337 ? QString("%1 (%2)").arg(m_strName, m_comMachine.GetName()) 338 : m_strName; 339 setText(Column_Name, strFinalName); 321 340 m_strDescription = m_fCurrentStateModified 322 341 ? tr("The current state differs from the state stored in the current snapshot") … … 330 349 /* Fetch snapshot information: */ 331 350 AssertReturnVoid(m_comSnapshot.isNotNull()); 351 const CMachine comMachine = m_comSnapshot.GetMachine(); 352 m_uMachineID = comMachine.GetId(); 332 353 m_uSnapshotID = m_comSnapshot.GetId(); 333 354 m_strName = m_comSnapshot.GetName(); 334 setText(Column_Name, m_strName); 355 const QString strFinalName = m_fExtendedNameRequired 356 ? QString("%1 (%2)").arg(m_strName, comMachine.GetName()) 357 : m_strName; 358 setText(Column_Name, strFinalName); 335 359 m_fOnline = m_comSnapshot.GetOnline(); 336 360 setIcon(Column_Name, *m_pSnapshotWidget->snapshotItemIcon(m_fOnline)); … … 505 529 , m_pActionPool(pActionPool) 506 530 , m_fShowToolbar(fShowToolbar) 507 , m_enmSessionState(KSessionState_Null)508 , m_fShapshotOperationsAllowed(false)509 531 , m_pLockReadWrite(0) 510 532 , m_pIconSnapshotOffline(0) … … 514 536 , m_pToolBar(0) 515 537 , m_pSnapshotTree(0) 516 , m_pCurrentSnapshotItem(0)517 , m_pCurrentStateItem(0)518 538 , m_pDetailsWidget(0) 519 539 { … … 528 548 void UISnapshotPane::setMachineItems(const QList<UIVirtualMachineItem*> &items) 529 549 { 530 /* Cache passed machine: */ 531 m_comMachine = items.isEmpty() ? CMachine() : items.first()->toLocal()->machine(); 532 533 /* Cache machine details: */ 534 if (m_comMachine.isNull()) 535 { 536 m_uMachineId = QUuid(); 537 m_enmSessionState = KSessionState_Null; 538 m_fShapshotOperationsAllowed = false; 539 } 540 else 541 { 542 m_uMachineId = m_comMachine.GetId(); 543 m_enmSessionState = m_comMachine.GetSessionState(); 544 m_fShapshotOperationsAllowed = gEDataManager->machineSnapshotOperationsEnabled(m_uMachineId); 550 /* Wipe out old stuff: */ 551 m_machines.clear(); 552 m_sessionStates.clear(); 553 m_operationAllowed.clear(); 554 555 /* For each machine item: */ 556 foreach (UIVirtualMachineItem *pItem, items) 557 { 558 /* Parse machine details: */ 559 AssertPtrReturnVoid(pItem); 560 CMachine comMachine = pItem->toLocal()->machine(); 561 562 /* Cache passed machine: */ 563 if (!comMachine.isNull()) 564 { 565 const QUuid uMachineId = comMachine.GetId(); 566 const KSessionState enmSessionState = comMachine.GetSessionState(); 567 const bool fAllowance = gEDataManager->machineSnapshotOperationsEnabled(uMachineId); 568 m_machines[uMachineId] = comMachine; 569 m_sessionStates[uMachineId] = enmSessionState; 570 m_operationAllowed[uMachineId] = fAllowance; 571 } 545 572 } 546 573 … … 556 583 bool UISnapshotPane::isCurrentStateItemSelected() const 557 584 { 558 return m_pCurrentStateItem && m_pSnapshotTree->currentItem() == m_pCurrentStateItem; 585 UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem()); 586 return m_currentStateItems.values().contains(pSnapshotItem); 559 587 } 560 588 … … 606 634 { 607 635 /* Make sure it's our VM: */ 608 if ( uMachineId != m_uMachineId)636 if (!m_machines.keys().contains(uMachineId)) 609 637 return; 610 638 … … 613 641 614 642 /* Recache "current state" item data: */ 615 m_ pCurrentStateItem->recache();643 m_currentStateItems.value(uMachineId)->recache(); 616 644 617 645 /* Choose current item again (to update details-widget): */ … … 622 650 { 623 651 /* Make sure it's our VM: */ 624 if ( uMachineId != m_uMachineId)652 if (!m_machines.keys().contains(uMachineId)) 625 653 return; 626 654 … … 629 657 630 658 /* Recache "current state" item data and machine-state: */ 631 m_ pCurrentStateItem->recache();632 m_ pCurrentStateItem->setMachineState(enmState);659 m_currentStateItems.value(uMachineId)->recache(); 660 m_currentStateItems.value(uMachineId)->setMachineState(enmState); 633 661 } 634 662 … … 636 664 { 637 665 /* Make sure it's our VM: */ 638 if ( uMachineId != m_uMachineId)666 if (!m_machines.keys().contains(uMachineId)) 639 667 return; 640 668 … … 643 671 644 672 /* Recache current session-state: */ 645 m_ enmSessionState= enmState;673 m_sessionStates[uMachineId] = enmState; 646 674 647 675 /* Update action states: */ … … 652 680 { 653 681 /* Make sure it's our VM: */ 654 if ( uMachineId != m_uMachineId)682 if (!m_machines.keys().contains(uMachineId)) 655 683 return; 656 684 … … 664 692 QWriteLocker locker(m_pLockReadWrite); 665 693 694 /* Acquire corresponding machine: */ 695 CMachine comMachine = m_machines.value(uMachineId); 696 666 697 /* Search for corresponding snapshot: */ 667 CSnapshot comSnapshot = m_comMachine.FindSnapshot(uSnapshotId.toString());668 fSuccess = m_comMachine.isOk() && !comSnapshot.isNull();698 CSnapshot comSnapshot = comMachine.FindSnapshot(uSnapshotId.toString()); 699 fSuccess = comMachine.isOk() && !comSnapshot.isNull(); 669 700 670 701 /* Show error message if necessary: */ 671 702 if (!fSuccess) 672 UINotificationMessage::cannotFindSnapshotById( m_comMachine, uSnapshotId);703 UINotificationMessage::cannotFindSnapshotById(comMachine, uSnapshotId); 673 704 else 674 705 { … … 697 728 /* Make sure this parent-item is a parent of "current state" item as well: */ 698 729 if (fSuccess) 699 fSuccess = qobject_cast<UISnapshotItem*>(m_ pCurrentStateItem->parentItem()) == pParentItem;730 fSuccess = qobject_cast<UISnapshotItem*>(m_currentStateItems.value(uMachineId)->parentItem()) == pParentItem; 700 731 /* Make sure this parent-item is a "current snapshot" item as well: */ 701 732 if (fSuccess) 702 fSuccess = m_ pCurrentSnapshotItem== pParentItem;733 fSuccess = m_currentSnapshotItems.value(uMachineId) == pParentItem; 703 734 704 735 /* Create new item: */ … … 706 737 { 707 738 /* Delete "current state" item first of all: */ 708 UISnapshotItem *pCurrentStateItem = m_ pCurrentStateItem;709 m_ pCurrentStateItem= 0;739 UISnapshotItem *pCurrentStateItem = m_currentStateItems.value(uMachineId); 740 m_currentStateItems[uMachineId] = 0; 710 741 delete pCurrentStateItem; 711 742 pCurrentStateItem = 0; 712 743 713 744 /* Create "current snapshot" item for a newly taken snapshot: */ 714 if (m_pCurrentSnapshotItem) 715 m_pCurrentSnapshotItem->setCurrentSnapshotItem(false); 716 m_pCurrentSnapshotItem = pParentItem 717 ? new UISnapshotItem(this, pParentItem, comSnapshot) 718 : new UISnapshotItem(this, m_pSnapshotTree, comSnapshot); 719 /* Mark it as editable: */ 720 m_pCurrentSnapshotItem->setFlags(m_pCurrentSnapshotItem->flags() | Qt::ItemIsEditable); 745 if (m_currentSnapshotItems.value(uMachineId)) 746 m_currentSnapshotItems.value(uMachineId)->setCurrentSnapshotItem(false); 747 m_currentSnapshotItems[uMachineId] = pParentItem 748 ? new UISnapshotItem(this, pParentItem, comSnapshot) 749 : new UISnapshotItem(this, m_pSnapshotTree, comSnapshot, m_machines.size() > 1); 721 750 /* Mark it as current: */ 722 m_ pCurrentSnapshotItem->setCurrentSnapshotItem(true);751 m_currentSnapshotItems.value(uMachineId)->setCurrentSnapshotItem(true); 723 752 /* And recache it's content: */ 724 m_ pCurrentSnapshotItem->recache();753 m_currentSnapshotItems.value(uMachineId)->recache(); 725 754 726 755 /* Create "current state" item as a child of "current snapshot" item: */ 727 m_ pCurrentStateItem = new UISnapshotItem(this, m_pCurrentSnapshotItem, m_comMachine);756 m_currentStateItems[uMachineId] = new UISnapshotItem(this, m_currentSnapshotItems.value(uMachineId), comMachine); 728 757 /* Recache it's content: */ 729 m_ pCurrentStateItem->recache();758 m_currentStateItems.value(uMachineId)->recache(); 730 759 /* And choose is as current one: */ 731 m_pSnapshotTree->setCurrentItem(m_ pCurrentStateItem);760 m_pSnapshotTree->setCurrentItem(m_currentStateItems.value(uMachineId)); 732 761 sltHandleCurrentItemChange(); 733 762 … … 748 777 { 749 778 /* Make sure it's our VM: */ 750 if ( uMachineId != m_uMachineId)779 if (!m_machines.keys().contains(uMachineId)) 751 780 return; 752 781 … … 806 835 if (fSuccess) 807 836 { 808 if (pItem == m_ pCurrentSnapshotItem)837 if (pItem == m_currentSnapshotItems.value(uMachineId)) 809 838 { 810 m_ pCurrentSnapshotItem= UISnapshotItem::toSnapshotItem(pParent);811 if (m_ pCurrentSnapshotItem)812 m_ pCurrentSnapshotItem->setCurrentSnapshotItem(true);839 m_currentSnapshotItems[uMachineId] = UISnapshotItem::toSnapshotItem(pParent); 840 if (m_currentSnapshotItems.value(uMachineId)) 841 m_currentSnapshotItems.value(uMachineId)->setCurrentSnapshotItem(true); 813 842 } 814 843 delete pItem; … … 830 859 { 831 860 /* Make sure it's our VM: */ 832 if ( uMachineId != m_uMachineId)861 if (!m_machines.keys().contains(uMachineId)) 833 862 return; 834 863 … … 870 899 { 871 900 /* Make sure it's our VM: */ 872 if ( uMachineId != m_uMachineId)901 if (!m_machines.keys().contains(uMachineId)) 873 902 return; 874 903 … … 890 919 { 891 920 /* Delete "current state" item first of all: */ 892 UISnapshotItem *pCurrentStateItem = m_ pCurrentStateItem;893 m_ pCurrentStateItem= 0;921 UISnapshotItem *pCurrentStateItem = m_currentStateItems.value(uMachineId); 922 m_currentStateItems[uMachineId] = 0; 894 923 delete pCurrentStateItem; 895 924 pCurrentStateItem = 0; 896 925 897 926 /* Move the "current snapshot" token from one to another: */ 898 AssertPtrReturnVoid(m_ pCurrentSnapshotItem);899 m_ pCurrentSnapshotItem->setCurrentSnapshotItem(false);900 m_ pCurrentSnapshotItem= pItem;901 m_ pCurrentSnapshotItem->setCurrentSnapshotItem(true);927 AssertPtrReturnVoid(m_currentSnapshotItems.value(uMachineId)); 928 m_currentSnapshotItems.value(uMachineId)->setCurrentSnapshotItem(false); 929 m_currentSnapshotItems[uMachineId] = pItem; 930 m_currentSnapshotItems.value(uMachineId)->setCurrentSnapshotItem(true); 902 931 903 932 /* Create "current state" item as a child of "current snapshot" item: */ 904 m_ pCurrentStateItem = new UISnapshotItem(this, m_pCurrentSnapshotItem, m_comMachine);905 m_ pCurrentStateItem->recache();933 m_currentStateItems[uMachineId] = new UISnapshotItem(this, m_currentSnapshotItems.value(uMachineId), m_machines.value(uMachineId)); 934 m_currentStateItems.value(uMachineId)->recache(); 906 935 /* And choose is as current one: */ 907 m_pSnapshotTree->setCurrentItem(m_ pCurrentStateItem);936 m_pSnapshotTree->setCurrentItem(m_currentStateItems.value(uMachineId)); 908 937 sltHandleCurrentItemChange(); 909 938 … … 957 986 if (pSnapshotItem->isCurrentStateItem()) 958 987 { 959 if (m_ comMachine.isNull())988 if (m_machines.value(pSnapshotItem->machineID()).isNull()) 960 989 m_pDetailsWidget->clearData(); 961 990 else 962 m_pDetailsWidget->setData(m_ comMachine);991 m_pDetailsWidget->setData(m_machines.value(pSnapshotItem->machineID())); 963 992 } 964 993 else … … 983 1012 984 1013 /* Take snapshot: */ 985 UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(m_ comMachine,1014 UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(m_machines.value(pSnapshotItem->machineID()), 986 1015 newData.name(), 987 1016 newData.description()); … … 1006 1035 /* Open a session (this call will handle all errors): */ 1007 1036 CSession comSession; 1008 if (m_ enmSessionState!= KSessionState_Unlocked)1009 comSession = uiCommon().openExistingSession( m_uMachineId);1037 if (m_sessionStates.value(pSnapshotItem->machineID()) != KSessionState_Unlocked) 1038 comSession = uiCommon().openExistingSession(pSnapshotItem->machineID()); 1010 1039 else 1011 comSession = uiCommon().openSession( m_uMachineId);1040 comSession = uiCommon().openSession(pSnapshotItem->machineID()); 1012 1041 if (comSession.isNotNull()) 1013 1042 { … … 1075 1104 if (pSnapshotItem->isCurrentStateItem()) 1076 1105 { 1077 if (m_comMachine.isNull()) 1106 CMachine comMachine = m_machines.value(pSnapshotItem->machineID()); 1107 if (comMachine.isNull()) 1078 1108 m_pDetailsWidget->clearData(); 1079 1109 else 1080 m_pDetailsWidget->setData( m_comMachine);1110 m_pDetailsWidget->setData(comMachine); 1081 1111 } 1082 1112 else … … 1105 1135 QMenu menu; 1106 1136 /* For snapshot item: */ 1107 if (m_ pCurrentSnapshotItem&& !pSnapshotItem->isCurrentStateItem())1137 if (m_currentSnapshotItems.value(pSnapshotItem->machineID()) && !pSnapshotItem->isCurrentStateItem()) 1108 1138 { 1109 1139 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Delete)); … … 1375 1405 QWriteLocker locker(m_pLockReadWrite); 1376 1406 1377 /* If VM is null, just updated the current item: */1378 if (m_ comMachine.isNull())1407 /* If VM list is empty, just updated the current item: */ 1408 if (m_machines.isEmpty()) 1379 1409 { 1380 1410 /* Clear the tree: */ … … 1396 1426 m_pSnapshotTree->clear(); 1397 1427 1398 /* If machine has snapshots: */ 1399 if (m_comMachine.GetSnapshotCount() > 0) 1400 { 1401 /* Get the first snapshot: */ 1402 const CSnapshot comSnapshot = m_comMachine.FindSnapshot(QString()); 1403 1404 /* Populate snapshot tree: */ 1405 populateSnapshots(comSnapshot, 0); 1406 /* And make sure it has "current snapshot" item: */ 1407 Assert(m_pCurrentSnapshotItem); 1408 1409 /* Add the "current state" item as a child to "current snapshot" item: */ 1410 m_pCurrentStateItem = new UISnapshotItem(this, m_pCurrentSnapshotItem, m_comMachine); 1411 m_pCurrentStateItem->recache(); 1412 1413 /* Search for a previously selected item: */ 1414 UISnapshotItem *pCurrentItem = findItem(uSelectedItem); 1415 if (pCurrentItem == 0) 1416 pCurrentItem = findItem(uFirstChildOfSelectedItem); 1417 if (pCurrentItem == 0) 1418 pCurrentItem = m_pCurrentStateItem; 1419 1420 /* Choose current item: */ 1421 m_pSnapshotTree->scrollToItem(pCurrentItem); 1422 m_pSnapshotTree->setCurrentItem(pCurrentItem); 1423 sltHandleCurrentItemChange(); 1424 } 1425 /* If machine has no snapshots: */ 1426 else 1427 { 1428 /* There is no "current snapshot" item: */ 1429 m_pCurrentSnapshotItem = 0; 1430 1431 /* Add the "current state" item as a child of snapshot tree: */ 1432 m_pCurrentStateItem = new UISnapshotItem(this, m_pSnapshotTree, m_comMachine); 1433 m_pCurrentStateItem->recache(); 1434 1435 /* Choose current item: */ 1436 m_pSnapshotTree->setCurrentItem(m_pCurrentStateItem); 1437 sltHandleCurrentItemChange(); 1428 /* Iterates over all the machines: */ 1429 foreach (const QUuid &uMachineId, m_machines.keys()) 1430 { 1431 CMachine comMachine = m_machines.value(uMachineId); 1432 1433 /* If machine has snapshots: */ 1434 if (comMachine.GetSnapshotCount() > 0) 1435 { 1436 /* Get the first snapshot: */ 1437 const CSnapshot comSnapshot = comMachine.FindSnapshot(QString()); 1438 1439 /* Populate snapshot tree: */ 1440 populateSnapshots(uMachineId, comSnapshot, 0); 1441 /* And make sure it has "current snapshot" item: */ 1442 Assert(m_currentSnapshotItems.value(uMachineId)); 1443 1444 /* Add the "current state" item as a child to "current snapshot" item: */ 1445 m_currentStateItems[uMachineId] = new UISnapshotItem(this, m_currentSnapshotItems.value(uMachineId), comMachine); 1446 m_currentStateItems.value(uMachineId)->recache(); 1447 1448 /* Search for a previously selected item: */ 1449 UISnapshotItem *pCurrentItem = findItem(uSelectedItem); 1450 if (pCurrentItem == 0) 1451 pCurrentItem = findItem(uFirstChildOfSelectedItem); 1452 if (pCurrentItem == 0) 1453 pCurrentItem = m_currentStateItems.value(uMachineId); 1454 1455 /* Choose current item: */ 1456 m_pSnapshotTree->scrollToItem(pCurrentItem); 1457 m_pSnapshotTree->setCurrentItem(pCurrentItem); 1458 sltHandleCurrentItemChange(); 1459 } 1460 /* If machine has no snapshots: */ 1461 else 1462 { 1463 /* There is no "current snapshot" item: */ 1464 m_currentSnapshotItems[uMachineId] = 0; 1465 1466 /* Add the "current state" item as a child of snapshot tree: */ 1467 m_currentStateItems[uMachineId] = new UISnapshotItem(this, m_pSnapshotTree, comMachine, m_machines.size() > 1); 1468 m_currentStateItems.value(uMachineId)->recache(); 1469 1470 /* Choose current item: */ 1471 m_pSnapshotTree->setCurrentItem(m_currentStateItems.value(uMachineId)); 1472 sltHandleCurrentItemChange(); 1473 } 1438 1474 } 1439 1475 … … 1445 1481 } 1446 1482 1447 void UISnapshotPane::populateSnapshots(const CSnapshot &comSnapshot, QITreeWidgetItem *pItem)1483 void UISnapshotPane::populateSnapshots(const QUuid &uMachineId, const CSnapshot &comSnapshot, QITreeWidgetItem *pItem) 1448 1484 { 1449 1485 /* Create a child of passed item: */ 1450 1486 UISnapshotItem *pSnapshotItem = pItem ? new UISnapshotItem(this, pItem, comSnapshot) 1451 : new UISnapshotItem(this, m_pSnapshotTree, comSnapshot );1487 : new UISnapshotItem(this, m_pSnapshotTree, comSnapshot, m_machines.size() > 1); 1452 1488 /* And recache it's content: */ 1453 1489 pSnapshotItem->recache(); 1454 1490 1455 1491 /* Mark snapshot item as "current" and remember it: */ 1456 CSnapshot comCurrentSnapshot = m_ comMachine.GetCurrentSnapshot();1492 CSnapshot comCurrentSnapshot = m_machines.value(uMachineId).GetCurrentSnapshot(); 1457 1493 if (!comCurrentSnapshot.isNull() && comCurrentSnapshot.GetId() == comSnapshot.GetId()) 1458 1494 { 1459 1495 pSnapshotItem->setCurrentSnapshotItem(true); 1460 m_ pCurrentSnapshotItem= pSnapshotItem;1496 m_currentSnapshotItems[uMachineId] = pSnapshotItem; 1461 1497 } 1462 1498 1463 1499 /* Walk through the children recursively: */ 1464 1500 foreach (const CSnapshot &comIteratedSnapshot, comSnapshot.GetChildren()) 1465 populateSnapshots( comIteratedSnapshot, pSnapshotItem);1501 populateSnapshots(uMachineId, comIteratedSnapshot, pSnapshotItem); 1466 1502 1467 1503 /* Expand the newly created item: */ 1468 1504 pSnapshotItem->setExpanded(true); 1469 /* And mark it as editable: */1470 pSnapshotItem->setFlags(pSnapshotItem->flags() | Qt::ItemIsEditable);1471 1505 } 1472 1506 … … 1497 1531 1498 1532 /* Check whether another direct session is opened: */ 1499 const bool fBusy = m_enmSessionState!= KSessionState_Unlocked;1533 const bool fBusy = !pSnapshotItem || m_sessionStates.value(pSnapshotItem->machineID()) != KSessionState_Unlocked; 1500 1534 1501 1535 /* Acquire machine-state of the "current state" item: */ 1502 1536 KMachineState enmState = KMachineState_Null; 1503 if (m_pCurrentStateItem) 1504 enmState = m_pCurrentStateItem->machineState(); 1537 if ( pSnapshotItem 1538 && m_currentStateItems.value(pSnapshotItem->machineID())) 1539 enmState = m_currentStateItems.value(pSnapshotItem->machineID())->machineState(); 1505 1540 1506 1541 /* Determine whether taking or deleting snapshots is possible: */ … … 1515 1550 /* Update 'Take' action: */ 1516 1551 m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Take)->setEnabled( 1517 m_fShapshotOperationsAllowed 1552 pSnapshotItem 1553 && m_operationAllowed.value(pSnapshotItem->machineID()) 1518 1554 && ( ( fCanTakeDeleteSnapshot 1519 && m_pCurrentSnapshotItem 1520 && pSnapshotItem 1555 && m_currentSnapshotItems.value(pSnapshotItem->machineID()) 1521 1556 && pSnapshotItem->isCurrentStateItem()) 1522 || ( pSnapshotItem 1523 && !m_pCurrentSnapshotItem)) 1557 || (!m_currentSnapshotItems.value(pSnapshotItem->machineID()))) 1524 1558 ); 1525 1559 1526 1560 /* Update 'Delete' action: */ 1527 1561 m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Delete)->setEnabled( 1528 m_fShapshotOperationsAllowed 1562 pSnapshotItem 1563 && m_operationAllowed.value(pSnapshotItem->machineID()) 1529 1564 && fCanTakeDeleteSnapshot 1530 && m_ pCurrentSnapshotItem1565 && m_currentSnapshotItems.value(pSnapshotItem->machineID()) 1531 1566 && pSnapshotItem 1532 1567 && !pSnapshotItem->isCurrentStateItem() … … 1536 1571 m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Restore)->setEnabled( 1537 1572 !fBusy 1538 && m_pCurrentSnapshotItem1539 1573 && pSnapshotItem 1574 && m_currentSnapshotItems.value(pSnapshotItem->machineID()) 1540 1575 && !pSnapshotItem->isCurrentStateItem() 1541 1576 ); … … 1556 1591 bool UISnapshotPane::takeSnapshot(bool fAutomatically /* = false */) 1557 1592 { 1593 /* Acquire "current snapshot" item: */ 1594 const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem()); 1595 AssertPtrReturn(pSnapshotItem, false); 1596 1597 /* Acquire machine: */ 1598 const CMachine comMachine = m_machines.value(pSnapshotItem->machineID()); 1599 1558 1600 /* Search for a maximum existing snapshot index: */ 1559 1601 int iMaximumIndex = 0; … … 1581 1623 /* Create take-snapshot dialog: */ 1582 1624 QWidget *pDlgParent = windowManager().realParentWindow(this); 1583 QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, m_comMachine);1625 QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, comMachine); 1584 1626 windowManager().registerNewParent(pDlg, pDlgParent); 1585 1627 1586 1628 /* Assign corresponding icon: */ 1587 QIcon icon = generalIconPool().userMachineIcon( m_comMachine);1629 QIcon icon = generalIconPool().userMachineIcon(comMachine); 1588 1630 if (icon.isNull()) 1589 icon = generalIconPool().guestOSTypeIcon( m_comMachine.GetOSTypeId());1631 icon = generalIconPool().guestOSTypeIcon(comMachine.GetOSTypeId()); 1590 1632 pDlg->setIcon(icon); 1591 1633 … … 1610 1652 1611 1653 /* Take snapshot: */ 1612 UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake( m_comMachine,1654 UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(comMachine, 1613 1655 strFinalName, 1614 1656 strFinalDescription); … … 1624 1666 const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem()); 1625 1667 AssertPtrReturn(pSnapshotItem, false); 1668 1669 /* Acquire machine: */ 1670 const CMachine comMachine = m_machines.value(pSnapshotItem->machineID()); 1626 1671 1627 1672 /* Get corresponding snapshot: */ … … 1643 1688 1644 1689 /* Delete snapshot: */ 1645 UINotificationProgressSnapshotDelete *pNotification = new UINotificationProgressSnapshotDelete( m_comMachine,1690 UINotificationProgressSnapshotDelete *pNotification = new UINotificationProgressSnapshotDelete(comMachine, 1646 1691 pSnapshotItem->snapshotID()); 1647 1692 gpNotificationCenter->append(pNotification); … … 1657 1702 AssertPtrReturn(pSnapshotItem, false); 1658 1703 1704 /* Acquire machine: */ 1705 const CMachine comMachine = m_machines.value(pSnapshotItem->machineID()); 1706 1659 1707 /* Get corresponding snapshot: */ 1660 1708 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); … … 1662 1710 1663 1711 /* In manual mode we should check whether current state is changed: */ 1664 if (!fAutomatically && m_comMachine.GetCurrentStateModified())1712 if (!fAutomatically && comMachine.GetCurrentStateModified()) 1665 1713 { 1666 1714 /* Ask if user really wants to restore the selected snapshot: */ 1667 int iResultCode = msgCenter().confirmSnapshotRestoring(comSnapshot.GetName(), m_comMachine.GetCurrentStateModified());1715 int iResultCode = msgCenter().confirmSnapshotRestoring(comSnapshot.GetName(), comMachine.GetCurrentStateModified()); 1668 1716 if (iResultCode & AlertButton_Cancel) 1669 1717 return false; … … 1673 1721 { 1674 1722 /* Take snapshot of changed current state: */ 1675 m_pSnapshotTree->setCurrentItem(m_ pCurrentStateItem);1723 m_pSnapshotTree->setCurrentItem(m_currentStateItems.value(pSnapshotItem->machineID())); 1676 1724 if (!takeSnapshot()) 1677 1725 return false; … … 1680 1728 1681 1729 /* Restore snapshot: */ 1682 UINotificationProgressSnapshotRestore *pNotification = new UINotificationProgressSnapshotRestore( m_comMachine, comSnapshot);1730 UINotificationProgressSnapshotRestore *pNotification = new UINotificationProgressSnapshotRestore(comMachine, comSnapshot); 1683 1731 gpNotificationCenter->append(pNotification); 1684 1732 -
trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h
r96635 r96660 185 185 void refreshAll(); 186 186 /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */ 187 void populateSnapshots(const CSnapshot &comSnapshot, QITreeWidgetItem *pItem);187 void populateSnapshots(const QUuid &uMachineId, const CSnapshot &comSnapshot, QITreeWidgetItem *pItem); 188 188 189 189 /** Cleanups all. */ … … 224 224 * @{ */ 225 225 /** Holds the action-pool reference. */ 226 UIActionPool 226 UIActionPool *m_pActionPool; 227 227 /** Holds whether we should show toolbar. */ 228 bool m_fShowToolbar; 229 /** Holds the COM machine object. */ 230 CMachine m_comMachine; 231 /** Holds the machine object ID. */ 232 QUuid m_uMachineId; 233 /** Holds the cached session state. */ 234 KSessionState m_enmSessionState; 235 236 /** Holds whether the snapshot operations are allowed. */ 237 bool m_fShapshotOperationsAllowed; 228 bool m_fShowToolbar; 229 230 /** Holds the COM machine object list. */ 231 QMap<QUuid, CMachine> m_machines; 232 /** Holds the cached session state list. */ 233 QMap<QUuid, KSessionState> m_sessionStates; 234 /** Holds the list of operation allowance states. */ 235 QMap<QUuid, bool> m_operationAllowed; 238 236 239 237 /** Holds the snapshot item editing protector. */ … … 259 257 /** Holds the snapshot tree instance. */ 260 258 UISnapshotTree *m_pSnapshotTree; 261 /** Holds the "current snapshot" item reference. */ 262 UISnapshotItem *m_pCurrentSnapshotItem; 263 /** Holds the "current state" item reference. */ 264 UISnapshotItem *m_pCurrentStateItem; 259 260 /** Holds the "current snapshot" item list. */ 261 QMap<QUuid, UISnapshotItem*> m_currentSnapshotItems; 262 /** Holds the "current state" item list. */ 263 QMap<QUuid, UISnapshotItem*> m_currentStateItems; 265 264 266 265 /** Holds the details-widget instance. */
Note:
See TracChangeset
for help on using the changeset viewer.