VirtualBox

Changeset 51038 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 10, 2014 2:12:38 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
93254
Message:

FE/Qt: 6660: Advanced extra-data management framework: UIExtraDataManager coding-style rework/cleanup, doxy comments added.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r51035 r51038  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox frontends: Qt GUI ("VirtualBox"):
    5  * UIExtraDataManager class implementation
     3 * VBox Qt GUI - UIExtraDataManager class implementation.
    64 */
    75
    86/*
    9  * Copyright (C) 2010-2013 Oracle Corporation
     7 * Copyright (C) 2010-2014 Oracle Corporation
    108 *
    119 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3230#include "CEventSource.h"
    3331
    34 class UIExtraDataEventHandler: public QObject
     32
     33/** QObject extension
     34  * notifying UIExtraDataManager whenever any of extra-data values changed. */
     35class UIExtraDataEventHandler : public QObject
    3536{
    3637    Q_OBJECT;
    3738
     39signals:
     40
     41    /** Notifies about GUI language change. */
     42    void sigLanguageChange(QString strLanguage);
     43
     44    /** Notifies about Selector UI keyboard shortcut change. */
     45    void sigSelectorUIShortcutChange();
     46    /** Notifies about Runtime UI keyboard shortcut change. */
     47    void sigRuntimeUIShortcutChange();
     48
     49    /** Notifies about HID LED sync state change. */
     50    void sigHIDLedsSyncStateChange(bool fEnabled);
     51#ifdef RT_OS_DARWIN
     52    /** Mac OS X: Notifies about 'presentation mode' status change. */
     53    void sigPresentationModeChange(bool fEnabled);
     54    /** Mac OS X: Notifies about 'dock icon' appearance change. */
     55    void sigDockIconAppearanceChange(bool fEnabled);
     56#endif /* RT_OS_DARWIN */
     57
    3858public:
    3959
    40     UIExtraDataEventHandler(QObject *pParent = 0)
    41         : QObject(pParent)
    42     {}
     60    /** Extra-data event-handler constructor. */
     61    UIExtraDataEventHandler(QObject *pParent);
    4362
    4463public slots:
    4564
    46     void sltExtraDataCanChange(QString strId, QString strKey, QString strValue, bool &fVeto, QString &strVetoReason)
    47     {
    48         if (QUuid(strId).isNull())
    49         {
    50             /* it's a global extra data key someone wants to change */
    51             if (strKey.startsWith("GUI/"))
     65    /** Handles extra-data 'can change' event: */
     66    void sltExtraDataCanChange(QString strMachineID, QString strKey, QString strValue, bool &fVeto, QString &strVetoReason);
     67    /** Handles extra-data 'change' event: */
     68    void sltExtraDataChange(QString strMachineID, QString strKey, QString strValue);
     69
     70private:
     71
     72    /** Protects sltExtraDataChange. */
     73    QMutex m_mutex;
     74};
     75
     76UIExtraDataEventHandler::UIExtraDataEventHandler(QObject *pParent)
     77    : QObject(pParent)
     78{}
     79
     80void UIExtraDataEventHandler::sltExtraDataCanChange(QString strMachineID, QString strKey, QString strValue, bool &fVeto, QString &strVetoReason)
     81{
     82    /* Global extra-data 'can change' event: */
     83    if (QUuid(strMachineID).isNull())
     84    {
     85        /* It's a global extra-data key someone wants to change: */
     86        if (strKey.startsWith("GUI/"))
     87        {
     88            /* Try to set the global setting to check its syntax: */
     89            VBoxGlobalSettings gs(false /* non-null */);
     90            /* Known GUI property key? */
     91            if (gs.setPublicProperty(strKey, strValue))
    5292            {
    53                 /* Try to set the global setting to check its syntax */
    54                 VBoxGlobalSettings gs(false /* non-null */);
    55                 if (gs.setPublicProperty (strKey, strValue))
     93                /* But invalid GUI property value? */
     94                if (!gs)
    5695                {
    57                     /* this is a known GUI property key */
    58                     if (!gs)
    59                     {
    60                         strVetoReason = gs.lastError();
    61                         /* disallow the change when there is an error*/
    62                         fVeto = true;
    63                     }
    64                     return;
     96                    /* Remember veto reason: */
     97                    strVetoReason = gs.lastError();
     98                    /* And disallow that change: */
     99                    fVeto = true;
    65100                }
     101                return;
    66102            }
    67103        }
    68104    }
    69 
    70     void sltExtraDataChange(QString strId, QString strKey, QString strValue)
    71     {
    72         if (QUuid(strId).isNull())
    73         {
    74             if (strKey.startsWith ("GUI/"))
     105}
     106
     107void UIExtraDataEventHandler::sltExtraDataChange(QString strMachineID, QString strKey, QString strValue)
     108{
     109    /* Global extra-data 'change' event: */
     110    if (QUuid(strMachineID).isNull())
     111    {
     112        if (strKey.startsWith("GUI/"))
     113        {
     114            /* Language changed? */
     115            if (strKey == GUI_LanguageId)
     116                emit sigLanguageChange(strValue);
     117            /* Selector UI shortcut changed? */
     118            else if (strKey == GUI_Input_SelectorShortcuts && gActionPool->type() == UIActionPoolType_Selector)
     119                emit sigSelectorUIShortcutChange();
     120            /* Runtime UI shortcut changed? */
     121            else if (strKey == GUI_Input_MachineShortcuts && gActionPool->type() == UIActionPoolType_Runtime)
     122                emit sigRuntimeUIShortcutChange();
     123#ifdef Q_WS_MAC
     124            /* 'Presentation mode' status changed? */
     125            else if (strKey == GUI_PresentationModeEnabled)
    75126            {
    76                 if (strKey == GUI_LanguageId)
    77                     emit sigGUILanguageChange(strValue);
    78                 if (strKey == GUI_Input_SelectorShortcuts && gActionPool->type() == UIActionPoolType_Selector)
    79                     emit sigSelectorShortcutsChanged();
    80                 if (strKey == GUI_Input_MachineShortcuts && gActionPool->type() == UIActionPoolType_Runtime)
    81                     emit sigMachineShortcutsChanged();
    82 #ifdef Q_WS_MAC
    83                 if (strKey == GUI_PresentationModeEnabled)
    84                 {
    85                     /* Default to true if it is an empty value */
    86                     QString testStr = strValue.toLower();
    87                     bool f = (testStr.isEmpty() || testStr == "false");
    88                     emit sigPresentationModeChange(f);
    89                 }
    90 #endif /* Q_WS_MAC */
    91 
    92                 m_mutex.lock();
    93                 vboxGlobal().settings().setPublicProperty(strKey, strValue);
    94                 m_mutex.unlock();
    95                 Assert(!!vboxGlobal().settings());
    96             }
    97         }
    98         else if (vboxGlobal().isVMConsoleProcess())
    99         {
    100             /* Take care about HID LEDs sync */
    101             if (strKey == GUI_HidLedsSync)
    102             {
    103                 /* If extra data GUI/HidLedsSync is not present in VM config or set
    104                  * to 1 then sync is enabled. Otherwise, it is disabled. */
    105                 bool f = (strValue.isEmpty() || strValue == "1") ? true : false;
    106                 emit sigHidLedsSyncStateChanged(f);
    107             }
    108 
    109 #ifdef Q_WS_MAC
    110             /* Check for the currently running machine */
    111             if (strId == vboxGlobal().managedVMUuid())
    112             {
    113                 if (   strKey == GUI_RealtimeDockIconUpdateEnabled
    114                     || strKey == GUI_RealtimeDockIconUpdateMonitor)
    115                 {
    116                     bool f = strValue.toLower() == "false" ? false : true;
    117                     emit sigDockIconAppearanceChange(f);
    118                 }
     127                // TODO: Make it global..
     128                /* Allowed what is not restricted: */
     129                bool fEnabled = strValue.isEmpty() || strValue.toLower() != "false";
     130                emit sigPresentationModeChange(fEnabled);
    119131            }
    120132#endif /* Q_WS_MAC */
    121         }
    122     }
    123 
    124 signals:
    125 
    126     void sigGUILanguageChange(QString strLang);
    127     void sigSelectorShortcutsChanged();
    128     void sigMachineShortcutsChanged();
    129     void sigHidLedsSyncStateChanged(bool fEnabled);
    130 #ifdef RT_OS_DARWIN
    131     void sigPresentationModeChange(bool fEnabled);
    132     void sigDockIconAppearanceChange(bool fEnabled);
    133 #endif /* RT_OS_DARWIN */
    134 
    135 private:
    136 
    137     /** protects #OnExtraDataChange() */
    138     QMutex m_mutex;
    139 };
     133
     134            /* Apply global property: */
     135            m_mutex.lock();
     136            vboxGlobal().settings().setPublicProperty(strKey, strValue);
     137            m_mutex.unlock();
     138            AssertMsgReturnVoid(!!vboxGlobal().settings(), ("Failed to apply global property.\n"));
     139        }
     140    }
     141    /* Make sure event came for the currently running VM: */
     142    else if (   vboxGlobal().isVMConsoleProcess()
     143             && strMachineID == vboxGlobal().managedVMUuid())
     144    {
     145        /* HID LEDs sync state changed? */
     146        if (strKey == GUI_HidLedsSync)
     147        {
     148            /* Allowed what is not restricted: */
     149            // TODO: Make it global..
     150            bool fEnabled = strValue.isEmpty() || strValue != "0";
     151            emit sigHIDLedsSyncStateChange(fEnabled);
     152        }
     153#ifdef Q_WS_MAC
     154        /* 'Dock icon' appearance changed? */
     155        else if (   strKey == GUI_RealtimeDockIconUpdateEnabled
     156                 || strKey == GUI_RealtimeDockIconUpdateMonitor)
     157        {
     158            /* Allowed what is not restricted: */
     159            // TODO: Make it global..
     160            bool fEnabled = strValue.isEmpty() || strValue.toLower() != "false";
     161            emit sigDockIconAppearanceChange(fEnabled);
     162        }
     163#endif /* Q_WS_MAC */
     164    }
     165}
     166
    140167
    141168/* static */
     
    145172UIExtraDataManager* UIExtraDataManager::instance()
    146173{
     174    /* Create instance if not yet exists: */
    147175    if (!m_pInstance)
    148176        m_pInstance = new UIExtraDataManager();
     177    /* Return instance: */
    149178    return m_pInstance;
    150179}
     
    153182void UIExtraDataManager::destroy()
    154183{
     184    /* Destroy instance if still exists: */
    155185    if (m_pInstance)
    156186    {
     
    161191
    162192UIExtraDataManager::UIExtraDataManager()
    163   : m_pHandler(new UIExtraDataEventHandler(this))
    164 {
    165 //    RTPrintf("Self add: %RTthrd\n", RTThreadSelf());
     193    : m_pHandler(new UIExtraDataEventHandler(this))
     194{
     195    /* Register Main event-listener:  */
    166196    const CVirtualBox &vbox = vboxGlobal().virtualBox();
    167197    ComObjPtr<UIMainEventListenerImpl> pListener;
    168198    pListener.createObject();
    169     pListener->init(new UIMainEventListener(), this);
    170     m_mainEventListener = CEventListener(pListener);
     199    pListener->init(new UIMainEventListener, this);
     200    m_listener = CEventListener(pListener);
    171201    QVector<KVBoxEventType> events;
    172202    events
    173203        << KVBoxEventType_OnExtraDataCanChange
    174204        << KVBoxEventType_OnExtraDataChanged;
    175 
    176     vbox.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE);
     205    vbox.GetEventSource().RegisterListener(m_listener, events, TRUE);
    177206    AssertWrapperOk(vbox);
    178207
    179     /* This is a vetoable event, so we have to respond to the event and have to
    180      * use a direct connection therefor. */
     208    /* This is a vetoable event, so we have to respond to the event and have to use a direct connection therefor: */
    181209    connect(pListener->getWrapped(), SIGNAL(sigExtraDataCanChange(QString, QString, QString, bool&, QString&)),
    182210            m_pHandler, SLOT(sltExtraDataCanChange(QString, QString, QString, bool&, QString&)),
    183211            Qt::DirectConnection);
    184 
    185     /* Use a direct connection to the helper class. */
     212    /* Use a direct connection to the helper class: */
    186213    connect(pListener->getWrapped(), SIGNAL(sigExtraDataChange(QString, QString, QString)),
    187214            m_pHandler, SLOT(sltExtraDataChange(QString, QString, QString)),
    188215            Qt::DirectConnection);
    189216
    190     /* UI signals */
    191     connect(m_pHandler, SIGNAL(sigGUILanguageChange(QString)),
    192             this, SIGNAL(sigGUILanguageChange(QString)),
    193             Qt::QueuedConnection);
    194 
    195     connect(m_pHandler, SIGNAL(sigSelectorShortcutsChanged()),
    196             this, SIGNAL(sigSelectorShortcutsChanged()),
    197             Qt::QueuedConnection);
    198 
    199     connect(m_pHandler, SIGNAL(sigMachineShortcutsChanged()),
    200             this, SIGNAL(sigMachineShortcutsChanged()),
    201             Qt::QueuedConnection);
    202 
    203     connect(m_pHandler, SIGNAL(sigHidLedsSyncStateChanged(bool)),
    204             this, SIGNAL(sigHidLedsSyncStateChanged(bool)),
     217    /* Language change signal: */
     218    connect(m_pHandler, SIGNAL(sigLanguageChange(QString)),
     219            this, SIGNAL(sigLanguageChange(QString)),
     220            Qt::QueuedConnection);
     221
     222    /* Selector/Runtime UI shortcut change signals: */
     223    connect(m_pHandler, SIGNAL(sigSelectorUIShortcutChange()),
     224            this, SIGNAL(sigSelectorUIShortcutChange()),
     225            Qt::QueuedConnection);
     226    connect(m_pHandler, SIGNAL(sigRuntimeUIShortcutChange()),
     227            this, SIGNAL(sigRuntimeUIShortcutChange()),
     228            Qt::QueuedConnection);
     229
     230    /* HID LED sync state change signal: */
     231    connect(m_pHandler, SIGNAL(sigHIDLedsSyncStateChange(bool)),
     232            this, SIGNAL(sigHIDLedsSyncStateChange(bool)),
    205233            Qt::QueuedConnection);
    206234
    207235#ifdef Q_WS_MAC
     236    /* 'Presentation mode' status change signal: */
    208237    connect(m_pHandler, SIGNAL(sigPresentationModeChange(bool)),
    209238            this, SIGNAL(sigPresentationModeChange(bool)),
    210239            Qt::QueuedConnection);
    211240
     241    /* 'Dock icon' appearance change signal: */
    212242    connect(m_pHandler, SIGNAL(sigDockIconAppearanceChange(bool)),
    213243            this, SIGNAL(sigDockIconAppearanceChange(bool)),
     
    218248UIExtraDataManager::~UIExtraDataManager()
    219249{
     250    /* Unregister Main event-listener:  */
    220251    const CVirtualBox &vbox = vboxGlobal().virtualBox();
    221     vbox.GetEventSource().UnregisterListener(m_mainEventListener);
     252    vbox.GetEventSource().UnregisterListener(m_listener);
    222253}
    223254
    224255#include "UIExtraDataManager.moc"
     256
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r51035 r51038  
    44
    55/*
    6  * Copyright (C) 2010-2013 Oracle Corporation
     6 * Copyright (C) 2010-2014 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2727class UIExtraDataEventHandler;
    2828
    29 class UIExtraDataManager: public QObject
     29/** Singleton QObject extension
     30  * providing GUI with corresponding extra-data values,
     31  * and notifying it whenever any of those values changed. */
     32class UIExtraDataManager : public QObject
    3033{
    3134    Q_OBJECT;
    3235
    33 public:
    34     static UIExtraDataManager* instance();
    35     static void destroy();
     36signals:
    3637
    37 signals:
    38     /* Specialized extra data signals */
    39     void sigGUILanguageChange(QString strLang);
    40     void sigSelectorShortcutsChanged();
    41     void sigMachineShortcutsChanged();
    42     void sigHidLedsSyncStateChanged(bool fEnabled);
     38    /** Notifies about GUI language change. */
     39    void sigLanguageChange(QString strLanguage);
     40
     41    /** Notifies about Selector UI keyboard shortcut change. */
     42    void sigSelectorUIShortcutChange();
     43    /** Notifies about Runtime UI keyboard shortcut change. */
     44    void sigRuntimeUIShortcutChange();
     45
     46    /** Notifies about HID LED sync state change. */
     47    void sigHIDLedsSyncStateChange(bool fEnabled);
     48
    4349#ifdef RT_OS_DARWIN
     50    /** Mac OS X: Notifies about 'presentation mode' status change. */
    4451    void sigPresentationModeChange(bool fEnabled);
     52    /** Mac OS X: Notifies about 'dock icon' appearance change. */
    4553    void sigDockIconAppearanceChange(bool fEnabled);
    4654#endif /* RT_OS_DARWIN */
    4755
     56public:
     57
     58    /** Static Extra-data Manager instance/constructor. */
     59    static UIExtraDataManager* instance();
     60    /** Static Extra-data Manager destructor. */
     61    static void destroy();
     62
    4863private:
     64
     65    /** Extra-data Manager constructor. */
    4966    UIExtraDataManager();
     67    /** Extra-data Manager destructor. */
    5068    ~UIExtraDataManager();
    5169
    52     /* Private member vars */
     70    /** Singleton Extra-data Manager instance. */
    5371    static UIExtraDataManager *m_pInstance;
    54     CEventListener m_mainEventListener;
     72
     73    /** Main event-listener instance. */
     74    CEventListener m_listener;
     75    /** Extra-data event-handler instance. */
    5576    UIExtraDataEventHandler *m_pHandler;
    5677};
    5778
     79/** Singleton Extra-data Manager 'official' name. */
    5880#define gEDataManager UIExtraDataManager::instance()
    5981
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIShortcutPool.cpp

    r51035 r51038  
    223223{
    224224    /* Connect to extra-data signals: */
    225     connect(gEDataManager, SIGNAL(sigSelectorShortcutsChanged()), this, SLOT(sltReloadSelectorShortcuts()));
    226     connect(gEDataManager, SIGNAL(sigMachineShortcutsChanged()), this, SLOT(sltReloadMachineShortcuts()));
     225    connect(gEDataManager, SIGNAL(sigSelectorUIShortcutChange()), this, SLOT(sltReloadSelectorShortcuts()));
     226    connect(gEDataManager, SIGNAL(sigRuntimeUIShortcutChange()), this, SLOT(sltReloadMachineShortcuts()));
    227227}
    228228
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r51035 r51038  
    44134413    retranslateUi();
    44144414
    4415     connect(gEDataManager, SIGNAL(sigGUILanguageChange(QString)),
     4415    connect(gEDataManager, SIGNAL(sigLanguageChange(QString)),
    44164416            this, SLOT(sltGUILanguageChange(QString)));
    44174417
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r51035 r51038  
    657657    /* Subscribe to GUI_HidLedsSync extradata changes in order to
    658658     * be able to enable or disable feature dynamically. */
    659     connect(gEDataManager, SIGNAL(sigHidLedsSyncStateChanged(bool)), this, SLOT(sltHidLedsSyncStateChanged(bool)));
     659    connect(gEDataManager, SIGNAL(sigHIDLedsSyncStateChange(bool)), this, SLOT(sltHidLedsSyncStateChanged(bool)));
    660660#else
    661661    m_isHidLedsSyncEnabled = false;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette