1 | /* $Id: VBoxGlobal.cpp 35730 2011-01-27 10:49:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * VBoxGlobal class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "VBoxGlobal.h"
|
---|
21 | #include <VBox/vd.h>
|
---|
22 | #include <VBox/version.h>
|
---|
23 |
|
---|
24 | #include "VBoxDefs.h"
|
---|
25 | #include "VBoxSelectorWnd.h"
|
---|
26 | #include "VBoxProblemReporter.h"
|
---|
27 | #include "QIMessageBox.h"
|
---|
28 | #include "QIDialogButtonBox.h"
|
---|
29 | #include "UIIconPool.h"
|
---|
30 | #include "UIExtraDataEventHandler.h"
|
---|
31 | #include "QIFileDialog.h"
|
---|
32 |
|
---|
33 | #include "UIMachine.h"
|
---|
34 | #include "UISession.h"
|
---|
35 | #ifdef VBOX_WITH_REGISTRATION
|
---|
36 | # include "UIRegistrationWzd.h"
|
---|
37 | #endif
|
---|
38 | #include "VBoxUpdateDlg.h"
|
---|
39 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
40 | # include "VBoxFBOverlay.h"
|
---|
41 | #endif /* VBOX_WITH_VIDEOHWACCEL */
|
---|
42 |
|
---|
43 | #ifdef Q_WS_MAC
|
---|
44 | # include "UIMachineWindowFullscreen.h"
|
---|
45 | # include "UIMachineWindowSeamless.h"
|
---|
46 | #endif /* Q_WS_MAC */
|
---|
47 |
|
---|
48 | /* Qt includes */
|
---|
49 | #include <QProgressDialog>
|
---|
50 | #include <QLibraryInfo>
|
---|
51 | #include <QFileDialog>
|
---|
52 | #include <QToolTip>
|
---|
53 | #include <QTranslator>
|
---|
54 | #include <QDesktopWidget>
|
---|
55 | #include <QDesktopServices>
|
---|
56 | #include <QMutex>
|
---|
57 | #include <QToolButton>
|
---|
58 | #include <QProcess>
|
---|
59 | #include <QThread>
|
---|
60 | #include <QPainter>
|
---|
61 | #include <QSettings>
|
---|
62 | #include <QTimer>
|
---|
63 | #include <QDir>
|
---|
64 | #include <QHelpEvent>
|
---|
65 | #include <QLocale>
|
---|
66 |
|
---|
67 | #ifdef VBOX_GUI_WITH_PIDFILE
|
---|
68 | # include <QTextStream>
|
---|
69 | #endif /* VBOX_GUI_WITH_PIDFILE */
|
---|
70 |
|
---|
71 | #include <math.h>
|
---|
72 |
|
---|
73 | #ifdef Q_WS_X11
|
---|
74 | # include "UIHotKeyEditor.h"
|
---|
75 | # ifndef VBOX_OSE
|
---|
76 | # include "VBoxLicenseViewer.h"
|
---|
77 | # endif /* VBOX_OSE */
|
---|
78 | # include <QTextBrowser>
|
---|
79 | # include <QScrollBar>
|
---|
80 | # include <QX11Info>
|
---|
81 | # include "VBoxX11Helper.h"
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | #ifdef Q_WS_MAC
|
---|
85 | # include "VBoxUtils-darwin.h"
|
---|
86 | #endif /* Q_WS_MAC */
|
---|
87 |
|
---|
88 | #if defined (Q_WS_WIN)
|
---|
89 | #include "shlobj.h"
|
---|
90 | #include <QEventLoop>
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | #if defined (Q_WS_X11)
|
---|
94 | #undef BOOL /* typedef CARD8 BOOL in Xmd.h conflicts with #define BOOL PRBool
|
---|
95 | * in COMDefs.h. A better fix would be to isolate X11-specific
|
---|
96 | * stuff by placing XX* helpers below to a separate source file. */
|
---|
97 | #include <X11/X.h>
|
---|
98 | #include <X11/Xmd.h>
|
---|
99 | #include <X11/Xlib.h>
|
---|
100 | #include <X11/Xatom.h>
|
---|
101 | #include <X11/extensions/Xinerama.h>
|
---|
102 | #define BOOL PRBool
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | #include <VBox/sup.h>
|
---|
106 | #include <VBox/com/Guid.h>
|
---|
107 |
|
---|
108 | #include <iprt/asm.h>
|
---|
109 | #include <iprt/err.h>
|
---|
110 | #include <iprt/param.h>
|
---|
111 | #include <iprt/path.h>
|
---|
112 | #include <iprt/env.h>
|
---|
113 | #include <iprt/file.h>
|
---|
114 | #include <iprt/ldr.h>
|
---|
115 | #include <iprt/system.h>
|
---|
116 | #include <iprt/stream.h>
|
---|
117 |
|
---|
118 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
119 | #include <iprt/process.h>
|
---|
120 |
|
---|
121 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
122 | #define HOSTSUFF_EXE ".exe"
|
---|
123 | #else /* !RT_OS_WINDOWS */
|
---|
124 | #define HOSTSUFF_EXE ""
|
---|
125 | #endif /* !RT_OS_WINDOWS */
|
---|
126 | #endif
|
---|
127 |
|
---|
128 | #if defined (Q_WS_X11)
|
---|
129 | #include <iprt/mem.h>
|
---|
130 | #endif
|
---|
131 |
|
---|
132 | //#define VBOX_WITH_FULL_DETAILS_REPORT /* hidden for now */
|
---|
133 |
|
---|
134 | //#warning "port me: check this"
|
---|
135 | /// @todo bird: Use (U)INT_PTR, (U)LONG_PTR, DWORD_PTR, or (u)intptr_t.
|
---|
136 | #if defined(Q_OS_WIN64)
|
---|
137 | typedef __int64 Q_LONG; /* word up to 64 bit signed */
|
---|
138 | typedef unsigned __int64 Q_ULONG; /* word up to 64 bit unsigned */
|
---|
139 | #else
|
---|
140 | typedef long Q_LONG; /* word up to 64 bit signed */
|
---|
141 | typedef unsigned long Q_ULONG; /* word up to 64 bit unsigned */
|
---|
142 | #endif
|
---|
143 |
|
---|
144 | // VBoxMediaEnumEvent
|
---|
145 | /////////////////////////////////////////////////////////////////////////////
|
---|
146 |
|
---|
147 | class VBoxMediaEnumEvent : public QEvent
|
---|
148 | {
|
---|
149 | public:
|
---|
150 |
|
---|
151 | /** Constructs a regular enum event */
|
---|
152 | VBoxMediaEnumEvent (const VBoxMedium &aMedium,
|
---|
153 | VBoxMediaList::iterator &aIterator)
|
---|
154 | : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType)
|
---|
155 | , mMedium (aMedium), mIterator (aIterator), mLast (false)
|
---|
156 | {}
|
---|
157 | /** Constructs the last enum event */
|
---|
158 | VBoxMediaEnumEvent (VBoxMediaList::iterator &aIterator)
|
---|
159 | : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType)
|
---|
160 | , mIterator (aIterator), mLast (true)
|
---|
161 | {}
|
---|
162 |
|
---|
163 | /** Last enumerated medium (not valid when #last is true) */
|
---|
164 | const VBoxMedium mMedium;
|
---|
165 | /** Opaque iterator provided by the event sender (guaranteed to be
|
---|
166 | * the same variable for all media in the single enumeration procedure) */
|
---|
167 | VBoxMediaList::iterator &mIterator;
|
---|
168 | /** Whether this is the last event for the given enumeration or not */
|
---|
169 | const bool mLast;
|
---|
170 | };
|
---|
171 |
|
---|
172 | // VBoxGlobal
|
---|
173 | ////////////////////////////////////////////////////////////////////////////////
|
---|
174 |
|
---|
175 | static bool sVBoxGlobalInited = false;
|
---|
176 | static bool sVBoxGlobalInCleanup = false;
|
---|
177 |
|
---|
178 | /** @internal
|
---|
179 | *
|
---|
180 | * Special routine to do VBoxGlobal cleanup when the application is being
|
---|
181 | * terminated. It is called before some essential Qt functionality (for
|
---|
182 | * instance, QThread) becomes unavailable, allowing us to use it from
|
---|
183 | * VBoxGlobal::cleanup() if necessary.
|
---|
184 | */
|
---|
185 | static void vboxGlobalCleanup()
|
---|
186 | {
|
---|
187 | Assert (!sVBoxGlobalInCleanup);
|
---|
188 | sVBoxGlobalInCleanup = true;
|
---|
189 | vboxGlobal().cleanup();
|
---|
190 | }
|
---|
191 |
|
---|
192 | /** @internal
|
---|
193 | *
|
---|
194 | * Determines the rendering mode from the argument. Sets the appropriate
|
---|
195 | * default rendering mode if the argument is NULL.
|
---|
196 | */
|
---|
197 | static VBoxDefs::RenderMode vboxGetRenderMode (const char *aModeStr)
|
---|
198 | {
|
---|
199 | VBoxDefs::RenderMode mode = VBoxDefs::InvalidRenderMode;
|
---|
200 |
|
---|
201 | #if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
|
---|
202 | mode = VBoxDefs::Quartz2DMode;
|
---|
203 | # ifdef RT_ARCH_X86
|
---|
204 | /* Quartz2DMode doesn't refresh correctly on 32-bit Snow Leopard, use image mode. */
|
---|
205 | // char szRelease[80];
|
---|
206 | // if ( RT_SUCCESS (RTSystemQueryOSInfo (RTSYSOSINFO_RELEASE, szRelease, sizeof (szRelease)))
|
---|
207 | // && !strncmp (szRelease, "10.", 3))
|
---|
208 | // mode = VBoxDefs::QImageMode;
|
---|
209 | # endif
|
---|
210 | #elif (defined (Q_WS_WIN32) || defined (Q_WS_PM) || defined (Q_WS_X11)) && defined (VBOX_GUI_USE_QIMAGE)
|
---|
211 | mode = VBoxDefs::QImageMode;
|
---|
212 | #elif defined (Q_WS_X11) && defined (VBOX_GUI_USE_SDL)
|
---|
213 | mode = VBoxDefs::SDLMode;
|
---|
214 | #elif defined (VBOX_GUI_USE_QIMAGE)
|
---|
215 | mode = VBoxDefs::QImageMode;
|
---|
216 | #else
|
---|
217 | # error "Cannot determine the default render mode!"
|
---|
218 | #endif
|
---|
219 |
|
---|
220 | if (aModeStr)
|
---|
221 | {
|
---|
222 | if (0) ;
|
---|
223 | #if defined (VBOX_GUI_USE_QIMAGE)
|
---|
224 | else if (::strcmp (aModeStr, "image") == 0)
|
---|
225 | mode = VBoxDefs::QImageMode;
|
---|
226 | #endif
|
---|
227 | #if defined (VBOX_GUI_USE_SDL)
|
---|
228 | else if (::strcmp (aModeStr, "sdl") == 0)
|
---|
229 | mode = VBoxDefs::SDLMode;
|
---|
230 | #endif
|
---|
231 | #if defined (VBOX_GUI_USE_DDRAW)
|
---|
232 | else if (::strcmp (aModeStr, "ddraw") == 0)
|
---|
233 | mode = VBoxDefs::DDRAWMode;
|
---|
234 | #endif
|
---|
235 | #if defined (VBOX_GUI_USE_QUARTZ2D)
|
---|
236 | else if (::strcmp (aModeStr, "quartz2d") == 0)
|
---|
237 | mode = VBoxDefs::Quartz2DMode;
|
---|
238 | #endif
|
---|
239 | #if defined (VBOX_GUI_USE_QGLFB)
|
---|
240 | else if (::strcmp (aModeStr, "qgl") == 0)
|
---|
241 | mode = VBoxDefs::QGLMode;
|
---|
242 | #endif
|
---|
243 | //#if defined (VBOX_GUI_USE_QGL)
|
---|
244 | // else if (::strcmp (aModeStr, "qgloverlay") == 0)
|
---|
245 | // mode = VBoxDefs::QGLOverlayMode;
|
---|
246 | //#endif
|
---|
247 |
|
---|
248 | }
|
---|
249 |
|
---|
250 | return mode;
|
---|
251 | }
|
---|
252 |
|
---|
253 | /** @class VBoxGlobal
|
---|
254 | *
|
---|
255 | * The VBoxGlobal class encapsulates the global VirtualBox data.
|
---|
256 | *
|
---|
257 | * There is only one instance of this class per VirtualBox application,
|
---|
258 | * the reference to it is returned by the static instance() method, or by
|
---|
259 | * the global vboxGlobal() function, that is just an inlined shortcut.
|
---|
260 | */
|
---|
261 |
|
---|
262 | VBoxGlobal::VBoxGlobal()
|
---|
263 | : mValid (false)
|
---|
264 | , mSelectorWnd (NULL)
|
---|
265 | , m_pVirtualMachine(0)
|
---|
266 | , mMainWindow (NULL)
|
---|
267 | #ifdef VBOX_WITH_REGISTRATION
|
---|
268 | , mRegDlg (NULL)
|
---|
269 | #endif
|
---|
270 | , mUpdDlg (NULL)
|
---|
271 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
272 | , mIsTrayMenu (false)
|
---|
273 | , mIncreasedWindowCounter (false)
|
---|
274 | #endif
|
---|
275 | , mMediaEnumThread (NULL)
|
---|
276 | , mIsKWinManaged (false)
|
---|
277 | , mVerString ("1.0")
|
---|
278 | {
|
---|
279 | }
|
---|
280 |
|
---|
281 | //
|
---|
282 | // Public members
|
---|
283 | /////////////////////////////////////////////////////////////////////////////
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * Returns a reference to the global VirtualBox data, managed by this class.
|
---|
287 | *
|
---|
288 | * The main() function of the VBox GUI must call this function soon after
|
---|
289 | * creating a QApplication instance but before opening any of the main windows
|
---|
290 | * (to let the VBoxGlobal initialization procedure use various Qt facilities),
|
---|
291 | * and continue execution only when the isValid() method of the returned
|
---|
292 | * instancereturns true, i.e. do something like:
|
---|
293 | *
|
---|
294 | * @code
|
---|
295 | * if ( !VBoxGlobal::instance().isValid() )
|
---|
296 | * return 1;
|
---|
297 | * @endcode
|
---|
298 | * or
|
---|
299 | * @code
|
---|
300 | * if ( !vboxGlobal().isValid() )
|
---|
301 | * return 1;
|
---|
302 | * @endcode
|
---|
303 | *
|
---|
304 | * @note Some VBoxGlobal methods can be used on a partially constructed
|
---|
305 | * VBoxGlobal instance, i.e. from constructors and methods called
|
---|
306 | * from the VBoxGlobal::init() method, which obtain the instance
|
---|
307 | * using this instance() call or the ::vboxGlobal() function. Currently, such
|
---|
308 | * methods are:
|
---|
309 | * #vmStateText, #vmTypeIcon, #vmTypeText, #vmTypeTextList, #vmTypeFromText.
|
---|
310 | *
|
---|
311 | * @see ::vboxGlobal
|
---|
312 | */
|
---|
313 | VBoxGlobal &VBoxGlobal::instance()
|
---|
314 | {
|
---|
315 | static VBoxGlobal vboxGlobal_instance;
|
---|
316 |
|
---|
317 | if (!sVBoxGlobalInited)
|
---|
318 | {
|
---|
319 | /* check that a QApplication instance is created */
|
---|
320 | if (qApp)
|
---|
321 | {
|
---|
322 | sVBoxGlobalInited = true;
|
---|
323 | vboxGlobal_instance.init();
|
---|
324 | /* add our cleanup handler to the list of Qt post routines */
|
---|
325 | qAddPostRoutine (vboxGlobalCleanup);
|
---|
326 | }
|
---|
327 | else
|
---|
328 | AssertMsgFailed (("Must construct a QApplication first!"));
|
---|
329 | }
|
---|
330 | return vboxGlobal_instance;
|
---|
331 | }
|
---|
332 |
|
---|
333 | VBoxGlobal::~VBoxGlobal()
|
---|
334 | {
|
---|
335 | qDeleteAll (mOsTypeIcons);
|
---|
336 | qDeleteAll (mVMStateIcons);
|
---|
337 | qDeleteAll (mVMStateColors);
|
---|
338 | }
|
---|
339 |
|
---|
340 | /* static */
|
---|
341 | QString VBoxGlobal::qtRTVersionString()
|
---|
342 | {
|
---|
343 | return QString::fromLatin1 (qVersion());
|
---|
344 | }
|
---|
345 |
|
---|
346 | /* static */
|
---|
347 | uint VBoxGlobal::qtRTVersion()
|
---|
348 | {
|
---|
349 | QString rt_ver_str = VBoxGlobal::qtRTVersionString();
|
---|
350 | return (rt_ver_str.section ('.', 0, 0).toInt() << 16) +
|
---|
351 | (rt_ver_str.section ('.', 1, 1).toInt() << 8) +
|
---|
352 | rt_ver_str.section ('.', 2, 2).toInt();
|
---|
353 | }
|
---|
354 |
|
---|
355 | /* static */
|
---|
356 | QString VBoxGlobal::qtCTVersionString()
|
---|
357 | {
|
---|
358 | return QString::fromLatin1 (QT_VERSION_STR);
|
---|
359 | }
|
---|
360 |
|
---|
361 | /* static */
|
---|
362 | uint VBoxGlobal::qtCTVersion()
|
---|
363 | {
|
---|
364 | QString ct_ver_str = VBoxGlobal::qtCTVersionString();
|
---|
365 | return (ct_ver_str.section ('.', 0, 0).toInt() << 16) +
|
---|
366 | (ct_ver_str.section ('.', 1, 1).toInt() << 8) +
|
---|
367 | ct_ver_str.section ('.', 2, 2).toInt();
|
---|
368 | }
|
---|
369 |
|
---|
370 | bool VBoxGlobal::isBeta() const
|
---|
371 | {
|
---|
372 | return mVBox.GetVersion().contains("BETA", Qt::CaseInsensitive);
|
---|
373 | }
|
---|
374 |
|
---|
375 | /**
|
---|
376 | * Sets the new global settings and saves them to the VirtualBox server.
|
---|
377 | */
|
---|
378 | bool VBoxGlobal::setSettings (VBoxGlobalSettings &gs)
|
---|
379 | {
|
---|
380 | gs.save (mVBox);
|
---|
381 |
|
---|
382 | if (!mVBox.isOk())
|
---|
383 | {
|
---|
384 | vboxProblem().cannotSaveGlobalConfig (mVBox);
|
---|
385 | return false;
|
---|
386 | }
|
---|
387 |
|
---|
388 | /* We don't assign gs to our gset member here, because VBoxCallback
|
---|
389 | * will update gset as necessary when new settings are successfully
|
---|
390 | * sent to the VirtualBox server by gs.save(). */
|
---|
391 |
|
---|
392 | return true;
|
---|
393 | }
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * Returns a reference to the main VBox VM Selector window.
|
---|
397 | * The reference is valid until application termination.
|
---|
398 | *
|
---|
399 | * There is only one such a window per VirtualBox application.
|
---|
400 | */
|
---|
401 | VBoxSelectorWnd &VBoxGlobal::selectorWnd()
|
---|
402 | {
|
---|
403 | AssertMsg (!vboxGlobal().isVMConsoleProcess(),
|
---|
404 | ("Must NOT be a VM console process"));
|
---|
405 | Assert (mValid);
|
---|
406 |
|
---|
407 | if (!mSelectorWnd)
|
---|
408 | {
|
---|
409 | /*
|
---|
410 | * We pass the address of mSelectorWnd to the constructor to let it be
|
---|
411 | * initialized right after the constructor is called. It is necessary
|
---|
412 | * to avoid recursion, since this method may be (and will be) called
|
---|
413 | * from the below constructor or from constructors/methods it calls.
|
---|
414 | */
|
---|
415 | VBoxSelectorWnd *w = new VBoxSelectorWnd (&mSelectorWnd, 0);
|
---|
416 | Assert (w == mSelectorWnd);
|
---|
417 | NOREF(w);
|
---|
418 | }
|
---|
419 |
|
---|
420 | return *mSelectorWnd;
|
---|
421 | }
|
---|
422 |
|
---|
423 |
|
---|
424 | QWidget *VBoxGlobal::vmWindow()
|
---|
425 | {
|
---|
426 | if (isVMConsoleProcess())
|
---|
427 | {
|
---|
428 | if (m_pVirtualMachine)
|
---|
429 | return m_pVirtualMachine->mainWindow();
|
---|
430 | }
|
---|
431 | return NULL;
|
---|
432 | }
|
---|
433 |
|
---|
434 | bool VBoxGlobal::createVirtualMachine(const CSession &session)
|
---|
435 | {
|
---|
436 | if (!m_pVirtualMachine && !session.isNull())
|
---|
437 | {
|
---|
438 | UIMachine *pVirtualMachine = new UIMachine(&m_pVirtualMachine, session);
|
---|
439 | Assert(pVirtualMachine == m_pVirtualMachine);
|
---|
440 | NOREF(pVirtualMachine);
|
---|
441 | return true;
|
---|
442 | }
|
---|
443 | return false;
|
---|
444 | }
|
---|
445 |
|
---|
446 | UIMachine* VBoxGlobal::virtualMachine()
|
---|
447 | {
|
---|
448 | return m_pVirtualMachine;
|
---|
449 | }
|
---|
450 |
|
---|
451 | #ifdef VBOX_GUI_WITH_PIDFILE
|
---|
452 | void VBoxGlobal::createPidfile()
|
---|
453 | {
|
---|
454 | if (!m_strPidfile.isEmpty())
|
---|
455 | {
|
---|
456 | qint64 pid = qApp->applicationPid();
|
---|
457 | QFile file(m_strPidfile);
|
---|
458 | if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
---|
459 | {
|
---|
460 | QTextStream out(&file);
|
---|
461 | out << pid << endl;
|
---|
462 | }
|
---|
463 | else
|
---|
464 | LogRel(("Failed to create pid file %s\n", m_strPidfile.toUtf8().constData()));
|
---|
465 | }
|
---|
466 | }
|
---|
467 |
|
---|
468 | void VBoxGlobal::deletePidfile()
|
---|
469 | {
|
---|
470 | if ( !m_strPidfile.isEmpty()
|
---|
471 | && QFile::exists(m_strPidfile))
|
---|
472 | QFile::remove(m_strPidfile);
|
---|
473 | }
|
---|
474 | #endif
|
---|
475 |
|
---|
476 | bool VBoxGlobal::brandingIsActive (bool aForce /* = false*/)
|
---|
477 | {
|
---|
478 | if (aForce)
|
---|
479 | return true;
|
---|
480 |
|
---|
481 | if (mBrandingConfig.isEmpty())
|
---|
482 | {
|
---|
483 | mBrandingConfig = QDir(QApplication::applicationDirPath()).absolutePath();
|
---|
484 | mBrandingConfig += "/custom/custom.ini";
|
---|
485 | }
|
---|
486 | return QFile::exists (mBrandingConfig);
|
---|
487 | }
|
---|
488 |
|
---|
489 | /**
|
---|
490 | * Gets a value from the custom .ini file
|
---|
491 | */
|
---|
492 | QString VBoxGlobal::brandingGetKey (QString aKey)
|
---|
493 | {
|
---|
494 | QSettings s(mBrandingConfig, QSettings::IniFormat);
|
---|
495 | return s.value(QString("%1").arg(aKey)).toString();
|
---|
496 | }
|
---|
497 |
|
---|
498 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
499 |
|
---|
500 | /**
|
---|
501 | * Returns true if the current instance a systray menu only (started with
|
---|
502 | * "-systray" parameter).
|
---|
503 | */
|
---|
504 | bool VBoxGlobal::isTrayMenu() const
|
---|
505 | {
|
---|
506 | return mIsTrayMenu;
|
---|
507 | }
|
---|
508 |
|
---|
509 | void VBoxGlobal::setTrayMenu(bool aIsTrayMenu)
|
---|
510 | {
|
---|
511 | mIsTrayMenu = aIsTrayMenu;
|
---|
512 | }
|
---|
513 |
|
---|
514 | /**
|
---|
515 | * Spawns a new selector window (process).
|
---|
516 | */
|
---|
517 | void VBoxGlobal::trayIconShowSelector()
|
---|
518 | {
|
---|
519 | /* Get the path to the executable. */
|
---|
520 | char path[RTPATH_MAX];
|
---|
521 | RTPathAppPrivateArch(path, RTPATH_MAX);
|
---|
522 | size_t sz = strlen(path);
|
---|
523 | path[sz++] = RTPATH_DELIMITER;
|
---|
524 | path[sz] = 0;
|
---|
525 | char *cmd = path + sz;
|
---|
526 | sz = RTPATH_MAX - sz;
|
---|
527 |
|
---|
528 | int rc = 0;
|
---|
529 | const char VirtualBox_exe[] = "VirtualBox" HOSTSUFF_EXE;
|
---|
530 | Assert(sz >= sizeof(VirtualBox_exe));
|
---|
531 | strcpy(cmd, VirtualBox_exe);
|
---|
532 | const char * args[] = {path, 0 };
|
---|
533 | rc = RTProcCreate(path, args, RTENV_DEFAULT, RTPROC_FLAGS_DETACHED, NULL);
|
---|
534 | if (RT_FAILURE(rc))
|
---|
535 | LogRel(("Systray: Failed to start new selector window! Path=%s, rc=%Rrc\n", path, rc));
|
---|
536 | }
|
---|
537 |
|
---|
538 | /**
|
---|
539 | * Tries to install the tray icon using the current instance (singleton).
|
---|
540 | * Returns true if this instance is the tray icon, false if not.
|
---|
541 | */
|
---|
542 | bool VBoxGlobal::trayIconInstall()
|
---|
543 | {
|
---|
544 | int rc = 0;
|
---|
545 | QString strTrayWinID = mVBox.GetExtraData(VBoxDefs::GUI_TrayIconWinID);
|
---|
546 | if (false == strTrayWinID.isEmpty())
|
---|
547 | {
|
---|
548 | /* Check if current tray icon is alive by writing some bogus value. */
|
---|
549 | mVBox.SetExtraData(VBoxDefs::GUI_TrayIconWinID, "0");
|
---|
550 | if (mVBox.isOk())
|
---|
551 | {
|
---|
552 | /* Current tray icon died - clean up. */
|
---|
553 | mVBox.SetExtraData(VBoxDefs::GUI_TrayIconWinID, NULL);
|
---|
554 | strTrayWinID.clear();
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 | /* Is there already a tray icon or is tray icon not active? */
|
---|
559 | if ( (mIsTrayMenu == false)
|
---|
560 | && (vboxGlobal().settings().trayIconEnabled())
|
---|
561 | && (QSystemTrayIcon::isSystemTrayAvailable())
|
---|
562 | && (strTrayWinID.isEmpty()))
|
---|
563 | {
|
---|
564 | /* Get the path to the executable. */
|
---|
565 | char path[RTPATH_MAX];
|
---|
566 | RTPathAppPrivateArch(path, RTPATH_MAX);
|
---|
567 | size_t sz = strlen(path);
|
---|
568 | path[sz++] = RTPATH_DELIMITER;
|
---|
569 | path[sz] = 0;
|
---|
570 | char *cmd = path + sz;
|
---|
571 | sz = RTPATH_MAX - sz;
|
---|
572 |
|
---|
573 | const char VirtualBox_exe[] = "VirtualBox" HOSTSUFF_EXE;
|
---|
574 | Assert(sz >= sizeof(VirtualBox_exe));
|
---|
575 | strcpy(cmd, VirtualBox_exe);
|
---|
576 | const char * args[] = {path, "-systray", 0 };
|
---|
577 | rc = RTProcCreate(path, args, RTENV_DEFAULT, RTPROC_FLAGS_DETACHED, NULL);
|
---|
578 | if (RT_FAILURE(rc))
|
---|
579 | {
|
---|
580 | LogRel(("Systray: Failed to start systray window! Path=%s, rc=%Rrc\n", path, rc));
|
---|
581 | return false;
|
---|
582 | }
|
---|
583 | }
|
---|
584 |
|
---|
585 | if (mIsTrayMenu)
|
---|
586 | {
|
---|
587 | // Use this selector for displaying the tray icon
|
---|
588 | mVBox.SetExtraData(VBoxDefs::GUI_TrayIconWinID,
|
---|
589 | QString("%1").arg((qulonglong)vboxGlobal().mainWindow()->winId()));
|
---|
590 |
|
---|
591 | /* The first process which can grab this "mutex" will win ->
|
---|
592 | * It will be the tray icon menu then. */
|
---|
593 | if (mVBox.isOk())
|
---|
594 | {
|
---|
595 | emit sigTrayIconShow(true);
|
---|
596 | return true;
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 | return false;
|
---|
601 | }
|
---|
602 |
|
---|
603 | #endif
|
---|
604 |
|
---|
605 | #ifdef Q_WS_X11
|
---|
606 | QList<QRect> XGetDesktopList()
|
---|
607 | {
|
---|
608 | /* Prepare empty resulting list: */
|
---|
609 | QList<QRect> result;
|
---|
610 |
|
---|
611 | /* Get current display: */
|
---|
612 | Display* pDisplay = QX11Info::display();
|
---|
613 |
|
---|
614 | /* If it's a Xinerama desktop: */
|
---|
615 | if (XineramaIsActive(pDisplay))
|
---|
616 | {
|
---|
617 | /* Reading Xinerama data: */
|
---|
618 | int iScreens = 0;
|
---|
619 | XineramaScreenInfo *pScreensData = XineramaQueryScreens(pDisplay, &iScreens);
|
---|
620 |
|
---|
621 | /* Fill resulting list: */
|
---|
622 | for (int i = 0; i < iScreens; ++ i)
|
---|
623 | result << QRect(pScreensData[i].x_org, pScreensData[i].y_org,
|
---|
624 | pScreensData[i].width, pScreensData[i].height);
|
---|
625 |
|
---|
626 | /* Free screens data: */
|
---|
627 | XFree(pScreensData);
|
---|
628 | }
|
---|
629 |
|
---|
630 | /* Return resulting list: */
|
---|
631 | return result;
|
---|
632 | }
|
---|
633 |
|
---|
634 | QList<Window> XGetWindowIDList()
|
---|
635 | {
|
---|
636 | /* Get current display: */
|
---|
637 | Display *pDisplay = QX11Info::display();
|
---|
638 |
|
---|
639 | /* Get virtual desktop window: */
|
---|
640 | Window window = QX11Info::appRootWindow();
|
---|
641 |
|
---|
642 | /* Get 'client list' atom: */
|
---|
643 | Atom propNameAtom = XInternAtom(pDisplay, "_NET_CLIENT_LIST", True /* only if exists */);
|
---|
644 |
|
---|
645 | /* Prepare empty resulting list: */
|
---|
646 | QList<Window> result;
|
---|
647 |
|
---|
648 | /* If atom does not exists return empty list: */
|
---|
649 | if (propNameAtom == None)
|
---|
650 | return result;
|
---|
651 |
|
---|
652 | /* Get atom value: */
|
---|
653 | Atom realAtomType = None;
|
---|
654 | int iRealFormat = 0;
|
---|
655 | unsigned long uItemsCount = 0;
|
---|
656 | unsigned long uBytesAfter = 0;
|
---|
657 | unsigned char *pData = 0;
|
---|
658 | int rc = XGetWindowProperty(pDisplay, window, propNameAtom,
|
---|
659 | 0, 0x7fffffff /*LONG_MAX*/, False /* delete */,
|
---|
660 | XA_WINDOW, &realAtomType, &iRealFormat,
|
---|
661 | &uItemsCount, &uBytesAfter, &pData);
|
---|
662 |
|
---|
663 | /* If get property is failed return empty list: */
|
---|
664 | if (rc != Success)
|
---|
665 | return result;
|
---|
666 |
|
---|
667 | /* Fill resulting list with win ids: */
|
---|
668 | Window *pWindowData = reinterpret_cast<Window*>(pData);
|
---|
669 | for (ulong i = 0; i < uItemsCount; ++ i)
|
---|
670 | result << pWindowData[i];
|
---|
671 |
|
---|
672 | /* Releasing resources: */
|
---|
673 | XFree(pData);
|
---|
674 |
|
---|
675 | /* Return resulting list: */
|
---|
676 | return result;
|
---|
677 | }
|
---|
678 |
|
---|
679 | QList<ulong> XGetStrut(Window window)
|
---|
680 | {
|
---|
681 | /* Get current display: */
|
---|
682 | Display *pDisplay = QX11Info::display();
|
---|
683 |
|
---|
684 | /* Get 'strut' atom: */
|
---|
685 | Atom propNameAtom = XInternAtom(pDisplay, "_NET_WM_STRUT_PARTIAL", True /* only if exists */);
|
---|
686 |
|
---|
687 | /* Prepare empty resulting list: */
|
---|
688 | QList<ulong> result;
|
---|
689 |
|
---|
690 | /* If atom does not exists return empty list: */
|
---|
691 | if (propNameAtom == None)
|
---|
692 | return result;
|
---|
693 |
|
---|
694 | /* Get atom value: */
|
---|
695 | Atom realAtomType = None;
|
---|
696 | int iRealFormat = 0;
|
---|
697 | ulong uItemsCount = 0;
|
---|
698 | ulong uBytesAfter = 0;
|
---|
699 | unsigned char *pData = 0;
|
---|
700 | int rc = XGetWindowProperty(pDisplay, window, propNameAtom,
|
---|
701 | 0, LONG_MAX, False /* delete */,
|
---|
702 | XA_CARDINAL, &realAtomType, &iRealFormat,
|
---|
703 | &uItemsCount, &uBytesAfter, &pData);
|
---|
704 |
|
---|
705 | /* If get property is failed return empty list: */
|
---|
706 | if (rc != Success)
|
---|
707 | return result;
|
---|
708 |
|
---|
709 | /* Fill resulting list with strut shifts: */
|
---|
710 | ulong *pStrutsData = reinterpret_cast<ulong*>(pData);
|
---|
711 | for (ulong i = 0; i < uItemsCount; ++ i)
|
---|
712 | result << pStrutsData[i];
|
---|
713 |
|
---|
714 | /* Releasing resources: */
|
---|
715 | XFree(pData);
|
---|
716 |
|
---|
717 | /* Return resulting list: */
|
---|
718 | return result;
|
---|
719 | }
|
---|
720 | #endif /* ifdef Q_WS_X11 */
|
---|
721 |
|
---|
722 | const QRect VBoxGlobal::availableGeometry(int iScreen) const
|
---|
723 | {
|
---|
724 | /* Prepare empty result: */
|
---|
725 | QRect result;
|
---|
726 |
|
---|
727 | #ifdef Q_WS_X11
|
---|
728 |
|
---|
729 | /* Get current display: */
|
---|
730 | Display* pDisplay = QX11Info::display();
|
---|
731 |
|
---|
732 | /* Get current application desktop: */
|
---|
733 | QDesktopWidget *pDesktopWidget = QApplication::desktop();
|
---|
734 |
|
---|
735 | /* If it's a virtual desktop: */
|
---|
736 | if (pDesktopWidget->isVirtualDesktop())
|
---|
737 | {
|
---|
738 | /* If it's a Xinerama desktop: */
|
---|
739 | if (XineramaIsActive(pDisplay))
|
---|
740 | {
|
---|
741 | /* Get desktops list: */
|
---|
742 | QList<QRect> desktops = XGetDesktopList();
|
---|
743 |
|
---|
744 | /* Combine to get full virtual region: */
|
---|
745 | QRegion virtualRegion;
|
---|
746 | foreach (QRect desktop, desktops)
|
---|
747 | virtualRegion += desktop;
|
---|
748 | virtualRegion = virtualRegion.boundingRect();
|
---|
749 |
|
---|
750 | /* Remember initial virtual desktop: */
|
---|
751 | QRect virtualDesktop = virtualRegion.boundingRect();
|
---|
752 | //AssertMsgFailed(("LOG... Virtual desktop is: %dx%dx%dx%d\n", virtualDesktop.x(), virtualDesktop.y(),
|
---|
753 | // virtualDesktop.width(), virtualDesktop.height()));
|
---|
754 |
|
---|
755 | /* Set available geometry to screen geometry initially: */
|
---|
756 | result = desktops[iScreen];
|
---|
757 |
|
---|
758 | /* Feat available geometry of virtual desktop to respect all the struts: */
|
---|
759 | QList<Window> list = XGetWindowIDList();
|
---|
760 | for (int i = 0; i < list.size(); ++ i)
|
---|
761 | {
|
---|
762 | /* Get window: */
|
---|
763 | Window wid = list[i];
|
---|
764 | QList<ulong> struts = XGetStrut(wid);
|
---|
765 |
|
---|
766 | /* If window has strut: */
|
---|
767 | if (struts.size())
|
---|
768 | {
|
---|
769 | ulong uLeftShift = struts[0];
|
---|
770 | ulong uLeftFromY = struts[4];
|
---|
771 | ulong uLeftToY = struts[5];
|
---|
772 |
|
---|
773 | ulong uRightShift = struts[1];
|
---|
774 | ulong uRightFromY = struts[6];
|
---|
775 | ulong uRightToY = struts[7];
|
---|
776 |
|
---|
777 | ulong uTopShift = struts[2];
|
---|
778 | ulong uTopFromX = struts[8];
|
---|
779 | ulong uTopToX = struts[9];
|
---|
780 |
|
---|
781 | ulong uBottomShift = struts[3];
|
---|
782 | ulong uBottomFromX = struts[10];
|
---|
783 | ulong uBottomToX = struts[11];
|
---|
784 |
|
---|
785 | if (uLeftShift)
|
---|
786 | {
|
---|
787 | QRect sr(QPoint(0, uLeftFromY),
|
---|
788 | QSize(uLeftShift, uLeftToY - uLeftFromY + 1));
|
---|
789 |
|
---|
790 | //AssertMsgFailed(("LOG... Subtract left strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height()));
|
---|
791 | virtualRegion -= sr;
|
---|
792 | }
|
---|
793 |
|
---|
794 | if (uRightShift)
|
---|
795 | {
|
---|
796 | QRect sr(QPoint(virtualDesktop.x() + virtualDesktop.width() - uRightShift, uRightFromY),
|
---|
797 | QSize(virtualDesktop.x() + virtualDesktop.width(), uRightToY - uRightFromY + 1));
|
---|
798 |
|
---|
799 | //AssertMsgFailed(("LOG... Subtract right strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height()));
|
---|
800 | virtualRegion -= sr;
|
---|
801 | }
|
---|
802 |
|
---|
803 | if (uTopShift)
|
---|
804 | {
|
---|
805 | QRect sr(QPoint(uTopFromX, 0),
|
---|
806 | QSize(uTopToX - uTopFromX + 1, uTopShift));
|
---|
807 |
|
---|
808 | //AssertMsgFailed(("LOG... Subtract top strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height()));
|
---|
809 | virtualRegion -= sr;
|
---|
810 | }
|
---|
811 |
|
---|
812 | if (uBottomShift)
|
---|
813 | {
|
---|
814 | QRect sr(QPoint(uBottomFromX, virtualDesktop.y() + virtualDesktop.height() - uBottomShift),
|
---|
815 | QSize(uBottomToX - uBottomFromX + 1, uBottomShift));
|
---|
816 |
|
---|
817 | //AssertMsgFailed(("LOG... Subtract bottom strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height()));
|
---|
818 | virtualRegion -= sr;
|
---|
819 | }
|
---|
820 | }
|
---|
821 | }
|
---|
822 |
|
---|
823 | /* Get final available geometry: */
|
---|
824 | result = (virtualRegion & result).boundingRect();
|
---|
825 | }
|
---|
826 | }
|
---|
827 |
|
---|
828 | /* If result is still NULL: */
|
---|
829 | if (result.isNull())
|
---|
830 | {
|
---|
831 | /* Use QT default functionality: */
|
---|
832 | result = pDesktopWidget->availableGeometry(iScreen);
|
---|
833 | }
|
---|
834 |
|
---|
835 | //AssertMsgFailed(("LOG... Final geometry: %dx%dx%dx%d\n", result.x(), result.y(), result.width(), result.height()));
|
---|
836 |
|
---|
837 | #else /* ifdef Q_WS_X11 */
|
---|
838 |
|
---|
839 | result = QApplication::desktop()->availableGeometry(iScreen);
|
---|
840 |
|
---|
841 | #endif /* ifndef Q_WS_X11 */
|
---|
842 |
|
---|
843 | return result;
|
---|
844 | }
|
---|
845 |
|
---|
846 | /**
|
---|
847 | * Returns the list of few guest OS types, queried from
|
---|
848 | * IVirtualBox corresponding to every family id.
|
---|
849 | */
|
---|
850 | QList <CGuestOSType> VBoxGlobal::vmGuestOSFamilyList() const
|
---|
851 | {
|
---|
852 | QList <CGuestOSType> result;
|
---|
853 | for (int i = 0 ; i < mFamilyIDs.size(); ++ i)
|
---|
854 | result << mTypes [i][0];
|
---|
855 | return result;
|
---|
856 | }
|
---|
857 |
|
---|
858 | /**
|
---|
859 | * Returns the list of all guest OS types, queried from
|
---|
860 | * IVirtualBox corresponding to passed family id.
|
---|
861 | */
|
---|
862 | QList <CGuestOSType> VBoxGlobal::vmGuestOSTypeList (const QString &aFamilyId) const
|
---|
863 | {
|
---|
864 | AssertMsg (mFamilyIDs.contains (aFamilyId), ("Family ID incorrect: '%s'.", aFamilyId.toLatin1().constData()));
|
---|
865 | return mFamilyIDs.contains (aFamilyId) ?
|
---|
866 | mTypes [mFamilyIDs.indexOf (aFamilyId)] : QList <CGuestOSType>();
|
---|
867 | }
|
---|
868 |
|
---|
869 | /**
|
---|
870 | * Returns the icon corresponding to the given guest OS type id.
|
---|
871 | */
|
---|
872 | QPixmap VBoxGlobal::vmGuestOSTypeIcon (const QString &aTypeId) const
|
---|
873 | {
|
---|
874 | static const QPixmap none;
|
---|
875 | QPixmap *p = mOsTypeIcons.value (aTypeId);
|
---|
876 | AssertMsg (p, ("Icon for type '%s' must be defined.", aTypeId.toLatin1().constData()));
|
---|
877 | return p ? *p : none;
|
---|
878 | }
|
---|
879 |
|
---|
880 | /**
|
---|
881 | * Returns the guest OS type object corresponding to the given type id of list
|
---|
882 | * containing OS types related to OS family determined by family id attribute.
|
---|
883 | * If the index is invalid a null object is returned.
|
---|
884 | */
|
---|
885 | CGuestOSType VBoxGlobal::vmGuestOSType (const QString &aTypeId,
|
---|
886 | const QString &aFamilyId /* = QString::null */) const
|
---|
887 | {
|
---|
888 | QList <CGuestOSType> list;
|
---|
889 | if (mFamilyIDs.contains (aFamilyId))
|
---|
890 | {
|
---|
891 | list = mTypes [mFamilyIDs.indexOf (aFamilyId)];
|
---|
892 | }
|
---|
893 | else
|
---|
894 | {
|
---|
895 | for (int i = 0; i < mFamilyIDs.size(); ++ i)
|
---|
896 | list += mTypes [i];
|
---|
897 | }
|
---|
898 | for (int j = 0; j < list.size(); ++ j)
|
---|
899 | if (!list [j].GetId().compare (aTypeId))
|
---|
900 | return list [j];
|
---|
901 | AssertMsgFailed (("Type ID incorrect: '%s'.", aTypeId.toLatin1().constData()));
|
---|
902 | return CGuestOSType();
|
---|
903 | }
|
---|
904 |
|
---|
905 | /**
|
---|
906 | * Returns the description corresponding to the given guest OS type id.
|
---|
907 | */
|
---|
908 | QString VBoxGlobal::vmGuestOSTypeDescription (const QString &aTypeId) const
|
---|
909 | {
|
---|
910 | for (int i = 0; i < mFamilyIDs.size(); ++ i)
|
---|
911 | {
|
---|
912 | QList <CGuestOSType> list (mTypes [i]);
|
---|
913 | for ( int j = 0; j < list.size(); ++ j)
|
---|
914 | if (!list [j].GetId().compare (aTypeId))
|
---|
915 | return list [j].GetDescription();
|
---|
916 | }
|
---|
917 | return QString::null;
|
---|
918 | }
|
---|
919 |
|
---|
920 | /**
|
---|
921 | * Returns a string representation of the given channel number on the given storage bus.
|
---|
922 | * Complementary to #toStorageChannel (KStorageBus, const QString &) const.
|
---|
923 | */
|
---|
924 | QString VBoxGlobal::toString (KStorageBus aBus, LONG aChannel) const
|
---|
925 | {
|
---|
926 | QString channel;
|
---|
927 |
|
---|
928 | switch (aBus)
|
---|
929 | {
|
---|
930 | case KStorageBus_IDE:
|
---|
931 | {
|
---|
932 | if (aChannel == 0 || aChannel == 1)
|
---|
933 | {
|
---|
934 | channel = mStorageBusChannels [aChannel];
|
---|
935 | break;
|
---|
936 | }
|
---|
937 | AssertMsgFailed (("Invalid IDE channel %d\n", aChannel));
|
---|
938 | break;
|
---|
939 | }
|
---|
940 | case KStorageBus_SATA:
|
---|
941 | case KStorageBus_SCSI:
|
---|
942 | {
|
---|
943 | channel = mStorageBusChannels [2].arg (aChannel);
|
---|
944 | break;
|
---|
945 | }
|
---|
946 | case KStorageBus_Floppy:
|
---|
947 | {
|
---|
948 | AssertMsgFailed (("Floppy have no channels, only devices\n"));
|
---|
949 | break;
|
---|
950 | }
|
---|
951 | default:
|
---|
952 | {
|
---|
953 | AssertMsgFailed (("Invalid bus type %d\n", aBus));
|
---|
954 | break;
|
---|
955 | }
|
---|
956 | }
|
---|
957 |
|
---|
958 | Assert (!channel.isNull());
|
---|
959 | return channel;
|
---|
960 | }
|
---|
961 |
|
---|
962 | /**
|
---|
963 | * Returns a channel number on the given storage bus corresponding to the given string representation.
|
---|
964 | * Complementary to #toString (KStorageBus, LONG) const.
|
---|
965 | */
|
---|
966 | LONG VBoxGlobal::toStorageChannel (KStorageBus aBus, const QString &aChannel) const
|
---|
967 | {
|
---|
968 | LONG channel = 0;
|
---|
969 |
|
---|
970 | switch (aBus)
|
---|
971 | {
|
---|
972 | case KStorageBus_IDE:
|
---|
973 | {
|
---|
974 | QLongStringHash::const_iterator it = qFind (mStorageBusChannels.begin(), mStorageBusChannels.end(), aChannel);
|
---|
975 | AssertMsgBreak (it != mStorageBusChannels.end(), ("No value for {%s}\n", aChannel.toLatin1().constData()));
|
---|
976 | channel = it.key();
|
---|
977 | break;
|
---|
978 | }
|
---|
979 | case KStorageBus_SATA:
|
---|
980 | case KStorageBus_SCSI:
|
---|
981 | {
|
---|
982 | QString tpl = mStorageBusChannels [2].arg ("");
|
---|
983 | if (aChannel.startsWith (tpl))
|
---|
984 | {
|
---|
985 | channel = aChannel.right (aChannel.length() - tpl.length()).toLong();
|
---|
986 | break;
|
---|
987 | }
|
---|
988 | AssertMsgFailed (("Invalid channel {%s}\n", aChannel.toLatin1().constData()));
|
---|
989 | break;
|
---|
990 | }
|
---|
991 | case KStorageBus_Floppy:
|
---|
992 | {
|
---|
993 | channel = 0;
|
---|
994 | break;
|
---|
995 | }
|
---|
996 | default:
|
---|
997 | {
|
---|
998 | AssertMsgFailed (("Invalid bus type %d\n", aBus));
|
---|
999 | break;
|
---|
1000 | }
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | return channel;
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | /**
|
---|
1007 | * Returns a string representation of the given device number of the given channel on the given storage bus.
|
---|
1008 | * Complementary to #toStorageDevice (KStorageBus, LONG, const QString &) const.
|
---|
1009 | */
|
---|
1010 | QString VBoxGlobal::toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const
|
---|
1011 | {
|
---|
1012 | NOREF (aChannel);
|
---|
1013 |
|
---|
1014 | QString device;
|
---|
1015 |
|
---|
1016 | switch (aBus)
|
---|
1017 | {
|
---|
1018 | case KStorageBus_IDE:
|
---|
1019 | {
|
---|
1020 | if (aDevice == 0 || aDevice == 1)
|
---|
1021 | {
|
---|
1022 | device = mStorageBusDevices [aDevice];
|
---|
1023 | break;
|
---|
1024 | }
|
---|
1025 | AssertMsgFailed (("Invalid device %d\n", aDevice));
|
---|
1026 | break;
|
---|
1027 | }
|
---|
1028 | case KStorageBus_SATA:
|
---|
1029 | case KStorageBus_SCSI:
|
---|
1030 | {
|
---|
1031 | AssertMsgFailed (("SATA & SCSI have no devices, only channels\n"));
|
---|
1032 | break;
|
---|
1033 | }
|
---|
1034 | case KStorageBus_Floppy:
|
---|
1035 | {
|
---|
1036 | AssertMsgBreak (aChannel == 0, ("Invalid channel %d\n", aChannel));
|
---|
1037 | device = mStorageBusDevices [2].arg (aDevice);
|
---|
1038 | break;
|
---|
1039 | }
|
---|
1040 | default:
|
---|
1041 | {
|
---|
1042 | AssertMsgFailed (("Invalid bus type %d\n", aBus));
|
---|
1043 | break;
|
---|
1044 | }
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | Assert (!device.isNull());
|
---|
1048 | return device;
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | /**
|
---|
1052 | * Returns a device number of the given channel on the given storage bus corresponding to the given string representation.
|
---|
1053 | * Complementary to #toString (KStorageBus, LONG, LONG) const.
|
---|
1054 | */
|
---|
1055 | LONG VBoxGlobal::toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const
|
---|
1056 | {
|
---|
1057 | NOREF (aChannel);
|
---|
1058 |
|
---|
1059 | LONG device = 0;
|
---|
1060 |
|
---|
1061 | switch (aBus)
|
---|
1062 | {
|
---|
1063 | case KStorageBus_IDE:
|
---|
1064 | {
|
---|
1065 | QLongStringHash::const_iterator it = qFind (mStorageBusDevices.begin(), mStorageBusDevices.end(), aDevice);
|
---|
1066 | AssertMsgBreak (it != mStorageBusDevices.end(), ("No value for {%s}", aDevice.toLatin1().constData()));
|
---|
1067 | device = it.key();
|
---|
1068 | break;
|
---|
1069 | }
|
---|
1070 | case KStorageBus_SATA:
|
---|
1071 | case KStorageBus_SCSI:
|
---|
1072 | {
|
---|
1073 | device = 0;
|
---|
1074 | break;
|
---|
1075 | }
|
---|
1076 | case KStorageBus_Floppy:
|
---|
1077 | {
|
---|
1078 | AssertMsgBreak (aChannel == 0, ("Invalid channel %d\n", aChannel));
|
---|
1079 | QString tpl = mStorageBusDevices [2].arg ("");
|
---|
1080 | if (aDevice.startsWith (tpl))
|
---|
1081 | {
|
---|
1082 | device = aDevice.right (aDevice.length() - tpl.length()).toLong();
|
---|
1083 | break;
|
---|
1084 | }
|
---|
1085 | AssertMsgFailed (("Invalid device {%s}\n", aDevice.toLatin1().constData()));
|
---|
1086 | break;
|
---|
1087 | }
|
---|
1088 | default:
|
---|
1089 | {
|
---|
1090 | AssertMsgFailed (("Invalid bus type %d\n", aBus));
|
---|
1091 | break;
|
---|
1092 | }
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | return device;
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | /**
|
---|
1099 | * Returns a full string representation of the given device of the given channel on the given storage bus.
|
---|
1100 | * This method does not uses any separate string tags related to bus, channel, device, it has own
|
---|
1101 | * separately translated string tags allowing to translate a full slot name into human readable format
|
---|
1102 | * to be consistent with i18n.
|
---|
1103 | * Complementary to #toStorageSlot (const QString &) const.
|
---|
1104 | */
|
---|
1105 | QString VBoxGlobal::toString (StorageSlot aSlot) const
|
---|
1106 | {
|
---|
1107 | switch (aSlot.bus)
|
---|
1108 | {
|
---|
1109 | case KStorageBus_IDE:
|
---|
1110 | case KStorageBus_SATA:
|
---|
1111 | case KStorageBus_SCSI:
|
---|
1112 | case KStorageBus_SAS:
|
---|
1113 | case KStorageBus_Floppy:
|
---|
1114 | break;
|
---|
1115 |
|
---|
1116 | default:
|
---|
1117 | {
|
---|
1118 | AssertMsgFailed (("Invalid bus type %d\n", aSlot.bus));
|
---|
1119 | break;
|
---|
1120 | }
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (aSlot.bus);
|
---|
1124 | int maxDevice = virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus (aSlot.bus);
|
---|
1125 | if (aSlot.port < 0 || aSlot.port > maxPort)
|
---|
1126 | AssertMsgFailed (("Invalid port %d\n", aSlot.port));
|
---|
1127 | if (aSlot.device < 0 || aSlot.device > maxDevice)
|
---|
1128 | AssertMsgFailed (("Invalid device %d\n", aSlot.device));
|
---|
1129 |
|
---|
1130 | QString result;
|
---|
1131 | switch (aSlot.bus)
|
---|
1132 | {
|
---|
1133 | case KStorageBus_IDE:
|
---|
1134 | {
|
---|
1135 | result = mSlotTemplates [aSlot.port * maxDevice + aSlot.device];
|
---|
1136 | break;
|
---|
1137 | }
|
---|
1138 | case KStorageBus_SATA:
|
---|
1139 | {
|
---|
1140 | result = mSlotTemplates [4].arg (aSlot.port);
|
---|
1141 | break;
|
---|
1142 | }
|
---|
1143 | case KStorageBus_SCSI:
|
---|
1144 | {
|
---|
1145 | result = mSlotTemplates [5].arg (aSlot.port);
|
---|
1146 | break;
|
---|
1147 | }
|
---|
1148 | case KStorageBus_SAS:
|
---|
1149 | {
|
---|
1150 | result = mSlotTemplates [6].arg (aSlot.port);
|
---|
1151 | break;
|
---|
1152 | }
|
---|
1153 | case KStorageBus_Floppy:
|
---|
1154 | {
|
---|
1155 | result = mSlotTemplates [7].arg (aSlot.device);
|
---|
1156 | break;
|
---|
1157 | }
|
---|
1158 | default:
|
---|
1159 | {
|
---|
1160 | AssertMsgFailed (("Invalid bus type %d\n", aSlot.bus));
|
---|
1161 | break;
|
---|
1162 | }
|
---|
1163 | }
|
---|
1164 | return result;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | /**
|
---|
1168 | * Returns a StorageSlot based on the given device of the given channel on the given storage bus.
|
---|
1169 | * Complementary to #toFullString (StorageSlot) const.
|
---|
1170 | */
|
---|
1171 | StorageSlot VBoxGlobal::toStorageSlot (const QString &aSlot) const
|
---|
1172 | {
|
---|
1173 | int index = -1;
|
---|
1174 | QRegExp regExp;
|
---|
1175 | for (int i = 0; i < mSlotTemplates.size(); ++ i)
|
---|
1176 | {
|
---|
1177 | regExp = QRegExp (i >= 0 && i <= 3 ? mSlotTemplates [i] : mSlotTemplates [i].arg ("(\\d+)"));
|
---|
1178 | if (regExp.indexIn (aSlot) != -1)
|
---|
1179 | {
|
---|
1180 | index = i;
|
---|
1181 | break;
|
---|
1182 | }
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | StorageSlot result;
|
---|
1186 | switch (index)
|
---|
1187 | {
|
---|
1188 | case 0:
|
---|
1189 | case 1:
|
---|
1190 | case 2:
|
---|
1191 | case 3:
|
---|
1192 | {
|
---|
1193 | result.bus = KStorageBus_IDE;
|
---|
1194 | int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus);
|
---|
1195 | result.port = index / maxPort;
|
---|
1196 | result.device = index % maxPort;
|
---|
1197 | break;
|
---|
1198 | }
|
---|
1199 | case 4:
|
---|
1200 | {
|
---|
1201 | result.bus = KStorageBus_SATA;
|
---|
1202 | int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus);
|
---|
1203 | result.port = regExp.cap (1).toInt();
|
---|
1204 | if (result.port < 0 || result.port > maxPort)
|
---|
1205 | AssertMsgFailed (("Invalid port %d\n", result.port));
|
---|
1206 | break;
|
---|
1207 | }
|
---|
1208 | case 5:
|
---|
1209 | {
|
---|
1210 | result.bus = KStorageBus_SCSI;
|
---|
1211 | int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus);
|
---|
1212 | result.port = regExp.cap (1).toInt();
|
---|
1213 | if (result.port < 0 || result.port > maxPort)
|
---|
1214 | AssertMsgFailed (("Invalid port %d\n", result.port));
|
---|
1215 | break;
|
---|
1216 | }
|
---|
1217 | case 6:
|
---|
1218 | {
|
---|
1219 | result.bus = KStorageBus_SAS;
|
---|
1220 | int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus);
|
---|
1221 | result.port = regExp.cap (1).toInt();
|
---|
1222 | if (result.port < 0 || result.port > maxPort)
|
---|
1223 | AssertMsgFailed (("Invalid port %d\n", result.port));
|
---|
1224 | break;
|
---|
1225 | }
|
---|
1226 | case 7:
|
---|
1227 | {
|
---|
1228 | result.bus = KStorageBus_Floppy;
|
---|
1229 | int maxDevice = virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus (result.bus);
|
---|
1230 | result.device = regExp.cap (1).toInt();
|
---|
1231 | if (result.device < 0 || result.device > maxDevice)
|
---|
1232 | AssertMsgFailed (("Invalid device %d\n", result.device));
|
---|
1233 | break;
|
---|
1234 | }
|
---|
1235 | default:
|
---|
1236 | break;
|
---|
1237 | }
|
---|
1238 | return result;
|
---|
1239 | }
|
---|
1240 |
|
---|
1241 | /**
|
---|
1242 | * Returns the list of all device types (VirtualBox::DeviceType COM enum).
|
---|
1243 | */
|
---|
1244 | QStringList VBoxGlobal::deviceTypeStrings() const
|
---|
1245 | {
|
---|
1246 | static QStringList list;
|
---|
1247 | if (list.empty())
|
---|
1248 | for (QULongStringHash::const_iterator it = mDeviceTypes.begin();
|
---|
1249 | it != mDeviceTypes.end(); ++ it)
|
---|
1250 | list += it.value();
|
---|
1251 | return list;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | struct PortConfig
|
---|
1255 | {
|
---|
1256 | const char *name;
|
---|
1257 | const ulong IRQ;
|
---|
1258 | const ulong IOBase;
|
---|
1259 | };
|
---|
1260 |
|
---|
1261 | static const PortConfig kComKnownPorts[] =
|
---|
1262 | {
|
---|
1263 | { "COM1", 4, 0x3F8 },
|
---|
1264 | { "COM2", 3, 0x2F8 },
|
---|
1265 | { "COM3", 4, 0x3E8 },
|
---|
1266 | { "COM4", 3, 0x2E8 },
|
---|
1267 | /* must not contain an element with IRQ=0 and IOBase=0 used to cause
|
---|
1268 | * toCOMPortName() to return the "User-defined" string for these values. */
|
---|
1269 | };
|
---|
1270 |
|
---|
1271 | static const PortConfig kLptKnownPorts[] =
|
---|
1272 | {
|
---|
1273 | { "LPT1", 7, 0x3BC },
|
---|
1274 | { "LPT2", 5, 0x378 },
|
---|
1275 | { "LPT3", 5, 0x278 },
|
---|
1276 | /* must not contain an element with IRQ=0 and IOBase=0 used to cause
|
---|
1277 | * toLPTPortName() to return the "User-defined" string for these values. */
|
---|
1278 | };
|
---|
1279 |
|
---|
1280 | /**
|
---|
1281 | * Returns the list of the standard COM port names (i.e. "COMx").
|
---|
1282 | */
|
---|
1283 | QStringList VBoxGlobal::COMPortNames() const
|
---|
1284 | {
|
---|
1285 | QStringList list;
|
---|
1286 | for (size_t i = 0; i < RT_ELEMENTS (kComKnownPorts); ++ i)
|
---|
1287 | list << kComKnownPorts [i].name;
|
---|
1288 |
|
---|
1289 | return list;
|
---|
1290 | }
|
---|
1291 |
|
---|
1292 | /**
|
---|
1293 | * Returns the list of the standard LPT port names (i.e. "LPTx").
|
---|
1294 | */
|
---|
1295 | QStringList VBoxGlobal::LPTPortNames() const
|
---|
1296 | {
|
---|
1297 | QStringList list;
|
---|
1298 | for (size_t i = 0; i < RT_ELEMENTS (kLptKnownPorts); ++ i)
|
---|
1299 | list << kLptKnownPorts [i].name;
|
---|
1300 |
|
---|
1301 | return list;
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 | /**
|
---|
1305 | * Returns the name of the standard COM port corresponding to the given
|
---|
1306 | * parameters, or "User-defined" (which is also returned when both
|
---|
1307 | * @a aIRQ and @a aIOBase are 0).
|
---|
1308 | */
|
---|
1309 | QString VBoxGlobal::toCOMPortName (ulong aIRQ, ulong aIOBase) const
|
---|
1310 | {
|
---|
1311 | for (size_t i = 0; i < RT_ELEMENTS (kComKnownPorts); ++ i)
|
---|
1312 | if (kComKnownPorts [i].IRQ == aIRQ &&
|
---|
1313 | kComKnownPorts [i].IOBase == aIOBase)
|
---|
1314 | return kComKnownPorts [i].name;
|
---|
1315 |
|
---|
1316 | return mUserDefinedPortName;
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | /**
|
---|
1320 | * Returns the name of the standard LPT port corresponding to the given
|
---|
1321 | * parameters, or "User-defined" (which is also returned when both
|
---|
1322 | * @a aIRQ and @a aIOBase are 0).
|
---|
1323 | */
|
---|
1324 | QString VBoxGlobal::toLPTPortName (ulong aIRQ, ulong aIOBase) const
|
---|
1325 | {
|
---|
1326 | for (size_t i = 0; i < RT_ELEMENTS (kLptKnownPorts); ++ i)
|
---|
1327 | if (kLptKnownPorts [i].IRQ == aIRQ &&
|
---|
1328 | kLptKnownPorts [i].IOBase == aIOBase)
|
---|
1329 | return kLptKnownPorts [i].name;
|
---|
1330 |
|
---|
1331 | return mUserDefinedPortName;
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | /**
|
---|
1335 | * Returns port parameters corresponding to the given standard COM name.
|
---|
1336 | * Returns @c true on success, or @c false if the given port name is not one
|
---|
1337 | * of the standard names (i.e. "COMx").
|
---|
1338 | */
|
---|
1339 | bool VBoxGlobal::toCOMPortNumbers (const QString &aName, ulong &aIRQ,
|
---|
1340 | ulong &aIOBase) const
|
---|
1341 | {
|
---|
1342 | for (size_t i = 0; i < RT_ELEMENTS (kComKnownPorts); ++ i)
|
---|
1343 | if (strcmp (kComKnownPorts [i].name, aName.toUtf8().data()) == 0)
|
---|
1344 | {
|
---|
1345 | aIRQ = kComKnownPorts [i].IRQ;
|
---|
1346 | aIOBase = kComKnownPorts [i].IOBase;
|
---|
1347 | return true;
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 | return false;
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | /**
|
---|
1354 | * Returns port parameters corresponding to the given standard LPT name.
|
---|
1355 | * Returns @c true on success, or @c false if the given port name is not one
|
---|
1356 | * of the standard names (i.e. "LPTx").
|
---|
1357 | */
|
---|
1358 | bool VBoxGlobal::toLPTPortNumbers (const QString &aName, ulong &aIRQ,
|
---|
1359 | ulong &aIOBase) const
|
---|
1360 | {
|
---|
1361 | for (size_t i = 0; i < RT_ELEMENTS (kLptKnownPorts); ++ i)
|
---|
1362 | if (strcmp (kLptKnownPorts [i].name, aName.toUtf8().data()) == 0)
|
---|
1363 | {
|
---|
1364 | aIRQ = kLptKnownPorts [i].IRQ;
|
---|
1365 | aIOBase = kLptKnownPorts [i].IOBase;
|
---|
1366 | return true;
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | return false;
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 | /**
|
---|
1373 | * Searches for the given hard disk in the list of known media descriptors and
|
---|
1374 | * calls VBoxMedium::details() on the found descriptor.
|
---|
1375 | *
|
---|
1376 | * If the requested hard disk is not found (for example, it's a new hard disk
|
---|
1377 | * for a new VM created outside our UI), then media enumeration is requested and
|
---|
1378 | * the search is repeated. We assume that the second attempt always succeeds and
|
---|
1379 | * assert otherwise.
|
---|
1380 | *
|
---|
1381 | * @note Technically, the second attempt may fail if, for example, the new hard
|
---|
1382 | * passed to this method disk gets removed before #startEnumeratingMedia()
|
---|
1383 | * succeeds. This (unexpected object uninitialization) is a generic
|
---|
1384 | * problem though and needs to be addressed using exceptions (see also the
|
---|
1385 | * @todo in VBoxMedium::details()).
|
---|
1386 | */
|
---|
1387 | QString VBoxGlobal::details (const CMedium &aMedium, bool aPredictDiff)
|
---|
1388 | {
|
---|
1389 | CMedium cmedium (aMedium);
|
---|
1390 | VBoxMedium medium;
|
---|
1391 |
|
---|
1392 | if (!findMedium (cmedium, medium))
|
---|
1393 | {
|
---|
1394 | /* Medium may be new and not already in the media list, request refresh */
|
---|
1395 | startEnumeratingMedia();
|
---|
1396 | if (!findMedium (cmedium, medium))
|
---|
1397 | /* Medium might be deleted already, return null string */
|
---|
1398 | return QString();
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | return medium.detailsHTML (true /* aNoDiffs */, aPredictDiff);
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | /**
|
---|
1405 | * Returns the details of the given USB device as a single-line string.
|
---|
1406 | */
|
---|
1407 | QString VBoxGlobal::details (const CUSBDevice &aDevice) const
|
---|
1408 | {
|
---|
1409 | QString sDetails;
|
---|
1410 | if (aDevice.isNull())
|
---|
1411 | sDetails = tr("Unknown device", "USB device details");
|
---|
1412 | else
|
---|
1413 | {
|
---|
1414 | QString m = aDevice.GetManufacturer().trimmed();
|
---|
1415 | QString p = aDevice.GetProduct().trimmed();
|
---|
1416 |
|
---|
1417 | if (m.isEmpty() && p.isEmpty())
|
---|
1418 | {
|
---|
1419 | sDetails =
|
---|
1420 | tr ("Unknown device %1:%2", "USB device details")
|
---|
1421 | .arg (QString().sprintf ("%04hX", aDevice.GetVendorId()))
|
---|
1422 | .arg (QString().sprintf ("%04hX", aDevice.GetProductId()));
|
---|
1423 | }
|
---|
1424 | else
|
---|
1425 | {
|
---|
1426 | if (p.toUpper().startsWith (m.toUpper()))
|
---|
1427 | sDetails = p;
|
---|
1428 | else
|
---|
1429 | sDetails = m + " " + p;
|
---|
1430 | }
|
---|
1431 | ushort r = aDevice.GetRevision();
|
---|
1432 | if (r != 0)
|
---|
1433 | sDetails += QString().sprintf (" [%04hX]", r);
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | return sDetails.trimmed();
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | /**
|
---|
1440 | * Returns the multi-line description of the given USB device.
|
---|
1441 | */
|
---|
1442 | QString VBoxGlobal::toolTip (const CUSBDevice &aDevice) const
|
---|
1443 | {
|
---|
1444 | QString tip =
|
---|
1445 | tr ("<nobr>Vendor ID: %1</nobr><br>"
|
---|
1446 | "<nobr>Product ID: %2</nobr><br>"
|
---|
1447 | "<nobr>Revision: %3</nobr>", "USB device tooltip")
|
---|
1448 | .arg (QString().sprintf ("%04hX", aDevice.GetVendorId()))
|
---|
1449 | .arg (QString().sprintf ("%04hX", aDevice.GetProductId()))
|
---|
1450 | .arg (QString().sprintf ("%04hX", aDevice.GetRevision()));
|
---|
1451 |
|
---|
1452 | QString ser = aDevice.GetSerialNumber();
|
---|
1453 | if (!ser.isEmpty())
|
---|
1454 | tip += QString (tr ("<br><nobr>Serial No. %1</nobr>", "USB device tooltip"))
|
---|
1455 | .arg (ser);
|
---|
1456 |
|
---|
1457 | /* add the state field if it's a host USB device */
|
---|
1458 | CHostUSBDevice hostDev (aDevice);
|
---|
1459 | if (!hostDev.isNull())
|
---|
1460 | {
|
---|
1461 | tip += QString (tr ("<br><nobr>State: %1</nobr>", "USB device tooltip"))
|
---|
1462 | .arg (vboxGlobal().toString (hostDev.GetState()));
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | return tip;
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | /**
|
---|
1469 | * Returns the multi-line description of the given USB filter
|
---|
1470 | */
|
---|
1471 | QString VBoxGlobal::toolTip (const CUSBDeviceFilter &aFilter) const
|
---|
1472 | {
|
---|
1473 | QString tip;
|
---|
1474 |
|
---|
1475 | QString vendorId = aFilter.GetVendorId();
|
---|
1476 | if (!vendorId.isEmpty())
|
---|
1477 | tip += tr ("<nobr>Vendor ID: %1</nobr>", "USB filter tooltip")
|
---|
1478 | .arg (vendorId);
|
---|
1479 |
|
---|
1480 | QString productId = aFilter.GetProductId();
|
---|
1481 | if (!productId.isEmpty())
|
---|
1482 | tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Product ID: %2</nobr>", "USB filter tooltip")
|
---|
1483 | .arg (productId);
|
---|
1484 |
|
---|
1485 | QString revision = aFilter.GetRevision();
|
---|
1486 | if (!revision.isEmpty())
|
---|
1487 | tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Revision: %3</nobr>", "USB filter tooltip")
|
---|
1488 | .arg (revision);
|
---|
1489 |
|
---|
1490 | QString product = aFilter.GetProduct();
|
---|
1491 | if (!product.isEmpty())
|
---|
1492 | tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Product: %4</nobr>", "USB filter tooltip")
|
---|
1493 | .arg (product);
|
---|
1494 |
|
---|
1495 | QString manufacturer = aFilter.GetManufacturer();
|
---|
1496 | if (!manufacturer.isEmpty())
|
---|
1497 | tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip")
|
---|
1498 | .arg (manufacturer);
|
---|
1499 |
|
---|
1500 | QString serial = aFilter.GetSerialNumber();
|
---|
1501 | if (!serial.isEmpty())
|
---|
1502 | tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Serial No.: %1</nobr>", "USB filter tooltip")
|
---|
1503 | .arg (serial);
|
---|
1504 |
|
---|
1505 | QString port = aFilter.GetPort();
|
---|
1506 | if (!port.isEmpty())
|
---|
1507 | tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Port: %1</nobr>", "USB filter tooltip")
|
---|
1508 | .arg (port);
|
---|
1509 |
|
---|
1510 | /* add the state field if it's a host USB device */
|
---|
1511 | CHostUSBDevice hostDev (aFilter);
|
---|
1512 | if (!hostDev.isNull())
|
---|
1513 | {
|
---|
1514 | tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>State: %1</nobr>", "USB filter tooltip")
|
---|
1515 | .arg (vboxGlobal().toString (hostDev.GetState()));
|
---|
1516 | }
|
---|
1517 |
|
---|
1518 | return tip;
|
---|
1519 | }
|
---|
1520 |
|
---|
1521 | /**
|
---|
1522 | * Returns a details report on a given VM represented as a HTML table.
|
---|
1523 | *
|
---|
1524 | * @param aMachine Machine to create a report for.
|
---|
1525 | * @param aWithLinks @c true if section titles should be hypertext links.
|
---|
1526 | */
|
---|
1527 | QString VBoxGlobal::detailsReport (const CMachine &aMachine, bool aWithLinks)
|
---|
1528 | {
|
---|
1529 | /* Details templates */
|
---|
1530 | static const char *sTableTpl =
|
---|
1531 | "<table border=0 cellspacing=1 cellpadding=0>%1</table>";
|
---|
1532 | static const char *sSectionHrefTpl =
|
---|
1533 | "<tr><td width=22 rowspan=%1 align=left><img src='%2'></td>"
|
---|
1534 | "<td colspan=3><b><a href='%3'><nobr>%4</nobr></a></b></td></tr>"
|
---|
1535 | "%5"
|
---|
1536 | "<tr><td colspan=3><font size=1> </font></td></tr>";
|
---|
1537 | static const char *sSectionBoldTpl =
|
---|
1538 | "<tr><td width=22 rowspan=%1 align=left><img src='%2'></td>"
|
---|
1539 | "<td colspan=3><!-- %3 --><b><nobr>%4</nobr></b></td></tr>"
|
---|
1540 | "%5"
|
---|
1541 | "<tr><td colspan=3><font size=1> </font></td></tr>";
|
---|
1542 | static const char *sSectionItemTpl1 =
|
---|
1543 | "<tr><td width=40%><nobr><i>%1</i></nobr></td><td/><td/></tr>";
|
---|
1544 | static const char *sSectionItemTpl2 =
|
---|
1545 | "<tr><td width=40%><nobr>%1:</nobr></td><td/><td>%2</td></tr>";
|
---|
1546 | static const char *sSectionItemTpl3 =
|
---|
1547 | "<tr><td width=40%><nobr>%1</nobr></td><td/><td/></tr>";
|
---|
1548 |
|
---|
1549 | const QString §ionTpl = aWithLinks ? sSectionHrefTpl : sSectionBoldTpl;
|
---|
1550 |
|
---|
1551 | /* Compose details report */
|
---|
1552 | QString report;
|
---|
1553 |
|
---|
1554 | /* General */
|
---|
1555 | {
|
---|
1556 | QString item = QString (sSectionItemTpl2).arg (tr ("Name", "details report"),
|
---|
1557 | aMachine.GetName())
|
---|
1558 | + QString (sSectionItemTpl2).arg (tr ("OS Type", "details report"),
|
---|
1559 | vmGuestOSTypeDescription (aMachine.GetOSTypeId()));
|
---|
1560 |
|
---|
1561 | report += sectionTpl
|
---|
1562 | .arg (2 + 2) /* rows */
|
---|
1563 | .arg (":/machine_16px.png", /* icon */
|
---|
1564 | "#general", /* link */
|
---|
1565 | tr ("General", "details report"), /* title */
|
---|
1566 | item); /* items */
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | /* System */
|
---|
1570 | {
|
---|
1571 | /* BIOS Settings holder */
|
---|
1572 | CBIOSSettings biosSettings = aMachine.GetBIOSSettings();
|
---|
1573 |
|
---|
1574 | /* System details row count: */
|
---|
1575 | int iRowCount = 2; /* Memory & CPU details rows initially. */
|
---|
1576 |
|
---|
1577 | /* Boot order */
|
---|
1578 | QString bootOrder;
|
---|
1579 | for (ulong i = 1; i <= mVBox.GetSystemProperties().GetMaxBootPosition(); ++ i)
|
---|
1580 | {
|
---|
1581 | KDeviceType device = aMachine.GetBootOrder (i);
|
---|
1582 | if (device == KDeviceType_Null)
|
---|
1583 | continue;
|
---|
1584 | if (!bootOrder.isEmpty())
|
---|
1585 | bootOrder += ", ";
|
---|
1586 | bootOrder += toString (device);
|
---|
1587 | }
|
---|
1588 | if (bootOrder.isEmpty())
|
---|
1589 | bootOrder = toString (KDeviceType_Null);
|
---|
1590 |
|
---|
1591 | iRowCount += 1; /* Boot-order row. */
|
---|
1592 |
|
---|
1593 | #ifdef VBOX_WITH_FULL_DETAILS_REPORT
|
---|
1594 | /* ACPI */
|
---|
1595 | QString acpi = biosSettings.GetACPIEnabled()
|
---|
1596 | ? tr ("Enabled", "details report (ACPI)")
|
---|
1597 | : tr ("Disabled", "details report (ACPI)");
|
---|
1598 |
|
---|
1599 | /* IO APIC */
|
---|
1600 | QString ioapic = biosSettings.GetIOAPICEnabled()
|
---|
1601 | ? tr ("Enabled", "details report (IO APIC)")
|
---|
1602 | : tr ("Disabled", "details report (IO APIC)");
|
---|
1603 |
|
---|
1604 | /* PAE/NX */
|
---|
1605 | QString pae = aMachine.GetCpuProperty(KCpuPropertyType_PAE)
|
---|
1606 | ? tr ("Enabled", "details report (PAE/NX)")
|
---|
1607 | : tr ("Disabled", "details report (PAE/NX)");
|
---|
1608 |
|
---|
1609 | iRowCount += 3; /* Full report rows. */
|
---|
1610 | #endif /* VBOX_WITH_FULL_DETAILS_REPORT */
|
---|
1611 |
|
---|
1612 | /* VT-x/AMD-V */
|
---|
1613 | QString virt = aMachine.GetHWVirtExProperty(KHWVirtExPropertyType_Enabled)
|
---|
1614 | ? tr ("Enabled", "details report (VT-x/AMD-V)")
|
---|
1615 | : tr ("Disabled", "details report (VT-x/AMD-V)");
|
---|
1616 |
|
---|
1617 | /* Nested Paging */
|
---|
1618 | QString nested = aMachine.GetHWVirtExProperty(KHWVirtExPropertyType_NestedPaging)
|
---|
1619 | ? tr ("Enabled", "details report (Nested Paging)")
|
---|
1620 | : tr ("Disabled", "details report (Nested Paging)");
|
---|
1621 |
|
---|
1622 | /* VT-x/AMD-V availability: */
|
---|
1623 | bool fVTxAMDVSupported = virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_HWVirtEx);
|
---|
1624 |
|
---|
1625 | if (fVTxAMDVSupported)
|
---|
1626 | iRowCount += 2; /* VT-x/AMD-V items. */
|
---|
1627 |
|
---|
1628 | QString item = QString (sSectionItemTpl2).arg (tr ("Base Memory", "details report"),
|
---|
1629 | tr ("<nobr>%1 MB</nobr>", "details report"))
|
---|
1630 | .arg (aMachine.GetMemorySize())
|
---|
1631 | + QString (sSectionItemTpl2).arg (tr ("Processor(s)", "details report"),
|
---|
1632 | tr ("<nobr>%1</nobr>", "details report"))
|
---|
1633 | .arg (aMachine.GetCPUCount())
|
---|
1634 | + QString (sSectionItemTpl2).arg (tr ("Boot Order", "details report"), bootOrder)
|
---|
1635 | #ifdef VBOX_WITH_FULL_DETAILS_REPORT
|
---|
1636 | + QString (sSectionItemTpl2).arg (tr ("ACPI", "details report"), acpi)
|
---|
1637 | + QString (sSectionItemTpl2).arg (tr ("IO APIC", "details report"), ioapic)
|
---|
1638 | + QString (sSectionItemTpl2).arg (tr ("PAE/NX", "details report"), pae)
|
---|
1639 | #endif /* VBOX_WITH_FULL_DETAILS_REPORT */
|
---|
1640 | ;
|
---|
1641 |
|
---|
1642 | if (fVTxAMDVSupported)
|
---|
1643 | item += QString (sSectionItemTpl2).arg (tr ("VT-x/AMD-V", "details report"), virt)
|
---|
1644 | + QString (sSectionItemTpl2).arg (tr ("Nested Paging", "details report"), nested);
|
---|
1645 |
|
---|
1646 | report += sectionTpl
|
---|
1647 | .arg (2 + iRowCount) /* rows */
|
---|
1648 | .arg (":/chipset_16px.png", /* icon */
|
---|
1649 | "#system", /* link */
|
---|
1650 | tr ("System", "details report"), /* title */
|
---|
1651 | item); /* items */
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | /* Display */
|
---|
1655 | {
|
---|
1656 | /* Rows including section header and footer */
|
---|
1657 | int rows = 2;
|
---|
1658 |
|
---|
1659 | /* Video tab */
|
---|
1660 | QString item = QString(sSectionItemTpl2)
|
---|
1661 | .arg(tr ("Video Memory", "details report"),
|
---|
1662 | tr ("<nobr>%1 MB</nobr>", "details report"))
|
---|
1663 | .arg(aMachine.GetVRAMSize());
|
---|
1664 | ++rows;
|
---|
1665 |
|
---|
1666 | int cGuestScreens = aMachine.GetMonitorCount();
|
---|
1667 | if (cGuestScreens > 1)
|
---|
1668 | {
|
---|
1669 | item += QString(sSectionItemTpl2)
|
---|
1670 | .arg(tr("Screens", "details report"))
|
---|
1671 | .arg(cGuestScreens);
|
---|
1672 | ++rows;
|
---|
1673 | }
|
---|
1674 |
|
---|
1675 | QString acc3d = aMachine.GetAccelerate3DEnabled()
|
---|
1676 | ? tr ("Enabled", "details report (3D Acceleration)")
|
---|
1677 | : tr ("Disabled", "details report (3D Acceleration)");
|
---|
1678 |
|
---|
1679 | item += QString(sSectionItemTpl2)
|
---|
1680 | .arg(tr("3D Acceleration", "details report"), acc3d);
|
---|
1681 | ++rows;
|
---|
1682 |
|
---|
1683 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1684 | QString acc2dVideo = aMachine.GetAccelerate2DVideoEnabled()
|
---|
1685 | ? tr ("Enabled", "details report (2D Video Acceleration)")
|
---|
1686 | : tr ("Disabled", "details report (2D Video Acceleration)");
|
---|
1687 |
|
---|
1688 | item += QString (sSectionItemTpl2)
|
---|
1689 | .arg (tr ("2D Video Acceleration", "details report"), acc2dVideo);
|
---|
1690 | ++ rows;
|
---|
1691 | #endif
|
---|
1692 |
|
---|
1693 | /* VRDP tab */
|
---|
1694 | CVRDEServer srv = aMachine.GetVRDEServer();
|
---|
1695 | if (!srv.isNull())
|
---|
1696 | {
|
---|
1697 | if (srv.GetEnabled())
|
---|
1698 | item += QString (sSectionItemTpl2)
|
---|
1699 | .arg (tr ("Remote Desktop Server Port", "details report (VRDE Server)"))
|
---|
1700 | .arg (srv.GetVRDEProperty("TCP/Ports"));
|
---|
1701 | else
|
---|
1702 | item += QString (sSectionItemTpl2)
|
---|
1703 | .arg (tr ("Remote Desktop Server", "details report (VRDE Server)"))
|
---|
1704 | .arg (tr ("Disabled", "details report (VRDE Server)"));
|
---|
1705 | ++ rows;
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 | report += sectionTpl
|
---|
1709 | .arg (rows) /* rows */
|
---|
1710 | .arg (":/vrdp_16px.png", /* icon */
|
---|
1711 | "#display", /* link */
|
---|
1712 | tr ("Display", "details report"), /* title */
|
---|
1713 | item); /* items */
|
---|
1714 | }
|
---|
1715 |
|
---|
1716 | /* Storage */
|
---|
1717 | {
|
---|
1718 | /* Rows including section header and footer */
|
---|
1719 | int rows = 2;
|
---|
1720 |
|
---|
1721 | QString item;
|
---|
1722 |
|
---|
1723 | /* Iterate over the all machine controllers: */
|
---|
1724 | CStorageControllerVector controllers = aMachine.GetStorageControllers();
|
---|
1725 | for (int i = 0; i < controllers.size(); ++i)
|
---|
1726 | {
|
---|
1727 | /* Get current controller: */
|
---|
1728 | const CStorageController &controller = controllers[i];
|
---|
1729 | /* Add controller information: */
|
---|
1730 | item += QString(sSectionItemTpl3).arg(controller.GetName());
|
---|
1731 | ++ rows;
|
---|
1732 |
|
---|
1733 | /* Populate sorted map with attachments information: */
|
---|
1734 | QMap<StorageSlot,QString> attachmentsMap;
|
---|
1735 | CMediumAttachmentVector attachments = aMachine.GetMediumAttachmentsOfController(controller.GetName());
|
---|
1736 | for (int j = 0; j < attachments.size(); ++j)
|
---|
1737 | {
|
---|
1738 | /* Get current attachment: */
|
---|
1739 | const CMediumAttachment &attachment = attachments[j];
|
---|
1740 | /* Prepare current storage slot: */
|
---|
1741 | StorageSlot attachmentSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice());
|
---|
1742 | /* Append 'device slot name' with 'device type name' for CD/DVD devices only: */
|
---|
1743 | QString strDeviceType = attachment.GetType() == KDeviceType_DVD ? tr("(CD/DVD)") : QString();
|
---|
1744 | if (!strDeviceType.isNull())
|
---|
1745 | strDeviceType.prepend(' ');
|
---|
1746 | /* Prepare current medium object: */
|
---|
1747 | const CMedium &medium = attachment.GetMedium();
|
---|
1748 | /* Prepare information about current medium & attachment: */
|
---|
1749 | QString strAttachmentInfo = !attachment.isOk() ? QString() :
|
---|
1750 | QString(sSectionItemTpl2)
|
---|
1751 | .arg(QString(" ") +
|
---|
1752 | toString(StorageSlot(controller.GetBus(),
|
---|
1753 | attachment.GetPort(),
|
---|
1754 | attachment.GetDevice())) + strDeviceType)
|
---|
1755 | .arg(details(medium, false));
|
---|
1756 | /* Insert that attachment into map: */
|
---|
1757 | if (!strAttachmentInfo.isNull())
|
---|
1758 | attachmentsMap.insert(attachmentSlot, strAttachmentInfo);
|
---|
1759 | }
|
---|
1760 |
|
---|
1761 | /* Iterate over the sorted map with attachments information: */
|
---|
1762 | QMapIterator<StorageSlot,QString> it(attachmentsMap);
|
---|
1763 | while (it.hasNext())
|
---|
1764 | {
|
---|
1765 | /* Add controller information: */
|
---|
1766 | it.next();
|
---|
1767 | item += it.value();
|
---|
1768 | ++rows;
|
---|
1769 | }
|
---|
1770 | }
|
---|
1771 |
|
---|
1772 | if (item.isNull())
|
---|
1773 | {
|
---|
1774 | item = QString (sSectionItemTpl1)
|
---|
1775 | .arg (tr ("Not Attached", "details report (Storage)"));
|
---|
1776 | ++ rows;
|
---|
1777 | }
|
---|
1778 |
|
---|
1779 | report += sectionTpl
|
---|
1780 | .arg (rows) /* rows */
|
---|
1781 | .arg (":/attachment_16px.png", /* icon */
|
---|
1782 | "#storage", /* link */
|
---|
1783 | tr ("Storage", "details report"), /* title */
|
---|
1784 | item); /* items */
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | /* Audio */
|
---|
1788 | {
|
---|
1789 | QString item;
|
---|
1790 |
|
---|
1791 | CAudioAdapter audio = aMachine.GetAudioAdapter();
|
---|
1792 | int rows = audio.GetEnabled() ? 3 : 2;
|
---|
1793 | if (audio.GetEnabled())
|
---|
1794 | item = QString (sSectionItemTpl2)
|
---|
1795 | .arg (tr ("Host Driver", "details report (audio)"),
|
---|
1796 | toString (audio.GetAudioDriver())) +
|
---|
1797 | QString (sSectionItemTpl2)
|
---|
1798 | .arg (tr ("Controller", "details report (audio)"),
|
---|
1799 | toString (audio.GetAudioController()));
|
---|
1800 | else
|
---|
1801 | item = QString (sSectionItemTpl1)
|
---|
1802 | .arg (tr ("Disabled", "details report (audio)"));
|
---|
1803 |
|
---|
1804 | report += sectionTpl
|
---|
1805 | .arg (rows + 1) /* rows */
|
---|
1806 | .arg (":/sound_16px.png", /* icon */
|
---|
1807 | "#audio", /* link */
|
---|
1808 | tr ("Audio", "details report"), /* title */
|
---|
1809 | item); /* items */
|
---|
1810 | }
|
---|
1811 |
|
---|
1812 | /* Network */
|
---|
1813 | {
|
---|
1814 | QString item;
|
---|
1815 |
|
---|
1816 | ulong count = mVBox.GetSystemProperties().GetNetworkAdapterCount();
|
---|
1817 | int rows = 2; /* including section header and footer */
|
---|
1818 | for (ulong slot = 0; slot < count; slot ++)
|
---|
1819 | {
|
---|
1820 | CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot);
|
---|
1821 | if (adapter.GetEnabled())
|
---|
1822 | {
|
---|
1823 | KNetworkAttachmentType type = adapter.GetAttachmentType();
|
---|
1824 | QString attType = toString (adapter.GetAdapterType())
|
---|
1825 | .replace (QRegExp ("\\s\\(.+\\)"), " (%1)");
|
---|
1826 | /* don't use the adapter type string for types that have
|
---|
1827 | * an additional symbolic network/interface name field, use
|
---|
1828 | * this name instead */
|
---|
1829 | if (type == KNetworkAttachmentType_Bridged)
|
---|
1830 | attType = attType.arg (tr ("Bridged adapter, %1",
|
---|
1831 | "details report (network)").arg (adapter.GetHostInterface()));
|
---|
1832 | else if (type == KNetworkAttachmentType_Internal)
|
---|
1833 | attType = attType.arg (tr ("Internal network, '%1'",
|
---|
1834 | "details report (network)").arg (adapter.GetInternalNetwork()));
|
---|
1835 | else if (type == KNetworkAttachmentType_HostOnly)
|
---|
1836 | attType = attType.arg (tr ("Host-only adapter, '%1'",
|
---|
1837 | "details report (network)").arg (adapter.GetHostInterface()));
|
---|
1838 | #ifdef VBOX_WITH_VDE
|
---|
1839 | else if (type == KNetworkAttachmentType_VDE)
|
---|
1840 | attType = attType.arg (tr ("VDE network, '%1'",
|
---|
1841 | "details report (network)").arg (adapter.GetVDENetwork()));
|
---|
1842 | #endif
|
---|
1843 | else
|
---|
1844 | attType = attType.arg (vboxGlobal().toString (type));
|
---|
1845 |
|
---|
1846 | item += QString (sSectionItemTpl2)
|
---|
1847 | .arg (tr ("Adapter %1", "details report (network)")
|
---|
1848 | .arg (adapter.GetSlot() + 1))
|
---|
1849 | .arg (attType);
|
---|
1850 | ++ rows;
|
---|
1851 | }
|
---|
1852 | }
|
---|
1853 | if (item.isNull())
|
---|
1854 | {
|
---|
1855 | item = QString (sSectionItemTpl1)
|
---|
1856 | .arg (tr ("Disabled", "details report (network)"));
|
---|
1857 | ++ rows;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | report += sectionTpl
|
---|
1861 | .arg (rows) /* rows */
|
---|
1862 | .arg (":/nw_16px.png", /* icon */
|
---|
1863 | "#network", /* link */
|
---|
1864 | tr ("Network", "details report"), /* title */
|
---|
1865 | item); /* items */
|
---|
1866 | }
|
---|
1867 |
|
---|
1868 | /* Serial Ports */
|
---|
1869 | {
|
---|
1870 | QString item;
|
---|
1871 |
|
---|
1872 | ulong count = mVBox.GetSystemProperties().GetSerialPortCount();
|
---|
1873 | int rows = 2; /* including section header and footer */
|
---|
1874 | for (ulong slot = 0; slot < count; slot ++)
|
---|
1875 | {
|
---|
1876 | CSerialPort port = aMachine.GetSerialPort (slot);
|
---|
1877 | if (port.GetEnabled())
|
---|
1878 | {
|
---|
1879 | KPortMode mode = port.GetHostMode();
|
---|
1880 | QString data =
|
---|
1881 | toCOMPortName (port.GetIRQ(), port.GetIOBase()) + ", ";
|
---|
1882 | if (mode == KPortMode_HostPipe ||
|
---|
1883 | mode == KPortMode_HostDevice ||
|
---|
1884 | mode == KPortMode_RawFile)
|
---|
1885 | data += QString ("%1 (<nobr>%2</nobr>)")
|
---|
1886 | .arg (vboxGlobal().toString (mode))
|
---|
1887 | .arg (QDir::toNativeSeparators (port.GetPath()));
|
---|
1888 | else
|
---|
1889 | data += toString (mode);
|
---|
1890 |
|
---|
1891 | item += QString (sSectionItemTpl2)
|
---|
1892 | .arg (tr ("Port %1", "details report (serial ports)")
|
---|
1893 | .arg (port.GetSlot() + 1))
|
---|
1894 | .arg (data);
|
---|
1895 | ++ rows;
|
---|
1896 | }
|
---|
1897 | }
|
---|
1898 | if (item.isNull())
|
---|
1899 | {
|
---|
1900 | item = QString (sSectionItemTpl1)
|
---|
1901 | .arg (tr ("Disabled", "details report (serial ports)"));
|
---|
1902 | ++ rows;
|
---|
1903 | }
|
---|
1904 |
|
---|
1905 | report += sectionTpl
|
---|
1906 | .arg (rows) /* rows */
|
---|
1907 | .arg (":/serial_port_16px.png", /* icon */
|
---|
1908 | "#serialPorts", /* link */
|
---|
1909 | tr ("Serial Ports", "details report"), /* title */
|
---|
1910 | item); /* items */
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | /* Parallel Ports */
|
---|
1914 | {
|
---|
1915 | QString item;
|
---|
1916 |
|
---|
1917 | ulong count = mVBox.GetSystemProperties().GetParallelPortCount();
|
---|
1918 | int rows = 2; /* including section header and footer */
|
---|
1919 | for (ulong slot = 0; slot < count; slot ++)
|
---|
1920 | {
|
---|
1921 | CParallelPort port = aMachine.GetParallelPort (slot);
|
---|
1922 | if (port.GetEnabled())
|
---|
1923 | {
|
---|
1924 | QString data =
|
---|
1925 | toLPTPortName (port.GetIRQ(), port.GetIOBase()) +
|
---|
1926 | QString (" (<nobr>%1</nobr>)")
|
---|
1927 | .arg (QDir::toNativeSeparators (port.GetPath()));
|
---|
1928 |
|
---|
1929 | item += QString (sSectionItemTpl2)
|
---|
1930 | .arg (tr ("Port %1", "details report (parallel ports)")
|
---|
1931 | .arg (port.GetSlot() + 1))
|
---|
1932 | .arg (data);
|
---|
1933 | ++ rows;
|
---|
1934 | }
|
---|
1935 | }
|
---|
1936 | if (item.isNull())
|
---|
1937 | {
|
---|
1938 | item = QString (sSectionItemTpl1)
|
---|
1939 | .arg (tr ("Disabled", "details report (parallel ports)"));
|
---|
1940 | ++ rows;
|
---|
1941 | }
|
---|
1942 |
|
---|
1943 | /* Temporary disabled */
|
---|
1944 | QString dummy = sectionTpl /* report += sectionTpl */
|
---|
1945 | .arg (rows) /* rows */
|
---|
1946 | .arg (":/parallel_port_16px.png", /* icon */
|
---|
1947 | "#parallelPorts", /* link */
|
---|
1948 | tr ("Parallel Ports", "details report"), /* title */
|
---|
1949 | item); /* items */
|
---|
1950 | }
|
---|
1951 |
|
---|
1952 | /* USB */
|
---|
1953 | {
|
---|
1954 | QString item;
|
---|
1955 |
|
---|
1956 | CUSBController ctl = aMachine.GetUSBController();
|
---|
1957 | if ( !ctl.isNull()
|
---|
1958 | && ctl.GetProxyAvailable())
|
---|
1959 | {
|
---|
1960 | /* the USB controller may be unavailable (i.e. in VirtualBox OSE) */
|
---|
1961 |
|
---|
1962 | if (ctl.GetEnabled())
|
---|
1963 | {
|
---|
1964 | CUSBDeviceFilterVector coll = ctl.GetDeviceFilters();
|
---|
1965 | uint active = 0;
|
---|
1966 | for (int i = 0; i < coll.size(); ++i)
|
---|
1967 | if (coll[i].GetActive())
|
---|
1968 | active ++;
|
---|
1969 |
|
---|
1970 | item = QString (sSectionItemTpl2)
|
---|
1971 | .arg (tr ("Device Filters", "details report (USB)"),
|
---|
1972 | tr ("%1 (%2 active)", "details report (USB)")
|
---|
1973 | .arg (coll.size()).arg (active));
|
---|
1974 | }
|
---|
1975 | else
|
---|
1976 | item = QString (sSectionItemTpl1)
|
---|
1977 | .arg (tr ("Disabled", "details report (USB)"));
|
---|
1978 |
|
---|
1979 | report += sectionTpl
|
---|
1980 | .arg (2 + 1) /* rows */
|
---|
1981 | .arg (":/usb_16px.png", /* icon */
|
---|
1982 | "#usb", /* link */
|
---|
1983 | tr ("USB", "details report"), /* title */
|
---|
1984 | item); /* items */
|
---|
1985 | }
|
---|
1986 | }
|
---|
1987 |
|
---|
1988 | /* Shared Folders */
|
---|
1989 | {
|
---|
1990 | QString item;
|
---|
1991 |
|
---|
1992 | ulong count = aMachine.GetSharedFolders().size();
|
---|
1993 | if (count > 0)
|
---|
1994 | {
|
---|
1995 | item = QString (sSectionItemTpl2)
|
---|
1996 | .arg (tr ("Shared Folders", "details report (shared folders)"))
|
---|
1997 | .arg (count);
|
---|
1998 | }
|
---|
1999 | else
|
---|
2000 | item = QString (sSectionItemTpl1)
|
---|
2001 | .arg (tr ("None", "details report (shared folders)"));
|
---|
2002 |
|
---|
2003 | report += sectionTpl
|
---|
2004 | .arg (2 + 1) /* rows */
|
---|
2005 | .arg (":/shared_folder_16px.png", /* icon */
|
---|
2006 | "#sfolders", /* link */
|
---|
2007 | tr ("Shared Folders", "details report"), /* title */
|
---|
2008 | item); /* items */
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | return QString (sTableTpl). arg (report);
|
---|
2012 | }
|
---|
2013 |
|
---|
2014 | QString VBoxGlobal::platformInfo()
|
---|
2015 | {
|
---|
2016 | QString platform;
|
---|
2017 |
|
---|
2018 | #if defined (Q_OS_WIN)
|
---|
2019 | platform = "win";
|
---|
2020 | #elif defined (Q_OS_LINUX)
|
---|
2021 | platform = "linux";
|
---|
2022 | #elif defined (Q_OS_MACX)
|
---|
2023 | platform = "macosx";
|
---|
2024 | #elif defined (Q_OS_OS2)
|
---|
2025 | platform = "os2";
|
---|
2026 | #elif defined (Q_OS_FREEBSD)
|
---|
2027 | platform = "freebsd";
|
---|
2028 | #elif defined (Q_OS_SOLARIS)
|
---|
2029 | platform = "solaris";
|
---|
2030 | #else
|
---|
2031 | platform = "unknown";
|
---|
2032 | #endif
|
---|
2033 |
|
---|
2034 | /* The format is <system>.<bitness> */
|
---|
2035 | platform += QString (".%1").arg (ARCH_BITS);
|
---|
2036 |
|
---|
2037 | /* Add more system information */
|
---|
2038 | #if defined (Q_OS_WIN)
|
---|
2039 | OSVERSIONINFO versionInfo;
|
---|
2040 | ZeroMemory (&versionInfo, sizeof (OSVERSIONINFO));
|
---|
2041 | versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
---|
2042 | GetVersionEx (&versionInfo);
|
---|
2043 | int major = versionInfo.dwMajorVersion;
|
---|
2044 | int minor = versionInfo.dwMinorVersion;
|
---|
2045 | int build = versionInfo.dwBuildNumber;
|
---|
2046 | QString sp = QString::fromUtf16 ((ushort*)versionInfo.szCSDVersion);
|
---|
2047 |
|
---|
2048 | QString distrib;
|
---|
2049 | if (major == 6)
|
---|
2050 | distrib = QString ("Windows Vista %1");
|
---|
2051 | else if (major == 5)
|
---|
2052 | {
|
---|
2053 | if (minor == 2)
|
---|
2054 | distrib = QString ("Windows Server 2003 %1");
|
---|
2055 | else if (minor == 1)
|
---|
2056 | distrib = QString ("Windows XP %1");
|
---|
2057 | else if (minor == 0)
|
---|
2058 | distrib = QString ("Windows 2000 %1");
|
---|
2059 | else
|
---|
2060 | distrib = QString ("Unknown %1");
|
---|
2061 | }
|
---|
2062 | else if (major == 4)
|
---|
2063 | {
|
---|
2064 | if (minor == 90)
|
---|
2065 | distrib = QString ("Windows Me %1");
|
---|
2066 | else if (minor == 10)
|
---|
2067 | distrib = QString ("Windows 98 %1");
|
---|
2068 | else if (minor == 0)
|
---|
2069 | distrib = QString ("Windows 95 %1");
|
---|
2070 | else
|
---|
2071 | distrib = QString ("Unknown %1");
|
---|
2072 | }
|
---|
2073 | else /** @todo Windows Server 2008 == vista? Probably not... */
|
---|
2074 | distrib = QString ("Unknown %1");
|
---|
2075 | distrib = distrib.arg (sp);
|
---|
2076 | QString version = QString ("%1.%2").arg (major).arg (minor);
|
---|
2077 | QString kernel = QString ("%1").arg (build);
|
---|
2078 | platform += QString (" [Distribution: %1 | Version: %2 | Build: %3]")
|
---|
2079 | .arg (distrib).arg (version).arg (kernel);
|
---|
2080 | #elif defined (Q_OS_LINUX)
|
---|
2081 | /* Get script path */
|
---|
2082 | char szAppPrivPath [RTPATH_MAX];
|
---|
2083 | int rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath)); NOREF(rc);
|
---|
2084 | AssertRC (rc);
|
---|
2085 | /* Run script */
|
---|
2086 | QByteArray result =
|
---|
2087 | Process::singleShot (QString (szAppPrivPath) + "/VBoxSysInfo.sh");
|
---|
2088 | if (!result.isNull())
|
---|
2089 | platform += QString (" [%1]").arg (QString (result).trimmed());
|
---|
2090 | #else
|
---|
2091 | /* Use RTSystemQueryOSInfo. */
|
---|
2092 | char szTmp[256];
|
---|
2093 | QStringList components;
|
---|
2094 | int vrc = RTSystemQueryOSInfo (RTSYSOSINFO_PRODUCT, szTmp, sizeof (szTmp));
|
---|
2095 | if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
2096 | components << QString ("Product: %1").arg (szTmp);
|
---|
2097 | vrc = RTSystemQueryOSInfo (RTSYSOSINFO_RELEASE, szTmp, sizeof (szTmp));
|
---|
2098 | if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
2099 | components << QString ("Release: %1").arg (szTmp);
|
---|
2100 | vrc = RTSystemQueryOSInfo (RTSYSOSINFO_VERSION, szTmp, sizeof (szTmp));
|
---|
2101 | if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
2102 | components << QString ("Version: %1").arg (szTmp);
|
---|
2103 | vrc = RTSystemQueryOSInfo (RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof (szTmp));
|
---|
2104 | if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
2105 | components << QString ("SP: %1").arg (szTmp);
|
---|
2106 | if (!components.isEmpty())
|
---|
2107 | platform += QString (" [%1]").arg (components.join (" | "));
|
---|
2108 | #endif
|
---|
2109 |
|
---|
2110 | return platform;
|
---|
2111 | }
|
---|
2112 |
|
---|
2113 | #if defined(Q_WS_X11) && !defined(VBOX_OSE)
|
---|
2114 | double VBoxGlobal::findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const
|
---|
2115 | {
|
---|
2116 | double maxVersionNumber = 0;
|
---|
2117 | aLicenseFile = "";
|
---|
2118 | for (int index = 0; index < aFilesList.count(); ++ index)
|
---|
2119 | {
|
---|
2120 | aPattern.indexIn (aFilesList [index]);
|
---|
2121 | QString version = aPattern.cap (1);
|
---|
2122 | if (maxVersionNumber < version.toDouble())
|
---|
2123 | {
|
---|
2124 | maxVersionNumber = version.toDouble();
|
---|
2125 | aLicenseFile = aFilesList [index];
|
---|
2126 | }
|
---|
2127 | }
|
---|
2128 | return maxVersionNumber;
|
---|
2129 | }
|
---|
2130 |
|
---|
2131 | bool VBoxGlobal::showVirtualBoxLicense()
|
---|
2132 | {
|
---|
2133 | /* get the apps doc path */
|
---|
2134 | int size = 256;
|
---|
2135 | char *buffer = (char*) RTMemTmpAlloc (size);
|
---|
2136 | RTPathAppDocs (buffer, size);
|
---|
2137 | QString path (buffer);
|
---|
2138 | RTMemTmpFree (buffer);
|
---|
2139 | QDir docDir (path);
|
---|
2140 | docDir.setFilter (QDir::Files);
|
---|
2141 | docDir.setNameFilters (QStringList ("License-*.html"));
|
---|
2142 |
|
---|
2143 | /* Make sure that the language is in two letter code.
|
---|
2144 | * Note: if languageId() returns an empty string lang.name() will
|
---|
2145 | * return "C" which is an valid language code. */
|
---|
2146 | QLocale lang (VBoxGlobal::languageId());
|
---|
2147 |
|
---|
2148 | QStringList filesList = docDir.entryList();
|
---|
2149 | QString licenseFile;
|
---|
2150 | /* First try to find a localized version of the license file. */
|
---|
2151 | double versionNumber = findLicenseFile (filesList, QRegExp (QString ("License-([\\d\\.]+)-%1.html").arg (lang.name())), licenseFile);
|
---|
2152 | /* If there wasn't a localized version of the currently selected language,
|
---|
2153 | * search for the generic one. */
|
---|
2154 | if (versionNumber == 0)
|
---|
2155 | versionNumber = findLicenseFile (filesList, QRegExp ("License-([\\d\\.]+).html"), licenseFile);
|
---|
2156 | /* Check the version again. */
|
---|
2157 | if (!versionNumber)
|
---|
2158 | {
|
---|
2159 | vboxProblem().cannotFindLicenseFiles (path);
|
---|
2160 | return false;
|
---|
2161 | }
|
---|
2162 |
|
---|
2163 | /* compose the latest license file full path */
|
---|
2164 | QString latestVersion = QString::number (versionNumber);
|
---|
2165 | QString latestFilePath = docDir.absoluteFilePath (licenseFile);
|
---|
2166 |
|
---|
2167 | /* check for the agreed license version */
|
---|
2168 | QStringList strList = virtualBox().GetExtraData (VBoxDefs::GUI_LicenseKey).split(",");
|
---|
2169 | for (int i=0; i < strList.size(); ++i)
|
---|
2170 | if (strList.at(i) == latestVersion)
|
---|
2171 | return true;
|
---|
2172 |
|
---|
2173 | VBoxLicenseViewer licenseDialog;
|
---|
2174 | bool result = licenseDialog.showLicenseFromFile(latestFilePath) == QDialog::Accepted;
|
---|
2175 | if (result)
|
---|
2176 | virtualBox().SetExtraData (VBoxDefs::GUI_LicenseKey, (strList << latestVersion).join(","));
|
---|
2177 | return result;
|
---|
2178 | }
|
---|
2179 | #endif /* defined(Q_WS_X11) && !defined(VBOX_OSE) */
|
---|
2180 |
|
---|
2181 | /**
|
---|
2182 | * Opens a direct session for a machine with the given ID.
|
---|
2183 | * This method does user-friendly error handling (display error messages, etc.).
|
---|
2184 | * and returns a null CSession object in case of any error.
|
---|
2185 | * If this method succeeds, don't forget to close the returned session when
|
---|
2186 | * it is no more necessary.
|
---|
2187 | *
|
---|
2188 | * @param aId Machine ID.
|
---|
2189 | * @param aExisting @c true to open an existing session with the machine
|
---|
2190 | * which is already running, @c false to open a new direct
|
---|
2191 | * session.
|
---|
2192 | */
|
---|
2193 | CSession VBoxGlobal::openSession(const QString &aId, bool aExisting /* = false */)
|
---|
2194 | {
|
---|
2195 | CSession session;
|
---|
2196 | session.createInstance(CLSID_Session);
|
---|
2197 | if (session.isNull())
|
---|
2198 | {
|
---|
2199 | vboxProblem().cannotOpenSession (session);
|
---|
2200 | return session;
|
---|
2201 | }
|
---|
2202 |
|
---|
2203 | CMachine foundMachine = CVirtualBox(mVBox).FindMachine(aId);
|
---|
2204 | if (!foundMachine.isNull())
|
---|
2205 | {
|
---|
2206 | foundMachine.LockMachine(session,
|
---|
2207 | (aExisting) ? KLockType_Shared : KLockType_Write);
|
---|
2208 | if (session.GetType() == KSessionType_Shared)
|
---|
2209 | {
|
---|
2210 | CMachine machine = session.GetMachine();
|
---|
2211 | /* Make sure that the language is in two letter code.
|
---|
2212 | * Note: if languageId() returns an empty string lang.name() will
|
---|
2213 | * return "C" which is an valid language code. */
|
---|
2214 | QLocale lang(VBoxGlobal::languageId());
|
---|
2215 | machine.SetGuestPropertyValue ("/VirtualBox/HostInfo/GUI/LanguageID", lang.name());
|
---|
2216 | }
|
---|
2217 | }
|
---|
2218 |
|
---|
2219 | if (!mVBox.isOk())
|
---|
2220 | {
|
---|
2221 | vboxProblem().cannotOpenSession(mVBox, foundMachine);
|
---|
2222 | session.detach();
|
---|
2223 | }
|
---|
2224 |
|
---|
2225 | return session;
|
---|
2226 | }
|
---|
2227 |
|
---|
2228 | /**
|
---|
2229 | * Starts a machine with the given ID.
|
---|
2230 | */
|
---|
2231 | bool VBoxGlobal::startMachine(const QString &strId)
|
---|
2232 | {
|
---|
2233 | AssertReturn(mValid, false);
|
---|
2234 |
|
---|
2235 | CSession session = vboxGlobal().openSession(strId);
|
---|
2236 | if (session.isNull())
|
---|
2237 | return false;
|
---|
2238 |
|
---|
2239 | return createVirtualMachine(session);
|
---|
2240 | }
|
---|
2241 |
|
---|
2242 | /**
|
---|
2243 | * Appends the NULL medium to the media list.
|
---|
2244 | * For using with VBoxGlobal::startEnumeratingMedia() only.
|
---|
2245 | */
|
---|
2246 | static void addNullMediumToList (VBoxMediaList &aList, VBoxMediaList::iterator aWhere)
|
---|
2247 | {
|
---|
2248 | VBoxMedium medium;
|
---|
2249 | aList.insert (aWhere, medium);
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | /**
|
---|
2253 | * Appends the given list of mediums to the media list.
|
---|
2254 | * For using with VBoxGlobal::startEnumeratingMedia() only.
|
---|
2255 | */
|
---|
2256 | static void addMediumsToList (const CMediumVector &aVector,
|
---|
2257 | VBoxMediaList &aList,
|
---|
2258 | VBoxMediaList::iterator aWhere,
|
---|
2259 | VBoxDefs::MediumType aType,
|
---|
2260 | VBoxMedium *aParent = 0)
|
---|
2261 | {
|
---|
2262 | VBoxMediaList::iterator first = aWhere;
|
---|
2263 |
|
---|
2264 | for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it)
|
---|
2265 | {
|
---|
2266 | CMedium cmedium (*it);
|
---|
2267 | VBoxMedium medium (cmedium, aType, aParent);
|
---|
2268 |
|
---|
2269 | /* Search for a proper alphabetic position */
|
---|
2270 | VBoxMediaList::iterator jt = first;
|
---|
2271 | for (; jt != aWhere; ++ jt)
|
---|
2272 | if ((*jt).name().localeAwareCompare (medium.name()) > 0)
|
---|
2273 | break;
|
---|
2274 |
|
---|
2275 | aList.insert (jt, medium);
|
---|
2276 |
|
---|
2277 | /* Adjust the first item if inserted before it */
|
---|
2278 | if (jt == first)
|
---|
2279 | -- first;
|
---|
2280 | }
|
---|
2281 | }
|
---|
2282 |
|
---|
2283 | /**
|
---|
2284 | * Appends the given list of hard disks and all their children to the media list.
|
---|
2285 | * For using with VBoxGlobal::startEnumeratingMedia() only.
|
---|
2286 | */
|
---|
2287 | static void addHardDisksToList (const CMediumVector &aVector,
|
---|
2288 | VBoxMediaList &aList,
|
---|
2289 | VBoxMediaList::iterator aWhere,
|
---|
2290 | VBoxMedium *aParent = 0)
|
---|
2291 | {
|
---|
2292 | VBoxMediaList::iterator first = aWhere;
|
---|
2293 |
|
---|
2294 | /* First pass: Add siblings sorted */
|
---|
2295 | for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it)
|
---|
2296 | {
|
---|
2297 | CMedium cmedium (*it);
|
---|
2298 | VBoxMedium medium (cmedium, VBoxDefs::MediumType_HardDisk, aParent);
|
---|
2299 |
|
---|
2300 | /* Search for a proper alphabetic position */
|
---|
2301 | VBoxMediaList::iterator jt = first;
|
---|
2302 | for (; jt != aWhere; ++ jt)
|
---|
2303 | if ((*jt).name().localeAwareCompare (medium.name()) > 0)
|
---|
2304 | break;
|
---|
2305 |
|
---|
2306 | aList.insert (jt, medium);
|
---|
2307 |
|
---|
2308 | /* Adjust the first item if inserted before it */
|
---|
2309 | if (jt == first)
|
---|
2310 | -- first;
|
---|
2311 | }
|
---|
2312 |
|
---|
2313 | /* Second pass: Add children */
|
---|
2314 | for (VBoxMediaList::iterator it = first; it != aWhere;)
|
---|
2315 | {
|
---|
2316 | CMediumVector children = (*it).medium().GetChildren();
|
---|
2317 | VBoxMedium *parent = &(*it);
|
---|
2318 |
|
---|
2319 | ++ it; /* go to the next sibling before inserting children */
|
---|
2320 | addHardDisksToList (children, aList, it, parent);
|
---|
2321 | }
|
---|
2322 | }
|
---|
2323 |
|
---|
2324 | /**
|
---|
2325 | * Starts a thread that asynchronously enumerates all currently registered
|
---|
2326 | * media.
|
---|
2327 | *
|
---|
2328 | * Before the enumeration is started, the current media list (a list returned by
|
---|
2329 | * #currentMediaList()) is populated with all registered media and the
|
---|
2330 | * #mediumEnumStarted() signal is emitted. The enumeration thread then walks this
|
---|
2331 | * list, checks for media accessibility and emits #mediumEnumerated() signals of
|
---|
2332 | * each checked medium. When all media are checked, the enumeration thread is
|
---|
2333 | * stopped and the #mediumEnumFinished() signal is emitted.
|
---|
2334 | *
|
---|
2335 | * If the enumeration is already in progress, no new thread is started.
|
---|
2336 | *
|
---|
2337 | * The media list returned by #currentMediaList() is always sorted
|
---|
2338 | * alphabetically by the location attribute and comes in the following order:
|
---|
2339 | * <ol>
|
---|
2340 | * <li>All hard disks. If a hard disk has children, these children
|
---|
2341 | * (alphabetically sorted) immediately follow their parent and therefore
|
---|
2342 | * appear before its next sibling hard disk.</li>
|
---|
2343 | * <li>All CD/DVD images.</li>
|
---|
2344 | * <li>All Floppy images.</li>
|
---|
2345 | * </ol>
|
---|
2346 | *
|
---|
2347 | * Note that #mediumEnumerated() signals are emitted in the same order as
|
---|
2348 | * described above.
|
---|
2349 | *
|
---|
2350 | * @sa #currentMediaList()
|
---|
2351 | * @sa #isMediaEnumerationStarted()
|
---|
2352 | */
|
---|
2353 | void VBoxGlobal::startEnumeratingMedia()
|
---|
2354 | {
|
---|
2355 | AssertReturnVoid (mValid);
|
---|
2356 |
|
---|
2357 | /* check if already started but not yet finished */
|
---|
2358 | if (mMediaEnumThread != NULL)
|
---|
2359 | return;
|
---|
2360 |
|
---|
2361 | /* ignore the request during application termination */
|
---|
2362 | if (sVBoxGlobalInCleanup)
|
---|
2363 | return;
|
---|
2364 |
|
---|
2365 | /* composes a list of all currently known media & their children */
|
---|
2366 | mMediaList.clear();
|
---|
2367 | addNullMediumToList (mMediaList, mMediaList.end());
|
---|
2368 | addHardDisksToList (mVBox.GetHardDisks(), mMediaList, mMediaList.end());
|
---|
2369 | addMediumsToList (mVBox.GetHost().GetDVDDrives(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_DVD);
|
---|
2370 | addMediumsToList (mVBox.GetDVDImages(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_DVD);
|
---|
2371 | addMediumsToList (mVBox.GetHost().GetFloppyDrives(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_Floppy);
|
---|
2372 | addMediumsToList (mVBox.GetFloppyImages(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_Floppy);
|
---|
2373 |
|
---|
2374 | /* enumeration thread class */
|
---|
2375 | class MediaEnumThread : public QThread
|
---|
2376 | {
|
---|
2377 | public:
|
---|
2378 |
|
---|
2379 | MediaEnumThread (VBoxMediaList &aList)
|
---|
2380 | : mVector (aList.size())
|
---|
2381 | , mSavedIt (aList.begin())
|
---|
2382 | {
|
---|
2383 | int i = 0;
|
---|
2384 | for (VBoxMediaList::const_iterator it = aList.begin();
|
---|
2385 | it != aList.end(); ++ it)
|
---|
2386 | mVector [i ++] = *it;
|
---|
2387 | }
|
---|
2388 |
|
---|
2389 | virtual void run()
|
---|
2390 | {
|
---|
2391 | LogFlow (("MediaEnumThread started.\n"));
|
---|
2392 | COMBase::InitializeCOM(false);
|
---|
2393 |
|
---|
2394 | CVirtualBox mVBox = vboxGlobal().virtualBox();
|
---|
2395 | QObject *self = &vboxGlobal();
|
---|
2396 |
|
---|
2397 | /* Enumerate the list */
|
---|
2398 | for (int i = 0; i < mVector.size() && !sVBoxGlobalInCleanup; ++ i)
|
---|
2399 | {
|
---|
2400 | mVector [i].blockAndQueryState();
|
---|
2401 | QApplication::
|
---|
2402 | postEvent (self,
|
---|
2403 | new VBoxMediaEnumEvent (mVector [i], mSavedIt));
|
---|
2404 | }
|
---|
2405 |
|
---|
2406 | /* Post the end-of-enumeration event */
|
---|
2407 | if (!sVBoxGlobalInCleanup)
|
---|
2408 | QApplication::postEvent (self, new VBoxMediaEnumEvent (mSavedIt));
|
---|
2409 |
|
---|
2410 | COMBase::CleanupCOM();
|
---|
2411 | LogFlow (("MediaEnumThread finished.\n"));
|
---|
2412 | }
|
---|
2413 |
|
---|
2414 | private:
|
---|
2415 |
|
---|
2416 | QVector <VBoxMedium> mVector;
|
---|
2417 | VBoxMediaList::iterator mSavedIt;
|
---|
2418 | };
|
---|
2419 |
|
---|
2420 | mMediaEnumThread = new MediaEnumThread (mMediaList);
|
---|
2421 | AssertReturnVoid (mMediaEnumThread);
|
---|
2422 |
|
---|
2423 | /* emit mediumEnumStarted() after we set mMediaEnumThread to != NULL
|
---|
2424 | * to cause isMediaEnumerationStarted() to return TRUE from slots */
|
---|
2425 | emit mediumEnumStarted();
|
---|
2426 |
|
---|
2427 | mMediaEnumThread->start();
|
---|
2428 | }
|
---|
2429 |
|
---|
2430 | VBoxDefs::MediumType VBoxGlobal::mediumTypeToLocal(KDeviceType globalType)
|
---|
2431 | {
|
---|
2432 | switch (globalType)
|
---|
2433 | {
|
---|
2434 | case KDeviceType_HardDisk:
|
---|
2435 | return VBoxDefs::MediumType_HardDisk;
|
---|
2436 | case KDeviceType_DVD:
|
---|
2437 | return VBoxDefs::MediumType_DVD;
|
---|
2438 | case KDeviceType_Floppy:
|
---|
2439 | return VBoxDefs::MediumType_Floppy;
|
---|
2440 | default:
|
---|
2441 | break;
|
---|
2442 | }
|
---|
2443 | return VBoxDefs::MediumType_Invalid;
|
---|
2444 | }
|
---|
2445 |
|
---|
2446 | KDeviceType VBoxGlobal::mediumTypeToGlobal(VBoxDefs::MediumType localType)
|
---|
2447 | {
|
---|
2448 | switch (localType)
|
---|
2449 | {
|
---|
2450 | case VBoxDefs::MediumType_HardDisk:
|
---|
2451 | return KDeviceType_HardDisk;
|
---|
2452 | case VBoxDefs::MediumType_DVD:
|
---|
2453 | return KDeviceType_DVD;
|
---|
2454 | case VBoxDefs::MediumType_Floppy:
|
---|
2455 | return KDeviceType_Floppy;
|
---|
2456 | default:
|
---|
2457 | break;
|
---|
2458 | }
|
---|
2459 | return KDeviceType_Null;
|
---|
2460 | }
|
---|
2461 |
|
---|
2462 | /**
|
---|
2463 | * Adds a new medium to the current media list and emits the #mediumAdded()
|
---|
2464 | * signal.
|
---|
2465 | *
|
---|
2466 | * @sa #currentMediaList()
|
---|
2467 | */
|
---|
2468 | void VBoxGlobal::addMedium (const VBoxMedium &aMedium)
|
---|
2469 | {
|
---|
2470 | /* Note that we maintain the same order here as #startEnumeratingMedia() */
|
---|
2471 |
|
---|
2472 | VBoxMediaList::iterator it = mMediaList.begin();
|
---|
2473 |
|
---|
2474 | if (aMedium.type() == VBoxDefs::MediumType_HardDisk)
|
---|
2475 | {
|
---|
2476 | VBoxMediaList::iterator itParent = mMediaList.end();
|
---|
2477 |
|
---|
2478 | for (; it != mMediaList.end(); ++ it)
|
---|
2479 | {
|
---|
2480 | /* skip null medium that come first */
|
---|
2481 | if ((*it).isNull()) continue;
|
---|
2482 |
|
---|
2483 | if ((*it).type() != VBoxDefs::MediumType_HardDisk)
|
---|
2484 | break;
|
---|
2485 |
|
---|
2486 | if (aMedium.parent() != NULL && itParent == mMediaList.end())
|
---|
2487 | {
|
---|
2488 | if (&*it == aMedium.parent())
|
---|
2489 | itParent = it;
|
---|
2490 | }
|
---|
2491 | else
|
---|
2492 | {
|
---|
2493 | /* break if met a parent's sibling (will insert before it) */
|
---|
2494 | if (aMedium.parent() != NULL &&
|
---|
2495 | (*it).parent() == (*itParent).parent())
|
---|
2496 | break;
|
---|
2497 |
|
---|
2498 | /* compare to aMedium's siblings */
|
---|
2499 | if ((*it).parent() == aMedium.parent() &&
|
---|
2500 | (*it).name().localeAwareCompare (aMedium.name()) > 0)
|
---|
2501 | break;
|
---|
2502 | }
|
---|
2503 | }
|
---|
2504 |
|
---|
2505 | AssertReturnVoid (aMedium.parent() == NULL || itParent != mMediaList.end());
|
---|
2506 | }
|
---|
2507 | else
|
---|
2508 | {
|
---|
2509 | for (; it != mMediaList.end(); ++ it)
|
---|
2510 | {
|
---|
2511 | /* skip null medium that come first */
|
---|
2512 | if ((*it).isNull()) continue;
|
---|
2513 |
|
---|
2514 | /* skip HardDisks that come first */
|
---|
2515 | if ((*it).type() == VBoxDefs::MediumType_HardDisk)
|
---|
2516 | continue;
|
---|
2517 |
|
---|
2518 | /* skip DVD when inserting Floppy */
|
---|
2519 | if (aMedium.type() == VBoxDefs::MediumType_Floppy &&
|
---|
2520 | (*it).type() == VBoxDefs::MediumType_DVD)
|
---|
2521 | continue;
|
---|
2522 |
|
---|
2523 | if ((*it).name().localeAwareCompare (aMedium.name()) > 0 ||
|
---|
2524 | (aMedium.type() == VBoxDefs::MediumType_DVD &&
|
---|
2525 | (*it).type() == VBoxDefs::MediumType_Floppy))
|
---|
2526 | break;
|
---|
2527 | }
|
---|
2528 | }
|
---|
2529 |
|
---|
2530 | it = mMediaList.insert (it, aMedium);
|
---|
2531 |
|
---|
2532 | emit mediumAdded (*it);
|
---|
2533 | }
|
---|
2534 |
|
---|
2535 | /**
|
---|
2536 | * Updates the medium in the current media list and emits the #mediumUpdated()
|
---|
2537 | * signal.
|
---|
2538 | *
|
---|
2539 | * @sa #currentMediaList()
|
---|
2540 | */
|
---|
2541 | void VBoxGlobal::updateMedium (const VBoxMedium &aMedium)
|
---|
2542 | {
|
---|
2543 | VBoxMediaList::Iterator it;
|
---|
2544 | for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
|
---|
2545 | if ((*it).id() == aMedium.id())
|
---|
2546 | break;
|
---|
2547 |
|
---|
2548 | AssertReturnVoid (it != mMediaList.end());
|
---|
2549 |
|
---|
2550 | if (&*it != &aMedium)
|
---|
2551 | *it = aMedium;
|
---|
2552 |
|
---|
2553 | emit mediumUpdated (*it);
|
---|
2554 | }
|
---|
2555 |
|
---|
2556 | /**
|
---|
2557 | * Removes the medium from the current media list and emits the #mediumRemoved()
|
---|
2558 | * signal.
|
---|
2559 | *
|
---|
2560 | * @sa #currentMediaList()
|
---|
2561 | */
|
---|
2562 | void VBoxGlobal::removeMedium (VBoxDefs::MediumType aType, const QString &aId)
|
---|
2563 | {
|
---|
2564 | VBoxMediaList::Iterator it;
|
---|
2565 | for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
|
---|
2566 | if ((*it).id() == aId)
|
---|
2567 | break;
|
---|
2568 |
|
---|
2569 | AssertReturnVoid (it != mMediaList.end());
|
---|
2570 |
|
---|
2571 | #if DEBUG
|
---|
2572 | /* sanity: must be no children */
|
---|
2573 | {
|
---|
2574 | VBoxMediaList::Iterator jt = it;
|
---|
2575 | ++ jt;
|
---|
2576 | AssertReturnVoid (jt == mMediaList.end() || (*jt).parent() != &*it);
|
---|
2577 | }
|
---|
2578 | #endif
|
---|
2579 |
|
---|
2580 | VBoxMedium *pParent = (*it).parent();
|
---|
2581 |
|
---|
2582 | /* remove the medium from the list to keep it in sync with the server "for
|
---|
2583 | * free" when the medium is deleted from one of our UIs */
|
---|
2584 | mMediaList.erase (it);
|
---|
2585 |
|
---|
2586 | emit mediumRemoved (aType, aId);
|
---|
2587 |
|
---|
2588 | /* also emit the parent update signal because some attributes like
|
---|
2589 | * isReadOnly() may have been changed after child removal */
|
---|
2590 | if (pParent != NULL)
|
---|
2591 | {
|
---|
2592 | pParent->refresh();
|
---|
2593 | emit mediumUpdated (*pParent);
|
---|
2594 | }
|
---|
2595 | }
|
---|
2596 |
|
---|
2597 | /**
|
---|
2598 | * Searches for a VBoxMedum object representing the given COM medium object.
|
---|
2599 | *
|
---|
2600 | * @return true if found and false otherwise.
|
---|
2601 | */
|
---|
2602 | bool VBoxGlobal::findMedium (const CMedium &aObj, VBoxMedium &aMedium) const
|
---|
2603 | {
|
---|
2604 | for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it)
|
---|
2605 | {
|
---|
2606 | if (((*it).medium().isNull() && aObj.isNull()) ||
|
---|
2607 | (!(*it).medium().isNull() && !aObj.isNull() && (*it).medium().GetId() == aObj.GetId()))
|
---|
2608 | {
|
---|
2609 | aMedium = (*it);
|
---|
2610 | return true;
|
---|
2611 | }
|
---|
2612 | }
|
---|
2613 | return false;
|
---|
2614 | }
|
---|
2615 |
|
---|
2616 | /**
|
---|
2617 | * Searches for a VBoxMedum object with the given medium id attribute.
|
---|
2618 | *
|
---|
2619 | * @return VBoxMedum if found which is invalid otherwise.
|
---|
2620 | */
|
---|
2621 | VBoxMedium VBoxGlobal::findMedium (const QString &aMediumId) const
|
---|
2622 | {
|
---|
2623 | for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it)
|
---|
2624 | if ((*it).id() == aMediumId)
|
---|
2625 | return *it;
|
---|
2626 | return VBoxMedium();
|
---|
2627 | }
|
---|
2628 |
|
---|
2629 | /* Open some external medium using file open dialog
|
---|
2630 | * and temporary cache (enumerate) it in GUI inner mediums cache: */
|
---|
2631 | QString VBoxGlobal::openMediumWithFileOpenDialog(VBoxDefs::MediumType mediumType, QWidget *pParent,
|
---|
2632 | const QString &strDefaultFolder /* = QString() */,
|
---|
2633 | bool fUseLastFolder /* = false */)
|
---|
2634 | {
|
---|
2635 | /* Initialize variables: */
|
---|
2636 | QString strHomeFolder = fUseLastFolder && !m_strLastFolder.isEmpty() ? m_strLastFolder :
|
---|
2637 | strDefaultFolder.isEmpty() ? vboxGlobal().virtualBox().GetHomeFolder() : strDefaultFolder;
|
---|
2638 | QList < QPair <QString, QString> > filters;
|
---|
2639 | QStringList backends;
|
---|
2640 | QStringList prefixes;
|
---|
2641 | QString strFilter;
|
---|
2642 | QString strTitle;
|
---|
2643 | QString allType;
|
---|
2644 | switch (mediumType)
|
---|
2645 | {
|
---|
2646 | case VBoxDefs::MediumType_HardDisk:
|
---|
2647 | {
|
---|
2648 | filters = vboxGlobal().HDDBackends();
|
---|
2649 | strTitle = tr ("Choose a virtual hard disk file");
|
---|
2650 | allType = tr ("hard disk");
|
---|
2651 | break;
|
---|
2652 | }
|
---|
2653 | case VBoxDefs::MediumType_DVD:
|
---|
2654 | {
|
---|
2655 | filters = vboxGlobal().DVDBackends();
|
---|
2656 | strTitle = tr ("Choose a virtual CD/DVD disk file");
|
---|
2657 | allType = tr ("CD/DVD-ROM disk");
|
---|
2658 | break;
|
---|
2659 | }
|
---|
2660 | case VBoxDefs::MediumType_Floppy:
|
---|
2661 | {
|
---|
2662 | filters = vboxGlobal().FloppyBackends();
|
---|
2663 | strTitle = tr ("Choose a virtual floppy disk file");
|
---|
2664 | allType = tr ("floppy disk");
|
---|
2665 | break;
|
---|
2666 | }
|
---|
2667 | default:
|
---|
2668 | break;
|
---|
2669 | }
|
---|
2670 |
|
---|
2671 | /* Prepare filters and backends: */
|
---|
2672 | for (int i = 0; i < filters.count(); ++i)
|
---|
2673 | {
|
---|
2674 | /* Get iterated filter: */
|
---|
2675 | QPair <QString, QString> item = filters.at(i);
|
---|
2676 | /* Create one backend filter string: */
|
---|
2677 | backends << QString("%1 (%2)").arg(item.first).arg(item.second);
|
---|
2678 | /* Save the suffix's for the "All" entry: */
|
---|
2679 | prefixes << item.second;
|
---|
2680 | }
|
---|
2681 | if (!prefixes.isEmpty())
|
---|
2682 | backends.insert(0, tr("All %1 images (%2)").arg(allType).arg(prefixes.join(" ").trimmed()));
|
---|
2683 | backends << tr("All files (*)");
|
---|
2684 | strFilter = backends.join(";;").trimmed();
|
---|
2685 |
|
---|
2686 | /* Create open file dialog: */
|
---|
2687 | QStringList files = QIFileDialog::getOpenFileNames(strHomeFolder, strFilter, pParent, strTitle, 0, true, true);
|
---|
2688 |
|
---|
2689 | /* If dialog has some result: */
|
---|
2690 | if (!files.empty() && !files[0].isEmpty())
|
---|
2691 | return openMedium(mediumType, files[0], pParent);
|
---|
2692 |
|
---|
2693 | return QString();
|
---|
2694 | }
|
---|
2695 |
|
---|
2696 | QString VBoxGlobal::openMedium(VBoxDefs::MediumType mediumType, QString strMediumLocation, QWidget *pParent /* = 0*/)
|
---|
2697 | {
|
---|
2698 | /* Convert to native separators: */
|
---|
2699 | strMediumLocation = QDir::toNativeSeparators(strMediumLocation);
|
---|
2700 |
|
---|
2701 | /* Initialize variables: */
|
---|
2702 | CVirtualBox vbox = vboxGlobal().virtualBox();
|
---|
2703 |
|
---|
2704 | /* Remember the path of the last chosen medium: */
|
---|
2705 | m_strLastFolder = QFileInfo(strMediumLocation).absolutePath();
|
---|
2706 |
|
---|
2707 | /* Update recently used list: */
|
---|
2708 | QString strRecentAddress = mediumType == VBoxDefs::MediumType_HardDisk ? VBoxDefs::GUI_RecentListHD :
|
---|
2709 | mediumType == VBoxDefs::MediumType_DVD ? VBoxDefs::GUI_RecentListCD :
|
---|
2710 | mediumType == VBoxDefs::MediumType_Floppy ? VBoxDefs::GUI_RecentListFD :
|
---|
2711 | QString();
|
---|
2712 | QStringList recentMediumList = virtualBox().GetExtraData(strRecentAddress).split(';');
|
---|
2713 | if (recentMediumList.contains(strMediumLocation))
|
---|
2714 | recentMediumList.removeAll(strMediumLocation);
|
---|
2715 | recentMediumList.prepend(strMediumLocation);
|
---|
2716 | while(recentMediumList.size() > 5) recentMediumList.removeLast();
|
---|
2717 | virtualBox().SetExtraData(strRecentAddress, recentMediumList.join(";"));
|
---|
2718 |
|
---|
2719 | /* Open corresponding medium: */
|
---|
2720 | CMedium comMedium = vbox.OpenMedium(strMediumLocation, mediumTypeToGlobal(mediumType), KAccessMode_ReadWrite);
|
---|
2721 |
|
---|
2722 | if (vbox.isOk())
|
---|
2723 | {
|
---|
2724 | /* Prepare vbox medium wrapper: */
|
---|
2725 | VBoxMedium vboxMedium;
|
---|
2726 |
|
---|
2727 | /* First of all we should test if that medium already opened: */
|
---|
2728 | if (!vboxGlobal().findMedium(comMedium, vboxMedium))
|
---|
2729 | {
|
---|
2730 | /* And create new otherwise: */
|
---|
2731 | vboxMedium = VBoxMedium(CMedium(comMedium), mediumType, KMediumState_Created);
|
---|
2732 | vboxGlobal().addMedium(vboxMedium);
|
---|
2733 | }
|
---|
2734 |
|
---|
2735 | /* Return vboxMedium id: */
|
---|
2736 | return vboxMedium.id();
|
---|
2737 | }
|
---|
2738 | else
|
---|
2739 | vboxProblem().cannotOpenMedium(pParent, vbox, mediumType, strMediumLocation);
|
---|
2740 |
|
---|
2741 | return QString();
|
---|
2742 | }
|
---|
2743 |
|
---|
2744 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
2745 | /**
|
---|
2746 | * Returns the number of current running Fe/Qt4 main windows.
|
---|
2747 | *
|
---|
2748 | * @return Number of running main windows.
|
---|
2749 | */
|
---|
2750 | int VBoxGlobal::mainWindowCount ()
|
---|
2751 | {
|
---|
2752 | return mVBox.GetExtraData (VBoxDefs::GUI_MainWindowCount).toInt();
|
---|
2753 | }
|
---|
2754 | #endif
|
---|
2755 |
|
---|
2756 | /**
|
---|
2757 | * Native language name of the currently installed translation.
|
---|
2758 | * Returns "English" if no translation is installed
|
---|
2759 | * or if the translation file is invalid.
|
---|
2760 | */
|
---|
2761 | QString VBoxGlobal::languageName() const
|
---|
2762 | {
|
---|
2763 |
|
---|
2764 | return qApp->translate ("@@@", "English",
|
---|
2765 | "Native language name");
|
---|
2766 | }
|
---|
2767 |
|
---|
2768 | /**
|
---|
2769 | * Native language country name of the currently installed translation.
|
---|
2770 | * Returns "--" if no translation is installed or if the translation file is
|
---|
2771 | * invalid, or if the language is independent on the country.
|
---|
2772 | */
|
---|
2773 | QString VBoxGlobal::languageCountry() const
|
---|
2774 | {
|
---|
2775 | return qApp->translate ("@@@", "--",
|
---|
2776 | "Native language country name "
|
---|
2777 | "(empty if this language is for all countries)");
|
---|
2778 | }
|
---|
2779 |
|
---|
2780 | /**
|
---|
2781 | * Language name of the currently installed translation, in English.
|
---|
2782 | * Returns "English" if no translation is installed
|
---|
2783 | * or if the translation file is invalid.
|
---|
2784 | */
|
---|
2785 | QString VBoxGlobal::languageNameEnglish() const
|
---|
2786 | {
|
---|
2787 |
|
---|
2788 | return qApp->translate ("@@@", "English",
|
---|
2789 | "Language name, in English");
|
---|
2790 | }
|
---|
2791 |
|
---|
2792 | /**
|
---|
2793 | * Language country name of the currently installed translation, in English.
|
---|
2794 | * Returns "--" if no translation is installed or if the translation file is
|
---|
2795 | * invalid, or if the language is independent on the country.
|
---|
2796 | */
|
---|
2797 | QString VBoxGlobal::languageCountryEnglish() const
|
---|
2798 | {
|
---|
2799 | return qApp->translate ("@@@", "--",
|
---|
2800 | "Language country name, in English "
|
---|
2801 | "(empty if native country name is empty)");
|
---|
2802 | }
|
---|
2803 |
|
---|
2804 | /**
|
---|
2805 | * Comma-separated list of authors of the currently installed translation.
|
---|
2806 | * Returns "Oracle Corporation" if no translation is installed or if the
|
---|
2807 | * translation file is invalid, or if the translation is supplied by Oracle
|
---|
2808 | * Corporation
|
---|
2809 | */
|
---|
2810 | QString VBoxGlobal::languageTranslators() const
|
---|
2811 | {
|
---|
2812 | return qApp->translate ("@@@", "Oracle Corporation",
|
---|
2813 | "Comma-separated list of translators");
|
---|
2814 | }
|
---|
2815 |
|
---|
2816 | /**
|
---|
2817 | * Changes the language of all global string constants according to the
|
---|
2818 | * currently installed translations tables.
|
---|
2819 | */
|
---|
2820 | void VBoxGlobal::retranslateUi()
|
---|
2821 | {
|
---|
2822 | mMachineStates [KMachineState_PoweredOff] = tr ("Powered Off", "MachineState");
|
---|
2823 | mMachineStates [KMachineState_Saved] = tr ("Saved", "MachineState");
|
---|
2824 | mMachineStates [KMachineState_Teleported] = tr ("Teleported", "MachineState");
|
---|
2825 | mMachineStates [KMachineState_Aborted] = tr ("Aborted", "MachineState");
|
---|
2826 | mMachineStates [KMachineState_Running] = tr ("Running", "MachineState");
|
---|
2827 | mMachineStates [KMachineState_Paused] = tr ("Paused", "MachineState");
|
---|
2828 | mMachineStates [KMachineState_Stuck] = tr ("Guru Meditation", "MachineState");
|
---|
2829 | mMachineStates [KMachineState_Teleporting] = tr ("Teleporting", "MachineState");
|
---|
2830 | mMachineStates [KMachineState_LiveSnapshotting] = tr ("Taking Live Snapshot", "MachineState");
|
---|
2831 | mMachineStates [KMachineState_Starting] = tr ("Starting", "MachineState");
|
---|
2832 | mMachineStates [KMachineState_Stopping] = tr ("Stopping", "MachineState");
|
---|
2833 | mMachineStates [KMachineState_Saving] = tr ("Saving", "MachineState");
|
---|
2834 | mMachineStates [KMachineState_Restoring] = tr ("Restoring", "MachineState");
|
---|
2835 | mMachineStates [KMachineState_TeleportingPausedVM] = tr ("Teleporting Paused VM", "MachineState");
|
---|
2836 | mMachineStates [KMachineState_TeleportingIn] = tr ("Teleporting", "MachineState");
|
---|
2837 | mMachineStates [KMachineState_RestoringSnapshot] = tr ("Restoring Snapshot", "MachineState");
|
---|
2838 | mMachineStates [KMachineState_DeletingSnapshot] = tr ("Deleting Snapshot", "MachineState");
|
---|
2839 | mMachineStates [KMachineState_DeletingSnapshotOnline] = tr ("Deleting Snapshot", "MachineState");
|
---|
2840 | mMachineStates [KMachineState_DeletingSnapshotPaused] = tr ("Deleting Snapshot", "MachineState");
|
---|
2841 | mMachineStates [KMachineState_SettingUp] = tr ("Setting Up", "MachineState");
|
---|
2842 | mMachineStates [KMachineState_FaultTolerantSyncing] = tr ("Fault Tolerant Syncing", "MachineState");
|
---|
2843 |
|
---|
2844 | mSessionStates [KSessionState_Unlocked] = tr ("Unlocked", "SessionState");
|
---|
2845 | mSessionStates [KSessionState_Locked] = tr ("Locked", "SessionState");
|
---|
2846 | mSessionStates [KSessionState_Spawning] = tr ("Spawning", "SessionState");
|
---|
2847 | mSessionStates [KSessionState_Unlocking] = tr ("Unlocking", "SessionState");
|
---|
2848 |
|
---|
2849 | mDeviceTypes [KDeviceType_Null] = tr ("None", "DeviceType");
|
---|
2850 | mDeviceTypes [KDeviceType_Floppy] = tr ("Floppy", "DeviceType");
|
---|
2851 | mDeviceTypes [KDeviceType_DVD] = tr ("CD/DVD-ROM", "DeviceType");
|
---|
2852 | mDeviceTypes [KDeviceType_HardDisk] = tr ("Hard Disk", "DeviceType");
|
---|
2853 | mDeviceTypes [KDeviceType_Network] = tr ("Network", "DeviceType");
|
---|
2854 | mDeviceTypes [KDeviceType_USB] = tr ("USB", "DeviceType");
|
---|
2855 | mDeviceTypes [KDeviceType_SharedFolder] = tr ("Shared Folder", "DeviceType");
|
---|
2856 |
|
---|
2857 | mStorageBuses [KStorageBus_IDE] = tr ("IDE", "StorageBus");
|
---|
2858 | mStorageBuses [KStorageBus_SATA] = tr ("SATA", "StorageBus");
|
---|
2859 | mStorageBuses [KStorageBus_SCSI] = tr ("SCSI", "StorageBus");
|
---|
2860 | mStorageBuses [KStorageBus_Floppy] = tr ("Floppy", "StorageBus");
|
---|
2861 | mStorageBuses [KStorageBus_SAS] = tr ("SAS", "StorageBus");
|
---|
2862 |
|
---|
2863 | mStorageBusChannels [0] = tr ("Primary", "StorageBusChannel");
|
---|
2864 | mStorageBusChannels [1] = tr ("Secondary", "StorageBusChannel");
|
---|
2865 | mStorageBusChannels [2] = tr ("Port %1", "StorageBusChannel");
|
---|
2866 |
|
---|
2867 | mStorageBusDevices [0] = tr ("Master", "StorageBusDevice");
|
---|
2868 | mStorageBusDevices [1] = tr ("Slave", "StorageBusDevice");
|
---|
2869 | mStorageBusDevices [2] = tr ("Device %1", "StorageBusDevice");
|
---|
2870 |
|
---|
2871 | mSlotTemplates [0] = tr ("IDE Primary Master", "New Storage UI : Slot Name");
|
---|
2872 | mSlotTemplates [1] = tr ("IDE Primary Slave", "New Storage UI : Slot Name");
|
---|
2873 | mSlotTemplates [2] = tr ("IDE Secondary Master", "New Storage UI : Slot Name");
|
---|
2874 | mSlotTemplates [3] = tr ("IDE Secondary Slave", "New Storage UI : Slot Name");
|
---|
2875 | mSlotTemplates [4] = tr ("SATA Port %1", "New Storage UI : Slot Name");
|
---|
2876 | mSlotTemplates [5] = tr ("SCSI Port %1", "New Storage UI : Slot Name");
|
---|
2877 | mSlotTemplates [6] = tr ("SAS Port %1", "New Storage UI : Slot Name");
|
---|
2878 | mSlotTemplates [7] = tr ("Floppy Device %1", "New Storage UI : Slot Name");
|
---|
2879 |
|
---|
2880 | mDiskTypes [KMediumType_Normal] = tr ("Normal", "DiskType");
|
---|
2881 | mDiskTypes [KMediumType_Immutable] = tr ("Immutable", "DiskType");
|
---|
2882 | mDiskTypes [KMediumType_Writethrough] = tr ("Writethrough", "DiskType");
|
---|
2883 | mDiskTypes [KMediumType_Shareable] = tr ("Shareable", "DiskType");
|
---|
2884 | mDiskTypes [KMediumType_Readonly] = tr ("Readonly", "DiskType");
|
---|
2885 | mDiskTypes [KMediumType_MultiAttach] = tr ("Multi-attach", "DiskType");
|
---|
2886 | mDiskTypes_Differencing = tr ("Differencing", "DiskType");
|
---|
2887 |
|
---|
2888 | mAuthTypes [KAuthType_Null] = tr ("Null", "AuthType");
|
---|
2889 | mAuthTypes [KAuthType_External] = tr ("External", "AuthType");
|
---|
2890 | mAuthTypes [KAuthType_Guest] = tr ("Guest", "AuthType");
|
---|
2891 |
|
---|
2892 | mPortModeTypes [KPortMode_Disconnected] = tr ("Disconnected", "PortMode");
|
---|
2893 | mPortModeTypes [KPortMode_HostPipe] = tr ("Host Pipe", "PortMode");
|
---|
2894 | mPortModeTypes [KPortMode_HostDevice] = tr ("Host Device", "PortMode");
|
---|
2895 | mPortModeTypes [KPortMode_RawFile] = tr ("Raw File", "PortMode");
|
---|
2896 |
|
---|
2897 | mUSBFilterActionTypes [KUSBDeviceFilterAction_Ignore] =
|
---|
2898 | tr ("Ignore", "USBFilterActionType");
|
---|
2899 | mUSBFilterActionTypes [KUSBDeviceFilterAction_Hold] =
|
---|
2900 | tr ("Hold", "USBFilterActionType");
|
---|
2901 |
|
---|
2902 | mAudioDriverTypes [KAudioDriverType_Null] =
|
---|
2903 | tr ("Null Audio Driver", "AudioDriverType");
|
---|
2904 | mAudioDriverTypes [KAudioDriverType_WinMM] =
|
---|
2905 | tr ("Windows Multimedia", "AudioDriverType");
|
---|
2906 | mAudioDriverTypes [KAudioDriverType_SolAudio] =
|
---|
2907 | tr ("Solaris Audio", "AudioDriverType");
|
---|
2908 | mAudioDriverTypes [KAudioDriverType_OSS] =
|
---|
2909 | tr ("OSS Audio Driver", "AudioDriverType");
|
---|
2910 | mAudioDriverTypes [KAudioDriverType_ALSA] =
|
---|
2911 | tr ("ALSA Audio Driver", "AudioDriverType");
|
---|
2912 | mAudioDriverTypes [KAudioDriverType_DirectSound] =
|
---|
2913 | tr ("Windows DirectSound", "AudioDriverType");
|
---|
2914 | mAudioDriverTypes [KAudioDriverType_CoreAudio] =
|
---|
2915 | tr ("CoreAudio", "AudioDriverType");
|
---|
2916 | mAudioDriverTypes [KAudioDriverType_Pulse] =
|
---|
2917 | tr ("PulseAudio", "AudioDriverType");
|
---|
2918 |
|
---|
2919 | mAudioControllerTypes [KAudioControllerType_AC97] =
|
---|
2920 | tr ("ICH AC97", "AudioControllerType");
|
---|
2921 | mAudioControllerTypes [KAudioControllerType_SB16] =
|
---|
2922 | tr ("SoundBlaster 16", "AudioControllerType");
|
---|
2923 | mAudioControllerTypes [KAudioControllerType_HDA] =
|
---|
2924 | tr ("Intel HD Audio", "AudioControllerType");
|
---|
2925 |
|
---|
2926 | mNetworkAdapterTypes [KNetworkAdapterType_Am79C970A] =
|
---|
2927 | tr ("PCnet-PCI II (Am79C970A)", "NetworkAdapterType");
|
---|
2928 | mNetworkAdapterTypes [KNetworkAdapterType_Am79C973] =
|
---|
2929 | tr ("PCnet-FAST III (Am79C973)", "NetworkAdapterType");
|
---|
2930 | mNetworkAdapterTypes [KNetworkAdapterType_I82540EM] =
|
---|
2931 | tr ("Intel PRO/1000 MT Desktop (82540EM)", "NetworkAdapterType");
|
---|
2932 | mNetworkAdapterTypes [KNetworkAdapterType_I82543GC] =
|
---|
2933 | tr ("Intel PRO/1000 T Server (82543GC)", "NetworkAdapterType");
|
---|
2934 | mNetworkAdapterTypes [KNetworkAdapterType_I82545EM] =
|
---|
2935 | tr ("Intel PRO/1000 MT Server (82545EM)", "NetworkAdapterType");
|
---|
2936 | #ifdef VBOX_WITH_VIRTIO
|
---|
2937 | mNetworkAdapterTypes [KNetworkAdapterType_Virtio] =
|
---|
2938 | tr ("Paravirtualized Network (virtio-net)", "NetworkAdapterType");
|
---|
2939 | #endif /* VBOX_WITH_VIRTIO */
|
---|
2940 |
|
---|
2941 | mNetworkAttachmentTypes [KNetworkAttachmentType_Null] =
|
---|
2942 | tr ("Not attached", "NetworkAttachmentType");
|
---|
2943 | mNetworkAttachmentTypes [KNetworkAttachmentType_NAT] =
|
---|
2944 | tr ("NAT", "NetworkAttachmentType");
|
---|
2945 | mNetworkAttachmentTypes [KNetworkAttachmentType_Bridged] =
|
---|
2946 | tr ("Bridged Adapter", "NetworkAttachmentType");
|
---|
2947 | mNetworkAttachmentTypes [KNetworkAttachmentType_Internal] =
|
---|
2948 | tr ("Internal Network", "NetworkAttachmentType");
|
---|
2949 | mNetworkAttachmentTypes [KNetworkAttachmentType_HostOnly] =
|
---|
2950 | tr ("Host-only Adapter", "NetworkAttachmentType");
|
---|
2951 | #ifdef VBOX_WITH_VDE
|
---|
2952 | mNetworkAttachmentTypes [KNetworkAttachmentType_VDE] =
|
---|
2953 | tr ("VDE Adapter", "NetworkAttachmentType");
|
---|
2954 | #endif
|
---|
2955 |
|
---|
2956 | mNATProtocolTypes [KNATProtocol_UDP] =
|
---|
2957 | tr ("UDP", "NATProtocolType");
|
---|
2958 | mNATProtocolTypes [KNATProtocol_TCP] =
|
---|
2959 | tr ("TCP", "NATProtocolType");
|
---|
2960 |
|
---|
2961 | mClipboardTypes [KClipboardMode_Disabled] =
|
---|
2962 | tr ("Disabled", "ClipboardType");
|
---|
2963 | mClipboardTypes [KClipboardMode_HostToGuest] =
|
---|
2964 | tr ("Host To Guest", "ClipboardType");
|
---|
2965 | mClipboardTypes [KClipboardMode_GuestToHost] =
|
---|
2966 | tr ("Guest To Host", "ClipboardType");
|
---|
2967 | mClipboardTypes [KClipboardMode_Bidirectional] =
|
---|
2968 | tr ("Bidirectional", "ClipboardType");
|
---|
2969 |
|
---|
2970 | mStorageControllerTypes [KStorageControllerType_PIIX3] =
|
---|
2971 | tr ("PIIX3", "StorageControllerType");
|
---|
2972 | mStorageControllerTypes [KStorageControllerType_PIIX4] =
|
---|
2973 | tr ("PIIX4", "StorageControllerType");
|
---|
2974 | mStorageControllerTypes [KStorageControllerType_ICH6] =
|
---|
2975 | tr ("ICH6", "StorageControllerType");
|
---|
2976 | mStorageControllerTypes [KStorageControllerType_IntelAhci] =
|
---|
2977 | tr ("AHCI", "StorageControllerType");
|
---|
2978 | mStorageControllerTypes [KStorageControllerType_LsiLogic] =
|
---|
2979 | tr ("Lsilogic", "StorageControllerType");
|
---|
2980 | mStorageControllerTypes [KStorageControllerType_BusLogic] =
|
---|
2981 | tr ("BusLogic", "StorageControllerType");
|
---|
2982 | mStorageControllerTypes [KStorageControllerType_I82078] =
|
---|
2983 | tr ("I82078", "StorageControllerType");
|
---|
2984 | mStorageControllerTypes [KStorageControllerType_LsiLogicSas] =
|
---|
2985 | tr ("LsiLogic SAS", "StorageControllerType");
|
---|
2986 |
|
---|
2987 | mUSBDeviceStates [KUSBDeviceState_NotSupported] =
|
---|
2988 | tr ("Not supported", "USBDeviceState");
|
---|
2989 | mUSBDeviceStates [KUSBDeviceState_Unavailable] =
|
---|
2990 | tr ("Unavailable", "USBDeviceState");
|
---|
2991 | mUSBDeviceStates [KUSBDeviceState_Busy] =
|
---|
2992 | tr ("Busy", "USBDeviceState");
|
---|
2993 | mUSBDeviceStates [KUSBDeviceState_Available] =
|
---|
2994 | tr ("Available", "USBDeviceState");
|
---|
2995 | mUSBDeviceStates [KUSBDeviceState_Held] =
|
---|
2996 | tr ("Held", "USBDeviceState");
|
---|
2997 | mUSBDeviceStates [KUSBDeviceState_Captured] =
|
---|
2998 | tr ("Captured", "USBDeviceState");
|
---|
2999 |
|
---|
3000 | mChipsetTypes [KChipsetType_PIIX3] =
|
---|
3001 | tr ("PIIX3", "ChipsetType");
|
---|
3002 | mChipsetTypes [KChipsetType_ICH9] =
|
---|
3003 | tr ("ICH9", "ChipsetType");
|
---|
3004 |
|
---|
3005 | mUserDefinedPortName = tr ("User-defined", "serial port");
|
---|
3006 |
|
---|
3007 | mWarningIcon = UIIconPool::defaultIcon(UIIconPool::MessageBoxWarningIcon).pixmap (16, 16);
|
---|
3008 | Assert (!mWarningIcon.isNull());
|
---|
3009 |
|
---|
3010 | mErrorIcon = UIIconPool::defaultIcon(UIIconPool::MessageBoxCriticalIcon).pixmap (16, 16);
|
---|
3011 | Assert (!mErrorIcon.isNull());
|
---|
3012 |
|
---|
3013 | /* refresh media properties since they contain some translations too */
|
---|
3014 | for (VBoxMediaList::iterator it = mMediaList.begin();
|
---|
3015 | it != mMediaList.end(); ++ it)
|
---|
3016 | it->refresh();
|
---|
3017 |
|
---|
3018 | #ifdef Q_WS_X11
|
---|
3019 | /* As X11 do not have functionality for providing human readable key names,
|
---|
3020 | * we keep a table of them, which must be updated when the language is changed. */
|
---|
3021 | UIHotKey::retranslateKeyNames();
|
---|
3022 | #endif /* Q_WS_X11 */
|
---|
3023 | }
|
---|
3024 |
|
---|
3025 | // public static stuff
|
---|
3026 | ////////////////////////////////////////////////////////////////////////////////
|
---|
3027 |
|
---|
3028 | /* static */
|
---|
3029 | bool VBoxGlobal::isDOSType (const QString &aOSTypeId)
|
---|
3030 | {
|
---|
3031 | if (aOSTypeId.left (3) == "dos" ||
|
---|
3032 | aOSTypeId.left (3) == "win" ||
|
---|
3033 | aOSTypeId.left (3) == "os2")
|
---|
3034 | return true;
|
---|
3035 |
|
---|
3036 | return false;
|
---|
3037 | }
|
---|
3038 |
|
---|
3039 | const char *gVBoxLangSubDir = "/nls";
|
---|
3040 | const char *gVBoxLangFileBase = "VirtualBox_";
|
---|
3041 | const char *gVBoxLangFileExt = ".qm";
|
---|
3042 | const char *gVBoxLangIDRegExp = "(([a-z]{2})(?:_([A-Z]{2}))?)|(C)";
|
---|
3043 | const char *gVBoxBuiltInLangName = "C";
|
---|
3044 |
|
---|
3045 | class VBoxTranslator : public QTranslator
|
---|
3046 | {
|
---|
3047 | public:
|
---|
3048 |
|
---|
3049 | VBoxTranslator (QObject *aParent = 0)
|
---|
3050 | : QTranslator (aParent) {}
|
---|
3051 |
|
---|
3052 | bool loadFile (const QString &aFileName)
|
---|
3053 | {
|
---|
3054 | QFile file (aFileName);
|
---|
3055 | if (!file.open (QIODevice::ReadOnly))
|
---|
3056 | return false;
|
---|
3057 | mData = file.readAll();
|
---|
3058 | return load ((uchar*) mData.data(), mData.size());
|
---|
3059 | }
|
---|
3060 |
|
---|
3061 | private:
|
---|
3062 |
|
---|
3063 | QByteArray mData;
|
---|
3064 | };
|
---|
3065 |
|
---|
3066 | static VBoxTranslator *sTranslator = 0;
|
---|
3067 | static QString sLoadedLangId = gVBoxBuiltInLangName;
|
---|
3068 |
|
---|
3069 | /**
|
---|
3070 | * Returns the loaded (active) language ID.
|
---|
3071 | * Note that it may not match with VBoxGlobalSettings::languageId() if the
|
---|
3072 | * specified language cannot be loaded.
|
---|
3073 | * If the built-in language is active, this method returns "C".
|
---|
3074 | *
|
---|
3075 | * @note "C" is treated as the built-in language for simplicity -- the C
|
---|
3076 | * locale is used in unix environments as a fallback when the requested
|
---|
3077 | * locale is invalid. This way we don't need to process both the "built_in"
|
---|
3078 | * language and the "C" language (which is a valid environment setting)
|
---|
3079 | * separately.
|
---|
3080 | */
|
---|
3081 | /* static */
|
---|
3082 | QString VBoxGlobal::languageId()
|
---|
3083 | {
|
---|
3084 | return sLoadedLangId;
|
---|
3085 | }
|
---|
3086 |
|
---|
3087 | /**
|
---|
3088 | * Loads the language by language ID.
|
---|
3089 | *
|
---|
3090 | * @param aLangId Language ID in in form of xx_YY. QString::null means the
|
---|
3091 | * system default language.
|
---|
3092 | */
|
---|
3093 | /* static */
|
---|
3094 | void VBoxGlobal::loadLanguage (const QString &aLangId)
|
---|
3095 | {
|
---|
3096 | QString langId = aLangId.isEmpty() ?
|
---|
3097 | VBoxGlobal::systemLanguageId() : aLangId;
|
---|
3098 | QString languageFileName;
|
---|
3099 | QString selectedLangId = gVBoxBuiltInLangName;
|
---|
3100 |
|
---|
3101 | /* If C is selected we change it temporary to en. This makes sure any extra
|
---|
3102 | * "en" translation file will be loaded. This is necessary for loading the
|
---|
3103 | * plural forms of some of our translations. */
|
---|
3104 | bool fResetToC = false;
|
---|
3105 | if (langId == "C")
|
---|
3106 | {
|
---|
3107 | langId = "en";
|
---|
3108 | fResetToC = true;
|
---|
3109 | }
|
---|
3110 |
|
---|
3111 | char szNlsPath[RTPATH_MAX];
|
---|
3112 | int rc;
|
---|
3113 |
|
---|
3114 | rc = RTPathAppPrivateNoArch(szNlsPath, sizeof(szNlsPath));
|
---|
3115 | AssertRC (rc);
|
---|
3116 |
|
---|
3117 | QString nlsPath = QString(szNlsPath) + gVBoxLangSubDir;
|
---|
3118 | QDir nlsDir (nlsPath);
|
---|
3119 |
|
---|
3120 | Assert (!langId.isEmpty());
|
---|
3121 | if (!langId.isEmpty() && langId != gVBoxBuiltInLangName)
|
---|
3122 | {
|
---|
3123 | QRegExp regExp (gVBoxLangIDRegExp);
|
---|
3124 | int pos = regExp.indexIn (langId);
|
---|
3125 | /* the language ID should match the regexp completely */
|
---|
3126 | AssertReturnVoid (pos == 0);
|
---|
3127 |
|
---|
3128 | QString lang = regExp.cap (2);
|
---|
3129 |
|
---|
3130 | if (nlsDir.exists (gVBoxLangFileBase + langId + gVBoxLangFileExt))
|
---|
3131 | {
|
---|
3132 | languageFileName = nlsDir.absoluteFilePath (gVBoxLangFileBase + langId +
|
---|
3133 | gVBoxLangFileExt);
|
---|
3134 | selectedLangId = langId;
|
---|
3135 | }
|
---|
3136 | else if (nlsDir.exists (gVBoxLangFileBase + lang + gVBoxLangFileExt))
|
---|
3137 | {
|
---|
3138 | languageFileName = nlsDir.absoluteFilePath (gVBoxLangFileBase + lang +
|
---|
3139 | gVBoxLangFileExt);
|
---|
3140 | selectedLangId = lang;
|
---|
3141 | }
|
---|
3142 | else
|
---|
3143 | {
|
---|
3144 | /* Never complain when the default language is requested. In any
|
---|
3145 | * case, if no explicit language file exists, we will simply
|
---|
3146 | * fall-back to English (built-in). */
|
---|
3147 | if (!aLangId.isNull() && langId != "en")
|
---|
3148 | vboxProblem().cannotFindLanguage (langId, nlsPath);
|
---|
3149 | /* selectedLangId remains built-in here */
|
---|
3150 | AssertReturnVoid (selectedLangId == gVBoxBuiltInLangName);
|
---|
3151 | }
|
---|
3152 | }
|
---|
3153 |
|
---|
3154 | /* delete the old translator if there is one */
|
---|
3155 | if (sTranslator)
|
---|
3156 | {
|
---|
3157 | /* QTranslator destructor will call qApp->removeTranslator() for
|
---|
3158 | * us. It will also delete all its child translations we attach to it
|
---|
3159 | * below, so we don't have to care about them specially. */
|
---|
3160 | delete sTranslator;
|
---|
3161 | }
|
---|
3162 |
|
---|
3163 | /* load new language files */
|
---|
3164 | sTranslator = new VBoxTranslator (qApp);
|
---|
3165 | Assert (sTranslator);
|
---|
3166 | bool loadOk = true;
|
---|
3167 | if (sTranslator)
|
---|
3168 | {
|
---|
3169 | if (selectedLangId != gVBoxBuiltInLangName)
|
---|
3170 | {
|
---|
3171 | Assert (!languageFileName.isNull());
|
---|
3172 | loadOk = sTranslator->loadFile (languageFileName);
|
---|
3173 | }
|
---|
3174 | /* we install the translator in any case: on failure, this will
|
---|
3175 | * activate an empty translator that will give us English
|
---|
3176 | * (built-in) */
|
---|
3177 | qApp->installTranslator (sTranslator);
|
---|
3178 | }
|
---|
3179 | else
|
---|
3180 | loadOk = false;
|
---|
3181 |
|
---|
3182 | if (loadOk)
|
---|
3183 | sLoadedLangId = selectedLangId;
|
---|
3184 | else
|
---|
3185 | {
|
---|
3186 | vboxProblem().cannotLoadLanguage (languageFileName);
|
---|
3187 | sLoadedLangId = gVBoxBuiltInLangName;
|
---|
3188 | }
|
---|
3189 |
|
---|
3190 | /* Try to load the corresponding Qt translation */
|
---|
3191 | if (sLoadedLangId != gVBoxBuiltInLangName)
|
---|
3192 | {
|
---|
3193 | #ifdef Q_OS_UNIX
|
---|
3194 | /* We use system installations of Qt on Linux systems, so first, try
|
---|
3195 | * to load the Qt translation from the system location. */
|
---|
3196 | languageFileName = QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" +
|
---|
3197 | sLoadedLangId + gVBoxLangFileExt;
|
---|
3198 | QTranslator *qtSysTr = new QTranslator (sTranslator);
|
---|
3199 | Assert (qtSysTr);
|
---|
3200 | if (qtSysTr && qtSysTr->load (languageFileName))
|
---|
3201 | qApp->installTranslator (qtSysTr);
|
---|
3202 | /* Note that the Qt translation supplied by Oracle is always loaded
|
---|
3203 | * afterwards to make sure it will take precedence over the system
|
---|
3204 | * translation (it may contain more decent variants of translation
|
---|
3205 | * that better correspond to VirtualBox UI). We need to load both
|
---|
3206 | * because a newer version of Qt may be installed on the user computer
|
---|
3207 | * and the Oracle version may not fully support it. We don't do it on
|
---|
3208 | * Win32 because we supply a Qt library there and therefore the
|
---|
3209 | * Oracle translation is always the best one. */
|
---|
3210 | #endif
|
---|
3211 | languageFileName = nlsDir.absoluteFilePath (QString ("qt_") +
|
---|
3212 | sLoadedLangId +
|
---|
3213 | gVBoxLangFileExt);
|
---|
3214 | QTranslator *qtTr = new QTranslator (sTranslator);
|
---|
3215 | Assert (qtTr);
|
---|
3216 | if (qtTr && (loadOk = qtTr->load (languageFileName)))
|
---|
3217 | qApp->installTranslator (qtTr);
|
---|
3218 | /* The below message doesn't fit 100% (because it's an additional
|
---|
3219 | * language and the main one won't be reset to built-in on failure)
|
---|
3220 | * but the load failure is so rare here that it's not worth a separate
|
---|
3221 | * message (but still, having something is better than having none) */
|
---|
3222 | if (!loadOk && !aLangId.isNull())
|
---|
3223 | vboxProblem().cannotLoadLanguage (languageFileName);
|
---|
3224 | }
|
---|
3225 | if (fResetToC)
|
---|
3226 | sLoadedLangId = "C";
|
---|
3227 | #ifdef Q_WS_MAC
|
---|
3228 | /* Qt doesn't translate the items in the Application menu initially.
|
---|
3229 | * Manually trigger an update. */
|
---|
3230 | ::darwinRetranslateAppMenu();
|
---|
3231 | #endif /* Q_WS_MAC */
|
---|
3232 | }
|
---|
3233 |
|
---|
3234 | QString VBoxGlobal::helpFile() const
|
---|
3235 | {
|
---|
3236 | #if defined (Q_WS_WIN32)
|
---|
3237 | const QString name = "VirtualBox";
|
---|
3238 | const QString suffix = "chm";
|
---|
3239 | #elif defined (Q_WS_MAC)
|
---|
3240 | const QString name = "UserManual";
|
---|
3241 | const QString suffix = "pdf";
|
---|
3242 | #elif defined (Q_WS_X11)
|
---|
3243 | # if defined VBOX_OSE
|
---|
3244 | const QString name = "UserManual";
|
---|
3245 | const QString suffix = "pdf";
|
---|
3246 | # else
|
---|
3247 | const QString name = "VirtualBox";
|
---|
3248 | const QString suffix = "chm";
|
---|
3249 | # endif
|
---|
3250 | #endif
|
---|
3251 | /* Where are the docs located? */
|
---|
3252 | char szDocsPath[RTPATH_MAX];
|
---|
3253 | int rc = RTPathAppDocs (szDocsPath, sizeof (szDocsPath));
|
---|
3254 | AssertRC (rc);
|
---|
3255 | /* Make sure that the language is in two letter code.
|
---|
3256 | * Note: if languageId() returns an empty string lang.name() will
|
---|
3257 | * return "C" which is an valid language code. */
|
---|
3258 | QLocale lang (VBoxGlobal::languageId());
|
---|
3259 |
|
---|
3260 | /* Construct the path and the filename */
|
---|
3261 | QString manual = QString ("%1/%2_%3.%4").arg (szDocsPath)
|
---|
3262 | .arg (name)
|
---|
3263 | .arg (lang.name())
|
---|
3264 | .arg (suffix);
|
---|
3265 | /* Check if a help file with that name exists */
|
---|
3266 | QFileInfo fi (manual);
|
---|
3267 | if (fi.exists())
|
---|
3268 | return manual;
|
---|
3269 |
|
---|
3270 | /* Fall back to the standard */
|
---|
3271 | manual = QString ("%1/%2.%4").arg (szDocsPath)
|
---|
3272 | .arg (name)
|
---|
3273 | .arg (suffix);
|
---|
3274 | return manual;
|
---|
3275 | }
|
---|
3276 |
|
---|
3277 | /**
|
---|
3278 | * Replacement for QToolButton::setTextLabel() that handles the shortcut
|
---|
3279 | * letter (if it is present in the argument string) as if it were a setText()
|
---|
3280 | * call: the shortcut letter is used to automatically assign an "Alt+<letter>"
|
---|
3281 | * accelerator key sequence to the given tool button.
|
---|
3282 | *
|
---|
3283 | * @note This method preserves the icon set if it was assigned before. Only
|
---|
3284 | * the text label and the accelerator are changed.
|
---|
3285 | *
|
---|
3286 | * @param aToolButton Tool button to set the text label on.
|
---|
3287 | * @param aTextLabel Text label to set.
|
---|
3288 | */
|
---|
3289 | /* static */
|
---|
3290 | void VBoxGlobal::setTextLabel (QToolButton *aToolButton,
|
---|
3291 | const QString &aTextLabel)
|
---|
3292 | {
|
---|
3293 | AssertReturnVoid (aToolButton != NULL);
|
---|
3294 |
|
---|
3295 | /* remember the icon set as setText() will kill it */
|
---|
3296 | QIcon iset = aToolButton->icon();
|
---|
3297 | /* re-use the setText() method to detect and set the accelerator */
|
---|
3298 | aToolButton->setText (aTextLabel);
|
---|
3299 | QKeySequence accel = aToolButton->shortcut();
|
---|
3300 | aToolButton->setText (aTextLabel);
|
---|
3301 | aToolButton->setIcon (iset);
|
---|
3302 | /* set the accel last as setIconSet() would kill it */
|
---|
3303 | aToolButton->setShortcut (accel);
|
---|
3304 | }
|
---|
3305 |
|
---|
3306 | /**
|
---|
3307 | * Performs direct and flipped search of position for \a aRectangle to make sure
|
---|
3308 | * it is fully contained inside \a aBoundRegion region by moving & resizing
|
---|
3309 | * \a aRectangle if necessary. Selects the minimum shifted result between direct
|
---|
3310 | * and flipped variants.
|
---|
3311 | */
|
---|
3312 | /* static */
|
---|
3313 | QRect VBoxGlobal::normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
|
---|
3314 | bool aCanResize /* = true */)
|
---|
3315 | {
|
---|
3316 | /* Direct search for normalized rectangle */
|
---|
3317 | QRect var1 (getNormalized (aRectangle, aBoundRegion, aCanResize));
|
---|
3318 |
|
---|
3319 | /* Flipped search for normalized rectangle */
|
---|
3320 | QRect var2 (flip (getNormalized (flip (aRectangle).boundingRect(),
|
---|
3321 | flip (aBoundRegion), aCanResize)).boundingRect());
|
---|
3322 |
|
---|
3323 | /* Calculate shift from starting position for both variants */
|
---|
3324 | double length1 = sqrt (pow ((double) (var1.x() - aRectangle.x()), (double) 2) +
|
---|
3325 | pow ((double) (var1.y() - aRectangle.y()), (double) 2));
|
---|
3326 | double length2 = sqrt (pow ((double) (var2.x() - aRectangle.x()), (double) 2) +
|
---|
3327 | pow ((double) (var2.y() - aRectangle.y()), (double) 2));
|
---|
3328 |
|
---|
3329 | /* Return minimum shifted variant */
|
---|
3330 | return length1 > length2 ? var2 : var1;
|
---|
3331 | }
|
---|
3332 |
|
---|
3333 | /**
|
---|
3334 | * Ensures that the given rectangle \a aRectangle is fully contained within the
|
---|
3335 | * region \a aBoundRegion by moving \a aRectangle if necessary. If \a aRectangle is
|
---|
3336 | * larger than \a aBoundRegion, top left corner of \a aRectangle is aligned with the
|
---|
3337 | * top left corner of maximum available rectangle and, if \a aCanResize is true,
|
---|
3338 | * \a aRectangle is shrinked to become fully visible.
|
---|
3339 | */
|
---|
3340 | /* static */
|
---|
3341 | QRect VBoxGlobal::getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
|
---|
3342 | bool /* aCanResize = true */)
|
---|
3343 | {
|
---|
3344 | /* Storing available horizontal sub-rectangles & vertical shifts */
|
---|
3345 | int windowVertical = aRectangle.center().y();
|
---|
3346 | QVector <QRect> rectanglesVector (aBoundRegion.rects());
|
---|
3347 | QList <QRect> rectanglesList;
|
---|
3348 | QList <int> shiftsList;
|
---|
3349 | foreach (QRect currentItem, rectanglesVector)
|
---|
3350 | {
|
---|
3351 | int currentDelta = qAbs (windowVertical - currentItem.center().y());
|
---|
3352 | int shift2Top = currentItem.top() - aRectangle.top();
|
---|
3353 | int shift2Bot = currentItem.bottom() - aRectangle.bottom();
|
---|
3354 |
|
---|
3355 | int itemPosition = 0;
|
---|
3356 | foreach (QRect item, rectanglesList)
|
---|
3357 | {
|
---|
3358 | int delta = qAbs (windowVertical - item.center().y());
|
---|
3359 | if (delta > currentDelta) break; else ++ itemPosition;
|
---|
3360 | }
|
---|
3361 | rectanglesList.insert (itemPosition, currentItem);
|
---|
3362 |
|
---|
3363 | int shift2TopPos = 0;
|
---|
3364 | foreach (int shift, shiftsList)
|
---|
3365 | if (qAbs (shift) > qAbs (shift2Top)) break; else ++ shift2TopPos;
|
---|
3366 | shiftsList.insert (shift2TopPos, shift2Top);
|
---|
3367 |
|
---|
3368 | int shift2BotPos = 0;
|
---|
3369 | foreach (int shift, shiftsList)
|
---|
3370 | if (qAbs (shift) > qAbs (shift2Bot)) break; else ++ shift2BotPos;
|
---|
3371 | shiftsList.insert (shift2BotPos, shift2Bot);
|
---|
3372 | }
|
---|
3373 |
|
---|
3374 | /* Trying to find the appropriate place for window */
|
---|
3375 | QRect result;
|
---|
3376 | for (int i = -1; i < shiftsList.size(); ++ i)
|
---|
3377 | {
|
---|
3378 | /* Move to appropriate vertical */
|
---|
3379 | QRect rectangle (aRectangle);
|
---|
3380 | if (i >= 0) rectangle.translate (0, shiftsList [i]);
|
---|
3381 |
|
---|
3382 | /* Search horizontal shift */
|
---|
3383 | int maxShift = 0;
|
---|
3384 | foreach (QRect item, rectanglesList)
|
---|
3385 | {
|
---|
3386 | QRect trectangle (rectangle.translated (item.left() - rectangle.left(), 0));
|
---|
3387 | if (!item.intersects (trectangle))
|
---|
3388 | continue;
|
---|
3389 |
|
---|
3390 | if (rectangle.left() < item.left())
|
---|
3391 | {
|
---|
3392 | int shift = item.left() - rectangle.left();
|
---|
3393 | maxShift = qAbs (shift) > qAbs (maxShift) ? shift : maxShift;
|
---|
3394 | }
|
---|
3395 | else if (rectangle.right() > item.right())
|
---|
3396 | {
|
---|
3397 | int shift = item.right() - rectangle.right();
|
---|
3398 | maxShift = qAbs (shift) > qAbs (maxShift) ? shift : maxShift;
|
---|
3399 | }
|
---|
3400 | }
|
---|
3401 |
|
---|
3402 | /* Shift across the horizontal direction */
|
---|
3403 | rectangle.translate (maxShift, 0);
|
---|
3404 |
|
---|
3405 | /* Check the translated rectangle to feat the rules */
|
---|
3406 | if (aBoundRegion.united (rectangle) == aBoundRegion)
|
---|
3407 | result = rectangle;
|
---|
3408 |
|
---|
3409 | if (!result.isNull()) break;
|
---|
3410 | }
|
---|
3411 |
|
---|
3412 | if (result.isNull())
|
---|
3413 | {
|
---|
3414 | /* Resize window to feat desirable size
|
---|
3415 | * using max of available rectangles */
|
---|
3416 | QRect maxRectangle;
|
---|
3417 | quint64 maxSquare = 0;
|
---|
3418 | foreach (QRect item, rectanglesList)
|
---|
3419 | {
|
---|
3420 | quint64 square = item.width() * item.height();
|
---|
3421 | if (square > maxSquare)
|
---|
3422 | {
|
---|
3423 | maxSquare = square;
|
---|
3424 | maxRectangle = item;
|
---|
3425 | }
|
---|
3426 | }
|
---|
3427 |
|
---|
3428 | result = aRectangle;
|
---|
3429 | result.moveTo (maxRectangle.x(), maxRectangle.y());
|
---|
3430 | if (maxRectangle.right() < result.right())
|
---|
3431 | result.setRight (maxRectangle.right());
|
---|
3432 | if (maxRectangle.bottom() < result.bottom())
|
---|
3433 | result.setBottom (maxRectangle.bottom());
|
---|
3434 | }
|
---|
3435 |
|
---|
3436 | return result;
|
---|
3437 | }
|
---|
3438 |
|
---|
3439 | /**
|
---|
3440 | * Returns the flipped (transposed) region.
|
---|
3441 | */
|
---|
3442 | /* static */
|
---|
3443 | QRegion VBoxGlobal::flip (const QRegion &aRegion)
|
---|
3444 | {
|
---|
3445 | QRegion result;
|
---|
3446 | QVector <QRect> rectangles (aRegion.rects());
|
---|
3447 | foreach (QRect rectangle, rectangles)
|
---|
3448 | result += QRect (rectangle.y(), rectangle.x(),
|
---|
3449 | rectangle.height(), rectangle.width());
|
---|
3450 | return result;
|
---|
3451 | }
|
---|
3452 |
|
---|
3453 | /**
|
---|
3454 | * Aligns the center of \a aWidget with the center of \a aRelative.
|
---|
3455 | *
|
---|
3456 | * If necessary, \a aWidget's position is adjusted to make it fully visible
|
---|
3457 | * within the available desktop area. If \a aWidget is bigger then this area,
|
---|
3458 | * it will also be resized unless \a aCanResize is false or there is an
|
---|
3459 | * inappropriate minimum size limit (in which case the top left corner will be
|
---|
3460 | * simply aligned with the top left corner of the available desktop area).
|
---|
3461 | *
|
---|
3462 | * \a aWidget must be a top-level widget. \a aRelative may be any widget, but
|
---|
3463 | * if it's not top-level itself, its top-level widget will be used for
|
---|
3464 | * calculations. \a aRelative can also be NULL, in which case \a aWidget will
|
---|
3465 | * be centered relative to the available desktop area.
|
---|
3466 | */
|
---|
3467 | /* static */
|
---|
3468 | void VBoxGlobal::centerWidget (QWidget *aWidget, QWidget *aRelative,
|
---|
3469 | bool aCanResize /* = true */)
|
---|
3470 | {
|
---|
3471 | AssertReturnVoid (aWidget);
|
---|
3472 | AssertReturnVoid (aWidget->isTopLevel());
|
---|
3473 |
|
---|
3474 | QRect deskGeo, parentGeo;
|
---|
3475 | QWidget *w = aRelative;
|
---|
3476 | if (w)
|
---|
3477 | {
|
---|
3478 | w = w->window();
|
---|
3479 | deskGeo = QApplication::desktop()->availableGeometry (w);
|
---|
3480 | parentGeo = w->frameGeometry();
|
---|
3481 | /* On X11/Gnome, geo/frameGeo.x() and y() are always 0 for top level
|
---|
3482 | * widgets with parents, what a shame. Use mapToGlobal() to workaround. */
|
---|
3483 | QPoint d = w->mapToGlobal (QPoint (0, 0));
|
---|
3484 | d.rx() -= w->geometry().x() - w->x();
|
---|
3485 | d.ry() -= w->geometry().y() - w->y();
|
---|
3486 | parentGeo.moveTopLeft (d);
|
---|
3487 | }
|
---|
3488 | else
|
---|
3489 | {
|
---|
3490 | deskGeo = QApplication::desktop()->availableGeometry();
|
---|
3491 | parentGeo = deskGeo;
|
---|
3492 | }
|
---|
3493 |
|
---|
3494 | /* On X11, there is no way to determine frame geometry (including WM
|
---|
3495 | * decorations) before the widget is shown for the first time. Stupidly
|
---|
3496 | * enumerate other top level widgets to find the thickest frame. The code
|
---|
3497 | * is based on the idea taken from QDialog::adjustPositionInternal(). */
|
---|
3498 |
|
---|
3499 | int extraw = 0, extrah = 0;
|
---|
3500 |
|
---|
3501 | QWidgetList list = QApplication::topLevelWidgets();
|
---|
3502 | QListIterator<QWidget*> it (list);
|
---|
3503 | while ((extraw == 0 || extrah == 0) && it.hasNext())
|
---|
3504 | {
|
---|
3505 | int framew, frameh;
|
---|
3506 | QWidget *current = it.next();
|
---|
3507 | if (!current->isVisible())
|
---|
3508 | continue;
|
---|
3509 |
|
---|
3510 | framew = current->frameGeometry().width() - current->width();
|
---|
3511 | frameh = current->frameGeometry().height() - current->height();
|
---|
3512 |
|
---|
3513 | extraw = qMax (extraw, framew);
|
---|
3514 | extrah = qMax (extrah, frameh);
|
---|
3515 | }
|
---|
3516 |
|
---|
3517 | /// @todo (r=dmik) not sure if we really need this
|
---|
3518 | #if 0
|
---|
3519 | /* sanity check for decoration frames. With embedding, we
|
---|
3520 | * might get extraordinary values */
|
---|
3521 | if (extraw == 0 || extrah == 0 || extraw > 20 || extrah > 50)
|
---|
3522 | {
|
---|
3523 | extrah = 50;
|
---|
3524 | extraw = 20;
|
---|
3525 | }
|
---|
3526 | #endif
|
---|
3527 |
|
---|
3528 | /* On non-X11 platforms, the following would be enough instead of the
|
---|
3529 | * above workaround: */
|
---|
3530 | // QRect geo = frameGeometry();
|
---|
3531 | QRect geo = QRect (0, 0, aWidget->width() + extraw,
|
---|
3532 | aWidget->height() + extrah);
|
---|
3533 |
|
---|
3534 | geo.moveCenter (QPoint (parentGeo.x() + (parentGeo.width() - 1) / 2,
|
---|
3535 | parentGeo.y() + (parentGeo.height() - 1) / 2));
|
---|
3536 |
|
---|
3537 | /* ensure the widget is within the available desktop area */
|
---|
3538 | QRect newGeo = normalizeGeometry (geo, deskGeo, aCanResize);
|
---|
3539 | #ifdef Q_WS_MAC
|
---|
3540 | /* No idea why, but Qt doesn't respect if there is a unified toolbar on the
|
---|
3541 | * ::move call. So manually add the height of the toolbar before setting
|
---|
3542 | * the position. */
|
---|
3543 | if (w)
|
---|
3544 | newGeo.translate (0, ::darwinWindowToolBarHeight (aWidget));
|
---|
3545 | #endif /* Q_WS_MAC */
|
---|
3546 |
|
---|
3547 | aWidget->move (newGeo.topLeft());
|
---|
3548 |
|
---|
3549 | if (aCanResize &&
|
---|
3550 | (geo.width() != newGeo.width() || geo.height() != newGeo.height()))
|
---|
3551 | aWidget->resize (newGeo.width() - extraw, newGeo.height() - extrah);
|
---|
3552 | }
|
---|
3553 |
|
---|
3554 | /**
|
---|
3555 | * Returns the decimal separator for the current locale.
|
---|
3556 | */
|
---|
3557 | /* static */
|
---|
3558 | QChar VBoxGlobal::decimalSep()
|
---|
3559 | {
|
---|
3560 | return QLocale::system().decimalPoint();
|
---|
3561 | }
|
---|
3562 |
|
---|
3563 | /**
|
---|
3564 | * Returns the regexp string that defines the format of the human-readable
|
---|
3565 | * size representation, <tt>####[.##] B|KB|MB|GB|TB|PB</tt>.
|
---|
3566 | *
|
---|
3567 | * This regexp will capture 5 groups of text:
|
---|
3568 | * - cap(1): integer number in case when no decimal point is present
|
---|
3569 | * (if empty, it means that decimal point is present)
|
---|
3570 | * - cap(2): size suffix in case when no decimal point is present (may be empty)
|
---|
3571 | * - cap(3): integer number in case when decimal point is present (may be empty)
|
---|
3572 | * - cap(4): fraction number (hundredth) in case when decimal point is present
|
---|
3573 | * - cap(5): size suffix in case when decimal point is present (note that
|
---|
3574 | * B cannot appear there)
|
---|
3575 | */
|
---|
3576 | /* static */
|
---|
3577 | QString VBoxGlobal::sizeRegexp()
|
---|
3578 | {
|
---|
3579 | QString regexp =
|
---|
3580 | QString ("^(?:(?:(\\d+)(?:\\s?(%2|%3|%4|%5|%6|%7))?)|(?:(\\d*)%1(\\d{1,2})(?:\\s?(%3|%4|%5|%6|%7))))$")
|
---|
3581 | .arg (decimalSep())
|
---|
3582 | .arg (tr ("B", "size suffix Bytes"))
|
---|
3583 | .arg (tr ("KB", "size suffix KBytes=1024 Bytes"))
|
---|
3584 | .arg (tr ("MB", "size suffix MBytes=1024 KBytes"))
|
---|
3585 | .arg (tr ("GB", "size suffix GBytes=1024 MBytes"))
|
---|
3586 | .arg (tr ("TB", "size suffix TBytes=1024 GBytes"))
|
---|
3587 | .arg (tr ("PB", "size suffix PBytes=1024 TBytes"));
|
---|
3588 | return regexp;
|
---|
3589 | }
|
---|
3590 |
|
---|
3591 | /* static */
|
---|
3592 | QString VBoxGlobal::toHumanReadableList(const QStringList &list)
|
---|
3593 | {
|
---|
3594 | QString strList;
|
---|
3595 | if (list.size() == 1)
|
---|
3596 | strList = list.at(0);
|
---|
3597 | else if (list.size() > 1)
|
---|
3598 | {
|
---|
3599 | for (int i = 0; i < list.size() - 1; ++i)
|
---|
3600 | {
|
---|
3601 | strList += list.at(i);
|
---|
3602 | if (i < list.size() - 2)
|
---|
3603 | strList += + ", ";
|
---|
3604 | }
|
---|
3605 | strList += " " + tr("and") + " " + list.at(list.size() - 1);
|
---|
3606 | }
|
---|
3607 | return strList;
|
---|
3608 | }
|
---|
3609 |
|
---|
3610 | /**
|
---|
3611 | * Parses the given size string that should be in form of
|
---|
3612 | * <tt>####[.##] B|KB|MB|GB|TB|PB</tt> and returns
|
---|
3613 | * the size value in bytes. Zero is returned on error.
|
---|
3614 | */
|
---|
3615 | /* static */
|
---|
3616 | quint64 VBoxGlobal::parseSize (const QString &aText)
|
---|
3617 | {
|
---|
3618 | QRegExp regexp (sizeRegexp());
|
---|
3619 | int pos = regexp.indexIn (aText);
|
---|
3620 | if (pos != -1)
|
---|
3621 | {
|
---|
3622 | QString intgS = regexp.cap (1);
|
---|
3623 | QString hundS;
|
---|
3624 | QString suff = regexp.cap (2);
|
---|
3625 | if (intgS.isEmpty())
|
---|
3626 | {
|
---|
3627 | intgS = regexp.cap (3);
|
---|
3628 | hundS = regexp.cap (4);
|
---|
3629 | suff = regexp.cap (5);
|
---|
3630 | }
|
---|
3631 |
|
---|
3632 | quint64 denom = 0;
|
---|
3633 | if (suff.isEmpty() || suff == tr ("B", "size suffix Bytes"))
|
---|
3634 | denom = 1;
|
---|
3635 | else if (suff == tr ("KB", "size suffix KBytes=1024 Bytes"))
|
---|
3636 | denom = _1K;
|
---|
3637 | else if (suff == tr ("MB", "size suffix MBytes=1024 KBytes"))
|
---|
3638 | denom = _1M;
|
---|
3639 | else if (suff == tr ("GB", "size suffix GBytes=1024 MBytes"))
|
---|
3640 | denom = _1G;
|
---|
3641 | else if (suff == tr ("TB", "size suffix TBytes=1024 GBytes"))
|
---|
3642 | denom = _1T;
|
---|
3643 | else if (suff == tr ("PB", "size suffix PBytes=1024 TBytes"))
|
---|
3644 | denom = _1P;
|
---|
3645 |
|
---|
3646 | quint64 intg = intgS.toULongLong();
|
---|
3647 | if (denom == 1)
|
---|
3648 | return intg;
|
---|
3649 |
|
---|
3650 | quint64 hund = hundS.leftJustified (2, '0').toULongLong();
|
---|
3651 | hund = hund * denom / 100;
|
---|
3652 | intg = intg * denom + hund;
|
---|
3653 | return intg;
|
---|
3654 | }
|
---|
3655 | else
|
---|
3656 | return 0;
|
---|
3657 | }
|
---|
3658 |
|
---|
3659 | /**
|
---|
3660 | * Formats the given @a aSize value in bytes to a human readable string
|
---|
3661 | * in form of <tt>####[.##] B|KB|MB|GB|TB|PB</tt>.
|
---|
3662 | *
|
---|
3663 | * The @a aMode and @a aDecimal parameters are used for rounding the resulting
|
---|
3664 | * number when converting the size value to KB, MB, etc gives a fractional part:
|
---|
3665 | * <ul>
|
---|
3666 | * <li>When \a aMode is FormatSize_Round, the result is rounded to the
|
---|
3667 | * closest number containing \a aDecimal decimal digits.
|
---|
3668 | * </li>
|
---|
3669 | * <li>When \a aMode is FormatSize_RoundDown, the result is rounded to the
|
---|
3670 | * largest number with \a aDecimal decimal digits that is not greater than
|
---|
3671 | * the result. This guarantees that converting the resulting string back to
|
---|
3672 | * the integer value in bytes will not produce a value greater that the
|
---|
3673 | * initial size parameter.
|
---|
3674 | * </li>
|
---|
3675 | * <li>When \a aMode is FormatSize_RoundUp, the result is rounded to the
|
---|
3676 | * smallest number with \a aDecimal decimal digits that is not less than the
|
---|
3677 | * result. This guarantees that converting the resulting string back to the
|
---|
3678 | * integer value in bytes will not produce a value less that the initial
|
---|
3679 | * size parameter.
|
---|
3680 | * </li>
|
---|
3681 | * </ul>
|
---|
3682 | *
|
---|
3683 | * @param aSize Size value in bytes.
|
---|
3684 | * @param aMode Conversion mode.
|
---|
3685 | * @param aDecimal Number of decimal digits in result.
|
---|
3686 | * @return Human-readable size string.
|
---|
3687 | */
|
---|
3688 | /* static */
|
---|
3689 | QString VBoxGlobal::formatSize (quint64 aSize, uint aDecimal /* = 2 */,
|
---|
3690 | VBoxDefs::FormatSize aMode /* = FormatSize_Round */)
|
---|
3691 | {
|
---|
3692 | static QString Suffixes [7];
|
---|
3693 | Suffixes[0] = tr ("B", "size suffix Bytes");
|
---|
3694 | Suffixes[1] = tr ("KB", "size suffix KBytes=1024 Bytes");
|
---|
3695 | Suffixes[2] = tr ("MB", "size suffix MBytes=1024 KBytes");
|
---|
3696 | Suffixes[3] = tr ("GB", "size suffix GBytes=1024 MBytes");
|
---|
3697 | Suffixes[4] = tr ("TB", "size suffix TBytes=1024 GBytes");
|
---|
3698 | Suffixes[5] = tr ("PB", "size suffix PBytes=1024 TBytes");
|
---|
3699 | Suffixes[6] = (const char *)NULL;
|
---|
3700 | AssertCompile(6 < RT_ELEMENTS (Suffixes));
|
---|
3701 |
|
---|
3702 | quint64 denom = 0;
|
---|
3703 | int suffix = 0;
|
---|
3704 |
|
---|
3705 | if (aSize < _1K)
|
---|
3706 | {
|
---|
3707 | denom = 1;
|
---|
3708 | suffix = 0;
|
---|
3709 | }
|
---|
3710 | else if (aSize < _1M)
|
---|
3711 | {
|
---|
3712 | denom = _1K;
|
---|
3713 | suffix = 1;
|
---|
3714 | }
|
---|
3715 | else if (aSize < _1G)
|
---|
3716 | {
|
---|
3717 | denom = _1M;
|
---|
3718 | suffix = 2;
|
---|
3719 | }
|
---|
3720 | else if (aSize < _1T)
|
---|
3721 | {
|
---|
3722 | denom = _1G;
|
---|
3723 | suffix = 3;
|
---|
3724 | }
|
---|
3725 | else if (aSize < _1P)
|
---|
3726 | {
|
---|
3727 | denom = _1T;
|
---|
3728 | suffix = 4;
|
---|
3729 | }
|
---|
3730 | else
|
---|
3731 | {
|
---|
3732 | denom = _1P;
|
---|
3733 | suffix = 5;
|
---|
3734 | }
|
---|
3735 |
|
---|
3736 | quint64 intg = aSize / denom;
|
---|
3737 | quint64 decm = aSize % denom;
|
---|
3738 | quint64 mult = 1;
|
---|
3739 | for (uint i = 0; i < aDecimal; ++ i) mult *= 10;
|
---|
3740 |
|
---|
3741 | QString number;
|
---|
3742 | if (denom > 1)
|
---|
3743 | {
|
---|
3744 | if (decm)
|
---|
3745 | {
|
---|
3746 | decm *= mult;
|
---|
3747 | /* not greater */
|
---|
3748 | if (aMode == VBoxDefs::FormatSize_RoundDown)
|
---|
3749 | decm = decm / denom;
|
---|
3750 | /* not less */
|
---|
3751 | else if (aMode == VBoxDefs::FormatSize_RoundUp)
|
---|
3752 | decm = (decm + denom - 1) / denom;
|
---|
3753 | /* nearest */
|
---|
3754 | else decm = (decm + denom / 2) / denom;
|
---|
3755 | }
|
---|
3756 | /* check for the fractional part overflow due to rounding */
|
---|
3757 | if (decm == mult)
|
---|
3758 | {
|
---|
3759 | decm = 0;
|
---|
3760 | ++ intg;
|
---|
3761 | /* check if we've got 1024 XB after rounding and scale down if so */
|
---|
3762 | if (intg == 1024 && Suffixes [suffix + 1] != NULL)
|
---|
3763 | {
|
---|
3764 | intg /= 1024;
|
---|
3765 | ++ suffix;
|
---|
3766 | }
|
---|
3767 | }
|
---|
3768 | number = QString::number (intg);
|
---|
3769 | if (aDecimal) number += QString ("%1%2").arg (decimalSep())
|
---|
3770 | .arg (QString::number (decm).rightJustified (aDecimal, '0'));
|
---|
3771 | }
|
---|
3772 | else
|
---|
3773 | {
|
---|
3774 | number = QString::number (intg);
|
---|
3775 | }
|
---|
3776 |
|
---|
3777 | return QString ("%1 %2").arg (number).arg (Suffixes [suffix]);
|
---|
3778 | }
|
---|
3779 |
|
---|
3780 | /* static */
|
---|
3781 | bool VBoxGlobal::shouldWarnAboutToLowVRAM(const CMachine *pMachine /* = 0 */)
|
---|
3782 | {
|
---|
3783 | static QStringList osList = QStringList()
|
---|
3784 | << "Other" << "DOS" << "Netware" << "L4" << "QNX" << "JRockitVE";
|
---|
3785 |
|
---|
3786 | bool fResult = true;
|
---|
3787 | if ( pMachine
|
---|
3788 | && !pMachine->isNull()
|
---|
3789 | && osList.contains(pMachine->GetOSTypeId()))
|
---|
3790 | fResult = false;
|
---|
3791 |
|
---|
3792 | return fResult;
|
---|
3793 | }
|
---|
3794 |
|
---|
3795 | /**
|
---|
3796 | * Returns the required video memory in bytes for the current desktop
|
---|
3797 | * resolution at maximum possible screen depth in bpp.
|
---|
3798 | */
|
---|
3799 | /* static */
|
---|
3800 | quint64 VBoxGlobal::requiredVideoMemory (CMachine *aMachine /* = 0 */, int cMonitors /* = 1 */)
|
---|
3801 | {
|
---|
3802 | QSize desktopRes = QApplication::desktop()->screenGeometry().size();
|
---|
3803 | QDesktopWidget *pDW = QApplication::desktop();
|
---|
3804 | /* We create a list of the size of all available host monitors. This list
|
---|
3805 | * is sorted by value and by starting with the biggest one, we calculate
|
---|
3806 | * the memory requirements for every guest screen. This is of course not
|
---|
3807 | * correct, but as we can't predict on which host screens the user will
|
---|
3808 | * open the guest windows, this is the best assumption we can do, cause it
|
---|
3809 | * is the worst case. */
|
---|
3810 | QVector<int> screenSize(qMax(cMonitors, pDW->numScreens()), 0);
|
---|
3811 | for (int i = 0; i < pDW->numScreens(); ++i)
|
---|
3812 | {
|
---|
3813 | QRect r = pDW->screenGeometry(i);
|
---|
3814 | screenSize[i] = r.width() * r.height();
|
---|
3815 | }
|
---|
3816 | /* Now sort the vector */
|
---|
3817 | qSort(screenSize.begin(), screenSize.end(), qGreater<int>());
|
---|
3818 | /* For the case that there are more guest screens configured then host
|
---|
3819 | * screens available, replace all zeros with the greatest value in the
|
---|
3820 | * vector. */
|
---|
3821 | for (int i = 0; i < screenSize.size(); ++i)
|
---|
3822 | if (screenSize.at(i) == 0)
|
---|
3823 | screenSize.replace(i, screenSize.at(0));
|
---|
3824 |
|
---|
3825 | quint64 needBits = 0;
|
---|
3826 | for (int i = 0; i < cMonitors; ++i)
|
---|
3827 | {
|
---|
3828 | /* Calculate summary required memory amount in bits */
|
---|
3829 | needBits += (screenSize.at(i) * /* with x height */
|
---|
3830 | 32 + /* we will take the maximum possible bpp for now */
|
---|
3831 | 8 * _1M) + /* current cache per screen - may be changed in future */
|
---|
3832 | 8 * 4096; /* adapter info */
|
---|
3833 | }
|
---|
3834 | /* Translate value into megabytes with rounding to highest side */
|
---|
3835 | quint64 needMBytes = needBits % (8 * _1M) ? needBits / (8 * _1M) + 1 :
|
---|
3836 | needBits / (8 * _1M) /* convert to megabytes */;
|
---|
3837 |
|
---|
3838 | if (aMachine && !aMachine->isNull())
|
---|
3839 | {
|
---|
3840 | QString typeId = aMachine->GetOSTypeId();
|
---|
3841 | if (typeId.startsWith("Windows"))
|
---|
3842 | {
|
---|
3843 | /* Windows guests need offscreen VRAM too for graphics acceleration features. */
|
---|
3844 | #ifdef VBOX_WITH_CRHGSMI
|
---|
3845 | if (typeId == "WindowsVista" || typeId == "Windows7")
|
---|
3846 | {
|
---|
3847 | /* wddm mode, there are two surfaces for each screen: shadow & primary */
|
---|
3848 | needMBytes *= 3;
|
---|
3849 | }
|
---|
3850 | else
|
---|
3851 | #endif
|
---|
3852 | {
|
---|
3853 | needMBytes *= 2;
|
---|
3854 | }
|
---|
3855 | }
|
---|
3856 | }
|
---|
3857 |
|
---|
3858 | return needMBytes * _1M;
|
---|
3859 | }
|
---|
3860 |
|
---|
3861 | /**
|
---|
3862 | * Puts soft hyphens after every path component in the given file name.
|
---|
3863 | *
|
---|
3864 | * @param aFileName File name (must be a full path name).
|
---|
3865 | */
|
---|
3866 | /* static */
|
---|
3867 | QString VBoxGlobal::locationForHTML (const QString &aFileName)
|
---|
3868 | {
|
---|
3869 | /// @todo (dmik) remove?
|
---|
3870 | // QString result = QDir::toNativeSeparators (fn);
|
---|
3871 | //#ifdef Q_OS_LINUX
|
---|
3872 | // result.replace ('/', "/<font color=red>­</font>");
|
---|
3873 | //#else
|
---|
3874 | // result.replace ('\\', "\\<font color=red>­</font>");
|
---|
3875 | //#endif
|
---|
3876 | // return result;
|
---|
3877 | QFileInfo fi (aFileName);
|
---|
3878 | return fi.fileName();
|
---|
3879 | }
|
---|
3880 |
|
---|
3881 | /**
|
---|
3882 | * Reformats the input string @a aStr so that:
|
---|
3883 | * - strings in single quotes will be put inside <nobr> and marked
|
---|
3884 | * with blue color;
|
---|
3885 | * - UUIDs be put inside <nobr> and marked
|
---|
3886 | * with green color;
|
---|
3887 | * - replaces new line chars with </p><p> constructs to form paragraphs
|
---|
3888 | * (note that <p> and </p> are not appended to the beginning and to the
|
---|
3889 | * end of the string respectively, to allow the result be appended
|
---|
3890 | * or prepended to the existing paragraph).
|
---|
3891 | *
|
---|
3892 | * If @a aToolTip is true, colouring is not applied, only the <nobr> tag
|
---|
3893 | * is added. Also, new line chars are replaced with <br> instead of <p>.
|
---|
3894 | */
|
---|
3895 | /* static */
|
---|
3896 | QString VBoxGlobal::highlight (const QString &aStr, bool aToolTip /* = false */)
|
---|
3897 | {
|
---|
3898 | QString strFont;
|
---|
3899 | QString uuidFont;
|
---|
3900 | QString endFont;
|
---|
3901 | if (!aToolTip)
|
---|
3902 | {
|
---|
3903 | strFont = "<font color=#0000CC>";
|
---|
3904 | uuidFont = "<font color=#008000>";
|
---|
3905 | endFont = "</font>";
|
---|
3906 | }
|
---|
3907 |
|
---|
3908 | QString text = aStr;
|
---|
3909 |
|
---|
3910 | /* replace special entities, '&' -- first! */
|
---|
3911 | text.replace ('&', "&");
|
---|
3912 | text.replace ('<', "<");
|
---|
3913 | text.replace ('>', ">");
|
---|
3914 | text.replace ('\"', """);
|
---|
3915 |
|
---|
3916 | /* mark strings in single quotes with color */
|
---|
3917 | QRegExp rx = QRegExp ("((?:^|\\s)[(]?)'([^']*)'(?=[:.-!);]?(?:\\s|$))");
|
---|
3918 | rx.setMinimal (true);
|
---|
3919 | text.replace (rx,
|
---|
3920 | QString ("\\1%1<nobr>'\\2'</nobr>%2").arg (strFont).arg (endFont));
|
---|
3921 |
|
---|
3922 | /* mark UUIDs with color */
|
---|
3923 | text.replace (QRegExp (
|
---|
3924 | "((?:^|\\s)[(]?)"
|
---|
3925 | "(\\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\})"
|
---|
3926 | "(?=[:.-!);]?(?:\\s|$))"),
|
---|
3927 | QString ("\\1%1<nobr>\\2</nobr>%2").arg (uuidFont).arg (endFont));
|
---|
3928 |
|
---|
3929 | /* split to paragraphs at \n chars */
|
---|
3930 | if (!aToolTip)
|
---|
3931 | text.replace ('\n', "</p><p>");
|
---|
3932 | else
|
---|
3933 | text.replace ('\n', "<br>");
|
---|
3934 |
|
---|
3935 | return text;
|
---|
3936 | }
|
---|
3937 |
|
---|
3938 | /* static */
|
---|
3939 | QString VBoxGlobal::replaceHtmlEntities(QString strText)
|
---|
3940 | {
|
---|
3941 | return strText
|
---|
3942 | .replace('&', "&")
|
---|
3943 | .replace('<', "<")
|
---|
3944 | .replace('>', ">")
|
---|
3945 | .replace('\"', """);
|
---|
3946 | }
|
---|
3947 |
|
---|
3948 | /**
|
---|
3949 | * Reformats the input string @a aStr so that:
|
---|
3950 | * - strings in single quotes will be put inside <nobr> and marked
|
---|
3951 | * with bold style;
|
---|
3952 | * - UUIDs be put inside <nobr> and marked
|
---|
3953 | * with italic style;
|
---|
3954 | * - replaces new line chars with </p><p> constructs to form paragraphs
|
---|
3955 | * (note that <p> and </p> are not appended to the beginning and to the
|
---|
3956 | * end of the string respectively, to allow the result be appended
|
---|
3957 | * or prepended to the existing paragraph).
|
---|
3958 | */
|
---|
3959 | /* static */
|
---|
3960 | QString VBoxGlobal::emphasize (const QString &aStr)
|
---|
3961 | {
|
---|
3962 | QString strEmphStart ("<b>");
|
---|
3963 | QString strEmphEnd ("</b>");
|
---|
3964 | QString uuidEmphStart ("<i>");
|
---|
3965 | QString uuidEmphEnd ("</i>");
|
---|
3966 |
|
---|
3967 | QString text = aStr;
|
---|
3968 |
|
---|
3969 | /* replace special entities, '&' -- first! */
|
---|
3970 | text.replace ('&', "&");
|
---|
3971 | text.replace ('<', "<");
|
---|
3972 | text.replace ('>', ">");
|
---|
3973 | text.replace ('\"', """);
|
---|
3974 |
|
---|
3975 | /* mark strings in single quotes with bold style */
|
---|
3976 | QRegExp rx = QRegExp ("((?:^|\\s)[(]?)'([^']*)'(?=[:.-!);]?(?:\\s|$))");
|
---|
3977 | rx.setMinimal (true);
|
---|
3978 | text.replace (rx,
|
---|
3979 | QString ("\\1%1<nobr>'\\2'</nobr>%2").arg (strEmphStart).arg (strEmphEnd));
|
---|
3980 |
|
---|
3981 | /* mark UUIDs with italic style */
|
---|
3982 | text.replace (QRegExp (
|
---|
3983 | "((?:^|\\s)[(]?)"
|
---|
3984 | "(\\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\})"
|
---|
3985 | "(?=[:.-!);]?(?:\\s|$))"),
|
---|
3986 | QString ("\\1%1<nobr>\\2</nobr>%2").arg (uuidEmphStart).arg (uuidEmphEnd));
|
---|
3987 |
|
---|
3988 | /* split to paragraphs at \n chars */
|
---|
3989 | text.replace ('\n', "</p><p>");
|
---|
3990 |
|
---|
3991 | return text;
|
---|
3992 | }
|
---|
3993 |
|
---|
3994 | /**
|
---|
3995 | * This does exactly the same as QLocale::system().name() but corrects its
|
---|
3996 | * wrong behavior on Linux systems (LC_NUMERIC for some strange reason takes
|
---|
3997 | * precedence over any other locale setting in the QLocale::system()
|
---|
3998 | * implementation). This implementation first looks at LC_ALL (as defined by
|
---|
3999 | * SUS), then looks at LC_MESSAGES which is designed to define a language for
|
---|
4000 | * program messages in case if it differs from the language for other locale
|
---|
4001 | * categories. Then it looks for LANG and finally falls back to
|
---|
4002 | * QLocale::system().name().
|
---|
4003 | *
|
---|
4004 | * The order of precedence is well defined here:
|
---|
4005 | * http://opengroup.org/onlinepubs/007908799/xbd/envvar.html
|
---|
4006 | *
|
---|
4007 | * @note This method will return "C" when the requested locale is invalid or
|
---|
4008 | * when the "C" locale is set explicitly.
|
---|
4009 | */
|
---|
4010 | /* static */
|
---|
4011 | QString VBoxGlobal::systemLanguageId()
|
---|
4012 | {
|
---|
4013 | #if defined (Q_WS_MAC)
|
---|
4014 | /* QLocale return the right id only if the user select the format of the
|
---|
4015 | * language also. So we use our own implementation */
|
---|
4016 | return ::darwinSystemLanguage();
|
---|
4017 | #elif defined (Q_OS_UNIX)
|
---|
4018 | const char *s = RTEnvGet ("LC_ALL");
|
---|
4019 | if (s == 0)
|
---|
4020 | s = RTEnvGet ("LC_MESSAGES");
|
---|
4021 | if (s == 0)
|
---|
4022 | s = RTEnvGet ("LANG");
|
---|
4023 | if (s != 0)
|
---|
4024 | return QLocale (s).name();
|
---|
4025 | #endif
|
---|
4026 | return QLocale::system().name();
|
---|
4027 | }
|
---|
4028 |
|
---|
4029 | #if defined (Q_WS_X11)
|
---|
4030 |
|
---|
4031 | static char *XXGetProperty (Display *aDpy, Window aWnd,
|
---|
4032 | Atom aPropType, const char *aPropName)
|
---|
4033 | {
|
---|
4034 | Atom propNameAtom = XInternAtom (aDpy, aPropName,
|
---|
4035 | True /* only_if_exists */);
|
---|
4036 | if (propNameAtom == None)
|
---|
4037 | return NULL;
|
---|
4038 |
|
---|
4039 | Atom actTypeAtom = None;
|
---|
4040 | int actFmt = 0;
|
---|
4041 | unsigned long nItems = 0;
|
---|
4042 | unsigned long nBytesAfter = 0;
|
---|
4043 | unsigned char *propVal = NULL;
|
---|
4044 | int rc = XGetWindowProperty (aDpy, aWnd, propNameAtom,
|
---|
4045 | 0, LONG_MAX, False /* delete */,
|
---|
4046 | aPropType, &actTypeAtom, &actFmt,
|
---|
4047 | &nItems, &nBytesAfter, &propVal);
|
---|
4048 | if (rc != Success)
|
---|
4049 | return NULL;
|
---|
4050 |
|
---|
4051 | return reinterpret_cast <char *> (propVal);
|
---|
4052 | }
|
---|
4053 |
|
---|
4054 | static Bool XXSendClientMessage (Display *aDpy, Window aWnd, const char *aMsg,
|
---|
4055 | unsigned long aData0 = 0, unsigned long aData1 = 0,
|
---|
4056 | unsigned long aData2 = 0, unsigned long aData3 = 0,
|
---|
4057 | unsigned long aData4 = 0)
|
---|
4058 | {
|
---|
4059 | Atom msgAtom = XInternAtom (aDpy, aMsg, True /* only_if_exists */);
|
---|
4060 | if (msgAtom == None)
|
---|
4061 | return False;
|
---|
4062 |
|
---|
4063 | XEvent ev;
|
---|
4064 |
|
---|
4065 | ev.xclient.type = ClientMessage;
|
---|
4066 | ev.xclient.serial = 0;
|
---|
4067 | ev.xclient.send_event = True;
|
---|
4068 | ev.xclient.display = aDpy;
|
---|
4069 | ev.xclient.window = aWnd;
|
---|
4070 | ev.xclient.message_type = msgAtom;
|
---|
4071 |
|
---|
4072 | /* always send as 32 bit for now */
|
---|
4073 | ev.xclient.format = 32;
|
---|
4074 | ev.xclient.data.l [0] = aData0;
|
---|
4075 | ev.xclient.data.l [1] = aData1;
|
---|
4076 | ev.xclient.data.l [2] = aData2;
|
---|
4077 | ev.xclient.data.l [3] = aData3;
|
---|
4078 | ev.xclient.data.l [4] = aData4;
|
---|
4079 |
|
---|
4080 | return XSendEvent (aDpy, DefaultRootWindow (aDpy), False,
|
---|
4081 | SubstructureRedirectMask, &ev) != 0;
|
---|
4082 | }
|
---|
4083 |
|
---|
4084 | #endif
|
---|
4085 |
|
---|
4086 | /**
|
---|
4087 | * Activates the specified window. If necessary, the window will be
|
---|
4088 | * de-iconified activation.
|
---|
4089 | *
|
---|
4090 | * @note On X11, it is implied that @a aWid represents a window of the same
|
---|
4091 | * display the application was started on.
|
---|
4092 | *
|
---|
4093 | * @param aWId Window ID to activate.
|
---|
4094 | * @param aSwitchDesktop @c true to switch to the window's desktop before
|
---|
4095 | * activation.
|
---|
4096 | *
|
---|
4097 | * @return @c true on success and @c false otherwise.
|
---|
4098 | */
|
---|
4099 | /* static */
|
---|
4100 | bool VBoxGlobal::activateWindow (WId aWId, bool aSwitchDesktop /* = true */)
|
---|
4101 | {
|
---|
4102 | bool result = true;
|
---|
4103 |
|
---|
4104 | #if defined (Q_WS_WIN32)
|
---|
4105 |
|
---|
4106 | if (IsIconic (aWId))
|
---|
4107 | result &= !!ShowWindow (aWId, SW_RESTORE);
|
---|
4108 | else if (!IsWindowVisible (aWId))
|
---|
4109 | result &= !!ShowWindow (aWId, SW_SHOW);
|
---|
4110 |
|
---|
4111 | result &= !!SetForegroundWindow (aWId);
|
---|
4112 |
|
---|
4113 | #elif defined (Q_WS_X11)
|
---|
4114 |
|
---|
4115 | Display *dpy = QX11Info::display();
|
---|
4116 |
|
---|
4117 | if (aSwitchDesktop)
|
---|
4118 | {
|
---|
4119 | /* try to find the desktop ID using the NetWM property */
|
---|
4120 | CARD32 *desktop = (CARD32 *) XXGetProperty (dpy, aWId, XA_CARDINAL,
|
---|
4121 | "_NET_WM_DESKTOP");
|
---|
4122 | if (desktop == NULL)
|
---|
4123 | /* if the NetWM properly is not supported try to find the desktop
|
---|
4124 | * ID using the GNOME WM property */
|
---|
4125 | desktop = (CARD32 *) XXGetProperty (dpy, aWId, XA_CARDINAL,
|
---|
4126 | "_WIN_WORKSPACE");
|
---|
4127 |
|
---|
4128 | if (desktop != NULL)
|
---|
4129 | {
|
---|
4130 | Bool ok = XXSendClientMessage (dpy, DefaultRootWindow (dpy),
|
---|
4131 | "_NET_CURRENT_DESKTOP",
|
---|
4132 | *desktop);
|
---|
4133 | if (!ok)
|
---|
4134 | {
|
---|
4135 | LogWarningFunc (("Couldn't switch to desktop=%08X\n",
|
---|
4136 | desktop));
|
---|
4137 | result = false;
|
---|
4138 | }
|
---|
4139 | XFree (desktop);
|
---|
4140 | }
|
---|
4141 | else
|
---|
4142 | {
|
---|
4143 | LogWarningFunc (("Couldn't find a desktop ID for aWId=%08X\n",
|
---|
4144 | aWId));
|
---|
4145 | result = false;
|
---|
4146 | }
|
---|
4147 | }
|
---|
4148 |
|
---|
4149 | Bool ok = XXSendClientMessage (dpy, aWId, "_NET_ACTIVE_WINDOW");
|
---|
4150 | result &= !!ok;
|
---|
4151 |
|
---|
4152 | XRaiseWindow (dpy, aWId);
|
---|
4153 |
|
---|
4154 | #else
|
---|
4155 |
|
---|
4156 | NOREF (aWId);
|
---|
4157 | NOREF (aSwitchDesktop);
|
---|
4158 | AssertFailed();
|
---|
4159 | result = false;
|
---|
4160 |
|
---|
4161 | #endif
|
---|
4162 |
|
---|
4163 | if (!result)
|
---|
4164 | LogWarningFunc (("Couldn't activate aWId=%08X\n", aWId));
|
---|
4165 |
|
---|
4166 | return result;
|
---|
4167 | }
|
---|
4168 |
|
---|
4169 | /**
|
---|
4170 | * Removes the accelerator mark (the ampersand symbol) from the given string
|
---|
4171 | * and returns the result. The string is supposed to be a menu item's text
|
---|
4172 | * that may (or may not) contain the accelerator mark.
|
---|
4173 | *
|
---|
4174 | * In order to support accelerators used in non-alphabet languages
|
---|
4175 | * (e.g. Japanese) that has a form of "(&<L>)" (where <L> is a latin letter),
|
---|
4176 | * this method first searches for this pattern and, if found, removes it as a
|
---|
4177 | * whole. If such a pattern is not found, then the '&' character is simply
|
---|
4178 | * removed from the string.
|
---|
4179 | *
|
---|
4180 | * @note This function removes only the first occurrence of the accelerator
|
---|
4181 | * mark.
|
---|
4182 | *
|
---|
4183 | * @param aText Menu item's text to remove the accelerator mark from.
|
---|
4184 | *
|
---|
4185 | * @return The resulting string.
|
---|
4186 | */
|
---|
4187 | /* static */
|
---|
4188 | QString VBoxGlobal::removeAccelMark (const QString &aText)
|
---|
4189 | {
|
---|
4190 | QString result = aText;
|
---|
4191 |
|
---|
4192 | QRegExp accel ("\\(&[a-zA-Z]\\)");
|
---|
4193 | int pos = accel.indexIn (result);
|
---|
4194 | if (pos >= 0)
|
---|
4195 | result.remove (pos, accel.cap().length());
|
---|
4196 | else
|
---|
4197 | {
|
---|
4198 | pos = result.indexOf ('&');
|
---|
4199 | if (pos >= 0)
|
---|
4200 | result.remove (pos, 1);
|
---|
4201 | }
|
---|
4202 |
|
---|
4203 | return result;
|
---|
4204 | }
|
---|
4205 |
|
---|
4206 | /* static */
|
---|
4207 | QString VBoxGlobal::insertKeyToActionText(const QString &strText, const QString &strKey)
|
---|
4208 | {
|
---|
4209 | #ifdef Q_WS_MAC
|
---|
4210 | QString pattern("%1 (Host+%2)");
|
---|
4211 | #else
|
---|
4212 | QString pattern("%1 \tHost+%2");
|
---|
4213 | #endif
|
---|
4214 | if ( strKey.isEmpty()
|
---|
4215 | || strKey.compare("None", Qt::CaseInsensitive) == 0)
|
---|
4216 | return strText;
|
---|
4217 | else
|
---|
4218 | return pattern.arg(strText).arg(QKeySequence(strKey).toString(QKeySequence::NativeText));
|
---|
4219 | }
|
---|
4220 |
|
---|
4221 | /* static */
|
---|
4222 | QString VBoxGlobal::extractKeyFromActionText (const QString &aText)
|
---|
4223 | {
|
---|
4224 | QString key;
|
---|
4225 | #ifdef Q_WS_MAC
|
---|
4226 | QRegExp re (".* \\(Host\\+(.+)\\)");
|
---|
4227 | #else
|
---|
4228 | QRegExp re (".* \\t\\Host\\+(.+)");
|
---|
4229 | #endif
|
---|
4230 | if (re.exactMatch (aText))
|
---|
4231 | key = re.cap (1);
|
---|
4232 | return key;
|
---|
4233 | }
|
---|
4234 |
|
---|
4235 | /**
|
---|
4236 | * Joins two pixmaps horizontally with 2px space between them and returns the
|
---|
4237 | * result.
|
---|
4238 | *
|
---|
4239 | * @param aPM1 Left pixmap.
|
---|
4240 | * @param aPM2 Right pixmap.
|
---|
4241 | */
|
---|
4242 | /* static */
|
---|
4243 | QPixmap VBoxGlobal::joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2)
|
---|
4244 | {
|
---|
4245 | if (aPM1.isNull())
|
---|
4246 | return aPM2;
|
---|
4247 | if (aPM2.isNull())
|
---|
4248 | return aPM1;
|
---|
4249 |
|
---|
4250 | QPixmap result (aPM1.width() + aPM2.width() + 2,
|
---|
4251 | qMax (aPM1.height(), aPM2.height()));
|
---|
4252 | result.fill (Qt::transparent);
|
---|
4253 |
|
---|
4254 | QPainter painter (&result);
|
---|
4255 | painter.drawPixmap (0, 0, aPM1);
|
---|
4256 | painter.drawPixmap (aPM1.width() + 2, result.height() - aPM2.height(), aPM2);
|
---|
4257 | painter.end();
|
---|
4258 |
|
---|
4259 | return result;
|
---|
4260 | }
|
---|
4261 |
|
---|
4262 | /**
|
---|
4263 | * Searches for a widget that with @a aName (if it is not NULL) which inherits
|
---|
4264 | * @a aClassName (if it is not NULL) and among children of @a aParent. If @a
|
---|
4265 | * aParent is NULL, all top-level widgets are searched. If @a aRecursive is
|
---|
4266 | * true, child widgets are recursively searched as well.
|
---|
4267 | */
|
---|
4268 | /* static */
|
---|
4269 | QWidget *VBoxGlobal::findWidget (QWidget *aParent, const char *aName,
|
---|
4270 | const char *aClassName /* = NULL */,
|
---|
4271 | bool aRecursive /* = false */)
|
---|
4272 | {
|
---|
4273 | if (aParent == NULL)
|
---|
4274 | {
|
---|
4275 | QWidgetList list = QApplication::topLevelWidgets();
|
---|
4276 | foreach(QWidget *w, list)
|
---|
4277 | {
|
---|
4278 | if ((!aName || strcmp (w->objectName().toAscii().constData(), aName) == 0) &&
|
---|
4279 | (!aClassName || strcmp (w->metaObject()->className(), aClassName) == 0))
|
---|
4280 | return w;
|
---|
4281 | if (aRecursive)
|
---|
4282 | {
|
---|
4283 | w = findWidget (w, aName, aClassName, aRecursive);
|
---|
4284 | if (w)
|
---|
4285 | return w;
|
---|
4286 | }
|
---|
4287 | }
|
---|
4288 | return NULL;
|
---|
4289 | }
|
---|
4290 |
|
---|
4291 | /* Find the first children of aParent with the appropriate properties.
|
---|
4292 | * Please note that this call is recursively. */
|
---|
4293 | QList<QWidget *> list = qFindChildren<QWidget *> (aParent, aName);
|
---|
4294 | foreach(QWidget *child, list)
|
---|
4295 | {
|
---|
4296 | if (!aClassName || strcmp (child->metaObject()->className(), aClassName) == 0)
|
---|
4297 | return child;
|
---|
4298 | }
|
---|
4299 | return NULL;
|
---|
4300 | }
|
---|
4301 |
|
---|
4302 | /**
|
---|
4303 | * Figures out which medium formats are currently supported by VirtualBox for
|
---|
4304 | * the given device type.
|
---|
4305 | * Returned is a list of pairs with the form
|
---|
4306 | * <tt>{"Backend Name", "*.suffix1 .suffix2 ..."}</tt>.
|
---|
4307 | */
|
---|
4308 | /* static */
|
---|
4309 | QList <QPair <QString, QString> > VBoxGlobal::MediumBackends(KDeviceType enmType)
|
---|
4310 | {
|
---|
4311 | CSystemProperties systemProperties = vboxGlobal().virtualBox().GetSystemProperties();
|
---|
4312 | QVector<CMediumFormat> mediumFormats = systemProperties.GetMediumFormats();
|
---|
4313 | QList< QPair<QString, QString> > backendPropList;
|
---|
4314 | for (int i = 0; i < mediumFormats.size(); ++ i)
|
---|
4315 | {
|
---|
4316 | /* File extensions */
|
---|
4317 | QVector <QString> fileExtensions;
|
---|
4318 | QVector <KDeviceType> deviceTypes;
|
---|
4319 |
|
---|
4320 | mediumFormats [i].DescribeFileExtensions(fileExtensions, deviceTypes);
|
---|
4321 |
|
---|
4322 | QStringList f;
|
---|
4323 | for (int a = 0; a < fileExtensions.size(); ++ a)
|
---|
4324 | if (deviceTypes [a] == enmType)
|
---|
4325 | f << QString ("*.%1").arg (fileExtensions [a]);
|
---|
4326 | /* Create a pair out of the backend description and all suffix's. */
|
---|
4327 | if (!f.isEmpty())
|
---|
4328 | backendPropList << QPair<QString, QString> (mediumFormats [i].GetName(), f.join(" "));
|
---|
4329 | }
|
---|
4330 | return backendPropList;
|
---|
4331 | }
|
---|
4332 |
|
---|
4333 | /**
|
---|
4334 | * Figures out which hard disk formats are currently supported by VirtualBox.
|
---|
4335 | * Returned is a list of pairs with the form
|
---|
4336 | * <tt>{"Backend Name", "*.suffix1 .suffix2 ..."}</tt>.
|
---|
4337 | */
|
---|
4338 | /* static */
|
---|
4339 | QList <QPair <QString, QString> > VBoxGlobal::HDDBackends()
|
---|
4340 | {
|
---|
4341 | return MediumBackends(KDeviceType_HardDisk);
|
---|
4342 | }
|
---|
4343 |
|
---|
4344 | /**
|
---|
4345 | * Figures out which CD/DVD disk formats are currently supported by VirtualBox.
|
---|
4346 | * Returned is a list of pairs with the form
|
---|
4347 | * <tt>{"Backend Name", "*.suffix1 .suffix2 ..."}</tt>.
|
---|
4348 | */
|
---|
4349 | /* static */
|
---|
4350 | QList <QPair <QString, QString> > VBoxGlobal::DVDBackends()
|
---|
4351 | {
|
---|
4352 | return MediumBackends(KDeviceType_DVD);
|
---|
4353 | }
|
---|
4354 |
|
---|
4355 | /**
|
---|
4356 | * Figures out which floppy disk formats are currently supported by VirtualBox.
|
---|
4357 | * Returned is a list of pairs with the form
|
---|
4358 | * <tt>{"Backend Name", "*.suffix1 .suffix2 ..."}</tt>.
|
---|
4359 | */
|
---|
4360 | /* static */
|
---|
4361 | QList <QPair <QString, QString> > VBoxGlobal::FloppyBackends()
|
---|
4362 | {
|
---|
4363 | return MediumBackends(KDeviceType_Floppy);
|
---|
4364 | }
|
---|
4365 |
|
---|
4366 | /* static */
|
---|
4367 | QString VBoxGlobal::documentsPath()
|
---|
4368 | {
|
---|
4369 | QString path;
|
---|
4370 | #if QT_VERSION < 0x040400
|
---|
4371 | path = QDir::homePath();
|
---|
4372 | #else
|
---|
4373 | path = QDesktopServices::storageLocation (QDesktopServices::DocumentsLocation);
|
---|
4374 | #endif
|
---|
4375 |
|
---|
4376 | /* Make sure the path exists */
|
---|
4377 | QDir dir (path);
|
---|
4378 | if (dir.exists())
|
---|
4379 | return QDir::cleanPath (dir.canonicalPath());
|
---|
4380 | else
|
---|
4381 | {
|
---|
4382 | dir.setPath (QDir::homePath() + "/Documents");
|
---|
4383 | if (dir.exists())
|
---|
4384 | return QDir::cleanPath (dir.canonicalPath());
|
---|
4385 | else
|
---|
4386 | return QDir::homePath();
|
---|
4387 | }
|
---|
4388 | }
|
---|
4389 |
|
---|
4390 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
4391 | /* static */
|
---|
4392 | bool VBoxGlobal::isAcceleration2DVideoAvailable()
|
---|
4393 | {
|
---|
4394 | return VBoxQGLOverlay::isAcceleration2DVideoAvailable();
|
---|
4395 | }
|
---|
4396 |
|
---|
4397 | /** additional video memory required for the best 2D support performance
|
---|
4398 | * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
|
---|
4399 | /* static */
|
---|
4400 | quint64 VBoxGlobal::required2DOffscreenVideoMemory()
|
---|
4401 | {
|
---|
4402 | return VBoxQGLOverlay::required2DOffscreenVideoMemory();
|
---|
4403 | }
|
---|
4404 |
|
---|
4405 | #endif
|
---|
4406 |
|
---|
4407 | #ifdef VBOX_WITH_CRHGSMI
|
---|
4408 | /* static */
|
---|
4409 | quint64 VBoxGlobal::required3DWddmOffscreenVideoMemory(CMachine *aMachine /* = 0 */, int cMonitors /* = 1 */)
|
---|
4410 | {
|
---|
4411 | cMonitors = RT_MAX(cMonitors, 1);
|
---|
4412 | quint64 cbSize = VBoxGlobal::requiredVideoMemory(aMachine, 1); /* why not cMonitors? */
|
---|
4413 | cbSize += 64 * _1M;
|
---|
4414 | return cbSize;
|
---|
4415 | }
|
---|
4416 | #endif
|
---|
4417 |
|
---|
4418 | #ifdef Q_WS_MAC
|
---|
4419 | bool VBoxGlobal::isSheetWindowsAllowed(QWidget *pParent) const
|
---|
4420 | {
|
---|
4421 | if (!( qobject_cast<UIMachineWindowFullscreen*>(pParent)
|
---|
4422 | || qobject_cast<UIMachineWindowSeamless*>(pParent)))
|
---|
4423 | return true;
|
---|
4424 | return false;
|
---|
4425 | }
|
---|
4426 | #endif /* Q_WS_MAC */
|
---|
4427 |
|
---|
4428 | // Public slots
|
---|
4429 | ////////////////////////////////////////////////////////////////////////////////
|
---|
4430 |
|
---|
4431 | /**
|
---|
4432 | * Opens the specified URL using OS/Desktop capabilities.
|
---|
4433 | *
|
---|
4434 | * @param aURL URL to open
|
---|
4435 | *
|
---|
4436 | * @return true on success and false otherwise
|
---|
4437 | */
|
---|
4438 | bool VBoxGlobal::openURL (const QString &aURL)
|
---|
4439 | {
|
---|
4440 | /* Service event */
|
---|
4441 | class ServiceEvent : public QEvent
|
---|
4442 | {
|
---|
4443 | public:
|
---|
4444 |
|
---|
4445 | ServiceEvent (bool aResult) : QEvent (QEvent::User), mResult (aResult) {}
|
---|
4446 |
|
---|
4447 | bool result() const { return mResult; }
|
---|
4448 |
|
---|
4449 | private:
|
---|
4450 |
|
---|
4451 | bool mResult;
|
---|
4452 | };
|
---|
4453 |
|
---|
4454 | /* Service-Client object */
|
---|
4455 | class ServiceClient : public QEventLoop
|
---|
4456 | {
|
---|
4457 | public:
|
---|
4458 |
|
---|
4459 | ServiceClient() : mResult (false) {}
|
---|
4460 |
|
---|
4461 | bool result() const { return mResult; }
|
---|
4462 |
|
---|
4463 | private:
|
---|
4464 |
|
---|
4465 | bool event (QEvent *aEvent)
|
---|
4466 | {
|
---|
4467 | if (aEvent->type() == QEvent::User)
|
---|
4468 | {
|
---|
4469 | ServiceEvent *pEvent = static_cast <ServiceEvent*> (aEvent);
|
---|
4470 | mResult = pEvent->result();
|
---|
4471 | pEvent->accept();
|
---|
4472 | quit();
|
---|
4473 | return true;
|
---|
4474 | }
|
---|
4475 | return false;
|
---|
4476 | }
|
---|
4477 |
|
---|
4478 | bool mResult;
|
---|
4479 | };
|
---|
4480 |
|
---|
4481 | /* Service-Server object */
|
---|
4482 | class ServiceServer : public QThread
|
---|
4483 | {
|
---|
4484 | public:
|
---|
4485 |
|
---|
4486 | ServiceServer (ServiceClient &aClient, const QString &sURL)
|
---|
4487 | : mClient (aClient), mURL (sURL) {}
|
---|
4488 |
|
---|
4489 | private:
|
---|
4490 |
|
---|
4491 | void run()
|
---|
4492 | {
|
---|
4493 | QApplication::postEvent (&mClient, new ServiceEvent (QDesktopServices::openUrl (mURL)));
|
---|
4494 | }
|
---|
4495 |
|
---|
4496 | ServiceClient &mClient;
|
---|
4497 | const QString &mURL;
|
---|
4498 | };
|
---|
4499 |
|
---|
4500 | ServiceClient client;
|
---|
4501 | ServiceServer server (client, aURL);
|
---|
4502 | server.start();
|
---|
4503 | client.exec();
|
---|
4504 | server.wait();
|
---|
4505 |
|
---|
4506 | bool result = client.result();
|
---|
4507 |
|
---|
4508 | if (!result)
|
---|
4509 | vboxProblem().cannotOpenURL (aURL);
|
---|
4510 |
|
---|
4511 | return result;
|
---|
4512 | }
|
---|
4513 |
|
---|
4514 | /**
|
---|
4515 | * Shows the VirtualBox registration dialog.
|
---|
4516 | *
|
---|
4517 | * @note that this method is not part of VBoxProblemReporter (like e.g.
|
---|
4518 | * VBoxProblemReporter::showHelpAboutDialog()) because it is tied to
|
---|
4519 | * VBoxCallback::OnExtraDataChange() handling performed by VBoxGlobal.
|
---|
4520 | *
|
---|
4521 | * @param aForce
|
---|
4522 | */
|
---|
4523 | void VBoxGlobal::showRegistrationDialog (bool aForce)
|
---|
4524 | {
|
---|
4525 | NOREF(aForce);
|
---|
4526 | #ifdef VBOX_WITH_REGISTRATION
|
---|
4527 | if (!aForce && !UIRegistrationWzd::hasToBeShown())
|
---|
4528 | return;
|
---|
4529 |
|
---|
4530 | if (mRegDlg)
|
---|
4531 | {
|
---|
4532 | /* Show the already opened registration dialog */
|
---|
4533 | mRegDlg->setWindowState (mRegDlg->windowState() & ~Qt::WindowMinimized);
|
---|
4534 | mRegDlg->raise();
|
---|
4535 | mRegDlg->activateWindow();
|
---|
4536 | }
|
---|
4537 | else
|
---|
4538 | {
|
---|
4539 | /* Store the ID of the main window to ensure that only one
|
---|
4540 | * registration dialog is shown at a time. Due to manipulations with
|
---|
4541 | * OnExtraDataCanChange() and OnExtraDataChange() signals, this extra
|
---|
4542 | * data item acts like an inter-process mutex, so the first process
|
---|
4543 | * that attempts to set it will win, the rest will get a failure from
|
---|
4544 | * the SetExtraData() call. */
|
---|
4545 | mVBox.SetExtraData (VBoxDefs::GUI_RegistrationDlgWinID,
|
---|
4546 | QString ("%1").arg ((qulonglong) mMainWindow->winId()));
|
---|
4547 |
|
---|
4548 | if (mVBox.isOk())
|
---|
4549 | {
|
---|
4550 | /* We've got the "mutex", create a new registration dialog */
|
---|
4551 | UIRegistrationWzd *dlg = new UIRegistrationWzd (&mRegDlg);
|
---|
4552 | dlg->setAttribute (Qt::WA_DeleteOnClose);
|
---|
4553 | Assert (dlg == mRegDlg);
|
---|
4554 | mRegDlg->show();
|
---|
4555 | }
|
---|
4556 | }
|
---|
4557 | #endif
|
---|
4558 | }
|
---|
4559 |
|
---|
4560 | /**
|
---|
4561 | * Shows the VirtualBox version check & update dialog.
|
---|
4562 | *
|
---|
4563 | * @note that this method is not part of VBoxProblemReporter (like e.g.
|
---|
4564 | * VBoxProblemReporter::showHelpAboutDialog()) because it is tied to
|
---|
4565 | * VBoxCallback::OnExtraDataChange() handling performed by VBoxGlobal.
|
---|
4566 | *
|
---|
4567 | * @param aForce
|
---|
4568 | */
|
---|
4569 | void VBoxGlobal::showUpdateDialog (bool aForce)
|
---|
4570 | {
|
---|
4571 | /* Silently check in one day after current time-stamp */
|
---|
4572 | QTimer::singleShot (24 /* hours */ * 60 /* minutes */ *
|
---|
4573 | 60 /* seconds */ * 1000 /* milliseconds */,
|
---|
4574 | this, SLOT (perDayNewVersionNotifier()));
|
---|
4575 |
|
---|
4576 | bool isNecessary = VBoxUpdateDlg::isNecessary();
|
---|
4577 |
|
---|
4578 | if (!aForce && !isNecessary)
|
---|
4579 | return;
|
---|
4580 |
|
---|
4581 | if (mUpdDlg)
|
---|
4582 | {
|
---|
4583 | if (!mUpdDlg->isHidden())
|
---|
4584 | {
|
---|
4585 | mUpdDlg->setWindowState (mUpdDlg->windowState() & ~Qt::WindowMinimized);
|
---|
4586 | mUpdDlg->raise();
|
---|
4587 | mUpdDlg->activateWindow();
|
---|
4588 | }
|
---|
4589 | }
|
---|
4590 | else
|
---|
4591 | {
|
---|
4592 | /* Store the ID of the main window to ensure that only one
|
---|
4593 | * update dialog is shown at a time. Due to manipulations with
|
---|
4594 | * OnExtraDataCanChange() and OnExtraDataChange() signals, this extra
|
---|
4595 | * data item acts like an inter-process mutex, so the first process
|
---|
4596 | * that attempts to set it will win, the rest will get a failure from
|
---|
4597 | * the SetExtraData() call. */
|
---|
4598 | mVBox.SetExtraData (VBoxDefs::GUI_UpdateDlgWinID,
|
---|
4599 | QString ("%1").arg ((qulonglong) mMainWindow->winId()));
|
---|
4600 |
|
---|
4601 | if (mVBox.isOk())
|
---|
4602 | {
|
---|
4603 | /* We've got the "mutex", create a new update dialog */
|
---|
4604 | VBoxUpdateDlg *dlg = new VBoxUpdateDlg (&mUpdDlg, aForce, 0);
|
---|
4605 | dlg->setAttribute (Qt::WA_DeleteOnClose);
|
---|
4606 | Assert (dlg == mUpdDlg);
|
---|
4607 |
|
---|
4608 | /* Update dialog always in background mode for now.
|
---|
4609 | * if (!aForce && isAutomatic) */
|
---|
4610 | mUpdDlg->search();
|
---|
4611 | /* else mUpdDlg->show(); */
|
---|
4612 | }
|
---|
4613 | }
|
---|
4614 | }
|
---|
4615 |
|
---|
4616 | void VBoxGlobal::perDayNewVersionNotifier()
|
---|
4617 | {
|
---|
4618 | showUpdateDialog (false /* force show? */);
|
---|
4619 | }
|
---|
4620 |
|
---|
4621 | void VBoxGlobal::sltGUILanguageChange(QString strLang)
|
---|
4622 | {
|
---|
4623 | loadLanguage(strLang);
|
---|
4624 | }
|
---|
4625 |
|
---|
4626 | // Protected members
|
---|
4627 | ////////////////////////////////////////////////////////////////////////////////
|
---|
4628 |
|
---|
4629 | bool VBoxGlobal::event (QEvent *e)
|
---|
4630 | {
|
---|
4631 | switch (e->type())
|
---|
4632 | {
|
---|
4633 | case VBoxDefs::MediaEnumEventType:
|
---|
4634 | {
|
---|
4635 | VBoxMediaEnumEvent *ev = (VBoxMediaEnumEvent*) e;
|
---|
4636 |
|
---|
4637 | if (!ev->mLast)
|
---|
4638 | {
|
---|
4639 | if (ev->mMedium.state() == KMediumState_Inaccessible &&
|
---|
4640 | !ev->mMedium.result().isOk())
|
---|
4641 | vboxProblem().cannotGetMediaAccessibility (ev->mMedium);
|
---|
4642 | Assert (ev->mIterator != mMediaList.end());
|
---|
4643 | *(ev->mIterator) = ev->mMedium;
|
---|
4644 | emit mediumEnumerated (*ev->mIterator);
|
---|
4645 | ++ ev->mIterator;
|
---|
4646 | }
|
---|
4647 | else
|
---|
4648 | {
|
---|
4649 | /* the thread has posted the last message, wait for termination */
|
---|
4650 | mMediaEnumThread->wait();
|
---|
4651 | delete mMediaEnumThread;
|
---|
4652 | mMediaEnumThread = 0;
|
---|
4653 | emit mediumEnumFinished (mMediaList);
|
---|
4654 | }
|
---|
4655 |
|
---|
4656 | return true;
|
---|
4657 | }
|
---|
4658 |
|
---|
4659 | default:
|
---|
4660 | break;
|
---|
4661 | }
|
---|
4662 |
|
---|
4663 | return QObject::event (e);
|
---|
4664 | }
|
---|
4665 |
|
---|
4666 | bool VBoxGlobal::eventFilter (QObject *aObject, QEvent *aEvent)
|
---|
4667 | {
|
---|
4668 | if (aEvent->type() == QEvent::LanguageChange &&
|
---|
4669 | aObject->isWidgetType() &&
|
---|
4670 | static_cast <QWidget *> (aObject)->isTopLevel())
|
---|
4671 | {
|
---|
4672 | /* Catch the language change event before any other widget gets it in
|
---|
4673 | * order to invalidate cached string resources (like the details view
|
---|
4674 | * templates) that may be used by other widgets. */
|
---|
4675 | QWidgetList list = QApplication::topLevelWidgets();
|
---|
4676 | if (list.first() == aObject)
|
---|
4677 | {
|
---|
4678 | /* call this only once per every language change (see
|
---|
4679 | * QApplication::installTranslator() for details) */
|
---|
4680 | retranslateUi();
|
---|
4681 | }
|
---|
4682 | }
|
---|
4683 |
|
---|
4684 | return QObject::eventFilter (aObject, aEvent);
|
---|
4685 | }
|
---|
4686 |
|
---|
4687 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
4688 |
|
---|
4689 | bool VBoxGlobal::isDebuggerEnabled(CMachine &aMachine)
|
---|
4690 | {
|
---|
4691 | return isDebuggerWorker(&mDbgEnabled, aMachine, VBoxDefs::GUI_DbgEnabled);
|
---|
4692 | }
|
---|
4693 |
|
---|
4694 | bool VBoxGlobal::isDebuggerAutoShowEnabled(CMachine &aMachine)
|
---|
4695 | {
|
---|
4696 | return isDebuggerWorker(&mDbgAutoShow, aMachine, VBoxDefs::GUI_DbgAutoShow);
|
---|
4697 | }
|
---|
4698 |
|
---|
4699 | bool VBoxGlobal::isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine)
|
---|
4700 | {
|
---|
4701 | return isDebuggerWorker(&mDbgAutoShowCommandLine, aMachine, VBoxDefs::GUI_DbgAutoShow);
|
---|
4702 | }
|
---|
4703 |
|
---|
4704 | bool VBoxGlobal::isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine)
|
---|
4705 | {
|
---|
4706 | return isDebuggerWorker(&mDbgAutoShowStatistics, aMachine, VBoxDefs::GUI_DbgAutoShow);
|
---|
4707 | }
|
---|
4708 |
|
---|
4709 | #endif /* VBOX_WITH_DEBUGGER_GUI */
|
---|
4710 |
|
---|
4711 | // Private members
|
---|
4712 | ////////////////////////////////////////////////////////////////////////////////
|
---|
4713 |
|
---|
4714 | bool VBoxGlobal::processArgs()
|
---|
4715 | {
|
---|
4716 | bool fResult = false;
|
---|
4717 | QStringList args = qApp->arguments();
|
---|
4718 | QList<QUrl> list;
|
---|
4719 | for (int i = 1; i < args.size(); ++i)
|
---|
4720 | {
|
---|
4721 | /* We break out after the first parameter, cause there could be
|
---|
4722 | parameters with arguments (e.g. --comment comment). */
|
---|
4723 | if (args.at(i).startsWith("-"))
|
---|
4724 | break;
|
---|
4725 | #ifdef Q_WS_MAC
|
---|
4726 | QString strArg = ::darwinResolveAlias(args.at(i));
|
---|
4727 | #else /* Q_WS_MAC */
|
---|
4728 | QString strArg = args.at(i);
|
---|
4729 | #endif /* !Q_WS_MAC */
|
---|
4730 | if ( !strArg.isEmpty()
|
---|
4731 | && QFile::exists(strArg))
|
---|
4732 | list << QUrl::fromLocalFile(strArg);
|
---|
4733 | }
|
---|
4734 | if (!list.isEmpty())
|
---|
4735 | {
|
---|
4736 | for (int i = 0; i < list.size(); ++i)
|
---|
4737 | {
|
---|
4738 | const QString& strFile = list.at(i).toLocalFile();
|
---|
4739 | if (VBoxGlobal::hasAllowedExtension(strFile, VBoxDefs::VBoxFileExts))
|
---|
4740 | {
|
---|
4741 | CVirtualBox vbox = vboxGlobal().virtualBox();
|
---|
4742 | CMachine machine = vbox.FindMachine(strFile);
|
---|
4743 | if (!machine.isNull())
|
---|
4744 | {
|
---|
4745 | fResult = true;
|
---|
4746 | launchMachine(machine);
|
---|
4747 | /* Remove from the arg list. */
|
---|
4748 | list.removeAll(strFile);
|
---|
4749 | }
|
---|
4750 | }
|
---|
4751 | }
|
---|
4752 | }
|
---|
4753 | if (!list.isEmpty())
|
---|
4754 | {
|
---|
4755 | m_ArgUrlList = list;
|
---|
4756 | QTimer::singleShot(0, &vboxGlobal().selectorWnd(), SLOT(sltOpenUrls()));
|
---|
4757 | }
|
---|
4758 | return fResult;
|
---|
4759 | }
|
---|
4760 |
|
---|
4761 | void VBoxGlobal::init()
|
---|
4762 | {
|
---|
4763 | #ifdef DEBUG
|
---|
4764 | mVerString += " [DEBUG]";
|
---|
4765 | #endif
|
---|
4766 |
|
---|
4767 | HRESULT rc = COMBase::InitializeCOM(true);
|
---|
4768 | if (FAILED (rc))
|
---|
4769 | {
|
---|
4770 | vboxProblem().cannotInitCOM (rc);
|
---|
4771 | return;
|
---|
4772 | }
|
---|
4773 |
|
---|
4774 | mVBox.createInstance (CLSID_VirtualBox);
|
---|
4775 | if (!mVBox.isOk())
|
---|
4776 | {
|
---|
4777 | vboxProblem().cannotCreateVirtualBox (mVBox);
|
---|
4778 | return;
|
---|
4779 | }
|
---|
4780 |
|
---|
4781 | /* create default non-null global settings */
|
---|
4782 | gset = VBoxGlobalSettings (false);
|
---|
4783 |
|
---|
4784 | /* try to load global settings */
|
---|
4785 | gset.load (mVBox);
|
---|
4786 | if (!mVBox.isOk() || !gset)
|
---|
4787 | {
|
---|
4788 | vboxProblem().cannotLoadGlobalConfig (mVBox, gset.lastError());
|
---|
4789 | return;
|
---|
4790 | }
|
---|
4791 |
|
---|
4792 | /* Load the customized language as early as possible to get possible error
|
---|
4793 | * messages translated */
|
---|
4794 | QString sLanguageId = gset.languageId();
|
---|
4795 | if (!sLanguageId.isNull())
|
---|
4796 | loadLanguage (sLanguageId);
|
---|
4797 |
|
---|
4798 | retranslateUi();
|
---|
4799 |
|
---|
4800 | connect(gEDataEvents, SIGNAL(sigGUILanguageChange(QString)),
|
---|
4801 | this, SLOT(sltGUILanguageChange(QString)));
|
---|
4802 |
|
---|
4803 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
4804 | {
|
---|
4805 | /* Increase open Fe/Qt4 windows reference count. */
|
---|
4806 | int c = mVBox.GetExtraData (VBoxDefs::GUI_MainWindowCount).toInt() + 1;
|
---|
4807 | AssertMsgReturnVoid ((c >= 0) || (mVBox.isOk()),
|
---|
4808 | ("Something went wrong with the window reference count!"));
|
---|
4809 | mVBox.SetExtraData (VBoxDefs::GUI_MainWindowCount, QString ("%1").arg (c));
|
---|
4810 | mIncreasedWindowCounter = mVBox.isOk();
|
---|
4811 | AssertReturnVoid (mIncreasedWindowCounter);
|
---|
4812 | }
|
---|
4813 | #endif
|
---|
4814 |
|
---|
4815 | /* Initialize guest OS Type list. */
|
---|
4816 | CGuestOSTypeVector coll = mVBox.GetGuestOSTypes();
|
---|
4817 | int osTypeCount = coll.size();
|
---|
4818 | AssertMsg (osTypeCount > 0, ("Number of OS types must not be zero"));
|
---|
4819 | if (osTypeCount > 0)
|
---|
4820 | {
|
---|
4821 | /* Here we assume the 'Other' type is always the first, so we
|
---|
4822 | * remember it and will append it to the list when finished. */
|
---|
4823 | CGuestOSType otherType = coll[0];
|
---|
4824 | QString otherFamilyId (otherType.GetFamilyId());
|
---|
4825 |
|
---|
4826 | /* Fill the lists with all the available OS Types except
|
---|
4827 | * the 'Other' type, which will be appended. */
|
---|
4828 | for (int i = 1; i < coll.size(); ++i)
|
---|
4829 | {
|
---|
4830 | CGuestOSType os = coll[i];
|
---|
4831 | QString familyId (os.GetFamilyId());
|
---|
4832 | if (!mFamilyIDs.contains (familyId))
|
---|
4833 | {
|
---|
4834 | mFamilyIDs << familyId;
|
---|
4835 | mTypes << QList <CGuestOSType> ();
|
---|
4836 | }
|
---|
4837 | mTypes [mFamilyIDs.indexOf (familyId)].append (os);
|
---|
4838 | }
|
---|
4839 |
|
---|
4840 | /* Append the 'Other' OS Type to the end of list. */
|
---|
4841 | if (!mFamilyIDs.contains (otherFamilyId))
|
---|
4842 | {
|
---|
4843 | mFamilyIDs << otherFamilyId;
|
---|
4844 | mTypes << QList <CGuestOSType> ();
|
---|
4845 | }
|
---|
4846 | mTypes [mFamilyIDs.indexOf (otherFamilyId)].append (otherType);
|
---|
4847 | }
|
---|
4848 |
|
---|
4849 | /* Fill in OS type icon dictionary. */
|
---|
4850 | static const char *kOSTypeIcons [][2] =
|
---|
4851 | {
|
---|
4852 | {"Other", ":/os_other.png"},
|
---|
4853 | {"DOS", ":/os_dos.png"},
|
---|
4854 | {"Netware", ":/os_netware.png"},
|
---|
4855 | {"L4", ":/os_l4.png"},
|
---|
4856 | {"Windows31", ":/os_win31.png"},
|
---|
4857 | {"Windows95", ":/os_win95.png"},
|
---|
4858 | {"Windows98", ":/os_win98.png"},
|
---|
4859 | {"WindowsMe", ":/os_winme.png"},
|
---|
4860 | {"WindowsNT4", ":/os_winnt4.png"},
|
---|
4861 | {"Windows2000", ":/os_win2k.png"},
|
---|
4862 | {"WindowsXP", ":/os_winxp.png"},
|
---|
4863 | {"WindowsXP_64", ":/os_winxp_64.png"},
|
---|
4864 | {"Windows2003", ":/os_win2k3.png"},
|
---|
4865 | {"Windows2003_64", ":/os_win2k3_64.png"},
|
---|
4866 | {"WindowsVista", ":/os_winvista.png"},
|
---|
4867 | {"WindowsVista_64", ":/os_winvista_64.png"},
|
---|
4868 | {"Windows2008", ":/os_win2k8.png"},
|
---|
4869 | {"Windows2008_64", ":/os_win2k8_64.png"},
|
---|
4870 | {"Windows7", ":/os_win7.png"},
|
---|
4871 | {"Windows7_64", ":/os_win7_64.png"},
|
---|
4872 | {"WindowsNT", ":/os_win_other.png"},
|
---|
4873 | {"OS2Warp3", ":/os_os2warp3.png"},
|
---|
4874 | {"OS2Warp4", ":/os_os2warp4.png"},
|
---|
4875 | {"OS2Warp45", ":/os_os2warp45.png"},
|
---|
4876 | {"OS2eCS", ":/os_os2ecs.png"},
|
---|
4877 | {"OS2", ":/os_os2_other.png"},
|
---|
4878 | {"Linux22", ":/os_linux22.png"},
|
---|
4879 | {"Linux24", ":/os_linux24.png"},
|
---|
4880 | {"Linux24_64", ":/os_linux24_64.png"},
|
---|
4881 | {"Linux26", ":/os_linux26.png"},
|
---|
4882 | {"Linux26_64", ":/os_linux26_64.png"},
|
---|
4883 | {"ArchLinux", ":/os_archlinux.png"},
|
---|
4884 | {"ArchLinux_64", ":/os_archlinux_64.png"},
|
---|
4885 | {"Debian", ":/os_debian.png"},
|
---|
4886 | {"Debian_64", ":/os_debian_64.png"},
|
---|
4887 | {"OpenSUSE", ":/os_opensuse.png"},
|
---|
4888 | {"OpenSUSE_64", ":/os_opensuse_64.png"},
|
---|
4889 | {"Fedora", ":/os_fedora.png"},
|
---|
4890 | {"Fedora_64", ":/os_fedora_64.png"},
|
---|
4891 | {"Gentoo", ":/os_gentoo.png"},
|
---|
4892 | {"Gentoo_64", ":/os_gentoo_64.png"},
|
---|
4893 | {"Mandriva", ":/os_mandriva.png"},
|
---|
4894 | {"Mandriva_64", ":/os_mandriva_64.png"},
|
---|
4895 | {"RedHat", ":/os_redhat.png"},
|
---|
4896 | {"RedHat_64", ":/os_redhat_64.png"},
|
---|
4897 | {"Turbolinux", ":/os_turbolinux.png"},
|
---|
4898 | {"Turbolinux_64", ":/os_turbolinux_64.png"},
|
---|
4899 | {"Ubuntu", ":/os_ubuntu.png"},
|
---|
4900 | {"Ubuntu_64", ":/os_ubuntu_64.png"},
|
---|
4901 | {"Xandros", ":/os_xandros.png"},
|
---|
4902 | {"Xandros_64", ":/os_xandros_64.png"},
|
---|
4903 | {"Oracle", ":/os_oracle.png"},
|
---|
4904 | {"Oracle_64", ":/os_oracle_64.png"},
|
---|
4905 | {"Linux", ":/os_linux_other.png"},
|
---|
4906 | {"FreeBSD", ":/os_freebsd.png"},
|
---|
4907 | {"FreeBSD_64", ":/os_freebsd_64.png"},
|
---|
4908 | {"OpenBSD", ":/os_openbsd.png"},
|
---|
4909 | {"OpenBSD_64", ":/os_openbsd_64.png"},
|
---|
4910 | {"NetBSD", ":/os_netbsd.png"},
|
---|
4911 | {"NetBSD_64", ":/os_netbsd_64.png"},
|
---|
4912 | {"Solaris", ":/os_solaris.png"},
|
---|
4913 | {"Solaris_64", ":/os_solaris_64.png"},
|
---|
4914 | {"OpenSolaris", ":/os_opensolaris.png"},
|
---|
4915 | {"OpenSolaris_64", ":/os_opensolaris_64.png"},
|
---|
4916 | {"QNX", ":/os_qnx.png"},
|
---|
4917 | {"MacOS", ":/os_macosx.png"},
|
---|
4918 | {"MacOS_64", ":/os_macosx_64.png"},
|
---|
4919 | {"JRockitVE", ":/os_jrockitve.png"},
|
---|
4920 | };
|
---|
4921 | for (uint n = 0; n < SIZEOF_ARRAY (kOSTypeIcons); ++ n)
|
---|
4922 | {
|
---|
4923 | mOsTypeIcons.insert (kOSTypeIcons [n][0],
|
---|
4924 | new QPixmap (kOSTypeIcons [n][1]));
|
---|
4925 | }
|
---|
4926 |
|
---|
4927 | /* fill in VM state icon map */
|
---|
4928 | static const struct
|
---|
4929 | {
|
---|
4930 | KMachineState state;
|
---|
4931 | const char *name;
|
---|
4932 | }
|
---|
4933 | kVMStateIcons[] =
|
---|
4934 | {
|
---|
4935 | {KMachineState_Null, NULL},
|
---|
4936 | {KMachineState_PoweredOff, ":/state_powered_off_16px.png"},
|
---|
4937 | {KMachineState_Saved, ":/state_saved_16px.png"},
|
---|
4938 | {KMachineState_Aborted, ":/state_aborted_16px.png"},
|
---|
4939 | {KMachineState_Teleported, ":/state_saved_16px.png"}, /** @todo Live Migration: New icon? (not really important) */
|
---|
4940 | {KMachineState_Running, ":/state_running_16px.png"},
|
---|
4941 | {KMachineState_Paused, ":/state_paused_16px.png"},
|
---|
4942 | {KMachineState_Teleporting, ":/state_running_16px.png"}, /** @todo Live Migration: New icon? (not really important) */
|
---|
4943 | {KMachineState_LiveSnapshotting, ":/state_running_16px.png"}, /** @todo Live Migration: New icon? (not really important) */
|
---|
4944 | {KMachineState_Stuck, ":/state_stuck_16px.png"},
|
---|
4945 | {KMachineState_Starting, ":/state_running_16px.png"}, /// @todo (dmik) separate icon?
|
---|
4946 | {KMachineState_Stopping, ":/state_running_16px.png"}, /// @todo (dmik) separate icon?
|
---|
4947 | {KMachineState_Saving, ":/state_saving_16px.png"},
|
---|
4948 | {KMachineState_Restoring, ":/state_restoring_16px.png"},
|
---|
4949 | {KMachineState_TeleportingPausedVM, ":/state_saving_16px.png"}, /** @todo Live Migration: New icon? (not really important) */
|
---|
4950 | {KMachineState_TeleportingIn, ":/state_restoring_16px.png"}, /** @todo Live Migration: New icon? (not really important) */
|
---|
4951 | {KMachineState_RestoringSnapshot, ":/state_discarding_16px.png"},
|
---|
4952 | {KMachineState_DeletingSnapshot, ":/state_discarding_16px.png"},
|
---|
4953 | {KMachineState_DeletingSnapshotOnline, ":/state_discarding_16px.png"}, /// @todo live snapshot deletion: new icon?
|
---|
4954 | {KMachineState_DeletingSnapshotPaused, ":/state_discarding_16px.png"}, /// @todo live snapshot deletion: new icon?
|
---|
4955 | {KMachineState_SettingUp, ":/settings_16px.png"},
|
---|
4956 | };
|
---|
4957 | for (uint n = 0; n < SIZEOF_ARRAY (kVMStateIcons); n ++)
|
---|
4958 | {
|
---|
4959 | mVMStateIcons.insert (kVMStateIcons [n].state,
|
---|
4960 | new QPixmap (kVMStateIcons [n].name));
|
---|
4961 | }
|
---|
4962 |
|
---|
4963 | /* initialize state colors map */
|
---|
4964 | mVMStateColors.insert (KMachineState_Null, new QColor (Qt::red));
|
---|
4965 | mVMStateColors.insert (KMachineState_PoweredOff, new QColor (Qt::gray));
|
---|
4966 | mVMStateColors.insert (KMachineState_Saved, new QColor (Qt::yellow));
|
---|
4967 | mVMStateColors.insert (KMachineState_Aborted, new QColor (Qt::darkRed));
|
---|
4968 | mVMStateColors.insert (KMachineState_Teleported, new QColor (Qt::red));
|
---|
4969 | mVMStateColors.insert (KMachineState_Running, new QColor (Qt::green));
|
---|
4970 | mVMStateColors.insert (KMachineState_Paused, new QColor (Qt::darkGreen));
|
---|
4971 | mVMStateColors.insert (KMachineState_Stuck, new QColor (Qt::darkMagenta));
|
---|
4972 | mVMStateColors.insert (KMachineState_Teleporting, new QColor (Qt::blue));
|
---|
4973 | mVMStateColors.insert (KMachineState_LiveSnapshotting, new QColor (Qt::green));
|
---|
4974 | mVMStateColors.insert (KMachineState_Starting, new QColor (Qt::green));
|
---|
4975 | mVMStateColors.insert (KMachineState_Stopping, new QColor (Qt::green));
|
---|
4976 | mVMStateColors.insert (KMachineState_Saving, new QColor (Qt::green));
|
---|
4977 | mVMStateColors.insert (KMachineState_Restoring, new QColor (Qt::green));
|
---|
4978 | mVMStateColors.insert (KMachineState_TeleportingPausedVM, new QColor (Qt::blue));
|
---|
4979 | mVMStateColors.insert (KMachineState_TeleportingIn, new QColor (Qt::blue));
|
---|
4980 | mVMStateColors.insert (KMachineState_RestoringSnapshot, new QColor (Qt::green));
|
---|
4981 | mVMStateColors.insert (KMachineState_DeletingSnapshot, new QColor (Qt::green));
|
---|
4982 | mVMStateColors.insert (KMachineState_DeletingSnapshotOnline, new QColor (Qt::green));
|
---|
4983 | mVMStateColors.insert (KMachineState_DeletingSnapshotPaused, new QColor (Qt::darkGreen));
|
---|
4984 | mVMStateColors.insert (KMachineState_SettingUp, new QColor (Qt::green));
|
---|
4985 |
|
---|
4986 | /* online/offline snapshot icons */
|
---|
4987 | mOfflineSnapshotIcon = QPixmap (":/offline_snapshot_16px.png");
|
---|
4988 | mOnlineSnapshotIcon = QPixmap (":/online_snapshot_16px.png");
|
---|
4989 |
|
---|
4990 | qApp->installEventFilter (this);
|
---|
4991 |
|
---|
4992 | /* process command line */
|
---|
4993 |
|
---|
4994 | bool bForceSeamless = false;
|
---|
4995 | bool bForceFullscreen = false;
|
---|
4996 |
|
---|
4997 | vm_render_mode_str = RTStrDup (virtualBox()
|
---|
4998 | .GetExtraData (VBoxDefs::GUI_RenderMode).toAscii().constData());
|
---|
4999 |
|
---|
5000 | #ifdef Q_WS_X11
|
---|
5001 | mIsKWinManaged = X11IsWindowManagerKWin();
|
---|
5002 | #endif
|
---|
5003 |
|
---|
5004 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
5005 | # ifdef VBOX_WITH_DEBUGGER_GUI_MENU
|
---|
5006 | initDebuggerVar(&mDbgEnabled, "VBOX_GUI_DBG_ENABLED", VBoxDefs::GUI_DbgEnabled, true);
|
---|
5007 | # else
|
---|
5008 | initDebuggerVar(&mDbgEnabled, "VBOX_GUI_DBG_ENABLED", VBoxDefs::GUI_DbgEnabled, false);
|
---|
5009 | # endif
|
---|
5010 | initDebuggerVar(&mDbgAutoShow, "VBOX_GUI_DBG_AUTO_SHOW", VBoxDefs::GUI_DbgAutoShow, false);
|
---|
5011 | mDbgAutoShowCommandLine = mDbgAutoShowStatistics = mDbgAutoShow;
|
---|
5012 | mStartPaused = false;
|
---|
5013 | #endif
|
---|
5014 |
|
---|
5015 | mShowStartVMErrors = true;
|
---|
5016 | bool startVM = false;
|
---|
5017 | QString vmNameOrUuid;
|
---|
5018 |
|
---|
5019 | int argc = qApp->argc();
|
---|
5020 | int i = 1;
|
---|
5021 | while (i < argc)
|
---|
5022 | {
|
---|
5023 | const char *arg = qApp->argv() [i];
|
---|
5024 | /* NOTE: the check here must match the corresponding check for the
|
---|
5025 | * options to start a VM in main.cpp and hardenedmain.cpp exactly,
|
---|
5026 | * otherwise there will be weird error messages. */
|
---|
5027 | if ( !::strcmp (arg, "--startvm")
|
---|
5028 | || !::strcmp (arg, "-startvm"))
|
---|
5029 | {
|
---|
5030 | if (++i < argc)
|
---|
5031 | {
|
---|
5032 | vmNameOrUuid = QString (qApp->argv() [i]);
|
---|
5033 | startVM = true;
|
---|
5034 | }
|
---|
5035 | }
|
---|
5036 | #ifdef VBOX_GUI_WITH_PIDFILE
|
---|
5037 | else if (!::strcmp(arg, "-pidfile") || !::strcmp(arg, "--pidfile"))
|
---|
5038 | {
|
---|
5039 | if (++i < argc)
|
---|
5040 | m_strPidfile = QString(qApp->argv()[i]);
|
---|
5041 | }
|
---|
5042 | #endif /* VBOX_GUI_WITH_PIDFILE */
|
---|
5043 | else if (!::strcmp(arg, "-seamless") || !::strcmp(arg, "--seamless"))
|
---|
5044 | {
|
---|
5045 | bForceSeamless = true;
|
---|
5046 | }
|
---|
5047 | else if (!::strcmp(arg, "-fullscreen") || !::strcmp(arg, "--fullscreen"))
|
---|
5048 | {
|
---|
5049 | bForceFullscreen = true;
|
---|
5050 | }
|
---|
5051 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
5052 | else if (!::strcmp (arg, "-systray") || !::strcmp (arg, "--systray"))
|
---|
5053 | {
|
---|
5054 | mIsTrayMenu = true;
|
---|
5055 | }
|
---|
5056 | #endif
|
---|
5057 | else if (!::strcmp (arg, "-comment") || !::strcmp (arg, "--comment"))
|
---|
5058 | {
|
---|
5059 | ++i;
|
---|
5060 | }
|
---|
5061 | else if (!::strcmp (arg, "-rmode") || !::strcmp (arg, "--rmode"))
|
---|
5062 | {
|
---|
5063 | if (++i < argc)
|
---|
5064 | vm_render_mode_str = qApp->argv() [i];
|
---|
5065 | }
|
---|
5066 | else if (!::strcmp (arg, "--no-startvm-errormsgbox"))
|
---|
5067 | {
|
---|
5068 | mShowStartVMErrors = false;
|
---|
5069 | }
|
---|
5070 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
5071 | else if (!::strcmp (arg, "-dbg") || !::strcmp (arg, "--dbg"))
|
---|
5072 | {
|
---|
5073 | setDebuggerVar(&mDbgEnabled, true);
|
---|
5074 | }
|
---|
5075 | else if (!::strcmp( arg, "-debug") || !::strcmp (arg, "--debug"))
|
---|
5076 | {
|
---|
5077 | setDebuggerVar(&mDbgEnabled, true);
|
---|
5078 | setDebuggerVar(&mDbgAutoShow, true);
|
---|
5079 | setDebuggerVar(&mDbgAutoShowCommandLine, true);
|
---|
5080 | setDebuggerVar(&mDbgAutoShowStatistics, true);
|
---|
5081 | mStartPaused = true;
|
---|
5082 | }
|
---|
5083 | else if (!::strcmp (arg, "--debug-command-line"))
|
---|
5084 | {
|
---|
5085 | setDebuggerVar(&mDbgEnabled, true);
|
---|
5086 | setDebuggerVar(&mDbgAutoShow, true);
|
---|
5087 | setDebuggerVar(&mDbgAutoShowCommandLine, true);
|
---|
5088 | mStartPaused = true;
|
---|
5089 | }
|
---|
5090 | else if (!::strcmp (arg, "--debug-statistics"))
|
---|
5091 | {
|
---|
5092 | setDebuggerVar(&mDbgEnabled, true);
|
---|
5093 | setDebuggerVar(&mDbgAutoShow, true);
|
---|
5094 | setDebuggerVar(&mDbgAutoShowStatistics, true);
|
---|
5095 | mStartPaused = true;
|
---|
5096 | }
|
---|
5097 | else if (!::strcmp (arg, "-no-debug") || !::strcmp (arg, "--no-debug"))
|
---|
5098 | {
|
---|
5099 | setDebuggerVar(&mDbgEnabled, false);
|
---|
5100 | setDebuggerVar(&mDbgAutoShow, false);
|
---|
5101 | setDebuggerVar(&mDbgAutoShowCommandLine, false);
|
---|
5102 | setDebuggerVar(&mDbgAutoShowStatistics, false);
|
---|
5103 | }
|
---|
5104 | /* Not quite debug options, but they're only useful with the debugger bits. */
|
---|
5105 | else if (!::strcmp (arg, "--start-paused"))
|
---|
5106 | {
|
---|
5107 | mStartPaused = true;
|
---|
5108 | }
|
---|
5109 | else if (!::strcmp (arg, "--start-running"))
|
---|
5110 | {
|
---|
5111 | mStartPaused = false;
|
---|
5112 | }
|
---|
5113 | #endif
|
---|
5114 | /** @todo add an else { msgbox(syntax error); exit(1); } here, pretty please... */
|
---|
5115 | i++;
|
---|
5116 | }
|
---|
5117 |
|
---|
5118 | if (startVM)
|
---|
5119 | {
|
---|
5120 | QUuid uuid = QUuid(vmNameOrUuid);
|
---|
5121 | if (!uuid.isNull())
|
---|
5122 | {
|
---|
5123 | vmUuid = vmNameOrUuid;
|
---|
5124 | }
|
---|
5125 | else
|
---|
5126 | {
|
---|
5127 | CMachine m = mVBox.FindMachine (vmNameOrUuid);
|
---|
5128 | if (m.isNull())
|
---|
5129 | {
|
---|
5130 | if (showStartVMErrors())
|
---|
5131 | vboxProblem().cannotFindMachineByName (mVBox, vmNameOrUuid);
|
---|
5132 | return;
|
---|
5133 | }
|
---|
5134 | vmUuid = m.GetId();
|
---|
5135 | }
|
---|
5136 | }
|
---|
5137 |
|
---|
5138 | if (bForceSeamless && !vmUuid.isEmpty())
|
---|
5139 | {
|
---|
5140 | mVBox.FindMachine(vmUuid).SetExtraData(VBoxDefs::GUI_Seamless, "on");
|
---|
5141 | }
|
---|
5142 | else if (bForceFullscreen && !vmUuid.isEmpty())
|
---|
5143 | {
|
---|
5144 | mVBox.FindMachine(vmUuid).SetExtraData(VBoxDefs::GUI_Fullscreen, "on");
|
---|
5145 | }
|
---|
5146 |
|
---|
5147 | vm_render_mode = vboxGetRenderMode (vm_render_mode_str);
|
---|
5148 |
|
---|
5149 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
5150 | /* setup the debugger gui. */
|
---|
5151 | if (RTEnvExist("VBOX_GUI_NO_DEBUGGER"))
|
---|
5152 | mDbgEnabled = mDbgAutoShow = mDbgAutoShowCommandLine = mDbgAutoShowStatistics = false;
|
---|
5153 | if (mDbgEnabled)
|
---|
5154 | {
|
---|
5155 | RTERRINFOSTATIC ErrInfo;
|
---|
5156 | RTErrInfoInitStatic(&ErrInfo);
|
---|
5157 | int vrc = SUPR3HardenedLdrLoadAppPriv("VBoxDbg", &mhVBoxDbg, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
|
---|
5158 | if (RT_FAILURE(vrc))
|
---|
5159 | {
|
---|
5160 | mhVBoxDbg = NIL_RTLDRMOD;
|
---|
5161 | mDbgAutoShow = mDbgAutoShowCommandLine = mDbgAutoShowStatistics = false;
|
---|
5162 | LogRel(("Failed to load VBoxDbg, rc=%Rrc - %s\n", vrc, ErrInfo.Core.pszMsg));
|
---|
5163 | }
|
---|
5164 | }
|
---|
5165 | #endif
|
---|
5166 |
|
---|
5167 | mValid = true;
|
---|
5168 |
|
---|
5169 | /* Cache IMedium data.
|
---|
5170 | * There could be no used mediums at all,
|
---|
5171 | * but this method should be run anyway just to enumerate null VBoxMedium object,
|
---|
5172 | * used by some VBox smart widgets, like VBoxMediaComboBox: */
|
---|
5173 | vboxGlobal().startEnumeratingMedia();
|
---|
5174 | }
|
---|
5175 |
|
---|
5176 |
|
---|
5177 | /** @internal
|
---|
5178 | *
|
---|
5179 | * This method should be never called directly. It is called automatically
|
---|
5180 | * when the application terminates.
|
---|
5181 | */
|
---|
5182 | void VBoxGlobal::cleanup()
|
---|
5183 | {
|
---|
5184 | /* sanity check */
|
---|
5185 | if (!sVBoxGlobalInCleanup)
|
---|
5186 | {
|
---|
5187 | AssertMsgFailed (("Should never be called directly\n"));
|
---|
5188 | return;
|
---|
5189 | }
|
---|
5190 |
|
---|
5191 | #ifdef VBOX_GUI_WITH_SYSTRAY
|
---|
5192 | if (mIncreasedWindowCounter)
|
---|
5193 | {
|
---|
5194 | /* Decrease open Fe/Qt4 windows reference count. */
|
---|
5195 | int c = mVBox.GetExtraData (VBoxDefs::GUI_MainWindowCount).toInt() - 1;
|
---|
5196 | AssertMsg ((c >= 0) || (mVBox.isOk()),
|
---|
5197 | ("Something went wrong with the window reference count!"));
|
---|
5198 | if (c < 0)
|
---|
5199 | c = 0; /* Clean up the mess. */
|
---|
5200 | mVBox.SetExtraData (VBoxDefs::GUI_MainWindowCount,
|
---|
5201 | (c > 0) ? QString ("%1").arg (c) : NULL);
|
---|
5202 | AssertWrapperOk (mVBox);
|
---|
5203 | if (c == 0)
|
---|
5204 | {
|
---|
5205 | mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, NULL);
|
---|
5206 | AssertWrapperOk (mVBox);
|
---|
5207 | }
|
---|
5208 | }
|
---|
5209 | #endif
|
---|
5210 |
|
---|
5211 | #ifdef VBOX_GUI_WITH_PIDFILE
|
---|
5212 | deletePidfile();
|
---|
5213 | #endif
|
---|
5214 |
|
---|
5215 | /* Destroy our event handlers */
|
---|
5216 | UIExtraDataEventHandler::destroy();
|
---|
5217 |
|
---|
5218 | if (mMediaEnumThread)
|
---|
5219 | {
|
---|
5220 | /* sVBoxGlobalInCleanup is true here, so just wait for the thread */
|
---|
5221 | mMediaEnumThread->wait();
|
---|
5222 | delete mMediaEnumThread;
|
---|
5223 | mMediaEnumThread = 0;
|
---|
5224 | }
|
---|
5225 |
|
---|
5226 | #ifdef VBOX_WITH_REGISTRATION
|
---|
5227 | if (mRegDlg)
|
---|
5228 | mRegDlg->close();
|
---|
5229 | #endif
|
---|
5230 |
|
---|
5231 | if (mSelectorWnd)
|
---|
5232 | delete mSelectorWnd;
|
---|
5233 | if (m_pVirtualMachine)
|
---|
5234 | delete m_pVirtualMachine;
|
---|
5235 |
|
---|
5236 | /* ensure CGuestOSType objects are no longer used */
|
---|
5237 | mFamilyIDs.clear();
|
---|
5238 | mTypes.clear();
|
---|
5239 |
|
---|
5240 | /* media list contains a lot of CUUnknown, release them */
|
---|
5241 | mMediaList.clear();
|
---|
5242 | /* the last step to ensure we don't use COM any more */
|
---|
5243 | mVBox.detach();
|
---|
5244 |
|
---|
5245 | /* There may be VBoxMediaEnumEvent instances still in the message
|
---|
5246 | * queue which reference COM objects. Remove them to release those objects
|
---|
5247 | * before uninitializing the COM subsystem. */
|
---|
5248 | QApplication::removePostedEvents (this);
|
---|
5249 |
|
---|
5250 | COMBase::CleanupCOM();
|
---|
5251 |
|
---|
5252 | mValid = false;
|
---|
5253 | }
|
---|
5254 |
|
---|
5255 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
5256 |
|
---|
5257 | # define VBOXGLOBAL_DBG_CFG_VAR_FALSE (0)
|
---|
5258 | # define VBOXGLOBAL_DBG_CFG_VAR_TRUE (1)
|
---|
5259 | # define VBOXGLOBAL_DBG_CFG_VAR_MASK (1)
|
---|
5260 | # define VBOXGLOBAL_DBG_CFG_VAR_CMD_LINE RT_BIT(3)
|
---|
5261 | # define VBOXGLOBAL_DBG_CFG_VAR_DONE RT_BIT(4)
|
---|
5262 |
|
---|
5263 | /**
|
---|
5264 | * Initialize a debugger config variable.
|
---|
5265 | *
|
---|
5266 | * @param piDbgCfgVar The debugger config variable to init.
|
---|
5267 | * @param pszEnvVar The environment variable name relating to this
|
---|
5268 | * variable.
|
---|
5269 | * @param pszExtraDataName The extra data name relating to this variable.
|
---|
5270 | * @param fDefault The default value.
|
---|
5271 | */
|
---|
5272 | void VBoxGlobal::initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault)
|
---|
5273 | {
|
---|
5274 | QString strEnvValue;
|
---|
5275 | char szEnvValue[256];
|
---|
5276 | int rc = RTEnvGetEx(RTENV_DEFAULT, pszEnvVar, szEnvValue, sizeof(szEnvValue), NULL);
|
---|
5277 | if (RT_SUCCESS(rc))
|
---|
5278 | {
|
---|
5279 | strEnvValue = QString::fromUtf8(&szEnvValue[0]).toLower().trimmed();
|
---|
5280 | if (strEnvValue.isEmpty())
|
---|
5281 | strEnvValue = "yes";
|
---|
5282 | }
|
---|
5283 | else if (rc != VERR_ENV_VAR_NOT_FOUND)
|
---|
5284 | strEnvValue = "veto";
|
---|
5285 |
|
---|
5286 | QString strExtraValue = mVBox.GetExtraData(pszExtraDataName).toLower().trimmed();
|
---|
5287 | if (strExtraValue.isEmpty())
|
---|
5288 | strExtraValue = QString();
|
---|
5289 |
|
---|
5290 | if ( strEnvValue.contains("veto") || strExtraValue.contains("veto"))
|
---|
5291 | *piDbgCfgVar = VBOXGLOBAL_DBG_CFG_VAR_DONE | VBOXGLOBAL_DBG_CFG_VAR_FALSE;
|
---|
5292 | else if (strEnvValue.isNull() && strExtraValue.isNull())
|
---|
5293 | *piDbgCfgVar = fDefault ? VBOXGLOBAL_DBG_CFG_VAR_TRUE : VBOXGLOBAL_DBG_CFG_VAR_FALSE;
|
---|
5294 | else
|
---|
5295 | {
|
---|
5296 | QString *pStr = !strEnvValue.isEmpty() ? &strEnvValue : &strExtraValue;
|
---|
5297 | if ( pStr->startsWith("y") // yes
|
---|
5298 | || pStr->startsWith("e") // enabled
|
---|
5299 | || pStr->startsWith("t") // true
|
---|
5300 | || pStr->startsWith("on")
|
---|
5301 | || pStr->toLongLong() != 0)
|
---|
5302 | *piDbgCfgVar = VBOXGLOBAL_DBG_CFG_VAR_TRUE;
|
---|
5303 | else if ( pStr->startsWith("n") // o
|
---|
5304 | || pStr->startsWith("d") // disable
|
---|
5305 | || pStr->startsWith("f") // false
|
---|
5306 | || pStr->startsWith("off")
|
---|
5307 | || pStr->contains("veto")
|
---|
5308 | || pStr->toLongLong() == 0)
|
---|
5309 | *piDbgCfgVar = VBOXGLOBAL_DBG_CFG_VAR_FALSE;
|
---|
5310 | else
|
---|
5311 | {
|
---|
5312 | LogFunc(("Ignoring unknown value '%s' for '%s'\n", pStr->toAscii().constData(), pStr == &strEnvValue ? pszEnvVar : pszExtraDataName));
|
---|
5313 | *piDbgCfgVar = fDefault ? VBOXGLOBAL_DBG_CFG_VAR_TRUE : VBOXGLOBAL_DBG_CFG_VAR_FALSE;
|
---|
5314 | }
|
---|
5315 | }
|
---|
5316 | }
|
---|
5317 |
|
---|
5318 | /**
|
---|
5319 | * Set a debugger config variable according according to start up argument.
|
---|
5320 | *
|
---|
5321 | * @param piDbgCfgVar The debugger config variable to set.
|
---|
5322 | * @param fState The value from the command line.
|
---|
5323 | */
|
---|
5324 | void VBoxGlobal::setDebuggerVar(int *piDbgCfgVar, bool fState)
|
---|
5325 | {
|
---|
5326 | if (!(*piDbgCfgVar & VBOXGLOBAL_DBG_CFG_VAR_DONE))
|
---|
5327 | *piDbgCfgVar = (fState ? VBOXGLOBAL_DBG_CFG_VAR_TRUE : VBOXGLOBAL_DBG_CFG_VAR_FALSE)
|
---|
5328 | | VBOXGLOBAL_DBG_CFG_VAR_CMD_LINE;
|
---|
5329 | }
|
---|
5330 |
|
---|
5331 | /**
|
---|
5332 | * Checks the state of a debugger config variable, updating it with the machine
|
---|
5333 | * settings on the first invocation.
|
---|
5334 | *
|
---|
5335 | * @returns true / false.
|
---|
5336 | * @param piDbgCfgVar The debugger config variable to consult.
|
---|
5337 | * @param rMachine Reference to the machine object.
|
---|
5338 | * @param pszExtraDataName The extra data name relating to this variable.
|
---|
5339 | */
|
---|
5340 | bool VBoxGlobal::isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName)
|
---|
5341 | {
|
---|
5342 | if (!(*piDbgCfgVar & VBOXGLOBAL_DBG_CFG_VAR_DONE) && !rMachine.isNull())
|
---|
5343 | {
|
---|
5344 | QString str = mVBox.GetExtraData(pszExtraDataName).toLower().trimmed();
|
---|
5345 | if (str.contains("veto"))
|
---|
5346 | *piDbgCfgVar = VBOXGLOBAL_DBG_CFG_VAR_DONE | VBOXGLOBAL_DBG_CFG_VAR_FALSE;
|
---|
5347 | else if (str.isEmpty() || (*piDbgCfgVar & VBOXGLOBAL_DBG_CFG_VAR_CMD_LINE))
|
---|
5348 | *piDbgCfgVar |= VBOXGLOBAL_DBG_CFG_VAR_DONE;
|
---|
5349 | else if ( str.startsWith("y") // yes
|
---|
5350 | || str.startsWith("e") // enabled
|
---|
5351 | || str.startsWith("t") // true
|
---|
5352 | || str.startsWith("on")
|
---|
5353 | || str.toLongLong() != 0)
|
---|
5354 | *piDbgCfgVar = VBOXGLOBAL_DBG_CFG_VAR_DONE | VBOXGLOBAL_DBG_CFG_VAR_TRUE;
|
---|
5355 | else if ( str.startsWith("n") // no
|
---|
5356 | || str.startsWith("d") // disable
|
---|
5357 | || str.startsWith("f") // false
|
---|
5358 | || str.toLongLong() == 0)
|
---|
5359 | *piDbgCfgVar = VBOXGLOBAL_DBG_CFG_VAR_DONE | VBOXGLOBAL_DBG_CFG_VAR_FALSE;
|
---|
5360 | else
|
---|
5361 | *piDbgCfgVar |= VBOXGLOBAL_DBG_CFG_VAR_DONE;
|
---|
5362 | }
|
---|
5363 |
|
---|
5364 | return (*piDbgCfgVar & VBOXGLOBAL_DBG_CFG_VAR_MASK) == VBOXGLOBAL_DBG_CFG_VAR_TRUE;
|
---|
5365 | }
|
---|
5366 |
|
---|
5367 | #endif /* VBOX_WITH_DEBUGGER_GUI */
|
---|
5368 |
|
---|
5369 | /** @fn vboxGlobal
|
---|
5370 | *
|
---|
5371 | * Shortcut to the static VBoxGlobal::instance() method, for convenience.
|
---|
5372 | */
|
---|
5373 |
|
---|
5374 | /**
|
---|
5375 | * USB Popup Menu class methods
|
---|
5376 | * This class provides the list of USB devices attached to the host.
|
---|
5377 | */
|
---|
5378 | VBoxUSBMenu::VBoxUSBMenu (QWidget *aParent) : QMenu (aParent)
|
---|
5379 | {
|
---|
5380 | connect (this, SIGNAL (aboutToShow()),
|
---|
5381 | this, SLOT (processAboutToShow()));
|
---|
5382 | // connect (this, SIGNAL (hovered (QAction *)),
|
---|
5383 | // this, SLOT (processHighlighted (QAction *)));
|
---|
5384 | }
|
---|
5385 |
|
---|
5386 | const CUSBDevice& VBoxUSBMenu::getUSB (QAction *aAction)
|
---|
5387 | {
|
---|
5388 | return mUSBDevicesMap [aAction];
|
---|
5389 | }
|
---|
5390 |
|
---|
5391 | void VBoxUSBMenu::setConsole (const CConsole &aConsole)
|
---|
5392 | {
|
---|
5393 | mConsole = aConsole;
|
---|
5394 | }
|
---|
5395 |
|
---|
5396 | void VBoxUSBMenu::processAboutToShow()
|
---|
5397 | {
|
---|
5398 | clear();
|
---|
5399 | mUSBDevicesMap.clear();
|
---|
5400 |
|
---|
5401 | CHost host = vboxGlobal().virtualBox().GetHost();
|
---|
5402 |
|
---|
5403 | bool isUSBEmpty = host.GetUSBDevices().size() == 0;
|
---|
5404 | if (isUSBEmpty)
|
---|
5405 | {
|
---|
5406 | QAction *action = addAction (tr ("<no devices available>", "USB devices"));
|
---|
5407 | action->setEnabled (false);
|
---|
5408 | action->setToolTip (tr ("No supported devices connected to the host PC",
|
---|
5409 | "USB device tooltip"));
|
---|
5410 | }
|
---|
5411 | else
|
---|
5412 | {
|
---|
5413 | CHostUSBDeviceVector devvec = host.GetUSBDevices();
|
---|
5414 | for (int i = 0; i < devvec.size(); ++i)
|
---|
5415 | {
|
---|
5416 | CHostUSBDevice dev = devvec[i];
|
---|
5417 | CUSBDevice usb (dev);
|
---|
5418 | QAction *action = addAction (vboxGlobal().details (usb));
|
---|
5419 | action->setCheckable (true);
|
---|
5420 | mUSBDevicesMap [action] = usb;
|
---|
5421 | /* check if created item was already attached to this session */
|
---|
5422 | if (!mConsole.isNull())
|
---|
5423 | {
|
---|
5424 | CUSBDevice attachedUSB =
|
---|
5425 | mConsole.FindUSBDeviceById (usb.GetId());
|
---|
5426 | action->setChecked (!attachedUSB.isNull());
|
---|
5427 | action->setEnabled (dev.GetState() !=
|
---|
5428 | KUSBDeviceState_Unavailable);
|
---|
5429 | }
|
---|
5430 | }
|
---|
5431 | }
|
---|
5432 | }
|
---|
5433 |
|
---|
5434 | bool VBoxUSBMenu::event(QEvent *aEvent)
|
---|
5435 | {
|
---|
5436 | /* We provide dynamic tooltips for the usb devices */
|
---|
5437 | if (aEvent->type() == QEvent::ToolTip)
|
---|
5438 | {
|
---|
5439 | QHelpEvent *helpEvent = static_cast<QHelpEvent *> (aEvent);
|
---|
5440 | QAction *action = actionAt (helpEvent->pos());
|
---|
5441 | if (action)
|
---|
5442 | {
|
---|
5443 | CUSBDevice usb = mUSBDevicesMap [action];
|
---|
5444 | if (!usb.isNull())
|
---|
5445 | {
|
---|
5446 | QToolTip::showText (helpEvent->globalPos(), vboxGlobal().toolTip (usb));
|
---|
5447 | return true;
|
---|
5448 | }
|
---|
5449 | }
|
---|
5450 | }
|
---|
5451 | return QMenu::event (aEvent);
|
---|
5452 | }
|
---|
5453 |
|
---|
5454 | /**
|
---|
5455 | * Enable/Disable Menu class.
|
---|
5456 | * This class provides enable/disable menu items.
|
---|
5457 | */
|
---|
5458 | VBoxSwitchMenu::VBoxSwitchMenu (QWidget *aParent, QAction *aAction,
|
---|
5459 | bool aInverted)
|
---|
5460 | : QMenu (aParent), mAction (aAction), mInverted (aInverted)
|
---|
5461 | {
|
---|
5462 | /* this menu works only with toggle action */
|
---|
5463 | Assert (aAction->isCheckable());
|
---|
5464 | addAction(aAction);
|
---|
5465 | connect (this, SIGNAL (aboutToShow()),
|
---|
5466 | this, SLOT (processAboutToShow()));
|
---|
5467 | }
|
---|
5468 |
|
---|
5469 | void VBoxSwitchMenu::setToolTip (const QString &aTip)
|
---|
5470 | {
|
---|
5471 | mAction->setToolTip (aTip);
|
---|
5472 | }
|
---|
5473 |
|
---|
5474 | void VBoxSwitchMenu::processAboutToShow()
|
---|
5475 | {
|
---|
5476 | QString text = mAction->isChecked() ^ mInverted ? tr ("Disable") : tr ("Enable");
|
---|
5477 | mAction->setText (text);
|
---|
5478 | }
|
---|
5479 |
|
---|
5480 | bool VBoxGlobal::switchToMachine(CMachine &machine)
|
---|
5481 | {
|
---|
5482 | #ifdef Q_WS_MAC
|
---|
5483 | ULONG64 id = machine.ShowConsoleWindow();
|
---|
5484 | #else
|
---|
5485 | WId id = (WId) machine.ShowConsoleWindow();
|
---|
5486 | #endif
|
---|
5487 | AssertWrapperOk(machine);
|
---|
5488 | if (!machine.isOk())
|
---|
5489 | return false;
|
---|
5490 |
|
---|
5491 | /* winId = 0 it means the console window has already done everything
|
---|
5492 | * necessary to implement the "show window" semantics. */
|
---|
5493 | if (id == 0)
|
---|
5494 | return true;
|
---|
5495 |
|
---|
5496 | #if defined (Q_WS_WIN32) || defined (Q_WS_X11)
|
---|
5497 |
|
---|
5498 | return vboxGlobal().activateWindow(id, true);
|
---|
5499 |
|
---|
5500 | #elif defined (Q_WS_MAC)
|
---|
5501 | /*
|
---|
5502 | * This is just for the case were the other process cannot steal
|
---|
5503 | * the focus from us. It will send us a PSN so we can try.
|
---|
5504 | */
|
---|
5505 | ProcessSerialNumber psn;
|
---|
5506 | psn.highLongOfPSN = id >> 32;
|
---|
5507 | psn.lowLongOfPSN = (UInt32)id;
|
---|
5508 | OSErr rc = ::SetFrontProcess(&psn);
|
---|
5509 | if (!rc)
|
---|
5510 | Log(("GUI: %#RX64 couldn't do SetFrontProcess on itself, the selector (we) had to do it...\n", id));
|
---|
5511 | else
|
---|
5512 | Log(("GUI: Failed to bring %#RX64 to front. rc=%#x\n", id, rc));
|
---|
5513 | return !rc;
|
---|
5514 |
|
---|
5515 | #endif
|
---|
5516 |
|
---|
5517 | return false;
|
---|
5518 |
|
---|
5519 | /// @todo Below is the old method of switching to the console window
|
---|
5520 | // based on the process ID of the console process. It should go away
|
---|
5521 | // after the new (callback-based) method is fully tested.
|
---|
5522 | #if 0
|
---|
5523 |
|
---|
5524 | if (!canSwitchTo())
|
---|
5525 | return false;
|
---|
5526 |
|
---|
5527 | #if defined (Q_WS_WIN32)
|
---|
5528 |
|
---|
5529 | HWND hwnd = mWinId;
|
---|
5530 |
|
---|
5531 | /* if there are blockers (modal and modeless dialogs, etc), find the
|
---|
5532 | * topmost one */
|
---|
5533 | HWND hwndAbove = NULL;
|
---|
5534 | do
|
---|
5535 | {
|
---|
5536 | hwndAbove = GetNextWindow(hwnd, GW_HWNDPREV);
|
---|
5537 | HWND hwndOwner;
|
---|
5538 | if (hwndAbove != NULL &&
|
---|
5539 | ((hwndOwner = GetWindow(hwndAbove, GW_OWNER)) == hwnd ||
|
---|
5540 | hwndOwner == hwndAbove))
|
---|
5541 | hwnd = hwndAbove;
|
---|
5542 | else
|
---|
5543 | break;
|
---|
5544 | }
|
---|
5545 | while (1);
|
---|
5546 |
|
---|
5547 | /* first, check that the primary window is visible */
|
---|
5548 | if (IsIconic(mWinId))
|
---|
5549 | ShowWindow(mWinId, SW_RESTORE);
|
---|
5550 | else if (!IsWindowVisible(mWinId))
|
---|
5551 | ShowWindow(mWinId, SW_SHOW);
|
---|
5552 |
|
---|
5553 | #if 0
|
---|
5554 | LogFlowFunc(("mWinId=%08X hwnd=%08X\n", mWinId, hwnd));
|
---|
5555 | #endif
|
---|
5556 |
|
---|
5557 | /* then, activate the topmost in the group */
|
---|
5558 | AllowSetForegroundWindow(m_pid);
|
---|
5559 | SetForegroundWindow(hwnd);
|
---|
5560 |
|
---|
5561 | return true;
|
---|
5562 |
|
---|
5563 | #elif defined (Q_WS_X11)
|
---|
5564 |
|
---|
5565 | return false;
|
---|
5566 |
|
---|
5567 | #elif defined (Q_WS_MAC)
|
---|
5568 |
|
---|
5569 | ProcessSerialNumber psn;
|
---|
5570 | OSStatus rc = ::GetProcessForPID(m_pid, &psn);
|
---|
5571 | if (!rc)
|
---|
5572 | {
|
---|
5573 | rc = ::SetFrontProcess(&psn);
|
---|
5574 |
|
---|
5575 | if (!rc)
|
---|
5576 | {
|
---|
5577 | ShowHideProcess(&psn, true);
|
---|
5578 | return true;
|
---|
5579 | }
|
---|
5580 | }
|
---|
5581 | return false;
|
---|
5582 |
|
---|
5583 | #else
|
---|
5584 |
|
---|
5585 | return false;
|
---|
5586 |
|
---|
5587 | #endif
|
---|
5588 |
|
---|
5589 | #endif
|
---|
5590 | }
|
---|
5591 |
|
---|
5592 | bool VBoxGlobal::launchMachine(CMachine &machine)
|
---|
5593 | {
|
---|
5594 | if (machine.CanShowConsoleWindow())
|
---|
5595 | return VBoxGlobal::switchToMachine(machine);
|
---|
5596 |
|
---|
5597 | KMachineState state = machine.GetState(); NOREF(state);
|
---|
5598 | AssertMsg( state == KMachineState_PoweredOff
|
---|
5599 | || state == KMachineState_Saved
|
---|
5600 | || state == KMachineState_Teleported
|
---|
5601 | || state == KMachineState_Aborted
|
---|
5602 | , ("Machine must be PoweredOff/Saved/Aborted (%d)", state));
|
---|
5603 |
|
---|
5604 | CVirtualBox vbox = vboxGlobal().virtualBox();
|
---|
5605 | CSession session;
|
---|
5606 | session.createInstance(CLSID_Session);
|
---|
5607 | if (session.isNull())
|
---|
5608 | {
|
---|
5609 | vboxProblem().cannotOpenSession(session);
|
---|
5610 | return false;
|
---|
5611 | }
|
---|
5612 |
|
---|
5613 | #if defined(Q_OS_WIN32)
|
---|
5614 | /* allow the started VM process to make itself the foreground window */
|
---|
5615 | AllowSetForegroundWindow(ASFW_ANY);
|
---|
5616 | #endif
|
---|
5617 |
|
---|
5618 | QString env;
|
---|
5619 | #if defined(Q_WS_X11)
|
---|
5620 | /* make sure the VM process will start on the same display as the Selector */
|
---|
5621 | const char *display = RTEnvGet("DISPLAY");
|
---|
5622 | if (display)
|
---|
5623 | env.append(QString("DISPLAY=%1\n").arg(display));
|
---|
5624 | const char *xauth = RTEnvGet("XAUTHORITY");
|
---|
5625 | if (xauth)
|
---|
5626 | env.append(QString("XAUTHORITY=%1\n").arg(xauth));
|
---|
5627 | #endif
|
---|
5628 |
|
---|
5629 | CProgress progress = machine.LaunchVMProcess(session, "GUI/Qt", env);
|
---|
5630 | if ( !vbox.isOk()
|
---|
5631 | || progress.isNull())
|
---|
5632 | {
|
---|
5633 | vboxProblem().cannotOpenSession(vbox, machine);
|
---|
5634 | return false;
|
---|
5635 | }
|
---|
5636 |
|
---|
5637 | /* Hide the "VM spawning" progress dialog */
|
---|
5638 | /* I hope 1 minute will be enough to spawn any running VM silently, isn't it? */
|
---|
5639 | int iSpawningDuration = 60000;
|
---|
5640 | vboxProblem().showModalProgressDialog(progress, machine.GetName(), "", 0, false, iSpawningDuration);
|
---|
5641 | if (progress.GetResultCode() != 0)
|
---|
5642 | vboxProblem().cannotOpenSession(vbox, machine, progress);
|
---|
5643 |
|
---|
5644 | session.UnlockMachine();
|
---|
5645 |
|
---|
5646 | return true;
|
---|
5647 | }
|
---|