VirtualBox

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

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

FE/Qt: 6660: Advanced extra-data management framework: Moving extra-data stuff from global UIDefs.* to corresponding separate files UIExtraDataDefs.*

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette