VirtualBox

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

Last change on this file since 12998 was 12891, checked in by vboxsync, 17 years ago

fixed OSE

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

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