VirtualBox

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

Last change on this file since 2764 was 2708, checked in by vboxsync, 18 years ago

FE/Qt: Implemented the "Show VM Window" functionality on X11.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxGlobal class declaration
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung 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 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#ifndef __VBoxGlobal_h__
24#define __VBoxGlobal_h__
25
26#include "COMDefs.h"
27
28#include "VBoxGlobalSettings.h"
29
30#include <qapplication.h>
31#include <qpixmap.h>
32#include <qiconset.h>
33#include <qcolor.h>
34#include <quuid.h>
35#include <qthread.h>
36#include <qpopupmenu.h>
37#include <qtooltip.h>
38
39#include <qptrvector.h>
40#include <qvaluevector.h>
41#include <qvaluelist.h>
42#include <qdict.h>
43#include <qintdict.h>
44
45class QAction;
46class QLabel;
47
48// Auxiliary types
49////////////////////////////////////////////////////////////////////////////////
50
51/** Simple media descriptor type. */
52struct VBoxMedia
53{
54 enum Status { Unknown, Ok, Error, Inaccessible };
55
56 VBoxMedia() : type (VBoxDefs::InvalidType), status (Ok) {}
57
58 VBoxMedia (const CUnknown &d, VBoxDefs::DiskType t, Status s)
59 : disk (d), type (t), status (s) {}
60
61 CUnknown disk;
62 VBoxDefs::DiskType type;
63 Status status;
64};
65
66typedef QValueList <VBoxMedia> VBoxMediaList;
67
68// VirtualBox callback events
69////////////////////////////////////////////////////////////////////////////////
70
71class VBoxMachineStateChangeEvent : public QEvent
72{
73public:
74 VBoxMachineStateChangeEvent (const QUuid &aId, CEnums::MachineState aState)
75 : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType)
76 , id (aId), state (aState)
77 {}
78
79 const QUuid id;
80 const CEnums::MachineState state;
81};
82
83class VBoxMachineDataChangeEvent : public QEvent
84{
85public:
86 VBoxMachineDataChangeEvent (const QUuid &aId)
87 : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType)
88 , id (aId)
89 {}
90
91 const QUuid id;
92};
93
94class VBoxMachineRegisteredEvent : public QEvent
95{
96public:
97 VBoxMachineRegisteredEvent (const QUuid &aId, bool aRegistered)
98 : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType)
99 , id (aId), registered (aRegistered)
100 {}
101
102 const QUuid id;
103 const bool registered;
104};
105
106class VBoxSessionStateChangeEvent : public QEvent
107{
108public:
109 VBoxSessionStateChangeEvent (const QUuid &aId, CEnums::SessionState aState)
110 : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType)
111 , id (aId), state (aState)
112 {}
113
114 const QUuid id;
115 const CEnums::SessionState state;
116};
117
118class VBoxSnapshotEvent : public QEvent
119{
120public:
121
122 enum What { Taken, Discarded, Changed };
123
124 VBoxSnapshotEvent (const QUuid &aMachineId, const QUuid &aSnapshotId,
125 What aWhat)
126 : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType)
127 , what (aWhat)
128 , machineId (aMachineId), snapshotId (aSnapshotId)
129 {}
130
131 const What what;
132
133 const QUuid machineId;
134 const QUuid snapshotId;
135};
136
137// VBoxGlobal
138////////////////////////////////////////////////////////////////////////////////
139
140class VBoxSelectorWnd;
141class VBoxConsoleWnd;
142
143class VBoxGlobal : public QObject
144{
145 Q_OBJECT
146
147public:
148
149 static VBoxGlobal &instance();
150
151 bool isValid() { return valid; }
152
153 QString versionString() { return verString; }
154
155 CVirtualBox virtualBox() const { return vbox; }
156
157 const VBoxGlobalSettings &settings() const { return gset; }
158 bool setSettings (const VBoxGlobalSettings &gs);
159
160 VBoxSelectorWnd &selectorWnd();
161 VBoxConsoleWnd &consoleWnd();
162
163 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
164 QUuid managedVMUuid() const { return vmUuid; }
165
166 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
167 const char *vmRenderModeStr() const { return vm_render_mode_str; }
168
169#ifdef VBOX_WITH_DEBUGGER_GUI
170 bool isDebuggerEnabled() const { return dbg_enabled; }
171 bool isDebuggerVisibleAtStartup() const { return dbg_visible_at_startup; }
172#endif
173
174 /* VBox enum to/from string/icon/color convertors */
175
176 QStringList vmGuestOSTypeDescriptions() const;
177 CGuestOSType vmGuestOSType (int aIndex) const;
178 int vmGuestOSTypeIndex (const QString &aId) const;
179 QPixmap vmGuestOSTypeIcon (const QString &aId) const;
180 QString vmGuestOSTypeDescription (const QString &aId) const;
181
182 QPixmap toIcon (CEnums::MachineState s) const
183 {
184 QPixmap *pm = mStateIcons [s];
185 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
186 return pm ? *pm : QPixmap();
187 }
188
189 const QColor &toColor (CEnums::MachineState s) const
190 {
191 static const QColor none;
192 AssertMsg (vm_state_color [s], ("No color for %d", s));
193 return vm_state_color [s] ? *vm_state_color [s] : none;
194 }
195
196 QString toString (CEnums::MachineState s) const
197 {
198 AssertMsg (!machineStates [s].isNull(), ("No text for %d", s));
199 return machineStates [s];
200 }
201
202 QString toString (CEnums::SessionState s) const
203 {
204 AssertMsg (!sessionStates [s].isNull(), ("No text for %d", s));
205 return sessionStates [s];
206 }
207
208 QString toString (CEnums::DiskControllerType t) const
209 {
210 AssertMsg (!diskControllerTypes [t].isNull(), ("No text for %d", t));
211 return diskControllerTypes [t];
212 }
213
214 QString toString (CEnums::HardDiskType t) const
215 {
216 AssertMsg (!diskTypes [t].isNull(), ("No text for %d", t));
217 return diskTypes [t];
218 }
219
220 QString toString (CEnums::HardDiskStorageType t) const
221 {
222 AssertMsg (!diskStorageTypes [t].isNull(), ("No text for %d", t));
223 return diskStorageTypes [t];
224 }
225
226 QString toString (CEnums::VRDPAuthType t) const
227 {
228 AssertMsg (!vrdpAuthTypes [t].isNull(), ("No text for %d", t));
229 return vrdpAuthTypes [t];
230 }
231
232 QString toString (CEnums::USBDeviceFilterAction t) const
233 {
234 AssertMsg (!usbFilterActionTypes [t].isNull(), ("No text for %d", t));
235 return usbFilterActionTypes [t];
236 }
237
238 QString toString (CEnums::ClipboardMode t) const
239 {
240 AssertMsg (!clipboardTypes [t].isNull(), ("No text for %d", t));
241 return clipboardTypes [t];
242 }
243
244 CEnums::ClipboardMode toClipboardModeType (const QString &s) const
245 {
246 QStringVector::const_iterator it =
247 qFind (clipboardTypes.begin(), clipboardTypes.end(), s);
248 AssertMsg (it != clipboardTypes.end(), ("No value for {%s}", s.latin1()));
249 return CEnums::ClipboardMode (it - clipboardTypes.begin());
250 }
251
252 CEnums::VRDPAuthType toVRDPAuthType (const QString &s) const
253 {
254 QStringVector::const_iterator it =
255 qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
256 AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.latin1()));
257 return CEnums::VRDPAuthType (it - vrdpAuthTypes.begin());
258 }
259
260 CEnums::USBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
261 {
262 QStringVector::const_iterator it =
263 qFind (usbFilterActionTypes.begin(), usbFilterActionTypes.end(), s);
264 AssertMsg (it != usbFilterActionTypes.end(), ("No value for {%s}", s.latin1()));
265 return CEnums::USBDeviceFilterAction (it - usbFilterActionTypes.begin());
266 }
267
268 /**
269 * Similar to toString (CEnums::HardDiskType), but returns 'Differencing'
270 * for normal hard disks that have a parent hard disk.
271 */
272 QString hardDiskTypeString (const CHardDisk &aHD) const
273 {
274 if (!aHD.GetParent().isNull())
275 {
276 Assert (aHD.GetType() == CEnums::NormalHardDisk);
277 return tr ("Differencing", "hard disk");
278 }
279 return toString (aHD.GetType());
280 }
281
282 QString toString (CEnums::DiskControllerType t, LONG d) const;
283
284 QString toString (CEnums::DeviceType t) const
285 {
286 AssertMsg (!deviceTypes [t].isNull(), ("No text for %d", t));
287 return deviceTypes [t];
288 }
289
290 CEnums::DeviceType toDeviceType (const QString &s) const
291 {
292 QStringVector::const_iterator it =
293 qFind (deviceTypes.begin(), deviceTypes.end(), s);
294 AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.latin1()));
295 return CEnums::DeviceType (it - deviceTypes.begin());
296 }
297
298 QStringList deviceTypeStrings() const;
299
300 QString toString (CEnums::AudioDriverType t) const
301 {
302 AssertMsg (!audioDriverTypes [t].isNull(), ("No text for %d", t));
303 return audioDriverTypes [t];
304 }
305
306 CEnums::AudioDriverType toAudioDriverType (const QString &s) const
307 {
308 QStringVector::const_iterator it =
309 qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
310 AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.latin1()));
311 return CEnums::AudioDriverType (it - audioDriverTypes.begin());
312 }
313
314 QString toString (CEnums::NetworkAttachmentType t) const
315 {
316 AssertMsg (!networkAttachmentTypes [t].isNull(), ("No text for %d", t));
317 return networkAttachmentTypes [t];
318 }
319
320 CEnums::NetworkAttachmentType toNetworkAttachmentType (const QString &s) const
321 {
322 QStringVector::const_iterator it =
323 qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
324 AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.latin1()));
325 return CEnums::NetworkAttachmentType (it - networkAttachmentTypes.begin());
326 }
327
328 QString toString (CEnums::USBDeviceState aState) const
329 {
330 AssertMsg (!USBDeviceStates [aState].isNull(), ("No text for %d", aState));
331 return USBDeviceStates [aState];
332 }
333
334 QPixmap snapshotIcon (bool online) const
335 {
336 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
337 }
338
339 /* details generators */
340
341 QString details (const CHardDisk &aHD, bool aPredict = false);
342
343 QString details (const CUSBDevice &aDevice) const;
344 QString toolTip (const CUSBDevice &aDevice) const;
345
346 QString prepareFileNameForHTML (const QString &fn) const;
347
348 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks);
349
350 /* VirtualBox helpers */
351
352 CSession openSession (const QUuid &id);
353
354 bool startMachine (const QUuid &id);
355
356 void startEnumeratingMedia();
357
358 /**
359 * Returns a list of all currently registered media. This list is used
360 * to globally track the accessiblity state of all media on a dedicated
361 * thread. This the list is initially empty (before the first enumeration
362 * process is started using #startEnumeratingMedia()).
363 */
364 const VBoxMediaList &currentMediaList() const { return media_list; }
365
366 /** Returns true if the media enumeration is in progress. */
367 bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
368
369 void addMedia (const VBoxMedia &);
370 void updateMedia (const VBoxMedia &);
371 void removeMedia (VBoxDefs::DiskType, const QUuid &);
372
373 bool findMedia (const CUnknown &, VBoxMedia &) const;
374
375 /* various helpers */
376
377 bool openURL (const QString &aURL);
378
379 QString languageName() const;
380 QString languageCountry() const;
381 QString languageNameEnglish() const;
382 QString languageCountryEnglish() const;
383 QString languageTranslators() const;
384
385 void languageChange();
386
387 /** @internal made public for internal purposes */
388 void cleanup();
389
390 /* public static stuff */
391
392 static void adoptLabelPixmap (QLabel *);
393
394 static QString languageId();
395 static void loadLanguage (const QString &aLangId = QString::null);
396
397 static QIconSet iconSet (const char *aNormal,
398 const char *aDisabled = 0,
399 const char *aActive = 0);
400 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
401 const char *aDisabled = 0, const char *aSmallDisabled = 0,
402 const char *aActive = 0, const char *aSmallActive = 0);
403
404 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
405 bool aCanResize = true);
406
407 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
408 bool aCanResize = true);
409
410 static QChar decimalSep();
411 static QString sizeRegexp();
412
413 static Q_UINT64 parseSize (const QString &);
414 static QString formatSize (Q_UINT64, int aMode = 0);
415
416 static QString highlight (const QString &aStr, bool aToolTip = false);
417
418 static QString systemLanguageId();
419
420 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
421 const char *aName = 0,
422 const QString &aCaption = QString::null,
423 bool aDirOnly = TRUE,
424 bool resolveSymlinks = TRUE);
425
426 static QString getOpenFileName (const QString &, const QString &, QWidget*,
427 const char*, const QString &,
428 QString *defaultFilter = 0,
429 bool resolveSymLinks = true);
430
431 static QString getFirstExistingDir (const QString &);
432
433 static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
434
435signals:
436
437 /**
438 * Emitted at the beginning of the enumeration process started
439 * by #startEnumeratingMedia().
440 */
441 void mediaEnumStarted();
442
443 /**
444 * Emitted when a new media item from the list has updated
445 * its accessibility state.
446 */
447 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
448
449 /**
450 * Emitted at the end of the enumeration process started
451 * by #startEnumeratingMedia(). The @a aList argument is passed for
452 * convenience, it is exactly the same as returned by #currentMediaList().
453 */
454 void mediaEnumFinished (const VBoxMediaList &aList);
455
456 /** Emitted when a new media is added using #addMedia(). */
457 void mediaAdded (const VBoxMedia &);
458
459 /** Emitted when the media is updated using #updateMedia(). */
460 void mediaUpdated (const VBoxMedia &);
461
462 /** Emitted when the media is removed using #removeMedia(). */
463 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
464
465 /* signals emitted when the VirtualBox callback is called by the server
466 * (not that currently these signals are emitted only when the application
467 * is the in the VM selector mode) */
468
469 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
470 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
471 void machineRegistered (const VBoxMachineRegisteredEvent &e);
472 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
473 void snapshotChanged (const VBoxSnapshotEvent &e);
474
475protected:
476
477 bool event (QEvent *e);
478 bool eventFilter (QObject *, QEvent *);
479
480private:
481
482 VBoxGlobal();
483 ~VBoxGlobal() {}
484
485 void init();
486
487 bool valid;
488
489 CVirtualBox vbox;
490
491 VBoxGlobalSettings gset;
492
493 VBoxSelectorWnd *selector_wnd;
494 VBoxConsoleWnd *console_wnd;
495
496 QUuid vmUuid;
497
498 QThread *media_enum_thread;
499 VBoxMediaList media_list;
500
501 VBoxDefs::RenderMode vm_render_mode;
502 const char * vm_render_mode_str;
503
504#ifdef VBOX_WITH_DEBUGGER_GUI
505 bool dbg_enabled;
506 bool dbg_visible_at_startup;
507#endif
508
509#if defined (Q_WS_WIN32)
510 DWORD dwHTMLHelpCookie;
511#endif
512
513 CVirtualBoxCallback callback;
514
515 typedef QValueVector <QString> QStringVector;
516
517 QString verString;
518
519 QValueVector <CGuestOSType> vm_os_types;
520 QDict <QPixmap> vm_os_type_icons;
521 QPtrVector <QColor> vm_state_color;
522
523 QIntDict <QPixmap> mStateIcons;
524 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
525
526 QStringVector machineStates;
527 QStringVector sessionStates;
528 QStringVector deviceTypes;
529 QStringVector diskControllerTypes;
530 QStringVector diskTypes;
531 QStringVector diskStorageTypes;
532 QStringVector vrdpAuthTypes;
533 QStringVector usbFilterActionTypes;
534 QStringVector diskControllerDevices;
535 QStringVector audioDriverTypes;
536 QStringVector networkAttachmentTypes;
537 QStringVector clipboardTypes;
538 QStringVector USBDeviceStates;
539
540 mutable bool detailReportTemplatesReady;
541
542 friend VBoxGlobal &vboxGlobal();
543 friend class VBoxCallback;
544};
545
546inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
547
548
549/**
550 * USB Popup Menu class.
551 * This class provides the list of USB devices attached to the host.
552 */
553class VBoxUSBMenu : public QPopupMenu
554{
555 Q_OBJECT
556
557public:
558
559 enum { USBDevicesMenuNoDevicesId = 1 };
560
561 VBoxUSBMenu (QWidget *);
562
563 const CUSBDevice& getUSB (int);
564
565 void setConsole (const CConsole &);
566
567private slots:
568
569 void processAboutToShow();
570
571 void processHighlighted (int);
572
573private:
574
575 QMap <int, CUSBDevice> mUSBDevicesMap;
576 CConsole mConsole;
577};
578
579
580/**
581 * Enable/Disable Menu class.
582 * This class provides enable/disable menu items.
583 */
584class VBoxSwitchMenu : public QPopupMenu
585{
586 Q_OBJECT
587
588public:
589
590 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
591
592 void setToolTip (const QString &);
593
594private slots:
595
596 void processAboutToShow();
597
598 void processActivated (int);
599
600private:
601
602 QAction *mAction;
603 QString mTip;
604 bool mInverted;
605};
606
607#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