VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h@ 33626

Last change on this file since 33626 was 33626, checked in by vboxsync, 14 years ago

gui: vram settings cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.4 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2010 Oracle Corporation
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
19#ifndef __VBoxGlobal_h__
20#define __VBoxGlobal_h__
21
22#include "COMDefs.h"
23#include "VBox/com/Guid.h"
24
25#include "VBoxGlobalSettings.h"
26#include "VBoxMedium.h"
27
28/* Qt includes */
29#include <QApplication>
30#include <QLayout>
31#include <QMenu>
32#include <QStyle>
33#include <QProcess>
34#include <QHash>
35
36#ifdef Q_WS_X11
37# include <sys/wait.h>
38#endif
39
40class QAction;
41class QLabel;
42class QToolButton;
43class UIMachine;
44
45class Process : public QProcess
46{
47 Q_OBJECT;
48
49public:
50
51 static QByteArray singleShot (const QString &aProcessName,
52 int aTimeout = 5000
53 /* wait for data maximum 5 seconds */)
54 {
55 /* Why is it really needed is because of Qt4.3 bug with QProcess.
56 * This bug is about QProcess sometimes (~70%) do not receive
57 * notification about process was finished, so this makes
58 * 'bool QProcess::waitForFinished (int)' block the GUI thread and
59 * never dismissed with 'true' result even if process was really
60 * started&finished. So we just waiting for some information
61 * on process output and destroy the process with force. Due to
62 * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
63 * we have to change process state to QProcess::NotRunning. */
64
65 QByteArray result;
66 Process process;
67 process.start (aProcessName);
68 bool firstShotReady = process.waitForReadyRead (aTimeout);
69 if (firstShotReady)
70 result = process.readAllStandardOutput();
71 process.setProcessState (QProcess::NotRunning);
72#ifdef Q_WS_X11
73 int status;
74 if (process.pid() > 0)
75 waitpid(process.pid(), &status, 0);
76#endif
77 return result;
78 }
79
80protected:
81
82 Process (QWidget *aParent = 0) : QProcess (aParent) {}
83};
84
85struct StorageSlot
86{
87 StorageSlot() : bus (KStorageBus_Null), port (0), device (0) {}
88 StorageSlot (const StorageSlot &aOther) : bus (aOther.bus), port (aOther.port), device (aOther.device) {}
89 StorageSlot (KStorageBus aBus, LONG aPort, LONG aDevice) : bus (aBus), port (aPort), device (aDevice) {}
90 StorageSlot& operator= (const StorageSlot &aOther) { bus = aOther.bus; port = aOther.port; device = aOther.device; return *this; }
91 bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; }
92 bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; }
93 bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) ||
94 (bus == aOther.bus && port < aOther.port) ||
95 (bus == aOther.bus && port == aOther.port && device < aOther.device); }
96 bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) ||
97 (bus == aOther.bus && port > aOther.port) ||
98 (bus == aOther.bus && port == aOther.port && device > aOther.device); }
99 bool isNull() { return bus == KStorageBus_Null; }
100 KStorageBus bus; LONG port; LONG device;
101};
102Q_DECLARE_METATYPE (StorageSlot);
103
104// VBoxGlobal class
105////////////////////////////////////////////////////////////////////////////////
106
107class VBoxSelectorWnd;
108class UIRegistrationWzd;
109class VBoxUpdateDlg;
110
111class VBoxGlobal : public QObject
112{
113 Q_OBJECT
114
115public:
116
117 typedef QHash <ulong, QString> QULongStringHash;
118 typedef QHash <long, QString> QLongStringHash;
119
120 static VBoxGlobal &instance();
121
122 bool isValid() { return mValid; }
123
124 static QString qtRTVersionString();
125 static uint qtRTVersion();
126 static QString qtCTVersionString();
127 static uint qtCTVersion();
128
129 QString versionString() { return mVerString; }
130
131 CVirtualBox virtualBox() const { return mVBox; }
132
133 VBoxGlobalSettings &settings() { return gset; }
134 bool setSettings (VBoxGlobalSettings &gs);
135
136 VBoxSelectorWnd &selectorWnd();
137
138 QWidget *vmWindow();
139
140 bool createVirtualMachine(const CSession &session);
141 UIMachine* virtualMachine();
142
143 /* main window handle storage */
144 void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
145 QWidget *mainWindow() const { return mMainWindow; }
146
147 /* branding */
148 bool brandingIsActive (bool aForce = false);
149 QString brandingGetKey (QString aKey);
150
151 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
152 bool showStartVMErrors() const { return mShowStartVMErrors; }
153#ifdef VBOX_GUI_WITH_SYSTRAY
154 bool isTrayMenu() const;
155 void setTrayMenu(bool aIsTrayMenu);
156 void trayIconShowSelector();
157 bool trayIconInstall();
158#endif
159 QString managedVMUuid() const { return vmUuid; }
160
161 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
162 const char *vmRenderModeStr() const { return vm_render_mode_str; }
163 bool isKWinManaged() const { return mIsKWinManaged; }
164
165 const QRect availableGeometry(int iScreen = 0) const;
166
167#ifdef VBOX_WITH_DEBUGGER_GUI
168 bool isDebuggerEnabled(CMachine &aMachine);
169 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
170 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
171 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
172 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
173
174 bool isStartPausedEnabled() const { return mStartPaused; }
175#else
176 bool isDebuggerAutoShowEnabled() const { return false; }
177 bool isDebuggerAutoShowCommandLineEnabled() const { return false; }
178 bool isDebuggerAutoShowStatisticsEnabled() const { return false; }
179
180 bool isStartPausedEnabled() const { return false; }
181#endif
182
183 /* VBox enum to/from string/icon/color convertors */
184
185 QList <CGuestOSType> vmGuestOSFamilyList() const;
186 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
187 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
188 CGuestOSType vmGuestOSType (const QString &aTypeId,
189 const QString &aFamilyId = QString::null) const;
190 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
191
192 QPixmap toIcon (KMachineState s) const
193 {
194 QPixmap *pm = mVMStateIcons.value (s);
195 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
196 return pm ? *pm : QPixmap();
197 }
198
199 static inline QString yearsToString (uint32_t cVal)
200 {
201 return tr("%n year(s)", "", cVal);
202 }
203
204 static inline QString monthsToString (uint32_t cVal)
205 {
206 return tr("%n month(s)", "", cVal);
207 }
208
209 static inline QString daysToString (uint32_t cVal)
210 {
211 return tr("%n day(s)", "", cVal);
212 }
213
214 static inline QString hoursToString (uint32_t cVal)
215 {
216 return tr("%n hour(s)", "", cVal);
217 }
218
219 static inline QString minutesToString (uint32_t cVal)
220 {
221 return tr("%n minute(s)", "", cVal);
222 }
223
224 static inline QString secondsToString (uint32_t cVal)
225 {
226 return tr("%n second(s)", "", cVal);
227 }
228
229 const QColor &toColor (KMachineState s) const
230 {
231 static const QColor none;
232 AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
233 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
234 }
235
236 QString toString (KMachineState s) const
237 {
238 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
239 return mMachineStates.value (s);
240 }
241
242 QString toString (KSessionState s) const
243 {
244 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
245 return mSessionStates.value (s);
246 }
247
248 /**
249 * Returns a string representation of the given KStorageBus enum value.
250 * Complementary to #toStorageBusType (const QString &) const.
251 */
252 QString toString (KStorageBus aBus) const
253 {
254 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
255 return mStorageBuses [aBus];
256 }
257
258 /**
259 * Returns a KStorageBus enum value corresponding to the given string
260 * representation. Complementary to #toString (KStorageBus) const.
261 */
262 KStorageBus toStorageBusType (const QString &aBus) const
263 {
264 QULongStringHash::const_iterator it =
265 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
266 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
267 aBus.toLatin1().constData()));
268 return KStorageBus (it.key());
269 }
270
271 KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
272 {
273 KStorageBus sb = KStorageBus_Null;
274 switch (aControllerType)
275 {
276 case KStorageControllerType_Null: sb = KStorageBus_Null; break;
277 case KStorageControllerType_PIIX3:
278 case KStorageControllerType_PIIX4:
279 case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
280 case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
281 case KStorageControllerType_LsiLogic:
282 case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
283 case KStorageControllerType_I82078: sb = KStorageBus_Floppy; break;
284 default:
285 AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
286 }
287 return sb;
288 }
289
290 QString toString (KStorageBus aBus, LONG aChannel) const;
291 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
292
293 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
294 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
295
296 QString toString (StorageSlot aSlot) const;
297 StorageSlot toStorageSlot (const QString &aSlot) const;
298
299 QString toString (KMediumType t) const
300 {
301 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
302 return mDiskTypes.value (t);
303 }
304
305 /**
306 * Similar to toString (KMediumType), but returns 'Differencing' for
307 * normal hard disks that have a parent.
308 */
309 QString mediumTypeString (const CMedium &aHD) const
310 {
311 if (!aHD.GetParent().isNull())
312 {
313 Assert (aHD.GetType() == KMediumType_Normal);
314 return mDiskTypes_Differencing;
315 }
316 return toString (aHD.GetType());
317 }
318
319 QString toString (KAuthType t) const
320 {
321 AssertMsg (!mAuthTypes.value (t).isNull(), ("No text for %d", t));
322 return mAuthTypes.value (t);
323 }
324
325 QString toString (KPortMode t) const
326 {
327 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
328 return mPortModeTypes.value (t);
329 }
330
331 QString toString (KUSBDeviceFilterAction t) const
332 {
333 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
334 return mUSBFilterActionTypes.value (t);
335 }
336
337 QString toString (KClipboardMode t) const
338 {
339 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
340 return mClipboardTypes.value (t);
341 }
342
343 KClipboardMode toClipboardModeType (const QString &s) const
344 {
345 QULongStringHash::const_iterator it =
346 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
347 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
348 s.toLatin1().constData()));
349 return KClipboardMode (it.key());
350 }
351
352 QString toString (KStorageControllerType t) const
353 {
354 AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
355 return mStorageControllerTypes.value (t);
356 }
357
358 KStorageControllerType toControllerType (const QString &s) const
359 {
360 QULongStringHash::const_iterator it =
361 qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
362 AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
363 s.toLatin1().constData()));
364 return KStorageControllerType (it.key());
365 }
366
367 KAuthType toAuthType (const QString &s) const
368 {
369 QULongStringHash::const_iterator it =
370 qFind (mAuthTypes.begin(), mAuthTypes.end(), s);
371 AssertMsg (it != mAuthTypes.end(), ("No value for {%s}",
372 s.toLatin1().constData()));
373 return KAuthType (it.key());
374 }
375
376 KPortMode toPortMode (const QString &s) const
377 {
378 QULongStringHash::const_iterator it =
379 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
380 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
381 s.toLatin1().constData()));
382 return KPortMode (it.key());
383 }
384
385 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
386 {
387 QULongStringHash::const_iterator it =
388 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
389 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
390 s.toLatin1().constData()));
391 return KUSBDeviceFilterAction (it.key());
392 }
393
394 QString toString (KDeviceType t) const
395 {
396 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
397 return mDeviceTypes.value (t);
398 }
399
400 KDeviceType toDeviceType (const QString &s) const
401 {
402 QULongStringHash::const_iterator it =
403 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
404 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
405 s.toLatin1().constData()));
406 return KDeviceType (it.key());
407 }
408
409 QStringList deviceTypeStrings() const;
410
411 QString toString (KAudioDriverType t) const
412 {
413 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
414 return mAudioDriverTypes.value (t);
415 }
416
417 KAudioDriverType toAudioDriverType (const QString &s) const
418 {
419 QULongStringHash::const_iterator it =
420 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
421 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
422 s.toLatin1().constData()));
423 return KAudioDriverType (it.key());
424 }
425
426 QString toString (KAudioControllerType t) const
427 {
428 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
429 return mAudioControllerTypes.value (t);
430 }
431
432 KAudioControllerType toAudioControllerType (const QString &s) const
433 {
434 QULongStringHash::const_iterator it =
435 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
436 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
437 s.toLatin1().constData()));
438 return KAudioControllerType (it.key());
439 }
440
441 QString toString (KNetworkAdapterType t) const
442 {
443 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
444 return mNetworkAdapterTypes.value (t);
445 }
446
447 KNetworkAdapterType toNetworkAdapterType (const QString &s) const
448 {
449 QULongStringHash::const_iterator it =
450 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
451 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
452 s.toLatin1().constData()));
453 return KNetworkAdapterType (it.key());
454 }
455
456 QString toString (KNetworkAttachmentType t) const
457 {
458 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
459 return mNetworkAttachmentTypes.value (t);
460 }
461
462 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
463 {
464 QULongStringHash::const_iterator it =
465 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
466 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
467 s.toLatin1().constData()));
468 return KNetworkAttachmentType (it.key());
469 }
470
471 QString toString (KNATProtocol t) const
472 {
473 AssertMsg (!mNATProtocolTypes.value (t).isNull(), ("No text for %d", t));
474 return mNATProtocolTypes.value (t);
475 }
476
477 KNATProtocol toNATProtocolType (const QString &s) const
478 {
479 QULongStringHash::const_iterator it =
480 qFind (mNATProtocolTypes.begin(), mNATProtocolTypes.end(), s);
481 AssertMsg (it != mNATProtocolTypes.end(), ("No value for {%s}",
482 s.toLatin1().constData()));
483 return KNATProtocol (it.key());
484 }
485
486 QString toString (KUSBDeviceState aState) const
487 {
488 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
489 return mUSBDeviceStates.value (aState);
490 }
491
492 QStringList COMPortNames() const;
493 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
494 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
495
496 QStringList LPTPortNames() const;
497 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
498 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
499
500 QPixmap snapshotIcon (bool online) const
501 {
502 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
503 }
504
505 QPixmap warningIcon() const { return mWarningIcon; }
506 QPixmap errorIcon() const { return mErrorIcon; }
507
508 /* details generators */
509
510 QString details (const CMedium &aHD, bool aPredictDiff);
511
512 QString details (const CUSBDevice &aDevice) const;
513 QString toolTip (const CUSBDevice &aDevice) const;
514 QString toolTip (const CUSBDeviceFilter &aFilter) const;
515
516 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
517
518 QString platformInfo();
519
520 /* VirtualBox helpers */
521
522#if defined(Q_WS_X11) && !defined(VBOX_OSE)
523 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
524 bool showVirtualBoxLicense();
525#endif
526
527 CSession openSession(const QString &aId, bool aExisting = false);
528
529 /** Shortcut to openSession (aId, true). */
530 CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
531
532 bool startMachine(const QString &strId);
533
534 void startEnumeratingMedia();
535
536 /**
537 * Returns a list of all currently registered media. This list is used to
538 * globally track the accessibility state of all media on a dedicated thread.
539 *
540 * Note that the media list is initially empty (i.e. before the enumeration
541 * process is started for the first time using #startEnumeratingMedia()).
542 * See #startEnumeratingMedia() for more information about how meida are
543 * sorted in the returned list.
544 */
545 const VBoxMediaList &currentMediaList() const { return mMediaList; }
546
547 /** Returns true if the media enumeration is in progress. */
548 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
549
550 void addMedium (const VBoxMedium &);
551 void updateMedium (const VBoxMedium &);
552 void removeMedium (VBoxDefs::MediumType, const QString &);
553
554 bool findMedium (const CMedium &, VBoxMedium &) const;
555 VBoxMedium findMedium (const QString &aMediumId) const;
556
557 /** Compact version of #findMediumTo(). Asserts if not found. */
558 VBoxMedium getMedium (const CMedium &aObj) const
559 {
560 VBoxMedium medium;
561 if (!findMedium (aObj, medium))
562 AssertFailed();
563 return medium;
564 }
565
566 /* Returns the number of current running Fe/Qt4 main windows. */
567 int mainWindowCount();
568
569 /* various helpers */
570
571 QString languageName() const;
572 QString languageCountry() const;
573 QString languageNameEnglish() const;
574 QString languageCountryEnglish() const;
575 QString languageTranslators() const;
576
577 void retranslateUi();
578
579 /** @internal made public for internal purposes */
580 void cleanup();
581
582 /* public static stuff */
583
584 static bool isDOSType (const QString &aOSTypeId);
585
586 static QString languageId();
587 static void loadLanguage (const QString &aLangId = QString::null);
588 QString helpFile() const;
589
590 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
591
592 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
593 bool aCanResize = true);
594 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
595 bool aCanResize = true);
596 static QRegion flip (const QRegion &aRegion);
597
598 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
599 bool aCanResize = true);
600
601 static QChar decimalSep();
602 static QString sizeRegexp();
603
604 static quint64 parseSize (const QString &);
605 static QString formatSize (quint64 aSize, uint aDecimal = 2,
606 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
607
608 static quint64 requiredVideoMemory (CMachine *aMachine = 0, int cMonitors = 1);
609
610 static QString locationForHTML (const QString &aFileName);
611
612 static QString highlight (const QString &aStr, bool aToolTip = false);
613
614 static QString replaceHtmlEntities(QString strText);
615 static QString emphasize (const QString &aStr);
616
617 static QString systemLanguageId();
618
619 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
620
621 static QString removeAccelMark (const QString &aText);
622
623 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
624 static QString extractKeyFromActionText (const QString &aText);
625
626 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
627
628 static QWidget *findWidget (QWidget *aParent, const char *aName,
629 const char *aClassName = NULL,
630 bool aRecursive = false);
631
632 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
633 static QList <QPair <QString, QString> > HDDBackends();
634 static QList <QPair <QString, QString> > DVDBackends();
635 static QList <QPair <QString, QString> > FloppyBackends();
636
637 /* Qt 4.2.0 support function */
638 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
639 {
640#if QT_VERSION < 0x040300
641 /* Deprecated since > 4.2 */
642 aLayout->setMargin (aMargin);
643#else
644 /* New since > 4.2 */
645 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
646#endif
647 }
648
649 static QString documentsPath();
650
651#ifdef VBOX_WITH_VIDEOHWACCEL
652 static bool isAcceleration2DVideoAvailable();
653
654 /** additional video memory required for the best 2D support performance
655 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
656 static quint64 required2DOffscreenVideoMemory();
657#endif
658
659#ifdef VBOX_WITH_CRHGSMI
660 static quint64 required3DWddmOffscreenVideoMemory(CMachine *aMachine = 0, int cMonitors = 1);
661#endif
662
663#ifdef Q_WS_MAC
664 bool isSheetWindowsAllowed(QWidget *pParent) const;
665#endif /* Q_WS_MAC */
666
667signals:
668
669 /**
670 * Emitted at the beginning of the enumeration process started by
671 * #startEnumeratingMedia().
672 */
673 void mediumEnumStarted();
674
675 /**
676 * Emitted when a new medium item from the list has updated its
677 * accessibility state.
678 */
679 void mediumEnumerated (const VBoxMedium &aMedum);
680
681 /**
682 * Emitted at the end of the enumeration process started by
683 * #startEnumeratingMedia(). The @a aList argument is passed for
684 * convenience, it is exactly the same as returned by #currentMediaList().
685 */
686 void mediumEnumFinished (const VBoxMediaList &aList);
687
688 /** Emitted when a new media is added using #addMedia(). */
689 void mediumAdded (const VBoxMedium &);
690
691 /** Emitted when the media is updated using #updateMedia(). */
692 void mediumUpdated (const VBoxMedium &);
693
694 /** Emitted when the media is removed using #removeMedia(). */
695 void mediumRemoved (VBoxDefs::MediumType, const QString &);
696
697#ifdef VBOX_GUI_WITH_SYSTRAY
698 void sigTrayIconShow(bool fEnabled);
699#endif
700
701public slots:
702
703 bool openURL (const QString &aURL);
704
705 void showRegistrationDialog (bool aForce = true);
706 void showUpdateDialog (bool aForce = true);
707 void perDayNewVersionNotifier();
708 void sltGUILanguageChange(QString strLang);
709
710protected:
711
712 bool event (QEvent *e);
713 bool eventFilter (QObject *, QEvent *);
714
715private:
716
717 VBoxGlobal();
718 ~VBoxGlobal();
719
720 void init();
721#ifdef VBOX_WITH_DEBUGGER_GUI
722 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
723 void setDebuggerVar(int *piDbgCfgVar, bool fState);
724 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
725#endif
726
727 bool mValid;
728
729 CVirtualBox mVBox;
730
731 VBoxGlobalSettings gset;
732
733 VBoxSelectorWnd *mSelectorWnd;
734 UIMachine *m_pVirtualMachine;
735 QWidget* mMainWindow;
736
737#ifdef VBOX_WITH_REGISTRATION
738 UIRegistrationWzd *mRegDlg;
739#endif
740 VBoxUpdateDlg *mUpdDlg;
741
742 QString vmUuid;
743
744#ifdef VBOX_GUI_WITH_SYSTRAY
745 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
746 bool mIncreasedWindowCounter : 1;
747#endif
748
749 /** Whether to show error message boxes for VM start errors. */
750 bool mShowStartVMErrors;
751
752 QThread *mMediaEnumThread;
753 VBoxMediaList mMediaList;
754
755 VBoxDefs::RenderMode vm_render_mode;
756 const char * vm_render_mode_str;
757 bool mIsKWinManaged;
758
759#ifdef VBOX_WITH_DEBUGGER_GUI
760 /** Whether the debugger should be accessible or not.
761 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
762 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
763 int mDbgEnabled;
764 /** Whether to show the debugger automatically with the console.
765 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
766 int mDbgAutoShow;
767 /** Whether to show the command line window when mDbgAutoShow is set. */
768 int mDbgAutoShowCommandLine;
769 /** Whether to show the statistics window when mDbgAutoShow is set. */
770 int mDbgAutoShowStatistics;
771 /** VBoxDbg module handle. */
772 RTLDRMOD mhVBoxDbg;
773
774 /** Whether to start the VM in paused state or not. */
775 bool mStartPaused;
776#endif
777
778#if defined (Q_WS_WIN32)
779 DWORD dwHTMLHelpCookie;
780#endif
781
782 QString mVerString;
783 QString mBrandingConfig;
784
785 QList <QString> mFamilyIDs;
786 QList <QList <CGuestOSType> > mTypes;
787 QHash <QString, QPixmap *> mOsTypeIcons;
788
789 QHash <ulong, QPixmap *> mVMStateIcons;
790 QHash <ulong, QColor *> mVMStateColors;
791
792 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
793
794 QULongStringHash mMachineStates;
795 QULongStringHash mSessionStates;
796 QULongStringHash mDeviceTypes;
797
798 QULongStringHash mStorageBuses;
799 QLongStringHash mStorageBusChannels;
800 QLongStringHash mStorageBusDevices;
801 QULongStringHash mSlotTemplates;
802
803 QULongStringHash mDiskTypes;
804 QString mDiskTypes_Differencing;
805
806 QULongStringHash mAuthTypes;
807 QULongStringHash mPortModeTypes;
808 QULongStringHash mUSBFilterActionTypes;
809 QULongStringHash mAudioDriverTypes;
810 QULongStringHash mAudioControllerTypes;
811 QULongStringHash mNetworkAdapterTypes;
812 QULongStringHash mNetworkAttachmentTypes;
813 QULongStringHash mNATProtocolTypes;
814 QULongStringHash mClipboardTypes;
815 QULongStringHash mStorageControllerTypes;
816 QULongStringHash mUSBDeviceStates;
817
818 QString mUserDefinedPortName;
819
820 QPixmap mWarningIcon, mErrorIcon;
821
822 friend VBoxGlobal &vboxGlobal();
823};
824
825inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
826
827// Helper classes
828////////////////////////////////////////////////////////////////////////////////
829
830/* Generic asynchronous event.
831 * This abstract class is intended to provide a convenient way
832 * to execute code on the main GUI thread asynchronously to the calling party.
833 * This is done by putting necessary actions to the handle() function
834 * in a subclass and then posting an instance of the subclass using post().
835 * The instance must be allocated on the heap and will be automatically deleted after processing. */
836class VBoxAsyncEvent : public QEvent
837{
838public:
839
840 /* VBoxAsyncEvent constructor: */
841 VBoxAsyncEvent(uint uDelay = 0);
842
843 /* Worker function. Gets executed on the GUI thread when
844 * the posted event is processed by the main event loop. */
845 virtual void handle() = 0;
846
847 /* Posts this event to the main event loop. The caller loses ownership of
848 * this object after this method returns and must not delete the object. */
849 void post();
850
851 /* Returns delay for this event: */
852 uint delay() const;
853
854private:
855
856 uint m_uDelay;
857};
858
859/* Asynchronous event poster.
860 * This class is used to post async event into VBoxGlobal event handler
861 * taking into account delay set during async event creation procedure. */
862class UIAsyncEventPoster : public QObject
863{
864 Q_OBJECT;
865
866public:
867
868 /* Async event poster creator: */
869 static void post(VBoxAsyncEvent *pAsyncEvent);
870
871protected:
872
873 /* Constructor/destructor: */
874 UIAsyncEventPoster(VBoxAsyncEvent *pAsyncEvent);
875 ~UIAsyncEventPoster();
876
877private slots:
878
879 /* Async event poster: */
880 void sltPostAsyncEvent();
881
882private:
883
884 static UIAsyncEventPoster *m_spInstance;
885 VBoxAsyncEvent *m_pAsyncEvent;
886};
887
888/**
889 * USB Popup Menu class.
890 * This class provides the list of USB devices attached to the host.
891 */
892class VBoxUSBMenu : public QMenu
893{
894 Q_OBJECT
895
896public:
897
898 VBoxUSBMenu (QWidget *);
899
900 const CUSBDevice& getUSB (QAction *aAction);
901
902 void setConsole (const CConsole &);
903
904private slots:
905
906 void processAboutToShow();
907
908private:
909 bool event(QEvent *aEvent);
910
911 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
912 CConsole mConsole;
913};
914
915/**
916 * Enable/Disable Menu class.
917 * This class provides enable/disable menu items.
918 */
919class VBoxSwitchMenu : public QMenu
920{
921 Q_OBJECT
922
923public:
924
925 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
926
927 void setToolTip (const QString &);
928
929private slots:
930
931 void processAboutToShow();
932
933private:
934
935 QAction *mAction;
936 bool mInverted;
937};
938
939#endif /* __VBoxGlobal_h__ */
940
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette