1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxGlobal class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef __VBoxGlobal_h__
|
---|
24 | #define __VBoxGlobal_h__
|
---|
25 |
|
---|
26 | #include "COMDefs.h"
|
---|
27 |
|
---|
28 | #include "VBoxGlobalSettings.h"
|
---|
29 |
|
---|
30 | /* Qt includes */
|
---|
31 | #include <QApplication>
|
---|
32 | #include <QLayout>
|
---|
33 | #include <QHash>
|
---|
34 | #include <QPixmap>
|
---|
35 | #include <QMenu>
|
---|
36 | #include <QStyle>
|
---|
37 | #include <QProcess>
|
---|
38 |
|
---|
39 | class QAction;
|
---|
40 | class QLabel;
|
---|
41 | class QToolButton;
|
---|
42 |
|
---|
43 | // Auxiliary types
|
---|
44 | ////////////////////////////////////////////////////////////////////////////////
|
---|
45 |
|
---|
46 | /** Simple media descriptor type. */
|
---|
47 | struct VBoxMedia
|
---|
48 | {
|
---|
49 | enum Status { Unknown, Ok, Error, Inaccessible };
|
---|
50 |
|
---|
51 | VBoxMedia() : type (VBoxDefs::InvalidType), status (Ok) {}
|
---|
52 |
|
---|
53 | VBoxMedia (const CUnknown &d, VBoxDefs::DiskType t, Status s)
|
---|
54 | : disk (d), type (t), status (s) {}
|
---|
55 |
|
---|
56 | CUnknown disk;
|
---|
57 | VBoxDefs::DiskType type;
|
---|
58 | Status status;
|
---|
59 | };
|
---|
60 |
|
---|
61 | typedef QList <VBoxMedia> VBoxMediaList;
|
---|
62 |
|
---|
63 | // VirtualBox callback events
|
---|
64 | ////////////////////////////////////////////////////////////////////////////////
|
---|
65 |
|
---|
66 | class VBoxMachineStateChangeEvent : public QEvent
|
---|
67 | {
|
---|
68 | public:
|
---|
69 | VBoxMachineStateChangeEvent (const QUuid &aId, KMachineState aState)
|
---|
70 | : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType)
|
---|
71 | , id (aId), state (aState)
|
---|
72 | {}
|
---|
73 |
|
---|
74 | const QUuid id;
|
---|
75 | const KMachineState state;
|
---|
76 | };
|
---|
77 |
|
---|
78 | class VBoxMachineDataChangeEvent : public QEvent
|
---|
79 | {
|
---|
80 | public:
|
---|
81 | VBoxMachineDataChangeEvent (const QUuid &aId)
|
---|
82 | : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType)
|
---|
83 | , id (aId)
|
---|
84 | {}
|
---|
85 |
|
---|
86 | const QUuid id;
|
---|
87 | };
|
---|
88 |
|
---|
89 | class VBoxMachineRegisteredEvent : public QEvent
|
---|
90 | {
|
---|
91 | public:
|
---|
92 | VBoxMachineRegisteredEvent (const QUuid &aId, bool aRegistered)
|
---|
93 | : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType)
|
---|
94 | , id (aId), registered (aRegistered)
|
---|
95 | {}
|
---|
96 |
|
---|
97 | const QUuid id;
|
---|
98 | const bool registered;
|
---|
99 | };
|
---|
100 |
|
---|
101 | class VBoxSessionStateChangeEvent : public QEvent
|
---|
102 | {
|
---|
103 | public:
|
---|
104 | VBoxSessionStateChangeEvent (const QUuid &aId, KSessionState aState)
|
---|
105 | : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType)
|
---|
106 | , id (aId), state (aState)
|
---|
107 | {}
|
---|
108 |
|
---|
109 | const QUuid id;
|
---|
110 | const KSessionState state;
|
---|
111 | };
|
---|
112 |
|
---|
113 | class VBoxSnapshotEvent : public QEvent
|
---|
114 | {
|
---|
115 | public:
|
---|
116 |
|
---|
117 | enum What { Taken, Discarded, Changed };
|
---|
118 |
|
---|
119 | VBoxSnapshotEvent (const QUuid &aMachineId, const QUuid &aSnapshotId,
|
---|
120 | What aWhat)
|
---|
121 | : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType)
|
---|
122 | , what (aWhat)
|
---|
123 | , machineId (aMachineId), snapshotId (aSnapshotId)
|
---|
124 | {}
|
---|
125 |
|
---|
126 | const What what;
|
---|
127 |
|
---|
128 | const QUuid machineId;
|
---|
129 | const QUuid snapshotId;
|
---|
130 | };
|
---|
131 |
|
---|
132 | class VBoxCanShowRegDlgEvent : public QEvent
|
---|
133 | {
|
---|
134 | public:
|
---|
135 | VBoxCanShowRegDlgEvent (bool aCanShow)
|
---|
136 | : QEvent ((QEvent::Type) VBoxDefs::CanShowRegDlgEventType)
|
---|
137 | , mCanShow (aCanShow)
|
---|
138 | {}
|
---|
139 |
|
---|
140 | const bool mCanShow;
|
---|
141 | };
|
---|
142 |
|
---|
143 | class VBoxCanShowUpdDlgEvent : public QEvent
|
---|
144 | {
|
---|
145 | public:
|
---|
146 | VBoxCanShowUpdDlgEvent (bool aCanShow)
|
---|
147 | : QEvent ((QEvent::Type) VBoxDefs::CanShowUpdDlgEventType)
|
---|
148 | , mCanShow (aCanShow)
|
---|
149 | {}
|
---|
150 |
|
---|
151 | const bool mCanShow;
|
---|
152 | };
|
---|
153 |
|
---|
154 | class VBoxChangeGUILanguageEvent : public QEvent
|
---|
155 | {
|
---|
156 | public:
|
---|
157 | VBoxChangeGUILanguageEvent (QString aLangId)
|
---|
158 | : QEvent ((QEvent::Type) VBoxDefs::ChangeGUILanguageEventType)
|
---|
159 | , mLangId (aLangId)
|
---|
160 | {}
|
---|
161 |
|
---|
162 | const QString mLangId;
|
---|
163 | };
|
---|
164 |
|
---|
165 | class Process : public QProcess
|
---|
166 | {
|
---|
167 | Q_OBJECT;
|
---|
168 |
|
---|
169 | public:
|
---|
170 |
|
---|
171 | static QByteArray singleShot (const QString &aProcessName,
|
---|
172 | int aTimeout = 5000
|
---|
173 | /* wait for data maximum 5 seconds */)
|
---|
174 | {
|
---|
175 | /* Why is it really needed is because of Qt4.3 bug with QProcess.
|
---|
176 | * This bug is about QProcess sometimes (~70%) do not receive
|
---|
177 | * notification about process was finished, so this makes
|
---|
178 | * 'bool QProcess::waitForFinished (int)' block the GUI thread and
|
---|
179 | * never dismissed with 'true' result even if process was really
|
---|
180 | * started&finished. So we just waiting for some information
|
---|
181 | * on process output and destroy the process with force. Due to
|
---|
182 | * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
|
---|
183 | * we have to change process state to QProcess::NotRunning. */
|
---|
184 |
|
---|
185 | QByteArray result;
|
---|
186 | Process process;
|
---|
187 | process.start (aProcessName);
|
---|
188 | bool firstShotReady = process.waitForReadyRead (aTimeout);
|
---|
189 | if (firstShotReady)
|
---|
190 | result = process.readAllStandardOutput();
|
---|
191 | process.setProcessState (QProcess::NotRunning);
|
---|
192 | return result;
|
---|
193 | }
|
---|
194 |
|
---|
195 | protected:
|
---|
196 |
|
---|
197 | Process (QWidget *aParent = 0) : QProcess (aParent) {}
|
---|
198 | };
|
---|
199 |
|
---|
200 | // VBoxGlobal class
|
---|
201 | ////////////////////////////////////////////////////////////////////////////////
|
---|
202 |
|
---|
203 | class VBoxSelectorWnd;
|
---|
204 | class VBoxConsoleWnd;
|
---|
205 | class VBoxRegistrationDlg;
|
---|
206 | class VBoxUpdateDlg;
|
---|
207 |
|
---|
208 | class VBoxGlobal : public QObject
|
---|
209 | {
|
---|
210 | Q_OBJECT
|
---|
211 |
|
---|
212 | public:
|
---|
213 |
|
---|
214 | static VBoxGlobal &instance();
|
---|
215 |
|
---|
216 | bool isValid() { return mValid; }
|
---|
217 |
|
---|
218 | QString versionString() { return verString; }
|
---|
219 |
|
---|
220 | CVirtualBox virtualBox() const { return mVBox; }
|
---|
221 |
|
---|
222 | const VBoxGlobalSettings &settings() const { return gset; }
|
---|
223 | bool setSettings (const VBoxGlobalSettings &gs);
|
---|
224 |
|
---|
225 | VBoxSelectorWnd &selectorWnd();
|
---|
226 | VBoxConsoleWnd &consoleWnd();
|
---|
227 |
|
---|
228 | /* main window handle storage */
|
---|
229 | void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
|
---|
230 | QWidget *mainWindow() const { return mMainWindow; }
|
---|
231 |
|
---|
232 |
|
---|
233 | bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
|
---|
234 | QUuid managedVMUuid() const { return vmUuid; }
|
---|
235 |
|
---|
236 | VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
|
---|
237 | const char *vmRenderModeStr() const { return vm_render_mode_str; }
|
---|
238 |
|
---|
239 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
240 | bool isDebuggerEnabled() const { return mDbgEnabled; }
|
---|
241 | bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
|
---|
242 | RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
|
---|
243 | #endif
|
---|
244 |
|
---|
245 | /* VBox enum to/from string/icon/color convertors */
|
---|
246 |
|
---|
247 | QStringList vmGuestOSTypeDescriptions() const;
|
---|
248 | QList<QPixmap> vmGuestOSTypeIcons (int aHorizonalMargin, int aVerticalMargin) const;
|
---|
249 | CGuestOSType vmGuestOSType (int aIndex) const;
|
---|
250 | int vmGuestOSTypeIndex (const QString &aId) const;
|
---|
251 | QPixmap vmGuestOSTypeIcon (const QString &aId) const;
|
---|
252 | QString vmGuestOSTypeDescription (const QString &aId) const;
|
---|
253 |
|
---|
254 | QPixmap toIcon (KMachineState s) const
|
---|
255 | {
|
---|
256 | QPixmap *pm = mStateIcons.value (s);
|
---|
257 | AssertMsg (pm, ("Icon for VM state %d must be defined", s));
|
---|
258 | return pm ? *pm : QPixmap();
|
---|
259 | }
|
---|
260 |
|
---|
261 | const QColor &toColor (KMachineState s) const
|
---|
262 | {
|
---|
263 | static const QColor none;
|
---|
264 | AssertMsg (vm_state_color.value (s), ("No color for %d", s));
|
---|
265 | return vm_state_color.value (s) ? *vm_state_color.value(s) : none;
|
---|
266 | }
|
---|
267 |
|
---|
268 | QString toString (KMachineState s) const
|
---|
269 | {
|
---|
270 | AssertMsg (!machineStates.value (s).isNull(), ("No text for %d", s));
|
---|
271 | return machineStates.value (s);
|
---|
272 | }
|
---|
273 |
|
---|
274 | QString toString (KSessionState s) const
|
---|
275 | {
|
---|
276 | AssertMsg (!sessionStates.value (s).isNull(), ("No text for %d", s));
|
---|
277 | return sessionStates.value (s);
|
---|
278 | }
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Returns a string representation of the given KStorageBus enum value.
|
---|
282 | * Complementary to #toStorageBusType (const QString &) const.
|
---|
283 | */
|
---|
284 | QString toString (KStorageBus aBus) const
|
---|
285 | {
|
---|
286 | AssertMsg (!storageBuses.value (aBus).isNull(), ("No text for %d", aBus));
|
---|
287 | return storageBuses [aBus];
|
---|
288 | }
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Returns a KStorageBus enum value corresponding to the given string
|
---|
292 | * representation. Complementary to #toString (KStorageBus) const.
|
---|
293 | */
|
---|
294 | KStorageBus toStorageBusType (const QString &aBus) const
|
---|
295 | {
|
---|
296 | QStringVector::const_iterator it =
|
---|
297 | qFind (storageBuses.begin(), storageBuses.end(), aBus);
|
---|
298 | AssertMsg (it != storageBuses.end(), ("No value for {%s}", aBus.toLatin1().constData()));
|
---|
299 | return KStorageBus (it - storageBuses.begin());
|
---|
300 | }
|
---|
301 |
|
---|
302 | QString toString (KStorageBus aBus, LONG aChannel) const;
|
---|
303 | LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
|
---|
304 |
|
---|
305 | QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
|
---|
306 | LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
|
---|
307 |
|
---|
308 | QString toFullString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
|
---|
309 |
|
---|
310 | QString toString (KHardDiskType t) const
|
---|
311 | {
|
---|
312 | AssertMsg (!diskTypes.value (t).isNull(), ("No text for %d", t));
|
---|
313 | return diskTypes.value (t);
|
---|
314 | }
|
---|
315 |
|
---|
316 | QString toString (KHardDiskStorageType t) const
|
---|
317 | {
|
---|
318 | AssertMsg (!diskStorageTypes.value (t).isNull(), ("No text for %d", t));
|
---|
319 | return diskStorageTypes.value (t);
|
---|
320 | }
|
---|
321 |
|
---|
322 | QString toString (KVRDPAuthType t) const
|
---|
323 | {
|
---|
324 | AssertMsg (!vrdpAuthTypes.value (t).isNull(), ("No text for %d", t));
|
---|
325 | return vrdpAuthTypes.value (t);
|
---|
326 | }
|
---|
327 |
|
---|
328 | QString toString (KPortMode t) const
|
---|
329 | {
|
---|
330 | AssertMsg (!portModeTypes.value (t).isNull(), ("No text for %d", t));
|
---|
331 | return portModeTypes.value (t);
|
---|
332 | }
|
---|
333 |
|
---|
334 | QString toString (KUSBDeviceFilterAction t) const
|
---|
335 | {
|
---|
336 | AssertMsg (!usbFilterActionTypes.value (t).isNull(), ("No text for %d", t));
|
---|
337 | return usbFilterActionTypes.value (t);
|
---|
338 | }
|
---|
339 |
|
---|
340 | QString toString (KClipboardMode t) const
|
---|
341 | {
|
---|
342 | AssertMsg (!clipboardTypes.value (t).isNull(), ("No text for %d", t));
|
---|
343 | return clipboardTypes.value (t);
|
---|
344 | }
|
---|
345 |
|
---|
346 | KClipboardMode toClipboardModeType (const QString &s) const
|
---|
347 | {
|
---|
348 | QStringVector::const_iterator it =
|
---|
349 | qFind (clipboardTypes.begin(), clipboardTypes.end(), s);
|
---|
350 | AssertMsg (it != clipboardTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
351 | return KClipboardMode (it - clipboardTypes.begin());
|
---|
352 | }
|
---|
353 |
|
---|
354 | QString toString (KIDEControllerType t) const
|
---|
355 | {
|
---|
356 | AssertMsg (!ideControllerTypes.value (t).isNull(), ("No text for %d", t));
|
---|
357 | return ideControllerTypes.value (t);
|
---|
358 | }
|
---|
359 |
|
---|
360 | KIDEControllerType toIDEControllerType (const QString &s) const
|
---|
361 | {
|
---|
362 | QStringVector::const_iterator it =
|
---|
363 | qFind (ideControllerTypes.begin(), ideControllerTypes.end(), s);
|
---|
364 | AssertMsg (it != ideControllerTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
365 | return KIDEControllerType (it - ideControllerTypes.begin());
|
---|
366 | }
|
---|
367 |
|
---|
368 | KVRDPAuthType toVRDPAuthType (const QString &s) const
|
---|
369 | {
|
---|
370 | QStringVector::const_iterator it =
|
---|
371 | qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
|
---|
372 | AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
373 | return KVRDPAuthType (it - vrdpAuthTypes.begin());
|
---|
374 | }
|
---|
375 |
|
---|
376 | KPortMode toPortMode (const QString &s) const
|
---|
377 | {
|
---|
378 | QStringVector::const_iterator it =
|
---|
379 | qFind (portModeTypes.begin(), portModeTypes.end(), s);
|
---|
380 | AssertMsg (it != portModeTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
381 | return KPortMode (it - portModeTypes.begin());
|
---|
382 | }
|
---|
383 |
|
---|
384 | KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
|
---|
385 | {
|
---|
386 | QStringVector::const_iterator it =
|
---|
387 | qFind (usbFilterActionTypes.begin(), usbFilterActionTypes.end(), s);
|
---|
388 | AssertMsg (it != usbFilterActionTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
389 | return KUSBDeviceFilterAction (it - usbFilterActionTypes.begin());
|
---|
390 | }
|
---|
391 |
|
---|
392 | /**
|
---|
393 | * Similar to toString (KHardDiskType), but returns 'Differencing'
|
---|
394 | * for normal hard disks that have a parent hard disk.
|
---|
395 | */
|
---|
396 | QString hardDiskTypeString (const CHardDisk &aHD) const
|
---|
397 | {
|
---|
398 | if (!aHD.GetParent().isNull())
|
---|
399 | {
|
---|
400 | Assert (aHD.GetType() == KHardDiskType_Normal);
|
---|
401 | return tr ("Differencing", "hard disk");
|
---|
402 | }
|
---|
403 | return toString (aHD.GetType());
|
---|
404 | }
|
---|
405 |
|
---|
406 | QString toString (KDeviceType t) const
|
---|
407 | {
|
---|
408 | AssertMsg (!deviceTypes.value (t).isNull(), ("No text for %d", t));
|
---|
409 | return deviceTypes.value (t);
|
---|
410 | }
|
---|
411 |
|
---|
412 | KDeviceType toDeviceType (const QString &s) const
|
---|
413 | {
|
---|
414 | QStringVector::const_iterator it =
|
---|
415 | qFind (deviceTypes.begin(), deviceTypes.end(), s);
|
---|
416 | AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
417 | return KDeviceType (it - deviceTypes.begin());
|
---|
418 | }
|
---|
419 |
|
---|
420 | QStringList deviceTypeStrings() const;
|
---|
421 |
|
---|
422 | QString toString (KAudioDriverType t) const
|
---|
423 | {
|
---|
424 | AssertMsg (!audioDriverTypes.value (t).isNull(), ("No text for %d", t));
|
---|
425 | return audioDriverTypes.value (t);
|
---|
426 | }
|
---|
427 |
|
---|
428 | KAudioDriverType toAudioDriverType (const QString &s) const
|
---|
429 | {
|
---|
430 | QStringVector::const_iterator it =
|
---|
431 | qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
|
---|
432 | AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
433 | return KAudioDriverType (it - audioDriverTypes.begin());
|
---|
434 | }
|
---|
435 |
|
---|
436 | QString toString (KAudioControllerType t) const
|
---|
437 | {
|
---|
438 | AssertMsg (!audioControllerTypes.value (t).isNull(), ("No text for %d", t));
|
---|
439 | return audioControllerTypes.value (t);
|
---|
440 | }
|
---|
441 |
|
---|
442 | KAudioControllerType toAudioControllerType (const QString &s) const
|
---|
443 | {
|
---|
444 | QStringVector::const_iterator it =
|
---|
445 | qFind (audioControllerTypes.begin(), audioControllerTypes.end(), s);
|
---|
446 | AssertMsg (it != audioControllerTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
447 | return KAudioControllerType (it - audioControllerTypes.begin());
|
---|
448 | }
|
---|
449 |
|
---|
450 | QString toString (KNetworkAdapterType t) const
|
---|
451 | {
|
---|
452 | AssertMsg (!networkAdapterTypes.value (t).isNull(), ("No text for %d", t));
|
---|
453 | return networkAdapterTypes.value (t);
|
---|
454 | }
|
---|
455 |
|
---|
456 | KNetworkAdapterType toNetworkAdapterType (const QString &s) const
|
---|
457 | {
|
---|
458 | QStringVector::const_iterator it =
|
---|
459 | qFind (networkAdapterTypes.begin(), networkAdapterTypes.end(), s);
|
---|
460 | AssertMsg (it != networkAdapterTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
461 | return KNetworkAdapterType (it - networkAdapterTypes.begin());
|
---|
462 | }
|
---|
463 |
|
---|
464 | QString toString (KNetworkAttachmentType t) const
|
---|
465 | {
|
---|
466 | AssertMsg (!networkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
|
---|
467 | return networkAttachmentTypes.value (t);
|
---|
468 | }
|
---|
469 |
|
---|
470 | KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
|
---|
471 | {
|
---|
472 | QStringVector::const_iterator it =
|
---|
473 | qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
|
---|
474 | AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
475 | return KNetworkAttachmentType (it - networkAttachmentTypes.begin());
|
---|
476 | }
|
---|
477 |
|
---|
478 | QString toString (KUSBDeviceState aState) const
|
---|
479 | {
|
---|
480 | AssertMsg (!USBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
|
---|
481 | return USBDeviceStates.value (aState);
|
---|
482 | }
|
---|
483 |
|
---|
484 | QStringList COMPortNames() const;
|
---|
485 | QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
|
---|
486 | bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
|
---|
487 |
|
---|
488 | QStringList LPTPortNames() const;
|
---|
489 | QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
|
---|
490 | bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
|
---|
491 |
|
---|
492 | QPixmap snapshotIcon (bool online) const
|
---|
493 | {
|
---|
494 | return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
|
---|
495 | }
|
---|
496 |
|
---|
497 | /* details generators */
|
---|
498 |
|
---|
499 | QString details (const CHardDisk &aHD, bool aPredict = false,
|
---|
500 | bool aDoRefresh = true);
|
---|
501 |
|
---|
502 | QString details (const CUSBDevice &aDevice) const;
|
---|
503 | QString toolTip (const CUSBDevice &aDevice) const;
|
---|
504 | QString toolTip (const CUSBDeviceFilter &aFilter) const;
|
---|
505 |
|
---|
506 | QString prepareFileNameForHTML (const QString &fn) const;
|
---|
507 |
|
---|
508 | QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks,
|
---|
509 | bool aDoRefresh = true);
|
---|
510 |
|
---|
511 | QString platformInfo();
|
---|
512 |
|
---|
513 | /* VirtualBox helpers */
|
---|
514 |
|
---|
515 | #if defined(Q_WS_X11) && !defined(VBOX_OSE)
|
---|
516 | bool showVirtualBoxLicense();
|
---|
517 | #endif
|
---|
518 |
|
---|
519 | void checkForAutoConvertedSettings();
|
---|
520 |
|
---|
521 | CSession openSession (const QUuid &aId, bool aExisting = false);
|
---|
522 |
|
---|
523 | /** Shortcut to openSession (aId, true). */
|
---|
524 | CSession openExistingSession (const QUuid &aId) { return openSession (aId, true); }
|
---|
525 |
|
---|
526 | bool startMachine (const QUuid &id);
|
---|
527 |
|
---|
528 | void startEnumeratingMedia();
|
---|
529 |
|
---|
530 | /**
|
---|
531 | * Returns a list of all currently registered media. This list is used
|
---|
532 | * to globally track the accessiblity state of all media on a dedicated
|
---|
533 | * thread. This the list is initially empty (before the first enumeration
|
---|
534 | * process is started using #startEnumeratingMedia()).
|
---|
535 | */
|
---|
536 | const VBoxMediaList ¤tMediaList() const { return media_list; }
|
---|
537 |
|
---|
538 | /** Returns true if the media enumeration is in progress. */
|
---|
539 | bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
|
---|
540 |
|
---|
541 | void addMedia (const VBoxMedia &);
|
---|
542 | void updateMedia (const VBoxMedia &);
|
---|
543 | void removeMedia (VBoxDefs::DiskType, const QUuid &);
|
---|
544 |
|
---|
545 | bool findMedia (const CUnknown &, VBoxMedia &) const;
|
---|
546 |
|
---|
547 | /* various helpers */
|
---|
548 |
|
---|
549 | QString languageName() const;
|
---|
550 | QString languageCountry() const;
|
---|
551 | QString languageNameEnglish() const;
|
---|
552 | QString languageCountryEnglish() const;
|
---|
553 | QString languageTranslators() const;
|
---|
554 |
|
---|
555 | void retranslateUi();
|
---|
556 |
|
---|
557 | /** @internal made public for internal purposes */
|
---|
558 | void cleanup();
|
---|
559 |
|
---|
560 | /* public static stuff */
|
---|
561 |
|
---|
562 | static bool isDOSType (const QString &aOSTypeId);
|
---|
563 |
|
---|
564 | static void adoptLabelPixmap (QLabel *);
|
---|
565 |
|
---|
566 | static QString languageId();
|
---|
567 | static void loadLanguage (const QString &aLangId = QString::null);
|
---|
568 |
|
---|
569 | static QIcon iconSet (const char *aNormal,
|
---|
570 | const char *aDisabled = NULL,
|
---|
571 | const char *aActive = NULL);
|
---|
572 | static QIcon iconSetEx (const char *aNormal, const char *aSmallNormal,
|
---|
573 | const char *aDisabled = NULL,
|
---|
574 | const char *aSmallDisabled = NULL,
|
---|
575 | const char *aActive = NULL,
|
---|
576 | const char *aSmallActive = NULL);
|
---|
577 |
|
---|
578 | static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);
|
---|
579 |
|
---|
580 | static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
|
---|
581 |
|
---|
582 | static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
|
---|
583 | bool aCanResize = true);
|
---|
584 |
|
---|
585 | static void centerWidget (QWidget *aWidget, QWidget *aRelative,
|
---|
586 | bool aCanResize = true);
|
---|
587 |
|
---|
588 | static QChar decimalSep();
|
---|
589 | static QString sizeRegexp();
|
---|
590 |
|
---|
591 | static quint64 parseSize (const QString &);
|
---|
592 | static QString formatSize (quint64, int aMode = 0);
|
---|
593 |
|
---|
594 | static QString highlight (const QString &aStr, bool aToolTip = false);
|
---|
595 |
|
---|
596 | static QString systemLanguageId();
|
---|
597 |
|
---|
598 | static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
|
---|
599 | const QString &aCaption = QString::null,
|
---|
600 | bool aDirOnly = TRUE,
|
---|
601 | bool resolveSymlinks = TRUE);
|
---|
602 |
|
---|
603 | static QString getOpenFileName (const QString &, const QString &, QWidget*,
|
---|
604 | const QString &, QString *defaultFilter = 0,
|
---|
605 | bool resolveSymLinks = true);
|
---|
606 |
|
---|
607 | static QString getFirstExistingDir (const QString &);
|
---|
608 |
|
---|
609 | static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
|
---|
610 |
|
---|
611 | static QString removeAccelMark (const QString &aText);
|
---|
612 |
|
---|
613 | static QString insertKeyToActionText (const QString &aText, const QString &aKey);
|
---|
614 | static QString extractKeyFromActionText (const QString &aText);
|
---|
615 |
|
---|
616 | static QWidget *findWidget (QWidget *aParent, const char *aName,
|
---|
617 | const char *aClassName = NULL,
|
---|
618 | bool aRecursive = false);
|
---|
619 |
|
---|
620 | static QList< QPair<QString, QString> > HDDBackends();
|
---|
621 |
|
---|
622 | /* Qt 4.2.0 support function */
|
---|
623 | static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
|
---|
624 | {
|
---|
625 | #if QT_VERSION < 0x040300
|
---|
626 | /* Deprecated since > 4.2 */
|
---|
627 | aLayout->setMargin (aMargin);
|
---|
628 | #else
|
---|
629 | /* New since > 4.2 */
|
---|
630 | aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
|
---|
631 | #endif
|
---|
632 | }
|
---|
633 |
|
---|
634 | signals:
|
---|
635 |
|
---|
636 | /**
|
---|
637 | * Emitted at the beginning of the enumeration process started
|
---|
638 | * by #startEnumeratingMedia().
|
---|
639 | */
|
---|
640 | void mediaEnumStarted();
|
---|
641 |
|
---|
642 | /**
|
---|
643 | * Emitted when a new media item from the list has updated
|
---|
644 | * its accessibility state.
|
---|
645 | */
|
---|
646 | void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
|
---|
647 |
|
---|
648 | /**
|
---|
649 | * Emitted at the end of the enumeration process started
|
---|
650 | * by #startEnumeratingMedia(). The @a aList argument is passed for
|
---|
651 | * convenience, it is exactly the same as returned by #currentMediaList().
|
---|
652 | */
|
---|
653 | void mediaEnumFinished (const VBoxMediaList &aList);
|
---|
654 |
|
---|
655 | /** Emitted when a new media is added using #addMedia(). */
|
---|
656 | void mediaAdded (const VBoxMedia &);
|
---|
657 |
|
---|
658 | /** Emitted when the media is updated using #updateMedia(). */
|
---|
659 | void mediaUpdated (const VBoxMedia &);
|
---|
660 |
|
---|
661 | /** Emitted when the media is removed using #removeMedia(). */
|
---|
662 | void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
|
---|
663 |
|
---|
664 | /* signals emitted when the VirtualBox callback is called by the server
|
---|
665 | * (not that currently these signals are emitted only when the application
|
---|
666 | * is the in the VM selector mode) */
|
---|
667 |
|
---|
668 | void machineStateChanged (const VBoxMachineStateChangeEvent &e);
|
---|
669 | void machineDataChanged (const VBoxMachineDataChangeEvent &e);
|
---|
670 | void machineRegistered (const VBoxMachineRegisteredEvent &e);
|
---|
671 | void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
|
---|
672 | void snapshotChanged (const VBoxSnapshotEvent &e);
|
---|
673 |
|
---|
674 | void canShowRegDlg (bool aCanShow);
|
---|
675 | void canShowUpdDlg (bool aCanShow);
|
---|
676 |
|
---|
677 | public slots:
|
---|
678 |
|
---|
679 | bool openURL (const QString &aURL);
|
---|
680 |
|
---|
681 | void showRegistrationDialog (bool aForce = true);
|
---|
682 | void showUpdateDialog (bool aForce = true);
|
---|
683 |
|
---|
684 | protected:
|
---|
685 |
|
---|
686 | bool event (QEvent *e);
|
---|
687 | bool eventFilter (QObject *, QEvent *);
|
---|
688 |
|
---|
689 | private:
|
---|
690 |
|
---|
691 | VBoxGlobal();
|
---|
692 | ~VBoxGlobal();
|
---|
693 |
|
---|
694 | void init();
|
---|
695 |
|
---|
696 | bool mValid;
|
---|
697 |
|
---|
698 | CVirtualBox mVBox;
|
---|
699 |
|
---|
700 | VBoxGlobalSettings gset;
|
---|
701 |
|
---|
702 | VBoxSelectorWnd *mSelectorWnd;
|
---|
703 | VBoxConsoleWnd *mConsoleWnd;
|
---|
704 | QWidget* mMainWindow;
|
---|
705 |
|
---|
706 | #ifdef VBOX_WITH_REGISTRATION
|
---|
707 | VBoxRegistrationDlg *mRegDlg;
|
---|
708 | #endif
|
---|
709 | VBoxUpdateDlg *mUpdDlg;
|
---|
710 |
|
---|
711 | QUuid vmUuid;
|
---|
712 |
|
---|
713 | QThread *media_enum_thread;
|
---|
714 | VBoxMediaList media_list;
|
---|
715 |
|
---|
716 | VBoxDefs::RenderMode vm_render_mode;
|
---|
717 | const char * vm_render_mode_str;
|
---|
718 |
|
---|
719 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
720 | /** Whether the debugger should be accessible or not.
|
---|
721 | * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
|
---|
722 | * VBOX_GUI_DBG_AUTO_SHOW to enable. */
|
---|
723 | bool mDbgEnabled;
|
---|
724 | /** Whether to show the debugger automatically with the console.
|
---|
725 | * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
|
---|
726 | bool mDbgAutoShow;
|
---|
727 | /** VBoxDbg module handle. */
|
---|
728 | RTLDRMOD mhVBoxDbg;
|
---|
729 | #endif
|
---|
730 |
|
---|
731 | #if defined (Q_WS_WIN32)
|
---|
732 | DWORD dwHTMLHelpCookie;
|
---|
733 | #endif
|
---|
734 |
|
---|
735 | CVirtualBoxCallback callback;
|
---|
736 |
|
---|
737 | typedef QVector <QString> QStringVector;
|
---|
738 |
|
---|
739 | QString verString;
|
---|
740 |
|
---|
741 | QVector <CGuestOSType> vm_os_types;
|
---|
742 | QHash <QString, QPixmap *> vm_os_type_icons;
|
---|
743 | QVector <QColor *> vm_state_color;
|
---|
744 |
|
---|
745 | QHash <long int, QPixmap *> mStateIcons;
|
---|
746 | QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
|
---|
747 |
|
---|
748 | QStringVector machineStates;
|
---|
749 | QStringVector sessionStates;
|
---|
750 | QStringVector deviceTypes;
|
---|
751 | QStringVector storageBuses;
|
---|
752 | QStringVector storageBusDevices;
|
---|
753 | QStringVector storageBusChannels;
|
---|
754 | QStringVector diskTypes;
|
---|
755 | QStringVector diskStorageTypes;
|
---|
756 | QStringVector vrdpAuthTypes;
|
---|
757 | QStringVector portModeTypes;
|
---|
758 | QStringVector usbFilterActionTypes;
|
---|
759 | QStringVector audioDriverTypes;
|
---|
760 | QStringVector audioControllerTypes;
|
---|
761 | QStringVector networkAdapterTypes;
|
---|
762 | QStringVector networkAttachmentTypes;
|
---|
763 | QStringVector clipboardTypes;
|
---|
764 | QStringVector ideControllerTypes;
|
---|
765 | QStringVector USBDeviceStates;
|
---|
766 |
|
---|
767 | QString mUserDefinedPortName;
|
---|
768 |
|
---|
769 | mutable bool detailReportTemplatesReady;
|
---|
770 |
|
---|
771 | friend VBoxGlobal &vboxGlobal();
|
---|
772 | friend class VBoxCallback;
|
---|
773 | };
|
---|
774 |
|
---|
775 | inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
|
---|
776 |
|
---|
777 | // Helper classes
|
---|
778 | ////////////////////////////////////////////////////////////////////////////////
|
---|
779 |
|
---|
780 | /**
|
---|
781 | * Generic asyncronous event.
|
---|
782 | *
|
---|
783 | * This abstract class is intended to provide a conveinent way to execute
|
---|
784 | * code on the main GUI thread asynchronously to the calling party. This is
|
---|
785 | * done by putting necessary actions to the #handle() function in a subclass
|
---|
786 | * and then posting an instance of the subclass using #post(). The instance
|
---|
787 | * must be allocated on the heap using the <tt>new</tt> operation and will be
|
---|
788 | * automatically deleted after processing. Note that if you don't call #post()
|
---|
789 | * on the created instance, you have to delete it yourself.
|
---|
790 | */
|
---|
791 | class VBoxAsyncEvent : public QEvent
|
---|
792 | {
|
---|
793 | public:
|
---|
794 |
|
---|
795 | VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
|
---|
796 |
|
---|
797 | /**
|
---|
798 | * Worker function. Gets executed on the GUI thread when the posted event
|
---|
799 | * is processed by the main event loop.
|
---|
800 | */
|
---|
801 | virtual void handle() = 0;
|
---|
802 |
|
---|
803 | /**
|
---|
804 | * Posts this event to the main event loop.
|
---|
805 | * The caller loses ownership of this object after this method returns
|
---|
806 | * and must not delete the object.
|
---|
807 | */
|
---|
808 | void post()
|
---|
809 | {
|
---|
810 | QApplication::postEvent (&vboxGlobal(), this);
|
---|
811 | }
|
---|
812 | };
|
---|
813 |
|
---|
814 | /**
|
---|
815 | * USB Popup Menu class.
|
---|
816 | * This class provides the list of USB devices attached to the host.
|
---|
817 | */
|
---|
818 | class VBoxUSBMenu : public QMenu
|
---|
819 | {
|
---|
820 | Q_OBJECT
|
---|
821 |
|
---|
822 | public:
|
---|
823 |
|
---|
824 | VBoxUSBMenu (QWidget *);
|
---|
825 |
|
---|
826 | const CUSBDevice& getUSB (QAction *aAction);
|
---|
827 |
|
---|
828 | void setConsole (const CConsole &);
|
---|
829 |
|
---|
830 | private slots:
|
---|
831 |
|
---|
832 | void processAboutToShow();
|
---|
833 |
|
---|
834 | private:
|
---|
835 | bool event(QEvent *aEvent);
|
---|
836 |
|
---|
837 | QMap <QAction *, CUSBDevice> mUSBDevicesMap;
|
---|
838 | CConsole mConsole;
|
---|
839 | };
|
---|
840 |
|
---|
841 | /**
|
---|
842 | * Enable/Disable Menu class.
|
---|
843 | * This class provides enable/disable menu items.
|
---|
844 | */
|
---|
845 | class VBoxSwitchMenu : public QMenu
|
---|
846 | {
|
---|
847 | Q_OBJECT
|
---|
848 |
|
---|
849 | public:
|
---|
850 |
|
---|
851 | VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
|
---|
852 |
|
---|
853 | void setToolTip (const QString &);
|
---|
854 |
|
---|
855 | private slots:
|
---|
856 |
|
---|
857 | void processAboutToShow();
|
---|
858 |
|
---|
859 | private:
|
---|
860 |
|
---|
861 | QAction *mAction;
|
---|
862 | bool mInverted;
|
---|
863 | };
|
---|
864 |
|
---|
865 | #endif /* __VBoxGlobal_h__ */
|
---|