VirtualBox

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

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

2292: Remove license display from .deb:
License Viewer implemented:

  1. If the GUI/LicenseAgreed flag is not presented in the user's VirtualBox.xml configuration file extra-data (or this flag's value is not equal to LicenseX-Y.html file version X-Y) then license file LicenseX-Y.html will be displayed to the user.
  2. If the file in LicenseX-Y.html format (for example, License1-3.html) is not presented in RTPathAppDocs() directory then the error-box will be displayed and application will exit (this will force the user to respect the license in case of license file is not found due to user simple removed this file).
  3. If the user read the license (at least scrolls the license-view to the end) and agreed it then the license viewer will be closed and will never bother the user until another license file with higher license version appears in RTPathAppDocs() directory (for example, License1-4.html).

NOTE: Feature temporary disabled due to License1-3.html file is not defaultly generated to RTPathAppDocs() directory yet.

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