VirtualBox

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

Last change on this file since 6645 was 6603, checked in by vboxsync, 17 years ago

1761: Create VM session information dialog:

First version of Session Information Dialog implemented.
Dialog Invoked from working VM console by Host+N key combination.
Dialog contains Basic & Runtime tabs with VM details, runtime parameters and HD statistics. Network & Other statistics will be added into GUI when the necessary counters appears.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.9 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
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
19#ifndef __VBoxGlobal_h__
20#define __VBoxGlobal_h__
21
22#include "COMDefs.h"
23
24#include "VBoxGlobalSettings.h"
25
26#include <qapplication.h>
27#include <qpixmap.h>
28#include <qiconset.h>
29#include <qcolor.h>
30#include <quuid.h>
31#include <qthread.h>
32#include <qpopupmenu.h>
33#include <qtooltip.h>
34
35#include <qptrvector.h>
36#include <qvaluevector.h>
37#include <qvaluelist.h>
38#include <qdict.h>
39#include <qintdict.h>
40
41class QAction;
42class QLabel;
43class QToolButton;
44
45// Auxiliary types
46////////////////////////////////////////////////////////////////////////////////
47
48/** Simple media descriptor type. */
49struct VBoxMedia
50{
51 enum Status { Unknown, Ok, Error, Inaccessible };
52
53 VBoxMedia() : type (VBoxDefs::InvalidType), status (Ok) {}
54
55 VBoxMedia (const CUnknown &d, VBoxDefs::DiskType t, Status s)
56 : disk (d), type (t), status (s) {}
57
58 CUnknown disk;
59 VBoxDefs::DiskType type;
60 Status status;
61};
62
63typedef QValueList <VBoxMedia> VBoxMediaList;
64
65// VirtualBox callback events
66////////////////////////////////////////////////////////////////////////////////
67
68class VBoxMachineStateChangeEvent : public QEvent
69{
70public:
71 VBoxMachineStateChangeEvent (const QUuid &aId, CEnums::MachineState aState)
72 : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType)
73 , id (aId), state (aState)
74 {}
75
76 const QUuid id;
77 const CEnums::MachineState state;
78};
79
80class VBoxMachineDataChangeEvent : public QEvent
81{
82public:
83 VBoxMachineDataChangeEvent (const QUuid &aId)
84 : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType)
85 , id (aId)
86 {}
87
88 const QUuid id;
89};
90
91class VBoxMachineRegisteredEvent : public QEvent
92{
93public:
94 VBoxMachineRegisteredEvent (const QUuid &aId, bool aRegistered)
95 : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType)
96 , id (aId), registered (aRegistered)
97 {}
98
99 const QUuid id;
100 const bool registered;
101};
102
103class VBoxSessionStateChangeEvent : public QEvent
104{
105public:
106 VBoxSessionStateChangeEvent (const QUuid &aId, CEnums::SessionState aState)
107 : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType)
108 , id (aId), state (aState)
109 {}
110
111 const QUuid id;
112 const CEnums::SessionState state;
113};
114
115class VBoxSnapshotEvent : public QEvent
116{
117public:
118
119 enum What { Taken, Discarded, Changed };
120
121 VBoxSnapshotEvent (const QUuid &aMachineId, const QUuid &aSnapshotId,
122 What aWhat)
123 : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType)
124 , what (aWhat)
125 , machineId (aMachineId), snapshotId (aSnapshotId)
126 {}
127
128 const What what;
129
130 const QUuid machineId;
131 const QUuid snapshotId;
132};
133
134class VBoxCanShowRegDlgEvent : public QEvent
135{
136public:
137 VBoxCanShowRegDlgEvent (bool aCanShow)
138 : QEvent ((QEvent::Type) VBoxDefs::CanShowRegDlgEventType)
139 , mCanShow (aCanShow)
140 {}
141
142 const bool mCanShow;
143};
144
145// VBoxGlobal
146////////////////////////////////////////////////////////////////////////////////
147
148class VBoxSelectorWnd;
149class VBoxConsoleWnd;
150class VBoxRegistrationDlg;
151
152class VBoxGlobal : public QObject
153{
154 Q_OBJECT
155
156public:
157
158 static VBoxGlobal &instance();
159
160 bool isValid() { return mValid; }
161
162 QString versionString() { return verString; }
163
164 CVirtualBox virtualBox() const { return mVBox; }
165
166 const VBoxGlobalSettings &settings() const { return gset; }
167 bool setSettings (const VBoxGlobalSettings &gs);
168
169 VBoxSelectorWnd &selectorWnd();
170 VBoxConsoleWnd &consoleWnd();
171
172 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
173 QUuid managedVMUuid() const { return vmUuid; }
174
175 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
176 const char *vmRenderModeStr() const { return vm_render_mode_str; }
177
178#ifdef VBOX_WITH_DEBUGGER_GUI
179 bool isDebuggerEnabled() const { return dbg_enabled; }
180 bool isDebuggerVisibleAtStartup() const { return dbg_visible_at_startup; }
181#endif
182
183 /* VBox enum to/from string/icon/color convertors */
184
185 QStringList vmGuestOSTypeDescriptions() const;
186 CGuestOSType vmGuestOSType (int aIndex) const;
187 int vmGuestOSTypeIndex (const QString &aId) const;
188 QPixmap vmGuestOSTypeIcon (const QString &aId) const;
189 QString vmGuestOSTypeDescription (const QString &aId) const;
190
191 QPixmap toIcon (CEnums::MachineState s) const
192 {
193 QPixmap *pm = mStateIcons [s];
194 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
195 return pm ? *pm : QPixmap();
196 }
197
198 const QColor &toColor (CEnums::MachineState s) const
199 {
200 static const QColor none;
201 AssertMsg (vm_state_color [s], ("No color for %d", s));
202 return vm_state_color [s] ? *vm_state_color [s] : none;
203 }
204
205 QString toString (CEnums::MachineState s) const
206 {
207 AssertMsg (!machineStates [s].isNull(), ("No text for %d", s));
208 return machineStates [s];
209 }
210
211 QString toString (CEnums::SessionState s) const
212 {
213 AssertMsg (!sessionStates [s].isNull(), ("No text for %d", s));
214 return sessionStates [s];
215 }
216
217 QString toString (CEnums::DiskControllerType t) const
218 {
219 AssertMsg (!diskControllerTypes [t].isNull(), ("No text for %d", t));
220 return diskControllerTypes [t];
221 }
222
223 QString toString (CEnums::HardDiskType t) const
224 {
225 AssertMsg (!diskTypes [t].isNull(), ("No text for %d", t));
226 return diskTypes [t];
227 }
228
229 QString toString (CEnums::HardDiskStorageType t) const
230 {
231 AssertMsg (!diskStorageTypes [t].isNull(), ("No text for %d", t));
232 return diskStorageTypes [t];
233 }
234
235 QString toString (CEnums::VRDPAuthType t) const
236 {
237 AssertMsg (!vrdpAuthTypes [t].isNull(), ("No text for %d", t));
238 return vrdpAuthTypes [t];
239 }
240
241 QString toString (CEnums::PortMode t) const
242 {
243 AssertMsg (!portModeTypes [t].isNull(), ("No text for %d", t));
244 return portModeTypes [t];
245 }
246
247 QString toString (CEnums::USBDeviceFilterAction t) const
248 {
249 AssertMsg (!usbFilterActionTypes [t].isNull(), ("No text for %d", t));
250 return usbFilterActionTypes [t];
251 }
252
253 QString toString (CEnums::ClipboardMode t) const
254 {
255 AssertMsg (!clipboardTypes [t].isNull(), ("No text for %d", t));
256 return clipboardTypes [t];
257 }
258
259 CEnums::ClipboardMode toClipboardModeType (const QString &s) const
260 {
261 QStringVector::const_iterator it =
262 qFind (clipboardTypes.begin(), clipboardTypes.end(), s);
263 AssertMsg (it != clipboardTypes.end(), ("No value for {%s}", s.latin1()));
264 return CEnums::ClipboardMode (it - clipboardTypes.begin());
265 }
266
267 QString toString (CEnums::IDEControllerType t) const
268 {
269 AssertMsg (!ideControllerTypes [t].isNull(), ("No text for %d", t));
270 return ideControllerTypes [t];
271 }
272
273 CEnums::IDEControllerType toIDEControllerType (const QString &s) const
274 {
275 QStringVector::const_iterator it =
276 qFind (ideControllerTypes.begin(), ideControllerTypes.end(), s);
277 AssertMsg (it != ideControllerTypes.end(), ("No value for {%s}", s.latin1()));
278 return CEnums::IDEControllerType (it - ideControllerTypes.begin());
279 }
280
281 CEnums::VRDPAuthType toVRDPAuthType (const QString &s) const
282 {
283 QStringVector::const_iterator it =
284 qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
285 AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.latin1()));
286 return CEnums::VRDPAuthType (it - vrdpAuthTypes.begin());
287 }
288
289 CEnums::PortMode toPortMode (const QString &s) const
290 {
291 QStringVector::const_iterator it =
292 qFind (portModeTypes.begin(), portModeTypes.end(), s);
293 AssertMsg (it != portModeTypes.end(), ("No value for {%s}", s.latin1()));
294 return CEnums::PortMode (it - portModeTypes.begin());
295 }
296
297 CEnums::USBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
298 {
299 QStringVector::const_iterator it =
300 qFind (usbFilterActionTypes.begin(), usbFilterActionTypes.end(), s);
301 AssertMsg (it != usbFilterActionTypes.end(), ("No value for {%s}", s.latin1()));
302 return CEnums::USBDeviceFilterAction (it - usbFilterActionTypes.begin());
303 }
304
305 /**
306 * Similar to toString (CEnums::HardDiskType), but returns 'Differencing'
307 * for normal hard disks that have a parent hard disk.
308 */
309 QString hardDiskTypeString (const CHardDisk &aHD) const
310 {
311 if (!aHD.GetParent().isNull())
312 {
313 Assert (aHD.GetType() == CEnums::NormalHardDisk);
314 return tr ("Differencing", "hard disk");
315 }
316 return toString (aHD.GetType());
317 }
318
319 QString toString (CEnums::DiskControllerType t, LONG d) const;
320
321 QString toString (CEnums::DeviceType t) const
322 {
323 AssertMsg (!deviceTypes [t].isNull(), ("No text for %d", t));
324 return deviceTypes [t];
325 }
326
327 CEnums::DeviceType toDeviceType (const QString &s) const
328 {
329 QStringVector::const_iterator it =
330 qFind (deviceTypes.begin(), deviceTypes.end(), s);
331 AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.latin1()));
332 return CEnums::DeviceType (it - deviceTypes.begin());
333 }
334
335 QStringList deviceTypeStrings() const;
336
337 QString toString (CEnums::AudioDriverType t) const
338 {
339 AssertMsg (!audioDriverTypes [t].isNull(), ("No text for %d", t));
340 return audioDriverTypes [t];
341 }
342
343 CEnums::AudioDriverType toAudioDriverType (const QString &s) const
344 {
345 QStringVector::const_iterator it =
346 qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
347 AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.latin1()));
348 return CEnums::AudioDriverType (it - audioDriverTypes.begin());
349 }
350
351 QString toString (CEnums::NetworkAttachmentType t) const
352 {
353 AssertMsg (!networkAttachmentTypes [t].isNull(), ("No text for %d", t));
354 return networkAttachmentTypes [t];
355 }
356
357 CEnums::NetworkAttachmentType toNetworkAttachmentType (const QString &s) const
358 {
359 QStringVector::const_iterator it =
360 qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
361 AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.latin1()));
362 return CEnums::NetworkAttachmentType (it - networkAttachmentTypes.begin());
363 }
364
365 QString toString (CEnums::USBDeviceState aState) const
366 {
367 AssertMsg (!USBDeviceStates [aState].isNull(), ("No text for %d", aState));
368 return USBDeviceStates [aState];
369 }
370
371 QStringList COMPortNames() const;
372 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
373 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
374
375 QStringList LPTPortNames() const;
376 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
377 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
378
379 QPixmap snapshotIcon (bool online) const
380 {
381 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
382 }
383
384 /* details generators */
385
386 QString details (const CHardDisk &aHD, bool aPredict = false,
387 bool aDoRefresh = true);
388
389 QString details (const CUSBDevice &aDevice) const;
390 QString toolTip (const CUSBDevice &aDevice) const;
391
392 QString prepareFileNameForHTML (const QString &fn) const;
393
394 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks,
395 bool aDoRefresh = true);
396
397 /* VirtualBox helpers */
398
399#ifdef Q_WS_X11
400 bool showVirtualBoxLicense();
401#endif
402
403 CSession openSession (const QUuid &id);
404
405 bool startMachine (const QUuid &id);
406
407 void startEnumeratingMedia();
408
409 /**
410 * Returns a list of all currently registered media. This list is used
411 * to globally track the accessiblity state of all media on a dedicated
412 * thread. This the list is initially empty (before the first enumeration
413 * process is started using #startEnumeratingMedia()).
414 */
415 const VBoxMediaList &currentMediaList() const { return media_list; }
416
417 /** Returns true if the media enumeration is in progress. */
418 bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
419
420 void addMedia (const VBoxMedia &);
421 void updateMedia (const VBoxMedia &);
422 void removeMedia (VBoxDefs::DiskType, const QUuid &);
423
424 bool findMedia (const CUnknown &, VBoxMedia &) const;
425
426 /* various helpers */
427
428 QString languageName() const;
429 QString languageCountry() const;
430 QString languageNameEnglish() const;
431 QString languageCountryEnglish() const;
432 QString languageTranslators() const;
433
434 void languageChange();
435
436 /** @internal made public for internal purposes */
437 void cleanup();
438
439 /* public static stuff */
440
441 static bool isDOSType (const QString &aOSTypeId);
442
443 static void adoptLabelPixmap (QLabel *);
444
445 static QString languageId();
446 static void loadLanguage (const QString &aLangId = QString::null);
447
448 static QIconSet iconSet (const char *aNormal,
449 const char *aDisabled = 0,
450 const char *aActive = 0);
451 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
452 const char *aDisabled = 0, const char *aSmallDisabled = 0,
453 const char *aActive = 0, const char *aSmallActive = 0);
454
455 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
456
457 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
458 bool aCanResize = true);
459
460 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
461 bool aCanResize = true);
462
463 static QChar decimalSep();
464 static QString sizeRegexp();
465
466 static Q_UINT64 parseSize (const QString &);
467 static QString formatSize (Q_UINT64, int aMode = 0);
468
469 static QString highlight (const QString &aStr, bool aToolTip = false);
470
471 static QString systemLanguageId();
472
473 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
474 const char *aName = 0,
475 const QString &aCaption = QString::null,
476 bool aDirOnly = TRUE,
477 bool resolveSymlinks = TRUE);
478
479 static QString getOpenFileName (const QString &, const QString &, QWidget*,
480 const char*, const QString &,
481 QString *defaultFilter = 0,
482 bool resolveSymLinks = true);
483
484 static QString getFirstExistingDir (const QString &);
485
486 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
487
488 static QString removeAccelMark (const QString &aText);
489
490 static QWidget *findWidget (QWidget *aParent, const char *aName,
491 const char *aClassName = NULL,
492 bool aRecursive = false);
493
494signals:
495
496 /**
497 * Emitted at the beginning of the enumeration process started
498 * by #startEnumeratingMedia().
499 */
500 void mediaEnumStarted();
501
502 /**
503 * Emitted when a new media item from the list has updated
504 * its accessibility state.
505 */
506 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
507
508 /**
509 * Emitted at the end of the enumeration process started
510 * by #startEnumeratingMedia(). The @a aList argument is passed for
511 * convenience, it is exactly the same as returned by #currentMediaList().
512 */
513 void mediaEnumFinished (const VBoxMediaList &aList);
514
515 /** Emitted when a new media is added using #addMedia(). */
516 void mediaAdded (const VBoxMedia &);
517
518 /** Emitted when the media is updated using #updateMedia(). */
519 void mediaUpdated (const VBoxMedia &);
520
521 /** Emitted when the media is removed using #removeMedia(). */
522 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
523
524 /* signals emitted when the VirtualBox callback is called by the server
525 * (not that currently these signals are emitted only when the application
526 * is the in the VM selector mode) */
527
528 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
529 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
530 void machineRegistered (const VBoxMachineRegisteredEvent &e);
531 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
532 void snapshotChanged (const VBoxSnapshotEvent &e);
533
534 void canShowRegDlg (bool aCanShow);
535
536public slots:
537
538 bool openURL (const QString &aURL);
539
540 void showRegistrationDialog (bool aForce = true);
541
542protected:
543
544 bool event (QEvent *e);
545 bool eventFilter (QObject *, QEvent *);
546
547private:
548
549 VBoxGlobal();
550 ~VBoxGlobal() {}
551
552 void init();
553
554 bool mValid;
555
556 CVirtualBox mVBox;
557
558 VBoxGlobalSettings gset;
559
560 VBoxSelectorWnd *mSelectorWnd;
561 VBoxConsoleWnd *mConsoleWnd;
562
563#ifdef VBOX_WITH_REGISTRATION
564 VBoxRegistrationDlg *mRegDlg;
565#endif
566
567 QUuid vmUuid;
568
569 QThread *media_enum_thread;
570 VBoxMediaList media_list;
571
572 VBoxDefs::RenderMode vm_render_mode;
573 const char * vm_render_mode_str;
574
575#ifdef VBOX_WITH_DEBUGGER_GUI
576 bool dbg_enabled;
577 bool dbg_visible_at_startup;
578#endif
579
580#if defined (Q_WS_WIN32)
581 DWORD dwHTMLHelpCookie;
582#endif
583
584 CVirtualBoxCallback callback;
585
586 typedef QValueVector <QString> QStringVector;
587
588 QString verString;
589
590 QValueVector <CGuestOSType> vm_os_types;
591 QDict <QPixmap> vm_os_type_icons;
592 QPtrVector <QColor> vm_state_color;
593
594 QIntDict <QPixmap> mStateIcons;
595 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
596
597 QStringVector machineStates;
598 QStringVector sessionStates;
599 QStringVector deviceTypes;
600 QStringVector diskControllerTypes;
601 QStringVector diskTypes;
602 QStringVector diskStorageTypes;
603 QStringVector vrdpAuthTypes;
604 QStringVector portModeTypes;
605 QStringVector usbFilterActionTypes;
606 QStringVector diskControllerDevices;
607 QStringVector audioDriverTypes;
608 QStringVector networkAttachmentTypes;
609 QStringVector clipboardTypes;
610 QStringVector ideControllerTypes;
611 QStringVector USBDeviceStates;
612
613 QString mUserDefinedPortName;
614
615 mutable bool detailReportTemplatesReady;
616
617 friend VBoxGlobal &vboxGlobal();
618 friend class VBoxCallback;
619};
620
621inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
622
623// Helper classes
624////////////////////////////////////////////////////////////////////////////////
625
626/**
627 * Generic asyncronous event.
628 *
629 * This abstract class is intended to provide a conveinent way to execute
630 * code on the main GUI thread asynchronously to the calling party. This is
631 * done by putting necessary actions to the #handle() function in a subclass
632 * and then posting an instance of the subclass using #post(). The instance
633 * must be allocated on the heap using the <tt>new</tt> operation and will be
634 * automatically deleted after processing. Note that if you don't call #post()
635 * on the created instance, you have to delete it yourself.
636 */
637class VBoxAsyncEvent : public QEvent
638{
639public:
640
641 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
642
643 /**
644 * Worker function. Gets executed on the GUI thread when the posted event
645 * is processed by the main event loop.
646 */
647 virtual void handle() = 0;
648
649 /**
650 * Posts this event to the main event loop.
651 * The caller loses ownership of this object after this method returns
652 * and must not delete the object.
653 */
654 void post()
655 {
656 QApplication::postEvent (&vboxGlobal(), this);
657 }
658};
659
660/**
661 * USB Popup Menu class.
662 * This class provides the list of USB devices attached to the host.
663 */
664class VBoxUSBMenu : public QPopupMenu
665{
666 Q_OBJECT
667
668public:
669
670 enum { USBDevicesMenuNoDevicesId = 1 };
671
672 VBoxUSBMenu (QWidget *);
673
674 const CUSBDevice& getUSB (int);
675
676 void setConsole (const CConsole &);
677
678private slots:
679
680 void processAboutToShow();
681
682 void processHighlighted (int);
683
684private:
685
686 QMap <int, CUSBDevice> mUSBDevicesMap;
687 CConsole mConsole;
688};
689
690
691/**
692 * Enable/Disable Menu class.
693 * This class provides enable/disable menu items.
694 */
695class VBoxSwitchMenu : public QPopupMenu
696{
697 Q_OBJECT
698
699public:
700
701 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
702
703 void setToolTip (const QString &);
704
705private slots:
706
707 void processAboutToShow();
708
709 void processActivated (int);
710
711private:
712
713 QAction *mAction;
714 QString mTip;
715 bool mInverted;
716};
717
718#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