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