VirtualBox

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

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

FE/Qt: 6234: Support for VM groups: Initial commit. GUI-3 branch reintegrated to trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 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
134#ifdef VBOX_WITH_DEBUGGER_GUI
135 bool isDebuggerEnabled(CMachine &aMachine);
136 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
137 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
138 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
139 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
140
141 bool isStartPausedEnabled() const { return mStartPaused; }
142#else
143 bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
144 bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
145 bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
146
147 bool isStartPausedEnabled() const { return false; }
148#endif
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 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
155 CGuestOSType vmGuestOSType (const QString &aTypeId,
156 const QString &aFamilyId = QString::null) const;
157 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
158
159 static inline QString yearsToString (uint32_t cVal)
160 {
161 return tr("%n year(s)", "", cVal);
162 }
163
164 static inline QString monthsToString (uint32_t cVal)
165 {
166 return tr("%n month(s)", "", cVal);
167 }
168
169 static inline QString daysToString (uint32_t cVal)
170 {
171 return tr("%n day(s)", "", cVal);
172 }
173
174 static inline QString hoursToString (uint32_t cVal)
175 {
176 return tr("%n hour(s)", "", cVal);
177 }
178
179 static inline QString minutesToString (uint32_t cVal)
180 {
181 return tr("%n minute(s)", "", cVal);
182 }
183
184 static inline QString secondsToString (uint32_t cVal)
185 {
186 return tr("%n second(s)", "", cVal);
187 }
188
189 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
190
191 /**
192 * Similar to toString (KMediumType), but returns 'Differencing' for
193 * normal hard disks that have a parent.
194 */
195 QString mediumTypeString(const CMedium &medium) const;
196
197 QStringList COMPortNames() const;
198 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
199 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
200
201 QStringList LPTPortNames() const;
202 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
203 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
204
205 QPixmap snapshotIcon (bool online) const
206 {
207 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
208 }
209
210 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
211 {
212 for (int i = 0; i < extList.size(); ++i)
213 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
214 return true;
215 return false;
216 }
217
218 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
219 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
220
221 QPixmap warningIcon() const { return mWarningIcon; }
222 QPixmap errorIcon() const { return mErrorIcon; }
223
224 /* details generators */
225
226 QString details (const CMedium &aHD, bool aPredictDiff, bool fUseHtml = true);
227
228 QString details (const CUSBDevice &aDevice) const;
229 QString toolTip (const CUSBDevice &aDevice) const;
230 QString toolTip (const CUSBDeviceFilter &aFilter) const;
231
232 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
233
234 /* VirtualBox helpers */
235
236#if defined(Q_WS_X11) && !defined(VBOX_OSE)
237 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
238 bool showVirtualBoxLicense();
239#endif
240
241 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
242
243 /** Shortcut to openSession (aId, true). */
244 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
245
246 void startEnumeratingMedia();
247
248 void reloadProxySettings();
249
250 /**
251 * Returns a list of all currently registered media. This list is used to
252 * globally track the accessibility state of all media on a dedicated thread.
253 *
254 * Note that the media list is initially empty (i.e. before the enumeration
255 * process is started for the first time using #startEnumeratingMedia()).
256 * See #startEnumeratingMedia() for more information about how meida are
257 * sorted in the returned list.
258 */
259 const VBoxMediaList &currentMediaList() const { return mMediaList; }
260
261 /** Returns true if the media enumeration is in progress. */
262 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
263
264 void addMedium (const UIMedium &);
265 void updateMedium (const UIMedium &);
266 void removeMedium (UIMediumType, const QString &);
267
268 bool findMedium (const CMedium &, UIMedium &) const;
269 UIMedium findMedium (const QString &aMediumId) const;
270
271 /** Compact version of #findMediumTo(). Asserts if not found. */
272 UIMedium getMedium (const CMedium &aObj) const
273 {
274 UIMedium medium;
275 if (!findMedium (aObj, medium))
276 AssertFailed();
277 return medium;
278 }
279
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 /* Returns the number of current running Fe/Qt4 main windows. */
285 int mainWindowCount();
286
287 /* various helpers */
288
289 QString languageName() const;
290 QString languageCountry() const;
291 QString languageNameEnglish() const;
292 QString languageCountryEnglish() const;
293 QString languageTranslators() const;
294
295 void retranslateUi();
296
297 /** @internal made public for internal purposes */
298 void cleanup();
299
300 /* public static stuff */
301
302 static bool isDOSType (const QString &aOSTypeId);
303
304 static QString languageId();
305 static void loadLanguage (const QString &aLangId = QString::null);
306 QString helpFile() const;
307
308 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
309
310 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
311 bool aCanResize = true);
312 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
313 bool aCanResize = true);
314 static QRegion flip (const QRegion &aRegion);
315
316 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
317 bool aCanResize = true);
318
319 static QChar decimalSep();
320 static QString sizeRegexp();
321
322 static QString toHumanReadableList(const QStringList &list);
323
324 static quint64 parseSize (const QString &);
325 static QString formatSize (quint64 aSize, uint aDecimal = 2, FormatSize aMode = FormatSize_Round);
326
327 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
328
329 static QString locationForHTML (const QString &aFileName);
330
331 static QString highlight (const QString &aStr, bool aToolTip = false);
332
333 static QString replaceHtmlEntities(QString strText);
334 static QString emphasize (const QString &aStr);
335
336 static QString systemLanguageId();
337
338 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
339
340 static QString removeAccelMark (const QString &aText);
341
342 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
343 static QString extractKeyFromActionText (const QString &aText);
344
345 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
346
347 static QWidget *findWidget (QWidget *aParent, const char *aName,
348 const char *aClassName = NULL,
349 bool aRecursive = false);
350
351 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
352 static QList <QPair <QString, QString> > HDDBackends();
353 static QList <QPair <QString, QString> > DVDBackends();
354 static QList <QPair <QString, QString> > FloppyBackends();
355
356 /* Qt 4.2.0 support function */
357 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
358 {
359#if QT_VERSION < 0x040300
360 /* Deprecated since > 4.2 */
361 aLayout->setMargin (aMargin);
362#else
363 /* New since > 4.2 */
364 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
365#endif
366 }
367
368 static QString documentsPath();
369
370#ifdef VBOX_WITH_VIDEOHWACCEL
371 static bool isAcceleration2DVideoAvailable();
372
373 /** additional video memory required for the best 2D support performance
374 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
375 static quint64 required2DOffscreenVideoMemory();
376#endif
377
378#ifdef VBOX_WITH_CRHGSMI
379 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
380 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
381#endif /* VBOX_WITH_CRHGSMI */
382
383#ifdef Q_WS_MAC
384 bool isSheetWindowsAllowed(QWidget *pParent) const;
385#endif /* Q_WS_MAC */
386
387 /* Returns full medium-format name for the given base medium-format name: */
388 static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
389
390signals:
391
392 /**
393 * Emitted at the beginning of the enumeration process started by
394 * #startEnumeratingMedia().
395 */
396 void mediumEnumStarted();
397
398 /**
399 * Emitted when a new medium item from the list has updated its
400 * accessibility state.
401 */
402 void mediumEnumerated (const UIMedium &aMedum);
403
404 /**
405 * Emitted at the end of the enumeration process started by
406 * #startEnumeratingMedia(). The @a aList argument is passed for
407 * convenience, it is exactly the same as returned by #currentMediaList().
408 */
409 void mediumEnumFinished (const VBoxMediaList &aList);
410
411 /** Emitted when a new media is added using #addMedia(). */
412 void mediumAdded (const UIMedium &);
413
414 /** Emitted when the media is updated using #updateMedia(). */
415 void mediumUpdated (const UIMedium &);
416
417 /** Emitted when the media is removed using #removeMedia(). */
418 void mediumRemoved (UIMediumType, const QString &);
419
420#ifdef VBOX_GUI_WITH_SYSTRAY
421 void sigTrayIconShow(bool fEnabled);
422#endif
423
424public slots:
425
426 bool openURL (const QString &aURL);
427
428 void showRegistrationDialog (bool aForce = true);
429 void sltGUILanguageChange(QString strLang);
430 void sltProcessGlobalSettingChange();
431
432protected:
433
434 bool event (QEvent *e);
435 bool eventFilter (QObject *, QEvent *);
436
437private:
438
439 VBoxGlobal();
440 ~VBoxGlobal();
441
442 void init();
443#ifdef VBOX_WITH_DEBUGGER_GUI
444 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
445 void setDebuggerVar(int *piDbgCfgVar, bool fState);
446 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
447#endif
448
449 bool mValid;
450
451 CVirtualBox mVBox;
452 CHost mHost;
453
454 VBoxGlobalSettings gset;
455
456 UISelectorWindow *mSelectorWnd;
457 UIMachine *m_pVirtualMachine;
458 QWidget* mMainWindow;
459
460#ifdef VBOX_WITH_REGISTRATION
461 UIRegistrationWzd *mRegDlg;
462#endif
463
464 QString vmUuid;
465 QList<QUrl> m_ArgUrlList;
466
467#ifdef VBOX_GUI_WITH_SYSTRAY
468 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
469 bool mIncreasedWindowCounter : 1;
470#endif
471
472 /** Whether to show error message boxes for VM start errors. */
473 bool mShowStartVMErrors;
474
475 QThread *mMediaEnumThread;
476 VBoxMediaList mMediaList;
477
478 RenderMode vm_render_mode;
479 const char * vm_render_mode_str;
480 bool mIsKWinManaged;
481
482 /** The --disable-patm option. */
483 bool mDisablePatm;
484 /** The --disable-csam option. */
485 bool mDisableCsam;
486 /** The --recompile-supervisor option. */
487 bool mRecompileSupervisor;
488 /** The --recompile-user option. */
489 bool mRecompileUser;
490
491#ifdef VBOX_WITH_DEBUGGER_GUI
492 /** Whether the debugger should be accessible or not.
493 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
494 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
495 int mDbgEnabled;
496 /** Whether to show the debugger automatically with the console.
497 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
498 int mDbgAutoShow;
499 /** Whether to show the command line window when mDbgAutoShow is set. */
500 int mDbgAutoShowCommandLine;
501 /** Whether to show the statistics window when mDbgAutoShow is set. */
502 int mDbgAutoShowStatistics;
503 /** VBoxDbg module handle. */
504 RTLDRMOD mhVBoxDbg;
505
506 /** Whether to start the VM in paused state or not. */
507 bool mStartPaused;
508#endif
509
510#if defined (Q_WS_WIN32)
511 DWORD dwHTMLHelpCookie;
512#endif
513
514 QString mVerString;
515 QString mBrandingConfig;
516
517 int m3DAvailable;
518
519 QList <QString> mFamilyIDs;
520 QList <QList <CGuestOSType> > mTypes;
521 QHash <QString, QPixmap *> mOsTypeIcons;
522
523 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
524
525 QString mDiskTypes_Differencing;
526
527 QString mUserDefinedPortName;
528
529 QPixmap mWarningIcon, mErrorIcon;
530
531 QFileIconProvider m_globalIconProvider;
532
533#ifdef VBOX_GUI_WITH_PIDFILE
534 QString m_strPidfile;
535#endif
536
537 char mSettingsPw[256];
538 bool mSettingsPwSet;
539
540 friend VBoxGlobal &vboxGlobal();
541};
542
543inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
544
545#endif /* __VBoxGlobal_h__ */
546
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