VirtualBox

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

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

Fe/Qt: --debug-command-line and --debug-statistics.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.3 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.215389.xyz. 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 bool isDebuggerAutoShowCommandLineEnabled() const { return mDbgAutoShowCommandLine; }
296 bool isDebuggerAutoShowStatisticsEnabled() const { return mDbgAutoShowStatistics; }
297 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
298#else
299 bool isDebuggerAutoShowEnabled() const { return false; }
300 bool isDebuggerAutoShowCommandLineEnabled() const { return false; }
301 bool isDebuggerAutoShowStatisticsEnabled() const { return false; }
302#endif
303
304 /* VBox enum to/from string/icon/color convertors */
305
306 QList <CGuestOSType> vmGuestOSFamilyList() const;
307 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
308 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
309 CGuestOSType vmGuestOSType (const QString &aTypeId,
310 const QString &aFamilyId = QString::null) const;
311 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
312
313 QPixmap toIcon (KMachineState s) const
314 {
315 QPixmap *pm = mVMStateIcons.value (s);
316 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
317 return pm ? *pm : QPixmap();
318 }
319
320 const QColor &toColor (KMachineState s) const
321 {
322 static const QColor none;
323 AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
324 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
325 }
326
327 QString toString (KMachineState s) const
328 {
329 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
330 return mMachineStates.value (s);
331 }
332
333 QString toString (KSessionState s) const
334 {
335 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
336 return mSessionStates.value (s);
337 }
338
339 /**
340 * Returns a string representation of the given KStorageBus enum value.
341 * Complementary to #toStorageBusType (const QString &) const.
342 */
343 QString toString (KStorageBus aBus) const
344 {
345 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
346 return mStorageBuses [aBus];
347 }
348
349 /**
350 * Returns a KStorageBus enum value corresponding to the given string
351 * representation. Complementary to #toString (KStorageBus) const.
352 */
353 KStorageBus toStorageBusType (const QString &aBus) const
354 {
355 QULongStringHash::const_iterator it =
356 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
357 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
358 aBus.toLatin1().constData()));
359 return KStorageBus (it.key());
360 }
361
362 KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
363 {
364 KStorageBus sb = KStorageBus_Null;
365 switch (aControllerType)
366 {
367 case KStorageControllerType_Null: sb = KStorageBus_Null; break;
368 case KStorageControllerType_PIIX3:
369 case KStorageControllerType_PIIX4:
370 case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
371 case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
372 case KStorageControllerType_LsiLogic:
373 case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
374 default:
375 AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
376 }
377 return sb;
378 }
379
380 QString toString (KStorageBus aBus, LONG aChannel) const;
381 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
382
383 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
384 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
385
386 QString toFullString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
387
388 QString toString (KHardDiskType t) const
389 {
390 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
391 return mDiskTypes.value (t);
392 }
393
394 /**
395 * Similar to toString (KHardDiskType), but returns 'Differencing' for
396 * normal hard disks that have a parent.
397 */
398 QString hardDiskTypeString (const CHardDisk &aHD) const
399 {
400 if (!aHD.GetParent().isNull())
401 {
402 Assert (aHD.GetType() == KHardDiskType_Normal);
403 return mDiskTypes_Differencing;
404 }
405 return toString (aHD.GetType());
406 }
407
408 QString toString (KVRDPAuthType t) const
409 {
410 AssertMsg (!mVRDPAuthTypes.value (t).isNull(), ("No text for %d", t));
411 return mVRDPAuthTypes.value (t);
412 }
413
414 QString toString (KPortMode t) const
415 {
416 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
417 return mPortModeTypes.value (t);
418 }
419
420 QString toString (KUSBDeviceFilterAction t) const
421 {
422 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
423 return mUSBFilterActionTypes.value (t);
424 }
425
426 QString toString (KClipboardMode t) const
427 {
428 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
429 return mClipboardTypes.value (t);
430 }
431
432 KClipboardMode toClipboardModeType (const QString &s) const
433 {
434 QULongStringHash::const_iterator it =
435 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
436 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
437 s.toLatin1().constData()));
438 return KClipboardMode (it.key());
439 }
440
441 QString toString (KStorageControllerType t) const
442 {
443 AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
444 return mStorageControllerTypes.value (t);
445 }
446
447 KStorageControllerType toIDEControllerType (const QString &s) const
448 {
449 QULongStringHash::const_iterator it =
450 qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
451 AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
452 s.toLatin1().constData()));
453 return KStorageControllerType (it.key());
454 }
455
456 KVRDPAuthType toVRDPAuthType (const QString &s) const
457 {
458 QULongStringHash::const_iterator it =
459 qFind (mVRDPAuthTypes.begin(), mVRDPAuthTypes.end(), s);
460 AssertMsg (it != mVRDPAuthTypes.end(), ("No value for {%s}",
461 s.toLatin1().constData()));
462 return KVRDPAuthType (it.key());
463 }
464
465 KPortMode toPortMode (const QString &s) const
466 {
467 QULongStringHash::const_iterator it =
468 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
469 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
470 s.toLatin1().constData()));
471 return KPortMode (it.key());
472 }
473
474 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
475 {
476 QULongStringHash::const_iterator it =
477 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
478 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
479 s.toLatin1().constData()));
480 return KUSBDeviceFilterAction (it.key());
481 }
482
483 QString toString (KDeviceType t) const
484 {
485 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
486 return mDeviceTypes.value (t);
487 }
488
489 KDeviceType toDeviceType (const QString &s) const
490 {
491 QULongStringHash::const_iterator it =
492 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
493 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
494 s.toLatin1().constData()));
495 return KDeviceType (it.key());
496 }
497
498 QStringList deviceTypeStrings() const;
499
500 QString toString (KAudioDriverType t) const
501 {
502 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
503 return mAudioDriverTypes.value (t);
504 }
505
506 KAudioDriverType toAudioDriverType (const QString &s) const
507 {
508 QULongStringHash::const_iterator it =
509 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
510 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
511 s.toLatin1().constData()));
512 return KAudioDriverType (it.key());
513 }
514
515 QString toString (KAudioControllerType t) const
516 {
517 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
518 return mAudioControllerTypes.value (t);
519 }
520
521 KAudioControllerType toAudioControllerType (const QString &s) const
522 {
523 QULongStringHash::const_iterator it =
524 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
525 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
526 s.toLatin1().constData()));
527 return KAudioControllerType (it.key());
528 }
529
530 QString toString (KNetworkAdapterType t) const
531 {
532 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
533 return mNetworkAdapterTypes.value (t);
534 }
535
536 KNetworkAdapterType toNetworkAdapterType (const QString &s) const
537 {
538 QULongStringHash::const_iterator it =
539 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
540 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
541 s.toLatin1().constData()));
542 return KNetworkAdapterType (it.key());
543 }
544
545 QString toString (KNetworkAttachmentType t) const
546 {
547 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
548 return mNetworkAttachmentTypes.value (t);
549 }
550
551 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
552 {
553 QULongStringHash::const_iterator it =
554 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
555 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
556 s.toLatin1().constData()));
557 return KNetworkAttachmentType (it.key());
558 }
559
560 QString toString (KUSBDeviceState aState) const
561 {
562 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
563 return mUSBDeviceStates.value (aState);
564 }
565
566 QStringList COMPortNames() const;
567 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
568 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
569
570 QStringList LPTPortNames() const;
571 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
572 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
573
574 QPixmap snapshotIcon (bool online) const
575 {
576 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
577 }
578
579 QPixmap warningIcon() const { return mWarningIcon; }
580 QPixmap errorIcon() const { return mErrorIcon; }
581
582 /* details generators */
583
584 QString details (const CHardDisk &aHD, bool aPredictDiff);
585
586 QString details (const CUSBDevice &aDevice) const;
587 QString toolTip (const CUSBDevice &aDevice) const;
588 QString toolTip (const CUSBDeviceFilter &aFilter) const;
589
590 QString detailsReport (const CMachine &aMachine, bool aIsNewVM,
591 bool aWithLinks);
592
593 QString platformInfo();
594
595 /* VirtualBox helpers */
596
597#if defined(Q_WS_X11) && !defined(VBOX_OSE)
598 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
599 bool showVirtualBoxLicense();
600#endif
601
602 bool checkForAutoConvertedSettings (bool aAfterRefresh = false);
603
604 void checkForAutoConvertedSettingsAfterRefresh()
605 { checkForAutoConvertedSettings (true); }
606
607 CSession openSession (const QUuid &aId, bool aExisting = false);
608
609 /** Shortcut to openSession (aId, true). */
610 CSession openExistingSession (const QUuid &aId) { return openSession (aId, true); }
611
612 bool startMachine (const QUuid &id);
613
614 void startEnumeratingMedia();
615
616 /**
617 * Returns a list of all currently registered media. This list is used to
618 * globally track the accessiblity state of all media on a dedicated thread.
619 *
620 * Note that the media list is initially empty (i.e. before the enumeration
621 * process is started for the first time using #startEnumeratingMedia()).
622 * See #startEnumeratingMedia() for more information about how meida are
623 * sorted in the returned list.
624 */
625 const VBoxMediaList &currentMediaList() const { return mMediaList; }
626
627 /** Returns true if the media enumeration is in progress. */
628 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
629
630 void addMedium (const VBoxMedium &);
631 void updateMedium (const VBoxMedium &);
632 void removeMedium (VBoxDefs::MediaType, const QUuid &);
633
634 bool findMedium (const CMedium &, VBoxMedium &) const;
635
636 /** Compact version of #findMediumTo(). Asserts if not found. */
637 VBoxMedium getMedium (const CMedium &aObj) const
638 {
639 VBoxMedium medium;
640 if (!findMedium (aObj, medium))
641 AssertFailed();
642 return medium;
643 }
644
645 /* Returns the number of current running Fe/Qt4 main windows. */
646 int mainWindowCount();
647
648 /* various helpers */
649
650 QString languageName() const;
651 QString languageCountry() const;
652 QString languageNameEnglish() const;
653 QString languageCountryEnglish() const;
654 QString languageTranslators() const;
655
656 void retranslateUi();
657
658 /** @internal made public for internal purposes */
659 void cleanup();
660
661 /* public static stuff */
662
663 static bool isDOSType (const QString &aOSTypeId);
664
665 static void adoptLabelPixmap (QLabel *);
666
667 static QString languageId();
668 static void loadLanguage (const QString &aLangId = QString::null);
669 QString helpFile() const;
670
671 static QIcon iconSet (const char *aNormal,
672 const char *aDisabled = NULL,
673 const char *aActive = NULL);
674 static QIcon iconSetOnOff (const char *aNormal, const char *aNormalOff,
675 const char *aDisabled = NULL,
676 const char *aDisabledOff = NULL,
677 const char *aActive = NULL,
678 const char *aActiveOff = NULL);
679 static QIcon iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,
680 const char *aNormal, const char *aSmallNormal,
681 const char *aDisabled = NULL,
682 const char *aSmallDisabled = NULL,
683 const char *aActive = NULL,
684 const char *aSmallActive = NULL);
685
686 static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);
687
688 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
689
690 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
691 bool aCanResize = true);
692 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
693 bool aCanResize = true);
694 static QRegion flip (const QRegion &aRegion);
695
696 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
697 bool aCanResize = true);
698
699 static QChar decimalSep();
700 static QString sizeRegexp();
701
702 static quint64 parseSize (const QString &);
703 static QString formatSize (quint64 aSize, uint aDecimal = 2,
704 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
705
706 static quint64 requiredVideoMemory (CMachine *aMachine = 0);
707
708 static QString locationForHTML (const QString &aFileName);
709
710 static QString highlight (const QString &aStr, bool aToolTip = false);
711
712 static QString emphasize (const QString &aStr);
713
714 static QString systemLanguageId();
715
716 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
717 const QString &aCaption = QString::null,
718 bool aDirOnly = TRUE,
719 bool resolveSymlinks = TRUE);
720
721 static QString getSaveFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
722 const QString &aCaption, QString *aSelectedFilter = NULL,
723 bool aResolveSymLinks = true);
724
725 static QString getOpenFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
726 const QString &aCaption, QString *aSelectedFilter = NULL,
727 bool aResolveSymLinks = true);
728
729 static QStringList getOpenFileNames (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
730 const QString &aCaption, QString *aSelectedFilter = NULL,
731 bool aResolveSymLinks = true,
732 bool aSingleFile = false);
733
734 static QString getFirstExistingDir (const QString &);
735
736 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
737
738 static QString removeAccelMark (const QString &aText);
739
740 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
741 static QString extractKeyFromActionText (const QString &aText);
742
743 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
744
745 static QWidget *findWidget (QWidget *aParent, const char *aName,
746 const char *aClassName = NULL,
747 bool aRecursive = false);
748
749 static QList <QPair <QString, QString> > HDDBackends();
750
751 /* Qt 4.2.0 support function */
752 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
753 {
754#if QT_VERSION < 0x040300
755 /* Deprecated since > 4.2 */
756 aLayout->setMargin (aMargin);
757#else
758 /* New since > 4.2 */
759 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
760#endif
761 }
762
763 static QString documentsPath();
764
765signals:
766
767 /**
768 * Emitted at the beginning of the enumeration process started by
769 * #startEnumeratingMedia().
770 */
771 void mediumEnumStarted();
772
773 /**
774 * Emitted when a new medium item from the list has updated its
775 * accessibility state.
776 */
777 void mediumEnumerated (const VBoxMedium &aMedum);
778
779 /**
780 * Emitted at the end of the enumeration process started by
781 * #startEnumeratingMedia(). The @a aList argument is passed for
782 * convenience, it is exactly the same as returned by #currentMediaList().
783 */
784 void mediumEnumFinished (const VBoxMediaList &aList);
785
786 /** Emitted when a new media is added using #addMedia(). */
787 void mediumAdded (const VBoxMedium &);
788
789 /** Emitted when the media is updated using #updateMedia(). */
790 void mediumUpdated (const VBoxMedium &);
791
792 /** Emitted when the media is removed using #removeMedia(). */
793 void mediumRemoved (VBoxDefs::MediaType, const QUuid &);
794
795 /* signals emitted when the VirtualBox callback is called by the server
796 * (note that currently these signals are emitted only when the application
797 * is the in the VM selector mode) */
798
799 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
800 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
801 void machineRegistered (const VBoxMachineRegisteredEvent &e);
802 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
803 void snapshotChanged (const VBoxSnapshotEvent &e);
804#ifdef VBOX_GUI_WITH_SYSTRAY
805 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &e);
806 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e);
807 void trayIconShow (const VBoxShowTrayIconEvent &e);
808 void trayIconChanged (const VBoxChangeTrayIconEvent &e);
809#endif
810 void dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &e);
811
812 void canShowRegDlg (bool aCanShow);
813 void canShowUpdDlg (bool aCanShow);
814
815public slots:
816
817 bool openURL (const QString &aURL);
818
819 void showRegistrationDialog (bool aForce = true);
820 void showUpdateDialog (bool aForce = true);
821 void perDayNewVersionNotifier();
822
823protected:
824
825 bool event (QEvent *e);
826 bool eventFilter (QObject *, QEvent *);
827
828private:
829
830 VBoxGlobal();
831 ~VBoxGlobal();
832
833 void init();
834
835 bool mValid;
836
837 CVirtualBox mVBox;
838
839 VBoxGlobalSettings gset;
840
841 VBoxSelectorWnd *mSelectorWnd;
842 VBoxConsoleWnd *mConsoleWnd;
843 QWidget* mMainWindow;
844
845#ifdef VBOX_WITH_REGISTRATION
846 VBoxRegistrationDlg *mRegDlg;
847#endif
848 VBoxUpdateDlg *mUpdDlg;
849
850 QUuid vmUuid;
851
852#ifdef VBOX_GUI_WITH_SYSTRAY
853 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
854 bool mIncreasedWindowCounter : 1;
855#endif
856
857 QThread *mMediaEnumThread;
858 VBoxMediaList mMediaList;
859
860 VBoxDefs::RenderMode vm_render_mode;
861 const char * vm_render_mode_str;
862
863#ifdef VBOX_WITH_DEBUGGER_GUI
864 /** Whether the debugger should be accessible or not.
865 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
866 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
867 bool mDbgEnabled;
868 /** Whether to show the debugger automatically with the console.
869 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
870 bool mDbgAutoShow;
871 /** Whether to show the command line window when mDbgAutoShow is set. */
872 bool mDbgAutoShowCommandLine;
873 /** Whether to show the statistics window when mDbgAutoShow is set. */
874 bool mDbgAutoShowStatistics;
875 /** VBoxDbg module handle. */
876 RTLDRMOD mhVBoxDbg;
877#endif
878
879#if defined (Q_WS_WIN32)
880 DWORD dwHTMLHelpCookie;
881#endif
882
883 CVirtualBoxCallback callback;
884
885 QString mVerString;
886
887 QList <QString> mFamilyIDs;
888 QList <QList <CGuestOSType> > mTypes;
889 QHash <QString, QPixmap *> mOsTypeIcons;
890
891 QHash <ulong, QPixmap *> mVMStateIcons;
892 QHash <ulong, QColor *> mVMStateColors;
893
894 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
895
896 QULongStringHash mMachineStates;
897 QULongStringHash mSessionStates;
898 QULongStringHash mDeviceTypes;
899
900 QULongStringHash mStorageBuses;
901 QLongStringHash mStorageBusChannels;
902 QLongStringHash mStorageBusDevices;
903
904 QULongStringHash mDiskTypes;
905 QString mDiskTypes_Differencing;
906
907 QULongStringHash mVRDPAuthTypes;
908 QULongStringHash mPortModeTypes;
909 QULongStringHash mUSBFilterActionTypes;
910 QULongStringHash mAudioDriverTypes;
911 QULongStringHash mAudioControllerTypes;
912 QULongStringHash mNetworkAdapterTypes;
913 QULongStringHash mNetworkAttachmentTypes;
914 QULongStringHash mClipboardTypes;
915 QULongStringHash mStorageControllerTypes;
916 QULongStringHash mUSBDeviceStates;
917
918 QString mUserDefinedPortName;
919
920 QPixmap mWarningIcon, mErrorIcon;
921
922 mutable bool mDetailReportTemplatesReady;
923
924 friend VBoxGlobal &vboxGlobal();
925 friend class VBoxCallback;
926};
927
928inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
929
930// Helper classes
931////////////////////////////////////////////////////////////////////////////////
932
933/**
934 * Generic asyncronous event.
935 *
936 * This abstract class is intended to provide a conveinent way to execute
937 * code on the main GUI thread asynchronously to the calling party. This is
938 * done by putting necessary actions to the #handle() function in a subclass
939 * and then posting an instance of the subclass using #post(). The instance
940 * must be allocated on the heap using the <tt>new</tt> operation and will be
941 * automatically deleted after processing. Note that if you don't call #post()
942 * on the created instance, you have to delete it yourself.
943 */
944class VBoxAsyncEvent : public QEvent
945{
946public:
947
948 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
949
950 /**
951 * Worker function. Gets executed on the GUI thread when the posted event
952 * is processed by the main event loop.
953 */
954 virtual void handle() = 0;
955
956 /**
957 * Posts this event to the main event loop.
958 * The caller loses ownership of this object after this method returns
959 * and must not delete the object.
960 */
961 void post()
962 {
963 QApplication::postEvent (&vboxGlobal(), this);
964 }
965};
966
967/**
968 * USB Popup Menu class.
969 * This class provides the list of USB devices attached to the host.
970 */
971class VBoxUSBMenu : public QMenu
972{
973 Q_OBJECT
974
975public:
976
977 VBoxUSBMenu (QWidget *);
978
979 const CUSBDevice& getUSB (QAction *aAction);
980
981 void setConsole (const CConsole &);
982
983private slots:
984
985 void processAboutToShow();
986
987private:
988 bool event(QEvent *aEvent);
989
990 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
991 CConsole mConsole;
992};
993
994/**
995 * Enable/Disable Menu class.
996 * This class provides enable/disable menu items.
997 */
998class VBoxSwitchMenu : public QMenu
999{
1000 Q_OBJECT
1001
1002public:
1003
1004 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
1005
1006 void setToolTip (const QString &);
1007
1008private slots:
1009
1010 void processAboutToShow();
1011
1012private:
1013
1014 QAction *mAction;
1015 bool mInverted;
1016};
1017
1018#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