VirtualBox

Changeset 72092 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 3, 2018 12:55:48 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and huge cleanup for UISettingsDialogSpecific and move it to VBoxGlobal library.

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

Legend:

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

    r72059 r72092  
    520520        src/selector/graphics/details/UIGDetailsElements.h \
    521521        src/selector/graphics/details/UIGMachinePreview.h \
    522         src/settings/UISettingsDialogSpecific.h \
    523522        src/settings/UISettingsPage.h \
    524523        src/settings/UISettingsSelector.h \
     
    664663        src/selector/UIVirtualBoxEventHandler.h \
    665664        src/settings/UISettingsDialog.h \
     665        src/settings/UISettingsDialogSpecific.h \
    666666        src/widgets/UIAddDiskEncryptionPasswordDialog.h \
    667667        src/widgets/UIBootTable.h \
     
    778778        src/selector/UIVirtualBoxEventHandler.h \
    779779        src/settings/UISettingsDialog.h \
     780        src/settings/UISettingsDialogSpecific.h \
    780781        src/widgets/UIAddDiskEncryptionPasswordDialog.h \
    781782        src/widgets/UIBootTable.h \
     
    10351036        src/selector/graphics/details/UIGDetailsElements.cpp \
    10361037        src/selector/graphics/details/UIGMachinePreview.cpp \
    1037         src/settings/UISettingsDialogSpecific.cpp \
    10381038        src/settings/UISettingsPage.cpp \
    10391039        src/settings/UISettingsSelector.cpp \
     
    12201220        src/settings/UISettingsDefs.cpp \
    12211221        src/settings/UISettingsDialog.cpp \
     1222        src/settings/UISettingsDialogSpecific.cpp \
    12221223        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    12231224        src/widgets/UIBootTable.cpp \
     
    13611362        src/settings/UISettingsDefs.cpp \
    13621363        src/settings/UISettingsDialog.cpp \
     1364        src/settings/UISettingsDialogSpecific.cpp \
    13631365        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    13641366        src/widgets/UIBootTable.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r71027 r72092  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* GUI includes: */
     23# include "QIWidgetValidator.h"
     24# include "VBoxGlobal.h"
     25# include "UIExtraDataManager.h"
     26# include "UIMessageCenter.h"
     27# include "UISettingsDefs.h"
    2328# include "UISettingsDialogSpecific.h"
    2429# include "UISettingsSerializer.h"
    25 # include "UISettingsDefs.h"
    26 # include "VBoxGlobal.h"
    27 # include "UIMessageCenter.h"
    28 # include "UIExtraDataManager.h"
    29 # include "QIWidgetValidator.h"
    3030# include "UISettingsSelector.h"
    3131# include "UIVirtualBoxEventHandler.h"
    3232
     33/* GUI includes: Global Preferences: */
     34# include "UIGlobalSettingsDisplay.h"
     35# include "UIGlobalSettingsExtension.h"
    3336# include "UIGlobalSettingsGeneral.h"
    3437# include "UIGlobalSettingsInput.h"
    35 # ifdef VBOX_GUI_WITH_NETWORK_MANAGER
    36 #  include "UIGlobalSettingsUpdate.h"
    37 # endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
    3838# include "UIGlobalSettingsLanguage.h"
    39 # include "UIGlobalSettingsDisplay.h"
    4039# include "UIGlobalSettingsNetwork.h"
    41 # include "UIGlobalSettingsExtension.h"
    4240# ifdef VBOX_GUI_WITH_NETWORK_MANAGER
    4341#  include "UIGlobalSettingsProxy.h"
    44 # endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
    45 
     42#  include "UIGlobalSettingsUpdate.h"
     43# endif
     44
     45/* GUI includes: Machine Settings: */
     46# include "UIMachineSettingsAudio.h"
     47# include "UIMachineSettingsDisplay.h"
    4648# include "UIMachineSettingsGeneral.h"
    47 # include "UIMachineSettingsSystem.h"
    48 # include "UIMachineSettingsDisplay.h"
    49 # include "UIMachineSettingsStorage.h"
    50 # include "UIMachineSettingsAudio.h"
     49# include "UIMachineSettingsInterface.h"
    5150# include "UIMachineSettingsNetwork.h"
    5251# include "UIMachineSettingsSerial.h"
     52# include "UIMachineSettingsSF.h"
     53# include "UIMachineSettingsStorage.h"
     54# include "UIMachineSettingsSystem.h"
    5355# include "UIMachineSettingsUSB.h"
    54 # include "UIMachineSettingsSF.h"
    55 # include "UIMachineSettingsInterface.h"
    5656
    5757/* COM includes: */
     
    6262#ifdef VBOX_WS_MAC
    6363# define VBOX_GUI_WITH_TOOLBAR_SETTINGS
    64 #endif /* VBOX_WS_MAC */
     64#endif
     65
     66
     67/*********************************************************************************************************************************
     68*   Class UISettingsDialogGlobal implementation.                                                                                 *
     69*********************************************************************************************************************************/
    6570
    6671UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent,
     
    6873                                               const QString &strControl /* = QString() */)
    6974    : UISettingsDialog(pParent)
     75    , m_strCategory(strCategory)
     76    , m_strControl(strControl)
     77{
     78    /* Prepare: */
     79    prepare();
     80}
     81
     82void UISettingsDialogGlobal::retranslateUi()
     83{
     84    /* Selector itself: */
     85    m_pSelector->widget()->setWhatsThis(tr("Allows to navigate through Global Property categories"));
     86
     87    /* General page: */
     88    m_pSelector->setItemText(GlobalSettingsPageType_General, tr("General"));
     89
     90    /* Input page: */
     91    m_pSelector->setItemText(GlobalSettingsPageType_Input, tr("Input"));
     92
     93#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
     94    /* Update page: */
     95    m_pSelector->setItemText(GlobalSettingsPageType_Update, tr("Update"));
     96#endif
     97
     98    /* Language page: */
     99    m_pSelector->setItemText(GlobalSettingsPageType_Language, tr("Language"));
     100
     101    /* Display page: */
     102    m_pSelector->setItemText(GlobalSettingsPageType_Display, tr("Display"));
     103
     104    /* Network page: */
     105    m_pSelector->setItemText(GlobalSettingsPageType_Network, tr("Network"));
     106
     107    /* Extension page: */
     108    m_pSelector->setItemText(GlobalSettingsPageType_Extensions, tr("Extensions"));
     109
     110#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
     111    /* Proxy page: */
     112    m_pSelector->setItemText(GlobalSettingsPageType_Proxy, tr("Proxy"));
     113#endif
     114
     115    /* Polish the selector: */
     116    m_pSelector->polish();
     117
     118    /* Base-class UI translation: */
     119    UISettingsDialog::retranslateUi();
     120
     121    /* Set dialog's name: */
     122    setWindowTitle(title());
     123}
     124
     125void UISettingsDialogGlobal::loadOwnData()
     126{
     127    /* Get properties: */
     128    CSystemProperties comProperties = vboxGlobal().virtualBox().GetSystemProperties();
     129    /* Prepare global data: */
     130    qRegisterMetaType<UISettingsDataGlobal>();
     131    UISettingsDataGlobal data(comProperties);
     132    QVariant varData = QVariant::fromValue(data);
     133
     134    /* Call to base-class: */
     135    UISettingsDialog::loadData(varData);
     136}
     137
     138void UISettingsDialogGlobal::saveOwnData()
     139{
     140    /* Get properties: */
     141    CSystemProperties comProperties = vboxGlobal().virtualBox().GetSystemProperties();
     142    /* Prepare global data: */
     143    qRegisterMetaType<UISettingsDataGlobal>();
     144    UISettingsDataGlobal data(comProperties);
     145    QVariant varData = QVariant::fromValue(data);
     146
     147    /* Call to base-class: */
     148    UISettingsDialog::saveData(varData);
     149
     150    /* Get updated properties: */
     151    CSystemProperties comNewProperties = varData.value<UISettingsDataGlobal>().m_properties;
     152    /* If properties are not OK => show the error: */
     153    if (!comNewProperties.isOk())
     154        msgCenter().cannotSetSystemProperties(comNewProperties, this);
     155
     156    /* Mark as saved: */
     157    sltMarkSaved();
     158}
     159
     160QString UISettingsDialogGlobal::titleExtension() const
     161{
     162#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     163    return m_pSelector->itemText(m_pSelector->currentId());
     164#else
     165    return tr("Preferences");
     166#endif
     167}
     168
     169QString UISettingsDialogGlobal::title() const
     170{
     171    return tr("VirtualBox - %1").arg(titleExtension());
     172}
     173
     174void UISettingsDialogGlobal::prepare()
    70175{
    71176    /* Window icon: */
    72177#ifndef VBOX_WS_MAC
    73178    setWindowIcon(QIcon(":/global_settings_16px.png"));
    74 #endif /* !VBOX_WS_MAC */
     179#endif
    75180
    76181    /* Creating settings pages: */
     
    165270    setConfigurationAccessLevel(ConfigurationAccessLevel_Full);
    166271
    167     /* Retranslate UI: */
     272    /* Apply language settings: */
    168273    retranslateUi();
    169274
    170275    /* Setup settings window: */
    171     if (!strCategory.isNull())
    172     {
    173         m_pSelector->selectByLink(strCategory);
     276    if (!m_strCategory.isNull())
     277    {
     278        m_pSelector->selectByLink(m_strCategory);
    174279        /* Search for a widget with the given name: */
    175         if (!strControl.isNull())
    176         {
    177             if (QWidget *pWidget = m_pStack->findChild<QWidget*>(strControl))
     280        if (!m_strControl.isNull())
     281        {
     282            if (QWidget *pWidget = m_pStack->findChild<QWidget*>(m_strControl))
    178283            {
    179284                QList<QWidget*> parents;
     
    183288                    if (QTabWidget *pTabWidget = qobject_cast<QTabWidget*>(pParentWidget))
    184289                    {
    185                         /* The tab contents widget is two steps down
    186                          * (QTabWidget -> QStackedWidget -> QWidget): */
     290                        // WORKAROUND:
     291                        // The tab contents widget is two steps down
     292                        // (QTabWidget -> QStackedWidget -> QWidget).
    187293                        QWidget *pTabPage = parents[parents.count() - 1];
    188294                        if (pTabPage)
     
    202308}
    203309
    204 void UISettingsDialogGlobal::loadOwnData()
    205 {
    206     /* Get properties: */
    207     CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties();
    208     /* Prepare global data: */
    209     qRegisterMetaType<UISettingsDataGlobal>();
    210     UISettingsDataGlobal data(properties);
    211     QVariant varData = QVariant::fromValue(data);
    212 
    213     /* Call to base-class: */
    214     UISettingsDialog::loadData(varData);
    215 }
    216 
    217 void UISettingsDialogGlobal::saveOwnData()
    218 {
    219     /* Get properties: */
    220     CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties();
    221     /* Prepare global data: */
    222     qRegisterMetaType<UISettingsDataGlobal>();
    223     UISettingsDataGlobal data(properties);
    224     QVariant varData = QVariant::fromValue(data);
    225 
    226     /* Call to base-class: */
    227     UISettingsDialog::saveData(varData);
    228 
    229     /* Get updated properties: */
    230     CSystemProperties newProperties = varData.value<UISettingsDataGlobal>().m_properties;
    231     /* If properties are not OK => show the error: */
    232     if (!newProperties.isOk())
    233         msgCenter().cannotSetSystemProperties(newProperties, this);
    234 
    235     /* Mark as saved: */
    236     sltMarkSaved();
    237 }
    238 
    239 void UISettingsDialogGlobal::retranslateUi()
    240 {
    241     /* Selector itself: */
    242     m_pSelector->widget()->setWhatsThis(tr("Allows to navigate through Global Property categories"));
    243 
    244     /* General page: */
    245     m_pSelector->setItemText(GlobalSettingsPageType_General, tr("General"));
    246 
    247     /* Input page: */
    248     m_pSelector->setItemText(GlobalSettingsPageType_Input, tr("Input"));
    249 
    250 #ifdef VBOX_GUI_WITH_NETWORK_MANAGER
    251     /* Update page: */
    252     m_pSelector->setItemText(GlobalSettingsPageType_Update, tr("Update"));
    253 #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
    254 
    255     /* Language page: */
    256     m_pSelector->setItemText(GlobalSettingsPageType_Language, tr("Language"));
    257 
    258     /* Display page: */
    259     m_pSelector->setItemText(GlobalSettingsPageType_Display, tr("Display"));
    260 
    261     /* Network page: */
    262     m_pSelector->setItemText(GlobalSettingsPageType_Network, tr("Network"));
    263 
    264     /* Extension page: */
    265     m_pSelector->setItemText(GlobalSettingsPageType_Extensions, tr("Extensions"));
    266 
    267 #ifdef VBOX_GUI_WITH_NETWORK_MANAGER
    268     /* Proxy page: */
    269     m_pSelector->setItemText(GlobalSettingsPageType_Proxy, tr("Proxy"));
    270 #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
    271 
    272     /* Polish the selector: */
    273     m_pSelector->polish();
    274 
    275     /* Base-class UI translation: */
    276     UISettingsDialog::retranslateUi();
    277 
    278     /* Set dialog's name: */
    279     setWindowTitle(title());
    280 }
    281 
    282 QString UISettingsDialogGlobal::titleExtension() const
    283 {
    284 #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    285     return m_pSelector->itemText(m_pSelector->currentId());
    286 #else /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
    287     return tr("Preferences");
    288 #endif /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
    289 }
    290 
    291 QString UISettingsDialogGlobal::title() const
    292 {
    293     return tr("VirtualBox - %1").arg(titleExtension());
    294 }
    295 
    296 bool UISettingsDialogGlobal::isPageAvailable(int iPageId)
     310bool UISettingsDialogGlobal::isPageAvailable(int iPageId) const
    297311{
    298312    switch (iPageId)
     
    302316#ifndef VBOX_WITH_NETFLT
    303317            return false;
    304 #endif /* !VBOX_WITH_NETFLT */
     318#endif
    305319            break;
    306320        }
     
    310324    return true;
    311325}
     326
     327
     328/*********************************************************************************************************************************
     329*   Class UISettingsDialogMachine implementation.                                                                                *
     330*********************************************************************************************************************************/
    312331
    313332UISettingsDialogMachine::UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
     
    315334    : UISettingsDialog(pParent)
    316335    , m_strMachineId(strMachineId)
     336    , m_strCategory(strCategory)
     337    , m_strControl(strControl)
    317338    , m_fAllowResetFirstRunFlag(false)
    318339    , m_fResetFirstRunFlag(false)
    319340{
    320     /* Window icon: */
    321 #ifndef VBOX_WS_MAC
    322     setWindowIcon(QIcon(":/vm_settings_16px.png"));
    323 #endif /* VBOX_WS_MAC */
    324 
    325     /* Allow to reset first-run flag just when medium enumeration was finished: */
    326     connect(&vboxGlobal(), SIGNAL(sigMediumEnumerationFinished()), this, SLOT(sltAllowResetFirstRunFlag()));
    327 
    328     /* Make sure settings window will be updated on session/machine state/data changes: */
    329     connect(gVBoxEvents, SIGNAL(sigSessionStateChange(QString, KSessionState)),
    330             this, SLOT(sltSessionStateChanged(QString, KSessionState)));
    331     connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QString, KMachineState)),
    332             this, SLOT(sltMachineStateChanged(QString, KMachineState)));
    333     connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)),
    334             this, SLOT(sltMachineDataChanged(QString)));
    335 
    336     /* Get corresponding machine (required to determine dialog type and page availability): */
    337     m_machine = vboxGlobal().virtualBox().FindMachine(m_strMachineId);
    338     AssertMsg(!m_machine.isNull(), ("Can't find corresponding machine!\n"));
    339     m_sessionState = m_machine.GetSessionState();
    340     m_machineState = m_machine.GetState();
    341 
    342     /* Creating settings pages: */
    343     QList<MachineSettingsPageType> restrictedMachineSettingsPages = gEDataManager->restrictedMachineSettingsPages(m_strMachineId);
    344     for (int iPageIndex = MachineSettingsPageType_General; iPageIndex < MachineSettingsPageType_Max; ++iPageIndex)
    345     {
    346         /* Make sure page was not restricted: */
    347         if (restrictedMachineSettingsPages.contains(static_cast<MachineSettingsPageType>(iPageIndex)))
    348             continue;
    349 
    350         /* Make sure page is available: */
    351         if (isPageAvailable(iPageIndex))
    352         {
    353             UISettingsPage *pSettingsPage = 0;
    354             switch (iPageIndex)
    355             {
    356                 /* General page: */
    357                 case MachineSettingsPageType_General:
    358                 {
    359                     pSettingsPage = new UIMachineSettingsGeneral;
    360                     addItem(":/machine_32px.png", ":/machine_24px.png", ":/machine_16px.png",
    361                             iPageIndex, "#general", pSettingsPage);
    362                     break;
    363                 }
    364                 /* System page: */
    365                 case MachineSettingsPageType_System:
    366                 {
    367                     pSettingsPage = new UIMachineSettingsSystem;
    368                     addItem(":/chipset_32px.png", ":/chipset_24px.png", ":/chipset_16px.png",
    369                             iPageIndex, "#system", pSettingsPage);
    370                     break;
    371                 }
    372                 /* Display page: */
    373                 case MachineSettingsPageType_Display:
    374                 {
    375                     pSettingsPage = new UIMachineSettingsDisplay;
    376                     addItem(":/vrdp_32px.png", ":/vrdp_24px.png", ":/vrdp_16px.png",
    377                             iPageIndex, "#display", pSettingsPage);
    378                     break;
    379                 }
    380                 /* Storage page: */
    381                 case MachineSettingsPageType_Storage:
    382                 {
    383                     pSettingsPage = new UIMachineSettingsStorage;
    384                     connect(pSettingsPage, SIGNAL(sigStorageChanged()), this, SLOT(sltResetFirstRunFlag()));
    385                     addItem(":/hd_32px.png", ":/hd_24px.png", ":/hd_16px.png",
    386                             iPageIndex, "#storage", pSettingsPage);
    387                     break;
    388                 }
    389                 /* Audio page: */
    390                 case MachineSettingsPageType_Audio:
    391                 {
    392                     pSettingsPage = new UIMachineSettingsAudio;
    393                     addItem(":/sound_32px.png", ":/sound_24px.png", ":/sound_16px.png",
    394                             iPageIndex, "#audio", pSettingsPage);
    395                     break;
    396                 }
    397                 /* Network page: */
    398                 case MachineSettingsPageType_Network:
    399                 {
    400                     pSettingsPage = new UIMachineSettingsNetworkPage;
    401                     addItem(":/nw_32px.png", ":/nw_24px.png", ":/nw_16px.png",
    402                             iPageIndex, "#network", pSettingsPage);
    403                     break;
    404                 }
    405                 /* Ports page: */
    406                 case MachineSettingsPageType_Ports:
    407                 {
    408                     addItem(":/serial_port_32px.png", ":/serial_port_24px.png", ":/serial_port_16px.png",
    409                             iPageIndex, "#ports");
    410                     break;
    411                 }
    412                 /* Serial page: */
    413                 case MachineSettingsPageType_Serial:
    414                 {
    415                     pSettingsPage = new UIMachineSettingsSerialPage;
    416                     addItem(":/serial_port_32px.png", ":/serial_port_24px.png", ":/serial_port_16px.png",
    417                             iPageIndex, "#serialPorts", pSettingsPage, MachineSettingsPageType_Ports);
    418                     break;
    419                 }
    420                 /* USB page: */
    421                 case MachineSettingsPageType_USB:
    422                 {
    423                     pSettingsPage = new UIMachineSettingsUSB;
    424                     addItem(":/usb_32px.png", ":/usb_24px.png", ":/usb_16px.png",
    425                             iPageIndex, "#usb", pSettingsPage, MachineSettingsPageType_Ports);
    426                     break;
    427                 }
    428                 /* Shared Folders page: */
    429                 case MachineSettingsPageType_SF:
    430                 {
    431                     pSettingsPage = new UIMachineSettingsSF;
    432                     addItem(":/sf_32px.png", ":/sf_24px.png", ":/sf_16px.png",
    433                             iPageIndex, "#sharedFolders", pSettingsPage);
    434                     break;
    435                 }
    436                 /* Interface page: */
    437                 case MachineSettingsPageType_Interface:
    438                 {
    439                     pSettingsPage = new UIMachineSettingsInterface(m_machine.GetId());
    440                     addItem(":/interface_32px.png", ":/interface_24px.png", ":/interface_16px.png",
    441                             iPageIndex, "#userInterface", pSettingsPage);
    442                     break;
    443                 }
    444                 default:
    445                     break;
    446             }
    447         }
    448     }
    449 
    450     /* Calculate initial configuration access level: */
    451     setConfigurationAccessLevel(::configurationAccessLevel(m_sessionState, m_machineState));
    452 
    453     /* Retranslate UI: */
    454     retranslateUi();
    455 
    456     /* Setup settings window: */
    457     if (!strCategory.isNull())
    458     {
    459         m_pSelector->selectByLink(strCategory);
    460         /* Search for a widget with the given name: */
    461         if (!strControl.isNull())
    462         {
    463             if (QWidget *pWidget = m_pStack->findChild<QWidget*>(strControl))
    464             {
    465                 QList<QWidget*> parents;
    466                 QWidget *pParentWidget = pWidget;
    467                 while ((pParentWidget = pParentWidget->parentWidget()) != 0)
    468                 {
    469                     if (QTabWidget *pTabWidget = qobject_cast<QTabWidget*>(pParentWidget))
    470                     {
    471                         /* The tab contents widget is two steps down
    472                          * (QTabWidget -> QStackedWidget -> QWidget): */
    473                         QWidget *pTabPage = parents[parents.count() - 1];
    474                         if (pTabPage)
    475                             pTabPage = parents[parents.count() - 2];
    476                         if (pTabPage)
    477                             pTabWidget->setCurrentWidget(pTabPage);
    478                     }
    479                     parents.append(pParentWidget);
    480                 }
    481                 pWidget->setFocus();
    482             }
    483         }
    484     }
    485     /* First item as default: */
    486     else
    487         m_pSelector->selectById(MachineSettingsPageType_General);
     341    /* Prepare: */
     342    prepare();
     343}
     344
     345void UISettingsDialogMachine::retranslateUi()
     346{
     347    /* Selector itself: */
     348    m_pSelector->widget()->setWhatsThis(tr("Allows to navigate through VM Settings categories"));
     349
     350    /* We have to make sure that the Network, Serial pages are retranslated
     351     * before they are revalidated. Cause: They do string comparing within
     352     * vboxGlobal which is retranslated at that point already: */
     353    QEvent event(QEvent::LanguageChange);
     354    if (QWidget *pPage = m_pSelector->idToPage(MachineSettingsPageType_Network))
     355        qApp->sendEvent(pPage, &event);
     356    if (QWidget *pPage = m_pSelector->idToPage(MachineSettingsPageType_Serial))
     357        qApp->sendEvent(pPage, &event);
     358
     359    /* General page: */
     360    m_pSelector->setItemText(MachineSettingsPageType_General, tr("General"));
     361
     362    /* System page: */
     363    m_pSelector->setItemText(MachineSettingsPageType_System, tr("System"));
     364
     365    /* Display page: */
     366    m_pSelector->setItemText(MachineSettingsPageType_Display, tr("Display"));
     367
     368    /* Storage page: */
     369    m_pSelector->setItemText(MachineSettingsPageType_Storage, tr("Storage"));
     370
     371    /* Audio page: */
     372    m_pSelector->setItemText(MachineSettingsPageType_Audio, tr("Audio"));
     373
     374    /* Network page: */
     375    m_pSelector->setItemText(MachineSettingsPageType_Network, tr("Network"));
     376
     377    /* Ports page: */
     378    m_pSelector->setItemText(MachineSettingsPageType_Ports, tr("Ports"));
     379
     380    /* Serial page: */
     381    m_pSelector->setItemText(MachineSettingsPageType_Serial, tr("Serial Ports"));
     382
     383    /* USB page: */
     384    m_pSelector->setItemText(MachineSettingsPageType_USB, tr("USB"));
     385
     386    /* SFolders page: */
     387    m_pSelector->setItemText(MachineSettingsPageType_SF, tr("Shared Folders"));
     388
     389    /* Interface page: */
     390    m_pSelector->setItemText(MachineSettingsPageType_Interface, tr("User Interface"));
     391
     392    /* Polish the selector: */
     393    m_pSelector->polish();
     394
     395    /* Base-class UI translation: */
     396    UISettingsDialog::retranslateUi();
     397
     398    /* Set dialog's name: */
     399    setWindowTitle(title());
    488400}
    489401
     
    584496}
    585497
    586 void UISettingsDialogMachine::retranslateUi()
    587 {
    588     /* Selector itself: */
    589     m_pSelector->widget()->setWhatsThis(tr("Allows to navigate through VM Settings categories"));
    590 
    591     /* We have to make sure that the Network, Serial pages are retranslated
    592      * before they are revalidated. Cause: They do string comparing within
    593      * vboxGlobal which is retranslated at that point already: */
    594     QEvent event(QEvent::LanguageChange);
    595     if (QWidget *pPage = m_pSelector->idToPage(MachineSettingsPageType_Network))
    596         qApp->sendEvent(pPage, &event);
    597     if (QWidget *pPage = m_pSelector->idToPage(MachineSettingsPageType_Serial))
    598         qApp->sendEvent(pPage, &event);
    599 
    600     /* General page: */
    601     m_pSelector->setItemText(MachineSettingsPageType_General, tr("General"));
    602 
    603     /* System page: */
    604     m_pSelector->setItemText(MachineSettingsPageType_System, tr("System"));
    605 
    606     /* Display page: */
    607     m_pSelector->setItemText(MachineSettingsPageType_Display, tr("Display"));
    608 
    609     /* Storage page: */
    610     m_pSelector->setItemText(MachineSettingsPageType_Storage, tr("Storage"));
    611 
    612     /* Audio page: */
    613     m_pSelector->setItemText(MachineSettingsPageType_Audio, tr("Audio"));
    614 
    615     /* Network page: */
    616     m_pSelector->setItemText(MachineSettingsPageType_Network, tr("Network"));
    617 
    618     /* Ports page: */
    619     m_pSelector->setItemText(MachineSettingsPageType_Ports, tr("Ports"));
    620 
    621     /* Serial page: */
    622     m_pSelector->setItemText(MachineSettingsPageType_Serial, tr("Serial Ports"));
    623 
    624     /* USB page: */
    625     m_pSelector->setItemText(MachineSettingsPageType_USB, tr("USB"));
    626 
    627     /* SFolders page: */
    628     m_pSelector->setItemText(MachineSettingsPageType_SF, tr("Shared Folders"));
    629 
    630     /* Interface page: */
    631     m_pSelector->setItemText(MachineSettingsPageType_Interface, tr("User Interface"));
    632 
    633     /* Polish the selector: */
    634     m_pSelector->polish();
    635 
    636     /* Base-class UI translation: */
    637     UISettingsDialog::retranslateUi();
    638 
    639     /* Set dialog's name: */
    640     setWindowTitle(title());
    641 }
    642 
    643498QString UISettingsDialogMachine::titleExtension() const
    644499{
    645500#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
    646501    return m_pSelector->itemText(m_pSelector->currentId());
    647 #else /* VBOX_GUI_WITH_TOOLBAR_SETTINGS */
     502#else
    648503    return tr("Settings");
    649 #endif /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
     504#endif
    650505}
    651506
     
    705560}
    706561
     562void UISettingsDialogMachine::sltCategoryChanged(int cId)
     563{
     564    /* Raise priority of requested page: */
     565    if (serializeProcess())
     566        serializeProcess()->raisePriorityOfPage(cId);
     567
     568    /* Call to base-class: */
     569    UISettingsDialog::sltCategoryChanged(cId);
     570}
     571
    707572void UISettingsDialogMachine::sltMarkLoaded()
    708573{
     
    738603}
    739604
    740 void UISettingsDialogMachine::sltSessionStateChanged(QString strMachineId, KSessionState sessionState)
     605void UISettingsDialogMachine::sltSessionStateChanged(QString strMachineId, KSessionState enmSessionState)
    741606{
    742607    /* Ignore if serialization is in progress: */
    743608    if (isSerializationInProgress())
    744609        return;
    745 
    746610    /* Ignore if thats NOT our VM: */
    747611    if (strMachineId != m_strMachineId)
     
    749613
    750614    /* Ignore if state was NOT actually changed: */
    751     if (m_sessionState == sessionState)
    752         return;
    753 
     615    if (m_enmSessionState == enmSessionState)
     616        return;
    754617    /* Update current session state: */
    755     m_sessionState = sessionState;
     618    m_enmSessionState = enmSessionState;
    756619
    757620    /* Recalculate configuration access level: */
     
    759622}
    760623
    761 void UISettingsDialogMachine::sltMachineStateChanged(QString strMachineId, KMachineState machineState)
     624void UISettingsDialogMachine::sltMachineStateChanged(QString strMachineId, KMachineState enmMachineState)
    762625{
    763626    /* Ignore if serialization is in progress: */
    764627    if (isSerializationInProgress())
    765628        return;
    766 
    767629    /* Ignore if thats NOT our VM: */
    768630    if (strMachineId != m_strMachineId)
     
    770632
    771633    /* Ignore if state was NOT actually changed: */
    772     if (m_machineState == machineState)
    773         return;
    774 
     634    if (m_enmMachineState == enmMachineState)
     635        return;
    775636    /* Update current machine state: */
    776     m_machineState = machineState;
     637    m_enmMachineState = enmMachineState;
    777638
    778639    /* Recalculate configuration access level: */
     
    785646    if (isSerializationInProgress())
    786647        return;
    787 
    788648    /* Ignore if thats NOT our VM: */
    789649    if (strMachineId != m_strMachineId)
     
    798658}
    799659
    800 void UISettingsDialogMachine::sltCategoryChanged(int cId)
    801 {
    802     if (serializeProcess())
    803         serializeProcess()->raisePriorityOfPage(cId);
    804 
    805     UISettingsDialog::sltCategoryChanged(cId);
    806 }
    807 
    808660void UISettingsDialogMachine::sltAllowResetFirstRunFlag()
    809661{
     
    817669}
    818670
    819 bool UISettingsDialogMachine::isPageAvailable(int iPageId)
     671void UISettingsDialogMachine::prepare()
     672{
     673    /* Window icon: */
     674#ifndef VBOX_WS_MAC
     675    setWindowIcon(QIcon(":/vm_settings_16px.png"));
     676#endif
     677
     678    /* Allow to reset first-run flag just when medium enumeration was finished: */
     679    connect(&vboxGlobal(), &VBoxGlobal::sigMediumEnumerationFinished,
     680            this, &UISettingsDialogMachine::sltAllowResetFirstRunFlag);
     681
     682    /* Make sure settings window will be updated on session/machine state/data changes: */
     683    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSessionStateChange,
     684            this, &UISettingsDialogMachine::sltSessionStateChanged);
     685    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
     686            this, &UISettingsDialogMachine::sltMachineStateChanged);
     687    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineDataChange,
     688            this, &UISettingsDialogMachine::sltMachineDataChanged);
     689
     690    /* Get corresponding machine (required to determine dialog type and page availability): */
     691    m_machine = vboxGlobal().virtualBox().FindMachine(m_strMachineId);
     692    AssertMsg(!m_machine.isNull(), ("Can't find corresponding machine!\n"));
     693    m_enmSessionState = m_machine.GetSessionState();
     694    m_enmMachineState = m_machine.GetState();
     695
     696    /* Creating settings pages: */
     697    QList<MachineSettingsPageType> restrictedMachineSettingsPages = gEDataManager->restrictedMachineSettingsPages(m_strMachineId);
     698    for (int iPageIndex = MachineSettingsPageType_General; iPageIndex < MachineSettingsPageType_Max; ++iPageIndex)
     699    {
     700        /* Make sure page was not restricted: */
     701        if (restrictedMachineSettingsPages.contains(static_cast<MachineSettingsPageType>(iPageIndex)))
     702            continue;
     703
     704        /* Make sure page is available: */
     705        if (isPageAvailable(iPageIndex))
     706        {
     707            UISettingsPage *pSettingsPage = 0;
     708            switch (iPageIndex)
     709            {
     710                /* General page: */
     711                case MachineSettingsPageType_General:
     712                {
     713                    pSettingsPage = new UIMachineSettingsGeneral;
     714                    addItem(":/machine_32px.png", ":/machine_24px.png", ":/machine_16px.png",
     715                            iPageIndex, "#general", pSettingsPage);
     716                    break;
     717                }
     718                /* System page: */
     719                case MachineSettingsPageType_System:
     720                {
     721                    pSettingsPage = new UIMachineSettingsSystem;
     722                    addItem(":/chipset_32px.png", ":/chipset_24px.png", ":/chipset_16px.png",
     723                            iPageIndex, "#system", pSettingsPage);
     724                    break;
     725                }
     726                /* Display page: */
     727                case MachineSettingsPageType_Display:
     728                {
     729                    pSettingsPage = new UIMachineSettingsDisplay;
     730                    addItem(":/vrdp_32px.png", ":/vrdp_24px.png", ":/vrdp_16px.png",
     731                            iPageIndex, "#display", pSettingsPage);
     732                    break;
     733                }
     734                /* Storage page: */
     735                case MachineSettingsPageType_Storage:
     736                {
     737                    pSettingsPage = new UIMachineSettingsStorage;
     738                    connect(static_cast<UIMachineSettingsStorage*>(pSettingsPage), &UIMachineSettingsStorage::sigStorageChanged,
     739                            this, &UISettingsDialogMachine::sltResetFirstRunFlag);
     740                    addItem(":/hd_32px.png", ":/hd_24px.png", ":/hd_16px.png",
     741                            iPageIndex, "#storage", pSettingsPage);
     742                    break;
     743                }
     744                /* Audio page: */
     745                case MachineSettingsPageType_Audio:
     746                {
     747                    pSettingsPage = new UIMachineSettingsAudio;
     748                    addItem(":/sound_32px.png", ":/sound_24px.png", ":/sound_16px.png",
     749                            iPageIndex, "#audio", pSettingsPage);
     750                    break;
     751                }
     752                /* Network page: */
     753                case MachineSettingsPageType_Network:
     754                {
     755                    pSettingsPage = new UIMachineSettingsNetworkPage;
     756                    addItem(":/nw_32px.png", ":/nw_24px.png", ":/nw_16px.png",
     757                            iPageIndex, "#network", pSettingsPage);
     758                    break;
     759                }
     760                /* Ports page: */
     761                case MachineSettingsPageType_Ports:
     762                {
     763                    addItem(":/serial_port_32px.png", ":/serial_port_24px.png", ":/serial_port_16px.png",
     764                            iPageIndex, "#ports");
     765                    break;
     766                }
     767                /* Serial page: */
     768                case MachineSettingsPageType_Serial:
     769                {
     770                    pSettingsPage = new UIMachineSettingsSerialPage;
     771                    addItem(":/serial_port_32px.png", ":/serial_port_24px.png", ":/serial_port_16px.png",
     772                            iPageIndex, "#serialPorts", pSettingsPage, MachineSettingsPageType_Ports);
     773                    break;
     774                }
     775                /* USB page: */
     776                case MachineSettingsPageType_USB:
     777                {
     778                    pSettingsPage = new UIMachineSettingsUSB;
     779                    addItem(":/usb_32px.png", ":/usb_24px.png", ":/usb_16px.png",
     780                            iPageIndex, "#usb", pSettingsPage, MachineSettingsPageType_Ports);
     781                    break;
     782                }
     783                /* Shared Folders page: */
     784                case MachineSettingsPageType_SF:
     785                {
     786                    pSettingsPage = new UIMachineSettingsSF;
     787                    addItem(":/sf_32px.png", ":/sf_24px.png", ":/sf_16px.png",
     788                            iPageIndex, "#sharedFolders", pSettingsPage);
     789                    break;
     790                }
     791                /* Interface page: */
     792                case MachineSettingsPageType_Interface:
     793                {
     794                    pSettingsPage = new UIMachineSettingsInterface(m_machine.GetId());
     795                    addItem(":/interface_32px.png", ":/interface_24px.png", ":/interface_16px.png",
     796                            iPageIndex, "#userInterface", pSettingsPage);
     797                    break;
     798                }
     799                default:
     800                    break;
     801            }
     802        }
     803    }
     804
     805    /* Calculate initial configuration access level: */
     806    setConfigurationAccessLevel(::configurationAccessLevel(m_enmSessionState, m_enmMachineState));
     807
     808    /* Apply language settings: */
     809    retranslateUi();
     810
     811    /* Setup settings window: */
     812    if (!m_strCategory.isNull())
     813    {
     814        m_pSelector->selectByLink(m_strCategory);
     815        /* Search for a widget with the given name: */
     816        if (!m_strControl.isNull())
     817        {
     818            if (QWidget *pWidget = m_pStack->findChild<QWidget*>(m_strControl))
     819            {
     820                QList<QWidget*> parents;
     821                QWidget *pParentWidget = pWidget;
     822                while ((pParentWidget = pParentWidget->parentWidget()) != 0)
     823                {
     824                    if (QTabWidget *pTabWidget = qobject_cast<QTabWidget*>(pParentWidget))
     825                    {
     826                        // WORKAROUND:
     827                        // The tab contents widget is two steps down
     828                        // (QTabWidget -> QStackedWidget -> QWidget).
     829                        QWidget *pTabPage = parents[parents.count() - 1];
     830                        if (pTabPage)
     831                            pTabPage = parents[parents.count() - 2];
     832                        if (pTabPage)
     833                            pTabWidget->setCurrentWidget(pTabPage);
     834                    }
     835                    parents.append(pParentWidget);
     836                }
     837                pWidget->setFocus();
     838            }
     839        }
     840    }
     841    /* First item as default: */
     842    else
     843        m_pSelector->selectById(MachineSettingsPageType_General);
     844}
     845
     846bool UISettingsDialogMachine::isPageAvailable(int iPageId) const
    820847{
    821848    if (m_machine.isNull())
     
    869896{
    870897    /* Determine new configuration access level: */
    871     ConfigurationAccessLevel newConfigurationAccessLevel = ::configurationAccessLevel(m_sessionState, m_machineState);
     898    const ConfigurationAccessLevel newConfigurationAccessLevel = ::configurationAccessLevel(m_enmSessionState, m_enmMachineState);
    872899
    873900    /* Make sure someting changed: */
     
    876903
    877904    /* Should we warn a user about access level decrease? */
    878     bool fShouldWeWarn = configurationAccessLevel() == ConfigurationAccessLevel_Full;
     905    const bool fShouldWeWarn = configurationAccessLevel() == ConfigurationAccessLevel_Full;
    879906
    880907    /* Apply new configuration access level: */
     
    885912        msgCenter().warnAboutStateChange(this);
    886913}
    887 
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h

    r71027 r72092  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UISettingsDialogSpecific_h__
    19 #define __UISettingsDialogSpecific_h__
     18#ifndef ___UISettingsDialogSpecific_h___
     19#define ___UISettingsDialogSpecific_h___
    2020
    2121/* GUI includes: */
     
    2424/* COM includes: */
    2525#include "COMEnums.h"
    26 #include "CSession.h"
    2726#include "CConsole.h"
    2827#include "CMachine.h"
     28#include "CSession.h"
    2929
    30 /* Dialog which encapsulate all the specific functionalities of the Global Settings */
    31 class UISettingsDialogGlobal : public UISettingsDialog
     30
     31/** UISettingsDialog extension encapsulating all the specific functionality of the Global Preferences. */
     32class SHARED_LIBRARY_STUFF UISettingsDialogGlobal : public UISettingsDialog
    3233{
    3334    Q_OBJECT;
     
    3536public:
    3637
     38    /** Constructs settings dialog passing @a pParent to the base-class.
     39      * @param  strCategory  Brings the name of category to be opened.
     40      * @param  strControl   Brings the name of control to be focused. */
    3741    UISettingsDialogGlobal(QWidget *pParent,
    3842                           const QString &strCategory = QString(),
     
    4145protected:
    4246
     47    /** Handles translation event. */
     48    virtual void retranslateUi() /* override */;
     49
    4350    /** Loads the data from the corresponding source. */
    44     void loadOwnData();
     51    virtual void loadOwnData() /* override */;
    4552    /** Saves the data to the corresponding source. */
    46     void saveOwnData();
    47 
    48     void retranslateUi();
     53    virtual void saveOwnData() /* override */;
    4954
    5055    /** Returns the dialog title extension. */
    51     QString titleExtension() const;
     56    virtual QString titleExtension() const /* override */;
    5257    /** Returns the dialog title. */
    53     QString title() const;
     58    virtual QString title() const /* override */;
    5459
    5560private:
    5661
    57     bool isPageAvailable(int iPageId);
     62    /** Prepares all. */
     63    void prepare();
     64
     65    /** Returns whether page with certain @a iPageId is available. */
     66    bool isPageAvailable(int iPageId) const;
     67
     68    /** Holds the name of category to be opened. */
     69    QString  m_strCategory;
     70    /** Holds the name of control to be focused. */
     71    QString  m_strControl;
    5872};
    5973
    60 /* Dialog which encapsulate all the specific functionalities of the Virtual Machine Settings */
    61 class UISettingsDialogMachine : public UISettingsDialog
     74
     75/** UISettingsDialog extension encapsulating all the specific functionality of the Machine Settings. */
     76class SHARED_LIBRARY_STUFF UISettingsDialogMachine : public UISettingsDialog
    6277{
    6378    Q_OBJECT;
     
    6580public:
    6681
     82    /** Constructs settings dialog passing @a pParent to the base-class.
     83      * @param  strMachineId  Brings the machine ID.
     84      * @param  strCategory   Brings the name of category to be opened.
     85      * @param  strControl    Brings the name of control to be focused. */
    6786    UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
    6887                            const QString &strCategory, const QString &strControl);
     
    7089protected:
    7190
     91    /** Handles translation event. */
     92    virtual void retranslateUi() /* override */;
     93
    7294    /** Loads the data from the corresponding source. */
    73     void loadOwnData();
     95    virtual void loadOwnData() /* override */;
    7496    /** Saves the data to the corresponding source. */
    75     void saveOwnData();
    76 
    77     void retranslateUi();
     97    virtual void saveOwnData() /* override */;
    7898
    7999    /** Returns the dialog title extension. */
    80     QString titleExtension() const;
     100    virtual QString titleExtension() const /* override */;
    81101    /** Returns the dialog title. */
    82     QString title() const;
     102    virtual QString title() const /* override */;
    83103
    84     void recorrelate(UISettingsPage *pSettingsPage);
     104    /** Verifies data integrity between certain @a pSettingsPage and other pages. */
     105    virtual void recorrelate(UISettingsPage *pSettingsPage) /* override */;
     106
     107protected slots:
     108
     109    /** Handles category change to @a cId. */
     110    virtual void sltCategoryChanged(int cId) /* override */;
     111
     112    /** Marks dialog loaded. */
     113    virtual void sltMarkLoaded() /* override */;
     114    /** Marks dialog saved. */
     115    virtual void sltMarkSaved() /* override */;
    85116
    86117private slots:
    87118
    88     void sltMarkLoaded();
    89     void sltMarkSaved();
    90     void sltSessionStateChanged(QString strMachineId, KSessionState sessionState);
    91     void sltMachineStateChanged(QString strMachineId, KMachineState machineState);
     119    /** Handles session state change for machine with certain @a strMachineId to @a enmSessionState. */
     120    void sltSessionStateChanged(QString strMachineId, KSessionState enmSessionState);
     121    /** Handles machine state change for machine with certain @a strMachineId to @a enmMachineState. */
     122    void sltMachineStateChanged(QString strMachineId, KMachineState enmMachineState);
     123    /** Handles machine data change for machine with certain @a strMachineId. */
    92124    void sltMachineDataChanged(QString strMachineId);
    93     void sltCategoryChanged(int cId);
     125
     126    /** Handles request to allow to reset first run flag. */
    94127    void sltAllowResetFirstRunFlag();
     128    /** Handles request to reset first run flag. */
    95129    void sltResetFirstRunFlag();
    96130
    97131private:
    98132
    99     bool isPageAvailable(int iPageId);
     133    /** Prepares all. */
     134    void prepare();
     135
     136    /** Returns whether page with certain @a iPageId is available. */
     137    bool isPageAvailable(int iPageId) const;
     138
     139    /** Returns whether settings were changed. */
    100140    bool isSettingsChanged();
    101141
    102     /* Recalculates configuration access level. */
     142    /** Recalculates configuration access level. */
    103143    void updateConfigurationAccessLevel();
    104144
    105     QString m_strMachineId;
    106     KSessionState m_sessionState;
    107     KMachineState m_machineState;
     145    /** Holds the machine ID. */
     146    QString  m_strMachineId;
     147    /** Holds the name of category to be opened. */
     148    QString  m_strCategory;
     149    /** Holds the name of control to be focused. */
     150    QString  m_strControl;
    108151
    109     CSession m_session;
    110     CMachine m_machine;
    111     CConsole m_console;
     152    /** Holds the session state. */
     153    KSessionState  m_enmSessionState;
     154    /** Holds the machine state. */
     155    KMachineState  m_enmMachineState;
    112156
    113     bool m_fAllowResetFirstRunFlag;
    114     bool m_fResetFirstRunFlag;
     157    /** Holds the session reference. */
     158    CSession  m_session;
     159    /** Holds the machine reference. */
     160    CMachine  m_machine;
     161    /** Holds the console reference. */
     162    CConsole  m_console;
     163
     164    /** Holds whether we are allowed to reset first run flag. */
     165    bool  m_fAllowResetFirstRunFlag : 1;
     166    /** Holds whether we have request to reset first run flag. */
     167    bool  m_fResetFirstRunFlag : 1;
    115168};
    116169
    117 #endif // __UISettingsDialogSpecific_h__
    118170
     171#endif /* !___UISettingsDialogSpecific_h___ */
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