VirtualBox

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

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

FE/Qt4: 3701: Remove native file dialog handling on Windows if possible - moving re-implementation into separate QIFileDialog class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.3 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.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 QString versionString() { return mVerString; }
269
270 CVirtualBox virtualBox() const { return mVBox; }
271
272 const VBoxGlobalSettings &settings() const { return gset; }
273 bool setSettings (const VBoxGlobalSettings &gs);
274
275 VBoxSelectorWnd &selectorWnd();
276 VBoxConsoleWnd &consoleWnd();
277
278 /* main window handle storage */
279 void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
280 QWidget *mainWindow() const { return mMainWindow; }
281
282 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
283#ifdef VBOX_GUI_WITH_SYSTRAY
284 bool isTrayMenu() const;
285 void setTrayMenu(bool aIsTrayMenu);
286 void trayIconShowSelector();
287 bool trayIconInstall();
288#endif
289 QString managedVMUuid() const { return vmUuid; }
290
291 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
292 const char *vmRenderModeStr() const { return vm_render_mode_str; }
293
294#ifdef VBOX_WITH_DEBUGGER_GUI
295 bool isDebuggerEnabled() const { return mDbgEnabled; }
296 bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
297 bool isDebuggerAutoShowCommandLineEnabled() const { return mDbgAutoShowCommandLine; }
298 bool isDebuggerAutoShowStatisticsEnabled() const { return mDbgAutoShowStatistics; }
299 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
300
301 bool isStartPausedEnabled() const { return mStartPaused; }
302#else
303 bool isDebuggerAutoShowEnabled() const { return false; }
304 bool isDebuggerAutoShowCommandLineEnabled() const { return false; }
305 bool isDebuggerAutoShowStatisticsEnabled() const { return false; }
306
307 bool isStartPausedEnabled() const { return false; }
308#endif
309
310 /* VBox enum to/from string/icon/color convertors */
311
312 QList <CGuestOSType> vmGuestOSFamilyList() const;
313 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
314 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
315 CGuestOSType vmGuestOSType (const QString &aTypeId,
316 const QString &aFamilyId = QString::null) const;
317 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
318
319 QPixmap toIcon (KMachineState s) const
320 {
321 QPixmap *pm = mVMStateIcons.value (s);
322 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
323 return pm ? *pm : QPixmap();
324 }
325
326 const QColor &toColor (KMachineState s) const
327 {
328 static const QColor none;
329 AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
330 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
331 }
332
333 QString toString (KMachineState s) const
334 {
335 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
336 return mMachineStates.value (s);
337 }
338
339 QString toString (KSessionState s) const
340 {
341 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
342 return mSessionStates.value (s);
343 }
344
345 /**
346 * Returns a string representation of the given KStorageBus enum value.
347 * Complementary to #toStorageBusType (const QString &) const.
348 */
349 QString toString (KStorageBus aBus) const
350 {
351 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
352 return mStorageBuses [aBus];
353 }
354
355 /**
356 * Returns a KStorageBus enum value corresponding to the given string
357 * representation. Complementary to #toString (KStorageBus) const.
358 */
359 KStorageBus toStorageBusType (const QString &aBus) const
360 {
361 QULongStringHash::const_iterator it =
362 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
363 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
364 aBus.toLatin1().constData()));
365 return KStorageBus (it.key());
366 }
367
368 KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
369 {
370 KStorageBus sb = KStorageBus_Null;
371 switch (aControllerType)
372 {
373 case KStorageControllerType_Null: sb = KStorageBus_Null; break;
374 case KStorageControllerType_PIIX3:
375 case KStorageControllerType_PIIX4:
376 case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
377 case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
378 case KStorageControllerType_LsiLogic:
379 case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
380 default:
381 AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
382 }
383 return sb;
384 }
385
386 QString toString (KStorageBus aBus, LONG aChannel) const;
387 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
388
389 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
390 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
391
392 QString toFullString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
393
394 QString toString (KHardDiskType t) const
395 {
396 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
397 return mDiskTypes.value (t);
398 }
399
400 /**
401 * Similar to toString (KHardDiskType), but returns 'Differencing' for
402 * normal hard disks that have a parent.
403 */
404 QString hardDiskTypeString (const CHardDisk &aHD) const
405 {
406 if (!aHD.GetParent().isNull())
407 {
408 Assert (aHD.GetType() == KHardDiskType_Normal);
409 return mDiskTypes_Differencing;
410 }
411 return toString (aHD.GetType());
412 }
413
414 QString toString (KVRDPAuthType t) const
415 {
416 AssertMsg (!mVRDPAuthTypes.value (t).isNull(), ("No text for %d", t));
417 return mVRDPAuthTypes.value (t);
418 }
419
420 QString toString (KPortMode t) const
421 {
422 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
423 return mPortModeTypes.value (t);
424 }
425
426 QString toString (KUSBDeviceFilterAction t) const
427 {
428 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
429 return mUSBFilterActionTypes.value (t);
430 }
431
432 QString toString (KClipboardMode t) const
433 {
434 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
435 return mClipboardTypes.value (t);
436 }
437
438 KClipboardMode toClipboardModeType (const QString &s) const
439 {
440 QULongStringHash::const_iterator it =
441 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
442 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
443 s.toLatin1().constData()));
444 return KClipboardMode (it.key());
445 }
446
447 QString toString (KStorageControllerType t) const
448 {
449 AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
450 return mStorageControllerTypes.value (t);
451 }
452
453 KStorageControllerType toIDEControllerType (const QString &s) const
454 {
455 QULongStringHash::const_iterator it =
456 qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
457 AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
458 s.toLatin1().constData()));
459 return KStorageControllerType (it.key());
460 }
461
462 KVRDPAuthType toVRDPAuthType (const QString &s) const
463 {
464 QULongStringHash::const_iterator it =
465 qFind (mVRDPAuthTypes.begin(), mVRDPAuthTypes.end(), s);
466 AssertMsg (it != mVRDPAuthTypes.end(), ("No value for {%s}",
467 s.toLatin1().constData()));
468 return KVRDPAuthType (it.key());
469 }
470
471 KPortMode toPortMode (const QString &s) const
472 {
473 QULongStringHash::const_iterator it =
474 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
475 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
476 s.toLatin1().constData()));
477 return KPortMode (it.key());
478 }
479
480 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
481 {
482 QULongStringHash::const_iterator it =
483 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
484 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
485 s.toLatin1().constData()));
486 return KUSBDeviceFilterAction (it.key());
487 }
488
489 QString toString (KDeviceType t) const
490 {
491 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
492 return mDeviceTypes.value (t);
493 }
494
495 KDeviceType toDeviceType (const QString &s) const
496 {
497 QULongStringHash::const_iterator it =
498 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
499 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
500 s.toLatin1().constData()));
501 return KDeviceType (it.key());
502 }
503
504 QStringList deviceTypeStrings() const;
505
506 QString toString (KAudioDriverType t) const
507 {
508 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
509 return mAudioDriverTypes.value (t);
510 }
511
512 KAudioDriverType toAudioDriverType (const QString &s) const
513 {
514 QULongStringHash::const_iterator it =
515 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
516 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
517 s.toLatin1().constData()));
518 return KAudioDriverType (it.key());
519 }
520
521 QString toString (KAudioControllerType t) const
522 {
523 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
524 return mAudioControllerTypes.value (t);
525 }
526
527 KAudioControllerType toAudioControllerType (const QString &s) const
528 {
529 QULongStringHash::const_iterator it =
530 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
531 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
532 s.toLatin1().constData()));
533 return KAudioControllerType (it.key());
534 }
535
536 QString toString (KNetworkAdapterType t) const
537 {
538 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
539 return mNetworkAdapterTypes.value (t);
540 }
541
542 KNetworkAdapterType toNetworkAdapterType (const QString &s) const
543 {
544 QULongStringHash::const_iterator it =
545 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
546 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
547 s.toLatin1().constData()));
548 return KNetworkAdapterType (it.key());
549 }
550
551 QString toString (KNetworkAttachmentType t) const
552 {
553 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
554 return mNetworkAttachmentTypes.value (t);
555 }
556
557 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
558 {
559 QULongStringHash::const_iterator it =
560 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
561 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
562 s.toLatin1().constData()));
563 return KNetworkAttachmentType (it.key());
564 }
565
566 QString toString (KUSBDeviceState aState) const
567 {
568 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
569 return mUSBDeviceStates.value (aState);
570 }
571
572 QStringList COMPortNames() const;
573 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
574 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
575
576 QStringList LPTPortNames() const;
577 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
578 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
579
580 QPixmap snapshotIcon (bool online) const
581 {
582 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
583 }
584
585 QPixmap warningIcon() const { return mWarningIcon; }
586 QPixmap errorIcon() const { return mErrorIcon; }
587
588 /* details generators */
589
590 QString details (const CHardDisk &aHD, bool aPredictDiff);
591
592 QString details (const CUSBDevice &aDevice) const;
593 QString toolTip (const CUSBDevice &aDevice) const;
594 QString toolTip (const CUSBDeviceFilter &aFilter) const;
595
596 QString detailsReport (const CMachine &aMachine, 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 bool activateWindow (WId aWId, bool aSwitchDesktop = true);
722
723 static QString removeAccelMark (const QString &aText);
724
725 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
726 static QString extractKeyFromActionText (const QString &aText);
727
728 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
729
730 static QWidget *findWidget (QWidget *aParent, const char *aName,
731 const char *aClassName = NULL,
732 bool aRecursive = false);
733
734 static QList <QPair <QString, QString> > HDDBackends();
735
736 /* Qt 4.2.0 support function */
737 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
738 {
739#if QT_VERSION < 0x040300
740 /* Deprecated since > 4.2 */
741 aLayout->setMargin (aMargin);
742#else
743 /* New since > 4.2 */
744 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
745#endif
746 }
747
748 static QString documentsPath();
749
750signals:
751
752 /**
753 * Emitted at the beginning of the enumeration process started by
754 * #startEnumeratingMedia().
755 */
756 void mediumEnumStarted();
757
758 /**
759 * Emitted when a new medium item from the list has updated its
760 * accessibility state.
761 */
762 void mediumEnumerated (const VBoxMedium &aMedum);
763
764 /**
765 * Emitted at the end of the enumeration process started by
766 * #startEnumeratingMedia(). The @a aList argument is passed for
767 * convenience, it is exactly the same as returned by #currentMediaList().
768 */
769 void mediumEnumFinished (const VBoxMediaList &aList);
770
771 /** Emitted when a new media is added using #addMedia(). */
772 void mediumAdded (const VBoxMedium &);
773
774 /** Emitted when the media is updated using #updateMedia(). */
775 void mediumUpdated (const VBoxMedium &);
776
777 /** Emitted when the media is removed using #removeMedia(). */
778 void mediumRemoved (VBoxDefs::MediaType, const QString &);
779
780 /* signals emitted when the VirtualBox callback is called by the server
781 * (note that currently these signals are emitted only when the application
782 * is the in the VM selector mode) */
783
784 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
785 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
786 void machineRegistered (const VBoxMachineRegisteredEvent &e);
787 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
788 void snapshotChanged (const VBoxSnapshotEvent &e);
789#ifdef VBOX_GUI_WITH_SYSTRAY
790 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &e);
791 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e);
792 void trayIconShow (const VBoxShowTrayIconEvent &e);
793 void trayIconChanged (const VBoxChangeTrayIconEvent &e);
794#endif
795 void dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &e);
796
797 void canShowRegDlg (bool aCanShow);
798 void canShowUpdDlg (bool aCanShow);
799
800public slots:
801
802 bool openURL (const QString &aURL);
803
804 void showRegistrationDialog (bool aForce = true);
805 void showUpdateDialog (bool aForce = true);
806 void perDayNewVersionNotifier();
807
808protected:
809
810 bool event (QEvent *e);
811 bool eventFilter (QObject *, QEvent *);
812
813private:
814
815 VBoxGlobal();
816 ~VBoxGlobal();
817
818 void init();
819
820 bool mValid;
821
822 CVirtualBox mVBox;
823
824 VBoxGlobalSettings gset;
825
826 VBoxSelectorWnd *mSelectorWnd;
827 VBoxConsoleWnd *mConsoleWnd;
828 QWidget* mMainWindow;
829
830#ifdef VBOX_WITH_REGISTRATION
831 VBoxRegistrationDlg *mRegDlg;
832#endif
833 VBoxUpdateDlg *mUpdDlg;
834
835 QString vmUuid;
836
837#ifdef VBOX_GUI_WITH_SYSTRAY
838 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
839 bool mIncreasedWindowCounter : 1;
840#endif
841
842 QThread *mMediaEnumThread;
843 VBoxMediaList mMediaList;
844
845 VBoxDefs::RenderMode vm_render_mode;
846 const char * vm_render_mode_str;
847
848#ifdef VBOX_WITH_DEBUGGER_GUI
849 /** Whether the debugger should be accessible or not.
850 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
851 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
852 bool mDbgEnabled;
853 /** Whether to show the debugger automatically with the console.
854 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
855 bool mDbgAutoShow;
856 /** Whether to show the command line window when mDbgAutoShow is set. */
857 bool mDbgAutoShowCommandLine;
858 /** Whether to show the statistics window when mDbgAutoShow is set. */
859 bool mDbgAutoShowStatistics;
860 /** VBoxDbg module handle. */
861 RTLDRMOD mhVBoxDbg;
862
863 /** Whether to start the VM in paused state or not. */
864 bool mStartPaused;
865#endif
866
867#if defined (Q_WS_WIN32)
868 DWORD dwHTMLHelpCookie;
869#endif
870
871 CVirtualBoxCallback callback;
872
873 QString mVerString;
874
875 QList <QString> mFamilyIDs;
876 QList <QList <CGuestOSType> > mTypes;
877 QHash <QString, QPixmap *> mOsTypeIcons;
878
879 QHash <ulong, QPixmap *> mVMStateIcons;
880 QHash <ulong, QColor *> mVMStateColors;
881
882 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
883
884 QULongStringHash mMachineStates;
885 QULongStringHash mSessionStates;
886 QULongStringHash mDeviceTypes;
887
888 QULongStringHash mStorageBuses;
889 QLongStringHash mStorageBusChannels;
890 QLongStringHash mStorageBusDevices;
891
892 QULongStringHash mDiskTypes;
893 QString mDiskTypes_Differencing;
894
895 QULongStringHash mVRDPAuthTypes;
896 QULongStringHash mPortModeTypes;
897 QULongStringHash mUSBFilterActionTypes;
898 QULongStringHash mAudioDriverTypes;
899 QULongStringHash mAudioControllerTypes;
900 QULongStringHash mNetworkAdapterTypes;
901 QULongStringHash mNetworkAttachmentTypes;
902 QULongStringHash mClipboardTypes;
903 QULongStringHash mStorageControllerTypes;
904 QULongStringHash mUSBDeviceStates;
905
906 QString mUserDefinedPortName;
907
908 QPixmap mWarningIcon, mErrorIcon;
909
910 friend VBoxGlobal &vboxGlobal();
911 friend class VBoxCallback;
912};
913
914inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
915
916// Helper classes
917////////////////////////////////////////////////////////////////////////////////
918
919/**
920 * Generic asyncronous event.
921 *
922 * This abstract class is intended to provide a conveinent way to execute
923 * code on the main GUI thread asynchronously to the calling party. This is
924 * done by putting necessary actions to the #handle() function in a subclass
925 * and then posting an instance of the subclass using #post(). The instance
926 * must be allocated on the heap using the <tt>new</tt> operation and will be
927 * automatically deleted after processing. Note that if you don't call #post()
928 * on the created instance, you have to delete it yourself.
929 */
930class VBoxAsyncEvent : public QEvent
931{
932public:
933
934 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
935
936 /**
937 * Worker function. Gets executed on the GUI thread when the posted event
938 * is processed by the main event loop.
939 */
940 virtual void handle() = 0;
941
942 /**
943 * Posts this event to the main event loop.
944 * The caller loses ownership of this object after this method returns
945 * and must not delete the object.
946 */
947 void post()
948 {
949 QApplication::postEvent (&vboxGlobal(), this);
950 }
951};
952
953/**
954 * USB Popup Menu class.
955 * This class provides the list of USB devices attached to the host.
956 */
957class VBoxUSBMenu : public QMenu
958{
959 Q_OBJECT
960
961public:
962
963 VBoxUSBMenu (QWidget *);
964
965 const CUSBDevice& getUSB (QAction *aAction);
966
967 void setConsole (const CConsole &);
968
969private slots:
970
971 void processAboutToShow();
972
973private:
974 bool event(QEvent *aEvent);
975
976 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
977 CConsole mConsole;
978};
979
980/**
981 * Enable/Disable Menu class.
982 * This class provides enable/disable menu items.
983 */
984class VBoxSwitchMenu : public QMenu
985{
986 Q_OBJECT
987
988public:
989
990 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
991
992 void setToolTip (const QString &);
993
994private slots:
995
996 void processAboutToShow();
997
998private:
999
1000 QAction *mAction;
1001 bool mInverted;
1002};
1003
1004#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