VirtualBox

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

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

Main: support for using VBox from Python on Windows (still certain limitation apply, such as enum visibility)

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