VirtualBox

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

Last change on this file since 26644 was 26644, checked in by vboxsync, 15 years ago

FE/Qt4: Entry point for new running VM core (vboxglobal).

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