VirtualBox

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

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

FE/Qt: 6660: Advanced extra-data management framework: Taking extra-data stuff from VBoxGlobal.

  • 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 "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
369#ifdef RT_OS_LINUX
370 static void checkForWrongUSBMounted();
371#endif /* RT_OS_LINUX */
372
373 /* Shame on Qt it hasn't stuff for tuning
374 * widget size suitable for reflecting content of desired size.
375 * For example QLineEdit, QSpinBox and similar widgets should have a methods
376 * to strict the minimum width to reflect at least [n] symbols. */
377 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
378
379signals:
380
381 /* Notifiers: Medium-processing stuff: */
382 void sigMediumCreated(const QString &strMediumID);
383 void sigMediumDeleted(const QString &strMediumID);
384
385 /* Notifiers: Medium-enumeration stuff: */
386 void sigMediumEnumerationStarted();
387 void sigMediumEnumerated(const QString &strMediumID);
388 void sigMediumEnumerationFinished();
389
390public slots:
391
392 bool openURL (const QString &aURL);
393
394 void sltGUILanguageChange(QString strLang);
395 void sltProcessGlobalSettingChange();
396
397protected slots:
398
399 /* Handlers: Prepare/cleanup stuff: */
400 void prepare();
401 void cleanup();
402
403protected:
404
405 bool eventFilter (QObject *, QEvent *);
406
407private:
408
409 /* Constructor/destructor: */
410 VBoxGlobal();
411 ~VBoxGlobal();
412
413#ifdef VBOX_WITH_DEBUGGER_GUI
414 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
415 void setDebuggerVar(int *piDbgCfgVar, bool fState);
416 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
417#endif
418
419 bool mValid;
420
421 CVirtualBox mVBox;
422 CHost mHost;
423
424 VBoxGlobalSettings gset;
425
426 UISelectorWindow *mSelectorWnd;
427 UIMachine *m_pVirtualMachine;
428
429 QString vmUuid;
430 QList<QUrl> m_ArgUrlList;
431
432 /** Whether to show error message boxes for VM start errors. */
433 bool mShowStartVMErrors;
434
435 /* Variable: Medium-enumeration stuff: */
436 UIMediumEnumerator *m_pMediumEnumerator;
437 mutable QReadWriteLock m_mediumEnumeratorDtorRwLock;
438
439 RenderMode vm_render_mode;
440 const char * vm_render_mode_str;
441 bool mIsKWinManaged;
442
443 /** The --aggressive-caching / --no-aggressive-caching option. */
444 bool mAgressiveCaching;
445 /** The --restore-current option. */
446 bool mRestoreCurrentSnapshot;
447 /** The --disable-patm option. */
448 bool mDisablePatm;
449 /** The --disable-csam option. */
450 bool mDisableCsam;
451 /** The --recompile-supervisor option. */
452 bool mRecompileSupervisor;
453 /** The --recompile-user option. */
454 bool mRecompileUser;
455 /** The --execute-all-in-iem option. */
456 bool mExecuteAllInIem;
457 /** The --warp-factor option value. */
458 uint32_t mWarpPct;
459
460#ifdef VBOX_WITH_DEBUGGER_GUI
461 /** Whether the debugger should be accessible or not.
462 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
463 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
464 int mDbgEnabled;
465 /** Whether to show the debugger automatically with the console.
466 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
467 int mDbgAutoShow;
468 /** Whether to show the command line window when mDbgAutoShow is set. */
469 int mDbgAutoShowCommandLine;
470 /** Whether to show the statistics window when mDbgAutoShow is set. */
471 int mDbgAutoShowStatistics;
472 /** VBoxDbg module handle. */
473 RTLDRMOD mhVBoxDbg;
474
475 /** Whether to start the VM in paused state or not. */
476 bool mStartPaused;
477#endif
478
479#if defined (Q_WS_WIN32)
480 DWORD dwHTMLHelpCookie;
481#endif
482
483 QString mVerString;
484 QString mBrandingConfig;
485
486 int m3DAvailable;
487
488 QList <QString> mFamilyIDs;
489 QList <QList <CGuestOSType> > mTypes;
490
491 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
492
493 QString mDiskTypes_Differencing;
494
495 QString mUserDefinedPortName;
496
497 QPixmap mWarningIcon, mErrorIcon;
498
499 QFileIconProvider m_globalIconProvider;
500
501#ifdef VBOX_GUI_WITH_PIDFILE
502 QString m_strPidfile;
503#endif
504
505 char mSettingsPw[256];
506 bool mSettingsPwSet;
507
508 /** General icon-pool. */
509 UIIconPoolGeneral *m_pIconPool;
510
511 /* API: Instance stuff: */
512 static bool m_sfCleanupInProgress;
513 static VBoxGlobal* m_spInstance;
514 friend VBoxGlobal& vboxGlobal();
515};
516
517/* Shortcut to the static VBoxGlobal::instance() method: */
518inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
519
520#endif /* !___VBoxGlobal_h___ */
521
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