VirtualBox

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

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

FE/Qt4: GUI support for the SCSI controllers

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette