VirtualBox

Changeset 36011 in vbox


Ignore:
Timestamp:
Feb 17, 2011 12:16:02 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 4539: Offer a user to take a snapshot of the current machine state when restoring to some previous snapshot if current machine state is changed.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.h

    r28800 r36011  
    7070
    7171        Default = 0x100, Escape = 0x200,
    72         FlagMask = 0x300
     72        FlagMask = 0x300,
     73
     74        OptionChosen = 0x400
    7375    };
    7476
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxProblemReporter.cpp

    r35730 r36011  
    254254 */
    255255
     256int VBoxProblemReporter::messageWithOption(QWidget *pParent,
     257                                           Type type,
     258                                           const QString &strMessage,
     259                                           const QString &strOptionText,
     260                                           bool fDefaultOptionValue /* = true */,
     261                                           const QString &strDetails /* = QString::null */,
     262                                           int iButton1 /* = 0 */,
     263                                           int iButton2 /* = 0 */,
     264                                           int iButton3 /* = 0 */,
     265                                           const QString &strButtonName1 /* = QString::null */,
     266                                           const QString &strButtonName2 /* = QString::null */,
     267                                           const QString &strButtonName3 /* = QString::null */) const
     268{
     269    /* If no buttons are set, using single 'OK' button: */
     270    if (iButton1 == 0 && iButton2 == 0 && iButton3 == 0)
     271        iButton1 = QIMessageBox::Ok | QIMessageBox::Default;
     272
     273    /* Assign corresponding title and icon: */
     274    QString strTitle;
     275    QIMessageBox::Icon icon;
     276    switch (type)
     277    {
     278        default:
     279        case Info:
     280            strTitle = tr("VirtualBox - Information", "msg box title");
     281            icon = QIMessageBox::Information;
     282            break;
     283        case Question:
     284            strTitle = tr("VirtualBox - Question", "msg box title");
     285            icon = QIMessageBox::Question;
     286            break;
     287        case Warning:
     288            strTitle = tr("VirtualBox - Warning", "msg box title");
     289            icon = QIMessageBox::Warning;
     290            break;
     291        case Error:
     292            strTitle = tr("VirtualBox - Error", "msg box title");
     293            icon = QIMessageBox::Critical;
     294            break;
     295        case Critical:
     296            strTitle = tr("VirtualBox - Critical Error", "msg box title");
     297            icon = QIMessageBox::Critical;
     298            break;
     299        case GuruMeditation:
     300            strTitle = "VirtualBox - Guru Meditation"; /* don't translate this */
     301            icon = QIMessageBox::GuruMeditation;
     302            break;
     303    }
     304
     305    /* Create message-box: */
     306    if (QPointer<QIMessageBox> pBox = new QIMessageBox(strTitle, strMessage, icon,
     307                                                       iButton1, iButton2, iButton3, pParent))
     308    {
     309        /* Append the list of all warnings with current: */
     310        m_warnings << pBox;
     311
     312        /* Setup message-box connections: */
     313        connect(this, SIGNAL(sigToCloseAllWarnings()), pBox, SLOT(deleteLater()));
     314
     315        /* Assign other text values: */
     316        if (!strOptionText.isNull())
     317        {
     318            pBox->setFlagText(strOptionText);
     319            pBox->setFlagChecked(fDefaultOptionValue);
     320        }
     321        if (!strButtonName1.isNull())
     322            pBox->setButtonText(0, strButtonName1);
     323        if (!strButtonName2.isNull())
     324            pBox->setButtonText(1, strButtonName2);
     325        if (!strButtonName3.isNull())
     326            pBox->setButtonText(2, strButtonName3);
     327        if (!strDetails.isEmpty())
     328            pBox->setDetailsText(strDetails);
     329
     330        /* Show the message box: */
     331        int iResultCode = pBox->exec();
     332
     333        /* Its possible what message-box will be deleted during some event-processing procedure,
     334         * in that case pBox will be null right after pBox->exec() returns from it's event-pool,
     335         * so we have to check this too: */
     336        if (pBox)
     337        {
     338            /* Cleanup the list of all warnings from current: */
     339            if (m_warnings.contains(pBox))
     340                m_warnings.removeAll(pBox);
     341
     342            /* Check if option was chosen: */
     343            if (pBox->isFlagChecked())
     344                iResultCode |= QIMessageBox::OptionChosen;
     345
     346            /* Destroy message-box: */
     347            if (pBox)
     348                delete pBox;
     349
     350            /* Return final result: */
     351            return iResultCode;
     352        }
     353    }
     354    return 0;
     355}
     356
    256357/**
    257358 *  Shows a modal progress dialog using a CProgress object passed as an
     
    840941}
    841942
    842 bool VBoxProblemReporter::askAboutSnapshotRestoring (const QString &aSnapshotName)
    843 {
    844     return messageOkCancel (mainWindowShown(), Question,
    845         tr ("<p>Are you sure you want to restore snapshot <b>%1</b>? "
    846             "This will cause you to lose your current machine state, which cannot be recovered.</p>")
    847             .arg (aSnapshotName),
    848         /* Do NOT allow this message to be disabled! */
    849         NULL /* aAutoConfirmId */,
    850         tr ("Restore"), tr ("Cancel"));
     943int VBoxProblemReporter::askAboutSnapshotRestoring(const QString &strSnapshotName, bool fAlsoCreateNewSnapshot)
     944{
     945    return fAlsoCreateNewSnapshot ?
     946           messageWithOption(mainWindowShown(), Question,
     947                             tr("<p>You are about to restore snapshot <b>%1</b>.</p>"
     948                                "<p>You can create a snapshot of the current state of the virtual machine first by checking the box below; "
     949                                "if you do not do this the current state will be permanently lost. Do you wish to proceed?</p>")
     950                                .arg(strSnapshotName),
     951                             tr("Create a snapshot of the current machine state"),
     952                             true /* choose option by default */,
     953                             QString::null /* details */,
     954                             QIMessageBox::Ok, QIMessageBox::Cancel, 0 /* 3rd button */,
     955                             tr("Restore"), tr("Cancel"), QString::null /* 3rd button text */) :
     956           message(mainWindowShown(), Question,
     957                   tr("<p>Are you sure you want to restore snapshot <b>%1</b>?</p>").arg(strSnapshotName),
     958                   0 /* auto-confirmation token */,
     959                   QIMessageBox::Ok, QIMessageBox::Cancel, 0 /* 3rd button */,
     960                   tr("Restore"), tr("Cancel"), QString::null /* 3rd button text */);
    851961}
    852962
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxProblemReporter.h

    r35587 r36011  
    138138    }
    139139
     140    int messageWithOption(QWidget *pParent,
     141                          Type type,
     142                          const QString &strMessage,
     143                          const QString &strOptionText,
     144                          bool fDefaultOptionValue = true,
     145                          const QString &strDetails = QString::null,
     146                          int iButton1 = 0,
     147                          int iButton2 = 0,
     148                          int iButton3 = 0,
     149                          const QString &strButtonName1 = QString::null,
     150                          const QString &strButtonName2 = QString::null,
     151                          const QString &strButtonName3 = QString::null) const;
     152
    140153    bool showModalProgressDialog(CProgress &progress, const QString &strTitle,
    141154                                 const QString &strImage = "", QWidget *pParent = 0,
     
    208221    bool warnAboutVirtNotEnabledGuestRequired(bool fHWVirtExSupported);
    209222
    210     bool askAboutSnapshotRestoring (const QString &aSnapshotName);
     223    int askAboutSnapshotRestoring (const QString &aSnapshotName, bool fAlsoCreateNewSnapshot);
    211224    bool askAboutSnapshotDeleting (const QString &aSnapshotName);
    212225    bool askAboutSnapshotDeletingFreeSpace (const QString &aSnapshotName,
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp

    r34983 r36011  
    397397             this, SLOT (onItemChanged (QTreeWidgetItem*)));
    398398
    399     connect (mRestoreSnapshotAction, SIGNAL (triggered()), this, SLOT (restoreSnapshot()));
    400     connect (mDeleteSnapshotAction, SIGNAL (triggered()), this, SLOT (deleteSnapshot()));
    401     connect (mShowSnapshotDetailsAction, SIGNAL (triggered()), this, SLOT (showSnapshotDetails()));
    402     connect (mTakeSnapshotAction, SIGNAL (triggered()), this, SLOT (takeSnapshot()));
     399    connect (mTakeSnapshotAction, SIGNAL (triggered()), this, SLOT (sltTakeSnapshot()));
     400    connect (mRestoreSnapshotAction, SIGNAL (triggered()), this, SLOT (sltRestoreSnapshot()));
     401    connect (mDeleteSnapshotAction, SIGNAL (triggered()), this, SLOT (sltDeleteSnapshot()));
     402    connect (mShowSnapshotDetailsAction, SIGNAL (triggered()), this, SLOT (sltShowSnapshotDetails()));
    403403
    404404    connect (gVBoxEvents, SIGNAL(sigMachineDataChange(QString)),
     
    432432}
    433433
     434void VBoxSnapshotsWgt::retranslateUi()
     435{
     436    /* Translate uic generated strings */
     437    Ui::VBoxSnapshotsWgt::retranslateUi (this);
     438
     439    mRestoreSnapshotAction->setText (tr ("&Restore Snapshot"));
     440    mDeleteSnapshotAction->setText (tr ("&Delete Snapshot"));
     441    mShowSnapshotDetailsAction->setText (tr ("S&how Details"));
     442    mTakeSnapshotAction->setText (tr ("Take &Snapshot"));
     443
     444    mRestoreSnapshotAction->setStatusTip (tr ("Restore the selected snapshot of the virtual machine"));
     445    mDeleteSnapshotAction->setStatusTip (tr ("Delete the selected snapshot of the virtual machine"));
     446    mShowSnapshotDetailsAction->setStatusTip (tr ("Show the details of the selected snapshot"));
     447    mTakeSnapshotAction->setStatusTip (tr ("Take a snapshot of the current virtual machine state"));
     448
     449    mRestoreSnapshotAction->setToolTip (mRestoreSnapshotAction->text().remove ('&').remove ('.') +
     450        QString (" (%1)").arg (mRestoreSnapshotAction->shortcut().toString()));
     451    mDeleteSnapshotAction->setToolTip (mDeleteSnapshotAction->text().remove ('&').remove ('.') +
     452        QString (" (%1)").arg (mDeleteSnapshotAction->shortcut().toString()));
     453    mShowSnapshotDetailsAction->setToolTip (mShowSnapshotDetailsAction->text().remove ('&').remove ('.') +
     454        QString (" (%1)").arg (mShowSnapshotDetailsAction->shortcut().toString()));
     455    mTakeSnapshotAction->setToolTip (mTakeSnapshotAction->text().remove ('&').remove ('.') +
     456        QString (" (%1)").arg (mTakeSnapshotAction->shortcut().toString()));
     457}
    434458
    435459void VBoxSnapshotsWgt::onCurrentChanged (QTreeWidgetItem *aItem)
     
    513537}
    514538
    515 void VBoxSnapshotsWgt::restoreSnapshot()
    516 {
    517     SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
    518         static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());
    519     AssertReturn (item, (void) 0);
    520 
    521     QString snapId = item->snapshotId();
    522     AssertReturn (!snapId.isNull(), (void) 0);
    523     CSnapshot snapshot = mMachine.FindSnapshot(snapId);
    524 
    525     if (!vboxProblem().askAboutSnapshotRestoring (snapshot.GetName()))
    526         return;
    527 
    528     /* Open a direct session (this call will handle all errors) */
    529     CSession session = vboxGlobal().openSession (mMachineId);
    530     if (session.isNull())
    531         return;
    532 
    533     CConsole console = session.GetConsole();
    534     CProgress progress = console.RestoreSnapshot (snapshot);
    535     if (console.isOk())
    536     {
    537         /* Show the progress dialog */
    538         vboxProblem().showModalProgressDialog (progress, mMachine.GetName(), ":/progress_snapshot_restore_90px.png",
    539                                                vboxProblem().mainWindowShown(), true);
    540 
    541         if (progress.GetResultCode() != 0)
    542             vboxProblem().cannotRestoreSnapshot (progress, snapshot.GetName());
    543     }
    544     else
    545         vboxProblem().cannotRestoreSnapshot (progress, snapshot.GetName());
    546 
    547     session.UnlockMachine();
    548 }
    549 
    550 void VBoxSnapshotsWgt::deleteSnapshot()
     539void VBoxSnapshotsWgt::sltTakeSnapshot()
     540{
     541    takeSnapshot();
     542}
     543
     544void VBoxSnapshotsWgt::sltRestoreSnapshot()
     545{
     546    /* Get currently chosen item: */
     547    SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0;
     548    AssertReturn(pItem, (void)0);
     549    /* Detemine snapshot id: */
     550    QString strSnapshotId = pItem->snapshotId();
     551    AssertReturn(!strSnapshotId.isNull(), (void)0);
     552    /* Get currently desired snapshot: */
     553    CSnapshot snapshot = mMachine.FindSnapshot(strSnapshotId);
     554
     555    /* Ask the user if he really wants to restore the snapshot: */
     556    int iResultCode = vboxProblem().askAboutSnapshotRestoring(snapshot.GetName(), mMachine.GetCurrentStateModified());
     557
     558    /* If user confirmed other snapshot restoring: */
     559    if (iResultCode & QIMessageBox::Ok)
     560    {
     561        /* If user also confirmed new snapshot creation: */
     562        if (iResultCode & QIMessageBox::OptionChosen)
     563        {
     564            /* Take snapshot of changed current state: */
     565            mTreeWidget->setCurrentItem(curStateItem());
     566            if (!takeSnapshot())
     567                return;
     568        }
     569
     570        /* Open a direct session (this call will handle all errors): */
     571        CSession session = vboxGlobal().openSession(mMachineId);
     572        if (session.isNull())
     573            return;
     574
     575        /* Restore chosen snapshot: */
     576        CConsole console = session.GetConsole();
     577        CProgress progress = console.RestoreSnapshot(snapshot);
     578        if (console.isOk())
     579        {
     580            vboxProblem().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_restore_90px.png",
     581                                                  vboxProblem().mainWindowShown(), true);
     582            if (progress.GetResultCode() != 0)
     583                vboxProblem().cannotRestoreSnapshot(progress, snapshot.GetName());
     584        }
     585        else
     586            vboxProblem().cannotRestoreSnapshot(progress, snapshot.GetName());
     587
     588        /* Unlock machine finally: */
     589        session.UnlockMachine();
     590    }
     591}
     592
     593void VBoxSnapshotsWgt::sltDeleteSnapshot()
    551594{
    552595    SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
     
    594637}
    595638
    596 void VBoxSnapshotsWgt::showSnapshotDetails()
     639void VBoxSnapshotsWgt::sltShowSnapshotDetails()
    597640{
    598641    SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
     
    611654        dlg.putBackToSnapshot();
    612655}
    613 
    614 void VBoxSnapshotsWgt::takeSnapshot()
    615 {
    616     SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
    617         static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());
    618     AssertReturn (item, (void) 0);
    619 
    620     VBoxTakeSnapshotDlg dlg (this, mMachine);
    621 
    622     QString typeId = mMachine.GetOSTypeId();
    623     dlg.mLbIcon->setPixmap (vboxGlobal().vmGuestOSTypeIcon (typeId));
    624 
    625     /* Search for the max available filter index */
    626     int maxSnapShotIndex = 0;
    627     QString snapShotName = tr ("Snapshot %1");
    628     QRegExp regExp (QString ("^") + snapShotName.arg ("([0-9]+)") + QString ("$"));
    629     QTreeWidgetItemIterator iterator (mTreeWidget);
    630     while (*iterator)
    631     {
    632         QString snapShot = static_cast <SnapshotWgtItem*> (*iterator)->text (0);
    633         int pos = regExp.indexIn (snapShot);
    634         if (pos != -1)
    635             maxSnapShotIndex = regExp.cap (1).toInt() > maxSnapShotIndex ?
    636                                regExp.cap (1).toInt() : maxSnapShotIndex;
    637         ++ iterator;
    638     }
    639     dlg.mLeName->setText (snapShotName.arg (maxSnapShotIndex + 1));
    640 
    641     if (dlg.exec() == QDialog::Accepted)
    642     {
    643         /* Open a direct session (this call will handle all errors) */
    644         bool busy = mSessionState != KSessionState_Unlocked;
    645         CSession session = vboxGlobal().openSession (mMachineId, busy /* aExisting */);
    646         if (session.isNull())
    647             return;
    648 
    649         CConsole console = session.GetConsole();
    650         CProgress progress = console.TakeSnapshot (dlg.mLeName->text().trimmed(),
    651                                                    dlg.mTeDescription->toPlainText());
    652         if (console.isOk())
    653         {
    654             /* Show the progress dialog */
    655             vboxProblem().showModalProgressDialog (progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png",
    656                                                    vboxProblem().mainWindowShown(), true);
    657 
    658             if (progress.GetResultCode() != 0)
    659                 vboxProblem().cannotTakeSnapshot (progress);
    660         }
    661         else
    662             vboxProblem().cannotTakeSnapshot (console);
    663 
    664         session.UnlockMachine();
    665     }
    666 }
    667 
    668656
    669657void VBoxSnapshotsWgt::machineDataChanged(QString strId)
     
    729717}
    730718
    731 void VBoxSnapshotsWgt::retranslateUi()
    732 {
    733     /* Translate uic generated strings */
    734     Ui::VBoxSnapshotsWgt::retranslateUi (this);
    735 
    736     mRestoreSnapshotAction->setText (tr ("&Restore Snapshot"));
    737     mDeleteSnapshotAction->setText (tr ("&Delete Snapshot"));
    738     mShowSnapshotDetailsAction->setText (tr ("S&how Details"));
    739     mTakeSnapshotAction->setText (tr ("Take &Snapshot"));
    740 
    741     mRestoreSnapshotAction->setStatusTip (tr ("Restore the selected snapshot of the virtual machine"));
    742     mDeleteSnapshotAction->setStatusTip (tr ("Delete the selected snapshot of the virtual machine"));
    743     mShowSnapshotDetailsAction->setStatusTip (tr ("Show the details of the selected snapshot"));
    744     mTakeSnapshotAction->setStatusTip (tr ("Take a snapshot of the current virtual machine state"));
    745 
    746     mRestoreSnapshotAction->setToolTip (mRestoreSnapshotAction->text().remove ('&').remove ('.') +
    747         QString (" (%1)").arg (mRestoreSnapshotAction->shortcut().toString()));
    748     mDeleteSnapshotAction->setToolTip (mDeleteSnapshotAction->text().remove ('&').remove ('.') +
    749         QString (" (%1)").arg (mDeleteSnapshotAction->shortcut().toString()));
    750     mShowSnapshotDetailsAction->setToolTip (mShowSnapshotDetailsAction->text().remove ('&').remove ('.') +
    751         QString (" (%1)").arg (mShowSnapshotDetailsAction->shortcut().toString()));
    752     mTakeSnapshotAction->setToolTip (mTakeSnapshotAction->text().remove ('&').remove ('.') +
    753         QString (" (%1)").arg (mTakeSnapshotAction->shortcut().toString()));
     719bool VBoxSnapshotsWgt::takeSnapshot()
     720{
     721    /* Get currently chosen item: */
     722    SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast <SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0;
     723    AssertReturn(pItem, (bool)0);
     724
     725    /* Create 'take new snapshot' dialog: */
     726    VBoxTakeSnapshotDlg dlg(this, mMachine);
     727    dlg.mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(mMachine.GetOSTypeId()));
     728
     729    /* Search for the max available filter index: */
     730    int iMaxSnapShotIndex = 0;
     731    QString snapShotName = tr("Snapshot %1");
     732    QRegExp regExp(QString("^") + snapShotName.arg("([0-9]+)") + QString("$"));
     733    QTreeWidgetItemIterator iterator(mTreeWidget);
     734    while (*iterator)
     735    {
     736        QString snapShot = static_cast<SnapshotWgtItem*>(*iterator)->text(0);
     737        int pos = regExp.indexIn(snapShot);
     738        if (pos != -1)
     739            iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex;
     740        ++iterator;
     741    }
     742    dlg.mLeName->setText(snapShotName.arg(iMaxSnapShotIndex + 1));
     743
     744    /* Show 'take new snapshot' dialog: */
     745    if (dlg.exec() == QDialog::Accepted)
     746    {
     747        /* Open a direct session (this call will handle all errors): */
     748        bool busy = mSessionState != KSessionState_Unlocked;
     749        CSession session = vboxGlobal().openSession(mMachineId, busy /* aExisting */);
     750        if (session.isNull())
     751            return false;
     752
     753        /* Take new snapshot: */
     754        CConsole console = session.GetConsole();
     755        CProgress progress = console.TakeSnapshot(dlg.mLeName->text().trimmed(), dlg.mTeDescription->toPlainText());
     756        if (console.isOk())
     757        {
     758            /* Show the progress dialog */
     759            vboxProblem().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png",
     760                                                  vboxProblem().mainWindowShown(), true);
     761            if (progress.GetResultCode() != 0)
     762                vboxProblem().cannotTakeSnapshot(progress);
     763        }
     764        else
     765            vboxProblem().cannotTakeSnapshot(console);
     766
     767        /* Unlock machine finally: */
     768        session.UnlockMachine();
     769
     770        return true;
     771    }
     772    return false;
    754773}
    755774
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.h

    r30868 r36011  
    5757private slots:
    5858
     59    /* Snapshot tree slots: */
    5960    void onCurrentChanged (QTreeWidgetItem *aItem = 0);
    6061    void onContextMenuRequested (const QPoint &aPoint);
    6162    void onItemChanged (QTreeWidgetItem *aItem);
    6263
    63     void restoreSnapshot();
    64     void deleteSnapshot();
    65     void showSnapshotDetails();
    66     void takeSnapshot();
     64    /* Snapshot functionality slots: */
     65    void sltTakeSnapshot();
     66    void sltRestoreSnapshot();
     67    void sltDeleteSnapshot();
     68    void sltShowSnapshotDetails();
    6769
     70    /* Main API event handlers: */
    6871    void machineDataChanged(QString strId);
    6972    void machineStateChanged(QString strId, KMachineState state);
     
    7376
    7477private:
     78
     79    /* Snapshot private functions: */
     80    bool takeSnapshot();
     81    //bool restoreSnapshot();
     82    //bool deleteSnapshot();
     83    //bool showSnapshotDetails();
    7584
    7685    void refreshAll();
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