VirtualBox

Changeset 37109 in vbox


Ignore:
Timestamp:
May 16, 2011 3:31:23 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 3887: Make certain settings editable during runtime: Opened VM settings dialog content now will be dynamically updated on machine data / state changes.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r36592 r37109  
    952952        return;
    953953
    954     /* Open shared session: */
    955     CSession sharedSession = vboxGlobal().openSession(session().GetMachine().GetId(), true);
    956     if (sharedSession.isNull())
    957         return;
    958 
    959     /* Get machine: */
    960     CMachine sharedMachine = sharedSession.GetMachine();
    961     if (sharedMachine.isNull())
    962         return;
    963 
    964     /* Prepare VM settings dialog: */
    965     UISettingsDialog *pDlg = new UISettingsDialogMachine(defaultMachineWindow()->machineWindow(),
    966                                                          SettingsDialogType_Online,
    967                                                          sharedMachine, session().GetConsole(),
    968                                                          strCategory, QString());
    969     pDlg->loadData();
    970 
    971     /* Show VM settings dialog: */
    972     if (pDlg->exec() == QDialog::Accepted)
    973     {
    974         /* If dialog was accepted => save changed settings: */
    975         pDlg->saveData();
    976         sharedMachine.SaveSettings();
    977         /* If settings were failed to be saved => show the error: */
    978         if (!sharedMachine.isOk())
    979             vboxProblem().cannotSaveMachineSettings(sharedMachine);
    980     }
    981 
    982     /* Delete VM settings dialog: */
    983     delete pDlg;
    984 
    985     /* Unlock machine: */
    986     sharedSession.UnlockMachine();
     954    /* Create and execute current VM settings dialog: */
     955    UISettingsDialogMachine dlg(defaultMachineWindow()->machineWindow(),
     956                                session().GetMachine().GetId(), strCategory, QString());
     957    dlg.execute();
    987958}
    988959
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp

    r36592 r37109  
    592592void VBoxSelectorWnd::fileSettings()
    593593{
    594     VBoxGlobalSettings settings = vboxGlobal().settings();
    595     CSystemProperties props = vboxGlobal().virtualBox().GetSystemProperties();
    596 
    597     UISettingsDialog *dlg = new UISettingsDialogGlobal(this, SettingsDialogType_Offline);
    598     dlg->loadData();
    599 
    600     if (dlg->exec() == QDialog::Accepted)
    601         dlg->saveData();
    602 
    603     delete dlg;
     594    /* Create and execute global settings dialog: */
     595    UISettingsDialogGlobal dlg(this);
     596    dlg.execute();
    604597}
    605598
     
    697690 *  Opens the VM settings dialog.
    698691 */
    699 void VBoxSelectorWnd::vmSettings(const QString &aCategory /* = QString::null */,
    700                                  const QString &aControl /* = QString::null */,
    701                                  const QString &aUuid /* = QString::null */)
    702 {
    703     if (!aCategory.isEmpty() && aCategory [0] != '#')
    704     {
    705         /* Assume it's a href from the Details HTML */
    706         vboxGlobal().openURL(aCategory);
     692void VBoxSelectorWnd::vmSettings(const QString &strCategoryRef /* = QString::null */,
     693                                 const QString &strControlRef /* = QString::null */,
     694                                 const QString &strMachineId /* = QString::null */)
     695{
     696    /* Process href from VM details / description: */
     697    if (!strCategoryRef.isEmpty() && strCategoryRef[0] != '#')
     698    {
     699        vboxGlobal().openURL(strCategoryRef);
    707700        return;
    708701    }
    709     QString strCategory = aCategory;
    710     QString strControl = aControl;
    711     /* Maybe the control is coded into the URL by %% */
    712     if (aControl == QString::null)
    713     {
    714         QStringList parts = aCategory.split("%%");
     702
     703    /* Get category and control: */
     704    QString strCategory = strCategoryRef;
     705    QString strControl = strControlRef;
     706    /* Check if control is coded into the URL by %%: */
     707    if (strControl.isEmpty())
     708    {
     709        QStringList parts = strCategory.split("%%");
    715710        if (parts.size() == 2)
    716711        {
     
    720715    }
    721716
    722     UIVMItem *pItem = aUuid.isNull() ? mVMListView->selectedItem() : mVMModel->itemById(aUuid);
    723     AssertMsgReturnVoid(pItem, ("Item must be always selected here"));
    724 
    725     SettingsDialogType dialogType = machineStateToSettingsDialogType(pItem->machineState());
    726 
    727     CSession session = vboxGlobal().openSession(pItem->id(), dialogType != SettingsDialogType_Offline /* connect to existing? */);
    728     AssertMsgReturnVoid(!session.isNull(), ("Session must not be null"));
    729     CMachine machine = session.GetMachine();
    730     AssertMsgReturnVoid(!machine.isNull(), ("Machine must not be null"));
    731     CConsole console = dialogType == SettingsDialogType_Offline ? CConsole() : session.GetConsole();
    732 
    733     /* Don't show the inaccessible warning if the user open the vm settings: */
     717    /* Don't show the inaccessible warning if the user tries to open VM settings: */
    734718    mDoneInaccessibleWarningOnce = true;
    735719
    736     UISettingsDialog *pDlg = new UISettingsDialogMachine(this, dialogType, machine, console, strCategory, strControl);
    737     pDlg->loadData();
    738 
    739     if (pDlg->exec() == QDialog::Accepted)
    740     {
    741         pDlg->saveData();
    742 
    743         machine.SaveSettings();
    744         if (!machine.isOk())
    745             vboxProblem().cannotSaveMachineSettings(machine);
    746 
    747         /* To check use the result in future:
    748          * vboxProblem().cannotApplyMachineSettings(m, res); */
    749     }
    750 
    751     delete pDlg;
    752 
    753     mVMListView->setFocus();
    754 
    755     session.UnlockMachine();
     720    /* Get corresponding VM item: */
     721    UIVMItem *pItem = strMachineId.isNull() ? mVMListView->selectedItem() : mVMModel->itemById(strMachineId);
     722    AssertMsgReturnVoid(pItem, ("Item must be always selected here!\n"));
     723
     724    /* Create and execute corresponding VM settings dialog: */
     725    UISettingsDialogMachine dlg(this, pItem->id(), strCategory, strControl);
     726    dlg.execute();
    756727}
    757728
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r37106 r37109  
    4343
    4444/* Settings Dialog Constructor: */
    45 UISettingsDialog::UISettingsDialog(QWidget *pParent, SettingsDialogType settingsDialogType)
     45UISettingsDialog::UISettingsDialog(QWidget *pParent)
    4646    /* Parent class: */
    4747    : QIWithRetranslateUI<QIMainDialog>(pParent)
     
    5050    , m_pStack(0)
    5151    /* Common variables: */
    52     , m_dialogType(settingsDialogType)
     52    , m_dialogType(SettingsDialogType_Wrong)
    5353    , m_fPolished(false)
    5454    /* Loading/saving stuff: */
     
    150150}
    151151
     152void UISettingsDialog::execute()
     153{
     154    /* Load data: */
     155    loadData();
     156
     157    /* Execute dialog and wait for completion: */
     158    if (exec() != QDialog::Accepted)
     159        return;
     160
     161    /* Save data: */
     162    saveData();
     163}
     164
    152165void UISettingsDialog::sltRevalidate(QIWidgetValidator *pValidator)
    153166{
     
    254267        if (!pValidator->isValid())
    255268            sltRevalidate(pValidator);
     269    }
     270}
     271
     272void UISettingsDialog::setDialogType(SettingsDialogType settingsDialogType)
     273{
     274    m_dialogType = settingsDialogType;
     275    for (int iWidgetNumber = 0; iWidgetNumber < m_pStack->count(); ++iWidgetNumber)
     276    {
     277        UISettingsPage *pPage = static_cast<UISettingsPage*>(m_pStack->widget(iWidgetNumber));
     278        pPage->setDialogType(dialogType());
    256279    }
    257280}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r37106 r37109  
    4646
    4747    /* Settings Dialog Constructor/Destructor: */
    48     UISettingsDialog(QWidget *pParent, SettingsDialogType settingsDialogType);
     48    UISettingsDialog(QWidget *pParent);
    4949   ~UISettingsDialog();
    5050
    51     /* Save/Load interface: */
    52     virtual void loadData() = 0;
    53     virtual void saveData() = 0;
     51    /* Execute API: */
     52    void execute();
    5453
    5554protected slots:
     
    7069protected:
    7170
     71    /* Save/load API: */
     72    virtual void loadData() = 0;
     73    virtual void saveData() = 0;
     74
    7275    /* UI translator: */
    7376    virtual void retranslateUi();
     
    7578    /* Dialog type: */
    7679    SettingsDialogType dialogType() { return m_dialogType; }
     80    void setDialogType(SettingsDialogType settingsDialogType);
    7781    /* Dialog title: */
    7882    virtual QString title() const = 0;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r37106 r37109  
    3232#include "QIWidgetValidator.h"
    3333#include "VBoxSettingsSelector.h"
     34#include "UIVirtualBoxEventHandler.h"
    3435
    3536#include "UIGlobalSettingsGeneral.h"
     
    305306UISettingsSerializer* UISettingsSerializer::m_pInstance = 0;
    306307
    307 UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent, SettingsDialogType settingsDialogType)
    308     : UISettingsDialog(pParent, settingsDialogType)
     308UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent)
     309    : UISettingsDialog(pParent)
    309310{
    310311    /* Window icon: */
     
    312313    setWindowIcon(QIcon(":/global_settings_16px.png"));
    313314#endif /* !Q_WS_MAC */
     315
     316    /* Assign default dialog type: */
     317    setDialogType(SettingsDialogType_Offline);
    314318
    315319    /* Creating settings pages: */
     
    524528}
    525529
    526 UISettingsDialogMachine::UISettingsDialogMachine(QWidget *pParent, SettingsDialogType settingsDialogType,
    527                                                  const CMachine &machine, const CConsole &console,
     530UISettingsDialogMachine::UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
    528531                                                 const QString &strCategory, const QString &strControl)
    529     : UISettingsDialog(pParent, settingsDialogType)
    530     , m_machine(machine)
    531     , m_console(console)
     532    : UISettingsDialog(pParent)
     533    , m_strMachineId(strMachineId)
    532534    , m_fAllowResetFirstRunFlag(false)
    533535    , m_fResetFirstRunFlag(false)
     
    540542    /* Allow to reset first-run flag just when medium enumeration was finished: */
    541543    connect(&vboxGlobal(), SIGNAL(mediumEnumFinished(const VBoxMediaList &)), this, SLOT(sltAllowResetFirstRunFlag()));
     544
     545    /* Get corresponding machine (required to determine dialog type): */
     546    m_machine = vboxGlobal().virtualBox().FindMachine(m_strMachineId);
     547    AssertMsg(!m_machine.isNull(), ("Can't find corresponding machine!\n"));
     548    /* Assign current dialog type: */
     549    setDialogType(machineStateToSettingsDialogType(m_machine.GetState()));
    542550
    543551    /* Creating settings pages: */
     
    663671    retranslateUi();
    664672
    665     /* Setup Settings Dialog: */
     673    /* Setup settings dialog: */
    666674    if (!strCategory.isNull())
    667675    {
     
    695703    else
    696704        m_pSelector->selectById(0);
     705
     706    /* Make sure settings dialog will be updated on machine state changes: */
     707    connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QString, KMachineState)),
     708            this, SLOT(sltMachineStateChanged(QString, KMachineState)));
     709    connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)),
     710            this, SLOT(sltMachineDataChanged(QString)));
    697711}
    698712
    699713void UISettingsDialogMachine::loadData()
    700714{
     715    /* Check that session is NOT created: */
     716    if (!m_session.isNull())
     717        return;
     718
     719    /* Prepare session: */
     720    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openSession(m_strMachineId, true /* shared */);
     721    /* Check that session was created: */
     722    if (m_session.isNull())
     723        return;
     724
     725    /* Get machine from session: */
     726    m_machine = m_session.GetMachine();
     727    /* Get console from session: */
     728    m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
     729
    701730    /* Prepare machine data: */
    702731    qRegisterMetaType<UISettingsDataMachine>();
     
    719748void UISettingsDialogMachine::saveData()
    720749{
     750    /* Check that session is NOT created: */
     751    if (!m_session.isNull())
     752        return;
     753
     754    /* Prepare session: */
     755    bool fSessionShared = dialogType() != SettingsDialogType_Offline;
     756    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openSession(m_strMachineId, fSessionShared);
     757    /* Check that session was created: */
     758    if (m_session.isNull())
     759        return;
     760
     761    /* Get machine from session: */
     762    m_machine = m_session.GetMachine();
     763    /* Get console from session: */
     764    m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
     765
    721766    /* Prepare machine data: */
    722767    qRegisterMetaType<UISettingsDataMachine>();
     
    734779    /* Get updated machine: */
    735780    m_machine = pMachineSettingsSaver->data().value<UISettingsDataMachine>().m_machine;
    736     m_console = pMachineSettingsSaver->data().value<UISettingsDataMachine>().m_console;
    737781    /* If machine is ok => perform final operations: */
    738782    if (m_machine.isOk())
     
    770814        if (m_fResetFirstRunFlag)
    771815            m_machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString::null);
    772     }
    773     /* If machine is NOT ok => show error message: */
    774     else
    775     {
    776         /* Show final error message: */
     816
     817        /* Save settings finally: */
     818        m_machine.SaveSettings();
     819    }
     820
     821    /* If machine is NOT ok => show the error message: */
     822    if (!m_machine.isOk())
    777823        vboxProblem().cannotSaveMachineSettings(m_machine);
    778     }
     824
     825    /* Mark page processed: */
     826    sltMarkProcessed();
    779827}
    780828
     
    9671015
    9681016    return true;
     1017}
     1018
     1019void UISettingsDialogMachine::sltMarkProcessed()
     1020{
     1021    /* Call for base-class: */
     1022    UISettingsDialog::sltMarkProcessed();
     1023
     1024    /* Unlock the session if exists: */
     1025    if (!m_session.isNull())
     1026    {
     1027        m_session.UnlockMachine();
     1028        m_session = CSession();
     1029        m_machine = CMachine();
     1030        m_console = CConsole();
     1031    }
     1032}
     1033
     1034void UISettingsDialogMachine::sltMachineStateChanged(QString strMachineId, KMachineState machineState)
     1035{
     1036    /* Ignore if thats NOT our VM: */
     1037    if (strMachineId != m_strMachineId)
     1038        return;
     1039
     1040    /* Ignore if state was NOT actually changed: */
     1041    if (m_machineState == machineState)
     1042        return;
     1043
     1044    /* Update current machine state: */
     1045    m_machineState = machineState;
     1046
     1047    /* Get new dialog type: */
     1048    SettingsDialogType newDialogType = machineStateToSettingsDialogType(m_machineState);
     1049
     1050    /* Ignore if dialog type was NOT actually changed: */
     1051    if (dialogType() == newDialogType)
     1052        return;
     1053
     1054    /* Update current dialog type: */
     1055    setDialogType(newDialogType);
     1056}
     1057
     1058void UISettingsDialogMachine::sltMachineDataChanged(QString strMachineId)
     1059{
     1060    /* Ignore if thats NOT our VM: */
     1061    if (strMachineId != m_strMachineId)
     1062        return;
     1063
     1064    /* Reload data: */
     1065    loadData();
    9691066}
    9701067
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h

    r36592 r37109  
    4343    };
    4444
    45     UISettingsDialogGlobal(QWidget *pParent, SettingsDialogType settingsDialogType);
     45    UISettingsDialogGlobal(QWidget *pParent);
    4646
    4747protected:
     
    8282    };
    8383
    84     UISettingsDialogMachine(QWidget *pParent, SettingsDialogType settingsDialogType,
    85                             const CMachine &machine, const CConsole &console,
     84    UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
    8685                            const QString &strCategory, const QString &strControl);
    8786
     
    9998private slots:
    10099
     100    void sltMarkProcessed();
     101    void sltMachineStateChanged(QString strMachineId, KMachineState machineState);
     102    void sltMachineDataChanged(QString strMachineId);
    101103    void sltCategoryChanged(int cId);
    102104    void sltAllowResetFirstRunFlag();
     
    108110    bool isPageAvailable(int iPageId);
    109111
     112    QString m_strMachineId;
     113    KMachineState m_machineState;
     114
     115    CSession m_session;
    110116    CMachine m_machine;
    111117    CConsole m_console;
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