VirtualBox

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

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

FE/Qt4: typo/build fix

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