VirtualBox

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

最後變更 在這個檔案從5193是 5193,由 vboxsync 提交於 17 年 前

FE/Qt: Added VBoxGlobal::setTextLabel(), a proper reimpl of QToolButton::setTextLabel() that assigns a correct accel if it is present in the text string.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 20.0 KB
 
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.alldomusa.eu.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;
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 CEnums::VRDPAuthType toVRDPAuthType (const QString &s) const
268 {
269 QStringVector::const_iterator it =
270 qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
271 AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.latin1()));
272 return CEnums::VRDPAuthType (it - vrdpAuthTypes.begin());
273 }
274
275 CEnums::PortMode toPortMode (const QString &s) const
276 {
277 QStringVector::const_iterator it =
278 qFind (portModeTypes.begin(), portModeTypes.end(), s);
279 AssertMsg (it != portModeTypes.end(), ("No value for {%s}", s.latin1()));
280 return CEnums::PortMode (it - portModeTypes.begin());
281 }
282
283 CEnums::USBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
284 {
285 QStringVector::const_iterator it =
286 qFind (usbFilterActionTypes.begin(), usbFilterActionTypes.end(), s);
287 AssertMsg (it != usbFilterActionTypes.end(), ("No value for {%s}", s.latin1()));
288 return CEnums::USBDeviceFilterAction (it - usbFilterActionTypes.begin());
289 }
290
291 /**
292 * Similar to toString (CEnums::HardDiskType), but returns 'Differencing'
293 * for normal hard disks that have a parent hard disk.
294 */
295 QString hardDiskTypeString (const CHardDisk &aHD) const
296 {
297 if (!aHD.GetParent().isNull())
298 {
299 Assert (aHD.GetType() == CEnums::NormalHardDisk);
300 return tr ("Differencing", "hard disk");
301 }
302 return toString (aHD.GetType());
303 }
304
305 QString toString (CEnums::DiskControllerType t, LONG d) const;
306
307 QString toString (CEnums::DeviceType t) const
308 {
309 AssertMsg (!deviceTypes [t].isNull(), ("No text for %d", t));
310 return deviceTypes [t];
311 }
312
313 CEnums::DeviceType toDeviceType (const QString &s) const
314 {
315 QStringVector::const_iterator it =
316 qFind (deviceTypes.begin(), deviceTypes.end(), s);
317 AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.latin1()));
318 return CEnums::DeviceType (it - deviceTypes.begin());
319 }
320
321 QStringList deviceTypeStrings() const;
322
323 QString toString (CEnums::AudioDriverType t) const
324 {
325 AssertMsg (!audioDriverTypes [t].isNull(), ("No text for %d", t));
326 return audioDriverTypes [t];
327 }
328
329 CEnums::AudioDriverType toAudioDriverType (const QString &s) const
330 {
331 QStringVector::const_iterator it =
332 qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
333 AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.latin1()));
334 return CEnums::AudioDriverType (it - audioDriverTypes.begin());
335 }
336
337 QString toString (CEnums::NetworkAttachmentType t) const
338 {
339 AssertMsg (!networkAttachmentTypes [t].isNull(), ("No text for %d", t));
340 return networkAttachmentTypes [t];
341 }
342
343 CEnums::NetworkAttachmentType toNetworkAttachmentType (const QString &s) const
344 {
345 QStringVector::const_iterator it =
346 qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
347 AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.latin1()));
348 return CEnums::NetworkAttachmentType (it - networkAttachmentTypes.begin());
349 }
350
351 QString toString (CEnums::USBDeviceState aState) const
352 {
353 AssertMsg (!USBDeviceStates [aState].isNull(), ("No text for %d", aState));
354 return USBDeviceStates [aState];
355 }
356
357 QStringList COMPortNames() const;
358 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
359 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
360
361 QPixmap snapshotIcon (bool online) const
362 {
363 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
364 }
365
366 /* details generators */
367
368 QString details (const CHardDisk &aHD, bool aPredict = false);
369
370 QString details (const CUSBDevice &aDevice) const;
371 QString toolTip (const CUSBDevice &aDevice) const;
372
373 QString prepareFileNameForHTML (const QString &fn) const;
374
375 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks);
376
377 /* VirtualBox helpers */
378
379#ifdef Q_WS_X11
380 bool showVirtualBoxLicense();
381#endif
382
383 CSession openSession (const QUuid &id);
384
385 bool startMachine (const QUuid &id);
386
387 void startEnumeratingMedia();
388
389 /**
390 * Returns a list of all currently registered media. This list is used
391 * to globally track the accessiblity state of all media on a dedicated
392 * thread. This the list is initially empty (before the first enumeration
393 * process is started using #startEnumeratingMedia()).
394 */
395 const VBoxMediaList &currentMediaList() const { return media_list; }
396
397 /** Returns true if the media enumeration is in progress. */
398 bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
399
400 void addMedia (const VBoxMedia &);
401 void updateMedia (const VBoxMedia &);
402 void removeMedia (VBoxDefs::DiskType, const QUuid &);
403
404 bool findMedia (const CUnknown &, VBoxMedia &) const;
405
406 /* various helpers */
407
408 QString languageName() const;
409 QString languageCountry() const;
410 QString languageNameEnglish() const;
411 QString languageCountryEnglish() const;
412 QString languageTranslators() const;
413
414 void languageChange();
415
416 /** @internal made public for internal purposes */
417 void cleanup();
418
419 /* public static stuff */
420
421 static bool isDOSType (const QString &aOSTypeId);
422
423 static void adoptLabelPixmap (QLabel *);
424
425 static QString languageId();
426 static void loadLanguage (const QString &aLangId = QString::null);
427
428 static QIconSet iconSet (const char *aNormal,
429 const char *aDisabled = 0,
430 const char *aActive = 0);
431 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
432 const char *aDisabled = 0, const char *aSmallDisabled = 0,
433 const char *aActive = 0, const char *aSmallActive = 0);
434
435 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
436
437 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
438 bool aCanResize = true);
439
440 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
441 bool aCanResize = true);
442
443 static QChar decimalSep();
444 static QString sizeRegexp();
445
446 static Q_UINT64 parseSize (const QString &);
447 static QString formatSize (Q_UINT64, int aMode = 0);
448
449 static QString highlight (const QString &aStr, bool aToolTip = false);
450
451 static QString systemLanguageId();
452
453 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
454 const char *aName = 0,
455 const QString &aCaption = QString::null,
456 bool aDirOnly = TRUE,
457 bool resolveSymlinks = TRUE);
458
459 static QString getOpenFileName (const QString &, const QString &, QWidget*,
460 const char*, const QString &,
461 QString *defaultFilter = 0,
462 bool resolveSymLinks = true);
463
464 static QString getFirstExistingDir (const QString &);
465
466 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
467
468 static QString removeAccelMark (const QString &aText);
469
470 static QWidget *findWidget (QWidget *aParent, const char *aName,
471 const char *aClassName = NULL,
472 bool aRecursive = false);
473
474signals:
475
476 /**
477 * Emitted at the beginning of the enumeration process started
478 * by #startEnumeratingMedia().
479 */
480 void mediaEnumStarted();
481
482 /**
483 * Emitted when a new media item from the list has updated
484 * its accessibility state.
485 */
486 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
487
488 /**
489 * Emitted at the end of the enumeration process started
490 * by #startEnumeratingMedia(). The @a aList argument is passed for
491 * convenience, it is exactly the same as returned by #currentMediaList().
492 */
493 void mediaEnumFinished (const VBoxMediaList &aList);
494
495 /** Emitted when a new media is added using #addMedia(). */
496 void mediaAdded (const VBoxMedia &);
497
498 /** Emitted when the media is updated using #updateMedia(). */
499 void mediaUpdated (const VBoxMedia &);
500
501 /** Emitted when the media is removed using #removeMedia(). */
502 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
503
504 /* signals emitted when the VirtualBox callback is called by the server
505 * (not that currently these signals are emitted only when the application
506 * is the in the VM selector mode) */
507
508 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
509 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
510 void machineRegistered (const VBoxMachineRegisteredEvent &e);
511 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
512 void snapshotChanged (const VBoxSnapshotEvent &e);
513
514 void canShowRegDlg (bool aCanShow);
515
516public slots:
517
518 bool openURL (const QString &aURL);
519
520 void showRegistrationDialog (bool aForce = true);
521
522protected:
523
524 bool event (QEvent *e);
525 bool eventFilter (QObject *, QEvent *);
526
527private:
528
529 VBoxGlobal();
530 ~VBoxGlobal() {}
531
532 void init();
533
534 bool mValid;
535
536 CVirtualBox mVBox;
537
538 VBoxGlobalSettings gset;
539
540 VBoxSelectorWnd *mSelectorWnd;
541 VBoxConsoleWnd *mConsoleWnd;
542
543#ifdef VBOX_WITH_REGISTRATION
544 VBoxRegistrationDlg *mRegDlg;
545#endif
546
547 QUuid vmUuid;
548
549 QThread *media_enum_thread;
550 VBoxMediaList media_list;
551
552 VBoxDefs::RenderMode vm_render_mode;
553 const char * vm_render_mode_str;
554
555#ifdef VBOX_WITH_DEBUGGER_GUI
556 bool dbg_enabled;
557 bool dbg_visible_at_startup;
558#endif
559
560#if defined (Q_WS_WIN32)
561 DWORD dwHTMLHelpCookie;
562#endif
563
564 CVirtualBoxCallback callback;
565
566 typedef QValueVector <QString> QStringVector;
567
568 QString verString;
569
570 QValueVector <CGuestOSType> vm_os_types;
571 QDict <QPixmap> vm_os_type_icons;
572 QPtrVector <QColor> vm_state_color;
573
574 QIntDict <QPixmap> mStateIcons;
575 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
576
577 QStringVector machineStates;
578 QStringVector sessionStates;
579 QStringVector deviceTypes;
580 QStringVector diskControllerTypes;
581 QStringVector diskTypes;
582 QStringVector diskStorageTypes;
583 QStringVector vrdpAuthTypes;
584 QStringVector portModeTypes;
585 QStringVector usbFilterActionTypes;
586 QStringVector diskControllerDevices;
587 QStringVector audioDriverTypes;
588 QStringVector networkAttachmentTypes;
589 QStringVector clipboardTypes;
590 QStringVector USBDeviceStates;
591
592 QString mUserDefinedCOMPortName;
593
594 mutable bool detailReportTemplatesReady;
595
596 friend VBoxGlobal &vboxGlobal();
597 friend class VBoxCallback;
598};
599
600inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
601
602// Helper classes
603////////////////////////////////////////////////////////////////////////////////
604
605/**
606 * Generic asyncronous event.
607 *
608 * This abstract class is intended to provide a conveinent way to execute
609 * code on the main GUI thread asynchronously to the calling party. This is
610 * done by putting necessary actions to the #handle() function in a subclass
611 * and then posting an instance of the subclass using #post(). The instance
612 * must be allocated on the heap using the <tt>new</tt> operation and will be
613 * automatically deleted after processing. Note that if you don't call #post()
614 * on the created instance, you have to delete it yourself.
615 */
616class VBoxAsyncEvent : public QEvent
617{
618public:
619
620 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
621
622 /**
623 * Worker function. Gets executed on the GUI thread when the posted event
624 * is processed by the main event loop.
625 */
626 virtual void handle() = 0;
627
628 /**
629 * Posts this event to the main event loop.
630 * The caller loses ownership of this object after this method returns
631 * and must not delete the object.
632 */
633 void post()
634 {
635 QApplication::postEvent (&vboxGlobal(), this);
636 }
637};
638
639/**
640 * USB Popup Menu class.
641 * This class provides the list of USB devices attached to the host.
642 */
643class VBoxUSBMenu : public QPopupMenu
644{
645 Q_OBJECT
646
647public:
648
649 enum { USBDevicesMenuNoDevicesId = 1 };
650
651 VBoxUSBMenu (QWidget *);
652
653 const CUSBDevice& getUSB (int);
654
655 void setConsole (const CConsole &);
656
657private slots:
658
659 void processAboutToShow();
660
661 void processHighlighted (int);
662
663private:
664
665 QMap <int, CUSBDevice> mUSBDevicesMap;
666 CConsole mConsole;
667};
668
669
670/**
671 * Enable/Disable Menu class.
672 * This class provides enable/disable menu items.
673 */
674class VBoxSwitchMenu : public QPopupMenu
675{
676 Q_OBJECT
677
678public:
679
680 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
681
682 void setToolTip (const QString &);
683
684private slots:
685
686 void processAboutToShow();
687
688 void processActivated (int);
689
690private:
691
692 QAction *mAction;
693 QString mTip;
694 bool mInverted;
695};
696
697#endif /* __VBoxGlobal_h__ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette