VirtualBox

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

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

FE/Qt: X11: Runtime UI: Mini-toolbar: Rework it to be window again, fixing conflicts with Unity panels for full-screen and seamless modes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.8 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 /** X11: Ensures @a pPropWidget become transient for the @a pWidget. */
326 static void setTransientFor(QWidget *pWidget, QWidget *pPropWidget);
327#endif /* Q_WS_X11 */
328
329 static QString removeAccelMark (const QString &aText);
330
331 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
332
333 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
334
335 static QWidget *findWidget (QWidget *aParent, const char *aName,
336 const char *aClassName = NULL,
337 bool aRecursive = false);
338
339 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
340 static QList <QPair <QString, QString> > HDDBackends();
341 static QList <QPair <QString, QString> > DVDBackends();
342 static QList <QPair <QString, QString> > FloppyBackends();
343
344 static QString documentsPath();
345
346#ifdef VBOX_WITH_VIDEOHWACCEL
347 static bool isAcceleration2DVideoAvailable();
348
349 /** additional video memory required for the best 2D support performance
350 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
351 static quint64 required2DOffscreenVideoMemory();
352#endif
353
354#ifdef VBOX_WITH_CRHGSMI
355 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
356 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
357#endif /* VBOX_WITH_CRHGSMI */
358
359 /* Returns full medium-format name for the given base medium-format name: */
360 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
361
362
363#ifdef RT_OS_LINUX
364 static void checkForWrongUSBMounted();
365#endif /* RT_OS_LINUX */
366
367 /* Shame on Qt it hasn't stuff for tuning
368 * widget size suitable for reflecting content of desired size.
369 * For example QLineEdit, QSpinBox and similar widgets should have a methods
370 * to strict the minimum width to reflect at least [n] symbols. */
371 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
372
373signals:
374
375 /* Notifiers: Medium-processing stuff: */
376 void sigMediumCreated(const QString &strMediumID);
377 void sigMediumDeleted(const QString &strMediumID);
378
379 /* Notifiers: Medium-enumeration stuff: */
380 void sigMediumEnumerationStarted();
381 void sigMediumEnumerated(const QString &strMediumID);
382 void sigMediumEnumerationFinished();
383
384public slots:
385
386 bool openURL (const QString &aURL);
387
388 void sltGUILanguageChange(QString strLang);
389 void sltProcessGlobalSettingChange();
390
391protected slots:
392
393 /* Handlers: Prepare/cleanup stuff: */
394 void prepare();
395 void cleanup();
396
397protected:
398
399 bool eventFilter (QObject *, QEvent *);
400
401private:
402
403 /* Constructor/destructor: */
404 VBoxGlobal();
405 ~VBoxGlobal();
406
407#ifdef VBOX_WITH_DEBUGGER_GUI
408 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
409 void setDebuggerVar(int *piDbgCfgVar, bool fState);
410 bool isDebuggerWorker(int *piDbgCfgVar, const char *pszExtraDataName) const;
411#endif
412
413 bool mValid;
414
415 CVirtualBox mVBox;
416 CHost mHost;
417
418 VBoxGlobalSettings gset;
419
420 UISelectorWindow *mSelectorWnd;
421 UIMachine *m_pVirtualMachine;
422
423 QString vmUuid;
424 QList<QUrl> m_ArgUrlList;
425
426 /** Whether to show error message boxes for VM start errors. */
427 bool mShowStartVMErrors;
428
429 /* Variable: Medium-enumeration stuff: */
430 UIMediumEnumerator *m_pMediumEnumerator;
431 mutable QReadWriteLock m_mediumEnumeratorDtorRwLock;
432
433 bool mIsKWinManaged;
434
435 /** The --aggressive-caching / --no-aggressive-caching option. */
436 bool mAgressiveCaching;
437 /** The --restore-current option. */
438 bool mRestoreCurrentSnapshot;
439 /** The --disable-patm option. */
440 bool mDisablePatm;
441 /** The --disable-csam option. */
442 bool mDisableCsam;
443 /** The --recompile-supervisor option. */
444 bool mRecompileSupervisor;
445 /** The --recompile-user option. */
446 bool mRecompileUser;
447 /** The --execute-all-in-iem option. */
448 bool mExecuteAllInIem;
449 /** The --warp-factor option value. */
450 uint32_t mWarpPct;
451
452#ifdef VBOX_WITH_DEBUGGER_GUI
453 /** Whether the debugger should be accessible or not.
454 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED,
455 * --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
456 mutable int m_fDbgEnabled;
457 /** Whether to show the debugger automatically with the console.
458 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
459 mutable int m_fDbgAutoShow;
460 /** Whether to show the command line window when m_fDbgAutoShow is set. */
461 mutable int m_fDbgAutoShowCommandLine;
462 /** Whether to show the statistics window when m_fDbgAutoShow is set. */
463 mutable int m_fDbgAutoShowStatistics;
464 /** VBoxDbg module handle. */
465 RTLDRMOD m_hVBoxDbg;
466
467 /** Whether to start the VM in paused state or not. */
468 bool mStartPaused;
469#endif
470
471#if defined (Q_WS_WIN32)
472 DWORD dwHTMLHelpCookie;
473#endif
474
475 QString mVerString;
476 QString mBrandingConfig;
477
478 int m3DAvailable;
479
480 QList <QString> mFamilyIDs;
481 QList <QList <CGuestOSType> > mTypes;
482
483 QString mDiskTypes_Differencing;
484
485 QString mUserDefinedPortName;
486
487 QPixmap mWarningIcon, mErrorIcon;
488
489 QFileIconProvider m_globalIconProvider;
490
491#ifdef VBOX_GUI_WITH_PIDFILE
492 QString m_strPidfile;
493#endif
494
495 char mSettingsPw[256];
496 bool mSettingsPwSet;
497
498 /** General icon-pool. */
499 UIIconPoolGeneral *m_pIconPool;
500
501 /* API: Instance stuff: */
502 static bool m_sfCleanupInProgress;
503 static VBoxGlobal* m_spInstance;
504 friend VBoxGlobal& vboxGlobal();
505};
506
507/* Shortcut to the static VBoxGlobal::instance() method: */
508inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
509
510#endif /* !___VBoxGlobal_h___ */
511
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