VirtualBox

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

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

FE/Qt: Added VBOX_WITH_REGISTRATION to guard the registration code; currently undefined for OSE.

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