VirtualBox

Changeset 67160 in vbox for trunk


Ignore:
Timestamp:
May 31, 2017 9:44:38 AM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Selector UI: Tools pane: Snapshot pane: Rework details dialog to be widget similarly to Host Network Manager has.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
7 edited
8 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc

    r67068 r67160  
    136136        <file alias="site_oracle_16px.png">images/site_oracle_16px.png</file>
    137137        <file alias="site_warning_16px.png">images/site_warning_16px.png</file>
     138        <file alias="snapshot_commit_details_16px.png">images/snapshot_commit_details_16px.png</file>
     139        <file alias="snapshot_commit_details_22px.png">images/snapshot_commit_details_22px.png</file>
     140        <file alias="snapshot_commit_details_disabled_16px.png">images/snapshot_commit_details_disabled_16px.png</file>
     141        <file alias="snapshot_commit_details_disabled_22px.png">images/snapshot_commit_details_disabled_22px.png</file>
    138142        <file alias="snapshot_delete_16px.png">images/snapshot_delete_16px.png</file>
    139143        <file alias="snapshot_delete_22px.png">images/snapshot_delete_22px.png</file>
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox2_hidpi.qrc

    r67068 r67160  
    145145        <file alias="site_oracle_16px_hidpi.png">images/hidpi/site_oracle_16px_hidpi.png</file>
    146146        <file alias="site_warning_16px_hidpi.png">images/hidpi/site_warning_16px_hidpi.png</file>
    147         <file alias="snapshot_manager_16px_hidpi.png">images/hidpi/snapshot_manager_16px_hidpi.png</file>
    148         <file alias="snapshot_manager_22px_hidpi.png">images/hidpi/snapshot_manager_22px_hidpi.png</file>
     147        <file alias="snapshot_commit_details_16px_hidpi.png">images/hidpi/snapshot_commit_details_16px_hidpi.png</file>
     148        <file alias="snapshot_commit_details_22px_hidpi.png">images/hidpi/snapshot_commit_details_22px_hidpi.png</file>
     149        <file alias="snapshot_commit_details_disabled_16px_hidpi.png">images/hidpi/snapshot_commit_details_disabled_16px_hidpi.png</file>
     150        <file alias="snapshot_commit_details_disabled_22px_hidpi.png">images/hidpi/snapshot_commit_details_disabled_22px_hidpi.png</file>
    149151        <file alias="snapshot_delete_16px_hidpi.png">images/hidpi/snapshot_delete_16px_hidpi.png</file>
    150152        <file alias="snapshot_delete_22px_hidpi.png">images/hidpi/snapshot_delete_22px_hidpi.png</file>
    151153        <file alias="snapshot_delete_disabled_16px_hidpi.png">images/hidpi/snapshot_delete_disabled_16px_hidpi.png</file>
    152154        <file alias="snapshot_delete_disabled_22px_hidpi.png">images/hidpi/snapshot_delete_disabled_22px_hidpi.png</file>
     155        <file alias="snapshot_manager_16px_hidpi.png">images/hidpi/snapshot_manager_16px_hidpi.png</file>
     156        <file alias="snapshot_manager_22px_hidpi.png">images/hidpi/snapshot_manager_22px_hidpi.png</file>
    153157        <file alias="snapshot_offline_16px_hidpi.png">images/hidpi/snapshot_offline_16px_hidpi.png</file>
    154158        <file alias="snapshot_online_16px_hidpi.png">images/hidpi/snapshot_online_16px_hidpi.png</file>
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp

    r67147 r67160  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VBoxSnapshotDetailsDlg class implementation.
     3 * VBox Qt GUI - UISnapshotDetailsWidget class implementation.
    44 */
    55
     
    256256
    257257/*********************************************************************************************************************************
    258 *   Class VBoxSnapshotDetailsDlg implementation.                                                                                 *
     258*   Class UISnapshotDetailsWidget implementation.                                                                                *
    259259*********************************************************************************************************************************/
    260260
    261 VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg(QWidget *pParent /* = 0 */)
    262     : QIWithRetranslateUI<QDialog>(pParent)
     261UISnapshotDetailsWidget::UISnapshotDetailsWidget(QWidget *pParent /* = 0 */)
     262    : QIWithRetranslateUI<QWidget>(pParent)
    263263{
    264264    /* Prepare: */
     
    266266}
    267267
    268 void VBoxSnapshotDetailsDlg::setData(const UIDataSnapshot &data, const CSnapshot &comSnapshot)
     268void UISnapshotDetailsWidget::setData(const UIDataSnapshot &data, const CSnapshot &comSnapshot)
    269269{
    270270    /* Cache old/new data: */
     
    275275    m_comSnapshot = comSnapshot;
    276276
    277     /* Load general snapshot properties: */
    278     mLeName->setText(m_newData.m_strName);
    279     mTeDescription->setText(m_newData.m_strDescription);
    280 
    281     /* If there is really a snapshot: */
    282     if (m_comSnapshot.isNotNull())
    283     {
    284         /* Calculate snapshot timestamp info: */
    285         QDateTime timestamp;
    286         timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000);
    287         bool fDateTimeToday = timestamp.date() == QDate::currentDate();
    288         QString dateTime = fDateTimeToday ? timestamp.time().toString(Qt::LocalDate) : timestamp.toString(Qt::LocalDate);
    289         mTxTaken->setText(dateTime);
    290 
    291         /* Read snapshot display contents: */
    292         CMachine comMachine = m_comSnapshot.GetMachine();
    293         ULONG iWidth = 0, iHeight = 0;
    294 
    295         /* Get thumbnail if present: */
    296         QVector<BYTE> thumbData = comMachine.ReadSavedThumbnailToArray(0, KBitmapFormat_BGR0, iWidth, iHeight);
    297         m_pixmapThumbnail = thumbData.size() != 0 ? QPixmap::fromImage(QImage(thumbData.data(),
    298                                                                               iWidth, iHeight,
    299                                                                               QImage::Format_RGB32).copy())
    300                                                   : QPixmap();
    301 
    302         /* Get screenshot if present: */
    303         QVector<BYTE> screenData = comMachine.ReadSavedScreenshotToArray(0, KBitmapFormat_PNG, iWidth, iHeight);
    304         m_pixmapScreenshot = screenData.size() != 0 ? QPixmap::fromImage(QImage::fromData(screenData.data(),
    305                                                                                           screenData.size(),
    306                                                                                           "PNG"))
    307                                                     : QPixmap();
    308 
    309         // TODO: Check whether layout manipulations are really
    310         //       necessary, they looks a bit dangerous to me..
    311         QGridLayout *pLayout = qobject_cast<QGridLayout*>(layout());
    312         AssertPtrReturnVoid(pLayout);
    313         if (m_pixmapThumbnail.isNull())
    314         {
    315             pLayout->removeWidget(mLbThumbnail);
    316             mLbThumbnail->setHidden(true);
    317 
    318             pLayout->removeWidget(mLeName);
    319             pLayout->removeWidget(mTxTaken);
    320             pLayout->addWidget(mLeName, 0, 1, 1, 2);
    321             pLayout->addWidget(mTxTaken, 1, 1, 1, 2);
    322         }
    323         else
    324         {
    325             pLayout->removeWidget(mLeName);
    326             pLayout->removeWidget(mTxTaken);
    327             pLayout->addWidget(mLeName, 0, 1);
    328             pLayout->addWidget(mTxTaken, 1, 1);
    329 
    330             pLayout->removeWidget(mLbThumbnail);
    331             pLayout->addWidget(mLbThumbnail, 0, 2, 2, 1);
    332             mLbThumbnail->setHidden(false);
    333         }
    334     }
    335     else
    336     {
    337         /* Clear snapshot timestamp info: */
    338         mTxTaken->clear();
    339 
    340         // TODO: Check whether layout manipulations are really
    341         //       necessary, they looks a bit dangerous to me..
    342         QGridLayout *pLayout = qobject_cast<QGridLayout*>(layout());
    343         AssertPtrReturnVoid(pLayout);
    344         {
    345             pLayout->removeWidget(mLbThumbnail);
    346             mLbThumbnail->setHidden(true);
    347 
    348             pLayout->removeWidget(mLeName);
    349             pLayout->removeWidget(mTxTaken);
    350             pLayout->addWidget(mLeName, 0, 1, 1, 2);
    351             pLayout->addWidget(mTxTaken, 1, 1, 1, 2);
    352         }
    353     }
    354 
    355     /* Retranslate: */
    356     retranslateUi();
    357 }
    358 
    359 void VBoxSnapshotDetailsDlg::saveData()
    360 {
    361     /* Make sure there is a snapshot: */
    362     AssertReturnVoid(m_comSnapshot.isNotNull());
    363 
    364     /* We need a session when we manipulate the snapshot data of a machine. */
    365     CSession comSession = vboxGlobal().openExistingSession(m_comSnapshot.GetMachine().GetId());
    366     if (comSession.isNull())
    367         return;
    368 
    369     /* Save snapshot name: */
    370     m_comSnapshot.SetName(m_newData.m_strName);
    371     /* Save snapshot description: */
    372     m_comSnapshot.SetDescription(m_newData.m_strDescription);
    373 
    374     /* Close the session again. */
    375     comSession.UnlockMachine();
    376 }
    377 
    378 bool VBoxSnapshotDetailsDlg::eventFilter(QObject *pObject, QEvent *pEvent)
     277    /* Load snapshot data: */
     278    loadSnapshotData();
     279}
     280
     281void UISnapshotDetailsWidget::clearData()
     282{
     283    /* Reset old/new data: */
     284    m_oldData = UIDataSnapshot();
     285    m_newData = m_oldData;
     286
     287    /* Reset snapshot: */
     288    m_comSnapshot = CSnapshot();
     289
     290    /* Load snapshot data: */
     291    loadSnapshotData();
     292}
     293
     294bool UISnapshotDetailsWidget::eventFilter(QObject *pObject, QEvent *pEvent)
    379295{
    380296    /* We have filter for thumbnail label only: */
     
    394310
    395311    /* Call to base-class: */
    396     return QDialog::eventFilter(pObject, pEvent);
    397 }
    398 
    399 void VBoxSnapshotDetailsDlg::retranslateUi()
     312    return QWidget::eventFilter(pObject, pEvent);
     313}
     314
     315void UISnapshotDetailsWidget::retranslateUi()
    400316{
    401317    /* Translate uic generated strings: */
     
    424340}
    425341
    426 void VBoxSnapshotDetailsDlg::showEvent(QShowEvent *pEvent)
     342void UISnapshotDetailsWidget::showEvent(QShowEvent *pEvent)
    427343{
    428344    /* Call to base-class: */
    429     QIWithRetranslateUI<QDialog>::showEvent(pEvent);
     345    QIWithRetranslateUI<QWidget>::showEvent(pEvent);
    430346
    431347    /* Make sure we should polish dialog: */
     
    440356}
    441357
    442 void VBoxSnapshotDetailsDlg::polishEvent(QShowEvent * /* pEvent */)
     358void UISnapshotDetailsWidget::polishEvent(QShowEvent * /* pEvent */)
    443359{
    444360    /* If we haven't assigned the thumbnail yet, do it now: */
     
    453369}
    454370
    455 void VBoxSnapshotDetailsDlg::sltHandleNameChange(const QString &strName)
    456 {
    457     /* Recache snapshot name: */
    458     m_newData.m_strName = strName;
    459     /* Perform snapshot name sanity check: */
    460     mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!strName.trimmed().isEmpty());
    461 }
    462 
    463 void VBoxSnapshotDetailsDlg::sltHandleDescriptionChange()
    464 {
    465     /* Recache snapshot description: */
     371void UISnapshotDetailsWidget::sltHandleNameChange()
     372{
     373    m_newData.m_strName = mLeName->text();
     374    //revalidate(m_pErrorPaneName);
     375    notify();
     376}
     377
     378void UISnapshotDetailsWidget::sltHandleDescriptionChange()
     379{
    466380    m_newData.m_strDescription = mTeDescription->toPlainText();
    467 }
    468 
    469 void VBoxSnapshotDetailsDlg::prepare()
     381    //revalidate(m_pErrorPaneName);
     382    notify();
     383}
     384
     385void UISnapshotDetailsWidget::prepare()
    470386{
    471387    /* Apply UI decorations: */
     
    479395            /* Configure editor: */
    480396            connect(mLeName, &QLineEdit::textChanged,
    481                     this, &VBoxSnapshotDetailsDlg::sltHandleNameChange);
     397                    this, &UISnapshotDetailsWidget::sltHandleNameChange);
    482398        }
    483399
     
    487403            /* Configure editor: */
    488404            connect(mTeDescription, &QTextEdit::textChanged,
    489                     this, &VBoxSnapshotDetailsDlg::sltHandleDescriptionChange);
     405                    this, &UISnapshotDetailsWidget::sltHandleDescriptionChange);
    490406        }
    491407
     
    508424}
    509425
     426void UISnapshotDetailsWidget::loadSnapshotData()
     427{
     428    /* Read general snapshot properties: */
     429    mLeName->setText(m_newData.m_strName);
     430    mTeDescription->setText(m_newData.m_strDescription);
     431
     432    /* If there is a snapshot: */
     433    if (m_comSnapshot.isNotNull())
     434    {
     435        /* Calculate snapshot timestamp info: */
     436        QDateTime timestamp;
     437        timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000);
     438        bool fDateTimeToday = timestamp.date() == QDate::currentDate();
     439        QString dateTime = fDateTimeToday ? timestamp.time().toString(Qt::LocalDate) : timestamp.toString(Qt::LocalDate);
     440        mTxTaken->setText(dateTime);
     441
     442        /* Read snapshot display contents: */
     443        CMachine comMachine = m_comSnapshot.GetMachine();
     444        ULONG iWidth = 0, iHeight = 0;
     445
     446        /* Get thumbnail if present: */
     447        QVector<BYTE> thumbData = comMachine.ReadSavedThumbnailToArray(0, KBitmapFormat_BGR0, iWidth, iHeight);
     448        m_pixmapThumbnail = thumbData.size() != 0 ? QPixmap::fromImage(QImage(thumbData.data(),
     449                                                                              iWidth, iHeight,
     450                                                                              QImage::Format_RGB32).copy())
     451                                                  : QPixmap();
     452
     453        /* Get screenshot if present: */
     454        QVector<BYTE> screenData = comMachine.ReadSavedScreenshotToArray(0, KBitmapFormat_PNG, iWidth, iHeight);
     455        m_pixmapScreenshot = screenData.size() != 0 ? QPixmap::fromImage(QImage::fromData(screenData.data(),
     456                                                                                          screenData.size(),
     457                                                                                          "PNG"))
     458                                                    : QPixmap();
     459
     460        // TODO: Check whether layout manipulations are really
     461        //       necessary, they looks a bit dangerous to me..
     462        QGridLayout *pLayout = qobject_cast<QGridLayout*>(layout());
     463        AssertPtrReturnVoid(pLayout);
     464        if (m_pixmapThumbnail.isNull())
     465        {
     466            pLayout->removeWidget(mLbThumbnail);
     467            mLbThumbnail->setHidden(true);
     468
     469            pLayout->removeWidget(mLeName);
     470            pLayout->removeWidget(mTxTaken);
     471            pLayout->addWidget(mLeName, 0, 1, 1, 2);
     472            pLayout->addWidget(mTxTaken, 1, 1, 1, 2);
     473        }
     474        else
     475        {
     476            pLayout->removeWidget(mLeName);
     477            pLayout->removeWidget(mTxTaken);
     478            pLayout->addWidget(mLeName, 0, 1);
     479            pLayout->addWidget(mTxTaken, 1, 1);
     480
     481            pLayout->removeWidget(mLbThumbnail);
     482            pLayout->addWidget(mLbThumbnail, 0, 2, 2, 1);
     483            mLbThumbnail->setHidden(false);
     484        }
     485    }
     486    else
     487    {
     488        /* Clear snapshot timestamp info: */
     489        mTxTaken->clear();
     490
     491        // TODO: Check whether layout manipulations are really
     492        //       necessary, they looks a bit dangerous to me..
     493        QGridLayout *pLayout = qobject_cast<QGridLayout*>(layout());
     494        AssertPtrReturnVoid(pLayout);
     495        {
     496            pLayout->removeWidget(mLbThumbnail);
     497            mLbThumbnail->setHidden(true);
     498
     499            pLayout->removeWidget(mLeName);
     500            pLayout->removeWidget(mTxTaken);
     501            pLayout->addWidget(mLeName, 0, 1, 1, 2);
     502            pLayout->addWidget(mTxTaken, 1, 1, 1, 2);
     503        }
     504    }
     505
     506    /* Retranslate: */
     507    retranslateUi();
     508}
     509
     510void UISnapshotDetailsWidget::notify()
     511{
     512//    if (m_oldData != m_newData)
     513//        printf("Snapshot: %s, %s\n",
     514//               m_newData.m_strName.toUtf8().constData(),
     515//               m_newData.m_strDescription.toUtf8().constData());
     516
     517    emit sigDataChanged(m_oldData != m_newData);
     518}
     519
    510520#include "VBoxSnapshotDetailsDlg.moc"
    511521
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.h

    r67147 r67160  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VBoxSnapshotDetailsDlg class declaration.
     3 * VBox Qt GUI - UISnapshotDetailsWidget class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef ___VBoxSnapshotDetailsDlg_h___
    19 #define ___VBoxSnapshotDetailsDlg_h___
     18#ifndef ___UISnapshotDetailsWidget_h___
     19#define ___UISnapshotDetailsWidget_h___
    2020
    2121/* GUI includes: */
     
    5757
    5858
    59 /** QDialog extension providing GUI with snapshot details dialog. */
    60 class VBoxSnapshotDetailsDlg : public QIWithRetranslateUI<QDialog>, public Ui::VBoxSnapshotDetailsDlg
     59/** QWidget extension providing GUI with snapshot details-widget. */
     60class UISnapshotDetailsWidget : public QIWithRetranslateUI<QWidget>, public Ui::VBoxSnapshotDetailsDlg
    6161{
    6262    Q_OBJECT;
    6363
     64signals:
     65
     66    /** Notifies listeners about data changed and whether it @a fDiffers. */
     67    void sigDataChanged(bool fDiffers);
     68
    6469public:
    6570
    66     /** Constructs snapshot details dialog passing @a pParent to the base-class. */
    67     VBoxSnapshotDetailsDlg(QWidget *pParent = 0);
     71    /** Constructs snapshot details-widget passing @a pParent to the base-class. */
     72    UISnapshotDetailsWidget(QWidget *pParent = 0);
    6873
     74    /** Returns the snapshot data. */
     75    const UIDataSnapshot &data() const { return m_newData; }
    6976    /** Defines the snapshot @a data. */
    7077    void setData(const UIDataSnapshot &data, const CSnapshot &comSnapshot);
    71     /** Saves the snapshot data. */
    72     void saveData();
     78    /** Clears the snapshot data. */
     79    void clearData();
    7380
    7481protected:
     
    8794private slots:
    8895
    89     /** Handles snapshot @a strName change. */
    90     void sltHandleNameChange(const QString &strName);
     96    /** Handles snapshot name change. */
     97    void sltHandleNameChange();
    9198    /** Handles snapshot description change. */
    9299    void sltHandleDescriptionChange();
     
    96103    /** Prepares all. */
    97104    void prepare();
     105
     106    /** Loads snapshot data. */
     107    void loadSnapshotData();
     108
     109    /** Notifies listeners about data changed or not. */
     110    void notify();
    98111
    99112    /** Holds whether this widget was polished. */
     
    114127};
    115128
    116 #endif /* !___VBoxSnapshotDetailsDlg_h___ */
     129#endif /* !___UISnapshotDetailsWidget_h___ */
    117130
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.ui

    r67067 r67160  
    1414 </comment>
    1515 <class>VBoxSnapshotDetailsDlg</class>
    16  <widget class="QDialog" name="VBoxSnapshotDetailsDlg">
     16 <widget class="QWidget" name="VBoxSnapshotDetailsDlg">
    1717  <property name="geometry">
    1818   <rect>
     
    147147    </widget>
    148148   </item>
    149    <item row="4" column="0" colspan="3">
    150     <widget class="QIDialogButtonBox" name="mButtonBox">
    151      <property name="standardButtons">
    152       <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
    153      </property>
    154     </widget>
    155    </item>
    156149  </layout>
    157150 </widget>
    158  <customwidgets>
    159   <customwidget>
    160    <class>QIDialogButtonBox</class>
    161    <extends>QDialogButtonBox</extends>
    162    <header>QIDialogButtonBox.h</header>
    163   </customwidget>
    164  </customwidgets>
    165151 <resources>
    166152  <include location="../VirtualBox1.qrc"/>
    167153 </resources>
    168  <connections>
    169   <connection>
    170    <sender>mButtonBox</sender>
    171    <signal>accepted()</signal>
    172    <receiver>VBoxSnapshotDetailsDlg</receiver>
    173    <slot>accept()</slot>
    174    <hints>
    175     <hint type="sourcelabel">
    176      <x>203</x>
    177      <y>365</y>
    178     </hint>
    179     <hint type="destinationlabel">
    180      <x>203</x>
    181      <y>193</y>
    182     </hint>
    183    </hints>
    184   </connection>
    185   <connection>
    186    <sender>mButtonBox</sender>
    187    <signal>rejected()</signal>
    188    <receiver>VBoxSnapshotDetailsDlg</receiver>
    189    <slot>reject()</slot>
    190    <hints>
    191     <hint type="sourcelabel">
    192      <x>203</x>
    193      <y>365</y>
    194     </hint>
    195     <hint type="destinationlabel">
    196      <x>203</x>
    197      <y>193</y>
    198     </hint>
    199    </hints>
    200   </connection>
    201  </connections>
    202154</ui>
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r67147 r67160  
    531531    , m_pActionRestoreSnapshot(0)
    532532    , m_pActionShowSnapshotDetails(0)
     533    , m_pActionCommitSnapshotDetails(0)
    533534    , m_pActionCloneSnapshot(0)
    534535    , m_pSnapshotTree(0)
    535536    , m_pCurrentSnapshotItem(0)
     537    , m_pDetailsWidget(0)
    536538{
    537539    /* Prepare: */
     
    583585    m_pActionRestoreSnapshot->setText(tr("&Restore"));
    584586    m_pActionShowSnapshotDetails->setText(tr("D&etails..."));
     587    m_pActionCommitSnapshotDetails->setText(tr("&Apply..."));
    585588    m_pActionCloneSnapshot->setText(tr("&Clone..."));
    586589    /* Translate actions tool-tips: */
     
    591594    m_pActionRestoreSnapshot->setToolTip(tr("Restore Snapshot (%1)")
    592595                                         .arg(m_pActionRestoreSnapshot->shortcut().toString()));
    593     m_pActionShowSnapshotDetails->setToolTip(tr("Show Snapshot Details (%1)")
     596    m_pActionShowSnapshotDetails->setToolTip(tr("Open Snapshot Details (%1)")
    594597                                             .arg(m_pActionShowSnapshotDetails->shortcut().toString()));
     598    m_pActionCommitSnapshotDetails->setToolTip(tr("Apply Changes in Snapshot Details (%1)")
     599                                               .arg(m_pActionCommitSnapshotDetails->shortcut().toString()));
    595600    m_pActionCloneSnapshot->setToolTip(tr("Clone Virtual Machine (%1)")
    596601                                       .arg(m_pActionCloneSnapshot->shortcut().toString()));
     
    599604    m_pActionDeleteSnapshot->setStatusTip(tr("Delete selected snapshot of the virtual machine"));
    600605    m_pActionRestoreSnapshot->setStatusTip(tr("Restore selected snapshot of the virtual machine"));
    601     m_pActionShowSnapshotDetails->setStatusTip(tr("Display a window with selected snapshot details"));
     606    m_pActionShowSnapshotDetails->setStatusTip(tr("Open pane with the selected snapshot details"));
     607    m_pActionCommitSnapshotDetails->setStatusTip(tr("Apply changes in snapshot details pane"));
    602608    m_pActionCloneSnapshot->setStatusTip(tr("Clone selected virtual machine"));
    603609
     
    677683}
    678684
     685void UISnapshotPane::sltToggleSnapshotDetailsVisibility(bool fVisible)
     686{
     687    /* Show/hide commit action and details-widget: */
     688    m_pActionCommitSnapshotDetails->setVisible(fVisible);
     689    m_pDetailsWidget->setVisible(fVisible);
     690    /* If details-widget is visible: */
     691    if (m_pDetailsWidget->isVisible())
     692    {
     693        /* Acquire current snapshot item: */
     694        const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
     695        /* Update details-widget: */
     696        m_pDetailsWidget->setData(*pSnapshotItem, pSnapshotItem->snapshot());
     697    }
     698}
     699
     700void UISnapshotPane::sltCommitSnapshotDetailsChanges()
     701{
     702    /* Make sure nothing being edited in the meantime: */
     703    if (!m_pLockReadWrite->tryLockForWrite())
     704        return;
     705
     706    /* Disable button first of all: */
     707    m_pActionCommitSnapshotDetails->setEnabled(false);
     708
     709    /* Acquire current snapshot item: */
     710    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
     711    AssertPtr(pSnapshotItem);
     712    if (pSnapshotItem)
     713    {
     714        /* Make sure that's a snapshot item indeed: */
     715        CSnapshot comSnapshot = pSnapshotItem->snapshot();
     716        if (comSnapshot.isNotNull())
     717        {
     718            /* Get item data: */
     719            UIDataSnapshot oldData = *pSnapshotItem;
     720            UIDataSnapshot newData = m_pDetailsWidget->data();
     721
     722            /* Update corresponding snapshot attributes if necessary: */
     723            if (newData != oldData)
     724            {
     725                /* We need to open a session when we manipulate the snapshot data of a machine: */
     726                CSession comSession = vboxGlobal().openExistingSession(comSnapshot.GetMachine().GetId());
     727                if (!comSession.isNull())
     728                {
     729                    // TODO: Add settings save validation.
     730
     731                    /* Save snapshot name: */
     732                    if (newData.m_strName != oldData.m_strName)
     733                        comSnapshot.SetName(newData.m_strName);
     734                    /* Save snapshot description: */
     735                    if (newData.m_strDescription != oldData.m_strDescription)
     736                        comSnapshot.SetDescription(newData.m_strDescription);
     737
     738                    /* Close the session again: */
     739                    comSession.UnlockMachine();
     740                }
     741            }
     742        }
     743    }
     744
     745    /* Allows editing again: */
     746    m_pLockReadWrite->unlock();
     747}
     748
    679749void UISnapshotPane::sltHandleCurrentItemChange()
    680750{
    681     /* Acquire corresponding snapshot item: */
     751    /* Acquire current snapshot item: */
    682752    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    683753
     
    734804        && !pSnapshotItem->isCurrentStateItem()
    735805    );
     806    m_pActionCommitSnapshotDetails->setEnabled(
     807        false
     808    );
    736809    m_pActionCloneSnapshot->setEnabled(
    737810           pSnapshotItem
     
    739812            || !fBusy)
    740813    );
     814
     815    /* If there is a proper snasphot item: */
     816    if (   m_pCurrentSnapshotItem
     817        && pSnapshotItem
     818        && !pSnapshotItem->isCurrentStateItem())
     819    {
     820        /* Update details-widget if it's visible: */
     821        if (m_pDetailsWidget->isVisible())
     822            m_pDetailsWidget->setData(*pSnapshotItem, pSnapshotItem->snapshot());
     823    }
     824    else
     825    {
     826        /* Clear details-widget if it's visible: */
     827        if (m_pDetailsWidget->isVisible())
     828            m_pDetailsWidget->clearData();
     829        /* Toggle details button off and hide the widget: */
     830        m_pActionShowSnapshotDetails->setChecked(false);
     831        sltToggleSnapshotDetailsVisibility(false);
     832    }
    741833}
    742834
     
    761853        menu.addAction(m_pActionRestoreSnapshot);
    762854        menu.addAction(m_pActionShowSnapshotDetails);
     855        menu.addAction(m_pActionCommitSnapshotDetails);
    763856        menu.addSeparator();
    764857        menu.addAction(m_pActionCloneSnapshot);
     
    784877    /* Acquire corresponding snapshot item: */
    785878    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(pItem);
    786     AssertReturnVoid(pSnapshotItem);
    787 
    788     /* Rename corresponding snapshot: */
    789     CSnapshot comSnapshot = pSnapshotItem->snapshotID().isNull()
    790                           ? CSnapshot()
    791                           : m_comMachine.FindSnapshot(pSnapshotItem->snapshotID());
    792     if (!comSnapshot.isNull() && comSnapshot.isOk() && comSnapshot.GetName() != pSnapshotItem->text(0))
    793         comSnapshot.SetName(pSnapshotItem->text(0));
     879    AssertPtr(pSnapshotItem);
     880    if (pSnapshotItem)
     881    {
     882        /* Make sure that's a snapshot item indeed: */
     883        CSnapshot comSnapshot = pSnapshotItem->snapshot();
     884        if (comSnapshot.isNotNull())
     885        {
     886            /* Rename corresponding snapshot if necessary: */
     887            if (comSnapshot.GetName() != pSnapshotItem->text(0))
     888            {
     889                /* We need to open a session when we manipulate the snapshot data of a machine: */
     890                CSession comSession = vboxGlobal().openExistingSession(comSnapshot.GetMachine().GetId());
     891                if (!comSession.isNull())
     892                {
     893                    // TODO: Add settings save validation.
     894
     895                    /* Save snapshot name: */
     896                    comSnapshot.SetName(pSnapshotItem->text(0));
     897
     898                    /* Close the session again: */
     899                    comSession.UnlockMachine();
     900                }
     901            }
     902        }
     903    }
    794904
    795905    /* Allows editing again: */
     
    803913    AssertReturnVoid(pSnapshotItem);
    804914
    805     /* Handle Ctrl+DoubleClick: */
    806     if (QApplication::keyboardModifiers() == Qt::ControlModifier)
    807     {
    808         /* As snapshot-restore procedure: */
    809         restoreSnapshot(true /* suppress non-critical warnings */);
     915    /* If this is a snapshot item: */
     916    if (   m_pCurrentSnapshotItem
     917        && pSnapshotItem
     918        && !pSnapshotItem->isCurrentStateItem())
     919    {
     920        /* Handle Ctrl+DoubleClick: */
     921        if (QApplication::keyboardModifiers() == Qt::ControlModifier)
     922        {
     923            /* As snapshot-restore procedure: */
     924            restoreSnapshot(true /* suppress non-critical warnings */);
     925        }
     926        /* Handle other kinds of DoubleClick: */
     927        else
     928        {
     929            /* As show details-widget procedure: */
     930            m_pActionShowSnapshotDetails->setChecked(true);
     931        }
    810932    }
    811933}
     
    862984        /* Prepare tree-widget: */
    863985        prepareTreeWidget();
     986        /* Prepare details-widget: */
     987        prepareDetailsWidget();
    864988    }
    865989}
     
    9121036                                                                                     ":/snapshot_show_details_16px.png",
    9131037                                                                                     ":/snapshot_show_details_disabled_22px.png",
    914                                                                                      ":/snapshot_details_show_disabled_16px.png"),
    915                                                              QString(), this, &UISnapshotPane::sltShowSnapshotDetails);
     1038                                                                                     ":/snapshot_show_details_disabled_16px.png"),
     1039                                                             QString());
    9161040        {
     1041            connect(m_pActionShowSnapshotDetails, &QAction::toggled,
     1042                    this, &UISnapshotPane::sltToggleSnapshotDetailsVisibility);
     1043            m_pActionShowSnapshotDetails->setCheckable(true);
    9171044            m_pActionShowSnapshotDetails->setShortcut(QString("Ctrl+Space"));
     1045        }
     1046
     1047        /* Add Commit Snapshot Details action: */
     1048        m_pActionCommitSnapshotDetails = m_pToolBar->addAction(UIIconPool::iconSetFull(":/snapshot_commit_details_22px.png",
     1049                                                                                       ":/snapshot_commit_details_16px.png",
     1050                                                                                       ":/snapshot_commit_details_disabled_22px.png",
     1051                                                                                       ":/snapshot_commit_details_disabled_16px.png"),
     1052                                                               QString(), this, &UISnapshotPane::sltCommitSnapshotDetailsChanges);
     1053        {
     1054            connect(m_pActionShowSnapshotDetails, &QAction::toggled,
     1055                    m_pActionCommitSnapshotDetails, &QAction::setVisible);
     1056            m_pActionCommitSnapshotDetails->setShortcut(QString("Ctrl+Return"));
    9181057        }
    9191058
     
    9421081    {
    9431082        /* Configure tree: */
     1083        m_pSnapshotTree->setExpandsOnDoubleClick(false);
     1084        m_pSnapshotTree->setEditTriggers(  QAbstractItemView::SelectedClicked
     1085                                         | QAbstractItemView::EditKeyPressed);
    9441086        connect(m_pSnapshotTree, &UISnapshotTree::currentItemChanged,
    9451087                this, &UISnapshotPane::sltHandleCurrentItemChange);
     
    9531095        /* Add into layout: */
    9541096        layout()->addWidget(m_pSnapshotTree);
     1097    }
     1098}
     1099
     1100void UISnapshotPane::prepareDetailsWidget()
     1101{
     1102    /* Create details-widget: */
     1103    m_pDetailsWidget = new UISnapshotDetailsWidget;
     1104    AssertPtrReturnVoid(m_pDetailsWidget);
     1105    {
     1106        /* Configure details-widget: */
     1107        m_pDetailsWidget->setVisible(false);
     1108        connect(m_pDetailsWidget, &UISnapshotDetailsWidget::sigDataChanged,
     1109                m_pActionCommitSnapshotDetails, &QAction::setEnabled);
     1110
     1111        /* Add into layout: */
     1112        layout()->addWidget(m_pDetailsWidget);
    9551113    }
    9561114}
     
    11791337    do
    11801338    {
    1181         /* Acquire currently chosen snapshot item: */
     1339        /* Acquire current snapshot item: */
    11821340        const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    11831341        AssertPtr(pSnapshotItem);
     
    12531411    do
    12541412    {
    1255         /* Acquire currently chosen snapshot item: */
     1413        /* Acquire current snapshot item: */
    12561414        const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    12571415        AssertPtr(pSnapshotItem);
     
    13221480}
    13231481
    1324 void UISnapshotPane::showSnapshotDetails()
    1325 {
    1326     /* Acquire currently chosen snapshot item: */
    1327     const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    1328     AssertReturnVoid(pSnapshotItem);
    1329 
    1330     /* Get corresponding snapshot: */
    1331     const CSnapshot comSnapshot = pSnapshotItem->snapshot();
    1332     AssertReturnVoid(!comSnapshot.isNull());
    1333 
    1334     /* Show Snapshot Details dialog: */
    1335     QPointer<VBoxSnapshotDetailsDlg> pDlg = new VBoxSnapshotDetailsDlg(this);
    1336     pDlg->setData(*pSnapshotItem, comSnapshot);
    1337     if (pDlg->exec() == QDialog::Accepted)
    1338         pDlg->saveData();
    1339     if (pDlg)
    1340         delete pDlg;
    1341 }
    1342 
    13431482void UISnapshotPane::cloneSnapshot()
    13441483{
    1345     /* Acquire currently chosen snapshot item: */
     1484    /* Acquire current snapshot item: */
    13461485    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    13471486    AssertReturnVoid(pSnapshotItem);
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h

    r67147 r67160  
    3232class QTreeWidgetItem;
    3333class QITreeWidgetItem;
     34class UISnapshotDetailsWidget;
     35class UISnapshotItem;
    3436class UISnapshotTree;
    35 class UISnapshotItem;
    3637class UIToolBar;
    3738
     
    9192    /** @name Toolbar handlers.
    9293      * @{ */
    93         /** Proposes to take a snapshot. */
     94        /** Handles command to take a snapshot. */
    9495        void sltTakeSnapshot() { takeSnapshot(); }
    95         /** Proposes to restore the snapshot. */
     96        /** Handles command to restore the snapshot. */
    9697        void sltRestoreSnapshot() { restoreSnapshot(); }
    97         /** Proposes to delete the snapshot. */
     98        /** Handles command to delete the snapshot. */
    9899        void sltDeleteSnapshot() { deleteSnapshot(); }
    99         /** Displays the snapshot details dialog. */
    100         void sltShowSnapshotDetails() { showSnapshotDetails(); }
     100        /** Handles command to make snapshot details @a fVisible. */
     101        void sltToggleSnapshotDetailsVisibility(bool fVisible);
     102        /** Handles command to commit snapshot details changes. */
     103        void sltCommitSnapshotDetailsChanges();
    101104        /** Proposes to clone the snapshot. */
    102105        void sltCloneSnapshot() { cloneSnapshot(); }
     
    127130        /** Prepares tree-widget. */
    128131        void prepareTreeWidget();
     132        /** Prepares details-widget. */
     133        void prepareDetailsWidget();
    129134
    130135        /** Refreshes everything. */
     
    145150        /** Proposes to restore the snapshot. */
    146151        bool restoreSnapshot(bool fSuppressNonCriticalWarnings = false);
    147         /** Displays the snapshot details dialog. */
    148         void showSnapshotDetails();
    149152        /** Proposes to clone the snapshot. */
    150153        void cloneSnapshot();
     
    198201        /** Holds the Show Snapshot Details action instance. */
    199202        QAction   *m_pActionShowSnapshotDetails;
     203        /** Holds the Commit Snapshot Details action instance. */
     204        QAction   *m_pActionCommitSnapshotDetails;
    200205        /** Holds the Clone Snapshot action instance. */
    201206        QAction   *m_pActionCloneSnapshot;
     
    205210        /** Holds the current snapshot item reference. */
    206211        UISnapshotItem *m_pCurrentSnapshotItem;
     212
     213        /** Holds the details-widget instance. */
     214        UISnapshotDetailsWidget *m_pDetailsWidget;
    207215    /** @} */
    208216};
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