VirtualBox

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

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

FE/Qt: Naming/placing corrections.

  • 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 index) const;
178 int vmGuestOSTypeIndex (const CGuestOSType &type) const;
179 QPixmap vmGuestOSTypeIcon (const QString &type) const;
180
181 QPixmap toIcon (CEnums::MachineState s) const
182 {
183 QPixmap *pm = mStateIcons [s];
184 AssertMsg (pm, ("Icon for VM state %d must be defined", s));
185 return pm ? *pm : QPixmap();
186 }
187
188 const QColor &toColor (CEnums::MachineState s) const
189 {
190 static const QColor none;
191 AssertMsg (vm_state_color [s], ("No color for %d", s));
192 return vm_state_color [s] ? *vm_state_color [s] : none;
193 }
194
195 QString toString (CEnums::MachineState s) const
196 {
197 AssertMsg (!machineStates [s].isNull(), ("No text for %d", s));
198 return machineStates [s];
199 }
200
201 QString toString (CEnums::SessionState s) const
202 {
203 AssertMsg (!sessionStates [s].isNull(), ("No text for %d", s));
204 return sessionStates [s];
205 }
206
207 QString toString (CEnums::DiskControllerType t) const
208 {
209 AssertMsg (!diskControllerTypes [t].isNull(), ("No text for %d", t));
210 return diskControllerTypes [t];
211 }
212
213 QString toString (CEnums::HardDiskType t) const
214 {
215 AssertMsg (!diskTypes [t].isNull(), ("No text for %d", t));
216 return diskTypes [t];
217 }
218
219 QString toString (CEnums::HardDiskStorageType t) const
220 {
221 AssertMsg (!diskStorageTypes [t].isNull(), ("No text for %d", t));
222 return diskStorageTypes [t];
223 }
224
225 QString toString (CEnums::VRDPAuthType t) const
226 {
227 AssertMsg (!vrdpAuthTypes [t].isNull(), ("No text for %d", t));
228 return vrdpAuthTypes [t];
229 }
230
231 QString toString (CEnums::USBDeviceFilterAction t) const
232 {
233 AssertMsg (!usbFilterActionTypes [t].isNull(), ("No text for %d", t));
234 return usbFilterActionTypes [t];
235 }
236
237 QString toString (CEnums::ClipboardMode t) const
238 {
239 AssertMsg (!clipboardTypes [t].isNull(), ("No text for %d", t));
240 return clipboardTypes [t];
241 }
242
243 CEnums::ClipboardMode toClipboardModeType (const QString &s) const
244 {
245 QStringVector::const_iterator it =
246 qFind (clipboardTypes.begin(), clipboardTypes.end(), s);
247 AssertMsg (it != clipboardTypes.end(), ("No value for {%s}", s.latin1()));
248 return CEnums::ClipboardMode (it - clipboardTypes.begin());
249 }
250
251 CEnums::VRDPAuthType toVRDPAuthType (const QString &s) const
252 {
253 QStringVector::const_iterator it =
254 qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
255 AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.latin1()));
256 return CEnums::VRDPAuthType (it - vrdpAuthTypes.begin());
257 }
258
259 CEnums::USBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
260 {
261 QStringVector::const_iterator it =
262 qFind (usbFilterActionTypes.begin(), usbFilterActionTypes.end(), s);
263 AssertMsg (it != usbFilterActionTypes.end(), ("No value for {%s}", s.latin1()));
264 return CEnums::USBDeviceFilterAction (it - usbFilterActionTypes.begin());
265 }
266
267 /**
268 * Similar to toString (CEnums::HardDiskType), but returns 'Differencing'
269 * for normal hard disks that have a parent hard disk.
270 */
271 QString hardDiskTypeString (const CHardDisk &aHD) const
272 {
273 if (!aHD.GetParent().isNull())
274 {
275 Assert (aHD.GetType() == CEnums::NormalHardDisk);
276 return tr ("Differencing", "hard disk");
277 }
278 return toString (aHD.GetType());
279 }
280
281 QString toString (CEnums::DiskControllerType t, LONG d) const;
282
283 QString toString (CEnums::DeviceType t) const
284 {
285 AssertMsg (!deviceTypes [t].isNull(), ("No text for %d", t));
286 return deviceTypes [t];
287 }
288
289 CEnums::DeviceType toDeviceType (const QString &s) const
290 {
291 QStringVector::const_iterator it =
292 qFind (deviceTypes.begin(), deviceTypes.end(), s);
293 AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.latin1()));
294 return CEnums::DeviceType (it - deviceTypes.begin());
295 }
296
297 QStringList deviceTypeStrings() const;
298
299 QString toString (CEnums::AudioDriverType t) const
300 {
301 AssertMsg (!audioDriverTypes [t].isNull(), ("No text for %d", t));
302 return audioDriverTypes [t];
303 }
304
305 CEnums::AudioDriverType toAudioDriverType (const QString &s) const
306 {
307 QStringVector::const_iterator it =
308 qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
309 AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.latin1()));
310 return CEnums::AudioDriverType (it - audioDriverTypes.begin());
311 }
312
313 QString toString (CEnums::NetworkAttachmentType t) const
314 {
315 AssertMsg (!networkAttachmentTypes [t].isNull(), ("No text for %d", t));
316 return networkAttachmentTypes [t];
317 }
318
319 CEnums::NetworkAttachmentType toNetworkAttachmentType (const QString &s) const
320 {
321 QStringVector::const_iterator it =
322 qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
323 AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.latin1()));
324 return CEnums::NetworkAttachmentType (it - networkAttachmentTypes.begin());
325 }
326
327 QString toString (CEnums::USBDeviceState aState) const
328 {
329 AssertMsg (!USBDeviceStates [aState].isNull(), ("No text for %d", aState));
330 return USBDeviceStates [aState];
331 }
332
333 QPixmap snapshotIcon (bool online) const
334 {
335 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
336 }
337
338 /* details generators */
339
340 QString details (const CHardDisk &aHD, bool aPredict = false);
341
342 QString details (const CUSBDevice &aDevice) const;
343 QString toolTip (const CUSBDevice &aDevice) const;
344
345 QString prepareFileNameForHTML (const QString &fn) const;
346
347 QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks);
348
349 /* VirtualBox helpers */
350
351 CSession openSession (const QUuid &id);
352
353 bool startMachine (const QUuid &id);
354
355 void startEnumeratingMedia();
356
357 /**
358 * Returns a list of all currently registered media. This list is used
359 * to globally track the accessiblity state of all media on a dedicated
360 * thread. This the list is initially empty (before the first enumeration
361 * process is started using #startEnumeratingMedia()).
362 */
363 const VBoxMediaList &currentMediaList() const { return media_list; }
364
365 /** Returns true if the media enumeration is in progress. */
366 bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
367
368 void addMedia (const VBoxMedia &);
369 void updateMedia (const VBoxMedia &);
370 void removeMedia (VBoxDefs::DiskType, const QUuid &);
371
372 bool findMedia (const CUnknown &, VBoxMedia &) const;
373
374 /* various helpers */
375
376 bool openURL (const QString &aURL);
377
378 QString languageName() const;
379 QString languageCountry() const;
380 QString languageNameEnglish() const;
381 QString languageCountryEnglish() const;
382 QString languageTranslators() const;
383
384 void languageChange();
385
386 /** @internal made public for internal purposes */
387 void cleanup();
388
389 /* public static stuff */
390
391 static void adoptLabelPixmap (QLabel *);
392
393 static QString languageId();
394 static void loadLanguage (const QString &aLangId = QString::null);
395
396 static QIconSet iconSet (const char *aNormal,
397 const char *aDisabled = 0,
398 const char *aActive = 0);
399 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
400 const char *aDisabled = 0, const char *aSmallDisabled = 0,
401 const char *aActive = 0, const char *aSmallActive = 0);
402
403 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
404 bool aCanResize = true);
405
406 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
407 bool aCanResize = true);
408
409 static QChar decimalSep();
410 static QString sizeRegexp();
411
412 static Q_UINT64 parseSize (const QString &);
413 static QString formatSize (Q_UINT64, int aMode = 0);
414
415 static QString highlight (const QString &aStr, bool aToolTip = false);
416
417 static QString systemLanguageId();
418
419 static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
420 const char *aName = 0,
421 const QString &aCaption = QString::null,
422 bool aDirOnly = TRUE,
423 bool resolveSymlinks = TRUE);
424
425 static QString getOpenFileName (const QString &, const QString &, QWidget*,
426 const char*, const QString &,
427 QString *defaultFilter = 0,
428 bool resolveSymLinks = true);
429
430 static QString getFirstExistingDir (const QString &);
431
432signals:
433
434 /**
435 * Emitted at the beginning of the enumeration process started
436 * by #startEnumeratingMedia().
437 */
438 void mediaEnumStarted();
439
440 /**
441 * Emitted when a new media item from the list has updated
442 * its accessibility state.
443 */
444 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
445
446 /**
447 * Emitted at the end of the enumeration process started
448 * by #startEnumeratingMedia(). The @a aList argument is passed for
449 * convenience, it is exactly the same as returned by #currentMediaList().
450 */
451 void mediaEnumFinished (const VBoxMediaList &aList);
452
453 /** Emitted when a new media is added using #addMedia(). */
454 void mediaAdded (const VBoxMedia &);
455
456 /** Emitted when the media is updated using #updateMedia(). */
457 void mediaUpdated (const VBoxMedia &);
458
459 /** Emitted when the media is removed using #removeMedia(). */
460 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
461
462 /* signals emitted when the VirtualBox callback is called by the server
463 * (not that currently these signals are emitted only when the application
464 * is the in the VM selector mode) */
465
466 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
467 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
468 void machineRegistered (const VBoxMachineRegisteredEvent &e);
469 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
470 void snapshotChanged (const VBoxSnapshotEvent &e);
471
472protected:
473
474 bool event (QEvent *e);
475 bool eventFilter (QObject *, QEvent *);
476
477private:
478
479 VBoxGlobal();
480 ~VBoxGlobal() {}
481
482 void init();
483
484 bool valid;
485
486 CVirtualBox vbox;
487
488 VBoxGlobalSettings gset;
489
490 VBoxSelectorWnd *selector_wnd;
491 VBoxConsoleWnd *console_wnd;
492
493 QUuid vmUuid;
494
495 QThread *media_enum_thread;
496 VBoxMediaList media_list;
497
498 VBoxDefs::RenderMode vm_render_mode;
499 const char * vm_render_mode_str;
500
501#ifdef VBOX_WITH_DEBUGGER_GUI
502 bool dbg_enabled;
503 bool dbg_visible_at_startup;
504#endif
505
506#if defined (Q_WS_WIN32)
507 DWORD dwHTMLHelpCookie;
508#endif
509
510 CVirtualBoxCallback callback;
511
512 typedef QValueVector <QString> QStringVector;
513
514 QString verString;
515
516 QValueVector <CGuestOSType> vm_os_types;
517 QDict <QPixmap> vm_os_type_icons;
518 QPtrVector <QColor> vm_state_color;
519
520 QIntDict <QPixmap> mStateIcons;
521 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
522
523 QStringVector machineStates;
524 QStringVector sessionStates;
525 QStringVector deviceTypes;
526 QStringVector diskControllerTypes;
527 QStringVector diskTypes;
528 QStringVector diskStorageTypes;
529 QStringVector vrdpAuthTypes;
530 QStringVector usbFilterActionTypes;
531 QStringVector diskControllerDevices;
532 QStringVector audioDriverTypes;
533 QStringVector networkAttachmentTypes;
534 QStringVector clipboardTypes;
535 QStringVector USBDeviceStates;
536
537 mutable bool detailReportTemplatesReady;
538
539 friend VBoxGlobal &vboxGlobal();
540 friend class VBoxCallback;
541};
542
543inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
544
545
546/**
547 * USB Popup Menu class.
548 * This class provides the list of USB devices attached to the host.
549 */
550class VBoxUSBMenu : public QPopupMenu
551{
552 Q_OBJECT
553
554public:
555
556 enum { USBDevicesMenuNoDevicesId = 1 };
557
558 VBoxUSBMenu (QWidget *);
559
560 const CUSBDevice& getUSB (int);
561
562 void setConsole (const CConsole &);
563
564private slots:
565
566 void processAboutToShow();
567
568 void processHighlighted (int);
569
570private:
571
572 QMap <int, CUSBDevice> mUSBDevicesMap;
573 CConsole mConsole;
574};
575
576
577/**
578 * Enable/Disable Menu class.
579 * This class provides enable/disable menu items.
580 */
581class VBoxSwitchMenu : public QPopupMenu
582{
583 Q_OBJECT
584
585public:
586
587 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
588
589 void setToolTip (const QString &);
590
591private slots:
592
593 void processAboutToShow();
594
595 void processActivated (int);
596
597private:
598
599 QAction *mAction;
600 QString mTip;
601 bool mInverted;
602};
603
604#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