VirtualBox

Changeset 33631 in vbox


Ignore:
Timestamp:
Nov 1, 2010 6:35:05 AM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: Async settings mechanism. Global and Machine settings reworked to use cache loaded and saved in parallel thread.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
46 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r33599 r33631  
    379379        src/extensions/QISplitter.cpp \
    380380        src/selector/UIVMDesktop.cpp \
     381        src/settings/UISettingsDialogSpecific.cpp \
    381382        src/settings/vm/VBoxVMSettingsPortForwardingDlg.cpp \
    382383        src/runtime/UIActionsPool.cpp \
     
    451452        src/settings/UISettingsDialog.cpp \
    452453        src/settings/UISettingsDialogSpecific.cpp \
     454        src/settings/UISettingsPage.cpp \
    453455        src/settings/VBoxSettingsSelector.cpp \
    454456        src/settings/global/VBoxGLSettingsGeneral.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r33626 r33631  
    28132813    mUSBDeviceStates [KUSBDeviceState_Captured] =
    28142814        tr ("Captured", "USBDeviceState");
     2815
     2816    mChipsetTypes [KChipsetType_PIIX3] =
     2817        tr ("PIIX3", "ChipsetType");
     2818    mChipsetTypes [KChipsetType_ICH9] =
     2819        tr ("ICH9", "ChipsetType");
    28152820
    28162821    mUserDefinedPortName = tr ("User-defined", "serial port");
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r33626 r33631  
    490490    }
    491491
     492    QString toString (KChipsetType t) const
     493    {
     494        AssertMsg (!mChipsetTypes.value (t).isNull(), ("No text for %d", t));
     495        return mChipsetTypes.value (t);
     496    }
     497
     498    KChipsetType toChipsetType (const QString &s) const
     499    {
     500        QULongStringHash::const_iterator it =
     501            qFind (mChipsetTypes.begin(), mChipsetTypes.end(), s);
     502        AssertMsg (it != mChipsetTypes.end(), ("No value for {%s}",
     503                                               s.toLatin1().constData()));
     504        return KChipsetType (it.key());
     505    }
     506
    492507    QStringList COMPortNames() const;
    493508    QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
     
    815830    QULongStringHash mStorageControllerTypes;
    816831    QULongStringHash mUSBDeviceStates;
     832    QULongStringHash mChipsetTypes;
    817833
    818834    QString mUserDefinedPortName;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r33540 r33631  
    115115        m_pSettings->setOrderAfter(this);
    116116        VBoxGlobal::setLayoutMargin(m_pSettings->layout(), 0);
    117         m_pSettings->getFrom(m_session.GetMachine());
     117        m_pSettings->loadDirectlyFrom(m_session.GetMachine());
    118118        pMainLayout->addWidget(m_pSettings);
    119119
     
    140140    virtual void accept()
    141141    {
    142         m_pSettings->putBackTo();
     142        m_pSettings->saveDirectlyTo(m_session.GetMachine());
    143143        CMachine machine = m_session.GetMachine();
    144144        machine.SaveSettings();
     
    160160private:
    161161
    162     UISettingsPage *m_pSettings;
     162    VBoxVMSettingsNetworkPage *m_pSettings;
    163163    CSession &m_session;
    164164};
     
    186186
    187187        /* Setup settings layout */
    188         m_pSettings = new VBoxVMSettingsSF(MachineType | ConsoleType, this);
     188        m_pSettings = new VBoxVMSettingsSF;
    189189        VBoxGlobal::setLayoutMargin(m_pSettings->layout(), 0);
    190         m_pSettings->getFromConsole(m_session.GetConsole());
    191         m_pSettings->getFromMachine(m_session.GetMachine());
     190        m_pSettings->loadDirectlyFrom(m_session.GetConsole());
    192191        pMainLayout->addWidget(m_pSettings);
    193192
     
    214213    virtual void accept()
    215214    {
    216         m_pSettings->putBackToConsole();
    217         m_pSettings->putBackToMachine();
     215        m_pSettings->saveDirectlyTo(m_session.GetConsole());
    218216        CMachine machine = m_session.GetMachine();
    219217        machine.SaveSettings();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r33540 r33631  
    161161}
    162162
     163void UISettingsDialog::sltCategoryChanged(int cId)
     164{
     165    QWidget *pRootPage = m_pSelector->rootPage(cId);
     166#ifdef Q_WS_MAC
     167    QSize cs = size();
     168    /* First make all fully resizeable: */
     169    setMinimumSize(QSize(minimumWidth(), 0));
     170    setMaximumSize(QSize(minimumWidth(), QWIDGETSIZE_MAX));
     171    for (int i = 0; i < m_pStack->count(); ++i)
     172        m_pStack->widget(i)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
     173    int a = m_pStack->indexOf(pRootPage);
     174    if (a < m_sizeList.count())
     175    {
     176        QSize ss = m_sizeList.at(a);
     177        m_pStack->widget(a)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
     178        /* Switch to the new page first if we are shrinking: */
     179        if (cs.height() > ss.height())
     180            m_pStack->setCurrentIndex(m_pStack->indexOf(pRootPage));
     181        /* Do the animation: */
     182        ::darwinWindowAnimateResize(this, QRect (x(), y(), ss.width(), ss.height()));
     183        /* Switch to the new page last if we are zooming: */
     184        if (cs.height() <= ss.height())
     185            m_pStack->setCurrentIndex(m_pStack->indexOf(pRootPage));
     186        /* Make the widget fixed size: */
     187        setFixedSize(ss);
     188    }
     189    ::darwinSetShowsResizeIndicator(this, false);
     190#else
     191    m_pLbTitle->setText(m_pSelector->itemText(cId));
     192    m_pStack->setCurrentIndex(m_pStack->indexOf(pRootPage));
     193#endif
     194#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     195    setWindowTitle(title());
     196#endif /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
     197}
     198
    163199void UISettingsDialog::retranslateUi()
    164200{
     
    371407}
    372408
    373 void UISettingsDialog::sltCategoryChanged(int cId)
    374 {
    375     QWidget *pRootPage = m_pSelector->rootPage(cId);
    376 #ifdef Q_WS_MAC
    377     QSize cs = size();
    378     /* First make all fully resizeable: */
    379     setMinimumSize(QSize(minimumWidth(), 0));
    380     setMaximumSize(QSize(minimumWidth(), QWIDGETSIZE_MAX));
    381     for (int i = 0; i < m_pStack->count(); ++i)
    382         m_pStack->widget(i)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
    383     int a = m_pStack->indexOf(pRootPage);
    384     if (a < m_sizeList.count())
    385     {
    386         QSize ss = m_sizeList.at(a);
    387         m_pStack->widget(a)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    388         /* Switch to the new page first if we are shrinking: */
    389         if (cs.height() > ss.height())
    390             m_pStack->setCurrentIndex(m_pStack->indexOf(pRootPage));
    391         /* Do the animation: */
    392         ::darwinWindowAnimateResize(this, QRect (x(), y(), ss.width(), ss.height()));
    393         /* Switch to the new page last if we are zooming: */
    394         if (cs.height() <= ss.height())
    395             m_pStack->setCurrentIndex(m_pStack->indexOf(pRootPage));
    396         /* Make the widget fixed size: */
    397         setFixedSize(ss);
    398     }
    399     ::darwinSetShowsResizeIndicator(this, false);
    400 #else
    401     m_pLbTitle->setText(m_pSelector->itemText(cId));
    402     m_pStack->setCurrentIndex(m_pStack->indexOf(pRootPage));
    403 #endif
    404 #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    405     setWindowTitle(title());
    406 #endif /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
    407 }
    408 
    409409bool UISettingsDialog::eventFilter(QObject *pObject, QEvent *pEvent)
    410410{
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r32814 r33631  
    5353    virtual void sltRevalidate(QIWidgetValidator *pValidator);
    5454
     55    /* Category-change slot: */
     56    virtual void sltCategoryChanged(int cId);
     57
    5558protected:
    5659
     
    8891    void sltUpdateWhatsThis(bool fGotFocus = false);
    8992
    90     /* Category-change slot: */
    91     void sltCategoryChanged(int cId);
    92 
    9393private:
    9494
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r33626 r33631  
    2020/* Global includes */
    2121#include <QStackedWidget>
     22#include <QThread>
     23#include <QTimer>
    2224
    2325/* Local includes */
     
    4951#endif /* Global USB filters are DISABLED now: */
    5052
     53/* Settings page list: */
     54typedef QList<UISettingsPage*> UISettingsPageList;
     55typedef QMap<int, UISettingsPage*> UISettingsPageMap;
     56
     57/* Serializer direction: */
     58enum UISettingsSerializeDirection
     59{
     60    UISettingsSerializeDirection_Load,
     61    UISettingsSerializeDirection_Save
     62};
     63
     64/* QThread reimplementation for loading/saving settings in async mode: */
     65class UISettingsSerializer : public QThread
     66{
     67    Q_OBJECT;
     68
     69public:
     70
     71    /* Settings serializer instance: */
     72    static UISettingsSerializer* instance() { return m_pInstance; }
     73
     74    /* Settings serializer constructor: */
     75    UISettingsSerializer(QObject *pParent, const QVariant &data, UISettingsSerializeDirection direction)
     76        : QThread(pParent)
     77        , m_direction(direction)
     78        , m_data(data)
     79        , m_iPageIdWeAreWaitingFor(-1)
     80        , m_iIdOfHighPriorityPage(-1)
     81    {
     82        /* Connecting thread signals: */
     83        connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), this, SLOT(sltHandleProcessedPage(int)), Qt::QueuedConnection);
     84        connect(this, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltHandleProcessedPages()), Qt::QueuedConnection);
     85        connect(this, SIGNAL(finished()), this, SLOT(sltDestroySerializer()), Qt::QueuedConnection);
     86
     87        /* Set instance: */
     88        m_pInstance = this;
     89    }
     90
     91    /* Settings serializer destructor: */
     92    ~UISettingsSerializer()
     93    {
     94        /* Reset instance: */
     95        m_pInstance = 0;
     96
     97        /* If serializer is being destructed by it's parent,
     98         * thread could still be running, we have to wait
     99         * for it to be finished! */
     100        if (isRunning())
     101            wait();
     102
     103        /* If serializer still having event loop running,
     104         * we should quit it now: */
     105        if (m_eventLoop.isRunning())
     106        {
     107            m_eventLoop.processEvents();
     108            m_eventLoop.quit();
     109        }
     110    }
     111
     112    /* Set pages list: */
     113    void setPageList(const UISettingsPageList &pageList)
     114    {
     115        for (int iPageIndex = 0; iPageIndex < pageList.size(); ++iPageIndex)
     116        {
     117            UISettingsPage *pPage = pageList[iPageIndex];
     118            m_pages.insert(pPage->id(), pPage);
     119        }
     120    }
     121
     122    /* Blocks calling thread until requested page will be processed: */
     123    void waitForPageToBeProcessed(int iPageId)
     124    {
     125        if (!isRunning())
     126            return;
     127        m_iPageIdWeAreWaitingFor = iPageId;
     128        m_eventLoop.exec();
     129    }
     130
     131    /* Blocks calling thread until all pages will be processed: */
     132    void waitForPagesToBeProcessed()
     133    {
     134        if (!isRunning())
     135            return;
     136        m_iPageIdWeAreWaitingFor = -1;
     137        m_eventLoop.exec();
     138    }
     139
     140    /* Raise priority of page: */
     141    void raisePriorityOfPage(int iPageId)
     142    {
     143        /* If that page is not present or was processed already: */
     144        if (!m_pages.contains(iPageId) || m_pages[iPageId]->processed())
     145        {
     146            /* We just ignoring that request: */
     147            return;
     148        }
     149        else
     150        {
     151            /* Else remember which page we should be processed next: */
     152            m_iIdOfHighPriorityPage = iPageId;
     153        }
     154    }
     155
     156    /* Return current m_data content: */
     157    QVariant& data() { return m_data; }
     158
     159signals:
     160
     161    /* Signal to notify main GUI thread about some page was processed: */
     162    void sigNotifyAboutPageProcessed(int iPageId);
     163
     164    /* Signal to notify main GUI thread about all pages were processed: */
     165    void sigNotifyAboutPagesProcessed();
     166
     167public slots:
     168
     169    void start(Priority priority = InheritPriority)
     170    {
     171        /* If serializer saves settings: */
     172        if (m_direction == UISettingsSerializeDirection_Save)
     173        {
     174            /* We should update internal page cache first: */
     175            for (int iPageIndex = 0; iPageIndex < m_pages.values().size(); ++iPageIndex)
     176                m_pages.values()[iPageIndex]->putToCache();
     177        }
     178        /* Start async thread: */
     179        QThread::start(priority);
     180    }
     181
     182protected slots:
     183
     184    /* Slot to handle the fact of some page was processed: */
     185    void sltHandleProcessedPage(int iPageId)
     186    {
     187        /* If serializer loads settings: */
     188        if (m_direction == UISettingsSerializeDirection_Load)
     189        {
     190            /* If such page present we should fetch internal page cache: */
     191            if (m_pages.contains(iPageId))
     192                m_pages[iPageId]->getFromCache();
     193        }
     194        /* If thats the page we are waiting for, unlock the loop,
     195         * after all the events of the page which is currently fetching
     196         * from cache will be processed: */
     197        if (iPageId == m_iPageIdWeAreWaitingFor && m_eventLoop.isRunning())
     198            QTimer::singleShot(0, this, SLOT(sltStopEventLoop()));
     199    }
     200
     201    /* Slot to handle the fact of some page was processed: */
     202    void sltHandleProcessedPages()
     203    {
     204        /* If all the pages were processed, unlock the loop,
     205         * after all the events of the last page will be processed: */
     206        if (m_eventLoop.isRunning())
     207            QTimer::singleShot(0, this, SLOT(sltStopEventLoop()));
     208    }
     209
     210    /* Slot to destroy serializer: */
     211    void sltDestroySerializer()
     212    {
     213        /* If event loop is still running,
     214         * we should try to destroy serializer only on next iteration: */
     215        if (m_eventLoop.isRunning())
     216            QTimer::singleShot(0, this, SLOT(sltDestroySerializer()));
     217        /* Else really make a request to destroy serializer: */
     218        else
     219            deleteLater();
     220    }
     221
     222    /* Slot to stop event loop: */
     223    void sltStopEventLoop()
     224    {
     225        /* If event loop is still running, we should stop it: */
     226        if (m_eventLoop.isRunning())
     227        {
     228            m_eventLoop.processEvents();
     229            m_eventLoop.quit();
     230        }
     231    }
     232
     233protected:
     234
     235    /* Settings processor: */
     236    void run()
     237    {
     238        /* Iterate over the all left settings pages: */
     239        UISettingsPageMap pages(m_pages);
     240        while (!pages.empty())
     241        {
     242            /* Get required page pointer, protect map by mutex while getting pointer: */
     243            UISettingsPage *pPage = m_iIdOfHighPriorityPage != -1 && pages.contains(m_iIdOfHighPriorityPage) ?
     244                                    pages[m_iIdOfHighPriorityPage] : *pages.begin();
     245            /* Reset request of high priority: */
     246            if (m_iIdOfHighPriorityPage != -1)
     247                m_iIdOfHighPriorityPage = -1;
     248            /* Process this page if its enabled: */
     249            if (pPage->isEnabled())
     250            {
     251                if (m_direction == UISettingsSerializeDirection_Load)
     252                    pPage->loadToCacheFrom(m_data);
     253                if (m_direction == UISettingsSerializeDirection_Save)
     254                    pPage->saveFromCacheTo(m_data);
     255            }
     256            /* Remember what page was processed: */
     257            pPage->setProcessed(true);
     258            /* Notify listeners about page was processed: */
     259            emit sigNotifyAboutPageProcessed(pPage->id());
     260            /* Remove processed page from our map: */
     261            pages.remove(pPage->id());
     262        }
     263        /* Notify listeners about all pages were processed: */
     264        emit sigNotifyAboutPagesProcessed();
     265    }
     266
     267    /* Variables: */
     268    UISettingsSerializeDirection m_direction;
     269    QVariant m_data;
     270    QEventLoop m_eventLoop;
     271    UISettingsPageMap m_pages;
     272    int m_iPageIdWeAreWaitingFor;
     273    int m_iIdOfHighPriorityPage;
     274    static UISettingsSerializer *m_pInstance;
     275};
     276
     277UISettingsSerializer* UISettingsSerializer::m_pInstance = 0;
     278
    51279UIGLSettingsDlg::UIGLSettingsDlg(QWidget *pParent)
    52280    : UISettingsDialog(pParent)
     
    68296                {
    69297                    UISettingsPage *pSettingsPage = new VBoxGLSettingsGeneral;
     298                    pSettingsPage->setId(i);
    70299                    addItem(":/machine_32px.png", ":/machine_disabled_32px.png",
    71300                            ":/machine_16px.png", ":/machine_disabled_16px.png",
     
    77306                {
    78307                    UISettingsPage *pSettingsPage = new VBoxGLSettingsInput;
     308                    pSettingsPage->setId(i);
    79309                    addItem(":/hostkey_32px.png", ":/hostkey_disabled_32px.png",
    80310                            ":/hostkey_16px.png", ":/hostkey_disabled_16px.png",
     
    86316                {
    87317                    UISettingsPage *pSettingsPage = new VBoxGLSettingsUpdate;
     318                    pSettingsPage->setId(i);
    88319                    addItem(":/refresh_32px.png", ":/refresh_disabled_32px.png",
    89320                            ":/refresh_16px.png", ":/refresh_disabled_16px.png",
     
    95326                {
    96327                    UISettingsPage *pSettingsPage = new VBoxGLSettingsLanguage;
     328                    pSettingsPage->setId(i);
    97329                    addItem(":/site_32px.png", ":/site_disabled_32px.png",
    98330                            ":/site_16px.png", ":/site_disabled_16px.png",
     
    103335                case GLSettingsPage_USB:
    104336                {
    105                     UISettingsPage *pSettingsPage = new VBoxVMSettingsUSB(VBoxVMSettingsUSB::HostType);
     337                    UISettingsPage *pSettingsPage = new VBoxVMSettingsUSB(UISettingsPageType_Global);
     338                    pSettingsPage->setId(i);
    106339                    addItem(":/usb_32px.png", ":/usb_disabled_32px.png",
    107340                            ":/usb_16px.png", ":/usb_disabled_16px.png",
     
    113346                {
    114347                    UISettingsPage *pSettingsPage = new VBoxGLSettingsNetwork;
     348                    pSettingsPage->setId(i);
    115349                    addItem(":/nw_32px.png", ":/nw_disabled_32px.png",
    116350                            ":/nw_16px.png", ":/nw_disabled_16px.png",
     
    133367void UIGLSettingsDlg::getFrom()
    134368{
     369    /* Prepare global data: */
     370    qRegisterMetaType<UISettingsDataGlobal>();
     371    UISettingsDataGlobal data(vboxGlobal().virtualBox().GetSystemProperties(), vboxGlobal().settings());
     372    /* Create global settings loader,
     373     * it will load global settings & delete itself in the appropriate time: */
     374    UISettingsSerializer *pGlobalSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
     375    /* Set pages to be loaded: */
     376    pGlobalSettingsLoader->setPageList(m_pSelector->settingPages());
     377    /* Start loader: */
     378    pGlobalSettingsLoader->start();
     379    /* Wait for just one (first) page to be loaded: */
     380    pGlobalSettingsLoader->waitForPageToBeProcessed(m_pSelector->currentId());
     381}
     382
     383void UIGLSettingsDlg::putBackTo()
     384{
    135385    /* Get properties and settings: */
    136386    CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties();
    137387    VBoxGlobalSettings settings = vboxGlobal().settings();
    138     /* Iterate over the settings pages: */
    139     QList<UISettingsPage*> pages = m_pSelector->settingPages();
    140     for (int i = 0; i < pages.size(); ++i)
    141     {
    142         /* For every page => load the settings: */
    143         UISettingsPage *pPage = pages[i];
    144         if (pPage->isEnabled())
    145             pPage->getFrom(properties, settings);
    146     }
    147 }
    148 
    149 void UIGLSettingsDlg::putBackTo()
    150 {
    151     /* Get properties and settings: */
    152     CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties();
    153     VBoxGlobalSettings oldSettings = vboxGlobal().settings();
    154     VBoxGlobalSettings newSettings = oldSettings;
    155     /* Iterate over the settings pages: */
    156     QList<UISettingsPage*> pages = m_pSelector->settingPages();
    157     for (int i = 0; i < pages.size(); ++i)
    158     {
    159         /* For every page => save the settings: */
    160         UISettingsPage *pPage = pages[i];
    161         if (pPage->isEnabled())
    162             pPage->putBackTo(properties, newSettings);
    163     }
     388    /* Prepare global data: */
     389    qRegisterMetaType<UISettingsDataGlobal>();
     390    UISettingsDataGlobal data(properties, settings);
     391    /* Create global settings saver,
     392     * it will save global settings & delete itself in the appropriate time: */
     393    UISettingsSerializer *pGlobalSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
     394    /* Set pages to be saved: */
     395    pGlobalSettingsSaver->setPageList(m_pSelector->settingPages());
     396    /* Start saver: */
     397    pGlobalSettingsSaver->start();
     398    /* Wait for all pages to be saved: */
     399    pGlobalSettingsSaver->waitForPagesToBeProcessed();
     400
     401    /* Get updated properties & settings: */
     402    CSystemProperties newProperties = pGlobalSettingsSaver->data().value<UISettingsDataGlobal>().m_properties;
     403    VBoxGlobalSettings newSettings = pGlobalSettingsSaver->data().value<UISettingsDataGlobal>().m_settings;
    164404    /* If properties are not OK => show the error: */
    165     if (!properties.isOk())
    166         vboxProblem().cannotSetSystemProperties(properties);
     405    if (!newProperties.isOk())
     406        vboxProblem().cannotSetSystemProperties(newProperties);
    167407    /* Else save the new settings if they were changed: */
    168     else if (!(newSettings == oldSettings))
     408    else if (!(newSettings == settings))
    169409        vboxGlobal().setSettings(newSettings);
    170410}
     
    271511                {
    272512                    UISettingsPage *pSettingsPage = new VBoxVMSettingsGeneral;
     513                    pSettingsPage->setId(i);
    273514                    addItem(":/machine_32px.png", ":/machine_disabled_32px.png",
    274515                            ":/machine_16px.png", ":/machine_disabled_16px.png",
     
    280521                {
    281522                    UISettingsPage *pSettingsPage = new VBoxVMSettingsSystem;
     523                    pSettingsPage->setId(i);
    282524                    connect(pSettingsPage, SIGNAL(tableChanged()), this, SLOT(sltResetFirstRunFlag()));
    283525                    addItem(":/chipset_32px.png", ":/chipset_disabled_32px.png",
     
    290532                {
    291533                    UISettingsPage *pSettingsPage = new VBoxVMSettingsDisplay;
     534                    pSettingsPage->setId(i);
    292535                    addItem(":/vrdp_32px.png", ":/vrdp_disabled_32px.png",
    293536                            ":/vrdp_16px.png", ":/vrdp_disabled_16px.png",
     
    299542                {
    300543                    UISettingsPage *pSettingsPage = new VBoxVMSettingsHD;
     544                    pSettingsPage->setId(i);
    301545                    connect(pSettingsPage, SIGNAL(storageChanged()), this, SLOT(sltResetFirstRunFlag()));
    302546                    addItem(":/hd_32px.png", ":/hd_disabled_32px.png",
     
    309553                {
    310554                    UISettingsPage *pSettingsPage = new VBoxVMSettingsAudio;
     555                    pSettingsPage->setId(i);
    311556                    addItem(":/sound_32px.png", ":/sound_disabled_32px.png",
    312557                            ":/sound_16px.png", ":/sound_disabled_16px.png",
     
    318563                {
    319564                    UISettingsPage *pSettingsPage = new VBoxVMSettingsNetworkPage;
     565                    pSettingsPage->setId(i);
    320566                    addItem(":/nw_32px.png", ":/nw_disabled_32px.png",
    321567                            ":/nw_16px.png", ":/nw_disabled_16px.png",
     
    335581                {
    336582                    UISettingsPage *pSettingsPage = new VBoxVMSettingsSerialPage;
     583                    pSettingsPage->setId(i);
    337584                    addItem(":/serial_port_32px.png", ":/serial_port_disabled_32px.png",
    338585                            ":/serial_port_16px.png", ":/serial_port_disabled_16px.png",
     
    344591                {
    345592                    UISettingsPage *pSettingsPage = new VBoxVMSettingsParallelPage;
     593                    pSettingsPage->setId(i);
    346594                    addItem(":/parallel_port_32px.png", ":/parallel_port_disabled_32px.png",
    347595                            ":/parallel_port_16px.png", ":/parallel_port_disabled_16px.png",
     
    352600                case VMSettingsPage_USB:
    353601                {
    354                     UISettingsPage *pSettingsPage = new VBoxVMSettingsUSB(VBoxVMSettingsUSB::MachineType);
     602                    UISettingsPage *pSettingsPage = new VBoxVMSettingsUSB(UISettingsPageType_Machine);
     603                    pSettingsPage->setId(i);
    355604                    addItem(":/usb_32px.png", ":/usb_disabled_32px.png",
    356605                            ":/usb_16px.png", ":/usb_disabled_16px.png",
     
    361610                case VMSettingsPage_SF:
    362611                {
    363                     UISettingsPage *pSettingsPage = new VBoxVMSettingsSF(MachineType);
     612                    UISettingsPage *pSettingsPage = new VBoxVMSettingsSF;
     613                    pSettingsPage->setId(i);
    364614                    addItem(":/shared_folder_32px.png", ":/shared_folder_disabled_32px.png",
    365615                            ":/shared_folder_16px.png", ":/shared_folder_disabled_16px.png",
     
    367617                    break;
    368618                }
     619                default:
     620                    break;
    369621            }
    370622        }
     
    410662void UIVMSettingsDlg::getFrom()
    411663{
    412     /* Iterate over the settings pages: */
    413     QList<UISettingsPage*> pages = m_pSelector->settingPages();
    414     for (int i = 0; i < pages.size(); ++i)
    415     {
    416         /* For every page => load the settings: */
    417         UISettingsPage *pPage = pages[i];
    418         if (pPage->isEnabled())
    419             pPage->getFrom(m_machine);
    420     }
    421     /* Finally set the reset First Run Wizard flag to "false" to make sure
    422      * user will see this dialog if he hasn't change the boot-order
    423      * and/or mounted images configuration: */
    424     m_fResetFirstRunFlag = false;
     664    /* Prepare machine data: */
     665    qRegisterMetaType<UISettingsDataMachine>();
     666    UISettingsDataMachine data(m_machine);
     667    /* Create machine settings loader,
     668     * it will load machine settings & delete itself in the appropriate time: */
     669    UISettingsSerializer *pMachineSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
     670    connect(pMachineSettingsLoader, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltSetFirstRunFlag()));
     671    /* Set pages to be loaded: */
     672    pMachineSettingsLoader->setPageList(m_pSelector->settingPages());
     673    /* Ask to raise required page priority: */
     674    pMachineSettingsLoader->raisePriorityOfPage(m_pSelector->currentId());
     675    /* Start page loader: */
     676    pMachineSettingsLoader->start();
     677    /* Wait for just one (required) page to be loaded: */
     678    pMachineSettingsLoader->waitForPageToBeProcessed(m_pSelector->currentId());
    425679}
    426680
    427681void UIVMSettingsDlg::putBackTo()
    428682{
    429     /* Iterate over the settings pages: */
    430     QList<UISettingsPage*> pages = m_pSelector->settingPages();
    431     for (int i = 0; i < pages.size(); ++i)
    432     {
    433         /* For every page => save the settings: */
    434         UISettingsPage *pPage = pages[i];
    435         if (pPage->isEnabled())
    436             pPage->putBackTo();
    437     }
     683    /* Prepare machine data: */
     684    qRegisterMetaType<UISettingsDataMachine>();
     685    UISettingsDataMachine data(m_machine);
     686    /* Create machine settings saver,
     687     * it will save machine settings & delete itself in the appropriate time: */
     688    UISettingsSerializer *pMachineSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
     689    /* Set pages to be saved: */
     690    pMachineSettingsSaver->setPageList(m_pSelector->settingPages());
     691    /* Start saver: */
     692    pMachineSettingsSaver->start();
     693    /* Wait for all pages to be saved: */
     694    pMachineSettingsSaver->waitForPagesToBeProcessed();
     695
     696    /* Get updated machine: */
     697    m_machine = pMachineSettingsSaver->data().value<UISettingsDataMachine>().m_machine;
     698    /* If machine is not OK => show the error: */
     699    if (!m_machine.isOk())
     700        vboxProblem().cannotSaveMachineSettings(m_machine);
    438701
    439702    /* Guest OS type & VT-x/AMD-V option correlation auto-fix: */
     
    482745     * vboxGlobal which is retranslated at that point already. */
    483746    QEvent event(QEvent::LanguageChange);
    484     QWidget *pPage = 0;
    485747
    486748    /* General page: */
     
    501763    /* Network page: */
    502764    m_pSelector->setItemText(VMSettingsPage_Network, tr("Network"));
    503     if ((pPage = m_pSelector->idToPage(VMSettingsPage_Network)))
     765    if (QWidget *pPage = m_pSelector->idToPage(VMSettingsPage_Network))
    504766        qApp->sendEvent(pPage, &event);
    505767
     
    509771    /* Serial page: */
    510772    m_pSelector->setItemText(VMSettingsPage_Serial, tr("Serial Ports"));
    511     if ((pPage = m_pSelector->idToPage(VMSettingsPage_Serial)))
     773    if (QWidget *pPage = m_pSelector->idToPage(VMSettingsPage_Serial))
    512774        qApp->sendEvent(pPage, &event);
    513775
    514776    /* Parallel page: */
    515777    m_pSelector->setItemText(VMSettingsPage_Parallel, tr("Parallel Ports"));
    516     if ((pPage = m_pSelector->idToPage(VMSettingsPage_Parallel)))
     778    if (QWidget *pPage = m_pSelector->idToPage(VMSettingsPage_Parallel))
    517779        qApp->sendEvent(pPage, &event);
    518780
     
    552814     * between different pages of VM Settings dialog: */
    553815
    554     if (pPage == m_pSelector->idToPage(VMSettingsPage_General) ||
    555         pPage == m_pSelector->idToPage(VMSettingsPage_System))
     816    if (pPage == m_pSelector->idToPage(VMSettingsPage_General))
    556817    {
    557818        /* Get General & System pages: */
     
    603864
    604865#ifndef VBOX_OSE
    605     if (pPage == m_pSelector->idToPage(VMSettingsPage_System) ||
    606         pPage == m_pSelector->idToPage(VMSettingsPage_USB))
     866    if (pPage == m_pSelector->idToPage(VMSettingsPage_System))
    607867    {
    608868        /* Get System & USB pages: */
     
    627887}
    628888
     889void UIVMSettingsDlg::sltCategoryChanged(int cId)
     890{
     891    if (UISettingsSerializer::instance())
     892        UISettingsSerializer::instance()->raisePriorityOfPage(cId);
     893
     894    UISettingsDialog::sltCategoryChanged(cId);
     895}
     896
    629897void UIVMSettingsDlg::sltAllowResetFirstRunFlag()
    630898{
    631899    m_fAllowResetFirstRunFlag = true;
     900}
     901
     902void UIVMSettingsDlg::sltSetFirstRunFlag()
     903{
     904    m_fResetFirstRunFlag = false;
    632905}
    633906
     
    684957}
    685958
     959# include "UISettingsDialogSpecific.moc"
     960
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h

    r33540 r33631  
    9797private slots:
    9898
     99    void sltCategoryChanged(int cId);
    99100    void sltAllowResetFirstRunFlag();
     101    void sltSetFirstRunFlag();
    100102    void sltResetFirstRunFlag();
    101103
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPage.cpp

    r33421 r33631  
     1/* $Id$ */
    12/** @file
    23 *
    34 * VBox frontends: Qt4 GUI ("VirtualBox"):
    4  * UISettingsPage class declaration
     5 * UISettingsPage class implementation
    56 */
    67
     
    1718 */
    1819
    19 #ifndef __UISettingsPage_h__
    20 #define __UISettingsPage_h__
     20/* Local includes */
     21#include "UISettingsPage.h"
    2122
    22 /* Global includes */
    23 #include <QWidget>
     23/* Returns settings page type: */
     24UISettingsPageType UISettingsPage::type() const
     25{
     26    return m_type;
     27}
    2428
    25 /* Local includes */
    26 #include "QIWithRetranslateUI.h"
    27 #include "COMDefs.h"
     29/* Validation stuff: */
     30void UISettingsPage::setValidator(QIWidgetValidator *pValidator)
     31{
     32    Q_UNUSED(pValidator);
     33}
    2834
    29 /* Forward declarations */
    30 class VBoxGlobalSettings;
    31 class QIWidgetValidator;
     35/* Validation stuff: */
     36bool UISettingsPage::revalidate(QString &strWarningText, QString &strTitle)
     37{
     38    Q_UNUSED(strWarningText);
     39    Q_UNUSED(strTitle);
     40    return true;
     41}
    3242
    33 /* Settings page base class: */
    34 class UISettingsPage : public QIWithRetranslateUI<QWidget>
     43/* Navigation stuff: */
     44void UISettingsPage::setOrderAfter(QWidget *pWidget)
    3545{
    36     Q_OBJECT;
     46    m_pFirstWidget = pWidget;
     47}
    3748
    38 public:
     49/* Page 'ID' stuff: */
     50int UISettingsPage::id() const
     51{
     52    return m_cId;
     53}
    3954
    40     /* Settings page constructor: */
    41     UISettingsPage(QWidget *pParent = 0)
    42         : QIWithRetranslateUI<QWidget>(pParent)
    43         , m_pFirstWidget(0)
    44     {
    45     }
     55/* Page 'ID' stuff: */
     56void UISettingsPage::setId(int cId)
     57{
     58    m_cId = cId;
     59}
    4660
    47     /* Global settings set/get stuff */
    48     virtual void getFrom (const CSystemProperties & /* aProps */,
    49                           const VBoxGlobalSettings & /* aGs */) {}
    50     virtual void putBackTo (CSystemProperties & /* aProps */,
    51                             VBoxGlobalSettings & /* aGs */) {}
     61/* Page 'processed' stuff: */
     62bool UISettingsPage::processed() const
     63{
     64    return m_fProcessed;
     65}
    5266
    53     /* VM settings set/get stuff */
    54     virtual void getFrom (const CMachine & /* aMachine */) {}
    55     virtual void putBackTo() {}
     67/* Page 'processed' stuff: */
     68void UISettingsPage::setProcessed(bool fProcessed)
     69{
     70    m_fProcessed = fProcessed;
     71}
    5672
    57     /* Validation stuff: */
    58     virtual void setValidator(QIWidgetValidator * /* pValidator */) {}
    59     virtual bool revalidate(QString & /* strWarningText */, QString & /* strTitle */) { return true; }
     73/* Settings page constructor, hidden: */
     74UISettingsPage::UISettingsPage(UISettingsPageType type, QWidget *pParent)
     75    : QIWithRetranslateUI<QWidget>(pParent)
     76    , m_type(type)
     77    , m_cId(-1)
     78    , m_fProcessed(false)
     79    , m_pFirstWidget(0)
     80{
     81}
    6082
    61     /* Navigation stuff: */
    62     virtual void setOrderAfter(QWidget *pWidget) { m_pFirstWidget = pWidget; }
     83/* Fetch data to m_properties & m_settings: */
     84void UISettingsPageGlobal::fetchData(const QVariant &data)
     85{
     86    m_properties = data.value<UISettingsDataGlobal>().m_properties;
     87    m_settings = data.value<UISettingsDataGlobal>().m_settings;
     88}
    6389
    64 protected:
     90/* Upload m_properties & m_settings to data: */
     91void UISettingsPageGlobal::uploadData(QVariant &data) const
     92{
     93    data = QVariant::fromValue(UISettingsDataGlobal(m_properties, m_settings));
     94}
    6595
    66     QWidget *m_pFirstWidget;
    67 };
     96/* Global settings page constructor, hidden: */
     97UISettingsPageGlobal::UISettingsPageGlobal(QWidget *pParent)
     98    : UISettingsPage(UISettingsPageType_Global, pParent)
     99{
     100}
    68101
    69 #endif // __UISettingsPage_h__
     102/* Fetch data to m_machine: */
     103void UISettingsPageMachine::fetchData(const QVariant &data)
     104{
     105    m_machine = data.value<UISettingsDataMachine>().m_machine;
     106}
    70107
     108/* Upload m_machine to data: */
     109void UISettingsPageMachine::uploadData(QVariant &data) const
     110{
     111    data = QVariant::fromValue(UISettingsDataMachine(m_machine));
     112}
     113
     114/* Machine settings page constructor, hidden: */
     115UISettingsPageMachine::UISettingsPageMachine(QWidget *pParent)
     116    : UISettingsPage(UISettingsPageType_Machine, pParent)
     117{
     118}
     119
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPage.h

    r32814 r33631  
    2222/* Global includes */
    2323#include <QWidget>
     24#include <QVariant>
    2425
    2526/* Local includes */
    2627#include "QIWithRetranslateUI.h"
    2728#include "COMDefs.h"
     29#include "VBoxGlobalSettings.h"
    2830
    2931/* Forward declarations */
    30 class VBoxGlobalSettings;
    3132class QIWidgetValidator;
     33
     34/* Settings page types: */
     35enum UISettingsPageType
     36{
     37    UISettingsPageType_Global,
     38    UISettingsPageType_Machine
     39};
     40
     41/* Global settings data wrapper: */
     42struct UISettingsDataGlobal
     43{
     44    UISettingsDataGlobal() {}
     45    UISettingsDataGlobal(const CSystemProperties &properties, const VBoxGlobalSettings &settings)
     46        : m_properties(properties), m_settings(settings) {}
     47    CSystemProperties m_properties;
     48    VBoxGlobalSettings m_settings;
     49};
     50Q_DECLARE_METATYPE(UISettingsDataGlobal);
     51
     52/* Machine settings data wrapper: */
     53struct UISettingsDataMachine
     54{
     55    UISettingsDataMachine() {}
     56    UISettingsDataMachine(const CMachine &machine)
     57        : m_machine(machine) {}
     58    CMachine m_machine;
     59};
     60Q_DECLARE_METATYPE(UISettingsDataMachine);
    3261
    3362/* Settings page base class: */
     
    3867public:
    3968
    40     /* Settings page constructor: */
    41     UISettingsPage(QWidget *pParent = 0)
    42         : QIWithRetranslateUI<QWidget>(pParent)
    43         , m_pFirstWidget(0)
    44     {
    45     }
     69    /* Load data to cashe from corresponding external object(s),
     70     * this task COULD be performed in other than GUI thread: */
     71    virtual void loadToCacheFrom(QVariant &data) = 0;
     72    /* Load data to corresponding widgets from cache,
     73     * this task SHOULD be performed in GUI thread only: */
     74    virtual void getFromCache() = 0;
    4675
    47     /* Global settings set/get stuff */
    48     virtual void getFrom (const CSystemProperties & /* aProps */,
    49                           const VBoxGlobalSettings & /* aGs */) {}
    50     virtual void putBackTo (CSystemProperties & /* aProps */,
    51                             VBoxGlobalSettings & /* aGs */) {}
     76    /* Save data from corresponding widgets to cache,
     77     * this task SHOULD be performed in GUI thread only: */
     78    virtual void putToCache() = 0;
     79    /* Save data from cache to corresponding external object(s),
     80     * this task COULD be performed in other than GUI thread: */
     81    virtual void saveFromCacheTo(QVariant &data) = 0;
    5282
    53     /* VM settings set/get stuff */
    54     virtual void getFrom (const CMachine & /* aMachine */) {}
    55     virtual void putBackTo() {}
     83    /* Returns settings page type: */
     84    virtual UISettingsPageType type() const;
    5685
    5786    /* Validation stuff: */
    58     virtual void setValidator(QIWidgetValidator * /* pValidator */) {}
    59     virtual bool revalidate(QString & /* strWarningText */, QString & /* strTitle */) { return true; }
     87    virtual void setValidator(QIWidgetValidator *pValidator);
     88    virtual bool revalidate(QString &strWarningText, QString &strTitle);
    6089
    6190    /* Navigation stuff: */
    62     virtual void setOrderAfter(QWidget *pWidget) { m_pFirstWidget = pWidget; }
     91    virtual void setOrderAfter(QWidget *pWidget);
     92
     93    /* Page 'ID' stuff: */
     94    int id() const;
     95    void setId(int cId);
     96
     97    /* Page 'processed' stuff: */
     98    bool processed() const;
     99    void setProcessed(bool fProcessed);
    63100
    64101protected:
    65102
     103    /* Settings page constructor, hidden: */
     104    UISettingsPage(UISettingsPageType type, QWidget *pParent = 0);
     105
     106    /* Variables: */
     107    UISettingsPageType m_type;
     108    int m_cId;
     109    bool m_fProcessed;
    66110    QWidget *m_pFirstWidget;
     111};
     112
     113/* Global settings page class: */
     114class UISettingsPageGlobal : public UISettingsPage
     115{
     116    Q_OBJECT;
     117
     118protected:
     119
     120    /* Fetch data to m_properties & m_settings: */
     121    void fetchData(const QVariant &data);
     122
     123    /* Upload m_properties & m_settings to data: */
     124    void uploadData(QVariant &data) const;
     125
     126    /* Global settings page constructor, hidden: */
     127    UISettingsPageGlobal(QWidget *pParent = 0);
     128
     129    /* Global data source: */
     130    CSystemProperties m_properties;
     131    VBoxGlobalSettings m_settings;
     132};
     133
     134/* Machine settings page class: */
     135class UISettingsPageMachine : public UISettingsPage
     136{
     137    Q_OBJECT;
     138
     139protected:
     140
     141    /* Fetch data to m_machine: */
     142    void fetchData(const QVariant &data);
     143
     144    /* Upload m_machine to data: */
     145    void uploadData(QVariant &data) const;
     146
     147    /* Machine settings page constructor, hidden: */
     148    UISettingsPageMachine(QWidget *pParent = 0);
     149
     150    /* Machine data source: */
     151    CMachine m_machine;
    67152};
    68153
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsGeneral.cpp

    r33386 r33631  
    77
    88/*
    9  * Copyright (C) 2006-2008 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4848        mLnSeparator2->hide();
    4949
    50     mPsHardDisk->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
    5150    mPsMach->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
    5251    mPsVRDP->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
     
    5756}
    5857
    59 void VBoxGLSettingsGeneral::getFrom (const CSystemProperties &aProps,
    60                                      const VBoxGlobalSettings &aGs)
     58/* Load data to cashe from corresponding external object(s),
     59 * this task COULD be performed in other than GUI thread: */
     60void VBoxGLSettingsGeneral::loadToCacheFrom(QVariant &data)
    6161{
    62     mPsMach->setPath (aProps.GetDefaultMachineFolder());
    63     mPsVRDP->setPath (aProps.GetVRDEAuthLibrary());
    64     mCbCheckTrayIcon->setChecked (aGs.trayIconEnabled());
     62    /* Fetch data to properties & settings: */
     63    UISettingsPageGlobal::fetchData(data);
     64
     65    /* Load to cache: */
     66    m_cache.m_strDefaultMachineFolder = m_properties.GetDefaultMachineFolder();
     67    m_cache.m_strVRDEAuthLibrary = m_properties.GetVRDEAuthLibrary();
     68    m_cache.m_fTrayIconEnabled = m_settings.trayIconEnabled();
    6569#ifdef Q_WS_MAC
    66     mCbCheckPresentationMode->setChecked (aGs.presentationModeEnabled());
     70    m_cache.m_fPresentationModeEnabled = m_settings.presentationModeEnabled();
    6771#endif /* Q_WS_MAC */
    68     mCbDisableHostScreenSaver->setChecked (aGs.hostScreenSaverDisabled());
     72    m_cache.m_fHostScreenSaverDisables = m_settings.hostScreenSaverDisabled();
     73
     74    /* Upload properties & settings to data: */
     75    UISettingsPageGlobal::uploadData(data);
    6976}
    7077
    71 void VBoxGLSettingsGeneral::putBackTo (CSystemProperties &aProps,
    72                                        VBoxGlobalSettings &aGs)
     78/* Load data to corresponding widgets from cache,
     79 * this task SHOULD be performed in GUI thread only: */
     80void VBoxGLSettingsGeneral::getFromCache()
    7381{
    74     if (aProps.isOk() && mPsMach->isModified())
    75         aProps.SetDefaultMachineFolder (mPsMach->path());
    76     if (aProps.isOk() && mPsVRDP->isModified())
    77         aProps.SetVRDEAuthLibrary (mPsVRDP->path());
    78     aGs.setTrayIconEnabled (mCbCheckTrayIcon->isChecked());
     82    /* Fetch from cache: */
     83    mPsMach->setPath(m_cache.m_strDefaultMachineFolder);
     84    mPsVRDP->setPath(m_cache.m_strVRDEAuthLibrary);
     85    mCbCheckTrayIcon->setChecked(m_cache.m_fTrayIconEnabled);
    7986#ifdef Q_WS_MAC
    80     aGs.setPresentationModeEnabled (mCbCheckPresentationMode->isChecked());
     87    mCbCheckPresentationMode->setChecked(m_cache.m_fPresentationModeEnabled);
    8188#endif /* Q_WS_MAC */
    82     aGs.setHostScreenSaverDisabled (mCbDisableHostScreenSaver->isChecked());
     89    mCbDisableHostScreenSaver->setChecked(m_cache.m_fHostScreenSaverDisables);
     90}
     91
     92/* Save data from corresponding widgets to cache,
     93 * this task SHOULD be performed in GUI thread only: */
     94void VBoxGLSettingsGeneral::putToCache()
     95{
     96    /* Upload to cache: */
     97    m_cache.m_strDefaultMachineFolder = mPsMach->path();
     98    m_cache.m_strVRDEAuthLibrary = mPsVRDP->path();
     99    m_cache.m_fTrayIconEnabled = mCbCheckTrayIcon->isChecked();
     100#ifdef Q_WS_MAC
     101    m_cache.m_fPresentationModeEnabled = mCbCheckPresentationMode->isChecked();
     102#endif /* Q_WS_MAC */
     103    m_cache.m_fHostScreenSaverDisables = mCbDisableHostScreenSaver->isChecked();
     104}
     105
     106/* Save data from cache to corresponding external object(s),
     107 * this task COULD be performed in other than GUI thread: */
     108void VBoxGLSettingsGeneral::saveFromCacheTo(QVariant &data)
     109{
     110    /* Fetch data to properties & settings: */
     111    UISettingsPageGlobal::fetchData(data);
     112
     113    /* Save from cache: */
     114    if (m_properties.isOk() && mPsMach->isModified())
     115        m_properties.SetDefaultMachineFolder(m_cache.m_strDefaultMachineFolder);
     116    if (m_properties.isOk() && mPsVRDP->isModified())
     117        m_properties.SetVRDEAuthLibrary(m_cache.m_strVRDEAuthLibrary);
     118    m_settings.setTrayIconEnabled(m_cache.m_fTrayIconEnabled);
     119#ifdef Q_WS_MAC
     120    m_settings.setPresentationModeEnabled(m_cache.m_fPresentationModeEnabled);
     121#endif /* Q_WS_MAC */
     122    m_settings.setHostScreenSaverDisabled(m_cache.m_fHostScreenSaverDisables);
     123
     124    /* Upload properties & settings to data: */
     125    UISettingsPageGlobal::uploadData(data);
     126}
     127
     128void VBoxGLSettingsGeneral::setOrderAfter (QWidget *aWidget)
     129{
     130    setTabOrder (aWidget, mPsMach);
     131    setTabOrder (mPsMach, mPsVRDP);
     132    setTabOrder (mPsVRDP, mCbCheckTrayIcon);
     133    setTabOrder (mCbCheckTrayIcon, mCbCheckPresentationMode);
     134    setTabOrder (mCbCheckPresentationMode, mCbDisableHostScreenSaver);
    83135}
    84136
     
    88140    Ui::VBoxGLSettingsGeneral::retranslateUi (this);
    89141
    90     mPsHardDisk->setWhatsThis (tr ("Displays the path to the default hard disk "
    91                                    "folder. This folder is used, if not explicitly "
    92                                    "specified otherwise, when adding existing or "
    93                                    "creating new virtual hard disks."));
    94142    mPsMach->setWhatsThis (tr ("Displays the path to the default virtual "
    95143                               "machine folder. This folder is used, if not "
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsGeneral.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2323#include "VBoxGLSettingsGeneral.gen.h"
    2424
    25 class VBoxGLSettingsGeneral : public UISettingsPage,
     25/* Global settings / General page / Cache: */
     26struct UISettingsCacheGlobalGeneral
     27{
     28    QString m_strDefaultMachineFolder;
     29    QString m_strVRDEAuthLibrary;
     30    bool m_fTrayIconEnabled;
     31#ifdef Q_WS_MAC
     32    bool m_fPresentationModeEnabled;
     33#endif /* Q_WS_MAC */
     34    bool m_fHostScreenSaverDisables;
     35};
     36
     37/* Global settings / General page: */
     38class VBoxGLSettingsGeneral : public UISettingsPageGlobal,
    2639                              public Ui::VBoxGLSettingsGeneral
    2740{
     
    3447protected:
    3548
    36     void getFrom (const CSystemProperties &aProps,
    37                   const VBoxGlobalSettings &aGs);
    38     void putBackTo (CSystemProperties &aProps,
    39                     VBoxGlobalSettings &aGs);
     49    /* Load data to cashe from corresponding external object(s),
     50     * this task COULD be performed in other than GUI thread: */
     51    void loadToCacheFrom(QVariant &data);
     52    /* Load data to corresponding widgets from cache,
     53     * this task SHOULD be performed in GUI thread only: */
     54    void getFromCache();
     55
     56    /* Save data from corresponding widgets to cache,
     57     * this task SHOULD be performed in GUI thread only: */
     58    void putToCache();
     59    /* Save data from cache to corresponding external object(s),
     60     * this task COULD be performed in other than GUI thread: */
     61    void saveFromCacheTo(QVariant &data);
     62
     63    void setOrderAfter (QWidget *aWidget);
    4064
    4165    void retranslateUi();
     66
     67private:
     68
     69    /* Cache: */
     70    UISettingsCacheGlobalGeneral m_cache;
    4271};
    4372
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsGeneral.ui

    r32100 r33631  
    44 VBox frontends: Qt4 GUI (&quot;VirtualBox&quot;):
    55
    6      Copyright (C) 2008 Oracle Corporation
     6     Copyright (C) 2008-2010 Oracle Corporation
    77
    88     This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929   </property>
    3030   <item row="0" column="0" colspan="2">
    31     <widget class="QLabel" name="mLbHardDisk">
    32      <property name="text">
    33       <string>Default &amp;Hard Disk Folder:</string>
    34      </property>
    35      <property name="alignment">
    36       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    37      </property>
    38      <property name="buddy">
    39       <cstring>mPsHardDisk</cstring>
    40      </property>
    41     </widget>
    42    </item>
    43    <item row="0" column="2">
    44     <widget class="VBoxFilePathSelectorWidget" name="mPsHardDisk">
    45      <property name="sizePolicy">
    46       <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
    47        <horstretch>0</horstretch>
    48        <verstretch>0</verstretch>
    49       </sizepolicy>
    50      </property>
    51     </widget>
    52    </item>
    53    <item row="1" column="0" colspan="2">
    5431    <widget class="QLabel" name="mLbMach">
    5532     <property name="text">
     
    6441    </widget>
    6542   </item>
    66    <item row="1" column="2">
     43   <item row="0" column="2">
    6744    <widget class="VBoxFilePathSelectorWidget" name="mPsMach">
    6845     <property name="sizePolicy">
     
    7451    </widget>
    7552   </item>
    76    <item row="2" column="0" colspan="3">
     53   <item row="1" column="0" colspan="3">
    7754    <widget class="Line" name="mLnSeparator">
    7855     <property name="orientation">
     
    8158    </widget>
    8259   </item>
    83    <item row="3" column="0" colspan="2">
     60   <item row="2" column="0" colspan="2">
    8461    <widget class="QLabel" name="mLbVRDP">
    8562     <property name="text">
     
    9471    </widget>
    9572   </item>
    96    <item row="3" column="2">
     73   <item row="2" column="2">
    9774    <widget class="VBoxFilePathSelectorWidget" name="mPsVRDP">
    9875     <property name="sizePolicy">
     
    10481    </widget>
    10582   </item>
    106    <item row="4" column="0" colspan="3">
     83   <item row="3" column="0" colspan="3">
    10784    <widget class="Line" name="mLnSeparator2">
    10885     <property name="orientation">
     
    11188    </widget>
    11289   </item>
    113    <item row="5" column="0">
     90   <item row="4" column="0">
    11491    <widget class="QWidget" name="mWtSpacer1">
    11592     <property name="sizePolicy">
     
    124101    </widget>
    125102   </item>
    126    <item row="5" column="1" colspan="2">
     103   <item row="4" column="1" colspan="2">
    127104    <widget class="QCheckBox" name="mCbCheckTrayIcon">
    128105     <property name="whatsThis">
     
    137114    </widget>
    138115   </item>
    139    <item row="6" column="0">
     116   <item row="5" column="0">
    140117    <widget class="QWidget" name="mWtSpacer2">
    141118     <property name="sizePolicy">
     
    150127    </widget>
    151128   </item>
    152    <item row="6" column="1" colspan="2">
     129   <item row="5" column="1" colspan="2">
    153130    <widget class="QCheckBox" name="mCbCheckPresentationMode">
    154131     <property name="text">
     
    157134    </widget>
    158135   </item>
    159    <item row="7" column="0">
     136   <item row="6" column="0">
    160137    <widget class="QWidget" name="mWtSpacer3">
    161138     <property name="sizePolicy">
     
    170147    </widget>
    171148   </item>
    172    <item row="7" column="1" colspan="2">
     149   <item row="6" column="1" colspan="2">
    173150    <widget class="QCheckBox" name="mCbDisableHostScreenSaver">
    174151     <property name="whatsThis">
     
    180157    </widget>
    181158   </item>
    182    <item row="10" column="0" colspan="3">
     159   <item row="7" column="0" colspan="3">
    183160    <spacer>
    184161     <property name="orientation">
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsInput.cpp

    r28800 r33631  
    77
    88/*
    9  * Copyright (C) 2006-2008 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3030}
    3131
    32 void VBoxGLSettingsInput::getFrom (const CSystemProperties &,
    33                                    const VBoxGlobalSettings &aGs)
     32/* Load data to cashe from corresponding external object(s),
     33 * this task COULD be performed in other than GUI thread: */
     34void VBoxGLSettingsInput::loadToCacheFrom(QVariant &data)
    3435{
    35     mHeHostKey->setKey (aGs.hostKey());
    36     mCbAutoGrab->setChecked (aGs.autoCapture());
     36    /* Fetch data to properties & settings: */
     37    UISettingsPageGlobal::fetchData(data);
     38
     39    /* Load to cache: */
     40    m_cache.m_iHostKey = m_settings.hostKey();
     41    m_cache.m_fAutoCapture = m_settings.autoCapture();
     42
     43    /* Upload properties & settings to data: */
     44    UISettingsPageGlobal::uploadData(data);
    3745}
    3846
    39 void VBoxGLSettingsInput::putBackTo (CSystemProperties &,
    40                                      VBoxGlobalSettings &aGs)
     47/* Load data to corresponding widgets from cache,
     48 * this task SHOULD be performed in GUI thread only: */
     49void VBoxGLSettingsInput::getFromCache()
    4150{
    42     aGs.setHostKey (mHeHostKey->key());
    43     aGs.setAutoCapture (mCbAutoGrab->isChecked());
     51    /* Fetch from cache: */
     52    mHeHostKey->setKey(m_cache.m_iHostKey);
     53    mCbAutoGrab->setChecked(m_cache.m_fAutoCapture);
     54}
     55
     56/* Save data from corresponding widgets to cache,
     57 * this task SHOULD be performed in GUI thread only: */
     58void VBoxGLSettingsInput::putToCache()
     59{
     60    /* Upload to cache: */
     61    m_cache.m_iHostKey = mHeHostKey->key();
     62    m_cache.m_fAutoCapture = mCbAutoGrab->isChecked();
     63}
     64
     65/* Save data from cache to corresponding external object(s),
     66 * this task COULD be performed in other than GUI thread: */
     67void VBoxGLSettingsInput::saveFromCacheTo(QVariant &data)
     68{
     69    /* Fetch data to properties & settings: */
     70    UISettingsPageGlobal::fetchData(data);
     71
     72    /* Save from cache: */
     73    m_settings.setHostKey(m_cache.m_iHostKey);
     74    m_settings.setAutoCapture(m_cache.m_fAutoCapture);
     75
     76    /* Upload properties & settings to data: */
     77    UISettingsPageGlobal::uploadData(data);
    4478}
    4579
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsInput.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2323#include "VBoxGLSettingsInput.gen.h"
    2424
    25 class VBoxGLSettingsInput : public UISettingsPage,
     25/* Global settings / Input page / Cache: */
     26struct UISettingsCacheGlobalInput
     27{
     28    int m_iHostKey;
     29    bool m_fAutoCapture;
     30};
     31
     32/* Global settings / Input page: */
     33class VBoxGLSettingsInput : public UISettingsPageGlobal,
    2634                            public Ui::VBoxGLSettingsInput
    2735{
     
    3442protected:
    3543
    36     void getFrom (const CSystemProperties &aProps,
    37                   const VBoxGlobalSettings &aGs);
    38     void putBackTo (CSystemProperties &aProps,
    39                     VBoxGlobalSettings &aGs);
     44    /* Load data to cashe from corresponding external object(s),
     45     * this task COULD be performed in other than GUI thread: */
     46    void loadToCacheFrom(QVariant &data);
     47    /* Load data to corresponding widgets from cache,
     48     * this task SHOULD be performed in GUI thread only: */
     49    void getFromCache();
     50
     51    /* Save data from corresponding widgets to cache,
     52     * this task SHOULD be performed in GUI thread only: */
     53    void putToCache();
     54    /* Save data from cache to corresponding external object(s),
     55     * this task COULD be performed in other than GUI thread: */
     56    void saveFromCacheTo(QVariant &data);
    4057
    4158    void setOrderAfter (QWidget *aWidget);
    4259
    4360    void retranslateUi();
     61
     62private:
     63
     64    /* Cache: */
     65    UISettingsCacheGlobalInput m_cache;
    4466};
    4567
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsLanguage.cpp

    r28800 r33631  
    77
    88/*
    9  * Copyright (C) 2006-2008 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    189189}
    190190
    191 void VBoxGLSettingsLanguage::getFrom (const CSystemProperties & /* aProps */, const VBoxGlobalSettings &aGs)
    192 {
    193     reload (aGs.languageId());
    194     mTxName->setFixedHeight (fontMetrics().height() * 4);
    195 }
    196 
    197 void VBoxGLSettingsLanguage::putBackTo (CSystemProperties & /* aProps */, VBoxGlobalSettings &aGs)
    198 {
    199     QTreeWidgetItem *curItem = mTwLanguage->currentItem();
    200     Assert (curItem);
    201     if (mLanguageChanged && curItem)
    202     {
    203         aGs.setLanguageId (curItem->text (1));
    204         VBoxGlobal::loadLanguage (curItem->text (1));
    205     }
     191/* Load data to cashe from corresponding external object(s),
     192 * this task COULD be performed in other than GUI thread: */
     193void VBoxGLSettingsLanguage::loadToCacheFrom(QVariant &data)
     194{
     195    /* Fetch data to properties & settings: */
     196    UISettingsPageGlobal::fetchData(data);
     197
     198    /* Load to cache: */
     199    m_cache.m_strLanguageId = m_settings.languageId();
     200
     201    /* Upload properties & settings to data: */
     202    UISettingsPageGlobal::uploadData(data);
     203}
     204
     205/* Load data to corresponding widgets from cache,
     206 * this task SHOULD be performed in GUI thread only: */
     207void VBoxGLSettingsLanguage::getFromCache()
     208{
     209    /* Fetch from cache: */
     210    reload(m_cache.m_strLanguageId);
     211    mTxName->setFixedHeight(fontMetrics().height() * 4);
     212}
     213
     214/* Save data from corresponding widgets to cache,
     215 * this task SHOULD be performed in GUI thread only: */
     216void VBoxGLSettingsLanguage::putToCache()
     217{
     218    /* Upload to cache: */
     219    QTreeWidgetItem *pCurrentItem = mTwLanguage->currentItem();
     220    Assert(pCurrentItem);
     221    if (pCurrentItem)
     222        m_cache.m_strLanguageId = pCurrentItem->text(1);
     223}
     224
     225/* Save data from cache to corresponding external object(s),
     226 * this task COULD be performed in other than GUI thread: */
     227void VBoxGLSettingsLanguage::saveFromCacheTo(QVariant &data)
     228{
     229    /* Fetch data to properties & settings: */
     230    UISettingsPageGlobal::fetchData(data);
     231
     232    /* Save from cache: */
     233    if (mLanguageChanged)
     234    {
     235        m_settings.setLanguageId(m_cache.m_strLanguageId);
     236        VBoxGlobal::loadLanguage(m_cache.m_strLanguageId);
     237    }
     238
     239    /* Upload properties & settings to data: */
     240    UISettingsPageGlobal::uploadData(data);
    206241}
    207242
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsLanguage.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2323#include "VBoxGLSettingsLanguage.gen.h"
    2424
    25 class VBoxGLSettingsLanguage : public UISettingsPage,
     25/* Global settings / Language page / Cache: */
     26struct UISettingsCacheGlobalLanguage
     27{
     28    QString m_strLanguageId;
     29};
     30
     31/* Global settings / Language page: */
     32class VBoxGLSettingsLanguage : public UISettingsPageGlobal,
    2633                               public Ui::VBoxGLSettingsLanguage
    2734{
     
    3441protected:
    3542
    36     void getFrom (const CSystemProperties &aProps,
    37                   const VBoxGlobalSettings &aGs);
    38     void putBackTo (CSystemProperties &aProps,
    39                     VBoxGlobalSettings &aGs);
     43    /* Load data to cashe from corresponding external object(s),
     44     * this task COULD be performed in other than GUI thread: */
     45    void loadToCacheFrom(QVariant &data);
     46    /* Load data to corresponding widgets from cache,
     47     * this task SHOULD be performed in GUI thread only: */
     48    void getFromCache();
     49
     50    /* Save data from corresponding widgets to cache,
     51     * this task SHOULD be performed in GUI thread only: */
     52    void putToCache();
     53    /* Save data from cache to corresponding external object(s),
     54     * this task COULD be performed in other than GUI thread: */
     55    void saveFromCacheTo(QVariant &data);
    4056
    4157    void setOrderAfter (QWidget *aWidget);
     
    5369
    5470    bool mLanguageChanged;
     71
     72    /* Cache: */
     73    UISettingsCacheGlobalLanguage m_cache;
    5574};
    5675
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsNetwork.cpp

    r30192 r33631  
    77
    88/*
    9  * Copyright (C) 2009 Oracle Corporation
     9 * Copyright (C) 2009-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232NetworkItem::NetworkItem()
    3333    : QTreeWidgetItem()
    34     , mChanged (false)
    35     , mName (QString::null)
    36     , mDhcpClientEnabled (false)
    37     , mInterfaceAddress (QString::null)
    38     , mInterfaceMask (QString::null)
    39     , mIpv6Supported (false)
    40     , mInterfaceAddress6 (QString::null)
    41     , mInterfaceMaskLength6 (QString::null)
    42     , mDhcpServerEnabled (false)
    43     , mDhcpServerAddress (QString::null)
    44     , mDhcpServerMask (QString::null)
    45     , mDhcpLowerAddress (QString::null)
    46     , mDhcpUpperAddress (QString::null)
    47 {
    48 }
    49 
    50 void NetworkItem::getFromInterface (const CHostNetworkInterface &aInterface)
    51 {
    52     /* Initialization */
    53     mInterface = aInterface;
    54     mName = mInterface.GetName();
    55     CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName (mInterface.GetNetworkName());
    56     if (dhcp.isNull()) vboxGlobal().virtualBox().CreateDHCPServer (mInterface.GetNetworkName());
    57     dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName (mInterface.GetNetworkName());
    58     AssertMsg (!dhcp.isNull(), ("DHCP Server creation failed!\n"));
    59     setText (0, VBoxGLSettingsNetwork::tr ("%1 network", "<adapter name> network").arg (mName));
    60 
    61     /* Host-only Interface settings */
    62     mDhcpClientEnabled = mInterface.GetDhcpEnabled();
    63     mInterfaceAddress = mInterface.GetIPAddress();
    64     mInterfaceMask = mInterface.GetNetworkMask();
    65     mIpv6Supported = mInterface.GetIPV6Supported();
    66     mInterfaceAddress6 = mInterface.GetIPV6Address();
    67     mInterfaceMaskLength6 = QString ("%1").arg (mInterface.GetIPV6NetworkMaskPrefixLength());
    68 
    69     /* DHCP Server settings */
    70     mDhcpServerEnabled = dhcp.GetEnabled();
    71     mDhcpServerAddress = dhcp.GetIPAddress();
    72     mDhcpServerMask = dhcp.GetNetworkMask();
    73     mDhcpLowerAddress = dhcp.GetLowerIP();
    74     mDhcpUpperAddress = dhcp.GetUpperIP();
    75 
    76     /* Update tool-tip */
     34{
     35}
     36
     37void NetworkItem::fetchNetworkData(const UIHostNetworkData &data)
     38{
     39    /* Fetch from cache: */
     40    m_data = data;
     41
     42    /* Update tool-tip: */
    7743    updateInfo();
    7844}
    7945
    80 void NetworkItem::putBackToInterface()
    81 {
    82     /* Host-only Interface settings */
    83     if (mDhcpClientEnabled)
    84     {
    85         mInterface.EnableDynamicIpConfig();
    86     }
    87     else
    88     {
    89         AssertMsg (mInterfaceAddress.isEmpty() ||
    90                    QHostAddress (mInterfaceAddress).protocol() == QAbstractSocket::IPv4Protocol,
    91                    ("Interface IPv4 address must be empty or IPv4-valid!\n"));
    92         AssertMsg (mInterfaceMask.isEmpty() ||
    93                    QHostAddress (mInterfaceMask).protocol() == QAbstractSocket::IPv4Protocol,
    94                    ("Interface IPv4 network mask must be empty or IPv4-valid!\n"));
    95         mInterface.EnableStaticIpConfig (mInterfaceAddress, mInterfaceMask);
    96         if (mInterface.GetIPV6Supported())
    97         {
    98             AssertMsg (mInterfaceAddress6.isEmpty() ||
    99                        QHostAddress (mInterfaceAddress6).protocol() == QAbstractSocket::IPv6Protocol,
    100                        ("Interface IPv6 address must be empty or IPv6-valid!\n"));
    101             mInterface.EnableStaticIpConfigV6 (mInterfaceAddress6, mInterfaceMaskLength6.toULong());
    102         }
    103     }
    104 
    105     /* DHCP Server settings */
    106     CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName (mInterface.GetNetworkName());
    107     AssertMsg (!dhcp.isNull(), ("DHCP Server should be already created!\n"));
    108     dhcp.SetEnabled (mDhcpServerEnabled);
    109     AssertMsg (QHostAddress (mDhcpServerAddress).protocol() == QAbstractSocket::IPv4Protocol,
    110                ("DHCP Server IPv4 address must be IPv4-valid!\n"));
    111     AssertMsg (QHostAddress (mDhcpServerMask).protocol() == QAbstractSocket::IPv4Protocol,
    112                ("DHCP Server IPv4 network mask must be IPv4-valid!\n"));
    113     AssertMsg (QHostAddress (mDhcpLowerAddress).protocol() == QAbstractSocket::IPv4Protocol,
    114                ("DHCP Server IPv4 lower bound must be IPv4-valid!\n"));
    115     AssertMsg (QHostAddress (mDhcpUpperAddress).protocol() == QAbstractSocket::IPv4Protocol,
    116                ("DHCP Server IPv4 upper bound must be IPv4-valid!\n"));
    117     dhcp.SetConfiguration (mDhcpServerAddress, mDhcpServerMask, mDhcpLowerAddress, mDhcpUpperAddress);
     46void NetworkItem::uploadNetworkData(UIHostNetworkData &data)
     47{
     48    /* Upload to cache: */
     49    data = m_data;
    11850}
    11951
     
    12153{
    12254    /* Host-only Interface validation */
    123     if (!mDhcpClientEnabled)
    124     {
    125         if (!mInterfaceAddress.isEmpty() &&
    126             (QHostAddress (mInterfaceAddress) == QHostAddress::Any ||
    127              QHostAddress (mInterfaceAddress).protocol() != QAbstractSocket::IPv4Protocol))
     55    if (!m_data.m_interface.m_fDhcpClientEnabled)
     56    {
     57        if (m_data.m_interface.m_strInterfaceAddress.isEmpty() &&
     58            (QHostAddress (m_data.m_interface.m_strInterfaceAddress) == QHostAddress::Any ||
     59             QHostAddress (m_data.m_interface.m_strInterfaceAddress).protocol() != QAbstractSocket::IPv4Protocol))
    12860        {
    12961            aWarning = VBoxGLSettingsNetwork::tr ("host IPv4 address of <b>%1</b> is wrong").arg (text (0));
    13062            return false;
    13163        }
    132         if (!mInterfaceMask.isEmpty() &&
    133             (QHostAddress (mInterfaceMask) == QHostAddress::Any ||
    134              QHostAddress (mInterfaceMask).protocol() != QAbstractSocket::IPv4Protocol))
     64        if (!m_data.m_interface.m_strInterfaceMask.isEmpty() &&
     65            (QHostAddress (m_data.m_interface.m_strInterfaceMask) == QHostAddress::Any ||
     66             QHostAddress (m_data.m_interface.m_strInterfaceMask).protocol() != QAbstractSocket::IPv4Protocol))
    13567        {
    13668            aWarning = VBoxGLSettingsNetwork::tr ("host IPv4 network mask of <b>%1</b> is wrong").arg (text (0));
    13769            return false;
    13870        }
    139         if (mIpv6Supported)
    140         {
    141             if (!mInterfaceAddress6.isEmpty() &&
    142                 (QHostAddress (mInterfaceAddress6) == QHostAddress::AnyIPv6 ||
    143                  QHostAddress (mInterfaceAddress6).protocol() != QAbstractSocket::IPv6Protocol))
     71        if (m_data.m_interface.m_fIpv6Supported)
     72        {
     73            if (!m_data.m_interface.m_strInterfaceAddress6.isEmpty() &&
     74                (QHostAddress (m_data.m_interface.m_strInterfaceAddress6) == QHostAddress::AnyIPv6 ||
     75                 QHostAddress (m_data.m_interface.m_strInterfaceAddress6).protocol() != QAbstractSocket::IPv6Protocol))
    14476            {
    14577                aWarning = VBoxGLSettingsNetwork::tr ("host IPv6 address of <b>%1</b> is wrong").arg (text (0));
     
    15082
    15183    /* DHCP Server settings */
    152     if (mDhcpServerEnabled)
    153     {
    154         if (QHostAddress (mDhcpServerAddress) == QHostAddress::Any ||
    155             QHostAddress (mDhcpServerAddress).protocol() != QAbstractSocket::IPv4Protocol)
     84    if (m_data.m_dhcpserver.m_fDhcpServerEnabled)
     85    {
     86        if (QHostAddress (m_data.m_dhcpserver.m_strDhcpServerAddress) == QHostAddress::Any ||
     87            QHostAddress (m_data.m_dhcpserver.m_strDhcpServerAddress).protocol() != QAbstractSocket::IPv4Protocol)
    15688        {
    15789            aWarning = VBoxGLSettingsNetwork::tr ("DHCP server address of <b>%1</b> is wrong").arg (text (0));
    15890            return false;
    15991        }
    160         if (QHostAddress (mDhcpServerMask) == QHostAddress::Any ||
    161             QHostAddress (mDhcpServerMask).protocol() != QAbstractSocket::IPv4Protocol)
     92        if (QHostAddress (m_data.m_dhcpserver.m_strDhcpServerMask) == QHostAddress::Any ||
     93            QHostAddress (m_data.m_dhcpserver.m_strDhcpServerMask).protocol() != QAbstractSocket::IPv4Protocol)
    16294        {
    16395            aWarning = VBoxGLSettingsNetwork::tr ("DHCP server network mask of <b>%1</b> is wrong").arg (text (0));
    16496            return false;
    16597        }
    166         if (QHostAddress (mDhcpLowerAddress) == QHostAddress::Any ||
    167             QHostAddress (mDhcpLowerAddress).protocol() != QAbstractSocket::IPv4Protocol)
     98        if (QHostAddress (m_data.m_dhcpserver.m_strDhcpLowerAddress) == QHostAddress::Any ||
     99            QHostAddress (m_data.m_dhcpserver.m_strDhcpLowerAddress).protocol() != QAbstractSocket::IPv4Protocol)
    168100        {
    169101            aWarning = VBoxGLSettingsNetwork::tr ("DHCP lower address bound of <b>%1</b> is wrong").arg (text (0));
    170102            return false;
    171103        }
    172         if (QHostAddress (mDhcpUpperAddress) == QHostAddress::Any ||
    173             QHostAddress (mDhcpUpperAddress).protocol() != QAbstractSocket::IPv4Protocol)
     104        if (QHostAddress (m_data.m_dhcpserver.m_strDhcpUpperAddress) == QHostAddress::Any ||
     105            QHostAddress (m_data.m_dhcpserver.m_strDhcpUpperAddress).protocol() != QAbstractSocket::IPv4Protocol)
    174106        {
    175107            aWarning = VBoxGLSettingsNetwork::tr ("DHCP upper address bound of <b>%1</b> is wrong").arg (text (0));
     
    182114QString NetworkItem::updateInfo()
    183115{
     116    /* Update text: */
     117    setText(0, m_data.m_interface.m_strName);
     118
    184119    /* Update information label */
    185120    QString hdr ("<tr><td><nobr>%1:&nbsp;</nobr></td>"
     
    191126    /* Host-only Interface information */
    192127    buffer = hdr.arg (VBoxGLSettingsNetwork::tr ("Adapter"))
    193                 .arg (mDhcpClientEnabled ? VBoxGLSettingsNetwork::tr ("Automatically configured", "interface")
    194                                          : VBoxGLSettingsNetwork::tr ("Manually configured", "interface"));
     128                .arg (m_data.m_interface.m_fDhcpClientEnabled ? VBoxGLSettingsNetwork::tr ("Automatically configured", "interface")
     129                                                              : VBoxGLSettingsNetwork::tr ("Manually configured", "interface"));
    195130    data += buffer;
    196131    tip += buffer;
    197132
    198     if (!mDhcpClientEnabled)
     133    if (!m_data.m_interface.m_fDhcpClientEnabled)
    199134    {
    200135        buffer = sub.arg (VBoxGLSettingsNetwork::tr ("IPv4 Address"))
    201                     .arg (mInterfaceAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "address")
    202                                                       : mInterfaceAddress) +
     136                    .arg (m_data.m_interface.m_strInterfaceAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "address")
     137                                                                             : m_data.m_interface.m_strInterfaceAddress) +
    203138                 sub.arg (VBoxGLSettingsNetwork::tr ("IPv4 Network Mask"))
    204                     .arg (mInterfaceMask.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "mask")
    205                                                    : mInterfaceMask);
     139                    .arg (m_data.m_interface.m_strInterfaceMask.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "mask")
     140                                                                          : m_data.m_interface.m_strInterfaceMask);
    206141        tip += buffer;
    207142
    208         if (mIpv6Supported)
     143        if (m_data.m_interface.m_fIpv6Supported)
    209144        {
    210145            buffer = sub.arg (VBoxGLSettingsNetwork::tr ("IPv6 Address"))
    211                         .arg (mInterfaceAddress6.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "address")
    212                                                            : mInterfaceAddress6) +
     146                        .arg (m_data.m_interface.m_strInterfaceAddress6.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "address")
     147                                                                                  : m_data.m_interface.m_strInterfaceAddress6) +
    213148                     sub.arg (VBoxGLSettingsNetwork::tr ("IPv6 Network Mask Length"))
    214                         .arg (mInterfaceMaskLength6.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "length")
    215                                                               : mInterfaceMaskLength6);
     149                        .arg (m_data.m_interface.m_strInterfaceMaskLength6.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "length")
     150                                                              : m_data.m_interface.m_strInterfaceMaskLength6);
    216151            tip += buffer;
    217152        }
     
    220155    /* DHCP Server information */
    221156    buffer = hdr.arg (VBoxGLSettingsNetwork::tr ("DHCP Server"))
    222                 .arg (mDhcpServerEnabled ? VBoxGLSettingsNetwork::tr ("Enabled", "server")
    223                                          : VBoxGLSettingsNetwork::tr ("Disabled", "server"));
     157                .arg (m_data.m_dhcpserver.m_fDhcpServerEnabled ? VBoxGLSettingsNetwork::tr ("Enabled", "server")
     158                                                               : VBoxGLSettingsNetwork::tr ("Disabled", "server"));
    224159    data += buffer;
    225160    tip += buffer;
    226161
    227     if (mDhcpServerEnabled)
     162    if (m_data.m_dhcpserver.m_fDhcpServerEnabled)
    228163    {
    229164        buffer = sub.arg (VBoxGLSettingsNetwork::tr ("Address"))
    230                     .arg (mDhcpServerAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "address")
    231                                                        : mDhcpServerAddress) +
     165                    .arg (m_data.m_dhcpserver.m_strDhcpServerAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "address")
     166                                                                               : m_data.m_dhcpserver.m_strDhcpServerAddress) +
    232167                 sub.arg (VBoxGLSettingsNetwork::tr ("Network Mask"))
    233                     .arg (mDhcpServerMask.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "mask")
    234                                                     : mDhcpServerMask) +
     168                    .arg (m_data.m_dhcpserver.m_strDhcpServerMask.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "mask")
     169                                                                            : m_data.m_dhcpserver.m_strDhcpServerMask) +
    235170                 sub.arg (VBoxGLSettingsNetwork::tr ("Lower Bound"))
    236                     .arg (mDhcpLowerAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "bound")
    237                                                       : mDhcpLowerAddress) +
     171                    .arg (m_data.m_dhcpserver.m_strDhcpLowerAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "bound")
     172                                                                              : m_data.m_dhcpserver.m_strDhcpLowerAddress) +
    238173                 sub.arg (VBoxGLSettingsNetwork::tr ("Upper Bound"))
    239                     .arg (mDhcpUpperAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "bound")
    240                                                       : mDhcpUpperAddress);
     174                    .arg (m_data.m_dhcpserver.m_strDhcpUpperAddress.isEmpty() ? VBoxGLSettingsNetwork::tr ("Not set", "bound")
     175                                                                              : m_data.m_dhcpserver.m_strDhcpUpperAddress);
    241176        tip += buffer;
    242177    }
     
    248183
    249184VBoxGLSettingsNetwork::VBoxGLSettingsNetwork()
     185    : m_fChanged(false)
    250186{
    251187    /* Apply UI decorations */
     
    257193        new QSpacerItem (0, 1, QSizePolicy::Expanding, QSizePolicy::Preferred);
    258194    QGridLayout *mainLayout = static_cast <QGridLayout*> (layout());
    259     mainLayout->addItem (shiftSpacer, 1, 4, 2);
     195    mainLayout->addItem (shiftSpacer, 1, 4);
    260196    static_cast <QHBoxLayout*> (mWtActions->layout())->addStretch();
    261197#endif
     
    312248}
    313249
    314 void VBoxGLSettingsNetwork::getFrom (const CSystemProperties &, const VBoxGlobalSettings &)
    315 {
    316     NetworkItem *item = 0;
    317     CHostNetworkInterfaceVector interfaces =
    318         vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
    319     for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
    320          it != interfaces.end(); ++ it)
    321     {
    322         if (it->GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
    323         {
    324             item = new NetworkItem();
    325             item->getFromInterface (*it);
    326             mTwInterfaces->addTopLevelItem (item);
    327             mTwInterfaces->sortItems (0, Qt::AscendingOrder);
    328         }
    329     }
    330 
    331     mTwInterfaces->setCurrentItem (item);
     250/* Load data to cashe from corresponding external object(s),
     251 * this task COULD be performed in other than GUI thread: */
     252void VBoxGLSettingsNetwork::loadToCacheFrom(QVariant &data)
     253{
     254    /* Fetch data to properties & settings: */
     255    UISettingsPageGlobal::fetchData(data);
     256
     257    /* Load to cache: */
     258    const CHostNetworkInterfaceVector &interfaces = vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
     259    for (int iNetworkIndex = 0; iNetworkIndex < interfaces.size(); ++iNetworkIndex)
     260    {
     261        const CHostNetworkInterface &iface = interfaces[iNetworkIndex];
     262        if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
     263        {
     264            /* Initialization: */
     265            CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
     266            if (dhcp.isNull()) vboxGlobal().virtualBox().CreateDHCPServer(iface.GetNetworkName());
     267            dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
     268            AssertMsg(!dhcp.isNull(), ("DHCP Server creation failed!\n"));
     269            UIHostNetworkData data;
     270            /* Host-only interface settings */
     271            data.m_interface.m_strName = iface.GetName();
     272            data.m_interface.m_fDhcpClientEnabled = iface.GetDhcpEnabled();
     273            data.m_interface.m_strInterfaceAddress = iface.GetIPAddress();
     274            data.m_interface.m_strInterfaceMask = iface.GetNetworkMask();
     275            data.m_interface.m_fIpv6Supported = iface.GetIPV6Supported();
     276            data.m_interface.m_strInterfaceAddress6 = iface.GetIPV6Address();
     277            data.m_interface.m_strInterfaceMaskLength6 = QString::number(iface.GetIPV6NetworkMaskPrefixLength());
     278            /* DHCP server settings: */
     279            data.m_dhcpserver.m_fDhcpServerEnabled = dhcp.GetEnabled();
     280            data.m_dhcpserver.m_strDhcpServerAddress = dhcp.GetIPAddress();
     281            data.m_dhcpserver.m_strDhcpServerMask = dhcp.GetNetworkMask();
     282            data.m_dhcpserver.m_strDhcpLowerAddress = dhcp.GetLowerIP();
     283            data.m_dhcpserver.m_strDhcpUpperAddress = dhcp.GetUpperIP();
     284            /* Cache: */
     285            m_cache.m_items << data;
     286        }
     287    }
     288
     289    /* Upload properties & settings to data: */
     290    UISettingsPageGlobal::uploadData(data);
     291}
     292
     293/* Load data to corresponding widgets from cache,
     294 * this task SHOULD be performed in GUI thread only: */
     295void VBoxGLSettingsNetwork::getFromCache()
     296{
     297    /* Fetch from cache: */
     298    for (int iNetworkIndex = 0; iNetworkIndex < m_cache.m_items.size(); ++iNetworkIndex)
     299    {
     300        const UIHostNetworkData &data = m_cache.m_items[iNetworkIndex];
     301        NetworkItem *pItem = new NetworkItem;
     302        pItem->fetchNetworkData(data);
     303        mTwInterfaces->addTopLevelItem(pItem);
     304    }
     305    mTwInterfaces->setCurrentItem(mTwInterfaces->topLevelItem(0));
    332306    updateCurrentItem();
    333 
    334307#ifdef Q_WS_MAC
    335     int width = qMax (static_cast<QAbstractItemView*> (mTwInterfaces)
    336         ->sizeHintForColumn (0) + 2 * mTwInterfaces->frameWidth() +
    337         QApplication::style()->pixelMetric (QStyle::PM_ScrollBarExtent),
    338         220);
    339     mTwInterfaces->setFixedWidth (width);
    340     mTwInterfaces->resizeColumnToContents (0);
     308    int width = qMax(static_cast<QAbstractItemView*>(mTwInterfaces)->sizeHintForColumn(0) +
     309                     2 * mTwInterfaces->frameWidth() + QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent),
     310                     220);
     311    mTwInterfaces->setFixedWidth(width);
     312    mTwInterfaces->resizeColumnToContents(0);
    341313#endif /* Q_WS_MAC */
    342314}
    343315
    344 void VBoxGLSettingsNetwork::putBackTo (CSystemProperties &, VBoxGlobalSettings &)
    345 {
    346     for (int i = 0; i < mTwInterfaces->topLevelItemCount(); ++ i)
    347     {
    348         NetworkItem *item =
    349             static_cast <NetworkItem*> (mTwInterfaces->topLevelItem (i));
    350         if (item->isChanged())
    351             item->putBackToInterface();
    352     }
     316/* Save data from corresponding widgets to cache,
     317 * this task SHOULD be performed in GUI thread only: */
     318void VBoxGLSettingsNetwork::putToCache()
     319{
     320    /* Upload to cache: */
     321    m_cache.m_items.clear();
     322    for (int iNetworkIndex = 0; iNetworkIndex < mTwInterfaces->topLevelItemCount(); ++iNetworkIndex)
     323    {
     324        UIHostNetworkData data;
     325        NetworkItem *pItem = static_cast<NetworkItem*>(mTwInterfaces->topLevelItem(iNetworkIndex));
     326        pItem->uploadNetworkData(data);
     327        m_cache.m_items << data;
     328    }
     329}
     330
     331/* Save data from cache to corresponding external object(s),
     332 * this task COULD be performed in other than GUI thread: */
     333void VBoxGLSettingsNetwork::saveFromCacheTo(QVariant &data)
     334{
     335    /* Ensure settings were changed: */
     336    if (!m_fChanged)
     337        return;
     338
     339    /* Fetch data to properties & settings: */
     340    UISettingsPageGlobal::fetchData(data);
     341
     342    /* Save from cache: */
     343    CVirtualBox &vbox = vboxGlobal().virtualBox();
     344    CHost &host = vbox.GetHost();
     345    const CHostNetworkInterfaceVector &interfaces = host.GetNetworkInterfaces();
     346    /* Remove all the old interfaces first: */
     347    for (int iNetworkIndex = 0; iNetworkIndex < interfaces.size(); ++iNetworkIndex)
     348    {
     349        /* Get iterated interface: */
     350        const CHostNetworkInterface &iface = interfaces[iNetworkIndex];
     351        if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
     352        {
     353            /* Search for this interface's dhcp sserver: */
     354            CDHCPServer &dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
     355            /* Delete it if its present: */
     356            if (!dhcp.isNull())
     357                vbox.RemoveDHCPServer(dhcp);
     358            /* Delete interface finally: */
     359            CProgress progress = host.RemoveHostOnlyNetworkInterface(iface.GetId());
     360            if (host.isOk())
     361            {
     362                progress.WaitForCompletion(-1);
     363                // TODO: Fix problem reporter!
     364                //vboxProblem().showModalProgressDialog(progress, tr("Performing", "creating/removing host-only network"), this);
     365                if (progress.GetResultCode() != 0)
     366                    // TODO: Fix problem reporter!
     367                    //vboxProblem().cannotRemoveHostInterface(progress, iface, this);
     368                    AssertMsgFailed(("Failed to remove Host-only Network Adapter, result code is %d!\n", progress.GetResultCode()));
     369            }
     370            else
     371                // TODO: Fix problem reporter!
     372                //vboxProblem().cannotRemoveHostInterface(host, iface, this);
     373                AssertMsgFailed(("Failed to remove Host-only Network Adapter!\n"));
     374        }
     375    }
     376    /* Add all the new interfaces finally: */
     377    for (int iNetworkIndex = 0; iNetworkIndex < m_cache.m_items.size(); ++iNetworkIndex)
     378    {
     379        /* Get iterated data: */
     380        const UIHostNetworkData &data = m_cache.m_items[iNetworkIndex];
     381        CHostNetworkInterface iface;
     382        /* Create interface: */
     383        CProgress progress = host.CreateHostOnlyNetworkInterface(iface);
     384        if (host.isOk())
     385        {
     386            // TODO: Fix problem reporter!
     387            //vboxProblem().showModalProgressDialog(progress, tr("Performing", "creating/removing host-only network"), this);
     388            progress.WaitForCompletion(-1);
     389            if (progress.GetResultCode() == 0)
     390            {
     391                /* Create DHCP server: */
     392                CDHCPServer dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName());
     393                if (dhcp.isNull()) vbox.CreateDHCPServer(iface.GetNetworkName());
     394                dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName());
     395                AssertMsg(!dhcp.isNull(), ("DHCP Server creation failed!\n"));
     396                /* Host-only Interface configuring: */
     397                if (data.m_interface.m_fDhcpClientEnabled)
     398                {
     399                    iface.EnableDynamicIpConfig();
     400                }
     401                else
     402                {
     403                    AssertMsg(data.m_interface.m_strInterfaceAddress.isEmpty() ||
     404                              QHostAddress(data.m_interface.m_strInterfaceAddress).protocol() == QAbstractSocket::IPv4Protocol,
     405                              ("Interface IPv4 address must be empty or IPv4-valid!\n"));
     406                    AssertMsg(data.m_interface.m_strInterfaceMask.isEmpty() ||
     407                              QHostAddress(data.m_interface.m_strInterfaceMask).protocol() == QAbstractSocket::IPv4Protocol,
     408                              ("Interface IPv4 network mask must be empty or IPv4-valid!\n"));
     409                    iface.EnableStaticIpConfig(data.m_interface.m_strInterfaceAddress, data.m_interface.m_strInterfaceMask);
     410                    if (iface.GetIPV6Supported())
     411                    {
     412                        AssertMsg(data.m_interface.m_strInterfaceAddress6.isEmpty() ||
     413                                  QHostAddress(data.m_interface.m_strInterfaceAddress6).protocol() == QAbstractSocket::IPv6Protocol,
     414                                  ("Interface IPv6 address must be empty or IPv6-valid!\n"));
     415                        iface.EnableStaticIpConfigV6(data.m_interface.m_strInterfaceAddress6, data.m_interface.m_strInterfaceMaskLength6.toULong());
     416                    }
     417                }
     418                /* DHCP Server configuring: */
     419                dhcp.SetEnabled(data.m_dhcpserver.m_fDhcpServerEnabled);
     420//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpServerAddress).protocol() == QAbstractSocket::IPv4Protocol,
     421//                          ("DHCP Server IPv4 address must be IPv4-valid!\n"));
     422//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpServerMask).protocol() == QAbstractSocket::IPv4Protocol,
     423//                          ("DHCP Server IPv4 network mask must be IPv4-valid!\n"));
     424//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpLowerAddress).protocol() == QAbstractSocket::IPv4Protocol,
     425//                          ("DHCP Server IPv4 lower bound must be IPv4-valid!\n"));
     426//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpUpperAddress).protocol() == QAbstractSocket::IPv4Protocol,
     427//                          ("DHCP Server IPv4 upper bound must be IPv4-valid!\n"));
     428                if (QHostAddress(data.m_dhcpserver.m_strDhcpServerAddress).protocol() == QAbstractSocket::IPv4Protocol &&
     429                    QHostAddress(data.m_dhcpserver.m_strDhcpServerMask).protocol() == QAbstractSocket::IPv4Protocol &&
     430                    QHostAddress(data.m_dhcpserver.m_strDhcpLowerAddress).protocol() == QAbstractSocket::IPv4Protocol &&
     431                    QHostAddress(data.m_dhcpserver.m_strDhcpUpperAddress).protocol() == QAbstractSocket::IPv4Protocol)
     432                    dhcp.SetConfiguration(data.m_dhcpserver.m_strDhcpServerAddress, data.m_dhcpserver.m_strDhcpServerMask,
     433                                          data.m_dhcpserver.m_strDhcpLowerAddress, data.m_dhcpserver.m_strDhcpUpperAddress);
     434            }
     435            else
     436                // TODO: Fix problem reporter!
     437                //vboxProblem().cannotCreateHostInterface(progress, this);
     438                AssertMsgFailed(("Failed to create Host-only Network Adapter, result code is %d!\n", progress.GetResultCode()));
     439        }
     440        else
     441            // TODO: Fix problem reporter!
     442            //vboxProblem().cannotCreateHostInterface(host, this);
     443            AssertMsgFailed(("Failed to create Host-only Network Adapter!\n"));
     444    }
     445
     446    /* Upload properties & settings to data: */
     447    UISettingsPageGlobal::uploadData(data);
    353448}
    354449
     
    389484void VBoxGLSettingsNetwork::addInterface()
    390485{
    391 #if defined (Q_WS_WIN32)
    392     /* Allow the started helper process to make itself the foreground window */
    393     AllowSetForegroundWindow (ASFW_ANY);
    394 #endif
    395     /* Creating interface */
    396     CHostNetworkInterface iface;
    397     CHost host = vboxGlobal().virtualBox().GetHost();
    398     CProgress progress = host.CreateHostOnlyNetworkInterface (iface);
    399     if (host.isOk())
    400     {
    401         vboxProblem().showModalProgressDialog (progress,
    402             tr ("Performing", "creating/removing host-only network"), this);
    403         if (progress.GetResultCode() == 0)
    404         {
    405             NetworkItem *item = new NetworkItem();
    406             item->getFromInterface (iface);
    407             mTwInterfaces->addTopLevelItem (item);
    408             mTwInterfaces->sortItems (0, Qt::AscendingOrder);
    409             mTwInterfaces->setCurrentItem (item);
    410         }
    411         else
    412             vboxProblem().cannotCreateHostInterface (progress, this);
    413     }
    414     else
    415         vboxProblem().cannotCreateHostInterface (host, this);
    416 #if defined (Q_WS_WIN32)
    417     /* Allow the started helper process to make itself the foreground window */
    418     AllowSetForegroundWindow (ASFW_ANY);
    419 #endif
     486    /* Creating interface item: */
     487    NetworkItem *pItem = new NetworkItem;
     488    /* Fill item's data: */
     489    UIHostNetworkData data;
     490    /* Interface data: */
     491    // TODO: Make unique name!
     492    data.m_interface.m_strName = tr("New Host-Only Interface");
     493    data.m_interface.m_fDhcpClientEnabled = true;
     494    data.m_interface.m_fIpv6Supported = false;
     495    /* DHCP data: */
     496    data.m_dhcpserver.m_fDhcpServerEnabled = false;
     497    /* Fetch item with data: */
     498    pItem->fetchNetworkData(data);
     499    /* Add new top-level item: */
     500    mTwInterfaces->addTopLevelItem(pItem);
     501    mTwInterfaces->sortItems(0, Qt::AscendingOrder);
     502    mTwInterfaces->setCurrentItem(pItem);
     503    /* Mark dialog as edited: */
     504    m_fChanged = true;
    420505}
    421506
    422507void VBoxGLSettingsNetwork::remInterface()
    423508{
    424 #if defined (Q_WS_WIN32)
    425     /* Allow the started helper process to make itself the foreground window */
    426     AllowSetForegroundWindow (ASFW_ANY);
    427 #endif
    428     /* Check interface presence & name */
    429     NetworkItem *item = static_cast <NetworkItem*> (mTwInterfaces->currentItem());
    430     AssertMsg (item, ("Current item should be selected!\n"));
    431     QString name (item->name());
    432 
    433     /* Asking user about deleting selected network interface */
    434     if (vboxProblem().confirmDeletingHostInterface (name, this) ==
    435         QIMessageBox::Cancel) return;
    436 
    437     /* Removing interface */
    438     CHost host = vboxGlobal().virtualBox().GetHost();
    439     CHostNetworkInterface iface = host.FindHostNetworkInterfaceByName (name);
    440     if (!iface.isNull())
    441     {
    442         /* Delete interface */
    443         CProgress progress = host.RemoveHostOnlyNetworkInterface (iface.GetId());
    444         if (host.isOk())
    445         {
    446             vboxProblem().showModalProgressDialog (progress,
    447                 tr ("Performing", "creating/removing host-only network"), this);
    448             if (progress.GetResultCode() == 0)
    449                 delete item;
    450             else
    451                 vboxProblem().cannotRemoveHostInterface (progress, iface, this);
    452         }
    453     }
    454     if (!host.isOk())
    455         vboxProblem().cannotRemoveHostInterface (host, iface, this);
    456 #if defined (Q_WS_WIN32)
    457     /* Allow the started helper process to make itself the foreground window */
    458     AllowSetForegroundWindow (ASFW_ANY);
    459 #endif
     509    /* Get interface item: */
     510    NetworkItem *pItem = static_cast<NetworkItem*>(mTwInterfaces->currentItem());
     511    AssertMsg(pItem, ("Current item should present!\n"));
     512    /* Get interface name: */
     513    QString strInterfaceName(pItem->name());
     514    /* Asking user about deleting selected network interface: */
     515    if (vboxProblem().confirmDeletingHostInterface(strInterfaceName, this) == QIMessageBox::Cancel)
     516        return;
     517    /* Removing interface: */
     518    delete pItem;
     519    /* Mark dialog as edited: */
     520    m_fChanged = true;
    460521}
    461522
     
    465526    NetworkItem *item = static_cast <NetworkItem*> (mTwInterfaces->currentItem());
    466527    AssertMsg (item, ("Current item should be selected!\n"));
    467 
    468528    /* Edit current item data */
    469529    VBoxGLSettingsNetworkDetails details (this);
     
    472532    {
    473533        details.putBackToItem();
    474         item->setChanged (true);
    475534        item->updateInfo();
    476535    }
    477 
    478536    updateCurrentItem();
    479537    mValidator->revalidate();
     538    /* Mark dialog as edited: */
     539    m_fChanged = true;
    480540}
    481541
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsNetwork.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2009 Oracle Corporation
     8 * Copyright (C) 2009-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2323#include "VBoxGLSettingsNetwork.gen.h"
    2424
     25/* Host interface data: */
     26struct UIHostInterfaceData
     27{
     28    /* Host-only Interface: */
     29    QString m_strName;
     30    bool m_fDhcpClientEnabled;
     31    QString m_strInterfaceAddress;
     32    QString m_strInterfaceMask;
     33    bool m_fIpv6Supported;
     34    QString m_strInterfaceAddress6;
     35    QString m_strInterfaceMaskLength6;
     36};
     37
     38/* DHCP server data: */
     39struct UIDHCPServerData
     40{
     41    /* DHCP Server */
     42    bool m_fDhcpServerEnabled;
     43    QString m_strDhcpServerAddress;
     44    QString m_strDhcpServerMask;
     45    QString m_strDhcpLowerAddress;
     46    QString m_strDhcpUpperAddress;
     47};
     48
     49/* Global network data: */
     50struct UIHostNetworkData
     51{
     52    UIHostInterfaceData m_interface;
     53    UIDHCPServerData m_dhcpserver;
     54};
     55
     56/* Global settings / Network page / Cache: */
     57struct UISettingsCacheGlobalNetwork
     58{
     59    QList<UIHostNetworkData> m_items;
     60};
     61
    2562class NetworkItem : public QTreeWidgetItem
    2663{
     
    2966    NetworkItem();
    3067
    31     void getFromInterface (const CHostNetworkInterface &aInterface);
    32     void putBackToInterface();
     68    void fetchNetworkData(const UIHostNetworkData &data);
     69    void uploadNetworkData(UIHostNetworkData &data);
    3370
    3471    bool revalidate (QString &aWarning, QString &aTitle);
     
    3673    QString updateInfo();
    3774
    38     /* Common getters */
    39     bool isChanged() const { return mChanged; }
     75    /* Page getters */
     76    QString name() const { return m_data.m_interface.m_strName; }
     77    bool isDhcpClientEnabled() const { return m_data.m_interface.m_fDhcpClientEnabled; }
     78    QString interfaceAddress() const { return m_data.m_interface.m_strInterfaceAddress; }
     79    QString interfaceMask() const { return m_data.m_interface.m_strInterfaceMask; }
     80    bool isIpv6Supported() const { return m_data.m_interface.m_fIpv6Supported; }
     81    QString interfaceAddress6() const { return m_data.m_interface.m_strInterfaceAddress6; }
     82    QString interfaceMaskLength6() const { return m_data.m_interface.m_strInterfaceMaskLength6; }
    4083
    41     /* Common setters */
    42     void setChanged (bool aChanged) { mChanged = aChanged; }
    43 
    44     /* Page getters */
    45     QString name() const { return mName; }
    46     bool isDhcpClientEnabled() const { return mDhcpClientEnabled; }
    47     QString interfaceAddress() const { return mInterfaceAddress; }
    48     QString interfaceMask() const { return mInterfaceMask; }
    49     bool isIpv6Supported() const { return mIpv6Supported; }
    50     QString interfaceAddress6() const { return mInterfaceAddress6; }
    51     QString interfaceMaskLength6() const { return mInterfaceMaskLength6; }
    52 
    53     bool isDhcpServerEnabled() const { return mDhcpServerEnabled; }
    54     QString dhcpServerAddress() const { return mDhcpServerAddress; }
    55     QString dhcpServerMask() const { return mDhcpServerMask; }
    56     QString dhcpLowerAddress() const { return mDhcpLowerAddress; }
    57     QString dhcpUpperAddress() const { return mDhcpUpperAddress; }
     84    bool isDhcpServerEnabled() const { return m_data.m_dhcpserver.m_fDhcpServerEnabled; }
     85    QString dhcpServerAddress() const { return m_data.m_dhcpserver.m_strDhcpServerAddress; }
     86    QString dhcpServerMask() const { return m_data.m_dhcpserver.m_strDhcpServerMask; }
     87    QString dhcpLowerAddress() const { return m_data.m_dhcpserver.m_strDhcpLowerAddress; }
     88    QString dhcpUpperAddress() const { return m_data.m_dhcpserver.m_strDhcpUpperAddress; }
    5889
    5990    /* Page setters */
    60     void setDhcpClientEnabled (bool aEnabled) { mDhcpClientEnabled = aEnabled; }
    61     void setInterfaceAddress (const QString &aValue) { mInterfaceAddress = aValue; }
    62     void setInterfaceMask (const QString &aValue) { mInterfaceMask = aValue; }
    63     void setIp6Supported (bool aSupported) { mIpv6Supported = aSupported; }
    64     void setInterfaceAddress6 (const QString &aValue) { mInterfaceAddress6 = aValue; }
    65     void setInterfaceMaskLength6 (const QString &aValue) { mInterfaceMaskLength6 = aValue; }
     91    void setDhcpClientEnabled (bool aEnabled) { m_data.m_interface.m_fDhcpClientEnabled = aEnabled; }
     92    void setInterfaceAddress (const QString &aValue) { m_data.m_interface.m_strInterfaceAddress = aValue; }
     93    void setInterfaceMask (const QString &aValue) { m_data.m_interface.m_strInterfaceMask = aValue; }
     94    void setIp6Supported (bool aSupported) { m_data.m_interface.m_fIpv6Supported = aSupported; }
     95    void setInterfaceAddress6 (const QString &aValue) { m_data.m_interface.m_strInterfaceAddress6 = aValue; }
     96    void setInterfaceMaskLength6 (const QString &aValue) { m_data.m_interface.m_strInterfaceMaskLength6 = aValue; }
    6697
    67     void setDhcpServerEnabled (bool aEnabled) { mDhcpServerEnabled = aEnabled; }
    68     void setDhcpServerAddress (const QString &aValue) { mDhcpServerAddress = aValue; }
    69     void setDhcpServerMask (const QString &aValue) { mDhcpServerMask = aValue; }
    70     void setDhcpLowerAddress (const QString &aValue) { mDhcpLowerAddress = aValue; }
    71     void setDhcpUpperAddress (const QString &aValue) { mDhcpUpperAddress = aValue; }
     98    void setDhcpServerEnabled (bool aEnabled) { m_data.m_dhcpserver.m_fDhcpServerEnabled = aEnabled; }
     99    void setDhcpServerAddress (const QString &aValue) { m_data.m_dhcpserver.m_strDhcpServerAddress = aValue; }
     100    void setDhcpServerMask (const QString &aValue) { m_data.m_dhcpserver.m_strDhcpServerMask = aValue; }
     101    void setDhcpLowerAddress (const QString &aValue) { m_data.m_dhcpserver.m_strDhcpLowerAddress = aValue; }
     102    void setDhcpUpperAddress (const QString &aValue) { m_data.m_dhcpserver.m_strDhcpUpperAddress = aValue; }
    72103
    73104private:
    74105
    75     /* Common */
    76     CHostNetworkInterface mInterface;
    77     bool mChanged;
    78 
    79     /* Host-only Interface */
    80     QString mName;
    81     bool mDhcpClientEnabled;
    82     QString mInterfaceAddress;
    83     QString mInterfaceMask;
    84     bool mIpv6Supported;
    85     QString mInterfaceAddress6;
    86     QString mInterfaceMaskLength6;
    87 
    88     /* DHCP Server */
    89     bool mDhcpServerEnabled;
    90     QString mDhcpServerAddress;
    91     QString mDhcpServerMask;
    92     QString mDhcpLowerAddress;
    93     QString mDhcpUpperAddress;
     106    /* Network data: */
     107    UIHostNetworkData m_data;
    94108};
    95109
    96 class VBoxGLSettingsNetwork : public UISettingsPage,
     110/* Global settings / Network page: */
     111class VBoxGLSettingsNetwork : public UISettingsPageGlobal,
    97112                              public Ui::VBoxGLSettingsNetwork
    98113{
     
    105120protected:
    106121
    107     void getFrom (const CSystemProperties &aProps,
    108                   const VBoxGlobalSettings &aGs);
    109     void putBackTo (CSystemProperties &aProps,
    110                     VBoxGlobalSettings &aGs);
     122    /* Load data to cashe from corresponding external object(s),
     123     * this task COULD be performed in other than GUI thread: */
     124    void loadToCacheFrom(QVariant &data);
     125    /* Load data to corresponding widgets from cache,
     126     * this task SHOULD be performed in GUI thread only: */
     127    void getFromCache();
     128
     129    /* Save data from corresponding widgets to cache,
     130     * this task SHOULD be performed in GUI thread only: */
     131    void putToCache();
     132    /* Save data from cache to corresponding external object(s),
     133     * this task COULD be performed in other than GUI thread: */
     134    void saveFromCacheTo(QVariant &data);
    111135
    112136    void setValidator (QIWidgetValidator *aVal);
     
    132156
    133157    QIWidgetValidator *mValidator;
     158
     159    bool m_fChanged;
     160
     161    /* Cache: */
     162    UISettingsCacheGlobalNetwork m_cache;
    134163};
    135164
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsNetwork.ui

    r32760 r33631  
    44 VBox frontends: Qt4 GUI (&quot;VirtualBox&quot;):
    55
    6      Copyright (C) 2009 Oracle Corporation
     6     Copyright (C) 2009-2010 Oracle Corporation
    77
    88     This file is part of VirtualBox Open Source Edition (OSE), as
     
    2525  </property>
    2626  <layout class="QGridLayout" name="gridLayout">
    27    <item row="0" column="0">
     27   <item row="0" column="0" rowspan="4">
    2828    <spacer>
    2929     <property name="orientation">
     
    5151    </widget>
    5252   </item>
    53    <item row="1" column="2" rowspan="2">
    54     <widget class="QTreeWidget" name="mTwInterfaces">
    55      <property name="sizePolicy">
    56       <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
    57        <horstretch>0</horstretch>
    58        <verstretch>0</verstretch>
    59       </sizepolicy>
    60      </property>
    61      <property name="minimumSize">
    62       <size>
    63        <width>0</width>
    64        <height>150</height>
    65       </size>
    66      </property>
    67      <property name="whatsThis">
    68       <string>Lists all available host-only networks.</string>
    69      </property>
    70      <property name="rootIsDecorated">
    71       <bool>false</bool>
    72      </property>
    73      <column>
    74       <property name="text">
    75        <string>Name</string>
    76       </property>
    77      </column>
    78     </widget>
    79    </item>
    80    <item row="1" column="3">
    81     <widget class="QWidget" name="mWtActions">
    82      <layout class="QHBoxLayout">
     53   <item row="1" column="2">
     54    <widget class="QWidget" native="1" name="m_pWidNetwork" >
     55     <layout class="QHBoxLayout" >
    8356      <property name="leftMargin" >
    8457       <number>0</number>
     
    9467      </property>
    9568      <property name="spacing" >
    96        <number>0</number>
     69       <number>1</number>
    9770      </property>
     71      <item>
     72       <widget class="QTreeWidget" name="mTwInterfaces">
     73        <property name="sizePolicy">
     74         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
     75          <horstretch>0</horstretch>
     76          <verstretch>0</verstretch>
     77         </sizepolicy>
     78        </property>
     79        <property name="minimumSize">
     80         <size>
     81          <width>0</width>
     82          <height>150</height>
     83         </size>
     84        </property>
     85        <property name="whatsThis">
     86         <string>Lists all available host-only networks.</string>
     87        </property>
     88        <property name="rootIsDecorated">
     89         <bool>false</bool>
     90        </property>
     91        <column>
     92         <property name="text">
     93          <string>Name</string>
     94         </property>
     95        </column>
     96       </widget>
     97      </item>
    9898      <item>
    9999       <widget class="UIToolBar" name="mTbActions">
     
    106106    </widget>
    107107   </item>
    108    <item row="2" column="1">
     108   <item row="1" column="1" rowspan="2">
    109109    <spacer>
    110110     <property name="orientation">
     
    122122    </spacer>
    123123   </item>
    124    <item row="2" column="3">
    125     <spacer>
    126      <property name="orientation">
    127       <enum>Qt::Vertical</enum>
    128      </property>
    129      <property name="sizeType">
    130       <enum>QSizePolicy::Expanding</enum>
    131      </property>
    132      <property name="sizeHint" stdset="0">
    133       <size>
    134        <width>10</width>
    135        <height>0</height>
    136       </size>
    137      </property>
    138     </spacer>
    139    </item>
    140    <item row="3" column="2" colspan="2">
     124   <item row="2" column="2" colspan="2">
    141125    <widget class="QLabel" name="mLbInfo">
    142126     <property name="sizePolicy">
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsUpdate.cpp

    r32814 r33631  
    77
    88/*
    9  * Copyright (C) 2006-2008 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3939}
    4040
    41 void VBoxGLSettingsUpdate::getFrom (const CSystemProperties &, const VBoxGlobalSettings &)
     41/* Load data to cashe from corresponding external object(s),
     42 * this task COULD be performed in other than GUI thread: */
     43void VBoxGLSettingsUpdate::loadToCacheFrom(QVariant &data)
    4244{
    43     VBoxUpdateData data (vboxGlobal().virtualBox().GetExtraData (VBoxDefs::GUI_UpdateDate));
     45    /* Fetch data to properties & settings: */
     46    UISettingsPageGlobal::fetchData(data);
    4447
    45     mCbCheck->setChecked (!data.isNoNeedToCheck());
     48    /* Fill internal variables with corresponding values: */
     49    VBoxUpdateData updateData(vboxGlobal().virtualBox().GetExtraData(VBoxDefs::GUI_UpdateDate));
     50    m_cache.m_fCheckEnabled = !updateData.isNoNeedToCheck();
     51    m_cache.m_periodIndex = updateData.periodIndex();
     52    m_cache.m_branchIndex = updateData.branchIndex();
     53    m_cache.m_strDate = updateData.date();
     54
     55    /* Upload properties & settings to data: */
     56    UISettingsPageGlobal::uploadData(data);
     57}
     58
     59/* Load data to corresponding widgets from cache,
     60 * this task SHOULD be performed in GUI thread only: */
     61void VBoxGLSettingsUpdate::getFromCache()
     62{
     63    /* Apply internal variables data to QWidget(s): */
     64    mCbCheck->setChecked(m_cache.m_fCheckEnabled);
    4665    if (mCbCheck->isChecked())
    4766    {
    48         mCbOncePer->setCurrentIndex (data.periodIndex());
    49         if (data.branchIndex() == VBoxUpdateData::BranchWithBetas)
    50             mRbWithBetas->setChecked (true);
    51         else if (data.branchIndex() == VBoxUpdateData::BranchAllRelease)
    52             mRbAllRelease->setChecked (true);
     67        mCbOncePer->setCurrentIndex(m_cache.m_periodIndex);
     68        if (m_cache.m_branchIndex == VBoxUpdateData::BranchWithBetas)
     69            mRbWithBetas->setChecked(true);
     70        else if (m_cache.m_branchIndex == VBoxUpdateData::BranchAllRelease)
     71            mRbAllRelease->setChecked(true);
    5372        else
    54             mRbStable->setChecked (true);
     73            mRbStable->setChecked(true);
    5574    }
    56     mTxDate->setText (data.date());
     75    mTxDate->setText(m_cache.m_strDate);
    5776
     77    /* Reset settings altering flag: */
    5878    mSettingsChanged = false;
    5979}
    6080
    61 void VBoxGLSettingsUpdate::putBackTo (CSystemProperties &, VBoxGlobalSettings &)
     81/* Save data from corresponding widgets to cache,
     82 * this task SHOULD be performed in GUI thread only: */
     83void VBoxGLSettingsUpdate::putToCache()
    6284{
     85    /* Gather internal variables data from QWidget(s): */
     86    m_cache.m_periodIndex = periodType();
     87    m_cache.m_branchIndex = branchType();
     88}
     89
     90/* Save data from cache to corresponding external object(s),
     91 * this task COULD be performed in other than GUI thread: */
     92void VBoxGLSettingsUpdate::saveFromCacheTo(QVariant &data)
     93{
     94    /* Test settings altering flag: */
    6395    if (!mSettingsChanged)
    6496        return;
    6597
    66     VBoxUpdateData newData (periodType(), branchType());
    67     vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_UpdateDate, newData.data());
     98    /* Fetch data to properties & settings: */
     99    UISettingsPageGlobal::fetchData(data);
     100
     101    /* Gather corresponding values from internal variables: */
     102    VBoxUpdateData newData(m_cache.m_periodIndex, m_cache.m_branchIndex);
     103    vboxGlobal().virtualBox().SetExtraData(VBoxDefs::GUI_UpdateDate, newData.data());
     104
     105    /* Upload properties & settings to data: */
     106    UISettingsPageGlobal::uploadData(data);
    68107}
    69108
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsUpdate.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#include "VBoxUpdateDlg.h"
    2525
    26 class VBoxGLSettingsUpdate : public UISettingsPage,
     26/* Global settings / Update page / Cache: */
     27struct UISettingsCacheGlobalUpdate
     28{
     29    bool m_fCheckEnabled;
     30    VBoxUpdateData::PeriodType m_periodIndex;
     31    VBoxUpdateData::BranchType m_branchIndex;
     32    QString m_strDate;
     33};
     34
     35/* Global settings / Update page: */
     36class VBoxGLSettingsUpdate : public UISettingsPageGlobal,
    2737                             public Ui::VBoxGLSettingsUpdate
    2838{
     
    3545protected:
    3646
    37     void getFrom (const CSystemProperties &aProps,
    38                   const VBoxGlobalSettings &aGs);
    39     void putBackTo (CSystemProperties &aProps,
    40                     VBoxGlobalSettings &aGs);
     47    /* Load data to cashe from corresponding external object(s),
     48     * this task COULD be performed in other than GUI thread: */
     49    void loadToCacheFrom(QVariant &data);
     50    /* Load data to corresponding widgets from cache,
     51     * this task SHOULD be performed in GUI thread only: */
     52    void getFromCache();
     53
     54    /* Save data from corresponding widgets to cache,
     55     * this task SHOULD be performed in GUI thread only: */
     56    void putToCache();
     57    /* Save data from cache to corresponding external object(s),
     58     * this task COULD be performed in other than GUI thread: */
     59    void saveFromCacheTo(QVariant &data);
    4160
    4261    void setOrderAfter (QWidget *aWidget);
     
    5978    bool mSettingsChanged;
    6079    QRadioButton *mLastChosen;
     80
     81    /* Cache: */
     82    UISettingsCacheGlobalUpdate m_cache;
    6183};
    6284
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsAudio.cpp

    r30976 r33631  
    77
    88/*
    9  * Copyright (C) 2006-2008 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929}
    3030
    31 void VBoxVMSettingsAudio::getFrom (const CMachine &aMachine)
     31/* Load data to cashe from corresponding external object(s),
     32 * this task COULD be performed in other than GUI thread: */
     33void VBoxVMSettingsAudio::loadToCacheFrom(QVariant &data)
    3234{
    33     mMachine = aMachine;
     35    /* Fetch data to machine: */
     36    UISettingsPageMachine::fetchData(data);
    3437
    35     CAudioAdapter audio = aMachine.GetAudioAdapter();
    36     mGbAudio->setChecked (audio.GetEnabled());
    37     mCbAudioDriver->setCurrentIndex (mCbAudioDriver->
    38         findText (vboxGlobal().toString (audio.GetAudioDriver())));
    39     mCbAudioController->setCurrentIndex (mCbAudioController->
    40         findText (vboxGlobal().toString (audio.GetAudioController())));
     38    /* Fill internal variables with corresponding values: */
     39    const CAudioAdapter &audio = m_machine.GetAudioAdapter();
     40    m_cache.m_fAudioEnabled = audio.GetEnabled();
     41    m_cache.m_audioDriverType = audio.GetAudioDriver();
     42    m_cache.m_audioControllerType = audio.GetAudioController();
     43
     44    /* Upload machine to data: */
     45    UISettingsPageMachine::uploadData(data);
    4146}
    4247
    43 void VBoxVMSettingsAudio::putBackTo()
     48/* Load data to corresponding widgets from cache,
     49 * this task SHOULD be performed in GUI thread only: */
     50void VBoxVMSettingsAudio::getFromCache()
    4451{
    45     CAudioAdapter audio = mMachine.GetAudioAdapter();
    46     audio.SetAudioDriver (vboxGlobal().toAudioDriverType (mCbAudioDriver->currentText()));
    47     audio.SetAudioController (vboxGlobal().toAudioControllerType (mCbAudioController->currentText()));
    48     audio.SetEnabled (mGbAudio->isChecked());
    49     AssertWrapperOk (audio);
     52    /* Apply internal variables data to QWidget(s): */
     53    mGbAudio->setChecked(m_cache.m_fAudioEnabled);
     54    mCbAudioDriver->setCurrentIndex(mCbAudioDriver->findText(vboxGlobal().toString(m_cache.m_audioDriverType)));
     55    mCbAudioController->setCurrentIndex(mCbAudioController->findText(vboxGlobal().toString(m_cache.m_audioControllerType)));
     56}
     57
     58/* Save data from corresponding widgets to cache,
     59 * this task SHOULD be performed in GUI thread only: */
     60void VBoxVMSettingsAudio::putToCache()
     61{
     62    /* Gather internal variables data from QWidget(s): */
     63    m_cache.m_fAudioEnabled = mGbAudio->isChecked();
     64    m_cache.m_audioDriverType = vboxGlobal().toAudioDriverType(mCbAudioDriver->currentText());
     65    m_cache.m_audioControllerType = vboxGlobal().toAudioControllerType(mCbAudioController->currentText());
     66}
     67
     68/* Save data from cache to corresponding external object(s),
     69 * this task COULD be performed in other than GUI thread: */
     70void VBoxVMSettingsAudio::saveFromCacheTo(QVariant &data)
     71{
     72    /* Fetch data to machine: */
     73    UISettingsPageMachine::fetchData(data);
     74
     75    /* Gather corresponding values from internal variables: */
     76    CAudioAdapter &audio = m_machine.GetAudioAdapter();
     77    audio.SetEnabled(m_cache.m_fAudioEnabled);
     78    audio.SetAudioDriver(m_cache.m_audioDriverType);
     79    audio.SetAudioController(m_cache.m_audioControllerType);
     80
     81    /* Upload machine to data: */
     82    UISettingsPageMachine::uploadData(data);
    5083}
    5184
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsAudio.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#include "COMDefs.h"
    2525
    26 class VBoxVMSettingsAudio : public UISettingsPage,
     26/* Machine settings / Audio page / Cache: */
     27struct UISettingsCacheMachineAudio
     28{
     29    bool m_fAudioEnabled;
     30    KAudioDriverType m_audioDriverType;
     31    KAudioControllerType m_audioControllerType;
     32};
     33
     34/* Machine settings / Audio page: */
     35class VBoxVMSettingsAudio : public UISettingsPageMachine,
    2736                            public Ui::VBoxVMSettingsAudio
    2837{
     
    3544protected:
    3645
    37     void getFrom (const CMachine &aMachine);
    38     void putBackTo();
     46    /* Load data to cashe from corresponding external object(s),
     47     * this task COULD be performed in other than GUI thread: */
     48    void loadToCacheFrom(QVariant &data);
     49    /* Load data to corresponding widgets from cache,
     50     * this task SHOULD be performed in GUI thread only: */
     51    void getFromCache();
     52
     53    /* Save data from corresponding widgets to cache,
     54     * this task SHOULD be performed in GUI thread only: */
     55    void putToCache();
     56    /* Save data from cache to corresponding external object(s),
     57     * this task COULD be performed in other than GUI thread: */
     58    void saveFromCacheTo(QVariant &data);
    3959
    4060    void setOrderAfter (QWidget *aWidget);
     
    4666    void prepareComboboxes();
    4767
    48     CMachine mMachine;
     68    /* Cache: */
     69    UISettingsCacheMachineAudio m_cache;
    4970};
    5071
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsDisplay.cpp

    r33626 r33631  
    8686    mSlMemory->setMaximum (m_maxVRAMVisible);
    8787    mSlMemory->setSnappingEnabled (true);
    88     quint64 needMBytes = VBoxGlobal::requiredVideoMemory (&mMachine) / _1M;
     88    quint64 needMBytes = VBoxGlobal::requiredVideoMemory (&m_machine) / _1M;
    8989    mSlMemory->setErrorHint (0, 1);
    9090    mSlMemory->setWarningHint (1, needMBytes);
     
    108108    mCbVRDE->setChecked (false);
    109109
    110     mCb3D->setEnabled (false);
    111 
    112110#ifndef VBOX_WITH_VIDEOHWACCEL
    113111    mCb2DVideo->setVisible (false);
     
    140138#endif
    141139
    142 void VBoxVMSettingsDisplay::getFrom (const CMachine &aMachine)
    143 {
    144     mMachine = aMachine;
    145 
    146     int currentSize = mMachine.GetVRAMSize();
    147     m_initialVRAM = RT_MIN(currentSize, m_maxVRAM);
    148 
    149     /* Memory Size */
    150     mSlMemory->setValue (currentSize);
    151 
    152     /* Monitors Count */
    153     mSlMonitors->setValue (mMachine.GetMonitorCount());
    154 
    155     /* 3D Acceleration */
    156     bool isAccelerationSupported = vboxGlobal().virtualBox().GetHost()
    157                                    .GetAcceleration3DAvailable();
    158     mCb3D->setEnabled (isAccelerationSupported);
    159     mCb3D->setChecked (mMachine.GetAccelerate3DEnabled());
    160 
    161     /* must come _before_ setting the initial memory value */
     140/* Load data to cashe from corresponding external object(s),
     141 * this task COULD be performed in other than GUI thread: */
     142void VBoxVMSettingsDisplay::loadToCacheFrom(QVariant &data)
     143{
     144    /* Fetch data to machine: */
     145    UISettingsPageMachine::fetchData(data);
     146
     147    /* Fill internal variables with corresponding values: */
     148    m_cache.m_iCurrentVRAM = m_machine.GetVRAMSize();
     149    m_cache.m_cMonitorCount = m_machine.GetMonitorCount();
     150    m_cache.m_f3dAccelerationSupported = vboxGlobal().virtualBox().GetHost().GetAcceleration3DAvailable();
     151    m_cache.m_f3dAccelerationEnabled = m_machine.GetAccelerate3DEnabled();
     152#ifdef VBOX_WITH_VIDEOHWACCEL
     153    m_cache.m_f2dAccelerationSupported = VBoxGlobal::isAcceleration2DVideoAvailable();
     154    m_cache.m_f2dAccelerationEnabled = m_machine.GetAccelerate2DVideoEnabled();
     155#endif
     156    CVRDEServer &vrdeServer = m_machine.GetVRDEServer();
     157    m_cache.m_fVRDEServerSupported = !vrdeServer.isNull();
     158    m_cache.m_fVRDEServerEnabled = m_cache.m_fVRDEServerSupported && vrdeServer.GetEnabled();
     159    m_cache.m_strVRDEPort = vrdeServer.GetVRDEProperty("TCP/Ports");
     160    m_cache.m_iVRDEAuthType = vrdeServer.GetAuthType();
     161    m_cache.m_uVRDETimeout = vrdeServer.GetAuthTimeout();
     162    m_cache.m_fMultipleConnectionsAllowed = vrdeServer.GetAllowMultiConnection();
     163
     164    /* Other variables: */
     165    m_initialVRAM = RT_MIN(m_cache.m_iCurrentVRAM, m_maxVRAM);
     166
     167    /* Upload machine to data: */
     168    UISettingsPageMachine::uploadData(data);
     169}
     170
     171/* Load data to corresponding widgets from cache,
     172 * this task SHOULD be performed in GUI thread only: */
     173void VBoxVMSettingsDisplay::getFromCache()
     174{
     175    /* Apply internal variables data to QWidget(s): */
     176    mSlMonitors->setValue(m_cache.m_cMonitorCount);
     177    mCb3D->setEnabled(m_cache.m_f3dAccelerationSupported);
     178    mCb3D->setChecked(m_cache.m_f3dAccelerationEnabled);
     179#ifdef VBOX_WITH_VIDEOHWACCEL
     180    mCb2DVideo->setEnabled(m_cache.m_f2dAccelerationSupported);
     181    mCb2DVideo->setChecked(m_cache.m_f2dAccelerationEnabled);
     182#endif
    162183    checkVRAMRequirements();
    163 
    164 #ifdef VBOX_WITH_VIDEOHWACCEL
    165     mCb2DVideo->setEnabled (VBoxGlobal::isAcceleration2DVideoAvailable());
    166     mCb2DVideo->setChecked (   mMachine.GetAccelerate2DVideoEnabled()
    167                             && VBoxGlobal::isAcceleration2DVideoAvailable());
    168 #endif
    169 
    170     /* Remote Desktop Settings */
    171     CVRDEServer vrdeServer = mMachine.GetVRDEServer();
     184    mSlMemory->setValue(m_cache.m_iCurrentVRAM);
     185    if (m_cache.m_fVRDEServerSupported)
     186    {
     187        mCbVRDE->setChecked(m_cache.m_fVRDEServerEnabled);
     188        mLeVRDEPort->setText(m_cache.m_strVRDEPort);
     189        mCbVRDEMethod->setCurrentIndex(mCbVRDEMethod->findText(vboxGlobal().toString(m_cache.m_iVRDEAuthType)));
     190        mLeVRDETimeout->setText(QString::number(m_cache.m_uVRDETimeout));
     191        mCbMultipleConn->setChecked(m_cache.m_fMultipleConnectionsAllowed);
     192    }
     193    else
     194        mTwDisplay->removeTab(1);
     195
     196    /* Revalidate if possible: */
     197    if (mValidator) mValidator->revalidate();
     198}
     199
     200/* Save data from corresponding widgets to cache,
     201 * this task SHOULD be performed in GUI thread only: */
     202void VBoxVMSettingsDisplay::putToCache()
     203{
     204    /* Gather internal variables data from QWidget(s): */
     205    m_cache.m_iCurrentVRAM = mSlMemory->value();
     206    m_cache.m_cMonitorCount = mSlMonitors->value();
     207    m_cache.m_f3dAccelerationEnabled = mCb3D->isChecked();
     208#ifdef VBOX_WITH_VIDEOHWACCEL
     209    m_cache.m_f2dAccelerationEnabled = mCb2DVideo->isChecked();
     210#endif
     211    if (m_cache.m_fVRDEServerSupported)
     212    {
     213        m_cache.m_fVRDEServerEnabled = mCbVRDE->isChecked();
     214        m_cache.m_strVRDEPort = mLeVRDEPort->text();
     215        m_cache.m_iVRDEAuthType = vboxGlobal().toAuthType(mCbVRDEMethod->currentText());
     216        m_cache.m_uVRDETimeout = mLeVRDETimeout->text().toULong();
     217        m_cache.m_fMultipleConnectionsAllowed = mCbMultipleConn->isChecked();
     218    }
     219}
     220
     221/* Save data from cache to corresponding external object(s),
     222 * this task COULD be performed in other than GUI thread: */
     223void VBoxVMSettingsDisplay::saveFromCacheTo(QVariant &data)
     224{
     225    /* Fetch data to machine: */
     226    UISettingsPageMachine::fetchData(data);
     227
     228    /* Gather corresponding values from internal variables: */
     229    m_machine.SetVRAMSize(m_cache.m_iCurrentVRAM);
     230    m_machine.SetMonitorCount(m_cache.m_cMonitorCount);
     231    m_machine.SetAccelerate3DEnabled(m_cache.m_f3dAccelerationEnabled);
     232#ifdef VBOX_WITH_VIDEOHWACCEL
     233    m_machine.SetAccelerate2DVideoEnabled(m_cache.m_f2dAccelerationEnabled);
     234#endif
     235    CVRDEServer &vrdeServer = m_machine.GetVRDEServer();
    172236    if (!vrdeServer.isNull())
    173237    {
    174         mCbVRDE->setChecked (vrdeServer.GetEnabled());
    175         mLeVRDEPort->setText (vrdeServer.GetVRDEProperty("TCP/Ports"));
    176         mCbVRDEMethod->setCurrentIndex (mCbVRDEMethod->
    177                                         findText (vboxGlobal().toString (vrdeServer.GetAuthType())));
    178         mLeVRDETimeout->setText (QString::number (vrdeServer.GetAuthTimeout()));
    179         mCbMultipleConn->setChecked(vrdeServer.GetAllowMultiConnection());
    180     }
    181     else
    182     {
    183         vboxProblem().cannotLoadMachineSettings (mMachine, false /* strict */);
    184         mTwDisplay->setTabEnabled (1, false);
    185     }
    186 }
    187 
    188 void VBoxVMSettingsDisplay::putBackTo()
    189 {
    190     /* Memory Size */
    191     mMachine.SetVRAMSize (mSlMemory->value());
    192 
    193     /* Monitors Count */
    194     mMachine.SetMonitorCount (mSlMonitors->value());
    195 
    196     /* 3D Acceleration */
    197     mMachine.SetAccelerate3DEnabled (mCb3D->isChecked());
    198 
    199 #ifdef VBOX_WITH_VIDEOHWACCEL
    200     /* 2D Video Acceleration */
    201     mMachine.SetAccelerate2DVideoEnabled (mCb2DVideo->isChecked());
    202 #endif
    203 
    204     /* VRDE Settings */
    205     CVRDEServer vrdeServer = mMachine.GetVRDEServer();
    206     if (!vrdeServer.isNull())
    207     {
    208         vrdeServer.SetEnabled (mCbVRDE->isChecked());
    209         vrdeServer.SetVRDEProperty("TCP/Ports", mLeVRDEPort->text());
    210         vrdeServer.SetAuthType (vboxGlobal().toAuthType (mCbVRDEMethod->currentText()));
    211         vrdeServer.SetAuthTimeout (mLeVRDETimeout->text().toULong());
    212         vrdeServer.SetAllowMultiConnection(mCbMultipleConn->isChecked());
    213     }
     238        vrdeServer.SetEnabled(m_cache.m_fVRDEServerEnabled);
     239        vrdeServer.SetVRDEProperty("TCP/Ports", m_cache.m_strVRDEPort);
     240        vrdeServer.SetAuthType(m_cache.m_iVRDEAuthType);
     241        vrdeServer.SetAuthTimeout(m_cache.m_uVRDETimeout);
     242        vrdeServer.SetAllowMultiConnection(m_cache.m_fMultipleConnectionsAllowed);
     243    }
     244
     245    /* Upload machine to data: */
     246    UISettingsPageMachine::uploadData(data);
    214247}
    215248
     
    234267{
    235268    /* Video RAM amount test */
    236     quint64 needBytes = VBoxGlobal::requiredVideoMemory (&mMachine, mSlMonitors->value());
     269    quint64 needBytes = VBoxGlobal::requiredVideoMemory (&m_machine, mSlMonitors->value());
    237270    if ((quint64) mSlMemory->value() * _1M < needBytes)
    238271    {
     
    260293    {
    261294        int cVal = mSlMonitors->value();
    262         needBytes += VBoxGlobal::required3DWddmOffscreenVideoMemory(&mMachine, cVal);
     295        needBytes += VBoxGlobal::required3DWddmOffscreenVideoMemory(&m_machine, cVal);
    263296        needBytes = RT_MAX(needBytes, 128 * _1M);
    264297        needBytes = RT_MIN(needBytes, 256 * _1M);
     
    347380    int cVal = mSlMonitors->value();
    348381    /* The memory requirements have changed too. */
    349     quint64 needMBytes = VBoxGlobal::requiredVideoMemory (&mMachine, cVal) / _1M;
     382    quint64 needMBytes = VBoxGlobal::requiredVideoMemory (&m_machine, cVal) / _1M;
    350383    /* Limit the maximum memory to save careless users from setting useless big values */
    351384#ifdef VBOX_WITH_VIDEOHWACCEL
     
    358391    if (m_bWddmMode && mCb3D->isChecked())
    359392    {
    360         needMBytes += VBoxGlobal::required3DWddmOffscreenVideoMemory(&mMachine, cVal) / _1M;
     393        needMBytes += VBoxGlobal::required3DWddmOffscreenVideoMemory(&m_machine, cVal) / _1M;
    361394        needMBytes = RT_MAX(needMBytes, 128);
    362395        needMBytes = RT_MIN(needMBytes, 256);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsDisplay.h

    r33626 r33631  
    2424#include "VBoxVMSettingsDisplay.gen.h"
    2525
    26 class VBoxVMSettingsDisplay : public UISettingsPage,
     26/* Machine settings / Display page / Cache: */
     27struct UISettingsCacheMachineDisplay
     28{
     29    int m_iCurrentVRAM;
     30    int m_cMonitorCount;
     31    bool m_f3dAccelerationSupported;
     32    bool m_f3dAccelerationEnabled;
     33    bool m_f2dAccelerationSupported;
     34    bool m_f2dAccelerationEnabled;
     35    bool m_fVRDEServerSupported;
     36    bool m_fVRDEServerEnabled;
     37    QString m_strVRDEPort;
     38    KAuthType m_iVRDEAuthType;
     39    ulong m_uVRDETimeout;
     40    bool m_fMultipleConnectionsAllowed;
     41};
     42
     43/* Machine settings / Display page: */
     44class VBoxVMSettingsDisplay : public UISettingsPageMachine,
    2745                              public Ui::VBoxVMSettingsDisplay
    2846{
     
    4361protected:
    4462
    45     void getFrom (const CMachine &aMachine);
    46     void putBackTo();
     63    /* Load data to cashe from corresponding external object(s),
     64     * this task COULD be performed in other than GUI thread: */
     65    void loadToCacheFrom(QVariant &data);
     66    /* Load data to corresponding widgets from cache,
     67     * this task SHOULD be performed in GUI thread only: */
     68    void getFromCache();
     69
     70    /* Save data from corresponding widgets to cache,
     71     * this task SHOULD be performed in GUI thread only: */
     72    void putToCache();
     73    /* Save data from cache to corresponding external object(s),
     74     * this task COULD be performed in other than GUI thread: */
     75    void saveFromCacheTo(QVariant &data);
    4776
    4877    void setValidator (QIWidgetValidator *aVal);
     
    6493    void checkVRAMRequirements();
    6594
    66     CMachine mMachine;
    6795    QIWidgetValidator *mValidator;
    6896
     
    77105    int m_initialVRAM;
    78106#ifdef VBOX_WITH_CRHGSMI
    79     /* specifies whether the guest os is wddm-capable */
     107    /* Specifies whether the guest os is wddm-capable: */
    80108    bool m_bWddmMode;
    81109#endif
     110
     111    /* Cache: */
     112    UISettingsCacheMachineDisplay m_cache;
    82113};
    83114
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsGeneral.cpp

    r33626 r33631  
    6363bool VBoxVMSettingsGeneral::isWddmSupportedForOSType() const
    6464{
    65     const QString & id = mOSTypeSelector->type().GetId();
    66     return id == "WindowsVista" || id == "Windows7";
     65    const QString &strOsId = mOSTypeSelector->type().GetId();
     66    return strOsId == "WindowsVista" || strOsId == "Windows7";
    6767}
    6868#endif
    6969
    70 void VBoxVMSettingsGeneral::getFrom (const CMachine &aMachine)
     70/* Load data to cashe from corresponding external object(s),
     71 * this task COULD be performed in other than GUI thread: */
     72void VBoxVMSettingsGeneral::loadToCacheFrom(QVariant &data)
    7173{
    72     mMachine = aMachine;
     74    /* Fetch data to machine: */
     75    UISettingsPageMachine::fetchData(data);
    7376
    74     /* Name */
    75     mLeName->setText (aMachine.GetName());
     77    /* Fill internal variables with corresponding values: */
     78    m_cache.m_strName = m_machine.GetName();
     79    m_cache.m_strGuestOsTypeId = m_machine.GetOSTypeId();
     80    QString strSaveMountedAtRuntime = m_machine.GetExtraData(VBoxDefs::GUI_SaveMountedAtRuntime);
     81    m_cache.m_fSaveMountedAtRuntime = strSaveMountedAtRuntime != "no";
     82    QString strShowMiniToolBar = m_machine.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar);
     83    m_cache.m_fShowMiniToolBar = strShowMiniToolBar != "no";
     84    QString strMiniToolBarAlignment = m_machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment);
     85    m_cache.m_fMiniToolBarAtTop = strMiniToolBarAlignment == "top";
     86    m_cache.m_strSnapshotsFolder = m_machine.GetSnapshotFolder();
     87    m_cache.m_strSnapshotsHomeDir = QFileInfo(m_machine.GetSettingsFilePath()).absolutePath();
     88    m_cache.m_clipboardMode = m_machine.GetClipboardMode();
     89    m_cache.m_strDescription = m_machine.GetDescription();
    7690
    77     /* OS type */
    78     mOSTypeSelector->setType (vboxGlobal().vmGuestOSType (aMachine.GetOSTypeId()));
    79 
    80     /* Remember mediums mounted at runtime */
    81     QString saveRtimeImages = mMachine.GetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime);
    82     mCbSaveMounted->setChecked (saveRtimeImages != "no");
    83 
    84     /* Show Mini ToolBar in fullscreen/seamless */
    85     QString showMiniToolBar = mMachine.GetExtraData (VBoxDefs::GUI_ShowMiniToolBar);
    86     mCbShowToolBar->setChecked (showMiniToolBar != "no");
    87 
    88     /* Show Mini ToolBar at top */
    89     QString miniToolBarAlignment = mMachine.GetExtraData (VBoxDefs::GUI_MiniToolBarAlignment);
    90     mCbToolBarAlignment->setChecked (miniToolBarAlignment == "top");
    91     mCbToolBarAlignment->setEnabled (mCbShowToolBar->isChecked());
    92 
    93     /* Snapshot folder */
    94     mPsSnapshot->setPath (aMachine.GetSnapshotFolder());
    95     mPsSnapshot->setHomeDir (QFileInfo (mMachine.GetSettingsFilePath()).absolutePath());
    96 
    97     /* Shared clipboard mode */
    98     mCbClipboard->setCurrentIndex (aMachine.GetClipboardMode());
    99 
    100     /* Description */
    101     mTeDescription->setPlainText (aMachine.GetDescription());
    102 
    103     if (mValidator)
    104         mValidator->revalidate();
     91    /* Upload machine to data: */
     92    UISettingsPageMachine::uploadData(data);
    10593}
    10694
    107 void VBoxVMSettingsGeneral::putBackTo()
     95/* Load data to corresponding widgets from cache,
     96 * this task SHOULD be performed in GUI thread only: */
     97void VBoxVMSettingsGeneral::getFromCache()
    10898{
    109     /* Name */
    110     mMachine.SetName (mLeName->text());
     99    /* Apply internal variables data to QWidget(s): */
     100    mLeName->setText(m_cache.m_strName);
     101    mOSTypeSelector->setType(vboxGlobal().vmGuestOSType(m_cache.m_strGuestOsTypeId));
     102    mCbSaveMounted->setChecked(m_cache.m_fSaveMountedAtRuntime);
     103    mCbShowToolBar->setChecked(m_cache.m_fShowMiniToolBar);
     104    mCbToolBarAlignment->setChecked(m_cache.m_fMiniToolBarAtTop);
     105    mCbToolBarAlignment->setEnabled(mCbShowToolBar->isChecked());
     106    mPsSnapshot->setPath(m_cache.m_strSnapshotsFolder);
     107    mPsSnapshot->setHomeDir(m_cache.m_strSnapshotsHomeDir);
     108    mCbClipboard->setCurrentIndex(m_cache.m_clipboardMode);
     109    mTeDescription->setPlainText(m_cache.m_strDescription);
    111110
    112     /* OS type */
    113     AssertMsg (!mOSTypeSelector->type().isNull(), ("mOSTypeSelector must return non-null type"));
    114     mMachine.SetOSTypeId (mOSTypeSelector->type().GetId());
     111    /* Revalidate if possible: */
     112    if (mValidator) mValidator->revalidate();
     113}
    115114
    116     /* Remember mediums mounted at runtime */
    117     mMachine.SetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime,
    118                            mCbSaveMounted->isChecked() ? "yes" : "no");
     115/* Save data from corresponding widgets to cache,
     116 * this task SHOULD be performed in GUI thread only: */
     117void VBoxVMSettingsGeneral::putToCache()
     118{
     119    /* Gather internal variables data from QWidget(s): */
     120    m_cache.m_strName = mLeName->text();
     121    m_cache.m_strGuestOsTypeId = mOSTypeSelector->type().GetId();
     122    m_cache.m_fSaveMountedAtRuntime = mCbSaveMounted->isChecked();
     123    m_cache.m_fShowMiniToolBar = mCbShowToolBar->isChecked();
     124    m_cache.m_fMiniToolBarAtTop = mCbToolBarAlignment->isChecked();
     125    m_cache.m_strSnapshotsFolder = mPsSnapshot->path();
     126    m_cache.m_clipboardMode = (KClipboardMode)mCbClipboard->currentIndex();
     127    m_cache.m_strDescription = mTeDescription->toPlainText().isEmpty() ?
     128                               QString::null : mTeDescription->toPlainText();
     129}
    119130
    120     /* Show Mini ToolBar in fullscreen/seamless */
    121     mMachine.SetExtraData (VBoxDefs::GUI_ShowMiniToolBar,
    122                            mCbShowToolBar->isChecked() ? "yes" : "no");
     131/* Save data from cache to corresponding external object(s),
     132 * this task COULD be performed in other than GUI thread: */
     133void VBoxVMSettingsGeneral::saveFromCacheTo(QVariant &data)
     134{
     135    /* Fetch data to machine: */
     136    UISettingsPageMachine::fetchData(data);
    123137
    124     /* Show Mini ToolBar at top */
    125     mMachine.SetExtraData (VBoxDefs::GUI_MiniToolBarAlignment,
    126                            mCbToolBarAlignment->isChecked() ? "top" : "bottom");
     138    /* Gather corresponding values from internal variables: */
     139    m_machine.SetName(m_cache.m_strName);
     140    m_machine.SetOSTypeId(m_cache.m_strGuestOsTypeId);
     141    m_machine.SetExtraData(VBoxDefs::GUI_SaveMountedAtRuntime, m_cache.m_fSaveMountedAtRuntime ? "yes" : "no");
     142    m_machine.SetExtraData(VBoxDefs::GUI_ShowMiniToolBar, m_cache.m_fShowMiniToolBar ? "yes" : "no");
     143    m_machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAlignment, m_cache.m_fMiniToolBarAtTop ? "top" : "bottom");
     144    m_machine.SetSnapshotFolder(m_cache.m_strSnapshotsFolder);
     145    m_machine.SetClipboardMode(m_cache.m_clipboardMode);
     146    m_machine.SetDescription(m_cache.m_strDescription);
    127147
    128     /* Saved state folder */
    129     if (mPsSnapshot->isModified())
    130     {
    131         mMachine.SetSnapshotFolder (mPsSnapshot->path());
    132         if (!mMachine.isOk())
    133             vboxProblem().cannotSetSnapshotFolder (mMachine,
    134                     QDir::toNativeSeparators (mPsSnapshot->path()));
    135     }
    136 
    137     /* Shared clipboard mode */
    138     mMachine.SetClipboardMode ((KClipboardMode) mCbClipboard->currentIndex());
    139 
    140     /* Description (set empty to null to avoid an empty <Description> node
    141      * in the settings file) */
    142     mMachine.SetDescription (mTeDescription->toPlainText().isEmpty() ?
    143                              QString::null : mTeDescription->toPlainText());
     148    /* Upload machine to data: */
     149    UISettingsPageMachine::uploadData(data);
    144150}
    145151
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsGeneral.h

    r33599 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#include "COMDefs.h"
    2525
    26 class VBoxVMSettingsGeneral : public UISettingsPage,
     26/* Machine settings / General page / Cache: */
     27struct UISettingsCacheMachineGeneral
     28{
     29    QString m_strName;
     30    QString m_strGuestOsTypeId;
     31    bool m_fSaveMountedAtRuntime;
     32    bool m_fShowMiniToolBar;
     33    bool m_fMiniToolBarAtTop;
     34    QString m_strSnapshotsFolder;
     35    QString m_strSnapshotsHomeDir;
     36    KClipboardMode m_clipboardMode;
     37    QString m_strDescription;
     38};
     39
     40/* Machine settings / General page: */
     41class VBoxVMSettingsGeneral : public UISettingsPageMachine,
    2742                              public Ui::VBoxVMSettingsGeneral
    2843{
     
    4560protected:
    4661
    47     void getFrom (const CMachine &aMachine);
    48     void putBackTo();
     62    /* Load data to cashe from corresponding external object(s),
     63     * this task COULD be performed in other than GUI thread: */
     64    void loadToCacheFrom(QVariant &data);
     65    /* Load data to corresponding widgets from cache,
     66     * this task SHOULD be performed in GUI thread only: */
     67    void getFromCache();
     68
     69    /* Save data from corresponding widgets to cache,
     70     * this task SHOULD be performed in GUI thread only: */
     71    void putToCache();
     72    /* Save data from cache to corresponding external object(s),
     73     * this task COULD be performed in other than GUI thread: */
     74    void saveFromCacheTo(QVariant &data);
    4975
    5076    void setValidator (QIWidgetValidator *aVal);
     
    5884    void showEvent (QShowEvent *aEvent);
    5985
    60     CMachine mMachine;
    6186    QIWidgetValidator *mValidator;
     87
     88    /* Cache: */
     89    UISettingsCacheMachineGeneral m_cache;
    6290};
    6391
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsHD.cpp

    r33540 r33631  
    17821782}
    17831783
    1784 void VBoxVMSettingsHD::getFrom (const CMachine &aMachine)
    1785 {
    1786     mMachine = aMachine;
    1787 
    1788     /* Set the machine id for the media-combo */
    1789     mCbVdi->setMachineId (mMachine.GetId());
    1790     mStorageModel->setMachineId (mMachine.GetId());
    1791 
    1792     /* Load currently present controllers & attachments */
    1793     CStorageControllerVector controllers = mMachine.GetStorageControllers();
    1794     foreach (const CStorageController &controller, controllers)
    1795     {
    1796         QString controllerName = controller.GetName();
    1797         QModelIndex ctrIndex = mStorageModel->addController (controllerName, controller.GetBus(), controller.GetControllerType());
    1798         QUuid ctrId = QUuid (mStorageModel->data (ctrIndex, StorageModel::R_ItemId).toString());
    1799 
    1800         bool useIoCache = controller.GetUseHostIOCache();
    1801 
    1802         mStorageModel->setData (ctrIndex, useIoCache, StorageModel::R_CtrIoCache);
    1803 
    1804         CMediumAttachmentVector attachments = mMachine.GetMediumAttachmentsOfController (controllerName);
    1805         foreach (const CMediumAttachment &attachment, attachments)
    1806         {
    1807             QModelIndex attIndex = mStorageModel->addAttachment (ctrId, attachment.GetType());
    1808             mStorageModel->setData (attIndex, QVariant::fromValue (StorageSlot (controller.GetBus(), attachment.GetPort(), attachment.GetDevice())), StorageModel::R_AttSlot);
    1809             CMedium medium (attachment.GetMedium());
     1784/* Load data to cashe from corresponding external object(s),
     1785 * this task COULD be performed in other than GUI thread: */
     1786void VBoxVMSettingsHD::loadToCacheFrom(QVariant &data)
     1787{
     1788    /* Fetch data to machine: */
     1789    UISettingsPageMachine::fetchData(data);
     1790
     1791    /* Fill internal variables with corresponding values: */
     1792    m_cache.m_strMachineId = m_machine.GetId();
     1793    /* Load controllers list: */
     1794    const CStorageControllerVector &controllers = m_machine.GetStorageControllers();
     1795    for (int iControllerIndex = 0; iControllerIndex < controllers.size(); ++iControllerIndex)
     1796    {
     1797        /* Prepare controller item: */
     1798        const CStorageController &controller = controllers[iControllerIndex];
     1799        UIStorageControllerData controllerData;
     1800        controllerData.m_strControllerName = controller.GetName();
     1801        controllerData.m_controllerBus = controller.GetBus();
     1802        controllerData.m_controllerType = controller.GetControllerType();
     1803        controllerData.m_fUseHostIOCache = controller.GetUseHostIOCache();
     1804        /* Load attachments list: */
     1805        const CMediumAttachmentVector &attachments = m_machine.GetMediumAttachmentsOfController(controllerData.m_strControllerName);
     1806        for (int iAttachmentIndex = 0; iAttachmentIndex < attachments.size(); ++iAttachmentIndex)
     1807        {
     1808            /* Prepare attachment item: */
     1809            const CMediumAttachment &attachment = attachments[iAttachmentIndex];
     1810            UIStorageAttachmentData attachmentData;
     1811            attachmentData.m_attachmentType = attachment.GetType();
     1812            attachmentData.m_iAttachmentPort = attachment.GetPort();
     1813            attachmentData.m_iAttachmentDevice = attachment.GetDevice();
     1814            attachmentData.m_fAttachmentPassthrough = attachment.GetPassthrough();
     1815            CMedium comMedium(attachment.GetMedium());
    18101816            VBoxMedium vboxMedium;
    1811             vboxGlobal().findMedium (medium, vboxMedium);
    1812             mStorageModel->setData (attIndex, vboxMedium.id(), StorageModel::R_AttMediumId);
    1813             mStorageModel->setData (attIndex, attachment.GetPassthrough(), StorageModel::R_AttIsPassthrough);
    1814         }
    1815     }
    1816 
     1817            vboxGlobal().findMedium(comMedium, vboxMedium);
     1818            attachmentData.m_strAttachmentMediumId = vboxMedium.id();
     1819            controllerData.m_items << attachmentData;
     1820        }
     1821        m_cache.m_items << controllerData;
     1822    }
     1823
     1824    /* Upload machine to data: */
     1825    UISettingsPageMachine::uploadData(data);
     1826}
     1827
     1828/* Load data to corresponding widgets from cache,
     1829 * this task SHOULD be performed in GUI thread only: */
     1830void VBoxVMSettingsHD::getFromCache()
     1831{
     1832    /* Apply internal variables data to QWidget(s): */
     1833    mCbVdi->setMachineId(m_cache.m_strMachineId);
     1834    mStorageModel->setMachineId(m_cache.m_strMachineId);
     1835    for (int iControllerIndex = 0; iControllerIndex < m_cache.m_items.size(); ++iControllerIndex)
     1836    {
     1837        /* Get iterated controller: */
     1838        const UIStorageControllerData &controllerData = m_cache.m_items[iControllerIndex];
     1839        QModelIndex controllerIndex = mStorageModel->addController(controllerData.m_strControllerName,
     1840                                                                   controllerData.m_controllerBus,
     1841                                                                   controllerData.m_controllerType);
     1842        QUuid controllerId = QUuid(mStorageModel->data(controllerIndex, StorageModel::R_ItemId).toString());
     1843        mStorageModel->setData(controllerIndex, controllerData.m_fUseHostIOCache, StorageModel::R_CtrIoCache);
     1844        for (int iAttachmentIndex = 0; iAttachmentIndex < controllerData.m_items.size(); ++iAttachmentIndex)
     1845        {
     1846            /* Get iterated attachment: */
     1847            const UIStorageAttachmentData &attachmentData = controllerData.m_items[iAttachmentIndex];
     1848            QModelIndex attachmentIndex = mStorageModel->addAttachment(controllerId, attachmentData.m_attachmentType);
     1849            StorageSlot attachmentStorageSlot(controllerData.m_controllerBus,
     1850                                              attachmentData.m_iAttachmentPort,
     1851                                              attachmentData.m_iAttachmentDevice);
     1852            mStorageModel->setData(attachmentIndex, QVariant::fromValue(attachmentStorageSlot), StorageModel::R_AttSlot);
     1853            mStorageModel->setData(attachmentIndex, attachmentData.m_fAttachmentPassthrough, StorageModel::R_AttIsPassthrough);
     1854            mStorageModel->setData(attachmentIndex, attachmentData.m_strAttachmentMediumId, StorageModel::R_AttMediumId);
     1855        }
     1856    }
    18171857    /* Set the first controller as current if present */
    1818     if (mStorageModel->rowCount (mStorageModel->root()) > 0)
    1819         mTwStorageTree->setCurrentIndex (mStorageModel->index (0, 0, mStorageModel->root()));
    1820 }
    1821 
    1822 void VBoxVMSettingsHD::putBackTo()
    1823 {
     1858    if (mStorageModel->rowCount(mStorageModel->root()) > 0)
     1859        mTwStorageTree->setCurrentIndex(mStorageModel->index(0, 0, mStorageModel->root()));
     1860
     1861    /* Revalidate if possible: */
     1862    if (mValidator) mValidator->revalidate();
     1863}
     1864
     1865/* Save data from corresponding widgets to cache,
     1866 * this task SHOULD be performed in GUI thread only: */
     1867void VBoxVMSettingsHD::putToCache()
     1868{
     1869    /* Gather internal variables data from QWidget(s): */
     1870    m_cache.m_items.clear();
     1871    QModelIndex rootIndex = mStorageModel->root();
     1872    for (int iControllerIndex = 0; iControllerIndex < mStorageModel->rowCount(rootIndex); ++iControllerIndex)
     1873    {
     1874        QModelIndex controllerIndex = mStorageModel->index(iControllerIndex, 0, rootIndex);
     1875        UIStorageControllerData controllerData;
     1876        controllerData.m_strControllerName = mStorageModel->data(controllerIndex, StorageModel::R_CtrName).toString();
     1877        controllerData.m_controllerBus = mStorageModel->data(controllerIndex, StorageModel::R_CtrBusType).value<KStorageBus>();
     1878        controllerData.m_controllerType = mStorageModel->data(controllerIndex, StorageModel::R_CtrType).value<KStorageControllerType>();
     1879        controllerData.m_fUseHostIOCache = mStorageModel->data(controllerIndex, StorageModel::R_CtrIoCache).toBool();
     1880        for (int iAttachmentIndex = 0; iAttachmentIndex < mStorageModel->rowCount(controllerIndex); ++iAttachmentIndex)
     1881        {
     1882            QModelIndex attachmentIndex = mStorageModel->index(iAttachmentIndex, 0, controllerIndex);
     1883            UIStorageAttachmentData attachmentData;
     1884            attachmentData.m_attachmentType = mStorageModel->data(attachmentIndex, StorageModel::R_AttDevice).value<KDeviceType>();
     1885            StorageSlot attachmentSlot = mStorageModel->data(attachmentIndex, StorageModel::R_AttSlot).value<StorageSlot>();
     1886            attachmentData.m_iAttachmentPort = attachmentSlot.port;
     1887            attachmentData.m_iAttachmentDevice = attachmentSlot.device;
     1888            attachmentData.m_fAttachmentPassthrough = mStorageModel->data(attachmentIndex, StorageModel::R_AttIsPassthrough).toBool();
     1889            attachmentData.m_strAttachmentMediumId = mStorageModel->data(attachmentIndex, StorageModel::R_AttMediumId).toString();
     1890            controllerData.m_items << attachmentData;
     1891        }
     1892        m_cache.m_items << controllerData;
     1893    }
     1894}
     1895
     1896/* Save data from cache to corresponding external object(s),
     1897 * this task COULD be performed in other than GUI thread: */
     1898void VBoxVMSettingsHD::saveFromCacheTo(QVariant &data)
     1899{
     1900    /* Fetch data to machine: */
     1901    UISettingsPageMachine::fetchData(data);
     1902
    18241903    /* Remove currently present controllers & attachments */
    1825     CStorageControllerVector controllers = mMachine.GetStorageControllers();
    1826     foreach (const CStorageController &controller, controllers)
    1827     {
    1828         QString controllerName (controller.GetName());
    1829         CMediumAttachmentVector attachments = mMachine.GetMediumAttachmentsOfController (controllerName);
    1830         foreach (const CMediumAttachment &attachment, attachments)
    1831             mMachine.DetachDevice (controllerName, attachment.GetPort(), attachment.GetDevice());
    1832         mMachine.RemoveStorageController (controllerName);
    1833     }
    1834 
    1835     /* Save created controllers & attachments */
    1836     QModelIndex rootIndex = mStorageModel->root();
    1837     for (int i = 0; i < mStorageModel->rowCount (rootIndex); ++ i)
    1838     {
    1839         QModelIndex ctrIndex = rootIndex.child (i, 0);
    1840         QString ctrName = mStorageModel->data (ctrIndex, StorageModel::R_CtrName).toString();
    1841         KStorageBus ctrBusType = mStorageModel->data (ctrIndex, StorageModel::R_CtrBusType).value <KStorageBus>();
    1842         KStorageControllerType ctrType = mStorageModel->data (ctrIndex, StorageModel::R_CtrType).value <KStorageControllerType>();
    1843         bool useIoCache = mStorageModel->data (ctrIndex, StorageModel::R_CtrIoCache).toBool();
    1844         CStorageController ctr = mMachine.AddStorageController (ctrName, ctrBusType);
    1845         ctr.SetControllerType (ctrType);
    1846         ctr.SetUseHostIOCache(useIoCache);
    1847         int maxUsedPort = -1;
    1848         for (int j = 0; j < mStorageModel->rowCount (ctrIndex); ++ j)
    1849         {
    1850             QModelIndex attIndex = ctrIndex.child (j, 0);
    1851             StorageSlot attStorageSlot = mStorageModel->data (attIndex, StorageModel::R_AttSlot).value <StorageSlot>();
    1852             KDeviceType attDeviceType = mStorageModel->data (attIndex, StorageModel::R_AttDevice).value <KDeviceType>();
    1853             QString attMediumId = mStorageModel->data (attIndex, StorageModel::R_AttMediumId).toString();
    1854             QString attMediumLocation = mStorageModel->data (attIndex, StorageModel::R_AttLocation).toString();
    1855 
    1856             VBoxMedium vmedium = vboxGlobal().findMedium(attMediumId);
    1857             CMedium medium = vmedium.medium();              // @todo r=dj can this be cached somewhere?
    1858             mMachine.AttachDevice(ctrName, attStorageSlot.port, attStorageSlot.device, attDeviceType, medium);
    1859             if (mMachine.isOk())
     1904    const CStorageControllerVector &controllers = m_machine.GetStorageControllers();
     1905    for (int iControllerIndex = 0; iControllerIndex < controllers.size(); ++iControllerIndex)
     1906    {
     1907        const CStorageController &controller = controllers[iControllerIndex];
     1908        QString strControllerName(controller.GetName());
     1909        const CMediumAttachmentVector &attachments = m_machine.GetMediumAttachmentsOfController(strControllerName);
     1910        for (int iAttachmentIndex = 0; iAttachmentIndex < attachments.size(); ++iAttachmentIndex)
     1911        {
     1912            const CMediumAttachment &attachment = attachments[iAttachmentIndex];
     1913            m_machine.DetachDevice(strControllerName, attachment.GetPort(), attachment.GetDevice());
     1914        }
     1915        m_machine.RemoveStorageController(strControllerName);
     1916    }
     1917    /* Save created controllers: */
     1918    for (int iControllerIndex = 0; iControllerIndex < m_cache.m_items.size(); ++iControllerIndex)
     1919    {
     1920        const UIStorageControllerData &controllerData = m_cache.m_items[iControllerIndex];
     1921        CStorageController &controller = m_machine.AddStorageController(controllerData.m_strControllerName, controllerData.m_controllerBus);
     1922        controller.SetControllerType(controllerData.m_controllerType);
     1923        controller.SetUseHostIOCache(controllerData.m_fUseHostIOCache);
     1924        int cMaxUsedPort = -1;
     1925        /* Save created attachments: */
     1926        for (int iAttachmentIndex = 0; iAttachmentIndex < controllerData.m_items.size(); ++iAttachmentIndex)
     1927        {
     1928            const UIStorageAttachmentData &attachmentData = controllerData.m_items[iAttachmentIndex];
     1929            VBoxMedium vboxMedium = vboxGlobal().findMedium(attachmentData.m_strAttachmentMediumId);
     1930            CMedium comMedium = vboxMedium.medium();
     1931            m_machine.AttachDevice(controllerData.m_strControllerName,
     1932                                   attachmentData.m_iAttachmentPort, attachmentData.m_iAttachmentDevice,
     1933                                   attachmentData.m_attachmentType, comMedium);
     1934            if (m_machine.isOk())
    18601935            {
    1861                 if (attDeviceType == KDeviceType_DVD)
    1862                     mMachine.PassthroughDevice (ctrName, attStorageSlot.port, attStorageSlot.device,
    1863                                                 mStorageModel->data (attIndex, StorageModel::R_AttIsPassthrough).toBool());
    1864                 maxUsedPort = attStorageSlot.port > maxUsedPort ? attStorageSlot.port : maxUsedPort;
     1936                if (attachmentData.m_attachmentType == KDeviceType_DVD)
     1937                    m_machine.PassthroughDevice(controllerData.m_strControllerName,
     1938                                                attachmentData.m_iAttachmentPort, attachmentData.m_iAttachmentDevice,
     1939                                                attachmentData.m_fAttachmentPassthrough);
     1940                cMaxUsedPort = attachmentData.m_iAttachmentPort > cMaxUsedPort ? attachmentData.m_iAttachmentPort : cMaxUsedPort;
    18651941            }
    18661942            else
    1867                 vboxProblem().cannotAttachDevice(this, mMachine, VBoxDefs::MediumType_HardDisk, attMediumLocation,
    1868                                                  attStorageSlot.bus, attStorageSlot.port, attStorageSlot.device);
    1869         }
    1870         if (ctrBusType == KStorageBus_SATA)
    1871         {
    1872             ULONG sataPortsCount = maxUsedPort + 1;
    1873             sataPortsCount = qMax (sataPortsCount, ctr.GetMinPortCount());
    1874             sataPortsCount = qMin (sataPortsCount, ctr.GetMaxPortCount());
    1875             ctr.SetPortCount (sataPortsCount);
    1876         }
    1877     }
     1943            {
     1944                // TODO: Fix problem reporter!
     1945                //vboxProblem().cannotAttachDevice(this, m_machine, VBoxDefs::MediumType_HardDisk, vboxMedium.location(),
     1946                //                                 controllerData.m_controllerBus, attachmentData.m_iAttachmentPort, attachmentData.m_iAttachmentDevice);
     1947            }
     1948        }
     1949        if (controllerData.m_controllerBus == KStorageBus_SATA)
     1950        {
     1951            ULONG uSataPortsCount = cMaxUsedPort + 1;
     1952            uSataPortsCount = qMax(uSataPortsCount, controller.GetMinPortCount());
     1953            uSataPortsCount = qMin(uSataPortsCount, controller.GetMaxPortCount());
     1954            controller.SetPortCount(uSataPortsCount);
     1955        }
     1956    }
     1957
     1958    /* Upload machine to data: */
     1959    UISettingsPageMachine::uploadData(data);
    18781960}
    18791961
     
    26662748               true /* do select? */,
    26672749               false /* do refresh? */,
    2668                mMachine,
     2750               m_machine,
    26692751               mCbVdi->id(),
    26702752               mCbShowDiffs->isChecked());
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsHD.h

    r33540 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2009 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    530530};
    531531
    532 /**
    533  * QWidget class reimplementation.
    534  * Used as HD Settings widget.
    535  */
    536 class VBoxVMSettingsHD : public UISettingsPage,
     532/* Machine settings / Storage page / Attachment data: */
     533struct UIStorageAttachmentData
     534{
     535    KDeviceType m_attachmentType;
     536    LONG m_iAttachmentPort;
     537    LONG m_iAttachmentDevice;
     538    QString m_strAttachmentMediumId;
     539    bool m_fAttachmentPassthrough;
     540};
     541
     542/* Machine settings / Storage page / Controller data: */
     543struct UIStorageControllerData
     544{
     545    QString m_strControllerName;
     546    KStorageBus m_controllerBus;
     547    KStorageControllerType m_controllerType;
     548    bool m_fUseHostIOCache;
     549    QList<UIStorageAttachmentData> m_items;
     550};
     551
     552/* Machine settings / Storage page / Cache: */
     553struct UISettingsCacheMachineStorage
     554{
     555    QString m_strMachineId;
     556    QList<UIStorageControllerData> m_items;
     557};
     558
     559/* Machine settings / Storage page: */
     560class VBoxVMSettingsHD : public UISettingsPageMachine,
    537561                         public Ui::VBoxVMSettingsHD
    538562{
     
    549573protected:
    550574
    551     void getFrom (const CMachine &aMachine);
    552     void putBackTo();
     575    /* Load data to cashe from corresponding external object(s),
     576     * this task COULD be performed in other than GUI thread: */
     577    void loadToCacheFrom(QVariant &data);
     578    /* Load data to corresponding widgets from cache,
     579     * this task SHOULD be performed in GUI thread only: */
     580    void getFromCache();
     581
     582    /* Save data from corresponding widgets to cache,
     583     * this task SHOULD be performed in GUI thread only: */
     584    void putToCache();
     585    /* Save data from cache to corresponding external object(s),
     586     * this task COULD be performed in other than GUI thread: */
     587    void saveFromCacheTo(QVariant &data);
    553588
    554589    void setValidator (QIWidgetValidator *aVal);
     
    611646    uint32_t deviceCount (KDeviceType aType) const;
    612647
    613     CMachine mMachine;
    614648    QIWidgetValidator *mValidator;
    615649
     
    632666    bool mIsPolished;
    633667    bool mDisableStaticControls;
     668
     669    /* Cache: */
     670    UISettingsCacheMachineStorage m_cache;
    634671};
    635672
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.cpp

    r32814 r33631  
    4242    , mParent (aParent)
    4343    , mValidator (0)
     44    , m_iSlot(-1)
    4445    , mPolished (false)
    4546    , mDisableStaticControls (false)
     
    7879}
    7980
    80 void VBoxVMSettingsNetwork::getFromAdapter (const CNetworkAdapter &aAdapter)
    81 {
    82     mAdapter = aAdapter;
    83 
    84     /* Load adapter activity state */
    85     mCbEnableAdapter->setChecked (aAdapter.GetEnabled());
    86 
    87     /* Load adapter type */
    88     int adapterPos = mCbAdapterType->findData (aAdapter.GetAdapterType());
    89     mCbAdapterType->setCurrentIndex (adapterPos == -1 ? 0 : adapterPos);
    90 
    91     /* Load attachment type */
    92     int attachmentPos = mCbAttachmentType->findData (aAdapter.GetAttachmentType());
    93     mCbAttachmentType->setCurrentIndex (attachmentPos == -1 ? 0 : attachmentPos);
    94 
    95     /* Load alternative name */
     81void VBoxVMSettingsNetwork::fetchAdapterData(const UINetworkAdapterData &data)
     82{
     83    /* Load adapter & slot number: */
     84    m_iSlot = data.m_iSlot;
     85    m_adapter = data.m_adapter;
     86
     87    /* Load adapter activity state: */
     88    mCbEnableAdapter->setChecked(data.m_fAdapterEnabled);
     89
     90    /* Load adapter type: */
     91    int adapterPos = mCbAdapterType->findData(data.m_adapterType);
     92    mCbAdapterType->setCurrentIndex(adapterPos == -1 ? 0 : adapterPos);
     93
     94    /* Load attachment type: */
     95    int attachmentPos = mCbAttachmentType->findData(data.m_attachmentType);
     96    mCbAttachmentType->setCurrentIndex(attachmentPos == -1 ? 0 : attachmentPos);
     97
     98    /* Load alternative name: */
    9699    switch (attachmentType())
    97100    {
    98101        case KNetworkAttachmentType_Bridged:
    99             mBrgName = mAdapter.GetHostInterface();
    100             if (mBrgName.isEmpty()) mBrgName = QString::null;
     102            mBrgName = data.m_strBridgedAdapterName;
     103            if (mBrgName.isEmpty()) mBrgName = QString();
    101104            break;
    102105        case KNetworkAttachmentType_Internal:
    103             mIntName = mAdapter.GetInternalNetwork();
    104             if (mIntName.isEmpty()) mIntName = QString::null;
     106            mIntName = data.m_strInternalNetworkName;
     107            if (mIntName.isEmpty()) mIntName = QString();
    105108            break;
    106109        case KNetworkAttachmentType_HostOnly:
    107             mHoiName = mAdapter.GetHostInterface();
    108             if (mHoiName.isEmpty()) mHoiName = QString::null;
     110            mHoiName = data.m_strHostInterfaceName;
     111            if (mHoiName.isEmpty()) mHoiName = QString();
    109112            break;
    110113#ifdef VBOX_WITH_VDE
    111114        case KNetworkAttachmentType_VDE:
    112             mVDEName = mAdapter.GetVDENetwork();
    113             if (mVDEName.isEmpty()) mVDEName = QString::null;
     115            mVDEName = data.m_strVDENetworkName;
     116            if (mVDEName.isEmpty()) mVDEName = QString();
    114117            break;
    115118#endif
     
    119122    updateAttachmentAlternative();
    120123
    121     mLeMAC->setText (mAdapter.GetMACAddress());
    122     mCbCableConnected->setChecked (mAdapter.GetCableConnected());
     124    /* Other options: */
     125    mLeMAC->setText(data.m_strMACAddress);
     126    mCbCableConnected->setChecked(data.m_fCableConnected);
    123127
    124128    /* Load port forwarding rules: */
    125     QVector<QString> redirects = mAdapter.GetNatDriver().GetRedirects();
    126     for (int i = 0; i < redirects.size(); ++i)
    127     {
    128         QStringList redirectData = redirects[i].split(',');
    129         AssertMsg(redirectData.size() == 6, ("Redirect rule should be composed of 6 parts!\n"));
    130         mPortForwardingRules << UIPortForwardingData(redirectData[0],
    131                                                      (KNATProtocol)redirectData[1].toUInt(),
    132                                                      redirectData[2],
    133                                                      redirectData[3].toUInt(),
    134                                                      redirectData[4],
    135                                                      redirectData[5].toUInt());
    136     }
    137 }
    138 
    139 void VBoxVMSettingsNetwork::putBackToAdapter()
    140 {
    141     /* Save adapter activity state */
    142     mAdapter.SetEnabled (mCbEnableAdapter->isChecked());
    143 
    144     /* Save adapter type */
    145     KNetworkAdapterType type = (KNetworkAdapterType)
    146         mCbAdapterType->itemData (mCbAdapterType->currentIndex()).toInt();
    147     mAdapter.SetAdapterType (type);
    148 
    149     /* Save attachment type & alternative name */
    150     switch (attachmentType())
     129    mPortForwardingRules = data.m_redirects;
     130}
     131
     132void VBoxVMSettingsNetwork::uploadAdapterData(UINetworkAdapterData &data)
     133{
     134    /* Save adapter activity state: */
     135    data.m_fAdapterEnabled = mCbEnableAdapter->isChecked();
     136
     137    /* Save adapter type: */
     138    data.m_adapterType = (KNetworkAdapterType)mCbAdapterType->itemData(mCbAdapterType->currentIndex()).toInt();
     139
     140    /* Save attachment type & alternative name: */
     141    data.m_attachmentType = attachmentType();
     142    switch (data.m_attachmentType)
    151143    {
    152144        case KNetworkAttachmentType_Null:
    153             mAdapter.Detach();
    154145            break;
    155146        case KNetworkAttachmentType_NAT:
    156             mAdapter.AttachToNAT();
    157147            break;
    158148        case KNetworkAttachmentType_Bridged:
    159             mAdapter.SetHostInterface (alternativeName());
    160             mAdapter.AttachToBridgedInterface();
     149            data.m_strBridgedAdapterName = alternativeName();
    161150            break;
    162151        case KNetworkAttachmentType_Internal:
    163             mAdapter.SetInternalNetwork (alternativeName());
    164             mAdapter.AttachToInternalNetwork();
     152            data.m_strInternalNetworkName = alternativeName();
    165153            break;
    166154        case KNetworkAttachmentType_HostOnly:
    167             mAdapter.SetHostInterface (alternativeName());
    168             mAdapter.AttachToHostOnlyInterface();
     155            data.m_strHostInterfaceName = alternativeName();
    169156            break;
    170157#ifdef VBOX_WITH_VDE
    171158        case KNetworkAttachmentType_VDE:
    172             mAdapter.SetVDENetwork (alternativeName());
    173             mAdapter.AttachToVDE();
     159            data.m_strVDENetworkName = alternativeName();
    174160            break;
    175161#endif
     
    178164    }
    179165
    180     mAdapter.SetMACAddress (mLeMAC->text().isEmpty() ? QString::null : mLeMAC->text());
    181     mAdapter.SetCableConnected (mCbCableConnected->isChecked());
     166    /* Other options: */
     167    data.m_strMACAddress = mLeMAC->text().isEmpty() ? QString() : mLeMAC->text();
     168    data.m_fCableConnected = mCbCableConnected->isChecked();
    182169
    183170    /* Save port forwarding rules: */
    184     QVector<QString> redirects = mAdapter.GetNatDriver().GetRedirects();
    185     for (int i = 0; i < redirects.size(); ++i)
    186         mAdapter.GetNatDriver().RemoveRedirect(redirects[i].section(',', 0, 0));
    187     for (int i = 0; i < mPortForwardingRules.size(); ++i)
    188     {
    189         UIPortForwardingData redirectData = mPortForwardingRules[i];
    190         mAdapter.GetNatDriver().AddRedirect(redirectData.name, redirectData.protocol,
    191                                             redirectData.hostIp, redirectData.hostPort.value(),
    192                                             redirectData.guestIp, redirectData.guestPort.value());
    193     }
     171    data.m_redirects = mPortForwardingRules;
    194172}
    195173
     
    269247QString VBoxVMSettingsNetwork::pageTitle() const
    270248{
    271     QString title;
    272     if (!mAdapter.isNull())
    273     {
    274         title = VBoxGlobal::tr ("Adapter %1", "network")
    275             .arg (QString ("&%1").arg (mAdapter.GetSlot() + 1));
    276     }
    277     return title;
     249    return VBoxGlobal::tr("Adapter %1", "network").arg(QString("&%1").arg(m_iSlot + 1));;
    278250}
    279251
     
    524496void VBoxVMSettingsNetwork::generateMac()
    525497{
    526     mAdapter.SetMACAddress (QString::null);
    527     mLeMAC->setText (mAdapter.GetMACAddress());
     498    m_adapter.SetMACAddress(QString::null);
     499    mLeMAC->setText(m_adapter.GetMACAddress());
    528500}
    529501
     
    663635}
    664636
     637void VBoxVMSettingsNetworkPage::loadDirectlyFrom(const CMachine &machine)
     638{
     639    qRegisterMetaType<UISettingsDataMachine>();
     640    UISettingsDataMachine data(machine);
     641    loadToCacheFrom(QVariant::fromValue(data));
     642    getFromCache();
     643}
     644
     645void VBoxVMSettingsNetworkPage::saveDirectlyTo(CMachine &machine)
     646{
     647    qRegisterMetaType<UISettingsDataMachine>();
     648    UISettingsDataMachine data(machine);
     649    putToCache();
     650    saveFromCacheTo(QVariant::fromValue(data));
     651}
     652
    665653QStringList VBoxVMSettingsNetworkPage::brgList (bool aRefresh)
    666654{
     
    741729}
    742730
    743 void VBoxVMSettingsNetworkPage::getFrom (const CMachine &aMachine)
    744 {
    745     /* Setup tab order */
    746     Assert (m_pFirstWidget);
    747     setTabOrder (m_pFirstWidget, mTwAdapters->focusProxy());
    748     QWidget *lastFocusWidget = mTwAdapters->focusProxy();
    749 
    750     /* Cache data */
    751     brgList (true);
    752     intList (true);
    753     hoiList (true);
    754 
    755     /* Creating Tab Pages */
    756     CVirtualBox vbox = vboxGlobal().virtualBox();
    757     ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
    758     for (ulong slot = 0; slot < count; ++ slot)
    759     {
    760         /* Get Adapter */
    761         CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot);
    762 
    763         /* Creating Adapter's page */
    764         VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork (this, mDisableStaticControls);
    765 
    766         /* Loading Adapter's data into page */
    767         page->getFromAdapter (adapter);
    768 
    769         /* Attach Adapter's page to Tab Widget */
    770         mTwAdapters->addTab (page, page->pageTitle());
    771 
    772         /* Disable tab page if adapter is being configured dynamically */
    773         if (mDisableStaticControls && !adapter.GetEnabled())
    774             mTwAdapters->setTabEnabled(slot, false);
    775 
    776         /* Setup validation */
    777         page->setValidator (mValidator);
    778 
    779         /* Setup tab order */
    780         lastFocusWidget = page->setOrderAfter (lastFocusWidget);
    781     }
    782 
    783     /* Applying language settings */
     731/* Load data to cashe from corresponding external object(s),
     732 * this task COULD be performed in other than GUI thread: */
     733void VBoxVMSettingsNetworkPage::loadToCacheFrom(QVariant &data)
     734{
     735    /* Fetch data to machine: */
     736    UISettingsPageMachine::fetchData(data);
     737
     738    /* Cache names lists: */
     739    brgList(true);
     740    intList(true);
     741    hoiList(true);
     742
     743    /* Load adapters data: */
     744    ulong uCount = qMin((ULONG)4, vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount());
     745    for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
     746    {
     747        /* Get adapter: */
     748        const CNetworkAdapter &adapter = m_machine.GetNetworkAdapter(uSlot);
     749
     750        /* Prepare adapter's data container: */
     751        UINetworkAdapterData data;
     752
     753        /* Load main options: */
     754        data.m_iSlot = uSlot;
     755        data.m_adapter = adapter;
     756        data.m_fAdapterEnabled = adapter.GetEnabled();
     757        data.m_adapterType = adapter.GetAdapterType();
     758        data.m_attachmentType = adapter.GetAttachmentType();
     759        switch (data.m_attachmentType)
     760        {
     761            case KNetworkAttachmentType_Bridged:
     762                data.m_strBridgedAdapterName = adapter.GetHostInterface();
     763                if (data.m_strBridgedAdapterName.isEmpty()) data.m_strBridgedAdapterName = QString();
     764                break;
     765            case KNetworkAttachmentType_Internal:
     766                data.m_strInternalNetworkName = adapter.GetInternalNetwork();
     767                if (data.m_strInternalNetworkName.isEmpty()) data.m_strInternalNetworkName = QString();
     768                break;
     769            case KNetworkAttachmentType_HostOnly:
     770                data.m_strHostInterfaceName = adapter.GetHostInterface();
     771                if (data.m_strHostInterfaceName.isEmpty()) data.m_strHostInterfaceName = QString();
     772                break;
     773#ifdef VBOX_WITH_VDE
     774            case KNetworkAttachmentType_VDE:
     775                data.m_strVDENetworkName = adapter.GetVDENetwork();
     776                if (data.m_strVDENetworkName.isEmpty()) data.m_strVDENetworkName = QString();
     777                break;
     778#endif
     779            default:
     780                break;
     781        }
     782
     783        /* Load advanced options: */
     784        data.m_strMACAddress = adapter.GetMACAddress();
     785        data.m_fCableConnected = adapter.GetCableConnected();
     786
     787        /* Load redirect options: */
     788        QVector<QString> redirects = adapter.GetNatDriver().GetRedirects();
     789        for (int i = 0; i < redirects.size(); ++i)
     790        {
     791            QStringList redirectData = redirects[i].split(',');
     792            AssertMsg(redirectData.size() == 6, ("Redirect rule should be composed of 6 parts!\n"));
     793            data.m_redirects << UIPortForwardingData(redirectData[0],
     794                                                     (KNATProtocol)redirectData[1].toUInt(),
     795                                                     redirectData[2],
     796                                                     redirectData[3].toUInt(),
     797                                                     redirectData[4],
     798                                                     redirectData[5].toUInt());
     799        }
     800
     801        /* Append adapter's data container: */
     802        m_cache.m_items << data;
     803    }
     804
     805    /* Upload machine to data: */
     806    UISettingsPageMachine::uploadData(data);
     807}
     808
     809/* Load data to corresponding widgets from cache,
     810 * this task SHOULD be performed in GUI thread only: */
     811void VBoxVMSettingsNetworkPage::getFromCache()
     812{
     813    /* Setup tab order: */
     814    Assert(m_pFirstWidget);
     815    setTabOrder(m_pFirstWidget, mTwAdapters->focusProxy());
     816    QWidget *pLastFocusWidget = mTwAdapters->focusProxy();
     817
     818    /* Apply internal variables data to QWidget(s): */
     819    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     820    {
     821        /* Creating adapter's page: */
     822        VBoxVMSettingsNetwork *pPage = new VBoxVMSettingsNetwork(this, mDisableStaticControls);
     823
     824        /* Loading adapter's data into page: */
     825        pPage->fetchAdapterData(m_cache.m_items[iSlot]);
     826
     827        /* Attach adapter's page to Tab Widget: */
     828        mTwAdapters->addTab(pPage, pPage->pageTitle());
     829
     830        /* Disable tab page of disabled adapter if it is being configured dynamically: */
     831        if (mDisableStaticControls && !m_cache.m_items[iSlot].m_fAdapterEnabled)
     832            mTwAdapters->setTabEnabled(iSlot, false);
     833
     834        /* Setup page validation: */
     835        pPage->setValidator(mValidator);
     836
     837        /* Setup tab order: */
     838        pLastFocusWidget = pPage->setOrderAfter(pLastFocusWidget);
     839    }
     840
     841    /* Applying language settings: */
    784842    retranslateUi();
    785 }
    786 
    787 void VBoxVMSettingsNetworkPage::putBackTo()
    788 {
    789     for (int i = 0; i < mTwAdapters->count(); ++ i)
    790     {
    791         VBoxVMSettingsNetwork *page =
    792             qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
    793         Assert (page);
    794         page->putBackToAdapter();
    795     }
     843
     844    /* Revalidate if possible: */
     845    if (mValidator) mValidator->revalidate();
     846}
     847
     848/* Save data from corresponding widgets to cache,
     849 * this task SHOULD be performed in GUI thread only: */
     850void VBoxVMSettingsNetworkPage::putToCache()
     851{
     852    /* Gather internal variables data from QWidget(s): */
     853    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     854    {
     855        /* Getting adapter's page: */
     856        VBoxVMSettingsNetwork *pPage = qobject_cast<VBoxVMSettingsNetwork*>(mTwAdapters->widget(iSlot));
     857
     858        /* Loading Adapter's data from page: */
     859        pPage->uploadAdapterData(m_cache.m_items[iSlot]);
     860    }
     861}
     862
     863/* Save data from cache to corresponding external object(s),
     864 * this task COULD be performed in other than GUI thread: */
     865void VBoxVMSettingsNetworkPage::saveFromCacheTo(QVariant &data)
     866{
     867    /* Fetch data to machine: */
     868    UISettingsPageMachine::fetchData(data);
     869
     870    /* Gather corresponding values from internal variables: */
     871    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     872    {
     873        /* Get adapter: */
     874        CNetworkAdapter &adapter = m_machine.GetNetworkAdapter(iSlot);
     875
     876        /* Get cached data for this adapter: */
     877        const UINetworkAdapterData &data = m_cache.m_items[iSlot];
     878
     879        /* Save main options: */
     880        adapter.SetEnabled(data.m_fAdapterEnabled);
     881        adapter.SetAdapterType(data.m_adapterType);
     882        switch (data.m_attachmentType)
     883        {
     884            case KNetworkAttachmentType_Null:
     885                adapter.Detach();
     886                break;
     887            case KNetworkAttachmentType_NAT:
     888                adapter.AttachToNAT();
     889                break;
     890            case KNetworkAttachmentType_Bridged:
     891                adapter.SetHostInterface(data.m_strBridgedAdapterName);
     892                adapter.AttachToBridgedInterface();
     893                break;
     894            case KNetworkAttachmentType_Internal:
     895                adapter.SetInternalNetwork(data.m_strInternalNetworkName);
     896                adapter.AttachToInternalNetwork();
     897                break;
     898            case KNetworkAttachmentType_HostOnly:
     899                adapter.SetHostInterface(data.m_strHostInterfaceName);
     900                adapter.AttachToHostOnlyInterface();
     901                break;
     902    #ifdef VBOX_WITH_VDE
     903            case KNetworkAttachmentType_VDE:
     904                adapter.SetVDENetwork(data.m_strVDENetworkName);
     905                adapter.AttachToVDE();
     906                break;
     907    #endif
     908            default:
     909                break;
     910        }
     911
     912        /* Save advanced options: */
     913        adapter.SetMACAddress(data.m_strMACAddress);
     914        adapter.SetCableConnected(data.m_fCableConnected);
     915
     916        /* Save redirect options: */
     917        QVector<QString> oldRedirects = adapter.GetNatDriver().GetRedirects();
     918        for (int i = 0; i < oldRedirects.size(); ++i)
     919            adapter.GetNatDriver().RemoveRedirect(oldRedirects[i].section(',', 0, 0));
     920        UIPortForwardingDataList newRedirects = data.m_redirects;
     921        for (int i = 0; i < newRedirects.size(); ++i)
     922        {
     923            UIPortForwardingData newRedirect = newRedirects[i];
     924            adapter.GetNatDriver().AddRedirect(newRedirect.name, newRedirect.protocol,
     925                                               newRedirect.hostIp, newRedirect.hostPort.value(),
     926                                               newRedirect.guestIp, newRedirect.guestPort.value());
     927        }
     928    }
     929
     930    /* Upload machine to data: */
     931    UISettingsPageMachine::uploadData(data);
    796932}
    797933
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.h

    r33540 r33631  
    3030class QITabWidget;
    3131
     32/* Machine settings / Network page / Adapter data: */
     33struct UINetworkAdapterData
     34{
     35    int m_iSlot;
     36    /* CNetworkAdapter used only for Generate MAC ability! */
     37    CNetworkAdapter m_adapter;
     38    bool m_fAdapterEnabled;
     39    KNetworkAdapterType m_adapterType;
     40    KNetworkAttachmentType m_attachmentType;
     41    QString m_strBridgedAdapterName;
     42    QString m_strInternalNetworkName;
     43    QString m_strHostInterfaceName;
     44#ifdef VBOX_WITH_VDE
     45    QString m_strVDENetworkName;
     46#endif /* VBOX_WITH_VDE */
     47    QString m_strMACAddress;
     48    bool m_fCableConnected;
     49    UIPortForwardingDataList m_redirects;
     50};
     51
     52/* Machine settings / Network page / Cache: */
     53struct UISettingsCacheMachineNetwork
     54{
     55    QList<UINetworkAdapterData> m_items;
     56};
     57
    3258class VBoxVMSettingsNetwork : public QIWithRetranslateUI <QWidget>,
    3359                              public Ui::VBoxVMSettingsNetwork
     
    3965    VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent, bool aDisableStaticControls = false);
    4066
    41     void getFromAdapter (const CNetworkAdapter &aAdapter);
    42     void putBackToAdapter();
     67    void fetchAdapterData(const UINetworkAdapterData &data);
     68    void uploadAdapterData(UINetworkAdapterData &data);
    4369
    4470    void setValidator (QIWidgetValidator *aValidator);
     
    7096
    7197    VBoxVMSettingsNetworkPage *mParent;
    72     CNetworkAdapter mAdapter;
    7398    QIWidgetValidator *mValidator;
     99    int m_iSlot;
     100    CNetworkAdapter m_adapter;
    74101
    75102    QString mBrgName;
     
    85112};
    86113
    87 class VBoxVMSettingsNetworkPage : public UISettingsPage
     114/* Machine settings / Network page: */
     115class VBoxVMSettingsNetworkPage : public UISettingsPageMachine
    88116{
    89117    Q_OBJECT;
     
    92120
    93121    VBoxVMSettingsNetworkPage (bool aDisableStaticControls = false);
     122
     123    void loadDirectlyFrom(const CMachine &machine);
     124    void saveDirectlyTo(CMachine &machine);
    94125
    95126    QStringList brgList (bool aRefresh = false);
     
    102133protected:
    103134
    104     void getFrom (const CMachine &aMachine);
    105     void putBackTo();
     135    /* Load data to cashe from corresponding external object(s),
     136     * this task COULD be performed in other than GUI thread: */
     137    void loadToCacheFrom(QVariant &data);
     138    /* Load data to corresponding widgets from cache,
     139     * this task SHOULD be performed in GUI thread only: */
     140    void getFromCache();
     141
     142    /* Save data from corresponding widgets to cache,
     143     * this task SHOULD be performed in GUI thread only: */
     144    void putToCache();
     145    /* Save data from cache to corresponding external object(s),
     146     * this task COULD be performed in other than GUI thread: */
     147    void saveFromCacheTo(QVariant &data);
    106148
    107149    void setValidator (QIWidgetValidator *aValidator);
     
    124166
    125167    bool mDisableStaticControls;
     168
     169    /* Cache: */
     170    UISettingsCacheMachineNetwork m_cache;
    126171};
    127172
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsParallel.cpp

    r32814 r33631  
    77
    88/*
    9  * Copyright (C) 2006-2008 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929    : QIWithRetranslateUI<QWidget> (0)
    3030    , mValidator (0)
     31    , m_iSlot(-1)
    3132{
    3233    /* Apply UI decorations */
     
    5758}
    5859
    59 void VBoxVMSettingsParallel::getFromPort (const CParallelPort &aPort)
    60 {
    61     mPort = aPort;
    62 
    63     mGbParallel->setChecked (mPort.GetEnabled());
    64     ulong IRQ = mPort.GetIRQ();
    65     ulong IOBase = mPort.GetIOBase();
    66     mCbNumber->setCurrentIndex (mCbNumber->
    67         findText (vboxGlobal().toCOMPortName (IRQ, IOBase)));
    68     mLeIRQ->setText (QString::number (IRQ));
    69     mLeIOPort->setText ("0x" + QString::number (IOBase, 16).toUpper());
    70     mLePath->setText (mPort.GetPath());
     60void VBoxVMSettingsParallel::fetchPortData(const UIParallelPortData &data)
     61{
     62    /* Load port slot number: */
     63    m_iSlot = data.m_iSlot;
     64
     65    /* Fetch port data: */
     66    mGbParallel->setChecked(data.m_fPortEnabled);
     67    mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(data.m_uIRQ, data.m_uIOBase)));
     68    mLeIRQ->setText(QString::number(data.m_uIRQ));
     69    mLeIOPort->setText("0x" + QString::number(data.m_uIOBase, 16).toUpper());
     70    mLePath->setText(data.m_strPath);
    7171
    7272    /* Ensure everything is up-to-date */
    73     mGbParallelToggled (mGbParallel->isChecked());
    74 }
    75 
    76 void VBoxVMSettingsParallel::putBackToPort()
    77 {
    78     mPort.SetEnabled (mGbParallel->isChecked());
    79     mPort.SetIRQ (mLeIRQ->text().toULong (NULL, 0));
    80     mPort.SetIOBase (mLeIOPort->text().toULong (NULL, 0));
    81     mPort.SetPath (QDir::toNativeSeparators (mLePath->text()));
     73    mGbParallelToggled(mGbParallel->isChecked());
     74}
     75
     76void VBoxVMSettingsParallel::uploadPortData(UIParallelPortData &data)
     77{
     78    /* Upload port data: */
     79    data.m_fPortEnabled = mGbParallel->isChecked();
     80    data.m_uIRQ = mLeIRQ->text().toULong(NULL, 0);
     81    data.m_uIOBase = mLeIOPort->text().toULong(NULL, 0);
     82    data.m_strPath = QDir::toNativeSeparators(mLePath->text());
    8283}
    8384
     
    107108QString VBoxVMSettingsParallel::pageTitle() const
    108109{
    109     QString pageTitle;
    110     if (!mPort.isNull())
    111         pageTitle = QString (tr ("Port %1", "parallel ports"))
    112             .arg (QString ("&%1").arg (mPort.GetSlot() + 1));
    113     return pageTitle;
     110    return QString(tr("Port %1", "parallel ports")).arg(QString("&%1").arg(m_iSlot + 1));
    114111}
    115112
     
    162159}
    163160
    164 void VBoxVMSettingsParallelPage::getFrom (const CMachine &aMachine)
    165 {
    166     Assert (m_pFirstWidget);
    167     setTabOrder (m_pFirstWidget, mTabWidget->focusProxy());
    168     QWidget *lastFocusWidget = mTabWidget->focusProxy();
    169 
    170     /* Tab pages loading */
    171     ulong count = vboxGlobal().virtualBox().
    172                   GetSystemProperties().GetParallelPortCount();
    173     for (ulong slot = 0; slot < count; ++ slot)
    174     {
    175         CParallelPort port = aMachine.GetParallelPort (slot);
    176         VBoxVMSettingsParallel *page = new VBoxVMSettingsParallel();
    177         page->getFromPort (port);
    178         mTabWidget->addTab (page, page->pageTitle());
    179         Assert (mValidator);
    180         page->setValidator (mValidator);
    181         lastFocusWidget = page->setOrderAfter (lastFocusWidget);
    182     }
    183 }
    184 
    185 void VBoxVMSettingsParallelPage::putBackTo()
    186 {
    187     for (int index = 0; index < mTabWidget->count(); ++ index)
    188     {
    189         VBoxVMSettingsParallel *page =
    190             (VBoxVMSettingsParallel*) mTabWidget->widget (index);
    191         Assert (page);
    192         page->putBackToPort();
    193     }
     161/* Load data to cashe from corresponding external object(s),
     162 * this task COULD be performed in other than GUI thread: */
     163void VBoxVMSettingsParallelPage::loadToCacheFrom(QVariant &data)
     164{
     165    /* Fetch data to machine: */
     166    UISettingsPageMachine::fetchData(data);
     167
     168    /* Load port data: */
     169    ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetParallelPortCount();
     170    for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
     171    {
     172        /* Get port: */
     173        const CParallelPort &port = m_machine.GetParallelPort(uSlot);
     174
     175        /* Prepare port's data container: */
     176        UIParallelPortData data;
     177
     178        /* Load options: */
     179        data.m_iSlot = uSlot;
     180        data.m_fPortEnabled = port.GetEnabled();
     181        data.m_uIRQ = port.GetIRQ();
     182        data.m_uIOBase = port.GetIOBase();
     183        data.m_strPath = port.GetPath();
     184
     185        /* Append adapter's data container: */
     186        m_cache.m_items << data;
     187    }
     188
     189    /* Upload machine to data: */
     190    UISettingsPageMachine::uploadData(data);
     191}
     192
     193/* Load data to corresponding widgets from cache,
     194 * this task SHOULD be performed in GUI thread only: */
     195void VBoxVMSettingsParallelPage::getFromCache()
     196{
     197    Assert(m_pFirstWidget);
     198    setTabOrder(m_pFirstWidget, mTabWidget->focusProxy());
     199    QWidget *pLastFocusWidget = mTabWidget->focusProxy();
     200
     201    /* Apply internal variables data to QWidget(s): */
     202    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     203    {
     204        /* Creating port's page: */
     205        VBoxVMSettingsParallel *pPage = new VBoxVMSettingsParallel;
     206
     207        /* Loading port's data into page: */
     208        pPage->fetchPortData(m_cache.m_items[iSlot]);
     209
     210        /* Attach port's page to Tab Widget: */
     211        mTabWidget->addTab(pPage, pPage->pageTitle());
     212
     213        /* Setup page validation: */
     214        pPage->setValidator(mValidator);
     215
     216        /* Setup tab order: */
     217        pLastFocusWidget = pPage->setOrderAfter(pLastFocusWidget);
     218    }
     219
     220    /* Applying language settings: */
     221    retranslateUi();
     222
     223    /* Revalidate if possible: */
     224    if (mValidator) mValidator->revalidate();
     225}
     226
     227/* Save data from corresponding widgets to cache,
     228 * this task SHOULD be performed in GUI thread only: */
     229void VBoxVMSettingsParallelPage::putToCache()
     230{
     231    /* Gather internal variables data from QWidget(s): */
     232    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     233    {
     234        /* Getting adapter's page: */
     235        VBoxVMSettingsParallel *pPage = qobject_cast<VBoxVMSettingsParallel*>(mTabWidget->widget(iSlot));
     236
     237        /* Loading Adapter's data from page: */
     238        pPage->uploadPortData(m_cache.m_items[iSlot]);
     239    }
     240}
     241
     242/* Save data from cache to corresponding external object(s),
     243 * this task COULD be performed in other than GUI thread: */
     244void VBoxVMSettingsParallelPage::saveFromCacheTo(QVariant &data)
     245{
     246    /* Fetch data to machine: */
     247    UISettingsPageMachine::fetchData(data);
     248
     249    /* Gather corresponding values from internal variables: */
     250    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     251    {
     252        /* Get adapter: */
     253        CParallelPort &port = m_machine.GetParallelPort(iSlot);
     254
     255        /* Get cached data for this slot: */
     256        const UIParallelPortData &data = m_cache.m_items[iSlot];
     257
     258        /* Save options: */
     259        port.SetIRQ(data.m_uIRQ);
     260        port.SetIOBase(data.m_uIOBase);
     261        port.SetPath(data.m_strPath);
     262        port.SetEnabled(data.m_fPortEnabled);
     263    }
     264
     265    /* Upload machine to data: */
     266    UISettingsPageMachine::uploadData(data);
    194267}
    195268
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsParallel.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626class QITabWidget;
    2727
     28struct UIParallelPortData
     29{
     30    int m_iSlot;
     31    bool m_fPortEnabled;
     32    ulong m_uIRQ;
     33    ulong m_uIOBase;
     34    QString m_strPath;
     35};
     36
     37/* Machine settings / Parallel page / Cache: */
     38struct UISettingsCacheMachineParallel
     39{
     40    QList<UIParallelPortData> m_items;
     41};
     42
    2843class VBoxVMSettingsParallel : public QIWithRetranslateUI<QWidget>,
    2944                               public Ui::VBoxVMSettingsParallel
     
    3550    VBoxVMSettingsParallel();
    3651
    37     void getFromPort (const CParallelPort &aPort);
    38     void putBackToPort();
     52    void fetchPortData(const UIParallelPortData &data);
     53    void uploadPortData(UIParallelPortData &data);
    3954
    4055    void setValidator (QIWidgetValidator *aVal);
     
    5772
    5873    QIWidgetValidator *mValidator;
    59     CParallelPort mPort;
     74    int m_iSlot;
    6075};
    6176
    62 class VBoxVMSettingsParallelPage : public UISettingsPage
     77/* Machine settings / Parallel page: */
     78class VBoxVMSettingsParallelPage : public UISettingsPageMachine
    6379{
    6480    Q_OBJECT;
     
    7086protected:
    7187
    72     void getFrom (const CMachine &aMachine);
    73     void putBackTo();
     88    /* Load data to cashe from corresponding external object(s),
     89     * this task COULD be performed in other than GUI thread: */
     90    void loadToCacheFrom(QVariant &data);
     91    /* Load data to corresponding widgets from cache,
     92     * this task SHOULD be performed in GUI thread only: */
     93    void getFromCache();
     94
     95    /* Save data from corresponding widgets to cache,
     96     * this task SHOULD be performed in GUI thread only: */
     97    void putToCache();
     98    /* Save data from cache to corresponding external object(s),
     99     * this task COULD be performed in other than GUI thread: */
     100    void saveFromCacheTo(QVariant &data);
    74101
    75102    void setValidator (QIWidgetValidator *aVal);
     
    82109    QIWidgetValidator *mValidator;
    83110    QITabWidget *mTabWidget;
     111
     112    /* Internals: */
     113    UISettingsCacheMachineParallel m_cache;
    84114};
    85115
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSF.cpp

    r32814 r33631  
    165165};
    166166
    167 VBoxVMSettingsSF::VBoxVMSettingsSF (int aType, QWidget *aParent)
    168     : UISettingsPage (aParent)
    169     , mDialogType (aType)
     167VBoxVMSettingsSF::VBoxVMSettingsSF()
     168    : m_type(WrongType)
    170169    , mIsListViewChanged (false)
    171170{
     
    209208             this, SLOT (showContextMenu (const QPoint &)));
    210209
    211     /* Create mTwFolders root items */
    212 #if 0
    213     if (aType == GlobalType)
    214     {
    215         QStringList fields;
    216         fields << tr (" Global Folders") /* name */ << QString::number (GlobalType) /* key */;
    217         new SFTreeViewItem (mTwFolders, fields, SFTreeViewItem::EllipsisEnd);
    218     }
    219 #endif
    220     if (aType & MachineType)
    221     {
    222         QStringList fields;
    223         fields << tr (" Machine Folders") /* name */ << QString::number (MachineType) /* key */;
    224         new SFTreeViewItem (mTwFolders, fields, SFTreeViewItem::EllipsisEnd);
    225     }
    226     if (aType & ConsoleType)
    227     {
    228         QStringList fields;
    229         fields << tr (" Transient Folders") /* name */ << QString::number (ConsoleType) /* key */;
    230         new SFTreeViewItem (mTwFolders, fields, SFTreeViewItem::EllipsisEnd);
    231     }
    232     mTwFolders->sortItems (0, Qt::AscendingOrder);
    233 
    234210    retranslateUi();
     211}
     212
     213void VBoxVMSettingsSF::loadDirectlyFrom(const CConsole &console)
     214{
     215    loadToCacheFromMachine(console.GetMachine());
     216    loadToCacheFromConsole(console);
     217    getFromCache();
     218}
     219
     220void VBoxVMSettingsSF::saveDirectlyTo(CConsole &console)
     221{
     222    putToCache();
     223    saveFromCacheToConsole(console);
     224    saveFromCacheToMachine(console.GetMachine());
    235225}
    236226
     
    241231}
    242232
    243 void VBoxVMSettingsSF::getFromGlobal()
    244 {
    245     AssertMsgFailed (("Global shared folders are not supported now!\n"));
    246 #if 0
    247     SFTreeViewItem *root = searchRoot (true, GlobalType);
    248     root->setHidden (false);
    249     getFrom (vboxGlobal().virtualBox().GetSharedFolders(), root);
    250 #endif
    251 }
    252 
    253 void VBoxVMSettingsSF::getFromMachine (const CMachine &aMachine)
    254 {
    255     mMachine = aMachine;
    256     SFTreeViewItem *root = searchRoot (true, MachineType);
    257     root->setHidden (false);
    258     getFrom (mMachine.GetSharedFolders(), root);
    259 }
    260 
    261 void VBoxVMSettingsSF::getFromConsole (const CConsole &aConsole)
    262 {
    263     mConsole = aConsole;
    264     SFTreeViewItem *root = searchRoot (true, ConsoleType);
    265     root->setHidden (false);
    266     getFrom (mConsole.GetSharedFolders(), root);
    267 }
    268 
    269 void VBoxVMSettingsSF::putBackToGlobal()
    270 {
    271     AssertMsgFailed (("Global shared folders are not supported now!\n"));
    272 #if 0
     233/* Load data to cashe from corresponding external object(s),
     234 * this task COULD be performed in other than GUI thread: */
     235void VBoxVMSettingsSF::loadToCacheFrom(QVariant &data)
     236{
     237    /* Fetch data to machine: */
     238    UISettingsPageMachine::fetchData(data);
     239
     240    /* Fill internal variables with corresponding values: */
     241    loadToCacheFromMachine(m_machine);
     242
     243    /* Upload machine to data: */
     244    UISettingsPageMachine::uploadData(data);
     245}
     246
     247void VBoxVMSettingsSF::loadToCacheFromMachine(const CMachine &machine)
     248{
     249    /* Update dialog type: */
     250    if (m_type == WrongType)
     251        m_type = MachineType;
     252    /* Load machine items into internal cache: */
     253    loadToCacheFromVector(machine.GetSharedFolders(), MachineType);
     254}
     255
     256void VBoxVMSettingsSF::loadToCacheFromConsole(const CConsole &console)
     257{
     258    /* Update dialog type: */
     259    if (m_type == WrongType || m_type == MachineType)
     260        m_type = ConsoleType;
     261    /* Load console items into internal cache: */
     262    loadToCacheFromVector(console.GetSharedFolders(), ConsoleType);
     263}
     264
     265void VBoxVMSettingsSF::loadToCacheFromVector(const CSharedFolderVector &vector, UISharedFolderType type)
     266{
     267    /* Cache shared folders in internal variables: */
     268    for (int iFolderIndex = 0; iFolderIndex < vector.size(); ++iFolderIndex)
     269    {
     270        const CSharedFolder &folder = vector[iFolderIndex];
     271        UISharedFolderData data;
     272        data.m_type = type;
     273        data.m_strName = folder.GetName();
     274        data.m_strHostPath = folder.GetHostPath();
     275        data.m_fAutoMount = folder.GetAutoMount();
     276        data.m_fWritable = folder.GetWritable();
     277        m_cache.m_items << data;
     278    }
     279}
     280
     281/* Load data to corresponding widgets from cache,
     282 * this task SHOULD be performed in GUI thread only: */
     283void VBoxVMSettingsSF::getFromCache()
     284{
     285    /* Apply internal variables data to QWidget(s): */
     286    if (m_type == MachineType || m_type == ConsoleType)
     287        root(MachineType);
     288    if (m_type == ConsoleType)
     289        root(ConsoleType);
     290    for (int iFolderIndex = 0; iFolderIndex < m_cache.m_items.size(); ++iFolderIndex)
     291    {
     292        /* Get iterated folder's data: */
     293        const UISharedFolderData &data = m_cache.m_items[iFolderIndex];
     294        /* Prepare list item's fields: */
     295        QStringList fields;
     296        fields << data.m_strName << data.m_strHostPath
     297               << (data.m_fAutoMount ? mTrYes : "")
     298               << (data.m_fWritable ? mTrFull : mTrReadOnly);
     299        /* Searching for item's root: */
     300        SFTreeViewItem *pItemsRoot = root(data.m_type);
     301        /* Create new folder list item: */
     302        new SFTreeViewItem(pItemsRoot, fields, SFTreeViewItem::EllipsisFile);
     303    }
     304    /* Sort populated item's list: */
     305    mTwFolders->sortItems(0, Qt::AscendingOrder);
     306    /* Ensure current item fetched: */
     307    mTwFolders->setCurrentItem(mTwFolders->topLevelItem(0));
     308    processCurrentChanged(mTwFolders->currentItem());
     309}
     310
     311/* Save data from corresponding widgets to cache,
     312 * this task SHOULD be performed in GUI thread only: */
     313void VBoxVMSettingsSF::putToCache()
     314{
     315    /* Reset cache: */
     316    m_cache.m_items.clear();
     317    /* Gather internal variables data from QWidget(s): */
     318    QTreeWidgetItem *pMainRootItem = mTwFolders->invisibleRootItem();
     319    /* Iterate other all the list top-level items: */
     320    for (int iFodlersTypeIndex = 0; iFodlersTypeIndex < pMainRootItem->childCount(); ++iFodlersTypeIndex)
     321    {
     322        SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFodlersTypeIndex));
     323        UISharedFolderType type = (UISharedFolderType)pFolderTypeRoot->text(1).toInt();
     324        AssertMsg(type != WrongType, ("Incorrent folders type!"));
     325        /* Iterate other all the folder items: */
     326        for (int iFoldersIndex = 0; iFoldersIndex < pFolderTypeRoot->childCount(); ++iFoldersIndex)
     327        {
     328            SFTreeViewItem *pFolderItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFoldersIndex));
     329            UISharedFolderData data;
     330            data.m_type = type;
     331            data.m_strName = pFolderItem->getText(0);
     332            data.m_strHostPath = pFolderItem->getText(1);
     333            data.m_fAutoMount = pFolderItem->getText(2) == mTrYes ? true : false;
     334            data.m_fWritable = pFolderItem->getText(3) == mTrFull ? true : false;
     335            m_cache.m_items << data;
     336        }
     337    }
     338}
     339
     340/* Save data from cache to corresponding external object(s),
     341 * this task COULD be performed in other than GUI thread: */
     342void VBoxVMSettingsSF::saveFromCacheTo(QVariant &data)
     343{
     344    /* Fetch data to machine: */
     345    UISettingsPageMachine::fetchData(data);
     346
     347    /* Gather corresponding values from internal variables: */
     348    saveFromCacheToMachine(m_machine);
     349
     350    /* Upload machine to data: */
     351    UISettingsPageMachine::uploadData(data);
     352}
     353
     354void VBoxVMSettingsSF::saveFromCacheToMachine(CMachine &machine)
     355{
     356    /* Save machine items from internal cache: */
     357    /* Check if items were changed: */
    273358    if (!mIsListViewChanged)
    274359        return;
    275     /* This function is only available for GlobalType dialog */
    276     Assert (mDialogType == GlobalType);
    277     /* Searching for GlobalType item's root */
    278     SFTreeViewItem *root = searchRoot (true, GlobalType);
    279     Assert (root);
    280     CSharedFolderVector vec = vboxGlobal().virtualBox().GetSharedFolders();
    281     putBackTo (vec, root);
    282 #endif
    283 }
    284 
    285 void VBoxVMSettingsSF::putBackToMachine()
    286 {
     360
     361    /* Delete all machine folders first: */
     362    const CSharedFolderVector &folders = machine.GetSharedFolders();
     363    for (int iFolderIndex = 0; iFolderIndex < folders.size(); ++iFolderIndex)
     364    {
     365        const CSharedFolder &folder = folders[iFolderIndex];
     366        QString strFolderName = folder.GetName();
     367        QString strFolderPath = folder.GetHostPath();
     368        machine.RemoveSharedFolder(strFolderName);
     369        if (!machine.isOk())
     370        {
     371            // TODO: Fix problem reporter!
     372            //vboxProblem().cannotRemoveSharedFolder(this, machine, strFolderName, strFolderPath);
     373        }
     374    }
     375
     376    /* Save all new machine folders: */
     377    for (int iFolderIndex = 0; iFolderIndex < m_cache.m_items.size(); ++iFolderIndex)
     378    {
     379        const UISharedFolderData &data = m_cache.m_items[iFolderIndex];
     380        if (data.m_type == MachineType)
     381        {
     382            machine.CreateSharedFolder(data.m_strName, data.m_strHostPath, data.m_fWritable, data.m_fAutoMount);
     383            if (!machine.isOk())
     384            {
     385                // TODO: Fix problem reporter!
     386                //vboxProblem().cannotCreateSharedFolder(this, machine, data.m_strName, data.m_strHostPath);
     387            }
     388        }
     389    }
     390}
     391
     392void VBoxVMSettingsSF::saveFromCacheToConsole(CConsole &console)
     393{
     394    /* Save console items from internal cache: */
     395    /* Check if items were changed: */
    287396    if (!mIsListViewChanged)
    288397        return;
    289     /* This function is only available for MachineType dialog */
    290     Assert (mDialogType & MachineType);
    291     /* Searching for MachineType item's root */
    292     SFTreeViewItem *root = searchRoot (true,  MachineType);
    293     Assert (root);
    294     CSharedFolderVector sfvec = mMachine.GetSharedFolders();
    295     putBackTo (sfvec, root);
    296 }
    297 
    298 void VBoxVMSettingsSF::putBackToConsole()
    299 {
    300     if (!mIsListViewChanged)
    301         return;
    302     /* This function is only available for ConsoleType dialog */
    303     Assert (mDialogType & ConsoleType);
    304     /* Searching for ConsoleType item's root */
    305     SFTreeViewItem *root = searchRoot (true, ConsoleType);
    306     Assert (root);
    307     CSharedFolderVector sfvec = mConsole.GetSharedFolders();
    308     putBackTo (sfvec, root);
    309 }
    310 
    311 int VBoxVMSettingsSF::dialogType() const
    312 {
    313      return mDialogType;
    314 }
    315 
    316 void VBoxVMSettingsSF::getFrom (const CMachine &aMachine)
    317 {
    318     getFromMachine (aMachine);
    319 }
    320 
    321 void VBoxVMSettingsSF::putBackTo()
    322 {
    323     putBackToMachine();
     398
     399    /* Delete all console folders first: */
     400    const CSharedFolderVector &folders = console.GetSharedFolders();
     401    for (int iFolderIndex = 0; iFolderIndex < folders.size(); ++iFolderIndex)
     402    {
     403        const CSharedFolder &folder = folders[iFolderIndex];
     404        QString strFolderName = folder.GetName();
     405        QString strFolderPath = folder.GetHostPath();
     406        console.RemoveSharedFolder(strFolderName);
     407        if (!console.isOk())
     408        {
     409            // TODO: Fix problem reporter!
     410            //vboxProblem().cannotRemoveSharedFolder(this, console, strFolderName, strFolderPath);
     411        }
     412    }
     413
     414    /* Save all new console folders: */
     415    for (int iFolderIndex = 0; iFolderIndex < m_cache.m_items.size(); ++iFolderIndex)
     416    {
     417        const UISharedFolderData &data = m_cache.m_items[iFolderIndex];
     418        if (data.m_type == ConsoleType)
     419        {
     420            console.CreateSharedFolder(data.m_strName, data.m_strHostPath, data.m_fWritable, data.m_fAutoMount);
     421            if (!console.isOk())
     422            {
     423                // TODO: Fix problem reporter!
     424                //vboxProblem().cannotCreateSharedFolder(this, console, data.m_strName, data.m_strHostPath);
     425            }
     426        }
     427    }
    324428}
    325429
     
    357461{
    358462    /* Invoke Add-Box Dialog */
    359     VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::AddType, mDialogType & ConsoleType, usedList (true), this);
     463    VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::AddType, m_type == ConsoleType, usedList (true), this);
    360464    if (dlg.exec() == QDialog::Accepted)
    361465    {
     
    366470        Assert (!name.isEmpty() && !path.isEmpty());
    367471        /* Searching root for the new listview item */
    368         SFTreeViewItem *root = searchRoot (isPermanent);
    369         Assert (root);
     472        SFTreeViewItem *pRoot = root(isPermanent ? MachineType : ConsoleType);
     473        Assert (pRoot);
    370474        /* Appending a new listview item to the root */
    371475        QStringList fields;
    372476        fields << name /* name */ << path /* path */
    373477               << (dlg.isAutoMounted() ? mTrYes : "" /* auto mount? */)
    374                << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */)
    375                << "edited" /* mark item as edited */;
    376         SFTreeViewItem *item = new SFTreeViewItem (root, fields, SFTreeViewItem::EllipsisFile);
     478               << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */);
     479        SFTreeViewItem *item = new SFTreeViewItem (pRoot, fields, SFTreeViewItem::EllipsisFile);
    377480        mTwFolders->sortItems (0, Qt::AscendingOrder);
    378481        mTwFolders->scrollToItem (item);
     
    396499
    397500    /* Invoke Edit-Box Dialog */
    398     VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::EditType, mDialogType & ConsoleType, usedList (false), this);
     501    VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::EditType, m_type == ConsoleType, usedList (false), this);
    399502    dlg.setPath (item->getText (1));
    400503    dlg.setName (item->getText (0));
    401     dlg.setPermanent ((SFDialogType)item->parent()->text (1).toInt() != ConsoleType);
     504    dlg.setPermanent ((UISharedFolderType)item->parent()->text (1).toInt() != ConsoleType);
    402505    dlg.setAutoMount (item->getText (2) == mTrYes);
    403506    dlg.setWriteable (item->getText (3) == mTrFull);
     
    410513        Assert (!name.isEmpty() && !path.isEmpty());
    411514        /* Searching new root for the selected listview item */
    412         SFTreeViewItem *root = searchRoot (isPermanent);
    413         Assert (root);
     515        SFTreeViewItem *pRoot = root(isPermanent ? MachineType : ConsoleType);
     516        Assert (pRoot);
    414517        /* Updating an edited listview item */
    415518        QStringList fields;
    416519        fields << name /* name */ << path /* path */
    417520               << (dlg.isAutoMounted() ? mTrYes : "" /* auto mount? */)
    418                << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */)
    419                << "edited" /* mark item as edited */;
     521               << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */);
    420522        item->updateText (fields);
    421523        mTwFolders->sortItems (0, Qt::AscendingOrder);
    422         if (item->parent() != root)
     524        if (item->parent() != pRoot)
    423525        {
    424526            /* Move the selected item into new location */
    425527            item->parent()->takeChild (item->parent()->indexOfChild (item));
    426             root->insertChild (root->childCount(), item);
     528            pRoot->insertChild (pRoot->childCount(), item);
    427529            mTwFolders->scrollToItem (item);
    428530            mTwFolders->setCurrentItem (item);
     
    451553    QString key = !aCurrentItem ? QString::null : aCurrentItem->parent() ?
    452554                  aCurrentItem->parent()->text (1) : aCurrentItem->text (1);
    453     bool addEnabled = aCurrentItem && isEditable (key);
     555    bool addEnabled = aCurrentItem;
    454556    bool removeEnabled = addEnabled && aCurrentItem->parent();
    455557    mNewAction->setEnabled (addEnabled);
     
    460562void VBoxVMSettingsSF::processDoubleClick (QTreeWidgetItem *aItem)
    461563{
    462     bool editEnabled = aItem && aItem->parent() && isEditable (aItem->parent()->text (1));
     564    bool editEnabled = aItem && aItem->parent();
    463565    if (editEnabled)
    464566        edtTriggered();
     
    540642}
    541643
    542 void VBoxVMSettingsSF::createSharedFolder (const QString &aName, const QString &aPath,
    543                                            bool aWritable, bool aAutoMount, SFDialogType aType)
    544 {
    545     switch (aType)
    546     {
    547         case GlobalType:
    548         {
    549             /* This feature is not supported now */
    550             AssertMsgFailed (("Global shared folders are not supported now!\n"));
     644SFTreeViewItem* VBoxVMSettingsSF::root(UISharedFolderType type)
     645{
     646    /* Prepare empty item: */
     647    SFTreeViewItem *pRootItem = 0;
     648    /* Get top-level root item: */
     649    QTreeWidgetItem *pMainRootItem = mTwFolders->invisibleRootItem();
     650    /* Iterate other the all root items: */
     651    for (int iFolderTypeIndex = 0; iFolderTypeIndex < pMainRootItem->childCount(); ++iFolderTypeIndex)
     652    {
     653        /* Get iterated item: */
     654        QTreeWidgetItem *pIteratedItem = pMainRootItem->child(iFolderTypeIndex);
     655        /* If iterated item's type is what we are looking for: */
     656        if (pIteratedItem->text(1).toInt() == type)
     657        {
     658            /* Remember the item: */
     659            pRootItem = static_cast<SFTreeViewItem*>(pIteratedItem);
     660            /* And break further search: */
    551661            break;
    552662        }
    553         case MachineType:
    554         {
    555             Assert (!mMachine.isNull());
    556             mMachine.CreateSharedFolder (aName, aPath, aWritable, aAutoMount);
    557             if (!mMachine.isOk())
    558                 vboxProblem().cannotCreateSharedFolder (this, mMachine, aName, aPath);
    559             break;
    560         }
    561         case ConsoleType:
    562         {
    563             Assert (!mConsole.isNull());
    564             mConsole.CreateSharedFolder (aName, aPath, aWritable, aAutoMount);
    565             if (!mConsole.isOk())
    566                 vboxProblem().cannotCreateSharedFolder (this, mConsole, aName, aPath);
    567             break;
    568         }
    569         default:
    570         {
    571             AssertMsgFailed (("Incorrect shared folder type\n"));
    572         }
    573     }
    574 }
    575 
    576 void VBoxVMSettingsSF::removeSharedFolder (const QString &aName, const QString &aPath, SFDialogType aType)
    577 {
    578     switch (aType)
    579     {
    580         case GlobalType:
    581         {
    582             /* This feature is not supported now */
    583             AssertMsgFailed (("Global shared folders are not supported now!\n"));
    584             break;
    585         }
    586         case MachineType:
    587         {
    588             Assert (!mMachine.isNull());
    589             mMachine.RemoveSharedFolder (aName);
    590             if (!mMachine.isOk())
    591                 vboxProblem().cannotRemoveSharedFolder (this, mMachine, aName, aPath);
    592             break;
    593         }
    594         case ConsoleType:
    595         {
    596             Assert (!mConsole.isNull());
    597             mConsole.RemoveSharedFolder (aName);
    598             if (!mConsole.isOk())
    599                 vboxProblem().cannotRemoveSharedFolder (this, mConsole, aName, aPath);
    600             break;
    601         }
    602         default:
    603         {
    604             AssertMsgFailed (("Incorrect shared folder type\n"));
    605         }
    606     }
    607 }
    608 
    609 void VBoxVMSettingsSF::getFrom (const CSharedFolderVector &aVec, SFTreeViewItem *aRoot)
    610 {
    611     for (int i = 0; i < aVec.size(); ++ i)
    612     {
    613         CSharedFolder sf = aVec [i];
     663    }
     664    /* If root item we are looking for still not found: */
     665    if (!pRootItem)
     666    {
     667        /* Preparing fields: */
    614668        QStringList fields;
    615         fields << sf.GetName() /* name */ << sf.GetHostPath() /* path */
    616                << (sf.GetAutoMount() ? mTrYes : "") /* auto mount? */
    617                << (sf.GetWritable() ? mTrFull : mTrReadOnly) /* writable? */
    618                << "not edited" /* initially not edited */;
    619         new SFTreeViewItem (aRoot, fields, SFTreeViewItem::EllipsisFile);
    620     }
    621     aRoot->setExpanded (true);
    622     mTwFolders->sortItems (0, Qt::AscendingOrder);
    623     mTwFolders->setCurrentItem (aRoot->childCount() ? aRoot->child (0) : aRoot);
    624     processCurrentChanged (aRoot->childCount() ? aRoot->child (0) : aRoot);
    625 }
    626 
    627 void VBoxVMSettingsSF::putBackTo (CSharedFolderVector &aVec, SFTreeViewItem *aRoot)
    628 {
    629     Assert (!aRoot->text (1).isNull());
    630     SFDialogType type = (SFDialogType) aRoot->text (1).toInt();
    631 
    632     /** @todo Use enums rather than numbers for the text fields (like  item->getText (4)). */
    633 
    634     /* Delete all changed folders from vm */
    635     for (int idx = 0; idx < aVec.size(); ++ idx)
    636     {
    637         CSharedFolder sf = aVec [idx];
    638 
    639         /* Iterate through this root's children */
    640         int i = 0;
    641         for (; i < aRoot->childCount(); ++ i)
    642         {
    643             SFTreeViewItem *item = aRoot->child (i);
    644             if (item->getText (0) == sf.GetName() && item->getText (4) == "not edited")
     669        /* Depending on folder type: */
     670        switch (type)
     671        {
     672            case MachineType:
     673                fields << tr(" Machine Folders") << QString::number(MachineType);
    645674                break;
    646         }
    647 
    648         if (i == aRoot->childCount())
    649             removeSharedFolder (sf.GetName(), sf.GetHostPath(), type);
    650     }
    651 
    652     /* Save all edited tree widget items as folders */
    653     for (int i = 0; i < aRoot->childCount(); ++ i)
    654     {
    655         SFTreeViewItem *item = aRoot->child (i);
    656 
    657         if (!item->getText (0).isNull() && !item->getText (1).isNull() && item->getText (4) == "edited")
    658             createSharedFolder (item->getText (0), item->getText (1),
    659                                 item->getText (3) == mTrFull ? true : false, item->getText (2) == mTrYes ? true : false,
    660                                 type);
    661     }
    662 }
    663 
    664 SFTreeViewItem* VBoxVMSettingsSF::searchRoot (bool aIsPermanent, SFDialogType aType)
    665 {
    666     QString type = aType != WrongType ? QString::number (aType) : !aIsPermanent ? QString::number (ConsoleType) :
    667                    mDialogType & MachineType ? QString::number (MachineType) : QString::number (GlobalType);
    668     QTreeWidgetItem *mainRoot = mTwFolders->invisibleRootItem();
    669 
    670     int i = 0;
    671     for (; i < mainRoot->childCount(); ++ i)
    672     {
    673         if (mainRoot->child (i)->text (1) == type)
    674             break;
    675     }
    676 
    677     Assert (i < mainRoot->childCount());
    678     return i < mainRoot->childCount() && mainRoot->child (i)->type() == SFTreeViewItem::SFTreeViewItemType ?
    679            static_cast <SFTreeViewItem*> (mainRoot->child (i)) : 0;
    680 }
    681 
    682 bool VBoxVMSettingsSF::isEditable (const QString &aKey)
    683 {
    684     /* mDialogType should be correct */
    685     Assert (mDialogType);
    686 
    687     SFDialogType type = (SFDialogType) aKey.toInt();
    688     if (!type) return false;
    689     return mDialogType & type;
     675            case ConsoleType:
     676                fields << tr(" Transient Folders") << QString::number(ConsoleType);
     677                break;
     678            default:
     679                break;
     680        }
     681        /* Creating root: */
     682        pRootItem = new SFTreeViewItem(mTwFolders, fields, SFTreeViewItem::EllipsisEnd);
     683        /* We should show it (its not?): */
     684        pRootItem->setHidden(false);
     685        /* Expand it: */
     686        pRootItem->setExpanded(true);
     687    }
     688    /* Return root item: */
     689    return pRootItem;
    690690}
    691691
     
    701701        {
    702702            SFTreeViewItem *item = static_cast <SFTreeViewItem*> (*it);
    703             SFDialogType type = (SFDialogType) item->parent()->text (1).toInt();
     703            UISharedFolderType type = (UISharedFolderType) item->parent()->text (1).toInt();
    704704            list << qMakePair (item->getText (0), type);
    705705        }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSF.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2008-2009 Oracle Corporation
     8 * Copyright (C) 2008-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2727class SFTreeViewItem;
    2828
    29 enum SFDialogType
     29enum UISharedFolderType
    3030{
    3131    WrongType   = 0x00,
    32     GlobalType  = 0x01,
    33     MachineType = 0x02,
    34     ConsoleType = 0x04
     32    MachineType = 0x01,
     33    ConsoleType = 0x02
    3534};
    36 typedef QPair <QString, SFDialogType> SFolderName;
     35typedef QPair <QString, UISharedFolderType> SFolderName;
    3736typedef QList <SFolderName> SFoldersNameList;
    3837
    39 class VBoxVMSettingsSF : public UISettingsPage, public Ui::VBoxVMSettingsSF
     38/* Machine settings / Shared Folders page / Folder data: */
     39struct UISharedFolderData
     40{
     41    UISharedFolderType m_type;
     42    QString m_strName;
     43    QString m_strHostPath;
     44    bool m_fAutoMount;
     45    bool m_fWritable;
     46    bool m_fEdited;
     47};
     48
     49/* Machine settings / Shared Folders page / Cache: */
     50struct UISettingsCacheMachineSFolders
     51{
     52    QList<UISharedFolderData> m_items;
     53};
     54
     55class VBoxVMSettingsSF : public UISettingsPageMachine,
     56                         public Ui::VBoxVMSettingsSF
    4057{
    4158    Q_OBJECT;
     
    4360public:
    4461
    45     VBoxVMSettingsSF (int aType = WrongType, QWidget *aParent = 0);
     62    VBoxVMSettingsSF();
    4663
    47     void getFromGlobal();
    48     void getFromMachine (const CMachine &aMachine);
    49     void getFromConsole (const CConsole &aConsole);
    50 
    51     void putBackToGlobal();
    52     void putBackToMachine();
    53     void putBackToConsole();
    54 
    55     int dialogType() const;
     64    void loadDirectlyFrom(const CConsole &console);
     65    void saveDirectlyTo(CConsole &console);
    5666
    5767protected:
    5868
    59     void getFrom (const CMachine &aMachine);
    60     void putBackTo();
     69    /* Load data to cashe from corresponding external object(s),
     70     * this task COULD be performed in other than GUI thread: */
     71    void loadToCacheFrom(QVariant &data);
     72    void loadToCacheFromMachine(const CMachine &machine);
     73    void loadToCacheFromConsole(const CConsole &console);
     74    void loadToCacheFromVector(const CSharedFolderVector &vector, UISharedFolderType type);
     75    /* Load data to corresponding widgets from cache,
     76     * this task SHOULD be performed in GUI thread only: */
     77    void getFromCache();
     78
     79    /* Save data from corresponding widgets to cache,
     80     * this task SHOULD be performed in GUI thread only: */
     81    void putToCache();
     82    /* Save data from cache to corresponding external object(s),
     83     * this task COULD be performed in other than GUI thread: */
     84    void saveFromCacheTo(QVariant &data);
     85    void saveFromCacheToMachine(CMachine &machine);
     86    void saveFromCacheToConsole(CConsole &console);
    6187
    6288    void setOrderAfter (QWidget *aWidget);
     
    83109    void showEvent (QShowEvent *aEvent);
    84110
    85     void createSharedFolder (const QString &aName, const QString &aPath, bool aWritable, bool aAutoMount, SFDialogType aType);
    86     void removeSharedFolder (const QString &aName, const QString &aPath, SFDialogType aType);
    87 
    88     void getFrom (const CSharedFolderVector &aVec, SFTreeViewItem *aItem);
    89     void putBackTo (CSharedFolderVector &aVec, SFTreeViewItem *aItem);
    90 
    91     SFTreeViewItem* searchRoot (bool aIsPermanent, SFDialogType aType = WrongType);
    92     bool isEditable (const QString &aKey);
     111    SFTreeViewItem* root(UISharedFolderType type);
    93112    SFoldersNameList usedList (bool aIncludeSelected);
    94113
    95     int       mDialogType;
     114    UISharedFolderType m_type;
     115
    96116    QAction  *mNewAction;
    97117    QAction  *mEdtAction;
    98118    QAction  *mDelAction;
    99119    bool      mIsListViewChanged;
    100     CMachine  mMachine;
    101     CConsole  mConsole;
    102120    QString   mTrFull;
    103121    QString   mTrReadOnly;
    104122    QString   mTrYes;
     123
     124    /* Cache: */
     125    UISettingsCacheMachineSFolders m_cache;
    105126};
    106127
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSFDetails.cpp

    r31002 r33631  
    77
    88/*
    9  * Copyright (C) 2010 Oracle Corporation
     9 * Copyright (C) 2008-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    140140void VBoxVMSettingsSFDetails::validate()
    141141{
    142     SFDialogType resultType =
    143         mCbPermanent && !mCbPermanent->isChecked() ? ConsoleType :
    144         mType & MachineType ? MachineType : GlobalType;
     142    UISharedFolderType resultType =
     143        mUsePermanent && !mCbPermanent->isChecked() ? ConsoleType : MachineType;
    145144    SFolderName pair = qMakePair (mLeName->text(), resultType);
    146145
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSFDetails.ui

    r31002 r33631  
    33 VBox frontends: Qt4 GUI ("VirtualBox"):
    44
    5      Copyright (C) 2008 Oracle Corporation
     5     Copyright (C) 2008-2010 Oracle Corporation
    66
    77     This file is part of VirtualBox Open Source Edition (OSE), as
     
    7979   <item row="4" column="1" >
    8080    <widget class="QCheckBox" name="mCbPermanent" >
     81     <property name="toolTip" >
     82      <string>If checked, this shared folder will be permanent.</string>
     83     </property>
    8184     <property name="text" >
    8285      <string>&amp;Make Permanent</string>
     
    8487    </widget>
    8588   </item>
    86    <item row="4" column="1" >
     89   <item row="5" column="1" >
    8790    <spacer>
    8891     <property name="orientation" >
     
    97100    </spacer>
    98101   </item>
    99    <item row="5" column="0" colspan="2" >
     102   <item row="6" column="0" colspan="2" >
    100103    <widget class="QIDialogButtonBox" name="mButtonBox" >
    101104     <property name="standardButtons" >
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSerial.cpp

    r32814 r33631  
    2929    : QIWithRetranslateUI<QWidget> (0)
    3030    , mValidator (0)
     31    , m_iSlot(-1)
    3132{
    3233    /* Apply UI decorations */
     
    6465}
    6566
    66 void VBoxVMSettingsSerial::getFromPort (const CSerialPort &aPort)
    67 {
    68     mPort = aPort;
    69 
    70     mGbSerial->setChecked (mPort.GetEnabled());
    71     ulong IRQ = mPort.GetIRQ();
    72     ulong IOBase = mPort.GetIOBase();
    73     mCbNumber->setCurrentIndex (mCbNumber->
    74         findText (vboxGlobal().toCOMPortName (IRQ, IOBase)));
    75     mLeIRQ->setText (QString::number (IRQ));
    76     mLeIOPort->setText ("0x" + QString::number (IOBase, 16).toUpper());
    77     mCbMode->setCurrentIndex (mCbMode->
    78         findText (vboxGlobal().toString (mPort.GetHostMode())));
    79     mCbPipe->setChecked (mPort.GetServer());
    80     mLePath->setText (mPort.GetPath());
     67void VBoxVMSettingsSerial::fetchPortData(const UISerialPortData &data)
     68{
     69    /* Load port slot number: */
     70    m_iSlot = data.m_iSlot;
     71
     72    /* Fetch port data: */
     73    mGbSerial->setChecked(data.m_fPortEnabled);
     74    mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(data.m_uIRQ, data.m_uIOBase)));
     75    mLeIRQ->setText(QString::number(data.m_uIRQ));
     76    mLeIOPort->setText("0x" + QString::number(data.m_uIOBase, 16).toUpper());
     77    mCbMode->setCurrentIndex(mCbMode->findText(vboxGlobal().toString(data.m_hostMode)));
     78    mCbPipe->setChecked(data.m_fServer);
     79    mLePath->setText(data.m_strPath);
    8180
    8281    /* Ensure everything is up-to-date */
    83     mGbSerialToggled (mGbSerial->isChecked());
    84 }
    85 
    86 void VBoxVMSettingsSerial::putBackToPort()
    87 {
    88     mPort.SetEnabled (mGbSerial->isChecked());
    89     mPort.SetIRQ (mLeIRQ->text().toULong (NULL, 0));
    90     mPort.SetIOBase (mLeIOPort->text().toULong (NULL, 0));
    91     mPort.SetServer (mCbPipe->isChecked());
    92     mPort.SetPath (QDir::toNativeSeparators (mLePath->text()));
    93     /* This *must* be last. The host mode will be changed to disconnected if
    94      * some of the necessary settings above will not meet the requirements for
    95      * the selected mode. */
    96     mPort.SetHostMode (vboxGlobal().toPortMode (mCbMode->currentText()));
     82    mGbSerialToggled(mGbSerial->isChecked());
     83}
     84
     85void VBoxVMSettingsSerial::uploadPortData(UISerialPortData &data)
     86{
     87    /* Upload port data: */
     88    data.m_fPortEnabled = mGbSerial->isChecked();
     89    data.m_uIRQ = mLeIRQ->text().toULong(NULL, 0);
     90    data.m_uIOBase = mLeIOPort->text().toULong (NULL, 0);
     91    data.m_fServer = mCbPipe->isChecked();
     92    data.m_hostMode = vboxGlobal().toPortMode(mCbMode->currentText());
     93    data.m_strPath = QDir::toNativeSeparators(mLePath->text());
    9794}
    9895
     
    124121QString VBoxVMSettingsSerial::pageTitle() const
    125122{
    126     QString pageTitle;
    127     if (!mPort.isNull())
    128     {
    129         pageTitle = QString (tr ("Port %1", "serial ports"))
    130             .arg (QString ("&%1").arg (mPort.GetSlot() + 1));
    131     }
    132     return pageTitle;
     123    return QString(tr("Port %1", "serial ports")).arg(QString("&%1").arg(m_iSlot + 1));
    133124}
    134125
     
    202193}
    203194
    204 void VBoxVMSettingsSerialPage::getFrom (const CMachine &aMachine)
    205 {
    206     Assert (m_pFirstWidget);
    207     setTabOrder (m_pFirstWidget, mTabWidget->focusProxy());
    208     QWidget *lastFocusWidget = mTabWidget->focusProxy();
    209 
    210     /* Tab pages loading */
    211     ulong count = vboxGlobal().virtualBox().
    212                   GetSystemProperties().GetSerialPortCount();
    213     for (ulong slot = 0; slot < count; ++ slot)
    214     {
    215         CSerialPort port = aMachine.GetSerialPort (slot);
    216         VBoxVMSettingsSerial *page = new VBoxVMSettingsSerial();
    217         page->getFromPort (port);
    218         mTabWidget->addTab (page, page->pageTitle());
    219         Assert (mValidator);
    220         page->setValidator (mValidator);
    221         lastFocusWidget = page->setOrderAfter (lastFocusWidget);
    222     }
    223 }
    224 
    225 void VBoxVMSettingsSerialPage::putBackTo()
    226 {
    227     for (int index = 0; index < mTabWidget->count(); ++ index)
    228     {
    229         VBoxVMSettingsSerial *page =
    230             (VBoxVMSettingsSerial*) mTabWidget->widget (index);
    231         Assert (page);
    232         page->putBackToPort();
    233     }
     195/* Load data to cashe from corresponding external object(s),
     196 * this task COULD be performed in other than GUI thread: */
     197void VBoxVMSettingsSerialPage::loadToCacheFrom(QVariant &data)
     198{
     199    /* Fetch data to machine: */
     200    UISettingsPageMachine::fetchData(data);
     201
     202    /* Load port data: */
     203    ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetSerialPortCount();
     204    for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
     205    {
     206        /* Get port: */
     207        const CSerialPort &port = m_machine.GetSerialPort(uSlot);
     208
     209        /* Prepare port's data container: */
     210        UISerialPortData data;
     211
     212        /* Load options: */
     213        data.m_iSlot = uSlot;
     214        data.m_fPortEnabled = port.GetEnabled();
     215        data.m_uIRQ = port.GetIRQ();
     216        data.m_uIOBase = port.GetIOBase();
     217        data.m_hostMode = port.GetHostMode();
     218        data.m_fServer = port.GetServer();
     219        data.m_strPath = port.GetPath();
     220
     221        /* Append adapter's data container: */
     222        m_cache.m_items << data;
     223    }
     224
     225    /* Upload machine to data: */
     226    UISettingsPageMachine::uploadData(data);
     227}
     228
     229/* Load data to corresponding widgets from cache,
     230 * this task SHOULD be performed in GUI thread only: */
     231void VBoxVMSettingsSerialPage::getFromCache()
     232{
     233    Assert(m_pFirstWidget);
     234    setTabOrder(m_pFirstWidget, mTabWidget->focusProxy());
     235    QWidget *pLastFocusWidget = mTabWidget->focusProxy();
     236
     237    /* Apply internal variables data to QWidget(s): */
     238    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     239    {
     240        /* Creating port's page: */
     241        VBoxVMSettingsSerial *pPage = new VBoxVMSettingsSerial;
     242
     243        /* Loading port's data into page: */
     244        pPage->fetchPortData(m_cache.m_items[iSlot]);
     245
     246        /* Attach port's page to Tab Widget: */
     247        mTabWidget->addTab(pPage, pPage->pageTitle());
     248
     249        /* Setup page validation: */
     250        pPage->setValidator(mValidator);
     251
     252        /* Setup tab order: */
     253        pLastFocusWidget = pPage->setOrderAfter(pLastFocusWidget);
     254    }
     255
     256    /* Applying language settings: */
     257    retranslateUi();
     258
     259    /* Revalidate if possible: */
     260    if (mValidator) mValidator->revalidate();
     261}
     262
     263/* Save data from corresponding widgets to cache,
     264 * this task SHOULD be performed in GUI thread only: */
     265void VBoxVMSettingsSerialPage::putToCache()
     266{
     267    /* Gather internal variables data from QWidget(s): */
     268    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     269    {
     270        /* Getting adapter's page: */
     271        VBoxVMSettingsSerial *pPage = qobject_cast<VBoxVMSettingsSerial*>(mTabWidget->widget(iSlot));
     272
     273        /* Loading Adapter's data from page: */
     274        pPage->uploadPortData(m_cache.m_items[iSlot]);
     275    }
     276}
     277
     278/* Save data from cache to corresponding external object(s),
     279 * this task COULD be performed in other than GUI thread: */
     280void VBoxVMSettingsSerialPage::saveFromCacheTo(QVariant &data)
     281{
     282    /* Fetch data to machine: */
     283    UISettingsPageMachine::fetchData(data);
     284
     285    /* Gather corresponding values from internal variables: */
     286    for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     287    {
     288        /* Get adapter: */
     289        CSerialPort &port = m_machine.GetSerialPort(iSlot);
     290
     291        /* Get cached data for this slot: */
     292        const UISerialPortData &data = m_cache.m_items[iSlot];
     293
     294        /* Save options: */
     295        port.SetEnabled(data.m_fPortEnabled);
     296        port.SetIRQ(data.m_uIRQ);
     297        port.SetIOBase(data.m_uIOBase);
     298        port.SetServer(data.m_fServer);
     299        port.SetPath(data.m_strPath);
     300        /* This *must* be last. The host mode will be changed to disconnected if
     301         * some of the necessary settings above will not meet the requirements for
     302         * the selected mode. */
     303        port.SetHostMode(data.m_hostMode);
     304    }
     305
     306    /* Upload machine to data: */
     307    UISettingsPageMachine::uploadData(data);
    234308}
    235309
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSerial.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626class QITabWidget;
    2727
     28/* Machine settings / Network page / Port data: */
     29struct UISerialPortData
     30{
     31    int m_iSlot;
     32    bool m_fPortEnabled;
     33    ulong m_uIRQ;
     34    ulong m_uIOBase;
     35    KPortMode m_hostMode;
     36    bool m_fServer;
     37    QString m_strPath;
     38};
     39
     40/* Machine settings / Serial page / Cache: */
     41struct UISettingsCacheMachineSerial
     42{
     43    QList<UISerialPortData> m_items;
     44};
     45
    2846class VBoxVMSettingsSerial : public QIWithRetranslateUI<QWidget>,
    2947                             public Ui::VBoxVMSettingsSerial
     
    3553    VBoxVMSettingsSerial();
    3654
    37     void getFromPort (const CSerialPort &aPort);
    38     void putBackToPort();
     55    void fetchPortData(const UISerialPortData &data);
     56    void uploadPortData(UISerialPortData &data);
    3957
    4058    void setValidator (QIWidgetValidator *aVal);
     
    5876
    5977    QIWidgetValidator *mValidator;
    60     CSerialPort mPort;
     78    int m_iSlot;
    6179};
    6280
    63 class VBoxVMSettingsSerialPage : public UISettingsPage
     81/* Machine settings / Serial page: */
     82class VBoxVMSettingsSerialPage : public UISettingsPageMachine
    6483{
    6584    Q_OBJECT;
     
    7190protected:
    7291
    73     void getFrom (const CMachine &aMachine);
    74     void putBackTo();
     92    /* Load data to cashe from corresponding external object(s),
     93     * this task COULD be performed in other than GUI thread: */
     94    void loadToCacheFrom(QVariant &data);
     95    /* Load data to corresponding widgets from cache,
     96     * this task SHOULD be performed in GUI thread only: */
     97    void getFromCache();
     98
     99    /* Save data from corresponding widgets to cache,
     100     * this task SHOULD be performed in GUI thread only: */
     101    void putToCache();
     102    /* Save data from cache to corresponding external object(s),
     103     * this task COULD be performed in other than GUI thread: */
     104    void saveFromCacheTo(QVariant &data);
    75105
    76106    void setValidator (QIWidgetValidator *aVal);
     
    83113    QIWidgetValidator *mValidator;
    84114    QITabWidget *mTabWidget;
     115
     116    /* Cache: */
     117    UISettingsCacheMachineSerial m_cache;
    85118};
    86119
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSystem.cpp

    r32510 r33631  
    3636
    3737    /* Setup constants */
    38     CSystemProperties sys = vboxGlobal().virtualBox().GetSystemProperties();
     38    CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties();
    3939    uint hostCPUs = vboxGlobal().virtualBox().GetHost().GetProcessorCount();
    40     mMinGuestCPU = sys.GetMinGuestCPUCount();
    41     mMaxGuestCPU = RT_MIN (2 * hostCPUs, sys.GetMaxGuestCPUCount());
     40    mMinGuestCPU = properties.GetMinGuestCPUCount();
     41    mMaxGuestCPU = RT_MIN (2 * hostCPUs, properties.GetMaxGuestCPUCount());
     42
     43    /* Populate possible boot items list.
     44     * Currently, it seems, we are supporting only 4 possible boot device types:
     45     * 1. Floppy, 2. DVD-ROM, 3. Hard Disk, 4. Network.
     46     * But maximum boot devices count supported by machine
     47     * should be retreived through the ISystemProperties getter.
     48     * Moreover, possible boot device types are not listed in some separate Main vector,
     49     * so we should get them (randomely?) from the list of all device types.
     50     * Until there will be separate Main getter for list of supported boot device types,
     51     * this list will be hard-coded here... */
     52    int iPossibleBootListSize = qMin((ulong)4, properties.GetMaxBootPosition());
     53    for (int iBootPosition = 1; iBootPosition <= iPossibleBootListSize; ++iBootPosition)
     54    {
     55        switch (iBootPosition)
     56        {
     57            case 1:
     58                m_possibleBootItems << KDeviceType_Floppy;
     59                break;
     60            case 2:
     61                m_possibleBootItems << KDeviceType_DVD;
     62                break;
     63            case 3:
     64                m_possibleBootItems << KDeviceType_HardDisk;
     65                break;
     66            case 4:
     67                m_possibleBootItems << KDeviceType_Network;
     68                break;
     69            default:
     70                break;
     71        }
     72    }
    4273
    4374    /* Setup validators */
     
    101132    /* Ensure mLeMemory value and validation is updated */
    102133    valueChangedCPU (mSlCPU->value());
     134    /* Populate chipset combo: */
     135    mCbChipset->insertItem(0, vboxGlobal().toString(KChipsetType_PIIX3), QVariant(KChipsetType_PIIX3));
     136    mCbChipset->insertItem(1, vboxGlobal().toString(KChipsetType_ICH9), QVariant(KChipsetType_ICH9));
    103137
    104138    /* Install global event filter */
     
    124158}
    125159
    126 void VBoxVMSettingsSystem::getFrom (const CMachine &aMachine)
    127 {
    128     mMachine = aMachine;
    129     CBIOSSettings biosSettings = mMachine.GetBIOSSettings();
    130 
    131     /* RAM size */
    132     mSlMemory->setValue (aMachine.GetMemorySize());
    133 
    134     /* Boot-order */
    135     {
    136         mTwBootOrder->clear();
    137         /* Load boot-items of current VM */
    138         QStringList uniqueList;
    139         for (int i = 1; i <= 4; ++ i)
     160/* Load data to cashe from corresponding external object(s),
     161 * this task COULD be performed in other than GUI thread: */
     162void VBoxVMSettingsSystem::loadToCacheFrom(QVariant &data)
     163{
     164    /* Fetch data to machine: */
     165    UISettingsPageMachine::fetchData(data);
     166
     167    /* Fill internal variables with corresponding values: */
     168    /* Load boot-items of current VM: */
     169    QList<KDeviceType> usedBootItems;
     170    for (int i = 1; i <= m_possibleBootItems.size(); ++i)
     171    {
     172        KDeviceType type = m_machine.GetBootOrder(i);
     173        if (type != KDeviceType_Null)
    140174        {
    141             KDeviceType type = mMachine.GetBootOrder (i);
    142             if (type != KDeviceType_Null)
    143             {
    144                 QString name = vboxGlobal().toString (type);
    145                 QTreeWidgetItem *item =
    146                     new QTreeWidgetItem (mTwBootOrder, QStringList (name));
    147                 QVariant vtype (type);
    148                 item->setData (0, ITEM_TYPE_ROLE, vtype);
    149                 item->setCheckState (0, Qt::Checked);
    150                 uniqueList << name;
    151             }
     175            usedBootItems << type;
     176            UIBootItemData data;
     177            data.m_type = type;
     178            data.m_fEnabled = true;
     179            m_cache.m_bootItems << data;
    152180        }
    153         /* Load other unique boot-items */
    154         for (int i = KDeviceType_Floppy; i < KDeviceType_USB; ++ i)
     181    }
     182    /* Load other unique boot-items: */
     183    for (int i = 0; i < m_possibleBootItems.size(); ++i)
     184    {
     185        KDeviceType type = m_possibleBootItems[i];
     186        if (!usedBootItems.contains(type))
    155187        {
    156             QString name = vboxGlobal().toString ((KDeviceType) i);
    157             if (!uniqueList.contains (name))
    158             {
    159                 QTreeWidgetItem *item =
    160                     new QTreeWidgetItem (mTwBootOrder, QStringList (name));
    161                 item->setData (0, ITEM_TYPE_ROLE, i);
    162                 item->setCheckState (0, Qt::Unchecked);
    163                 uniqueList << name;
    164             }
     188            UIBootItemData data;
     189            data.m_type = type;
     190            data.m_fEnabled = false;
     191            m_cache.m_bootItems << data;
    165192        }
    166         adjustBootOrderTWSize();
    167     }
    168 
    169     /* IO APIC */
    170     mCbApic->setChecked (biosSettings.GetIOAPICEnabled());
    171 
    172     /* EFI */
    173     mCbEFI->setChecked (mMachine.GetFirmwareType() >= KFirmwareType_EFI && mMachine.GetFirmwareType() <= KFirmwareType_EFIDUAL);
    174 
    175     /* RTC */
    176     bool rtcUseUTC = mMachine.GetRTCUseUTC ();
    177     mCbTCUseUTC->setChecked (rtcUseUTC);
    178 
    179     /* USB tablet */
    180     KPointingHidType pointingHid = mMachine.GetPointingHidType ();
    181     mCbUseAbsHID->setChecked (pointingHid == KPointingHidType_USBTablet);
    182 
    183     /* CPU count */
    184     bool fVTxAMDVSupported = vboxGlobal().virtualBox().GetHost()
    185                              .GetProcessorFeature (KProcessorFeature_HWVirtEx);
    186     mSlCPU->setEnabled (fVTxAMDVSupported);
    187     mLeCPU->setEnabled (fVTxAMDVSupported);
    188     mSlCPU->setValue (fVTxAMDVSupported ? aMachine.GetCPUCount() : 1);
    189 
    190     /* PAE/NX */
    191     bool fPAESupported = vboxGlobal().virtualBox().GetHost()
    192                          .GetProcessorFeature (KProcessorFeature_PAE);
    193     mCbPae->setEnabled (fPAESupported);
    194     mCbPae->setChecked (aMachine.GetCPUProperty(KCPUPropertyType_PAE));
    195 
    196     /* VT-x/AMD-V page */
    197     if (!fVTxAMDVSupported)
     193    }
     194    m_cache.m_fPFHwVirtExSupported = vboxGlobal().virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_HWVirtEx);
     195    m_cache.m_fPFPAESupported = vboxGlobal().virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_PAE);
     196    m_cache.m_fIoApicEnabled = m_machine.GetBIOSSettings().GetIOAPICEnabled();
     197    m_cache.m_fEFIEnabled = m_machine.GetFirmwareType() >= KFirmwareType_EFI && m_machine.GetFirmwareType() <= KFirmwareType_EFIDUAL;
     198    m_cache.m_fUTCEnabled = m_machine.GetRTCUseUTC();
     199    m_cache.m_fUseAbsHID = m_machine.GetPointingHidType() == KPointingHidType_USBTablet;
     200    m_cache.m_fPAEEnabled = m_machine.GetCPUProperty(KCPUPropertyType_PAE);
     201    m_cache.m_fHwVirtExEnabled = m_machine.GetHWVirtExProperty(KHWVirtExPropertyType_Enabled);
     202    m_cache.m_fNestedPagingEnabled = m_machine.GetHWVirtExProperty(KHWVirtExPropertyType_NestedPaging);
     203    m_cache.m_iRAMSize = m_machine.GetMemorySize();
     204    m_cache.m_cCPUCount = m_cache.m_fPFHwVirtExSupported ? m_machine.GetCPUCount() : 1;
     205    m_cache.m_chipsetType = m_machine.GetChipsetType();
     206
     207    /* Upload machine to data: */
     208    UISettingsPageMachine::uploadData(data);
     209}
     210
     211/* Load data to corresponding widgets from cache,
     212 * this task SHOULD be performed in GUI thread only: */
     213void VBoxVMSettingsSystem::getFromCache()
     214{
     215    /* Apply internal variables data to QWidget(s): */
     216    for (int i = 0; i < m_cache.m_bootItems.size(); ++i)
     217    {
     218        UIBootItemData data = m_cache.m_bootItems[i];
     219        QString name = vboxGlobal().toString(data.m_type);
     220        QTreeWidgetItem *pItem = new QTreeWidgetItem(QStringList(name));
     221        pItem->setData(0, ITEM_TYPE_ROLE, QVariant(data.m_type));
     222        pItem->setCheckState(0, data.m_fEnabled ? Qt::Checked : Qt::Unchecked);
     223        mTwBootOrder->addTopLevelItem(pItem);
     224    }
     225    mCbApic->setChecked(m_cache.m_fIoApicEnabled);
     226    mCbEFI->setChecked(m_cache.m_fEFIEnabled);
     227    mCbTCUseUTC->setChecked(m_cache.m_fUTCEnabled);
     228    mCbUseAbsHID->setChecked(m_cache.m_fUseAbsHID);
     229    mSlCPU->setEnabled(m_cache.m_fPFHwVirtExSupported);
     230    mLeCPU->setEnabled(m_cache.m_fPFHwVirtExSupported);
     231    mCbPae->setEnabled(m_cache.m_fPFPAESupported);
     232    mCbPae->setChecked(m_cache.m_fPAEEnabled);
     233    mCbVirt->setEnabled(m_cache.m_fPFHwVirtExSupported);
     234    mCbVirt->setChecked(m_cache.m_fHwVirtExEnabled);
     235    mCbNestedPaging->setEnabled(m_cache.m_fPFHwVirtExSupported && m_cache.m_fHwVirtExEnabled);
     236    mCbNestedPaging->setChecked(m_cache.m_fNestedPagingEnabled);
     237    mSlMemory->setValue(m_cache.m_iRAMSize);
     238    mSlCPU->setValue(m_cache.m_cCPUCount);
     239    int iChipsetPositionPos = mCbChipset->findData(m_cache.m_chipsetType);
     240    mCbChipset->setCurrentIndex(iChipsetPositionPos == -1 ? 0 : iChipsetPositionPos);
     241    adjustBootOrderTWSize();
     242    if (!m_cache.m_fPFHwVirtExSupported)
    198243        mTwSystem->removeTab(2);
    199244
    200     /* VT-x/AMD-V */
    201     mCbVirt->setEnabled (fVTxAMDVSupported);
    202     mCbVirt->setChecked (aMachine.GetHWVirtExProperty(KHWVirtExPropertyType_Enabled));
    203 
    204     /* Nested Paging */
    205     mCbNestedPaging->setEnabled (fVTxAMDVSupported &&
    206                                  aMachine.GetHWVirtExProperty(KHWVirtExPropertyType_Enabled));
    207     mCbNestedPaging->setChecked (aMachine.GetHWVirtExProperty(KHWVirtExPropertyType_NestedPaging));
    208 
    209     if (mValidator)
    210         mValidator->revalidate();
    211 }
    212 
    213 void VBoxVMSettingsSystem::putBackTo()
    214 {
    215     CBIOSSettings biosSettings = mMachine.GetBIOSSettings();
    216 
    217     /* RAM size */
    218     mMachine.SetMemorySize (mSlMemory->value());
    219 
    220     /* Boot order */
    221     {
    222         /* Search for checked items */
    223         int index = 1;
    224 
    225         for (int i = 0; i < mTwBootOrder->topLevelItemCount(); ++ i)
    226         {
    227             QTreeWidgetItem *item = mTwBootOrder->topLevelItem (i);
    228             if (item->checkState (0) == Qt::Checked)
    229             {
    230                 KDeviceType type = vboxGlobal().toDeviceType (item->text (0));
    231                 mMachine.SetBootOrder (index ++, type);
    232             }
    233         }
    234 
    235         /* Search for non-checked items */
    236         for (int i = 0; i < mTwBootOrder->topLevelItemCount(); ++ i)
    237         {
    238             QTreeWidgetItem *item = mTwBootOrder->topLevelItem (i);
    239             if (item->checkState (0) != Qt::Checked)
    240                 mMachine.SetBootOrder (index ++, KDeviceType_Null);
    241         }
    242     }
    243 
    244     /* IO APIC */
    245     biosSettings.SetIOAPICEnabled (mCbApic->isChecked() ||
    246                                    mSlCPU->value() > 1);
    247 
    248     /* EFI */
    249     mMachine.SetFirmwareType (mCbEFI->isChecked() ? KFirmwareType_EFI : KFirmwareType_BIOS);
    250 
    251     /* RTC */
    252     mMachine.SetRTCUseUTC (mCbTCUseUTC->isChecked());
    253 
    254     /* USB tablet */
    255     mMachine.SetPointingHidType (mCbUseAbsHID->isChecked() ? KPointingHidType_USBTablet : KPointingHidType_PS2Mouse );
    256 
    257     /* RAM size */
    258     mMachine.SetCPUCount (mSlCPU->value());
    259 
    260     /* PAE/NX */
    261     mMachine.SetCPUProperty(KCPUPropertyType_PAE, mCbPae->isChecked());
    262 
    263     /* VT-x/AMD-V */
    264     mMachine.SetHWVirtExProperty(KHWVirtExPropertyType_Enabled,
    265                                  mCbVirt->checkState() == Qt::Checked || mSlCPU->value() > 1);
    266 
    267     /* Nested Paging */
    268     mMachine.SetHWVirtExProperty(KHWVirtExPropertyType_NestedPaging, mCbNestedPaging->isChecked());
     245    /* Revalidate if possible: */
     246    if (mValidator) mValidator->revalidate();
     247}
     248
     249/* Save data from corresponding widgets to cache,
     250 * this task SHOULD be performed in GUI thread only: */
     251void VBoxVMSettingsSystem::putToCache()
     252{
     253    /* Gather internal variables data from QWidget(s): */
     254    m_cache.m_bootItems.clear();
     255    for (int i = 0; i < mTwBootOrder->topLevelItemCount(); ++i)
     256    {
     257        QTreeWidgetItem *pItem = mTwBootOrder->topLevelItem(i);
     258        UIBootItemData data;
     259        data.m_type = (KDeviceType)pItem->data(0, ITEM_TYPE_ROLE).toInt();
     260        data.m_fEnabled = pItem->checkState(0) == Qt::Checked;
     261        m_cache.m_bootItems << data;
     262    }
     263    m_cache.m_fIoApicEnabled = mCbApic->isChecked() || mSlCPU->value() > 1;
     264    m_cache.m_fEFIEnabled = mCbEFI->isChecked();
     265    m_cache.m_fUTCEnabled = mCbTCUseUTC->isChecked();
     266    m_cache.m_fUseAbsHID = mCbUseAbsHID->isChecked();
     267    m_cache.m_fPAEEnabled = mCbPae->isChecked();
     268    m_cache.m_fHwVirtExEnabled = mCbVirt->checkState() == Qt::Checked || mSlCPU->value() > 1;
     269    m_cache.m_fNestedPagingEnabled = mCbNestedPaging->isChecked();
     270    m_cache.m_iRAMSize = mSlMemory->value();
     271    m_cache.m_cCPUCount = mSlCPU->value();
     272    m_cache.m_chipsetType = (KChipsetType)mCbChipset->itemData(mCbChipset->currentIndex()).toInt();
     273}
     274
     275/* Save data from cache to corresponding external object(s),
     276 * this task COULD be performed in other than GUI thread: */
     277void VBoxVMSettingsSystem::saveFromCacheTo(QVariant &data)
     278{
     279    /* Fetch data to machine: */
     280    UISettingsPageMachine::fetchData(data);
     281
     282    /* Gather corresponding values from internal variables: */
     283    int iBootIndex = 0;
     284    /* Save boot-items of current VM: */
     285    for (int i = 0; i < m_cache.m_bootItems.size(); ++i)
     286    {
     287        if (m_cache.m_bootItems[i].m_fEnabled)
     288            m_machine.SetBootOrder(++iBootIndex, m_cache.m_bootItems[i].m_type);
     289    }
     290    /* Save other unique boot-items: */
     291    for (int i = 0; i < m_cache.m_bootItems.size(); ++i)
     292    {
     293        if (!m_cache.m_bootItems[i].m_fEnabled)
     294            m_machine.SetBootOrder(++iBootIndex, KDeviceType_Null);
     295    }
     296    m_machine.GetBIOSSettings().SetIOAPICEnabled(m_cache.m_fIoApicEnabled);
     297    m_machine.SetFirmwareType(m_cache.m_fEFIEnabled ? KFirmwareType_EFI : KFirmwareType_BIOS);
     298    m_machine.SetRTCUseUTC(m_cache.m_fUTCEnabled);
     299    m_machine.SetPointingHidType(m_cache.m_fUseAbsHID ? KPointingHidType_USBTablet : KPointingHidType_PS2Mouse);
     300    m_machine.SetCPUProperty(KCPUPropertyType_PAE, m_cache.m_fPAEEnabled);
     301    m_machine.SetHWVirtExProperty(KHWVirtExPropertyType_Enabled, m_cache.m_fHwVirtExEnabled);
     302    m_machine.SetHWVirtExProperty(KHWVirtExPropertyType_NestedPaging, m_cache.m_fNestedPagingEnabled);
     303    m_machine.SetMemorySize(m_cache.m_iRAMSize);
     304    m_machine.SetCPUCount(m_cache.m_cCPUCount);
     305    m_machine.SetChipsetType(m_cache.m_chipsetType);
     306
     307    /* Upload machine to data: */
     308    UISettingsPageMachine::uploadData(data);
    269309}
    270310
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSystem.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2008-2009 Oracle Corporation
     8 * Copyright (C) 2008-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#include "VBoxVMSettingsSystem.gen.h"
    2525
    26 class VBoxVMSettingsSystem : public UISettingsPage,
     26/* Machine settings / System page / Boot item: */
     27struct UIBootItemData
     28{
     29    KDeviceType m_type;
     30    bool m_fEnabled;
     31};
     32
     33/* Machine settings / System page / Cache: */
     34struct UISettingsCacheMachineSystem
     35{
     36    QList<UIBootItemData> m_bootItems;
     37    KChipsetType m_chipsetType;
     38    bool m_fPFHwVirtExSupported;
     39    bool m_fPFPAESupported;
     40    bool m_fIoApicEnabled;
     41    bool m_fEFIEnabled;
     42    bool m_fUTCEnabled;
     43    bool m_fUseAbsHID;
     44    bool m_fPAEEnabled;
     45    bool m_fHwVirtExEnabled;
     46    bool m_fNestedPagingEnabled;
     47    int m_iRAMSize;
     48    int m_cCPUCount;
     49};
     50
     51/* Machine settings / System page: */
     52class VBoxVMSettingsSystem : public UISettingsPageMachine,
    2753                             public Ui::VBoxVMSettingsSystem
    2854{
     
    4369protected:
    4470
    45     void getFrom (const CMachine &aMachine);
    46     void putBackTo();
     71    /* Load data to cashe from corresponding external object(s),
     72     * this task COULD be performed in other than GUI thread: */
     73    void loadToCacheFrom(QVariant &data);
     74    /* Load data to corresponding widgets from cache,
     75     * this task SHOULD be performed in GUI thread only: */
     76    void getFromCache();
     77
     78    /* Save data from corresponding widgets to cache,
     79     * this task SHOULD be performed in GUI thread only: */
     80    void putToCache();
     81    /* Save data from cache to corresponding external object(s),
     82     * this task COULD be performed in other than GUI thread: */
     83    void saveFromCacheTo(QVariant &data);
    4784
    4885    void setValidator (QIWidgetValidator *aVal);
     
    72109    void adjustBootOrderTWSize();
    73110
    74     CMachine mMachine;
    75111    QIWidgetValidator *mValidator;
    76112
    77113    uint mMinGuestCPU;
    78114    uint mMaxGuestCPU;
     115
     116    QList<KDeviceType> m_possibleBootItems;
     117
     118    /* Cache: */
     119    UISettingsCacheMachineSystem m_cache;
    79120};
    80121
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSystem.ui

    r29972 r33631  
    5454        </widget>
    5555       </item>
    56        <item row="0" column="1" rowspan="2">
     56       <item row="0" column="1" rowspan="2" colspan="2">
    5757        <layout class="QVBoxLayout" name="mLtMemorySlider">
    5858         <property name="spacing">
     
    117117        </layout>
    118118       </item>
    119        <item row="0" column="2">
     119       <item row="0" column="3">
    120120        <layout class="QHBoxLayout" name="mLtMemoryUnits">
    121121         <item>
     
    292292       </item>
    293293       <item row="4" column="0">
    294         <widget class="QLabel" name="mLbMotherboardExtended">
     294        <widget class="QLabel" name="mLbChipset">
    295295         <property name="sizePolicy">
    296296          <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
     
    300300         </property>
    301301         <property name="text">
    302           <string>Extended Features:</string>
     302          <string>&amp;Chipset:</string>
    303303         </property>
    304304         <property name="alignment">
    305305          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    306306         </property>
    307         </widget>
    308        </item>
    309        <item row="4" column="1" colspan="2">
     307         <property name="buddy">
     308          <cstring>mCbChipset</cstring>
     309         </property>
     310        </widget>
     311       </item>
     312       <item row="4" column="1">
     313        <widget class="QComboBox" name="mCbChipset">
     314         <property name="sizePolicy">
     315          <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
     316           <horstretch>0</horstretch>
     317           <verstretch>0</verstretch>
     318          </sizepolicy>
     319         </property>
     320         <property name="whatsThis">
     321          <string>Defines chipset type used in this VM.</string>
     322         </property>
     323        </widget>
     324       </item>
     325       <item row="5" column="0">
     326        <widget class="QLabel" name="mLbMotherboardExtended">
     327         <property name="sizePolicy">
     328          <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
     329           <horstretch>0</horstretch>
     330           <verstretch>0</verstretch>
     331          </sizepolicy>
     332         </property>
     333         <property name="text">
     334          <string>Extended Features:</string>
     335         </property>
     336         <property name="alignment">
     337          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
     338         </property>
     339        </widget>
     340       </item>
     341       <item row="5" column="1" colspan="3">
    310342        <widget class="QCheckBox" name="mCbApic">
    311343         <property name="sizePolicy">
     
    323355        </widget>
    324356       </item>
    325        <item row="5" column="1" colspan="2">
     357       <item row="6" column="1" colspan="3">
    326358        <widget class="QCheckBox" name="mCbEFI">
    327359         <property name="sizePolicy">
     
    339371        </widget>
    340372       </item>
    341        <item row="6" column="1" >
     373       <item row="7" column="1" colspan="3">
    342374        <widget class="QCheckBox" name="mCbTCUseUTC" >
    343375         <property name="sizePolicy" >
     
    355387        </widget>
    356388       </item>
    357        <item row="7" column="1" >
     389       <item row="8" column="1" colspan="3">
    358390        <widget class="QCheckBox" name="mCbUseAbsHID" >
    359391         <property name="sizePolicy" >
     
    371403        </widget>
    372404       </item>
    373        <item row="8" column="0" colspan="3">
     405       <item row="9" column="0" colspan="4">
    374406        <spacer name="mSpVer1">
    375407         <property name="orientation">
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsUSB.cpp

    r32760 r33631  
    77
    88/*
    9  * Copyright (C) 2006-2008 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929#include <QHeaderView>
    3030
    31 inline static QString emptyToNull (const QString &str)
    32 {
    33     return str.isEmpty() ? QString::null : str;
    34 }
    35 
    36 VBoxVMSettingsUSB::VBoxVMSettingsUSB (FilterType aType)
    37     : mValidator (0)
    38     , mType (aType)
     31VBoxVMSettingsUSB::VBoxVMSettingsUSB(UISettingsPageType type)
     32    : UISettingsPage(type)
     33    , mValidator (0)
    3934    , mUSBFilterListModified (false)
    4035{
     
    108103             this, SLOT (edtClicked()));
    109104    connect (mTwFilters, SIGNAL (itemChanged (QTreeWidgetItem *, int)),
    110              this, SLOT (markSettingsChanged()));
     105             this, SLOT (sltUpdateActivityState(QTreeWidgetItem *)));
    111106
    112107    mUSBDevicesMenu = new VBoxUSBMenu (this);
     
    142137}
    143138
    144 void VBoxVMSettingsUSB::getFrom (const CSystemProperties &, const VBoxGlobalSettings &)
    145 {
    146     mGbUSB->setVisible (false);
    147 
    148     CHostUSBDeviceFilterVector filtvec = vboxGlobal().virtualBox().GetHost()
    149                                         .GetUSBDeviceFilters();
    150     for (int i = 0; i < filtvec.size(); ++i)
    151     {
    152         CHostUSBDeviceFilter hostFilter = filtvec[i];
    153         CUSBDeviceFilter filter (hostFilter);
    154         addUSBFilter (filter, false /* isNew */);
    155     }
    156 
    157     mTwFilters->setCurrentItem (mTwFilters->topLevelItem (0));
    158     currentChanged (mTwFilters->currentItem());
    159 
     139/* Load data to cashe from corresponding external object(s),
     140 * this task COULD be performed in other than GUI thread: */
     141void VBoxVMSettingsUSB::loadToCacheFrom(QVariant &data)
     142{
     143    /* Fetch data to properties & settings or machine: */
     144    fetchData(data);
     145
     146    /* Depending on page type: */
     147    switch (type())
     148    {
     149        case UISettingsPageType_Global:
     150        {
     151            /* Fill internal variables with corresponding values: */
     152            m_cache.m_fUSBEnabled = false;
     153            m_cache.m_fEHCIEnabled = false;
     154            const CHostUSBDeviceFilterVector &filters = vboxGlobal().virtualBox().GetHost().GetUSBDeviceFilters();
     155            for (int iFilterIndex = 0; iFilterIndex < filters.size(); ++iFilterIndex)
     156            {
     157                const CHostUSBDeviceFilter &filter = filters[iFilterIndex];
     158                UIUSBFilterData data;
     159                data.m_fActive = filter.GetActive();
     160                data.m_strName = filter.GetName();
     161                data.m_strVendorId = filter.GetVendorId();
     162                data.m_strProductId = filter.GetProductId();
     163                data.m_strRevision = filter.GetRevision();
     164                data.m_strManufacturer = filter.GetManufacturer();
     165                data.m_strProduct = filter.GetProduct();
     166                data.m_strSerialNumber = filter.GetSerialNumber();
     167                data.m_strPort = filter.GetPort();
     168                data.m_strRemote = filter.GetRemote();
     169                data.m_action = filter.GetAction();
     170                CHostUSBDevice hostUSBDevice(filter);
     171                if (!hostUSBDevice.isNull())
     172                {
     173                    data.m_fHostUSBDevice = true;
     174                    data.m_hostUSBDeviceState = hostUSBDevice.GetState();
     175                }
     176                else
     177                {
     178                    data.m_fHostUSBDevice = false;
     179                    data.m_hostUSBDeviceState = KUSBDeviceState_NotSupported;
     180                }
     181                m_cache.m_items << data;
     182            }
     183            break;
     184        }
     185        case UISettingsPageType_Machine:
     186        {
     187            /* Initialize machine COM storage: */
     188            m_machine = data.value<UISettingsDataMachine>().m_machine;
     189            /* Fill internal variables with corresponding values: */
     190            const CUSBController &ctl = m_machine.GetUSBController();
     191            bool fIsControllerAvailable = !ctl.isNull();
     192            m_cache.m_fUSBEnabled = fIsControllerAvailable && ctl.GetEnabled();
     193            m_cache.m_fEHCIEnabled = fIsControllerAvailable && ctl.GetEnabledEhci();
     194            if (fIsControllerAvailable)
     195            {
     196                const CUSBDeviceFilterVector &filters = ctl.GetDeviceFilters();
     197                for (int iFilterIndex = 0; iFilterIndex < filters.size(); ++iFilterIndex)
     198                {
     199                    const CUSBDeviceFilter &filter = filters[iFilterIndex];
     200                    UIUSBFilterData data;
     201                    data.m_fActive = filter.GetActive();
     202                    data.m_strName = filter.GetName();
     203                    data.m_strVendorId = filter.GetVendorId();
     204                    data.m_strProductId = filter.GetProductId();
     205                    data.m_strRevision = filter.GetRevision();
     206                    data.m_strManufacturer = filter.GetManufacturer();
     207                    data.m_strProduct = filter.GetProduct();
     208                    data.m_strSerialNumber = filter.GetSerialNumber();
     209                    data.m_strPort = filter.GetPort();
     210                    data.m_strRemote = filter.GetRemote();
     211                    data.m_fHostUSBDevice = false;
     212                    m_cache.m_items << data;
     213                }
     214            }
     215            break;
     216        }
     217        default:
     218            break;
     219    }
     220
     221    /* Upload properties & settings or machine to data: */
     222    uploadData(data);
     223}
     224
     225/* Load data to corresponding widgets from cache,
     226 * this task SHOULD be performed in GUI thread only: */
     227void VBoxVMSettingsUSB::getFromCache()
     228{
     229    /* Depending on page type: */
     230    switch (type())
     231    {
     232        case UISettingsPageType_Global:
     233        {
     234            /* Apply internal variables data to QWidget(s): */
     235            mGbUSB->setVisible(false);
     236            mCbUSB2->setVisible(false);
     237            break;
     238        }
     239        case UISettingsPageType_Machine:
     240        {
     241            /* Apply internal variables data to QWidget(s): */
     242            mGbUSB->setChecked(m_cache.m_fUSBEnabled);
     243            mCbUSB2->setChecked(m_cache.m_fEHCIEnabled);
     244            usbAdapterToggled(mGbUSB->isChecked());
     245            break;
     246        }
     247        default:
     248            break;
     249    }
     250    /* Apply internal variables data to QWidget(s): */
     251    for (int iFilterIndex = 0; iFilterIndex < m_cache.m_items.size(); ++iFilterIndex)
     252        addUSBFilter(m_cache.m_items[iFilterIndex], false /* its new? */);
     253    /* Choose first filter as current: */
     254    mTwFilters->setCurrentItem(mTwFilters->topLevelItem(0));
     255    currentChanged(mTwFilters->currentItem());
     256    /* Mark dialog as not edited:  */
    160257    mUSBFilterListModified = false;
    161 }
    162 
    163 void VBoxVMSettingsUSB::putBackTo (CSystemProperties &, VBoxGlobalSettings &)
    164 {
    165     CHost host = vboxGlobal().virtualBox().GetHost();
    166 
    167     if (mUSBFilterListModified)
    168     {
    169         /* First, remove all old filters */
    170         for (ulong count = host.GetUSBDeviceFilters().size(); count; -- count)
    171             host.RemoveUSBDeviceFilter (0);
    172 
    173         /* Then add all new filters */
    174         for (int i = 0; i < mFilters.size(); ++ i)
    175         {
    176             CUSBDeviceFilter filter = mFilters [i];
    177             filter.SetActive (mTwFilters->topLevelItem (i)->
    178                 checkState (0) == Qt::Checked);
    179             CHostUSBDeviceFilter insertedFilter (filter);
    180             host.InsertUSBDeviceFilter (host.GetUSBDeviceFilters().size(),
    181                                         insertedFilter);
    182         }
    183     }
    184 
    185     mUSBFilterListModified = false;
    186 }
    187 
    188 void VBoxVMSettingsUSB::getFrom (const CMachine &aMachine)
    189 {
    190     mMachine = aMachine;
    191 
    192     CUSBController ctl = aMachine.GetUSBController();
    193     mGbUSB->setChecked (!ctl.isNull() && ctl.GetEnabled());
    194     mCbUSB2->setChecked (!ctl.isNull() && ctl.GetEnabledEhci());
    195     usbAdapterToggled (mGbUSB->isChecked());
    196 
    197     if (!ctl.isNull())
    198     {
    199         CUSBDeviceFilterVector filtvec = ctl.GetDeviceFilters();
    200         for (int i = 0; i < filtvec.size(); ++i)
    201             addUSBFilter (filtvec[i], false /* isNew */);
    202     }
    203 
    204     mTwFilters->setCurrentItem (mTwFilters->topLevelItem (0));
    205     currentChanged (mTwFilters->currentItem());
    206 
    207     mUSBFilterListModified = false;
    208 }
    209 
    210 void VBoxVMSettingsUSB::putBackTo()
    211 {
    212     CUSBController ctl = mMachine.GetUSBController();
    213     if (!ctl.isNull())
    214     {
    215         ctl.SetEnabled (mGbUSB->isChecked());
    216         ctl.SetEnabledEhci (mCbUSB2->isChecked());
    217 
    218         if (mUSBFilterListModified)
    219         {
    220             /* First, remove all old filters */
    221             for (ulong count = ctl.GetDeviceFilters().size(); count; -- count)
    222                 ctl.RemoveDeviceFilter (0);
    223 
    224             /* Then add all new filters */
    225             for (int i = 0; i < mFilters.size(); ++ i)
     258
     259    /* Revalidate if possible: */
     260    if (mValidator) mValidator->revalidate();
     261}
     262
     263/* Save data from corresponding widgets to cache,
     264 * this task SHOULD be performed in GUI thread only: */
     265void VBoxVMSettingsUSB::putToCache()
     266{
     267    /* Depending on page type: */
     268    switch (type())
     269    {
     270        case UISettingsPageType_Machine:
     271        {
     272            /* Gather internal variables data from QWidget(s): */
     273            m_cache.m_fUSBEnabled = mGbUSB->isChecked();
     274            m_cache.m_fEHCIEnabled = mCbUSB2->isChecked();
     275            break;
     276        }
     277        default:
     278            break;
     279    }
     280}
     281
     282/* Save data from cache to corresponding external object(s),
     283 * this task COULD be performed in other than GUI thread: */
     284void VBoxVMSettingsUSB::saveFromCacheTo(QVariant &data)
     285{
     286    /* Fetch data to properties & settings or machine: */
     287    fetchData(data);
     288
     289    /* Depending on page type: */
     290    switch (type())
     291    {
     292        case UISettingsPageType_Global:
     293        {
     294            /* Gather corresponding values from internal variables: */
     295            if (mUSBFilterListModified)
    226296            {
    227                 CUSBDeviceFilter filter = mFilters [i];
    228                 filter.SetActive (mTwFilters->topLevelItem (i)->
    229                     checkState (0) == Qt::Checked);
    230                 ctl.InsertDeviceFilter (~0, filter);
     297                /* Get host: */
     298                CHost &host = vboxGlobal().virtualBox().GetHost();
     299                /* First, remove all old filters: */
     300                for (ulong count = host.GetUSBDeviceFilters().size(); count; --count)
     301                    host.RemoveUSBDeviceFilter(0);
     302                /* Then add all new filters: */
     303                for (int iFilterIndex = 0; iFilterIndex < m_cache.m_items.size(); ++iFilterIndex)
     304                {
     305                    UIUSBFilterData data = m_cache.m_items[iFilterIndex];
     306                    CHostUSBDeviceFilter &hostFilter = host.CreateUSBDeviceFilter(data.m_strName);
     307                    hostFilter.SetActive(data.m_fActive);
     308                    hostFilter.SetVendorId(data.m_strVendorId);
     309                    hostFilter.SetProductId(data.m_strProductId);
     310                    hostFilter.SetRevision(data.m_strRevision);
     311                    hostFilter.SetManufacturer(data.m_strManufacturer);
     312                    hostFilter.SetProduct(data.m_strProduct);
     313                    hostFilter.SetSerialNumber(data.m_strSerialNumber);
     314                    hostFilter.SetPort(data.m_strPort);
     315                    hostFilter.SetRemote(data.m_strRemote);
     316                    hostFilter.SetAction(data.m_action);
     317                    host.InsertUSBDeviceFilter(host.GetUSBDeviceFilters().size(), hostFilter);
     318                }
    231319            }
    232         }
    233     }
    234     mUSBFilterListModified = false;
     320            break;
     321        }
     322        case UISettingsPageType_Machine:
     323        {
     324            /* Initialize machine COM storage: */
     325            m_machine = data.value<UISettingsDataMachine>().m_machine;
     326            /* Get machine USB controller: */
     327            CUSBController &ctl = m_machine.GetUSBController();
     328            /* Gather corresponding values from internal variables: */
     329            if (!ctl.isNull())
     330            {
     331                ctl.SetEnabled(m_cache.m_fUSBEnabled);
     332                ctl.SetEnabledEhci(m_cache.m_fEHCIEnabled);
     333                if (mUSBFilterListModified)
     334                {
     335                    /* First, remove all old filters: */
     336                    for (ulong count = ctl.GetDeviceFilters().size(); count; --count)
     337                        ctl.RemoveDeviceFilter(0);
     338                    /* Then add all new filters: */
     339                    for (int iFilterIndex = 0; iFilterIndex < m_cache.m_items.size(); ++iFilterIndex)
     340                    {
     341                        const UIUSBFilterData &data = m_cache.m_items[iFilterIndex];
     342                        CUSBDeviceFilter &filter = ctl.CreateDeviceFilter(data.m_strName);
     343                        filter.SetActive(data.m_fActive);
     344                        filter.SetVendorId(data.m_strVendorId);
     345                        filter.SetProductId(data.m_strProductId);
     346                        filter.SetRevision(data.m_strRevision);
     347                        filter.SetManufacturer(data.m_strManufacturer);
     348                        filter.SetProduct(data.m_strProduct);
     349                        filter.SetSerialNumber(data.m_strSerialNumber);
     350                        filter.SetPort(data.m_strPort);
     351                        filter.SetRemote(data.m_strRemote);
     352                        ctl.InsertDeviceFilter(~0, filter);
     353                    }
     354                }
     355            }
     356            break;
     357        }
     358        default:
     359            break;
     360    }
     361
     362    /* Upload properties & settings or machine to data: */
     363    uploadData(data);
    235364}
    236365
     
    330459    }
    331460
    332     /* Creating new usb filter */
    333     CUSBDeviceFilter filter;
    334 
    335     if (mType == HostType)
    336     {
    337         CHost host = vboxGlobal().virtualBox().GetHost();
    338         CHostUSBDeviceFilter hostFilter = host
    339             .CreateUSBDeviceFilter (mUSBFilterName.arg (maxFilterIndex + 1));
    340         hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
    341         filter = hostFilter;
    342     }
    343     else if (mType == MachineType)
    344     {
    345         CUSBController ctl = mMachine.GetUSBController();
    346         if (ctl.isNull())
    347             return;
    348         filter = ctl.CreateDeviceFilter (mUSBFilterName.arg (maxFilterIndex + 1));
    349     }
    350     else
    351     {
    352         AssertMsgFailed (("Invalid VBoxVMSettingsUSB type"));
    353     }
    354 
    355     filter.SetActive (true);
    356     addUSBFilter (filter, true /* isNew */);
    357 
    358     mUSBFilterListModified = true;
     461    /* Add new corresponding list item to the cache: */
     462    UIUSBFilterData data;
     463    switch (type())
     464    {
     465        case UISettingsPageType_Global:
     466            data.m_action = KUSBDeviceFilterAction_Hold;
     467            break;
     468        default:
     469            break;
     470    }
     471    data.m_fActive = true;
     472    data.m_strName = mUSBFilterName.arg(maxFilterIndex + 1);
     473    data.m_fHostUSBDevice = false;
     474    m_cache.m_items << data;
     475
     476    /* Add new corresponding tree-widget-item to the tree-widget: */
     477    addUSBFilter(data, true /* its new? */);
     478    /* Mark filter's list as edited: */
     479    markSettingsChanged();
     480    /* Revalidate if possible: */
     481    if (mValidator)
     482        mValidator->revalidate();
    359483}
    360484
     
    366490void VBoxVMSettingsUSB::addConfirmed (QAction *aAction)
    367491{
     492    /* Get USB device: */
    368493    CUSBDevice usb = mUSBDevicesMenu->getUSB (aAction);
    369494    /* if null then some other item but a USB device is selected */
     
    371496        return;
    372497
    373     /* Creating new usb filter */
    374     CUSBDeviceFilter filter;
    375 
    376     if (mType == HostType)
    377     {
    378         CHost host = vboxGlobal().virtualBox().GetHost();
    379         CHostUSBDeviceFilter hostFilter = host
    380             .CreateUSBDeviceFilter (vboxGlobal().details (usb));
    381         hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
    382         filter = hostFilter;
    383     }
    384     else if (mType == MachineType)
    385     {
    386         CUSBController ctl = mMachine.GetUSBController();
    387         if (ctl.isNull())
    388             return;
    389         filter = ctl.CreateDeviceFilter (vboxGlobal().details (usb));
    390     }
    391     else
    392     {
    393         AssertMsgFailed (("Invalid VBoxVMSettingsUSB type"));
    394     }
    395 
    396     filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
    397     filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
    398     filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
     498    /* Add new corresponding list item to the cache: */
     499    UIUSBFilterData data;
     500    switch (type())
     501    {
     502        case UISettingsPageType_Global:
     503            data.m_action = KUSBDeviceFilterAction_Hold;
     504            /* Check that under host (global) USB settings if they will be enabled! */
     505            data.m_fHostUSBDevice = false;
     506            break;
     507        case UISettingsPageType_Machine:
     508            data.m_fHostUSBDevice = false;
     509            break;
     510        default:
     511            break;
     512    }
     513    data.m_fActive = true;
     514    data.m_strName = vboxGlobal().details(usb);
     515    data.m_strVendorId = QString().sprintf("%04hX", usb.GetVendorId());
     516    data.m_strProductId = QString().sprintf("%04hX", usb.GetProductId());
     517    data.m_strRevision = QString().sprintf("%04hX", usb.GetRevision());
    399518    /* The port property depends on the host computer rather than on the USB
    400519     * device itself; for this reason only a few people will want to use it
     
    402521     * will not match the filter in this case. */
    403522#if 0
    404     /// @todo set it anyway if Alt is currently pressed
    405     filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
     523    data.m_strPort = QString().sprintf("%04hX", usb.GetPort());
    406524#endif
    407     filter.SetManufacturer (usb.GetManufacturer());
    408     filter.SetProduct (usb.GetProduct());
    409     filter.SetSerialNumber (usb.GetSerialNumber());
    410     filter.SetRemote (usb.GetRemote() ? "yes" : "no");
    411 
    412     filter.SetActive (true);
    413     addUSBFilter (filter, true /* isNew */);
    414 
    415     mUSBFilterListModified = true;
     525    data.m_strManufacturer = usb.GetManufacturer();
     526    data.m_strProduct = usb.GetProduct();
     527    data.m_strSerialNumber = usb.GetSerialNumber();
     528    data.m_strRemote = QString::number(usb.GetRemote());
     529    m_cache.m_items << data;
     530
     531    /* Add new corresponding tree-widget-item to the tree-widget: */
     532    addUSBFilter(data, true /* its new? */);
     533    /* Mark filter's list as edited: */
     534    markSettingsChanged();
     535    /* Revalidate if possible: */
     536    if (mValidator)
     537        mValidator->revalidate();
    416538}
    417539
    418540void VBoxVMSettingsUSB::edtClicked()
    419541{
    420     QTreeWidgetItem *item = mTwFilters->currentItem();
    421     Assert (item);
    422 
    423     VBoxVMSettingsUSBFilterDetails fd (mType, this);
    424 
    425     CUSBDeviceFilter filter =
    426         mFilters [mTwFilters->indexOfTopLevelItem (item)];
    427 
    428     fd.mLeName->setText (filter.isNull() ? QString::null : filter.GetName());
    429     fd.mLeVendorID->setText (filter.isNull() ? QString::null : filter.GetVendorId());
    430     fd.mLeProductID->setText (filter.isNull() ? QString::null : filter.GetProductId());
    431     fd.mLeRevision->setText (filter.isNull() ? QString::null : filter.GetRevision());
    432     fd.mLePort->setText (filter.isNull() ? QString::null : filter.GetPort());
    433     fd.mLeManufacturer->setText (filter.isNull() ? QString::null : filter.GetManufacturer());
    434     fd.mLeProduct->setText (filter.isNull() ? QString::null : filter.GetProduct());
    435     fd.mLeSerialNo->setText (filter.isNull() ? QString::null : filter.GetSerialNumber());
    436 
    437     switch (mType)
    438     {
    439         case MachineType:
    440         {
    441             QString remote = filter.isNull() ? QString::null : filter.GetRemote().toLower();
    442             if (remote == "yes" || remote == "true" || remote == "1")
    443                 fd.mCbRemote->setCurrentIndex (ModeOn);
    444             else if (remote == "no" || remote == "false" || remote == "0")
    445                 fd.mCbRemote->setCurrentIndex (ModeOff);
     542    /* Get current USB filter item: */
     543    QTreeWidgetItem *pItem = mTwFilters->currentItem();
     544    Assert(pItem);
     545    UIUSBFilterData &data = m_cache.m_items[mTwFilters->indexOfTopLevelItem(pItem)];
     546
     547    /* Configure USB filter details dialog: */
     548    VBoxVMSettingsUSBFilterDetails dlgFilterDetails(type(), this);
     549    dlgFilterDetails.mLeName->setText(data.m_strName);
     550    dlgFilterDetails.mLeVendorID->setText(data.m_strVendorId);
     551    dlgFilterDetails.mLeProductID->setText(data.m_strProductId);
     552    dlgFilterDetails.mLeRevision->setText(data.m_strRevision);
     553    dlgFilterDetails.mLePort->setText(data.m_strPort);
     554    dlgFilterDetails.mLeManufacturer->setText(data.m_strManufacturer);
     555    dlgFilterDetails.mLeProduct->setText(data.m_strProduct);
     556    dlgFilterDetails.mLeSerialNo->setText(data.m_strSerialNumber);
     557    switch (type())
     558    {
     559        case UISettingsPageType_Global:
     560        {
     561            if (data.m_action == KUSBDeviceFilterAction_Ignore)
     562                dlgFilterDetails.mCbAction->setCurrentIndex(0);
     563            else if (data.m_action == KUSBDeviceFilterAction_Hold)
     564                dlgFilterDetails.mCbAction->setCurrentIndex(1);
    446565            else
    447                 fd.mCbRemote->setCurrentIndex (ModeAny);
    448             break;
    449         }
    450         case HostType:
    451         {
    452             CHostUSBDeviceFilter hostFilter (filter);
    453             KUSBDeviceFilterAction action = hostFilter.isNull() ?
    454                 KUSBDeviceFilterAction_Ignore : hostFilter.GetAction();
    455             if (action == KUSBDeviceFilterAction_Ignore)
    456                 fd.mCbAction->setCurrentIndex (0);
    457             else if (action == KUSBDeviceFilterAction_Hold)
    458                 fd.mCbAction->setCurrentIndex (1);
     566                AssertMsgFailed(("Invalid USBDeviceFilterAction type"));
     567            break;
     568        }
     569        case UISettingsPageType_Machine:
     570        {
     571            QString strRemote = data.m_strRemote.toLower();
     572            if (strRemote == "yes" || strRemote == "true" || strRemote == "1")
     573                dlgFilterDetails.mCbRemote->setCurrentIndex(ModeOn);
     574            else if (strRemote == "no" || strRemote == "false" || strRemote == "0")
     575                dlgFilterDetails.mCbRemote->setCurrentIndex(ModeOff);
    459576            else
    460                 AssertMsgFailed (("Invalid USBDeviceFilterAction type"));
    461             break;
    462         }
    463         default:
    464         {
    465             AssertMsgFailed (("Invalid VBoxVMSettingsUSB type"));
    466             break;
    467         }
    468     }
    469 
    470     if (fd.exec() == QDialog::Accepted)
    471     {
    472         filter.SetName (fd.mLeName->text().isEmpty() ? QString::null : fd.mLeName->text());
    473         item->setText (0, fd.mLeName->text());
    474         filter.SetVendorId (fd.mLeVendorID->text().isEmpty() ? QString::null : fd.mLeVendorID->text());
    475         filter.SetProductId (fd.mLeProductID->text().isEmpty() ? QString::null : fd.mLeProductID->text());
    476         filter.SetRevision (fd.mLeRevision->text().isEmpty() ? QString::null : fd.mLeRevision->text());
    477         filter.SetManufacturer (fd.mLeManufacturer->text().isEmpty() ? QString::null : fd.mLeManufacturer->text());
    478         filter.SetProduct (fd.mLeProduct->text().isEmpty() ? QString::null : fd.mLeProduct->text());
    479         filter.SetSerialNumber (fd.mLeSerialNo->text().isEmpty() ? QString::null : fd.mLeSerialNo->text());
    480         filter.SetPort (fd.mLePort->text().isEmpty() ? QString::null : fd.mLePort->text());
    481         if (mType == MachineType)
    482         {
    483             switch (fd.mCbRemote->currentIndex())
    484              {
    485                  case ModeAny: filter.SetRemote (QString::null); break;
    486                  case ModeOn:  filter.SetRemote ("yes"); break;
    487                  case ModeOff: filter.SetRemote ("no"); break;
    488                  default: AssertMsgFailed (("Invalid combo box index"));
    489              }
    490         }
    491         else
    492         if (mType == HostType)
    493         {
    494             CHostUSBDeviceFilter hostFilter (filter);
    495             hostFilter.SetAction (vboxGlobal().toUSBDevFilterAction (fd.mCbAction->currentText()));
    496         }
    497         item->setToolTip (0, vboxGlobal().toolTip (filter));
     577                dlgFilterDetails.mCbRemote->setCurrentIndex(ModeAny);
     578            break;
     579        }
     580        default:
     581            break;
     582    }
     583
     584    /* Run USB filter details dialog: */
     585    if (dlgFilterDetails.exec() == QDialog::Accepted)
     586    {
     587        data.m_strName = dlgFilterDetails.mLeName->text().isEmpty() ? QString::null : dlgFilterDetails.mLeName->text();
     588        data.m_strVendorId = dlgFilterDetails.mLeVendorID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeVendorID->text();
     589        data.m_strProductId = dlgFilterDetails.mLeProductID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProductID->text();
     590        data.m_strRevision = dlgFilterDetails.mLeRevision->text().isEmpty() ? QString::null : dlgFilterDetails.mLeRevision->text();
     591        data.m_strManufacturer = dlgFilterDetails.mLeManufacturer->text().isEmpty() ? QString::null : dlgFilterDetails.mLeManufacturer->text();
     592        data.m_strProduct = dlgFilterDetails.mLeProduct->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProduct->text();
     593        data.m_strSerialNumber = dlgFilterDetails.mLeSerialNo->text().isEmpty() ? QString::null : dlgFilterDetails.mLeSerialNo->text();
     594        data.m_strPort = dlgFilterDetails.mLePort->text().isEmpty() ? QString::null : dlgFilterDetails.mLePort->text();
     595        switch (type())
     596        {
     597            case UISettingsPageType_Global:
     598            {
     599                data.m_action = vboxGlobal().toUSBDevFilterAction(dlgFilterDetails.mCbAction->currentText());
     600                break;
     601            }
     602            case UISettingsPageType_Machine:
     603            {
     604                switch (dlgFilterDetails.mCbRemote->currentIndex())
     605                {
     606                    case ModeAny: data.m_strRemote = QString(); break;
     607                    case ModeOn:  data.m_strRemote = QString::number(1); break;
     608                    case ModeOff: data.m_strRemote = QString::number(0); break;
     609                    default: AssertMsgFailed(("Invalid combo box index"));
     610                }
     611                break;
     612            }
     613            default:
     614                break;
     615        }
     616        pItem->setText(0, data.m_strName);
     617        pItem->setToolTip(0, toolTipFor(data));
     618        /* Mark filter's list as edited: */
     619        markSettingsChanged();
    498620    }
    499621}
     
    501623void VBoxVMSettingsUSB::delClicked()
    502624{
    503     QTreeWidgetItem *item = mTwFilters->currentItem();
    504     Assert (item);
    505     int index = mTwFilters->indexOfTopLevelItem (item);
    506 
    507     delete item;
    508     mFilters.removeAt (index);
    509 
    510     /* Setup validators */
     625    /* Get current USB filter item: */
     626    QTreeWidgetItem *pItem = mTwFilters->currentItem();
     627    Assert(pItem);
     628
     629    /* Delete corresponding items: */
     630    m_cache.m_items.removeAt(mTwFilters->indexOfTopLevelItem(pItem));
     631    delete pItem;
     632
     633    /* Update current item: */
     634    currentChanged(mTwFilters->currentItem());
     635    /* Mark filter's list as edited: */
     636    markSettingsChanged();
     637    /* Revalidate if possible: */
    511638    if (!mTwFilters->topLevelItemCount())
    512639    {
     
    517644        }
    518645    }
    519 
    520     currentChanged (mTwFilters->currentItem());
    521     mUSBFilterListModified = true;
    522646}
    523647
     
    531655    Assert (item == takenItem);
    532656    mTwFilters->insertTopLevelItem (index - 1, takenItem);
    533     mFilters.swap (index, index - 1);
     657    m_cache.m_items.swap (index, index - 1);
    534658
    535659    mTwFilters->setCurrentItem (takenItem);
    536     mUSBFilterListModified = true;
     660    markSettingsChanged();
    537661}
    538662
     
    546670    Assert (item == takenItem);
    547671    mTwFilters->insertTopLevelItem (index + 1, takenItem);
    548     mFilters.swap (index, index + 1);
     672    m_cache.m_items.swap (index, index + 1);
    549673
    550674    mTwFilters->setCurrentItem (takenItem);
     675    markSettingsChanged();
     676}
     677
     678void VBoxVMSettingsUSB::showContextMenu (const QPoint &aPos)
     679{
     680    mMenu->exec (mTwFilters->mapToGlobal (aPos));
     681}
     682
     683void VBoxVMSettingsUSB::sltUpdateActivityState(QTreeWidgetItem *pChangedItem)
     684{
     685    /* Check changed USB filter item: */
     686    Assert(pChangedItem);
     687
     688    /* Delete corresponding items: */
     689    UIUSBFilterData &data = m_cache.m_items[mTwFilters->indexOfTopLevelItem(pChangedItem)];
     690    data.m_fActive = pChangedItem->checkState(0) == Qt::Checked;
     691
     692    markSettingsChanged();
     693}
     694
     695void VBoxVMSettingsUSB::markSettingsChanged()
     696{
    551697    mUSBFilterListModified = true;
    552698}
    553699
    554 void VBoxVMSettingsUSB::showContextMenu (const QPoint &aPos)
    555 {
    556     mMenu->exec (mTwFilters->mapToGlobal (aPos));
    557 }
    558 
    559 void VBoxVMSettingsUSB::markSettingsChanged()
    560 {
    561     mUSBFilterListModified = true;
    562 }
    563 
    564 void VBoxVMSettingsUSB::addUSBFilter (const CUSBDeviceFilter &aFilter,
    565                                       bool isNew)
    566 {
    567     QTreeWidgetItem *currentItem = isNew ?
    568         mTwFilters->currentItem() :
    569         mTwFilters->topLevelItem (mTwFilters->topLevelItemCount() - 1);
    570 
    571     int pos = currentItem ? mTwFilters->indexOfTopLevelItem (currentItem) : -1;
    572     mFilters.insert (pos + 1, aFilter);
    573 
    574     QTreeWidgetItem *item = pos >= 0 ?
    575         new QTreeWidgetItem (mTwFilters, mTwFilters->topLevelItem (pos)) :
    576         new QTreeWidgetItem (mTwFilters);
    577     item->setCheckState (0, aFilter.GetActive() ? Qt::Checked : Qt::Unchecked);
    578     item->setText (0, aFilter.GetName());
    579     item->setToolTip (0, vboxGlobal().toolTip (aFilter));
    580 
    581     if (isNew)
    582         mTwFilters->setCurrentItem (item);
    583 
    584     if (mValidator)
    585         mValidator->revalidate();
    586 }
    587 
     700void VBoxVMSettingsUSB::addUSBFilter(const UIUSBFilterData &data, bool fIsNew)
     701{
     702    /* Append tree-widget with item: */
     703    QTreeWidgetItem *pItem = new QTreeWidgetItem;
     704    pItem->setCheckState(0, data.m_fActive ? Qt::Checked : Qt::Unchecked);
     705    pItem->setText(0, data.m_strName);
     706    pItem->setToolTip(0, toolTipFor(data));
     707    mTwFilters->addTopLevelItem(pItem);
     708
     709    /* Select this item if its new: */
     710    if (fIsNew)
     711        mTwFilters->setCurrentItem(pItem);
     712}
     713
     714/* Fetch data to m_properties & m_settings or m_machine: */
     715void VBoxVMSettingsUSB::fetchData(const QVariant &data)
     716{
     717    switch (type())
     718    {
     719        case UISettingsPageType_Global:
     720        {
     721            m_properties = data.value<UISettingsDataGlobal>().m_properties;
     722            m_settings = data.value<UISettingsDataGlobal>().m_settings;
     723            break;
     724        }
     725        case UISettingsPageType_Machine:
     726        {
     727            m_machine = data.value<UISettingsDataMachine>().m_machine;
     728            break;
     729        }
     730        default:
     731            break;
     732    }
     733}
     734
     735/* Upload m_properties & m_settings or m_machine to data: */
     736void VBoxVMSettingsUSB::uploadData(QVariant &data) const
     737{
     738    switch (type())
     739    {
     740        case UISettingsPageType_Global:
     741        {
     742            data = QVariant::fromValue(UISettingsDataGlobal(m_properties, m_settings));
     743            break;
     744        }
     745        case UISettingsPageType_Machine:
     746        {
     747            data = QVariant::fromValue(UISettingsDataMachine(m_machine));
     748            break;
     749        }
     750        default:
     751            break;
     752    }
     753}
     754
     755/* static */ QString VBoxVMSettingsUSB::toolTipFor(const UIUSBFilterData &data)
     756{
     757    /* Prepare tool-tip: */
     758    QString strToolTip;
     759
     760    QString strVendorId = data.m_strVendorId;
     761    if (!strVendorId.isEmpty())
     762        strToolTip += tr("<nobr>Vendor ID: %1</nobr>", "USB filter tooltip").arg(strVendorId);
     763
     764    QString strProductId = data.m_strProductId;
     765    if (!strProductId.isEmpty())
     766        strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product ID: %2</nobr>", "USB filter tooltip").arg(strProductId);
     767
     768    QString strRevision = data.m_strRevision;
     769    if (!strRevision.isEmpty())
     770        strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Revision: %3</nobr>", "USB filter tooltip").arg(strRevision);
     771
     772    QString strProduct = data.m_strProduct;
     773    if (!strProduct.isEmpty())
     774        strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product: %4</nobr>", "USB filter tooltip").arg(strProduct);
     775
     776    QString strManufacturer = data.m_strManufacturer;
     777    if (!strManufacturer.isEmpty())
     778        strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip").arg(strManufacturer);
     779
     780    QString strSerial = data.m_strSerialNumber;
     781    if (!strSerial.isEmpty())
     782        strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Serial No.: %1</nobr>", "USB filter tooltip").arg(strSerial);
     783
     784    QString strPort = data.m_strPort;
     785    if (!strPort.isEmpty())
     786        strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Port: %1</nobr>", "USB filter tooltip").arg(strPort);
     787
     788    /* Add the state field if it's a host USB device: */
     789    if (data.m_fHostUSBDevice)
     790    {
     791        strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>State: %1</nobr>", "USB filter tooltip")
     792                                                          .arg(vboxGlobal().toString(data.m_hostUSBDeviceState));
     793    }
     794
     795    return strToolTip;
     796}
     797
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsUSB.h

    r32814 r33631  
    66
    77/*
    8  * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2006-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626class VBoxUSBMenu;
    2727
     28/* Common settings / USB page / Filter data: */
     29struct UIUSBFilterData
     30{
     31    /* Common: */
     32    bool m_fActive;
     33    QString m_strName;
     34    QString m_strVendorId;
     35    QString m_strProductId;
     36    QString m_strRevision;
     37    QString m_strManufacturer;
     38    QString m_strProduct;
     39    QString m_strSerialNumber;
     40    QString m_strPort;
     41    QString m_strRemote;
     42
     43    /* Host only: */
     44    KUSBDeviceFilterAction m_action;
     45    bool m_fHostUSBDevice;
     46    KUSBDeviceState m_hostUSBDeviceState;
     47};
     48
     49/* Common settings / USB page / Cache: */
     50struct UISettingsCacheCommonUSB
     51{
     52    bool m_fUSBEnabled;
     53    bool m_fEHCIEnabled;
     54    QList<UIUSBFilterData> m_items;
     55};
     56
     57/* Common settings / USB page: */
    2858class VBoxVMSettingsUSB : public UISettingsPage,
    2959                          public Ui::VBoxVMSettingsUSB
     
    3262
    3363public:
    34 
    35     enum FilterType
    36     {
    37         WrongType = 0,
    38         HostType = 1,
    39         MachineType = 2
    40     };
    4164
    4265    enum RemoteMode
     
    4770    };
    4871
    49     VBoxVMSettingsUSB (FilterType aType);
     72    VBoxVMSettingsUSB(UISettingsPageType type);
    5073
    5174    bool isOHCIEnabled() const;
     
    5376protected:
    5477
    55     void getFrom (const CSystemProperties &aProps,
    56                   const VBoxGlobalSettings &aGs);
    57     void putBackTo (CSystemProperties &aProps,
    58                     VBoxGlobalSettings &aGs);
     78    /* Load data to cashe from corresponding external object(s),
     79     * this task COULD be performed in other than GUI thread: */
     80    void loadToCacheFrom(QVariant &data);
     81    /* Load data to corresponding widgets from cache,
     82     * this task SHOULD be performed in GUI thread only: */
     83    void getFromCache();
    5984
    60     void getFrom (const CMachine &aMachine);
    61     void putBackTo();
     85    /* Save data from corresponding widgets to cache,
     86     * this task SHOULD be performed in GUI thread only: */
     87    void putToCache();
     88    /* Save data from cache to corresponding external object(s),
     89     * this task COULD be performed in other than GUI thread: */
     90    void saveFromCacheTo(QVariant &data);
    6291
    6392    void setValidator (QIWidgetValidator *aVal);
     
    81110    void mdnClicked();
    82111    void showContextMenu (const QPoint &aPos);
     112    void sltUpdateActivityState(QTreeWidgetItem *pChangedItem);
    83113    void markSettingsChanged();
    84114
    85115private:
    86116
    87     void addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew);
     117    void addUSBFilter(const UIUSBFilterData &data, bool fIsNew);
    88118
    89     CMachine mMachine;
     119    /* Fetch data to m_properties, m_settings or m_machine: */
     120    void fetchData(const QVariant &data);
     121
     122    /* Upload m_properties, m_settings or m_machine to data: */
     123    void uploadData(QVariant &data) const;
     124
     125    /* Returns the multi-line description of the given USB filter: */
     126    static QString toolTipFor(const UIUSBFilterData &data);
     127
     128    /* Global data source: */
     129    CSystemProperties m_properties;
     130    VBoxGlobalSettings m_settings;
     131
     132    /* Machine data source: */
     133    CMachine m_machine;
     134
     135    /* Other variables: */
    90136    QIWidgetValidator *mValidator;
    91     FilterType mType;
    92137    QAction *mNewAction;
    93138    QAction *mAddAction;
     
    99144    VBoxUSBMenu *mUSBDevicesMenu;
    100145    bool mUSBFilterListModified;
    101     QList<CUSBDeviceFilter> mFilters;
     146    QString mUSBFilterName;
    102147
    103     QString mUSBFilterName;
     148    /* Cache: */
     149    UISettingsCacheCommonUSB m_cache;
    104150};
    105151
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsUSBFilterDetails.cpp

    r28800 r33631  
    77
    88/*
    9  * Copyright (C) 2008 Oracle Corporation
     9 * Copyright (C) 2008-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121#include "VBoxGlobal.h"
    2222
    23 VBoxVMSettingsUSBFilterDetails::VBoxVMSettingsUSBFilterDetails (VBoxVMSettingsUSB::FilterType aType, QWidget *aParent /* = NULL */)
    24     : QIWithRetranslateUI2<QIDialog> (aParent, Qt::Sheet)
    25     , mType (aType)
     23VBoxVMSettingsUSBFilterDetails::VBoxVMSettingsUSBFilterDetails(UISettingsPageType type, QWidget *pParent /* = 0 */)
     24    : QIWithRetranslateUI2<QIDialog>(pParent, Qt::Sheet)
     25    , m_type(type)
    2626{
    2727    /* Apply UI decorations */
     
    3131    mCbRemote->insertItem (VBoxVMSettingsUSB::ModeOn,  ""); /* Yes */
    3232    mCbRemote->insertItem (VBoxVMSettingsUSB::ModeOff, ""); /* No */
    33     mLbRemote->setHidden (mType != VBoxVMSettingsUSB::MachineType);
    34     mCbRemote->setHidden (mType != VBoxVMSettingsUSB::MachineType);
     33    mLbRemote->setHidden (m_type != UISettingsPageType_Machine);
     34    mCbRemote->setHidden (m_type != UISettingsPageType_Machine);
    3535
    3636    mCbAction->insertItem (0, ""); /* KUSBDeviceFilterAction_Ignore */
    3737    mCbAction->insertItem (1, ""); /* KUSBDeviceFilterAction_Hold */
    38     mLbAction->setHidden (mType != VBoxVMSettingsUSB::HostType);
    39     mCbAction->setHidden (mType != VBoxVMSettingsUSB::HostType);
     38    mLbAction->setHidden (m_type != UISettingsPageType_Global);
     39    mCbAction->setHidden (m_type != UISettingsPageType_Global);
    4040
    4141    mLeName->setValidator (new QRegExpValidator (QRegExp (".+"), this));
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsUSBFilterDetails.h

    r28800 r33631  
    66
    77/*
    8  * Copyright (C) 2008 Oracle Corporation
     8 * Copyright (C) 2008-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232public:
    3333
    34     VBoxVMSettingsUSBFilterDetails (VBoxVMSettingsUSB::FilterType aType, QWidget *aParent = NULL);
     34    VBoxVMSettingsUSBFilterDetails(UISettingsPageType type, QWidget *pParent = 0);
    3535
    3636protected:
     
    4141
    4242    /* Private member vars */
    43     VBoxVMSettingsUSB::FilterType mType;
     43    UISettingsPageType m_type;
    4444};
    4545
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