VirtualBox

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

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

FE/Qt4: Added support for automatically generating the filedialog filters for
the supported hdd backends of vbox.

  • 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 static QList< QPair<QString, QString> > HDDBackends();
620
621 /* Qt 4.2.0 support function */
622 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
623 {
624#if QT_VERSION < 0x040300
625 /* Deprecated since > 4.2 */
626 aLayout->setMargin (aMargin);
627#else
628 /* New since > 4.2 */
629 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
630#endif
631 }
632
633signals:
634
635 /**
636 * Emitted at the beginning of the enumeration process started
637 * by #startEnumeratingMedia().
638 */
639 void mediaEnumStarted();
640
641 /**
642 * Emitted when a new media item from the list has updated
643 * its accessibility state.
644 */
645 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
646
647 /**
648 * Emitted at the end of the enumeration process started
649 * by #startEnumeratingMedia(). The @a aList argument is passed for
650 * convenience, it is exactly the same as returned by #currentMediaList().
651 */
652 void mediaEnumFinished (const VBoxMediaList &aList);
653
654 /** Emitted when a new media is added using #addMedia(). */
655 void mediaAdded (const VBoxMedia &);
656
657 /** Emitted when the media is updated using #updateMedia(). */
658 void mediaUpdated (const VBoxMedia &);
659
660 /** Emitted when the media is removed using #removeMedia(). */
661 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
662
663 /* signals emitted when the VirtualBox callback is called by the server
664 * (not that currently these signals are emitted only when the application
665 * is the in the VM selector mode) */
666
667 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
668 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
669 void machineRegistered (const VBoxMachineRegisteredEvent &e);
670 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
671 void snapshotChanged (const VBoxSnapshotEvent &e);
672
673 void canShowRegDlg (bool aCanShow);
674 void canShowUpdDlg (bool aCanShow);
675
676public slots:
677
678 bool openURL (const QString &aURL);
679
680 void showRegistrationDialog (bool aForce = true);
681 void showUpdateDialog (bool aForce = true);
682
683protected:
684
685 bool event (QEvent *e);
686 bool eventFilter (QObject *, QEvent *);
687
688private:
689
690 VBoxGlobal();
691 ~VBoxGlobal();
692
693 void init();
694
695 bool mValid;
696
697 CVirtualBox mVBox;
698
699 VBoxGlobalSettings gset;
700
701 VBoxSelectorWnd *mSelectorWnd;
702 VBoxConsoleWnd *mConsoleWnd;
703 QWidget* mMainWindow;
704
705#ifdef VBOX_WITH_REGISTRATION
706 VBoxRegistrationDlg *mRegDlg;
707#endif
708 VBoxUpdateDlg *mUpdDlg;
709
710 QUuid vmUuid;
711
712 QThread *media_enum_thread;
713 VBoxMediaList media_list;
714
715 VBoxDefs::RenderMode vm_render_mode;
716 const char * vm_render_mode_str;
717
718#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
719 bool dbg_enabled;
720 bool dbg_visible_at_startup;
721#endif
722
723#if defined (Q_WS_WIN32)
724 DWORD dwHTMLHelpCookie;
725#endif
726
727 CVirtualBoxCallback callback;
728
729 typedef QVector <QString> QStringVector;
730
731 QString verString;
732
733 QVector <CGuestOSType> vm_os_types;
734 QHash <QString, QPixmap *> vm_os_type_icons;
735 QVector <QColor *> vm_state_color;
736
737 QHash <long int, QPixmap *> mStateIcons;
738 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
739
740 QStringVector machineStates;
741 QStringVector sessionStates;
742 QStringVector deviceTypes;
743 QStringVector storageBuses;
744 QStringVector storageBusDevices;
745 QStringVector storageBusChannels;
746 QStringVector diskTypes;
747 QStringVector diskStorageTypes;
748 QStringVector vrdpAuthTypes;
749 QStringVector portModeTypes;
750 QStringVector usbFilterActionTypes;
751 QStringVector audioDriverTypes;
752 QStringVector audioControllerTypes;
753 QStringVector networkAdapterTypes;
754 QStringVector networkAttachmentTypes;
755 QStringVector clipboardTypes;
756 QStringVector ideControllerTypes;
757 QStringVector USBDeviceStates;
758
759 QString mUserDefinedPortName;
760
761 mutable bool detailReportTemplatesReady;
762
763 friend VBoxGlobal &vboxGlobal();
764 friend class VBoxCallback;
765};
766
767inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
768
769// Helper classes
770////////////////////////////////////////////////////////////////////////////////
771
772/**
773 * Generic asyncronous event.
774 *
775 * This abstract class is intended to provide a conveinent way to execute
776 * code on the main GUI thread asynchronously to the calling party. This is
777 * done by putting necessary actions to the #handle() function in a subclass
778 * and then posting an instance of the subclass using #post(). The instance
779 * must be allocated on the heap using the <tt>new</tt> operation and will be
780 * automatically deleted after processing. Note that if you don't call #post()
781 * on the created instance, you have to delete it yourself.
782 */
783class VBoxAsyncEvent : public QEvent
784{
785public:
786
787 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
788
789 /**
790 * Worker function. Gets executed on the GUI thread when the posted event
791 * is processed by the main event loop.
792 */
793 virtual void handle() = 0;
794
795 /**
796 * Posts this event to the main event loop.
797 * The caller loses ownership of this object after this method returns
798 * and must not delete the object.
799 */
800 void post()
801 {
802 QApplication::postEvent (&vboxGlobal(), this);
803 }
804};
805
806/**
807 * USB Popup Menu class.
808 * This class provides the list of USB devices attached to the host.
809 */
810class VBoxUSBMenu : public QMenu
811{
812 Q_OBJECT
813
814public:
815
816 VBoxUSBMenu (QWidget *);
817
818 const CUSBDevice& getUSB (QAction *aAction);
819
820 void setConsole (const CConsole &);
821
822private slots:
823
824 void processAboutToShow();
825
826private:
827 bool event(QEvent *aEvent);
828
829 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
830 CConsole mConsole;
831};
832
833/**
834 * Enable/Disable Menu class.
835 * This class provides enable/disable menu items.
836 */
837class VBoxSwitchMenu : public QMenu
838{
839 Q_OBJECT
840
841public:
842
843 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
844
845 void setToolTip (const QString &);
846
847private slots:
848
849 void processAboutToShow();
850
851private:
852
853 QAction *mAction;
854 bool mInverted;
855};
856
857#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