VirtualBox

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

Last change on this file since 52894 was 52894, checked in by vboxsync, 10 years ago

Frontends/VirtualBox: option to run a separate VM process.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.0 KB
Line 
1/** @file
2 * VBox Qt GUI - VBoxGlobal class declaration.
3 */
4
5/*
6 * Copyright (C) 2006-2014 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ___VBoxGlobal_h___
18#define ___VBoxGlobal_h___
19
20/* Qt includes: */
21#include <QApplication>
22#include <QLayout>
23#include <QMenu>
24#include <QStyle>
25#include <QHash>
26#include <QFileIconProvider>
27#include <QReadWriteLock>
28#ifdef Q_WS_MAC
29# include <QSet>
30#endif /* Q_WS_MAC */
31
32/* GUI includes: */
33#include "UIDefs.h"
34#include "UIMediumDefs.h"
35#include "VBoxGlobalSettings.h"
36
37/* COM includes: */
38#include "VBox/com/Guid.h"
39#include "CHost.h"
40#include "CVirtualBox.h"
41#include "CSession.h"
42#include "CGuestOSType.h"
43
44/* Forward declarations: */
45class QAction;
46class QLabel;
47class QToolButton;
48class UIMachine;
49class CMachine;
50class CMedium;
51class CUSBDevice;
52class CHostVideoInputDevice;
53class QSpinBox;
54class UIMediumEnumerator;
55class UIMedium;
56class UIIconPoolGeneral;
57
58// VBoxGlobal class
59////////////////////////////////////////////////////////////////////////////////
60
61class UISelectorWindow;
62class VBoxUpdateDlg;
63
64class VBoxGlobal : public QObject
65{
66 Q_OBJECT
67
68public:
69
70 /* Static API: Create/destroy stuff: */
71 static VBoxGlobal* instance();
72 static void create();
73 static void destroy();
74
75 bool isValid() { return mValid; }
76 bool isCleaningUp() { return m_sfCleanupInProgress; }
77
78 static QString qtRTVersionString();
79 static uint qtRTVersion();
80 static QString qtCTVersionString();
81 static uint qtCTVersion();
82
83 QString vboxVersionString() const;
84 QString vboxVersionStringNormalized() const;
85
86 QString versionString() const { return mVerString; }
87 bool isBeta() const;
88
89 bool isSeparate() const { return mIsSeparate; }
90
91#ifdef Q_WS_MAC
92 static MacOSXRelease osRelease();
93#endif /* Q_WS_MAC */
94
95 CVirtualBox virtualBox() const { return mVBox; }
96 CHost host() const { return mHost; }
97
98 VBoxGlobalSettings &settings() { return gset; }
99 bool setSettings (VBoxGlobalSettings &gs);
100
101 UISelectorWindow &selectorWnd();
102
103 /* VM stuff: */
104 bool startMachine(const QString &strMachineId);
105 UIMachine* virtualMachine();
106 QWidget* activeMachineWindow();
107
108 bool is3DAvailableWorker() const;
109 bool is3DAvailable() const { if (m3DAvailable < 0) return is3DAvailableWorker(); return m3DAvailable != 0; }
110
111#ifdef VBOX_GUI_WITH_PIDFILE
112 void createPidfile();
113 void deletePidfile();
114#endif
115
116 /* branding */
117 bool brandingIsActive (bool aForce = false);
118 QString brandingGetKey (QString aKey);
119
120 bool processArgs();
121
122 bool switchToMachine(CMachine &machine);
123
124 enum LaunchMode
125 {
126 LaunchMode_Default,
127 LaunchMode_Headless,
128 LaunchMode_Separate
129 };
130 bool launchMachine(CMachine &machine, LaunchMode enmLaunchMode = LaunchMode_Default);
131
132 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
133 bool showStartVMErrors() const { return mShowStartVMErrors; }
134 QString managedVMUuid() const { return vmUuid; }
135 QList<QUrl> &argUrlList() { return m_ArgUrlList; }
136
137 bool isKWinManaged() const { return mIsKWinManaged; }
138
139 bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
140 bool isPatmDisabled() const { return mDisablePatm; }
141 bool isCsamDisabled() const { return mDisableCsam; }
142 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
143 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
144 bool areWeToExecuteAllInIem() const { return mExecuteAllInIem; }
145 bool isDefaultWarpPct() const { return mWarpPct == 100; }
146 uint32_t getWarpPct() const { return mWarpPct; }
147
148#ifdef VBOX_WITH_DEBUGGER_GUI
149 bool isDebuggerEnabled() const;
150 bool isDebuggerAutoShowEnabled() const;
151 bool isDebuggerAutoShowCommandLineEnabled() const;
152 bool isDebuggerAutoShowStatisticsEnabled() const;
153
154 RTLDRMOD getDebuggerModule() const { return m_hVBoxDbg; }
155
156 bool isStartPausedEnabled() const { return mStartPaused; }
157#endif /* VBOX_WITH_DEBUGGER_GUI */
158
159 /* VBox enum to/from string/icon/color convertors */
160
161 QList <CGuestOSType> vmGuestOSFamilyList() const;
162 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
163
164 /** Returns pixmap corresponding to passed @a strOSTypeID.
165 * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
166 QPixmap vmGuestOSTypeIcon(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
167
168 CGuestOSType vmGuestOSType (const QString &aTypeId,
169 const QString &aFamilyId = QString::null) const;
170 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
171
172 static inline QString yearsToString (uint32_t cVal)
173 {
174 return tr("%n year(s)", "", cVal);
175 }
176
177 static inline QString monthsToString (uint32_t cVal)
178 {
179 return tr("%n month(s)", "", cVal);
180 }
181
182 static inline QString daysToString (uint32_t cVal)
183 {
184 return tr("%n day(s)", "", cVal);
185 }
186
187 static inline QString hoursToString (uint32_t cVal)
188 {
189 return tr("%n hour(s)", "", cVal);
190 }
191
192 static inline QString minutesToString (uint32_t cVal)
193 {
194 return tr("%n minute(s)", "", cVal);
195 }
196
197 static inline QString secondsToString (uint32_t cVal)
198 {
199 return tr("%n second(s)", "", cVal);
200 }
201
202 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
203
204 /**
205 * Similar to toString (KMediumType), but returns 'Differencing' for
206 * normal hard disks that have a parent.
207 */
208 QString mediumTypeString(const CMedium &medium) const;
209
210 QStringList COMPortNames() const;
211 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
212 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
213
214 QStringList LPTPortNames() const;
215 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
216 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
217
218 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
219 {
220 for (int i = 0; i < extList.size(); ++i)
221 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
222 return true;
223 return false;
224 }
225
226 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
227 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
228
229 QPixmap warningIcon() const { return mWarningIcon; }
230 QPixmap errorIcon() const { return mErrorIcon; }
231
232 /* details generators */
233
234 QString details(const CMedium &medium, bool fPredictDiff, bool fUseHtml = true);
235
236 QString details (const CUSBDevice &aDevice) const;
237 QString toolTip (const CUSBDevice &aDevice) const;
238 QString toolTip (const CUSBDeviceFilter &aFilter) const;
239 QString toolTip(const CHostVideoInputDevice &webcam) const;
240
241 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
242
243 /* VirtualBox helpers */
244
245 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
246
247 /** Shortcut to openSession (aId, true). */
248 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
249
250#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
251 void reloadProxySettings();
252#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
253
254 /* API: Medium-processing stuff: */
255 void createMedium(const UIMedium &medium);
256 void deleteMedium(const QString &strMediumID);
257 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
258 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
259 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
260
261 /* API: Medium-enumeration stuff: */
262 void startMediumEnumeration(bool fForceStart = true);
263 bool agressiveCaching() const { return mAgressiveCaching; }
264 bool isMediumEnumerationInProgress() const;
265 UIMedium medium(const QString &strMediumID) const;
266 QList<QString> mediumIDs() const;
267
268 /** Prepares storage menu according passed parameters.
269 * @param menu QMenu being prepared.
270 * @param pListener Listener QObject, this menu being prepared for.
271 * @param pszSlotName SLOT in the @a pListener above, this menu will be handled with.
272 * @param machine CMachine object, this menu being prepared for.
273 * @param strControllerName The name of the CStorageController in the @a machine above.
274 * @param storageSlot The StorageSlot of the CStorageController called @a strControllerName above. */
275 void prepareStorageMenu(QMenu &menu,
276 QObject *pListener, const char *pszSlotName,
277 const CMachine &machine, const QString &strControllerName, const StorageSlot &storageSlot);
278 /** Updates @a constMachine storage with data described by @a target. */
279 void updateMachineStorage(const CMachine &constMachine, const UIMediumTarget &target);
280
281 /* various helpers */
282
283 QString languageName() const;
284 QString languageCountry() const;
285 QString languageNameEnglish() const;
286 QString languageCountryEnglish() const;
287 QString languageTranslators() const;
288
289 void retranslateUi();
290
291 /* public static stuff */
292
293 static bool isDOSType (const QString &aOSTypeId);
294
295 static QString languageId();
296 static void loadLanguage (const QString &aLangId = QString::null);
297 QString helpFile() const;
298
299 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
300
301 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
302 bool aCanResize = true);
303 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
304 bool aCanResize = true);
305 static QRegion flip (const QRegion &aRegion);
306
307 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
308 bool aCanResize = true);
309
310 static QChar decimalSep();
311 static QString sizeRegexp();
312
313 static quint64 parseSize (const QString &);
314 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
315
316 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
317
318 static QString locationForHTML (const QString &aFileName);
319
320 static QString highlight (const QString &aStr, bool aToolTip = false);
321
322 static QString replaceHtmlEntities(QString strText);
323 static QString emphasize (const QString &aStr);
324
325 static QString systemLanguageId();
326
327 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
328
329#ifdef Q_WS_X11
330 /** X11: Test whether the current window manager supports full screen mode. */
331 static bool supportsFullScreenMonitorsProtocolX11();
332 /** X11: Performs mapping of the passed @a pWidget to host-screen with passed @a uScreenId. */
333 static bool setFullScreenMonitorX11(QWidget *pWidget, ulong uScreenId);
334 /** X11: Ensures @a pPropWidget become transient for the @a pWidget. */
335 static void setTransientFor(QWidget *pWidget, QWidget *pPropWidget);
336#endif /* Q_WS_X11 */
337
338 static QString removeAccelMark (const QString &aText);
339
340 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
341
342 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
343
344 static QWidget *findWidget (QWidget *aParent, const char *aName,
345 const char *aClassName = NULL,
346 bool aRecursive = false);
347
348 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
349 static QList <QPair <QString, QString> > HDDBackends();
350 static QList <QPair <QString, QString> > DVDBackends();
351 static QList <QPair <QString, QString> > FloppyBackends();
352
353 static QString documentsPath();
354
355#ifdef VBOX_WITH_VIDEOHWACCEL
356 static bool isAcceleration2DVideoAvailable();
357
358 /** additional video memory required for the best 2D support performance
359 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
360 static quint64 required2DOffscreenVideoMemory();
361#endif
362
363#ifdef VBOX_WITH_CRHGSMI
364 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
365 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
366#endif /* VBOX_WITH_CRHGSMI */
367
368 /* Returns full medium-format name for the given base medium-format name: */
369 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
370
371
372#ifdef RT_OS_LINUX
373 static void checkForWrongUSBMounted();
374#endif /* RT_OS_LINUX */
375
376 /* Shame on Qt it hasn't stuff for tuning
377 * widget size suitable for reflecting content of desired size.
378 * For example QLineEdit, QSpinBox and similar widgets should have a methods
379 * to strict the minimum width to reflect at least [n] symbols. */
380 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
381
382signals:
383
384 /* Notifiers: Medium-processing stuff: */
385 void sigMediumCreated(const QString &strMediumID);
386 void sigMediumDeleted(const QString &strMediumID);
387
388 /* Notifiers: Medium-enumeration stuff: */
389 void sigMediumEnumerationStarted();
390 void sigMediumEnumerated(const QString &strMediumID);
391 void sigMediumEnumerationFinished();
392
393public slots:
394
395 bool openURL (const QString &aURL);
396
397 void sltGUILanguageChange(QString strLang);
398 void sltProcessGlobalSettingChange();
399
400protected slots:
401
402 /* Handlers: Prepare/cleanup stuff: */
403 void prepare();
404 void cleanup();
405
406protected:
407
408 bool eventFilter (QObject *, QEvent *);
409
410private:
411
412 /* Constructor/destructor: */
413 VBoxGlobal();
414 ~VBoxGlobal();
415
416#ifdef VBOX_WITH_DEBUGGER_GUI
417 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
418 void setDebuggerVar(int *piDbgCfgVar, bool fState);
419 bool isDebuggerWorker(int *piDbgCfgVar, const char *pszExtraDataName) const;
420#endif
421
422 bool mValid;
423
424 CVirtualBox mVBox;
425 CHost mHost;
426
427 VBoxGlobalSettings gset;
428
429 UISelectorWindow *mSelectorWnd;
430 UIMachine *m_pVirtualMachine;
431
432 bool mIsSeparate;
433
434 QString vmUuid;
435 QList<QUrl> m_ArgUrlList;
436
437 /** Whether to show error message boxes for VM start errors. */
438 bool mShowStartVMErrors;
439
440 /* Variable: Medium-enumeration stuff: */
441 UIMediumEnumerator *m_pMediumEnumerator;
442 mutable QReadWriteLock m_mediumEnumeratorDtorRwLock;
443
444 bool mIsKWinManaged;
445
446 /** The --aggressive-caching / --no-aggressive-caching option. */
447 bool mAgressiveCaching;
448 /** The --restore-current option. */
449 bool mRestoreCurrentSnapshot;
450 /** The --disable-patm option. */
451 bool mDisablePatm;
452 /** The --disable-csam option. */
453 bool mDisableCsam;
454 /** The --recompile-supervisor option. */
455 bool mRecompileSupervisor;
456 /** The --recompile-user option. */
457 bool mRecompileUser;
458 /** The --execute-all-in-iem option. */
459 bool mExecuteAllInIem;
460 /** The --warp-factor option value. */
461 uint32_t mWarpPct;
462
463#ifdef VBOX_WITH_DEBUGGER_GUI
464 /** Whether the debugger should be accessible or not.
465 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED,
466 * --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
467 mutable int m_fDbgEnabled;
468 /** Whether to show the debugger automatically with the console.
469 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
470 mutable int m_fDbgAutoShow;
471 /** Whether to show the command line window when m_fDbgAutoShow is set. */
472 mutable int m_fDbgAutoShowCommandLine;
473 /** Whether to show the statistics window when m_fDbgAutoShow is set. */
474 mutable int m_fDbgAutoShowStatistics;
475 /** VBoxDbg module handle. */
476 RTLDRMOD m_hVBoxDbg;
477
478 /** Whether to start the VM in paused state or not. */
479 bool mStartPaused;
480#endif
481
482#if defined (Q_WS_WIN32)
483 DWORD dwHTMLHelpCookie;
484#endif
485
486 QString mVerString;
487 QString mBrandingConfig;
488
489 int m3DAvailable;
490
491 QList <QString> mFamilyIDs;
492 QList <QList <CGuestOSType> > mTypes;
493
494 QString mDiskTypes_Differencing;
495
496 QString mUserDefinedPortName;
497
498 QPixmap mWarningIcon, mErrorIcon;
499
500 QFileIconProvider m_globalIconProvider;
501
502#ifdef VBOX_GUI_WITH_PIDFILE
503 QString m_strPidfile;
504#endif
505
506 char mSettingsPw[256];
507 bool mSettingsPwSet;
508
509 /** General icon-pool. */
510 UIIconPoolGeneral *m_pIconPool;
511
512 /* API: Instance stuff: */
513 static bool m_sfCleanupInProgress;
514 static VBoxGlobal* m_spInstance;
515 friend VBoxGlobal& vboxGlobal();
516};
517
518/* Shortcut to the static VBoxGlobal::instance() method: */
519inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
520
521#endif /* !___VBoxGlobal_h___ */
522
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