VirtualBox

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

Last change on this file since 38467 was 38467, checked in by vboxsync, 14 years ago

FE/Qt4: allows starting a VM headless by pressing SHIFT

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.5 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#include "COMDefs.h"
23#include "VBox/com/Guid.h"
24
25#include "VBoxGlobalSettings.h"
26#include "VBoxMedium.h"
27
28/* Qt includes */
29#include <QApplication>
30#include <QLayout>
31#include <QMenu>
32#include <QStyle>
33#include <QProcess>
34#include <QHash>
35#include <QFileIconProvider>
36
37#ifdef Q_WS_X11
38# include <sys/wait.h>
39#endif
40
41class QAction;
42class QLabel;
43class QToolButton;
44class UIMachine;
45
46class Process : public QProcess
47{
48 Q_OBJECT;
49
50public:
51
52 static QByteArray singleShot (const QString &aProcessName,
53 int aTimeout = 5000
54 /* wait for data maximum 5 seconds */)
55 {
56 /* Why is it really needed is because of Qt4.3 bug with QProcess.
57 * This bug is about QProcess sometimes (~70%) do not receive
58 * notification about process was finished, so this makes
59 * 'bool QProcess::waitForFinished (int)' block the GUI thread and
60 * never dismissed with 'true' result even if process was really
61 * started&finished. So we just waiting for some information
62 * on process output and destroy the process with force. Due to
63 * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
64 * we have to change process state to QProcess::NotRunning. */
65
66 QByteArray result;
67 Process process;
68 process.start (aProcessName);
69 bool firstShotReady = process.waitForReadyRead (aTimeout);
70 if (firstShotReady)
71 result = process.readAllStandardOutput();
72 process.setProcessState (QProcess::NotRunning);
73#ifdef Q_WS_X11
74 int status;
75 if (process.pid() > 0)
76 waitpid(process.pid(), &status, 0);
77#endif
78 return result;
79 }
80
81protected:
82
83 Process (QWidget *aParent = 0) : QProcess (aParent) {}
84};
85
86struct StorageSlot
87{
88 StorageSlot() : bus (KStorageBus_Null), port (0), device (0) {}
89 StorageSlot (const StorageSlot &aOther) : bus (aOther.bus), port (aOther.port), device (aOther.device) {}
90 StorageSlot (KStorageBus aBus, LONG aPort, LONG aDevice) : bus (aBus), port (aPort), device (aDevice) {}
91 StorageSlot& operator= (const StorageSlot &aOther) { bus = aOther.bus; port = aOther.port; device = aOther.device; return *this; }
92 bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; }
93 bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; }
94 bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) ||
95 (bus == aOther.bus && port < aOther.port) ||
96 (bus == aOther.bus && port == aOther.port && device < aOther.device); }
97 bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) ||
98 (bus == aOther.bus && port > aOther.port) ||
99 (bus == aOther.bus && port == aOther.port && device > aOther.device); }
100 bool isNull() { return bus == KStorageBus_Null; }
101 KStorageBus bus; LONG port; LONG device;
102};
103Q_DECLARE_METATYPE (StorageSlot);
104
105// VBoxGlobal class
106////////////////////////////////////////////////////////////////////////////////
107
108class VBoxSelectorWnd;
109class UIRegistrationWzd;
110class VBoxUpdateDlg;
111
112class VBoxGlobal : public QObject
113{
114 Q_OBJECT
115
116public:
117
118 typedef QHash <ulong, QString> QULongStringHash;
119 typedef QHash <long, QString> QLongStringHash;
120
121 static VBoxGlobal &instance();
122
123 bool isValid() { return mValid; }
124
125 static QString qtRTVersionString();
126 static uint qtRTVersion();
127 static QString qtCTVersionString();
128 static uint qtCTVersion();
129
130 QString versionString() const { return mVerString; }
131 bool isBeta() const;
132
133 CVirtualBox virtualBox() const { return mVBox; }
134
135 VBoxGlobalSettings &settings() { return gset; }
136 bool setSettings (VBoxGlobalSettings &gs);
137
138 VBoxSelectorWnd &selectorWnd();
139
140 QWidget *vmWindow();
141
142 bool createVirtualMachine(const CSession &session);
143 UIMachine* virtualMachine();
144
145 /* main window handle storage */
146 void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
147 QWidget *mainWindow() const { return mMainWindow; }
148
149#ifdef VBOX_GUI_WITH_PIDFILE
150 void createPidfile();
151 void deletePidfile();
152#endif
153
154 /* branding */
155 bool brandingIsActive (bool aForce = false);
156 QString brandingGetKey (QString aKey);
157
158 bool processArgs();
159
160 bool switchToMachine(CMachine &machine);
161 bool launchMachine(CMachine &machine, bool fHeadless = false);
162
163 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
164 bool showStartVMErrors() const { return mShowStartVMErrors; }
165#ifdef VBOX_GUI_WITH_SYSTRAY
166 bool isTrayMenu() const;
167 void setTrayMenu(bool aIsTrayMenu);
168 void trayIconShowSelector();
169 bool trayIconInstall();
170#endif
171 QString managedVMUuid() const { return vmUuid; }
172 QList<QUrl> &argUrlList() { return m_ArgUrlList; }
173
174 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
175 const char *vmRenderModeStr() const { return vm_render_mode_str; }
176 bool isKWinManaged() const { return mIsKWinManaged; }
177
178 const QRect availableGeometry(int iScreen = 0) const;
179
180 bool isPatmDisabled() const { return mDisablePatm; }
181 bool isCsamDisabled() const { return mDisableCsam; }
182 bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
183 bool isUserCodeExecedRecompiled() const { return mRecompileUser; }
184
185#ifdef VBOX_WITH_DEBUGGER_GUI
186 bool isDebuggerEnabled(CMachine &aMachine);
187 bool isDebuggerAutoShowEnabled(CMachine &aMachine);
188 bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
189 bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
190 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
191
192 bool isStartPausedEnabled() const { return mStartPaused; }
193#else
194 bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
195 bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
196 bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
197
198 bool isStartPausedEnabled() const { return false; }
199#endif
200
201 /* VBox enum to/from string/icon/color convertors */
202
203 QList <CGuestOSType> vmGuestOSFamilyList() const;
204 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
205 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
206 CGuestOSType vmGuestOSType (const QString &aTypeId,
207 const QString &aFamilyId = QString::null) const;
208 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
209
210 QPixmap toIcon (KMachineState s) const
211 {
212 QPixmap *pm = mVMStateIcons.value (s);
213 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
214 return pm ? *pm : QPixmap();
215 }
216
217 static inline QString yearsToString (uint32_t cVal)
218 {
219 return tr("%n year(s)", "", cVal);
220 }
221
222 static inline QString monthsToString (uint32_t cVal)
223 {
224 return tr("%n month(s)", "", cVal);
225 }
226
227 static inline QString daysToString (uint32_t cVal)
228 {
229 return tr("%n day(s)", "", cVal);
230 }
231
232 static inline QString hoursToString (uint32_t cVal)
233 {
234 return tr("%n hour(s)", "", cVal);
235 }
236
237 static inline QString minutesToString (uint32_t cVal)
238 {
239 return tr("%n minute(s)", "", cVal);
240 }
241
242 static inline QString secondsToString (uint32_t cVal)
243 {
244 return tr("%n second(s)", "", cVal);
245 }
246
247 const QColor &toColor (KMachineState s) const
248 {
249 static const QColor none;
250 AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
251 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
252 }
253
254 QString toString (KMachineState s) const
255 {
256 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
257 return mMachineStates.value (s);
258 }
259
260 QString toString (KSessionState s) const
261 {
262 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
263 return mSessionStates.value (s);
264 }
265
266 /**
267 * Returns a string representation of the given KStorageBus enum value.
268 * Complementary to #toStorageBusType (const QString &) const.
269 */
270 QString toString (KStorageBus aBus) const
271 {
272 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
273 return mStorageBuses [aBus];
274 }
275
276 /**
277 * Returns a KStorageBus enum value corresponding to the given string
278 * representation. Complementary to #toString (KStorageBus) const.
279 */
280 KStorageBus toStorageBusType (const QString &aBus) const
281 {
282 QULongStringHash::const_iterator it =
283 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
284 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
285 aBus.toLatin1().constData()));
286 return KStorageBus (it.key());
287 }
288
289 KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
290 {
291 KStorageBus sb = KStorageBus_Null;
292 switch (aControllerType)
293 {
294 case KStorageControllerType_Null: sb = KStorageBus_Null; break;
295 case KStorageControllerType_PIIX3:
296 case KStorageControllerType_PIIX4:
297 case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
298 case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
299 case KStorageControllerType_LsiLogic:
300 case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
301 case KStorageControllerType_I82078: sb = KStorageBus_Floppy; break;
302 default:
303 AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
304 }
305 return sb;
306 }
307
308 QString toString (KStorageBus aBus, LONG aChannel) const;
309 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
310
311 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
312 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
313
314 QString toString (StorageSlot aSlot) const;
315 StorageSlot toStorageSlot (const QString &aSlot) const;
316
317 QString toString (KMediumType t) const
318 {
319 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
320 return mDiskTypes.value (t);
321 }
322 QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
323
324 QString toString(KMediumVariant mediumVariant) const;
325
326 /**
327 * Similar to toString (KMediumType), but returns 'Differencing' for
328 * normal hard disks that have a parent.
329 */
330 QString mediumTypeString (const CMedium &aHD) const
331 {
332 if (!aHD.GetParent().isNull())
333 {
334 Assert (aHD.GetType() == KMediumType_Normal);
335 return mDiskTypes_Differencing;
336 }
337 return toString (aHD.GetType());
338 }
339
340 QString toString (KAuthType t) const
341 {
342 AssertMsg (!mAuthTypes.value (t).isNull(), ("No text for %d", t));
343 return mAuthTypes.value (t);
344 }
345
346 QString toString (KPortMode t) const
347 {
348 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
349 return mPortModeTypes.value (t);
350 }
351
352 QString toString (KUSBDeviceFilterAction t) const
353 {
354 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
355 return mUSBFilterActionTypes.value (t);
356 }
357
358 QString toString (KClipboardMode t) const
359 {
360 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
361 return mClipboardTypes.value (t);
362 }
363
364 KClipboardMode toClipboardModeType (const QString &s) const
365 {
366 QULongStringHash::const_iterator it =
367 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
368 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
369 s.toLatin1().constData()));
370 return KClipboardMode (it.key());
371 }
372
373 QString toString (KStorageControllerType t) const
374 {
375 AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
376 return mStorageControllerTypes.value (t);
377 }
378
379 KStorageControllerType toControllerType (const QString &s) const
380 {
381 QULongStringHash::const_iterator it =
382 qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
383 AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
384 s.toLatin1().constData()));
385 return KStorageControllerType (it.key());
386 }
387
388 KAuthType toAuthType (const QString &s) const
389 {
390 QULongStringHash::const_iterator it =
391 qFind (mAuthTypes.begin(), mAuthTypes.end(), s);
392 AssertMsg (it != mAuthTypes.end(), ("No value for {%s}",
393 s.toLatin1().constData()));
394 return KAuthType (it.key());
395 }
396
397 KPortMode toPortMode (const QString &s) const
398 {
399 QULongStringHash::const_iterator it =
400 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
401 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
402 s.toLatin1().constData()));
403 return KPortMode (it.key());
404 }
405
406 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
407 {
408 QULongStringHash::const_iterator it =
409 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
410 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
411 s.toLatin1().constData()));
412 return KUSBDeviceFilterAction (it.key());
413 }
414
415 QString toString (KDeviceType t) const
416 {
417 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
418 return mDeviceTypes.value (t);
419 }
420
421 KDeviceType toDeviceType (const QString &s) const
422 {
423 QULongStringHash::const_iterator it =
424 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
425 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
426 s.toLatin1().constData()));
427 return KDeviceType (it.key());
428 }
429
430 QStringList deviceTypeStrings() const;
431
432 QString toString (KAudioDriverType t) const
433 {
434 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
435 return mAudioDriverTypes.value (t);
436 }
437
438 KAudioDriverType toAudioDriverType (const QString &s) const
439 {
440 QULongStringHash::const_iterator it =
441 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
442 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
443 s.toLatin1().constData()));
444 return KAudioDriverType (it.key());
445 }
446
447 QString toString (KAudioControllerType t) const
448 {
449 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
450 return mAudioControllerTypes.value (t);
451 }
452
453 KAudioControllerType toAudioControllerType (const QString &s) const
454 {
455 QULongStringHash::const_iterator it =
456 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
457 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
458 s.toLatin1().constData()));
459 return KAudioControllerType (it.key());
460 }
461
462 QString toString (KNetworkAdapterType t) const
463 {
464 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
465 return mNetworkAdapterTypes.value (t);
466 }
467
468 KNetworkAdapterType toNetworkAdapterType (const QString &s) const
469 {
470 QULongStringHash::const_iterator it =
471 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
472 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
473 s.toLatin1().constData()));
474 return KNetworkAdapterType (it.key());
475 }
476
477 QString toString (KNetworkAttachmentType t) const
478 {
479 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
480 return mNetworkAttachmentTypes.value (t);
481 }
482
483 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
484 {
485 QULongStringHash::const_iterator it =
486 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
487 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
488 s.toLatin1().constData()));
489 return KNetworkAttachmentType (it.key());
490 }
491
492 QString toString (KNetworkAdapterPromiscModePolicy t) const
493 {
494 AssertMsg (!mNetworkAdapterPromiscModePolicyTypes.value (t).isNull(), ("No text for %d", t));
495 return mNetworkAdapterPromiscModePolicyTypes.value (t);
496 }
497
498 KNetworkAdapterPromiscModePolicy toNetworkAdapterPromiscModePolicyType (const QString &s) const
499 {
500 QULongStringHash::const_iterator it =
501 qFind (mNetworkAdapterPromiscModePolicyTypes.begin(), mNetworkAdapterPromiscModePolicyTypes.end(), s);
502 AssertMsg (it != mNetworkAdapterPromiscModePolicyTypes.end(), ("No value for {%s}",
503 s.toLatin1().constData()));
504 return KNetworkAdapterPromiscModePolicy (it.key());
505 }
506
507 QString toString (KNATProtocol t) const
508 {
509 AssertMsg (!mNATProtocolTypes.value (t).isNull(), ("No text for %d", t));
510 return mNATProtocolTypes.value (t);
511 }
512
513 KNATProtocol toNATProtocolType (const QString &s) const
514 {
515 QULongStringHash::const_iterator it =
516 qFind (mNATProtocolTypes.begin(), mNATProtocolTypes.end(), s);
517 AssertMsg (it != mNATProtocolTypes.end(), ("No value for {%s}",
518 s.toLatin1().constData()));
519 return KNATProtocol (it.key());
520 }
521
522 QString toString (KUSBDeviceState aState) const
523 {
524 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
525 return mUSBDeviceStates.value (aState);
526 }
527
528 QString toString (KChipsetType t) const
529 {
530 AssertMsg (!mChipsetTypes.value (t).isNull(), ("No text for %d", t));
531 return mChipsetTypes.value (t);
532 }
533
534 KChipsetType toChipsetType (const QString &s) const
535 {
536 QULongStringHash::const_iterator it =
537 qFind (mChipsetTypes.begin(), mChipsetTypes.end(), s);
538 AssertMsg (it != mChipsetTypes.end(), ("No value for {%s}",
539 s.toLatin1().constData()));
540 return KChipsetType (it.key());
541 }
542
543 QStringList COMPortNames() const;
544 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
545 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
546
547 QStringList LPTPortNames() const;
548 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
549 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
550
551 QPixmap snapshotIcon (bool online) const
552 {
553 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
554 }
555
556 static bool hasAllowedExtension(const QString &strExt, const QStringList &extList) { for(int i = 0; i < extList.size(); ++i) if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive)) return true; return false;}
557 QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
558 QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
559
560 QPixmap warningIcon() const { return mWarningIcon; }
561 QPixmap errorIcon() const { return mErrorIcon; }
562
563 /* details generators */
564
565 QString details (const CMedium &aHD, bool aPredictDiff);
566
567 QString details (const CUSBDevice &aDevice) const;
568 QString toolTip (const CUSBDevice &aDevice) const;
569 QString toolTip (const CUSBDeviceFilter &aFilter) const;
570
571 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
572
573 QString platformInfo();
574
575 /* VirtualBox helpers */
576
577#if defined(Q_WS_X11) && !defined(VBOX_OSE)
578 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
579 bool showVirtualBoxLicense();
580#endif
581
582 CSession openSession(const QString &aId, bool aExisting = false);
583
584 /** Shortcut to openSession (aId, true). */
585 CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
586
587 bool startMachine(const QString &strId);
588
589 void startEnumeratingMedia();
590
591 void reloadProxySettings();
592
593 /**
594 * Returns a list of all currently registered media. This list is used to
595 * globally track the accessibility state of all media on a dedicated thread.
596 *
597 * Note that the media list is initially empty (i.e. before the enumeration
598 * process is started for the first time using #startEnumeratingMedia()).
599 * See #startEnumeratingMedia() for more information about how meida are
600 * sorted in the returned list.
601 */
602 const VBoxMediaList &currentMediaList() const { return mMediaList; }
603
604 /** Returns true if the media enumeration is in progress. */
605 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
606
607 VBoxDefs::MediumType mediumTypeToLocal(KDeviceType globalType);
608 KDeviceType mediumTypeToGlobal(VBoxDefs::MediumType localType);
609
610 void addMedium (const VBoxMedium &);
611 void updateMedium (const VBoxMedium &);
612 void removeMedium (VBoxDefs::MediumType, const QString &);
613
614 bool findMedium (const CMedium &, VBoxMedium &) const;
615 VBoxMedium findMedium (const QString &aMediumId) const;
616
617 /** Compact version of #findMediumTo(). Asserts if not found. */
618 VBoxMedium getMedium (const CMedium &aObj) const
619 {
620 VBoxMedium medium;
621 if (!findMedium (aObj, medium))
622 AssertFailed();
623 return medium;
624 }
625
626 QString openMediumWithFileOpenDialog(VBoxDefs::MediumType mediumType, QWidget *pParent = 0,
627 const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
628 QString openMedium(VBoxDefs::MediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
629
630 /* Returns the number of current running Fe/Qt4 main windows. */
631 int mainWindowCount();
632
633 /* various helpers */
634
635 QString languageName() const;
636 QString languageCountry() const;
637 QString languageNameEnglish() const;
638 QString languageCountryEnglish() const;
639 QString languageTranslators() const;
640
641 void retranslateUi();
642
643 /** @internal made public for internal purposes */
644 void cleanup();
645
646 /* public static stuff */
647
648 static bool isDOSType (const QString &aOSTypeId);
649
650 static QString languageId();
651 static void loadLanguage (const QString &aLangId = QString::null);
652 QString helpFile() const;
653
654 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
655
656 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
657 bool aCanResize = true);
658 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
659 bool aCanResize = true);
660 static QRegion flip (const QRegion &aRegion);
661
662 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
663 bool aCanResize = true);
664
665 static QChar decimalSep();
666 static QString sizeRegexp();
667
668 static QString toHumanReadableList(const QStringList &list);
669
670 static quint64 parseSize (const QString &);
671 static QString formatSize (quint64 aSize, uint aDecimal = 2,
672 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
673
674 static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
675
676 static QString locationForHTML (const QString &aFileName);
677
678 static QString highlight (const QString &aStr, bool aToolTip = false);
679
680 static QString replaceHtmlEntities(QString strText);
681 static QString emphasize (const QString &aStr);
682
683 static QString systemLanguageId();
684
685 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
686
687 static QString removeAccelMark (const QString &aText);
688
689 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
690 static QString extractKeyFromActionText (const QString &aText);
691
692 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
693
694 static QWidget *findWidget (QWidget *aParent, const char *aName,
695 const char *aClassName = NULL,
696 bool aRecursive = false);
697
698 static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
699 static QList <QPair <QString, QString> > HDDBackends();
700 static QList <QPair <QString, QString> > DVDBackends();
701 static QList <QPair <QString, QString> > FloppyBackends();
702
703 /* Qt 4.2.0 support function */
704 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
705 {
706#if QT_VERSION < 0x040300
707 /* Deprecated since > 4.2 */
708 aLayout->setMargin (aMargin);
709#else
710 /* New since > 4.2 */
711 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
712#endif
713 }
714
715 static QString documentsPath();
716
717#ifdef VBOX_WITH_VIDEOHWACCEL
718 static bool isAcceleration2DVideoAvailable();
719
720 /** additional video memory required for the best 2D support performance
721 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
722 static quint64 required2DOffscreenVideoMemory();
723#endif
724
725#ifdef VBOX_WITH_CRHGSMI
726 static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
727 static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
728#endif /* VBOX_WITH_CRHGSMI */
729
730#ifdef Q_WS_MAC
731 bool isSheetWindowsAllowed(QWidget *pParent) const;
732#endif /* Q_WS_MAC */
733
734signals:
735
736 /**
737 * Emitted at the beginning of the enumeration process started by
738 * #startEnumeratingMedia().
739 */
740 void mediumEnumStarted();
741
742 /**
743 * Emitted when a new medium item from the list has updated its
744 * accessibility state.
745 */
746 void mediumEnumerated (const VBoxMedium &aMedum);
747
748 /**
749 * Emitted at the end of the enumeration process started by
750 * #startEnumeratingMedia(). The @a aList argument is passed for
751 * convenience, it is exactly the same as returned by #currentMediaList().
752 */
753 void mediumEnumFinished (const VBoxMediaList &aList);
754
755 /** Emitted when a new media is added using #addMedia(). */
756 void mediumAdded (const VBoxMedium &);
757
758 /** Emitted when the media is updated using #updateMedia(). */
759 void mediumUpdated (const VBoxMedium &);
760
761 /** Emitted when the media is removed using #removeMedia(). */
762 void mediumRemoved (VBoxDefs::MediumType, const QString &);
763
764#ifdef VBOX_GUI_WITH_SYSTRAY
765 void sigTrayIconShow(bool fEnabled);
766#endif
767
768public slots:
769
770 bool openURL (const QString &aURL);
771
772 void showRegistrationDialog (bool aForce = true);
773 void showUpdateDialog (bool aForce = true);
774 void perDayNewVersionNotifier();
775 void sltGUILanguageChange(QString strLang);
776 void sltProcessGlobalSettingChange();
777
778protected:
779
780 bool event (QEvent *e);
781 bool eventFilter (QObject *, QEvent *);
782
783private:
784
785 VBoxGlobal();
786 ~VBoxGlobal();
787
788 void init();
789#ifdef VBOX_WITH_DEBUGGER_GUI
790 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
791 void setDebuggerVar(int *piDbgCfgVar, bool fState);
792 bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
793#endif
794
795 bool mValid;
796
797 CVirtualBox mVBox;
798
799 VBoxGlobalSettings gset;
800
801 VBoxSelectorWnd *mSelectorWnd;
802 UIMachine *m_pVirtualMachine;
803 QWidget* mMainWindow;
804
805#ifdef VBOX_WITH_REGISTRATION
806 UIRegistrationWzd *mRegDlg;
807#endif
808 VBoxUpdateDlg *mUpdDlg;
809
810 QString vmUuid;
811 QList<QUrl> m_ArgUrlList;
812
813#ifdef VBOX_GUI_WITH_SYSTRAY
814 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
815 bool mIncreasedWindowCounter : 1;
816#endif
817
818 /** Whether to show error message boxes for VM start errors. */
819 bool mShowStartVMErrors;
820
821 QThread *mMediaEnumThread;
822 VBoxMediaList mMediaList;
823
824 VBoxDefs::RenderMode vm_render_mode;
825 const char * vm_render_mode_str;
826 bool mIsKWinManaged;
827
828 /** The --disable-patm option. */
829 bool mDisablePatm;
830 /** The --disable-csam option. */
831 bool mDisableCsam;
832 /** The --recompile-supervisor option. */
833 bool mRecompileSupervisor;
834 /** The --recompile-user option. */
835 bool mRecompileUser;
836
837#ifdef VBOX_WITH_DEBUGGER_GUI
838 /** Whether the debugger should be accessible or not.
839 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
840 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
841 int mDbgEnabled;
842 /** Whether to show the debugger automatically with the console.
843 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
844 int mDbgAutoShow;
845 /** Whether to show the command line window when mDbgAutoShow is set. */
846 int mDbgAutoShowCommandLine;
847 /** Whether to show the statistics window when mDbgAutoShow is set. */
848 int mDbgAutoShowStatistics;
849 /** VBoxDbg module handle. */
850 RTLDRMOD mhVBoxDbg;
851
852 /** Whether to start the VM in paused state or not. */
853 bool mStartPaused;
854#endif
855
856#if defined (Q_WS_WIN32)
857 DWORD dwHTMLHelpCookie;
858#endif
859
860 QString mVerString;
861 QString mBrandingConfig;
862
863 QList <QString> mFamilyIDs;
864 QList <QList <CGuestOSType> > mTypes;
865 QHash <QString, QPixmap *> mOsTypeIcons;
866
867 QHash <ulong, QPixmap *> mVMStateIcons;
868 QHash <ulong, QColor *> mVMStateColors;
869
870 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
871
872 QULongStringHash mMachineStates;
873 QULongStringHash mSessionStates;
874 QULongStringHash mDeviceTypes;
875
876 QULongStringHash mStorageBuses;
877 QLongStringHash mStorageBusChannels;
878 QLongStringHash mStorageBusDevices;
879 QULongStringHash mSlotTemplates;
880
881 QULongStringHash mDiskTypes;
882 QString mDiskTypes_Differencing;
883
884 QULongStringHash mAuthTypes;
885 QULongStringHash mPortModeTypes;
886 QULongStringHash mUSBFilterActionTypes;
887 QULongStringHash mAudioDriverTypes;
888 QULongStringHash mAudioControllerTypes;
889 QULongStringHash mNetworkAdapterTypes;
890 QULongStringHash mNetworkAttachmentTypes;
891 QULongStringHash mNetworkAdapterPromiscModePolicyTypes;
892 QULongStringHash mNATProtocolTypes;
893 QULongStringHash mClipboardTypes;
894 QULongStringHash mStorageControllerTypes;
895 QULongStringHash mUSBDeviceStates;
896 QULongStringHash mChipsetTypes;
897
898 QString mUserDefinedPortName;
899
900 QPixmap mWarningIcon, mErrorIcon;
901
902 QFileIconProvider m_globalIconProvider;
903
904#ifdef VBOX_GUI_WITH_PIDFILE
905 QString m_strPidfile;
906#endif
907
908 friend VBoxGlobal &vboxGlobal();
909};
910
911inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
912
913// Helper classes
914////////////////////////////////////////////////////////////////////////////////
915
916/**
917 * USB Popup Menu class.
918 * This class provides the list of USB devices attached to the host.
919 */
920class VBoxUSBMenu : public QMenu
921{
922 Q_OBJECT
923
924public:
925
926 VBoxUSBMenu (QWidget *);
927
928 const CUSBDevice& getUSB (QAction *aAction);
929
930 void setConsole (const CConsole &);
931
932private slots:
933
934 void processAboutToShow();
935
936private:
937 bool event(QEvent *aEvent);
938
939 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
940 CConsole mConsole;
941};
942
943/**
944 * Enable/Disable Menu class.
945 * This class provides enable/disable menu items.
946 */
947class VBoxSwitchMenu : public QMenu
948{
949 Q_OBJECT
950
951public:
952
953 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
954
955 void setToolTip (const QString &);
956
957private slots:
958
959 void processAboutToShow();
960
961private:
962
963 QAction *mAction;
964 bool mInverted;
965};
966
967#endif /* __VBoxGlobal_h__ */
968
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