VirtualBox

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

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

FE/Qt: Added VRDP UI to the VM Console window.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 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 "VMGlobalSettings.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
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
134// VBoxGlobal
135////////////////////////////////////////////////////////////////////////////////
136
137class VBoxSelectorWnd;
138class VBoxConsoleWnd;
139
140class VBoxGlobal : public QObject
141{
142 Q_OBJECT
143
144public:
145
146 static VBoxGlobal &instance();
147
148 bool isValid() { return valid; }
149
150 QString versionString() { return verString; }
151
152 CVirtualBox virtualBox() const { return vbox; }
153
154 const VMGlobalSettings &settings() const { return gset; }
155 bool setSettings (const VMGlobalSettings &gs);
156
157 VBoxSelectorWnd &selectorWnd();
158 VBoxConsoleWnd &consoleWnd();
159
160 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
161 QUuid managedVMUuid() const { return vmUuid; }
162
163 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
164 const char *vmRenderModeStr() const { return vm_render_mode_str; }
165
166#ifdef VBOX_WITH_DEBUGGER_GUI
167 bool isDebuggerEnabled() const { return dbg_enabled; }
168 bool isDebuggerVisibleAtStartup() const { return dbg_visible_at_startup; }
169#endif
170
171 // VBox enum to/from string/icon/color convertors
172
173 QStringList vmGuestOSTypeDescriptions() const;
174 CGuestOSType vmGuestOSType (int index) const;
175 int vmGuestOSTypeIndex (const CGuestOSType &type) const;
176 QPixmap vmGuestOSTypeIcon (const QString &type) 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 CEnums::VRDPAuthType toVRDPAuthType (const QString &s) const
235 {
236 QStringVector::const_iterator it =
237 qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
238 AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.latin1()));
239 return CEnums::VRDPAuthType (it - vrdpAuthTypes.begin());
240 }
241
242 CEnums::USBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
243 {
244 QStringVector::const_iterator it =
245 qFind (usbFilterActionTypes.begin(), usbFilterActionTypes.end(), s);
246 AssertMsg (it != usbFilterActionTypes.end(), ("No value for {%s}", s.latin1()));
247 return CEnums::USBDeviceFilterAction (it - usbFilterActionTypes.begin());
248 }
249
250 /**
251 * Similar to toString (CEnums::HardDiskType), but returns 'Differencing'
252 * for normal hard disks that have a parent hard disk.
253 */
254 QString hardDiskTypeString (const CHardDisk &aHD) const
255 {
256 if (!aHD.GetParent().isNull())
257 {
258 Assert (aHD.GetType() == CEnums::NormalHardDisk);
259 return tr ("Differencing", "hard disk");
260 }
261 return toString (aHD.GetType());
262 }
263
264 QString toString (CEnums::DiskControllerType t, LONG d) const;
265
266 QString toString (CEnums::DeviceType t) const
267 {
268 AssertMsg (!deviceTypes [t].isNull(), ("No text for %d", t));
269 return deviceTypes [t];
270 }
271
272 CEnums::DeviceType toDeviceType (const QString &s) const
273 {
274 QStringVector::const_iterator it =
275 qFind (deviceTypes.begin(), deviceTypes.end(), s);
276 AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.latin1()));
277 return CEnums::DeviceType (it - deviceTypes.begin());
278 }
279
280 QStringList deviceTypeStrings() const;
281
282 QString toString (CEnums::AudioDriverType t) const
283 {
284 AssertMsg (!audioDriverTypes [t].isNull(), ("No text for %d", t));
285 return audioDriverTypes [t];
286 }
287
288 CEnums::AudioDriverType toAudioDriverType (const QString &s) const
289 {
290 QStringVector::const_iterator it =
291 qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
292 AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.latin1()));
293 return CEnums::AudioDriverType (it - audioDriverTypes.begin());
294 }
295
296 QString toString (CEnums::NetworkAttachmentType t) const
297 {
298 AssertMsg (!networkAttachmentTypes [t].isNull(), ("No text for %d", t));
299 return networkAttachmentTypes [t];
300 }
301
302 CEnums::NetworkAttachmentType toNetworkAttachmentType (const QString &s) const
303 {
304 QStringVector::const_iterator it =
305 qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
306 AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.latin1()));
307 return CEnums::NetworkAttachmentType (it - networkAttachmentTypes.begin());
308 }
309
310 QString toString (CEnums::USBDeviceState aState) const
311 {
312 AssertMsg (!USBDeviceStates [aState].isNull(), ("No text for %d", aState));
313 return USBDeviceStates [aState];
314 }
315
316 QPixmap snapshotIcon (bool online) const
317 {
318 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
319 }
320
321 /* details generators */
322
323 QString details (const CHardDisk &aHD, bool aPredict = false) const;
324
325 QString details (const CUSBDevice &aDevice) const;
326 QString toolTip (const CUSBDevice &aDevice) const;
327
328 QString prepareFileNameForHTML (const QString &fn) const;
329
330 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks) const;
331
332 /* VirtualBox helpers */
333
334 CSession openSession (const QUuid &id);
335
336 bool startMachine (const QUuid &id);
337
338 void startEnumeratingMedia();
339
340 /**
341 * Returns a list of all currently registered media. This list is used
342 * to globally track the accessiblity state of all media on a dedicated
343 * thread. This the list is initially empty (before the first enumeration
344 * process is started using #startEnumeratingMedia()).
345 */
346 const VBoxMediaList &currentMediaList() const { return media_list; }
347
348 /** Returns true if the media enumeration is in progress. */
349 bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
350
351 void addMedia (const VBoxMedia &);
352 void updateMedia (const VBoxMedia &);
353 void removeMedia (VBoxDefs::DiskType, const QUuid &);
354
355 /* various helpers */
356
357 void languageChange();
358
359 /* made public for internal purposes */
360 void cleanup();
361
362 /* public static stuff */
363
364 static QIconSet iconSet (const char *aNormal,
365 const char *aDisabled = 0,
366 const char *aActive = 0);
367 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
368 const char *aDisabled = 0, const char *aSmallDisabled = 0,
369 const char *aActive = 0, const char *aSmallActive = 0);
370
371 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
372 bool aCanResize = true);
373
374 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
375 bool aCanResize = true);
376
377 static QChar decimalSep();
378 static QString sizeRegexp();
379
380 static Q_UINT64 parseSize (const QString &);
381 static QString formatSize (Q_UINT64, int aMode = 0);
382
383 static QString highlight (const QString &aStr, bool aToolTip = false);
384
385signals:
386
387 /**
388 * Emitted at the beginning of the enumeration process started
389 * by #startEnumeratingMedia().
390 */
391 void mediaEnumStarted();
392
393 /**
394 * Emitted when a new media item from the list has updated
395 * its accessibility state.
396 */
397 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
398
399 /**
400 * Emitted at the end of the enumeration process started
401 * by #startEnumeratingMedia(). The @a aList argument is passed for
402 * convenience, it is exactly the same as returned by #currentMediaList().
403 */
404 void mediaEnumFinished (const VBoxMediaList &aList);
405
406 /** Emitted when a new media is added using #addMedia(). */
407 void mediaAdded (const VBoxMedia &);
408
409 /** Emitted when the media is updated using #updateMedia(). */
410 void mediaUpdated (const VBoxMedia &);
411
412 /** Emitted when the media is removed using #removeMedia(). */
413 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
414
415 /* signals emitted when the VirtualBox callback is called by the server
416 * (not that currently these signals are emitted only when the application
417 * is the in the VM selector mode) */
418
419 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
420 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
421 void machineRegistered (const VBoxMachineRegisteredEvent &e);
422 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
423 void snapshotChanged (const VBoxSnapshotEvent &e);
424
425protected:
426
427 bool event (QEvent *e);
428
429private:
430
431 VBoxGlobal();
432 ~VBoxGlobal() {}
433
434 void init();
435
436 bool valid;
437
438 CVirtualBox vbox;
439
440 VMGlobalSettings gset;
441
442 VBoxSelectorWnd *selector_wnd;
443 VBoxConsoleWnd *console_wnd;
444
445 QUuid vmUuid;
446
447 QThread *media_enum_thread;
448 VBoxMediaList media_list;
449
450 VBoxDefs::RenderMode vm_render_mode;
451 const char * vm_render_mode_str;
452
453#ifdef VBOX_WITH_DEBUGGER_GUI
454 bool dbg_enabled;
455 bool dbg_visible_at_startup;
456#endif
457
458#if defined (Q_WS_WIN32)
459 DWORD dwHTMLHelpCookie;
460#endif
461
462 CVirtualBoxCallback callback;
463
464 typedef QValueVector <QString> QStringVector;
465
466 QString verString;
467
468 QValueVector <CGuestOSType> vm_os_types;
469 QDict <QPixmap> vm_os_type_icons;
470 QPtrVector <QColor> vm_state_color;
471
472 QIntDict <QPixmap> mStateIcons;
473 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
474
475 QStringVector machineStates;
476 QStringVector sessionStates;
477 QStringVector deviceTypes;
478 QStringVector diskControllerTypes;
479 QStringVector diskTypes;
480 QStringVector diskStorageTypes;
481 QStringVector vrdpAuthTypes;
482 QStringVector usbFilterActionTypes;
483 QStringVector diskControllerDevices;
484 QStringVector audioDriverTypes;
485 QStringVector networkAttachmentTypes;
486 QStringVector USBDeviceStates;
487
488 mutable bool detailReportTemplatesReady;
489
490 friend VBoxGlobal &vboxGlobal();
491 friend class VBoxCallback;
492};
493
494inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
495
496
497/**
498 * USB Popup Menu class.
499 * This class provides the list of USB devices attached to the host.
500 */
501class VBoxUSBMenu : public QPopupMenu
502{
503 Q_OBJECT
504
505public:
506
507 enum { USBDevicesMenuNoDevicesId = 1 };
508
509 VBoxUSBMenu (QWidget *);
510
511 const CUSBDevice& getUSB (int);
512
513 void setConsole (const CConsole &);
514
515private slots:
516
517 void processAboutToShow();
518
519 void processHighlighted (int);
520
521private:
522
523 QMap <int, CUSBDevice> mUSBDevicesMap;
524 CConsole mConsole;
525};
526
527#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