VirtualBox

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

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

FE/Qt: Don't pollute public namespace with one-time private methods.

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