VirtualBox

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

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

Main & All Frontends: replaced the IGuestOSType IMachine::OSType property with the wstring IMachine::OSTypeId property (+ converted IGuest and IGuestOSType to VirtualBoxBaseNEXT semantics).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.3 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
433signals:
434
435 /**
436 * Emitted at the beginning of the enumeration process started
437 * by #startEnumeratingMedia().
438 */
439 void mediaEnumStarted();
440
441 /**
442 * Emitted when a new media item from the list has updated
443 * its accessibility state.
444 */
445 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
446
447 /**
448 * Emitted at the end of the enumeration process started
449 * by #startEnumeratingMedia(). The @a aList argument is passed for
450 * convenience, it is exactly the same as returned by #currentMediaList().
451 */
452 void mediaEnumFinished (const VBoxMediaList &aList);
453
454 /** Emitted when a new media is added using #addMedia(). */
455 void mediaAdded (const VBoxMedia &);
456
457 /** Emitted when the media is updated using #updateMedia(). */
458 void mediaUpdated (const VBoxMedia &);
459
460 /** Emitted when the media is removed using #removeMedia(). */
461 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
462
463 /* signals emitted when the VirtualBox callback is called by the server
464 * (not that currently these signals are emitted only when the application
465 * is the in the VM selector mode) */
466
467 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
468 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
469 void machineRegistered (const VBoxMachineRegisteredEvent &e);
470 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
471 void snapshotChanged (const VBoxSnapshotEvent &e);
472
473protected:
474
475 bool event (QEvent *e);
476 bool eventFilter (QObject *, QEvent *);
477
478private:
479
480 VBoxGlobal();
481 ~VBoxGlobal() {}
482
483 void init();
484
485 bool valid;
486
487 CVirtualBox vbox;
488
489 VBoxGlobalSettings gset;
490
491 VBoxSelectorWnd *selector_wnd;
492 VBoxConsoleWnd *console_wnd;
493
494 QUuid vmUuid;
495
496 QThread *media_enum_thread;
497 VBoxMediaList media_list;
498
499 VBoxDefs::RenderMode vm_render_mode;
500 const char * vm_render_mode_str;
501
502#ifdef VBOX_WITH_DEBUGGER_GUI
503 bool dbg_enabled;
504 bool dbg_visible_at_startup;
505#endif
506
507#if defined (Q_WS_WIN32)
508 DWORD dwHTMLHelpCookie;
509#endif
510
511 CVirtualBoxCallback callback;
512
513 typedef QValueVector <QString> QStringVector;
514
515 QString verString;
516
517 QValueVector <CGuestOSType> vm_os_types;
518 QDict <QPixmap> vm_os_type_icons;
519 QPtrVector <QColor> vm_state_color;
520
521 QIntDict <QPixmap> mStateIcons;
522 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
523
524 QStringVector machineStates;
525 QStringVector sessionStates;
526 QStringVector deviceTypes;
527 QStringVector diskControllerTypes;
528 QStringVector diskTypes;
529 QStringVector diskStorageTypes;
530 QStringVector vrdpAuthTypes;
531 QStringVector usbFilterActionTypes;
532 QStringVector diskControllerDevices;
533 QStringVector audioDriverTypes;
534 QStringVector networkAttachmentTypes;
535 QStringVector clipboardTypes;
536 QStringVector USBDeviceStates;
537
538 mutable bool detailReportTemplatesReady;
539
540 friend VBoxGlobal &vboxGlobal();
541 friend class VBoxCallback;
542};
543
544inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
545
546
547/**
548 * USB Popup Menu class.
549 * This class provides the list of USB devices attached to the host.
550 */
551class VBoxUSBMenu : public QPopupMenu
552{
553 Q_OBJECT
554
555public:
556
557 enum { USBDevicesMenuNoDevicesId = 1 };
558
559 VBoxUSBMenu (QWidget *);
560
561 const CUSBDevice& getUSB (int);
562
563 void setConsole (const CConsole &);
564
565private slots:
566
567 void processAboutToShow();
568
569 void processHighlighted (int);
570
571private:
572
573 QMap <int, CUSBDevice> mUSBDevicesMap;
574 CConsole mConsole;
575};
576
577
578/**
579 * Enable/Disable Menu class.
580 * This class provides enable/disable menu items.
581 */
582class VBoxSwitchMenu : public QPopupMenu
583{
584 Q_OBJECT
585
586public:
587
588 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
589
590 void setToolTip (const QString &);
591
592private slots:
593
594 void processAboutToShow();
595
596 void processActivated (int);
597
598private:
599
600 QAction *mAction;
601 QString mTip;
602 bool mInverted;
603};
604
605#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