VirtualBox

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

Last change on this file since 41689 was 41689, checked in by vboxsync, 13 years ago

FE/Qt: VBoxDefs renamed to UIDefs and reworked into namespace. Corresponding files which were using VBoxDefs updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.5 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2011 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/* Qt includes: */
23#include <QApplication>
24#include <QLayout>
25#include <QMenu>
26#include <QStyle>
27#include <QHash>
28#include <QFileIconProvider>
29
30/* GUI includes: */
31#include "UIDefs.h"
32#include "VBoxGlobalSettings.h"
33#include "UIMedium.h"
34
35/* COM includes: */
36#include "VBox/com/Guid.h"
37#include "COMEnums.h"
38#include "CHost.h"
39#include "CVirtualBox.h"
40#include "CSession.h"
41#include "CGuestOSType.h"
42
43/* Forward declarations: */
44class QAction;
45class QLabel;
46class QToolButton;
47class UIMachine;
48class CMachine;
49class CMedium;
50class CUSBDevice;
51
52struct StorageSlot
53{
54 StorageSlot() : bus (KStorageBus_Null), port (0), device (0) {}
55 StorageSlot (const StorageSlot &aOther) : bus (aOther.bus), port (aOther.port), device (aOther.device) {}
56 StorageSlot (KStorageBus aBus, LONG aPort, LONG aDevice) : bus (aBus), port (aPort), device (aDevice) {}
57 StorageSlot& operator= (const StorageSlot &aOther) { bus = aOther.bus; port = aOther.port; device = aOther.device; return *this; }
58 bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; }
59 bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; }
60 bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) ||
61 (bus == aOther.bus && port < aOther.port) ||
62 (bus == aOther.bus && port == aOther.port && device < aOther.device); }
63 bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) ||
64 (bus == aOther.bus && port > aOther.port) ||
65 (bus == aOther.bus && port == aOther.port && device > aOther.device); }
66 bool isNull() { return bus == KStorageBus_Null; }
67 KStorageBus bus; LONG port; LONG device;
68};
69Q_DECLARE_METATYPE (StorageSlot);
70
71// VBoxGlobal class
72////////////////////////////////////////////////////////////////////////////////
73
74class UISelectorWindow;
75class UIRegistrationWzd;
76class VBoxUpdateDlg;
77
78class VBoxGlobal : public QObject
79{
80 Q_OBJECT
81
82public:
83
84 typedef QHash <ulong, QString> QULongStringHash;
85
86 static VBoxGlobal &instance();
87
88 bool isValid() { return mValid; }
89
90 static QString qtRTVersionString();
91 static uint qtRTVersion();
92 static QString qtCTVersionString();
93 static uint qtCTVersion();
94
95 QString vboxVersionString() const;
96 QString vboxVersionStringNormalized() const;
97
98 QString versionString() const { return mVerString; }
99 bool isBeta() const;
100
101 CVirtualBox virtualBox() const { return mVBox; }
102 CHost host() const { return mHost; }
103
104 VBoxGlobalSettings &settings() { return gset; }
105 bool setSettings (VBoxGlobalSettings &gs);
106
107 UISelectorWindow &selectorWnd();
108
109 /* VM stuff: */
110 bool startMachine(const QString &strMachineId);
111 UIMachine* virtualMachine();
112 QWidget* vmWindow();
113
114 /* Main application window storage: */
115 void setMainWindow(QWidget *pMainWindow) { mMainWindow = pMainWindow; }
116 QWidget* mainWindow() const { return mMainWindow; }
117
118 bool is3DAvailable() const { return m3DAvailable; }
119
120#ifdef VBOX_GUI_WITH_PIDFILE
121 void createPidfile();
122 void deletePidfile();
123#endif
124
125 /* branding */
126 bool brandingIsActive (bool aForce = false);
127 QString brandingGetKey (QString aKey);
128
129 bool processArgs();
130
131 bool switchToMachine(CMachine &machine);
132 bool launchMachine(CMachine &machine, bool fHeadless = false);
133
134 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
135 bool showStartVMErrors() const { return mShowStartVMErrors; }
136#ifdef VBOX_GUI_WITH_SYSTRAY
137 bool isTrayMenu() const;
138 void setTrayMenu(bool aIsTrayMenu);
139 void trayIconShowSelector();
140 bool trayIconInstall();
141#endif
142 QString managedVMUuid() const { return vmUuid; }
143 QList<QUrl> &argUrlList() { return m_ArgUrlList; }
144
145 RenderMode vmRenderMode() const { return vm_render_mode; }
146 const char *vmRenderModeStr() const { return vm_render_mode_str; }
147 bool isKWinManaged() const { return mIsKWinManaged; }
148
149 const QRect availableGeometry(int iScreen = 0) const;
150
151 bool isPatmDisabled() const { return mDisablePatm; }
152 bool isCsamDisabled() const { return mDisableCsam; }
153 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
154 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
155
156#ifdef VBOX_WITH_DEBUGGER_GUI
157 bool isDebuggerEnabled(CMachine &aMachine);
158 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
159 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
160 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
161 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
162
163 bool isStartPausedEnabled() const { return mStartPaused; }
164#else
165 bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
166 bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
167 bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
168
169 bool isStartPausedEnabled() const { return false; }
170#endif
171
172 /* VBox enum to/from string/icon/color convertors */
173
174 QList <CGuestOSType> vmGuestOSFamilyList() const;
175 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
176 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
177 CGuestOSType vmGuestOSType (const QString &aTypeId,
178 const QString &aFamilyId = QString::null) const;
179 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
180
181 static inline QString yearsToString (uint32_t cVal)
182 {
183 return tr("%n year(s)", "", cVal);
184 }
185
186 static inline QString monthsToString (uint32_t cVal)
187 {
188 return tr("%n month(s)", "", cVal);
189 }
190
191 static inline QString daysToString (uint32_t cVal)
192 {
193 return tr("%n day(s)", "", cVal);
194 }
195
196 static inline QString hoursToString (uint32_t cVal)
197 {
198 return tr("%n hour(s)", "", cVal);
199 }
200
201 static inline QString minutesToString (uint32_t cVal)
202 {
203 return tr("%n minute(s)", "", cVal);
204 }
205
206 static inline QString secondsToString (uint32_t cVal)
207 {
208 return tr("%n second(s)", "", cVal);
209 }
210
211 QString toString (StorageSlot aSlot) const;
212 StorageSlot toStorageSlot (const QString &aSlot) const;
213
214 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
215
216 /**
217 * Similar to toString (KMediumType), but returns 'Differencing' for
218 * normal hard disks that have a parent.
219 */
220 QString mediumTypeString(const CMedium &medium) const;
221
222 QStringList COMPortNames() const;
223 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
224 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
225
226 QStringList LPTPortNames() const;
227 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
228 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
229
230 QPixmap snapshotIcon (bool online) const
231 {
232 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
233 }
234
235 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
236 {
237 for (int i = 0; i < extList.size(); ++i)
238 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
239 return true;
240 return false;
241 }
242
243 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
244 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
245
246 QPixmap warningIcon() const { return mWarningIcon; }
247 QPixmap errorIcon() const { return mErrorIcon; }
248
249 /* details generators */
250
251 QString details (const CMedium &aHD, bool aPredictDiff);
252
253 QString details (const CUSBDevice &aDevice) const;
254 QString toolTip (const CUSBDevice &aDevice) const;
255 QString toolTip (const CUSBDeviceFilter &aFilter) const;
256
257 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
258
259 /* VirtualBox helpers */
260
261#if defined(Q_WS_X11) && !defined(VBOX_OSE)
262 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
263 bool showVirtualBoxLicense();
264#endif
265
266 CSession openSession(const QString &aId, bool aExisting = false);
267
268 /** Shortcut to openSession (aId, true). */
269 CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
270
271 void startEnumeratingMedia();
272
273 void reloadProxySettings();
274
275 /**
276 * Returns a list of all currently registered media. This list is used to
277 * globally track the accessibility state of all media on a dedicated thread.
278 *
279 * Note that the media list is initially empty (i.e. before the enumeration
280 * process is started for the first time using #startEnumeratingMedia()).
281 * See #startEnumeratingMedia() for more information about how meida are
282 * sorted in the returned list.
283 */
284 const VBoxMediaList &currentMediaList() const { return mMediaList; }
285
286 /** Returns true if the media enumeration is in progress. */
287 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
288
289 void addMedium (const UIMedium &);
290 void updateMedium (const UIMedium &);
291 void removeMedium (UIMediumType, const QString &);
292
293 bool findMedium (const CMedium &, UIMedium &) const;
294 UIMedium findMedium (const QString &aMediumId) const;
295
296 /** Compact version of #findMediumTo(). Asserts if not found. */
297 UIMedium getMedium (const CMedium &aObj) const
298 {
299 UIMedium medium;
300 if (!findMedium (aObj, medium))
301 AssertFailed();
302 return medium;
303 }
304
305 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
306 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
307 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
308
309 /* Returns the number of current running Fe/Qt4 main windows. */
310 int mainWindowCount();
311
312 /* various helpers */
313
314 QString languageName() const;
315 QString languageCountry() const;
316 QString languageNameEnglish() const;
317 QString languageCountryEnglish() const;
318 QString languageTranslators() const;
319
320 void retranslateUi();
321
322 /** @internal made public for internal purposes */
323 void cleanup();
324
325 /* public static stuff */
326
327 static bool isDOSType (const QString &aOSTypeId);
328
329 static QString languageId();
330 static void loadLanguage (const QString &aLangId = QString::null);
331 QString helpFile() const;
332
333 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
334
335 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
336 bool aCanResize = true);
337 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
338 bool aCanResize = true);
339 static QRegion flip (const QRegion &aRegion);
340
341 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
342 bool aCanResize = true);
343
344 static QChar decimalSep();
345 static QString sizeRegexp();
346
347 static QString toHumanReadableList(const QStringList &list);
348
349 static quint64 parseSize (const QString &);
350 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
351
352 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
353
354 static QString locationForHTML (const QString &aFileName);
355
356 static QString highlight (const QString &aStr, bool aToolTip = false);
357
358 static QString replaceHtmlEntities(QString strText);
359 static QString emphasize (const QString &aStr);
360
361 static QString systemLanguageId();
362
363 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
364
365 static QString removeAccelMark (const QString &aText);
366
367 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
368 static QString extractKeyFromActionText (const QString &aText);
369
370 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
371
372 static QWidget *findWidget (QWidget *aParent, const char *aName,
373 const char *aClassName = NULL,
374 bool aRecursive = false);
375
376 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
377 static QList <QPair <QString, QString> > HDDBackends();
378 static QList <QPair <QString, QString> > DVDBackends();
379 static QList <QPair <QString, QString> > FloppyBackends();
380
381 /* Qt 4.2.0 support function */
382 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
383 {
384#if QT_VERSION < 0x040300
385 /* Deprecated since > 4.2 */
386 aLayout->setMargin (aMargin);
387#else
388 /* New since > 4.2 */
389 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
390#endif
391 }
392
393 static QString documentsPath();
394
395#ifdef VBOX_WITH_VIDEOHWACCEL
396 static bool isAcceleration2DVideoAvailable();
397
398 /** additional video memory required for the best 2D support performance
399 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
400 static quint64 required2DOffscreenVideoMemory();
401#endif
402
403#ifdef VBOX_WITH_CRHGSMI
404 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
405 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
406#endif /* VBOX_WITH_CRHGSMI */
407
408#ifdef Q_WS_MAC
409 bool isSheetWindowsAllowed(QWidget *pParent) const;
410#endif /* Q_WS_MAC */
411
412 /* Returns full medium-format name for the given base medium-format name: */
413 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
414
415signals:
416
417 /**
418 * Emitted at the beginning of the enumeration process started by
419 * #startEnumeratingMedia().
420 */
421 void mediumEnumStarted();
422
423 /**
424 * Emitted when a new medium item from the list has updated its
425 * accessibility state.
426 */
427 void mediumEnumerated (const UIMedium &aMedum);
428
429 /**
430 * Emitted at the end of the enumeration process started by
431 * #startEnumeratingMedia(). The @a aList argument is passed for
432 * convenience, it is exactly the same as returned by #currentMediaList().
433 */
434 void mediumEnumFinished (const VBoxMediaList &aList);
435
436 /** Emitted when a new media is added using #addMedia(). */
437 void mediumAdded (const UIMedium &);
438
439 /** Emitted when the media is updated using #updateMedia(). */
440 void mediumUpdated (const UIMedium &);
441
442 /** Emitted when the media is removed using #removeMedia(). */
443 void mediumRemoved (UIMediumType, const QString &);
444
445#ifdef VBOX_GUI_WITH_SYSTRAY
446 void sigTrayIconShow(bool fEnabled);
447#endif
448
449public slots:
450
451 bool openURL (const QString &aURL);
452
453 void showRegistrationDialog (bool aForce = true);
454 void sltGUILanguageChange(QString strLang);
455 void sltProcessGlobalSettingChange();
456
457protected:
458
459 bool event (QEvent *e);
460 bool eventFilter (QObject *, QEvent *);
461
462private:
463
464 VBoxGlobal();
465 ~VBoxGlobal();
466
467 void init();
468#ifdef VBOX_WITH_DEBUGGER_GUI
469 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
470 void setDebuggerVar(int *piDbgCfgVar, bool fState);
471 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
472#endif
473
474 bool mValid;
475
476 CVirtualBox mVBox;
477 CHost mHost;
478
479 VBoxGlobalSettings gset;
480
481 UISelectorWindow *mSelectorWnd;
482 UIMachine *m_pVirtualMachine;
483 QWidget* mMainWindow;
484
485#ifdef VBOX_WITH_REGISTRATION
486 UIRegistrationWzd *mRegDlg;
487#endif
488
489 QString vmUuid;
490 QList<QUrl> m_ArgUrlList;
491
492#ifdef VBOX_GUI_WITH_SYSTRAY
493 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
494 bool mIncreasedWindowCounter : 1;
495#endif
496
497 /** Whether to show error message boxes for VM start errors. */
498 bool mShowStartVMErrors;
499
500 QThread *mMediaEnumThread;
501 VBoxMediaList mMediaList;
502
503 RenderMode vm_render_mode;
504 const char * vm_render_mode_str;
505 bool mIsKWinManaged;
506
507 /** The --disable-patm option. */
508 bool mDisablePatm;
509 /** The --disable-csam option. */
510 bool mDisableCsam;
511 /** The --recompile-supervisor option. */
512 bool mRecompileSupervisor;
513 /** The --recompile-user option. */
514 bool mRecompileUser;
515
516#ifdef VBOX_WITH_DEBUGGER_GUI
517 /** Whether the debugger should be accessible or not.
518 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
519 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
520 int mDbgEnabled;
521 /** Whether to show the debugger automatically with the console.
522 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
523 int mDbgAutoShow;
524 /** Whether to show the command line window when mDbgAutoShow is set. */
525 int mDbgAutoShowCommandLine;
526 /** Whether to show the statistics window when mDbgAutoShow is set. */
527 int mDbgAutoShowStatistics;
528 /** VBoxDbg module handle. */
529 RTLDRMOD mhVBoxDbg;
530
531 /** Whether to start the VM in paused state or not. */
532 bool mStartPaused;
533#endif
534
535#if defined (Q_WS_WIN32)
536 DWORD dwHTMLHelpCookie;
537#endif
538
539 QString mVerString;
540 QString mBrandingConfig;
541
542 int m3DAvailable;
543
544 QList <QString> mFamilyIDs;
545 QList <QList <CGuestOSType> > mTypes;
546 QHash <QString, QPixmap *> mOsTypeIcons;
547
548 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
549
550 QULongStringHash mSlotTemplates;
551
552 QString mDiskTypes_Differencing;
553
554 QString mUserDefinedPortName;
555
556 QPixmap mWarningIcon, mErrorIcon;
557
558 QFileIconProvider m_globalIconProvider;
559
560#ifdef VBOX_GUI_WITH_PIDFILE
561 QString m_strPidfile;
562#endif
563
564 friend VBoxGlobal &vboxGlobal();
565};
566
567inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
568
569#endif /* __VBoxGlobal_h__ */
570
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