VirtualBox

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

Last change on this file since 4225 was 4201, checked in by vboxsync, 18 years ago

FE/Qt: Refined indicator tooltips in the console window (+ more useful info for the shared folders indicator).

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

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