VirtualBox

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

Last change on this file since 31759 was 31759, checked in by vboxsync, 15 years ago

FE/Qt: 3601: While the warning about the wrong color depth is shown, all other updates should be performed (x11 host, 1st try).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.9 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() const { return mDbgEnabled; }
169 bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
170 bool isDebuggerAutoShowCommandLineEnabled() const { return mDbgAutoShowCommandLine; }
171 bool isDebuggerAutoShowStatisticsEnabled() const { return mDbgAutoShowStatistics; }
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 (KVRDPAuthType t) const
320 {
321 AssertMsg (!mVRDPAuthTypes.value (t).isNull(), ("No text for %d", t));
322 return mVRDPAuthTypes.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 KVRDPAuthType toVRDPAuthType (const QString &s) const
368 {
369 QULongStringHash::const_iterator it =
370 qFind (mVRDPAuthTypes.begin(), mVRDPAuthTypes.end(), s);
371 AssertMsg (it != mVRDPAuthTypes.end(), ("No value for {%s}",
372 s.toLatin1().constData()));
373 return KVRDPAuthType (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 accessiblity 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> > HDDBackends();
633
634 /* Qt 4.2.0 support function */
635 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
636 {
637#if QT_VERSION < 0x040300
638 /* Deprecated since > 4.2 */
639 aLayout->setMargin (aMargin);
640#else
641 /* New since > 4.2 */
642 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
643#endif
644 }
645
646 static QString documentsPath();
647
648#ifdef VBOX_WITH_VIDEOHWACCEL
649 static bool isAcceleration2DVideoAvailable();
650
651 /** additional video memory required for the best 2D support performance
652 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
653 static quint64 required2DOffscreenVideoMemory();
654#endif
655
656#ifdef Q_WS_MAC
657 bool isSheetWindowsAllowed(QWidget *pParent) const;
658#endif /* Q_WS_MAC */
659
660signals:
661
662 /**
663 * Emitted at the beginning of the enumeration process started by
664 * #startEnumeratingMedia().
665 */
666 void mediumEnumStarted();
667
668 /**
669 * Emitted when a new medium item from the list has updated its
670 * accessibility state.
671 */
672 void mediumEnumerated (const VBoxMedium &aMedum);
673
674 /**
675 * Emitted at the end of the enumeration process started by
676 * #startEnumeratingMedia(). The @a aList argument is passed for
677 * convenience, it is exactly the same as returned by #currentMediaList().
678 */
679 void mediumEnumFinished (const VBoxMediaList &aList);
680
681 /** Emitted when a new media is added using #addMedia(). */
682 void mediumAdded (const VBoxMedium &);
683
684 /** Emitted when the media is updated using #updateMedia(). */
685 void mediumUpdated (const VBoxMedium &);
686
687 /** Emitted when the media is removed using #removeMedia(). */
688 void mediumRemoved (VBoxDefs::MediumType, const QString &);
689
690#ifdef VBOX_GUI_WITH_SYSTRAY
691 void sigTrayIconShow(bool fEnabled);
692#endif
693
694public slots:
695
696 bool openURL (const QString &aURL);
697
698 void showRegistrationDialog (bool aForce = true);
699 void showUpdateDialog (bool aForce = true);
700 void perDayNewVersionNotifier();
701 void sltGUILanguageChange(QString strLang);
702
703protected:
704
705 bool event (QEvent *e);
706 bool eventFilter (QObject *, QEvent *);
707
708private:
709
710 VBoxGlobal();
711 ~VBoxGlobal();
712
713 void init();
714
715 bool mValid;
716
717 CVirtualBox mVBox;
718
719 VBoxGlobalSettings gset;
720
721 VBoxSelectorWnd *mSelectorWnd;
722 UIMachine *m_pVirtualMachine;
723 QWidget* mMainWindow;
724
725#ifdef VBOX_WITH_REGISTRATION
726 UIRegistrationWzd *mRegDlg;
727#endif
728 VBoxUpdateDlg *mUpdDlg;
729
730 QString vmUuid;
731
732#ifdef VBOX_GUI_WITH_SYSTRAY
733 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
734 bool mIncreasedWindowCounter : 1;
735#endif
736
737 /** Whether to show error message boxes for VM start errors. */
738 bool mShowStartVMErrors;
739
740 QThread *mMediaEnumThread;
741 VBoxMediaList mMediaList;
742
743 VBoxDefs::RenderMode vm_render_mode;
744 const char * vm_render_mode_str;
745 bool mIsKWinManaged;
746
747#ifdef VBOX_WITH_DEBUGGER_GUI
748 /** Whether the debugger should be accessible or not.
749 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
750 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
751 bool mDbgEnabled;
752 /** Whether to show the debugger automatically with the console.
753 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
754 bool mDbgAutoShow;
755 /** Whether to show the command line window when mDbgAutoShow is set. */
756 bool mDbgAutoShowCommandLine;
757 /** Whether to show the statistics window when mDbgAutoShow is set. */
758 bool mDbgAutoShowStatistics;
759 /** VBoxDbg module handle. */
760 RTLDRMOD mhVBoxDbg;
761
762 /** Whether to start the VM in paused state or not. */
763 bool mStartPaused;
764#endif
765
766#if defined (Q_WS_WIN32)
767 DWORD dwHTMLHelpCookie;
768#endif
769
770 QString mVerString;
771 QString mBrandingConfig;
772
773 QList <QString> mFamilyIDs;
774 QList <QList <CGuestOSType> > mTypes;
775 QHash <QString, QPixmap *> mOsTypeIcons;
776
777 QHash <ulong, QPixmap *> mVMStateIcons;
778 QHash <ulong, QColor *> mVMStateColors;
779
780 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
781
782 QULongStringHash mMachineStates;
783 QULongStringHash mSessionStates;
784 QULongStringHash mDeviceTypes;
785
786 QULongStringHash mStorageBuses;
787 QLongStringHash mStorageBusChannels;
788 QLongStringHash mStorageBusDevices;
789 QULongStringHash mSlotTemplates;
790
791 QULongStringHash mDiskTypes;
792 QString mDiskTypes_Differencing;
793
794 QULongStringHash mVRDPAuthTypes;
795 QULongStringHash mPortModeTypes;
796 QULongStringHash mUSBFilterActionTypes;
797 QULongStringHash mAudioDriverTypes;
798 QULongStringHash mAudioControllerTypes;
799 QULongStringHash mNetworkAdapterTypes;
800 QULongStringHash mNetworkAttachmentTypes;
801 QULongStringHash mNATProtocolTypes;
802 QULongStringHash mClipboardTypes;
803 QULongStringHash mStorageControllerTypes;
804 QULongStringHash mUSBDeviceStates;
805
806 QString mUserDefinedPortName;
807
808 QPixmap mWarningIcon, mErrorIcon;
809
810 friend VBoxGlobal &vboxGlobal();
811};
812
813inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
814
815// Helper classes
816////////////////////////////////////////////////////////////////////////////////
817
818/* Generic asyncronous event.
819 * This abstract class is intended to provide a conveinent way
820 * to execute code on the main GUI thread asynchronously to the calling party.
821 * This is done by putting necessary actions to the handle() function
822 * in a subclass and then posting an instance of the subclass using post().
823 * The instance must be allocated on the heap and will be automatically deleted after processing. */
824class VBoxAsyncEvent : public QEvent
825{
826public:
827
828 /* VBoxAsyncEvent constructor: */
829 VBoxAsyncEvent(uint uDelay = 0);
830
831 /* Worker function. Gets executed on the GUI thread when
832 * the posted event is processed by the main event loop. */
833 virtual void handle() = 0;
834
835 /* Posts this event to the main event loop. The caller loses ownership of
836 * this object after this method returns and must not delete the object. */
837 void post();
838
839 /* Returns delay for this event: */
840 uint delay() const;
841
842private:
843
844 uint m_uDelay;
845};
846
847/* Asyncronous event poster.
848 * This class is used to post async event into VBoxGlobal event handler
849 * taking into account delay set during async event creation procedure. */
850class UIAsyncEventPoster : public QObject
851{
852 Q_OBJECT;
853
854public:
855
856 /* Async event poster creator: */
857 static void post(VBoxAsyncEvent *pAsyncEvent);
858
859protected:
860
861 /* Constructor/destructor: */
862 UIAsyncEventPoster(VBoxAsyncEvent *pAsyncEvent);
863 ~UIAsyncEventPoster();
864
865private slots:
866
867 /* Async event poster: */
868 void sltPostAsyncEvent();
869
870private:
871
872 static UIAsyncEventPoster *m_spInstance;
873 VBoxAsyncEvent *m_pAsyncEvent;
874};
875
876/**
877 * USB Popup Menu class.
878 * This class provides the list of USB devices attached to the host.
879 */
880class VBoxUSBMenu : public QMenu
881{
882 Q_OBJECT
883
884public:
885
886 VBoxUSBMenu (QWidget *);
887
888 const CUSBDevice& getUSB (QAction *aAction);
889
890 void setConsole (const CConsole &);
891
892private slots:
893
894 void processAboutToShow();
895
896private:
897 bool event(QEvent *aEvent);
898
899 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
900 CConsole mConsole;
901};
902
903/**
904 * Enable/Disable Menu class.
905 * This class provides enable/disable menu items.
906 */
907class VBoxSwitchMenu : public QMenu
908{
909 Q_OBJECT
910
911public:
912
913 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
914
915 void setToolTip (const QString &);
916
917private slots:
918
919 void processAboutToShow();
920
921private:
922
923 QAction *mAction;
924 bool mInverted;
925};
926
927#endif /* __VBoxGlobal_h__ */
928
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