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