VirtualBox

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

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

FE/Qt: Get rid of Virtual Media Manager links in Machine storage settings, New VM wizard, working VM window, First Run wizard.

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