VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h@ 12171

Last change on this file since 12171 was 12171, checked in by vboxsync, 16 years ago

VirtualBox4: Disable VBOX_WITH_DEBUGGER_GUI in the source, avoid messing with makefile globals like DEFS.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette