From ffecf47cadb3f5d6da97c931d6a9517a0eb05127 Mon Sep 17 00:00:00 2001 From: vboxsync Date: Thu, 30 Mar 2023 12:09:03 +0000 Subject: FE/Qt: bugref:6669: !VirtualBox Manager: Move Clone VM wizard onto non-modal rails. git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@99218 cfe28804-0f27-0410-a406-dd0f0b0b656f --- .../VirtualBox/src/manager/UIToolPaneMachine.cpp | 9 ++-- .../VirtualBox/src/manager/UIToolPaneMachine.h | 4 ++ .../VirtualBox/src/manager/UIVirtualBoxManager.cpp | 53 ++++++++++++++++------ .../VirtualBox/src/manager/UIVirtualBoxManager.h | 3 ++ .../src/manager/UIVirtualBoxManagerWidget.cpp | 5 ++ .../src/manager/UIVirtualBoxManagerWidget.h | 4 ++ .../VirtualBox/src/snapshots/UISnapshotPane.cpp | 36 ++++----------- .../VirtualBox/src/snapshots/UISnapshotPane.h | 12 +++-- 8 files changed, 77 insertions(+), 49 deletions(-) diff --git a/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.cpp b/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.cpp index 389784edfc4..def34499429 100644 --- a/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.cpp +++ b/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.cpp @@ -341,9 +341,12 @@ void UIToolPaneMachine::setItems(const QList &items) bool UIToolPaneMachine::isCurrentStateItemSelected() const { - if (!m_pPaneSnapshots) - return false; - return m_pPaneSnapshots->isCurrentStateItemSelected(); + return m_pPaneSnapshots ? m_pPaneSnapshots->isCurrentStateItemSelected() : false; +} + +QUuid UIToolPaneMachine::currentSnapshotId() +{ + return m_pPaneSnapshots ? m_pPaneSnapshots->currentSnapshotId() : QUuid(); } QString UIToolPaneMachine::currentHelpKeyword() const diff --git a/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.h b/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.h index 5efb17e7c20..45b5c8e0e5d 100644 --- a/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.h +++ b/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneMachine.h @@ -32,6 +32,7 @@ #endif /* Qt includes: */ +#include #include /* GUI includes: */ @@ -107,6 +108,9 @@ public: /** Returns whether current-state item of Snapshot pane is selected. */ bool isCurrentStateItemSelected() const; + /** Returns currently selected snapshot ID if any. */ + QUuid currentSnapshotId(); + /** Returns the help keyword of the current tool's widget. */ QString currentHelpKeyword() const; diff --git a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp index 8d622c8185c..37a54286ba7 100644 --- a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp +++ b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp @@ -469,6 +469,7 @@ UIVirtualBoxManager::UIVirtualBoxManager() , m_pLogViewerDialog(0) , m_pWidget(0) , m_iGeometrySaveTimerId(-1) + , m_fSnapshotCloneByDefault(false) , m_fImportFromOCI(false) , m_fExportToOCI(false) { @@ -989,6 +990,34 @@ void UIVirtualBoxManager::sltOpenWizard(WizardType enmType) case WizardType_NewVM: m_wizards[enmType] = new UIWizardNewVM(this, actionPool(), m_pWidget->fullGroupName(), m_strISOFilePath); break; + case WizardType_CloneVM: + { + UIVirtualMachineItem *pItem = currentItem(); + UIVirtualMachineItemLocal *pItemLocal = pItem ? pItem->toLocal() : 0; + CMachine comMachine = pItemLocal ? pItemLocal->machine() : CMachine(); + CSnapshot comSnapshot; + if (m_fSnapshotCloneByDefault) + { + const QUuid uId = m_pWidget->currentSnapshotId(); + if (!uId.isNull() && comMachine.isNotNull()) + { + printf("Looking for snapshot with ID = {%s}\n", uId.toString().toUtf8().constData()); + comSnapshot = comMachine.FindSnapshot(uId.toString()); + if (comSnapshot.isNotNull()) + { + printf("Snapshot found, acquiring machine ..\n"); + const CMachine comSnapshotMachine = comSnapshot.GetMachine(); + if (comSnapshotMachine.isNotNull()) + comMachine = comSnapshotMachine; + } + } + } + m_wizards[enmType] = new UIWizardCloneVM(this, + comMachine, + pItemLocal->groups().value(0), + comSnapshot); + break; + } case WizardType_ExportAppliance: m_wizards[enmType] = new UIWizardExportApp(this, m_names, m_fExportToOCI); break; @@ -1168,21 +1197,15 @@ void UIVirtualBoxManager::sltCloseSettingsDialog() void UIVirtualBoxManager::sltOpenCloneMachineWizard() { - /* Get current item: */ - UIVirtualMachineItem *pItem = currentItem(); - AssertMsgReturnVoid(pItem, ("Current item should be selected!\n")); - /* Make sure current item is local one: */ - UIVirtualMachineItemLocal *pItemLocal = pItem->toLocal(); - AssertMsgReturnVoid(pItemLocal, ("Current item should be local one!\n")); + /* Configure wizard variables: */ + m_fSnapshotCloneByDefault = false; + QAction *pAction = qobject_cast(sender()); + if ( pAction + && pAction == actionPool()->action(UIActionIndexMN_M_Snapshot_S_Clone)) + m_fSnapshotCloneByDefault = true; - /* Use the "safe way" to open stack of Mac OS X Sheets: */ - QWidget *pWizardParent = windowManager().realParentWindow(this); - const QStringList &machineGroupNames = pItemLocal->groups(); - const QString strGroup = !machineGroupNames.isEmpty() ? machineGroupNames.at(0) : QString(); - QPointer pWizard = new UIWizardCloneVM(pWizardParent, pItemLocal->machine(), strGroup, CSnapshot()); - windowManager().registerNewParent(pWizard, pWizardParent); - pWizard->exec(); - delete pWizard; + /* Open Clone VM Wizard: */ + sltOpenWizard(WizardType_CloneVM); } void UIVirtualBoxManager::sltPerformMachineMove() @@ -2326,6 +2349,8 @@ void UIVirtualBoxManager::prepareConnections() this, &UIVirtualBoxManager::sltOpenSettingsDialogDefault); connect(actionPool()->action(UIActionIndexMN_M_Machine_S_Clone), &UIAction::triggered, this, &UIVirtualBoxManager::sltOpenCloneMachineWizard); + connect(actionPool()->action(UIActionIndexMN_M_Snapshot_S_Clone), &UIAction::triggered, + this, &UIVirtualBoxManager::sltOpenCloneMachineWizard); connect(actionPool()->action(UIActionIndexMN_M_Machine_S_Move), &UIAction::triggered, this, &UIVirtualBoxManager::sltPerformMachineMove); connect(actionPool()->action(UIActionIndexMN_M_Machine_S_ExportToOCI), &UIAction::triggered, diff --git a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h index 79c22219f26..010929e58d2 100644 --- a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h +++ b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h @@ -524,6 +524,9 @@ private: /** Holds the ISO file path used by new VM wizard. */ QString m_strISOFilePath; + /** Holds whether snapshot clone should be done by clone VM wizard. */ + bool m_fSnapshotCloneByDefault; + /** Holds whether OCI importing should be started by default. */ bool m_fImportFromOCI; /** Holds the file-name used by import wizard. */ diff --git a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp index d5935d50564..9c7f0e1ac89 100644 --- a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp +++ b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp @@ -275,6 +275,11 @@ bool UIVirtualBoxManagerWidget::isCurrentStateItemSelected() const return m_pPaneToolsMachine->isCurrentStateItemSelected(); } +QUuid UIVirtualBoxManagerWidget::currentSnapshotId() +{ + return m_pPaneToolsMachine->currentSnapshotId(); +} + void UIVirtualBoxManagerWidget::updateToolBarMenuButtons(bool fSeparateMenuSection) { QToolButton *pButton = qobject_cast(m_pToolBar->widgetForAction(actionPool()->action(UIActionIndexMN_M_Machine_M_StartOrShow))); diff --git a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.h b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.h index 1692b472151..c00f57176e8 100644 --- a/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.h +++ b/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.h @@ -32,6 +32,7 @@ #endif /* Qt includes: */ +#include #include /* GUI includes: */ @@ -213,6 +214,9 @@ public: * @{ */ /** Returns whether current-state item of Snapshot pane is selected. */ bool isCurrentStateItemSelected() const; + + /** Returns currently selected snapshot ID if any. */ + QUuid currentSnapshotId(); /** @} */ /** @name Tool-bar stuff. diff --git a/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp b/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp index edd2db34fbe..a603d4d4b45 100644 --- a/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp +++ b/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp @@ -62,6 +62,7 @@ /* COM includes: */ #include "CConsole.h" +#include "CSnapshot.h" /** Snapshot tree column tags. */ @@ -586,6 +587,13 @@ bool UISnapshotPane::isCurrentStateItemSelected() const return m_currentStateItems.values().contains(pSnapshotItem); } +QUuid UISnapshotPane::currentSnapshotId() +{ + UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem()); + CSnapshot comSnapshot = pSnapshotItem ? pSnapshotItem->snapshot() : CSnapshot(); + return comSnapshot.isNotNull() ? comSnapshot.GetId() : QUuid(); +} + void UISnapshotPane::retranslateUi() { /* Translate snapshot tree: */ @@ -1302,8 +1310,6 @@ void UISnapshotPane::prepareActions() this, &UISnapshotPane::sltRestoreSnapshot); connect(m_pActionPool->action(UIActionIndexMN_M_Snapshot_T_Properties), &UIAction::toggled, this, &UISnapshotPane::sltToggleSnapshotDetailsVisibility); - connect(m_pActionPool->action(UIActionIndexMN_M_Snapshot_S_Clone), &UIAction::triggered, - this, &UISnapshotPane::sltCloneSnapshot); } void UISnapshotPane::prepareWidgets() @@ -1738,32 +1744,6 @@ bool UISnapshotPane::restoreSnapshot(bool fAutomatically /* = false */) return true; } -void UISnapshotPane::cloneSnapshot() -{ - /* Acquire "current snapshot" item: */ - const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem()); - AssertReturnVoid(pSnapshotItem); - - /* Get desired machine/snapshot: */ - CMachine comMachine; - CSnapshot comSnapshot; - if (pSnapshotItem->isCurrentStateItem()) - comMachine = pSnapshotItem->machine(); - else - { - comSnapshot = pSnapshotItem->snapshot(); - AssertReturnVoid(!comSnapshot.isNull()); - comMachine = comSnapshot.GetMachine(); - } - AssertReturnVoid(!comMachine.isNull()); - - /* Show Clone VM wizard: */ - QPointer pWizard = new UIWizardCloneVM(this, comMachine, QString(), comSnapshot); - pWizard->exec(); - if (pWizard) - delete pWizard; -} - void UISnapshotPane::adjustTreeWidget() { /* Get the snapshot tree abstract interface: */ diff --git a/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h b/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h index 11276bdca0e..1075f57aee3 100644 --- a/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h +++ b/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h @@ -31,11 +31,15 @@ # pragma once #endif +/* Qt includes: */ +#include + /* GUI includes: */ #include "QIWithRetranslateUI.h" #include "UICommon.h" /* COM includes: */ +#include "COMEnums.h" #include "CMachine.h" /* Forward declarations: */ @@ -51,6 +55,7 @@ class UISnapshotDetailsWidget; class UISnapshotItem; class UISnapshotTree; class UIVirtualMachineItem; +class CSnapshot; /** Snapshot age format. */ @@ -90,6 +95,9 @@ public: /** Returns whether "current state" item selected. */ bool isCurrentStateItemSelected() const; + /** Returns currently selected snapshot ID if any. */ + QUuid currentSnapshotId(); + protected: /** @name Qt event handlers. @@ -144,8 +152,6 @@ private slots: void sltToggleSnapshotDetailsVisibility(bool fVisible); /** Handles command to apply snapshot details changes. */ void sltApplySnapshotDetailsChanges(); - /** Proposes to clone the snapshot. */ - void sltCloneSnapshot() { cloneSnapshot(); } /** @} */ /** @name Tree-widget handlers. @@ -201,8 +207,6 @@ private: bool deleteSnapshot(bool fAutomatically = false); /** Proposes to restore the snapshot. */ bool restoreSnapshot(bool fAutomatically = false); - /** Proposes to clone the snapshot. */ - void cloneSnapshot(); /** @} */ /** @name Tree-widget helpers. -- cgit v1.2.1