VirtualBox

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

Last change on this file since 52794 was 52794, checked in by vboxsync, 10 years ago

FE/Qt: X11: Runtime UI: Seamless mode: Calcualte available-regions using Qt again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.7 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 bool isKWinManaged() const { return mIsKWinManaged; }
129
130 bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
131 bool isPatmDisabled() const { return mDisablePatm; }
132 bool isCsamDisabled() const { return mDisableCsam; }
133 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
134 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
135 bool areWeToExecuteAllInIem() const { return mExecuteAllInIem; }
136 bool isDefaultWarpPct() const { return mWarpPct == 100; }
137 uint32_t getWarpPct() const { return mWarpPct; }
138
139#ifdef VBOX_WITH_DEBUGGER_GUI
140 bool isDebuggerEnabled() const;
141 bool isDebuggerAutoShowEnabled() const;
142 bool isDebuggerAutoShowCommandLineEnabled() const;
143 bool isDebuggerAutoShowStatisticsEnabled() const;
144
145 RTLDRMOD getDebuggerModule() const { return m_hVBoxDbg; }
146
147 bool isStartPausedEnabled() const { return mStartPaused; }
148#endif /* VBOX_WITH_DEBUGGER_GUI */
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
155 /** Returns pixmap corresponding to passed @a strOSTypeID.
156 * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
157 QPixmap vmGuestOSTypeIcon(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
158
159 CGuestOSType vmGuestOSType (const QString &aTypeId,
160 const QString &aFamilyId = QString::null) const;
161 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
162
163 static inline QString yearsToString (uint32_t cVal)
164 {
165 return tr("%n year(s)", "", cVal);
166 }
167
168 static inline QString monthsToString (uint32_t cVal)
169 {
170 return tr("%n month(s)", "", cVal);
171 }
172
173 static inline QString daysToString (uint32_t cVal)
174 {
175 return tr("%n day(s)", "", cVal);
176 }
177
178 static inline QString hoursToString (uint32_t cVal)
179 {
180 return tr("%n hour(s)", "", cVal);
181 }
182
183 static inline QString minutesToString (uint32_t cVal)
184 {
185 return tr("%n minute(s)", "", cVal);
186 }
187
188 static inline QString secondsToString (uint32_t cVal)
189 {
190 return tr("%n second(s)", "", cVal);
191 }
192
193 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
194
195 /**
196 * Similar to toString (KMediumType), but returns 'Differencing' for
197 * normal hard disks that have a parent.
198 */
199 QString mediumTypeString(const CMedium &medium) const;
200
201 QStringList COMPortNames() const;
202 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
203 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
204
205 QStringList LPTPortNames() const;
206 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
207 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
208
209 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
210 {
211 for (int i = 0; i < extList.size(); ++i)
212 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
213 return true;
214 return false;
215 }
216
217 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
218 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
219
220 QPixmap warningIcon() const { return mWarningIcon; }
221 QPixmap errorIcon() const { return mErrorIcon; }
222
223 /* details generators */
224
225 QString details(const CMedium &medium, bool fPredictDiff, bool fUseHtml = true);
226
227 QString details (const CUSBDevice &aDevice) const;
228 QString toolTip (const CUSBDevice &aDevice) const;
229 QString toolTip (const CUSBDeviceFilter &aFilter) const;
230 QString toolTip(const CHostVideoInputDevice &webcam) 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#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
242 void reloadProxySettings();
243#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
244
245 /* API: Medium-processing stuff: */
246 void createMedium(const UIMedium &medium);
247 void deleteMedium(const QString &strMediumID);
248 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
249 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
250 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
251
252 /* API: Medium-enumeration stuff: */
253 void startMediumEnumeration(bool fForceStart = true);
254 bool agressiveCaching() const { return mAgressiveCaching; }
255 bool isMediumEnumerationInProgress() const;
256 UIMedium medium(const QString &strMediumID) const;
257 QList<QString> mediumIDs() const;
258
259 /** Prepares storage menu according passed parameters.
260 * @param menu QMenu being prepared.
261 * @param pListener Listener QObject, this menu being prepared for.
262 * @param pszSlotName SLOT in the @a pListener above, this menu will be handled with.
263 * @param machine CMachine object, this menu being prepared for.
264 * @param strControllerName The name of the CStorageController in the @a machine above.
265 * @param storageSlot The StorageSlot of the CStorageController called @a strControllerName above. */
266 void prepareStorageMenu(QMenu &menu,
267 QObject *pListener, const char *pszSlotName,
268 const CMachine &machine, const QString &strControllerName, const StorageSlot &storageSlot);
269 /** Updates @a constMachine storage with data described by @a target. */
270 void updateMachineStorage(const CMachine &constMachine, const UIMediumTarget &target);
271
272 /* various helpers */
273
274 QString languageName() const;
275 QString languageCountry() const;
276 QString languageNameEnglish() const;
277 QString languageCountryEnglish() const;
278 QString languageTranslators() const;
279
280 void retranslateUi();
281
282 /* public static stuff */
283
284 static bool isDOSType (const QString &aOSTypeId);
285
286 static QString languageId();
287 static void loadLanguage (const QString &aLangId = QString::null);
288 QString helpFile() const;
289
290 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
291
292 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
293 bool aCanResize = true);
294 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
295 bool aCanResize = true);
296 static QRegion flip (const QRegion &aRegion);
297
298 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
299 bool aCanResize = true);
300
301 static QChar decimalSep();
302 static QString sizeRegexp();
303
304 static quint64 parseSize (const QString &);
305 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
306
307 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
308
309 static QString locationForHTML (const QString &aFileName);
310
311 static QString highlight (const QString &aStr, bool aToolTip = false);
312
313 static QString replaceHtmlEntities(QString strText);
314 static QString emphasize (const QString &aStr);
315
316 static QString systemLanguageId();
317
318 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
319
320#ifdef Q_WS_X11
321 /** X11: Test whether the current window manager supports full screen mode. */
322 static bool supportsFullScreenMonitorsProtocolX11();
323 /** X11: Performs mapping of the passed @a pWidget to host-screen with passed @a uScreenId. */
324 static bool setFullScreenMonitorX11(QWidget *pWidget, ulong uScreenId);
325#endif /* Q_WS_X11 */
326
327 static QString removeAccelMark (const QString &aText);
328
329 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
330
331 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
332
333 static QWidget *findWidget (QWidget *aParent, const char *aName,
334 const char *aClassName = NULL,
335 bool aRecursive = false);
336
337 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
338 static QList <QPair <QString, QString> > HDDBackends();
339 static QList <QPair <QString, QString> > DVDBackends();
340 static QList <QPair <QString, QString> > FloppyBackends();
341
342 static QString documentsPath();
343
344#ifdef VBOX_WITH_VIDEOHWACCEL
345 static bool isAcceleration2DVideoAvailable();
346
347 /** additional video memory required for the best 2D support performance
348 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
349 static quint64 required2DOffscreenVideoMemory();
350#endif
351
352#ifdef VBOX_WITH_CRHGSMI
353 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
354 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
355#endif /* VBOX_WITH_CRHGSMI */
356
357 /* Returns full medium-format name for the given base medium-format name: */
358 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
359
360
361#ifdef RT_OS_LINUX
362 static void checkForWrongUSBMounted();
363#endif /* RT_OS_LINUX */
364
365 /* Shame on Qt it hasn't stuff for tuning
366 * widget size suitable for reflecting content of desired size.
367 * For example QLineEdit, QSpinBox and similar widgets should have a methods
368 * to strict the minimum width to reflect at least [n] symbols. */
369 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
370
371signals:
372
373 /* Notifiers: Medium-processing stuff: */
374 void sigMediumCreated(const QString &strMediumID);
375 void sigMediumDeleted(const QString &strMediumID);
376
377 /* Notifiers: Medium-enumeration stuff: */
378 void sigMediumEnumerationStarted();
379 void sigMediumEnumerated(const QString &strMediumID);
380 void sigMediumEnumerationFinished();
381
382public slots:
383
384 bool openURL (const QString &aURL);
385
386 void sltGUILanguageChange(QString strLang);
387 void sltProcessGlobalSettingChange();
388
389protected slots:
390
391 /* Handlers: Prepare/cleanup stuff: */
392 void prepare();
393 void cleanup();
394
395protected:
396
397 bool eventFilter (QObject *, QEvent *);
398
399private:
400
401 /* Constructor/destructor: */
402 VBoxGlobal();
403 ~VBoxGlobal();
404
405#ifdef VBOX_WITH_DEBUGGER_GUI
406 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
407 void setDebuggerVar(int *piDbgCfgVar, bool fState);
408 bool isDebuggerWorker(int *piDbgCfgVar, const char *pszExtraDataName) const;
409#endif
410
411 bool mValid;
412
413 CVirtualBox mVBox;
414 CHost mHost;
415
416 VBoxGlobalSettings gset;
417
418 UISelectorWindow *mSelectorWnd;
419 UIMachine *m_pVirtualMachine;
420
421 QString vmUuid;
422 QList<QUrl> m_ArgUrlList;
423
424 /** Whether to show error message boxes for VM start errors. */
425 bool mShowStartVMErrors;
426
427 /* Variable: Medium-enumeration stuff: */
428 UIMediumEnumerator *m_pMediumEnumerator;
429 mutable QReadWriteLock m_mediumEnumeratorDtorRwLock;
430
431 bool mIsKWinManaged;
432
433 /** The --aggressive-caching / --no-aggressive-caching option. */
434 bool mAgressiveCaching;
435 /** The --restore-current option. */
436 bool mRestoreCurrentSnapshot;
437 /** The --disable-patm option. */
438 bool mDisablePatm;
439 /** The --disable-csam option. */
440 bool mDisableCsam;
441 /** The --recompile-supervisor option. */
442 bool mRecompileSupervisor;
443 /** The --recompile-user option. */
444 bool mRecompileUser;
445 /** The --execute-all-in-iem option. */
446 bool mExecuteAllInIem;
447 /** The --warp-factor option value. */
448 uint32_t mWarpPct;
449
450#ifdef VBOX_WITH_DEBUGGER_GUI
451 /** Whether the debugger should be accessible or not.
452 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED,
453 * --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
454 mutable int m_fDbgEnabled;
455 /** Whether to show the debugger automatically with the console.
456 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
457 mutable int m_fDbgAutoShow;
458 /** Whether to show the command line window when m_fDbgAutoShow is set. */
459 mutable int m_fDbgAutoShowCommandLine;
460 /** Whether to show the statistics window when m_fDbgAutoShow is set. */
461 mutable int m_fDbgAutoShowStatistics;
462 /** VBoxDbg module handle. */
463 RTLDRMOD m_hVBoxDbg;
464
465 /** Whether to start the VM in paused state or not. */
466 bool mStartPaused;
467#endif
468
469#if defined (Q_WS_WIN32)
470 DWORD dwHTMLHelpCookie;
471#endif
472
473 QString mVerString;
474 QString mBrandingConfig;
475
476 int m3DAvailable;
477
478 QList <QString> mFamilyIDs;
479 QList <QList <CGuestOSType> > mTypes;
480
481 QString mDiskTypes_Differencing;
482
483 QString mUserDefinedPortName;
484
485 QPixmap mWarningIcon, mErrorIcon;
486
487 QFileIconProvider m_globalIconProvider;
488
489#ifdef VBOX_GUI_WITH_PIDFILE
490 QString m_strPidfile;
491#endif
492
493 char mSettingsPw[256];
494 bool mSettingsPwSet;
495
496 /** General icon-pool. */
497 UIIconPoolGeneral *m_pIconPool;
498
499 /* API: Instance stuff: */
500 static bool m_sfCleanupInProgress;
501 static VBoxGlobal* m_spInstance;
502 friend VBoxGlobal& vboxGlobal();
503};
504
505/* Shortcut to the static VBoxGlobal::instance() method: */
506inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
507
508#endif /* !___VBoxGlobal_h___ */
509
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