- Timestamp:
- Aug 1, 2021 11:45:11 AM (4 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
r90451 r90455 967 967 968 968 /********************************************************************************************************************************* 969 * Class UINotificationProgressSnapshotTake implementation. * 970 *********************************************************************************************************************************/ 971 972 UINotificationProgressSnapshotTake::UINotificationProgressSnapshotTake(const CMachine &comMachine, 973 const QString &strSnapshotName, 974 const QString &strSnapshotDescription) 975 : m_comMachine(comMachine) 976 , m_strSnapshotName(strSnapshotName) 977 , m_strSnapshotDescription(strSnapshotDescription) 978 { 979 connect(this, &UINotificationProgress::sigProgressFinished, 980 this, &UINotificationProgressSnapshotTake::sltHandleProgressFinished); 981 } 982 983 QString UINotificationProgressSnapshotTake::name() const 984 { 985 return UINotificationProgress::tr("Taking snapshot ..."); 986 } 987 988 QString UINotificationProgressSnapshotTake::details() const 989 { 990 return UINotificationProgress::tr("<b>VM Name:</b> %1<br><b>Snapshot Name:</b> %2").arg(m_strName, m_strSnapshotName); 991 } 992 993 CProgress UINotificationProgressSnapshotTake::createProgress(COMResult &comResult) 994 { 995 /* Acquire VM id: */ 996 const QUuid uId = m_comMachine.GetId(); 997 if (!m_comMachine.isOk()) 998 { 999 comResult = m_comMachine; 1000 return CProgress(); 1001 } 1002 1003 /* Acquire VM name: */ 1004 m_strName = m_comMachine.GetName(); 1005 if (!m_comMachine.isOk()) 1006 { 1007 comResult = m_comMachine; 1008 return CProgress(); 1009 } 1010 1011 /* Acquire session state: */ 1012 const KSessionState enmSessionState = m_comMachine.GetSessionState(); 1013 if (!m_comMachine.isOk()) 1014 { 1015 comResult = m_comMachine; 1016 return CProgress(); 1017 } 1018 1019 /* Open a session thru which we will modify the machine: */ 1020 if (enmSessionState != KSessionState_Unlocked) 1021 m_comSession = uiCommon().openExistingSession(uId); 1022 else 1023 m_comSession = uiCommon().openSession(uId); 1024 if (m_comSession.isNull()) 1025 return CProgress(); 1026 1027 /* Get session machine: */ 1028 CMachine comMachine = m_comSession.GetMachine(); 1029 if (!m_comSession.isOk()) 1030 { 1031 comResult = m_comSession; 1032 m_comSession.UnlockMachine(); 1033 return CProgress(); 1034 } 1035 1036 /* Initialize progress-wrapper: */ 1037 QUuid uSnapshotId; 1038 CProgress comProgress = comMachine.TakeSnapshot(m_strSnapshotName, 1039 m_strSnapshotDescription, 1040 true, uSnapshotId); 1041 /* Store COM result: */ 1042 comResult = m_comMachine; 1043 /* Return progress-wrapper: */ 1044 return comProgress; 1045 } 1046 1047 void UINotificationProgressSnapshotTake::sltHandleProgressFinished() 1048 { 1049 m_comSession.UnlockMachine(); 1050 } 1051 1052 1053 /********************************************************************************************************************************* 969 1054 * Class UINotificationProgressApplianceExport implementation. * 970 1055 *********************************************************************************************************************************/ -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h
r90425 r90455 295 295 public: 296 296 297 /** Constructs m ediummove notification-progress.297 /** Constructs machine move notification-progress. 298 298 * @param uId Brings the machine id. 299 299 * @param strDestination Brings the move destination. … … 744 744 }; 745 745 746 /** UINotificationProgress extension for snapshot take functionality. */ 747 class SHARED_LIBRARY_STUFF UINotificationProgressSnapshotTake : public UINotificationProgress 748 { 749 Q_OBJECT; 750 751 public: 752 753 /** Constructs snapshot take notification-progress. 754 * @param comMachine Brings the machine we are taking snapshot for. 755 * @param strSnapshotName Brings the name of snapshot being taken. 756 * @param strSnapshotDescription Brings the description of snapshot being taken. */ 757 UINotificationProgressSnapshotTake(const CMachine &comMachine, 758 const QString &strSnapshotName, 759 const QString &strSnapshotDescription); 760 761 protected: 762 763 /** Returns object name. */ 764 virtual QString name() const /* override final */; 765 /** Returns object details. */ 766 virtual QString details() const /* override final */; 767 /** Creates and returns started progress-wrapper. */ 768 virtual CProgress createProgress(COMResult &comResult) /* override final */; 769 770 private slots: 771 772 /** Handles signal about progress being finished. */ 773 void sltHandleProgressFinished(); 774 775 private: 776 777 /** Holds the machine we are taking snapshot for. */ 778 CMachine m_comMachine; 779 /** Holds the name of snapshot being taken. */ 780 QString m_strSnapshotName; 781 /** Holds the description of snapshot being taken. */ 782 QString m_strSnapshotDescription; 783 /** Holds the machine name. */ 784 QString m_strName; 785 /** Holds the session being opened. */ 786 CSession m_comSession; 787 }; 788 746 789 /** UINotificationProgress extension for export appliance functionality. */ 747 790 class SHARED_LIBRARY_STUFF UINotificationProgressApplianceExport : public UINotificationProgress -
trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp
r88684 r90455 39 39 #include "UIMessageCenter.h" 40 40 #include "UIModalWindowManager.h" 41 #include "UINotificationCenter.h" 41 42 #include "UISnapshotDetailsWidget.h" 42 43 #include "UISnapshotPane.h" … … 941 942 UIDataSnapshot newData = m_pDetailsWidget->data(); 942 943 943 /* Open a session (this call will handle all errors): */ 944 CSession comSession; 945 if (m_enmSessionState != KSessionState_Unlocked) 946 comSession = uiCommon().openExistingSession(m_uMachineId); 947 else 948 comSession = uiCommon().openSession(m_uMachineId); 949 if (comSession.isNotNull()) 950 { 951 /* Get corresponding machine object: */ 952 CMachine comMachine = comSession.GetMachine(); 953 954 /* Perform separate linked steps: */ 955 do 956 { 957 /* Take snapshot: */ 958 QUuid uSnapshotId; 959 CProgress comProgress = comMachine.TakeSnapshot(newData.m_strName, 960 newData.m_strDescription, 961 true, uSnapshotId); 962 if (!comMachine.isOk()) 963 { 964 msgCenter().cannotTakeSnapshot(comMachine, comMachine.GetName()); 965 break; 966 } 967 968 /* Show snapshot taking progress: */ 969 msgCenter().showModalProgressDialog(comProgress, comMachine.GetName(), 970 ":/progress_snapshot_create_90px.png"); 971 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 972 { 973 msgCenter().cannotTakeSnapshot(comProgress, comMachine.GetName()); 974 break; 975 } 976 } 977 while (0); 978 979 /* Cleanup session: */ 980 comSession.UnlockMachine(); 981 } 944 /* Take snapshot: */ 945 UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(m_comMachine, 946 newData.m_strName, 947 newData.m_strDescription); 948 notificationCenter().append(pNotification); 982 949 } 983 950 /* For snapshot items: */ … … 1548 1515 bool UISnapshotPane::takeSnapshot(bool fAutomatically /* = false */) 1549 1516 { 1550 /* Simulate try-catch block: */ 1551 bool fSuccess = false; 1552 do 1553 { 1554 /* Open a session (this call will handle all errors): */ 1555 CSession comSession; 1556 if (m_enmSessionState != KSessionState_Unlocked) 1557 comSession = uiCommon().openExistingSession(m_uMachineId); 1558 else 1559 comSession = uiCommon().openSession(m_uMachineId); 1560 if (comSession.isNull()) 1561 break; 1562 1563 /* Simulate try-catch block: */ 1564 do 1517 /* Search for a maximum existing snapshot index: */ 1518 int iMaximumIndex = 0; 1519 const QString strNameTemplate = tr("Snapshot %1"); 1520 const QRegExp reName(QString("^") + strNameTemplate.arg("([0-9]+)") + QString("$")); 1521 QTreeWidgetItemIterator iterator(m_pSnapshotTree); 1522 while (*iterator) 1523 { 1524 const QString strName = static_cast<UISnapshotItem*>(*iterator)->text(Column_Name); 1525 const int iPosition = reName.indexIn(strName); 1526 if (iPosition != -1) 1527 iMaximumIndex = reName.cap(1).toInt() > iMaximumIndex 1528 ? reName.cap(1).toInt() 1529 : iMaximumIndex; 1530 ++iterator; 1531 } 1532 1533 /* Prepare snapshot name/description: */ 1534 QString strFinalName = strNameTemplate.arg(iMaximumIndex + 1); 1535 QString strFinalDescription; 1536 1537 /* In manual mode we should show take snapshot dialog: */ 1538 if (!fAutomatically) 1539 { 1540 /* Create take-snapshot dialog: */ 1541 QWidget *pDlgParent = windowManager().realParentWindow(this); 1542 QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, m_comMachine); 1543 windowManager().registerNewParent(pDlg, pDlgParent); 1544 1545 /* Assign corresponding icon: */ 1546 QIcon icon = uiCommon().vmUserIcon(m_comMachine); 1547 if (icon.isNull()) 1548 icon = uiCommon().vmGuestOSTypeIcon(m_comMachine.GetOSTypeId()); 1549 pDlg->setIcon(icon); 1550 1551 /* Assign corresponding snapshot name: */ 1552 pDlg->setName(strFinalName); 1553 1554 /* Show Take Snapshot dialog: */ 1555 if (pDlg->exec() != QDialog::Accepted) 1565 1556 { 1566 /* Get corresponding machine object: */ 1567 CMachine comMachine = comSession.GetMachine(); 1568 1569 /* Search for a maximum available snapshot index: */ 1570 int iMaximumIndex = 0; 1571 const QString strNameTemplate = tr("Snapshot %1"); 1572 const QRegExp reName(QString("^") + strNameTemplate.arg("([0-9]+)") + QString("$")); 1573 QTreeWidgetItemIterator iterator(m_pSnapshotTree); 1574 while (*iterator) 1575 { 1576 const QString strName = static_cast<UISnapshotItem*>(*iterator)->text(Column_Name); 1577 const int iPosition = reName.indexIn(strName); 1578 if (iPosition != -1) 1579 iMaximumIndex = reName.cap(1).toInt() > iMaximumIndex 1580 ? reName.cap(1).toInt() 1581 : iMaximumIndex; 1582 ++iterator; 1583 } 1584 1585 /* Prepare final snapshot name/description: */ 1586 QString strFinalName = strNameTemplate.arg(iMaximumIndex + 1); 1587 QString strFinalDescription; 1588 1589 /* In manual mode we should show take snapshot dialog: */ 1590 if (!fAutomatically) 1591 { 1592 /* Create take-snapshot dialog: */ 1593 QWidget *pDlgParent = windowManager().realParentWindow(this); 1594 QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, comMachine); 1595 windowManager().registerNewParent(pDlg, pDlgParent); 1596 1597 /* Assign corresponding icon: */ 1598 QIcon icon = uiCommon().vmUserIcon(comMachine); 1599 if (icon.isNull()) 1600 icon = uiCommon().vmGuestOSTypeIcon(comMachine.GetOSTypeId()); 1601 pDlg->setIcon(icon); 1602 1603 /* Assign corresponding snapshot name: */ 1604 pDlg->setName(strFinalName); 1605 1606 /* Show Take Snapshot dialog: */ 1607 if (pDlg->exec() != QDialog::Accepted) 1608 { 1609 /* Cleanup dialog if it wasn't destroyed in own loop: */ 1610 if (pDlg) 1611 delete pDlg; 1612 break; 1613 } 1614 1615 /* Acquire final snapshot name/description: */ 1616 strFinalName = pDlg->name().trimmed(); 1617 strFinalDescription = pDlg->description(); 1618 1619 /* Cleanup dialog: */ 1620 delete pDlg; 1621 } 1622 1623 /* Take snapshot: */ 1624 QUuid uSnapshotId; 1625 CProgress comProgress = comMachine.TakeSnapshot(strFinalName, strFinalDescription, true, uSnapshotId); 1626 if (!comMachine.isOk()) 1627 { 1628 msgCenter().cannotTakeSnapshot(comMachine, comMachine.GetName()); 1629 break; 1630 } 1631 1632 /* Show snapshot taking progress: */ 1633 msgCenter().showModalProgressDialog(comProgress, comMachine.GetName(), ":/progress_snapshot_create_90px.png"); 1634 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 1635 { 1636 msgCenter().cannotTakeSnapshot(comProgress, comMachine.GetName()); 1637 break; 1638 } 1639 1640 /* Mark snapshot restoring successful: */ 1641 fSuccess = true; 1557 /* Cleanup dialog if it wasn't destroyed in own loop: */ 1558 delete pDlg; 1559 return false; 1642 1560 } 1643 while (0); 1644 1645 /* Cleanup try-catch block: */ 1646 comSession.UnlockMachine(); 1647 } 1648 while (0); 1649 1650 /* Adjust snapshot tree: */ 1651 adjustTreeWidget(); 1561 1562 /* Acquire final snapshot name/description: */ 1563 strFinalName = pDlg->name().trimmed(); 1564 strFinalDescription = pDlg->description(); 1565 1566 /* Cleanup dialog: */ 1567 delete pDlg; 1568 } 1569 1570 /* Take snapshot: */ 1571 UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(m_comMachine, 1572 strFinalName, 1573 strFinalDescription); 1574 notificationCenter().append(pNotification); 1652 1575 1653 1576 /* Return result: */ 1654 return fSuccess;1577 return true; 1655 1578 } 1656 1579
Note:
See TracChangeset
for help on using the changeset viewer.