~ubuntu-branches/ubuntu/trusty/virtualbox-lts-xenial/trusty-proposed

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/globals/UIExtraDataEventHandler.cpp

  • Committer: Package Import Robot
  • Author(s): Gianfranco Costamagna
  • Date: 2016-02-23 14:28:26 UTC
  • Revision ID: package-import@ubuntu.com-20160223142826-bdu69el2z6wa2a44
Tags: upstream-4.3.36-dfsg
ImportĀ upstreamĀ versionĀ 4.3.36-dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: UIExtraDataEventHandler.cpp $ */
 
2
/** @file
 
3
 *
 
4
 * VBox frontends: Qt GUI ("VirtualBox"):
 
5
 * UIExtraDataEventHandler class implementation
 
6
 */
 
7
 
 
8
/*
 
9
 * Copyright (C) 2010-2013 Oracle Corporation
 
10
 *
 
11
 * This file is part of VirtualBox Open Source Edition (OSE), as
 
12
 * available from http://www.virtualbox.org. This file is free software;
 
13
 * you can redistribute it and/or modify it under the terms of the GNU
 
14
 * General Public License (GPL) as published by the Free Software
 
15
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 
16
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 
17
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 
18
 */
 
19
 
 
20
/* Qt includes: */
 
21
#include <QMutex>
 
22
 
 
23
/* GUI includes: */
 
24
#include "UIExtraDataEventHandler.h"
 
25
#include "UIMainEventListener.h"
 
26
#include "VBoxGlobal.h"
 
27
#include "VBoxGlobalSettings.h"
 
28
#include "UIActionPool.h"
 
29
 
 
30
/* COM includes: */
 
31
#include "COMEnums.h"
 
32
#include "CEventSource.h"
 
33
 
 
34
class UIExtraDataEventHandlerPrivate: public QObject
 
35
{
 
36
    Q_OBJECT;
 
37
 
 
38
public:
 
39
 
 
40
    UIExtraDataEventHandlerPrivate(QObject *pParent = 0)
 
41
        : QObject(pParent)
 
42
    {}
 
43
 
 
44
public slots:
 
45
 
 
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/"))
 
52
            {
 
53
                /* Try to set the global setting to check its syntax */
 
54
                VBoxGlobalSettings gs(false /* non-null */);
 
55
                if (gs.setPublicProperty (strKey, strValue))
 
56
                {
 
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;
 
65
                }
 
66
            }
 
67
        }
 
68
    }
 
69
 
 
70
    void sltExtraDataChange(QString strId, QString strKey, QString strValue)
 
71
    {
 
72
        if (QUuid(strId).isNull())
 
73
        {
 
74
            if (strKey.startsWith ("GUI/"))
 
75
            {
 
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
 
 
106
                /* (temporary disabled by default) */
 
107
                bool f = (strValue == "1") ? true : false;
 
108
                emit sigHidLedsSyncStateChanged(f);
 
109
            }
 
110
 
 
111
#ifdef Q_WS_MAC
 
112
            /* Check for the currently running machine */
 
113
            if (strId == vboxGlobal().managedVMUuid())
 
114
            {
 
115
                if (   strKey == GUI_RealtimeDockIconUpdateEnabled
 
116
                    || strKey == GUI_RealtimeDockIconUpdateMonitor)
 
117
                {
 
118
                    bool f = strValue.toLower() == "false" ? false : true;
 
119
                    emit sigDockIconAppearanceChange(f);
 
120
                }
 
121
            }
 
122
#endif /* Q_WS_MAC */
 
123
        }
 
124
    }
 
125
 
 
126
signals:
 
127
 
 
128
    void sigGUILanguageChange(QString strLang);
 
129
    void sigSelectorShortcutsChanged();
 
130
    void sigMachineShortcutsChanged();
 
131
    void sigHidLedsSyncStateChanged(bool fEnabled);
 
132
#ifdef RT_OS_DARWIN
 
133
    void sigPresentationModeChange(bool fEnabled);
 
134
    void sigDockIconAppearanceChange(bool fEnabled);
 
135
#endif /* RT_OS_DARWIN */
 
136
 
 
137
private:
 
138
 
 
139
    /** protects #OnExtraDataChange() */
 
140
    QMutex m_mutex;
 
141
};
 
142
 
 
143
/* static */
 
144
UIExtraDataEventHandler *UIExtraDataEventHandler::m_pInstance = 0;
 
145
 
 
146
/* static */
 
147
UIExtraDataEventHandler* UIExtraDataEventHandler::instance()
 
148
{
 
149
    if (!m_pInstance)
 
150
        m_pInstance = new UIExtraDataEventHandler();
 
151
    return m_pInstance;
 
152
}
 
153
 
 
154
/* static */
 
155
void UIExtraDataEventHandler::destroy()
 
156
{
 
157
    if (m_pInstance)
 
158
    {
 
159
        delete m_pInstance;
 
160
        m_pInstance = 0;
 
161
    }
 
162
}
 
163
 
 
164
UIExtraDataEventHandler::UIExtraDataEventHandler()
 
165
  : m_pHandler(new UIExtraDataEventHandlerPrivate(this))
 
166
{
 
167
//    RTPrintf("Self add: %RTthrd\n", RTThreadSelf());
 
168
    const CVirtualBox &vbox = vboxGlobal().virtualBox();
 
169
    ComObjPtr<UIMainEventListenerImpl> pListener;
 
170
    pListener.createObject();
 
171
    pListener->init(new UIMainEventListener(), this);
 
172
    m_mainEventListener = CEventListener(pListener);
 
173
    QVector<KVBoxEventType> events;
 
174
    events
 
175
        << KVBoxEventType_OnExtraDataCanChange
 
176
        << KVBoxEventType_OnExtraDataChanged;
 
177
 
 
178
    vbox.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE);
 
179
    AssertWrapperOk(vbox);
 
180
 
 
181
    /* This is a vetoable event, so we have to respond to the event and have to
 
182
     * use a direct connection therefor. */
 
183
    connect(pListener->getWrapped(), SIGNAL(sigExtraDataCanChange(QString, QString, QString, bool&, QString&)),
 
184
            m_pHandler, SLOT(sltExtraDataCanChange(QString, QString, QString, bool&, QString&)),
 
185
            Qt::DirectConnection);
 
186
 
 
187
    /* Use a direct connection to the helper class. */
 
188
    connect(pListener->getWrapped(), SIGNAL(sigExtraDataChange(QString, QString, QString)),
 
189
            m_pHandler, SLOT(sltExtraDataChange(QString, QString, QString)),
 
190
            Qt::DirectConnection);
 
191
 
 
192
    /* UI signals */
 
193
    connect(m_pHandler, SIGNAL(sigGUILanguageChange(QString)),
 
194
            this, SIGNAL(sigGUILanguageChange(QString)),
 
195
            Qt::QueuedConnection);
 
196
 
 
197
    connect(m_pHandler, SIGNAL(sigSelectorShortcutsChanged()),
 
198
            this, SIGNAL(sigSelectorShortcutsChanged()),
 
199
            Qt::QueuedConnection);
 
200
 
 
201
    connect(m_pHandler, SIGNAL(sigMachineShortcutsChanged()),
 
202
            this, SIGNAL(sigMachineShortcutsChanged()),
 
203
            Qt::QueuedConnection);
 
204
 
 
205
    connect(m_pHandler, SIGNAL(sigHidLedsSyncStateChanged(bool)),
 
206
            this, SIGNAL(sigHidLedsSyncStateChanged(bool)),
 
207
            Qt::QueuedConnection);
 
208
 
 
209
#ifdef Q_WS_MAC
 
210
    connect(m_pHandler, SIGNAL(sigPresentationModeChange(bool)),
 
211
            this, SIGNAL(sigPresentationModeChange(bool)),
 
212
            Qt::QueuedConnection);
 
213
 
 
214
    connect(m_pHandler, SIGNAL(sigDockIconAppearanceChange(bool)),
 
215
            this, SIGNAL(sigDockIconAppearanceChange(bool)),
 
216
            Qt::QueuedConnection);
 
217
#endif /* Q_WS_MAC */
 
218
}
 
219
 
 
220
UIExtraDataEventHandler::~UIExtraDataEventHandler()
 
221
{
 
222
    const CVirtualBox &vbox = vboxGlobal().virtualBox();
 
223
    vbox.GetEventSource().UnregisterListener(m_mainEventListener);
 
224
}
 
225
 
 
226
#include "UIExtraDataEventHandler.moc"