VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h@ 23373

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

Fe/Qt: Build fix.

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