1
/* $Id: UIExtraDataEventHandler.cpp $ */
4
* VBox frontends: Qt GUI ("VirtualBox"):
5
* UIExtraDataEventHandler class implementation
9
* Copyright (C) 2010-2013 Oracle Corporation
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.
24
#include "UIExtraDataEventHandler.h"
25
#include "UIMainEventListener.h"
26
#include "VBoxGlobal.h"
27
#include "VBoxGlobalSettings.h"
28
#include "UIActionPool.h"
32
#include "CEventSource.h"
34
class UIExtraDataEventHandlerPrivate: public QObject
40
UIExtraDataEventHandlerPrivate(QObject *pParent = 0)
46
void sltExtraDataCanChange(QString strId, QString strKey, QString strValue, bool &fVeto, QString &strVetoReason)
48
if (QUuid(strId).isNull())
50
/* it's a global extra data key someone wants to change */
51
if (strKey.startsWith("GUI/"))
53
/* Try to set the global setting to check its syntax */
54
VBoxGlobalSettings gs(false /* non-null */);
55
if (gs.setPublicProperty (strKey, strValue))
57
/* this is a known GUI property key */
60
strVetoReason = gs.lastError();
61
/* disallow the change when there is an error*/
70
void sltExtraDataChange(QString strId, QString strKey, QString strValue)
72
if (QUuid(strId).isNull())
74
if (strKey.startsWith ("GUI/"))
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();
83
if (strKey == GUI_PresentationModeEnabled)
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);
93
vboxGlobal().settings().setPublicProperty(strKey, strValue);
95
Assert(!!vboxGlobal().settings());
98
else if (vboxGlobal().isVMConsoleProcess())
100
/* Take care about HID LEDs sync */
101
if (strKey == GUI_HidLedsSync)
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. */
106
/* (temporary disabled by default) */
107
bool f = (strValue == "1") ? true : false;
108
emit sigHidLedsSyncStateChanged(f);
112
/* Check for the currently running machine */
113
if (strId == vboxGlobal().managedVMUuid())
115
if ( strKey == GUI_RealtimeDockIconUpdateEnabled
116
|| strKey == GUI_RealtimeDockIconUpdateMonitor)
118
bool f = strValue.toLower() == "false" ? false : true;
119
emit sigDockIconAppearanceChange(f);
122
#endif /* Q_WS_MAC */
128
void sigGUILanguageChange(QString strLang);
129
void sigSelectorShortcutsChanged();
130
void sigMachineShortcutsChanged();
131
void sigHidLedsSyncStateChanged(bool fEnabled);
133
void sigPresentationModeChange(bool fEnabled);
134
void sigDockIconAppearanceChange(bool fEnabled);
135
#endif /* RT_OS_DARWIN */
139
/** protects #OnExtraDataChange() */
144
UIExtraDataEventHandler *UIExtraDataEventHandler::m_pInstance = 0;
147
UIExtraDataEventHandler* UIExtraDataEventHandler::instance()
150
m_pInstance = new UIExtraDataEventHandler();
155
void UIExtraDataEventHandler::destroy()
164
UIExtraDataEventHandler::UIExtraDataEventHandler()
165
: m_pHandler(new UIExtraDataEventHandlerPrivate(this))
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;
175
<< KVBoxEventType_OnExtraDataCanChange
176
<< KVBoxEventType_OnExtraDataChanged;
178
vbox.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE);
179
AssertWrapperOk(vbox);
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);
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);
193
connect(m_pHandler, SIGNAL(sigGUILanguageChange(QString)),
194
this, SIGNAL(sigGUILanguageChange(QString)),
195
Qt::QueuedConnection);
197
connect(m_pHandler, SIGNAL(sigSelectorShortcutsChanged()),
198
this, SIGNAL(sigSelectorShortcutsChanged()),
199
Qt::QueuedConnection);
201
connect(m_pHandler, SIGNAL(sigMachineShortcutsChanged()),
202
this, SIGNAL(sigMachineShortcutsChanged()),
203
Qt::QueuedConnection);
205
connect(m_pHandler, SIGNAL(sigHidLedsSyncStateChanged(bool)),
206
this, SIGNAL(sigHidLedsSyncStateChanged(bool)),
207
Qt::QueuedConnection);
210
connect(m_pHandler, SIGNAL(sigPresentationModeChange(bool)),
211
this, SIGNAL(sigPresentationModeChange(bool)),
212
Qt::QueuedConnection);
214
connect(m_pHandler, SIGNAL(sigDockIconAppearanceChange(bool)),
215
this, SIGNAL(sigDockIconAppearanceChange(bool)),
216
Qt::QueuedConnection);
217
#endif /* Q_WS_MAC */
220
UIExtraDataEventHandler::~UIExtraDataEventHandler()
222
const CVirtualBox &vbox = vboxGlobal().virtualBox();
223
vbox.GetEventSource().UnregisterListener(m_mainEventListener);
226
#include "UIExtraDataEventHandler.moc"