Changeset 90457 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Aug 1, 2021 1:11:31 PM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.cpp
r90456 r90457 26 26 /* COM includes: */ 27 27 #include "CConsole.h" 28 #include "CSnapshot.h"29 28 30 29 … … 1053 1052 1054 1053 /********************************************************************************************************************************* 1054 * Class UINotificationProgressSnapshotRestore implementation. * 1055 *********************************************************************************************************************************/ 1056 1057 UINotificationProgressSnapshotRestore::UINotificationProgressSnapshotRestore(const CMachine &comMachine, 1058 const CSnapshot &comSnapshot) 1059 : m_comMachine(comMachine) 1060 , m_comSnapshot(comSnapshot) 1061 { 1062 connect(this, &UINotificationProgress::sigProgressFinished, 1063 this, &UINotificationProgressSnapshotRestore::sltHandleProgressFinished); 1064 } 1065 1066 QString UINotificationProgressSnapshotRestore::name() const 1067 { 1068 return UINotificationProgress::tr("Restoring snapshot ..."); 1069 } 1070 1071 QString UINotificationProgressSnapshotRestore::details() const 1072 { 1073 return UINotificationProgress::tr("<b>VM Name:</b> %1<br><b>Snapshot Name:</b> %2").arg(m_strMachineName, m_strSnapshotName); 1074 } 1075 1076 CProgress UINotificationProgressSnapshotRestore::createProgress(COMResult &comResult) 1077 { 1078 /* Acquire VM id: */ 1079 const QUuid uId = m_comMachine.GetId(); 1080 if (!m_comMachine.isOk()) 1081 { 1082 comResult = m_comMachine; 1083 return CProgress(); 1084 } 1085 1086 /* Acquire VM name: */ 1087 m_strMachineName = m_comMachine.GetName(); 1088 if (!m_comMachine.isOk()) 1089 { 1090 comResult = m_comMachine; 1091 return CProgress(); 1092 } 1093 1094 /* Acquire snapshot name: */ 1095 m_strSnapshotName = m_comSnapshot.GetName(); 1096 if (!m_comSnapshot.isOk()) 1097 { 1098 comResult = m_comSnapshot; 1099 return CProgress(); 1100 } 1101 1102 /* Acquire session state: */ 1103 const KSessionState enmSessionState = m_comMachine.GetSessionState(); 1104 if (!m_comMachine.isOk()) 1105 { 1106 comResult = m_comMachine; 1107 return CProgress(); 1108 } 1109 1110 /* Open a session thru which we will modify the machine: */ 1111 if (enmSessionState != KSessionState_Unlocked) 1112 m_comSession = uiCommon().openExistingSession(uId); 1113 else 1114 m_comSession = uiCommon().openSession(uId); 1115 if (m_comSession.isNull()) 1116 return CProgress(); 1117 1118 /* Get session machine: */ 1119 CMachine comMachine = m_comSession.GetMachine(); 1120 if (!m_comSession.isOk()) 1121 { 1122 comResult = m_comSession; 1123 m_comSession.UnlockMachine(); 1124 return CProgress(); 1125 } 1126 1127 /* Initialize progress-wrapper: */ 1128 CProgress comProgress = comMachine.RestoreSnapshot(m_comSnapshot); 1129 /* Store COM result: */ 1130 comResult = m_comMachine; 1131 /* Return progress-wrapper: */ 1132 return comProgress; 1133 } 1134 1135 void UINotificationProgressSnapshotRestore::sltHandleProgressFinished() 1136 { 1137 m_comSession.UnlockMachine(); 1138 } 1139 1140 1141 /********************************************************************************************************************************* 1055 1142 * Class UINotificationProgressSnapshotDelete implementation. * 1056 1143 *********************************************************************************************************************************/ -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h
r90456 r90457 38 38 #include "CMedium.h" 39 39 #include "CSession.h" 40 #include "CSnapshot.h" 40 41 #include "CVirtualSystemDescription.h" 41 42 … … 787 788 }; 788 789 790 /** UINotificationProgress extension for snapshot restore functionality. */ 791 class SHARED_LIBRARY_STUFF UINotificationProgressSnapshotRestore : public UINotificationProgress 792 { 793 Q_OBJECT; 794 795 public: 796 797 /** Constructs snapshot restore notification-progress. 798 * @param comMachine Brings the machine we are restoring snapshot for. 799 * @param comSnapshot Brings the snapshot being restored. */ 800 UINotificationProgressSnapshotRestore(const CMachine &comMachine, 801 const CSnapshot &comSnapshot); 802 803 protected: 804 805 /** Returns object name. */ 806 virtual QString name() const /* override final */; 807 /** Returns object details. */ 808 virtual QString details() const /* override final */; 809 /** Creates and returns started progress-wrapper. */ 810 virtual CProgress createProgress(COMResult &comResult) /* override final */; 811 812 private slots: 813 814 /** Handles signal about progress being finished. */ 815 void sltHandleProgressFinished(); 816 817 private: 818 819 /** Holds the machine we are restoring snapshot for. */ 820 CMachine m_comMachine; 821 /** Holds the snapshot being restored. */ 822 CSnapshot m_comSnapshot; 823 /** Holds the machine name. */ 824 QString m_strMachineName; 825 /** Holds the snapshot name. */ 826 QString m_strSnapshotName; 827 /** Holds the session being opened. */ 828 CSession m_comSession; 829 }; 830 789 831 /** UINotificationProgress extension for snapshot delete functionality. */ 790 832 class SHARED_LIBRARY_STUFF UINotificationProgressSnapshotDelete : public UINotificationProgress -
trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp
r90456 r90457 1612 1612 bool UISnapshotPane::restoreSnapshot(bool fAutomatically /* = false */) 1613 1613 { 1614 /* Simulate try-catch block: */1615 bool fSuccess = false;1616 do1617 { 1618 /* Acquire "current snapshot" item: */1619 const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());1620 AssertPtr(pSnapshotItem);1621 if (!pSnapshotItem) 1622 break;1623 1624 /* Get corresponding snapshot: */1625 const CSnapshot comSnapshot = pSnapshotItem->snapshot();1626 Assert(!comSnapshot.isNull());1627 if ( comSnapshot.isNull())1628 break;1629 1630 /* In manual mode we should check whether current stateis changed: */1631 if ( !fAutomatically && m_comMachine.GetCurrentStateModified())1614 /* Acquire "current snapshot" item: */ 1615 const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem()); 1616 AssertPtrReturn(pSnapshotItem, false); 1617 1618 /* Get corresponding snapshot: */ 1619 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 1620 AssertReturn(!comSnapshot.isNull(), false); 1621 1622 /* In manual mode we should check whether current state is changed: */ 1623 if (!fAutomatically && m_comMachine.GetCurrentStateModified()) 1624 { 1625 /* Ask if user really wants to restore the selected snapshot: */ 1626 int iResultCode = msgCenter().confirmSnapshotRestoring(comSnapshot.GetName(), m_comMachine.GetCurrentStateModified()); 1627 if (iResultCode & AlertButton_Cancel) 1628 return false; 1629 1630 /* Ask if user also wants to create new snapshot of current state which is changed: */ 1631 if (iResultCode & AlertOption_CheckBox) 1632 1632 { 1633 /* Ask if user really wants to restore the selected snapshot: */ 1634 int iResultCode = msgCenter().confirmSnapshotRestoring(comSnapshot.GetName(), m_comMachine.GetCurrentStateModified()); 1635 if (iResultCode & AlertButton_Cancel) 1636 break; 1637 1638 /* Ask if user also wants to create new snapshot of current state which is changed: */ 1639 if (iResultCode & AlertOption_CheckBox) 1640 { 1641 /* Take snapshot of changed current state: */ 1642 m_pSnapshotTree->setCurrentItem(m_pCurrentStateItem); 1643 if (!takeSnapshot()) 1644 break; 1645 } 1633 /* Take snapshot of changed current state: */ 1634 m_pSnapshotTree->setCurrentItem(m_pCurrentStateItem); 1635 if (!takeSnapshot()) 1636 return false; 1646 1637 } 1647 1648 /* Open a direct session (this call will handle all errors): */ 1649 CSession comSession = uiCommon().openSession(m_uMachineId); 1650 if (comSession.isNull()) 1651 break; 1652 1653 /* Simulate try-catch block: */ 1654 do 1655 { 1656 /* Restore chosen snapshot: */ 1657 CMachine comMachine = comSession.GetMachine(); 1658 CProgress comProgress = comMachine.RestoreSnapshot(comSnapshot); 1659 if (!comMachine.isOk()) 1660 { 1661 msgCenter().cannotRestoreSnapshot(comMachine, comSnapshot.GetName(), m_comMachine.GetName()); 1662 break; 1663 } 1664 1665 /* Show snapshot restoring progress: */ 1666 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_restore_90px.png"); 1667 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 1668 { 1669 msgCenter().cannotRestoreSnapshot(comProgress, comSnapshot.GetName(), m_comMachine.GetName()); 1670 break; 1671 } 1672 1673 /* Mark snapshot restoring successful: */ 1674 fSuccess = true; 1675 } 1676 while (0); 1677 1678 /* Cleanup try-catch block: */ 1679 comSession.UnlockMachine(); 1680 } 1681 while (0); 1682 1683 /* Adjust snapshot tree: */ 1684 adjustTreeWidget(); 1638 } 1639 1640 /* Restore snapshot: */ 1641 UINotificationProgressSnapshotRestore *pNotification = new UINotificationProgressSnapshotRestore(m_comMachine, comSnapshot); 1642 notificationCenter().append(pNotification); 1685 1643 1686 1644 /* Return result: */ 1687 return fSuccess;1645 return true; 1688 1646 } 1689 1647
Note:
See TracChangeset
for help on using the changeset viewer.