VirtualBox

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

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

Fe/Qt4: Own QProcess implementation to avoid Qt4 (4.3.x version) bug concerning QProcess blocks the GUI thread due to didn't get process-finished inner notification. This object will be used in Registration & New Version Notifier dialog.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.0 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
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 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 /* VirtualBox helpers */
511
512#if defined(Q_WS_X11) && !defined(VBOX_OSE)
513 bool showVirtualBoxLicense();
514#endif
515
516 void checkForAutoConvertedSettings();
517
518 CSession openSession (const QUuid &aId, bool aExisting = false);
519
520 /** Shortcut to openSession (aId, true). */
521 CSession openExistingSession (const QUuid &aId) { return openSession (aId, true); }
522
523 bool startMachine (const QUuid &id);
524
525 void startEnumeratingMedia();
526
527 /**
528 * Returns a list of all currently registered media. This list is used
529 * to globally track the accessiblity state of all media on a dedicated
530 * thread. This the list is initially empty (before the first enumeration
531 * process is started using #startEnumeratingMedia()).
532 */
533 const VBoxMediaList &currentMediaList() const { return media_list; }
534
535 /** Returns true if the media enumeration is in progress. */
536 bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
537
538 void addMedia (const VBoxMedia &);
539 void updateMedia (const VBoxMedia &);
540 void removeMedia (VBoxDefs::DiskType, const QUuid &);
541
542 bool findMedia (const CUnknown &, VBoxMedia &) const;
543
544 /* various helpers */
545
546 QString languageName() const;
547 QString languageCountry() const;
548 QString languageNameEnglish() const;
549 QString languageCountryEnglish() const;
550 QString languageTranslators() const;
551
552 void retranslateUi();
553
554 /** @internal made public for internal purposes */
555 void cleanup();
556
557 /* public static stuff */
558
559 static bool isDOSType (const QString &aOSTypeId);
560
561 static void adoptLabelPixmap (QLabel *);
562
563 static QString languageId();
564 static void loadLanguage (const QString &aLangId = QString::null);
565
566 static QIcon iconSet (const char *aNormal,
567 const char *aDisabled = NULL,
568 const char *aActive = NULL);
569 static QIcon iconSetEx (const char *aNormal, const char *aSmallNormal,
570 const char *aDisabled = NULL,
571 const char *aSmallDisabled = NULL,
572 const char *aActive = NULL,
573 const char *aSmallActive = NULL);
574
575 static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);
576
577 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
578
579 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
580 bool aCanResize = true);
581
582 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
583 bool aCanResize = true);
584
585 static QChar decimalSep();
586 static QString sizeRegexp();
587
588 static quint64 parseSize (const QString &);
589 static QString formatSize (quint64, int aMode = 0);
590
591 static QString highlight (const QString &aStr, bool aToolTip = false);
592
593 static QString systemLanguageId();
594
595 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
596 const QString &aCaption = QString::null,
597 bool aDirOnly = TRUE,
598 bool resolveSymlinks = TRUE);
599
600 static QString getOpenFileName (const QString &, const QString &, QWidget*,
601 const QString &, QString *defaultFilter = 0,
602 bool resolveSymLinks = true);
603
604 static QString getFirstExistingDir (const QString &);
605
606 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
607
608 static QString removeAccelMark (const QString &aText);
609
610 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
611 static QString extractKeyFromActionText (const QString &aText);
612
613 static QWidget *findWidget (QWidget *aParent, const char *aName,
614 const char *aClassName = NULL,
615 bool aRecursive = false);
616
617 /* Qt 4.2.0 support function */
618 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
619 {
620#if QT_VERSION < 0x040300
621 /* Deprecated since > 4.2 */
622 aLayout->setMargin (aMargin);
623#else
624 /* New since > 4.2 */
625 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
626#endif
627 }
628
629signals:
630
631 /**
632 * Emitted at the beginning of the enumeration process started
633 * by #startEnumeratingMedia().
634 */
635 void mediaEnumStarted();
636
637 /**
638 * Emitted when a new media item from the list has updated
639 * its accessibility state.
640 */
641 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
642
643 /**
644 * Emitted at the end of the enumeration process started
645 * by #startEnumeratingMedia(). The @a aList argument is passed for
646 * convenience, it is exactly the same as returned by #currentMediaList().
647 */
648 void mediaEnumFinished (const VBoxMediaList &aList);
649
650 /** Emitted when a new media is added using #addMedia(). */
651 void mediaAdded (const VBoxMedia &);
652
653 /** Emitted when the media is updated using #updateMedia(). */
654 void mediaUpdated (const VBoxMedia &);
655
656 /** Emitted when the media is removed using #removeMedia(). */
657 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
658
659 /* signals emitted when the VirtualBox callback is called by the server
660 * (not that currently these signals are emitted only when the application
661 * is the in the VM selector mode) */
662
663 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
664 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
665 void machineRegistered (const VBoxMachineRegisteredEvent &e);
666 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
667 void snapshotChanged (const VBoxSnapshotEvent &e);
668
669 void canShowRegDlg (bool aCanShow);
670 void canShowUpdDlg (bool aCanShow);
671
672public slots:
673
674 bool openURL (const QString &aURL);
675
676 void showRegistrationDialog (bool aForce = true);
677 void showUpdateDialog (bool aForce = true);
678
679protected:
680
681 bool event (QEvent *e);
682 bool eventFilter (QObject *, QEvent *);
683
684private:
685
686 VBoxGlobal();
687 ~VBoxGlobal();
688
689 void init();
690
691 bool mValid;
692
693 CVirtualBox mVBox;
694
695 VBoxGlobalSettings gset;
696
697 VBoxSelectorWnd *mSelectorWnd;
698 VBoxConsoleWnd *mConsoleWnd;
699 QWidget* mMainWindow;
700
701#ifdef VBOX_WITH_REGISTRATION
702 VBoxRegistrationDlg *mRegDlg;
703#endif
704 VBoxUpdateDlg *mUpdDlg;
705
706 QUuid vmUuid;
707
708 QThread *media_enum_thread;
709 VBoxMediaList media_list;
710
711 VBoxDefs::RenderMode vm_render_mode;
712 const char * vm_render_mode_str;
713
714#ifdef VBOX_WITH_DEBUGGER_GUI
715 bool dbg_enabled;
716 bool dbg_visible_at_startup;
717#endif
718
719#if defined (Q_WS_WIN32)
720 DWORD dwHTMLHelpCookie;
721#endif
722
723 CVirtualBoxCallback callback;
724
725 typedef QVector <QString> QStringVector;
726
727 QString verString;
728
729 QVector <CGuestOSType> vm_os_types;
730 QHash <QString, QPixmap *> vm_os_type_icons;
731 QVector <QColor *> vm_state_color;
732
733 QHash <long int, QPixmap *> mStateIcons;
734 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
735
736 QStringVector machineStates;
737 QStringVector sessionStates;
738 QStringVector deviceTypes;
739 QStringVector storageBuses;
740 QStringVector storageBusDevices;
741 QStringVector storageBusChannels;
742 QStringVector diskTypes;
743 QStringVector diskStorageTypes;
744 QStringVector vrdpAuthTypes;
745 QStringVector portModeTypes;
746 QStringVector usbFilterActionTypes;
747 QStringVector audioDriverTypes;
748 QStringVector audioControllerTypes;
749 QStringVector networkAdapterTypes;
750 QStringVector networkAttachmentTypes;
751 QStringVector clipboardTypes;
752 QStringVector ideControllerTypes;
753 QStringVector USBDeviceStates;
754
755 QString mUserDefinedPortName;
756
757 mutable bool detailReportTemplatesReady;
758
759 friend VBoxGlobal &vboxGlobal();
760 friend class VBoxCallback;
761};
762
763inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
764
765// Helper classes
766////////////////////////////////////////////////////////////////////////////////
767
768/**
769 * Generic asyncronous event.
770 *
771 * This abstract class is intended to provide a conveinent way to execute
772 * code on the main GUI thread asynchronously to the calling party. This is
773 * done by putting necessary actions to the #handle() function in a subclass
774 * and then posting an instance of the subclass using #post(). The instance
775 * must be allocated on the heap using the <tt>new</tt> operation and will be
776 * automatically deleted after processing. Note that if you don't call #post()
777 * on the created instance, you have to delete it yourself.
778 */
779class VBoxAsyncEvent : public QEvent
780{
781public:
782
783 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
784
785 /**
786 * Worker function. Gets executed on the GUI thread when the posted event
787 * is processed by the main event loop.
788 */
789 virtual void handle() = 0;
790
791 /**
792 * Posts this event to the main event loop.
793 * The caller loses ownership of this object after this method returns
794 * and must not delete the object.
795 */
796 void post()
797 {
798 QApplication::postEvent (&vboxGlobal(), this);
799 }
800};
801
802/**
803 * USB Popup Menu class.
804 * This class provides the list of USB devices attached to the host.
805 */
806class VBoxUSBMenu : public QMenu
807{
808 Q_OBJECT
809
810public:
811
812 VBoxUSBMenu (QWidget *);
813
814 const CUSBDevice& getUSB (QAction *aAction);
815
816 void setConsole (const CConsole &);
817
818private slots:
819
820 void processAboutToShow();
821
822private:
823 bool event(QEvent *aEvent);
824
825 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
826 CConsole mConsole;
827};
828
829/**
830 * Enable/Disable Menu class.
831 * This class provides enable/disable menu items.
832 */
833class VBoxSwitchMenu : public QMenu
834{
835 Q_OBJECT
836
837public:
838
839 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
840
841 void setToolTip (const QString &);
842
843private slots:
844
845 void processAboutToShow();
846
847private:
848
849 QAction *mAction;
850 bool mInverted;
851};
852
853#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