1 | /* $Id: UIExtraDataEventHandler.cpp 44453 2013-01-30 10:21:33Z vboxsync $ */
|
---|
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 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
43 | , m_fIsTrayIconOwner(false)
|
---|
44 | #endif /* VBOX_GUI_WITH_SYSTRAY */
|
---|
45 | {}
|
---|
46 |
|
---|
47 | public slots:
|
---|
48 |
|
---|
49 | void sltExtraDataCanChange(QString strId, QString strKey, QString strValue, bool &fVeto, QString &strVetoReason)
|
---|
50 | {
|
---|
51 | if (QUuid(strId).isNull())
|
---|
52 | {
|
---|
53 | /* it's a global extra data key someone wants to change */
|
---|
54 | if (strKey.startsWith("GUI/"))
|
---|
55 | {
|
---|
56 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
57 | if (strKey == GUI_TrayIconWinID)
|
---|
58 | {
|
---|
59 | if (m_fIsTrayIconOwner)
|
---|
60 | {
|
---|
61 | if (!(strValue.isEmpty() ||
|
---|
62 | strValue == QString("%1")
|
---|
63 | .arg((qulonglong)vboxGlobal().mainWindow()->winId())))
|
---|
64 | fVeto = true;
|
---|
65 | }
|
---|
66 | return;
|
---|
67 | }
|
---|
68 | #endif /* VBOX_GUI_WITH_SYSTRAY */
|
---|
69 | /* Try to set the global setting to check its syntax */
|
---|
70 | VBoxGlobalSettings gs(false /* non-null */);
|
---|
71 | if (gs.setPublicProperty (strKey, strValue))
|
---|
72 | {
|
---|
73 | /* this is a known GUI property key */
|
---|
74 | if (!gs)
|
---|
75 | {
|
---|
76 | strVetoReason = gs.lastError();
|
---|
77 | /* disallow the change when there is an error*/
|
---|
78 | fVeto = true;
|
---|
79 | }
|
---|
80 | return;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | void sltExtraDataChange(QString strId, QString strKey, QString strValue)
|
---|
87 | {
|
---|
88 | if (QUuid(strId).isNull())
|
---|
89 | {
|
---|
90 | if (strKey.startsWith ("GUI/"))
|
---|
91 | {
|
---|
92 | if (strKey == GUI_LanguageId)
|
---|
93 | emit sigGUILanguageChange(strValue);
|
---|
94 | if (strKey == GUI_Input_SelectorShortcuts && gActionPool->type() == UIActionPoolType_Selector)
|
---|
95 | emit sigSelectorShortcutsChanged();
|
---|
96 | if (strKey == GUI_Input_MachineShortcuts && gActionPool->type() == UIActionPoolType_Runtime)
|
---|
97 | emit sigMachineShortcutsChanged();
|
---|
98 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
99 | if (strKey == GUI_MainWindowCount)
|
---|
100 | emit sigMainWindowCountChange(strValue.toInt());
|
---|
101 | if (strKey == GUI_TrayIconWinID)
|
---|
102 | {
|
---|
103 | if (strValue.isEmpty())
|
---|
104 | {
|
---|
105 | m_fIsTrayIconOwner = false;
|
---|
106 | emit sigCanShowTrayIcon(true);
|
---|
107 | }
|
---|
108 | else if (strValue == QString("%1")
|
---|
109 | .arg((qulonglong)vboxGlobal().mainWindow()->winId()))
|
---|
110 | {
|
---|
111 | m_fIsTrayIconOwner = true;
|
---|
112 | emit sigCanShowTrayIcon(true);
|
---|
113 | }
|
---|
114 | else
|
---|
115 | emit sigCanShowTrayIcon(false);
|
---|
116 | }
|
---|
117 | if (strKey == GUI_TrayIconEnabled)
|
---|
118 | emit sigTrayIconChange((strValue.toLower() == "true") ? true : false);
|
---|
119 | #endif /* VBOX_GUI_WITH_SYSTRAY */
|
---|
120 | #ifdef Q_WS_MAC
|
---|
121 | if (strKey == GUI_PresentationModeEnabled)
|
---|
122 | {
|
---|
123 | /* Default to true if it is an empty value */
|
---|
124 | QString testStr = strValue.toLower();
|
---|
125 | bool f = (testStr.isEmpty() || testStr == "false");
|
---|
126 | emit sigPresentationModeChange(f);
|
---|
127 | }
|
---|
128 | #endif /* Q_WS_MAC */
|
---|
129 |
|
---|
130 | m_mutex.lock();
|
---|
131 | vboxGlobal().settings().setPublicProperty(strKey, strValue);
|
---|
132 | m_mutex.unlock();
|
---|
133 | Assert(!!vboxGlobal().settings());
|
---|
134 | }
|
---|
135 | }
|
---|
136 | #ifdef Q_WS_MAC
|
---|
137 | else if (vboxGlobal().isVMConsoleProcess())
|
---|
138 | {
|
---|
139 | /* Check for the currently running machine */
|
---|
140 | if (strId == vboxGlobal().managedVMUuid())
|
---|
141 | {
|
---|
142 | if ( strKey == GUI_RealtimeDockIconUpdateEnabled
|
---|
143 | || strKey == GUI_RealtimeDockIconUpdateMonitor)
|
---|
144 | {
|
---|
145 | bool f = strValue.toLower() == "false" ? false : true;
|
---|
146 | emit sigDockIconAppearanceChange(f);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 | #endif /* Q_WS_MAC */
|
---|
151 | }
|
---|
152 |
|
---|
153 | signals:
|
---|
154 |
|
---|
155 | void sigGUILanguageChange(QString strLang);
|
---|
156 | void sigSelectorShortcutsChanged();
|
---|
157 | void sigMachineShortcutsChanged();
|
---|
158 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
159 | void sigMainWindowCountChange(int count);
|
---|
160 | void sigCanShowTrayIcon(bool fEnabled);
|
---|
161 | void sigTrayIconChange(bool fEnabled);
|
---|
162 | #endif /* VBOX_GUI_WITH_SYSTRAY */
|
---|
163 | #ifdef RT_OS_DARWIN
|
---|
164 | void sigPresentationModeChange(bool fEnabled);
|
---|
165 | void sigDockIconAppearanceChange(bool fEnabled);
|
---|
166 | #endif /* RT_OS_DARWIN */
|
---|
167 |
|
---|
168 | private:
|
---|
169 |
|
---|
170 | /** protects #OnExtraDataChange() */
|
---|
171 | QMutex m_mutex;
|
---|
172 |
|
---|
173 | /* Private member vars */
|
---|
174 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
175 | bool m_fIsTrayIconOwner;
|
---|
176 | #endif /* VBOX_GUI_WITH_SYSTRAY */
|
---|
177 | };
|
---|
178 |
|
---|
179 | /* static */
|
---|
180 | UIExtraDataEventHandler *UIExtraDataEventHandler::m_pInstance = 0;
|
---|
181 |
|
---|
182 | /* static */
|
---|
183 | UIExtraDataEventHandler* UIExtraDataEventHandler::instance()
|
---|
184 | {
|
---|
185 | if (!m_pInstance)
|
---|
186 | m_pInstance = new UIExtraDataEventHandler();
|
---|
187 | return m_pInstance;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /* static */
|
---|
191 | void UIExtraDataEventHandler::destroy()
|
---|
192 | {
|
---|
193 | if (m_pInstance)
|
---|
194 | {
|
---|
195 | delete m_pInstance;
|
---|
196 | m_pInstance = 0;
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | UIExtraDataEventHandler::UIExtraDataEventHandler()
|
---|
201 | : m_pHandler(new UIExtraDataEventHandlerPrivate(this))
|
---|
202 | {
|
---|
203 | // RTPrintf("Self add: %RTthrd\n", RTThreadSelf());
|
---|
204 | const CVirtualBox &vbox = vboxGlobal().virtualBox();
|
---|
205 | ComObjPtr<UIMainEventListenerImpl> pListener;
|
---|
206 | pListener.createObject();
|
---|
207 | pListener->init(new UIMainEventListener(), this);
|
---|
208 | m_mainEventListener = CEventListener(pListener);
|
---|
209 | QVector<KVBoxEventType> events;
|
---|
210 | events
|
---|
211 | << KVBoxEventType_OnExtraDataCanChange
|
---|
212 | << KVBoxEventType_OnExtraDataChanged;
|
---|
213 |
|
---|
214 | vbox.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE);
|
---|
215 | AssertWrapperOk(vbox);
|
---|
216 |
|
---|
217 | /* This is a vetoable event, so we have to respond to the event and have to
|
---|
218 | * use a direct connection therefor. */
|
---|
219 | connect(pListener->getWrapped(), SIGNAL(sigExtraDataCanChange(QString, QString, QString, bool&, QString&)),
|
---|
220 | m_pHandler, SLOT(sltExtraDataCanChange(QString, QString, QString, bool&, QString&)),
|
---|
221 | Qt::DirectConnection);
|
---|
222 |
|
---|
223 | /* Use a direct connection to the helper class. */
|
---|
224 | connect(pListener->getWrapped(), SIGNAL(sigExtraDataChange(QString, QString, QString)),
|
---|
225 | m_pHandler, SLOT(sltExtraDataChange(QString, QString, QString)),
|
---|
226 | Qt::DirectConnection);
|
---|
227 |
|
---|
228 | /* UI signals */
|
---|
229 | connect(m_pHandler, SIGNAL(sigGUILanguageChange(QString)),
|
---|
230 | this, SIGNAL(sigGUILanguageChange(QString)),
|
---|
231 | Qt::QueuedConnection);
|
---|
232 |
|
---|
233 | connect(m_pHandler, SIGNAL(sigSelectorShortcutsChanged()),
|
---|
234 | this, SIGNAL(sigSelectorShortcutsChanged()),
|
---|
235 | Qt::QueuedConnection);
|
---|
236 |
|
---|
237 | connect(m_pHandler, SIGNAL(sigMachineShortcutsChanged()),
|
---|
238 | this, SIGNAL(sigMachineShortcutsChanged()),
|
---|
239 | Qt::QueuedConnection);
|
---|
240 |
|
---|
241 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
242 | connect(m_pHandler, SIGNAL(sigMainWindowCountChange(int)),
|
---|
243 | this, SIGNAL(sigMainWindowCountChange(int)),
|
---|
244 | Qt::QueuedConnection);
|
---|
245 |
|
---|
246 | connect(m_pHandler, SIGNAL(sigCanShowTrayIcon(bool)),
|
---|
247 | this, SIGNAL(sigCanShowTrayIcon(bool)),
|
---|
248 | Qt::QueuedConnection);
|
---|
249 |
|
---|
250 | connect(m_pHandler, SIGNAL(sigTrayIconChange(bool)),
|
---|
251 | this, SIGNAL(sigTrayIconChange(bool)),
|
---|
252 | Qt::QueuedConnection);
|
---|
253 | #endif /* VBOX_GUI_WITH_SYSTRAY */
|
---|
254 |
|
---|
255 | #ifdef Q_WS_MAC
|
---|
256 | connect(m_pHandler, SIGNAL(sigPresentationModeChange(bool)),
|
---|
257 | this, SIGNAL(sigPresentationModeChange(bool)),
|
---|
258 | Qt::QueuedConnection);
|
---|
259 |
|
---|
260 | connect(m_pHandler, SIGNAL(sigDockIconAppearanceChange(bool)),
|
---|
261 | this, SIGNAL(sigDockIconAppearanceChange(bool)),
|
---|
262 | Qt::QueuedConnection);
|
---|
263 | #endif /* Q_WS_MAC */
|
---|
264 | }
|
---|
265 |
|
---|
266 | UIExtraDataEventHandler::~UIExtraDataEventHandler()
|
---|
267 | {
|
---|
268 | const CVirtualBox &vbox = vboxGlobal().virtualBox();
|
---|
269 | vbox.GetEventSource().UnregisterListener(m_mainEventListener);
|
---|
270 | }
|
---|
271 |
|
---|
272 | #include "UIExtraDataEventHandler.moc"
|
---|