VirtualBox

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

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

FE/Qt: Fixed --start-running behavior.

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