1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxGlobal class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef __VBoxGlobal_h__
|
---|
20 | #define __VBoxGlobal_h__
|
---|
21 |
|
---|
22 | #include "COMDefs.h"
|
---|
23 | #include "VBox/com/Guid.h"
|
---|
24 |
|
---|
25 | #include "VBoxGlobalSettings.h"
|
---|
26 | #include "VBoxMedium.h"
|
---|
27 |
|
---|
28 | /* Qt includes */
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QLayout>
|
---|
31 | #include <QMenu>
|
---|
32 | #include <QStyle>
|
---|
33 | #include <QProcess>
|
---|
34 | #include <QHash>
|
---|
35 | #include <QFileIconProvider>
|
---|
36 |
|
---|
37 | #ifdef Q_WS_X11
|
---|
38 | # include <sys/wait.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | class QAction;
|
---|
42 | class QLabel;
|
---|
43 | class QToolButton;
|
---|
44 | class UIMachine;
|
---|
45 |
|
---|
46 | class Process : public QProcess
|
---|
47 | {
|
---|
48 | Q_OBJECT;
|
---|
49 |
|
---|
50 | public:
|
---|
51 |
|
---|
52 | static QByteArray singleShot (const QString &aProcessName,
|
---|
53 | int aTimeout = 5000
|
---|
54 | /* wait for data maximum 5 seconds */)
|
---|
55 | {
|
---|
56 | /* Why is it really needed is because of Qt4.3 bug with QProcess.
|
---|
57 | * This bug is about QProcess sometimes (~70%) do not receive
|
---|
58 | * notification about process was finished, so this makes
|
---|
59 | * 'bool QProcess::waitForFinished (int)' block the GUI thread and
|
---|
60 | * never dismissed with 'true' result even if process was really
|
---|
61 | * started&finished. So we just waiting for some information
|
---|
62 | * on process output and destroy the process with force. Due to
|
---|
63 | * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
|
---|
64 | * we have to change process state to QProcess::NotRunning. */
|
---|
65 |
|
---|
66 | QByteArray result;
|
---|
67 | Process process;
|
---|
68 | process.start (aProcessName);
|
---|
69 | bool firstShotReady = process.waitForReadyRead (aTimeout);
|
---|
70 | if (firstShotReady)
|
---|
71 | result = process.readAllStandardOutput();
|
---|
72 | process.setProcessState (QProcess::NotRunning);
|
---|
73 | #ifdef Q_WS_X11
|
---|
74 | int status;
|
---|
75 | if (process.pid() > 0)
|
---|
76 | waitpid(process.pid(), &status, 0);
|
---|
77 | #endif
|
---|
78 | return result;
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected:
|
---|
82 |
|
---|
83 | Process (QWidget *aParent = 0) : QProcess (aParent) {}
|
---|
84 | };
|
---|
85 |
|
---|
86 | struct StorageSlot
|
---|
87 | {
|
---|
88 | StorageSlot() : bus (KStorageBus_Null), port (0), device (0) {}
|
---|
89 | StorageSlot (const StorageSlot &aOther) : bus (aOther.bus), port (aOther.port), device (aOther.device) {}
|
---|
90 | StorageSlot (KStorageBus aBus, LONG aPort, LONG aDevice) : bus (aBus), port (aPort), device (aDevice) {}
|
---|
91 | StorageSlot& operator= (const StorageSlot &aOther) { bus = aOther.bus; port = aOther.port; device = aOther.device; return *this; }
|
---|
92 | bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; }
|
---|
93 | bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; }
|
---|
94 | bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) ||
|
---|
95 | (bus == aOther.bus && port < aOther.port) ||
|
---|
96 | (bus == aOther.bus && port == aOther.port && device < aOther.device); }
|
---|
97 | bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) ||
|
---|
98 | (bus == aOther.bus && port > aOther.port) ||
|
---|
99 | (bus == aOther.bus && port == aOther.port && device > aOther.device); }
|
---|
100 | bool isNull() { return bus == KStorageBus_Null; }
|
---|
101 | KStorageBus bus; LONG port; LONG device;
|
---|
102 | };
|
---|
103 | Q_DECLARE_METATYPE (StorageSlot);
|
---|
104 |
|
---|
105 | // VBoxGlobal class
|
---|
106 | ////////////////////////////////////////////////////////////////////////////////
|
---|
107 |
|
---|
108 | class VBoxSelectorWnd;
|
---|
109 | class UIRegistrationWzd;
|
---|
110 | class VBoxUpdateDlg;
|
---|
111 |
|
---|
112 | class VBoxGlobal : public QObject
|
---|
113 | {
|
---|
114 | Q_OBJECT
|
---|
115 |
|
---|
116 | public:
|
---|
117 |
|
---|
118 | typedef QHash <ulong, QString> QULongStringHash;
|
---|
119 | typedef QHash <long, QString> QLongStringHash;
|
---|
120 |
|
---|
121 | static VBoxGlobal &instance();
|
---|
122 |
|
---|
123 | bool isValid() { return mValid; }
|
---|
124 |
|
---|
125 | static QString qtRTVersionString();
|
---|
126 | static uint qtRTVersion();
|
---|
127 | static QString qtCTVersionString();
|
---|
128 | static uint qtCTVersion();
|
---|
129 |
|
---|
130 | QString versionString() { return mVerString; }
|
---|
131 |
|
---|
132 | CVirtualBox virtualBox() const { return mVBox; }
|
---|
133 |
|
---|
134 | VBoxGlobalSettings &settings() { return gset; }
|
---|
135 | bool setSettings (VBoxGlobalSettings &gs);
|
---|
136 |
|
---|
137 | VBoxSelectorWnd &selectorWnd();
|
---|
138 |
|
---|
139 | QWidget *vmWindow();
|
---|
140 |
|
---|
141 | bool createVirtualMachine(const CSession &session);
|
---|
142 | UIMachine* virtualMachine();
|
---|
143 |
|
---|
144 | /* main window handle storage */
|
---|
145 | void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
|
---|
146 | QWidget *mainWindow() const { return mMainWindow; }
|
---|
147 |
|
---|
148 | /* branding */
|
---|
149 | bool brandingIsActive (bool aForce = false);
|
---|
150 | QString brandingGetKey (QString aKey);
|
---|
151 |
|
---|
152 | bool processArgs();
|
---|
153 |
|
---|
154 | bool switchToMachine(CMachine &machine);
|
---|
155 | bool launchMachine(CMachine &machine);
|
---|
156 |
|
---|
157 | bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
|
---|
158 | bool showStartVMErrors() const { return mShowStartVMErrors; }
|
---|
159 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
160 | bool isTrayMenu() const;
|
---|
161 | void setTrayMenu(bool aIsTrayMenu);
|
---|
162 | void trayIconShowSelector();
|
---|
163 | bool trayIconInstall();
|
---|
164 | #endif
|
---|
165 | QString managedVMUuid() const { return vmUuid; }
|
---|
166 | QList<QUrl> &argUrlList() { return m_ArgUrlList; }
|
---|
167 |
|
---|
168 | VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
|
---|
169 | const char *vmRenderModeStr() const { return vm_render_mode_str; }
|
---|
170 | bool isKWinManaged() const { return mIsKWinManaged; }
|
---|
171 |
|
---|
172 | const QRect availableGeometry(int iScreen = 0) const;
|
---|
173 |
|
---|
174 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
175 | bool isDebuggerEnabled(CMachine &aMachine);
|
---|
176 | bool isDebuggerAutoShowEnabled(CMachine &aMachine);
|
---|
177 | bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
|
---|
178 | bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
|
---|
179 | RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
|
---|
180 |
|
---|
181 | bool isStartPausedEnabled() const { return mStartPaused; }
|
---|
182 | #else
|
---|
183 | bool isDebuggerAutoShowEnabled() const { return false; }
|
---|
184 | bool isDebuggerAutoShowCommandLineEnabled() const { return false; }
|
---|
185 | bool isDebuggerAutoShowStatisticsEnabled() const { return false; }
|
---|
186 |
|
---|
187 | bool isStartPausedEnabled() const { return false; }
|
---|
188 | #endif
|
---|
189 |
|
---|
190 | /* VBox enum to/from string/icon/color convertors */
|
---|
191 |
|
---|
192 | QList <CGuestOSType> vmGuestOSFamilyList() const;
|
---|
193 | QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
|
---|
194 | QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
|
---|
195 | CGuestOSType vmGuestOSType (const QString &aTypeId,
|
---|
196 | const QString &aFamilyId = QString::null) const;
|
---|
197 | QString vmGuestOSTypeDescription (const QString &aTypeId) const;
|
---|
198 |
|
---|
199 | QPixmap toIcon (KMachineState s) const
|
---|
200 | {
|
---|
201 | QPixmap *pm = mVMStateIcons.value (s);
|
---|
202 | AssertMsg (pm, ("Icon for VM state %d must be defined", s));
|
---|
203 | return pm ? *pm : QPixmap();
|
---|
204 | }
|
---|
205 |
|
---|
206 | static inline QString yearsToString (uint32_t cVal)
|
---|
207 | {
|
---|
208 | return tr("%n year(s)", "", cVal);
|
---|
209 | }
|
---|
210 |
|
---|
211 | static inline QString monthsToString (uint32_t cVal)
|
---|
212 | {
|
---|
213 | return tr("%n month(s)", "", cVal);
|
---|
214 | }
|
---|
215 |
|
---|
216 | static inline QString daysToString (uint32_t cVal)
|
---|
217 | {
|
---|
218 | return tr("%n day(s)", "", cVal);
|
---|
219 | }
|
---|
220 |
|
---|
221 | static inline QString hoursToString (uint32_t cVal)
|
---|
222 | {
|
---|
223 | return tr("%n hour(s)", "", cVal);
|
---|
224 | }
|
---|
225 |
|
---|
226 | static inline QString minutesToString (uint32_t cVal)
|
---|
227 | {
|
---|
228 | return tr("%n minute(s)", "", cVal);
|
---|
229 | }
|
---|
230 |
|
---|
231 | static inline QString secondsToString (uint32_t cVal)
|
---|
232 | {
|
---|
233 | return tr("%n second(s)", "", cVal);
|
---|
234 | }
|
---|
235 |
|
---|
236 | const QColor &toColor (KMachineState s) const
|
---|
237 | {
|
---|
238 | static const QColor none;
|
---|
239 | AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
|
---|
240 | return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
|
---|
241 | }
|
---|
242 |
|
---|
243 | QString toString (KMachineState s) const
|
---|
244 | {
|
---|
245 | AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
|
---|
246 | return mMachineStates.value (s);
|
---|
247 | }
|
---|
248 |
|
---|
249 | QString toString (KSessionState s) const
|
---|
250 | {
|
---|
251 | AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
|
---|
252 | return mSessionStates.value (s);
|
---|
253 | }
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Returns a string representation of the given KStorageBus enum value.
|
---|
257 | * Complementary to #toStorageBusType (const QString &) const.
|
---|
258 | */
|
---|
259 | QString toString (KStorageBus aBus) const
|
---|
260 | {
|
---|
261 | AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
|
---|
262 | return mStorageBuses [aBus];
|
---|
263 | }
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * Returns a KStorageBus enum value corresponding to the given string
|
---|
267 | * representation. Complementary to #toString (KStorageBus) const.
|
---|
268 | */
|
---|
269 | KStorageBus toStorageBusType (const QString &aBus) const
|
---|
270 | {
|
---|
271 | QULongStringHash::const_iterator it =
|
---|
272 | qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
|
---|
273 | AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
|
---|
274 | aBus.toLatin1().constData()));
|
---|
275 | return KStorageBus (it.key());
|
---|
276 | }
|
---|
277 |
|
---|
278 | KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
|
---|
279 | {
|
---|
280 | KStorageBus sb = KStorageBus_Null;
|
---|
281 | switch (aControllerType)
|
---|
282 | {
|
---|
283 | case KStorageControllerType_Null: sb = KStorageBus_Null; break;
|
---|
284 | case KStorageControllerType_PIIX3:
|
---|
285 | case KStorageControllerType_PIIX4:
|
---|
286 | case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
|
---|
287 | case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
|
---|
288 | case KStorageControllerType_LsiLogic:
|
---|
289 | case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
|
---|
290 | case KStorageControllerType_I82078: sb = KStorageBus_Floppy; break;
|
---|
291 | default:
|
---|
292 | AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
|
---|
293 | }
|
---|
294 | return sb;
|
---|
295 | }
|
---|
296 |
|
---|
297 | QString toString (KStorageBus aBus, LONG aChannel) const;
|
---|
298 | LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
|
---|
299 |
|
---|
300 | QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
|
---|
301 | LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
|
---|
302 |
|
---|
303 | QString toString (StorageSlot aSlot) const;
|
---|
304 | StorageSlot toStorageSlot (const QString &aSlot) const;
|
---|
305 |
|
---|
306 | QString toString (KMediumType t) const
|
---|
307 | {
|
---|
308 | AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
|
---|
309 | return mDiskTypes.value (t);
|
---|
310 | }
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Similar to toString (KMediumType), but returns 'Differencing' for
|
---|
314 | * normal hard disks that have a parent.
|
---|
315 | */
|
---|
316 | QString mediumTypeString (const CMedium &aHD) const
|
---|
317 | {
|
---|
318 | if (!aHD.GetParent().isNull())
|
---|
319 | {
|
---|
320 | Assert (aHD.GetType() == KMediumType_Normal);
|
---|
321 | return mDiskTypes_Differencing;
|
---|
322 | }
|
---|
323 | return toString (aHD.GetType());
|
---|
324 | }
|
---|
325 |
|
---|
326 | QString toString (KAuthType t) const
|
---|
327 | {
|
---|
328 | AssertMsg (!mAuthTypes.value (t).isNull(), ("No text for %d", t));
|
---|
329 | return mAuthTypes.value (t);
|
---|
330 | }
|
---|
331 |
|
---|
332 | QString toString (KPortMode t) const
|
---|
333 | {
|
---|
334 | AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
|
---|
335 | return mPortModeTypes.value (t);
|
---|
336 | }
|
---|
337 |
|
---|
338 | QString toString (KUSBDeviceFilterAction t) const
|
---|
339 | {
|
---|
340 | AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
|
---|
341 | return mUSBFilterActionTypes.value (t);
|
---|
342 | }
|
---|
343 |
|
---|
344 | QString toString (KClipboardMode t) const
|
---|
345 | {
|
---|
346 | AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
|
---|
347 | return mClipboardTypes.value (t);
|
---|
348 | }
|
---|
349 |
|
---|
350 | KClipboardMode toClipboardModeType (const QString &s) const
|
---|
351 | {
|
---|
352 | QULongStringHash::const_iterator it =
|
---|
353 | qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
|
---|
354 | AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
|
---|
355 | s.toLatin1().constData()));
|
---|
356 | return KClipboardMode (it.key());
|
---|
357 | }
|
---|
358 |
|
---|
359 | QString toString (KStorageControllerType t) const
|
---|
360 | {
|
---|
361 | AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
|
---|
362 | return mStorageControllerTypes.value (t);
|
---|
363 | }
|
---|
364 |
|
---|
365 | KStorageControllerType toControllerType (const QString &s) const
|
---|
366 | {
|
---|
367 | QULongStringHash::const_iterator it =
|
---|
368 | qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
|
---|
369 | AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
|
---|
370 | s.toLatin1().constData()));
|
---|
371 | return KStorageControllerType (it.key());
|
---|
372 | }
|
---|
373 |
|
---|
374 | KAuthType toAuthType (const QString &s) const
|
---|
375 | {
|
---|
376 | QULongStringHash::const_iterator it =
|
---|
377 | qFind (mAuthTypes.begin(), mAuthTypes.end(), s);
|
---|
378 | AssertMsg (it != mAuthTypes.end(), ("No value for {%s}",
|
---|
379 | s.toLatin1().constData()));
|
---|
380 | return KAuthType (it.key());
|
---|
381 | }
|
---|
382 |
|
---|
383 | KPortMode toPortMode (const QString &s) const
|
---|
384 | {
|
---|
385 | QULongStringHash::const_iterator it =
|
---|
386 | qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
|
---|
387 | AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
|
---|
388 | s.toLatin1().constData()));
|
---|
389 | return KPortMode (it.key());
|
---|
390 | }
|
---|
391 |
|
---|
392 | KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
|
---|
393 | {
|
---|
394 | QULongStringHash::const_iterator it =
|
---|
395 | qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
|
---|
396 | AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
|
---|
397 | s.toLatin1().constData()));
|
---|
398 | return KUSBDeviceFilterAction (it.key());
|
---|
399 | }
|
---|
400 |
|
---|
401 | QString toString (KDeviceType t) const
|
---|
402 | {
|
---|
403 | AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
|
---|
404 | return mDeviceTypes.value (t);
|
---|
405 | }
|
---|
406 |
|
---|
407 | KDeviceType toDeviceType (const QString &s) const
|
---|
408 | {
|
---|
409 | QULongStringHash::const_iterator it =
|
---|
410 | qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
|
---|
411 | AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
|
---|
412 | s.toLatin1().constData()));
|
---|
413 | return KDeviceType (it.key());
|
---|
414 | }
|
---|
415 |
|
---|
416 | QStringList deviceTypeStrings() const;
|
---|
417 |
|
---|
418 | QString toString (KAudioDriverType t) const
|
---|
419 | {
|
---|
420 | AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
|
---|
421 | return mAudioDriverTypes.value (t);
|
---|
422 | }
|
---|
423 |
|
---|
424 | KAudioDriverType toAudioDriverType (const QString &s) const
|
---|
425 | {
|
---|
426 | QULongStringHash::const_iterator it =
|
---|
427 | qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
|
---|
428 | AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
|
---|
429 | s.toLatin1().constData()));
|
---|
430 | return KAudioDriverType (it.key());
|
---|
431 | }
|
---|
432 |
|
---|
433 | QString toString (KAudioControllerType t) const
|
---|
434 | {
|
---|
435 | AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
|
---|
436 | return mAudioControllerTypes.value (t);
|
---|
437 | }
|
---|
438 |
|
---|
439 | KAudioControllerType toAudioControllerType (const QString &s) const
|
---|
440 | {
|
---|
441 | QULongStringHash::const_iterator it =
|
---|
442 | qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
|
---|
443 | AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
|
---|
444 | s.toLatin1().constData()));
|
---|
445 | return KAudioControllerType (it.key());
|
---|
446 | }
|
---|
447 |
|
---|
448 | QString toString (KNetworkAdapterType t) const
|
---|
449 | {
|
---|
450 | AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
|
---|
451 | return mNetworkAdapterTypes.value (t);
|
---|
452 | }
|
---|
453 |
|
---|
454 | KNetworkAdapterType toNetworkAdapterType (const QString &s) const
|
---|
455 | {
|
---|
456 | QULongStringHash::const_iterator it =
|
---|
457 | qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
|
---|
458 | AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
|
---|
459 | s.toLatin1().constData()));
|
---|
460 | return KNetworkAdapterType (it.key());
|
---|
461 | }
|
---|
462 |
|
---|
463 | QString toString (KNetworkAttachmentType t) const
|
---|
464 | {
|
---|
465 | AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
|
---|
466 | return mNetworkAttachmentTypes.value (t);
|
---|
467 | }
|
---|
468 |
|
---|
469 | KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
|
---|
470 | {
|
---|
471 | QULongStringHash::const_iterator it =
|
---|
472 | qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
|
---|
473 | AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
|
---|
474 | s.toLatin1().constData()));
|
---|
475 | return KNetworkAttachmentType (it.key());
|
---|
476 | }
|
---|
477 |
|
---|
478 | QString toString (KNATProtocol t) const
|
---|
479 | {
|
---|
480 | AssertMsg (!mNATProtocolTypes.value (t).isNull(), ("No text for %d", t));
|
---|
481 | return mNATProtocolTypes.value (t);
|
---|
482 | }
|
---|
483 |
|
---|
484 | KNATProtocol toNATProtocolType (const QString &s) const
|
---|
485 | {
|
---|
486 | QULongStringHash::const_iterator it =
|
---|
487 | qFind (mNATProtocolTypes.begin(), mNATProtocolTypes.end(), s);
|
---|
488 | AssertMsg (it != mNATProtocolTypes.end(), ("No value for {%s}",
|
---|
489 | s.toLatin1().constData()));
|
---|
490 | return KNATProtocol (it.key());
|
---|
491 | }
|
---|
492 |
|
---|
493 | QString toString (KUSBDeviceState aState) const
|
---|
494 | {
|
---|
495 | AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
|
---|
496 | return mUSBDeviceStates.value (aState);
|
---|
497 | }
|
---|
498 |
|
---|
499 | QString toString (KChipsetType t) const
|
---|
500 | {
|
---|
501 | AssertMsg (!mChipsetTypes.value (t).isNull(), ("No text for %d", t));
|
---|
502 | return mChipsetTypes.value (t);
|
---|
503 | }
|
---|
504 |
|
---|
505 | KChipsetType toChipsetType (const QString &s) const
|
---|
506 | {
|
---|
507 | QULongStringHash::const_iterator it =
|
---|
508 | qFind (mChipsetTypes.begin(), mChipsetTypes.end(), s);
|
---|
509 | AssertMsg (it != mChipsetTypes.end(), ("No value for {%s}",
|
---|
510 | s.toLatin1().constData()));
|
---|
511 | return KChipsetType (it.key());
|
---|
512 | }
|
---|
513 |
|
---|
514 | QStringList COMPortNames() const;
|
---|
515 | QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
|
---|
516 | bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
|
---|
517 |
|
---|
518 | QStringList LPTPortNames() const;
|
---|
519 | QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
|
---|
520 | bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
|
---|
521 |
|
---|
522 | QPixmap snapshotIcon (bool online) const
|
---|
523 | {
|
---|
524 | return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
|
---|
525 | }
|
---|
526 |
|
---|
527 | static bool hasAllowedExtension(const QString &strExt, const QStringList &extList) { for(int i = 0; i < extList.size(); ++i) if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive)) return true; return false;}
|
---|
528 | QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
|
---|
529 | QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
|
---|
530 |
|
---|
531 | QPixmap warningIcon() const { return mWarningIcon; }
|
---|
532 | QPixmap errorIcon() const { return mErrorIcon; }
|
---|
533 |
|
---|
534 | /* details generators */
|
---|
535 |
|
---|
536 | QString details (const CMedium &aHD, bool aPredictDiff);
|
---|
537 |
|
---|
538 | QString details (const CUSBDevice &aDevice) const;
|
---|
539 | QString toolTip (const CUSBDevice &aDevice) const;
|
---|
540 | QString toolTip (const CUSBDeviceFilter &aFilter) const;
|
---|
541 |
|
---|
542 | QString detailsReport (const CMachine &aMachine, bool aWithLinks);
|
---|
543 |
|
---|
544 | QString platformInfo();
|
---|
545 |
|
---|
546 | /* VirtualBox helpers */
|
---|
547 |
|
---|
548 | #if defined(Q_WS_X11) && !defined(VBOX_OSE)
|
---|
549 | double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
|
---|
550 | bool showVirtualBoxLicense();
|
---|
551 | #endif
|
---|
552 |
|
---|
553 | CSession openSession(const QString &aId, bool aExisting = false);
|
---|
554 |
|
---|
555 | /** Shortcut to openSession (aId, true). */
|
---|
556 | CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
|
---|
557 |
|
---|
558 | bool startMachine(const QString &strId);
|
---|
559 |
|
---|
560 | void startEnumeratingMedia();
|
---|
561 |
|
---|
562 | /**
|
---|
563 | * Returns a list of all currently registered media. This list is used to
|
---|
564 | * globally track the accessibility state of all media on a dedicated thread.
|
---|
565 | *
|
---|
566 | * Note that the media list is initially empty (i.e. before the enumeration
|
---|
567 | * process is started for the first time using #startEnumeratingMedia()).
|
---|
568 | * See #startEnumeratingMedia() for more information about how meida are
|
---|
569 | * sorted in the returned list.
|
---|
570 | */
|
---|
571 | const VBoxMediaList ¤tMediaList() const { return mMediaList; }
|
---|
572 |
|
---|
573 | /** Returns true if the media enumeration is in progress. */
|
---|
574 | bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
|
---|
575 |
|
---|
576 | VBoxDefs::MediumType mediumTypeToLocal(KDeviceType globalType);
|
---|
577 | KDeviceType mediumTypeToGlobal(VBoxDefs::MediumType localType);
|
---|
578 |
|
---|
579 | void addMedium (const VBoxMedium &);
|
---|
580 | void updateMedium (const VBoxMedium &);
|
---|
581 | void removeMedium (VBoxDefs::MediumType, const QString &);
|
---|
582 |
|
---|
583 | bool findMedium (const CMedium &, VBoxMedium &) const;
|
---|
584 | VBoxMedium findMedium (const QString &aMediumId) const;
|
---|
585 |
|
---|
586 | /** Compact version of #findMediumTo(). Asserts if not found. */
|
---|
587 | VBoxMedium getMedium (const CMedium &aObj) const
|
---|
588 | {
|
---|
589 | VBoxMedium medium;
|
---|
590 | if (!findMedium (aObj, medium))
|
---|
591 | AssertFailed();
|
---|
592 | return medium;
|
---|
593 | }
|
---|
594 |
|
---|
595 | QString openMediumWithFileOpenDialog(VBoxDefs::MediumType mediumType, QWidget *pParent = 0,
|
---|
596 | const QString &strDefaultFolder = QString(), bool fUseLastFolder = false) const;
|
---|
597 |
|
---|
598 | /* Returns the number of current running Fe/Qt4 main windows. */
|
---|
599 | int mainWindowCount();
|
---|
600 |
|
---|
601 | /* various helpers */
|
---|
602 |
|
---|
603 | QString languageName() const;
|
---|
604 | QString languageCountry() const;
|
---|
605 | QString languageNameEnglish() const;
|
---|
606 | QString languageCountryEnglish() const;
|
---|
607 | QString languageTranslators() const;
|
---|
608 |
|
---|
609 | void retranslateUi();
|
---|
610 |
|
---|
611 | /** @internal made public for internal purposes */
|
---|
612 | void cleanup();
|
---|
613 |
|
---|
614 | /* public static stuff */
|
---|
615 |
|
---|
616 | static bool shouldWarnAboutToLowVRAM(const CMachine *pMachine = 0);
|
---|
617 | static bool isDOSType (const QString &aOSTypeId);
|
---|
618 |
|
---|
619 | static QString languageId();
|
---|
620 | static void loadLanguage (const QString &aLangId = QString::null);
|
---|
621 | QString helpFile() const;
|
---|
622 |
|
---|
623 | static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
|
---|
624 |
|
---|
625 | static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
|
---|
626 | bool aCanResize = true);
|
---|
627 | static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
|
---|
628 | bool aCanResize = true);
|
---|
629 | static QRegion flip (const QRegion &aRegion);
|
---|
630 |
|
---|
631 | static void centerWidget (QWidget *aWidget, QWidget *aRelative,
|
---|
632 | bool aCanResize = true);
|
---|
633 |
|
---|
634 | static QChar decimalSep();
|
---|
635 | static QString sizeRegexp();
|
---|
636 |
|
---|
637 | static QString toHumanReadableList(const QStringList &list);
|
---|
638 |
|
---|
639 | static quint64 parseSize (const QString &);
|
---|
640 | static QString formatSize (quint64 aSize, uint aDecimal = 2,
|
---|
641 | VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
|
---|
642 |
|
---|
643 | static quint64 requiredVideoMemory (CMachine *aMachine = 0, int cMonitors = 1);
|
---|
644 |
|
---|
645 | static QString locationForHTML (const QString &aFileName);
|
---|
646 |
|
---|
647 | static QString highlight (const QString &aStr, bool aToolTip = false);
|
---|
648 |
|
---|
649 | static QString replaceHtmlEntities(QString strText);
|
---|
650 | static QString emphasize (const QString &aStr);
|
---|
651 |
|
---|
652 | static QString systemLanguageId();
|
---|
653 |
|
---|
654 | static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
|
---|
655 |
|
---|
656 | static QString removeAccelMark (const QString &aText);
|
---|
657 |
|
---|
658 | static QString insertKeyToActionText (const QString &aText, const QString &aKey);
|
---|
659 | static QString extractKeyFromActionText (const QString &aText);
|
---|
660 |
|
---|
661 | static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
|
---|
662 |
|
---|
663 | static QWidget *findWidget (QWidget *aParent, const char *aName,
|
---|
664 | const char *aClassName = NULL,
|
---|
665 | bool aRecursive = false);
|
---|
666 |
|
---|
667 | static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
|
---|
668 | static QList <QPair <QString, QString> > HDDBackends();
|
---|
669 | static QList <QPair <QString, QString> > DVDBackends();
|
---|
670 | static QList <QPair <QString, QString> > FloppyBackends();
|
---|
671 |
|
---|
672 | /* Qt 4.2.0 support function */
|
---|
673 | static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
|
---|
674 | {
|
---|
675 | #if QT_VERSION < 0x040300
|
---|
676 | /* Deprecated since > 4.2 */
|
---|
677 | aLayout->setMargin (aMargin);
|
---|
678 | #else
|
---|
679 | /* New since > 4.2 */
|
---|
680 | aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
|
---|
681 | #endif
|
---|
682 | }
|
---|
683 |
|
---|
684 | static QString documentsPath();
|
---|
685 |
|
---|
686 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
687 | static bool isAcceleration2DVideoAvailable();
|
---|
688 |
|
---|
689 | /** additional video memory required for the best 2D support performance
|
---|
690 | * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
|
---|
691 | static quint64 required2DOffscreenVideoMemory();
|
---|
692 | #endif
|
---|
693 |
|
---|
694 | #ifdef VBOX_WITH_CRHGSMI
|
---|
695 | static quint64 required3DWddmOffscreenVideoMemory(CMachine *aMachine = 0, int cMonitors = 1);
|
---|
696 | #endif
|
---|
697 |
|
---|
698 | #ifdef Q_WS_MAC
|
---|
699 | bool isSheetWindowsAllowed(QWidget *pParent) const;
|
---|
700 | #endif /* Q_WS_MAC */
|
---|
701 |
|
---|
702 | signals:
|
---|
703 |
|
---|
704 | /**
|
---|
705 | * Emitted at the beginning of the enumeration process started by
|
---|
706 | * #startEnumeratingMedia().
|
---|
707 | */
|
---|
708 | void mediumEnumStarted();
|
---|
709 |
|
---|
710 | /**
|
---|
711 | * Emitted when a new medium item from the list has updated its
|
---|
712 | * accessibility state.
|
---|
713 | */
|
---|
714 | void mediumEnumerated (const VBoxMedium &aMedum);
|
---|
715 |
|
---|
716 | /**
|
---|
717 | * Emitted at the end of the enumeration process started by
|
---|
718 | * #startEnumeratingMedia(). The @a aList argument is passed for
|
---|
719 | * convenience, it is exactly the same as returned by #currentMediaList().
|
---|
720 | */
|
---|
721 | void mediumEnumFinished (const VBoxMediaList &aList);
|
---|
722 |
|
---|
723 | /** Emitted when a new media is added using #addMedia(). */
|
---|
724 | void mediumAdded (const VBoxMedium &);
|
---|
725 |
|
---|
726 | /** Emitted when the media is updated using #updateMedia(). */
|
---|
727 | void mediumUpdated (const VBoxMedium &);
|
---|
728 |
|
---|
729 | /** Emitted when the media is removed using #removeMedia(). */
|
---|
730 | void mediumRemoved (VBoxDefs::MediumType, const QString &);
|
---|
731 |
|
---|
732 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
733 | void sigTrayIconShow(bool fEnabled);
|
---|
734 | #endif
|
---|
735 |
|
---|
736 | public slots:
|
---|
737 |
|
---|
738 | bool openURL (const QString &aURL);
|
---|
739 |
|
---|
740 | void showRegistrationDialog (bool aForce = true);
|
---|
741 | void showUpdateDialog (bool aForce = true);
|
---|
742 | void perDayNewVersionNotifier();
|
---|
743 | void sltGUILanguageChange(QString strLang);
|
---|
744 |
|
---|
745 | protected:
|
---|
746 |
|
---|
747 | bool event (QEvent *e);
|
---|
748 | bool eventFilter (QObject *, QEvent *);
|
---|
749 |
|
---|
750 | private:
|
---|
751 |
|
---|
752 | VBoxGlobal();
|
---|
753 | ~VBoxGlobal();
|
---|
754 |
|
---|
755 | void init();
|
---|
756 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
757 | void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
|
---|
758 | void setDebuggerVar(int *piDbgCfgVar, bool fState);
|
---|
759 | bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
|
---|
760 | #endif
|
---|
761 |
|
---|
762 | bool mValid;
|
---|
763 |
|
---|
764 | CVirtualBox mVBox;
|
---|
765 |
|
---|
766 | VBoxGlobalSettings gset;
|
---|
767 |
|
---|
768 | VBoxSelectorWnd *mSelectorWnd;
|
---|
769 | UIMachine *m_pVirtualMachine;
|
---|
770 | QWidget* mMainWindow;
|
---|
771 |
|
---|
772 | #ifdef VBOX_WITH_REGISTRATION
|
---|
773 | UIRegistrationWzd *mRegDlg;
|
---|
774 | #endif
|
---|
775 | VBoxUpdateDlg *mUpdDlg;
|
---|
776 |
|
---|
777 | QString vmUuid;
|
---|
778 | QList<QUrl> m_ArgUrlList;
|
---|
779 |
|
---|
780 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
781 | bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
|
---|
782 | bool mIncreasedWindowCounter : 1;
|
---|
783 | #endif
|
---|
784 |
|
---|
785 | /** Whether to show error message boxes for VM start errors. */
|
---|
786 | bool mShowStartVMErrors;
|
---|
787 |
|
---|
788 | QThread *mMediaEnumThread;
|
---|
789 | VBoxMediaList mMediaList;
|
---|
790 |
|
---|
791 | VBoxDefs::RenderMode vm_render_mode;
|
---|
792 | const char * vm_render_mode_str;
|
---|
793 | bool mIsKWinManaged;
|
---|
794 |
|
---|
795 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
796 | /** Whether the debugger should be accessible or not.
|
---|
797 | * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
|
---|
798 | * VBOX_GUI_DBG_AUTO_SHOW to enable. */
|
---|
799 | int mDbgEnabled;
|
---|
800 | /** Whether to show the debugger automatically with the console.
|
---|
801 | * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
|
---|
802 | int mDbgAutoShow;
|
---|
803 | /** Whether to show the command line window when mDbgAutoShow is set. */
|
---|
804 | int mDbgAutoShowCommandLine;
|
---|
805 | /** Whether to show the statistics window when mDbgAutoShow is set. */
|
---|
806 | int mDbgAutoShowStatistics;
|
---|
807 | /** VBoxDbg module handle. */
|
---|
808 | RTLDRMOD mhVBoxDbg;
|
---|
809 |
|
---|
810 | /** Whether to start the VM in paused state or not. */
|
---|
811 | bool mStartPaused;
|
---|
812 | #endif
|
---|
813 |
|
---|
814 | #if defined (Q_WS_WIN32)
|
---|
815 | DWORD dwHTMLHelpCookie;
|
---|
816 | #endif
|
---|
817 |
|
---|
818 | QString mVerString;
|
---|
819 | QString mBrandingConfig;
|
---|
820 |
|
---|
821 | QList <QString> mFamilyIDs;
|
---|
822 | QList <QList <CGuestOSType> > mTypes;
|
---|
823 | QHash <QString, QPixmap *> mOsTypeIcons;
|
---|
824 |
|
---|
825 | QHash <ulong, QPixmap *> mVMStateIcons;
|
---|
826 | QHash <ulong, QColor *> mVMStateColors;
|
---|
827 |
|
---|
828 | QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
|
---|
829 |
|
---|
830 | QULongStringHash mMachineStates;
|
---|
831 | QULongStringHash mSessionStates;
|
---|
832 | QULongStringHash mDeviceTypes;
|
---|
833 |
|
---|
834 | QULongStringHash mStorageBuses;
|
---|
835 | QLongStringHash mStorageBusChannels;
|
---|
836 | QLongStringHash mStorageBusDevices;
|
---|
837 | QULongStringHash mSlotTemplates;
|
---|
838 |
|
---|
839 | QULongStringHash mDiskTypes;
|
---|
840 | QString mDiskTypes_Differencing;
|
---|
841 |
|
---|
842 | QULongStringHash mAuthTypes;
|
---|
843 | QULongStringHash mPortModeTypes;
|
---|
844 | QULongStringHash mUSBFilterActionTypes;
|
---|
845 | QULongStringHash mAudioDriverTypes;
|
---|
846 | QULongStringHash mAudioControllerTypes;
|
---|
847 | QULongStringHash mNetworkAdapterTypes;
|
---|
848 | QULongStringHash mNetworkAttachmentTypes;
|
---|
849 | QULongStringHash mNATProtocolTypes;
|
---|
850 | QULongStringHash mClipboardTypes;
|
---|
851 | QULongStringHash mStorageControllerTypes;
|
---|
852 | QULongStringHash mUSBDeviceStates;
|
---|
853 | QULongStringHash mChipsetTypes;
|
---|
854 |
|
---|
855 | QString mUserDefinedPortName;
|
---|
856 |
|
---|
857 | mutable QString m_strLastFolder;
|
---|
858 |
|
---|
859 | QPixmap mWarningIcon, mErrorIcon;
|
---|
860 |
|
---|
861 | QFileIconProvider m_globalIconProvider;
|
---|
862 |
|
---|
863 | friend VBoxGlobal &vboxGlobal();
|
---|
864 | };
|
---|
865 |
|
---|
866 | inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
|
---|
867 |
|
---|
868 | // Helper classes
|
---|
869 | ////////////////////////////////////////////////////////////////////////////////
|
---|
870 |
|
---|
871 | /**
|
---|
872 | * USB Popup Menu class.
|
---|
873 | * This class provides the list of USB devices attached to the host.
|
---|
874 | */
|
---|
875 | class VBoxUSBMenu : public QMenu
|
---|
876 | {
|
---|
877 | Q_OBJECT
|
---|
878 |
|
---|
879 | public:
|
---|
880 |
|
---|
881 | VBoxUSBMenu (QWidget *);
|
---|
882 |
|
---|
883 | const CUSBDevice& getUSB (QAction *aAction);
|
---|
884 |
|
---|
885 | void setConsole (const CConsole &);
|
---|
886 |
|
---|
887 | private slots:
|
---|
888 |
|
---|
889 | void processAboutToShow();
|
---|
890 |
|
---|
891 | private:
|
---|
892 | bool event(QEvent *aEvent);
|
---|
893 |
|
---|
894 | QMap <QAction *, CUSBDevice> mUSBDevicesMap;
|
---|
895 | CConsole mConsole;
|
---|
896 | };
|
---|
897 |
|
---|
898 | /**
|
---|
899 | * Enable/Disable Menu class.
|
---|
900 | * This class provides enable/disable menu items.
|
---|
901 | */
|
---|
902 | class VBoxSwitchMenu : public QMenu
|
---|
903 | {
|
---|
904 | Q_OBJECT
|
---|
905 |
|
---|
906 | public:
|
---|
907 |
|
---|
908 | VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
|
---|
909 |
|
---|
910 | void setToolTip (const QString &);
|
---|
911 |
|
---|
912 | private slots:
|
---|
913 |
|
---|
914 | void processAboutToShow();
|
---|
915 |
|
---|
916 | private:
|
---|
917 |
|
---|
918 | QAction *mAction;
|
---|
919 | bool mInverted;
|
---|
920 | };
|
---|
921 |
|
---|
922 | #endif /* __VBoxGlobal_h__ */
|
---|
923 |
|
---|