VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h@ 18553

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

FE/Qt4: don't leave zombies after starting a process with Process::singleShot()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.7 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2009 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#include "VBoxMedium.h"
30
31/* Qt includes */
32#include <QApplication>
33#include <QLayout>
34#include <QMenu>
35#include <QStyle>
36#include <QProcess>
37#include <QHash>
38
39#ifdef Q_WS_X11
40# include <sys/wait.h>
41#endif
42
43class QAction;
44class QLabel;
45class QToolButton;
46
47// VirtualBox callback events
48////////////////////////////////////////////////////////////////////////////////
49
50class VBoxMachineStateChangeEvent : public QEvent
51{
52public:
53 VBoxMachineStateChangeEvent (const QUuid &aId, KMachineState aState)
54 : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType)
55 , id (aId), state (aState)
56 {}
57
58 const QUuid id;
59 const KMachineState state;
60};
61
62class VBoxMachineDataChangeEvent : public QEvent
63{
64public:
65 VBoxMachineDataChangeEvent (const QUuid &aId)
66 : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType)
67 , id (aId)
68 {}
69
70 const QUuid id;
71};
72
73class VBoxMachineRegisteredEvent : public QEvent
74{
75public:
76 VBoxMachineRegisteredEvent (const QUuid &aId, bool aRegistered)
77 : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType)
78 , id (aId), registered (aRegistered)
79 {}
80
81 const QUuid id;
82 const bool registered;
83};
84
85class VBoxSessionStateChangeEvent : public QEvent
86{
87public:
88 VBoxSessionStateChangeEvent (const QUuid &aId, KSessionState aState)
89 : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType)
90 , id (aId), state (aState)
91 {}
92
93 const QUuid id;
94 const KSessionState state;
95};
96
97class VBoxSnapshotEvent : public QEvent
98{
99public:
100
101 enum What { Taken, Discarded, Changed };
102
103 VBoxSnapshotEvent (const QUuid &aMachineId, const QUuid &aSnapshotId,
104 What aWhat)
105 : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType)
106 , what (aWhat)
107 , machineId (aMachineId), snapshotId (aSnapshotId)
108 {}
109
110 const What what;
111
112 const QUuid machineId;
113 const QUuid snapshotId;
114};
115
116class VBoxCanShowRegDlgEvent : public QEvent
117{
118public:
119 VBoxCanShowRegDlgEvent (bool aCanShow)
120 : QEvent ((QEvent::Type) VBoxDefs::CanShowRegDlgEventType)
121 , mCanShow (aCanShow)
122 {}
123
124 const bool mCanShow;
125};
126
127class VBoxCanShowUpdDlgEvent : public QEvent
128{
129public:
130 VBoxCanShowUpdDlgEvent (bool aCanShow)
131 : QEvent ((QEvent::Type) VBoxDefs::CanShowUpdDlgEventType)
132 , mCanShow (aCanShow)
133 {}
134
135 const bool mCanShow;
136};
137
138class VBoxChangeGUILanguageEvent : public QEvent
139{
140public:
141 VBoxChangeGUILanguageEvent (QString aLangId)
142 : QEvent ((QEvent::Type) VBoxDefs::ChangeGUILanguageEventType)
143 , mLangId (aLangId)
144 {}
145
146 const QString mLangId;
147};
148
149#ifdef VBOX_GUI_WITH_SYSTRAY
150class VBoxMainWindowCountChangeEvent : public QEvent
151{
152public:
153 VBoxMainWindowCountChangeEvent (int aCount)
154 : QEvent ((QEvent::Type) VBoxDefs::MainWindowCountChangeEventType)
155 , mCount (aCount)
156 {}
157
158 const int mCount;
159};
160
161class VBoxCanShowTrayIconEvent : public QEvent
162{
163public:
164 VBoxCanShowTrayIconEvent (bool aCanShow)
165 : QEvent ((QEvent::Type) VBoxDefs::CanShowTrayIconEventType)
166 , mCanShow (aCanShow)
167 {}
168
169 const bool mCanShow;
170};
171
172class VBoxShowTrayIconEvent : public QEvent
173{
174public:
175 VBoxShowTrayIconEvent (bool aShow)
176 : QEvent ((QEvent::Type) VBoxDefs::ShowTrayIconEventType)
177 , mShow (aShow)
178 {}
179
180 const bool mShow;
181};
182
183class VBoxChangeTrayIconEvent : public QEvent
184{
185public:
186 VBoxChangeTrayIconEvent (bool aChanged)
187 : QEvent ((QEvent::Type) VBoxDefs::TrayIconChangeEventType)
188 , mChanged (aChanged)
189 {}
190
191 const bool mChanged;
192};
193#endif
194
195class VBoxChangeDockIconUpdateEvent : public QEvent
196{
197public:
198 VBoxChangeDockIconUpdateEvent (bool aChanged)
199 : QEvent ((QEvent::Type) VBoxDefs::ChangeDockIconUpdateEventType)
200 , mChanged (aChanged)
201 {}
202
203 const bool mChanged;
204};
205
206class Process : public QProcess
207{
208 Q_OBJECT;
209
210public:
211
212 static QByteArray singleShot (const QString &aProcessName,
213 int aTimeout = 5000
214 /* wait for data maximum 5 seconds */)
215 {
216 /* Why is it really needed is because of Qt4.3 bug with QProcess.
217 * This bug is about QProcess sometimes (~70%) do not receive
218 * notification about process was finished, so this makes
219 * 'bool QProcess::waitForFinished (int)' block the GUI thread and
220 * never dismissed with 'true' result even if process was really
221 * started&finished. So we just waiting for some information
222 * on process output and destroy the process with force. Due to
223 * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
224 * we have to change process state to QProcess::NotRunning. */
225
226 QByteArray result;
227 Process process;
228 process.start (aProcessName);
229 bool firstShotReady = process.waitForReadyRead (aTimeout);
230 if (firstShotReady)
231 result = process.readAllStandardOutput();
232 process.setProcessState (QProcess::NotRunning);
233#ifdef Q_WS_X11
234 int status;
235 waitpid(process.pid(), &status, 0);
236#endif
237 return result;
238 }
239
240protected:
241
242 Process (QWidget *aParent = 0) : QProcess (aParent) {}
243};
244
245// VBoxGlobal class
246////////////////////////////////////////////////////////////////////////////////
247
248class VBoxSelectorWnd;
249class VBoxConsoleWnd;
250class VBoxRegistrationDlg;
251class VBoxUpdateDlg;
252
253class VBoxGlobal : public QObject
254{
255 Q_OBJECT
256
257public:
258
259 typedef QHash <ulong, QString> QULongStringHash;
260 typedef QHash <long, QString> QLongStringHash;
261
262 static VBoxGlobal &instance();
263
264 bool isValid() { return mValid; }
265
266 QString versionString() { return mVerString; }
267
268 CVirtualBox virtualBox() const { return mVBox; }
269
270 const VBoxGlobalSettings &settings() const { return gset; }
271 bool setSettings (const VBoxGlobalSettings &gs);
272
273 VBoxSelectorWnd &selectorWnd();
274 VBoxConsoleWnd &consoleWnd();
275
276 /* main window handle storage */
277 void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
278 QWidget *mainWindow() const { return mMainWindow; }
279
280 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
281#ifdef VBOX_GUI_WITH_SYSTRAY
282 bool isTrayMenu() const;
283 void setTrayMenu(bool aIsTrayMenu);
284 void trayIconShowSelector();
285 bool trayIconInstall();
286#endif
287 QUuid managedVMUuid() const { return vmUuid; }
288
289 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
290 const char *vmRenderModeStr() const { return vm_render_mode_str; }
291
292#ifdef VBOX_WITH_DEBUGGER_GUI
293 bool isDebuggerEnabled() const { return mDbgEnabled; }
294 bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
295 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
296#else
297 bool isDebuggerAutoShowEnabled() const { return false; }
298#endif
299
300 /* VBox enum to/from string/icon/color convertors */
301
302 QList <CGuestOSType> vmGuestOSFamilyList() const;
303 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
304 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
305 CGuestOSType vmGuestOSType (const QString &aTypeId,
306 const QString &aFamilyId = QString::null) const;
307 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
308
309 QPixmap toIcon (KMachineState s) const
310 {
311 QPixmap *pm = mVMStateIcons.value (s);
312 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
313 return pm ? *pm : QPixmap();
314 }
315
316 const QColor &toColor (KMachineState s) const
317 {
318 static const QColor none;
319 AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
320 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
321 }
322
323 QString toString (KMachineState s) const
324 {
325 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
326 return mMachineStates.value (s);
327 }
328
329 QString toString (KSessionState s) const
330 {
331 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
332 return mSessionStates.value (s);
333 }
334
335 /**
336 * Returns a string representation of the given KStorageBus enum value.
337 * Complementary to #toStorageBusType (const QString &) const.
338 */
339 QString toString (KStorageBus aBus) const
340 {
341 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
342 return mStorageBuses [aBus];
343 }
344
345 /**
346 * Returns a KStorageBus enum value corresponding to the given string
347 * representation. Complementary to #toString (KStorageBus) const.
348 */
349 KStorageBus toStorageBusType (const QString &aBus) const
350 {
351 QULongStringHash::const_iterator it =
352 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
353 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
354 aBus.toLatin1().constData()));
355 return KStorageBus (it.key());
356 }
357
358 KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
359 {
360 KStorageBus sb = KStorageBus_Null;
361 switch (aControllerType)
362 {
363 case KStorageControllerType_Null: sb = KStorageBus_Null; break;
364 case KStorageControllerType_PIIX3:
365 case KStorageControllerType_PIIX4:
366 case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
367 case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
368 case KStorageControllerType_LsiLogic:
369 case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
370 default:
371 AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
372 }
373 return sb;
374 }
375
376 QString toString (KStorageBus aBus, LONG aChannel) const;
377 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
378
379 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
380 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
381
382 QString toFullString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
383
384 QString toString (KHardDiskType t) const
385 {
386 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
387 return mDiskTypes.value (t);
388 }
389
390 /**
391 * Similar to toString (KHardDiskType), but returns 'Differencing' for
392 * normal hard disks that have a parent.
393 */
394 QString hardDiskTypeString (const CHardDisk &aHD) const
395 {
396 if (!aHD.GetParent().isNull())
397 {
398 Assert (aHD.GetType() == KHardDiskType_Normal);
399 return mDiskTypes_Differencing;
400 }
401 return toString (aHD.GetType());
402 }
403
404 QString toString (KVRDPAuthType t) const
405 {
406 AssertMsg (!mVRDPAuthTypes.value (t).isNull(), ("No text for %d", t));
407 return mVRDPAuthTypes.value (t);
408 }
409
410 QString toString (KPortMode t) const
411 {
412 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
413 return mPortModeTypes.value (t);
414 }
415
416 QString toString (KUSBDeviceFilterAction t) const
417 {
418 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
419 return mUSBFilterActionTypes.value (t);
420 }
421
422 QString toString (KClipboardMode t) const
423 {
424 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
425 return mClipboardTypes.value (t);
426 }
427
428 KClipboardMode toClipboardModeType (const QString &s) const
429 {
430 QULongStringHash::const_iterator it =
431 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
432 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
433 s.toLatin1().constData()));
434 return KClipboardMode (it.key());
435 }
436
437 QString toString (KStorageControllerType t) const
438 {
439 AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
440 return mStorageControllerTypes.value (t);
441 }
442
443 KStorageControllerType toIDEControllerType (const QString &s) const
444 {
445 QULongStringHash::const_iterator it =
446 qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
447 AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
448 s.toLatin1().constData()));
449 return KStorageControllerType (it.key());
450 }
451
452 KVRDPAuthType toVRDPAuthType (const QString &s) const
453 {
454 QULongStringHash::const_iterator it =
455 qFind (mVRDPAuthTypes.begin(), mVRDPAuthTypes.end(), s);
456 AssertMsg (it != mVRDPAuthTypes.end(), ("No value for {%s}",
457 s.toLatin1().constData()));
458 return KVRDPAuthType (it.key());
459 }
460
461 KPortMode toPortMode (const QString &s) const
462 {
463 QULongStringHash::const_iterator it =
464 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
465 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
466 s.toLatin1().constData()));
467 return KPortMode (it.key());
468 }
469
470 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
471 {
472 QULongStringHash::const_iterator it =
473 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
474 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
475 s.toLatin1().constData()));
476 return KUSBDeviceFilterAction (it.key());
477 }
478
479 QString toString (KDeviceType t) const
480 {
481 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
482 return mDeviceTypes.value (t);
483 }
484
485 KDeviceType toDeviceType (const QString &s) const
486 {
487 QULongStringHash::const_iterator it =
488 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
489 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
490 s.toLatin1().constData()));
491 return KDeviceType (it.key());
492 }
493
494 QStringList deviceTypeStrings() const;
495
496 QString toString (KAudioDriverType t) const
497 {
498 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
499 return mAudioDriverTypes.value (t);
500 }
501
502 KAudioDriverType toAudioDriverType (const QString &s) const
503 {
504 QULongStringHash::const_iterator it =
505 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
506 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
507 s.toLatin1().constData()));
508 return KAudioDriverType (it.key());
509 }
510
511 QString toString (KAudioControllerType t) const
512 {
513 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
514 return mAudioControllerTypes.value (t);
515 }
516
517 KAudioControllerType toAudioControllerType (const QString &s) const
518 {
519 QULongStringHash::const_iterator it =
520 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
521 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
522 s.toLatin1().constData()));
523 return KAudioControllerType (it.key());
524 }
525
526 QString toString (KNetworkAdapterType t) const
527 {
528 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
529 return mNetworkAdapterTypes.value (t);
530 }
531
532 KNetworkAdapterType toNetworkAdapterType (const QString &s) const
533 {
534 QULongStringHash::const_iterator it =
535 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
536 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
537 s.toLatin1().constData()));
538 return KNetworkAdapterType (it.key());
539 }
540
541 QString toString (KNetworkAttachmentType t) const
542 {
543 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
544 return mNetworkAttachmentTypes.value (t);
545 }
546
547 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
548 {
549 QULongStringHash::const_iterator it =
550 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
551 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
552 s.toLatin1().constData()));
553 return KNetworkAttachmentType (it.key());
554 }
555
556 QString toString (KUSBDeviceState aState) const
557 {
558 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
559 return mUSBDeviceStates.value (aState);
560 }
561
562 QStringList COMPortNames() const;
563 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
564 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
565
566 QStringList LPTPortNames() const;
567 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
568 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
569
570 QPixmap snapshotIcon (bool online) const
571 {
572 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
573 }
574
575 QPixmap warningIcon() const { return mWarningIcon; }
576 QPixmap errorIcon() const { return mErrorIcon; }
577
578 /* details generators */
579
580 QString details (const CHardDisk &aHD, bool aPredictDiff);
581
582 QString details (const CUSBDevice &aDevice) const;
583 QString toolTip (const CUSBDevice &aDevice) const;
584 QString toolTip (const CUSBDeviceFilter &aFilter) const;
585
586 QString detailsReport (const CMachine &aMachine, bool aIsNewVM,
587 bool aWithLinks);
588
589 QString platformInfo();
590
591 /* VirtualBox helpers */
592
593#if defined(Q_WS_X11) && !defined(VBOX_OSE)
594 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
595 bool showVirtualBoxLicense();
596#endif
597
598 bool checkForAutoConvertedSettings (bool aAfterRefresh = false);
599
600 void checkForAutoConvertedSettingsAfterRefresh()
601 { checkForAutoConvertedSettings (true); }
602
603 CSession openSession (const QUuid &aId, bool aExisting = false);
604
605 /** Shortcut to openSession (aId, true). */
606 CSession openExistingSession (const QUuid &aId) { return openSession (aId, true); }
607
608 bool startMachine (const QUuid &id);
609
610 void startEnumeratingMedia();
611
612 /**
613 * Returns a list of all currently registered media. This list is used to
614 * globally track the accessiblity state of all media on a dedicated thread.
615 *
616 * Note that the media list is initially empty (i.e. before the enumeration
617 * process is started for the first time using #startEnumeratingMedia()).
618 * See #startEnumeratingMedia() for more information about how meida are
619 * sorted in the returned list.
620 */
621 const VBoxMediaList &currentMediaList() const { return mMediaList; }
622
623 /** Returns true if the media enumeration is in progress. */
624 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
625
626 void addMedium (const VBoxMedium &);
627 void updateMedium (const VBoxMedium &);
628 void removeMedium (VBoxDefs::MediaType, const QUuid &);
629
630 bool findMedium (const CMedium &, VBoxMedium &) const;
631
632 /** Compact version of #findMediumTo(). Asserts if not found. */
633 VBoxMedium getMedium (const CMedium &aObj) const
634 {
635 VBoxMedium medium;
636 if (!findMedium (aObj, medium))
637 AssertFailed();
638 return medium;
639 }
640
641 /* Returns the number of current running Fe/Qt4 main windows. */
642 int mainWindowCount();
643
644 /* various helpers */
645
646 QString languageName() const;
647 QString languageCountry() const;
648 QString languageNameEnglish() const;
649 QString languageCountryEnglish() const;
650 QString languageTranslators() const;
651
652 void retranslateUi();
653
654 /** @internal made public for internal purposes */
655 void cleanup();
656
657 /* public static stuff */
658
659 static bool isDOSType (const QString &aOSTypeId);
660
661 static void adoptLabelPixmap (QLabel *);
662
663 static QString languageId();
664 static void loadLanguage (const QString &aLangId = QString::null);
665 QString helpFile() const;
666
667 static QIcon iconSet (const char *aNormal,
668 const char *aDisabled = NULL,
669 const char *aActive = NULL);
670 static QIcon iconSetOnOff (const char *aNormal, const char *aNormalOff,
671 const char *aDisabled = NULL,
672 const char *aDisabledOff = NULL,
673 const char *aActive = NULL,
674 const char *aActiveOff = NULL);
675 static QIcon iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,
676 const char *aNormal, const char *aSmallNormal,
677 const char *aDisabled = NULL,
678 const char *aSmallDisabled = NULL,
679 const char *aActive = NULL,
680 const char *aSmallActive = NULL);
681
682 static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);
683
684 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
685
686 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
687 bool aCanResize = true);
688 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
689 bool aCanResize = true);
690 static QRegion flip (const QRegion &aRegion);
691
692 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
693 bool aCanResize = true);
694
695 static QChar decimalSep();
696 static QString sizeRegexp();
697
698 static quint64 parseSize (const QString &);
699 static QString formatSize (quint64 aSize, uint aDecimal = 2,
700 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
701
702 static quint64 requiredVideoMemory (CMachine *aMachine = 0);
703
704 static QString locationForHTML (const QString &aFileName);
705
706 static QString highlight (const QString &aStr, bool aToolTip = false);
707
708 static QString emphasize (const QString &aStr);
709
710 static QString systemLanguageId();
711
712 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
713 const QString &aCaption = QString::null,
714 bool aDirOnly = TRUE,
715 bool resolveSymlinks = TRUE);
716
717 static QString getSaveFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
718 const QString &aCaption, QString *aSelectedFilter = NULL,
719 bool aResolveSymLinks = true);
720
721 static QString getOpenFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
722 const QString &aCaption, QString *aSelectedFilter = NULL,
723 bool aResolveSymLinks = true);
724
725 static QStringList getOpenFileNames (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
726 const QString &aCaption, QString *aSelectedFilter = NULL,
727 bool aResolveSymLinks = true,
728 bool aSingleFile = false);
729
730 static QString getFirstExistingDir (const QString &);
731
732 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
733
734 static QString removeAccelMark (const QString &aText);
735
736 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
737 static QString extractKeyFromActionText (const QString &aText);
738
739 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
740
741 static QWidget *findWidget (QWidget *aParent, const char *aName,
742 const char *aClassName = NULL,
743 bool aRecursive = false);
744
745 static QList <QPair <QString, QString> > HDDBackends();
746
747 /* Qt 4.2.0 support function */
748 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
749 {
750#if QT_VERSION < 0x040300
751 /* Deprecated since > 4.2 */
752 aLayout->setMargin (aMargin);
753#else
754 /* New since > 4.2 */
755 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
756#endif
757 }
758
759 static QString documentsPath();
760
761signals:
762
763 /**
764 * Emitted at the beginning of the enumeration process started by
765 * #startEnumeratingMedia().
766 */
767 void mediumEnumStarted();
768
769 /**
770 * Emitted when a new medium item from the list has updated its
771 * accessibility state.
772 */
773 void mediumEnumerated (const VBoxMedium &aMedum);
774
775 /**
776 * Emitted at the end of the enumeration process started by
777 * #startEnumeratingMedia(). The @a aList argument is passed for
778 * convenience, it is exactly the same as returned by #currentMediaList().
779 */
780 void mediumEnumFinished (const VBoxMediaList &aList);
781
782 /** Emitted when a new media is added using #addMedia(). */
783 void mediumAdded (const VBoxMedium &);
784
785 /** Emitted when the media is updated using #updateMedia(). */
786 void mediumUpdated (const VBoxMedium &);
787
788 /** Emitted when the media is removed using #removeMedia(). */
789 void mediumRemoved (VBoxDefs::MediaType, const QUuid &);
790
791 /* signals emitted when the VirtualBox callback is called by the server
792 * (note that currently these signals are emitted only when the application
793 * is the in the VM selector mode) */
794
795 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
796 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
797 void machineRegistered (const VBoxMachineRegisteredEvent &e);
798 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
799 void snapshotChanged (const VBoxSnapshotEvent &e);
800#ifdef VBOX_GUI_WITH_SYSTRAY
801 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &e);
802 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e);
803 void trayIconShow (const VBoxShowTrayIconEvent &e);
804 void trayIconChanged (const VBoxChangeTrayIconEvent &e);
805#endif
806 void dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &e);
807
808 void canShowRegDlg (bool aCanShow);
809 void canShowUpdDlg (bool aCanShow);
810
811public slots:
812
813 bool openURL (const QString &aURL);
814
815 void showRegistrationDialog (bool aForce = true);
816 void showUpdateDialog (bool aForce = true);
817 void perDayNewVersionNotifier();
818
819protected:
820
821 bool event (QEvent *e);
822 bool eventFilter (QObject *, QEvent *);
823
824private:
825
826 VBoxGlobal();
827 ~VBoxGlobal();
828
829 void init();
830
831 bool mValid;
832
833 CVirtualBox mVBox;
834
835 VBoxGlobalSettings gset;
836
837 VBoxSelectorWnd *mSelectorWnd;
838 VBoxConsoleWnd *mConsoleWnd;
839 QWidget* mMainWindow;
840
841#ifdef VBOX_WITH_REGISTRATION
842 VBoxRegistrationDlg *mRegDlg;
843#endif
844 VBoxUpdateDlg *mUpdDlg;
845
846 QUuid vmUuid;
847
848#ifdef VBOX_GUI_WITH_SYSTRAY
849 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
850 bool mIncreasedWindowCounter : 1;
851#endif
852
853 QThread *mMediaEnumThread;
854 VBoxMediaList mMediaList;
855
856 VBoxDefs::RenderMode vm_render_mode;
857 const char * vm_render_mode_str;
858
859#ifdef VBOX_WITH_DEBUGGER_GUI
860 /** Whether the debugger should be accessible or not.
861 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
862 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
863 bool mDbgEnabled;
864 /** Whether to show the debugger automatically with the console.
865 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
866 bool mDbgAutoShow;
867 /** VBoxDbg module handle. */
868 RTLDRMOD mhVBoxDbg;
869#endif
870
871#if defined (Q_WS_WIN32)
872 DWORD dwHTMLHelpCookie;
873#endif
874
875 CVirtualBoxCallback callback;
876
877 QString mVerString;
878
879 QList <QString> mFamilyIDs;
880 QList <QList <CGuestOSType> > mTypes;
881 QHash <QString, QPixmap *> mOsTypeIcons;
882
883 QHash <ulong, QPixmap *> mVMStateIcons;
884 QHash <ulong, QColor *> mVMStateColors;
885
886 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
887
888 QULongStringHash mMachineStates;
889 QULongStringHash mSessionStates;
890 QULongStringHash mDeviceTypes;
891
892 QULongStringHash mStorageBuses;
893 QLongStringHash mStorageBusChannels;
894 QLongStringHash mStorageBusDevices;
895
896 QULongStringHash mDiskTypes;
897 QString mDiskTypes_Differencing;
898
899 QULongStringHash mVRDPAuthTypes;
900 QULongStringHash mPortModeTypes;
901 QULongStringHash mUSBFilterActionTypes;
902 QULongStringHash mAudioDriverTypes;
903 QULongStringHash mAudioControllerTypes;
904 QULongStringHash mNetworkAdapterTypes;
905 QULongStringHash mNetworkAttachmentTypes;
906 QULongStringHash mClipboardTypes;
907 QULongStringHash mStorageControllerTypes;
908 QULongStringHash mUSBDeviceStates;
909
910 QString mUserDefinedPortName;
911
912 QPixmap mWarningIcon, mErrorIcon;
913
914 mutable bool mDetailReportTemplatesReady;
915
916 friend VBoxGlobal &vboxGlobal();
917 friend class VBoxCallback;
918};
919
920inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
921
922// Helper classes
923////////////////////////////////////////////////////////////////////////////////
924
925/**
926 * Generic asyncronous event.
927 *
928 * This abstract class is intended to provide a conveinent way to execute
929 * code on the main GUI thread asynchronously to the calling party. This is
930 * done by putting necessary actions to the #handle() function in a subclass
931 * and then posting an instance of the subclass using #post(). The instance
932 * must be allocated on the heap using the <tt>new</tt> operation and will be
933 * automatically deleted after processing. Note that if you don't call #post()
934 * on the created instance, you have to delete it yourself.
935 */
936class VBoxAsyncEvent : public QEvent
937{
938public:
939
940 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
941
942 /**
943 * Worker function. Gets executed on the GUI thread when the posted event
944 * is processed by the main event loop.
945 */
946 virtual void handle() = 0;
947
948 /**
949 * Posts this event to the main event loop.
950 * The caller loses ownership of this object after this method returns
951 * and must not delete the object.
952 */
953 void post()
954 {
955 QApplication::postEvent (&vboxGlobal(), this);
956 }
957};
958
959/**
960 * USB Popup Menu class.
961 * This class provides the list of USB devices attached to the host.
962 */
963class VBoxUSBMenu : public QMenu
964{
965 Q_OBJECT
966
967public:
968
969 VBoxUSBMenu (QWidget *);
970
971 const CUSBDevice& getUSB (QAction *aAction);
972
973 void setConsole (const CConsole &);
974
975private slots:
976
977 void processAboutToShow();
978
979private:
980 bool event(QEvent *aEvent);
981
982 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
983 CConsole mConsole;
984};
985
986/**
987 * Enable/Disable Menu class.
988 * This class provides enable/disable menu items.
989 */
990class VBoxSwitchMenu : public QMenu
991{
992 Q_OBJECT
993
994public:
995
996 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
997
998 void setToolTip (const QString &);
999
1000private slots:
1001
1002 void processAboutToShow();
1003
1004private:
1005
1006 QAction *mAction;
1007 bool mInverted;
1008};
1009
1010#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