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