VirtualBox

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

Last change on this file since 43138 was 43104, checked in by vboxsync, 12 years ago

FE/Qt: 6357: Make sure no Mac Sheets with the same parent are used when
there is already one.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use