VirtualBox

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

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

FE/Qt4: Replaced languageChange by the appropriate QEvent & retranslateUi.

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