VirtualBox

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

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

VirtualBox: Added --fdc <image|none> and --dvd <image|none> from VBoxSDL.

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