VirtualBox

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

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

FE/Qt: X11: 5978: Adjusting mini-toolbar z-order for Mutter a bit, some weird x11 magic.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.5 KB
Line 
1/* $Id: VBoxGlobal.h 56932 2015-07-14 14:43:45Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - VBoxGlobal class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___VBoxGlobal_h___
19#define ___VBoxGlobal_h___
20
21/* Qt includes: */
22#include <QApplication>
23#include <QLayout>
24#include <QMenu>
25#include <QStyle>
26#include <QHash>
27#include <QFileIconProvider>
28#include <QReadWriteLock>
29#ifdef Q_WS_MAC
30# include <QSet>
31#endif /* Q_WS_MAC */
32
33/* GUI includes: */
34#include "UIDefs.h"
35#include "UIMediumDefs.h"
36#include "VBoxGlobalSettings.h"
37#ifdef Q_WS_X11
38# include "VBoxX11Helper.h"
39#endif /* Q_WS_X11 */
40
41/* COM includes: */
42#include "VBox/com/Guid.h"
43#include "CHost.h"
44#include "CVirtualBoxClient.h"
45#include "CVirtualBox.h"
46#include "CSession.h"
47#include "CGuestOSType.h"
48
49/* Forward declarations: */
50class QAction;
51class QLabel;
52class QToolButton;
53class UIMachine;
54class CMachine;
55class CMedium;
56class CUSBDevice;
57class CHostVideoInputDevice;
58class QSpinBox;
59class UIMediumEnumerator;
60class UIMedium;
61class UIIconPoolGeneral;
62
63// VBoxGlobal class
64////////////////////////////////////////////////////////////////////////////////
65
66class UISelectorWindow;
67class VBoxUpdateDlg;
68
69class VBoxGlobal : public QObject
70{
71 Q_OBJECT
72
73public:
74
75 /** VM launch modes. */
76 enum LaunchMode
77 {
78 LaunchMode_Default,
79 LaunchMode_Headless,
80 LaunchMode_Separate
81 };
82
83 /* Static API: Create/destroy stuff: */
84 static VBoxGlobal* instance();
85 static void create();
86 static void destroy();
87
88 bool isValid() { return mValid; }
89 bool isCleaningUp() { return m_sfCleanupInProgress; }
90
91 static QString qtRTVersionString();
92 static uint qtRTVersion();
93 static QString qtCTVersionString();
94 static uint qtCTVersion();
95
96 QString vboxVersionString() const;
97 QString vboxVersionStringNormalized() const;
98
99 QString versionString() const { return mVerString; }
100 bool isBeta() const;
101
102 /** Returns whether GUI is separate (from VM) process. */
103 bool isSeparateProcess() const { return m_fSeparateProcess; }
104
105#ifdef Q_WS_MAC
106 static MacOSXRelease osRelease();
107#endif /* Q_WS_MAC */
108
109 /** Returns the copy of VirtualBox client wrapper. */
110 CVirtualBoxClient virtualBoxClient() const { return m_client; }
111 /** Returns the copy of VirtualBox object wrapper. */
112 CVirtualBox virtualBox() const { return m_vbox; }
113 /** Returns the copy of VirtualBox host-object wrapper. */
114 CHost host() const { return m_host; }
115 /** Returns the symbolic VirtualBox home-folder representation. */
116 QString homeFolder() const { return m_strHomeFolder; }
117
118 /** Returns the VBoxSVC availability value. */
119 bool isVBoxSVCAvailable() const { return m_fVBoxSVCAvailable; }
120
121 VBoxGlobalSettings &settings() { return gset; }
122 bool setSettings (VBoxGlobalSettings &gs);
123
124 UISelectorWindow &selectorWnd();
125
126 /** Returns current virtual machine. */
127 UIMachine* virtualMachine() const;
128 /** Returns currently active virtual machine window. */
129 QWidget* activeMachineWindow() const;
130
131 bool is3DAvailableWorker() const;
132 bool is3DAvailable() const { if (m3DAvailable < 0) return is3DAvailableWorker(); return m3DAvailable != 0; }
133
134#ifdef VBOX_GUI_WITH_PIDFILE
135 void createPidfile();
136 void deletePidfile();
137#endif
138
139 /* branding */
140 bool brandingIsActive (bool aForce = false);
141 QString brandingGetKey (QString aKey);
142
143 bool processArgs();
144
145 bool switchToMachine(CMachine &machine);
146
147 bool launchMachine(CMachine &machine, LaunchMode enmLaunchMode = LaunchMode_Default);
148
149 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
150 bool showStartVMErrors() const { return mShowStartVMErrors; }
151 QString managedVMUuid() const { return vmUuid; }
152 QList<QUrl> &argUrlList() { return m_ArgUrlList; }
153
154#ifdef Q_WS_X11
155 /** X11: Returns the type of the Window Manager we are running under. */
156 X11WMType typeOfWindowManager() const { return m_enmWindowManagerType; }
157#endif /* Q_WS_X11 */
158
159 /** Returns whether we should restore current snapshot before VM started. */
160 bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
161 /** Defines whether we should fRestore current snapshot before VM started. */
162 void setShouldRestoreCurrentSnapshot(bool fRestore) { mRestoreCurrentSnapshot = fRestore; }
163
164 bool hasFloppyImageToMount() const { return !m_strFloppyImage.isEmpty(); }
165 bool hasDvdImageToMount() const { return !m_strDvdImage.isEmpty(); }
166 QString const &getFloppyImage() const { return m_strFloppyImage; }
167 QString const &getDvdImage() const { return m_strDvdImage; }
168
169 bool isPatmDisabled() const { return mDisablePatm; }
170 bool isCsamDisabled() const { return mDisableCsam; }
171 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
172 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
173 bool areWeToExecuteAllInIem() const { return mExecuteAllInIem; }
174 bool isDefaultWarpPct() const { return mWarpPct == 100; }
175 uint32_t getWarpPct() const { return mWarpPct; }
176
177#ifdef VBOX_WITH_DEBUGGER_GUI
178 bool isDebuggerEnabled() const;
179 bool isDebuggerAutoShowEnabled() const;
180 bool isDebuggerAutoShowCommandLineEnabled() const;
181 bool isDebuggerAutoShowStatisticsEnabled() const;
182
183 RTLDRMOD getDebuggerModule() const { return m_hVBoxDbg; }
184
185 bool isStartPausedEnabled() const { return mStartPaused; }
186#endif /* VBOX_WITH_DEBUGGER_GUI */
187
188 /* VBox enum to/from string/icon/color convertors */
189
190 QList <CGuestOSType> vmGuestOSFamilyList() const;
191 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
192
193 /** Returns pixmap corresponding to passed @a strOSTypeID.
194 * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
195 QPixmap vmGuestOSTypeIcon(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
196
197 CGuestOSType vmGuestOSType (const QString &aTypeId,
198 const QString &aFamilyId = QString::null) const;
199 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
200
201 static inline QString yearsToString (uint32_t cVal)
202 {
203 return tr("%n year(s)", "", cVal);
204 }
205
206 static inline QString monthsToString (uint32_t cVal)
207 {
208 return tr("%n month(s)", "", cVal);
209 }
210
211 static inline QString daysToString (uint32_t cVal)
212 {
213 return tr("%n day(s)", "", cVal);
214 }
215
216 static inline QString hoursToString (uint32_t cVal)
217 {
218 return tr("%n hour(s)", "", cVal);
219 }
220
221 static inline QString minutesToString (uint32_t cVal)
222 {
223 return tr("%n minute(s)", "", cVal);
224 }
225
226 static inline QString secondsToString (uint32_t cVal)
227 {
228 return tr("%n second(s)", "", cVal);
229 }
230
231 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
232
233 /**
234 * Similar to toString (KMediumType), but returns 'Differencing' for
235 * normal hard disks that have a parent.
236 */
237 QString mediumTypeString(const CMedium &medium) const;
238
239 QStringList COMPortNames() const;
240 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
241 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
242
243 QStringList LPTPortNames() const;
244 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
245 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
246
247 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
248 {
249 for (int i = 0; i < extList.size(); ++i)
250 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
251 return true;
252 return false;
253 }
254
255 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
256 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
257
258 QPixmap warningIcon() const { return mWarningIcon; }
259 QPixmap errorIcon() const { return mErrorIcon; }
260
261 /* details generators */
262
263 QString details(const CMedium &medium, bool fPredictDiff, bool fUseHtml = true);
264
265 QString details (const CUSBDevice &aDevice) const;
266 QString toolTip (const CUSBDevice &aDevice) const;
267 QString toolTip (const CUSBDeviceFilter &aFilter) const;
268 QString toolTip(const CHostVideoInputDevice &webcam) const;
269
270 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
271
272 /* VirtualBox helpers */
273
274 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
275
276 /** Shortcut to openSession (aId, true). */
277 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
278
279#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
280 void reloadProxySettings();
281#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
282
283 /* API: Medium-processing stuff: */
284 void createMedium(const UIMedium &medium);
285 void deleteMedium(const QString &strMediumID);
286 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
287 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
288 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
289
290 /* API: Medium-enumeration stuff: */
291 void startMediumEnumeration(bool fForceStart = true);
292 bool agressiveCaching() const { return mAgressiveCaching; }
293 bool isMediumEnumerationInProgress() const;
294 UIMedium medium(const QString &strMediumID) const;
295 QList<QString> mediumIDs() const;
296
297 /** Prepares storage menu according passed parameters.
298 * @param menu QMenu being prepared.
299 * @param pListener Listener QObject, this menu being prepared for.
300 * @param pszSlotName SLOT in the @a pListener above, this menu will be handled with.
301 * @param machine CMachine object, this menu being prepared for.
302 * @param strControllerName The name of the CStorageController in the @a machine above.
303 * @param storageSlot The StorageSlot of the CStorageController called @a strControllerName above. */
304 void prepareStorageMenu(QMenu &menu,
305 QObject *pListener, const char *pszSlotName,
306 const CMachine &machine, const QString &strControllerName, const StorageSlot &storageSlot);
307 /** Updates @a constMachine storage with data described by @a target. */
308 void updateMachineStorage(const CMachine &constMachine, const UIMediumTarget &target);
309
310 /* various helpers */
311
312 QString languageName() const;
313 QString languageCountry() const;
314 QString languageNameEnglish() const;
315 QString languageCountryEnglish() const;
316 QString languageTranslators() const;
317
318 void retranslateUi();
319
320 /* public static stuff */
321
322 static bool isDOSType (const QString &aOSTypeId);
323
324 static QString languageId();
325 static void loadLanguage (const QString &aLangId = QString::null);
326 QString helpFile() const;
327
328 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
329
330 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
331 bool aCanResize = true);
332 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
333 bool aCanResize = true);
334 static QRegion flip (const QRegion &aRegion);
335
336 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
337 bool aCanResize = true);
338
339 static QChar decimalSep();
340 static QString sizeRegexp();
341
342 static quint64 parseSize (const QString &);
343 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
344
345 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
346
347 static QString locationForHTML (const QString &aFileName);
348
349 static QString highlight (const QString &aStr, bool aToolTip = false);
350
351 static QString replaceHtmlEntities(QString strText);
352 static QString emphasize (const QString &aStr);
353
354 static QString systemLanguageId();
355
356 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
357
358#ifdef Q_WS_X11
359 /** X11: Test whether the current window manager supports full screen mode. */
360 static bool supportsFullScreenMonitorsProtocolX11();
361 /** X11: Performs mapping of the passed @a pWidget to host-screen with passed @a uScreenId. */
362 static bool setFullScreenMonitorX11(QWidget *pWidget, ulong uScreenId);
363 /** X11: Ensures @a pPropWidget become transient for the @a pWidget. */
364 static void setTransientFor(QWidget *pWidget, QWidget *pPropWidget);
365 /** X11: Represents @a pWidget as X11 tool-bar. */
366 static void representAsToolbar(QWidget *pWidget);
367#endif /* Q_WS_X11 */
368
369 static QString removeAccelMark (const QString &aText);
370
371 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
372
373 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
374
375 static QWidget *findWidget (QWidget *aParent, const char *aName,
376 const char *aClassName = NULL,
377 bool aRecursive = false);
378
379 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
380 static QList <QPair <QString, QString> > HDDBackends();
381 static QList <QPair <QString, QString> > DVDBackends();
382 static QList <QPair <QString, QString> > FloppyBackends();
383
384 static QString documentsPath();
385
386#ifdef VBOX_WITH_VIDEOHWACCEL
387 static bool isAcceleration2DVideoAvailable();
388
389 /** additional video memory required for the best 2D support performance
390 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
391 static quint64 required2DOffscreenVideoMemory();
392#endif
393
394#ifdef VBOX_WITH_CRHGSMI
395 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
396 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
397#endif /* VBOX_WITH_CRHGSMI */
398
399 /* Returns full medium-format name for the given base medium-format name: */
400 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
401
402
403#ifdef RT_OS_LINUX
404 static void checkForWrongUSBMounted();
405#endif /* RT_OS_LINUX */
406
407 /* Shame on Qt it hasn't stuff for tuning
408 * widget size suitable for reflecting content of desired size.
409 * For example QLineEdit, QSpinBox and similar widgets should have a methods
410 * to strict the minimum width to reflect at least [n] symbols. */
411 static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
412
413signals:
414
415 /** Notifies listeners about the VBoxSVC availability change. */
416 void sigVBoxSVCAvailabilityChange();
417
418 /* Notifiers: Medium-processing stuff: */
419 void sigMediumCreated(const QString &strMediumID);
420 void sigMediumDeleted(const QString &strMediumID);
421
422 /* Notifiers: Medium-enumeration stuff: */
423 void sigMediumEnumerationStarted();
424 void sigMediumEnumerated(const QString &strMediumID);
425 void sigMediumEnumerationFinished();
426
427public slots:
428
429 bool openURL (const QString &aURL);
430
431 void sltGUILanguageChange(QString strLang);
432 void sltProcessGlobalSettingChange();
433
434protected slots:
435
436 /* Handlers: Prepare/cleanup stuff: */
437 void prepare();
438 void cleanup();
439
440 /** Handles the VBoxSVC availability change. */
441 void sltHandleVBoxSVCAvailabilityChange(bool fAvailable);
442
443protected:
444
445 bool eventFilter (QObject *, QEvent *);
446
447private:
448
449 /* Constructor/destructor: */
450 VBoxGlobal();
451 ~VBoxGlobal();
452
453#ifdef VBOX_WITH_DEBUGGER_GUI
454 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
455 void setDebuggerVar(int *piDbgCfgVar, bool fState);
456 bool isDebuggerWorker(int *piDbgCfgVar, const char *pszExtraDataName) const;
457#endif
458
459 bool mValid;
460
461 /** Holds the instance of VirtualBox client wrapper. */
462 CVirtualBoxClient m_client;
463 /** Holds the copy of VirtualBox object wrapper. */
464 CVirtualBox m_vbox;
465 /** Holds the copy of VirtualBox host-object wrapper. */
466 CHost m_host;
467 /** Holds the symbolic VirtualBox home-folder representation. */
468 QString m_strHomeFolder;
469
470 /** Holds the VBoxSVC availability value. */
471 bool m_fVBoxSVCAvailable;
472
473 VBoxGlobalSettings gset;
474
475 UISelectorWindow *mSelectorWnd;
476
477 /** Holds whether GUI is separate (from VM) process. */
478 bool m_fSeparateProcess;
479
480 QString vmUuid;
481 QList<QUrl> m_ArgUrlList;
482
483 /** Whether to show error message boxes for VM start errors. */
484 bool mShowStartVMErrors;
485
486 /* Variable: Medium-enumeration stuff: */
487 UIMediumEnumerator *m_pMediumEnumerator;
488 mutable QReadWriteLock m_mediumEnumeratorDtorRwLock;
489
490#ifdef Q_WS_X11
491 /** X11: Holds the type of the Window Manager we are running under. */
492 X11WMType m_enmWindowManagerType;
493#endif /* Q_WS_X11 */
494
495 /** The --aggressive-caching / --no-aggressive-caching option. */
496 bool mAgressiveCaching;
497 /** The --restore-current option. */
498 bool mRestoreCurrentSnapshot;
499 /** @name Ad-hoc VM reconfiguration.
500 * @{ */
501 /** Floppy image. */
502 QString m_strFloppyImage;
503 /** DVD image. */
504 QString m_strDvdImage;
505 /** @} */
506 /** @name VMM options
507 * @{ */
508 /** The --disable-patm option. */
509 bool mDisablePatm;
510 /** The --disable-csam option. */
511 bool mDisableCsam;
512 /** The --recompile-supervisor option. */
513 bool mRecompileSupervisor;
514 /** The --recompile-user option. */
515 bool mRecompileUser;
516 /** The --execute-all-in-iem option. */
517 bool mExecuteAllInIem;
518 /** The --warp-factor option value. */
519 uint32_t mWarpPct;
520 /** @} */
521
522#ifdef VBOX_WITH_DEBUGGER_GUI
523 /** Whether the debugger should be accessible or not.
524 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED,
525 * --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
526 mutable int m_fDbgEnabled;
527 /** Whether to show the debugger automatically with the console.
528 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
529 mutable int m_fDbgAutoShow;
530 /** Whether to show the command line window when m_fDbgAutoShow is set. */
531 mutable int m_fDbgAutoShowCommandLine;
532 /** Whether to show the statistics window when m_fDbgAutoShow is set. */
533 mutable int m_fDbgAutoShowStatistics;
534 /** VBoxDbg module handle. */
535 RTLDRMOD m_hVBoxDbg;
536
537 /** Whether to start the VM in paused state or not. */
538 bool mStartPaused;
539#endif
540
541#if defined (Q_WS_WIN32)
542 DWORD dwHTMLHelpCookie;
543#endif
544
545 QString mVerString;
546 QString mBrandingConfig;
547
548 int m3DAvailable;
549
550 QList <QString> mFamilyIDs;
551 QList <QList <CGuestOSType> > mTypes;
552
553 QString mDiskTypes_Differencing;
554
555 QString mUserDefinedPortName;
556
557 QPixmap mWarningIcon, mErrorIcon;
558
559 QFileIconProvider m_globalIconProvider;
560
561#ifdef VBOX_GUI_WITH_PIDFILE
562 QString m_strPidfile;
563#endif
564
565 char mSettingsPw[256];
566 bool mSettingsPwSet;
567
568 /** General icon-pool. */
569 UIIconPoolGeneral *m_pIconPool;
570
571 /* API: Instance stuff: */
572 static bool m_sfCleanupInProgress;
573 static VBoxGlobal* m_spInstance;
574 friend VBoxGlobal& vboxGlobal();
575};
576
577/* Shortcut to the static VBoxGlobal::instance() method: */
578inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
579
580#endif /* !___VBoxGlobal_h___ */
581
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette