VirtualBox

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

Last change on this file since 47478 was 47478, checked in by vboxsync, 12 years ago

FE/Qt: Runtime UI: Adding extra-data flag 'GUI/RestrictedVisualStates' to restrict unwanted visual-representation states.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.1 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2013 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef __VBoxGlobal_h__
20#define __VBoxGlobal_h__
21
22/* Qt includes: */
23#include <QApplication>
24#include <QLayout>
25#include <QMenu>
26#include <QStyle>
27#include <QHash>
28#include <QFileIconProvider>
29#ifdef Q_WS_MAC
30# include <QSet>
31#endif /* Q_WS_MAC */
32
33/* GUI includes: */
34#include "UIDefs.h"
35#include "VBoxGlobalSettings.h"
36#include "UIMedium.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 QSpinBox;
54
55// VBoxGlobal class
56////////////////////////////////////////////////////////////////////////////////
57
58class UISelectorWindow;
59class VBoxUpdateDlg;
60
61class VBoxGlobal : public QObject
62{
63 Q_OBJECT
64
65public:
66
67 /* Static API: Create/destroy stuff: */
68 static VBoxGlobal* instance();
69 static void create();
70 static void destroy();
71
72 bool isValid() { return mValid; }
73
74 static QString qtRTVersionString();
75 static uint qtRTVersion();
76 static QString qtCTVersionString();
77 static uint qtCTVersion();
78
79 QString vboxVersionString() const;
80 QString vboxVersionStringNormalized() const;
81
82 QString versionString() const { return mVerString; }
83 bool isBeta() const;
84
85 CVirtualBox virtualBox() const { return mVBox; }
86 CHost host() const { return mHost; }
87
88 VBoxGlobalSettings &settings() { return gset; }
89 bool setSettings (VBoxGlobalSettings &gs);
90
91 UISelectorWindow &selectorWnd();
92
93 /* VM stuff: */
94 bool startMachine(const QString &strMachineId);
95 UIMachine* virtualMachine();
96 QWidget* activeMachineWindow();
97
98 bool is3DAvailableWorker() const;
99 bool is3DAvailable() const { if (m3DAvailable < 0) return is3DAvailableWorker(); return m3DAvailable != 0; }
100
101#ifdef VBOX_GUI_WITH_PIDFILE
102 void createPidfile();
103 void deletePidfile();
104#endif
105
106 /* branding */
107 bool brandingIsActive (bool aForce = false);
108 QString brandingGetKey (QString aKey);
109
110 bool processArgs();
111
112 bool switchToMachine(CMachine &machine);
113 bool launchMachine(CMachine &machine, bool fHeadless = false);
114
115 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
116 bool showStartVMErrors() const { return mShowStartVMErrors; }
117 QString managedVMUuid() const { return vmUuid; }
118 QList<QUrl> &argUrlList() { return m_ArgUrlList; }
119
120 RenderMode vmRenderMode() const { return vm_render_mode; }
121 const char *vmRenderModeStr() const { return vm_render_mode_str; }
122 bool isKWinManaged() const { return mIsKWinManaged; }
123
124 const QRect availableGeometry(int iScreen = 0) const;
125
126 bool isPatmDisabled() const { return mDisablePatm; }
127 bool isCsamDisabled() const { return mDisableCsam; }
128 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
129 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
130 bool areWeToExecuteAllInIem() const { return mExecuteAllInIem; }
131 bool isDefaultWarpPct() const { return mWarpPct == 100; }
132 uint32_t getWarpPct() const { return mWarpPct; }
133
134#ifdef VBOX_WITH_DEBUGGER_GUI
135 bool isDebuggerEnabled(CMachine &aMachine);
136 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
137 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
138 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
139 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
140
141 bool isStartPausedEnabled() const { return mStartPaused; }
142#else
143 bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
144 bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
145 bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
146
147 bool isStartPausedEnabled() const { return false; }
148#endif
149
150 /* VBox enum to/from string/icon/color convertors */
151
152 QList <CGuestOSType> vmGuestOSFamilyList() const;
153 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
154 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
155 CGuestOSType vmGuestOSType (const QString &aTypeId,
156 const QString &aFamilyId = QString::null) const;
157 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
158
159 static inline QString yearsToString (uint32_t cVal)
160 {
161 return tr("%n year(s)", "", cVal);
162 }
163
164 static inline QString monthsToString (uint32_t cVal)
165 {
166 return tr("%n month(s)", "", cVal);
167 }
168
169 static inline QString daysToString (uint32_t cVal)
170 {
171 return tr("%n day(s)", "", cVal);
172 }
173
174 static inline QString hoursToString (uint32_t cVal)
175 {
176 return tr("%n hour(s)", "", cVal);
177 }
178
179 static inline QString minutesToString (uint32_t cVal)
180 {
181 return tr("%n minute(s)", "", cVal);
182 }
183
184 static inline QString secondsToString (uint32_t cVal)
185 {
186 return tr("%n second(s)", "", cVal);
187 }
188
189 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
190
191 /**
192 * Similar to toString (KMediumType), but returns 'Differencing' for
193 * normal hard disks that have a parent.
194 */
195 QString mediumTypeString(const CMedium &medium) const;
196
197 QStringList COMPortNames() const;
198 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
199 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
200
201 QStringList LPTPortNames() const;
202 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
203 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
204
205 QPixmap snapshotIcon (bool online) const
206 {
207 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
208 }
209
210 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
211 {
212 for (int i = 0; i < extList.size(); ++i)
213 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
214 return true;
215 return false;
216 }
217
218 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
219 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
220
221 QPixmap warningIcon() const { return mWarningIcon; }
222 QPixmap errorIcon() const { return mErrorIcon; }
223
224 /* details generators */
225
226 QString details (const CMedium &aHD, bool aPredictDiff, bool fUseHtml = true);
227
228 QString details (const CUSBDevice &aDevice) const;
229 QString toolTip (const CUSBDevice &aDevice) const;
230 QString toolTip (const CUSBDeviceFilter &aFilter) const;
231
232 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
233
234 /* VirtualBox helpers */
235
236 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
237
238 /** Shortcut to openSession (aId, true). */
239 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
240
241 void startEnumeratingMedia();
242
243 void reloadProxySettings();
244
245 /**
246 * Returns a list of all currently registered media. This list is used to
247 * globally track the accessibility state of all media on a dedicated thread.
248 *
249 * Note that the media list is initially empty (i.e. before the enumeration
250 * process is started for the first time using #startEnumeratingMedia()).
251 * See #startEnumeratingMedia() for more information about how meida are
252 * sorted in the returned list.
253 */
254 const VBoxMediaList &currentMediaList() const { return mMediaList; }
255
256 /** Returns true if the media enumeration is in progress. */
257 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
258
259 void addMedium (const UIMedium &);
260 void updateMedium (const UIMedium &);
261 void removeMedium (UIMediumType, const QString &);
262
263 bool findMedium (const CMedium &, UIMedium &) const;
264 UIMedium findMedium (const QString &aMediumId) const;
265
266 /** Compact version of #findMediumTo(). Asserts if not found. */
267 UIMedium getMedium (const CMedium &aObj) const
268 {
269 UIMedium medium;
270 if (!findMedium (aObj, medium))
271 AssertFailed();
272 return medium;
273 }
274
275 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
276 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
277 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
278
279 /* Returns the number of current running Fe/Qt4 main windows. */
280 int mainWindowCount();
281
282 /* various helpers */
283
284 QString languageName() const;
285 QString languageCountry() const;
286 QString languageNameEnglish() const;
287 QString languageCountryEnglish() const;
288 QString languageTranslators() const;
289
290 void retranslateUi();
291
292 /* public static stuff */
293
294 static bool isDOSType (const QString &aOSTypeId);
295
296 static QString languageId();
297 static void loadLanguage (const QString &aLangId = QString::null);
298 QString helpFile() const;
299
300 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
301
302 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
303 bool aCanResize = true);
304 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
305 bool aCanResize = true);
306 static QRegion flip (const QRegion &aRegion);
307
308 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
309 bool aCanResize = true);
310
311 static QChar decimalSep();
312 static QString sizeRegexp();
313
314 static quint64 parseSize (const QString &);
315 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
316
317 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
318
319 static QString locationForHTML (const QString &aFileName);
320
321 static QString highlight (const QString &aStr, bool aToolTip = false);
322
323 static QString replaceHtmlEntities(QString strText);
324 static QString emphasize (const QString &aStr);
325
326 static QString systemLanguageId();
327
328 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
329
330 static QString removeAccelMark (const QString &aText);
331
332 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
333 static QString extractKeyFromActionText (const QString &aText);
334
335 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
336
337 static QWidget *findWidget (QWidget *aParent, const char *aName,
338 const char *aClassName = NULL,
339 bool aRecursive = false);
340
341 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
342 static QList <QPair <QString, QString> > HDDBackends();
343 static QList <QPair <QString, QString> > DVDBackends();
344 static QList <QPair <QString, QString> > FloppyBackends();
345
346 static QString documentsPath();
347
348#ifdef VBOX_WITH_VIDEOHWACCEL
349 static bool isAcceleration2DVideoAvailable();
350
351 /** additional video memory required for the best 2D support performance
352 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
353 static quint64 required2DOffscreenVideoMemory();
354#endif
355
356#ifdef VBOX_WITH_CRHGSMI
357 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
358 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
359#endif /* VBOX_WITH_CRHGSMI */
360
361 /* Returns full medium-format name for the given base medium-format name: */
362 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
363
364 /* Extra-data settings stuff: */
365 static bool isApprovedByExtraData(CVirtualBox &vbox, const QString &strExtraDataKey);
366 static bool isApprovedByExtraData(CMachine &machine, const QString &strExtraDataKey);
367 static bool shouldWeAllowApplicationUpdate(CVirtualBox &vbox);
368 static bool shouldWeShowMachine(CMachine &machine);
369 static bool shouldWeAllowMachineReconfiguration(CMachine &machine,
370 bool fIncludingMachineGeneralCheck = false,
371 bool fIncludingMachineStateCheck = false);
372 static bool shouldWeShowDetails(CMachine &machine,
373 bool fIncludingMachineGeneralCheck = false);
374 static bool shouldWeAutoMountGuestScreens(CMachine &machine, bool fIncludingSanityCheck = true);
375 static bool shouldWeAllowSnapshotOperations(CMachine &machine, bool fIncludingSanityCheck = true);
376 static RuntimeMenuType restrictedRuntimeMenuTypes(CMachine &machine);
377 static UIVisualStateType restrictedVisualStateTypes(CMachine &machine);
378 static QList<IndicatorType> restrictedStatusBarIndicators(CMachine &machine);
379 static QList<MachineCloseAction> restrictedMachineCloseActions(CMachine &machine);
380 static QList<GlobalSettingsPageType> restrictedGlobalSettingsPages(CVirtualBox &vbox);
381 static QList<MachineSettingsPageType> restrictedMachineSettingsPages(CMachine &machine);
382
383#ifdef RT_OS_LINUX
384 static void checkForWrongUSBMounted();
385#endif /* RT_OS_LINUX */
386
387 /* Shame on Qt it hasn't stuff for tuning
388 * widget size suitable for reflecting content of desired size.
389 * For example QLineEdit, QSpinBox and similar widgets should have a methods
390 * to strict the minimum width to reflect at least [n] symbols. */
391 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
392
393signals:
394
395 /**
396 * Emitted at the beginning of the enumeration process started by
397 * #startEnumeratingMedia().
398 */
399 void mediumEnumStarted();
400
401 /**
402 * Emitted when a new medium item from the list has updated its
403 * accessibility state.
404 */
405 void mediumEnumerated (const UIMedium &aMedum);
406
407 /**
408 * Emitted at the end of the enumeration process started by
409 * #startEnumeratingMedia(). The @a aList argument is passed for
410 * convenience, it is exactly the same as returned by #currentMediaList().
411 */
412 void mediumEnumFinished (const VBoxMediaList &aList);
413
414 /** Emitted when a new media is added using #addMedia(). */
415 void mediumAdded (const UIMedium &);
416
417 /** Emitted when the media is updated using #updateMedia(). */
418 void mediumUpdated (const UIMedium &);
419
420 /** Emitted when the media is removed using #removeMedia(). */
421 void mediumRemoved (UIMediumType, const QString &);
422
423public slots:
424
425 bool openURL (const QString &aURL);
426
427 void sltGUILanguageChange(QString strLang);
428 void sltProcessGlobalSettingChange();
429
430protected slots:
431
432 /* Handlers: Prepare/cleanup stuff: */
433 void prepare();
434 void cleanup();
435
436protected:
437
438 bool event (QEvent *e);
439 bool eventFilter (QObject *, QEvent *);
440
441private:
442
443 /* Constructor/destructor: */
444 VBoxGlobal();
445 ~VBoxGlobal();
446
447#ifdef VBOX_WITH_DEBUGGER_GUI
448 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
449 void setDebuggerVar(int *piDbgCfgVar, bool fState);
450 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
451#endif
452
453 bool mValid;
454
455 CVirtualBox mVBox;
456 CHost mHost;
457
458 VBoxGlobalSettings gset;
459
460 UISelectorWindow *mSelectorWnd;
461 UIMachine *m_pVirtualMachine;
462
463 QString vmUuid;
464 QList<QUrl> m_ArgUrlList;
465
466 /** Whether to show error message boxes for VM start errors. */
467 bool mShowStartVMErrors;
468
469 QThread *mMediaEnumThread;
470 VBoxMediaList mMediaList;
471
472 RenderMode vm_render_mode;
473 const char * vm_render_mode_str;
474 bool mIsKWinManaged;
475
476 /** The --disable-patm option. */
477 bool mDisablePatm;
478 /** The --disable-csam option. */
479 bool mDisableCsam;
480 /** The --recompile-supervisor option. */
481 bool mRecompileSupervisor;
482 /** The --recompile-user option. */
483 bool mRecompileUser;
484 /** The --execute-all-in-iem option. */
485 bool mExecuteAllInIem;
486 /** The --warp-factor option value. */
487 uint32_t mWarpPct;
488
489#ifdef VBOX_WITH_DEBUGGER_GUI
490 /** Whether the debugger should be accessible or not.
491 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
492 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
493 int mDbgEnabled;
494 /** Whether to show the debugger automatically with the console.
495 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
496 int mDbgAutoShow;
497 /** Whether to show the command line window when mDbgAutoShow is set. */
498 int mDbgAutoShowCommandLine;
499 /** Whether to show the statistics window when mDbgAutoShow is set. */
500 int mDbgAutoShowStatistics;
501 /** VBoxDbg module handle. */
502 RTLDRMOD mhVBoxDbg;
503
504 /** Whether to start the VM in paused state or not. */
505 bool mStartPaused;
506#endif
507
508#if defined (Q_WS_WIN32)
509 DWORD dwHTMLHelpCookie;
510#endif
511
512 QString mVerString;
513 QString mBrandingConfig;
514
515 int m3DAvailable;
516
517 QList <QString> mFamilyIDs;
518 QList <QList <CGuestOSType> > mTypes;
519 QHash <QString, QPixmap *> mOsTypeIcons;
520
521 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
522
523 QString mDiskTypes_Differencing;
524
525 QString mUserDefinedPortName;
526
527 QPixmap mWarningIcon, mErrorIcon;
528
529 QFileIconProvider m_globalIconProvider;
530
531#ifdef VBOX_GUI_WITH_PIDFILE
532 QString m_strPidfile;
533#endif
534
535 char mSettingsPw[256];
536 bool mSettingsPwSet;
537
538 /* API: Instance stuff: */
539 static bool m_sfCleanupInProgress;
540 static VBoxGlobal* m_spInstance;
541 friend VBoxGlobal& vboxGlobal();
542};
543
544/* Shortcut to the static VBoxGlobal::instance() method: */
545inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
546
547#endif /* __VBoxGlobal_h__ */
548
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