VirtualBox

Changeset 41590 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 6, 2012 6:15:39 AM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: Move QIProcess out of VBoxGlobal into separate file.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r41588 r41590  
    256256        src/extensions/QIMainDialog.h \
    257257        src/extensions/QIMessageBox.h \
     258        src/extensions/QIProcess.h \
    258259        src/extensions/QIRichTextLabel.h \
    259260        src/extensions/QIRichToolButton.h \
     
    456457        src/extensions/QIMainDialog.cpp \
    457458        src/extensions/QIMessageBox.cpp \
     459        src/extensions/QIProcess.cpp \
    458460        src/extensions/QIRichTextLabel.cpp \
    459461        src/extensions/QIRichToolButton.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIProcess.cpp

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h74233
    r41589 r41590  
     1/* $Id$ */
    12/** @file
    23 *
    34 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VBoxGlobal class declaration
     5 * QIProcess class implementation
    56 */
    67
    78/*
    8  * Copyright (C) 2006-2011 Oracle Corporation
     9 * Copyright (C) 2006-2012 Oracle Corporation
    910 *
    1011 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1718 */
    1819
    19 #ifndef __VBoxGlobal_h__
    20 #define __VBoxGlobal_h__
     20/* GUI includes: */
     21#include "QIProcess.h"
    2122
    22 /* Qt includes: */
    23 #include <QApplication>
    24 #include <QLayout>
    25 #include <QMenu>
    26 #include <QStyle>
    27 #include <QProcess>
    28 #include <QHash>
    29 #include <QFileIconProvider>
    30 
    31 /* GUI includes: */
    32 #include "VBoxGlobalSettings.h"
    33 #include "VBoxMedium.h"
    34 
    35 /* COM includes: */
    36 #include "VBox/com/Guid.h"
    37 #include "COMEnums.h"
    38 #include "CHost.h"
    39 #include "CVirtualBox.h"
    40 #include "CSession.h"
    41 #include "CConsole.h"
    42 #include "CMachine.h"
    43 #include "CMedium.h"
    44 #include "CGuestOSType.h"
    45 #include "CUSBDevice.h"
    46 
    47 /* Other VBox includes: */
     23/* External includes: */
    4824#ifdef Q_WS_X11
    4925# include <sys/wait.h>
    5026#endif /* Q_WS_X11 */
    5127
    52 /* Forward declarations: */
    53 class QAction;
    54 class QLabel;
    55 class QToolButton;
    56 class UIMachine;
     28/* static */
     29QByteArray QIProcess::singleShot(const QString &strProcessName, int iTimeout)
     30{
     31    /* Why is it really needed is because of Qt4.3 bug with QProcess.
     32     * This bug is about QProcess sometimes (~70%) do not receive
     33     * notification about process was finished, so this makes
     34     * 'bool QProcess::waitForFinished (int)' block the GUI thread and
     35     * never dismissed with 'true' result even if process was really
     36     * started&finished. So we just waiting for some information
     37     * on process output and destroy the process with force. Due to
     38     * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
     39     * we have to change process state to QProcess::NotRunning. */
    5740
    58 class Process : public QProcess
     41    QByteArray result;
     42    QIProcess process;
     43    process.start(strProcessName);
     44    bool firstShotReady = process.waitForReadyRead(iTimeout);
     45    if (firstShotReady)
     46        result = process.readAllStandardOutput();
     47    process.setProcessState(QProcess::NotRunning);
     48#ifdef Q_WS_X11
     49    int iStatus;
     50    if (process.pid() > 0)
     51        waitpid(process.pid(), &iStatus, 0);
     52#endif /* Q_WS_X11 */
     53    return result;
     54}
     55
     56QIProcess::QIProcess(QObject *pParent /* = 0 */)
     57    : QProcess(pParent)
    5958{
    60     Q_OBJECT;
     59}
    6160
    62 public:
    63 
    64     static QByteArray singleShot (const QString &aProcessName,
    65                                   int aTimeout = 5000
    66                                   /* wait for data maximum 5 seconds */)
    67     {
    68         /* Why is it really needed is because of Qt4.3 bug with QProcess.
    69          * This bug is about QProcess sometimes (~70%) do not receive
    70          * notification about process was finished, so this makes
    71          * 'bool QProcess::waitForFinished (int)' block the GUI thread and
    72          * never dismissed with 'true' result even if process was really
    73          * started&finished. So we just waiting for some information
    74          * on process output and destroy the process with force. Due to
    75          * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
    76          * we have to change process state to QProcess::NotRunning. */
    77 
    78         QByteArray result;
    79         Process process;
    80         process.start (aProcessName);
    81         bool firstShotReady = process.waitForReadyRead (aTimeout);
    82         if (firstShotReady)
    83             result = process.readAllStandardOutput();
    84         process.setProcessState (QProcess::NotRunning);
    85 #ifdef Q_WS_X11
    86         int status;
    87         if (process.pid() > 0)
    88             waitpid(process.pid(), &status, 0);
    89 #endif
    90         return result;
    91     }
    92 
    93 protected:
    94 
    95     Process (QWidget *aParent = 0) : QProcess (aParent) {}
    96 };
    97 
    98 struct StorageSlot
    99 {
    100     StorageSlot() : bus (KStorageBus_Null), port (0), device (0) {}
    101     StorageSlot (const StorageSlot &aOther) : bus (aOther.bus), port (aOther.port), device (aOther.device) {}
    102     StorageSlot (KStorageBus aBus, LONG aPort, LONG aDevice) : bus (aBus), port (aPort), device (aDevice) {}
    103     StorageSlot& operator= (const StorageSlot &aOther) { bus = aOther.bus; port = aOther.port; device = aOther.device; return *this; }
    104     bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; }
    105     bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; }
    106     bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) ||
    107                                                               (bus == aOther.bus && port < aOther.port) ||
    108                                                               (bus == aOther.bus && port == aOther.port && device < aOther.device); }
    109     bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) ||
    110                                                               (bus == aOther.bus && port > aOther.port) ||
    111                                                               (bus == aOther.bus && port == aOther.port && device > aOther.device); }
    112     bool isNull() { return bus == KStorageBus_Null; }
    113     KStorageBus bus; LONG port; LONG device;
    114 };
    115 Q_DECLARE_METATYPE (StorageSlot);
    116 
    117 // VBoxGlobal class
    118 ////////////////////////////////////////////////////////////////////////////////
    119 
    120 class UISelectorWindow;
    121 class UIRegistrationWzd;
    122 class VBoxUpdateDlg;
    123 
    124 class VBoxGlobal : public QObject
    125 {
    126     Q_OBJECT
    127 
    128 public:
    129 
    130     typedef QHash <ulong, QString> QULongStringHash;
    131     typedef QHash <long, QString> QLongStringHash;
    132 
    133     static VBoxGlobal &instance();
    134 
    135     bool isValid() { return mValid; }
    136 
    137     static QString qtRTVersionString();
    138     static uint qtRTVersion();
    139     static QString qtCTVersionString();
    140     static uint qtCTVersion();
    141 
    142     QString vboxVersionString() const;
    143     QString vboxVersionStringNormalized() const;
    144 
    145     QString versionString() const { return mVerString; }
    146     bool isBeta() const;
    147 
    148     CVirtualBox virtualBox() const { return mVBox; }
    149     CHost host() const { return mHost; }
    150 
    151     VBoxGlobalSettings &settings() { return gset; }
    152     bool setSettings (VBoxGlobalSettings &gs);
    153 
    154     UISelectorWindow &selectorWnd();
    155 
    156     /* VM stuff: */
    157     bool startMachine(const QString &strMachineId);
    158     UIMachine* virtualMachine();
    159     QWidget* vmWindow();
    160 
    161     /* Main application window storage: */
    162     void setMainWindow(QWidget *pMainWindow) { mMainWindow = pMainWindow; }
    163     QWidget* mainWindow() const { return mMainWindow; }
    164 
    165     bool is3DAvailable() const { return m3DAvailable; }
    166 
    167 #ifdef VBOX_GUI_WITH_PIDFILE
    168     void createPidfile();
    169     void deletePidfile();
    170 #endif
    171 
    172     /* branding */
    173     bool brandingIsActive (bool aForce = false);
    174     QString brandingGetKey (QString aKey);
    175 
    176     bool processArgs();
    177 
    178     bool switchToMachine(CMachine &machine);
    179     bool launchMachine(CMachine &machine, bool fHeadless = false);
    180 
    181     bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
    182     bool showStartVMErrors() const { return mShowStartVMErrors; }
    183 #ifdef VBOX_GUI_WITH_SYSTRAY
    184     bool isTrayMenu() const;
    185     void setTrayMenu(bool aIsTrayMenu);
    186     void trayIconShowSelector();
    187     bool trayIconInstall();
    188 #endif
    189     QString managedVMUuid() const { return vmUuid; }
    190     QList<QUrl> &argUrlList() { return m_ArgUrlList; }
    191 
    192     VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
    193     const char *vmRenderModeStr() const { return vm_render_mode_str; }
    194     bool isKWinManaged() const { return mIsKWinManaged; }
    195 
    196     const QRect availableGeometry(int iScreen = 0) const;
    197 
    198     bool isPatmDisabled() const { return mDisablePatm; }
    199     bool isCsamDisabled() const { return mDisableCsam; }
    200     bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
    201     bool isUserCodeExecedRecompiled()       const { return mRecompileUser; }
    202 
    203 #ifdef VBOX_WITH_DEBUGGER_GUI
    204     bool isDebuggerEnabled(CMachine &aMachine);
    205     bool isDebuggerAutoShowEnabled(CMachine &aMachine);
    206     bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
    207     bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
    208     RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
    209 
    210     bool isStartPausedEnabled() const { return mStartPaused; }
    211 #else
    212     bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
    213     bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
    214     bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
    215 
    216     bool isStartPausedEnabled() const { return false; }
    217 #endif
    218 
    219     /* VBox enum to/from string/icon/color convertors */
    220 
    221     QList <CGuestOSType> vmGuestOSFamilyList() const;
    222     QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
    223     QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
    224     CGuestOSType vmGuestOSType (const QString &aTypeId,
    225                                 const QString &aFamilyId = QString::null) const;
    226     QString vmGuestOSTypeDescription (const QString &aTypeId) const;
    227 
    228     QPixmap toIcon (KMachineState s) const
    229     {
    230         QPixmap *pm = mVMStateIcons.value (s);
    231         AssertMsg (pm, ("Icon for VM state %d must be defined", s));
    232         return pm ? *pm : QPixmap();
    233     }
    234 
    235     static inline QString yearsToString (uint32_t cVal)
    236     {
    237         return tr("%n year(s)", "", cVal);
    238     }
    239 
    240     static inline QString monthsToString (uint32_t cVal)
    241     {
    242         return tr("%n month(s)", "", cVal);
    243     }
    244 
    245     static inline QString daysToString (uint32_t cVal)
    246     {
    247         return tr("%n day(s)", "", cVal);
    248     }
    249 
    250     static inline QString hoursToString (uint32_t cVal)
    251     {
    252         return tr("%n hour(s)", "", cVal);
    253     }
    254 
    255     static inline QString minutesToString (uint32_t cVal)
    256     {
    257         return tr("%n minute(s)", "", cVal);
    258     }
    259 
    260     static inline QString secondsToString (uint32_t cVal)
    261     {
    262         return tr("%n second(s)", "", cVal);
    263     }
    264 
    265     const QColor &toColor (KMachineState s) const
    266     {
    267         static const QColor none;
    268         AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
    269         return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
    270     }
    271 
    272     QString toString (KMachineState s) const
    273     {
    274         AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
    275         return mMachineStates.value (s);
    276     }
    277 
    278     QString toString (KSessionState s) const
    279     {
    280         AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
    281         return mSessionStates.value (s);
    282     }
    283 
    284     /**
    285      * Returns a string representation of the given KStorageBus enum value.
    286      * Complementary to #toStorageBusType (const QString &) const.
    287      */
    288     QString toString (KStorageBus aBus) const
    289     {
    290         AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
    291         return mStorageBuses [aBus];
    292     }
    293 
    294     /**
    295      * Returns a KStorageBus enum value corresponding to the given string
    296      * representation. Complementary to #toString (KStorageBus) const.
    297      */
    298     KStorageBus toStorageBusType (const QString &aBus) const
    299     {
    300         QULongStringHash::const_iterator it =
    301             qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
    302         AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
    303                                                aBus.toLatin1().constData()));
    304         return KStorageBus (it.key());
    305     }
    306 
    307     KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
    308     {
    309         KStorageBus sb = KStorageBus_Null;
    310         switch (aControllerType)
    311         {
    312             case KStorageControllerType_Null: sb = KStorageBus_Null; break;
    313             case KStorageControllerType_PIIX3:
    314             case KStorageControllerType_PIIX4:
    315             case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
    316             case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
    317             case KStorageControllerType_LsiLogic:
    318             case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
    319             case KStorageControllerType_I82078: sb = KStorageBus_Floppy; break;
    320             default:
    321               AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
    322         }
    323         return sb;
    324     }
    325 
    326     QString toString (KStorageBus aBus, LONG aChannel) const;
    327     LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
    328 
    329     QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
    330     LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
    331 
    332     QString toString (StorageSlot aSlot) const;
    333     StorageSlot toStorageSlot (const QString &aSlot) const;
    334 
    335     QString toString (KMediumType t) const
    336     {
    337         AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
    338         return mDiskTypes.value (t);
    339     }
    340     QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
    341 
    342     QString toString(KMediumVariant mediumVariant) const;
    343 
    344     /**
    345      * Similar to toString (KMediumType), but returns 'Differencing' for
    346      * normal hard disks that have a parent.
    347      */
    348     QString mediumTypeString (const CMedium &aHD) const
    349     {
    350         if (!aHD.GetParent().isNull())
    351         {
    352             Assert (aHD.GetType() == KMediumType_Normal);
    353             return mDiskTypes_Differencing;
    354         }
    355         return toString (aHD.GetType());
    356     }
    357 
    358     QString toString (KAuthType t) const
    359     {
    360         AssertMsg (!mAuthTypes.value (t).isNull(), ("No text for %d", t));
    361         return mAuthTypes.value (t);
    362     }
    363 
    364     QString toString (KPortMode t) const
    365     {
    366         AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
    367         return mPortModeTypes.value (t);
    368     }
    369 
    370     QString toString (KUSBDeviceFilterAction t) const
    371     {
    372         AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
    373         return mUSBFilterActionTypes.value (t);
    374     }
    375 
    376     QString toString (KClipboardMode t) const
    377     {
    378         AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
    379         return mClipboardTypes.value (t);
    380     }
    381 
    382     KClipboardMode toClipboardModeType (const QString &s) const
    383     {
    384         QULongStringHash::const_iterator it =
    385             qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
    386         AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
    387                                                  s.toLatin1().constData()));
    388         return KClipboardMode (it.key());
    389     }
    390 
    391     QString toString (KStorageControllerType t) const
    392     {
    393         AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
    394         return mStorageControllerTypes.value (t);
    395     }
    396 
    397     KStorageControllerType toControllerType (const QString &s) const
    398     {
    399         QULongStringHash::const_iterator it =
    400             qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
    401         AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
    402                                                          s.toLatin1().constData()));
    403         return KStorageControllerType (it.key());
    404     }
    405 
    406     KAuthType toAuthType (const QString &s) const
    407     {
    408         QULongStringHash::const_iterator it =
    409             qFind (mAuthTypes.begin(), mAuthTypes.end(), s);
    410         AssertMsg (it != mAuthTypes.end(), ("No value for {%s}",
    411                                                 s.toLatin1().constData()));
    412         return KAuthType (it.key());
    413     }
    414 
    415     KPortMode toPortMode (const QString &s) const
    416     {
    417         QULongStringHash::const_iterator it =
    418             qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
    419         AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
    420                                                 s.toLatin1().constData()));
    421         return KPortMode (it.key());
    422     }
    423 
    424     KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
    425     {
    426         QULongStringHash::const_iterator it =
    427             qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
    428         AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
    429                                                        s.toLatin1().constData()));
    430         return KUSBDeviceFilterAction (it.key());
    431     }
    432 
    433     QString toString (KDeviceType t) const
    434     {
    435         AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
    436         return mDeviceTypes.value (t);
    437     }
    438 
    439     KDeviceType toDeviceType (const QString &s) const
    440     {
    441         QULongStringHash::const_iterator it =
    442             qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
    443         AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
    444                                               s.toLatin1().constData()));
    445         return KDeviceType (it.key());
    446     }
    447 
    448     QStringList deviceTypeStrings() const;
    449 
    450     QString toString (KAudioDriverType t) const
    451     {
    452         AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
    453         return mAudioDriverTypes.value (t);
    454     }
    455 
    456     KAudioDriverType toAudioDriverType (const QString &s) const
    457     {
    458         QULongStringHash::const_iterator it =
    459             qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
    460         AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
    461                                                    s.toLatin1().constData()));
    462         return KAudioDriverType (it.key());
    463     }
    464 
    465     QString toString (KAudioControllerType t) const
    466     {
    467         AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
    468         return mAudioControllerTypes.value (t);
    469     }
    470 
    471     KAudioControllerType toAudioControllerType (const QString &s) const
    472     {
    473         QULongStringHash::const_iterator it =
    474             qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
    475         AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
    476                                                        s.toLatin1().constData()));
    477         return KAudioControllerType (it.key());
    478     }
    479 
    480     QString toString (KNetworkAdapterType t) const
    481     {
    482         AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
    483         return mNetworkAdapterTypes.value (t);
    484     }
    485 
    486     KNetworkAdapterType toNetworkAdapterType (const QString &s) const
    487     {
    488         QULongStringHash::const_iterator it =
    489             qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
    490         AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
    491                                                       s.toLatin1().constData()));
    492         return KNetworkAdapterType (it.key());
    493     }
    494 
    495     QString toString (KNetworkAttachmentType t) const
    496     {
    497         AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
    498         return mNetworkAttachmentTypes.value (t);
    499     }
    500 
    501     KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
    502     {
    503         QULongStringHash::const_iterator it =
    504             qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
    505         AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
    506                                                          s.toLatin1().constData()));
    507         return KNetworkAttachmentType (it.key());
    508     }
    509 
    510     QString toString (KNetworkAdapterPromiscModePolicy t) const
    511     {
    512         AssertMsg (!mNetworkAdapterPromiscModePolicyTypes.value (t).isNull(), ("No text for %d", t));
    513         return mNetworkAdapterPromiscModePolicyTypes.value (t);
    514     }
    515 
    516     KNetworkAdapterPromiscModePolicy toNetworkAdapterPromiscModePolicyType (const QString &s) const
    517     {
    518         QULongStringHash::const_iterator it =
    519             qFind (mNetworkAdapterPromiscModePolicyTypes.begin(), mNetworkAdapterPromiscModePolicyTypes.end(), s);
    520         AssertMsg (it != mNetworkAdapterPromiscModePolicyTypes.end(), ("No value for {%s}",
    521                                                                        s.toLatin1().constData()));
    522         return KNetworkAdapterPromiscModePolicy (it.key());
    523     }
    524 
    525     QString toString (KNATProtocol t) const
    526     {
    527         AssertMsg (!mNATProtocolTypes.value (t).isNull(), ("No text for %d", t));
    528         return mNATProtocolTypes.value (t);
    529     }
    530 
    531     KNATProtocol toNATProtocolType (const QString &s) const
    532     {
    533         QULongStringHash::const_iterator it =
    534             qFind (mNATProtocolTypes.begin(), mNATProtocolTypes.end(), s);
    535         AssertMsg (it != mNATProtocolTypes.end(), ("No value for {%s}",
    536                                                    s.toLatin1().constData()));
    537         return KNATProtocol (it.key());
    538     }
    539 
    540     QString toString (KUSBDeviceState aState) const
    541     {
    542         AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
    543         return mUSBDeviceStates.value (aState);
    544     }
    545 
    546     QString toString (KChipsetType t) const
    547     {
    548         AssertMsg (!mChipsetTypes.value (t).isNull(), ("No text for %d", t));
    549         return mChipsetTypes.value (t);
    550     }
    551 
    552     KChipsetType toChipsetType (const QString &s) const
    553     {
    554         QULongStringHash::const_iterator it =
    555             qFind (mChipsetTypes.begin(), mChipsetTypes.end(), s);
    556         AssertMsg (it != mChipsetTypes.end(), ("No value for {%s}",
    557                                                s.toLatin1().constData()));
    558         return KChipsetType (it.key());
    559     }
    560 
    561     QStringList COMPortNames() const;
    562     QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
    563     bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
    564 
    565     QStringList LPTPortNames() const;
    566     QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
    567     bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
    568 
    569     QPixmap snapshotIcon (bool online) const
    570     {
    571         return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
    572     }
    573 
    574     static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
    575     {
    576         for (int i = 0; i < extList.size(); ++i)
    577             if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
    578                 return true;
    579         return false;
    580     }
    581 
    582     QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
    583     QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
    584 
    585     QPixmap warningIcon() const { return mWarningIcon; }
    586     QPixmap errorIcon() const { return mErrorIcon; }
    587 
    588     /* details generators */
    589 
    590     QString details (const CMedium &aHD, bool aPredictDiff);
    591 
    592     QString details (const CUSBDevice &aDevice) const;
    593     QString toolTip (const CUSBDevice &aDevice) const;
    594     QString toolTip (const CUSBDeviceFilter &aFilter) const;
    595 
    596     QString detailsReport (const CMachine &aMachine, bool aWithLinks);
    597 
    598     QString platformInfo();
    599 
    600     /* VirtualBox helpers */
    601 
    602 #if defined(Q_WS_X11) && !defined(VBOX_OSE)
    603     double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
    604     bool showVirtualBoxLicense();
    605 #endif
    606 
    607     CSession openSession(const QString &aId, bool aExisting = false);
    608 
    609     /** Shortcut to openSession (aId, true). */
    610     CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
    611 
    612     void startEnumeratingMedia();
    613 
    614     void reloadProxySettings();
    615 
    616     /**
    617      * Returns a list of all currently registered media. This list is used to
    618      * globally track the accessibility state of all media on a dedicated thread.
    619      *
    620      * Note that the media list is initially empty (i.e. before the enumeration
    621      * process is started for the first time using #startEnumeratingMedia()).
    622      * See #startEnumeratingMedia() for more information about how meida are
    623      * sorted in the returned list.
    624      */
    625     const VBoxMediaList &currentMediaList() const { return mMediaList; }
    626 
    627     /** Returns true if the media enumeration is in progress. */
    628     bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
    629 
    630     VBoxDefs::MediumType mediumTypeToLocal(KDeviceType globalType);
    631     KDeviceType mediumTypeToGlobal(VBoxDefs::MediumType localType);
    632 
    633     void addMedium (const VBoxMedium &);
    634     void updateMedium (const VBoxMedium &);
    635     void removeMedium (VBoxDefs::MediumType, const QString &);
    636 
    637     bool findMedium (const CMedium &, VBoxMedium &) const;
    638     VBoxMedium findMedium (const QString &aMediumId) const;
    639 
    640     /** Compact version of #findMediumTo(). Asserts if not found. */
    641     VBoxMedium getMedium (const CMedium &aObj) const
    642     {
    643         VBoxMedium medium;
    644         if (!findMedium (aObj, medium))
    645             AssertFailed();
    646         return medium;
    647     }
    648 
    649     QString openMediumWithFileOpenDialog(VBoxDefs::MediumType mediumType, QWidget *pParent = 0,
    650                                          const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
    651     QString openMedium(VBoxDefs::MediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
    652 
    653     /* Returns the number of current running Fe/Qt4 main windows. */
    654     int mainWindowCount();
    655 
    656     /* various helpers */
    657 
    658     QString languageName() const;
    659     QString languageCountry() const;
    660     QString languageNameEnglish() const;
    661     QString languageCountryEnglish() const;
    662     QString languageTranslators() const;
    663 
    664     void retranslateUi();
    665 
    666     /** @internal made public for internal purposes */
    667     void cleanup();
    668 
    669     /* public static stuff */
    670 
    671     static bool isDOSType (const QString &aOSTypeId);
    672 
    673     static QString languageId();
    674     static void loadLanguage (const QString &aLangId = QString::null);
    675     QString helpFile() const;
    676 
    677     static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
    678 
    679     static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
    680                                     bool aCanResize = true);
    681     static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
    682                                 bool aCanResize = true);
    683     static QRegion flip (const QRegion &aRegion);
    684 
    685     static void centerWidget (QWidget *aWidget, QWidget *aRelative,
    686                               bool aCanResize = true);
    687 
    688     static QChar decimalSep();
    689     static QString sizeRegexp();
    690 
    691     static QString toHumanReadableList(const QStringList &list);
    692 
    693     static quint64 parseSize (const QString &);
    694     static QString formatSize (quint64 aSize, uint aDecimal = 2,
    695                                VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
    696 
    697     static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
    698 
    699     static QString locationForHTML (const QString &aFileName);
    700 
    701     static QString highlight (const QString &aStr, bool aToolTip = false);
    702 
    703     static QString replaceHtmlEntities(QString strText);
    704     static QString emphasize (const QString &aStr);
    705 
    706     static QString systemLanguageId();
    707 
    708     static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
    709 
    710     static QString removeAccelMark (const QString &aText);
    711 
    712     static QString insertKeyToActionText (const QString &aText, const QString &aKey);
    713     static QString extractKeyFromActionText (const QString &aText);
    714 
    715     static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
    716 
    717     static QWidget *findWidget (QWidget *aParent, const char *aName,
    718                                 const char *aClassName = NULL,
    719                                 bool aRecursive = false);
    720 
    721     static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
    722     static QList <QPair <QString, QString> > HDDBackends();
    723     static QList <QPair <QString, QString> > DVDBackends();
    724     static QList <QPair <QString, QString> > FloppyBackends();
    725 
    726     /* Qt 4.2.0 support function */
    727     static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
    728     {
    729 #if QT_VERSION < 0x040300
    730         /* Deprecated since > 4.2 */
    731         aLayout->setMargin (aMargin);
    732 #else
    733         /* New since > 4.2 */
    734         aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
    735 #endif
    736     }
    737 
    738     static QString documentsPath();
    739 
    740 #ifdef VBOX_WITH_VIDEOHWACCEL
    741     static bool isAcceleration2DVideoAvailable();
    742 
    743     /** additional video memory required for the best 2D support performance
    744      *  total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory  */
    745     static quint64 required2DOffscreenVideoMemory();
    746 #endif
    747 
    748 #ifdef VBOX_WITH_CRHGSMI
    749     static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
    750     static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
    751 #endif /* VBOX_WITH_CRHGSMI */
    752 
    753 #ifdef Q_WS_MAC
    754     bool isSheetWindowsAllowed(QWidget *pParent) const;
    755 #endif /* Q_WS_MAC */
    756 
    757     /* Returns full medium-format name for the given base medium-format name: */
    758     static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
    759 
    760 signals:
    761 
    762     /**
    763      * Emitted at the beginning of the enumeration process started by
    764      * #startEnumeratingMedia().
    765      */
    766     void mediumEnumStarted();
    767 
    768     /**
    769      * Emitted when a new medium item from the list has updated its
    770      * accessibility state.
    771      */
    772     void mediumEnumerated (const VBoxMedium &aMedum);
    773 
    774     /**
    775      * Emitted at the end of the enumeration process started by
    776      * #startEnumeratingMedia(). The @a aList argument is passed for
    777      * convenience, it is exactly the same as returned by #currentMediaList().
    778      */
    779     void mediumEnumFinished (const VBoxMediaList &aList);
    780 
    781     /** Emitted when a new media is added using #addMedia(). */
    782     void mediumAdded (const VBoxMedium &);
    783 
    784     /** Emitted when the media is updated using #updateMedia(). */
    785     void mediumUpdated (const VBoxMedium &);
    786 
    787     /** Emitted when the media is removed using #removeMedia(). */
    788     void mediumRemoved (VBoxDefs::MediumType, const QString &);
    789 
    790 #ifdef VBOX_GUI_WITH_SYSTRAY
    791     void sigTrayIconShow(bool fEnabled);
    792 #endif
    793 
    794 public slots:
    795 
    796     bool openURL (const QString &aURL);
    797 
    798     void showRegistrationDialog (bool aForce = true);
    799     void sltGUILanguageChange(QString strLang);
    800     void sltProcessGlobalSettingChange();
    801 
    802 protected:
    803 
    804     bool event (QEvent *e);
    805     bool eventFilter (QObject *, QEvent *);
    806 
    807 private:
    808 
    809     VBoxGlobal();
    810     ~VBoxGlobal();
    811 
    812     void init();
    813 #ifdef VBOX_WITH_DEBUGGER_GUI
    814     void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
    815     void setDebuggerVar(int *piDbgCfgVar, bool fState);
    816     bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
    817 #endif
    818 
    819     bool mValid;
    820 
    821     CVirtualBox mVBox;
    822     CHost mHost;
    823 
    824     VBoxGlobalSettings gset;
    825 
    826     UISelectorWindow *mSelectorWnd;
    827     UIMachine *m_pVirtualMachine;
    828     QWidget* mMainWindow;
    829 
    830 #ifdef VBOX_WITH_REGISTRATION
    831     UIRegistrationWzd *mRegDlg;
    832 #endif
    833 
    834     QString vmUuid;
    835     QList<QUrl> m_ArgUrlList;
    836 
    837 #ifdef VBOX_GUI_WITH_SYSTRAY
    838     bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
    839     bool mIncreasedWindowCounter : 1;
    840 #endif
    841 
    842     /** Whether to show error message boxes for VM start errors. */
    843     bool mShowStartVMErrors;
    844 
    845     QThread *mMediaEnumThread;
    846     VBoxMediaList mMediaList;
    847 
    848     VBoxDefs::RenderMode vm_render_mode;
    849     const char * vm_render_mode_str;
    850     bool mIsKWinManaged;
    851 
    852     /** The --disable-patm option. */
    853     bool mDisablePatm;
    854     /** The --disable-csam option. */
    855     bool mDisableCsam;
    856     /** The --recompile-supervisor option. */
    857     bool mRecompileSupervisor;
    858     /** The --recompile-user option. */
    859     bool mRecompileUser;
    860 
    861 #ifdef VBOX_WITH_DEBUGGER_GUI
    862     /** Whether the debugger should be accessible or not.
    863      * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
    864      * VBOX_GUI_DBG_AUTO_SHOW to enable. */
    865     int mDbgEnabled;
    866     /** Whether to show the debugger automatically with the console.
    867      * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
    868     int mDbgAutoShow;
    869     /** Whether to show the command line window when mDbgAutoShow is set. */
    870     int mDbgAutoShowCommandLine;
    871     /** Whether to show the statistics window when mDbgAutoShow is set. */
    872     int mDbgAutoShowStatistics;
    873     /** VBoxDbg module handle. */
    874     RTLDRMOD mhVBoxDbg;
    875 
    876     /** Whether to start the VM in paused state or not. */
    877     bool mStartPaused;
    878 #endif
    879 
    880 #if defined (Q_WS_WIN32)
    881     DWORD dwHTMLHelpCookie;
    882 #endif
    883 
    884     QString mVerString;
    885     QString mBrandingConfig;
    886 
    887     int m3DAvailable;
    888 
    889     QList <QString> mFamilyIDs;
    890     QList <QList <CGuestOSType> > mTypes;
    891     QHash <QString, QPixmap *> mOsTypeIcons;
    892 
    893     QHash <ulong, QPixmap *> mVMStateIcons;
    894     QHash <ulong, QColor *> mVMStateColors;
    895 
    896     QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
    897 
    898     QULongStringHash mMachineStates;
    899     QULongStringHash mSessionStates;
    900     QULongStringHash mDeviceTypes;
    901 
    902     QULongStringHash mStorageBuses;
    903     QLongStringHash mStorageBusChannels;
    904     QLongStringHash mStorageBusDevices;
    905     QULongStringHash mSlotTemplates;
    906 
    907     QULongStringHash mDiskTypes;
    908     QString mDiskTypes_Differencing;
    909 
    910     QULongStringHash mAuthTypes;
    911     QULongStringHash mPortModeTypes;
    912     QULongStringHash mUSBFilterActionTypes;
    913     QULongStringHash mAudioDriverTypes;
    914     QULongStringHash mAudioControllerTypes;
    915     QULongStringHash mNetworkAdapterTypes;
    916     QULongStringHash mNetworkAttachmentTypes;
    917     QULongStringHash mNetworkAdapterPromiscModePolicyTypes;
    918     QULongStringHash mNATProtocolTypes;
    919     QULongStringHash mClipboardTypes;
    920     QULongStringHash mStorageControllerTypes;
    921     QULongStringHash mUSBDeviceStates;
    922     QULongStringHash mChipsetTypes;
    923 
    924     QString mUserDefinedPortName;
    925 
    926     QPixmap mWarningIcon, mErrorIcon;
    927 
    928     QFileIconProvider m_globalIconProvider;
    929 
    930 #ifdef VBOX_GUI_WITH_PIDFILE
    931     QString m_strPidfile;
    932 #endif
    933 
    934     friend VBoxGlobal &vboxGlobal();
    935 };
    936 
    937 inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
    938 
    939 // Helper classes
    940 ////////////////////////////////////////////////////////////////////////////////
    941 
    942 /**
    943  *  USB Popup Menu class.
    944  *  This class provides the list of USB devices attached to the host.
    945  */
    946 class VBoxUSBMenu : public QMenu
    947 {
    948     Q_OBJECT
    949 
    950 public:
    951 
    952     VBoxUSBMenu (QWidget *);
    953 
    954     const CUSBDevice& getUSB (QAction *aAction);
    955 
    956     void setConsole (const CConsole &);
    957 
    958 private slots:
    959 
    960     void processAboutToShow();
    961 
    962 private:
    963     bool event(QEvent *aEvent);
    964 
    965     QMap <QAction *, CUSBDevice> mUSBDevicesMap;
    966     CConsole mConsole;
    967 };
    968 
    969 /**
    970  *  Enable/Disable Menu class.
    971  *  This class provides enable/disable menu items.
    972  */
    973 class VBoxSwitchMenu : public QMenu
    974 {
    975     Q_OBJECT
    976 
    977 public:
    978 
    979     VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
    980 
    981     void setToolTip (const QString &);
    982 
    983 private slots:
    984 
    985     void processAboutToShow();
    986 
    987 private:
    988 
    989     QAction *mAction;
    990     bool     mInverted;
    991 };
    992 
    993 #endif /* __VBoxGlobal_h__ */
    994 
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIProcess.h

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h74233
    r41589 r41590  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VBoxGlobal class declaration
     4 * QIProcess class declaration
    55 */
    66
    77/*
    8  * Copyright (C) 2006-2011 Oracle Corporation
     8 * Copyright (C) 2006-2012 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717 */
    1818
    19 #ifndef __VBoxGlobal_h__
    20 #define __VBoxGlobal_h__
     19#ifndef __QIProcess_h__
     20#define __QIProcess_h__
    2121
    2222/* Qt includes: */
    23 #include <QApplication>
    24 #include <QLayout>
    25 #include <QMenu>
    26 #include <QStyle>
    2723#include <QProcess>
    28 #include <QHash>
    29 #include <QFileIconProvider>
    3024
    31 /* GUI includes: */
    32 #include "VBoxGlobalSettings.h"
    33 #include "VBoxMedium.h"
    34 
    35 /* COM includes: */
    36 #include "VBox/com/Guid.h"
    37 #include "COMEnums.h"
    38 #include "CHost.h"
    39 #include "CVirtualBox.h"
    40 #include "CSession.h"
    41 #include "CConsole.h"
    42 #include "CMachine.h"
    43 #include "CMedium.h"
    44 #include "CGuestOSType.h"
    45 #include "CUSBDevice.h"
    46 
    47 /* Other VBox includes: */
    48 #ifdef Q_WS_X11
    49 # include <sys/wait.h>
    50 #endif /* Q_WS_X11 */
    51 
    52 /* Forward declarations: */
    53 class QAction;
    54 class QLabel;
    55 class QToolButton;
    56 class UIMachine;
    57 
    58 class Process : public QProcess
     25/* QProcess reimplementation for VBox GUI needs: */
     26class QIProcess : public QProcess
    5927{
    6028    Q_OBJECT;
     
    6230public:
    6331
    64     static QByteArray singleShot (const QString &aProcessName,
    65                                   int aTimeout = 5000
    66                                   /* wait for data maximum 5 seconds */)
    67     {
    68         /* Why is it really needed is because of Qt4.3 bug with QProcess.
    69          * This bug is about QProcess sometimes (~70%) do not receive
    70          * notification about process was finished, so this makes
    71          * 'bool QProcess::waitForFinished (int)' block the GUI thread and
    72          * never dismissed with 'true' result even if process was really
    73          * started&finished. So we just waiting for some information
    74          * on process output and destroy the process with force. Due to
    75          * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
    76          * we have to change process state to QProcess::NotRunning. */
    77 
    78         QByteArray result;
    79         Process process;
    80         process.start (aProcessName);
    81         bool firstShotReady = process.waitForReadyRead (aTimeout);
    82         if (firstShotReady)
    83             result = process.readAllStandardOutput();
    84         process.setProcessState (QProcess::NotRunning);
    85 #ifdef Q_WS_X11
    86         int status;
    87         if (process.pid() > 0)
    88             waitpid(process.pid(), &status, 0);
    89 #endif
    90         return result;
    91     }
     32    /* Static single-shot method to execute some script: */
     33    static QByteArray singleShot(const QString &strProcessName,
     34                                 int iTimeout = 5000 /* wait for data maximum 5 seconds */);
    9235
    9336protected:
    9437
    95     Process (QWidget *aParent = 0) : QProcess (aParent) {}
     38    /* Constructor: */
     39    QIProcess(QObject *pParent = 0);
    9640};
    9741
    98 struct StorageSlot
    99 {
    100     StorageSlot() : bus (KStorageBus_Null), port (0), device (0) {}
    101     StorageSlot (const StorageSlot &aOther) : bus (aOther.bus), port (aOther.port), device (aOther.device) {}
    102     StorageSlot (KStorageBus aBus, LONG aPort, LONG aDevice) : bus (aBus), port (aPort), device (aDevice) {}
    103     StorageSlot& operator= (const StorageSlot &aOther) { bus = aOther.bus; port = aOther.port; device = aOther.device; return *this; }
    104     bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; }
    105     bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; }
    106     bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) ||
    107                                                               (bus == aOther.bus && port < aOther.port) ||
    108                                                               (bus == aOther.bus && port == aOther.port && device < aOther.device); }
    109     bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) ||
    110                                                               (bus == aOther.bus && port > aOther.port) ||
    111                                                               (bus == aOther.bus && port == aOther.port && device > aOther.device); }
    112     bool isNull() { return bus == KStorageBus_Null; }
    113     KStorageBus bus; LONG port; LONG device;
    114 };
    115 Q_DECLARE_METATYPE (StorageSlot);
     42#endif /* __QIProcess_h__ */
    11643
    117 // VBoxGlobal class
    118 ////////////////////////////////////////////////////////////////////////////////
    119 
    120 class UISelectorWindow;
    121 class UIRegistrationWzd;
    122 class VBoxUpdateDlg;
    123 
    124 class VBoxGlobal : public QObject
    125 {
    126     Q_OBJECT
    127 
    128 public:
    129 
    130     typedef QHash <ulong, QString> QULongStringHash;
    131     typedef QHash <long, QString> QLongStringHash;
    132 
    133     static VBoxGlobal &instance();
    134 
    135     bool isValid() { return mValid; }
    136 
    137     static QString qtRTVersionString();
    138     static uint qtRTVersion();
    139     static QString qtCTVersionString();
    140     static uint qtCTVersion();
    141 
    142     QString vboxVersionString() const;
    143     QString vboxVersionStringNormalized() const;
    144 
    145     QString versionString() const { return mVerString; }
    146     bool isBeta() const;
    147 
    148     CVirtualBox virtualBox() const { return mVBox; }
    149     CHost host() const { return mHost; }
    150 
    151     VBoxGlobalSettings &settings() { return gset; }
    152     bool setSettings (VBoxGlobalSettings &gs);
    153 
    154     UISelectorWindow &selectorWnd();
    155 
    156     /* VM stuff: */
    157     bool startMachine(const QString &strMachineId);
    158     UIMachine* virtualMachine();
    159     QWidget* vmWindow();
    160 
    161     /* Main application window storage: */
    162     void setMainWindow(QWidget *pMainWindow) { mMainWindow = pMainWindow; }
    163     QWidget* mainWindow() const { return mMainWindow; }
    164 
    165     bool is3DAvailable() const { return m3DAvailable; }
    166 
    167 #ifdef VBOX_GUI_WITH_PIDFILE
    168     void createPidfile();
    169     void deletePidfile();
    170 #endif
    171 
    172     /* branding */
    173     bool brandingIsActive (bool aForce = false);
    174     QString brandingGetKey (QString aKey);
    175 
    176     bool processArgs();
    177 
    178     bool switchToMachine(CMachine &machine);
    179     bool launchMachine(CMachine &machine, bool fHeadless = false);
    180 
    181     bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
    182     bool showStartVMErrors() const { return mShowStartVMErrors; }
    183 #ifdef VBOX_GUI_WITH_SYSTRAY
    184     bool isTrayMenu() const;
    185     void setTrayMenu(bool aIsTrayMenu);
    186     void trayIconShowSelector();
    187     bool trayIconInstall();
    188 #endif
    189     QString managedVMUuid() const { return vmUuid; }
    190     QList<QUrl> &argUrlList() { return m_ArgUrlList; }
    191 
    192     VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; }
    193     const char *vmRenderModeStr() const { return vm_render_mode_str; }
    194     bool isKWinManaged() const { return mIsKWinManaged; }
    195 
    196     const QRect availableGeometry(int iScreen = 0) const;
    197 
    198     bool isPatmDisabled() const { return mDisablePatm; }
    199     bool isCsamDisabled() const { return mDisableCsam; }
    200     bool isSupervisorCodeExecedRecompiled() const { return mRecompileSupervisor; }
    201     bool isUserCodeExecedRecompiled()       const { return mRecompileUser; }
    202 
    203 #ifdef VBOX_WITH_DEBUGGER_GUI
    204     bool isDebuggerEnabled(CMachine &aMachine);
    205     bool isDebuggerAutoShowEnabled(CMachine &aMachine);
    206     bool isDebuggerAutoShowCommandLineEnabled(CMachine &aMachine);
    207     bool isDebuggerAutoShowStatisticsEnabled(CMachine &aMachine);
    208     RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
    209 
    210     bool isStartPausedEnabled() const { return mStartPaused; }
    211 #else
    212     bool isDebuggerAutoShowEnabled(CMachine & /*aMachine*/) const { return false; }
    213     bool isDebuggerAutoShowCommandLineEnabled(CMachine & /*aMachine*/) const { return false; }
    214     bool isDebuggerAutoShowStatisticsEnabled(CMachine & /*aMachine*/) const { return false; }
    215 
    216     bool isStartPausedEnabled() const { return false; }
    217 #endif
    218 
    219     /* VBox enum to/from string/icon/color convertors */
    220 
    221     QList <CGuestOSType> vmGuestOSFamilyList() const;
    222     QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
    223     QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const;
    224     CGuestOSType vmGuestOSType (const QString &aTypeId,
    225                                 const QString &aFamilyId = QString::null) const;
    226     QString vmGuestOSTypeDescription (const QString &aTypeId) const;
    227 
    228     QPixmap toIcon (KMachineState s) const
    229     {
    230         QPixmap *pm = mVMStateIcons.value (s);
    231         AssertMsg (pm, ("Icon for VM state %d must be defined", s));
    232         return pm ? *pm : QPixmap();
    233     }
    234 
    235     static inline QString yearsToString (uint32_t cVal)
    236     {
    237         return tr("%n year(s)", "", cVal);
    238     }
    239 
    240     static inline QString monthsToString (uint32_t cVal)
    241     {
    242         return tr("%n month(s)", "", cVal);
    243     }
    244 
    245     static inline QString daysToString (uint32_t cVal)
    246     {
    247         return tr("%n day(s)", "", cVal);
    248     }
    249 
    250     static inline QString hoursToString (uint32_t cVal)
    251     {
    252         return tr("%n hour(s)", "", cVal);
    253     }
    254 
    255     static inline QString minutesToString (uint32_t cVal)
    256     {
    257         return tr("%n minute(s)", "", cVal);
    258     }
    259 
    260     static inline QString secondsToString (uint32_t cVal)
    261     {
    262         return tr("%n second(s)", "", cVal);
    263     }
    264 
    265     const QColor &toColor (KMachineState s) const
    266     {
    267         static const QColor none;
    268         AssertMsg (mVMStateColors.value (s), ("No color for %d", s));
    269         return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none;
    270     }
    271 
    272     QString toString (KMachineState s) const
    273     {
    274         AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s));
    275         return mMachineStates.value (s);
    276     }
    277 
    278     QString toString (KSessionState s) const
    279     {
    280         AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s));
    281         return mSessionStates.value (s);
    282     }
    283 
    284     /**
    285      * Returns a string representation of the given KStorageBus enum value.
    286      * Complementary to #toStorageBusType (const QString &) const.
    287      */
    288     QString toString (KStorageBus aBus) const
    289     {
    290         AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus));
    291         return mStorageBuses [aBus];
    292     }
    293 
    294     /**
    295      * Returns a KStorageBus enum value corresponding to the given string
    296      * representation. Complementary to #toString (KStorageBus) const.
    297      */
    298     KStorageBus toStorageBusType (const QString &aBus) const
    299     {
    300         QULongStringHash::const_iterator it =
    301             qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus);
    302         AssertMsg (it != mStorageBuses.end(), ("No value for {%s}",
    303                                                aBus.toLatin1().constData()));
    304         return KStorageBus (it.key());
    305     }
    306 
    307     KStorageBus toStorageBusType (KStorageControllerType aControllerType) const
    308     {
    309         KStorageBus sb = KStorageBus_Null;
    310         switch (aControllerType)
    311         {
    312             case KStorageControllerType_Null: sb = KStorageBus_Null; break;
    313             case KStorageControllerType_PIIX3:
    314             case KStorageControllerType_PIIX4:
    315             case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break;
    316             case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break;
    317             case KStorageControllerType_LsiLogic:
    318             case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break;
    319             case KStorageControllerType_I82078: sb = KStorageBus_Floppy; break;
    320             default:
    321               AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break;
    322         }
    323         return sb;
    324     }
    325 
    326     QString toString (KStorageBus aBus, LONG aChannel) const;
    327     LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const;
    328 
    329     QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const;
    330     LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const;
    331 
    332     QString toString (StorageSlot aSlot) const;
    333     StorageSlot toStorageSlot (const QString &aSlot) const;
    334 
    335     QString toString (KMediumType t) const
    336     {
    337         AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t));
    338         return mDiskTypes.value (t);
    339     }
    340     QString differencingMediumTypeName() const { return mDiskTypes_Differencing; }
    341 
    342     QString toString(KMediumVariant mediumVariant) const;
    343 
    344     /**
    345      * Similar to toString (KMediumType), but returns 'Differencing' for
    346      * normal hard disks that have a parent.
    347      */
    348     QString mediumTypeString (const CMedium &aHD) const
    349     {
    350         if (!aHD.GetParent().isNull())
    351         {
    352             Assert (aHD.GetType() == KMediumType_Normal);
    353             return mDiskTypes_Differencing;
    354         }
    355         return toString (aHD.GetType());
    356     }
    357 
    358     QString toString (KAuthType t) const
    359     {
    360         AssertMsg (!mAuthTypes.value (t).isNull(), ("No text for %d", t));
    361         return mAuthTypes.value (t);
    362     }
    363 
    364     QString toString (KPortMode t) const
    365     {
    366         AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t));
    367         return mPortModeTypes.value (t);
    368     }
    369 
    370     QString toString (KUSBDeviceFilterAction t) const
    371     {
    372         AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t));
    373         return mUSBFilterActionTypes.value (t);
    374     }
    375 
    376     QString toString (KClipboardMode t) const
    377     {
    378         AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t));
    379         return mClipboardTypes.value (t);
    380     }
    381 
    382     KClipboardMode toClipboardModeType (const QString &s) const
    383     {
    384         QULongStringHash::const_iterator it =
    385             qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s);
    386         AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}",
    387                                                  s.toLatin1().constData()));
    388         return KClipboardMode (it.key());
    389     }
    390 
    391     QString toString (KStorageControllerType t) const
    392     {
    393         AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t));
    394         return mStorageControllerTypes.value (t);
    395     }
    396 
    397     KStorageControllerType toControllerType (const QString &s) const
    398     {
    399         QULongStringHash::const_iterator it =
    400             qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s);
    401         AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}",
    402                                                          s.toLatin1().constData()));
    403         return KStorageControllerType (it.key());
    404     }
    405 
    406     KAuthType toAuthType (const QString &s) const
    407     {
    408         QULongStringHash::const_iterator it =
    409             qFind (mAuthTypes.begin(), mAuthTypes.end(), s);
    410         AssertMsg (it != mAuthTypes.end(), ("No value for {%s}",
    411                                                 s.toLatin1().constData()));
    412         return KAuthType (it.key());
    413     }
    414 
    415     KPortMode toPortMode (const QString &s) const
    416     {
    417         QULongStringHash::const_iterator it =
    418             qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s);
    419         AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}",
    420                                                 s.toLatin1().constData()));
    421         return KPortMode (it.key());
    422     }
    423 
    424     KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const
    425     {
    426         QULongStringHash::const_iterator it =
    427             qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s);
    428         AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}",
    429                                                        s.toLatin1().constData()));
    430         return KUSBDeviceFilterAction (it.key());
    431     }
    432 
    433     QString toString (KDeviceType t) const
    434     {
    435         AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t));
    436         return mDeviceTypes.value (t);
    437     }
    438 
    439     KDeviceType toDeviceType (const QString &s) const
    440     {
    441         QULongStringHash::const_iterator it =
    442             qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s);
    443         AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}",
    444                                               s.toLatin1().constData()));
    445         return KDeviceType (it.key());
    446     }
    447 
    448     QStringList deviceTypeStrings() const;
    449 
    450     QString toString (KAudioDriverType t) const
    451     {
    452         AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t));
    453         return mAudioDriverTypes.value (t);
    454     }
    455 
    456     KAudioDriverType toAudioDriverType (const QString &s) const
    457     {
    458         QULongStringHash::const_iterator it =
    459             qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s);
    460         AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}",
    461                                                    s.toLatin1().constData()));
    462         return KAudioDriverType (it.key());
    463     }
    464 
    465     QString toString (KAudioControllerType t) const
    466     {
    467         AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t));
    468         return mAudioControllerTypes.value (t);
    469     }
    470 
    471     KAudioControllerType toAudioControllerType (const QString &s) const
    472     {
    473         QULongStringHash::const_iterator it =
    474             qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s);
    475         AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}",
    476                                                        s.toLatin1().constData()));
    477         return KAudioControllerType (it.key());
    478     }
    479 
    480     QString toString (KNetworkAdapterType t) const
    481     {
    482         AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t));
    483         return mNetworkAdapterTypes.value (t);
    484     }
    485 
    486     KNetworkAdapterType toNetworkAdapterType (const QString &s) const
    487     {
    488         QULongStringHash::const_iterator it =
    489             qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s);
    490         AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}",
    491                                                       s.toLatin1().constData()));
    492         return KNetworkAdapterType (it.key());
    493     }
    494 
    495     QString toString (KNetworkAttachmentType t) const
    496     {
    497         AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t));
    498         return mNetworkAttachmentTypes.value (t);
    499     }
    500 
    501     KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const
    502     {
    503         QULongStringHash::const_iterator it =
    504             qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s);
    505         AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}",
    506                                                          s.toLatin1().constData()));
    507         return KNetworkAttachmentType (it.key());
    508     }
    509 
    510     QString toString (KNetworkAdapterPromiscModePolicy t) const
    511     {
    512         AssertMsg (!mNetworkAdapterPromiscModePolicyTypes.value (t).isNull(), ("No text for %d", t));
    513         return mNetworkAdapterPromiscModePolicyTypes.value (t);
    514     }
    515 
    516     KNetworkAdapterPromiscModePolicy toNetworkAdapterPromiscModePolicyType (const QString &s) const
    517     {
    518         QULongStringHash::const_iterator it =
    519             qFind (mNetworkAdapterPromiscModePolicyTypes.begin(), mNetworkAdapterPromiscModePolicyTypes.end(), s);
    520         AssertMsg (it != mNetworkAdapterPromiscModePolicyTypes.end(), ("No value for {%s}",
    521                                                                        s.toLatin1().constData()));
    522         return KNetworkAdapterPromiscModePolicy (it.key());
    523     }
    524 
    525     QString toString (KNATProtocol t) const
    526     {
    527         AssertMsg (!mNATProtocolTypes.value (t).isNull(), ("No text for %d", t));
    528         return mNATProtocolTypes.value (t);
    529     }
    530 
    531     KNATProtocol toNATProtocolType (const QString &s) const
    532     {
    533         QULongStringHash::const_iterator it =
    534             qFind (mNATProtocolTypes.begin(), mNATProtocolTypes.end(), s);
    535         AssertMsg (it != mNATProtocolTypes.end(), ("No value for {%s}",
    536                                                    s.toLatin1().constData()));
    537         return KNATProtocol (it.key());
    538     }
    539 
    540     QString toString (KUSBDeviceState aState) const
    541     {
    542         AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState));
    543         return mUSBDeviceStates.value (aState);
    544     }
    545 
    546     QString toString (KChipsetType t) const
    547     {
    548         AssertMsg (!mChipsetTypes.value (t).isNull(), ("No text for %d", t));
    549         return mChipsetTypes.value (t);
    550     }
    551 
    552     KChipsetType toChipsetType (const QString &s) const
    553     {
    554         QULongStringHash::const_iterator it =
    555             qFind (mChipsetTypes.begin(), mChipsetTypes.end(), s);
    556         AssertMsg (it != mChipsetTypes.end(), ("No value for {%s}",
    557                                                s.toLatin1().constData()));
    558         return KChipsetType (it.key());
    559     }
    560 
    561     QStringList COMPortNames() const;
    562     QString toCOMPortName (ulong aIRQ, ulong aIOBase) const;
    563     bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
    564 
    565     QStringList LPTPortNames() const;
    566     QString toLPTPortName (ulong aIRQ, ulong aIOBase) const;
    567     bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const;
    568 
    569     QPixmap snapshotIcon (bool online) const
    570     {
    571         return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon;
    572     }
    573 
    574     static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
    575     {
    576         for (int i = 0; i < extList.size(); ++i)
    577             if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
    578                 return true;
    579         return false;
    580     }
    581 
    582     QIcon icon(QFileIconProvider::IconType type) { return m_globalIconProvider.icon(type); }
    583     QIcon icon(const QFileInfo &info) { return m_globalIconProvider.icon(info); }
    584 
    585     QPixmap warningIcon() const { return mWarningIcon; }
    586     QPixmap errorIcon() const { return mErrorIcon; }
    587 
    588     /* details generators */
    589 
    590     QString details (const CMedium &aHD, bool aPredictDiff);
    591 
    592     QString details (const CUSBDevice &aDevice) const;
    593     QString toolTip (const CUSBDevice &aDevice) const;
    594     QString toolTip (const CUSBDeviceFilter &aFilter) const;
    595 
    596     QString detailsReport (const CMachine &aMachine, bool aWithLinks);
    597 
    598     QString platformInfo();
    599 
    600     /* VirtualBox helpers */
    601 
    602 #if defined(Q_WS_X11) && !defined(VBOX_OSE)
    603     double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
    604     bool showVirtualBoxLicense();
    605 #endif
    606 
    607     CSession openSession(const QString &aId, bool aExisting = false);
    608 
    609     /** Shortcut to openSession (aId, true). */
    610     CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
    611 
    612     void startEnumeratingMedia();
    613 
    614     void reloadProxySettings();
    615 
    616     /**
    617      * Returns a list of all currently registered media. This list is used to
    618      * globally track the accessibility state of all media on a dedicated thread.
    619      *
    620      * Note that the media list is initially empty (i.e. before the enumeration
    621      * process is started for the first time using #startEnumeratingMedia()).
    622      * See #startEnumeratingMedia() for more information about how meida are
    623      * sorted in the returned list.
    624      */
    625     const VBoxMediaList &currentMediaList() const { return mMediaList; }
    626 
    627     /** Returns true if the media enumeration is in progress. */
    628     bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
    629 
    630     VBoxDefs::MediumType mediumTypeToLocal(KDeviceType globalType);
    631     KDeviceType mediumTypeToGlobal(VBoxDefs::MediumType localType);
    632 
    633     void addMedium (const VBoxMedium &);
    634     void updateMedium (const VBoxMedium &);
    635     void removeMedium (VBoxDefs::MediumType, const QString &);
    636 
    637     bool findMedium (const CMedium &, VBoxMedium &) const;
    638     VBoxMedium findMedium (const QString &aMediumId) const;
    639 
    640     /** Compact version of #findMediumTo(). Asserts if not found. */
    641     VBoxMedium getMedium (const CMedium &aObj) const
    642     {
    643         VBoxMedium medium;
    644         if (!findMedium (aObj, medium))
    645             AssertFailed();
    646         return medium;
    647     }
    648 
    649     QString openMediumWithFileOpenDialog(VBoxDefs::MediumType mediumType, QWidget *pParent = 0,
    650                                          const QString &strDefaultFolder = QString(), bool fUseLastFolder = true);
    651     QString openMedium(VBoxDefs::MediumType mediumType, QString strMediumLocation, QWidget *pParent = 0);
    652 
    653     /* Returns the number of current running Fe/Qt4 main windows. */
    654     int mainWindowCount();
    655 
    656     /* various helpers */
    657 
    658     QString languageName() const;
    659     QString languageCountry() const;
    660     QString languageNameEnglish() const;
    661     QString languageCountryEnglish() const;
    662     QString languageTranslators() const;
    663 
    664     void retranslateUi();
    665 
    666     /** @internal made public for internal purposes */
    667     void cleanup();
    668 
    669     /* public static stuff */
    670 
    671     static bool isDOSType (const QString &aOSTypeId);
    672 
    673     static QString languageId();
    674     static void loadLanguage (const QString &aLangId = QString::null);
    675     QString helpFile() const;
    676 
    677     static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
    678 
    679     static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
    680                                     bool aCanResize = true);
    681     static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
    682                                 bool aCanResize = true);
    683     static QRegion flip (const QRegion &aRegion);
    684 
    685     static void centerWidget (QWidget *aWidget, QWidget *aRelative,
    686                               bool aCanResize = true);
    687 
    688     static QChar decimalSep();
    689     static QString sizeRegexp();
    690 
    691     static QString toHumanReadableList(const QStringList &list);
    692 
    693     static quint64 parseSize (const QString &);
    694     static QString formatSize (quint64 aSize, uint aDecimal = 2,
    695                                VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
    696 
    697     static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
    698 
    699     static QString locationForHTML (const QString &aFileName);
    700 
    701     static QString highlight (const QString &aStr, bool aToolTip = false);
    702 
    703     static QString replaceHtmlEntities(QString strText);
    704     static QString emphasize (const QString &aStr);
    705 
    706     static QString systemLanguageId();
    707 
    708     static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
    709 
    710     static QString removeAccelMark (const QString &aText);
    711 
    712     static QString insertKeyToActionText (const QString &aText, const QString &aKey);
    713     static QString extractKeyFromActionText (const QString &aText);
    714 
    715     static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
    716 
    717     static QWidget *findWidget (QWidget *aParent, const char *aName,
    718                                 const char *aClassName = NULL,
    719                                 bool aRecursive = false);
    720 
    721     static QList <QPair <QString, QString> > MediumBackends(KDeviceType enmDeviceType);
    722     static QList <QPair <QString, QString> > HDDBackends();
    723     static QList <QPair <QString, QString> > DVDBackends();
    724     static QList <QPair <QString, QString> > FloppyBackends();
    725 
    726     /* Qt 4.2.0 support function */
    727     static inline void setLayoutMargin (QLayout *aLayout, int aMargin)
    728     {
    729 #if QT_VERSION < 0x040300
    730         /* Deprecated since > 4.2 */
    731         aLayout->setMargin (aMargin);
    732 #else
    733         /* New since > 4.2 */
    734         aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin);
    735 #endif
    736     }
    737 
    738     static QString documentsPath();
    739 
    740 #ifdef VBOX_WITH_VIDEOHWACCEL
    741     static bool isAcceleration2DVideoAvailable();
    742 
    743     /** additional video memory required for the best 2D support performance
    744      *  total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory  */
    745     static quint64 required2DOffscreenVideoMemory();
    746 #endif
    747 
    748 #ifdef VBOX_WITH_CRHGSMI
    749     static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
    750     static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
    751 #endif /* VBOX_WITH_CRHGSMI */
    752 
    753 #ifdef Q_WS_MAC
    754     bool isSheetWindowsAllowed(QWidget *pParent) const;
    755 #endif /* Q_WS_MAC */
    756 
    757     /* Returns full medium-format name for the given base medium-format name: */
    758     static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
    759 
    760 signals:
    761 
    762     /**
    763      * Emitted at the beginning of the enumeration process started by
    764      * #startEnumeratingMedia().
    765      */
    766     void mediumEnumStarted();
    767 
    768     /**
    769      * Emitted when a new medium item from the list has updated its
    770      * accessibility state.
    771      */
    772     void mediumEnumerated (const VBoxMedium &aMedum);
    773 
    774     /**
    775      * Emitted at the end of the enumeration process started by
    776      * #startEnumeratingMedia(). The @a aList argument is passed for
    777      * convenience, it is exactly the same as returned by #currentMediaList().
    778      */
    779     void mediumEnumFinished (const VBoxMediaList &aList);
    780 
    781     /** Emitted when a new media is added using #addMedia(). */
    782     void mediumAdded (const VBoxMedium &);
    783 
    784     /** Emitted when the media is updated using #updateMedia(). */
    785     void mediumUpdated (const VBoxMedium &);
    786 
    787     /** Emitted when the media is removed using #removeMedia(). */
    788     void mediumRemoved (VBoxDefs::MediumType, const QString &);
    789 
    790 #ifdef VBOX_GUI_WITH_SYSTRAY
    791     void sigTrayIconShow(bool fEnabled);
    792 #endif
    793 
    794 public slots:
    795 
    796     bool openURL (const QString &aURL);
    797 
    798     void showRegistrationDialog (bool aForce = true);
    799     void sltGUILanguageChange(QString strLang);
    800     void sltProcessGlobalSettingChange();
    801 
    802 protected:
    803 
    804     bool event (QEvent *e);
    805     bool eventFilter (QObject *, QEvent *);
    806 
    807 private:
    808 
    809     VBoxGlobal();
    810     ~VBoxGlobal();
    811 
    812     void init();
    813 #ifdef VBOX_WITH_DEBUGGER_GUI
    814     void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
    815     void setDebuggerVar(int *piDbgCfgVar, bool fState);
    816     bool isDebuggerWorker(int *piDbgCfgVar, CMachine &rMachine, const char *pszExtraDataName);
    817 #endif
    818 
    819     bool mValid;
    820 
    821     CVirtualBox mVBox;
    822     CHost mHost;
    823 
    824     VBoxGlobalSettings gset;
    825 
    826     UISelectorWindow *mSelectorWnd;
    827     UIMachine *m_pVirtualMachine;
    828     QWidget* mMainWindow;
    829 
    830 #ifdef VBOX_WITH_REGISTRATION
    831     UIRegistrationWzd *mRegDlg;
    832 #endif
    833 
    834     QString vmUuid;
    835     QList<QUrl> m_ArgUrlList;
    836 
    837 #ifdef VBOX_GUI_WITH_SYSTRAY
    838     bool mIsTrayMenu : 1; /*< Tray icon active/desired? */
    839     bool mIncreasedWindowCounter : 1;
    840 #endif
    841 
    842     /** Whether to show error message boxes for VM start errors. */
    843     bool mShowStartVMErrors;
    844 
    845     QThread *mMediaEnumThread;
    846     VBoxMediaList mMediaList;
    847 
    848     VBoxDefs::RenderMode vm_render_mode;
    849     const char * vm_render_mode_str;
    850     bool mIsKWinManaged;
    851 
    852     /** The --disable-patm option. */
    853     bool mDisablePatm;
    854     /** The --disable-csam option. */
    855     bool mDisableCsam;
    856     /** The --recompile-supervisor option. */
    857     bool mRecompileSupervisor;
    858     /** The --recompile-user option. */
    859     bool mRecompileUser;
    860 
    861 #ifdef VBOX_WITH_DEBUGGER_GUI
    862     /** Whether the debugger should be accessible or not.
    863      * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
    864      * VBOX_GUI_DBG_AUTO_SHOW to enable. */
    865     int mDbgEnabled;
    866     /** Whether to show the debugger automatically with the console.
    867      * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
    868     int mDbgAutoShow;
    869     /** Whether to show the command line window when mDbgAutoShow is set. */
    870     int mDbgAutoShowCommandLine;
    871     /** Whether to show the statistics window when mDbgAutoShow is set. */
    872     int mDbgAutoShowStatistics;
    873     /** VBoxDbg module handle. */
    874     RTLDRMOD mhVBoxDbg;
    875 
    876     /** Whether to start the VM in paused state or not. */
    877     bool mStartPaused;
    878 #endif
    879 
    880 #if defined (Q_WS_WIN32)
    881     DWORD dwHTMLHelpCookie;
    882 #endif
    883 
    884     QString mVerString;
    885     QString mBrandingConfig;
    886 
    887     int m3DAvailable;
    888 
    889     QList <QString> mFamilyIDs;
    890     QList <QList <CGuestOSType> > mTypes;
    891     QHash <QString, QPixmap *> mOsTypeIcons;
    892 
    893     QHash <ulong, QPixmap *> mVMStateIcons;
    894     QHash <ulong, QColor *> mVMStateColors;
    895 
    896     QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon;
    897 
    898     QULongStringHash mMachineStates;
    899     QULongStringHash mSessionStates;
    900     QULongStringHash mDeviceTypes;
    901 
    902     QULongStringHash mStorageBuses;
    903     QLongStringHash mStorageBusChannels;
    904     QLongStringHash mStorageBusDevices;
    905     QULongStringHash mSlotTemplates;
    906 
    907     QULongStringHash mDiskTypes;
    908     QString mDiskTypes_Differencing;
    909 
    910     QULongStringHash mAuthTypes;
    911     QULongStringHash mPortModeTypes;
    912     QULongStringHash mUSBFilterActionTypes;
    913     QULongStringHash mAudioDriverTypes;
    914     QULongStringHash mAudioControllerTypes;
    915     QULongStringHash mNetworkAdapterTypes;
    916     QULongStringHash mNetworkAttachmentTypes;
    917     QULongStringHash mNetworkAdapterPromiscModePolicyTypes;
    918     QULongStringHash mNATProtocolTypes;
    919     QULongStringHash mClipboardTypes;
    920     QULongStringHash mStorageControllerTypes;
    921     QULongStringHash mUSBDeviceStates;
    922     QULongStringHash mChipsetTypes;
    923 
    924     QString mUserDefinedPortName;
    925 
    926     QPixmap mWarningIcon, mErrorIcon;
    927 
    928     QFileIconProvider m_globalIconProvider;
    929 
    930 #ifdef VBOX_GUI_WITH_PIDFILE
    931     QString m_strPidfile;
    932 #endif
    933 
    934     friend VBoxGlobal &vboxGlobal();
    935 };
    936 
    937 inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
    938 
    939 // Helper classes
    940 ////////////////////////////////////////////////////////////////////////////////
    941 
    942 /**
    943  *  USB Popup Menu class.
    944  *  This class provides the list of USB devices attached to the host.
    945  */
    946 class VBoxUSBMenu : public QMenu
    947 {
    948     Q_OBJECT
    949 
    950 public:
    951 
    952     VBoxUSBMenu (QWidget *);
    953 
    954     const CUSBDevice& getUSB (QAction *aAction);
    955 
    956     void setConsole (const CConsole &);
    957 
    958 private slots:
    959 
    960     void processAboutToShow();
    961 
    962 private:
    963     bool event(QEvent *aEvent);
    964 
    965     QMap <QAction *, CUSBDevice> mUSBDevicesMap;
    966     CConsole mConsole;
    967 };
    968 
    969 /**
    970  *  Enable/Disable Menu class.
    971  *  This class provides enable/disable menu items.
    972  */
    973 class VBoxSwitchMenu : public QMenu
    974 {
    975     Q_OBJECT
    976 
    977 public:
    978 
    979     VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);
    980 
    981     void setToolTip (const QString &);
    982 
    983 private slots:
    984 
    985     void processAboutToShow();
    986 
    987 private:
    988 
    989     QAction *mAction;
    990     bool     mInverted;
    991 };
    992 
    993 #endif /* __VBoxGlobal_h__ */
    994 
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r41587 r41590  
    2424#include <QLocale>
    2525#include <QThread>
     26#include <QProcess>
    2627#ifdef Q_WS_MAC
    2728# include <QPushButton>
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r41587 r41590  
    5858#include "QIMessageBox.h"
    5959#include "QIDialogButtonBox.h"
     60#include "QIProcess.h"
    6061#include "UIIconPool.h"
    6162#include "UIActionPoolSelector.h"
     
    21412142        .arg (distrib).arg (version).arg (kernel);
    21422143#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 =
    2149         Process::singleShot (QString (szAppPrivPath) + "/VBoxSysInfo.sh");
     2144    /* Get script path: */
     2145    char szAppPrivPath[RTPATH_MAX];
     2146    int rc = RTPathAppPrivateNoArch(szAppPrivPath, sizeof(szAppPrivPath)); NOREF(rc);
     2147    AssertRC(rc);
     2148    /* Run script: */
     2149    QByteArray result = QIProcess::singleShot(QString(szAppPrivPath) + "/VBoxSysInfo.sh");
    21502150    if (!result.isNull())
    2151         platform += QString (" [%1]").arg (QString (result).trimmed());
     2151        platform += QString(" [%1]").arg(QString(result).trimmed());
    21522152#else
    21532153    /* Use RTSystemQueryOSInfo. */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r41587 r41590  
    2525#include <QMenu>
    2626#include <QStyle>
    27 #include <QProcess>
    2827#include <QHash>
    2928#include <QFileIconProvider>
     
    4544#include "CUSBDevice.h"
    4645
    47 /* Other VBox includes: */
    48 #ifdef Q_WS_X11
    49 # include <sys/wait.h>
    50 #endif /* Q_WS_X11 */
    51 
    5246/* Forward declarations: */
    5347class QAction;
     
    5549class QToolButton;
    5650class UIMachine;
    57 
    58 class Process : public QProcess
    59 {
    60     Q_OBJECT;
    61 
    62 public:
    63 
    64     static QByteArray singleShot (const QString &aProcessName,
    65                                   int aTimeout = 5000
    66                                   /* wait for data maximum 5 seconds */)
    67     {
    68         /* Why is it really needed is because of Qt4.3 bug with QProcess.
    69          * This bug is about QProcess sometimes (~70%) do not receive
    70          * notification about process was finished, so this makes
    71          * 'bool QProcess::waitForFinished (int)' block the GUI thread and
    72          * never dismissed with 'true' result even if process was really
    73          * started&finished. So we just waiting for some information
    74          * on process output and destroy the process with force. Due to
    75          * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
    76          * we have to change process state to QProcess::NotRunning. */
    77 
    78         QByteArray result;
    79         Process process;
    80         process.start (aProcessName);
    81         bool firstShotReady = process.waitForReadyRead (aTimeout);
    82         if (firstShotReady)
    83             result = process.readAllStandardOutput();
    84         process.setProcessState (QProcess::NotRunning);
    85 #ifdef Q_WS_X11
    86         int status;
    87         if (process.pid() > 0)
    88             waitpid(process.pid(), &status, 0);
    89 #endif
    90         return result;
    91     }
    92 
    93 protected:
    94 
    95     Process (QWidget *aParent = 0) : QProcess (aParent) {}
    96 };
    9751
    9852struct StorageSlot
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp

    r41587 r41590  
    2121#include <QCloseEvent>
    2222#include <QTimer>
    23 #include <VBox/version.h>
     23#include <QProcess>
    2424
    2525/* GUI includes: */
     
    3737#include "UISession.h"
    3838#include "UIVMCloseDialog.h"
     39
     40/* COM includes: */
     41#include "CSnapshot.h"
     42
     43/* Other VBox includes: */
     44#include <VBox/version.h>
     45#ifdef VBOX_BLEEDING_EDGE
     46# include <iprt/buildconfig.h>
     47#endif /* VBOX_BLEEDING_EDGE */
     48
     49/* External includes: */
    3950#ifdef Q_WS_X11
    4051# include <X11/Xlib.h>
    4152#endif /* Q_WS_X11 */
    42 
    43 /* COM includes: */
    44 #include "CSnapshot.h"
    45 
    46 /* Other VBox includes: */
    47 #ifdef VBOX_BLEEDING_EDGE
    48 # include <iprt/buildconfig.h>
    49 #endif /* VBOX_BLEEDING_EDGE */
    5053
    5154/* static */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette