VirtualBox

Changeset 96660 in vbox


Ignore:
Timestamp:
Sep 8, 2022 1:26:20 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
153542
Message:

FE/Qt: bugref:9930: Snapshot UI: Support for multiple VM selection, initial version.

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  
    8989    UISnapshotItem(UISnapshotPane *pSnapshotWidget,
    9090                   QITreeWidget *pTreeWidget,
    91                    const CSnapshot &comSnapshot);
     91                   const CSnapshot &comSnapshot,
     92                   bool fExtendedNameRequired);
    9293    /** Constructs normal snapshot item (child of tree-widget-item). */
    9394    UISnapshotItem(UISnapshotPane *pSnapshotWidget,
     
    9899    UISnapshotItem(UISnapshotPane *pSnapshotWidget,
    99100                   QITreeWidget *pTreeWidget,
    100                    const CMachine &comMachine);
     101                   const CMachine &comMachine,
     102                   bool fExtendedNameRequired);
    101103    /** Constructs "current state" item (child of tree-widget-item). */
    102104    UISnapshotItem(UISnapshotPane *pSnapshotWidget,
     
    106108    /** Returns item machine. */
    107109    CMachine machine() const { return m_comMachine; }
     110    /** Returns item machine ID. */
     111    QUuid machineID() const { return m_uMachineID; }
    108112    /** Returns item snapshot. */
    109113    CSnapshot snapshot() const { return m_comSnapshot; }
     
    140144private:
    141145
     146    /** Holds whether this item requires extended name. */
     147    bool  m_fExtendedNameRequired;
     148
    142149    /** Holds the pointer to the snapshot-widget this item belongs to. */
    143150    QPointer<UISnapshotPane>  m_pSnapshotWidget;
     
    153160    CMachine   m_comMachine;
    154161
     162    /** Holds the machine ID. */
     163    QUuid  m_uMachineID;
    155164    /** Holds the "current snapshot" ID. */
    156165    QUuid  m_uSnapshotID;
     
    210219UISnapshotItem::UISnapshotItem(UISnapshotPane *pSnapshotWidget,
    211220                               QITreeWidget *pTreeWidget,
    212                                const CSnapshot &comSnapshot)
     221                               const CSnapshot &comSnapshot,
     222                               bool fExtendedNameRequired)
    213223    : QITreeWidgetItem(pTreeWidget)
     224    , m_fExtendedNameRequired(fExtendedNameRequired)
    214225    , m_pSnapshotWidget(pSnapshotWidget)
    215226    , m_fCurrentStateItem(false)
     
    226237                               const CSnapshot &comSnapshot)
    227238    : QITreeWidgetItem(pRootItem)
     239    , m_fExtendedNameRequired(false)
    228240    , m_pSnapshotWidget(pSnapshotWidget)
    229241    , m_fCurrentStateItem(false)
     
    238250UISnapshotItem::UISnapshotItem(UISnapshotPane *pSnapshotWidget,
    239251                               QITreeWidget *pTreeWidget,
    240                                const CMachine &comMachine)
     252                               const CMachine &comMachine,
     253                               bool fExtendedNameRequired)
    241254    : QITreeWidgetItem(pTreeWidget)
     255    , m_fExtendedNameRequired(fExtendedNameRequired)
    242256    , m_pSnapshotWidget(pSnapshotWidget)
    243257    , m_fCurrentStateItem(true)
     
    262276                               const CMachine &comMachine)
    263277    : QITreeWidgetItem(pRootItem)
     278    , m_fExtendedNameRequired(false)
    264279    , m_pSnapshotWidget(pSnapshotWidget)
    265280    , m_fCurrentStateItem(true)
     
    314329        /* Fetch machine information: */
    315330        AssertReturnVoid(m_comMachine.isNotNull());
     331        m_uMachineID = m_comMachine.GetId();
    316332        m_fCurrentStateModified = m_comMachine.GetCurrentStateModified();
    317333        m_strName = m_fCurrentStateModified
    318334                  ? tr("Current State (changed)", "Current State (Modified)")
    319335                  : 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);
    321340        m_strDescription = m_fCurrentStateModified
    322341                         ? tr("The current state differs from the state stored in the current snapshot")
     
    330349        /* Fetch snapshot information: */
    331350        AssertReturnVoid(m_comSnapshot.isNotNull());
     351        const CMachine comMachine = m_comSnapshot.GetMachine();
     352        m_uMachineID = comMachine.GetId();
    332353        m_uSnapshotID = m_comSnapshot.GetId();
    333354        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);
    335359        m_fOnline = m_comSnapshot.GetOnline();
    336360        setIcon(Column_Name, *m_pSnapshotWidget->snapshotItemIcon(m_fOnline));
     
    505529    , m_pActionPool(pActionPool)
    506530    , m_fShowToolbar(fShowToolbar)
    507     , m_enmSessionState(KSessionState_Null)
    508     , m_fShapshotOperationsAllowed(false)
    509531    , m_pLockReadWrite(0)
    510532    , m_pIconSnapshotOffline(0)
     
    514536    , m_pToolBar(0)
    515537    , m_pSnapshotTree(0)
    516     , m_pCurrentSnapshotItem(0)
    517     , m_pCurrentStateItem(0)
    518538    , m_pDetailsWidget(0)
    519539{
     
    528548void UISnapshotPane::setMachineItems(const QList<UIVirtualMachineItem*> &items)
    529549{
    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        }
    545572    }
    546573
     
    556583bool UISnapshotPane::isCurrentStateItemSelected() const
    557584{
    558     return m_pCurrentStateItem && m_pSnapshotTree->currentItem() == m_pCurrentStateItem;
     585    UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
     586    return m_currentStateItems.values().contains(pSnapshotItem);
    559587}
    560588
     
    606634{
    607635    /* Make sure it's our VM: */
    608     if (uMachineId != m_uMachineId)
     636    if (!m_machines.keys().contains(uMachineId))
    609637        return;
    610638
     
    613641
    614642    /* Recache "current state" item data: */
    615     m_pCurrentStateItem->recache();
     643    m_currentStateItems.value(uMachineId)->recache();
    616644
    617645    /* Choose current item again (to update details-widget): */
     
    622650{
    623651    /* Make sure it's our VM: */
    624     if (uMachineId != m_uMachineId)
     652    if (!m_machines.keys().contains(uMachineId))
    625653        return;
    626654
     
    629657
    630658    /* 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);
    633661}
    634662
     
    636664{
    637665    /* Make sure it's our VM: */
    638     if (uMachineId != m_uMachineId)
     666    if (!m_machines.keys().contains(uMachineId))
    639667        return;
    640668
     
    643671
    644672    /* Recache current session-state: */
    645     m_enmSessionState = enmState;
     673    m_sessionStates[uMachineId] = enmState;
    646674
    647675    /* Update action states: */
     
    652680{
    653681    /* Make sure it's our VM: */
    654     if (uMachineId != m_uMachineId)
     682    if (!m_machines.keys().contains(uMachineId))
    655683        return;
    656684
     
    664692        QWriteLocker locker(m_pLockReadWrite);
    665693
     694        /* Acquire corresponding machine: */
     695        CMachine comMachine = m_machines.value(uMachineId);
     696
    666697        /* 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();
    669700
    670701        /* Show error message if necessary: */
    671702        if (!fSuccess)
    672             UINotificationMessage::cannotFindSnapshotById(m_comMachine, uSnapshotId);
     703            UINotificationMessage::cannotFindSnapshotById(comMachine, uSnapshotId);
    673704        else
    674705        {
     
    697728            /* Make sure this parent-item is a parent of "current state" item as well: */
    698729            if (fSuccess)
    699                 fSuccess = qobject_cast<UISnapshotItem*>(m_pCurrentStateItem->parentItem()) == pParentItem;
     730                fSuccess = qobject_cast<UISnapshotItem*>(m_currentStateItems.value(uMachineId)->parentItem()) == pParentItem;
    700731            /* Make sure this parent-item is a "current snapshot" item as well: */
    701732            if (fSuccess)
    702                 fSuccess = m_pCurrentSnapshotItem == pParentItem;
     733                fSuccess = m_currentSnapshotItems.value(uMachineId) == pParentItem;
    703734
    704735            /* Create new item: */
     
    706737            {
    707738                /* 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;
    710741                delete pCurrentStateItem;
    711742                pCurrentStateItem = 0;
    712743
    713744                /* 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);
    721750                /* Mark it as current: */
    722                 m_pCurrentSnapshotItem->setCurrentSnapshotItem(true);
     751                m_currentSnapshotItems.value(uMachineId)->setCurrentSnapshotItem(true);
    723752                /* And recache it's content: */
    724                 m_pCurrentSnapshotItem->recache();
     753                m_currentSnapshotItems.value(uMachineId)->recache();
    725754
    726755                /* 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);
    728757                /* Recache it's content: */
    729                 m_pCurrentStateItem->recache();
     758                m_currentStateItems.value(uMachineId)->recache();
    730759                /* And choose is as current one: */
    731                 m_pSnapshotTree->setCurrentItem(m_pCurrentStateItem);
     760                m_pSnapshotTree->setCurrentItem(m_currentStateItems.value(uMachineId));
    732761                sltHandleCurrentItemChange();
    733762
     
    748777{
    749778    /* Make sure it's our VM: */
    750     if (uMachineId != m_uMachineId)
     779    if (!m_machines.keys().contains(uMachineId))
    751780        return;
    752781
     
    806835        if (fSuccess)
    807836        {
    808             if (pItem == m_pCurrentSnapshotItem)
     837            if (pItem == m_currentSnapshotItems.value(uMachineId))
    809838            {
    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);
    813842            }
    814843            delete pItem;
     
    830859{
    831860    /* Make sure it's our VM: */
    832     if (uMachineId != m_uMachineId)
     861    if (!m_machines.keys().contains(uMachineId))
    833862        return;
    834863
     
    870899{
    871900    /* Make sure it's our VM: */
    872     if (uMachineId != m_uMachineId)
     901    if (!m_machines.keys().contains(uMachineId))
    873902        return;
    874903
     
    890919        {
    891920            /* 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;
    894923            delete pCurrentStateItem;
    895924            pCurrentStateItem = 0;
    896925
    897926            /* 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);
    902931
    903932            /* 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();
    906935            /* And choose is as current one: */
    907             m_pSnapshotTree->setCurrentItem(m_pCurrentStateItem);
     936            m_pSnapshotTree->setCurrentItem(m_currentStateItems.value(uMachineId));
    908937            sltHandleCurrentItemChange();
    909938
     
    957986        if (pSnapshotItem->isCurrentStateItem())
    958987        {
    959             if (m_comMachine.isNull())
     988            if (m_machines.value(pSnapshotItem->machineID()).isNull())
    960989                m_pDetailsWidget->clearData();
    961990            else
    962                 m_pDetailsWidget->setData(m_comMachine);
     991                m_pDetailsWidget->setData(m_machines.value(pSnapshotItem->machineID()));
    963992        }
    964993        else
     
    9831012
    9841013        /* Take snapshot: */
    985         UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(m_comMachine,
     1014        UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(m_machines.value(pSnapshotItem->machineID()),
    9861015                                                                                                   newData.name(),
    9871016                                                                                                   newData.description());
     
    10061035        /* Open a session (this call will handle all errors): */
    10071036        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());
    10101039        else
    1011             comSession = uiCommon().openSession(m_uMachineId);
     1040            comSession = uiCommon().openSession(pSnapshotItem->machineID());
    10121041        if (comSession.isNotNull())
    10131042        {
     
    10751104        if (pSnapshotItem->isCurrentStateItem())
    10761105        {
    1077             if (m_comMachine.isNull())
     1106            CMachine comMachine = m_machines.value(pSnapshotItem->machineID());
     1107            if (comMachine.isNull())
    10781108                m_pDetailsWidget->clearData();
    10791109            else
    1080                 m_pDetailsWidget->setData(m_comMachine);
     1110                m_pDetailsWidget->setData(comMachine);
    10811111        }
    10821112        else
     
    11051135    QMenu menu;
    11061136    /* For snapshot item: */
    1107     if (m_pCurrentSnapshotItem && !pSnapshotItem->isCurrentStateItem())
     1137    if (m_currentSnapshotItems.value(pSnapshotItem->machineID()) && !pSnapshotItem->isCurrentStateItem())
    11081138    {
    11091139        menu.addAction(m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Delete));
     
    13751405    QWriteLocker locker(m_pLockReadWrite);
    13761406
    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())
    13791409    {
    13801410        /* Clear the tree: */
     
    13961426    m_pSnapshotTree->clear();
    13971427
    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        }
    14381474    }
    14391475
     
    14451481}
    14461482
    1447 void UISnapshotPane::populateSnapshots(const CSnapshot &comSnapshot, QITreeWidgetItem *pItem)
     1483void UISnapshotPane::populateSnapshots(const QUuid &uMachineId, const CSnapshot &comSnapshot, QITreeWidgetItem *pItem)
    14481484{
    14491485    /* Create a child of passed item: */
    14501486    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);
    14521488    /* And recache it's content: */
    14531489    pSnapshotItem->recache();
    14541490
    14551491    /* Mark snapshot item as "current" and remember it: */
    1456     CSnapshot comCurrentSnapshot = m_comMachine.GetCurrentSnapshot();
     1492    CSnapshot comCurrentSnapshot = m_machines.value(uMachineId).GetCurrentSnapshot();
    14571493    if (!comCurrentSnapshot.isNull() && comCurrentSnapshot.GetId() == comSnapshot.GetId())
    14581494    {
    14591495        pSnapshotItem->setCurrentSnapshotItem(true);
    1460         m_pCurrentSnapshotItem = pSnapshotItem;
     1496        m_currentSnapshotItems[uMachineId] = pSnapshotItem;
    14611497    }
    14621498
    14631499    /* Walk through the children recursively: */
    14641500    foreach (const CSnapshot &comIteratedSnapshot, comSnapshot.GetChildren())
    1465         populateSnapshots(comIteratedSnapshot, pSnapshotItem);
     1501        populateSnapshots(uMachineId, comIteratedSnapshot, pSnapshotItem);
    14661502
    14671503    /* Expand the newly created item: */
    14681504    pSnapshotItem->setExpanded(true);
    1469     /* And mark it as editable: */
    1470     pSnapshotItem->setFlags(pSnapshotItem->flags() | Qt::ItemIsEditable);
    14711505}
    14721506
     
    14971531
    14981532    /* 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;
    15001534
    15011535    /* Acquire machine-state of the "current state" item: */
    15021536    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();
    15051540
    15061541    /* Determine whether taking or deleting snapshots is possible: */
     
    15151550    /* Update 'Take' action: */
    15161551    m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Take)->setEnabled(
    1517            m_fShapshotOperationsAllowed
     1552           pSnapshotItem
     1553        && m_operationAllowed.value(pSnapshotItem->machineID())
    15181554        && (   (   fCanTakeDeleteSnapshot
    1519                 && m_pCurrentSnapshotItem
    1520                 && pSnapshotItem
     1555                && m_currentSnapshotItems.value(pSnapshotItem->machineID())
    15211556                && pSnapshotItem->isCurrentStateItem())
    1522             || (   pSnapshotItem
    1523                 && !m_pCurrentSnapshotItem))
     1557            || (!m_currentSnapshotItems.value(pSnapshotItem->machineID())))
    15241558    );
    15251559
    15261560    /* Update 'Delete' action: */
    15271561    m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Delete)->setEnabled(
    1528            m_fShapshotOperationsAllowed
     1562           pSnapshotItem
     1563        && m_operationAllowed.value(pSnapshotItem->machineID())
    15291564        && fCanTakeDeleteSnapshot
    1530         && m_pCurrentSnapshotItem
     1565        && m_currentSnapshotItems.value(pSnapshotItem->machineID())
    15311566        && pSnapshotItem
    15321567        && !pSnapshotItem->isCurrentStateItem()
     
    15361571    m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Restore)->setEnabled(
    15371572           !fBusy
    1538         && m_pCurrentSnapshotItem
    15391573        && pSnapshotItem
     1574        && m_currentSnapshotItems.value(pSnapshotItem->machineID())
    15401575        && !pSnapshotItem->isCurrentStateItem()
    15411576    );
     
    15561591bool UISnapshotPane::takeSnapshot(bool fAutomatically /* = false */)
    15571592{
     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
    15581600    /* Search for a maximum existing snapshot index: */
    15591601    int iMaximumIndex = 0;
     
    15811623        /* Create take-snapshot dialog: */
    15821624        QWidget *pDlgParent = windowManager().realParentWindow(this);
    1583         QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, m_comMachine);
     1625        QPointer<UITakeSnapshotDialog> pDlg = new UITakeSnapshotDialog(pDlgParent, comMachine);
    15841626        windowManager().registerNewParent(pDlg, pDlgParent);
    15851627
    15861628        /* Assign corresponding icon: */
    1587         QIcon icon = generalIconPool().userMachineIcon(m_comMachine);
     1629        QIcon icon = generalIconPool().userMachineIcon(comMachine);
    15881630        if (icon.isNull())
    1589             icon = generalIconPool().guestOSTypeIcon(m_comMachine.GetOSTypeId());
     1631            icon = generalIconPool().guestOSTypeIcon(comMachine.GetOSTypeId());
    15901632        pDlg->setIcon(icon);
    15911633
     
    16101652
    16111653    /* Take snapshot: */
    1612     UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(m_comMachine,
     1654    UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(comMachine,
    16131655                                                                                               strFinalName,
    16141656                                                                                               strFinalDescription);
     
    16241666    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    16251667    AssertPtrReturn(pSnapshotItem, false);
     1668
     1669    /* Acquire machine: */
     1670    const CMachine comMachine = m_machines.value(pSnapshotItem->machineID());
    16261671
    16271672    /* Get corresponding snapshot: */
     
    16431688
    16441689    /* Delete snapshot: */
    1645     UINotificationProgressSnapshotDelete *pNotification = new UINotificationProgressSnapshotDelete(m_comMachine,
     1690    UINotificationProgressSnapshotDelete *pNotification = new UINotificationProgressSnapshotDelete(comMachine,
    16461691                                                                                                   pSnapshotItem->snapshotID());
    16471692    gpNotificationCenter->append(pNotification);
     
    16571702    AssertPtrReturn(pSnapshotItem, false);
    16581703
     1704    /* Acquire machine: */
     1705    const CMachine comMachine = m_machines.value(pSnapshotItem->machineID());
     1706
    16591707    /* Get corresponding snapshot: */
    16601708    const CSnapshot comSnapshot = pSnapshotItem->snapshot();
     
    16621710
    16631711    /* In manual mode we should check whether current state is changed: */
    1664     if (!fAutomatically && m_comMachine.GetCurrentStateModified())
     1712    if (!fAutomatically && comMachine.GetCurrentStateModified())
    16651713    {
    16661714        /* 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());
    16681716        if (iResultCode & AlertButton_Cancel)
    16691717            return false;
     
    16731721        {
    16741722            /* Take snapshot of changed current state: */
    1675             m_pSnapshotTree->setCurrentItem(m_pCurrentStateItem);
     1723            m_pSnapshotTree->setCurrentItem(m_currentStateItems.value(pSnapshotItem->machineID()));
    16761724            if (!takeSnapshot())
    16771725                return false;
     
    16801728
    16811729    /* Restore snapshot: */
    1682     UINotificationProgressSnapshotRestore *pNotification = new UINotificationProgressSnapshotRestore(m_comMachine, comSnapshot);
     1730    UINotificationProgressSnapshotRestore *pNotification = new UINotificationProgressSnapshotRestore(comMachine, comSnapshot);
    16831731    gpNotificationCenter->append(pNotification);
    16841732
  • trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h

    r96635 r96660  
    185185        void refreshAll();
    186186        /** 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);
    188188
    189189        /** Cleanups all. */
     
    224224      * @{ */
    225225        /** Holds the action-pool reference. */
    226         UIActionPool  *m_pActionPool;
     226        UIActionPool *m_pActionPool;
    227227        /** 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;
    238236
    239237        /** Holds the snapshot item editing protector. */
     
    259257        /** Holds the snapshot tree instance. */
    260258        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;
    265264
    266265        /** Holds the details-widget instance. */
Note: See TracChangeset for help on using the changeset viewer.

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