VirtualBox

Changeset 90456 in vbox


Ignore:
Timestamp:
Aug 1, 2021 12:26:40 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10067: Notification signature for snapshot delete progress which should now go to center instead of modal dialogs; Also a tiny refactoring for previous commit r146059.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.cpp

    r90455 r90456  
    2626/* COM includes: */
    2727#include "CConsole.h"
     28#include "CSnapshot.h"
    2829
    2930
     
    988989QString UINotificationProgressSnapshotTake::details() const
    989990{
    990     return UINotificationProgress::tr("<b>VM Name:</b> %1<br><b>Snapshot Name:</b> %2").arg(m_strName, m_strSnapshotName);
     991    return UINotificationProgress::tr("<b>VM Name:</b> %1<br><b>Snapshot Name:</b> %2").arg(m_strMachineName, m_strSnapshotName);
    991992}
    992993
     
    10021003
    10031004    /* Acquire VM name: */
    1004     m_strName = m_comMachine.GetName();
     1005    m_strMachineName = m_comMachine.GetName();
    10051006    if (!m_comMachine.isOk())
    10061007    {
     
    10461047
    10471048void UINotificationProgressSnapshotTake::sltHandleProgressFinished()
     1049{
     1050    m_comSession.UnlockMachine();
     1051}
     1052
     1053
     1054/*********************************************************************************************************************************
     1055*   Class UINotificationProgressSnapshotDelete implementation.                                                                   *
     1056*********************************************************************************************************************************/
     1057
     1058UINotificationProgressSnapshotDelete::UINotificationProgressSnapshotDelete(const CMachine &comMachine,
     1059                                                                           const QUuid &uSnapshotId)
     1060    : m_comMachine(comMachine)
     1061    , m_uSnapshotId(uSnapshotId)
     1062{
     1063    connect(this, &UINotificationProgress::sigProgressFinished,
     1064            this, &UINotificationProgressSnapshotDelete::sltHandleProgressFinished);
     1065}
     1066
     1067QString UINotificationProgressSnapshotDelete::name() const
     1068{
     1069    return UINotificationProgress::tr("Deleting snapshot ...");
     1070}
     1071
     1072QString UINotificationProgressSnapshotDelete::details() const
     1073{
     1074    return UINotificationProgress::tr("<b>VM Name:</b> %1<br><b>Snapshot Name:</b> %2").arg(m_strMachineName, m_strSnapshotName);
     1075}
     1076
     1077CProgress UINotificationProgressSnapshotDelete::createProgress(COMResult &comResult)
     1078{
     1079    /* Acquire VM id: */
     1080    const QUuid uId = m_comMachine.GetId();
     1081    if (!m_comMachine.isOk())
     1082    {
     1083        comResult = m_comMachine;
     1084        return CProgress();
     1085    }
     1086
     1087    /* Acquire VM name: */
     1088    m_strMachineName = m_comMachine.GetName();
     1089    if (!m_comMachine.isOk())
     1090    {
     1091        comResult = m_comMachine;
     1092        return CProgress();
     1093    }
     1094
     1095    /* Acquire snapshot: */
     1096    CSnapshot comSnapshot = m_comMachine.FindSnapshot(m_uSnapshotId.toString());
     1097    if (!m_comMachine.isOk())
     1098    {
     1099        comResult = m_comMachine;
     1100        return CProgress();
     1101    }
     1102
     1103    /* Acquire snapshot name: */
     1104    m_strSnapshotName = comSnapshot.GetName();
     1105    if (!comSnapshot.isOk())
     1106    {
     1107        comResult = comSnapshot;
     1108        return CProgress();
     1109    }
     1110
     1111    /* Acquire session state: */
     1112    const KSessionState enmSessionState = m_comMachine.GetSessionState();
     1113    if (!m_comMachine.isOk())
     1114    {
     1115        comResult = m_comMachine;
     1116        return CProgress();
     1117    }
     1118
     1119    /* Open a session thru which we will modify the machine: */
     1120    if (enmSessionState != KSessionState_Unlocked)
     1121        m_comSession = uiCommon().openExistingSession(uId);
     1122    else
     1123        m_comSession = uiCommon().openSession(uId);
     1124    if (m_comSession.isNull())
     1125        return CProgress();
     1126
     1127    /* Get session machine: */
     1128    CMachine comMachine = m_comSession.GetMachine();
     1129    if (!m_comSession.isOk())
     1130    {
     1131        comResult = m_comSession;
     1132        m_comSession.UnlockMachine();
     1133        return CProgress();
     1134    }
     1135
     1136    /* Initialize progress-wrapper: */
     1137    CProgress comProgress = comMachine.DeleteSnapshot(m_uSnapshotId);
     1138    /* Store COM result: */
     1139    comResult = m_comMachine;
     1140    /* Return progress-wrapper: */
     1141    return comProgress;
     1142}
     1143
     1144void UINotificationProgressSnapshotDelete::sltHandleProgressFinished()
    10481145{
    10491146    m_comSession.UnlockMachine();
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h

    r90455 r90456  
    782782    QString   m_strSnapshotDescription;
    783783    /** Holds the machine name. */
    784     QString   m_strName;
     784    QString   m_strMachineName;
     785    /** Holds the session being opened. */
     786    CSession  m_comSession;
     787};
     788
     789/** UINotificationProgress extension for snapshot delete functionality. */
     790class SHARED_LIBRARY_STUFF UINotificationProgressSnapshotDelete : public UINotificationProgress
     791{
     792    Q_OBJECT;
     793
     794public:
     795
     796    /** Constructs snapshot delete notification-progress.
     797      * @param  comMachine   Brings the machine we are deleting snapshot from.
     798      * @param  uSnapshotId  Brings the ID of snapshot being deleted. */
     799    UINotificationProgressSnapshotDelete(const CMachine &comMachine,
     800                                         const QUuid &uSnapshotId);
     801
     802protected:
     803
     804    /** Returns object name. */
     805    virtual QString name() const /* override final */;
     806    /** Returns object details. */
     807    virtual QString details() const /* override final */;
     808    /** Creates and returns started progress-wrapper. */
     809    virtual CProgress createProgress(COMResult &comResult) /* override final */;
     810
     811private slots:
     812
     813    /** Handles signal about progress being finished. */
     814    void sltHandleProgressFinished();
     815
     816private:
     817
     818    /** Holds the machine we are deleting snapshot from. */
     819    CMachine  m_comMachine;
     820    /** Holds the ID of snapshot being deleted. */
     821    QUuid     m_uSnapshotId;
     822    /** Holds the machine name. */
     823    QString   m_strMachineName;
     824    /** Holds the snapshot name. */
     825    QString   m_strSnapshotName;
    785826    /** Holds the session being opened. */
    786827    CSession  m_comSession;
  • trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp

    r90455 r90456  
    15801580bool UISnapshotPane::deleteSnapshot(bool fAutomatically /* = false */)
    15811581{
    1582     /* Simulate try-catch block: */
    1583     bool fSuccess = false;
    1584     do
    1585     {
    1586         /* Acquire "current snapshot" item: */
    1587         const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    1588         AssertPtr(pSnapshotItem);
    1589         if (!pSnapshotItem)
    1590             break;
    1591 
    1592         /* Get corresponding snapshot: */
    1593         const CSnapshot comSnapshot = pSnapshotItem->snapshot();
    1594         Assert(!comSnapshot.isNull());
    1595         if (comSnapshot.isNull())
    1596             break;
    1597 
    1598         /* In manual mode we should ask if user really wants to remove the selected snapshot: */
    1599         if (!fAutomatically && !msgCenter().confirmSnapshotRemoval(comSnapshot.GetName()))
    1600             break;
    1601 
    1602         /** @todo check available space on the target filesystem etc etc. */
     1582    /* Acquire "current snapshot" item: */
     1583    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
     1584    AssertPtrReturn(pSnapshotItem, false);
     1585
     1586    /* Get corresponding snapshot: */
     1587    const CSnapshot comSnapshot = pSnapshotItem->snapshot();
     1588    AssertReturn(!comSnapshot.isNull(), false);
     1589
     1590    /* In manual mode we should ask if user really wants to remove the selected snapshot: */
     1591    if (!fAutomatically && !msgCenter().confirmSnapshotRemoval(comSnapshot.GetName()))
     1592        return false;
     1593
    16031594#if 0
    1604         if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(comSnapshot.GetName(),
    1605                                                            "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi",
    1606                                                            "59 GiB",
    1607                                                            "15 GiB"))
    1608             break;
     1595    /** @todo check available space on the target filesystem etc etc. */
     1596    if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(comSnapshot.GetName(),
     1597                                                       "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi",
     1598                                                       "59 GiB",
     1599                                                       "15 GiB"))
     1600        return false;
    16091601#endif
    16101602
    1611         /* Open a session (this call will handle all errors): */
    1612         CSession comSession;
    1613         if (m_enmSessionState != KSessionState_Unlocked)
    1614             comSession = uiCommon().openExistingSession(m_uMachineId);
    1615         else
    1616             comSession = uiCommon().openSession(m_uMachineId);
    1617         if (comSession.isNull())
    1618             break;
    1619 
    1620         /* Simulate try-catch block: */
    1621         do
    1622         {
    1623             /* Remove chosen snapshot: */
    1624             CMachine comMachine = comSession.GetMachine();
    1625             CProgress comProgress = comMachine.DeleteSnapshot(pSnapshotItem->snapshotID());
    1626             if (!comMachine.isOk())
    1627             {
    1628                 msgCenter().cannotRemoveSnapshot(comMachine,  comSnapshot.GetName(), m_comMachine.GetName());
    1629                 break;
    1630             }
    1631 
    1632             /* Show snapshot removing progress: */
    1633             msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_discard_90px.png");
    1634             if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
    1635             {
    1636                 msgCenter().cannotRemoveSnapshot(comProgress,  comSnapshot.GetName(), m_comMachine.GetName());
    1637                 break;
    1638             }
    1639 
    1640             /* Mark snapshot removing successful: */
    1641             fSuccess = true;
    1642         }
    1643         while (0);
    1644 
    1645         /* Cleanup try-catch block: */
    1646         comSession.UnlockMachine();
    1647     }
    1648     while (0);
    1649 
    1650     /* Adjust snapshot tree: */
    1651     adjustTreeWidget();
     1603    /* Delete snapshot: */
     1604    UINotificationProgressSnapshotDelete *pNotification = new UINotificationProgressSnapshotDelete(m_comMachine,
     1605                                                                                                   pSnapshotItem->snapshotID());
     1606    notificationCenter().append(pNotification);
    16521607
    16531608    /* Return result: */
    1654     return fSuccess;
     1609    return true;
    16551610}
    16561611
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette