VirtualBox

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

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

FE/Qt: 4397: Virtual Media Manager UI: Medium type change UI (combo-box) added.

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