VirtualBox

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

Last change on this file since 19837 was 19837, checked in by vboxsync, 16 years ago

FE/Qt4: 3875: Guest SMP settings - Initial Commit.

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