VirtualBox

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

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

FE/Qt4: New running VM core: fixing bug with session closing, now saving VM is restored.

  • 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 bool createVirtualMachine(const CSession &session);
311 UIMachine* virtualMachine();
312#endif
313
314 /* main window handle storage */
315 void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
316 QWidget *mainWindow() const { return mMainWindow; }
317
318 /* branding */
319 bool brandingIsActive (bool aForce = false);
320 QString brandingGetKey (QString aKey);
321
322 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
323#ifdef VBOX_GUI_WITH_SYSTRAY
324 bool isTrayMenu() const;
325 void setTrayMenu(bool aIsTrayMenu);
326 void trayIconShowSelector();
327 bool trayIconInstall();
328#endif
329 QString managedVMUuid() const { return vmUuid; }
330
331 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
332 const char *vmRenderModeStr() const { return vm_render_mode_str; }
333 bool isKWinManaged() const { return mIsKWinManaged; }
334
335#ifdef VBOX_WITH_DEBUGGER_GUI
336 bool isDebuggerEnabled() const { return mDbgEnabled; }
337 bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
338 bool isDebuggerAutoShowCommandLineEnabled() const { return mDbgAutoShowCommandLine; }
339 bool isDebuggerAutoShowStatisticsEnabled() const { return mDbgAutoShowStatistics; }
340 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
341
342 bool isStartPausedEnabled() const { return mStartPaused; }
343#else
344 bool isDebuggerAutoShowEnabled() const { return false; }
345 bool isDebuggerAutoShowCommandLineEnabled() const { return false; }
346 bool isDebuggerAutoShowStatisticsEnabled() const { return false; }
347
348 bool isStartPausedEnabled() const { return false; }
349#endif
350
351 /* VBox enum to/from string/icon/color convertors */
352
353 QList <CGuestOSType> vmGuestOSFamilyList() const;
354 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
355 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
356 CGuestOSType vmGuestOSType (const QString &aTypeId,
357 const QString &aFamilyId = QString::null) const;
358 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
359
360 QPixmap toIcon (KMachineState s) const
361 {
362 QPixmap *pm = mVMStateIcons.value (s);
363 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
364 return pm ? *pm : QPixmap();
365 }
366
367 static inline QString yearsToString (uint32_t cVal)
368 {
369 return tr("%n year(s)", "", cVal);
370 }
371
372 static inline QString monthsToString (uint32_t cVal)
373 {
374 return tr("%n month(s)", "", cVal);
375 }
376
377 static inline QString daysToString (uint32_t cVal)
378 {
379 return tr("%n day(s)", "", cVal);
380 }
381
382 static inline QString hoursToString (uint32_t cVal)
383 {
384 return tr("%n hour(s)", "", cVal);
385 }
386
387 static inline QString minutesToString (uint32_t cVal)
388 {
389 return tr("%n minute(s)", "", cVal);
390 }
391
392 static inline QString secondsToString (uint32_t cVal)
393 {
394 return tr("%n second(s)", "", cVal);
395 }
396
397 const QColor &toColor (KMachineState s) const
398 {
399 static const QColor none;
400 AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
401 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
402 }
403
404 QString toString (KMachineState s) const
405 {
406 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
407 return mMachineStates.value (s);
408 }
409
410 QString toString (KSessionState s) const
411 {
412 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
413 return mSessionStates.value (s);
414 }
415
416 /**
417 * Returns a string representation of the given KStorageBus enum value.
418 * Complementary to #toStorageBusType (const QString &) const.
419 */
420 QString toString (KStorageBus aBus) const
421 {
422 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
423 return mStorageBuses [aBus];
424 }
425
426 /**
427 * Returns a KStorageBus enum value corresponding to the given string
428 * representation. Complementary to #toString (KStorageBus) const.
429 */
430 KStorageBus toStorageBusType (const QString &aBus) const
431 {
432 QULongStringHash::const_iterator it =
433 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
434 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
435 aBus.toLatin1().constData()));
436 return KStorageBus (it.key());
437 }
438
439 KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
440 {
441 KStorageBus sb = KStorageBus_Null;
442 switch (aControllerType)
443 {
444 case KStorageControllerType_Null: sb = KStorageBus_Null; break;
445 case KStorageControllerType_PIIX3:
446 case KStorageControllerType_PIIX4:
447 case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
448 case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
449 case KStorageControllerType_LsiLogic:
450 case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
451 case KStorageControllerType_I82078: sb = KStorageBus_Floppy; break;
452 default:
453 AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
454 }
455 return sb;
456 }
457
458 QString toString (KStorageBus aBus, LONG aChannel) const;
459 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
460
461 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
462 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
463
464 QString toString (StorageSlot aSlot) const;
465 StorageSlot toStorageSlot (const QString &aSlot) const;
466
467 QString toString (KMediumType t) const
468 {
469 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
470 return mDiskTypes.value (t);
471 }
472
473 /**
474 * Similar to toString (KMediumType), but returns 'Differencing' for
475 * normal hard disks that have a parent.
476 */
477 QString mediumTypeString (const CMedium &aHD) const
478 {
479 if (!aHD.GetParent().isNull())
480 {
481 Assert (aHD.GetType() == KMediumType_Normal);
482 return mDiskTypes_Differencing;
483 }
484 return toString (aHD.GetType());
485 }
486
487 QString toString (KVRDPAuthType t) const
488 {
489 AssertMsg (!mVRDPAuthTypes.value (t).isNull(), ("No text for %d", t));
490 return mVRDPAuthTypes.value (t);
491 }
492
493 QString toString (KPortMode t) const
494 {
495 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
496 return mPortModeTypes.value (t);
497 }
498
499 QString toString (KUSBDeviceFilterAction t) const
500 {
501 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
502 return mUSBFilterActionTypes.value (t);
503 }
504
505 QString toString (KClipboardMode t) const
506 {
507 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
508 return mClipboardTypes.value (t);
509 }
510
511 KClipboardMode toClipboardModeType (const QString &s) const
512 {
513 QULongStringHash::const_iterator it =
514 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
515 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
516 s.toLatin1().constData()));
517 return KClipboardMode (it.key());
518 }
519
520 QString toString (KStorageControllerType t) const
521 {
522 AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
523 return mStorageControllerTypes.value (t);
524 }
525
526 KStorageControllerType toControllerType (const QString &s) const
527 {
528 QULongStringHash::const_iterator it =
529 qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
530 AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
531 s.toLatin1().constData()));
532 return KStorageControllerType (it.key());
533 }
534
535 KVRDPAuthType toVRDPAuthType (const QString &s) const
536 {
537 QULongStringHash::const_iterator it =
538 qFind (mVRDPAuthTypes.begin(), mVRDPAuthTypes.end(), s);
539 AssertMsg (it != mVRDPAuthTypes.end(), ("No value for {%s}",
540 s.toLatin1().constData()));
541 return KVRDPAuthType (it.key());
542 }
543
544 KPortMode toPortMode (const QString &s) const
545 {
546 QULongStringHash::const_iterator it =
547 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
548 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
549 s.toLatin1().constData()));
550 return KPortMode (it.key());
551 }
552
553 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
554 {
555 QULongStringHash::const_iterator it =
556 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
557 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
558 s.toLatin1().constData()));
559 return KUSBDeviceFilterAction (it.key());
560 }
561
562 QString toString (KDeviceType t) const
563 {
564 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
565 return mDeviceTypes.value (t);
566 }
567
568 KDeviceType toDeviceType (const QString &s) const
569 {
570 QULongStringHash::const_iterator it =
571 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
572 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
573 s.toLatin1().constData()));
574 return KDeviceType (it.key());
575 }
576
577 QStringList deviceTypeStrings() const;
578
579 QString toString (KAudioDriverType t) const
580 {
581 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
582 return mAudioDriverTypes.value (t);
583 }
584
585 KAudioDriverType toAudioDriverType (const QString &s) const
586 {
587 QULongStringHash::const_iterator it =
588 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
589 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
590 s.toLatin1().constData()));
591 return KAudioDriverType (it.key());
592 }
593
594 QString toString (KAudioControllerType t) const
595 {
596 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
597 return mAudioControllerTypes.value (t);
598 }
599
600 KAudioControllerType toAudioControllerType (const QString &s) const
601 {
602 QULongStringHash::const_iterator it =
603 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
604 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
605 s.toLatin1().constData()));
606 return KAudioControllerType (it.key());
607 }
608
609 QString toString (KNetworkAdapterType t) const
610 {
611 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
612 return mNetworkAdapterTypes.value (t);
613 }
614
615 KNetworkAdapterType toNetworkAdapterType (const QString &s) const
616 {
617 QULongStringHash::const_iterator it =
618 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
619 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
620 s.toLatin1().constData()));
621 return KNetworkAdapterType (it.key());
622 }
623
624 QString toString (KNetworkAttachmentType t) const
625 {
626 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
627 return mNetworkAttachmentTypes.value (t);
628 }
629
630 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
631 {
632 QULongStringHash::const_iterator it =
633 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
634 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
635 s.toLatin1().constData()));
636 return KNetworkAttachmentType (it.key());
637 }
638
639 QString toString (KUSBDeviceState aState) const
640 {
641 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
642 return mUSBDeviceStates.value (aState);
643 }
644
645 QStringList COMPortNames() const;
646 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
647 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
648
649 QStringList LPTPortNames() const;
650 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
651 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
652
653 QPixmap snapshotIcon (bool online) const
654 {
655 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
656 }
657
658 QPixmap warningIcon() const { return mWarningIcon; }
659 QPixmap errorIcon() const { return mErrorIcon; }
660
661 /* details generators */
662
663 QString details (const CMedium &aHD, bool aPredictDiff);
664
665 QString details (const CUSBDevice &aDevice) const;
666 QString toolTip (const CUSBDevice &aDevice) const;
667 QString toolTip (const CUSBDeviceFilter &aFilter) const;
668
669 QString detailsReport (const CMachine &aMachine, bool aWithLinks);
670
671 QString platformInfo();
672
673 /* VirtualBox helpers */
674
675#if defined(Q_WS_X11) && !defined(VBOX_OSE)
676 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
677 bool showVirtualBoxLicense();
678#endif
679
680 CSession openSession (const QString &aId, bool aExisting = false);
681
682 /** Shortcut to openSession (aId, true). */
683 CSession openExistingSession (const QString &aId) { return openSession (aId, true); }
684
685 bool startMachine(const QString &strId);
686
687 void startEnumeratingMedia();
688
689 /**
690 * Returns a list of all currently registered media. This list is used to
691 * globally track the accessiblity state of all media on a dedicated thread.
692 *
693 * Note that the media list is initially empty (i.e. before the enumeration
694 * process is started for the first time using #startEnumeratingMedia()).
695 * See #startEnumeratingMedia() for more information about how meida are
696 * sorted in the returned list.
697 */
698 const VBoxMediaList &currentMediaList() const { return mMediaList; }
699
700 /** Returns true if the media enumeration is in progress. */
701 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
702
703 void addMedium (const VBoxMedium &);
704 void updateMedium (const VBoxMedium &);
705 void removeMedium (VBoxDefs::MediumType, const QString &);
706
707 bool findMedium (const CMedium &, VBoxMedium &) const;
708 VBoxMedium findMedium (const QString &aMediumId) const;
709
710 /** Compact version of #findMediumTo(). Asserts if not found. */
711 VBoxMedium getMedium (const CMedium &aObj) const
712 {
713 VBoxMedium medium;
714 if (!findMedium (aObj, medium))
715 AssertFailed();
716 return medium;
717 }
718
719 /* Returns the number of current running Fe/Qt4 main windows. */
720 int mainWindowCount();
721
722 /* various helpers */
723
724 QString languageName() const;
725 QString languageCountry() const;
726 QString languageNameEnglish() const;
727 QString languageCountryEnglish() const;
728 QString languageTranslators() const;
729
730 void retranslateUi();
731
732 /** @internal made public for internal purposes */
733 void cleanup();
734
735 /* public static stuff */
736
737 static bool isDOSType (const QString &aOSTypeId);
738
739 static QString languageId();
740 static void loadLanguage (const QString &aLangId = QString::null);
741 QString helpFile() const;
742
743 static QIcon iconSet (const QPixmap &aNormal,
744 const QPixmap &aDisabled = QPixmap(),
745 const QPixmap &aActive = QPixmap());
746 static QIcon iconSet (const char *aNormal,
747 const char *aDisabled = NULL,
748 const char *aActive = NULL);
749 static QIcon iconSetOnOff (const char *aNormal, const char *aNormalOff,
750 const char *aDisabled = NULL,
751 const char *aDisabledOff = NULL,
752 const char *aActive = NULL,
753 const char *aActiveOff = NULL);
754 static QIcon iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,
755 const char *aNormal, const char *aSmallNormal,
756 const char *aDisabled = NULL,
757 const char *aSmallDisabled = NULL,
758 const char *aActive = NULL,
759 const char *aSmallActive = NULL);
760
761 static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);
762
763 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
764
765 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
766 bool aCanResize = true);
767 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
768 bool aCanResize = true);
769 static QRegion flip (const QRegion &aRegion);
770
771 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
772 bool aCanResize = true);
773
774 static QChar decimalSep();
775 static QString sizeRegexp();
776
777 static quint64 parseSize (const QString &);
778 static QString formatSize (quint64 aSize, uint aDecimal = 2,
779 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
780
781 static quint64 requiredVideoMemory (CMachine *aMachine = 0);
782
783 static QString locationForHTML (const QString &aFileName);
784
785 static QString highlight (const QString &aStr, bool aToolTip = false);
786
787 static QString replaceHtmlEntities(QString strText);
788 static QString emphasize (const QString &aStr);
789
790 static QString systemLanguageId();
791
792 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
793
794 static QString removeAccelMark (const QString &aText);
795
796 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
797 static QString extractKeyFromActionText (const QString &aText);
798
799 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
800
801 static QWidget *findWidget (QWidget *aParent, const char *aName,
802 const char *aClassName = NULL,
803 bool aRecursive = false);
804
805 static QList <QPair <QString, QString> > HDDBackends();
806
807 /* Qt 4.2.0 support function */
808 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
809 {
810#if QT_VERSION < 0x040300
811 /* Deprecated since > 4.2 */
812 aLayout->setMargin (aMargin);
813#else
814 /* New since > 4.2 */
815 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
816#endif
817 }
818
819 static QString documentsPath();
820
821#ifdef VBOX_WITH_VIDEOHWACCEL
822 static bool isAcceleration2DVideoAvailable();
823
824 /** additional video memory required for the best 2D support performance
825 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
826 static quint64 required2DOffscreenVideoMemory();
827#endif
828
829signals:
830
831 /**
832 * Emitted at the beginning of the enumeration process started by
833 * #startEnumeratingMedia().
834 */
835 void mediumEnumStarted();
836
837 /**
838 * Emitted when a new medium item from the list has updated its
839 * accessibility state.
840 */
841 void mediumEnumerated (const VBoxMedium &aMedum);
842
843 /**
844 * Emitted at the end of the enumeration process started by
845 * #startEnumeratingMedia(). The @a aList argument is passed for
846 * convenience, it is exactly the same as returned by #currentMediaList().
847 */
848 void mediumEnumFinished (const VBoxMediaList &aList);
849
850 /** Emitted when a new media is added using #addMedia(). */
851 void mediumAdded (const VBoxMedium &);
852
853 /** Emitted when the media is updated using #updateMedia(). */
854 void mediumUpdated (const VBoxMedium &);
855
856 /** Emitted when the media is removed using #removeMedia(). */
857 void mediumRemoved (VBoxDefs::MediumType, const QString &);
858
859 /* signals emitted when the VirtualBox callback is called by the server
860 * (note that currently these signals are emitted only when the application
861 * is the in the VM selector mode) */
862
863 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
864 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
865 void machineRegistered (const VBoxMachineRegisteredEvent &e);
866 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
867 void snapshotChanged (const VBoxSnapshotEvent &e);
868#ifdef VBOX_GUI_WITH_SYSTRAY
869 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &e);
870 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e);
871 void trayIconShow (const VBoxShowTrayIconEvent &e);
872 void trayIconChanged (const VBoxChangeTrayIconEvent &e);
873#endif
874 void dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &e);
875 void presentationModeChanged (const VBoxChangePresentationModeEvent &e);
876
877 void canShowRegDlg (bool aCanShow);
878 void canShowUpdDlg (bool aCanShow);
879
880public slots:
881
882 bool openURL (const QString &aURL);
883
884 void showRegistrationDialog (bool aForce = true);
885 void showUpdateDialog (bool aForce = true);
886 void perDayNewVersionNotifier();
887
888protected:
889
890 bool event (QEvent *e);
891 bool eventFilter (QObject *, QEvent *);
892
893private:
894
895 VBoxGlobal();
896 ~VBoxGlobal();
897
898 void init();
899
900 bool mValid;
901
902 CVirtualBox mVBox;
903
904 VBoxGlobalSettings gset;
905
906 VBoxSelectorWnd *mSelectorWnd;
907 VBoxConsoleWnd *mConsoleWnd;
908#ifdef VBOX_WITH_NEW_RUNTIME_CORE
909 UIMachine *m_pVirtualMachine;
910#endif
911 QWidget* mMainWindow;
912
913#ifdef VBOX_WITH_REGISTRATION
914 UIRegistrationWzd *mRegDlg;
915#endif
916 VBoxUpdateDlg *mUpdDlg;
917
918 QString vmUuid;
919
920#ifdef VBOX_GUI_WITH_SYSTRAY
921 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
922 bool mIncreasedWindowCounter : 1;
923#endif
924
925 QThread *mMediaEnumThread;
926 VBoxMediaList mMediaList;
927
928 VBoxDefs::RenderMode vm_render_mode;
929 const char * vm_render_mode_str;
930 bool mIsKWinManaged;
931
932#ifdef VBOX_WITH_DEBUGGER_GUI
933 /** Whether the debugger should be accessible or not.
934 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
935 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
936 bool mDbgEnabled;
937 /** Whether to show the debugger automatically with the console.
938 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
939 bool mDbgAutoShow;
940 /** Whether to show the command line window when mDbgAutoShow is set. */
941 bool mDbgAutoShowCommandLine;
942 /** Whether to show the statistics window when mDbgAutoShow is set. */
943 bool mDbgAutoShowStatistics;
944 /** VBoxDbg module handle. */
945 RTLDRMOD mhVBoxDbg;
946
947 /** Whether to start the VM in paused state or not. */
948 bool mStartPaused;
949#endif
950
951#if defined (Q_WS_WIN32)
952 DWORD dwHTMLHelpCookie;
953#endif
954
955 CVirtualBoxCallback callback;
956
957 QString mVerString;
958 QString mBrandingConfig;
959
960 QList <QString> mFamilyIDs;
961 QList <QList <CGuestOSType> > mTypes;
962 QHash <QString, QPixmap *> mOsTypeIcons;
963
964 QHash <ulong, QPixmap *> mVMStateIcons;
965 QHash <ulong, QColor *> mVMStateColors;
966
967 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
968
969 QULongStringHash mMachineStates;
970 QULongStringHash mSessionStates;
971 QULongStringHash mDeviceTypes;
972
973 QULongStringHash mStorageBuses;
974 QLongStringHash mStorageBusChannels;
975 QLongStringHash mStorageBusDevices;
976 QULongStringHash mSlotTemplates;
977
978 QULongStringHash mDiskTypes;
979 QString mDiskTypes_Differencing;
980
981 QULongStringHash mVRDPAuthTypes;
982 QULongStringHash mPortModeTypes;
983 QULongStringHash mUSBFilterActionTypes;
984 QULongStringHash mAudioDriverTypes;
985 QULongStringHash mAudioControllerTypes;
986 QULongStringHash mNetworkAdapterTypes;
987 QULongStringHash mNetworkAttachmentTypes;
988 QULongStringHash mClipboardTypes;
989 QULongStringHash mStorageControllerTypes;
990 QULongStringHash mUSBDeviceStates;
991
992 QString mUserDefinedPortName;
993
994 QPixmap mWarningIcon, mErrorIcon;
995
996 friend VBoxGlobal &vboxGlobal();
997 friend class VBoxCallback;
998};
999
1000inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
1001
1002// Helper classes
1003////////////////////////////////////////////////////////////////////////////////
1004
1005/**
1006 * Generic asyncronous event.
1007 *
1008 * This abstract class is intended to provide a conveinent way to execute
1009 * code on the main GUI thread asynchronously to the calling party. This is
1010 * done by putting necessary actions to the #handle() function in a subclass
1011 * and then posting an instance of the subclass using #post(). The instance
1012 * must be allocated on the heap using the <tt>new</tt> operation and will be
1013 * automatically deleted after processing. Note that if you don't call #post()
1014 * on the created instance, you have to delete it yourself.
1015 */
1016class VBoxAsyncEvent : public QEvent
1017{
1018public:
1019
1020 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
1021
1022 /**
1023 * Worker function. Gets executed on the GUI thread when the posted event
1024 * is processed by the main event loop.
1025 */
1026 virtual void handle() = 0;
1027
1028 /**
1029 * Posts this event to the main event loop.
1030 * The caller loses ownership of this object after this method returns
1031 * and must not delete the object.
1032 */
1033 void post()
1034 {
1035 QApplication::postEvent (&vboxGlobal(), this);
1036 }
1037};
1038
1039/**
1040 * USB Popup Menu class.
1041 * This class provides the list of USB devices attached to the host.
1042 */
1043class VBoxUSBMenu : public QMenu
1044{
1045 Q_OBJECT
1046
1047public:
1048
1049 VBoxUSBMenu (QWidget *);
1050
1051 const CUSBDevice& getUSB (QAction *aAction);
1052
1053 void setConsole (const CConsole &);
1054
1055private slots:
1056
1057 void processAboutToShow();
1058
1059private:
1060 bool event(QEvent *aEvent);
1061
1062 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
1063 CConsole mConsole;
1064};
1065
1066/**
1067 * Enable/Disable Menu class.
1068 * This class provides enable/disable menu items.
1069 */
1070class VBoxSwitchMenu : public QMenu
1071{
1072 Q_OBJECT
1073
1074public:
1075
1076 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
1077
1078 void setToolTip (const QString &);
1079
1080private slots:
1081
1082 void processAboutToShow();
1083
1084private:
1085
1086 QAction *mAction;
1087 bool mInverted;
1088};
1089
1090#endif /* __VBoxGlobal_h__ */
1091
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