VirtualBox

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

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

FE/Qt: Runtime UI rework/cleanup for 7115 (part #5): Better encapsulation for UIMachine (part #2).

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