VirtualBox

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

Last change on this file since 42998 was 42665, checked in by vboxsync, 12 years ago

VirtualBox(GUI): Added --warp-pct <pct> factor for debugging purposes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.1 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2011 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef __VBoxGlobal_h__
20#define __VBoxGlobal_h__
21
22/* Qt includes: */
23#include <QApplication>
24#include <QLayout>
25#include <QMenu>
26#include <QStyle>
27#include <QHash>
28#include <QFileIconProvider>
29
30/* GUI includes: */
31#include "UIDefs.h"
32#include "VBoxGlobalSettings.h"
33#include "UIMedium.h"
34
35/* COM includes: */
36#include "VBox/com/Guid.h"
37#include "CHost.h"
38#include "CVirtualBox.h"
39#include "CSession.h"
40#include "CGuestOSType.h"
41
42/* Forward declarations: */
43class QAction;
44class QLabel;
45class QToolButton;
46class UIMachine;
47class CMachine;
48class CMedium;
49class CUSBDevice;
50
51// VBoxGlobal class
52////////////////////////////////////////////////////////////////////////////////
53
54class UISelectorWindow;
55class UIRegistrationWzd;
56class VBoxUpdateDlg;
57
58class VBoxGlobal : public QObject
59{
60 Q_OBJECT
61
62public:
63
64 static VBoxGlobal &instance();
65
66 bool isValid() { return mValid; }
67
68 static QString qtRTVersionString();
69 static uint qtRTVersion();
70 static QString qtCTVersionString();
71 static uint qtCTVersion();
72
73 QString vboxVersionString() const;
74 QString vboxVersionStringNormalized() const;
75
76 QString versionString() const { return mVerString; }
77 bool isBeta() const;
78
79 CVirtualBox virtualBox() const { return mVBox; }
80 CHost host() const { return mHost; }
81
82 VBoxGlobalSettings &settings() { return gset; }
83 bool setSettings (VBoxGlobalSettings &gs);
84
85 UISelectorWindow &selectorWnd();
86
87 /* VM stuff: */
88 bool startMachine(const QString &strMachineId);
89 UIMachine* virtualMachine();
90 QWidget* vmWindow();
91
92 /* Main application window storage: */
93 void setMainWindow(QWidget *pMainWindow) { mMainWindow = pMainWindow; }
94 QWidget* mainWindow() const { return mMainWindow; }
95
96 bool is3DAvailable() const { return m3DAvailable; }
97
98#ifdef VBOX_GUI_WITH_PIDFILE
99 void createPidfile();
100 void deletePidfile();
101#endif
102
103 /* branding */
104 bool brandingIsActive (bool aForce = false);
105 QString brandingGetKey (QString aKey);
106
107 bool processArgs();
108
109 bool switchToMachine(CMachine &machine);
110 bool launchMachine(CMachine &machine, bool fHeadless = false);
111
112 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
113 bool showStartVMErrors() const { return mShowStartVMErrors; }
114#ifdef VBOX_GUI_WITH_SYSTRAY
115 bool isTrayMenu() const;
116 void setTrayMenu(bool aIsTrayMenu);
117 void trayIconShowSelector();
118 bool trayIconInstall();
119#endif
120 QString managedVMUuid() const { return vmUuid; }
121 QList<QUrl> &argUrlList() { return m_ArgUrlList; }
122
123 RenderMode vmRenderMode() const { return vm_render_mode; }
124 const char *vmRenderModeStr() const { return vm_render_mode_str; }
125 bool isKWinManaged() const { return mIsKWinManaged; }
126
127 const QRect availableGeometry(int iScreen = 0) const;
128
129 bool isPatmDisabled() const { return mDisablePatm; }
130 bool isCsamDisabled() const { return mDisableCsam; }
131 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
132 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
133 bool isDefaultWarpPct() const { return mWarpPct == 100; }
134 uint32_t getWarpPct() const { return mWarpPct; }
135
136#ifdef VBOX_WITH_DEBUGGER_GUI
137 bool isDebuggerEnabled(CMachine &aMachine);
138 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
139 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
140 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
141 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
142
143 bool isStartPausedEnabled() const { return mStartPaused; }
144#else
145 bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
146 bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
147 bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
148
149 bool isStartPausedEnabled() const { return false; }
150#endif
151
152 /* VBox enum to/from string/icon/color convertors */
153
154 QList <CGuestOSType> vmGuestOSFamilyList() const;
155 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
156 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
157 CGuestOSType vmGuestOSType (const QString &aTypeId,
158 const QString &aFamilyId = QString::null) const;
159 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
160
161 static inline QString yearsToString (uint32_t cVal)
162 {
163 return tr("%n year(s)", "", cVal);
164 }
165
166 static inline QString monthsToString (uint32_t cVal)
167 {
168 return tr("%n month(s)", "", cVal);
169 }
170
171 static inline QString daysToString (uint32_t cVal)
172 {
173 return tr("%n day(s)", "", cVal);
174 }
175
176 static inline QString hoursToString (uint32_t cVal)
177 {
178 return tr("%n hour(s)", "", cVal);
179 }
180
181 static inline QString minutesToString (uint32_t cVal)
182 {
183 return tr("%n minute(s)", "", cVal);
184 }
185
186 static inline QString secondsToString (uint32_t cVal)
187 {
188 return tr("%n second(s)", "", cVal);
189 }
190
191 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
192
193 /**
194 * Similar to toString (KMediumType), but returns 'Differencing' for
195 * normal hard disks that have a parent.
196 */
197 QString mediumTypeString(const CMedium &medium) const;
198
199 QStringList COMPortNames() const;
200 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
201 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
202
203 QStringList LPTPortNames() const;
204 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
205 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
206
207 QPixmap snapshotIcon (bool online) const
208 {
209 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
210 }
211
212 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
213 {
214 for (int i = 0; i < extList.size(); ++i)
215 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
216 return true;
217 return false;
218 }
219
220 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
221 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
222
223 QPixmap warningIcon() const { return mWarningIcon; }
224 QPixmap errorIcon() const { return mErrorIcon; }
225
226 /* details generators */
227
228 QString details (const CMedium &aHD, bool aPredictDiff, bool fUseHtml = true);
229
230 QString details (const CUSBDevice &aDevice) const;
231 QString toolTip (const CUSBDevice &aDevice) const;
232 QString toolTip (const CUSBDeviceFilter &aFilter) const;
233
234 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
235
236 /* VirtualBox helpers */
237
238#if defined(Q_WS_X11) && !defined(VBOX_OSE)
239 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
240 bool showVirtualBoxLicense();
241#endif
242
243 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
244
245 /** Shortcut to openSession (aId, true). */
246 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
247
248 void startEnumeratingMedia();
249
250 void reloadProxySettings();
251
252 /**
253 * Returns a list of all currently registered media. This list is used to
254 * globally track the accessibility state of all media on a dedicated thread.
255 *
256 * Note that the media list is initially empty (i.e. before the enumeration
257 * process is started for the first time using #startEnumeratingMedia()).
258 * See #startEnumeratingMedia() for more information about how meida are
259 * sorted in the returned list.
260 */
261 const VBoxMediaList &currentMediaList() const { return mMediaList; }
262
263 /** Returns true if the media enumeration is in progress. */
264 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
265
266 void addMedium (const UIMedium &);
267 void updateMedium (const UIMedium &);
268 void removeMedium (UIMediumType, const QString &);
269
270 bool findMedium (const CMedium &, UIMedium &) const;
271 UIMedium findMedium (const QString &aMediumId) const;
272
273 /** Compact version of #findMediumTo(). Asserts if not found. */
274 UIMedium getMedium (const CMedium &aObj) const
275 {
276 UIMedium medium;
277 if (!findMedium (aObj, medium))
278 AssertFailed();
279 return medium;
280 }
281
282 QString openMediumWithFileOpenDialog(UIMediumType mediumType, QWidget *pParent = 0,
283 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
284 QString openMedium(UIMediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
285
286 /* Returns the number of current running Fe/Qt4 main windows. */
287 int mainWindowCount();
288
289 /* various helpers */
290
291 QString languageName() const;
292 QString languageCountry() const;
293 QString languageNameEnglish() const;
294 QString languageCountryEnglish() const;
295 QString languageTranslators() const;
296
297 void retranslateUi();
298
299 /** @internal made public for internal purposes */
300 void cleanup();
301
302 /* public static stuff */
303
304 static bool isDOSType (const QString &aOSTypeId);
305
306 static QString languageId();
307 static void loadLanguage (const QString &aLangId = QString::null);
308 QString helpFile() const;
309
310 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
311
312 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
313 bool aCanResize = true);
314 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
315 bool aCanResize = true);
316 static QRegion flip (const QRegion &aRegion);
317
318 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
319 bool aCanResize = true);
320
321 static QChar decimalSep();
322 static QString sizeRegexp();
323
324 static QString toHumanReadableList(const QStringList &list);
325
326 static quint64 parseSize (const QString &);
327 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
328
329 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
330
331 static QString locationForHTML (const QString &aFileName);
332
333 static QString highlight (const QString &aStr, bool aToolTip = false);
334
335 static QString replaceHtmlEntities(QString strText);
336 static QString emphasize (const QString &aStr);
337
338 static QString systemLanguageId();
339
340 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
341
342 static QString removeAccelMark (const QString &aText);
343
344 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
345 static QString extractKeyFromActionText (const QString &aText);
346
347 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
348
349 static QWidget *findWidget (QWidget *aParent, const char *aName,
350 const char *aClassName = NULL,
351 bool aRecursive = false);
352
353 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
354 static QList <QPair <QString, QString> > HDDBackends();
355 static QList <QPair <QString, QString> > DVDBackends();
356 static QList <QPair <QString, QString> > FloppyBackends();
357
358 /* Qt 4.2.0 support function */
359 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
360 {
361#if QT_VERSION < 0x040300
362 /* Deprecated since > 4.2 */
363 aLayout->setMargin (aMargin);
364#else
365 /* New since > 4.2 */
366 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
367#endif
368 }
369
370 static QString documentsPath();
371
372#ifdef VBOX_WITH_VIDEOHWACCEL
373 static bool isAcceleration2DVideoAvailable();
374
375 /** additional video memory required for the best 2D support performance
376 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
377 static quint64 required2DOffscreenVideoMemory();
378#endif
379
380#ifdef VBOX_WITH_CRHGSMI
381 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
382 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
383#endif /* VBOX_WITH_CRHGSMI */
384
385#ifdef Q_WS_MAC
386 bool isSheetWindowsAllowed(QWidget *pParent) const;
387#endif /* Q_WS_MAC */
388
389 /* Returns full medium-format name for the given base medium-format name: */
390 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
391
392signals:
393
394 /**
395 * Emitted at the beginning of the enumeration process started by
396 * #startEnumeratingMedia().
397 */
398 void mediumEnumStarted();
399
400 /**
401 * Emitted when a new medium item from the list has updated its
402 * accessibility state.
403 */
404 void mediumEnumerated (const UIMedium &aMedum);
405
406 /**
407 * Emitted at the end of the enumeration process started by
408 * #startEnumeratingMedia(). The @a aList argument is passed for
409 * convenience, it is exactly the same as returned by #currentMediaList().
410 */
411 void mediumEnumFinished (const VBoxMediaList &aList);
412
413 /** Emitted when a new media is added using #addMedia(). */
414 void mediumAdded (const UIMedium &);
415
416 /** Emitted when the media is updated using #updateMedia(). */
417 void mediumUpdated (const UIMedium &);
418
419 /** Emitted when the media is removed using #removeMedia(). */
420 void mediumRemoved (UIMediumType, const QString &);
421
422#ifdef VBOX_GUI_WITH_SYSTRAY
423 void sigTrayIconShow(bool fEnabled);
424#endif
425
426public slots:
427
428 bool openURL (const QString &aURL);
429
430 void showRegistrationDialog (bool aForce = true);
431 void sltGUILanguageChange(QString strLang);
432 void sltProcessGlobalSettingChange();
433
434protected:
435
436 bool event (QEvent *e);
437 bool eventFilter (QObject *, QEvent *);
438
439private:
440
441 VBoxGlobal();
442 ~VBoxGlobal();
443
444 void init();
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, CMachine &rMachine, const char *pszExtraDataName);
449#endif
450
451 bool mValid;
452
453 CVirtualBox mVBox;
454 CHost mHost;
455
456 VBoxGlobalSettings gset;
457
458 UISelectorWindow *mSelectorWnd;
459 UIMachine *m_pVirtualMachine;
460 QWidget* mMainWindow;
461
462#ifdef VBOX_WITH_REGISTRATION
463 UIRegistrationWzd *mRegDlg;
464#endif
465
466 QString vmUuid;
467 QList<QUrl> m_ArgUrlList;
468
469#ifdef VBOX_GUI_WITH_SYSTRAY
470 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
471 bool mIncreasedWindowCounter : 1;
472#endif
473
474 /** Whether to show error message boxes for VM start errors. */
475 bool mShowStartVMErrors;
476
477 QThread *mMediaEnumThread;
478 VBoxMediaList mMediaList;
479
480 RenderMode vm_render_mode;
481 const char * vm_render_mode_str;
482 bool mIsKWinManaged;
483
484 /** The --disable-patm option. */
485 bool mDisablePatm;
486 /** The --disable-csam option. */
487 bool mDisableCsam;
488 /** The --recompile-supervisor option. */
489 bool mRecompileSupervisor;
490 /** The --recompile-user option. */
491 bool mRecompileUser;
492 /** The --warp-factor option value. */
493 uint32_t mWarpPct;
494
495#ifdef VBOX_WITH_DEBUGGER_GUI
496 /** Whether the debugger should be accessible or not.
497 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
498 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
499 int mDbgEnabled;
500 /** Whether to show the debugger automatically with the console.
501 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
502 int mDbgAutoShow;
503 /** Whether to show the command line window when mDbgAutoShow is set. */
504 int mDbgAutoShowCommandLine;
505 /** Whether to show the statistics window when mDbgAutoShow is set. */
506 int mDbgAutoShowStatistics;
507 /** VBoxDbg module handle. */
508 RTLDRMOD mhVBoxDbg;
509
510 /** Whether to start the VM in paused state or not. */
511 bool mStartPaused;
512#endif
513
514#if defined (Q_WS_WIN32)
515 DWORD dwHTMLHelpCookie;
516#endif
517
518 QString mVerString;
519 QString mBrandingConfig;
520
521 int m3DAvailable;
522
523 QList <QString> mFamilyIDs;
524 QList <QList <CGuestOSType> > mTypes;
525 QHash <QString, QPixmap *> mOsTypeIcons;
526
527 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
528
529 QString mDiskTypes_Differencing;
530
531 QString mUserDefinedPortName;
532
533 QPixmap mWarningIcon, mErrorIcon;
534
535 QFileIconProvider m_globalIconProvider;
536
537#ifdef VBOX_GUI_WITH_PIDFILE
538 QString m_strPidfile;
539#endif
540
541 char mSettingsPw[256];
542 bool mSettingsPwSet;
543
544 friend VBoxGlobal &vboxGlobal();
545};
546
547inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
548
549#endif /* __VBoxGlobal_h__ */
550
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use