VirtualBox

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

Last change on this file since 2387 was 2357, checked in by vboxsync, 18 years ago

1764: Better default size in "Create VDI" wizard when called from "Create VM" wizard.

These changes related both to NewVM and NewHD wizards.

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