VirtualBox

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

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

FE/Qt: Async settings mechanism. Global and Machine settings reworked to use cache loaded and saved in parallel thread.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.0 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 QString toString (KChipsetType t) const
493 {
494 AssertMsg (!mChipsetTypes.value (t).isNull(), ("No text for %d", t));
495 return mChipsetTypes.value (t);
496 }
497
498 KChipsetType toChipsetType (const QString &s) const
499 {
500 QULongStringHash::const_iterator it =
501 qFind (mChipsetTypes.begin(), mChipsetTypes.end(), s);
502 AssertMsg (it != mChipsetTypes.end(), ("No value for {%s}",
503 s.toLatin1().constData()));
504 return KChipsetType (it.key());
505 }
506
507 QStringList COMPortNames() const;
508 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
509 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
510
511 QStringList LPTPortNames() const;
512 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
513 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
514
515 QPixmap snapshotIcon (bool online) const
516 {
517 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
518 }
519
520 QPixmap warningIcon() const { return mWarningIcon; }
521 QPixmap errorIcon() const { return mErrorIcon; }
522
523 /* details generators */
524
525 QString details (const CMedium &aHD, bool aPredictDiff);
526
527 QString details (const CUSBDevice &aDevice) const;
528 QString toolTip (const CUSBDevice &aDevice) const;
529 QString toolTip (const CUSBDeviceFilter &aFilter) const;
530
531 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
532
533 QString platformInfo();
534
535 /* VirtualBox helpers */
536
537#if defined(Q_WS_X11) && !defined(VBOX_OSE)
538 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
539 bool showVirtualBoxLicense();
540#endif
541
542 CSession openSession(const QString &aId, bool aExisting = false);
543
544 /** Shortcut to openSession (aId, true). */
545 CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
546
547 bool startMachine(const QString &strId);
548
549 void startEnumeratingMedia();
550
551 /**
552 * Returns a list of all currently registered media. This list is used to
553 * globally track the accessibility state of all media on a dedicated thread.
554 *
555 * Note that the media list is initially empty (i.e. before the enumeration
556 * process is started for the first time using #startEnumeratingMedia()).
557 * See #startEnumeratingMedia() for more information about how meida are
558 * sorted in the returned list.
559 */
560 const VBoxMediaList &currentMediaList() const { return mMediaList; }
561
562 /** Returns true if the media enumeration is in progress. */
563 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
564
565 void addMedium (const VBoxMedium &);
566 void updateMedium (const VBoxMedium &);
567 void removeMedium (VBoxDefs::MediumType, const QString &);
568
569 bool findMedium (const CMedium &, VBoxMedium &) const;
570 VBoxMedium findMedium (const QString &aMediumId) const;
571
572 /** Compact version of #findMediumTo(). Asserts if not found. */
573 VBoxMedium getMedium (const CMedium &aObj) const
574 {
575 VBoxMedium medium;
576 if (!findMedium (aObj, medium))
577 AssertFailed();
578 return medium;
579 }
580
581 /* Returns the number of current running Fe/Qt4 main windows. */
582 int mainWindowCount();
583
584 /* various helpers */
585
586 QString languageName() const;
587 QString languageCountry() const;
588 QString languageNameEnglish() const;
589 QString languageCountryEnglish() const;
590 QString languageTranslators() const;
591
592 void retranslateUi();
593
594 /** @internal made public for internal purposes */
595 void cleanup();
596
597 /* public static stuff */
598
599 static bool isDOSType (const QString &aOSTypeId);
600
601 static QString languageId();
602 static void loadLanguage (const QString &aLangId = QString::null);
603 QString helpFile() const;
604
605 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
606
607 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
608 bool aCanResize = true);
609 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
610 bool aCanResize = true);
611 static QRegion flip (const QRegion &aRegion);
612
613 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
614 bool aCanResize = true);
615
616 static QChar decimalSep();
617 static QString sizeRegexp();
618
619 static quint64 parseSize (const QString &);
620 static QString formatSize (quint64 aSize, uint aDecimal = 2,
621 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
622
623 static quint64 requiredVideoMemory (CMachine *aMachine = 0, int cMonitors = 1);
624
625 static QString locationForHTML (const QString &aFileName);
626
627 static QString highlight (const QString &aStr, bool aToolTip = false);
628
629 static QString replaceHtmlEntities(QString strText);
630 static QString emphasize (const QString &aStr);
631
632 static QString systemLanguageId();
633
634 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
635
636 static QString removeAccelMark (const QString &aText);
637
638 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
639 static QString extractKeyFromActionText (const QString &aText);
640
641 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
642
643 static QWidget *findWidget (QWidget *aParent, const char *aName,
644 const char *aClassName = NULL,
645 bool aRecursive = false);
646
647 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
648 static QList <QPair <QString, QString> > HDDBackends();
649 static QList <QPair <QString, QString> > DVDBackends();
650 static QList <QPair <QString, QString> > FloppyBackends();
651
652 /* Qt 4.2.0 support function */
653 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
654 {
655#if QT_VERSION < 0x040300
656 /* Deprecated since > 4.2 */
657 aLayout->setMargin (aMargin);
658#else
659 /* New since > 4.2 */
660 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
661#endif
662 }
663
664 static QString documentsPath();
665
666#ifdef VBOX_WITH_VIDEOHWACCEL
667 static bool isAcceleration2DVideoAvailable();
668
669 /** additional video memory required for the best 2D support performance
670 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
671 static quint64 required2DOffscreenVideoMemory();
672#endif
673
674#ifdef VBOX_WITH_CRHGSMI
675 static quint64 required3DWddmOffscreenVideoMemory(CMachine *aMachine = 0, int cMonitors = 1);
676#endif
677
678#ifdef Q_WS_MAC
679 bool isSheetWindowsAllowed(QWidget *pParent) const;
680#endif /* Q_WS_MAC */
681
682signals:
683
684 /**
685 * Emitted at the beginning of the enumeration process started by
686 * #startEnumeratingMedia().
687 */
688 void mediumEnumStarted();
689
690 /**
691 * Emitted when a new medium item from the list has updated its
692 * accessibility state.
693 */
694 void mediumEnumerated (const VBoxMedium &aMedum);
695
696 /**
697 * Emitted at the end of the enumeration process started by
698 * #startEnumeratingMedia(). The @a aList argument is passed for
699 * convenience, it is exactly the same as returned by #currentMediaList().
700 */
701 void mediumEnumFinished (const VBoxMediaList &aList);
702
703 /** Emitted when a new media is added using #addMedia(). */
704 void mediumAdded (const VBoxMedium &);
705
706 /** Emitted when the media is updated using #updateMedia(). */
707 void mediumUpdated (const VBoxMedium &);
708
709 /** Emitted when the media is removed using #removeMedia(). */
710 void mediumRemoved (VBoxDefs::MediumType, const QString &);
711
712#ifdef VBOX_GUI_WITH_SYSTRAY
713 void sigTrayIconShow(bool fEnabled);
714#endif
715
716public slots:
717
718 bool openURL (const QString &aURL);
719
720 void showRegistrationDialog (bool aForce = true);
721 void showUpdateDialog (bool aForce = true);
722 void perDayNewVersionNotifier();
723 void sltGUILanguageChange(QString strLang);
724
725protected:
726
727 bool event (QEvent *e);
728 bool eventFilter (QObject *, QEvent *);
729
730private:
731
732 VBoxGlobal();
733 ~VBoxGlobal();
734
735 void init();
736#ifdef VBOX_WITH_DEBUGGER_GUI
737 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
738 void setDebuggerVar(int *piDbgCfgVar, bool fState);
739 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
740#endif
741
742 bool mValid;
743
744 CVirtualBox mVBox;
745
746 VBoxGlobalSettings gset;
747
748 VBoxSelectorWnd *mSelectorWnd;
749 UIMachine *m_pVirtualMachine;
750 QWidget* mMainWindow;
751
752#ifdef VBOX_WITH_REGISTRATION
753 UIRegistrationWzd *mRegDlg;
754#endif
755 VBoxUpdateDlg *mUpdDlg;
756
757 QString vmUuid;
758
759#ifdef VBOX_GUI_WITH_SYSTRAY
760 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
761 bool mIncreasedWindowCounter : 1;
762#endif
763
764 /** Whether to show error message boxes for VM start errors. */
765 bool mShowStartVMErrors;
766
767 QThread *mMediaEnumThread;
768 VBoxMediaList mMediaList;
769
770 VBoxDefs::RenderMode vm_render_mode;
771 const char * vm_render_mode_str;
772 bool mIsKWinManaged;
773
774#ifdef VBOX_WITH_DEBUGGER_GUI
775 /** Whether the debugger should be accessible or not.
776 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
777 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
778 int mDbgEnabled;
779 /** Whether to show the debugger automatically with the console.
780 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
781 int mDbgAutoShow;
782 /** Whether to show the command line window when mDbgAutoShow is set. */
783 int mDbgAutoShowCommandLine;
784 /** Whether to show the statistics window when mDbgAutoShow is set. */
785 int mDbgAutoShowStatistics;
786 /** VBoxDbg module handle. */
787 RTLDRMOD mhVBoxDbg;
788
789 /** Whether to start the VM in paused state or not. */
790 bool mStartPaused;
791#endif
792
793#if defined (Q_WS_WIN32)
794 DWORD dwHTMLHelpCookie;
795#endif
796
797 QString mVerString;
798 QString mBrandingConfig;
799
800 QList <QString> mFamilyIDs;
801 QList <QList <CGuestOSType> > mTypes;
802 QHash <QString, QPixmap *> mOsTypeIcons;
803
804 QHash <ulong, QPixmap *> mVMStateIcons;
805 QHash <ulong, QColor *> mVMStateColors;
806
807 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
808
809 QULongStringHash mMachineStates;
810 QULongStringHash mSessionStates;
811 QULongStringHash mDeviceTypes;
812
813 QULongStringHash mStorageBuses;
814 QLongStringHash mStorageBusChannels;
815 QLongStringHash mStorageBusDevices;
816 QULongStringHash mSlotTemplates;
817
818 QULongStringHash mDiskTypes;
819 QString mDiskTypes_Differencing;
820
821 QULongStringHash mAuthTypes;
822 QULongStringHash mPortModeTypes;
823 QULongStringHash mUSBFilterActionTypes;
824 QULongStringHash mAudioDriverTypes;
825 QULongStringHash mAudioControllerTypes;
826 QULongStringHash mNetworkAdapterTypes;
827 QULongStringHash mNetworkAttachmentTypes;
828 QULongStringHash mNATProtocolTypes;
829 QULongStringHash mClipboardTypes;
830 QULongStringHash mStorageControllerTypes;
831 QULongStringHash mUSBDeviceStates;
832 QULongStringHash mChipsetTypes;
833
834 QString mUserDefinedPortName;
835
836 QPixmap mWarningIcon, mErrorIcon;
837
838 friend VBoxGlobal &vboxGlobal();
839};
840
841inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
842
843// Helper classes
844////////////////////////////////////////////////////////////////////////////////
845
846/* Generic asynchronous event.
847 * This abstract class is intended to provide a convenient way
848 * to execute code on the main GUI thread asynchronously to the calling party.
849 * This is done by putting necessary actions to the handle() function
850 * in a subclass and then posting an instance of the subclass using post().
851 * The instance must be allocated on the heap and will be automatically deleted after processing. */
852class VBoxAsyncEvent : public QEvent
853{
854public:
855
856 /* VBoxAsyncEvent constructor: */
857 VBoxAsyncEvent(uint uDelay = 0);
858
859 /* Worker function. Gets executed on the GUI thread when
860 * the posted event is processed by the main event loop. */
861 virtual void handle() = 0;
862
863 /* Posts this event to the main event loop. The caller loses ownership of
864 * this object after this method returns and must not delete the object. */
865 void post();
866
867 /* Returns delay for this event: */
868 uint delay() const;
869
870private:
871
872 uint m_uDelay;
873};
874
875/* Asynchronous event poster.
876 * This class is used to post async event into VBoxGlobal event handler
877 * taking into account delay set during async event creation procedure. */
878class UIAsyncEventPoster : public QObject
879{
880 Q_OBJECT;
881
882public:
883
884 /* Async event poster creator: */
885 static void post(VBoxAsyncEvent *pAsyncEvent);
886
887protected:
888
889 /* Constructor/destructor: */
890 UIAsyncEventPoster(VBoxAsyncEvent *pAsyncEvent);
891 ~UIAsyncEventPoster();
892
893private slots:
894
895 /* Async event poster: */
896 void sltPostAsyncEvent();
897
898private:
899
900 static UIAsyncEventPoster *m_spInstance;
901 VBoxAsyncEvent *m_pAsyncEvent;
902};
903
904/**
905 * USB Popup Menu class.
906 * This class provides the list of USB devices attached to the host.
907 */
908class VBoxUSBMenu : public QMenu
909{
910 Q_OBJECT
911
912public:
913
914 VBoxUSBMenu (QWidget *);
915
916 const CUSBDevice& getUSB (QAction *aAction);
917
918 void setConsole (const CConsole &);
919
920private slots:
921
922 void processAboutToShow();
923
924private:
925 bool event(QEvent *aEvent);
926
927 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
928 CConsole mConsole;
929};
930
931/**
932 * Enable/Disable Menu class.
933 * This class provides enable/disable menu items.
934 */
935class VBoxSwitchMenu : public QMenu
936{
937 Q_OBJECT
938
939public:
940
941 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
942
943 void setToolTip (const QString &);
944
945private slots:
946
947 void processAboutToShow();
948
949private:
950
951 QAction *mAction;
952 bool mInverted;
953};
954
955#endif /* __VBoxGlobal_h__ */
956
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