VirtualBox

Changeset 50906 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 27, 2014 2:37:16 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Reworking SettingsDialogType => ConfigurationAccessLevel for further reuse by other places besides settings-dialog.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDefs.cpp

    r44529 r50906  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox frontends: Qt GUI ("VirtualBox"):
    5  * UISettingsDefs implementation
     3 * VBox Qt GUI - UISettingsDefs implementation
    64 */
    75
    86/*
    9  * Copyright (C) 2011-2012 Oracle Corporation
     7 * Copyright (C) 2011-2014 Oracle Corporation
    108 *
    119 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1816 */
    1917
    20 /* VBox includes: */
     18/* GUI includes: */
    2119#include "UISettingsDefs.h"
    2220
     
    2422using namespace UISettingsDefs;
    2523
    26 /* Machine state => Settings dialog type converter: */
    27 SettingsDialogType UISettingsDefs::determineSettingsDialogType(KSessionState sessionState, KMachineState machineState)
     24ConfigurationAccessLevel UISettingsDefs::configurationAccessLevel(KSessionState sessionState, KMachineState machineState)
    2825{
    29     SettingsDialogType result = SettingsDialogType_Wrong;
     26    /* Depending on passed arguments: */
    3027    switch (machineState)
    3128    {
    3229        case KMachineState_PoweredOff:
    3330        case KMachineState_Teleported:
    34         case KMachineState_Aborted:
    35             result = sessionState == KSessionState_Unlocked ? SettingsDialogType_Offline :
    36                                                               SettingsDialogType_Online;
    37             break;
    38         case KMachineState_Saved:
    39             result = SettingsDialogType_Saved;
    40             break;
     31        case KMachineState_Aborted:    return sessionState == KSessionState_Unlocked ? ConfigurationAccessLevel_Full : ConfigurationAccessLevel_Runtime;
     32        case KMachineState_Saved:      return ConfigurationAccessLevel_Saved;
    4133        case KMachineState_Running:
    42         case KMachineState_Paused:
    43             result = SettingsDialogType_Online;
    44             break;
    45         default:
    46             break;
     34        case KMachineState_Paused:     return ConfigurationAccessLevel_Runtime;
     35        default: break;
    4736    }
    48     return result;
     37    /* Null by default: */
     38    return ConfigurationAccessLevel_Null;
    4939}
    5040
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDefs.h

    r48577 r50906  
    11/** @file
    2  *
    3  * VBox frontends: Qt GUI ("VirtualBox"):
    4  * Header with definitions and functions related to settings window
     2 * VBox Qt GUI - Header with definitions and functions related to settings configuration.
    53 */
    64
    75/*
    8  * Copyright (C) 2011-2012 Oracle Corporation
     6 * Copyright (C) 2011-2014 Oracle Corporation
    97 *
    108 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1715 */
    1816
    19 #ifndef __UISettingsDefs_h__
    20 #define __UISettingsDefs_h__
     17#ifndef ___UISettingsDefs_h___
     18#define ___UISettingsDefs_h___
    2119
    2220/* Qt includes: */
     
    2725#include "COMEnums.h"
    2826
    29 /* Settings dialog namespace: */
     27/** Settings configuration namespace: */
    3028namespace UISettingsDefs
    3129{
    32     /* Settings dialog types: */
    33     enum SettingsDialogType
     30    /** Configuration access levels: */
     31    enum ConfigurationAccessLevel
    3432    {
    35         SettingsDialogType_Wrong,
    36         SettingsDialogType_Offline,
    37         SettingsDialogType_Saved,
    38         SettingsDialogType_Online
     33        ConfigurationAccessLevel_Null,
     34        ConfigurationAccessLevel_Saved,
     35        ConfigurationAccessLevel_Runtime,
     36        ConfigurationAccessLevel_Full
    3937    };
    4038
    41     /* Machine state => Settings dialog type converter: */
    42     SettingsDialogType determineSettingsDialogType(KSessionState sessionState, KMachineState machineState);
     39    /** Determines configuration access level for passed @a sessionState and @a machineState. */
     40    ConfigurationAccessLevel configurationAccessLevel(KSessionState sessionState, KMachineState machineState);
    4341}
    4442
     
    164162};
    165163
    166 #endif /* __UISettingsDefs_h__ */
    167 
     164#endif /* !___UISettingsDefs_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r50890 r50906  
    5252    , m_pStack(0)
    5353    /* Common variables: */
    54     , m_dialogType(SettingsDialogType_Wrong)
     54    , m_configurationAccessLevel(ConfigurationAccessLevel_Null)
    5555    , m_fPolished(false)
    5656    /* Loading/saving stuff: */
     
    246246}
    247247
    248 void UISettingsDialog::setDialogType(SettingsDialogType settingsDialogType)
    249 {
    250     /* Remember new dialog-type: */
    251     m_dialogType = settingsDialogType;
    252 
    253     /* Propagate it to settings-page(s): */
     248void UISettingsDialog::setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel)
     249{
     250    /* Make sure something changed: */
     251    if (m_configurationAccessLevel == newConfigurationAccessLevel)
     252        return;
     253
     254    /* Apply new configuration access level: */
     255    m_configurationAccessLevel = newConfigurationAccessLevel;
     256
     257    /* And propagate it to settings-page(s): */
    254258    foreach (UISettingsPage *pPage, m_pSelector->settingPages())
    255         pPage->setDialogType(dialogType());
     259        pPage->setConfigurationAccessLevel(configurationAccessLevel());
    256260}
    257261
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r50890 r50906  
    7575    virtual void retranslateUi();
    7676
    77     /* Dialog type: */
    78     SettingsDialogType dialogType() { return m_dialogType; }
    79     void setDialogType(SettingsDialogType settingsDialogType);
     77    /** Returns configuration access level. */
     78    ConfigurationAccessLevel configurationAccessLevel() { return m_configurationAccessLevel; }
     79    /** Defines configuration access level. */
     80    void setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel);
     81
    8082    /* Dialog title: */
    8183    virtual QString title() const = 0;
     
    119121    void assignValidator(UISettingsPage *pPage);
    120122
     123    /** Holds configuration access level. */
     124    ConfigurationAccessLevel m_configurationAccessLevel;
     125
    121126    /* Global Flags: */
    122     SettingsDialogType m_dialogType;
    123127    bool m_fPolished;
    124128
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r50890 r50906  
    323323#endif /* !Q_WS_MAC */
    324324
    325     /* Assign default dialog type: */
    326     setDialogType(SettingsDialogType_Offline);
    327 
    328325    /* Creating settings pages: */
    329326    CVirtualBox vbox = vboxGlobal().virtualBox();
     
    412409                    break;
    413410            }
    414             if (pSettingsPage)
    415                 pSettingsPage->setDialogType(dialogType());
    416         }
    417     }
     411        }
     412    }
     413
     414    /* Assign default (full) configuration access level: */
     415    setConfigurationAccessLevel(ConfigurationAccessLevel_Full);
    418416
    419417    /* Retranslate UI: */
     
    564562    m_sessionState = m_machine.GetSessionState();
    565563    m_machineState = m_machine.GetState();
    566     /* Recalculate current dialog-type: */
    567     updateDialogType();
    568564
    569565    /* Creating settings pages: */
     
    672668                    break;
    673669            }
    674             if (pSettingsPage)
    675                 pSettingsPage->setDialogType(dialogType());
    676         }
    677     }
     670        }
     671    }
     672
     673    /* Recalculate configuration access level: */
     674    updateConfigurationAccessLevel();
    678675
    679676    /* Retranslate UI: */
     
    734731
    735732    /* Prepare session: */
    736     m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openExistingSession(m_strMachineId);
     733    m_session = configurationAccessLevel() == ConfigurationAccessLevel_Null ? CSession() : vboxGlobal().openExistingSession(m_strMachineId);
    737734    /* Check that session was created: */
    738735    if (m_session.isNull())
     
    742739    m_machine = m_session.GetMachine();
    743740    /* Get console from session: */
    744     m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
     741    m_console = configurationAccessLevel() == ConfigurationAccessLevel_Full ? CConsole() : m_session.GetConsole();
    745742
    746743    /* Prepare machine data: */
     
    773770
    774771    /* Prepare session: */
    775     if (dialogType() == SettingsDialogType_Wrong)
     772    if (configurationAccessLevel() == ConfigurationAccessLevel_Null)
    776773        m_session = CSession();
    777     else if (dialogType() != SettingsDialogType_Offline)
     774    else if (configurationAccessLevel() != ConfigurationAccessLevel_Full)
    778775        m_session = vboxGlobal().openExistingSession(m_strMachineId);
    779776    else
     
    786783    m_machine = m_session.GetMachine();
    787784    /* Get console from session: */
    788     m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
     785    m_console = configurationAccessLevel() == ConfigurationAccessLevel_Full ? CConsole() : m_session.GetConsole();
    789786
    790787    /* Prepare machine data: */
     
    10111008    m_sessionState = sessionState;
    10121009
    1013     /* Update dialog-type if necessary: */
    1014     updateDialogType();
     1010    /* Recalculate configuration access level: */
     1011    updateConfigurationAccessLevel();
    10151012}
    10161013
     
    10281025    m_machineState = machineState;
    10291026
    1030     /* Update dialog-type if necessary: */
    1031     updateDialogType();
     1027    /* Recalculate configuration access level: */
     1028    updateConfigurationAccessLevel();
    10321029}
    10331030
     
    11271124}
    11281125
    1129 void UISettingsDialogMachine::updateDialogType()
    1130 {
    1131     /* Get new dialog type: */
    1132     SettingsDialogType newDialogType = determineSettingsDialogType(m_sessionState, m_machineState);
    1133 
    1134     /* Ignore if dialog type was NOT actually changed: */
    1135     if (dialogType() == newDialogType)
     1126void UISettingsDialogMachine::updateConfigurationAccessLevel()
     1127{
     1128    /* Determine new configuration access level: */
     1129    ConfigurationAccessLevel newConfigurationAccessLevel = ::configurationAccessLevel(m_sessionState, m_machineState);
     1130
     1131    /* Make sure someting changed: */
     1132    if (configurationAccessLevel() == newConfigurationAccessLevel)
    11361133        return;
    11371134
    1138     /* Should we show a warning about leaving 'offline' state? */
    1139     bool fShouldWe = dialogType() == SettingsDialogType_Offline;
    1140 
    1141     /* Update current dialog type: */
    1142     setDialogType(newDialogType);
    1143 
    1144     /* Show a warning about leaving 'offline' state if we should: */
    1145     if (isSettingsChanged() && fShouldWe)
     1135    /* Should we warn a user about access level decrease? */
     1136    bool fShouldWeWarn = configurationAccessLevel() == ConfigurationAccessLevel_Full;
     1137
     1138    /* Apply new configuration access level: */
     1139    setConfigurationAccessLevel(newConfigurationAccessLevel);
     1140
     1141    /* Show a warning about access level decrease if we should: */
     1142    if (isSettingsChanged() && fShouldWeWarn)
    11461143        msgCenter().warnAboutStateChange(this);
    11471144}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h

    r46759 r50906  
    9191    bool isPageAvailable(int iPageId);
    9292    bool isSettingsChanged();
    93     void updateDialogType();
     93
     94    /* Recalculates configuration access level. */
     95    void updateConfigurationAccessLevel();
    9496
    9597    QString m_strMachineId;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPage.cpp

    r47595 r50906  
    2626UISettingsPage::UISettingsPage(UISettingsPageType pageType)
    2727    : m_pageType(pageType)
    28     , m_dialogType(SettingsDialogType_Wrong)
     28    , m_configurationAccessLevel(ConfigurationAccessLevel_Null)
    2929    , m_cId(-1)
    3030    , m_fProcessed(false)
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPage.h

    r47944 r50906  
    108108    UISettingsPageType pageType() const { return m_pageType; }
    109109
    110     /* Settings dialog type stuff: */
    111     SettingsDialogType dialogType() const { return m_dialogType; }
    112     virtual void setDialogType(SettingsDialogType settingsDialogType) { m_dialogType = settingsDialogType; polishPage(); }
    113     bool isMachineOffline() const { return dialogType() == SettingsDialogType_Offline; }
    114     bool isMachineSaved() const { return dialogType() == SettingsDialogType_Saved; }
    115     bool isMachineOnline() const { return dialogType() == SettingsDialogType_Online; }
     110    /* Configuration access level stuff: */
     111    ConfigurationAccessLevel configurationAccessLevel() const { return m_configurationAccessLevel; }
     112    virtual void setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel) { m_configurationAccessLevel = newConfigurationAccessLevel; polishPage(); }
     113    bool isMachineOffline() const { return configurationAccessLevel() == ConfigurationAccessLevel_Full; }
     114    bool isMachineSaved() const { return configurationAccessLevel() == ConfigurationAccessLevel_Saved; }
     115    bool isMachineOnline() const { return configurationAccessLevel() == ConfigurationAccessLevel_Runtime; }
    116116    bool isMachineInValidMode() const { return isMachineOffline() || isMachineSaved() || isMachineOnline(); }
    117117
     
    154154    /* Variables: */
    155155    UISettingsPageType m_pageType;
    156     SettingsDialogType m_dialogType;
     156    ConfigurationAccessLevel m_configurationAccessLevel;
    157157    int m_cId;
    158158    bool m_fProcessed;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp

    r50897 r50906  
    864864    , mToolTipType (DefaultToolTip)
    865865    , m_chipsetType(KChipsetType_PIIX3)
    866     , m_dialogType(SettingsDialogType_Wrong)
     866    , m_configurationAccessLevel(ConfigurationAccessLevel_Null)
    867867{
    868868}
     
    10341034        case R_IsMoreIDEControllersPossible:
    10351035        {
    1036             return (m_dialogType == SettingsDialogType_Offline) &&
     1036            return (m_configurationAccessLevel == ConfigurationAccessLevel_Full) &&
    10371037                   (static_cast<RootItem*>(mRootItem)->childCount(KStorageBus_IDE) <
    10381038                    vboxGlobal().virtualBox().GetSystemProperties().GetMaxInstancesOfStorageBus(chipsetType(), KStorageBus_IDE));
     
    10401040        case R_IsMoreSATAControllersPossible:
    10411041        {
    1042             return (m_dialogType == SettingsDialogType_Offline) &&
     1042            return (m_configurationAccessLevel == ConfigurationAccessLevel_Full) &&
    10431043                   (static_cast<RootItem*>(mRootItem)->childCount(KStorageBus_SATA) <
    10441044                    vboxGlobal().virtualBox().GetSystemProperties().GetMaxInstancesOfStorageBus(chipsetType(), KStorageBus_SATA));
     
    10461046        case R_IsMoreSCSIControllersPossible:
    10471047        {
    1048             return (m_dialogType == SettingsDialogType_Offline) &&
     1048            return (m_configurationAccessLevel == ConfigurationAccessLevel_Full) &&
    10491049                   (static_cast<RootItem*>(mRootItem)->childCount(KStorageBus_SCSI) <
    10501050                    vboxGlobal().virtualBox().GetSystemProperties().GetMaxInstancesOfStorageBus(chipsetType(), KStorageBus_SCSI));
     
    10521052        case R_IsMoreFloppyControllersPossible:
    10531053        {
    1054             return (m_dialogType == SettingsDialogType_Offline) &&
     1054            return (m_configurationAccessLevel == ConfigurationAccessLevel_Full) &&
    10551055                   (static_cast<RootItem*>(mRootItem)->childCount(KStorageBus_Floppy) <
    10561056                    vboxGlobal().virtualBox().GetSystemProperties().GetMaxInstancesOfStorageBus(chipsetType(), KStorageBus_Floppy));
     
    10581058        case R_IsMoreSASControllersPossible:
    10591059        {
    1060             return (m_dialogType == SettingsDialogType_Offline) &&
     1060            return (m_configurationAccessLevel == ConfigurationAccessLevel_Full) &&
    10611061                   (static_cast<RootItem*>(mRootItem)->childCount(KStorageBus_SAS) <
    10621062                    vboxGlobal().virtualBox().GetSystemProperties().GetMaxInstancesOfStorageBus(chipsetType(), KStorageBus_SAS));
     
    10641064        case R_IsMoreUSBControllersPossible:
    10651065        {
    1066             return (m_dialogType == SettingsDialogType_Offline) &&
     1066            return (m_configurationAccessLevel == ConfigurationAccessLevel_Full) &&
    10671067                   (static_cast<RootItem*>(mRootItem)->childCount(KStorageBus_USB) <
    10681068                    vboxGlobal().virtualBox().GetSystemProperties().GetMaxInstancesOfStorageBus(chipsetType(), KStorageBus_USB));
     
    10761076                    ControllerItem *ctr = static_cast <ControllerItem*> (item);
    10771077                    CSystemProperties sp = vboxGlobal().virtualBox().GetSystemProperties();
    1078                     switch (m_dialogType)
     1078                    switch (m_configurationAccessLevel)
    10791079                    {
    1080                         case SettingsDialogType_Offline: return ((uint)rowCount(aIndex) < sp.GetMaxPortCountForStorageBus(ctr->ctrBusType()) *
    1081                                                                                           sp.GetMaxDevicesPerPortForStorageBus(ctr->ctrBusType()));
    1082                         case SettingsDialogType_Online: return (ctr->ctrBusType() == KStorageBus_SATA) &&
    1083                                                                ((uint)rowCount(aIndex) < ctr->portCount());
     1080                        case ConfigurationAccessLevel_Full: return ((uint)rowCount(aIndex) < sp.GetMaxPortCountForStorageBus(ctr->ctrBusType()) *
     1081                                                                                             sp.GetMaxDevicesPerPortForStorageBus(ctr->ctrBusType()));
     1082                        case ConfigurationAccessLevel_Runtime: return (ctr->ctrBusType() == KStorageBus_SATA) &&
     1083                                                                      ((uint)rowCount(aIndex) < ctr->portCount());
    10841084                        default: break;
    10851085                    }
     
    15041504        beginInsertRows (parentIndex, parent->childCount(), parent->childCount());
    15051505        AttachmentItem *pItem = new AttachmentItem (parent, aDeviceType);
    1506         pItem->setAttIsHotPluggable(m_dialogType != SettingsDialogType_Offline);
     1506        pItem->setAttIsHotPluggable(m_configurationAccessLevel != ConfigurationAccessLevel_Full);
    15071507        pItem->setAttMediumId(strMediumId);
    15081508        endInsertRows();
     
    16171617}
    16181618
    1619 void StorageModel::setDialogType(SettingsDialogType dialogType)
    1620 {
    1621     m_dialogType = dialogType;
     1619void StorageModel::setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel)
     1620{
     1621    m_configurationAccessLevel = newConfigurationAccessLevel;
    16221622}
    16231623
     
    38123812}
    38133813
    3814 void UIMachineSettingsStorage::setDialogType(SettingsDialogType settingsDialogType)
    3815 {
    3816     /* Update model 'settings window type': */
    3817     mStorageModel->setDialogType(settingsDialogType);
    3818     /* Update 'settings window type' of base class: */
    3819     UISettingsPageMachine::setDialogType(settingsDialogType);
     3814void UIMachineSettingsStorage::setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel)
     3815{
     3816    /* Update model 'configuration access level': */
     3817    mStorageModel->setConfigurationAccessLevel(newConfigurationAccessLevel);
     3818    /* Update 'configuration access level' of base class: */
     3819    UISettingsPageMachine::setConfigurationAccessLevel(newConfigurationAccessLevel);
    38203820}
    38213821
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.h

    r50885 r50906  
    542542    void setChipsetType(KChipsetType type);
    543543
    544     void setDialogType(SettingsDialogType settingsDialogType);
     544    /** Defines configuration access level. */
     545    void setConfigurationAccessLevel(ConfigurationAccessLevel newConfigurationAccessLevel);
    545546
    546547    void clear();
     
    564565
    565566    KChipsetType m_chipsetType;
    566     SettingsDialogType m_dialogType;
     567
     568    /** Holds configuration access level. */
     569    ConfigurationAccessLevel m_configurationAccessLevel;
    567570};
    568571Q_DECLARE_METATYPE (StorageModel::ToolTipType);
     
    784787    bool isAttachmentCouldBeUpdated(const UICacheSettingsMachineStorageAttachment &attachmentCache) const;
    785788
    786     void setDialogType(SettingsDialogType settingsDialogType);
     789    /** Defines configuration access level. */
     790    void setConfigurationAccessLevel(ConfigurationAccessLevel configurationAccessLevel);
     791
    787792    void polishPage();
    788793
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