VirtualBox

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

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

FE/Qt4: better approach

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