1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxGlobal class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef __VBoxGlobal_h__
|
---|
24 | #define __VBoxGlobal_h__
|
---|
25 |
|
---|
26 | #include "COMDefs.h"
|
---|
27 |
|
---|
28 | #include "VBoxGlobalSettings.h"
|
---|
29 |
|
---|
30 | /* Qt includes */
|
---|
31 | #include <QApplication>
|
---|
32 | #include <QLayout>
|
---|
33 | #include <QHash>
|
---|
34 | #include <QPixmap>
|
---|
35 | #include <QMenu>
|
---|
36 | #include <QStyle>
|
---|
37 | #include <QProcess>
|
---|
38 |
|
---|
39 | class QAction;
|
---|
40 | class QLabel;
|
---|
41 | class QToolButton;
|
---|
42 |
|
---|
43 | // Auxiliary types
|
---|
44 | ////////////////////////////////////////////////////////////////////////////////
|
---|
45 |
|
---|
46 | /** Simple media descriptor type. */
|
---|
47 | struct VBoxMedia
|
---|
48 | {
|
---|
49 | enum Status { Unknown, Ok, Error, Inaccessible };
|
---|
50 |
|
---|
51 | VBoxMedia() : type (VBoxDefs::InvalidType), status (Ok) {}
|
---|
52 |
|
---|
53 | VBoxMedia (const CUnknown &d, VBoxDefs::DiskType t, Status s)
|
---|
54 | : disk (d), type (t), status (s) {}
|
---|
55 |
|
---|
56 | CUnknown disk;
|
---|
57 | VBoxDefs::DiskType type;
|
---|
58 | Status status;
|
---|
59 | };
|
---|
60 |
|
---|
61 | typedef QList <VBoxMedia> VBoxMediaList;
|
---|
62 |
|
---|
63 | // VirtualBox callback events
|
---|
64 | ////////////////////////////////////////////////////////////////////////////////
|
---|
65 |
|
---|
66 | class VBoxMachineStateChangeEvent : public QEvent
|
---|
67 | {
|
---|
68 | public:
|
---|
69 | VBoxMachineStateChangeEvent (const QUuid &aId, KMachineState aState)
|
---|
70 | : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType)
|
---|
71 | , id (aId), state (aState)
|
---|
72 | {}
|
---|
73 |
|
---|
74 | const QUuid id;
|
---|
75 | const KMachineState state;
|
---|
76 | };
|
---|
77 |
|
---|
78 | class VBoxMachineDataChangeEvent : public QEvent
|
---|
79 | {
|
---|
80 | public:
|
---|
81 | VBoxMachineDataChangeEvent (const QUuid &aId)
|
---|
82 | : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType)
|
---|
83 | , id (aId)
|
---|
84 | {}
|
---|
85 |
|
---|
86 | const QUuid id;
|
---|
87 | };
|
---|
88 |
|
---|
89 | class VBoxMachineRegisteredEvent : public QEvent
|
---|
90 | {
|
---|
91 | public:
|
---|
92 | VBoxMachineRegisteredEvent (const QUuid &aId, bool aRegistered)
|
---|
93 | : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType)
|
---|
94 | , id (aId), registered (aRegistered)
|
---|
95 | {}
|
---|
96 |
|
---|
97 | const QUuid id;
|
---|
98 | const bool registered;
|
---|
99 | };
|
---|
100 |
|
---|
101 | class VBoxSessionStateChangeEvent : public QEvent
|
---|
102 | {
|
---|
103 | public:
|
---|
104 | VBoxSessionStateChangeEvent (const QUuid &aId, KSessionState aState)
|
---|
105 | : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType)
|
---|
106 | , id (aId), state (aState)
|
---|
107 | {}
|
---|
108 |
|
---|
109 | const QUuid id;
|
---|
110 | const KSessionState state;
|
---|
111 | };
|
---|
112 |
|
---|
113 | class VBoxSnapshotEvent : public QEvent
|
---|
114 | {
|
---|
115 | public:
|
---|
116 |
|
---|
117 | enum What { Taken, Discarded, Changed };
|
---|
118 |
|
---|
119 | VBoxSnapshotEvent (const QUuid &aMachineId, const QUuid &aSnapshotId,
|
---|
120 | What aWhat)
|
---|
121 | : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType)
|
---|
122 | , what (aWhat)
|
---|
123 | , machineId (aMachineId), snapshotId (aSnapshotId)
|
---|
124 | {}
|
---|
125 |
|
---|
126 | const What what;
|
---|
127 |
|
---|
128 | const QUuid machineId;
|
---|
129 | const QUuid snapshotId;
|
---|
130 | };
|
---|
131 |
|
---|
132 | class VBoxCanShowRegDlgEvent : public QEvent
|
---|
133 | {
|
---|
134 | public:
|
---|
135 | VBoxCanShowRegDlgEvent (bool aCanShow)
|
---|
136 | : QEvent ((QEvent::Type) VBoxDefs::CanShowRegDlgEventType)
|
---|
137 | , mCanShow (aCanShow)
|
---|
138 | {}
|
---|
139 |
|
---|
140 | const bool mCanShow;
|
---|
141 | };
|
---|
142 |
|
---|
143 | class VBoxCanShowUpdDlgEvent : public QEvent
|
---|
144 | {
|
---|
145 | public:
|
---|
146 | VBoxCanShowUpdDlgEvent (bool aCanShow)
|
---|
147 | : QEvent ((QEvent::Type) VBoxDefs::CanShowUpdDlgEventType)
|
---|
148 | , mCanShow (aCanShow)
|
---|
149 | {}
|
---|
150 |
|
---|
151 | const bool mCanShow;
|
---|
152 | };
|
---|
153 |
|
---|
154 | class VBoxChangeGUILanguageEvent : public QEvent
|
---|
155 | {
|
---|
156 | public:
|
---|
157 | VBoxChangeGUILanguageEvent (QString aLangId)
|
---|
158 | : QEvent ((QEvent::Type) VBoxDefs::ChangeGUILanguageEventType)
|
---|
159 | , mLangId (aLangId)
|
---|
160 | {}
|
---|
161 |
|
---|
162 | const QString mLangId;
|
---|
163 | };
|
---|
164 |
|
---|
165 | class Process : public QProcess
|
---|
166 | {
|
---|
167 | Q_OBJECT;
|
---|
168 |
|
---|
169 | public:
|
---|
170 |
|
---|
171 | static QByteArray singleShot (const QString &aProcessName,
|
---|
172 | int aTimeout = 5000
|
---|
173 | /* wait for data maximum 5 seconds */)
|
---|
174 | {
|
---|
175 | /* Why is it really needed is because of Qt4.3 bug with QProcess.
|
---|
176 | * This bug is about QProcess sometimes (~70%) do not receive
|
---|
177 | * notification about process was finished, so this makes
|
---|
178 | * 'bool QProcess::waitForFinished (int)' block the GUI thread and
|
---|
179 | * never dismissed with 'true' result even if process was really
|
---|
180 | * started&finished. So we just waiting for some information
|
---|
181 | * on process output and destroy the process with force. Due to
|
---|
182 | * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
|
---|
183 | * we have to change process state to QProcess::NotRunning. */
|
---|
184 |
|
---|
185 | QByteArray result;
|
---|
186 | Process process;
|
---|
187 | process.start (aProcessName);
|
---|
188 | bool firstShotReady = process.waitForReadyRead (aTimeout);
|
---|
189 | if (firstShotReady)
|
---|
190 | result = process.readAllStandardOutput();
|
---|
191 | process.setProcessState (QProcess::NotRunning);
|
---|
192 | return result;
|
---|
193 | }
|
---|
194 |
|
---|
195 | protected:
|
---|
196 |
|
---|
197 | Process (QWidget *aParent = 0) : QProcess (aParent) {}
|
---|
198 | };
|
---|
199 |
|
---|
200 | // VBoxGlobal class
|
---|
201 | ////////////////////////////////////////////////////////////////////////////////
|
---|
202 |
|
---|
203 | class VBoxSelectorWnd;
|
---|
204 | class VBoxConsoleWnd;
|
---|
205 | class VBoxRegistrationDlg;
|
---|
206 | class VBoxUpdateDlg;
|
---|
207 |
|
---|
208 | class VBoxGlobal : public QObject
|
---|
209 | {
|
---|
210 | Q_OBJECT
|
---|
211 |
|
---|
212 | public:
|
---|
213 |
|
---|
214 | static VBoxGlobal &instance();
|
---|
215 |
|
---|
216 | bool isValid() { return mValid; }
|
---|
217 |
|
---|
218 | QString versionString() { return verString; }
|
---|
219 |
|
---|
220 | CVirtualBox virtualBox() const { return mVBox; }
|
---|
221 |
|
---|
222 | const VBoxGlobalSettings &settings() const { return gset; }
|
---|
223 | bool setSettings (const VBoxGlobalSettings &gs);
|
---|
224 |
|
---|
225 | VBoxSelectorWnd &selectorWnd();
|
---|
226 | VBoxConsoleWnd &consoleWnd();
|
---|
227 |
|
---|
228 | /* main window handle storage */
|
---|
229 | void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; }
|
---|
230 | QWidget *mainWindow() const { return mMainWindow; }
|
---|
231 |
|
---|
232 |
|
---|
233 | bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
|
---|
234 | QUuid managedVMUuid() const { return vmUuid; }
|
---|
235 |
|
---|
236 | VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
|
---|
237 | const char *vmRenderModeStr() const { return vm_render_mode_str; }
|
---|
238 |
|
---|
239 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
240 | bool isDebuggerEnabled() const { return mDbgEnabled; }
|
---|
241 | bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
|
---|
242 | RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
|
---|
243 | #else
|
---|
244 | bool isDebuggerAutoShowEnabled() const { return false; }
|
---|
245 | #endif
|
---|
246 |
|
---|
247 | /* VBox enum to/from string/icon/color convertors */
|
---|
248 |
|
---|
249 | QStringList vmGuestOSTypeDescriptions() const;
|
---|
250 | QList<QPixmap> vmGuestOSTypeIcons (int aHorizonalMargin, int aVerticalMargin) const;
|
---|
251 | CGuestOSType vmGuestOSType (int aIndex) const;
|
---|
252 | int vmGuestOSTypeIndex (const QString &aId) const;
|
---|
253 | QPixmap vmGuestOSTypeIcon (const QString &aId) const;
|
---|
254 | QString vmGuestOSTypeDescription (const QString &aId) const;
|
---|
255 |
|
---|
256 | QPixmap toIcon (KMachineState s) const
|
---|
257 | {
|
---|
258 | QPixmap *pm = mStateIcons.value (s);
|
---|
259 | AssertMsg (pm, ("Icon for VM state %d must be defined", s));
|
---|
260 | return pm ? *pm : QPixmap();
|
---|
261 | }
|
---|
262 |
|
---|
263 | const QColor &toColor (KMachineState s) const
|
---|
264 | {
|
---|
265 | static const QColor none;
|
---|
266 | AssertMsg (vm_state_color.value (s), ("No color for %d", s));
|
---|
267 | return vm_state_color.value (s) ? *vm_state_color.value(s) : none;
|
---|
268 | }
|
---|
269 |
|
---|
270 | QString toString (KMachineState s) const
|
---|
271 | {
|
---|
272 | AssertMsg (!machineStates.value (s).isNull(), ("No text for %d", s));
|
---|
273 | return machineStates.value (s);
|
---|
274 | }
|
---|
275 |
|
---|
276 | QString toString (KSessionState s) const
|
---|
277 | {
|
---|
278 | AssertMsg (!sessionStates.value (s).isNull(), ("No text for %d", s));
|
---|
279 | return sessionStates.value (s);
|
---|
280 | }
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Returns a string representation of the given KStorageBus enum value.
|
---|
284 | * Complementary to #toStorageBusType (const QString &) const.
|
---|
285 | */
|
---|
286 | QString toString (KStorageBus aBus) const
|
---|
287 | {
|
---|
288 | AssertMsg (!storageBuses.value (aBus).isNull(), ("No text for %d", aBus));
|
---|
289 | return storageBuses [aBus];
|
---|
290 | }
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Returns a KStorageBus enum value corresponding to the given string
|
---|
294 | * representation. Complementary to #toString (KStorageBus) const.
|
---|
295 | */
|
---|
296 | KStorageBus toStorageBusType (const QString &aBus) const
|
---|
297 | {
|
---|
298 | QStringVector::const_iterator it =
|
---|
299 | qFind (storageBuses.begin(), storageBuses.end(), aBus);
|
---|
300 | AssertMsg (it != storageBuses.end(), ("No value for {%s}", aBus.toLatin1().constData()));
|
---|
301 | return KStorageBus (it - storageBuses.begin());
|
---|
302 | }
|
---|
303 |
|
---|
304 | QString toString (KStorageBus aBus, LONG aChannel) const;
|
---|
305 | LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
|
---|
306 |
|
---|
307 | QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
|
---|
308 | LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
|
---|
309 |
|
---|
310 | QString toFullString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
|
---|
311 |
|
---|
312 | QString toString (KHardDiskType t) const
|
---|
313 | {
|
---|
314 | AssertMsg (!diskTypes.value (t).isNull(), ("No text for %d", t));
|
---|
315 | return diskTypes.value (t);
|
---|
316 | }
|
---|
317 |
|
---|
318 | QString toString (KHardDiskStorageType t) const
|
---|
319 | {
|
---|
320 | AssertMsg (!diskStorageTypes.value (t).isNull(), ("No text for %d", t));
|
---|
321 | return diskStorageTypes.value (t);
|
---|
322 | }
|
---|
323 |
|
---|
324 | QString toString (KVRDPAuthType t) const
|
---|
325 | {
|
---|
326 | AssertMsg (!vrdpAuthTypes.value (t).isNull(), ("No text for %d", t));
|
---|
327 | return vrdpAuthTypes.value (t);
|
---|
328 | }
|
---|
329 |
|
---|
330 | QString toString (KPortMode t) const
|
---|
331 | {
|
---|
332 | AssertMsg (!portModeTypes.value (t).isNull(), ("No text for %d", t));
|
---|
333 | return portModeTypes.value (t);
|
---|
334 | }
|
---|
335 |
|
---|
336 | QString toString (KUSBDeviceFilterAction t) const
|
---|
337 | {
|
---|
338 | AssertMsg (!usbFilterActionTypes.value (t).isNull(), ("No text for %d", t));
|
---|
339 | return usbFilterActionTypes.value (t);
|
---|
340 | }
|
---|
341 |
|
---|
342 | QString toString (KClipboardMode t) const
|
---|
343 | {
|
---|
344 | AssertMsg (!clipboardTypes.value (t).isNull(), ("No text for %d", t));
|
---|
345 | return clipboardTypes.value (t);
|
---|
346 | }
|
---|
347 |
|
---|
348 | KClipboardMode toClipboardModeType (const QString &s) const
|
---|
349 | {
|
---|
350 | QStringVector::const_iterator it =
|
---|
351 | qFind (clipboardTypes.begin(), clipboardTypes.end(), s);
|
---|
352 | AssertMsg (it != clipboardTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
353 | return KClipboardMode (it - clipboardTypes.begin());
|
---|
354 | }
|
---|
355 |
|
---|
356 | QString toString (KIDEControllerType t) const
|
---|
357 | {
|
---|
358 | AssertMsg (!ideControllerTypes.value (t).isNull(), ("No text for %d", t));
|
---|
359 | return ideControllerTypes.value (t);
|
---|
360 | }
|
---|
361 |
|
---|
362 | KIDEControllerType toIDEControllerType (const QString &s) const
|
---|
363 | {
|
---|
364 | QStringVector::const_iterator it =
|
---|
365 | qFind (ideControllerTypes.begin(), ideControllerTypes.end(), s);
|
---|
366 | AssertMsg (it != ideControllerTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
367 | return KIDEControllerType (it - ideControllerTypes.begin());
|
---|
368 | }
|
---|
369 |
|
---|
370 | KVRDPAuthType toVRDPAuthType (const QString &s) const
|
---|
371 | {
|
---|
372 | QStringVector::const_iterator it =
|
---|
373 | qFind (vrdpAuthTypes.begin(), vrdpAuthTypes.end(), s);
|
---|
374 | AssertMsg (it != vrdpAuthTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
375 | return KVRDPAuthType (it - vrdpAuthTypes.begin());
|
---|
376 | }
|
---|
377 |
|
---|
378 | KPortMode toPortMode (const QString &s) const
|
---|
379 | {
|
---|
380 | QStringVector::const_iterator it =
|
---|
381 | qFind (portModeTypes.begin(), portModeTypes.end(), s);
|
---|
382 | AssertMsg (it != portModeTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
383 | return KPortMode (it - portModeTypes.begin());
|
---|
384 | }
|
---|
385 |
|
---|
386 | KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
|
---|
387 | {
|
---|
388 | QStringVector::const_iterator it =
|
---|
389 | qFind (usbFilterActionTypes.begin(), usbFilterActionTypes.end(), s);
|
---|
390 | AssertMsg (it != usbFilterActionTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
391 | return KUSBDeviceFilterAction (it - usbFilterActionTypes.begin());
|
---|
392 | }
|
---|
393 |
|
---|
394 | /**
|
---|
395 | * Similar to toString (KHardDiskType), but returns 'Differencing'
|
---|
396 | * for normal hard disks that have a parent hard disk.
|
---|
397 | */
|
---|
398 | QString hardDiskTypeString (const CHardDisk &aHD) const
|
---|
399 | {
|
---|
400 | if (!aHD.GetParent().isNull())
|
---|
401 | {
|
---|
402 | Assert (aHD.GetType() == KHardDiskType_Normal);
|
---|
403 | return tr ("Differencing", "hard disk");
|
---|
404 | }
|
---|
405 | return toString (aHD.GetType());
|
---|
406 | }
|
---|
407 |
|
---|
408 | QString toString (KDeviceType t) const
|
---|
409 | {
|
---|
410 | AssertMsg (!deviceTypes.value (t).isNull(), ("No text for %d", t));
|
---|
411 | return deviceTypes.value (t);
|
---|
412 | }
|
---|
413 |
|
---|
414 | KDeviceType toDeviceType (const QString &s) const
|
---|
415 | {
|
---|
416 | QStringVector::const_iterator it =
|
---|
417 | qFind (deviceTypes.begin(), deviceTypes.end(), s);
|
---|
418 | AssertMsg (it != deviceTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
419 | return KDeviceType (it - deviceTypes.begin());
|
---|
420 | }
|
---|
421 |
|
---|
422 | QStringList deviceTypeStrings() const;
|
---|
423 |
|
---|
424 | QString toString (KAudioDriverType t) const
|
---|
425 | {
|
---|
426 | AssertMsg (!audioDriverTypes.value (t).isNull(), ("No text for %d", t));
|
---|
427 | return audioDriverTypes.value (t);
|
---|
428 | }
|
---|
429 |
|
---|
430 | KAudioDriverType toAudioDriverType (const QString &s) const
|
---|
431 | {
|
---|
432 | QStringVector::const_iterator it =
|
---|
433 | qFind (audioDriverTypes.begin(), audioDriverTypes.end(), s);
|
---|
434 | AssertMsg (it != audioDriverTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
435 | return KAudioDriverType (it - audioDriverTypes.begin());
|
---|
436 | }
|
---|
437 |
|
---|
438 | QString toString (KAudioControllerType t) const
|
---|
439 | {
|
---|
440 | AssertMsg (!audioControllerTypes.value (t).isNull(), ("No text for %d", t));
|
---|
441 | return audioControllerTypes.value (t);
|
---|
442 | }
|
---|
443 |
|
---|
444 | KAudioControllerType toAudioControllerType (const QString &s) const
|
---|
445 | {
|
---|
446 | QStringVector::const_iterator it =
|
---|
447 | qFind (audioControllerTypes.begin(), audioControllerTypes.end(), s);
|
---|
448 | AssertMsg (it != audioControllerTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
449 | return KAudioControllerType (it - audioControllerTypes.begin());
|
---|
450 | }
|
---|
451 |
|
---|
452 | QString toString (KNetworkAdapterType t) const
|
---|
453 | {
|
---|
454 | AssertMsg (!networkAdapterTypes.value (t).isNull(), ("No text for %d", t));
|
---|
455 | return networkAdapterTypes.value (t);
|
---|
456 | }
|
---|
457 |
|
---|
458 | KNetworkAdapterType toNetworkAdapterType (const QString &s) const
|
---|
459 | {
|
---|
460 | QStringVector::const_iterator it =
|
---|
461 | qFind (networkAdapterTypes.begin(), networkAdapterTypes.end(), s);
|
---|
462 | AssertMsg (it != networkAdapterTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
463 | return KNetworkAdapterType (it - networkAdapterTypes.begin());
|
---|
464 | }
|
---|
465 |
|
---|
466 | QString toString (KNetworkAttachmentType t) const
|
---|
467 | {
|
---|
468 | AssertMsg (!networkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
|
---|
469 | return networkAttachmentTypes.value (t);
|
---|
470 | }
|
---|
471 |
|
---|
472 | KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
|
---|
473 | {
|
---|
474 | QStringVector::const_iterator it =
|
---|
475 | qFind (networkAttachmentTypes.begin(), networkAttachmentTypes.end(), s);
|
---|
476 | AssertMsg (it != networkAttachmentTypes.end(), ("No value for {%s}", s.toLatin1().constData()));
|
---|
477 | return KNetworkAttachmentType (it - networkAttachmentTypes.begin());
|
---|
478 | }
|
---|
479 |
|
---|
480 | QString toString (KUSBDeviceState aState) const
|
---|
481 | {
|
---|
482 | AssertMsg (!USBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
|
---|
483 | return USBDeviceStates.value (aState);
|
---|
484 | }
|
---|
485 |
|
---|
486 | QStringList COMPortNames() const;
|
---|
487 | QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
|
---|
488 | bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
|
---|
489 |
|
---|
490 | QStringList LPTPortNames() const;
|
---|
491 | QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
|
---|
492 | bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
|
---|
493 |
|
---|
494 | QPixmap snapshotIcon (bool online) const
|
---|
495 | {
|
---|
496 | return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
|
---|
497 | }
|
---|
498 |
|
---|
499 | /* details generators */
|
---|
500 |
|
---|
501 | QString details (const CHardDisk &aHD, bool aPredict = false,
|
---|
502 | bool aDoRefresh = true);
|
---|
503 |
|
---|
504 | QString details (const CUSBDevice &aDevice) const;
|
---|
505 | QString toolTip (const CUSBDevice &aDevice) const;
|
---|
506 | QString toolTip (const CUSBDeviceFilter &aFilter) const;
|
---|
507 |
|
---|
508 | QString prepareFileNameForHTML (const QString &fn) const;
|
---|
509 |
|
---|
510 | QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks,
|
---|
511 | bool aDoRefresh = true);
|
---|
512 |
|
---|
513 | QString platformInfo();
|
---|
514 |
|
---|
515 | /* VirtualBox helpers */
|
---|
516 |
|
---|
517 | #if defined(Q_WS_X11) && !defined(VBOX_OSE)
|
---|
518 | double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
|
---|
519 | bool showVirtualBoxLicense();
|
---|
520 | #endif
|
---|
521 |
|
---|
522 | void checkForAutoConvertedSettings();
|
---|
523 |
|
---|
524 | CSession openSession (const QUuid &aId, bool aExisting = false);
|
---|
525 |
|
---|
526 | /** Shortcut to openSession (aId, true). */
|
---|
527 | CSession openExistingSession (const QUuid &aId) { return openSession (aId, true); }
|
---|
528 |
|
---|
529 | bool startMachine (const QUuid &id);
|
---|
530 |
|
---|
531 | void startEnumeratingMedia();
|
---|
532 |
|
---|
533 | /**
|
---|
534 | * Returns a list of all currently registered media. This list is used
|
---|
535 | * to globally track the accessiblity state of all media on a dedicated
|
---|
536 | * thread. This the list is initially empty (before the first enumeration
|
---|
537 | * process is started using #startEnumeratingMedia()).
|
---|
538 | */
|
---|
539 | const VBoxMediaList ¤tMediaList() const { return media_list; }
|
---|
540 |
|
---|
541 | /** Returns true if the media enumeration is in progress. */
|
---|
542 | bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
|
---|
543 |
|
---|
544 | void addMedia (const VBoxMedia &);
|
---|
545 | void updateMedia (const VBoxMedia &);
|
---|
546 | void removeMedia (VBoxDefs::DiskType, const QUuid &);
|
---|
547 |
|
---|
548 | bool findMedia (const CUnknown &, VBoxMedia &) const;
|
---|
549 |
|
---|
550 | /* various helpers */
|
---|
551 |
|
---|
552 | QString languageName() const;
|
---|
553 | QString languageCountry() const;
|
---|
554 | QString languageNameEnglish() const;
|
---|
555 | QString languageCountryEnglish() const;
|
---|
556 | QString languageTranslators() const;
|
---|
557 |
|
---|
558 | void retranslateUi();
|
---|
559 |
|
---|
560 | /** @internal made public for internal purposes */
|
---|
561 | void cleanup();
|
---|
562 |
|
---|
563 | /* public static stuff */
|
---|
564 |
|
---|
565 | static bool isDOSType (const QString &aOSTypeId);
|
---|
566 |
|
---|
567 | static void adoptLabelPixmap (QLabel *);
|
---|
568 |
|
---|
569 | static QString languageId();
|
---|
570 | static void loadLanguage (const QString &aLangId = QString::null);
|
---|
571 | QString helpFile() const;
|
---|
572 |
|
---|
573 | static QIcon iconSet (const char *aNormal,
|
---|
574 | const char *aDisabled = NULL,
|
---|
575 | const char *aActive = NULL);
|
---|
576 | static QIcon iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,
|
---|
577 | const char *aNormal, const char *aSmallNormal,
|
---|
578 | const char *aDisabled = NULL,
|
---|
579 | const char *aSmallDisabled = NULL,
|
---|
580 | const char *aActive = NULL,
|
---|
581 | const char *aSmallActive = NULL);
|
---|
582 |
|
---|
583 | static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);
|
---|
584 |
|
---|
585 | static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
|
---|
586 |
|
---|
587 | static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
|
---|
588 | bool aCanResize = true);
|
---|
589 |
|
---|
590 | static void centerWidget (QWidget *aWidget, QWidget *aRelative,
|
---|
591 | bool aCanResize = true);
|
---|
592 |
|
---|
593 | static QChar decimalSep();
|
---|
594 | static QString sizeRegexp();
|
---|
595 |
|
---|
596 | static quint64 parseSize (const QString &);
|
---|
597 | static QString formatSize (quint64, int aMode = 0);
|
---|
598 |
|
---|
599 | static QString highlight (const QString &aStr, bool aToolTip = false);
|
---|
600 |
|
---|
601 | static QString systemLanguageId();
|
---|
602 |
|
---|
603 | static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
|
---|
604 | const QString &aCaption = QString::null,
|
---|
605 | bool aDirOnly = TRUE,
|
---|
606 | bool resolveSymlinks = TRUE);
|
---|
607 |
|
---|
608 | static QString getOpenFileName (const QString &, const QString &, QWidget*,
|
---|
609 | const QString &, QString *defaultFilter = 0,
|
---|
610 | bool resolveSymLinks = true);
|
---|
611 |
|
---|
612 | static QString getFirstExistingDir (const QString &);
|
---|
613 |
|
---|
614 | static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
|
---|
615 |
|
---|
616 | static QString removeAccelMark (const QString &aText);
|
---|
617 |
|
---|
618 | static QString insertKeyToActionText (const QString &aText, const QString &aKey);
|
---|
619 | static QString extractKeyFromActionText (const QString &aText);
|
---|
620 |
|
---|
621 | static QWidget *findWidget (QWidget *aParent, const char *aName,
|
---|
622 | const char *aClassName = NULL,
|
---|
623 | bool aRecursive = false);
|
---|
624 |
|
---|
625 | static QList< QPair<QString, QString> > HDDBackends();
|
---|
626 |
|
---|
627 | /* Qt 4.2.0 support function */
|
---|
628 | static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
|
---|
629 | {
|
---|
630 | #if QT_VERSION < 0x040300
|
---|
631 | /* Deprecated since > 4.2 */
|
---|
632 | aLayout->setMargin (aMargin);
|
---|
633 | #else
|
---|
634 | /* New since > 4.2 */
|
---|
635 | aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
|
---|
636 | #endif
|
---|
637 | }
|
---|
638 |
|
---|
639 | signals:
|
---|
640 |
|
---|
641 | /**
|
---|
642 | * Emitted at the beginning of the enumeration process started
|
---|
643 | * by #startEnumeratingMedia().
|
---|
644 | */
|
---|
645 | void mediaEnumStarted();
|
---|
646 |
|
---|
647 | /**
|
---|
648 | * Emitted when a new media item from the list has updated
|
---|
649 | * its accessibility state.
|
---|
650 | */
|
---|
651 | void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
|
---|
652 |
|
---|
653 | /**
|
---|
654 | * Emitted at the end of the enumeration process started
|
---|
655 | * by #startEnumeratingMedia(). The @a aList argument is passed for
|
---|
656 | * convenience, it is exactly the same as returned by #currentMediaList().
|
---|
657 | */
|
---|
658 | void mediaEnumFinished (const VBoxMediaList &aList);
|
---|
659 |
|
---|
660 | /** Emitted when a new media is added using #addMedia(). */
|
---|
661 | void mediaAdded (const VBoxMedia &);
|
---|
662 |
|
---|
663 | /** Emitted when the media is updated using #updateMedia(). */
|
---|
664 | void mediaUpdated (const VBoxMedia &);
|
---|
665 |
|
---|
666 | /** Emitted when the media is removed using #removeMedia(). */
|
---|
667 | void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
|
---|
668 |
|
---|
669 | /* signals emitted when the VirtualBox callback is called by the server
|
---|
670 | * (not that currently these signals are emitted only when the application
|
---|
671 | * is the in the VM selector mode) */
|
---|
672 |
|
---|
673 | void machineStateChanged (const VBoxMachineStateChangeEvent &e);
|
---|
674 | void machineDataChanged (const VBoxMachineDataChangeEvent &e);
|
---|
675 | void machineRegistered (const VBoxMachineRegisteredEvent &e);
|
---|
676 | void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
|
---|
677 | void snapshotChanged (const VBoxSnapshotEvent &e);
|
---|
678 |
|
---|
679 | void canShowRegDlg (bool aCanShow);
|
---|
680 | void canShowUpdDlg (bool aCanShow);
|
---|
681 |
|
---|
682 | public slots:
|
---|
683 |
|
---|
684 | bool openURL (const QString &aURL);
|
---|
685 |
|
---|
686 | void showRegistrationDialog (bool aForce = true);
|
---|
687 | void showUpdateDialog (bool aForce = true);
|
---|
688 |
|
---|
689 | protected:
|
---|
690 |
|
---|
691 | bool event (QEvent *e);
|
---|
692 | bool eventFilter (QObject *, QEvent *);
|
---|
693 |
|
---|
694 | private:
|
---|
695 |
|
---|
696 | VBoxGlobal();
|
---|
697 | ~VBoxGlobal();
|
---|
698 |
|
---|
699 | void init();
|
---|
700 |
|
---|
701 | bool mValid;
|
---|
702 |
|
---|
703 | CVirtualBox mVBox;
|
---|
704 |
|
---|
705 | VBoxGlobalSettings gset;
|
---|
706 |
|
---|
707 | VBoxSelectorWnd *mSelectorWnd;
|
---|
708 | VBoxConsoleWnd *mConsoleWnd;
|
---|
709 | QWidget* mMainWindow;
|
---|
710 |
|
---|
711 | #ifdef VBOX_WITH_REGISTRATION
|
---|
712 | VBoxRegistrationDlg *mRegDlg;
|
---|
713 | #endif
|
---|
714 | VBoxUpdateDlg *mUpdDlg;
|
---|
715 |
|
---|
716 | QUuid vmUuid;
|
---|
717 |
|
---|
718 | QThread *media_enum_thread;
|
---|
719 | VBoxMediaList media_list;
|
---|
720 |
|
---|
721 | VBoxDefs::RenderMode vm_render_mode;
|
---|
722 | const char * vm_render_mode_str;
|
---|
723 |
|
---|
724 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
725 | /** Whether the debugger should be accessible or not.
|
---|
726 | * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
|
---|
727 | * VBOX_GUI_DBG_AUTO_SHOW to enable. */
|
---|
728 | bool mDbgEnabled;
|
---|
729 | /** Whether to show the debugger automatically with the console.
|
---|
730 | * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
|
---|
731 | bool mDbgAutoShow;
|
---|
732 | /** VBoxDbg module handle. */
|
---|
733 | RTLDRMOD mhVBoxDbg;
|
---|
734 | #endif
|
---|
735 |
|
---|
736 | #if defined (Q_WS_WIN32)
|
---|
737 | DWORD dwHTMLHelpCookie;
|
---|
738 | #endif
|
---|
739 |
|
---|
740 | CVirtualBoxCallback callback;
|
---|
741 |
|
---|
742 | typedef QVector <QString> QStringVector;
|
---|
743 |
|
---|
744 | QString verString;
|
---|
745 |
|
---|
746 | QVector <CGuestOSType> vm_os_types;
|
---|
747 | QHash <QString, QPixmap *> vm_os_type_icons;
|
---|
748 | QVector <QColor *> vm_state_color;
|
---|
749 |
|
---|
750 | QHash <long int, QPixmap *> mStateIcons;
|
---|
751 | QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
|
---|
752 |
|
---|
753 | QStringVector machineStates;
|
---|
754 | QStringVector sessionStates;
|
---|
755 | QStringVector deviceTypes;
|
---|
756 | QStringVector storageBuses;
|
---|
757 | QStringVector storageBusDevices;
|
---|
758 | QStringVector storageBusChannels;
|
---|
759 | QStringVector diskTypes;
|
---|
760 | QStringVector diskStorageTypes;
|
---|
761 | QStringVector vrdpAuthTypes;
|
---|
762 | QStringVector portModeTypes;
|
---|
763 | QStringVector usbFilterActionTypes;
|
---|
764 | QStringVector audioDriverTypes;
|
---|
765 | QStringVector audioControllerTypes;
|
---|
766 | QStringVector networkAdapterTypes;
|
---|
767 | QStringVector networkAttachmentTypes;
|
---|
768 | QStringVector clipboardTypes;
|
---|
769 | QStringVector ideControllerTypes;
|
---|
770 | QStringVector USBDeviceStates;
|
---|
771 |
|
---|
772 | QString mUserDefinedPortName;
|
---|
773 |
|
---|
774 | mutable bool detailReportTemplatesReady;
|
---|
775 |
|
---|
776 | friend VBoxGlobal &vboxGlobal();
|
---|
777 | friend class VBoxCallback;
|
---|
778 | };
|
---|
779 |
|
---|
780 | inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
|
---|
781 |
|
---|
782 | // Helper classes
|
---|
783 | ////////////////////////////////////////////////////////////////////////////////
|
---|
784 |
|
---|
785 | /**
|
---|
786 | * Generic asyncronous event.
|
---|
787 | *
|
---|
788 | * This abstract class is intended to provide a conveinent way to execute
|
---|
789 | * code on the main GUI thread asynchronously to the calling party. This is
|
---|
790 | * done by putting necessary actions to the #handle() function in a subclass
|
---|
791 | * and then posting an instance of the subclass using #post(). The instance
|
---|
792 | * must be allocated on the heap using the <tt>new</tt> operation and will be
|
---|
793 | * automatically deleted after processing. Note that if you don't call #post()
|
---|
794 | * on the created instance, you have to delete it yourself.
|
---|
795 | */
|
---|
796 | class VBoxAsyncEvent : public QEvent
|
---|
797 | {
|
---|
798 | public:
|
---|
799 |
|
---|
800 | VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
|
---|
801 |
|
---|
802 | /**
|
---|
803 | * Worker function. Gets executed on the GUI thread when the posted event
|
---|
804 | * is processed by the main event loop.
|
---|
805 | */
|
---|
806 | virtual void handle() = 0;
|
---|
807 |
|
---|
808 | /**
|
---|
809 | * Posts this event to the main event loop.
|
---|
810 | * The caller loses ownership of this object after this method returns
|
---|
811 | * and must not delete the object.
|
---|
812 | */
|
---|
813 | void post()
|
---|
814 | {
|
---|
815 | QApplication::postEvent (&vboxGlobal(), this);
|
---|
816 | }
|
---|
817 | };
|
---|
818 |
|
---|
819 | /**
|
---|
820 | * USB Popup Menu class.
|
---|
821 | * This class provides the list of USB devices attached to the host.
|
---|
822 | */
|
---|
823 | class VBoxUSBMenu : public QMenu
|
---|
824 | {
|
---|
825 | Q_OBJECT
|
---|
826 |
|
---|
827 | public:
|
---|
828 |
|
---|
829 | VBoxUSBMenu (QWidget *);
|
---|
830 |
|
---|
831 | const CUSBDevice& getUSB (QAction *aAction);
|
---|
832 |
|
---|
833 | void setConsole (const CConsole &);
|
---|
834 |
|
---|
835 | private slots:
|
---|
836 |
|
---|
837 | void processAboutToShow();
|
---|
838 |
|
---|
839 | private:
|
---|
840 | bool event(QEvent *aEvent);
|
---|
841 |
|
---|
842 | QMap <QAction *, CUSBDevice> mUSBDevicesMap;
|
---|
843 | CConsole mConsole;
|
---|
844 | };
|
---|
845 |
|
---|
846 | /**
|
---|
847 | * Enable/Disable Menu class.
|
---|
848 | * This class provides enable/disable menu items.
|
---|
849 | */
|
---|
850 | class VBoxSwitchMenu : public QMenu
|
---|
851 | {
|
---|
852 | Q_OBJECT
|
---|
853 |
|
---|
854 | public:
|
---|
855 |
|
---|
856 | VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
|
---|
857 |
|
---|
858 | void setToolTip (const QString &);
|
---|
859 |
|
---|
860 | private slots:
|
---|
861 |
|
---|
862 | void processAboutToShow();
|
---|
863 |
|
---|
864 | private:
|
---|
865 |
|
---|
866 | QAction *mAction;
|
---|
867 | bool mInverted;
|
---|
868 | };
|
---|
869 |
|
---|
870 | #endif /* __VBoxGlobal_h__ */
|
---|