VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 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 { Ok = 0, Error = 0x01, Inaccessible = 0x02 };
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 /**
221 * Similar to toString (CEnums::HardDiskType), but returns 'Differencing'
222 * for normal hard disks that have a parent hard disk.
223 */
224 QString hardDiskTypeString (const CHardDisk &aHD) const
225 {
226 if (!aHD.GetParent().isNull())
227 {
228 Assert (aHD.GetType() == CEnums::NormalHardDisk);
229 return tr ("Differencing", "hard disk");
230 }
231 return toString (aHD.GetType());
232 }
233
234 QString toString (CEnums::DiskControllerType t, LONG d) const;
235
236 QString toString (CEnums::DeviceType t) const
237 {
238 AssertMsg (!deviceTypes [t].isNull(), ("No text for %d", t));
239 return deviceTypes [t];
240 }
241
242 CEnums::DeviceType toDeviceType (const QString &s) const
243 {
244 QStringVector::const_iterator it =
245 qFind (deviceTypes.begin(), deviceTypes.end(), s);
246 AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.latin1()));
247 return CEnums::DeviceType (it - deviceTypes.begin());
248 }
249
250 QStringList deviceTypeStrings() const;
251
252 QString toString (CEnums::AudioDriverType t) const
253 {
254 AssertMsg (!audioDriverTypes [t].isNull(), ("No text for %d", t));
255 return audioDriverTypes [t];
256 }
257
258 CEnums::AudioDriverType toAudioDriverType (const QString &s) const
259 {
260 QStringVector::const_iterator it =
261 qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
262 AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.latin1()));
263 return CEnums::AudioDriverType (it - audioDriverTypes.begin());
264 }
265
266 QString toString (CEnums::NetworkAttachmentType t) const
267 {
268 AssertMsg (!networkAttachmentTypes [t].isNull(), ("No text for %d", t));
269 return networkAttachmentTypes [t];
270 }
271
272 CEnums::NetworkAttachmentType toNetworkAttachmentType (const QString &s) const
273 {
274 QStringVector::const_iterator it =
275 qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
276 AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.latin1()));
277 return CEnums::NetworkAttachmentType (it - networkAttachmentTypes.begin());
278 }
279
280 QPixmap snapshotIcon (bool online) const
281 {
282 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
283 }
284
285 // details generators
286
287 QString details (const CHardDisk &aHD, bool aPredict = false) const;
288
289 QString prepareFileNameForHTML (const QString &fn) const;
290
291 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks) const;
292
293 // VirtualBox helpers
294
295 CSession openSession (const QUuid &id);
296
297 bool startMachine (const QUuid &id);
298
299 void startEnumeratingMedia();
300
301 /** Returns a list of all currently enumerated media (it is empty if the
302 * enumeration has been finished or never been started). */
303 VBoxMediaList currentMediaList() const { return media_list; }
304
305 // various helpers
306
307 void languageChange();
308
309 void cleanup(); // made public for internal purposes
310
311 // public static stuff
312
313 static QIconSet iconSet (const char *aNormal,
314 const char *aDisabled = 0,
315 const char *aActive = 0);
316 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
317 const char *aDisabled = 0, const char *aSmallDisabled = 0,
318 const char *aActive = 0, const char *aSmallActive = 0);
319
320 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
321 bool aCanResize = true);
322
323 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
324 bool aCanResize = true);
325
326 static unsigned long long parseSize (QString);
327 static QString formatSize (unsigned long long);
328
329signals:
330
331 /**
332 * Emitted during the enumeration process started
333 * by #startEnumeratingMedia(). */
334 void mediaEnumerated (const VBoxMedia &media);
335
336 /**
337 * Emitted at the end of the enumeration process started
338 * by #startEnumeratingMedia().
339 * @note #currentMediaList() will return an empty list
340 * when this signal is emitted, use the argument instead. */
341 void mediaEnumerated (const VBoxMediaList &list);
342
343 // signals emitted when the VirtualBox callback is called by the server
344 // (not that currently these signals are emitted only when the application
345 // is the in the VM selector mode)
346
347 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
348 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
349 void machineRegistered (const VBoxMachineRegisteredEvent &e);
350 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
351 void snapshotChanged (const VBoxSnapshotEvent &e);
352
353protected:
354
355 bool event (QEvent *e);
356
357private:
358
359 VBoxGlobal();
360 ~VBoxGlobal() {}
361
362 void init();
363
364 bool valid;
365
366 CVirtualBox vbox;
367
368 VMGlobalSettings gset;
369
370 VBoxSelectorWnd *selector_wnd;
371 VBoxConsoleWnd *console_wnd;
372
373 QUuid vmUuid;
374
375 QThread *media_enum_thread;
376 VBoxMediaList media_list;
377
378 VBoxDefs::RenderMode vm_render_mode;
379 const char * vm_render_mode_str;
380
381#ifdef VBOX_WITH_DEBUGGER_GUI
382 bool dbg_enabled;
383 bool dbg_visible_at_startup;
384#endif
385
386#if defined (Q_WS_WIN32)
387 DWORD dwHTMLHelpCookie;
388#endif
389
390 CVirtualBoxCallback callback;
391
392 typedef QValueVector <QString> QStringVector;
393
394 QString verString;
395
396 QValueVector <CGuestOSType> vm_os_types;
397 QDict <QPixmap> vm_os_type_icons;
398 QPtrVector <QColor> vm_state_color;
399
400 QIntDict <QPixmap> mStateIcons;
401 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
402
403 QStringVector machineStates;
404 QStringVector sessionStates;
405 QStringVector deviceTypes;
406 QStringVector diskControllerTypes;
407 QStringVector diskTypes;
408 QStringVector diskStorageTypes;
409 QStringVector diskControllerDevices;
410 QStringVector audioDriverTypes;
411 QStringVector networkAttachmentTypes;
412
413 mutable bool detailReportTemplatesReady;
414
415 friend VBoxGlobal &vboxGlobal();
416 friend class VBoxCallback;
417};
418
419inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
420
421#endif // __VBoxGlobal_h__
422
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