VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h@ 15622

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

backed out 41122, not authorized

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.1 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2007 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
30/* Qt includes */
31#include <QApplication>
32#include <QLayout>
33#include <QHash>
34#include <QPixmap>
35#include <QMenu>
36#include <QStyle>
37#include <QProcess>
38#include <QLinkedList>
39
40class QAction;
41class QLabel;
42class QToolButton;
43
44// Auxiliary types
45////////////////////////////////////////////////////////////////////////////////
46
47/**
48 * Media descriptor for the GUI.
49 *
50 * Maintains the results of the last state (accessibility) check and precomposes
51 * string parameters such as location, size which can be used in various GUI
52 * controls.
53 *
54 * Many getter methods take the boolean @a aNoDiffs argument. Unless explicitly
55 * stated otherwise, this argument, when set to @c true, will cause the
56 * corresponding property of this object's root medium to be returned instead of
57 * its own one. This is useful when hard disk media is represented in the
58 * user-friendly "don't show diffs" mode. For non-hard disk media, the value of
59 * this argument is irrelevant because the root object for such medium is
60 * the medium itself.
61 *
62 * Note that this class "abuses" the KMediaState_NotCreated state value to
63 * indicate that the accessibility check of the given medium (see
64 * #blockAndQueryState()) has not been done yet and therefore some parameters
65 * such as #size() are meaningless because they can be read only from the
66 * accessible medium. The real KMediaState_NotCreated state is not necessary
67 * because this class is only used with created (existing) media.
68 */
69class VBoxMedium
70{
71public:
72
73 /**
74 * Creates a null medium descriptor which is not associated with any medium.
75 * The state field is set to KMediaState_NotCreated.
76 */
77 VBoxMedium()
78 : mType (VBoxDefs::MediaType_Invalid)
79 , mState (KMediaState_NotCreated)
80 , mIsReadOnly (false), mIsUsedInSnapshots (false)
81 , mParent (NULL) {}
82
83 /**
84 * Creates a media descriptor associated with the given medium.
85 *
86 * The state field remain KMediaState_NotCreated until #blockAndQueryState()
87 * is called. All precomposed strings are filled up by implicitly calling
88 * #refresh(), see the #refresh() details for more info.
89 *
90 * One of the hardDisk, dvdImage, or floppyImage members is assigned from
91 * aMedium according to aType. @a aParent must be always NULL for non-hard
92 * disk media.
93 */
94 VBoxMedium (const CMedium &aMedium, VBoxDefs::MediaType aType,
95 VBoxMedium *aParent = NULL)
96 : mMedium (aMedium), mType (aType)
97 , mState (KMediaState_NotCreated)
98 , mIsReadOnly (false), mIsUsedInSnapshots (false)
99 , mParent (aParent) { init(); }
100
101 /**
102 * Similar to the other non-null constructor but sets the media state to
103 * @a aState. Suitable when the media state is known such as right after
104 * creation.
105 */
106 VBoxMedium (const CMedium &aMedium, VBoxDefs::MediaType aType,
107 KMediaState aState)
108 : mMedium (aMedium), mType (aType)
109 , mState (aState)
110 , mIsReadOnly (false), mIsUsedInSnapshots (false)
111 , mParent (NULL) { init(); }
112
113 void blockAndQueryState();
114 void refresh();
115
116 const CMedium &medium() const { return mMedium; };
117
118 VBoxDefs::MediaType type() const { return mType; }
119
120 /**
121 * Media state. In "don't show diffs" mode, this is the worst state (in
122 * terms of inaccessibility) detected on the given hard disk chain.
123 *
124 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
125 */
126 KMediaState state (bool aNoDiffs = false) const
127 {
128 unconst (this)->checkNoDiffs (aNoDiffs);
129 return aNoDiffs ? mNoDiffs.state : mState;
130 }
131
132 QString lastAccessError() const { return mLastAccessError; }
133
134 /**
135 * Result of the last blockAndQueryState() call. Will indicate an error and
136 * contain a proper error info if the last state check fails. In "don't show
137 * diffs" mode, this is the worst result (in terms of inaccessibility)
138 * detected on the given hard disk chain.
139 *
140 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
141 */
142 const COMResult &result (bool aNoDiffs = false) const
143 {
144 unconst (this)->checkNoDiffs (aNoDiffs);
145 return aNoDiffs ? mNoDiffs.result : mResult;
146 }
147
148 const CHardDisk2 &hardDisk() const { return mHardDisk; }
149 const CDVDImage2 &dvdImage() const { return mDVDImage; }
150 const CFloppyImage2 &floppyImage() const { return mFloppyImage; }
151
152 QUuid id() const { return mId; }
153
154 QString location (bool aNoDiffs = false) const
155 { return aNoDiffs ? root().mLocation : mLocation; }
156 QString name (bool aNoDiffs = false) const
157 { return aNoDiffs ? root().mName : mName; }
158
159 QString size (bool aNoDiffs = false) const
160 { return aNoDiffs ? root().mSize : mSize; }
161
162 QString hardDiskFormat (bool aNoDiffs = false) const
163 { return aNoDiffs ? root().mHardDiskFormat : mHardDiskFormat; }
164 QString hardDiskType (bool aNoDiffs = false) const
165 { return aNoDiffs ? root().mHardDiskType : mHardDiskType; }
166 QString logicalSize (bool aNoDiffs = false) const
167 { return aNoDiffs ? root().mLogicalSize : mLogicalSize; }
168
169 QString usage (bool aNoDiffs = false) const
170 { return aNoDiffs ? root().mUsage : mUsage; }
171
172 /**
173 * Returns @c true if this medium is read-only (either because it is
174 * Immutable or because it has child hard disks). Read-only media can only
175 * be attached indirectly.
176 */
177 bool isReadOnly() const { return mIsReadOnly; }
178
179 /**
180 * Returns @c true if this medium is attached to any VM (in the current
181 * state or in a snapshot) in which case #usage() will contain a string with
182 * comma-sparated VM names (with snapshot names, if any, in parenthesis).
183 */
184 bool isUsed() const { return !mUsage.isNull(); }
185
186 /**
187 * Returns @c true if this medium is attached to any VM in any snapshot.
188 * which case #usage() will contain a string with comma-sparated VM names.
189 */
190 bool isUsedInSnapshots() const { return mIsUsedInSnapshots; }
191
192 /**
193 * Returns @c true if this medium is attached to the given machine in the
194 * current state.
195 */
196 bool isAttachedInCurStateTo (const QUuid &aMachineId) const
197 { return mCurStateMachineIds.indexOf (aMachineId) >= 0; }
198
199 /**
200 * Returns a vector of IDs of all machines this medium is attached
201 * to in their current state (i.e. excluding snapshots).
202 */
203 const QList <QUuid> &curStateMachineIds() const
204 { return mCurStateMachineIds; }
205
206 /**
207 * Returns a parent medium. For non-hard disk media, this is always NULL.
208 */
209 VBoxMedium *parent() const { return mParent; }
210
211 VBoxMedium &root() const;
212
213 QString toolTip(bool aNoDiffs = false, bool aCheckRO = false) const;
214 QPixmap icon (bool aNoDiffs = false, bool aCheckRO = false) const;
215
216 /** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */
217 QString toolTipCheckRO (bool aNoDiffs = false) const
218 { return toolTip (aNoDiffs, true); }
219
220 /** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */
221 QPixmap iconCheckRO (bool aNoDiffs = false) const
222 { return icon (aNoDiffs, true); }
223
224 QString details (bool aNoDiffs = false, bool aPredictDiff = false,
225 bool aUseHTML = false) const;
226
227 /** Shortcut to <tt>#details (aNoDiffs, aPredictDiff, true)</tt>. */
228 QString detailsHTML (bool aNoDiffs = false, bool aPredictDiff = false) const
229 { return details (aNoDiffs, aPredictDiff, true); }
230
231 /** Returns @c true if this media descriptor is a null object. */
232 bool isNull() const { return mMedium.isNull(); }
233
234private:
235
236 void init();
237
238 void checkNoDiffs (bool aNoDiffs);
239
240 CMedium mMedium;
241
242 VBoxDefs::MediaType mType;
243
244 KMediaState mState;
245 QString mLastAccessError;
246 COMResult mResult;
247
248 CHardDisk2 mHardDisk;
249 CDVDImage2 mDVDImage;
250 CFloppyImage2 mFloppyImage;
251
252 QUuid mId;
253 QString mLocation;
254 QString mName;
255 QString mSize;
256
257 QString mHardDiskFormat;
258 QString mHardDiskType;
259 QString mLogicalSize;
260
261 QString mUsage;
262 QString mToolTip;
263
264 bool mIsReadOnly : 1;
265 bool mIsUsedInSnapshots : 1;
266
267 QList <QUuid> mCurStateMachineIds;
268
269 VBoxMedium *mParent;
270
271 /**
272 * Used to override some attributes in the user-friendly "don't show diffs"
273 * mode.
274 */
275 struct NoDiffs
276 {
277 NoDiffs() : isSet (false), state (KMediaState_NotCreated) {}
278
279 bool isSet : 1;
280
281 KMediaState state;
282 COMResult result;
283 QString toolTip;
284 }
285 mNoDiffs;
286};
287
288typedef QLinkedList <VBoxMedium> VBoxMediaList;
289
290// VirtualBox callback events
291////////////////////////////////////////////////////////////////////////////////
292
293class VBoxMachineStateChangeEvent : public QEvent
294{
295public:
296 VBoxMachineStateChangeEvent (const QUuid &aId, KMachineState aState)
297 : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType)
298 , id (aId), state (aState)
299 {}
300
301 const QUuid id;
302 const KMachineState state;
303};
304
305class VBoxMachineDataChangeEvent : public QEvent
306{
307public:
308 VBoxMachineDataChangeEvent (const QUuid &aId)
309 : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType)
310 , id (aId)
311 {}
312
313 const QUuid id;
314};
315
316class VBoxMachineRegisteredEvent : public QEvent
317{
318public:
319 VBoxMachineRegisteredEvent (const QUuid &aId, bool aRegistered)
320 : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType)
321 , id (aId), registered (aRegistered)
322 {}
323
324 const QUuid id;
325 const bool registered;
326};
327
328class VBoxSessionStateChangeEvent : public QEvent
329{
330public:
331 VBoxSessionStateChangeEvent (const QUuid &aId, KSessionState aState)
332 : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType)
333 , id (aId), state (aState)
334 {}
335
336 const QUuid id;
337 const KSessionState state;
338};
339
340class VBoxSnapshotEvent : public QEvent
341{
342public:
343
344 enum What { Taken, Discarded, Changed };
345
346 VBoxSnapshotEvent (const QUuid &aMachineId, const QUuid &aSnapshotId,
347 What aWhat)
348 : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType)
349 , what (aWhat)
350 , machineId (aMachineId), snapshotId (aSnapshotId)
351 {}
352
353 const What what;
354
355 const QUuid machineId;
356 const QUuid snapshotId;
357};
358
359class VBoxCanShowRegDlgEvent : public QEvent
360{
361public:
362 VBoxCanShowRegDlgEvent (bool aCanShow)
363 : QEvent ((QEvent::Type) VBoxDefs::CanShowRegDlgEventType)
364 , mCanShow (aCanShow)
365 {}
366
367 const bool mCanShow;
368};
369
370class VBoxCanShowUpdDlgEvent : public QEvent
371{
372public:
373 VBoxCanShowUpdDlgEvent (bool aCanShow)
374 : QEvent ((QEvent::Type) VBoxDefs::CanShowUpdDlgEventType)
375 , mCanShow (aCanShow)
376 {}
377
378 const bool mCanShow;
379};
380
381class VBoxChangeGUILanguageEvent : public QEvent
382{
383public:
384 VBoxChangeGUILanguageEvent (QString aLangId)
385 : QEvent ((QEvent::Type) VBoxDefs::ChangeGUILanguageEventType)
386 , mLangId (aLangId)
387 {}
388
389 const QString mLangId;
390};
391
392#ifdef VBOX_GUI_WITH_SYSTRAY
393class VBoxMainWindowCountChangeEvent : public QEvent
394{
395public:
396 VBoxMainWindowCountChangeEvent (int aCount)
397 : QEvent ((QEvent::Type) VBoxDefs::MainWindowCountChangeEventType)
398 , mCount (aCount)
399 {}
400
401 const int mCount;
402};
403
404class VBoxCanShowTrayIconEvent : public QEvent
405{
406public:
407 VBoxCanShowTrayIconEvent (bool aCanShow)
408 : QEvent ((QEvent::Type) VBoxDefs::CanShowTrayIconEventType)
409 , mCanShow (aCanShow)
410 {}
411
412 const bool mCanShow;
413};
414
415class VBoxShowTrayIconEvent : public QEvent
416{
417public:
418 VBoxShowTrayIconEvent (bool aShow)
419 : QEvent ((QEvent::Type) VBoxDefs::ShowTrayIconEventType)
420 , mShow (aShow)
421 {}
422
423 const bool mShow;
424};
425
426class VBoxChangeTrayIconEvent : public QEvent
427{
428public:
429 VBoxChangeTrayIconEvent (bool aChanged)
430 : QEvent ((QEvent::Type) VBoxDefs::TrayIconChangeEventType)
431 , mChanged (aChanged)
432 {}
433
434 const bool mChanged;
435};
436#endif
437
438class VBoxChangeDockIconUpdateEvent : public QEvent
439{
440public:
441 VBoxChangeDockIconUpdateEvent (bool aChanged)
442 : QEvent ((QEvent::Type) VBoxDefs::ChangeDockIconUpdateEventType)
443 , mChanged (aChanged)
444 {}
445
446 const bool mChanged;
447};
448
449class Process : public QProcess
450{
451 Q_OBJECT;
452
453public:
454
455 static QByteArray singleShot (const QString &aProcessName,
456 int aTimeout = 5000
457 /* wait for data maximum 5 seconds */)
458 {
459 /* Why is it really needed is because of Qt4.3 bug with QProcess.
460 * This bug is about QProcess sometimes (~70%) do not receive
461 * notification about process was finished, so this makes
462 * 'bool QProcess::waitForFinished (int)' block the GUI thread and
463 * never dismissed with 'true' result even if process was really
464 * started&finished. So we just waiting for some information
465 * on process output and destroy the process with force. Due to
466 * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
467 * we have to change process state to QProcess::NotRunning. */
468
469 QByteArray result;
470 Process process;
471 process.start (aProcessName);
472 bool firstShotReady = process.waitForReadyRead (aTimeout);
473 if (firstShotReady)
474 result = process.readAllStandardOutput();
475 process.setProcessState (QProcess::NotRunning);
476 return result;
477 }
478
479protected:
480
481 Process (QWidget *aParent = 0) : QProcess (aParent) {}
482};
483
484// VBoxGlobal class
485////////////////////////////////////////////////////////////////////////////////
486
487class VBoxSelectorWnd;
488class VBoxConsoleWnd;
489class VBoxRegistrationDlg;
490class VBoxUpdateDlg;
491
492class VBoxGlobal : public QObject
493{
494 Q_OBJECT
495
496public:
497
498 typedef QHash <ulong, QString> QULongStringHash;
499 typedef QHash <long, QString> QLongStringHash;
500
501 static VBoxGlobal &instance();
502
503 bool isValid() { return mValid; }
504
505 QString versionString() { return mVerString; }
506
507 CVirtualBox virtualBox() const { return mVBox; }
508
509 const VBoxGlobalSettings &settings() const { return gset; }
510 bool setSettings (const VBoxGlobalSettings &gs);
511
512 VBoxSelectorWnd &selectorWnd();
513 VBoxConsoleWnd &consoleWnd();
514
515 /* main window handle storage */
516 void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
517 QWidget *mainWindow() const { return mMainWindow; }
518
519 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
520#ifdef VBOX_GUI_WITH_SYSTRAY
521 bool isTrayMenu() const;
522 void setTrayMenu(bool aIsTrayMenu);
523 void trayIconShowSelector();
524 bool trayIconInstall();
525#endif
526 QUuid managedVMUuid() const { return vmUuid; }
527
528 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
529 const char *vmRenderModeStr() const { return vm_render_mode_str; }
530
531#ifdef VBOX_WITH_DEBUGGER_GUI
532 bool isDebuggerEnabled() const { return mDbgEnabled; }
533 bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
534 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
535#else
536 bool isDebuggerAutoShowEnabled() const { return false; }
537#endif
538
539 /* VBox enum to/from string/icon/color convertors */
540
541 QList <CGuestOSType> vmGuestOSFamilyList() const;
542 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
543 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
544 CGuestOSType vmGuestOSType (const QString &aTypeId,
545 const QString &aFamilyId = QString::null) const;
546 QString vmGuestOSTypeDescription (const QString &aTypeId) const;
547
548 QPixmap toIcon (KMachineState s) const
549 {
550 QPixmap *pm = mVMStateIcons.value (s);
551 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
552 return pm ? *pm : QPixmap();
553 }
554
555 const QColor &toColor (KMachineState s) const
556 {
557 static const QColor none;
558 AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
559 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
560 }
561
562 QString toString (KMachineState s) const
563 {
564 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
565 return mMachineStates.value (s);
566 }
567
568 QString toString (KSessionState s) const
569 {
570 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
571 return mSessionStates.value (s);
572 }
573
574 /**
575 * Returns a string representation of the given KStorageBus enum value.
576 * Complementary to #toStorageBusType (const QString &) const.
577 */
578 QString toString (KStorageBus aBus) const
579 {
580 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
581 return mStorageBuses [aBus];
582 }
583
584 /**
585 * Returns a KStorageBus enum value corresponding to the given string
586 * representation. Complementary to #toString (KStorageBus) const.
587 */
588 KStorageBus toStorageBusType (const QString &aBus) const
589 {
590 QULongStringHash::const_iterator it =
591 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
592 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
593 aBus.toLatin1().constData()));
594 return KStorageBus (it.key());
595 }
596
597 QString toString (KStorageBus aBus, LONG aChannel) const;
598 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
599
600 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
601 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
602
603 QString toFullString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
604
605 QString toString (KHardDiskType t) const
606 {
607 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
608 return mDiskTypes.value (t);
609 }
610
611 /**
612 * Similar to toString (KHardDiskType), but returns 'Differencing' for
613 * normal hard disks that have a parent.
614 */
615 QString hardDiskTypeString (const CHardDisk2 &aHD) const
616 {
617 if (!aHD.GetParent().isNull())
618 {
619 Assert (aHD.GetType() == KHardDiskType_Normal);
620 return mDiskTypes_Differencing;
621 }
622 return toString (aHD.GetType());
623 }
624
625 QString toString (KVRDPAuthType t) const
626 {
627 AssertMsg (!mVRDPAuthTypes.value (t).isNull(), ("No text for %d", t));
628 return mVRDPAuthTypes.value (t);
629 }
630
631 QString toString (KPortMode t) const
632 {
633 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
634 return mPortModeTypes.value (t);
635 }
636
637 QString toString (KUSBDeviceFilterAction t) const
638 {
639 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
640 return mUSBFilterActionTypes.value (t);
641 }
642
643 QString toString (KClipboardMode t) const
644 {
645 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
646 return mClipboardTypes.value (t);
647 }
648
649 KClipboardMode toClipboardModeType (const QString &s) const
650 {
651 QULongStringHash::const_iterator it =
652 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
653 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
654 s.toLatin1().constData()));
655 return KClipboardMode (it.key());
656 }
657
658 QString toString (KIDEControllerType t) const
659 {
660 AssertMsg (!mIDEControllerTypes.value (t).isNull(), ("No text for %d", t));
661 return mIDEControllerTypes.value (t);
662 }
663
664 KIDEControllerType toIDEControllerType (const QString &s) const
665 {
666 QULongStringHash::const_iterator it =
667 qFind (mIDEControllerTypes.begin(), mIDEControllerTypes.end(), s);
668 AssertMsg (it != mIDEControllerTypes.end(), ("No value for {%s}",
669 s.toLatin1().constData()));
670 return KIDEControllerType (it.key());
671 }
672
673 KVRDPAuthType toVRDPAuthType (const QString &s) const
674 {
675 QULongStringHash::const_iterator it =
676 qFind (mVRDPAuthTypes.begin(), mVRDPAuthTypes.end(), s);
677 AssertMsg (it != mVRDPAuthTypes.end(), ("No value for {%s}",
678 s.toLatin1().constData()));
679 return KVRDPAuthType (it.key());
680 }
681
682 KPortMode toPortMode (const QString &s) const
683 {
684 QULongStringHash::const_iterator it =
685 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
686 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
687 s.toLatin1().constData()));
688 return KPortMode (it.key());
689 }
690
691 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
692 {
693 QULongStringHash::const_iterator it =
694 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
695 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
696 s.toLatin1().constData()));
697 return KUSBDeviceFilterAction (it.key());
698 }
699
700 QString toString (KDeviceType t) const
701 {
702 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
703 return mDeviceTypes.value (t);
704 }
705
706 KDeviceType toDeviceType (const QString &s) const
707 {
708 QULongStringHash::const_iterator it =
709 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
710 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
711 s.toLatin1().constData()));
712 return KDeviceType (it.key());
713 }
714
715 QStringList deviceTypeStrings() const;
716
717 QString toString (KAudioDriverType t) const
718 {
719 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
720 return mAudioDriverTypes.value (t);
721 }
722
723 KAudioDriverType toAudioDriverType (const QString &s) const
724 {
725 QULongStringHash::const_iterator it =
726 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
727 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
728 s.toLatin1().constData()));
729 return KAudioDriverType (it.key());
730 }
731
732 QString toString (KAudioControllerType t) const
733 {
734 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
735 return mAudioControllerTypes.value (t);
736 }
737
738 KAudioControllerType toAudioControllerType (const QString &s) const
739 {
740 QULongStringHash::const_iterator it =
741 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
742 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
743 s.toLatin1().constData()));
744 return KAudioControllerType (it.key());
745 }
746
747 QString toString (KNetworkAdapterType t) const
748 {
749 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
750 return mNetworkAdapterTypes.value (t);
751 }
752
753 KNetworkAdapterType toNetworkAdapterType (const QString &s) const
754 {
755 QULongStringHash::const_iterator it =
756 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
757 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
758 s.toLatin1().constData()));
759 return KNetworkAdapterType (it.key());
760 }
761
762 QString toString (KNetworkAttachmentType t) const
763 {
764 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
765 return mNetworkAttachmentTypes.value (t);
766 }
767
768 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
769 {
770 QULongStringHash::const_iterator it =
771 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
772 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
773 s.toLatin1().constData()));
774 return KNetworkAttachmentType (it.key());
775 }
776
777 QString toString (KUSBDeviceState aState) const
778 {
779 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
780 return mUSBDeviceStates.value (aState);
781 }
782
783 QStringList COMPortNames() const;
784 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
785 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
786
787 QStringList LPTPortNames() const;
788 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
789 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
790
791 QPixmap snapshotIcon (bool online) const
792 {
793 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
794 }
795
796 QPixmap warningIcon() const { return mWarningIcon; }
797 QPixmap errorIcon() const { return mErrorIcon; }
798
799 /* details generators */
800
801 QString details (const CHardDisk2 &aHD, bool aPredictDiff);
802
803 QString details (const CUSBDevice &aDevice) const;
804 QString toolTip (const CUSBDevice &aDevice) const;
805 QString toolTip (const CUSBDeviceFilter &aFilter) const;
806
807 QString detailsReport (const CMachine &aMachine, bool aIsNewVM,
808 bool aWithLinks);
809
810 QString platformInfo();
811
812 /* VirtualBox helpers */
813
814#if defined(Q_WS_X11) && !defined(VBOX_OSE)
815 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
816 bool showVirtualBoxLicense();
817#endif
818
819 bool checkForAutoConvertedSettings (bool aAfterRefresh = false);
820
821 void checkForAutoConvertedSettingsAfterRefresh()
822 { checkForAutoConvertedSettings (true); }
823
824 CSession openSession (const QUuid &aId, bool aExisting = false);
825
826 /** Shortcut to openSession (aId, true). */
827 CSession openExistingSession (const QUuid &aId) { return openSession (aId, true); }
828
829 bool startMachine (const QUuid &id);
830
831 void startEnumeratingMedia();
832
833 /**
834 * Returns a list of all currently registered media. This list is used to
835 * globally track the accessiblity state of all media on a dedicated thread.
836 *
837 * Note that the media list is initially empty (i.e. before the enumeration
838 * process is started for the first time using #startEnumeratingMedia()).
839 * See #startEnumeratingMedia() for more information about how meida are
840 * sorted in the returned list.
841 */
842 const VBoxMediaList &currentMediaList() const { return mMediaList; }
843
844 /** Returns true if the media enumeration is in progress. */
845 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
846
847 void addMedium (const VBoxMedium &);
848 void updateMedium (const VBoxMedium &);
849 void removeMedium (VBoxDefs::MediaType, const QUuid &);
850
851 bool findMedium (const CMedium &, VBoxMedium &) const;
852
853 /** Compact version of #findMediumTo(). Asserts if not found. */
854 VBoxMedium getMedium (const CMedium &aObj) const
855 {
856 VBoxMedium medium;
857 if (!findMedium (aObj, medium))
858 AssertFailed();
859 return medium;
860 }
861
862 /* Returns the number of current running Fe/Qt4 main windows. */
863 int mainWindowCount();
864
865 /* various helpers */
866
867 QString languageName() const;
868 QString languageCountry() const;
869 QString languageNameEnglish() const;
870 QString languageCountryEnglish() const;
871 QString languageTranslators() const;
872
873 void retranslateUi();
874
875 /** @internal made public for internal purposes */
876 void cleanup();
877
878 /* public static stuff */
879
880 static bool isDOSType (const QString &aOSTypeId);
881
882 static void adoptLabelPixmap (QLabel *);
883
884 static QString languageId();
885 static void loadLanguage (const QString &aLangId = QString::null);
886 QString helpFile() const;
887
888 static QIcon iconSet (const char *aNormal,
889 const char *aDisabled = NULL,
890 const char *aActive = NULL);
891 static QIcon iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,
892 const char *aNormal, const char *aSmallNormal,
893 const char *aDisabled = NULL,
894 const char *aSmallDisabled = NULL,
895 const char *aActive = NULL,
896 const char *aSmallActive = NULL);
897
898 static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);
899
900 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
901
902 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
903 bool aCanResize = true);
904
905 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
906 bool aCanResize = true);
907
908 static QChar decimalSep();
909 static QString sizeRegexp();
910
911 static quint64 parseSize (const QString &);
912 static QString formatSize (quint64 aSize, uint aDecimal = 2,
913 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
914
915 static quint64 requiredVideoMemory (CMachine *aMachine = 0);
916
917 static QString locationForHTML (const QString &aFileName);
918
919 static QString highlight (const QString &aStr, bool aToolTip = false);
920
921 static QString systemLanguageId();
922
923 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
924 const QString &aCaption = QString::null,
925 bool aDirOnly = TRUE,
926 bool resolveSymlinks = TRUE);
927
928 static QString getOpenFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
929 const QString &aCaption, QString *aSelectedFilter = NULL,
930 bool aResolveSymLinks = true);
931
932 static QStringList getOpenFileNames (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
933 const QString &aCaption, QString *aSelectedFilter = NULL,
934 bool aResolveSymLinks = true,
935 bool aSingleFile = false);
936
937 static QString getFirstExistingDir (const QString &);
938
939 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
940
941 static QString removeAccelMark (const QString &aText);
942
943 static QString insertKeyToActionText (const QString &aText, const QString &aKey);
944 static QString extractKeyFromActionText (const QString &aText);
945
946 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
947
948 static QWidget *findWidget (QWidget *aParent, const char *aName,
949 const char *aClassName = NULL,
950 bool aRecursive = false);
951
952 static QList <QPair <QString, QString> > HDDBackends();
953
954 /* Qt 4.2.0 support function */
955 static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
956 {
957#if QT_VERSION < 0x040300
958 /* Deprecated since > 4.2 */
959 aLayout->setMargin (aMargin);
960#else
961 /* New since > 4.2 */
962 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
963#endif
964 }
965
966signals:
967
968 /**
969 * Emitted at the beginning of the enumeration process started by
970 * #startEnumeratingMedia().
971 */
972 void mediumEnumStarted();
973
974 /**
975 * Emitted when a new medium item from the list has updated its
976 * accessibility state.
977 */
978 void mediumEnumerated (const VBoxMedium &aMedum);
979
980 /**
981 * Emitted at the end of the enumeration process started by
982 * #startEnumeratingMedia(). The @a aList argument is passed for
983 * convenience, it is exactly the same as returned by #currentMediaList().
984 */
985 void mediumEnumFinished (const VBoxMediaList &aList);
986
987 /** Emitted when a new media is added using #addMedia(). */
988 void mediumAdded (const VBoxMedium &);
989
990 /** Emitted when the media is updated using #updateMedia(). */
991 void mediumUpdated (const VBoxMedium &);
992
993 /** Emitted when the media is removed using #removeMedia(). */
994 void mediumRemoved (VBoxDefs::MediaType, const QUuid &);
995
996 /* signals emitted when the VirtualBox callback is called by the server
997 * (note that currently these signals are emitted only when the application
998 * is the in the VM selector mode) */
999
1000 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
1001 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
1002 void machineRegistered (const VBoxMachineRegisteredEvent &e);
1003 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
1004 void snapshotChanged (const VBoxSnapshotEvent &e);
1005#ifdef VBOX_GUI_WITH_SYSTRAY
1006 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &e);
1007 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e);
1008 void trayIconShow (const VBoxShowTrayIconEvent &e);
1009 void trayIconChanged (const VBoxChangeTrayIconEvent &e);
1010#endif
1011 void dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &e);
1012
1013 void canShowRegDlg (bool aCanShow);
1014 void canShowUpdDlg (bool aCanShow);
1015
1016public slots:
1017
1018 bool openURL (const QString &aURL);
1019
1020 void showRegistrationDialog (bool aForce = true);
1021 void showUpdateDialog (bool aForce = true);
1022
1023protected:
1024
1025 bool event (QEvent *e);
1026 bool eventFilter (QObject *, QEvent *);
1027
1028private:
1029
1030 VBoxGlobal();
1031 ~VBoxGlobal();
1032
1033 void init();
1034
1035 bool mValid;
1036
1037 CVirtualBox mVBox;
1038
1039 VBoxGlobalSettings gset;
1040
1041 VBoxSelectorWnd *mSelectorWnd;
1042 VBoxConsoleWnd *mConsoleWnd;
1043 QWidget* mMainWindow;
1044
1045#ifdef VBOX_WITH_REGISTRATION
1046 VBoxRegistrationDlg *mRegDlg;
1047#endif
1048 VBoxUpdateDlg *mUpdDlg;
1049
1050 QUuid vmUuid;
1051
1052#ifdef VBOX_GUI_WITH_SYSTRAY
1053 bool mIsTrayMenu; /* Tray icon active/desired? */
1054#endif
1055 QThread *mMediaEnumThread;
1056 VBoxMediaList mMediaList;
1057
1058 VBoxDefs::RenderMode vm_render_mode;
1059 const char * vm_render_mode_str;
1060
1061#ifdef VBOX_WITH_DEBUGGER_GUI
1062 /** Whether the debugger should be accessible or not.
1063 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
1064 * VBOX_GUI_DBG_AUTO_SHOW to enable. */
1065 bool mDbgEnabled;
1066 /** Whether to show the debugger automatically with the console.
1067 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
1068 bool mDbgAutoShow;
1069 /** VBoxDbg module handle. */
1070 RTLDRMOD mhVBoxDbg;
1071#endif
1072
1073#if defined (Q_WS_WIN32)
1074 DWORD dwHTMLHelpCookie;
1075#endif
1076
1077 CVirtualBoxCallback callback;
1078
1079 QString mVerString;
1080
1081 QList <QString> mFamilyIDs;
1082 QList <QList <CGuestOSType> > mTypes;
1083 QHash <QString, QPixmap *> mOsTypeIcons;
1084
1085 QHash <ulong, QPixmap *> mVMStateIcons;
1086 QHash <ulong, QColor *> mVMStateColors;
1087
1088 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
1089
1090 QULongStringHash mMachineStates;
1091 QULongStringHash mSessionStates;
1092 QULongStringHash mDeviceTypes;
1093
1094 QULongStringHash mStorageBuses;
1095 QLongStringHash mStorageBusChannels;
1096 QLongStringHash mStorageBusDevices;
1097
1098 QULongStringHash mDiskTypes;
1099 QString mDiskTypes_Differencing;
1100
1101 QULongStringHash mVRDPAuthTypes;
1102 QULongStringHash mPortModeTypes;
1103 QULongStringHash mUSBFilterActionTypes;
1104 QULongStringHash mAudioDriverTypes;
1105 QULongStringHash mAudioControllerTypes;
1106 QULongStringHash mNetworkAdapterTypes;
1107 QULongStringHash mNetworkAttachmentTypes;
1108 QULongStringHash mClipboardTypes;
1109 QULongStringHash mIDEControllerTypes;
1110 QULongStringHash mUSBDeviceStates;
1111
1112 QString mUserDefinedPortName;
1113
1114 QPixmap mWarningIcon, mErrorIcon;
1115
1116 mutable bool mDetailReportTemplatesReady;
1117
1118 friend VBoxGlobal &vboxGlobal();
1119 friend class VBoxCallback;
1120};
1121
1122inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
1123
1124// Helper classes
1125////////////////////////////////////////////////////////////////////////////////
1126
1127/**
1128 * Generic asyncronous event.
1129 *
1130 * This abstract class is intended to provide a conveinent way to execute
1131 * code on the main GUI thread asynchronously to the calling party. This is
1132 * done by putting necessary actions to the #handle() function in a subclass
1133 * and then posting an instance of the subclass using #post(). The instance
1134 * must be allocated on the heap using the <tt>new</tt> operation and will be
1135 * automatically deleted after processing. Note that if you don't call #post()
1136 * on the created instance, you have to delete it yourself.
1137 */
1138class VBoxAsyncEvent : public QEvent
1139{
1140public:
1141
1142 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
1143
1144 /**
1145 * Worker function. Gets executed on the GUI thread when the posted event
1146 * is processed by the main event loop.
1147 */
1148 virtual void handle() = 0;
1149
1150 /**
1151 * Posts this event to the main event loop.
1152 * The caller loses ownership of this object after this method returns
1153 * and must not delete the object.
1154 */
1155 void post()
1156 {
1157 QApplication::postEvent (&vboxGlobal(), this);
1158 }
1159};
1160
1161/**
1162 * USB Popup Menu class.
1163 * This class provides the list of USB devices attached to the host.
1164 */
1165class VBoxUSBMenu : public QMenu
1166{
1167 Q_OBJECT
1168
1169public:
1170
1171 VBoxUSBMenu (QWidget *);
1172
1173 const CUSBDevice& getUSB (QAction *aAction);
1174
1175 void setConsole (const CConsole &);
1176
1177private slots:
1178
1179 void processAboutToShow();
1180
1181private:
1182 bool event(QEvent *aEvent);
1183
1184 QMap <QAction *, CUSBDevice> mUSBDevicesMap;
1185 CConsole mConsole;
1186};
1187
1188/**
1189 * Enable/Disable Menu class.
1190 * This class provides enable/disable menu items.
1191 */
1192class VBoxSwitchMenu : public QMenu
1193{
1194 Q_OBJECT
1195
1196public:
1197
1198 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
1199
1200 void setToolTip (const QString &);
1201
1202private slots:
1203
1204 void processAboutToShow();
1205
1206private:
1207
1208 QAction *mAction;
1209 bool mInverted;
1210};
1211
1212#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