VirtualBox

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

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

FE/Qt: 6909: Medium-enumeration cleanup (part 4).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 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 shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
127 bool isPatmDisabled() const { return mDisablePatm; }
128 bool isCsamDisabled() const { return mDisableCsam; }
129 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
130 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
131 bool areWeToExecuteAllInIem() const { return mExecuteAllInIem; }
132 bool isDefaultWarpPct() const { return mWarpPct == 100; }
133 uint32_t getWarpPct() const { return mWarpPct; }
134
135#ifdef VBOX_WITH_DEBUGGER_GUI
136 bool isDebuggerEnabled(CMachine &aMachine);
137 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
138 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
139 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
140 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
141
142 bool isStartPausedEnabled() const { return mStartPaused; }
143#else
144 bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
145 bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
146 bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
147
148 bool isStartPausedEnabled() const { return false; }
149#endif
150
151 /* VBox enum to/from string/icon/color convertors */
152
153 QList <CGuestOSType> vmGuestOSFamilyList() const;
154 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
155 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
156 CGuestOSType vmGuestOSType (const QString &aTypeId,
157 const QString &aFamilyId = QString::null) const;
158 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
159
160 static inline QString yearsToString (uint32_t cVal)
161 {
162 return tr("%n year(s)", "", cVal);
163 }
164
165 static inline QString monthsToString (uint32_t cVal)
166 {
167 return tr("%n month(s)", "", cVal);
168 }
169
170 static inline QString daysToString (uint32_t cVal)
171 {
172 return tr("%n day(s)", "", cVal);
173 }
174
175 static inline QString hoursToString (uint32_t cVal)
176 {
177 return tr("%n hour(s)", "", cVal);
178 }
179
180 static inline QString minutesToString (uint32_t cVal)
181 {
182 return tr("%n minute(s)", "", cVal);
183 }
184
185 static inline QString secondsToString (uint32_t cVal)
186 {
187 return tr("%n second(s)", "", cVal);
188 }
189
190 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
191
192 /**
193 * Similar to toString (KMediumType), but returns 'Differencing' for
194 * normal hard disks that have a parent.
195 */
196 QString mediumTypeString(const CMedium &medium) const;
197
198 QStringList COMPortNames() const;
199 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
200 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
201
202 QStringList LPTPortNames() const;
203 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
204 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
205
206 QPixmap snapshotIcon (bool online) const
207 {
208 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
209 }
210
211 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
212 {
213 for (int i = 0; i < extList.size(); ++i)
214 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
215 return true;
216 return false;
217 }
218
219 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
220 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
221
222 QPixmap warningIcon() const { return mWarningIcon; }
223 QPixmap errorIcon() const { return mErrorIcon; }
224
225 /* details generators */
226
227 QString details (const CMedium &aHD, bool aPredictDiff, bool fUseHtml = true);
228
229 QString details (const CUSBDevice &aDevice) const;
230 QString toolTip (const CUSBDevice &aDevice) const;
231 QString toolTip (const CUSBDeviceFilter &aFilter) const;
232
233 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
234
235 /* VirtualBox helpers */
236
237 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
238
239 /** Shortcut to openSession (aId, true). */
240 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
241
242 void reloadProxySettings();
243
244 /* API: Medium-enumeration stuff: */
245 void startEnumeratingMedia(bool fForceStart = true);
246 bool agressiveCaching() const { return mAgressiveCaching; }
247 bool isMediaEnumerationStarted() const { return !!m_pMediumEnumerationThread; }
248 const VBoxMediaList &currentMediaList() const { return m_mediums; }
249
250 void addMedium (const UIMedium &);
251 void updateMedium (const UIMedium &);
252 void removeMedium (UIMediumType, const QString &);
253
254 bool findMedium (const CMedium &, UIMedium &) const;
255 UIMedium findMedium (const QString &aMediumId) const;
256
257 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
258 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
259 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
260
261 /* Returns the number of current running Fe/Qt4 main windows. */
262 int mainWindowCount();
263
264 /* various helpers */
265
266 QString languageName() const;
267 QString languageCountry() const;
268 QString languageNameEnglish() const;
269 QString languageCountryEnglish() const;
270 QString languageTranslators() const;
271
272 void retranslateUi();
273
274 /* public static stuff */
275
276 static bool isDOSType (const QString &aOSTypeId);
277
278 static QString languageId();
279 static void loadLanguage (const QString &aLangId = QString::null);
280 QString helpFile() const;
281
282 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
283
284 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
285 bool aCanResize = true);
286 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
287 bool aCanResize = true);
288 static QRegion flip (const QRegion &aRegion);
289
290 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
291 bool aCanResize = true);
292
293 static QChar decimalSep();
294 static QString sizeRegexp();
295
296 static quint64 parseSize (const QString &);
297 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
298
299 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
300
301 static QString locationForHTML (const QString &aFileName);
302
303 static QString highlight (const QString &aStr, bool aToolTip = false);
304
305 static QString replaceHtmlEntities(QString strText);
306 static QString emphasize (const QString &aStr);
307
308 static QString systemLanguageId();
309
310 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
311
312 static QString removeAccelMark (const QString &aText);
313
314 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
315 static QString extractKeyFromActionText (const QString &aText);
316
317 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
318
319 static QWidget *findWidget (QWidget *aParent, const char *aName,
320 const char *aClassName = NULL,
321 bool aRecursive = false);
322
323 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
324 static QList <QPair <QString, QString> > HDDBackends();
325 static QList <QPair <QString, QString> > DVDBackends();
326 static QList <QPair <QString, QString> > FloppyBackends();
327
328 static QString documentsPath();
329
330#ifdef VBOX_WITH_VIDEOHWACCEL
331 static bool isAcceleration2DVideoAvailable();
332
333 /** additional video memory required for the best 2D support performance
334 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
335 static quint64 required2DOffscreenVideoMemory();
336#endif
337
338#ifdef VBOX_WITH_CRHGSMI
339 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
340 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
341#endif /* VBOX_WITH_CRHGSMI */
342
343 /* Returns full medium-format name for the given base medium-format name: */
344 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
345
346 /* Extra-data settings stuff: */
347 static bool isApprovedByExtraData(CVirtualBox &vbox, const QString &strExtraDataKey);
348 static bool isApprovedByExtraData(CMachine &machine, const QString &strExtraDataKey);
349 static bool shouldWeAllowApplicationUpdate(CVirtualBox &vbox);
350 static bool shouldWeShowMachine(CMachine &machine);
351 static bool shouldWeAllowMachineReconfiguration(CMachine &machine,
352 bool fIncludingMachineGeneralCheck = false,
353 bool fIncludingMachineStateCheck = false);
354 static bool shouldWeShowDetails(CMachine &machine,
355 bool fIncludingMachineGeneralCheck = false);
356 static bool shouldWeAutoMountGuestScreens(CMachine &machine, bool fIncludingSanityCheck = true);
357 static bool shouldWeAllowSnapshotOperations(CMachine &machine, bool fIncludingSanityCheck = true);
358 static RuntimeMenuType restrictedRuntimeMenuTypes(CMachine &machine);
359 static UIVisualStateType restrictedVisualStateTypes(CMachine &machine);
360 static QList<IndicatorType> restrictedStatusBarIndicators(CMachine &machine);
361 static QList<MachineCloseAction> restrictedMachineCloseActions(CMachine &machine);
362 static QList<GlobalSettingsPageType> restrictedGlobalSettingsPages(CVirtualBox &vbox);
363 static QList<MachineSettingsPageType> restrictedMachineSettingsPages(CMachine &machine);
364
365#ifdef RT_OS_LINUX
366 static void checkForWrongUSBMounted();
367#endif /* RT_OS_LINUX */
368
369 /* Shame on Qt it hasn't stuff for tuning
370 * widget size suitable for reflecting content of desired size.
371 * For example QLineEdit, QSpinBox and similar widgets should have a methods
372 * to strict the minimum width to reflect at least [n] symbols. */
373 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
374
375signals:
376
377 /* Notifiers: Medium-enumeration stuff: */
378 void sigMediumEnumerationStarted();
379 void sigMediumEnumerated(const UIMedium &medium);
380 void sigMediumEnumerationFinished(const VBoxMediaList &mediums);
381
382 /** Emitted when a new media is added using #addMedia(). */
383 void mediumAdded (const UIMedium &);
384
385 /** Emitted when the media is updated using #updateMedia(). */
386 void mediumUpdated (const UIMedium &);
387
388 /** Emitted when the media is removed using #removeMedia(). */
389 void mediumRemoved (UIMediumType, const QString &);
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 event (QEvent *e);
407 bool eventFilter (QObject *, QEvent *);
408
409private:
410
411 /* Constructor/destructor: */
412 VBoxGlobal();
413 ~VBoxGlobal();
414
415#ifdef VBOX_WITH_DEBUGGER_GUI
416 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
417 void setDebuggerVar(int *piDbgCfgVar, bool fState);
418 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
419#endif
420
421 bool mValid;
422
423 CVirtualBox mVBox;
424 CHost mHost;
425
426 VBoxGlobalSettings gset;
427
428 UISelectorWindow *mSelectorWnd;
429 UIMachine *m_pVirtualMachine;
430
431 QString vmUuid;
432 QList<QUrl> m_ArgUrlList;
433
434 /** Whether to show error message boxes for VM start errors. */
435 bool mShowStartVMErrors;
436
437 QThread *m_pMediumEnumerationThread;
438 VBoxMediaList m_mediums;
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 QHash <QString, QPixmap *> mOsTypeIcons;
492
493 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
494
495 QString mDiskTypes_Differencing;
496
497 QString mUserDefinedPortName;
498
499 QPixmap mWarningIcon, mErrorIcon;
500
501 QFileIconProvider m_globalIconProvider;
502
503#ifdef VBOX_GUI_WITH_PIDFILE
504 QString m_strPidfile;
505#endif
506
507 char mSettingsPw[256];
508 bool mSettingsPwSet;
509
510 /* API: Instance stuff: */
511 static bool m_sfCleanupInProgress;
512 static VBoxGlobal* m_spInstance;
513 friend VBoxGlobal& vboxGlobal();
514};
515
516/* Shortcut to the static VBoxGlobal::instance() method: */
517inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
518
519#endif /* __VBoxGlobal_h__ */
520
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