VirtualBox

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

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

FE/Qt4: make the KWin hack only active if we are actually running on KWin

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