VirtualBox

Changeset 63818 in vbox for trunk


Ignore:
Timestamp:
Sep 13, 2016 4:43:16 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 25): Selector UI: Cleanup UISnapshotPane doxy/comments.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r63804 r63818  
    5252
    5353
    54 /**
    55  *  QTreeWidgetItem subclass for snapshots items
    56  */
     54/** QTreeWidgetItem subclass for snapshots items. */
    5755class SnapshotWgtItem : public QTreeWidgetItem
    5856{
    5957public:
    6058
     59    /** Item type for SnapshotWgtItem. */
    6160    enum { ItemType = QTreeWidgetItem::UserType + 1 };
    6261
    63     /* Normal snapshot item (child of tree-widget) */
     62    /** Constructs normal snapshot item (child of tree-widget). */
    6463    SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidget *aTreeWidget, const CSnapshot &aSnapshot)
    6564        : QTreeWidgetItem (aTreeWidget, ItemType)
     
    7069    }
    7170
    72     /* Normal snapshot item (child of tree-widget-item) */
     71    /** Constructs normal snapshot item (child of tree-widget-item). */
    7372    SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *aRootItem, const CSnapshot &aSnapshot)
    7473        : QTreeWidgetItem (aRootItem, ItemType)
     
    7978    }
    8079
    81     /* Current state item (child of tree-widget) */
     80    /** Constructs "current state" item (child of tree-widget). */
    8281    SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidget *aTreeWidget, const CMachine &aMachine)
    8382        : QTreeWidgetItem (aTreeWidget, ItemType)
     
    8685        , mMachine (aMachine)
    8786    {
     87        /* Fetch current machine state: */
    8888        updateCurrentState (mMachine.GetState());
    8989    }
    9090
    91     /* Current state item (child of tree-widget-item) */
     91    /** Constructs "current state" item (child of tree-widget-item). */
    9292    SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *aRootItem, const CMachine &aMachine)
    9393        : QTreeWidgetItem (aRootItem, ItemType)
     
    9696        , mMachine (aMachine)
    9797    {
     98        /* Fetch current machine state: */
    9899        updateCurrentState (mMachine.GetState());
    99100    }
    100101
     102    /** Returns item data for corresponding @a iColumn and @a iRole. */
    101103    QVariant data (int aColumn, int aRole) const
    102104    {
     
    104106        {
    105107            case Qt::DisplayRole:
     108            {
     109                /* Call to the base-class for "current state" item, compose ourselves otherwise: */
    106110                return mIsCurrentState ? QTreeWidgetItem::data (aColumn, aRole) : QVariant (QString ("%1%2")
    107111                                         .arg (QTreeWidgetItem::data (aColumn, Qt::DisplayRole).toString())
    108112                                         .arg (QTreeWidgetItem::data (aColumn, Qt::UserRole).toString()));
     113            }
    109114            case Qt::SizeHintRole:
    110115            {
     
    123128                break;
    124129        }
     130
     131        /* Call to base-class: */
    125132        return QTreeWidgetItem::data (aColumn, aRole);
    126133    }
    127134
     135    /** Returns item text for corresponding @a iColumn. */
    128136    QString text (int aColumn) const
    129137    {
     
    131139    }
    132140
     141    /** Returns whether this is the "current state" item. */
    133142    bool isCurrentStateItem() const
    134143    {
     
    136145    }
    137146
     147    /** Calculates and returns the current item level. */
    138148    int level()
    139149    {
     
    148158    }
    149159
     160    /** Returns whether the font is bold. */
    150161    bool bold() const { return font (0).bold(); }
     162    /** Defines whether the font is @a fBold. */
    151163    void setBold (bool aBold)
    152164    {
     165        /* Update font: */
    153166        QFont myFont = font (0);
    154167        myFont.setBold (aBold);
    155168        setFont (0, myFont);
     169
     170        /* Adjust text: */
    156171        adjustText();
    157172    }
    158173
     174    /** Returns whether the font is italic. */
    159175    bool italic() const { return font (0).italic(); }
     176    /** Defines whether the font is @a fItalic. */
    160177    void setItalic (bool aItalic)
    161178    {
     179        /* Update font: */
    162180        QFont myFont = font (0);
    163181        myFont.setItalic (aItalic);
    164182        setFont (0, myFont);
     183
     184        /* Adjust text: */
    165185        adjustText();
    166186    }
    167187
     188    /** Returns item machine. */
    168189    CMachine machine() const { return mMachine; }
     190    /** Returns item snapshot. */
    169191    CSnapshot snapshot() const { return mSnapshot; }
     192    /** Returns item snapshot ID. */
    170193    QString snapshotId() const { return mId; }
    171194
     195    /** Recaches the item's contents. */
    172196    void recache()
    173197    {
     198        /* For "current state" item: */
    174199        if (mIsCurrentState)
    175200        {
     
    185210                    QString::null;
    186211        }
     212        /* For others: */
    187213        else
    188214        {
     
    196222            mCurStateModified = false;
    197223        }
     224
     225        /* Adjust text: */
    198226        adjustText();
     227        /* Update tool-tip: */
    199228        recacheToolTip();
    200229    }
    201230
     231    /** Returns current machine state. */
    202232    KMachineState getCurrentState()
    203233    {
     234        /* Make sure machine is valid: */
    204235        if (mMachine.isNull())
    205236            return KMachineState_Null;
    206237
     238        /* Return cached state: */
    207239        return mMachineState;
    208240    }
    209241
     242    /** Recaches current machine state. */
    210243    void updateCurrentState (KMachineState aState)
    211244    {
     245        /* Make sure machine is valid: */
    212246        if (mMachine.isNull())
    213247            return;
    214248
     249        /* Set corresponding icon: */
    215250        setIcon(0, gpConverter->toIcon(aState));
     251        /* Cache new state: */
    216252        mMachineState = aState;
     253        /* Update timestamp: */
    217254        mTimestamp.setTime_t (mMachine.GetLastStateChange() / 1000);
    218255    }
    219256
     257    /** Updates item age. */
    220258    SnapshotAgeFormat updateAge()
    221259    {
     260        /* Prepare age: */
    222261        QString age;
    223262
     
    254293        }
    255294
    256         /* Update data */
     295        /* Update data: */
    257296        setData (0, Qt::UserRole, age);
    258297
     298        /* Return age: */
    259299        return ageFormat;
    260300    }
     
    262302private:
    263303
     304    /** Adjusts item text. */
    264305    void adjustText()
    265306    {
     
    272313                   treeWidget()->indentation() /* indent */ +
    273314                   16 /* icon */;
     315
     316        /* Adjust size finally: */
    274317        setSizeHint (0, QSize (wid0, hei0));
    275318    }
    276319
     320    /** Recaches item tool-tip. */
    277321    void recacheToolTip()
    278322    {
     323        /* Is the saved date today? */
    279324        QString name = text (0);
    280325
     326        /* Compose date time: */
    281327        bool dateTimeToday = mTimestamp.date() == QDate::currentDate();
    282328        QString dateTime = dateTimeToday ?
     
    284330                           mTimestamp.toString (Qt::LocalDate);
    285331
     332        /* Prepare details: */
    286333        QString details;
    287334
     335        /* For snapshot item: */
    288336        if (!mSnapshot.isNull())
    289337        {
     
    293341            else
    294342                details = " (";
     343
     344            /* Add online/offline information: */
    295345            details += mOnline ? UISnapshotPane::tr ("online)", "Snapshot details")
    296346                               : UISnapshotPane::tr ("offline)", "Snapshot details");
    297347
     348            /* Add date/time information: */
    298349            if (dateTimeToday)
    299350                dateTime = UISnapshotPane::tr ("Taken at %1", "Snapshot (time)").arg (dateTime);
     
    301352                dateTime = UISnapshotPane::tr ("Taken on %1", "Snapshot (date + time)").arg (dateTime);
    302353        }
     354        /* For "current state" item: */
    303355        else
    304356        {
     
    307359        }
    308360
     361        /* Prepare tool-tip: */
    309362        QString toolTip = QString ("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>")
    310363            .arg (name) .arg (details).arg (dateTime);
    311364
     365        /* Append description if any: */
    312366        if (!mDesc.isEmpty())
    313367            toolTip += "<hr>" + mDesc;
    314368
     369        /* Assign tool-tip finally: */
    315370        setToolTip (0, toolTip);
    316371    }
    317372
    318     /** Holds pointer to snapshot-widget 'this' item belongs to. */
     373    /** Holds the pointer to the snapshot-widget this item belongs to. */
    319374    QPointer<UISnapshotPane> m_pSnapshotWidget;
    320375
     376    /** Holds whether this is a "current state" item. */
    321377    bool mIsCurrentState;
    322378
     379    /** Holds the snapshot COM wrapper. */
    323380    CSnapshot mSnapshot;
     381    /** Holds the machine COM wrapper. */
    324382    CMachine mMachine;
    325383
     384    /** Holds the current snapshot ID. */
    326385    QString mId;
     386    /** Holds whether the current snapshot is online one. */
    327387    bool mOnline;
     388
     389    /** Holds the item description. */
    328390    QString mDesc;
     391    /** Holds the item timestamp. */
    329392    QDateTime mTimestamp;
    330393
     394    /** Holds whether the current state is modified. */
    331395    bool mCurStateModified;
     396    /** Holds the cached machine state. */
    332397    KMachineState mMachineState;
    333398};
    334399
    335 /**
    336  *  Simple guard block to prevent cyclic call caused by:
    337  *  changing tree-widget item content (rename) leads to snapshot update &
    338  *  snapshot update leads to changing tree-widget item content.
    339  */
     400
     401/** Simple guard block to prevent cyclic call caused by:
     402  * changing tree-widget item content (rename) leads to snapshot
     403  * update & snapshot update leads to changing tree-widget item content. */
    340404class SnapshotEditBlocker
    341405{
    342406public:
    343407
     408    /** Constructs edit blocker. */
    344409    SnapshotEditBlocker (bool &aProtector)
    345410        : mProtector (aProtector)
     
    348413    }
    349414
     415    /** Destructs edit blocker. */
    350416   ~SnapshotEditBlocker()
    351417    {
     
    355421private:
    356422
     423    /** Holds the protector flag reference. */
    357424    bool &mProtector;
    358425};
     426
    359427
    360428UISnapshotPane::UISnapshotPane (QWidget *aParent)
     
    371439    , m_fShapshotOperationsAllowed(false)
    372440{
    373     /* Apply UI decorations */
     441    /* Apply UI decorations: */
    374442    Ui::UISnapshotPane::setupUi (this);
    375443
     444    /* No header: */
    376445    mTreeWidget->header()->hide();
    377446
    378447#if QT_VERSION < 0x050000
    379     /* The snapshots widget is not very useful if there are a lot
    380      * of snapshots in a tree and the current Qt style decides not
    381      * to draw lines (branches) between the snapshot nodes; it is
    382      * then often unclear which snapshot is a child of another.
    383      * So on platforms whose styles do not normally draw branches,
    384      * we use QWindowsStyle which is present on every platform and
    385      * draws required thing like we want. */
     448    // WORKAROUND:
     449    // The snapshots widget is not very useful if there are a lot
     450    // of snapshots in a tree and the current Qt style decides not
     451    // to draw lines (branches) between the snapshot nodes; it is
     452    // then often unclear which snapshot is a child of another.
     453    // So on platforms whose styles do not normally draw branches,
     454    // we use QWindowsStyle which is present on every platform and
     455    // draws required thing like we want. */
    386456// #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
    387457    QWindowsStyle *treeWidgetStyle = new QWindowsStyle;
     
    399469    const int iIconMetric = (int)(pStyle->pixelMetric(QStyle::PM_SmallIconSize) * 1.375);
    400470
    401     /* ToolBar creation */
     471    /* Create tool-bar: */
    402472    UIToolBar *toolBar = new UIToolBar (this);
    403473    toolBar->setIconSize (QSize (iIconMetric, iIconMetric));
    404474    toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
    405 
     475    /* Add actions into tool-bar: */
    406476    toolBar->addAction (mTakeSnapshotAction);
    407477    toolBar->addSeparator();
     
    411481    toolBar->addSeparator();
    412482    toolBar->addAction(mCloneSnapshotAction);
    413 
     483    /* Add tool-bar into layout: */
    414484    ((QVBoxLayout*)layout())->insertWidget (0, toolBar);
    415485
    416     /* Setup actions */
     486    /* Setup action icons: */
    417487    mRestoreSnapshotAction->setIcon(UIIconPool::iconSetFull(
    418488        ":/snapshot_restore_22px.png", ":/snapshot_restore_16px.png",
     
    430500        ":/vm_clone_22px.png", ":/vm_clone_16px.png",
    431501        ":/vm_clone_disabled_22px.png", ":/vm_clone_disabled_16px.png"));
    432 
     502    /* Setup action shortcuts: */
    433503    mRestoreSnapshotAction->setShortcut (QString ("Ctrl+Shift+R"));
    434504    mDeleteSnapshotAction->setShortcut (QString ("Ctrl+Shift+D"));
     
    437507    mCloneSnapshotAction->setShortcut(QString ("Ctrl+Shift+C"));
    438508
     509    /* Setup timer: */
    439510    mAgeUpdateTimer.setSingleShot (true);
    440511
    441     /* Setup connections */
     512    /* Setup tree-widget connections: */
    442513    connect (mTreeWidget, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
    443514             this, SLOT (onCurrentChanged (QTreeWidgetItem*)));
     
    448519    connect(mTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    449520            this, SLOT (sltItemDoubleClicked(QTreeWidgetItem*)));
    450 
     521    /* Setup snapshot operation connections: */
    451522    connect (mTakeSnapshotAction, SIGNAL (triggered()), this, SLOT (sltTakeSnapshot()));
    452523    connect (mRestoreSnapshotAction, SIGNAL (triggered()), this, SLOT (sltRestoreSnapshot()));
     
    454525    connect (mShowSnapshotDetailsAction, SIGNAL (triggered()), this, SLOT (sltShowSnapshotDetails()));
    455526    connect (mCloneSnapshotAction, SIGNAL(triggered()), this, SLOT(sltCloneSnapshot()));
    456 
     527    /* Setup Main event connections: */
    457528    connect (gVBoxEvents, SIGNAL(sigMachineDataChange(QString)),
    458529             this, SLOT(machineDataChanged(QString)));
     
    461532    connect (gVBoxEvents, SIGNAL(sigSessionStateChange(QString, KSessionState)),
    462533             this, SLOT(sessionStateChanged(QString, KSessionState)));
    463 
     534    /* Setup timer event connections: */
    464535    connect (&mAgeUpdateTimer, SIGNAL (timeout()), this, SLOT (updateSnapshotsAge()));
    465536
     537    /* Translate finally: */
    466538    retranslateUi();
    467539}
     
    469541void UISnapshotPane::setMachine (const CMachine &aMachine)
    470542{
     543    /* Cache passed machine: */
    471544    mMachine = aMachine;
    472545
     546    /* Cache machine details: */
    473547    if (aMachine.isNull())
    474548    {
     
    484558    }
    485559
     560    /* Refresh everything: */
    486561    refreshAll();
    487562}
     
    492567    Ui::UISnapshotPane::retranslateUi(this);
    493568
     569    /* Translate actions names: */
    494570    mRestoreSnapshotAction->setText(tr("&Restore Snapshot"));
    495571    mDeleteSnapshotAction->setText(tr("&Delete Snapshot"));
     
    497573    mTakeSnapshotAction->setText(tr("Take &Snapshot"));
    498574    mCloneSnapshotAction->setText(tr("&Clone..."));
    499 
     575    /* Translate actions status-tips: */
    500576    mRestoreSnapshotAction->setStatusTip(tr("Restore selected snapshot of the virtual machine"));
    501577    mDeleteSnapshotAction->setStatusTip(tr("Delete selected snapshot of the virtual machine"));
     
    503579    mTakeSnapshotAction->setStatusTip(tr("Take a snapshot of the current virtual machine state"));
    504580    mCloneSnapshotAction->setStatusTip(tr("Clone selected virtual machine"));
    505 
     581    /* Translate actions tool-tips: */
    506582    mRestoreSnapshotAction->setToolTip(mRestoreSnapshotAction->statusTip() +
    507583        QString(" (%1)").arg(mRestoreSnapshotAction->shortcut().toString()));
     
    527603    }
    528604
    529     /* Whether another direct session is open or not */
     605    /* Whether another direct session is open or not: */
    530606    bool busy = mSessionState != KSessionState_Unlocked;
    531607
    532     /* Machine state of the current state item */
     608    /* Acquire machine state of the "current state" item: */
    533609    KMachineState s = KMachineState_Null;
    534610    if (curStateItem())
    535611        s = curStateItem()->getCurrentState();
    536612
    537     /* Whether taking or deleting snapshots is possible right now */
     613    /* Whether taking or deleting snapshots is possible right now: */
    538614    bool canTakeDeleteSnapshot =    !busy
    539615                                 || s == KMachineState_PoweredOff
     
    543619                                 || s == KMachineState_Paused;
    544620
    545     /* Enable/disable restoring snapshot */
     621    /* Enable/disable snapshot operations: */
    546622    mRestoreSnapshotAction->setEnabled (!busy && mCurSnapshotItem && item && !item->isCurrentStateItem());
    547 
    548     /* Enable/disable deleting snapshot */
    549623    mDeleteSnapshotAction->setEnabled (m_fShapshotOperationsAllowed &&
    550624                                       canTakeDeleteSnapshot && mCurSnapshotItem && item && !item->isCurrentStateItem());
    551 
    552     /* Enable/disable the details action regardless of the session state */
    553625    mShowSnapshotDetailsAction->setEnabled (mCurSnapshotItem && item && !item->isCurrentStateItem());
    554 
    555     /* Enable/disable taking snapshots */
    556626    mTakeSnapshotAction->setEnabled (m_fShapshotOperationsAllowed &&
    557627                                     ((canTakeDeleteSnapshot && mCurSnapshotItem && item && item->isCurrentStateItem()) ||
    558628                                      (item && !mCurSnapshotItem)));
    559 
    560     /* Enable/disable cloning snapshots */
    561629    mCloneSnapshotAction->setEnabled(!busy && item);
    562630}
     
    564632void UISnapshotPane::onContextMenuRequested (const QPoint &aPoint)
    565633{
     634    /* Search for corresponding snapshot item: */
    566635    QTreeWidgetItem *item = mTreeWidget->itemAt (aPoint);
    567636    SnapshotWgtItem *snapshotItem = item ? static_cast <SnapshotWgtItem*> (item) : 0;
     
    569638        return;
    570639
     640    /* Prepare menu: */
    571641    QMenu menu;
    572 
     642    /* For snapshot item: */
    573643    if (mCurSnapshotItem && !snapshotItem->isCurrentStateItem())
    574644    {
     
    579649        menu.addAction(mCloneSnapshotAction);
    580650    }
     651    /* For "current state" item: */
    581652    else
    582653    {
     
    586657    }
    587658
     659    /* Show menu: */
    588660    menu.exec (mTreeWidget->viewport()->mapToGlobal (aPoint));
    589661}
     
    591663void UISnapshotPane::onItemChanged (QTreeWidgetItem *aItem)
    592664{
     665    /* Make sure nothing is being edited currently: */
    593666    if (mEditProtector)
    594667        return;
    595668
     669    /* Make sure snapshot item was changed: */
    596670    SnapshotWgtItem *item = aItem ? static_cast <SnapshotWgtItem*> (aItem) : 0;
    597671
    598672    if (item)
    599673    {
     674        /* Rename corresponding snapshot: */
    600675        CSnapshot snap = item->snapshotId().isNull()    ? CSnapshot() : mMachine.FindSnapshot(item->snapshotId());
    601676        if (!snap.isNull() && snap.isOk() && snap.GetName() != item->text (0))
     
    606681void UISnapshotPane::sltItemDoubleClicked(QTreeWidgetItem *pItem)
    607682{
    608     /* Make sure *nothing* is being edited currently: */
     683    /* Make sure nothing is being edited currently: */
    609684    if (mEditProtector)
    610685        return;
    611686
    612     /* Make sure some *valid* item was *really* double-clicked: */
     687    /* Make sure snapshot item was double-clicked: */
    613688    SnapshotWgtItem *pValidItem = pItem ? static_cast<SnapshotWgtItem*>(pItem) : 0;
    614689    if (!pValidItem)
     
    618693    if (QApplication::keyboardModifiers() == Qt::ControlModifier)
    619694    {
    620         /* As call for snapshot-restore procedure: */
     695        /* As snapshot-restore procedure: */
    621696        sltRestoreSnapshot(true /* suppress non-critical warnings */);
    622697    }
     
    633708    SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0;
    634709    AssertReturn(pItem, (void)0);
     710
    635711    /* Detemine snapshot id: */
    636712    QString strSnapshotId = pItem->snapshotId();
     
    680756void UISnapshotPane::sltDeleteSnapshot()
    681757{
     758    /* Get currently chosen item: */
    682759    SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
    683760        static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());
    684761    AssertReturn (item, (void) 0);
    685762
     763    /* Detemine snapshot id: */
    686764    QString snapId = item->snapshotId();
    687765    AssertReturn (!snapId.isNull(), (void) 0);
     766    /* Get currently desired snapshot: */
    688767    CSnapshot snapshot = mMachine.FindSnapshot(snapId);
    689768
     769    /* Confirm snapshot removal: */
    690770    if (!msgCenter().confirmSnapshotRemoval(snapshot.GetName()))
    691771        return;
     
    700780#endif
    701781
    702     /* Open a direct session (this call will handle all errors) */
     782    /* Open a session (this call will handle all errors): */
    703783    bool busy = mSessionState != KSessionState_Unlocked;
    704784    CSession session;
     
    715795    if (machine.isOk())
    716796    {
    717         /* Show the progress dialog */
    718797        msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_discard_90px.png");
    719 
    720798        if (progress.GetResultCode() != 0)
    721799            msgCenter().cannotRemoveSnapshot(progress,  snapshot.GetName(), mMachine.GetName());
     
    724802        msgCenter().cannotRemoveSnapshot(machine,  snapshot.GetName(), mMachine.GetName());
    725803
     804    /* Unlock machine finally: */
    726805    session.UnlockMachine();
    727806}
     
    729808void UISnapshotPane::sltShowSnapshotDetails()
    730809{
     810    /* Get currently chosen item: */
    731811    SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
    732812        static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());
    733813    AssertReturn (item, (void) 0);
    734814
     815    /* Get desired snapshot: */
    735816    CSnapshot snap = item->snapshot();
    736817    AssertReturn (!snap.isNull(), (void) 0);
     
    738819    CMachine snapMachine = snap.GetMachine();
    739820
     821    /* Show Snapshot Details dialog: */
    740822    VBoxSnapshotDetailsDlg dlg (this);
    741823    dlg.getFromSnapshot (snap);
     
    747829void UISnapshotPane::sltCloneSnapshot()
    748830{
     831    /* Get currently chosen item: */
    749832    SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
    750833        static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());
    751834    AssertReturn (item, (void) 0);
    752835
     836    /* Get desired machine/snapshot: */
    753837    CMachine machine;
    754838    CSnapshot snapshot;
     
    773857void UISnapshotPane::machineDataChanged(QString strId)
    774858{
     859    /* Prevent snapshot editing in the meantime: */
    775860    SnapshotEditBlocker guardBlock (mEditProtector);
    776861
     862    /* Make sure it's our VM: */
    777863    if (strId != mMachineId)
    778864        return;
    779865
     866    /* Recache state current item: */
    780867    curStateItem()->recache();
    781868}
     
    783870void UISnapshotPane::machineStateChanged(QString strId, KMachineState state)
    784871{
     872    /* Prevent snapshot editing in the meantime: */
    785873    SnapshotEditBlocker guardBlock (mEditProtector);
    786874
     875    /* Make sure it's our VM: */
    787876    if (strId != mMachineId)
    788877        return;
    789878
     879    /* Recache new machine state: */
    790880    curStateItem()->recache();
    791881    curStateItem()->updateCurrentState(state);
     
    794884void UISnapshotPane::sessionStateChanged(QString strId, KSessionState state)
    795885{
     886    /* Prevent snapshot editing in the meantime: */
    796887    SnapshotEditBlocker guardBlock (mEditProtector);
    797888
     889    /* Make sure it's our VM: */
    798890    if (strId != mMachineId)
    799891        return;
    800892
     893    /* Recache new session state: */
    801894    mSessionState = state;
    802895    onCurrentChanged (mTreeWidget->currentItem());
     
    805898void UISnapshotPane::updateSnapshotsAge()
    806899{
     900    /* Stop timer if active: */
    807901    if (mAgeUpdateTimer.isActive())
    808902        mAgeUpdateTimer.stop();
    809903
     904    /* Search for smallest snapshot age to optimize timer timeout: */
    810905    SnapshotAgeFormat age = traverseSnapshotAge (mTreeWidget->invisibleRootItem());
    811 
    812906    switch (age)
    813907    {
     
    829923    }
    830924
     925    /* Restart timer if necessary: */
    831926    if (mAgeUpdateTimer.interval() > 0)
    832927        mAgeUpdateTimer.start();
     
    842937    AssertReturn(pItem, (bool)0);
    843938
    844     /* Open a session to work with corresponding VM: */
     939    /* Open a session (this call will handle all errors): */
    845940    CSession session;
    846941    if (mSessionState != KSessionState_Unlocked)
     
    860955        windowManager().registerNewParent(pDlg, pDlgParent);
    861956
    862         /* Assign corresponding icon: */
     957        // TODO: Assign corresponding icon through sub-dialog API: */
    863958        pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(mMachine.GetOSTypeId()));
    864959
     
    876971            ++iterator;
    877972        }
     973        // TODO: Assign corresponding snapshot name through sub-dialog API: */
    878974        pDlg->mLeName->setText(snapShotName.arg(iMaxSnapShotIndex + 1));
    879975
    880         /* Exec the dialog: */
     976        /* Show Take Snapshot dialog: */
    881977        bool fDialogAccepted = pDlg->exec() == QDialog::Accepted;
    882978
     
    884980        if (pDlg)
    885981        {
    886             /* Acquire variables: */
     982            /* Acquire snapshot name/description: */
    887983            QString strSnapshotName = pDlg->mLeName->text().trimmed();
    888984            QString strSnapshotDescription = pDlg->mTeDescription->toPlainText();
     
    894990            if (fDialogAccepted)
    895991            {
     992                /* Take snapshot: */
    896993                QString strSnapshotId;
    897                 /* Prepare the take-snapshot progress: */
    898994                CProgress progress = machine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotId);
    899995                if (machine.isOk())
    900996                {
    901                     /* Show the take-snapshot progress: */
    902997                    msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png");
    903998                    if (!progress.isOk() || progress.GetResultCode() != 0)
     
    9291024void UISnapshotPane::refreshAll()
    9301025{
     1026    /* Prevent snapshot editing in the meantime: */
    9311027    SnapshotEditBlocker guardBlock (mEditProtector);
    9321028
     1029    /* If VM is null, just updated the current itm: */
    9331030    if (mMachine.isNull())
    9341031    {
     
    9371034    }
    9381035
     1036    /* Remember the selected item and it's first child: */
    9391037    QString selectedItem, firstChildOfSelectedItem;
    9401038    SnapshotWgtItem *cur = !mTreeWidget->currentItem() ? 0 :
     
    9471045    }
    9481046
     1047    /* Clear the tree: */
    9491048    mTreeWidget->clear();
    9501049
    951     /* Get the first snapshot */
     1050    /* If machine has snapshots: */
    9521051    if (mMachine.GetSnapshotCount() > 0)
    9531052    {
     1053        /* Get the first snapshot: */
    9541054        CSnapshot snapshot = mMachine.FindSnapshot(QString::null);
    9551055
     1056        /* Populate snapshot tree: */
    9561057        populateSnapshots (snapshot, 0);
     1058        /* And make sure it has current snapshot item: */
    9571059        Assert (mCurSnapshotItem);
    9581060
    959         /* Add the "current state" item */
     1061        /* Add the "current state" item as a child to current snapshot item: */
    9601062        SnapshotWgtItem *csi = new SnapshotWgtItem(this, mCurSnapshotItem, mMachine);
    9611063        csi->setBold (true);
    9621064        csi->recache();
    9631065
     1066        /* Search for a previously selected item: */
    9641067        SnapshotWgtItem *cur = findItem (selectedItem);
    9651068        if (cur == 0)
     
    9681071            cur = curStateItem();
    9691072
     1073        /* Choose current item: */
    9701074        mTreeWidget->scrollToItem (cur);
    9711075        mTreeWidget->setCurrentItem (cur);
    9721076        onCurrentChanged (cur);
    9731077    }
     1078    /* If machine has no snapshots: */
    9741079    else
    9751080    {
     1081        /* There is no current snapshot item: */
    9761082        mCurSnapshotItem = 0;
    9771083
    978         /* Add the "current state" item */
     1084        /* Add the "current state" item as a child of tree-widget: */
    9791085        SnapshotWgtItem *csi = new SnapshotWgtItem(this, mTreeWidget, mMachine);
    9801086        csi->setBold (true);
    9811087        csi->recache();
    9821088
     1089        /* Choose current item: */
    9831090        mTreeWidget->setCurrentItem (csi);
    9841091        onCurrentChanged (csi);
    9851092    }
    9861093
    987     /* Updating age */
     1094    /* Update age: */
    9881095    updateSnapshotsAge();
    9891096
     1097    /* Adjust tree-widget: */
    9901098    mTreeWidget->resizeColumnToContents (0);
    9911099}
     
    9931101SnapshotWgtItem* UISnapshotPane::findItem (const QString &aSnapshotId)
    9941102{
     1103    /* Search for the first item with required ID: */
    9951104    QTreeWidgetItemIterator it (mTreeWidget);
    9961105    while (*it)
     
    10021111    }
    10031112
     1113    /* Null by default: */
    10041114    return 0;
    10051115}
     
    10071117SnapshotWgtItem *UISnapshotPane::curStateItem()
    10081118{
     1119    /* Last child of the current snapshot item if any or first child of invisible root item otherwise: */
    10091120    QTreeWidgetItem *csi = mCurSnapshotItem ?
    10101121                           mCurSnapshotItem->child (mCurSnapshotItem->childCount() - 1) :
     
    10151126void UISnapshotPane::populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem)
    10161127{
     1128    /* Create a child of passed item: */
    10171129    SnapshotWgtItem *item = aItem ? new SnapshotWgtItem(this, aItem, aSnapshot) :
    10181130                                    new SnapshotWgtItem(this, mTreeWidget, aSnapshot);
     1131    /* And recache it's content: */
    10191132    item->recache();
    10201133
     1134    /* Mark current snapshot item bold and remember it: */
    10211135    CSnapshot curSnapshot = mMachine.GetCurrentSnapshot();
    10221136    if (!curSnapshot.isNull() && curSnapshot.GetId() == aSnapshot.GetId())
     
    10261140    }
    10271141
     1142    /* Walk through the children recursively: */
    10281143    CSnapshotVector snapshots = aSnapshot.GetChildren();
    10291144    foreach (const CSnapshot &snapshot, snapshots)
    10301145        populateSnapshots (snapshot, item);
    10311146
     1147    /* Expand the newly created item: */
    10321148    item->setExpanded (true);
     1149    /* And mark it as editable: */
    10331150    item->setFlags (item->flags() | Qt::ItemIsEditable);
    10341151}
     
    10361153SnapshotAgeFormat UISnapshotPane::traverseSnapshotAge (QTreeWidgetItem *aParentItem)
    10371154{
     1155    /* Make sure passed root is of valid type: */
    10381156    SnapshotWgtItem *parentItem = aParentItem->type() == SnapshotWgtItem::ItemType ?
    10391157                                  static_cast <SnapshotWgtItem*> (aParentItem) : 0;
    10401158
     1159    /* Fetch the snapshot age of the root if it's valid: */
    10411160    SnapshotAgeFormat age = parentItem ? parentItem->updateAge() : AgeMax;
     1161
     1162    /* Walk through the children recursively: */
    10421163    for (int i = 0; i < aParentItem->childCount(); ++ i)
    10431164    {
     1165        /* Fetch the smallest snapshot age of the children: */
    10441166        SnapshotAgeFormat newAge = traverseSnapshotAge (aParentItem->child (i));
     1167        /* Remember the smallest snapshot age among existing: */
    10451168        age = newAge < age ? newAge : age;
    10461169    }
    10471170
     1171    /* Return result: */
    10481172    return age;
    10491173}
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h

    r63804 r63818  
    1616 */
    1717
    18 #ifndef __UISnapshotPane_h__
    19 #define __UISnapshotPane_h__
     18#ifndef ___UISnapshotPane_h___
     19#define ___UISnapshotPane_h___
    2020
    2121/* Qt includes: */
     
    3131#include "CMachine.h"
    3232
    33 /* Local forwards */
     33/* Forward declarations: */
    3434class SnapshotWgtItem;
    3535
    36 /* Snapshot age format */
     36
     37/** Snapshot age format. */
    3738enum SnapshotAgeFormat
    3839{
     
    4445};
    4546
     47
     48/** QWidget extension providing GUI with the pane to control snapshot related functionality. */
    4649class UISnapshotPane : public QIWithRetranslateUI <QWidget>, public Ui::UISnapshotPane
    4750{
     
    5053public:
    5154
     55    /** Constructs snapshot pane passing @a aParent to the base-class. */
    5256    UISnapshotPane(QWidget *aParent);
    5357
     58    /** Defines the @a aMachine to be parsed. */
    5459    void setMachine (const CMachine &aMachine);
    5560
     
    5964protected:
    6065
     66    /** Handles translation event. */
    6167    void retranslateUi();
    6268
    6369private slots:
    6470
    65     /* Snapshot tree slots: */
    66     void onCurrentChanged (QTreeWidgetItem *aItem = 0);
    67     void onContextMenuRequested (const QPoint &aPoint);
    68     void onItemChanged (QTreeWidgetItem *aItem);
    69     void sltItemDoubleClicked(QTreeWidgetItem *pItem);
     71    /** @name Tree-view handlers
     72      * @{ */
     73        /** Handles cursor change to @a aItem. */
     74        void onCurrentChanged (QTreeWidgetItem *aItem = 0);
     75        /** Handles context menu request for @a aPoint. */
     76        void onContextMenuRequested (const QPoint &aPoint);
     77        /** Handles modification for @a aItem. */
     78        void onItemChanged (QTreeWidgetItem *aItem);
     79        /** Handles double-click for @a pItem. */
     80        void sltItemDoubleClicked(QTreeWidgetItem *pItem);
     81    /** @} */
    7082
    71     /* Snapshot functionality slots: */
    72     void sltTakeSnapshot();
    73     void sltRestoreSnapshot(bool fSuppressNonCriticalWarnings = false);
    74     void sltDeleteSnapshot();
    75     void sltShowSnapshotDetails();
    76     void sltCloneSnapshot();
     83    /** @name Snapshot operations
     84      * @{ */
     85        /** Proposes to take a snapshot. */
     86        void sltTakeSnapshot();
     87        /** Proposes to restore the snapshot. */
     88        void sltRestoreSnapshot(bool fSuppressNonCriticalWarnings = false);
     89        /** Proposes to delete the snapshot. */
     90        void sltDeleteSnapshot();
     91        /** Displays the snapshot details dialog. */
     92        void sltShowSnapshotDetails();
     93        /** Proposes to clone the snapshot. */
     94        void sltCloneSnapshot();
     95    /** @} */
    7796
    78     /* Main API event handlers: */
    79     void machineDataChanged(QString strId);
    80     void machineStateChanged(QString strId, KMachineState state);
    81     void sessionStateChanged(QString strId, KSessionState state);
     97    /** @name Main event handlers
     98      * @{ */
     99        /** Handles machine data change for machine with @a strId. */
     100        void machineDataChanged(QString strId);
     101        /** Handles machine @a state change for machine with @a strId. */
     102        void machineStateChanged(QString strId, KMachineState state);
     103        /** Handles session @a state change for machine with @a strId. */
     104        void sessionStateChanged(QString strId, KSessionState state);
     105    /** @} */
    82106
    83     void updateSnapshotsAge();
     107    /** @name Timer event handlers
     108      * @{ */
     109        /** Updates snapshots age. */
     110        void updateSnapshotsAge();
     111    /** @} */
    84112
    85113private:
    86114
    87     /* Snapshot private functions: */
    88     bool takeSnapshot();
    89     //bool restoreSnapshot();
    90     //bool deleteSnapshot();
    91     //bool showSnapshotDetails();
     115    /** @name Snapshot operations
     116      * @{ */
     117        /** Proposes to take a snapshot. */
     118        bool takeSnapshot();
     119        /** Proposes to restore the snapshot. */
     120        //bool restoreSnapshot();
     121        /** Proposes to delete the snapshot. */
     122        //bool deleteSnapshot();
     123        /** Displays the snapshot details dialog. */
     124        //bool showSnapshotDetails();
     125        /** Proposes to clone the snapshot. */
     126        //bool cloneSnapshot();
     127    /** @} */
    92128
     129    /** Refreshes everything. */
    93130    void refreshAll();
     131
     132    /** Searches for an item with corresponding @a aSnapshotId. */
    94133    SnapshotWgtItem* findItem (const QString &aSnapshotId);
     134    /** Returns the "current state" item. */
    95135    SnapshotWgtItem* curStateItem();
     136
     137    /** Populates snapshot items for corresponding @a aSnapshot using @a aItem as parent. */
    96138    void populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem);
     139
     140    /** Searches for smallest snapshot age starting with @a aParentItem as parent. */
    97141    SnapshotAgeFormat traverseSnapshotAge (QTreeWidgetItem *aParentItem);
    98142
     143    /** Holds the machine COM wrapper. */
    99144    CMachine         mMachine;
     145    /** Holds the machine ID. */
    100146    QString          mMachineId;
     147    /** Holds the cached session state. */
    101148    KSessionState    mSessionState;
     149    /** Holds the current snapshot item reference. */
    102150    SnapshotWgtItem *mCurSnapshotItem;
     151    /** Holds the snapshot item editing protector. */
    103152    bool             mEditProtector;
    104153
     154    /** Holds the snapshot item action group instance. */
    105155    QActionGroup    *mSnapshotActionGroup;
     156    /** Holds the current item action group instance. */
    106157    QActionGroup    *mCurStateActionGroup;
    107158
     159    /** Holds the snapshot restore action instance. */
    108160    QAction         *mRestoreSnapshotAction;
     161    /** Holds the snapshot delete action instance. */
    109162    QAction         *mDeleteSnapshotAction;
     163    /** Holds the show snapshot details action instance. */
    110164    QAction         *mShowSnapshotDetailsAction;
     165    /** Holds the snapshot take action instance. */
    111166    QAction         *mTakeSnapshotAction;
     167    /** Holds the snapshot clone action instance. */
    112168    QAction         *mCloneSnapshotAction;
    113169
    114     QTimer          mAgeUpdateTimer;
     170    /** Holds the snapshot age update timer. */
     171    QTimer           mAgeUpdateTimer;
    115172
    116     bool            m_fShapshotOperationsAllowed;
     173    /** Holds whether the snapshot operations are allowed. */
     174    bool             m_fShapshotOperationsAllowed;
    117175
    118     /** Pointer to cached snapshot-item pixmap for 'offline' state. */
    119     QIcon           m_offlineSnapshotIcon;
    120     /** Pointer to cached snapshot-item pixmap for 'online' state. */
    121     QIcon           m_onlineSnapshotIcon;
     176    /** Holds the cached snapshot-item pixmap for 'offline' state. */
     177    QIcon            m_offlineSnapshotIcon;
     178    /** Holds the cached snapshot-item pixmap for 'online' state. */
     179    QIcon            m_onlineSnapshotIcon;
    122180};
    123181
    124 #endif // __UISnapshotPane_h__
     182#endif /* !___UISnapshotPane_h___ */
     183
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