VirtualBox

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

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

FE/Qt: Attempted to fix a bunch of bugs in VBoxGlobal::getOpenFileName().

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.1 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 QString languageID() const;
364 QString languageName() const;
365 QString languageCountry() const;
366 QString languageNameEnglish() const;
367 QString languageCountryEnglish() const;
368 QString languageTranslators() const;
369
370 void languageChange();
371
372 /** @internal made public for internal purposes */
373 void cleanup();
374
375 /* public static stuff */
376
377 static QIconSet iconSet (const char *aNormal,
378 const char *aDisabled = 0,
379 const char *aActive = 0);
380 static QIconSet iconSetEx (const char *aNormal, const char *aSmallNormal,
381 const char *aDisabled = 0, const char *aSmallDisabled = 0,
382 const char *aActive = 0, const char *aSmallActive = 0);
383
384 static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
385 bool aCanResize = true);
386
387 static void centerWidget (QWidget *aWidget, QWidget *aRelative,
388 bool aCanResize = true);
389
390 static QChar decimalSep();
391 static QString sizeRegexp();
392
393 static Q_UINT64 parseSize (const QString &);
394 static QString formatSize (Q_UINT64, int aMode = 0);
395
396 static QString highlight (const QString &aStr, bool aToolTip = false);
397
398 static QString getOpenFileName (const QString &, const QString &, QWidget*,
399 const char*, const QString &,
400 QString *defaultFilter = 0,
401 bool resolveSymLinks = true);
402
403signals:
404
405 /**
406 * Emitted at the beginning of the enumeration process started
407 * by #startEnumeratingMedia().
408 */
409 void mediaEnumStarted();
410
411 /**
412 * Emitted when a new media item from the list has updated
413 * its accessibility state.
414 */
415 void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
416
417 /**
418 * Emitted at the end of the enumeration process started
419 * by #startEnumeratingMedia(). The @a aList argument is passed for
420 * convenience, it is exactly the same as returned by #currentMediaList().
421 */
422 void mediaEnumFinished (const VBoxMediaList &aList);
423
424 /** Emitted when a new media is added using #addMedia(). */
425 void mediaAdded (const VBoxMedia &);
426
427 /** Emitted when the media is updated using #updateMedia(). */
428 void mediaUpdated (const VBoxMedia &);
429
430 /** Emitted when the media is removed using #removeMedia(). */
431 void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
432
433 /* signals emitted when the VirtualBox callback is called by the server
434 * (not that currently these signals are emitted only when the application
435 * is the in the VM selector mode) */
436
437 void machineStateChanged (const VBoxMachineStateChangeEvent &e);
438 void machineDataChanged (const VBoxMachineDataChangeEvent &e);
439 void machineRegistered (const VBoxMachineRegisteredEvent &e);
440 void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
441 void snapshotChanged (const VBoxSnapshotEvent &e);
442
443protected:
444
445 bool event (QEvent *e);
446
447private:
448
449 VBoxGlobal();
450 ~VBoxGlobal() {}
451
452 void init();
453
454 bool valid;
455
456 CVirtualBox vbox;
457
458 VMGlobalSettings gset;
459
460 VBoxSelectorWnd *selector_wnd;
461 VBoxConsoleWnd *console_wnd;
462
463 QUuid vmUuid;
464
465 QThread *media_enum_thread;
466 VBoxMediaList media_list;
467
468 VBoxDefs::RenderMode vm_render_mode;
469 const char * vm_render_mode_str;
470
471#ifdef VBOX_WITH_DEBUGGER_GUI
472 bool dbg_enabled;
473 bool dbg_visible_at_startup;
474#endif
475
476#if defined (Q_WS_WIN32)
477 DWORD dwHTMLHelpCookie;
478#endif
479
480 CVirtualBoxCallback callback;
481
482 typedef QValueVector <QString> QStringVector;
483
484 QString verString;
485
486 QValueVector <CGuestOSType> vm_os_types;
487 QDict <QPixmap> vm_os_type_icons;
488 QPtrVector <QColor> vm_state_color;
489
490 QIntDict <QPixmap> mStateIcons;
491 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
492
493 QStringVector machineStates;
494 QStringVector sessionStates;
495 QStringVector deviceTypes;
496 QStringVector diskControllerTypes;
497 QStringVector diskTypes;
498 QStringVector diskStorageTypes;
499 QStringVector vrdpAuthTypes;
500 QStringVector usbFilterActionTypes;
501 QStringVector diskControllerDevices;
502 QStringVector audioDriverTypes;
503 QStringVector networkAttachmentTypes;
504 QStringVector USBDeviceStates;
505
506 mutable bool detailReportTemplatesReady;
507
508 friend VBoxGlobal &vboxGlobal();
509 friend class VBoxCallback;
510};
511
512inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
513
514
515/**
516 * USB Popup Menu class.
517 * This class provides the list of USB devices attached to the host.
518 */
519class VBoxUSBMenu : public QPopupMenu
520{
521 Q_OBJECT
522
523public:
524
525 enum { USBDevicesMenuNoDevicesId = 1 };
526
527 VBoxUSBMenu (QWidget *);
528
529 const CUSBDevice& getUSB (int);
530
531 void setConsole (const CConsole &);
532
533private slots:
534
535 void processAboutToShow();
536
537 void processHighlighted (int);
538
539private:
540
541 QMap <int, CUSBDevice> mUSBDevicesMap;
542 CConsole mConsole;
543};
544
545
546/**
547 * Enable/Disable Menu class.
548 * This class provides enable/disable menu items.
549 */
550class VBoxSwitchMenu : public QPopupMenu
551{
552 Q_OBJECT
553
554public:
555
556 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
557
558 void setToolTip (const QString &);
559
560private slots:
561
562 void processAboutToShow();
563
564 void processActivated (int);
565
566private:
567
568 QAction *mAction;
569 QString mTip;
570 bool mInverted;
571};
572
573#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