VirtualBox

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

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

Main: Improved serial port API (mostly spelling);
FE/Qt: Improved serial port UI (spelling and duplicate handling).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.2 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 QPixmap snapshotIcon (bool online) const
345 {
346 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
347 }
348
349 /* details generators */
350
351 QString details (const CHardDisk &aHD, bool aPredict = false);
352
353 QString details (const CUSBDevice &aDevice) const;
354 QString toolTip (const CUSBDevice &aDevice) const;
355
356 QString prepareFileNameForHTML (const QString &fn) const;
357
358 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks);
359
360 /* VirtualBox helpers */
361
362 CSession openSession (const QUuid &id);
363
364 bool startMachine (const QUuid &id);
365
366 void startEnumeratingMedia();
367
368 /**
369 * Returns a list of all currently registered media. This list is used
370 * to globally track the accessiblity state of all media on a dedicated
371 * thread. This the list is initially empty (before the first enumeration
372 * process is started using #startEnumeratingMedia()).
373 */
374 const VBoxMediaList &currentMediaList() const { return media_list; }
375
376 /** Returns true if the media enumeration is in progress. */
377 bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
378
379 void addMedia (const VBoxMedia &);
380 void updateMedia (const VBoxMedia &);
381 void removeMedia (VBoxDefs::DiskType, const QUuid &);
382
383 bool findMedia (const CUnknown &, VBoxMedia &) const;
384
385 /* various helpers */
386
387 bool openURL (const QString &aURL);
388
389 QString languageName() const;
390 QString languageCountry() const;
391 QString languageNameEnglish() const;
392 QString languageCountryEnglish() const;
393 QString languageTranslators() const;
394
395 void languageChange();
396
397 /** @internal made public for internal purposes */
398 void cleanup();
399
400 /* public static stuff */
401
402 static bool isDOSType (const QString &aOSTypeId);
403
404 static void adoptLabelPixmap (QLabel *);
405
406 static QString languageId();
407 static void loadLanguage (const QString &aLangId = QString::null);
408
409 static QIconSet iconSet (const char *aNormal,
410 const char *aDisabled = 0,
411 const char *aActive = 0);
412 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
413 const char *aDisabled = 0, const char *aSmallDisabled = 0,
414 const char *aActive = 0, const char *aSmallActive = 0);
415
416 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
417 bool aCanResize = true);
418
419 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
420 bool aCanResize = true);
421
422 static QChar decimalSep();
423 static QString sizeRegexp();
424
425 static Q_UINT64 parseSize (const QString &);
426 static QString formatSize (Q_UINT64, int aMode = 0);
427
428 static QString highlight (const QString &aStr, bool aToolTip = false);
429
430 static QString systemLanguageId();
431
432 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
433 const char *aName = 0,
434 const QString &aCaption = QString::null,
435 bool aDirOnly = TRUE,
436 bool resolveSymlinks = TRUE);
437
438 static QString getOpenFileName (const QString &, const QString &, QWidget*,
439 const char*, const QString &,
440 QString *defaultFilter = 0,
441 bool resolveSymLinks = true);
442
443 static QString getFirstExistingDir (const QString &);
444
445 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
446
447 static QString removeAccelMark (const QString &aText);
448
449 static QWidget *findWidget (QWidget *aParent, const char *aName,
450 const char *aClassName = NULL,
451 bool aRecursive = false);
452
453signals:
454
455 /**
456 * Emitted at the beginning of the enumeration process started
457 * by #startEnumeratingMedia().
458 */
459 void mediaEnumStarted();
460
461 /**
462 * Emitted when a new media item from the list has updated
463 * its accessibility state.
464 */
465 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
466
467 /**
468 * Emitted at the end of the enumeration process started
469 * by #startEnumeratingMedia(). The @a aList argument is passed for
470 * convenience, it is exactly the same as returned by #currentMediaList().
471 */
472 void mediaEnumFinished (const VBoxMediaList &aList);
473
474 /** Emitted when a new media is added using #addMedia(). */
475 void mediaAdded (const VBoxMedia &);
476
477 /** Emitted when the media is updated using #updateMedia(). */
478 void mediaUpdated (const VBoxMedia &);
479
480 /** Emitted when the media is removed using #removeMedia(). */
481 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
482
483 /* signals emitted when the VirtualBox callback is called by the server
484 * (not that currently these signals are emitted only when the application
485 * is the in the VM selector mode) */
486
487 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
488 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
489 void machineRegistered (const VBoxMachineRegisteredEvent &e);
490 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
491 void snapshotChanged (const VBoxSnapshotEvent &e);
492
493protected:
494
495 bool event (QEvent *e);
496 bool eventFilter (QObject *, QEvent *);
497
498private:
499
500 VBoxGlobal();
501 ~VBoxGlobal() {}
502
503 void init();
504
505 bool valid;
506
507 CVirtualBox vbox;
508
509 VBoxGlobalSettings gset;
510
511 VBoxSelectorWnd *selector_wnd;
512 VBoxConsoleWnd *console_wnd;
513
514 QUuid vmUuid;
515
516 QThread *media_enum_thread;
517 VBoxMediaList media_list;
518
519 VBoxDefs::RenderMode vm_render_mode;
520 const char * vm_render_mode_str;
521
522#ifdef VBOX_WITH_DEBUGGER_GUI
523 bool dbg_enabled;
524 bool dbg_visible_at_startup;
525#endif
526
527#if defined (Q_WS_WIN32)
528 DWORD dwHTMLHelpCookie;
529#endif
530
531 CVirtualBoxCallback callback;
532
533 typedef QValueVector <QString> QStringVector;
534
535 QString verString;
536
537 QValueVector <CGuestOSType> vm_os_types;
538 QDict <QPixmap> vm_os_type_icons;
539 QPtrVector <QColor> vm_state_color;
540
541 QIntDict <QPixmap> mStateIcons;
542 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
543
544 QStringVector machineStates;
545 QStringVector sessionStates;
546 QStringVector deviceTypes;
547 QStringVector diskControllerTypes;
548 QStringVector diskTypes;
549 QStringVector diskStorageTypes;
550 QStringVector vrdpAuthTypes;
551 QStringVector portModeTypes;
552 QStringVector usbFilterActionTypes;
553 QStringVector diskControllerDevices;
554 QStringVector audioDriverTypes;
555 QStringVector networkAttachmentTypes;
556 QStringVector clipboardTypes;
557 QStringVector USBDeviceStates;
558
559 mutable bool detailReportTemplatesReady;
560
561 friend VBoxGlobal &vboxGlobal();
562 friend class VBoxCallback;
563};
564
565inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
566
567// Helper classes
568////////////////////////////////////////////////////////////////////////////////
569
570/**
571 * Generic asyncronous event.
572 *
573 * This abstract class is intended to provide a conveinent way to execute
574 * code on the main GUI thread asynchronously to the calling party. This is
575 * done by putting necessary actions to the #handle() function in a subclass
576 * and then posting an instance of the subclass using #post(). The instance
577 * must be allocated on the heap using the <tt>new</tt> operation and will be
578 * automatically deleted after processing. Note that if you don't call #post()
579 * on the created instance, you have to delete it yourself.
580 */
581class VBoxAsyncEvent : public QEvent
582{
583public:
584
585 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
586
587 /**
588 * Worker function. Gets executed on the GUI thread when the posted event
589 * is processed by the main event loop.
590 */
591 virtual void handle() = 0;
592
593 /**
594 * Posts this event to the main event loop.
595 * The caller loses ownership of this object after this method returns
596 * and must not delete the object.
597 */
598 void post()
599 {
600 QApplication::postEvent (&vboxGlobal(), this);
601 }
602};
603
604/**
605 * USB Popup Menu class.
606 * This class provides the list of USB devices attached to the host.
607 */
608class VBoxUSBMenu : public QPopupMenu
609{
610 Q_OBJECT
611
612public:
613
614 enum { USBDevicesMenuNoDevicesId = 1 };
615
616 VBoxUSBMenu (QWidget *);
617
618 const CUSBDevice& getUSB (int);
619
620 void setConsole (const CConsole &);
621
622private slots:
623
624 void processAboutToShow();
625
626 void processHighlighted (int);
627
628private:
629
630 QMap <int, CUSBDevice> mUSBDevicesMap;
631 CConsole mConsole;
632};
633
634
635/**
636 * Enable/Disable Menu class.
637 * This class provides enable/disable menu items.
638 */
639class VBoxSwitchMenu : public QPopupMenu
640{
641 Q_OBJECT
642
643public:
644
645 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
646
647 void setToolTip (const QString &);
648
649private slots:
650
651 void processAboutToShow();
652
653 void processActivated (int);
654
655private:
656
657 QAction *mAction;
658 QString mTip;
659 bool mInverted;
660};
661
662#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