VirtualBox

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

Last change on this file since 50935 was 50935, checked in by vboxsync, 11 years ago

FE/Qt: Optimization fix for r93080.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.4 KB
Line 
1/** @file
2 * VBox Qt GUI - VBoxGlobal class declaration.
3 */
4
5/*
6 * Copyright (C) 2006-2013 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#ifdef Q_WS_MAC
90 static MacOSXRelease osRelease();
91#endif /* Q_WS_MAC */
92
93 CVirtualBox virtualBox() const { return mVBox; }
94 CHost host() const { return mHost; }
95
96 VBoxGlobalSettings &settings() { return gset; }
97 bool setSettings (VBoxGlobalSettings &gs);
98
99 UISelectorWindow &selectorWnd();
100
101 /* VM stuff: */
102 bool startMachine(const QString &strMachineId);
103 UIMachine* virtualMachine();
104 QWidget* activeMachineWindow();
105
106 bool is3DAvailableWorker() const;
107 bool is3DAvailable() const { if (m3DAvailable < 0) return is3DAvailableWorker(); return m3DAvailable != 0; }
108
109#ifdef VBOX_GUI_WITH_PIDFILE
110 void createPidfile();
111 void deletePidfile();
112#endif
113
114 /* branding */
115 bool brandingIsActive (bool aForce = false);
116 QString brandingGetKey (QString aKey);
117
118 bool processArgs();
119
120 bool switchToMachine(CMachine &machine);
121 bool launchMachine(CMachine &machine, bool fHeadless = false);
122
123 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
124 bool showStartVMErrors() const { return mShowStartVMErrors; }
125 QString managedVMUuid() const { return vmUuid; }
126 QList<QUrl> &argUrlList() { return m_ArgUrlList; }
127
128 RenderMode vmRenderMode() const { return vm_render_mode; }
129 const char *vmRenderModeStr() const { return vm_render_mode_str; }
130 bool isKWinManaged() const { return mIsKWinManaged; }
131
132 const QRect availableGeometry(int iScreen = 0) const;
133
134 bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
135 bool isPatmDisabled() const { return mDisablePatm; }
136 bool isCsamDisabled() const { return mDisableCsam; }
137 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
138 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
139 bool areWeToExecuteAllInIem() const { return mExecuteAllInIem; }
140 bool isDefaultWarpPct() const { return mWarpPct == 100; }
141 uint32_t getWarpPct() const { return mWarpPct; }
142
143#ifdef VBOX_WITH_DEBUGGER_GUI
144 bool isDebuggerEnabled(CMachine &aMachine);
145 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
146 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
147 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
148 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
149
150 bool isStartPausedEnabled() const { return mStartPaused; }
151#else
152 bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
153 bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
154 bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
155
156 bool isStartPausedEnabled() const { return false; }
157#endif
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 QPixmap snapshotIcon (bool online) const
219 {
220 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
221 }
222
223 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
224 {
225 for (int i = 0; i < extList.size(); ++i)
226 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
227 return true;
228 return false;
229 }
230
231 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
232 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
233
234 QPixmap warningIcon() const { return mWarningIcon; }
235 QPixmap errorIcon() const { return mErrorIcon; }
236
237 /* details generators */
238
239 QString details(const CMedium &medium, bool fPredictDiff, bool fUseHtml = true);
240
241 QString details (const CUSBDevice &aDevice) const;
242 QString toolTip (const CUSBDevice &aDevice) const;
243 QString toolTip (const CUSBDeviceFilter &aFilter) const;
244 QString toolTip(const CHostVideoInputDevice &webcam) const;
245
246 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
247
248 /* VirtualBox helpers */
249
250 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
251
252 /** Shortcut to openSession (aId, true). */
253 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
254
255#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
256 void reloadProxySettings();
257#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
258
259 /* API: Medium-processing stuff: */
260 void createMedium(const UIMedium &medium);
261 void deleteMedium(const QString &strMediumID);
262 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
263 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
264 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
265
266 /* API: Medium-enumeration stuff: */
267 void startMediumEnumeration(bool fForceStart = true);
268 bool agressiveCaching() const { return mAgressiveCaching; }
269 bool isMediumEnumerationInProgress() const;
270 UIMedium medium(const QString &strMediumID) const;
271 QList<QString> mediumIDs() const;
272
273 /** Prepares storage menu according passed parameters.
274 * @param menu QMenu being prepared.
275 * @param pListener Listener QObject, this menu being prepared for.
276 * @param pszSlotName SLOT in the @a pListener above, this menu will be handled with.
277 * @param machine CMachine object, this menu being prepared for.
278 * @param strControllerName The name of the CStorageController in the @a machine above.
279 * @param storageSlot The StorageSlot of the CStorageController called @a strControllerName above. */
280 void prepareStorageMenu(QMenu &menu,
281 QObject *pListener, const char *pszSlotName,
282 const CMachine &machine, const QString &strControllerName, const StorageSlot &storageSlot);
283 /** Updates @a constMachine storage with data described by @a target. */
284 void updateMachineStorage(const CMachine &constMachine, const UIMediumTarget &target);
285
286 /* various helpers */
287
288 QString languageName() const;
289 QString languageCountry() const;
290 QString languageNameEnglish() const;
291 QString languageCountryEnglish() const;
292 QString languageTranslators() const;
293
294 void retranslateUi();
295
296 /* public static stuff */
297
298 static bool isDOSType (const QString &aOSTypeId);
299
300 static QString languageId();
301 static void loadLanguage (const QString &aLangId = QString::null);
302 QString helpFile() const;
303
304 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
305
306 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
307 bool aCanResize = true);
308 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
309 bool aCanResize = true);
310 static QRegion flip (const QRegion &aRegion);
311
312 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
313 bool aCanResize = true);
314
315 static QChar decimalSep();
316 static QString sizeRegexp();
317
318 static quint64 parseSize (const QString &);
319 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
320
321 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
322
323 static QString locationForHTML (const QString &aFileName);
324
325 static QString highlight (const QString &aStr, bool aToolTip = false);
326
327 static QString replaceHtmlEntities(QString strText);
328 static QString emphasize (const QString &aStr);
329
330 static QString systemLanguageId();
331
332 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
333
334 static QString removeAccelMark (const QString &aText);
335
336 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
337 static QString extractKeyFromActionText (const QString &aText);
338
339 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
340
341 static QWidget *findWidget (QWidget *aParent, const char *aName,
342 const char *aClassName = NULL,
343 bool aRecursive = false);
344
345 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
346 static QList <QPair <QString, QString> > HDDBackends();
347 static QList <QPair <QString, QString> > DVDBackends();
348 static QList <QPair <QString, QString> > FloppyBackends();
349
350 static QString documentsPath();
351
352#ifdef VBOX_WITH_VIDEOHWACCEL
353 static bool isAcceleration2DVideoAvailable();
354
355 /** additional video memory required for the best 2D support performance
356 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
357 static quint64 required2DOffscreenVideoMemory();
358#endif
359
360#ifdef VBOX_WITH_CRHGSMI
361 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
362 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
363#endif /* VBOX_WITH_CRHGSMI */
364
365 /* Returns full medium-format name for the given base medium-format name: */
366 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
367
368 /* Extra-data settings stuff: */
369 static bool isApprovedByExtraData(CVirtualBox &vbox, const QString &strExtraDataKey);
370 static bool isApprovedByExtraData(CMachine &machine, const QString &strExtraDataKey);
371#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
372 static bool shouldWeAllowApplicationUpdate(CVirtualBox &vbox);
373#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
374 static bool shouldWeShowMachine(CMachine &machine);
375 static bool shouldWeAllowMachineReconfiguration(CMachine &machine,
376 bool fIncludingMachineGeneralCheck = false,
377 bool fIncludingMachineStateCheck = false);
378 static bool shouldWeShowDetails(CMachine &machine,
379 bool fIncludingMachineGeneralCheck = false);
380 static bool shouldWeAutoMountGuestScreens(CMachine &machine, bool fIncludingSanityCheck = true);
381 static bool shouldWeAllowSnapshotOperations(CMachine &machine, bool fIncludingSanityCheck = true);
382 static MachineCloseAction defaultMachineCloseAction(CMachine &machine);
383 static RuntimeMenuType restrictedRuntimeMenuTypes(CMachine &machine);
384#ifdef Q_WS_MAC
385 static RuntimeMenuApplicationActionType restrictedRuntimeMenuApplicationActionTypes(CMachine &machine);
386#endif /* Q_WS_MAC */
387 static RuntimeMenuMachineActionType restrictedRuntimeMenuMachineActionTypes(CMachine &machine);
388 static RuntimeMenuViewActionType restrictedRuntimeMenuViewActionTypes(CMachine &machine);
389 static RuntimeMenuDevicesActionType restrictedRuntimeMenuDevicesActionTypes(CMachine &machine);
390#ifdef VBOX_WITH_DEBUGGER_GUI
391 static RuntimeMenuDebuggerActionType restrictedRuntimeMenuDebuggerActionTypes(CMachine &machine);
392#endif /* VBOX_WITH_DEBUGGER_GUI */
393 static RuntimeMenuHelpActionType restrictedRuntimeMenuHelpActionTypes(CMachine &machine);
394 static UIVisualStateType restrictedVisualStateTypes(CMachine &machine);
395 static QList<IndicatorType> restrictedStatusBarIndicators(CMachine &machine);
396 static MachineCloseAction restrictedMachineCloseActions(CMachine &machine);
397 static QList<GlobalSettingsPageType> restrictedGlobalSettingsPages(CVirtualBox &vbox);
398 static QList<MachineSettingsPageType> restrictedMachineSettingsPages(CMachine &machine);
399
400#ifdef RT_OS_LINUX
401 static void checkForWrongUSBMounted();
402#endif /* RT_OS_LINUX */
403
404 /* Shame on Qt it hasn't stuff for tuning
405 * widget size suitable for reflecting content of desired size.
406 * For example QLineEdit, QSpinBox and similar widgets should have a methods
407 * to strict the minimum width to reflect at least [n] symbols. */
408 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
409
410signals:
411
412 /* Notifiers: Medium-processing stuff: */
413 void sigMediumCreated(const QString &strMediumID);
414 void sigMediumDeleted(const QString &strMediumID);
415
416 /* Notifiers: Medium-enumeration stuff: */
417 void sigMediumEnumerationStarted();
418 void sigMediumEnumerated(const QString &strMediumID);
419 void sigMediumEnumerationFinished();
420
421public slots:
422
423 bool openURL (const QString &aURL);
424
425 void sltGUILanguageChange(QString strLang);
426 void sltProcessGlobalSettingChange();
427
428protected slots:
429
430 /* Handlers: Prepare/cleanup stuff: */
431 void prepare();
432 void cleanup();
433
434protected:
435
436 bool eventFilter (QObject *, QEvent *);
437
438private:
439
440 /* Constructor/destructor: */
441 VBoxGlobal();
442 ~VBoxGlobal();
443
444#ifdef VBOX_WITH_DEBUGGER_GUI
445 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
446 void setDebuggerVar(int *piDbgCfgVar, bool fState);
447 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
448#endif
449
450 bool mValid;
451
452 CVirtualBox mVBox;
453 CHost mHost;
454
455 VBoxGlobalSettings gset;
456
457 UISelectorWindow *mSelectorWnd;
458 UIMachine *m_pVirtualMachine;
459
460 QString vmUuid;
461 QList<QUrl> m_ArgUrlList;
462
463 /** Whether to show error message boxes for VM start errors. */
464 bool mShowStartVMErrors;
465
466 /* Variable: Medium-enumeration stuff: */
467 UIMediumEnumerator *m_pMediumEnumerator;
468 mutable QReadWriteLock m_mediumEnumeratorDtorRwLock;
469
470 RenderMode vm_render_mode;
471 const char * vm_render_mode_str;
472 bool mIsKWinManaged;
473
474 /** The --aggressive-caching / --no-aggressive-caching option. */
475 bool mAgressiveCaching;
476 /** The --restore-current option. */
477 bool mRestoreCurrentSnapshot;
478 /** The --disable-patm option. */
479 bool mDisablePatm;
480 /** The --disable-csam option. */
481 bool mDisableCsam;
482 /** The --recompile-supervisor option. */
483 bool mRecompileSupervisor;
484 /** The --recompile-user option. */
485 bool mRecompileUser;
486 /** The --execute-all-in-iem option. */
487 bool mExecuteAllInIem;
488 /** The --warp-factor option value. */
489 uint32_t mWarpPct;
490
491#ifdef VBOX_WITH_DEBUGGER_GUI
492 /** Whether the debugger should be accessible or not.
493 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
494 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
495 int mDbgEnabled;
496 /** Whether to show the debugger automatically with the console.
497 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
498 int mDbgAutoShow;
499 /** Whether to show the command line window when mDbgAutoShow is set. */
500 int mDbgAutoShowCommandLine;
501 /** Whether to show the statistics window when mDbgAutoShow is set. */
502 int mDbgAutoShowStatistics;
503 /** VBoxDbg module handle. */
504 RTLDRMOD mhVBoxDbg;
505
506 /** Whether to start the VM in paused state or not. */
507 bool mStartPaused;
508#endif
509
510#if defined (Q_WS_WIN32)
511 DWORD dwHTMLHelpCookie;
512#endif
513
514 QString mVerString;
515 QString mBrandingConfig;
516
517 int m3DAvailable;
518
519 QList <QString> mFamilyIDs;
520 QList <QList <CGuestOSType> > mTypes;
521
522 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
523
524 QString mDiskTypes_Differencing;
525
526 QString mUserDefinedPortName;
527
528 QPixmap mWarningIcon, mErrorIcon;
529
530 QFileIconProvider m_globalIconProvider;
531
532#ifdef VBOX_GUI_WITH_PIDFILE
533 QString m_strPidfile;
534#endif
535
536 char mSettingsPw[256];
537 bool mSettingsPwSet;
538
539 /** General icon-pool. */
540 UIIconPoolGeneral *m_pIconPool;
541
542 /* API: Instance stuff: */
543 static bool m_sfCleanupInProgress;
544 static VBoxGlobal* m_spInstance;
545 friend VBoxGlobal& vboxGlobal();
546};
547
548/* Shortcut to the static VBoxGlobal::instance() method: */
549inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
550
551#endif /* !___VBoxGlobal_h___ */
552
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