diff options
6 files changed, 70 insertions, 26 deletions
diff --git a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp index 77e70bc0d46..60f9730b42c 100644 --- a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp +++ b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp @@ -378,6 +378,11 @@ bool UIMachine::acquireCurrentSnapshotName(QString &strName) return uisession()->acquireCurrentSnapshotName(strName); } +bool UIMachine::acquireMaxSnapshotIndex(const QString &strNameTemplate, ulong &uIndex) +{ + return uisession()->acquireMaxSnapshotIndex(strNameTemplate, uIndex); +} + bool UIMachine::acquireWhetherAudioAdapterPresent(bool &fPresent) { return uisession()->acquireWhetherAudioAdapterPresent(fPresent); diff --git a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h index 75a183afdc6..9f8419156d5 100644 --- a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h +++ b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h @@ -259,6 +259,9 @@ public: bool acquireSnapshotCount(ulong &uCount); /** Acquires current snapshot name. */ bool acquireCurrentSnapshotName(QString &strName); + + /** Recursively searches for a first snapshot matching name template conditions. */ + bool acquireMaxSnapshotIndex(const QString &strNameTemplate, ulong &uIndex); /** @} */ /** @name Audio stuff. diff --git a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp index c3418d80e64..25a056e9ebc 100644 --- a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp +++ b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp @@ -1598,8 +1598,9 @@ void UIMachineLogic::sltTakeSnapshot() /* Search for the max available filter index: */ const QString strNameTemplate = UITakeSnapshotDialog::tr("Snapshot %1"); - int iMaxSnapshotIndex = searchMaxSnapshotIndex(machine(), machine().FindSnapshot(QString()), strNameTemplate); - pDlg->setName(strNameTemplate.arg(++ iMaxSnapshotIndex)); + ulong uMaxSnapshotIndex = 0; + uimachine()->acquireMaxSnapshotIndex(strNameTemplate, uMaxSnapshotIndex); + pDlg->setName(strNameTemplate.arg(++uMaxSnapshotIndex)); /* Exec the dialog: */ const bool fDialogAccepted = pDlg->exec() == QDialog::Accepted; @@ -2989,29 +2990,6 @@ void UIMachineLogic::askUserForTheDiskEncryptionPasswords() } } -int UIMachineLogic::searchMaxSnapshotIndex(const CMachine &machine, - const CSnapshot &snapshot, - const QString &strNameTemplate) -{ - int iMaxIndex = 0; - QRegExp regExp(QString("^") + strNameTemplate.arg("([0-9]+)") + QString("$")); - if (!snapshot.isNull()) - { - /* Check the current snapshot name */ - QString strName = snapshot.GetName(); - int iPos = regExp.indexIn(strName); - if (iPos != -1) - iMaxIndex = regExp.cap(1).toInt() > iMaxIndex ? regExp.cap(1).toInt() : iMaxIndex; - /* Traversing all the snapshot children */ - foreach (const CSnapshot &child, snapshot.GetChildren()) - { - int iMaxIndexOfChildren = searchMaxSnapshotIndex(machine, child, strNameTemplate); - iMaxIndex = iMaxIndexOfChildren > iMaxIndex ? iMaxIndexOfChildren : iMaxIndex; - } - } - return iMaxIndex; -} - void UIMachineLogic::takeScreenshot(const QString &strFile, const QString &strFormat /* = "png" */) const { /* Get console: */ diff --git a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h index 694609a9563..5d2b7577a4c 100644 --- a/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h +++ b/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h @@ -367,7 +367,6 @@ private: void askUserForTheDiskEncryptionPasswords(); /* Helpers: */ - static int searchMaxSnapshotIndex(const CMachine &machine, const CSnapshot &snapshot, const QString &strNameTemplate); void takeScreenshot(const QString &strFile, const QString &strFormat /* = "png" */) const; /** Reactivates the screen saver. This is possbily called during vm window close and enables host screen diff --git a/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp b/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp index 61e92358dd3..e95c66513c7 100644 --- a/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp +++ b/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp @@ -342,6 +342,13 @@ bool UISession::acquireCurrentSnapshotName(QString &strName) return fSuccess; } +bool UISession::acquireMaxSnapshotIndex(const QString &strNameTemplate, ulong &uIndex) +{ + CMachine comMachine = machine(); + CSnapshot comSnapshot = comMachine.FindSnapshot(QString()); + return searchMaxSnapshotIndex(comMachine, comSnapshot, strNameTemplate, uIndex); +} + bool UISession::putScancode(LONG iCode) { CKeyboard comKeyboard = keyboard(); @@ -2102,6 +2109,48 @@ void UISession::recacheMachineMedia() uiCommon().enumerateMedia(comMedia); } +/* static */ +bool UISession::searchMaxSnapshotIndex(const CMachine &comMachine, + const CSnapshot &comSnapshot, + const QString &strNameTemplate, + ulong &uIndex) +{ + bool fSuccess = true; + ulong uMaxIndex = 0; + QRegExp regExp(QString("^") + strNameTemplate.arg("([0-9]+)") + QString("$")); + if (!comSnapshot.isNull()) + { + /* Check current snapshot name: */ + const QString strName = comSnapshot.GetName(); + fSuccess = comSnapshot.isOk(); + if (!fSuccess) + UINotificationMessage::cannotAcquireSnapshotParameter(comSnapshot); + else + { + const int iPos = regExp.indexIn(strName); + if (iPos != -1) + uMaxIndex = regExp.cap(1).toULong() > uMaxIndex ? regExp.cap(1).toULong() : uMaxIndex; + /* Traversing all the snapshot children: */ + QVector<CSnapshot> comSnapshotChildren = comSnapshot.GetChildren(); + fSuccess = comSnapshot.isOk(); + if (!fSuccess) + UINotificationMessage::cannotAcquireSnapshotParameter(comSnapshot); + else + foreach (const CSnapshot &comSnapshotChild, comSnapshotChildren) + { + ulong uMaxIndexOfChildren = 0; + fSuccess = searchMaxSnapshotIndex(comMachine, comSnapshotChild, strNameTemplate, uMaxIndexOfChildren); + if (!fSuccess) + break; + uMaxIndex = uMaxIndexOfChildren > uMaxIndex ? uMaxIndexOfChildren : uMaxIndex; + } + } + } + if (fSuccess) + uIndex = uMaxIndex; + return fSuccess; +} + #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER /** * Custom signal handler. When switching VTs, we might not get release events diff --git a/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h b/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h index 2bdfee98dea..604f451506d 100644 --- a/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h +++ b/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h @@ -256,6 +256,9 @@ public: bool acquireSnapshotCount(ulong &uCount); /** Acquires current snapshot name. */ bool acquireCurrentSnapshotName(QString &strName); + + /** Recursively searches for a first snapshot matching name template conditions. */ + bool acquireMaxSnapshotIndex(const QString &strNameTemplate, ulong &uIndex); /** @} */ /** @name Keyboard stuff. @@ -608,6 +611,13 @@ private: void recacheMachineMedia(); /** @} */ + /** @name Snapshot stuff. + ** @{ */ + /** Recursively searches for a first snapshot matching name template conditions. */ + static bool searchMaxSnapshotIndex(const CMachine &machine, const CSnapshot &snapshot, + const QString &strNameTemplate, ulong &uIndex); + /** @} */ + /** @name General stuff. ** @{ */ /** Holds the machine UI reference. */ |