VirtualBox

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

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

export to OSE again

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.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
37#include <qptrvector.h>
38#include <qvaluevector.h>
39#include <qvaluelist.h>
40#include <qdict.h>
41#include <qintdict.h>
42
43// Auxiliary types
44////////////////////////////////////////////////////////////////////////////////
45
46/** Simple media descriptor type. */
47struct VBoxMedia
48{
49 enum Status { Unknown, Ok, Error, Inaccessible };
50
51 VBoxMedia() : type (VBoxDefs::InvalidType), status (Ok) {}
52
53 VBoxMedia (const CUnknown &d, VBoxDefs::DiskType t, Status s)
54 : disk (d), type (t), status (s) {}
55
56 CUnknown disk;
57 VBoxDefs::DiskType type;
58 Status status;
59};
60
61typedef QValueList <VBoxMedia> VBoxMediaList;
62
63// VirtualBox callback events
64////////////////////////////////////////////////////////////////////////////////
65
66class VBoxMachineStateChangeEvent : public QEvent
67{
68public:
69 VBoxMachineStateChangeEvent (const QUuid &aId, CEnums::MachineState aState)
70 : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType)
71 , id (aId), state (aState)
72 {}
73
74 const QUuid id;
75 const CEnums::MachineState state;
76};
77
78class VBoxMachineDataChangeEvent : public QEvent
79{
80public:
81 VBoxMachineDataChangeEvent (const QUuid &aId)
82 : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType)
83 , id (aId)
84 {}
85
86 const QUuid id;
87};
88
89class VBoxMachineRegisteredEvent : public QEvent
90{
91public:
92 VBoxMachineRegisteredEvent (const QUuid &aId, bool aRegistered)
93 : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType)
94 , id (aId), registered (aRegistered)
95 {}
96
97 const QUuid id;
98 const bool registered;
99};
100
101class VBoxSessionStateChangeEvent : public QEvent
102{
103public:
104 VBoxSessionStateChangeEvent (const QUuid &aId, CEnums::SessionState aState)
105 : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType)
106 , id (aId), state (aState)
107 {}
108
109 const QUuid id;
110 const CEnums::SessionState state;
111};
112
113class VBoxSnapshotEvent : public QEvent
114{
115public:
116
117 enum What { Taken, Discarded, Changed };
118
119 VBoxSnapshotEvent (const QUuid &aMachineId, const QUuid &aSnapshotId,
120 What aWhat)
121 : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType)
122 , what (aWhat)
123 , machineId (aMachineId), snapshotId (aSnapshotId)
124 {}
125
126 const What what;
127
128 const QUuid machineId;
129 const QUuid snapshotId;
130};
131
132// VBoxGlobal
133////////////////////////////////////////////////////////////////////////////////
134
135class VBoxSelectorWnd;
136class VBoxConsoleWnd;
137
138class VBoxGlobal : public QObject
139{
140 Q_OBJECT
141
142public:
143
144 static VBoxGlobal &instance();
145
146 bool isValid() { return valid; }
147
148 QString versionString() { return verString; }
149
150 CVirtualBox virtualBox() const { return vbox; }
151
152 const VMGlobalSettings &settings() const { return gset; }
153 bool setSettings (const VMGlobalSettings &gs);
154
155 VBoxSelectorWnd &selectorWnd();
156 VBoxConsoleWnd &consoleWnd();
157
158 bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
159 QUuid managedVMUuid() const { return vmUuid; }
160
161 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
162 const char *vmRenderModeStr() const { return vm_render_mode_str; }
163
164#ifdef VBOX_WITH_DEBUGGER_GUI
165 bool isDebuggerEnabled() const { return dbg_enabled; }
166 bool isDebuggerVisibleAtStartup() const { return dbg_visible_at_startup; }
167#endif
168
169 // VBox enum to/from string/icon/color convertors
170
171 QStringList vmGuestOSTypeDescriptions() const;
172 CGuestOSType vmGuestOSType (int index) const;
173 int vmGuestOSTypeIndex (const CGuestOSType &type) const;
174 QPixmap vmGuestOSTypeIcon (const QString &type) const;
175
176 QPixmap toIcon (CEnums::MachineState s) const
177 {
178 QPixmap *pm = mStateIcons [s];
179 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
180 return pm ? *pm : QPixmap();
181 }
182
183 const QColor &toColor (CEnums::MachineState s) const
184 {
185 static const QColor none;
186 AssertMsg (vm_state_color [s], ("No color for %d", s));
187 return vm_state_color [s] ? *vm_state_color [s] : none;
188 }
189
190 QString toString (CEnums::MachineState s) const
191 {
192 AssertMsg (!machineStates [s].isNull(), ("No text for %d", s));
193 return machineStates [s];
194 }
195
196 QString toString (CEnums::SessionState s) const
197 {
198 AssertMsg (!sessionStates [s].isNull(), ("No text for %d", s));
199 return sessionStates [s];
200 }
201
202 QString toString (CEnums::DiskControllerType t) const
203 {
204 AssertMsg (!diskControllerTypes [t].isNull(), ("No text for %d", t));
205 return diskControllerTypes [t];
206 }
207
208 QString toString (CEnums::HardDiskType t) const
209 {
210 AssertMsg (!diskTypes [t].isNull(), ("No text for %d", t));
211 return diskTypes [t];
212 }
213
214 QString toString (CEnums::HardDiskStorageType t) const
215 {
216 AssertMsg (!diskStorageTypes [t].isNull(), ("No text for %d", t));
217 return diskStorageTypes [t];
218 }
219
220 QString toString (CEnums::VRDPAuthType t) const
221 {
222 AssertMsg (!vrdpAuthTypes [t].isNull(), ("No text for %d", t));
223 return vrdpAuthTypes [t];
224 }
225
226 CEnums::VRDPAuthType toVRDPAuthType (const QString &s) const
227 {
228 QStringVector::const_iterator it =
229 qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
230 AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.latin1()));
231 return CEnums::VRDPAuthType (it - vrdpAuthTypes.begin());
232 }
233
234 /**
235 * Similar to toString (CEnums::HardDiskType), but returns 'Differencing'
236 * for normal hard disks that have a parent hard disk.
237 */
238 QString hardDiskTypeString (const CHardDisk &aHD) const
239 {
240 if (!aHD.GetParent().isNull())
241 {
242 Assert (aHD.GetType() == CEnums::NormalHardDisk);
243 return tr ("Differencing", "hard disk");
244 }
245 return toString (aHD.GetType());
246 }
247
248 QString toString (CEnums::DiskControllerType t, LONG d) const;
249
250 QString toString (CEnums::DeviceType t) const
251 {
252 AssertMsg (!deviceTypes [t].isNull(), ("No text for %d", t));
253 return deviceTypes [t];
254 }
255
256 CEnums::DeviceType toDeviceType (const QString &s) const
257 {
258 QStringVector::const_iterator it =
259 qFind (deviceTypes.begin(), deviceTypes.end(), s);
260 AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.latin1()));
261 return CEnums::DeviceType (it - deviceTypes.begin());
262 }
263
264 QStringList deviceTypeStrings() const;
265
266 QString toString (CEnums::AudioDriverType t) const
267 {
268 AssertMsg (!audioDriverTypes [t].isNull(), ("No text for %d", t));
269 return audioDriverTypes [t];
270 }
271
272 CEnums::AudioDriverType toAudioDriverType (const QString &s) const
273 {
274 QStringVector::const_iterator it =
275 qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
276 AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.latin1()));
277 return CEnums::AudioDriverType (it - audioDriverTypes.begin());
278 }
279
280 QString toString (CEnums::NetworkAttachmentType t) const
281 {
282 AssertMsg (!networkAttachmentTypes [t].isNull(), ("No text for %d", t));
283 return networkAttachmentTypes [t];
284 }
285
286 CEnums::NetworkAttachmentType toNetworkAttachmentType (const QString &s) const
287 {
288 QStringVector::const_iterator it =
289 qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
290 AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.latin1()));
291 return CEnums::NetworkAttachmentType (it - networkAttachmentTypes.begin());
292 }
293
294 QString toString (CEnums::USBDeviceState aState) const
295 {
296 AssertMsg (!USBDeviceStates [aState].isNull(), ("No text for %d", aState));
297 return USBDeviceStates [aState];
298 }
299
300 QPixmap snapshotIcon (bool online) const
301 {
302 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
303 }
304
305 /* details generators */
306
307 QString details (const CHardDisk &aHD, bool aPredict = false) const;
308
309 QString details (const CUSBDevice &aDevice) const;
310 QString toolTip (const CUSBDevice &aDevice) const;
311
312 QString prepareFileNameForHTML (const QString &fn) const;
313
314 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks) const;
315
316 /* VirtualBox helpers */
317
318 CSession openSession (const QUuid &id);
319
320 bool startMachine (const QUuid &id);
321
322 void startEnumeratingMedia();
323 bool isInEnumeratingProcess() { return media_enum_thread ? true : false; }
324
325 /** Returns a list of all currently enumerated media (it is empty if the
326 * enumeration has been finished or never been started). */
327 VBoxMediaList currentMediaList() const { return media_list; }
328
329 /* various helpers */
330
331 void languageChange();
332
333 /* made public for internal purposes */
334 void cleanup();
335
336 /* public static stuff */
337
338 static QIconSet iconSet (const char *aNormal,
339 const char *aDisabled = 0,
340 const char *aActive = 0);
341 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
342 const char *aDisabled = 0, const char *aSmallDisabled = 0,
343 const char *aActive = 0, const char *aSmallActive = 0);
344
345 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
346 bool aCanResize = true);
347
348 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
349 bool aCanResize = true);
350
351 static QChar decimalSep();
352 static QString sizeRegexp();
353
354 static Q_UINT64 parseSize (const QString &);
355 static QString formatSize (Q_UINT64, int aMode = 0);
356
357 static QString highlight (const QString &aStr, bool aToolTip = false);
358
359signals:
360
361 /**
362 * Emitted during the enumeration process started
363 * by #startEnumeratingMedia(). */
364 void mediaEnumerated (const VBoxMedia &media);
365
366 /**
367 * Emitted at the end of the enumeration process started
368 * by #startEnumeratingMedia().
369 * @note #currentMediaList() will return an empty list
370 * when this signal is emitted, use the argument instead. */
371 void mediaEnumerated (const VBoxMediaList &list);
372
373 /* signals emitted when the VirtualBox callback is called by the server
374 * (not that currently these signals are emitted only when the application
375 * is the in the VM selector mode) */
376
377 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
378 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
379 void machineRegistered (const VBoxMachineRegisteredEvent &e);
380 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
381 void snapshotChanged (const VBoxSnapshotEvent &e);
382
383protected:
384
385 bool event (QEvent *e);
386
387private:
388
389 VBoxGlobal();
390 ~VBoxGlobal() {}
391
392 void init();
393
394 bool valid;
395
396 CVirtualBox vbox;
397
398 VMGlobalSettings gset;
399
400 VBoxSelectorWnd *selector_wnd;
401 VBoxConsoleWnd *console_wnd;
402
403 QUuid vmUuid;
404
405 QThread *media_enum_thread;
406 VBoxMediaList media_list;
407
408 VBoxDefs::RenderMode vm_render_mode;
409 const char * vm_render_mode_str;
410
411#ifdef VBOX_WITH_DEBUGGER_GUI
412 bool dbg_enabled;
413 bool dbg_visible_at_startup;
414#endif
415
416#if defined (Q_WS_WIN32)
417 DWORD dwHTMLHelpCookie;
418#endif
419
420 CVirtualBoxCallback callback;
421
422 typedef QValueVector <QString> QStringVector;
423
424 QString verString;
425
426 QValueVector <CGuestOSType> vm_os_types;
427 QDict <QPixmap> vm_os_type_icons;
428 QPtrVector <QColor> vm_state_color;
429
430 QIntDict <QPixmap> mStateIcons;
431 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
432
433 QStringVector machineStates;
434 QStringVector sessionStates;
435 QStringVector deviceTypes;
436 QStringVector diskControllerTypes;
437 QStringVector diskTypes;
438 QStringVector diskStorageTypes;
439 QStringVector vrdpAuthTypes;
440 QStringVector diskControllerDevices;
441 QStringVector audioDriverTypes;
442 QStringVector networkAttachmentTypes;
443 QStringVector USBDeviceStates;
444
445 mutable bool detailReportTemplatesReady;
446
447 friend VBoxGlobal &vboxGlobal();
448 friend class VBoxCallback;
449};
450
451inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
452
453#endif /* __VBoxGlobal_h__ */
454
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