VirtualBox

Ignore:
Timestamp:
Oct 27, 2008 2:04:18 PM (16 years ago)
Author:
vboxsync
Message:

Ported s2 branch (r37120:38456).

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 added
2 deleted
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/VBoxUI.pro

    r9060 r13580  
    2525LANGUAGE        = C++
    2626
    27 FORMS   = ui/VBoxDiskImageManagerDlg.ui \
     27FORMS   = ui/VBoxMediaManagerDlg.ui \
    2828        ui/VBoxVMNetworkSettings.ui \
    2929        ui/VBoxVMSerialPortSettings.ui \
  • trunk/src/VBox/Frontends/VirtualBox/include/COMDefs.h

    r8155 r13580  
    179179
    180180/**
    181  *  Base COM class the CInterface template and all wrapper classes are derived
    182  *  from. Provides common functionality for all COM wrappers.
     181 * Base COM class the CInterface template and all wrapper classes are derived
     182 * from. Provides common functionality for all COM wrappers.
    183183 */
    184184class COMBase
     
    190190
    191191    /**
    192      *  Returns the result code of the last interface method called
    193      *  by the wrapper instance or the result of CInterface::createInstance()
    194      *  operation.
     192     * Returns the result code of the last interface method called by the
     193     * wrapper instance or the result of CInterface::createInstance()
     194     * operation.
    195195     */
    196196    HRESULT lastRC() const { return mRC; }
    197 
    198     /**
    199      *  Returns error info set by the last unsuccessfully invoked interface
    200      *  method. Returned error info is useful only if CInterface::lastRC()
    201      *  represents a failure or a warning (i.e. CInterface::isReallyOk() is
    202      *  false).
    203      */
    204     virtual COMErrorInfo errorInfo() const { return COMErrorInfo(); }
    205197
    206198#if !defined (VBOX_WITH_XPCOM)
     
    231223    static void ToSafeArray (const QValueVector <QT> &aVec, com::SafeArray <CT> &aArr)
    232224    {
     225        Q_UNUSED (aVec);
     226        Q_UNUSED (aArr);
    233227        AssertMsgFailedReturnVoid (("No conversion!\n"));
    234228    }
     
    237231    static void FromSafeArray (const com::SafeArray <CT> &aArr, QValueVector <QT> &aVec)
    238232    {
     233        Q_UNUSED (aArr);
     234        Q_UNUSED (aVec);
    239235        AssertMsgFailedReturnVoid (("No conversion!\n"));
    240236    }
     
    243239    static void ToSafeArray (const QValueVector <QT *> &aVec, com::SafeArray <CT *> &aArr)
    244240    {
     241        Q_UNUSED (aVec);
     242        Q_UNUSED (aArr);
    245243        AssertMsgFailedReturnVoid (("No conversion!\n"));
    246244    }
     
    249247    static void FromSafeArray (const com::SafeArray <CT *> &aArr, QValueVector <QT *> &aVec)
    250248    {
     249        Q_UNUSED (aArr);
     250        Q_UNUSED (aVec);
    251251        AssertMsgFailedReturnVoid (("No conversion!\n"));
    252252    }
     
    280280    static void FromSafeArray (const com::SafeArray <BSTR> &aArr,
    281281                               QValueVector <QString> &aVec);
     282
     283    /* Arrays of GUID */
     284
     285    static void ToSafeArray (const QValueVector <QUuid> &aVec,
     286                             com::SafeGUIDArray &aArr);
     287    static void FromSafeArray (const com::SafeGUIDArray &aArr,
     288                               QValueVector <QUuid> &aVec);
    282289
    283290    /* Arrays of interface pointers. Note: we need a separate pair of names
     
    299306             it != aVec.end(); ++ it, ++ i)
    300307        {
    301             aArr [i] = (*it).iface();
     308            aArr [i] = (*it).raw();
    302309            if (aArr [i])
    303310                aArr [i]->AddRef();
     
    457464#endif /* !defined (VBOX_WITH_XPCOM) */
    458465
    459     void fetchErrorInfo (IUnknown * /*callee*/, const GUID * /*calleeIID*/) const {}
     466    static void addref (IUnknown *aIface) { if (aIface) aIface->AddRef(); }
     467    static void release (IUnknown *aIface) { if (aIface) aIface->Release(); }
     468
     469protected:
    460470
    461471    mutable HRESULT mRC;
     
    467477
    468478/**
    469  *  Alternative base class for the CInterface template that adds
    470  *  the errorInfo() method for providing extended error info about
    471  *  unsuccessful invocation of the last called interface method.
     479 * Alternative base class for the CInterface template that adds the errorInfo()
     480 * method for providing extended error info about unsuccessful invocation of the
     481 * last called interface method.
    472482 */
    473483class COMBaseWithEI : public COMBase
     
    476486
    477487    /**
    478      *  Returns error info set by the last unsuccessfully invoked interface
    479      *  method. Returned error info is useful only if CInterface::lastRC()
    480      *  represents a failure or a warning (i.e. CInterface::isReallyOk() is
    481      *  false).
    482      */
    483     COMErrorInfo errorInfo() const { return mErrInfo; }
     488     * Returns error info set by the last unsuccessfully invoked interface
     489     * method. Returned error info is useful only if CInterface::lastRC()
     490     * represents a failure or a warning (i.e. CInterface::isReallyOk() is
     491     * false).
     492     */
     493    const COMErrorInfo &errorInfo() const { return mErrInfo; }
    484494
    485495protected:
    486496
    487     /* no arbitrary instance creations */
     497    /* no arbitrary instance creation */
    488498    COMBaseWithEI() : COMBase () {};
    489499
    490     void fetchErrorInfo (IUnknown *callee, const GUID *calleeIID) const
    491     {
    492         mErrInfo.fetchFromCurrentThread (callee, calleeIID);
     500    void setErrorInfo (const COMErrorInfo &aErrInfo) { mErrInfo = aErrInfo; }
     501
     502    void fetchErrorInfo (IUnknown *aCallee, const GUID *aCalleeIID) const
     503    {
     504        mErrInfo.fetchFromCurrentThread (aCallee, aCalleeIID);
    493505    }
    494506
     
    499511
    500512/**
    501  *  Simple class that encapsulates the result code and COMErrorInfo.
     513 * Simple class that encapsulates the result code and COMErrorInfo.
    502514 */
    503515class COMResult
     
    507519    COMResult() : mRC (S_OK) {}
    508520
    509     /** Queries the current result code and error info from the given component */
    510     COMResult (const COMBase &aComponent)
    511     {
    512         mErrInfo = aComponent.errorInfo();
    513         mRC = aComponent.lastRC();
    514     }
    515 
    516     /** Queries the current result code and error info from the given component */
     521    /**
     522     * Queries the current result code from the given component.
     523     */
     524    explicit COMResult (const COMBase &aComponent)
     525        : mRC (aComponent.lastRC()) {}
     526
     527    /**
     528     * Queries the current result code and error info from the given component.
     529     */
     530    COMResult (const COMBaseWithEI &aComponent)
     531        : mRC (aComponent.lastRC())
     532        , mErrInfo (aComponent.errorInfo()) {}
     533
     534    /**
     535     * Queries the current result code from the given component.
     536     */
    517537    COMResult &operator= (const COMBase &aComponent)
    518538    {
    519         mErrInfo = aComponent.errorInfo();
    520539        mRC = aComponent.lastRC();
    521540        return *this;
    522541    }
    523542
     543    /**
     544     * Queries the current result code and error info from the given component.
     545     */
     546    COMResult &operator= (const COMBaseWithEI &aComponent)
     547    {
     548        mRC = aComponent.lastRC();
     549        mErrInfo = aComponent.errorInfo();
     550        return *this;
     551    }
     552
    524553    bool isNull() const { return mErrInfo.isNull(); }
    525554
     
    546575private:
    547576
     577    HRESULT mRC;
    548578    COMErrorInfo mErrInfo;
    549     HRESULT mRC;
    550579};
    551580
    552581/////////////////////////////////////////////////////////////////////////////
    553582
    554 class CUnknown;
    555 
    556583/**
    557  *  Wrapper template class for all interfaces.
    558  *
    559  *  All interface methods named as they are in the original, i.e. starting
    560  *  with the capital letter. All utility non-interface methods are named
    561  *  starting with the small letter. Utility methods should be not normally
    562  *  called by the end-user client application.
    563  *
    564  *  @param  I   interface class (i.e. IUnknown/nsISupports derivant)
    565  *  @param  B   base class, either COMBase (by default) or COMBaseWithEI
     584 * Wrapper template class for all interfaces.
     585 *
     586 * All interface methods named as they are in the original, i.e. starting
     587 * with the capital letter. All utility non-interface methods are named
     588 * starting with the small letter. Utility methods should be not normally
     589 * called by the end-user client application.
     590 *
     591 * @param  I    Interface class (i.e. IUnknown/nsISupports derivant).
     592 * @param  B    Base class, either COMBase (by default) or COMBaseWithEI.
    566593 */
    567594template <class I, class B = COMBase>
     
    573600    typedef I Iface;
    574601
    575     /* constructors & destructor */
     602    // constructors & destructor
    576603
    577604    CInterface() : mIface (NULL) {}
     
    582609    }
    583610
    584     CInterface (const CUnknown &that);
    585 
    586     CInterface (I *i) : mIface (i) { addref (mIface); }
     611    CInterface (I *aIface) : mIface (aIface) { addref (mIface); }
    587612
    588613    virtual ~CInterface() { release (mIface); }
    589614
    590     /* utility methods */
    591 
    592     void createInstance (const CLSID &clsid)
     615    // utility methods
     616
     617    void createInstance (const CLSID &aClsId)
    593618    {
    594619        AssertMsg (!mIface, ("Instance is already non-NULL\n"));
     
    597622#if !defined (VBOX_WITH_XPCOM)
    598623
    599             B::mRC = CoCreateInstance (clsid, NULL, CLSCTX_ALL,
     624            B::mRC = CoCreateInstance (aClsId, NULL, CLSCTX_ALL,
    600625                                       _ATL_IIDOF (I), (void **) &mIface);
    601626
     
    605630            B::mRC = NS_GetComponentManager (getter_AddRefs (manager));
    606631            if (SUCCEEDED (B::mRC))
    607                 B::mRC = manager->CreateInstance (clsid, nsnull, NS_GET_IID (I),
     632                B::mRC = manager->CreateInstance (aClsId, nsnull, NS_GET_IID (I),
    608633                                                  (void **) &mIface);
    609634
     
    617642    }
    618643
    619     void attach (I *i)
    620     {
    621         /* be aware of self (from COM point of view) assignment */
    622         I *old_iface = mIface;
    623         mIface = i;
    624         addref (mIface);
    625         release (old_iface);
     644    /**
     645     * Attaches to the given foreign interface pointer by querying the own
     646     * interface on it. The operation may fail.
     647     */
     648    template <class OI>
     649    void attach (OI *aIface)
     650    {
     651        /* be aware of self assignment */
     652        addref (aIface);
     653        release (mIface);
     654        if (aIface)
     655        {
     656            mIface = NULL;
     657#if !defined (VBOX_WITH_XPCOM)
     658            B::mRC = aIface->QueryInterface (_ATL_IIDOF (I), (void **) &mIface);
     659#else /* !defined (VBOX_WITH_XPCOM) */
     660            B::mRC = aIface->QueryInterface (NS_GET_IID (I), (void **) &mIface);
     661#endif /* !defined (VBOX_WITH_XPCOM) */
     662        }
     663        else
     664        {
     665            mIface = NULL;
     666            B::mRC = S_OK;
     667        }
     668    };
     669
     670    /** Specialization of attach() for our own interface I. Never fails. */
     671    void attach (I *aIface)
     672    {
     673        /* be aware of self assignment */
     674        addref (aIface);
     675        release (mIface);
     676        mIface = aIface;
    626677        B::mRC = S_OK;
    627678    };
    628679
    629     void attachUnknown (IUnknown *i)
    630     {
    631         /* be aware of self (from COM point of view) assignment */
    632         I *old_iface = mIface;
    633         mIface = NULL;
    634         B::mRC = S_OK;
    635         if (i)
    636 #if !defined (VBOX_WITH_XPCOM)
    637             B::mRC = i->QueryInterface (_ATL_IIDOF (I), (void **) &mIface);
    638 #else /* !defined (VBOX_WITH_XPCOM) */
    639             B::mRC = i->QueryInterface (NS_GET_IID (I), (void **) &mIface);
    640 #endif /* !defined (VBOX_WITH_XPCOM) */
    641         release (old_iface);
    642     };
    643 
     680    /** Detaches from the underlying interface pointer. */
    644681    void detach() { release (mIface); mIface = NULL; }
    645682
     683    /** Returns @c true if not attached to any interface pointer. */
    646684    bool isNull() const { return mIface == NULL; }
    647685
     
    663701    bool isReallyOk() const { return !isNull() && B::mRC == S_OK; }
    664702
    665     /* utility operators */
     703    // utility operators
    666704
    667705    CInterface &operator= (const CInterface &that)
     
    672710    }
    673711
    674     I *iface() const { return mIface; }
     712    CInterface &operator= (I *aIface)
     713    {
     714        attach (aIface);
     715        return *this;
     716    }
     717
     718    /**
     719     * Returns the raw interface pointer. Not intended to be used for anything
     720     * else but in generated wrappers and for debugging. You've been warned.
     721     */
     722    I *raw() const { return mIface; }
    675723
    676724    bool operator== (const CInterface &that) const { return mIface == that.mIface; }
    677725    bool operator!= (const CInterface &that) const { return mIface != that.mIface; }
    678726
    679     CInterface &operator= (const CUnknown &that);
    680 
    681727protected:
    682 
    683     static void addref (I *i) { if (i) i->AddRef(); }
    684     static void release (I *i) { if (i) i->Release(); }
    685728
    686729    mutable I *mIface;
     
    693736public:
    694737
    695     CUnknown() : CInterface <IUnknown, COMBaseWithEI> () {}
    696 
    697     template <class C>
    698     explicit CUnknown (const C &that)
    699     {
    700         mIface = NULL;
    701         if (that.mIface)
    702 #if !defined (VBOX_WITH_XPCOM)
    703             mRC = that.mIface->QueryInterface (_ATL_IIDOF (IUnknown), (void**) &mIface);
    704 #else /* !defined (VBOX_WITH_XPCOM) */
    705             mRC = that.mIface->QueryInterface (NS_GET_IID (IUnknown), (void**) &mIface);
    706 #endif /* !defined (VBOX_WITH_XPCOM) */
     738    typedef CInterface <IUnknown, COMBaseWithEI> Base;
     739
     740    CUnknown() {}
     741
     742    /** Creates an instance given another CInterface-based instance. */
     743    template <class OI, class OB>
     744    explicit CUnknown (const CInterface <OI, OB> &that)
     745    {
     746        attach (that.mIface);
    707747        if (SUCCEEDED (mRC))
    708748        {
     749            /* preserve old error info if any */
    709750            mRC = that.lastRC();
    710             mErrInfo = that.errorInfo();
    711         }
    712     }
    713 
    714     /* specialization for CUnknown */
    715     CUnknown (const CUnknown &that) : CInterface <IUnknown, COMBaseWithEI> ()
    716     {
    717         mIface = that.mIface;
    718         addref (mIface);
    719         COMBaseWithEI::operator= (that);
    720     }
    721 
    722     template <class C>
    723     CUnknown &operator= (const C &that)
    724     {
    725         /* be aware of self (from COM point of view) assignment */
    726         IUnknown *old_iface = mIface;
    727         mIface = NULL;
    728         mRC = S_OK;
    729 #if !defined (VBOX_WITH_XPCOM)
    730         if (that.mIface)
    731             mRC = that.mIface->QueryInterface (_ATL_IIDOF (IUnknown), (void**) &mIface);
    732 #else /* !defined (VBOX_WITH_XPCOM) */
    733         if (that.mIface)
    734             mRC = that.mIface->QueryInterface (NS_GET_IID (IUnknown), (void**) &mIface);
    735 #endif /* !defined (VBOX_WITH_XPCOM) */
     751            setErrorInfo (that.errorInfo());
     752        }
     753    }
     754
     755    /** Constructor specialization for IUnknown. */
     756    CUnknown (const CUnknown &that) : Base (that) {}
     757
     758    /** Creates an instance given a foreign interface pointer. */
     759    template <class OI>
     760    explicit CUnknown (OI *aIface)
     761    {
     762        attach (aIface);
     763    }
     764
     765    /** Constructor specialization for IUnknown. */
     766    explicit CUnknown (IUnknown *aIface) : Base (aIface) {}
     767
     768    /** Assigns from another CInterface-based instance. */
     769    template <class OI, class OB>
     770    CUnknown &operator= (const CInterface <OI, OB> &that)
     771    {
     772        attach (that.mIface);
    736773        if (SUCCEEDED (mRC))
    737774        {
     775            /* preserve old error info if any */
    738776            mRC = that.lastRC();
    739             mErrInfo = that.errorInfo();
    740         }
    741         release (old_iface);
     777            setErrorInfo (that.errorInfo());
     778        }
    742779        return *this;
    743780    }
    744781
    745     /* specialization for CUnknown */
     782    /** Assignment specialization for CUnknown. */
    746783    CUnknown &operator= (const CUnknown &that)
    747784    {
    748         attach (that.mIface);
    749         COMBaseWithEI::operator= (that);
     785        Base::operator= (that);
    750786        return *this;
    751787    }
    752788
    753     /* @internal Used in wrappers. */
    754     IUnknown *&ifaceRef() { return mIface; };
     789    /** Assigns from a foreign interface pointer. */
     790    template <class OI>
     791    CUnknown &operator= (OI *aIface)
     792    {
     793        attach (aIface);
     794        return *this;
     795    }
     796
     797    /** Assignment specialization for IUnknown. */
     798    CUnknown &operator= (IUnknown *aIface)
     799    {
     800        Base::operator= (aIface);
     801        return *this;
     802    }
     803
     804    /* @internal Used in generated wrappers. Never use directly. */
     805    IUnknown *&rawRef() { return mIface; };
    755806};
    756 
    757 /* inlined CInterface methods that use CUnknown */
    758 
    759 template <class I, class B>
    760 inline CInterface <I, B>::CInterface (const CUnknown &that)
    761     : mIface (NULL)
    762 {
    763     attachUnknown (that.iface());
    764     if (SUCCEEDED (B::mRC))
    765         B::operator= ((B &) that);
    766 }
    767 
    768 template <class I, class B>
    769 inline CInterface <I, B> &CInterface <I, B>::operator =(const CUnknown &that)
    770 {
    771     attachUnknown (that.iface());
    772     if (SUCCEEDED (B::mRC))
    773         B::operator= ((B &) that);
    774     return *this;
    775 }
    776807
    777808/////////////////////////////////////////////////////////////////////////////
  • trunk/src/VBox/Frontends/VirtualBox/include/COMWrappers.xsl

    r11982 r13580  
    1111
    1212/*
    13      Copyright (C) 2006-2007 Sun Microsystems, Inc.
     13     Copyright (C) 2006-2008 Sun Microsystems, Inc.
    1414
    1515     This file is part of VirtualBox Open Source Edition (OSE), as
     
    352352</xsl:template>
    353353
     354<xsl:template name="declareAttributes">
     355
     356  <xsl:param name="iface"/>
     357
     358  <xsl:apply-templates select="$iface//attribute[not(@internal='yes')]" mode="declare"/>
     359  <xsl:if test="$iface//attribute[not(@internal='yes')]">
     360    <xsl:text>&#x0A;</xsl:text>
     361  </xsl:if>
     362  <!-- go to the base interface -->
     363  <xsl:if test="$iface/@extends and $iface/@extends!='$unknown'">
     364    <xsl:choose>
     365      <!-- interfaces within library/if -->
     366      <xsl:when test="name(..)='if'">
     367        <xsl:call-template name="declareAttributes">
     368          <xsl:with-param name="iface" select="
     369            preceding-sibling::
     370              *[(self::interface or self::collection) and @name=$iface/@extends] |
     371            following-sibling::
     372              *[(self::interface or self::collection) and @name=$iface/@extends] |
     373            ../preceding-sibling::if[@target=../@target]/
     374              *[(self::interface or self::collection) and @name=$iface/@extends] |
     375            ../following-sibling::if[@target=../@target]/
     376              *[(self::interface or self::collection) and @name=$iface/@extends]
     377          "/>
     378        </xsl:call-template>
     379      </xsl:when>
     380      <!-- interfaces within library -->
     381      <xsl:otherwise>
     382        <xsl:call-template name="declareAttributes">
     383          <xsl:with-param name="iface" select="
     384            preceding-sibling::
     385              *[(self::interface or self::collection) and @name=$iface/@extends] |
     386            following-sibling::
     387              *[(self::interface or self::collection) and @name=$iface/@extends]
     388          "/>
     389        </xsl:call-template>
     390      </xsl:otherwise>
     391    </xsl:choose>
     392  </xsl:if>
     393
     394</xsl:template>
     395
     396<xsl:template name="declareMethods">
     397
     398  <xsl:param name="iface"/>
     399
     400  <xsl:apply-templates select="$iface//method[not(@internal='yes')]" mode="declare"/>
     401  <xsl:if test="$iface//method[not(@internal='yes')]">
     402    <xsl:text>&#x0A;</xsl:text>
     403  </xsl:if>
     404  <!-- go to the base interface -->
     405  <xsl:if test="$iface/@extends and $iface/@extends!='$unknown'">
     406    <xsl:choose>
     407      <!-- interfaces within library/if -->
     408      <xsl:when test="name(..)='if'">
     409        <xsl:call-template name="declareMethods">
     410          <xsl:with-param name="iface" select="
     411            preceding-sibling::
     412              *[(self::interface or self::collection) and @name=$iface/@extends] |
     413            following-sibling::
     414              *[(self::interface or self::collection) and @name=$iface/@extends] |
     415            ../preceding-sibling::if[@target=../@target]/
     416              *[(self::interface or self::collection) and @name=$iface/@extends] |
     417            ../following-sibling::if[@target=../@target]/
     418              *[(self::interface or self::collection) and @name=$iface/@extends]
     419          "/>
     420        </xsl:call-template>
     421      </xsl:when>
     422      <!-- interfaces within library -->
     423      <xsl:otherwise>
     424        <xsl:call-template name="declareMethods">
     425          <xsl:with-param name="iface" select="
     426            preceding-sibling::
     427              *[(self::interface or self::collection) and @name=$iface/@extends] |
     428            following-sibling::
     429              *[(self::interface or self::collection) and @name=$iface/@extends]
     430          "/>
     431        </xsl:call-template>
     432      </xsl:otherwise>
     433    </xsl:choose>
     434  </xsl:if>
     435
     436</xsl:template>
     437
    354438<xsl:template name="declareMembers">
    355439
     
    359443  <xsl:text>    C</xsl:text>
    360444  <xsl:value-of select="substring(@name,2)"/>
    361   <xsl:text> () : Base () {}&#x0A;</xsl:text>
    362   <!-- constructor taking CUnknown -->
     445  <xsl:text> () {}&#x0A;&#x0A;</xsl:text>
     446  <!-- constructor taking CWhatever -->
     447  <xsl:text>    template &lt;class OI, class OB&gt; explicit C</xsl:text>
     448  <xsl:value-of select="substring(@name,2)"/>
     449<xsl:text> (const CInterface &lt;OI, OB&gt; &amp; that)
     450    {
     451        attach (that.raw());
     452        if (SUCCEEDED (mRC))
     453        {
     454            mRC = that.lastRC();
     455            setErrorInfo (that.errorInfo());
     456        }
     457    }
     458</xsl:text>
     459  <xsl:text>&#x0A;</xsl:text>
     460  <!-- specialization for ourselves (copy constructor) -->
    363461  <xsl:text>    C</xsl:text>
    364462  <xsl:value-of select="substring(@name,2)"/>
    365   <xsl:text> (const CUnknown &amp; that) : Base (that) {}&#x0A;</xsl:text>
    366   <!-- constructor taking raw iface pointer -->
    367   <xsl:text>    C</xsl:text>
     463  <xsl:text> (const C</xsl:text>
     464  <xsl:value-of select="substring(@name,2)"/>
     465  <xsl:text> &amp; that) : Base (that) {}&#x0A;&#x0A;</xsl:text>
     466  <!-- constructor taking a raw iface pointer -->
     467  <xsl:text>    template &lt;class OI&gt; explicit C</xsl:text>
     468  <xsl:value-of select="substring(@name,2)"/>
     469  <xsl:text> (OI * aIface) { attach (aIface); }&#x0A;&#x0A;</xsl:text>
     470  <!-- specialization for ourselves -->
     471  <xsl:text>    explicit C</xsl:text>
    368472  <xsl:value-of select="substring(@name,2)"/>
    369473  <xsl:text> (</xsl:text>
    370474  <xsl:value-of select="@name"/>
    371   <xsl:text> *i) : Base (i) {}&#x0A;</xsl:text>
    372   <!-- assignment taking CUnknown -->
     475  <xsl:text> * aIface) : Base (aIface) {}&#x0A;&#x0A;</xsl:text>
     476  <!-- assignment taking CWhatever -->
     477  <xsl:text>    template &lt;class OI, class OB&gt; C</xsl:text>
     478  <xsl:value-of select="substring(@name,2)"/>
     479<xsl:text> &amp; operator = (const CInterface &lt;OI, OB&gt; &amp; that)
     480    {
     481        attach (that.raw());
     482        if (SUCCEEDED (mRC))
     483        {
     484            mRC = that.lastRC();
     485            setErrorInfo (that.errorInfo());
     486        }
     487        return *this;
     488    }
     489</xsl:text>
     490  <xsl:text>&#x0A;</xsl:text>
     491  <!-- specialization for ourselves -->
    373492  <xsl:text>    C</xsl:text>
    374493  <xsl:value-of select="substring(@name,2)"/>
    375   <xsl:text> &amp; operator = (const CUnknown &amp; that)&#x0A;    {&#x0A;        return (C</xsl:text>
     494  <xsl:text> &amp; operator = (const C</xsl:text>
    376495  <xsl:value-of select="substring(@name,2)"/>
    377   <xsl:text> &amp;) Base::operator = (that);&#x0A;    }&#x0A;&#x0A;</xsl:text>
     496<xsl:text> &amp; that)
     497    {
     498        Base::operator= (that);
     499        return *this;
     500    }
     501</xsl:text>
     502  <xsl:text>&#x0A;</xsl:text>
     503  <!-- assignment taking a raw iface pointer -->
     504  <xsl:text>    template &lt;class OI&gt; C</xsl:text>
     505  <xsl:value-of select="substring(@name,2)"/>
     506<xsl:text> &amp; operator = (OI * aIface)
     507    {
     508        attach (aIface);
     509        return *this;
     510    }
     511</xsl:text>
     512  <xsl:text>&#x0A;</xsl:text>
     513  <!-- specialization for ourselves -->
     514  <xsl:text>    C</xsl:text>
     515  <xsl:value-of select="substring(@name,2)"/>
     516  <xsl:text> &amp; operator = (</xsl:text>
     517  <xsl:value-of select="@name"/>
     518<xsl:text> * aIface)
     519    {
     520        Base::operator= (aIface);
     521        return *this;
     522    }
     523</xsl:text>
     524  <xsl:text>&#x0A;</xsl:text>
    378525
    379526  <xsl:text>    // attributes (properties)&#x0A;&#x0A;</xsl:text>
    380   <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="declare"/>
    381   <xsl:if test=".//attribute[not(@internal='yes')]">
    382     <xsl:text>&#x0A;</xsl:text>
    383   </xsl:if>
     527  <xsl:call-template name="declareAttributes">
     528    <xsl:with-param name="iface" select="."/>
     529  </xsl:call-template>
    384530
    385531  <xsl:text>    // methods&#x0A;&#x0A;</xsl:text>
    386   <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="declare"/>
    387   <xsl:if test=".//method[not(@internal='yes')]">
    388     <xsl:text>&#x0A;</xsl:text>
    389   </xsl:if>
     532  <xsl:call-template name="declareMethods">
     533    <xsl:with-param name="iface" select="."/>
     534  </xsl:call-template>
    390535
    391536  <xsl:text>    // friend wrappers&#x0A;&#x0A;</xsl:text>
     
    561706</xsl:template>
    562707
     708<xsl:template name="defineAttributes">
     709
     710  <xsl:param name="iface"/>
     711
     712  <xsl:apply-templates select="$iface//attribute[not(@internal='yes')]" mode="define">
     713    <xsl:with-param name="namespace" select="."/>
     714  </xsl:apply-templates>
     715
     716  <!-- go to the base interface -->
     717  <xsl:if test="$iface/@extends and $iface/@extends!='$unknown'">
     718    <xsl:choose>
     719      <!-- interfaces within library/if -->
     720      <xsl:when test="name(..)='if'">
     721        <xsl:call-template name="defineAttributes">
     722          <xsl:with-param name="iface" select="
     723            preceding-sibling::
     724              *[(self::interface or self::collection) and @name=$iface/@extends] |
     725            following-sibling::
     726              *[(self::interface or self::collection) and @name=$iface/@extends] |
     727            ../preceding-sibling::if[@target=../@target]/
     728              *[(self::interface or self::collection) and @name=$iface/@extends] |
     729            ../following-sibling::if[@target=../@target]/
     730              *[(self::interface or self::collection) and @name=$iface/@extends]
     731          "/>
     732        </xsl:call-template>
     733      </xsl:when>
     734      <!-- interfaces within library -->
     735      <xsl:otherwise>
     736        <xsl:call-template name="defineAttributes">
     737          <xsl:with-param name="iface" select="
     738            preceding-sibling::
     739              *[(self::interface or self::collection) and @name=$iface/@extends] |
     740            following-sibling::
     741              *[(self::interface or self::collection) and @name=$iface/@extends]
     742          "/>
     743        </xsl:call-template>
     744      </xsl:otherwise>
     745    </xsl:choose>
     746  </xsl:if>
     747
     748</xsl:template>
     749
     750<xsl:template name="defineMethods">
     751
     752  <xsl:param name="iface"/>
     753
     754  <xsl:apply-templates select="$iface//method[not(@internal='yes')]" mode="define">
     755    <xsl:with-param name="namespace" select="."/>
     756  </xsl:apply-templates>
     757
     758  <!-- go to the base interface -->
     759  <xsl:if test="$iface/@extends and $iface/@extends!='$unknown'">
     760    <xsl:choose>
     761      <!-- interfaces within library/if -->
     762      <xsl:when test="name(..)='if'">
     763        <xsl:call-template name="defineMethods">
     764          <xsl:with-param name="iface" select="
     765            preceding-sibling::
     766              *[(self::interface or self::collection) and @name=$iface/@extends] |
     767            following-sibling::
     768              *[(self::interface or self::collection) and @name=$iface/@extends] |
     769            ../preceding-sibling::if[@target=../@target]/
     770              *[(self::interface or self::collection) and @name=$iface/@extends] |
     771            ../following-sibling::if[@target=../@target]/
     772              *[(self::interface or self::collection) and @name=$iface/@extends]
     773          "/>
     774        </xsl:call-template>
     775      </xsl:when>
     776      <!-- interfaces within library -->
     777      <xsl:otherwise>
     778        <xsl:call-template name="defineMethods">
     779          <xsl:with-param name="iface" select="
     780            preceding-sibling::
     781              *[(self::interface or self::collection) and @name=$iface/@extends] |
     782            following-sibling::
     783              *[(self::interface or self::collection) and @name=$iface/@extends]
     784          "/>
     785        </xsl:call-template>
     786      </xsl:otherwise>
     787    </xsl:choose>
     788  </xsl:if>
     789
     790</xsl:template>
     791
    563792<xsl:template name="defineMembers">
    564     <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="define"/>
    565     <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="define"/>
     793  <xsl:call-template name="defineAttributes">
     794    <xsl:with-param name="iface" select="."/>
     795  </xsl:call-template>
     796  <xsl:call-template name="defineMethods">
     797    <xsl:with-param name="iface" select="."/>
     798  </xsl:call-template>
    566799</xsl:template>
    567800
    568801<!-- attribute definitions -->
    569802<xsl:template match="interface//attribute | collection//attribute" mode="define">
     803
     804  <xsl:param name="namespace" select="(ancestor::interface | ancestor::collection)[1]"/>
     805
    570806  <xsl:apply-templates select="parent::node()" mode="begin"/>
    571807  <xsl:apply-templates select="@if" mode="begin"/>
     
    573809    <xsl:with-param name="return" select="."/>
    574810    <xsl:with-param name="define" select="'yes'"/>
     811    <xsl:with-param name="namespace" select="$namespace"/>
    575812  </xsl:call-template>
    576813  <xsl:if test="not(@readonly='yes')">
     
    578815      <xsl:with-param name="return" select="''"/>
    579816      <xsl:with-param name="define" select="'yes'"/>
     817      <xsl:with-param name="namespace" select="$namespace"/>
    580818    </xsl:call-template>
    581819  </xsl:if>
     
    583821  <xsl:apply-templates select="parent::node()" mode="end"/>
    584822  <xsl:text>&#x0A;</xsl:text>
     823
    585824</xsl:template>
    586825
    587826<!-- method definitions -->
    588827<xsl:template match="interface//method | collection//method" mode="define">
     828
     829  <xsl:param name="namespace" select="(ancestor::interface | ancestor::collection)[1]"/>
     830
    589831  <xsl:apply-templates select="parent::node()" mode="begin"/>
    590832  <xsl:apply-templates select="@if" mode="begin"/>
    591833  <xsl:call-template name="composeMethod">
    592834    <xsl:with-param name="define" select="'yes'"/>
     835    <xsl:with-param name="namespace" select="$namespace"/>
    593836  </xsl:call-template>
    594837  <xsl:apply-templates select="@if" mode="end"/>
    595838  <xsl:apply-templates select="parent::node()" mode="end"/>
    596839  <xsl:text>&#x0A;</xsl:text>
     840
    597841</xsl:template>
    598842
     
    622866 *      declaration, or
    623867 *      empty string to produce method declaration only (w/o body)
     868 *  @param namespace
     869 *      actual interface node for which this method is being defined
     870 *      (necessary to properly set a class name for inherited methods).
     871 *      If not specified, will default to the parent interface/collection
     872 *      node of the method being defined.
    624873-->
    625874<xsl:template name="composeMethod">
    626875  <xsl:param name="return" select="param[@dir='return']"/>
    627876  <xsl:param name="define" select="''"/>
    628   <xsl:variable name="namespace" select="(ancestor::interface | ancestor::collection)[1]"/>
     877  <xsl:param name="namespace" select="(ancestor::interface | ancestor::collection)[1]"/>
    629878  <xsl:choose>
    630879    <!-- no return value -->
     
    10241273          <xsl:choose>
    10251274            <xsl:when test="@type='$unknown'">
    1026               <xsl:text>.iface()</xsl:text>
     1275              <xsl:text>.raw()</xsl:text>
    10271276            </xsl:when>
    10281277            <xsl:otherwise>
     
    10381287          <xsl:choose>
    10391288            <xsl:when test="@type='$unknown'">
    1040               <xsl:text>.ifaceRef()</xsl:text>
     1289              <xsl:text>.rawRef()</xsl:text>
    10411290            </xsl:when>
    10421291            <xsl:otherwise>
     
    15451794              <xsl:text>&gt; </xsl:text>
    15461795            </xsl:when>
     1796            <!-- GUID is special too -->
     1797            <xsl:when test="@type='uuid'">
     1798              <xsl:text>    com::SafeGUIDArray </xsl:text>
     1799            </xsl:when>
     1800            <!-- everything else is not -->
    15471801            <xsl:otherwise>
    15481802              <xsl:text>    com::SafeArray &lt;</xsl:text>
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h

    r10395 r13580  
    112112    void machineStateChanged (KMachineState state);
    113113    void additionsStateChanged (const QString &, bool, bool, bool);
    114     void mediaChanged (VBoxDefs::DiskType aType);
     114    void mediaDriveChanged (VBoxDefs::MediaType aType);
    115115    void networkStateChange();
    116116    void usbStateChange();
     
    241241    bool mAutoresizeGuest : 1;
    242242
    243     /** 
     243    /**
    244244     * This flag indicates whether the last console resize should trigger
    245245     * a size hint to the guest.  This is important particularly when
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleWnd.h

    r9036 r13580  
    178178    void updateNetworkAdarptersState();
    179179    void updateUsbState();
    180     void updateMediaState (VBoxDefs::DiskType aType);
     180    void updateMediaDriveState (VBoxDefs::MediaType aType);
    181181    void updateSharedFoldersState();
    182182
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxDefs.h

    r12627 r13580  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    106106struct VBoxDefs
    107107{
    108     /** Disk image type. */
    109     enum DiskType { InvalidType, HD = 0x01, CD = 0x02, FD = 0x04 };
     108    /** Media type. */
     109    enum MediaType
     110    {
     111        MediaType_Invalid,
     112        MediaType_HardDisk,
     113        MediaType_DVD,
     114        MediaType_Floppy,
     115        MediaType_All
     116    };
    110117
    111118    /** VM display rendering mode. */
     
    126133        MachineStateChangeEventType,
    127134        AdditionsStateChangeEventType,
    128         MediaChangeEventType,
     135        MediaDriveChangeEventType,
    129136        MachineDataChangeEventType,
    130137        MachineRegisteredEventType,
     
    138145        RuntimeErrorEventType,
    139146        ModifierKeyChangeEventType,
    140         EnumerateMediaEventType,
     147        MediaEnumEventType,
    141148#if defined (Q_WS_WIN)
    142149        ShellExecuteEventType,
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r8155 r13580  
    5050////////////////////////////////////////////////////////////////////////////////
    5151
    52 /** Simple media descriptor type. */
    53 struct VBoxMedia
     52/**
     53 * Media descriptor for the GUI.
     54 *
     55 * Maintains the results of the last state (accessibility) check and precomposes
     56 * string parameters such as location, size which can be used in various GUI
     57 * controls.
     58 *
     59 * Many getter methods take the boolean @a aNoDiffs argument. Unless explicitly
     60 * stated otherwise, this argument, when set to @c true, will cause the
     61 * corresponding property of this object's root medium to be returned instead of
     62 * its own one. This is useful when hard disk media is represented in the
     63 * user-friendly "don't show diffs" mode. For non-hard disk media, the value of
     64 * this argument is irrelevant because the root object for such medium is
     65 * the medium itself.
     66 *
     67 * Note that this class "abuses" the KMediaState_NotCreated state value to
     68 * indicate that the accessibility check of the given medium (see
     69 * #blockAndQueryState()) has not been done yet and therefore some parameters
     70 * such as #size() are meaningless because they can be read only from the
     71 * accessible medium. The real KMediaState_NotCreated state is not necessary
     72 * because this class is only used with created (existing) media.
     73 */
     74class VBoxMedium
    5475{
    55     enum Status { Unknown, Ok, Error, Inaccessible };
    56 
    57     VBoxMedia() : type (VBoxDefs::InvalidType), status (Ok) {}
    58 
    59     VBoxMedia (const CUnknown &d, VBoxDefs::DiskType t, Status s)
    60         : disk (d), type (t), status (s) {}
    61 
    62     CUnknown disk;
    63     VBoxDefs::DiskType type;
    64     Status status;
     76public:
     77
     78    /**
     79     * Creates a null medium descriptor which is not associated with any medium.
     80     * The state field is set to KMediaState_NotCreated.
     81     */
     82    VBoxMedium()
     83        : mType (VBoxDefs::MediaType_Invalid)
     84        , mState (KMediaState_NotCreated)
     85        , mIsReadOnly (false), mIsUsedInSnapshots (false)
     86        , mParent (NULL) {}
     87
     88    /**
     89     * Creates a media descriptor associated with the given medium.
     90     *
     91     * The state field remain KMediaState_NotCreated until #blockAndQueryState()
     92     * is called. All precomposed strings are filled up by implicitly calling
     93     * #refresh(), see the #refresh() details for more info.
     94     *
     95     * One of the hardDisk, dvdImage, or floppyImage members is assigned from
     96     * aMedium according to aType. @a aParent must be always NULL for non-hard
     97     * disk media.
     98     */
     99    VBoxMedium (const CMedium &aMedium, VBoxDefs::MediaType aType,
     100                VBoxMedium *aParent = NULL)
     101        : mMedium (aMedium), mType (aType)
     102        , mState (KMediaState_NotCreated)
     103        , mIsReadOnly (false), mIsUsedInSnapshots (false)
     104        , mParent (aParent) { init(); }
     105
     106    /**
     107     * Similar to the other non-null constructor but sets the media state to
     108     * @a aState. Suitable when the media state is known such as right after
     109     * creation.
     110     */
     111    VBoxMedium (const CMedium &aMedium, VBoxDefs::MediaType aType,
     112                KMediaState aState)
     113        : mMedium (aMedium), mType (aType)
     114        , mState (aState)
     115        , mIsReadOnly (false), mIsUsedInSnapshots (false)
     116        , mParent (NULL) { init(); }
     117
     118    void blockAndQueryState();
     119    void refresh();
     120
     121    const CMedium &medium() const { return mMedium; };
     122
     123    VBoxDefs::MediaType type() const { return mType; }
     124
     125    /**
     126     * Media state. In "don't show diffs" mode, this is the worst state (in
     127     * terms of inaccessibility) detected on the given hard disk chain.
     128     *
     129     * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
     130     */
     131    KMediaState state (bool aNoDiffs = false) const
     132    {
     133        unconst (this)->checkNoDiffs (aNoDiffs);
     134        return aNoDiffs ? mNoDiffs.state : mState;
     135    }
     136
     137    QString lastAccessError() const { return mLastAccessError; }
     138
     139    /**
     140     * Result of the last blockAndQueryState() call. Will indicate an error and
     141     * contain a proper error info if the last state check fails. In "don't show
     142     * diffs" mode, this is the worst result (in terms of inaccessibility)
     143     * detected on the given hard disk chain.
     144     *
     145     * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
     146     */
     147    const COMResult &result (bool aNoDiffs = false) const
     148    {
     149        unconst (this)->checkNoDiffs (aNoDiffs);
     150        return aNoDiffs ? mNoDiffs.result : mResult;
     151    }
     152
     153    const CHardDisk2 &hardDisk() const { return mHardDisk; }
     154    const CDVDImage2 &dvdImage() const { return mDVDImage; }
     155    const CFloppyImage2 &floppyImage() const { return mFloppyImage; }
     156
     157    QUuid id() const { return mId; }
     158
     159    QString location (bool aNoDiffs = false) const
     160        { return aNoDiffs ? root().mLocation : mLocation; }
     161    QString name (bool aNoDiffs = false) const
     162        { return aNoDiffs ? root().mName : mName; }
     163
     164    QString size (bool aNoDiffs = false) const
     165        { return aNoDiffs ? root().mSize : mSize; }
     166
     167    QString hardDiskFormat (bool aNoDiffs = false) const
     168        { return aNoDiffs ? root().mHardDiskFormat : mHardDiskFormat; }
     169    QString hardDiskType (bool aNoDiffs = false) const
     170        { return aNoDiffs ? root().mHardDiskType : mHardDiskType; }
     171    QString logicalSize (bool aNoDiffs = false) const
     172        { return aNoDiffs ? root().mLogicalSize : mLogicalSize; }
     173
     174    QString usage (bool aNoDiffs = false) const
     175    { return aNoDiffs ? root().mUsage : mUsage; }
     176
     177    /**
     178     * Returns @c true if this medium is read-only (either because it is
     179     * Immutable or because it has child hard disks). Read-only media can only
     180     * be attached indirectly.
     181     */
     182    bool isReadOnly() const { return mIsReadOnly; }
     183
     184    /**
     185     * Returns @c true if this medium is attached to any VM (in the current
     186     * state or in a snapshot) in which case #usage() will contain a string with
     187     * comma-sparated VM names (with snapshot names, if any, in parenthesis).
     188     */
     189    bool isUsed() const { return !mUsage.isNull(); }
     190
     191    /**
     192     * Returns @c true if this medium is attached to any VM in any snapshot.
     193     * which case #usage() will contain a string with comma-sparated VM names.
     194     */
     195    bool isUsedInSnapshots() const { return mIsUsedInSnapshots; }
     196
     197    /**
     198     * Returns @c true if this medium is attached to the given machine in the
     199     * current state.
     200     */
     201    bool isAttachedInCurStateTo (const QUuid &aMachineId) const
     202        { return mCurStateMachineIds.findIndex (aMachineId) >= 0; }
     203
     204    /**
     205     * Returns a vector of IDs of all machines this medium is attached
     206     * to in their current state (i.e. excluding snapshots).
     207     */
     208    const QValueList <QUuid> &curStateMachineIds() const
     209        { return mCurStateMachineIds; }
     210
     211    /**
     212     * Returns a parent medium. For non-hard disk media, this is always NULL.
     213     */
     214    VBoxMedium *parent() const { return mParent; }
     215
     216    VBoxMedium &root() const;
     217
     218    QString toolTip(bool aNoDiffs = false, bool aCheckRO = false) const;
     219    QPixmap icon (bool aNoDiffs = false, bool aCheckRO = false) const;
     220
     221    /** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */
     222    QString toolTipCheckRO (bool aNoDiffs = false) const
     223        { return toolTip (aNoDiffs, true); }
     224
     225    /** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */
     226    QPixmap iconCheckRO (bool aNoDiffs = false) const
     227        { return icon (aNoDiffs, true); }
     228
     229    QString details (bool aNoDiffs = false, bool aPredictDiff = false,
     230                     bool aUseHTML = false) const;
     231
     232    /** Shortcut to <tt>#details (aNoDiffs, aPredictDiff, true)</tt>. */
     233    QString detailsHTML (bool aNoDiffs = false, bool aPredictDiff = false) const
     234        { return details (aNoDiffs, aPredictDiff, true); }
     235
     236    /** Returns @c true if this media descriptor is a null object. */
     237    bool isNull() const { return mMedium.isNull(); }
     238
     239private:
     240
     241    void init();
     242
     243    void checkNoDiffs (bool aNoDiffs);
     244
     245    CMedium mMedium;
     246
     247    VBoxDefs::MediaType mType;
     248
     249    KMediaState mState;
     250    QString mLastAccessError;
     251    COMResult mResult;
     252
     253    CHardDisk2 mHardDisk;
     254    CDVDImage2 mDVDImage;
     255    CFloppyImage2 mFloppyImage;
     256
     257    QUuid mId;
     258    QString mLocation;
     259    QString mName;
     260    QString mSize;
     261
     262    QString mHardDiskFormat;
     263    QString mHardDiskType;
     264    QString mLogicalSize;
     265
     266    QString mUsage;
     267    QString mToolTip;
     268
     269    bool mIsReadOnly        : 1;
     270    bool mIsUsedInSnapshots : 1;
     271
     272    QValueList <QUuid> mCurStateMachineIds;
     273
     274    VBoxMedium *mParent;
     275
     276    /**
     277     * Used to override some attributes in the user-friendly "don't show diffs"
     278     * mode.
     279     */
     280    struct NoDiffs
     281    {
     282        NoDiffs() : isSet (false), state (KMediaState_NotCreated) {}
     283
     284        bool isSet : 1;
     285
     286        KMediaState state;
     287        COMResult result;
     288        QString toolTip;
     289    }
     290    mNoDiffs;
    65291};
    66292
    67 typedef QValueList <VBoxMedia> VBoxMediaList;
     293typedef QValueList <VBoxMedium> VBoxMediaList;
    68294
    69295// VirtualBox callback events
     
    255481    }
    256482
    257     QString toString (KHardDiskStorageType t) const
    258     {
    259         AssertMsg (!diskStorageTypes [t].isNull(), ("No text for %d", t));
    260         return diskStorageTypes [t];
     483    /**
     484     * Similar to toString (KHardDiskType), but returns 'Differencing' for
     485     * normal hard disks that have a parent.
     486     */
     487    QString hardDiskTypeString (const CHardDisk2 &aHD) const
     488    {
     489        if (!aHD.GetParent().isNull())
     490        {
     491            Assert (aHD.GetType() == KHardDiskType_Normal);
     492            return diskTypes_Differencing;
     493        }
     494        return toString (aHD.GetType());
    261495    }
    262496
     
    331565    }
    332566
    333     /**
    334      *  Similar to toString (KHardDiskType), but returns 'Differencing'
    335      *  for normal hard disks that have a parent hard disk.
    336      */
    337     QString hardDiskTypeString (const CHardDisk &aHD) const
    338     {
    339         if (!aHD.GetParent().isNull())
    340         {
    341             Assert (aHD.GetType() == KHardDiskType_Normal);
    342             return tr ("Differencing", "hard disk");
    343         }
    344         return toString (aHD.GetType());
    345     }
    346 
    347567    QString toString (KDeviceType t) const
    348568    {
     
    436656    }
    437657
     658    QPixmap warningIcon() const { return mWarningIcon; }
     659    QPixmap errorIcon() const { return mErrorIcon; }
     660
    438661    /* details generators */
    439662
    440     QString details (const CHardDisk &aHD, bool aPredict = false,
    441                      bool aDoRefresh = true);
     663    QString details (const CHardDisk2 &aHD, bool aPredictDiff);
    442664
    443665    QString details (const CUSBDevice &aDevice) const;
    444666    QString toolTip (const CUSBDevice &aDevice) const;
    445667
    446     QString prepareFileNameForHTML (const QString &fn) const;
    447 
    448     QString detailsReport (const CMachine &m, bool isNewVM, bool withLinks,
    449                            bool aDoRefresh = true);
     668    QString detailsReport (const CMachine &aMachine, bool aIsNewVM,
     669                           bool aWithLinks);
    450670
    451671    /* VirtualBox helpers */
     
    467687
    468688    /**
    469      *  Returns a list of all currently registered media. This list is used
    470      *  to globally track the accessiblity state of all media on a dedicated
    471      *  thread. This the list is initially empty (before the first enumeration
    472      *  process is started using #startEnumeratingMedia()).
    473      */
    474     const VBoxMediaList &currentMediaList() const { return media_list; }
     689     * Returns a list of all currently registered media. This list is used to
     690     * globally track the accessiblity state of all media on a dedicated thread.
     691     *
     692     * Note that the media list is initially empty (i.e. before the enumeration
     693     * process is started for the first time using #startEnumeratingMedia()).
     694     * See #startEnumeratingMedia() for more information about how meida are
     695     * sorted in the returned list.
     696     */
     697    const VBoxMediaList &currentMediaList() const { return mMediaList; }
    475698
    476699    /** Returns true if the media enumeration is in progress. */
    477     bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
    478 
    479     void addMedia (const VBoxMedia &);
    480     void updateMedia (const VBoxMedia &);
    481     void removeMedia (VBoxDefs::DiskType, const QUuid &);
    482 
    483     bool findMedia (const CUnknown &, VBoxMedia &) const;
     700    bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
     701
     702    void addMedium (const VBoxMedium &);
     703    void updateMedium (const VBoxMedium &);
     704    void removeMedium (VBoxDefs::MediaType, const QUuid &);
     705
     706    bool findMedium (const CMedium &, VBoxMedium &) const;
     707
     708    /** Compact version of #findMediumTo(). Asserts if not found. */
     709    VBoxMedium getMedium (const CMedium &aObj) const
     710    {
     711        VBoxMedium medium;
     712        if (!findMedium (aObj, medium))
     713            AssertFailed();
     714        return medium;
     715    }
    484716
    485717    /* various helpers */
     
    526758    static QString formatSize (Q_UINT64, int aMode = 0);
    527759
     760    static QString locationForHTML (const QString &aFileName);
     761
    528762    static QString highlight (const QString &aStr, bool aToolTip = false);
    529763
     
    547781    static QString removeAccelMark (const QString &aText);
    548782
     783    static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
     784
    549785    static QWidget *findWidget (QWidget *aParent, const char *aName,
    550786                                const char *aClassName = NULL,
     
    554790
    555791    /**
    556      *  Emitted at the beginning of the enumeration process started
    557      *  by #startEnumeratingMedia().
     792     * Emitted at the beginning of the enumeration process started by
     793     * #startEnumeratingMedia().
    558794     */
    559795    void mediaEnumStarted();
    560796
    561797    /**
    562      *  Emitted when a new media item from the list has updated
    563      *  its accessibility state.
    564      */
    565     void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
    566 
    567     /**
    568      *  Emitted at the end of the enumeration process started
    569      *  by #startEnumeratingMedia(). The @a aList argument is passed for
    570      *  convenience, it is exactly the same as returned by #currentMediaList().
     798     * Emitted when a new medium item from the list has updated its
     799     * accessibility state.
     800     */
     801    void mediumEnumerated (const VBoxMedium &aMedum, int aIndex);
     802
     803    /**
     804     * Emitted at the end of the enumeration process started by
     805     * #startEnumeratingMedia(). The @a aList argument is passed for
     806     * convenience, it is exactly the same as returned by #currentMediaList().
    571807     */
    572808    void mediaEnumFinished (const VBoxMediaList &aList);
    573809
    574810    /** Emitted when a new media is added using #addMedia(). */
    575     void mediaAdded (const VBoxMedia &);
     811    void mediumAdded (const VBoxMedium &);
    576812
    577813    /** Emitted when the media is updated using #updateMedia(). */
    578     void mediaUpdated (const VBoxMedia &);
     814    void mediumUpdated (const VBoxMedium &);
    579815
    580816    /** Emitted when the media is removed using #removeMedia(). */
    581     void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
     817    void mediumRemoved (VBoxDefs::MediaType, const QUuid &);
    582818
    583819    /* signals emitted when the VirtualBox callback is called by the server
     
    626862    QUuid vmUuid;
    627863
    628     QThread *media_enum_thread;
    629     VBoxMediaList media_list;
     864    QThread *mMediaEnumThread;
     865    VBoxMediaList mMediaList;
    630866
    631867    VBoxDefs::RenderMode vm_render_mode;
     
    657893    QStringVector sessionStates;
    658894    QStringVector deviceTypes;
     895
    659896    QStringVector storageBuses;
    660897    QStringVector storageBusDevices;
    661898    QStringVector storageBusChannels;
     899
    662900    QStringVector diskTypes;
    663     QStringVector diskStorageTypes;
     901    QString diskTypes_Differencing;
     902
    664903    QStringVector vrdpAuthTypes;
    665904    QStringVector portModeTypes;
     
    674913
    675914    QString mUserDefinedPortName;
     915
     916    QPixmap mWarningIcon, mErrorIcon;
    676917
    677918    mutable bool detailReportTemplatesReady;
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxMediaComboBox.h

    r8418 r13580  
    2727
    2828#include <qcombobox.h>
     29#include <qvaluelist.h>
    2930
    3031class QListBoxItem;
     
    3637public:
    3738
    38     VBoxMediaComboBox (QWidget *aParent = 0, const char *aName = 0,
    39                        int aType = 0, bool aUseEmptyItem = false);
     39    typedef QMap <QUuid, QUuid> BaseToDiffMap;
     40
     41    VBoxMediaComboBox (QWidget *aParent, const char *aName,
     42                       VBoxDefs::MediaType aType, QUuid aMachineId = QUuid());
    4043    ~VBoxMediaComboBox() {}
    4144
    42     void  refresh();
    43     void  setUseEmptyItem (bool);
    44     void  setBelongsTo (const QUuid &);
    45     QUuid getId (int aId = -1);
    46     QUuid getBelongsTo();
    47     void  setCurrentItem (const QUuid &);
    48     void  setType (int);
     45    void refresh();
     46    void repopulate();
     47
     48    QUuid id (int = -1);
     49    QString location (int = -1);
     50
     51    void setCurrentItem (const QUuid &);
     52    void setType (VBoxDefs::MediaType);
     53
     54    void setShowDiffs (bool aShowDiffs);
     55    bool showDiffs() const { return mShowDiffs; }
    4956
    5057protected slots:
    5158
    5259    void mediaEnumStarted();
    53     void mediaEnumerated (const VBoxMedia &, int);
    54     void mediaAdded (const VBoxMedia &);
    55     void mediaUpdated (const VBoxMedia &);
    56     void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
     60    void mediumEnumerated (const VBoxMedium &, int);
     61    void mediumAdded (const VBoxMedium &);
     62    void mediumUpdated (const VBoxMedium &);
     63    void mediumRemoved (VBoxDefs::MediaType, const QUuid &);
    5764    void processOnItem (QListBoxItem *);
    5865    void processActivated (int);
     
    6067protected:
    6168
     69    void addNoMediaItem();
     70
    6271    void updateToolTip (int);
    63     void processMedia (const VBoxMedia &);
    64     void processHdMedia (const VBoxMedia &);
    65     void processCdMedia (const VBoxMedia &);
    66     void processFdMedia (const VBoxMedia &);
    67     void appendItem (const QString &, const QUuid &,
    68                      const QString &, QPixmap *);
    69     void replaceItem (int, const QString &,
    70                       const QString &, QPixmap *);
    71     void updateShortcut (const QString &, const QUuid &, const QString &,
    72                           VBoxMedia::Status);
    7372
    74     int         mType;
    75     QStringList mUuidList;
    76     QStringList mTipList;
    77     QUuid       mMachineId;
    78     QUuid       mRequiredId;
    79     bool        mUseEmptyItem;
    80     QPixmap     mPmInacc;
    81     QPixmap     mPmError;
     73    void appendItem (const VBoxMedium &);
     74    void replaceItem (int, const VBoxMedium &);
     75
     76    bool findMediaIndex (const QUuid &aId, size_t &aIndex);
     77
     78    VBoxDefs::MediaType mType;
     79
     80    /** Obtruncated VBoxMedium structure. */
     81    struct Medium
     82    {
     83        Medium() {}
     84        Medium (const QUuid &aId, const QString &aLocation,
     85                const QString aToolTip)
     86            : id (aId), location (aLocation), toolTip (aToolTip) {}
     87
     88        QUuid id;
     89        QString location;
     90        QString toolTip;
     91    };
     92
     93    typedef QValueVector <Medium> Media;
     94    Media mMedia;
     95
     96    QUuid mLastId;
     97
     98    bool mShowDiffs : 1;
     99
     100    QUuid mMachineId;
    82101};
    83102
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxProblemReporter.h

    r13374 r13580  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929#include <qobject.h>
    3030
     31class VBoxMedium;
     32
    3133class QProcess;
    3234
     
    147149    void cannotSaveGlobalConfig (const CVirtualBox &vbox);
    148150    void cannotSetSystemProperties (const CSystemProperties &props);
    149     void cannotAccessUSB (const COMBase &obj);
     151    void cannotAccessUSB (const COMBaseWithEI &obj);
    150152
    151153    void cannotCreateMachine (const CVirtualBox &vbox,
     
    175177
    176178    void cannotSetSnapshotFolder (const CMachine &aMachine, const QString &aPath);
    177     void cannotDiscardSnapshot (const CConsole &console, const CSnapshot &snapshot);
    178     void cannotDiscardSnapshot (const CProgress &progress, const CSnapshot &snapshot);
     179    void cannotDiscardSnapshot (const CConsole &aConsole,
     180                                const QString &aSnapshotName);
     181    void cannotDiscardSnapshot (const CProgress &aProgress,
     182                                const QString &aSnapshotName);
    179183    void cannotDiscardCurrentState (const CConsole &console);
    180184    void cannotDiscardCurrentState (const CProgress &progress);
     
    192196    bool confirmDiscardSavedState (const CMachine &machine);
    193197
    194     bool confirmReleaseImage (QWidget *parent, const QString &usage);
    195 
    196     void sayCannotOverwriteHardDiskImage (QWidget *parent, const QString &src);
    197     int confirmHardDiskImageDeletion (QWidget *parent, const QString &src);
    198     void cannotDeleteHardDiskImage (QWidget *parent, const CVirtualDiskImage &vdi);
    199 
    200     bool confirmHardDiskUnregister (QWidget *parent, const QString &src);
     198    bool confirmReleaseMedium (QWidget *aParent, const VBoxMedium &aMedium,
     199                               const QString &aUsage);
     200
     201    bool confirmRemoveMedium (QWidget *aParent, const VBoxMedium &aMedium);
     202
     203    void sayCannotOverwriteHardDiskStorage (QWidget *aParent,
     204                                            const QString &aLocation);
     205    int confirmDeleteHardDiskStorage (QWidget *aParent,
     206                                      const QString &aLocation);
     207    void cannotDeleteHardDiskStorage (QWidget *aParent, const CHardDisk2 &aHD,
     208                                      const CProgress &aProgress);
    201209
    202210    int confirmDetachSATASlots (QWidget *aParent);
    203211    int confirmRunNewHDWzdOrVDM (QWidget *aParent);
    204212
    205     void cannotCreateHardDiskImage (
    206         QWidget *parent, const CVirtualBox &vbox, const QString &src,
    207         const CVirtualDiskImage &vdi, const CProgress &progress);
    208     void cannotAttachHardDisk (QWidget *parent, const CMachine &m, const QUuid &id,
    209                                KStorageBus bus, LONG channel, LONG dev);
    210     void cannotDetachHardDisk (QWidget *parent, const CMachine &m,
    211                                KStorageBus bus, LONG channel, LONG dev);
    212     void cannotRegisterMedia (QWidget *parent, const CVirtualBox &vbox,
    213                               VBoxDefs::DiskType type, const QString &src);
    214     void cannotUnregisterMedia (QWidget *parent, const CVirtualBox &vbox,
    215                                 VBoxDefs::DiskType type, const QString &src);
     213    void cannotCreateHardDiskStorage (QWidget *aParent, const CVirtualBox &aVBox,
     214                                      const QString &aLocaiton,
     215                                      const CHardDisk2 &aHD,
     216                                      const CProgress &aProgress);
     217    void cannotAttachHardDisk (QWidget *aParent, const CMachine &aMachine,
     218                               const QString &aLocation, KStorageBus aBus,
     219                               LONG aChannel, LONG aDevice);
     220    void cannotDetachHardDisk (QWidget *aParent, const CMachine &aMachine,
     221                               const QString &aLocation, KStorageBus aBus,
     222                               LONG aChannel, LONG aDevice);
     223
     224    void cannotMountMedium (QWidget *aParent, const CMachine &aMachine,
     225                            const VBoxMedium &aMedium, const COMResult &aResult);
     226    void cannotUnmountMedium (QWidget *aParent, const CMachine &aMachine,
     227                            const VBoxMedium &aMedium, const COMResult &aResult);
     228
     229    void cannotOpenMedium (QWidget *aParent, const CVirtualBox &aVBox,
     230                           VBoxDefs::MediaType aType, const QString &aLocation);
     231    void cannotCloseMedium (QWidget *aParent, const VBoxMedium &aMedium,
     232                            const COMResult &aResult);
    216233
    217234    void cannotOpenSession (const CSession &session);
     
    219236                            const CProgress &progress = CProgress());
    220237
    221     void cannotGetMediaAccessibility (const CUnknown &unk);
    222 
    223 /// @todo (r=dmik) later
    224 //    void cannotMountMedia (const CUnknown &unk);
    225 //    void cannotUnmountMedia (const CUnknown &unk);
     238    void cannotGetMediaAccessibility (const VBoxMedium &aMedium);
    226239
    227240#if defined Q_WS_WIN
     
    297310                           const QString &errorMsg);
    298311
     312    static QString toAccusative (VBoxDefs::MediaType aType);
     313
    299314    static QString formatRC (HRESULT aRC);
    300315
     
    307322    }
    308323
    309     static QString formatErrorInfo (const COMBase &aWrapper)
     324    static QString formatErrorInfo (const COMBaseWithEI &aWrapper)
    310325    {
    311326        Assert (aWrapper.lastRC() != S_OK);
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxSelectorWnd.h

    r8155 r13580  
    6262public slots:
    6363
    64     void fileDiskMgr();
     64    void fileMediaMgr();
    6565    void fileSettings();
    6666    void fileExit();
     
    117117
    118118    /* actions */
    119     QAction *fileDiskMgrAction;
     119    QAction *fileMediaMgrAction;
    120120    QAction *fileSettingsAction;
    121121    QAction *fileExitAction;
  • trunk/src/VBox/Frontends/VirtualBox/src/COMDefs.cpp

    r8155 r13580  
    208208}
    209209
     210/* static */
     211void COMBase::ToSafeArray (const QValueVector <QUuid> &aVec,
     212                           com::SafeGUIDArray &aArr)
     213{
     214    AssertCompileSize (GUID, sizeof (QUuid));
     215    aArr.reset (aVec.size());
     216    size_t i = 0;
     217    for (QValueVector <QUuid>::const_iterator it = aVec.begin();
     218         it != aVec.end(); ++ it, ++ i)
     219        aArr [i] = *(GUID *) &(*it);
     220}
     221
     222/* static */
     223void COMBase::FromSafeArray (const com::SafeGUIDArray &aArr,
     224                             QValueVector <QUuid> &aVec)
     225{
     226    AssertCompileSize (GUID, sizeof (QUuid));
     227    aVec = QValueVector <QUuid> (aArr.size());
     228    size_t i = 0;
     229    for (QValueVector <QUuid>::iterator it = aVec.begin();
     230         it != aVec.end(); ++ it, ++ i)
     231        *it = *(QUuid *) &aArr [i];
     232}
     233
    210234////////////////////////////////////////////////////////////////////////////////
    211235
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r11667 r13580  
    269269};
    270270
    271 /** DVD/FD change event */
    272 class MediaChangeEvent : public QEvent
     271/** DVD/Floppy drive change event */
     272class MediaDriveChangeEvent : public QEvent
    273273{
    274274public:
    275     MediaChangeEvent (VBoxDefs::DiskType aType)
    276         : QEvent ((QEvent::Type) VBoxDefs::MediaChangeEventType)
     275    MediaDriveChangeEvent (VBoxDefs::MediaType aType)
     276        : QEvent ((QEvent::Type) VBoxDefs::MediaDriveChangeEventType)
    277277        , mType (aType) {}
    278     VBoxDefs::DiskType diskType() const { return mType; }
     278    VBoxDefs::MediaType type() const { return mType; }
    279279private:
    280     VBoxDefs::DiskType mType;
     280    VBoxDefs::MediaType mType;
    281281};
    282282
     
    465465    {
    466466        LogFlowFunc (("DVD Drive changed\n"));
    467         QApplication::postEvent (mView, new MediaChangeEvent (VBoxDefs::CD));
     467        QApplication::postEvent (mView,
     468            new MediaDriveChangeEvent (VBoxDefs::MediaType_DVD));
    468469        return S_OK;
    469470    }
     
    472473    {
    473474        LogFlowFunc (("Floppy Drive changed\n"));
    474         QApplication::postEvent (mView, new MediaChangeEvent (VBoxDefs::FD));
     475        QApplication::postEvent (mView,
     476            new MediaDriveChangeEvent (VBoxDefs::MediaType_Floppy));
    475477        return S_OK;
    476478    }
     
    12171219            }
    12181220
    1219             case VBoxDefs::MediaChangeEventType:
    1220             {
    1221                 MediaChangeEvent *mce = (MediaChangeEvent *) e;
     1221            case VBoxDefs::MediaDriveChangeEventType:
     1222            {
     1223                MediaDriveChangeEvent *mce = (MediaDriveChangeEvent *) e;
    12221224                LogFlowFunc (("MediaChangeEvent\n"));
    12231225
    1224                 emit mediaChanged (mce->diskType());
     1226                emit mediaDriveChanged (mce->type());
    12251227                return true;
    12261228            }
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r13374 r13580  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2525#include "VBoxCloseVMDlg.h"
    2626#include "VBoxTakeSnapshotDlg.h"
    27 #include "VBoxDiskImageManagerDlg.h"
     27#include "VBoxMediaManagerDlg.h"
    2828#include "VBoxVMFirstRunWzd.h"
    2929#include "VBoxSharedFoldersSettings.h"
     
    817817    connect (console, SIGNAL (additionsStateChanged (const QString&, bool, bool, bool)),
    818818             this, SLOT (updateAdditionsState (const QString &, bool, bool, bool)));
    819     connect (console, SIGNAL (mediaChanged (VBoxDefs::DiskType)),
    820              this, SLOT (updateMediaState (VBoxDefs::DiskType)));
     819    connect (console, SIGNAL (mediaDriveChanged (VBoxDefs::MediaType)),
     820             this, SLOT (updateMediaDriveState (VBoxDefs::MediaType)));
    821821    connect (console, SIGNAL (usbStateChange()),
    822822             this, SLOT (updateUsbState()));
     
    16781678                name = tr ("<br><nobr><b>Image</b>: %1</nobr>",
    16791679                           "Floppy tooltip")
    1680                     .arg (QDir::convertSeparators (floppy.GetImage().GetFilePath()));
     1680                    .arg (QDir::convertSeparators (floppy.GetImage().GetLocation()));
    16811681                break;
    16821682            }
     
    17221722                name = tr ("<br><nobr><b>Image</b>: %1</nobr>",
    17231723                           "DVD-ROM tooltip")
    1724                     .arg (QDir::convertSeparators (dvd.GetImage().GetFilePath()));
     1724                    .arg (QDir::convertSeparators (dvd.GetImage().GetLocation()));
    17251725                break;
    17261726            }
     
    17431743        QString data;
    17441744        bool hasDisks = false;
    1745         CHardDiskAttachmentEnumerator aen = cmachine.GetHardDiskAttachments().Enumerate();
    1746         while (aen.HasMore())
    1747         {
    1748             CHardDiskAttachment hda = aen.GetNext();
    1749             CHardDisk hd = hda.GetHardDisk();
     1745        CHardDisk2AttachmentVector vec = cmachine.GetHardDisk2Attachments();
     1746        for (CHardDisk2AttachmentVector::ConstIterator hda = vec.begin();
     1747             hda != vec.end(); ++ hda)
     1748        {
     1749            CHardDisk2 hd = hda->GetHardDisk();
    17501750            data += QString ("<br><nobr><b>%1 %2</b>: %3</nobr>")
    1751                 .arg (vboxGlobal().toString (hda.GetBus(), hda.GetChannel()))
    1752                 .arg (vboxGlobal().toString (hda.GetBus(), hda.GetChannel(),
    1753                                              hda.GetDevice()))
     1751                .arg (vboxGlobal().toString (hda->GetBus(), hda->GetChannel()))
     1752                .arg (vboxGlobal().toString (hda->GetBus(), hda->GetChannel(),
     1753                                             hda->GetDevice()))
    17541754                .arg (QDir::convertSeparators (hd.GetLocation()));
    17551755            hasDisks = true;
     
    25002500    if (!console) return;
    25012501
    2502     VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg", WType_Dialog | WShowModal);
    2503     QUuid id = csession.GetMachine().GetId();
    2504     dlg.setup (VBoxDefs::FD, true, &id);
    2505 
    2506     if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
     2502    VBoxMediaManagerDlg dlg (this, "VBoxMediaManagerDlg", WType_Dialog | WShowModal);
     2503
     2504    dlg.setup (VBoxDefs::MediaType_Floppy, true /* aDoSelect */,
     2505               true /* aRefresh */, csession.GetMachine());
     2506
     2507    if (dlg.exec() == VBoxMediaManagerDlg::Accepted)
    25072508    {
    25082509        CFloppyDrive drv = csession.GetMachine().GetFloppyDrive();
    2509         drv.MountImage (dlg.getSelectedUuid());
     2510        drv.MountImage (dlg.selectedId());
    25102511        AssertWrapperOk (drv);
    25112512        if (drv.isOk())
     
    25442545    if (!console) return;
    25452546
    2546     VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg", WType_Dialog | WShowModal);
    2547     QUuid id = csession.GetMachine().GetId();
    2548     dlg.setup (VBoxDefs::CD, true, &id);
    2549 
    2550     if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
     2547    VBoxMediaManagerDlg dlg (this, "VBoxMediaManagerDlg", WType_Dialog | WShowModal);
     2548
     2549    dlg.setup (VBoxDefs::MediaType_DVD, true /* aDoSelect */,
     2550               true /* aRefresh */, csession.GetMachine());
     2551
     2552    if (dlg.exec() == VBoxMediaManagerDlg::Accepted)
    25512553    {
    25522554        CDVDDrive drv = csession.GetMachine().GetDVDDrive();
    2553         drv.MountImage (dlg.getSelectedUuid());
     2555        drv.MountImage (dlg.selectedId());
    25542556        AssertWrapperOk (drv);
    25552557        if (drv.isOk())
     
    26282630    else
    26292631    {
    2630         /* Check for the already registered required image: */
     2632        /* Check for the already registered required image */
    26312633        CVirtualBox vbox = vboxGlobal().virtualBox();
    26322634        QString name = QString ("VBoxGuestAdditions_%1.iso")
    26332635                                 .arg (vbox.GetVersion().remove ("_OSE"));
    2634         CDVDImageEnumerator en = vbox.GetDVDImages().Enumerate();
    2635         while (en.HasMore())
    2636         {
    2637             QString path = en.GetNext().GetFilePath();
    2638             /* compare the name part ignoring the file case*/
     2636
     2637        CDVDImage2Vector vec = vbox.GetDVDImages();
     2638        for (CDVDImage2Vector::ConstIterator it = vec.begin();
     2639             it != vec.end(); ++ it)
     2640        {
     2641            QString path = it->GetLocation();
     2642            /* compare the name part ignoring the file case */
    26392643            QString fn = QFileInfo (path).fileName();
    26402644            if (RTPathCompare (name.utf8(), fn.utf8()) == 0)
    26412645                return installGuestAdditionsFrom (path);
    26422646        }
    2643         /* Download required image: */
     2647
     2648        /* Download the required image */
    26442649        int rc = vboxProblem().cannotFindGuestAdditions (
    26452650            QDir::convertSeparators (src1), QDir::convertSeparators (src2));
     
    26622667    QUuid uuid;
    26632668
    2664     CDVDImage image = vbox.FindDVDImage (aSource);
     2669    CDVDImage2 image = vbox.FindDVDImage (aSource);
    26652670    if (image.isNull())
    26662671    {
    26672672        image = vbox.OpenDVDImage (aSource, uuid);
    26682673        if (vbox.isOk())
    2669             vbox.RegisterDVDImage (image);
    2670         if (vbox.isOk())
    26712674            uuid = image.GetId();
    26722675    }
     
    26762679    if (!vbox.isOk())
    26772680    {
    2678         vboxProblem().cannotRegisterMedia (this, vbox, VBoxDefs::CD, aSource);
     2681        vboxProblem().cannotOpenMedium (this, vbox,
     2682                                        VBoxDefs::MediaType_DVD, aSource);
    26792683        return;
    26802684    }
     
    26832687    CDVDDrive drv = csession.GetMachine().GetDVDDrive();
    26842688    drv.MountImage (uuid);
    2685     /// @todo (r=dmik) use VBoxProblemReporter::cannotMountMedia...
     2689    /// @todo NEWMEDIA use VBoxProblemReporter::cannotMountMedia
    26862690    AssertWrapperOk (drv);
    26872691}
     
    33043308}
    33053309
    3306 void VBoxConsoleWnd::updateMediaState (VBoxDefs::DiskType aType)
    3307 {
    3308     Assert (aType == VBoxDefs::CD || aType == VBoxDefs::FD);
    3309     updateAppearanceOf (aType == VBoxDefs::CD ? DVDStuff :
    3310                         aType == VBoxDefs::FD ? FloppyStuff : AllStuff);
     3310void VBoxConsoleWnd::updateMediaDriveState (VBoxDefs::MediaType aType)
     3311{
     3312    Assert (aType == VBoxDefs::MediaType_DVD || aType == VBoxDefs::MediaType_Floppy);
     3313    updateAppearanceOf (aType == VBoxDefs::MediaType_DVD ? DVDStuff :
     3314                        aType == VBoxDefs::MediaType_Floppy ? FloppyStuff :
     3315                        AllStuff);
    33113316}
    33123317
     
    34523457bool VBoxConsoleWnd::dbgCreated()
    34533458{
     3459#if 0
     3460    /// @todo needs to be ported back from VirtualBox4
    34543461    if (dbg_gui)
    34553462        return true;
    3456     int rc = DBGGuiCreate (csession.iface(), &dbg_gui, NULL);
     3463    int rc = DBGGuiCreate (csession.raw(), &dbg_gui);
    34573464    if (VBOX_SUCCESS (rc))
    34583465    {
     
    34603467        return true;
    34613468    }
     3469#endif
    34623470    return false;
    34633471}
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r12629 r13580  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    9797#endif
    9898
    99 // VBoxEnumerateMediaEvent
     99// VBoxMedium
    100100/////////////////////////////////////////////////////////////////////////////
    101101
    102 class VBoxEnumerateMediaEvent : public QEvent
     102void VBoxMedium::init()
     103{
     104    AssertReturnVoid (!mMedium.isNull());
     105
     106    switch (mType)
     107    {
     108        case VBoxDefs::MediaType_HardDisk:
     109        {
     110            mHardDisk = mMedium;
     111            AssertReturnVoid (!mHardDisk.isNull());
     112            break;
     113        }
     114        case VBoxDefs::MediaType_DVD:
     115        {
     116            mDVDImage = mMedium;
     117            AssertReturnVoid (!mDVDImage.isNull());
     118            Assert (mParent == NULL);
     119            break;
     120        }
     121        case VBoxDefs::MediaType_Floppy:
     122        {
     123            mFloppyImage = mMedium;
     124            AssertReturnVoid (!mFloppyImage.isNull());
     125            Assert (mParent == NULL);
     126            break;
     127        }
     128        default:
     129            AssertFailed();
     130    }
     131
     132    refresh();
     133}
     134
     135/**
     136 * Queries the medium state. Call this and then read the state field instad
     137 * of calling GetState() on medium directly as it will properly handle the
     138 * situation when GetState() itself fails by setting state to Inaccessible
     139 * and memorizing the error info describing why GetState() failed.
     140 *
     141 * As the last step, this method calls #refresh() to refresh all precomposed
     142 * strings.
     143 *
     144 * @note This method blocks for the duration of the state check. Since this
     145 *       check may take quite a while (e.g. for a medium located on a
     146 *       network share), the calling thread must not be the UI thread. You
     147 *       have been warned.
     148 */
     149void VBoxMedium::blockAndQueryState()
     150{
     151    mState = mMedium.GetState();
     152
     153    /* save the result to distinguish between inaccessible and e.g.
     154     * uninitialized objects */
     155    mResult = COMResult (mMedium);
     156
     157    if (!mResult.isOk())
     158    {
     159        mState = KMediaState_Inaccessible;
     160        mLastAccessError = QString::null;
     161    }
     162    else
     163        mLastAccessError = mMedium.GetLastAccessError();
     164
     165    refresh();
     166}
     167
     168/**
     169 * Refreshes the precomposed strings containing such media parameters as
     170 * location, size by querying the respective data from the associated
     171 * media object.
     172 *
     173 * Note that some string such as #size() are meaningless if the media state is
     174 * KMediaState_NotCreated (i.e. the medium has not yet been checked for
     175 * accessibility).
     176 */
     177void VBoxMedium::refresh()
     178{
     179    mId = mMedium.GetId();
     180    mLocation = mMedium.GetLocation();
     181    mName = mMedium.GetName();
     182
     183    if (mType == VBoxDefs::MediaType_HardDisk)
     184    {
     185        /// @todo NEWMEDIA use CSystemProperties::GetHardDIskFormats to see if the
     186        /// given hard disk format is a file
     187        mLocation = QDir::convertSeparators (mLocation);
     188        mHardDiskFormat = mHardDisk.GetFormat();
     189        mHardDiskType = vboxGlobal().hardDiskTypeString (mHardDisk);
     190
     191        mIsReadOnly = mHardDisk.GetReadOnly();
     192
     193        /* adjust the parent if necessary (note that mParent must always point
     194         * to an item from VBoxGlobal::currentMediaList()) */
     195
     196        CHardDisk2 parent = mHardDisk.GetParent();
     197        Assert (!parent.isNull() || mParent == NULL);
     198
     199        if (!parent.isNull() &&
     200            (mParent == NULL || mParent->mHardDisk != parent))
     201        {
     202            /* search for the parent (must be there) */
     203            const VBoxMediaList &list = vboxGlobal().currentMediaList();
     204            for (VBoxMediaList::const_iterator it = list.begin();
     205                  it != list.end(); ++ it)
     206            {
     207                if ((*it).mType != VBoxDefs::MediaType_HardDisk)
     208                    break;
     209
     210                if ((*it).mHardDisk == parent)
     211                {
     212                    /* we unconst here because by the const list we don't mean
     213                     * const items */
     214                    mParent = unconst (&*it);
     215                    break;
     216                }
     217            }
     218
     219            Assert (mParent != NULL && mParent->mHardDisk == parent);
     220        }
     221    }
     222    else
     223    {
     224        mLocation = QDir::convertSeparators (mLocation);
     225        mHardDiskFormat = QString::null;
     226        mHardDiskType = QString::null;
     227
     228        mIsReadOnly = false;
     229    }
     230
     231    if (mState != KMediaState_Inaccessible &&
     232        mState != KMediaState_NotCreated)
     233    {
     234        mSize = vboxGlobal().formatSize (mMedium.GetSize());
     235        if (mType == VBoxDefs::MediaType_HardDisk)
     236            mLogicalSize = vboxGlobal()
     237                .formatSize (mHardDisk.GetLogicalSize() * _1M);
     238        else
     239            mLogicalSize = mSize;
     240    }
     241    else
     242    {
     243        mSize = mLogicalSize = QString ("--");
     244    }
     245
     246    /* detect usage */
     247
     248    mUsage = QString::null; /* important: null means not used! */
     249
     250    mCurStateMachineIds.clear();
     251
     252    QValueVector <QUuid> machineIds = mMedium.GetMachineIds();
     253    if (machineIds.size() > 0)
     254    {
     255        QString usage;
     256
     257        CVirtualBox vbox = vboxGlobal().virtualBox();
     258
     259        for (QValueVector <QUuid>::ConstIterator it = machineIds.begin();
     260             it != machineIds.end(); ++ it)
     261        {
     262            CMachine machine = vbox.GetMachine (*it);
     263
     264            QString name = machine.GetName();
     265            QString snapshots;
     266
     267            QValueVector <QUuid> snapIds = mMedium.GetSnapshotIds (*it);
     268            for (QValueVector <QUuid>::ConstIterator jt = snapIds.begin();
     269                 jt != snapIds.end(); ++ jt)
     270            {
     271                if (*jt == *it)
     272                {
     273                    /* the medium is attached to the machine in the current
     274                     * state, we don't distinguish this for now by always
     275                     * giving the VM name in front of snapshot names. */
     276
     277                    mCurStateMachineIds.push_back (*jt);
     278                    continue;
     279                }
     280
     281                CSnapshot snapshot = machine.GetSnapshot (*jt);
     282                if (!snapshots.isNull())
     283                    snapshots += ", ";
     284                snapshots += snapshot.GetName();
     285            }
     286
     287            if (!usage.isNull())
     288                usage += ", ";
     289
     290            usage += name;
     291
     292            if (!snapshots.isNull())
     293            {
     294                usage += QString (" (%2)").arg (snapshots);
     295                mIsUsedInSnapshots = true;
     296            }
     297            else
     298                mIsUsedInSnapshots = false;
     299        }
     300
     301        Assert (!usage.isEmpty());
     302        mUsage = usage;
     303    }
     304
     305    /* compose the tooltip (makes sense to keep the format in sync with
     306     * VBoxMediaManagerDlg::languageChangeImp() and
     307     * VBoxMediaManagerDlg::processCurrentChanged()) */
     308
     309    mToolTip = QString ("<nobr><b>%1</b></nobr>").arg (mLocation);
     310
     311    if (mType == VBoxDefs::MediaType_HardDisk)
     312    {
     313        mToolTip += VBoxGlobal::tr (
     314            "<br><nobr>Type&nbsp;(Format):&nbsp;&nbsp;%2&nbsp;(%3)</nobr>",
     315            "hard disk")
     316            .arg (mHardDiskType)
     317            .arg (mHardDiskFormat);
     318    }
     319
     320    mToolTip += VBoxGlobal::tr (
     321        "<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>", "medium")
     322        .arg (mUsage.isNull() ?
     323              VBoxGlobal::tr ("<i>Not&nbsp;Attached</i>", "medium") :
     324              mUsage);
     325
     326    switch (mState)
     327    {
     328        case KMediaState_NotCreated:
     329        {
     330            mToolTip += VBoxGlobal::tr ("<br><i>Checking accessibility...</i>",
     331                                        "medium");
     332            break;
     333        }
     334        case KMediaState_Inaccessible:
     335        {
     336            if (mResult.isOk())
     337            {
     338                /* not accessibile */
     339                mToolTip += QString ("<hr>%1").
     340                    arg (VBoxGlobal::highlight (mLastAccessError,
     341                                                true /* aToolTip */));
     342            }
     343            else
     344            {
     345                /* accessibility check (eg GetState()) itself failed */
     346                mToolTip = VBoxGlobal::tr (
     347                    "<hr>Failed to check media accessibility.<br>%1.",
     348                    "medium").
     349                    arg (VBoxProblemReporter::formatErrorInfo (mResult));
     350            }
     351            break;
     352        }
     353        default:
     354            break;
     355    }
     356
     357    /* reset mNoDiffs */
     358    mNoDiffs.isSet = false;
     359}
     360
     361/**
     362 * Returns a root medium of this medium. For non-hard disk media, this is always
     363 * this medium itself.
     364 */
     365VBoxMedium &VBoxMedium::root() const
     366{
     367    VBoxMedium *root = unconst (this);
     368    while (root->mParent != NULL)
     369        root = root->mParent;
     370
     371    return *root;
     372}
     373
     374/**
     375 * Returns a tooltip for this medium.
     376 *
     377 * In "don't show diffs" mode (where the attributes of the base hard disk are
     378 * shown instead of the attributes of the differencing hard disk), extra
     379 * information will be added to the tooltip to give the user a hint that the
     380 * medium is actually a differencing hard disk.
     381 *
     382 * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
     383 * @param aCheckRO  @c true to perform the #readOnly() check and add a notice
     384 *                  accordingly.
     385 */
     386QString VBoxMedium::toolTip (bool aNoDiffs /*= false*/,
     387                             bool aCheckRO /*= false*/) const
     388{
     389    unconst (this)->checkNoDiffs (aNoDiffs);
     390
     391    QString tip = aNoDiffs ? mNoDiffs.toolTip : mToolTip;
     392
     393    if (aCheckRO && mIsReadOnly)
     394        tip += VBoxGlobal::tr (
     395            "<hr><img src=%1/>&nbsp;Attaching this hard disk will "
     396            "be performed indirectly using a newly created "
     397            "differencing hard disk.",
     398            "medium").
     399            arg ("new_16px.png");
     400
     401    return tip;
     402}
     403
     404/**
     405 * Returns an icon corresponding to the media state. Distinguishes between
     406 * the Inaccessible state and the situation when querying the state itself
     407 * failed.
     408 *
     409 * In "don't show diffs" mode (where the attributes of the base hard disk are
     410 * shown instead of the attributes of the differencing hard disk), the most
     411 * worst media state on the given hard disk chain will be used to select the
     412 * media icon.
     413 *
     414 * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
     415 * @param aCheckRO  @c true to perform the #readOnly() check and change the icon
     416 *                  accordingly.
     417 */
     418QPixmap VBoxMedium::icon (bool aNoDiffs /*= false*/,
     419                          bool aCheckRO /*= false*/) const
     420{
     421    QPixmap icon;
     422
     423    if (state (aNoDiffs) == KMediaState_Inaccessible)
     424        icon = result (aNoDiffs).isOk() ?
     425            vboxGlobal().warningIcon() : vboxGlobal().errorIcon();
     426
     427    if (aCheckRO && mIsReadOnly)
     428        icon = VBoxGlobal::
     429            joinPixmaps (icon, QPixmap::fromMimeSource ("new_16px.png"));
     430
     431    return icon;
     432}
     433
     434/**
     435 * Returns the details of this medium as a single-line string
     436 *
     437 * For hard disks, the details include the location, type and the logical size
     438 * of the hard disk. Note that if @a aNoDiffs is @c true, these properties are
     439 * queried on the root hard disk of the given hard disk because the primary
     440 * purpose of the returned string is to be human readabile (so that seeing a
     441 * complex diff hard disk name is usually not desirable).
     442 *
     443 * For other media types, the location and the actual size are returned.
     444 * Arguments @a aPredictDiff and @a aNoRoot are ignored in this case.
     445 *
     446 * @param aNoDiffs      @c true to enable user-friendly "don't show diffs" mode.
     447 * @param aPredictDiff  @c true to mark the hard disk as differencing if
     448 *                      attaching it would create a differencing hard disk (not
     449 *                      used when @a aNoRoot is true).
     450 * @param aUseHTML      @c true to allow for emphasizing using bold and italics.
     451 *
     452 * @note Use #detailsHTML() instead of passing @c true for @a aUseHTML.
     453 *
     454 * @note The media object may become uninitialized by a third party while this
     455 *       method is reading its properties. In this case, the method will return
     456 *       an empty string.
     457 */
     458QString VBoxMedium::details (bool aNoDiffs /*= false*/,
     459                             bool aPredictDiff /*= false*/,
     460                             bool aUseHTML /*= false */) const
     461{
     462    // @todo *** the below check is rough; if mMedium becomes uninitialized, any
     463    // of getters called afterwards will also fail. The same relates to the
     464    // root hard disk object (that will be the hard disk itself in case of
     465    // non-differencing disks). However, this check was added to fix a
     466    // particular use case: when the hard disk is a differencing hard disk and
     467    // it happens to be discarded (and uninitialized) after this method is
     468    // called but before we read all its properties (yes, it's possible!), the
     469    // root object will be null and calling methods on it will assert in the
     470    // debug builds. This check seems to be enough as a quick solution (fresh
     471    // hard disk attachments will be re-read by a machine state change signal
     472    // after the discard operation is finished, so the user will eventually see
     473    // correct data), but in order to solve the problem properly we need to use
     474    // exceptions everywhere (or check the result after every method call). See
     475    // also Defect #2149.
     476    if (!mMedium.isOk())
     477        return QString::null;
     478
     479    QString details, str;
     480
     481    VBoxMedium *root = unconst (this);
     482    KMediaState state = mState;
     483
     484    if (mType == VBoxDefs::MediaType_HardDisk)
     485    {
     486        if (aNoDiffs)
     487        {
     488            root = &this->root();
     489
     490            bool isDiff =
     491                (!aPredictDiff && mParent != NULL) ||
     492                (aPredictDiff && mIsReadOnly);
     493
     494            details = isDiff && aUseHTML ?
     495                QString ("<i>%1</i>, ").arg (root->mHardDiskType) :
     496                QString ("%1, ").arg (root->mHardDiskType);
     497
     498            /* overall (worst) state */
     499            state = this->state (true /* aNoDiffs */);
     500
     501            /* we cannot get the logical size if the root is not checked yet */
     502            if (root->mState == KMediaState_NotCreated)
     503                state = KMediaState_NotCreated;
     504        }
     505        else
     506        {
     507            details = QString ("%1, ").arg (root->mHardDiskType);
     508        }
     509    }
     510
     511    /// @todo prepend the details with the warning/error
     512    //  icon when not accessible
     513
     514    switch (state)
     515    {
     516        case KMediaState_NotCreated:
     517            str = VBoxGlobal::tr ("Checking...", "medium");
     518            details += aUseHTML ? QString ("<i>%1</i>").arg (str) : str;
     519            break;
     520        case KMediaState_Inaccessible:
     521            str = VBoxGlobal::tr ("Inaccessible", "medium");
     522            details += aUseHTML ? QString ("<b>%1</b>").arg (str) : str;
     523            break;
     524        default:
     525            details += mType == VBoxDefs::MediaType_HardDisk ?
     526                       root->mLogicalSize : root->mSize;
     527            break;
     528    }
     529
     530    details = aUseHTML ?
     531        QString ("%1 (<nobr>%2</nobr>)").
     532            arg (VBoxGlobal::locationForHTML (root->mName), details) :
     533        QString ("%1 (%2)").
     534            arg (VBoxGlobal::locationForHTML (root->mName), details);
     535
     536    return details;
     537}
     538
     539/**
     540 * Checks if mNoDiffs is filled in and does it if not.
     541 *
     542 * @param aNoDiffs  @if false, this method immediately returns.
     543 */
     544void VBoxMedium::checkNoDiffs (bool aNoDiffs)
     545{
     546    if (!aNoDiffs || mNoDiffs.isSet)
     547        return;
     548
     549    /* fill mNoDiffs */
     550
     551    mNoDiffs.toolTip = QString::null;
     552
     553    /* detect the overall (worst) state of the given hard disk chain */
     554    mNoDiffs.state = mState;
     555    for (VBoxMedium *cur = mParent; cur != NULL;
     556         cur = cur->mParent)
     557    {
     558        if (cur->mState == KMediaState_Inaccessible)
     559        {
     560            mNoDiffs.state = cur->mState;
     561
     562            if (mNoDiffs.toolTip.isNull())
     563                mNoDiffs.toolTip = VBoxGlobal::tr (
     564                    "<hr>Some of the media in this hard disk chain are "
     565                    "inaccessible. Please use the Virtual Media Manager "
     566                    "in <b>Show Differencing Hard Disks</b> mode to inspect "
     567                    "these media.");
     568
     569            if (!cur->mResult.isOk())
     570            {
     571                mNoDiffs.result = cur->mResult;
     572                break;
     573            }
     574
     575            /* comtinue looking for another !cur->mResult.isOk() */
     576        }
     577    }
     578
     579    if (mParent != NULL && !mIsReadOnly)
     580    {
     581        mNoDiffs.toolTip = VBoxGlobal::tr (
     582            "%1"
     583            "<hr>This base hard disk is indirectly attached using the "
     584            "following differencing hard disk:<br>"
     585            "%2%3").
     586            arg (root().toolTip(), mToolTip, mNoDiffs.toolTip);
     587    }
     588
     589    if (mNoDiffs.toolTip.isNull())
     590        mNoDiffs.toolTip = mToolTip;
     591
     592    mNoDiffs.isSet = true;
     593}
     594
     595// VBoxMediaEnumEvent
     596/////////////////////////////////////////////////////////////////////////////
     597
     598class VBoxMediaEnumEvent : public QEvent
    103599{
    104600public:
    105601
    106602    /** Constructs a regular enum event */
    107     VBoxEnumerateMediaEvent (const VBoxMedia &aMedia, int aIndex)
    108         : QEvent ((QEvent::Type) VBoxDefs::EnumerateMediaEventType)
    109         , mMedia (aMedia), mLast (false), mIndex (aIndex)
     603    VBoxMediaEnumEvent (const VBoxMedium &aMedium, int aIndex)
     604        : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType)
     605        , mMedium (aMedium), mLast (false), mIndex (aIndex)
    110606        {}
    111607    /** Constructs the last enum event */
    112     VBoxEnumerateMediaEvent()
    113         : QEvent ((QEvent::Type) VBoxDefs::EnumerateMediaEventType)
     608    VBoxMediaEnumEvent()
     609        : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType)
    114610        , mLast (true), mIndex (-1)
    115611        {}
    116612
    117     /** the last enumerated media (not valid when #last is true) */
    118     const VBoxMedia mMedia;
     613    /** the last enumerated medium (not valid when #last is true) */
     614    const VBoxMedium mMedium;
    119615    /** whether this is the last event for the given enumeration or not */
    120616    const bool mLast;
     
    130626    /** Constructs a regular enum event */
    131627    VBoxShellExecuteEvent (QThread *aThread, const QString &aURL,
    132                              bool aOk)
     628                           bool aOk)
    133629        : QEvent ((QEvent::Type) VBoxDefs::ShellExecuteEventType)
    134630        , mThread (aThread), mURL (aURL), mOk (aOk)
     
    7531249    , mRegDlg (NULL)
    7541250#endif
    755     , media_enum_thread (NULL)
     1251    , mMediaEnumThread (NULL)
    7561252    , verString ("1.0")
    7571253    , vm_state_color (KMachineState_COUNT)
     
    7631259    , storageBusChannels (3)
    7641260    , diskTypes (KHardDiskType_COUNT)
    765     , diskStorageTypes (KHardDiskStorageType_COUNT)
    7661261    , vrdpAuthTypes (KVRDPAuthType_COUNT)
    7671262    , portModeTypes (KPortMode_COUNT)
     
    12961791
    12971792/**
    1298  *  Returns the details of the given hard disk as a single-line string
    1299  *  to be used in the VM details view.
    1300  *
    1301  *  The details include the type and the virtual size of the hard disk.
    1302  *  Note that for differencing hard disks based on immutable hard disks,
    1303  *  the Immutable hard disk type is returned.
    1304  *
    1305  *  @param aHD      hard disk image (when predict = true, must be a top-level image)
    1306  *  @param aPredict when true, the function predicts the type of the resulting
    1307  *                  image after attaching the given image to the machine.
    1308  *                  Otherwise, a real type of the given image is returned
    1309  *                  (with the exception mentioned above).
    1310  *
    1311  *  @note The hard disk object may become uninitialized by a third party
    1312  *  while this method is reading its properties. In this case, the method will
    1313  *  return an empty string.
    1314  */
    1315 QString VBoxGlobal::details (const CHardDisk &aHD, bool aPredict /* = false */,
    1316                              bool aDoRefresh)
    1317 {
    1318     Assert (!aPredict || aHD.GetParent().isNull());
    1319 
    1320     VBoxMedia media;
    1321     if (!aDoRefresh)
    1322         media = VBoxMedia (CUnknown (aHD), VBoxDefs::HD, VBoxMedia::Ok);
    1323     else if (!findMedia (CUnknown (aHD), media))
     1793 * Searches for the given hard disk in the list of known media descriptors and
     1794 * calls VBoxMedium::details() on the found desriptor.
     1795 *
     1796 * If the requeststed hard disk is not found (for example, it's a new hard disk
     1797 * for a new VM created outside our UI), then media enumeration is requested and
     1798 * the search is repeated. We assume that the secont attempt always succeeds and
     1799 * assert otherwise.
     1800 *
     1801 * @note Technically, the second attempt may fail if, for example, the new hard
     1802 *       passed to this method disk gets removed before #startEnumeratingMedia()
     1803 *       succeeds. This (unexpected object uninitialization) is a generic
     1804 *       problem though and needs to be addressed using exceptions (see also the
     1805 *       @todo in VBoxMedium::details()).
     1806 */
     1807QString VBoxGlobal::details (const CHardDisk2 &aHD,
     1808                             bool aPredictDiff)
     1809{
     1810    CMedium cmedium (aHD);
     1811    VBoxMedium medium;
     1812
     1813    if (!findMedium (cmedium, medium))
    13241814    {
    13251815        /* media may be new and not alredy in the media list, request refresh */
    13261816        startEnumeratingMedia();
    1327         if (!findMedia (CUnknown (aHD), media))
    1328             AssertFailed();
    1329     }
    1330 
    1331     CHardDisk root = aHD.GetRoot();
    1332 
    1333     // @todo *** this check is rough; if aHD becomes uninitialized, any of aHD
    1334     // getters called afterwards will also fail. The same relates to the root
    1335     // object (that will be aHD itself in case of non-differencing
    1336     // disks). However, this check was added to fix a particular use case:
    1337     // when aHD is a differencing hard disk and it happens to be discarded
    1338     // (and uninitialized) after this method is called but before we read all
    1339     // its properties (yes, it's possible!), the root object will be null and
    1340     // calling methods on it will assert in the debug builds. This check seems
    1341     // to be enough as a quick solution (fresh hard disk attachments will be
    1342     // re-read by a state change signal after the discard operation is
    1343     // finished, so the user will eventually see correct data), but in order
    1344     // to solve the problem properly we need to use exceptions everywhere (or
    1345     // check the result after every method call). See also Comment #17 and
    1346     // below in Defect #2126.
    1347     if (!aHD.isOk())
    1348         return QString::null;
    1349 
    1350     QString details;
    1351 
    1352     KHardDiskType type = root.GetType();
    1353 
    1354     if (type == KHardDiskType_Normal &&
    1355         (aHD != root || (aPredict && root.GetChildren().GetCount() != 0)))
    1356             details = tr ("Differencing", "hard disk");
    1357     else
    1358         details = hardDiskTypeString (root);
    1359 
    1360     details += ", ";
    1361 
    1362     /// @todo prepend the details with the warning/error
    1363     //  icon when not accessible
    1364 
    1365     switch (media.status)
    1366     {
    1367         case VBoxMedia::Unknown:
    1368             details += tr ("<i>Checking...</i>", "hard disk");
    1369             break;
    1370         case VBoxMedia::Ok:
    1371             details += formatSize (root.GetSize() * _1M);
    1372             break;
    1373         case VBoxMedia::Error:
    1374         case VBoxMedia::Inaccessible:
    1375             details += tr ("<i>Inaccessible</i>", "hard disk");
    1376             break;
    1377     }
    1378 
    1379     return details;
     1817        if (!findMedium (cmedium, medium))
     1818            AssertFailedReturn (QString::null);
     1819    }
     1820
     1821    return medium.detailsHTML (true /* aNoDiffs */, aPredictDiff);
    13801822}
    13811823
     
    14281870
    14291871    /* add the state field if it's a host USB device */
    1430     CHostUSBDevice hostDev = CUnknown (aDevice);
     1872    CHostUSBDevice hostDev (aDevice);
    14311873    if (!hostDev.isNull())
    14321874    {
     
    14391881
    14401882/**
    1441  *  Puts soft hyphens after every path component in the given file name.
    1442  *  @param fn   file name (must be a full path name)
    1443  */
    1444 QString VBoxGlobal::prepareFileNameForHTML (const QString &fn) const
    1445 {
    1446 /// @todo (dmik) remove?
    1447 //    QString result = QDir::convertSeparators (fn);
    1448 //#ifdef Q_OS_LINUX
    1449 //    result.replace ('/', "/<font color=red>&shy;</font>");
    1450 //#else
    1451 //    result.replace ('\\', "\\<font color=red>&shy;</font>");
    1452 //#endif
    1453 //    return result;
    1454     QFileInfo fi (fn);
    1455     return fi.fileName();
    1456 }
    1457 
    1458 /**
    1459  *  Returns a details report on a given VM enclosed in a HTML table.
    1460  *
    1461  *  @param m            machine to create a report for
    1462  *  @param isNewVM      true when called by the New VM Wizard
    1463  *  @param withLinks    true if section titles should be hypertext links
    1464  */
    1465 QString VBoxGlobal::detailsReport (const CMachine &m, bool isNewVM,
    1466                                    bool withLinks, bool aDoRefresh)
     1883 * Returns a details report on a given VM represented as a HTML table.
     1884 *
     1885 * @param aMachine      Machine to create a report for.
     1886 * @param aIsNewVM      @c true when called by the New VM Wizard.
     1887 * @param aWithLinks    @c true if section titles should be hypertext links.
     1888 */
     1889QString VBoxGlobal::detailsReport (const CMachine &aMachine, bool aIsNewVM,
     1890                                   bool aWithLinks)
    14671891{
    14681892    static const char *sTableTpl =
     
    15331957    /* common generated content */
    15341958
    1535     const QString &sectionTpl = withLinks
     1959    const QString &sectionTpl = aWithLinks
    15361960        ? sSectionHrefTpl
    15371961        : sSectionBoldTpl;
     
    15411965        int rows = 2; /* including section header and footer */
    15421966
    1543         CHardDiskAttachmentEnumerator aen = m.GetHardDiskAttachments().Enumerate();
    1544         while (aen.HasMore())
    1545         {
    1546             CHardDiskAttachment hda = aen.GetNext();
    1547             CHardDisk hd = hda.GetHardDisk();
    1548             /// @todo for the explaination of the below isOk() checks, see
    1549             /// @todo *** in #details (const CHardDisk &, bool).
     1967        CHardDisk2AttachmentVector vec = aMachine.GetHardDisk2Attachments();
     1968        for (size_t i = 0; i < vec.size(); ++ i)
     1969        {
     1970            CHardDisk2Attachment hda = vec [i];
     1971            CHardDisk2 hd = hda.GetHardDisk();
     1972
     1973            /// @todo for the explaination of the below isOk() checks, see ***
     1974            /// in #details (const CHardDisk &, bool).
    15501975            if (hda.isOk())
    15511976            {
    1552                 CHardDisk root = hd.GetRoot();
    1553                 if (hd.isOk())
    1554                 {
    1555                     QString src = root.GetLocation();
    1556                     KStorageBus bus = hda.GetBus();
    1557                     LONG channel = hda.GetChannel();
    1558                     LONG device = hda.GetDevice();
    1559                     hardDisks += QString (sSectionItemTpl)
    1560                         .arg (toFullString (bus, channel, device))
    1561                         .arg (QString ("%1 [<nobr>%2</nobr>]")
    1562                               .arg (prepareFileNameForHTML (src))
    1563                               .arg (details (hd, isNewVM /* predict */, aDoRefresh)));
    1564                     ++ rows;
    1565                 }
     1977                KStorageBus bus = hda.GetBus();
     1978                LONG channel = hda.GetChannel();
     1979                LONG device = hda.GetDevice();
     1980                hardDisks += QString (sSectionItemTpl)
     1981                    .arg (toFullString (bus, channel, device))
     1982                    .arg (details (hd, aIsNewVM));
     1983                ++ rows;
    15661984            }
    15671985        }
     
    15842002    /* compose details report */
    15852003
    1586     const QString &generalBasicTpl = withLinks
     2004    const QString &generalBasicTpl = aWithLinks
    15872005        ? sGeneralBasicHrefTpl
    15882006        : sGeneralBasicBoldTpl;
    15892007
    1590     const QString &generalFullTpl = withLinks
     2008    const QString &generalFullTpl = aWithLinks
    15912009        ? sGeneralFullHrefTpl
    15922010        : sGeneralFullBoldTpl;
     
    15942012    QString detailsReport;
    15952013
    1596     if (isNewVM)
     2014    if (aIsNewVM)
    15972015    {
    15982016        detailsReport
    15992017            = generalBasicTpl
    1600                 .arg (m.GetName())
    1601                 .arg (vmGuestOSTypeDescription (m.GetOSTypeId()))
    1602                 .arg (m.GetMemorySize())
     2018                .arg (aMachine.GetName())
     2019                .arg (vmGuestOSTypeDescription (aMachine.GetOSTypeId()))
     2020                .arg (aMachine.GetMemorySize())
    16032021            + hardDisks;
    16042022    }
     
    16092027        for (ulong i = 1; i <= mVBox.GetSystemProperties().GetMaxBootPosition(); i++)
    16102028        {
    1611             KDeviceType device = m.GetBootOrder (i);
     2029            KDeviceType device = aMachine.GetBootOrder (i);
    16122030            if (device == KDeviceType_Null)
    16132031                continue;
     
    16192037            bootOrder = toString (KDeviceType_Null);
    16202038
    1621         CBIOSSettings biosSettings = m.GetBIOSSettings();
     2039        CBIOSSettings biosSettings = aMachine.GetBIOSSettings();
    16222040
    16232041        /* ACPI */
     
    16332051        /* VT-x/AMD-V */
    16342052        CSystemProperties props = vboxGlobal().virtualBox().GetSystemProperties();
    1635         QString virt = m.GetHWVirtExEnabled() == KTSBool_True ?
     2053        QString virt = aMachine.GetHWVirtExEnabled() == KTSBool_True ?
    16362054                       tr ("Enabled", "details report (VT-x/AMD-V)") :
    1637                        m.GetHWVirtExEnabled() == KTSBool_False ?
     2055                       aMachine.GetHWVirtExEnabled() == KTSBool_False ?
    16382056                       tr ("Disabled", "details report (VT-x/AMD-V)") :
    16392057                       props.GetHWVirtExEnabled() ?
     
    16422060
    16432061        /* PAE/NX */
    1644         QString pae = m.GetPAEEnabled()
     2062        QString pae = aMachine.GetPAEEnabled()
    16452063            ? tr ("Enabled", "details report (PAE/NX)")
    16462064            : tr ("Disabled", "details report (PAE/NX)");
     
    16492067        detailsReport
    16502068            = generalFullTpl
    1651                 .arg (m.GetName())
    1652                 .arg (vmGuestOSTypeDescription (m.GetOSTypeId()))
    1653                 .arg (m.GetMemorySize())
    1654                 .arg (m.GetVRAMSize())
     2069                .arg (aMachine.GetName())
     2070                .arg (vmGuestOSTypeDescription (aMachine.GetOSTypeId()))
     2071                .arg (aMachine.GetMemorySize())
     2072                .arg (aMachine.GetVRAMSize())
    16552073                .arg (bootOrder)
    16562074                .arg (acpi)
     
    16632081
    16642082        /* DVD */
    1665         CDVDDrive dvd = m.GetDVDDrive();
     2083        CDVDDrive dvd = aMachine.GetDVDDrive();
    16662084        item = QString (sSectionItemTpl);
    16672085        switch (dvd.GetState())
     
    16722090            case KDriveState_ImageMounted:
    16732091            {
    1674                 CDVDImage img = dvd.GetImage();
     2092                CDVDImage2 img = dvd.GetImage();
    16752093                item = item.arg (tr ("Image", "details report (DVD)"),
    1676                                  prepareFileNameForHTML (img.GetFilePath()));
     2094                                 locationForHTML (img.GetName()));
    16772095                break;
    16782096            }
     
    17002118
    17012119        /* Floppy */
    1702         CFloppyDrive floppy = m.GetFloppyDrive();
     2120        CFloppyDrive floppy = aMachine.GetFloppyDrive();
    17032121        item = QString (sSectionItemTpl);
    17042122        switch (floppy.GetState())
     
    17092127            case KDriveState_ImageMounted:
    17102128            {
    1711                 CFloppyImage img = floppy.GetImage();
     2129                CFloppyImage2 img = floppy.GetImage();
    17122130                item = item.arg (tr ("Image", "details report (floppy)"),
    1713                                  prepareFileNameForHTML (img.GetFilePath()));
     2131                                 locationForHTML (img.GetName()));
    17142132                break;
    17152133            }
     
    17382156        /* audio */
    17392157        {
    1740             CAudioAdapter audio = m.GetAudioAdapter();
     2158            CAudioAdapter audio = aMachine.GetAudioAdapter();
    17412159            int rows = audio.GetEnabled() ? 3 : 2;
    17422160            if (audio.GetEnabled())
     
    17652183            for (ulong slot = 0; slot < count; slot ++)
    17662184            {
    1767                 CNetworkAdapter adapter = m.GetNetworkAdapter (slot);
     2185                CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot);
    17682186                if (adapter.GetEnabled())
    17692187                {
     
    18112229            for (ulong slot = 0; slot < count; slot ++)
    18122230            {
    1813                 CSerialPort port = m.GetSerialPort (slot);
     2231                CSerialPort port = aMachine.GetSerialPort (slot);
    18142232                if (port.GetEnabled())
    18152233                {
     
    18532271            for (ulong slot = 0; slot < count; slot ++)
    18542272            {
    1855                 CParallelPort port = m.GetParallelPort (slot);
     2273                CParallelPort port = aMachine.GetParallelPort (slot);
    18562274                if (port.GetEnabled())
    18572275                {
     
    18852303        /* USB */
    18862304        {
    1887             CUSBController ctl = m.GetUSBController();
     2305            CUSBController ctl = aMachine.GetUSBController();
    18882306            if (!ctl.isNull())
    18892307            {
     
    19182336        /* Shared folders */
    19192337        {
    1920             ulong count = m.GetSharedFolders().GetCount();
     2338            ulong count = aMachine.GetSharedFolders().GetCount();
    19212339            if (count > 0)
    19222340            {
     
    19392357        /* VRDP */
    19402358        {
    1941             CVRDPServer srv = m.GetVRDPServer();
     2359            CVRDPServer srv = aMachine.GetVRDPServer();
    19422360            if (!srv.isNull())
    19432361            {
     
    21462564
    21472565/**
    2148  *  Appends the disk object and all its children to the media list.
     2566 * Appends the given list of hard disks and all their children to the media
     2567 * list. To be called only from VBoxGlobal::startEnumeratingMedia().
    21492568 */
    21502569static
    2151 void addMediaToList (VBoxMediaList &aList,
    2152                      const CUnknown &aDisk,
    2153                      VBoxDefs::DiskType aType)
    2154 {
    2155     VBoxMedia media (aDisk, aType, VBoxMedia::Unknown);
    2156     aList += media;
    2157     /* append all vdi children */
    2158     if (aType == VBoxDefs::HD)
    2159     {
    2160         CHardDisk hd = aDisk;
    2161         CHardDiskEnumerator enumerator = hd.GetChildren().Enumerate();
    2162         while (enumerator.HasMore())
    2163         {
    2164             CHardDisk subHd = enumerator.GetNext();
    2165             addMediaToList (aList, CUnknown (subHd), VBoxDefs::HD);
    2166         }
    2167     }
    2168 }
    2169 
    2170 /**
    2171  *  Starts a thread that asynchronously enumerates all currently registered
    2172  *  media, checks for its accessibility and posts VBoxEnumerateMediaEvent
    2173  *  events to the VBoxGlobal object until all media is enumerated.
    2174  *
    2175  *  If the enumeration is already in progress, no new thread is started.
    2176  *
    2177  *  @sa #currentMediaList()
    2178  *  @sa #isMediaEnumerationStarted()
     2570void AddHardDisksToList (VBoxMediaList &aList,
     2571                         VBoxMediaList::iterator aWhere,
     2572                         const CHardDisk2Vector &aVector,
     2573                         VBoxMedium *aParent = NULL)
     2574{
     2575    VBoxMediaList::iterator first = aWhere;
     2576
     2577    /* first pass: add siblings sorted */
     2578    for (CHardDisk2Vector::ConstIterator it = aVector.begin();
     2579         it != aVector.end(); ++ it)
     2580    {
     2581        VBoxMedium medium (CMedium (*it), VBoxDefs::MediaType_HardDisk,
     2582                           aParent);
     2583
     2584        /* search for a proper alphabetic position */
     2585        VBoxMediaList::iterator jt = first;
     2586        for (; jt != aWhere; ++ jt)
     2587            if ((*jt).name().localeAwareCompare (medium.name()) > 0)
     2588                break;
     2589
     2590        aList.insert (jt, medium);
     2591
     2592        /* adjust the first item if inserted before it */
     2593        if (jt == first)
     2594            -- first;
     2595    }
     2596
     2597    /* second pass: add children */
     2598    for (VBoxMediaList::iterator it = first; it != aWhere;)
     2599    {
     2600        CHardDisk2Vector children = (*it).hardDisk().GetChildren();
     2601        VBoxMedium *parent = &(*it);
     2602
     2603        ++ it; /* go to the next sibling before inserting children */
     2604        AddHardDisksToList (aList, it, children, parent);
     2605    }
     2606}
     2607
     2608/**
     2609 * Starts a thread that asynchronously enumerates all currently registered
     2610 * media.
     2611 *
     2612 * Before the enumeration is started, the current media list (a list returned by
     2613 * #currentMediaList()) is populated with all registered media and the
     2614 * #mediaEnumStarted() signal is emitted. The enumeration thread then walks this
     2615 * list, checks for media acessiblity and emits #mediumEnumerated() signals of
     2616 * each checked medium. When all media are checked, the enumeration thread is
     2617 * stopped and the #mediaEnumFinished() signal is emitted.
     2618 *
     2619 * If the enumeration is already in progress, no new thread is started.
     2620 *
     2621 * The media list returned by #currentMediaList() is always sorted
     2622 * alphabetically by the location attribute and comes in the following order:
     2623 * <ol>
     2624 *  <li>All hard disks. If a hard disk has children, these children
     2625 *      (alphabetically sorted) immediately follow their parent and terefore
     2626 *      appear before its next sibling hard disk.</li>
     2627 *  <li>All CD/DVD images.</li>
     2628 *  <li>All Floppy images.</li>
     2629 * </ol>
     2630 *
     2631 * Note that #mediumEnumerated() signals are emitted in the same order as
     2632 * described above.
     2633 *
     2634 * @sa #currentMediaList()
     2635 * @sa #isMediaEnumerationStarted()
    21792636 */
    21802637void VBoxGlobal::startEnumeratingMedia()
    21812638{
    2182     Assert (mValid);
     2639    AssertReturnVoid (mValid);
    21832640
    21842641    /* check if already started but not yet finished */
    2185     if (media_enum_thread)
     2642    if (mMediaEnumThread != NULL)
    21862643        return;
    21872644
     
    21912648
    21922649    /* composes a list of all currently known media & their children */
    2193     media_list.clear();
    2194     {
    2195         CHardDiskEnumerator enHD = mVBox.GetHardDisks().Enumerate();
    2196         while (enHD.HasMore())
    2197             addMediaToList (media_list, CUnknown (enHD.GetNext()), VBoxDefs::HD);
    2198 
    2199         CDVDImageEnumerator enCD = mVBox.GetDVDImages().Enumerate();
    2200         while (enCD.HasMore())
    2201             addMediaToList (media_list, CUnknown (enCD.GetNext()), VBoxDefs::CD);
    2202 
    2203         CFloppyImageEnumerator enFD = mVBox.GetFloppyImages().Enumerate();
    2204         while (enFD.HasMore())
    2205             addMediaToList (media_list, CUnknown (enFD.GetNext()), VBoxDefs::FD);
     2650    mMediaList.clear();
     2651    {
     2652        CHardDisk2Vector vec = mVBox.GetHardDisks2();
     2653        AddHardDisksToList (mMediaList, mMediaList.end(), vec);
     2654    }
     2655    {
     2656        VBoxMediaList::iterator first = mMediaList.end();
     2657
     2658        CDVDImage2Vector vec = mVBox.GetDVDImages();
     2659        for (CDVDImage2Vector::ConstIterator it = vec.begin();
     2660             it != vec.end(); ++ it)
     2661        {
     2662            VBoxMedium medium (CMedium (*it), VBoxDefs::MediaType_DVD);
     2663
     2664            /* search for a proper alphabetic position */
     2665            VBoxMediaList::iterator jt = first;
     2666            for (; jt != mMediaList.end(); ++ jt)
     2667                if ((*jt).name().localeAwareCompare (medium.name()) > 0)
     2668                    break;
     2669
     2670            mMediaList.insert (jt, medium);
     2671
     2672            /* adjust the first item if inserted before it */
     2673            if (jt == first)
     2674                -- first;
     2675        }
     2676    }
     2677    {
     2678        VBoxMediaList::iterator first = mMediaList.end();
     2679
     2680        CFloppyImage2Vector vec = mVBox.GetFloppyImages();
     2681        for (CFloppyImage2Vector::ConstIterator it = vec.begin();
     2682             it != vec.end(); ++ it)
     2683        {
     2684            VBoxMedium medium (CMedium (*it), VBoxDefs::MediaType_Floppy);
     2685
     2686            /* search for a proper alphabetic position */
     2687            VBoxMediaList::iterator jt = first;
     2688            for (; jt != mMediaList.end(); ++ jt)
     2689                if ((*jt).name().localeAwareCompare (medium.name()) > 0)
     2690                    break;
     2691
     2692            mMediaList.insert (jt, medium);
     2693
     2694            /* adjust the first item if inserted before it */
     2695            if (jt == first)
     2696                -- first;
     2697        }
    22062698    }
    22072699
    22082700    /* enumeration thread class */
    2209     class Thread : public QThread
     2701    class MediaEnumThread : public QThread
    22102702    {
    22112703    public:
    22122704
    2213         Thread (const VBoxMediaList &aList) : mList (aList) {}
     2705        MediaEnumThread (const VBoxMediaList &aList) : mList (aList) {}
    22142706
    22152707        virtual void run()
     
    22192711
    22202712            CVirtualBox mVBox = vboxGlobal().virtualBox();
    2221             QObject *target = &vboxGlobal();
    2222 
    2223             /* enumerating list */
     2713            QObject *self = &vboxGlobal();
     2714
     2715            /* enumerate the list */
    22242716            int index = 0;
    22252717            VBoxMediaList::const_iterator it;
     
    22282720                 ++ it, ++ index)
    22292721            {
    2230                 VBoxMedia media = *it;
    2231                 switch (media.type)
    2232                 {
    2233                     case VBoxDefs::HD:
    2234                     {
    2235                         CHardDisk hd = media.disk;
    2236                         media.status =
    2237                             hd.GetAccessible() == TRUE ? VBoxMedia::Ok :
    2238                             hd.isOk() ? VBoxMedia::Inaccessible :
    2239                             VBoxMedia::Error;
    2240                         /* assign back to store error info if any */
    2241                         media.disk = hd;
    2242                         if (media.status == VBoxMedia::Inaccessible)
    2243                         {
    2244                             QUuid machineId = hd.GetMachineId();
    2245                             if (!machineId.isNull())
    2246                             {
    2247                                 CMachine machine = mVBox.GetMachine (machineId);
    2248                                 if (!machine.isNull() && (machine.GetState() >= KMachineState_Running))
    2249                                     media.status = VBoxMedia::Ok;
    2250                             }
    2251                         }
    2252                         QApplication::postEvent (target,
    2253                             new VBoxEnumerateMediaEvent (media, index));
    2254                         break;
    2255                     }
    2256                     case VBoxDefs::CD:
    2257                     {
    2258                         CDVDImage cd = media.disk;
    2259                         media.status =
    2260                             cd.GetAccessible() == TRUE ? VBoxMedia::Ok :
    2261                             cd.isOk() ? VBoxMedia::Inaccessible :
    2262                             VBoxMedia::Error;
    2263                         /* assign back to store error info if any */
    2264                         media.disk = cd;
    2265                         QApplication::postEvent (target,
    2266                             new VBoxEnumerateMediaEvent (media, index));
    2267                         break;
    2268                     }
    2269                     case VBoxDefs::FD:
    2270                     {
    2271                         CFloppyImage fd = media.disk;
    2272                         media.status =
    2273                             fd.GetAccessible() == TRUE ? VBoxMedia::Ok :
    2274                             fd.isOk() ? VBoxMedia::Inaccessible :
    2275                             VBoxMedia::Error;
    2276                         /* assign back to store error info if any */
    2277                         media.disk = fd;
    2278                         QApplication::postEvent (target,
    2279                             new VBoxEnumerateMediaEvent (media, index));
    2280                         break;
    2281                     }
    2282                     default:
    2283                     {
    2284                         AssertMsgFailed (("Invalid aMedia type\n"));
    2285                         break;
    2286                     }
    2287                 }
     2722                VBoxMedium medium = *it;
     2723                medium.blockAndQueryState();
     2724                QApplication::postEvent (self,
     2725                    new VBoxMediaEnumEvent (medium, index));
    22882726            }
    22892727
    2290             /* post the last message to indicate the end of enumeration */
     2728            /* post the end-of-enumeration event */
    22912729            if (!sVBoxGlobalInCleanup)
    2292                 QApplication::postEvent (target, new VBoxEnumerateMediaEvent());
     2730                QApplication::postEvent (self, new VBoxMediaEnumEvent());
    22932731
    22942732            COMBase::CleanupCOM();
     
    23012739    };
    23022740
    2303     media_enum_thread = new Thread (media_list);
    2304     AssertReturnVoid (media_enum_thread);
    2305 
    2306     /* emit mediaEnumStarted() after we set media_enum_thread to != NULL
     2741    mMediaEnumThread = new MediaEnumThread (mMediaList);
     2742    AssertReturnVoid (mMediaEnumThread);
     2743
     2744    /* emit mediaEnumStarted() after we set mMediaEnumThread to != NULL
    23072745     * to cause isMediaEnumerationStarted() to return TRUE from slots */
    23082746    emit mediaEnumStarted();
    23092747
    2310     media_enum_thread->start();
    2311 }
    2312 
    2313 /**
    2314  *  Adds a new media to the current media list.
    2315  *  @note Currently, this method does nothing but emits the mediaAdded() signal.
    2316  *        Later, it will be used to synchronize the current media list with
    2317  *        the actial media list on the server after a single media opetartion
    2318  *        performed from within one of our UIs.
    2319  *  @sa #currentMediaList()
    2320  */
    2321 void VBoxGlobal::addMedia (const VBoxMedia &aMedia)
    2322 {
    2323     emit mediaAdded (aMedia);
    2324 }
    2325 
    2326 /**
    2327  *  Updates the media in the current media list.
    2328  *  @note Currently, this method does nothing but emits the mediaUpdated() signal.
    2329  *        Later, it will be used to synchronize the current media list with
    2330  *        the actial media list on the server after a single media opetartion
    2331  *        performed from within one of our UIs.
    2332  *  @sa #currentMediaList()
    2333  */
    2334 void VBoxGlobal::updateMedia (const VBoxMedia &aMedia)
    2335 {
    2336     emit mediaUpdated (aMedia);
    2337 }
    2338 
    2339 /**
    2340  *  Removes the media from the current media list.
    2341  *  @note Currently, this method does nothing but emits the mediaRemoved() signal.
    2342  *        Later, it will be used to synchronize the current media list with
    2343  *        the actial media list on the server after a single media opetartion
    2344  *        performed from within one of our UIs.
    2345  *  @sa #currentMediaList()
    2346  */
    2347 void VBoxGlobal::removeMedia (VBoxDefs::DiskType aType, const QUuid &aId)
    2348 {
    2349     emit mediaRemoved (aType, aId);
    2350 }
    2351 
    2352 /**
    2353  *  Searches for a VBoxMedia object representing the given COM media object.
     2748    mMediaEnumThread->start();
     2749}
     2750
     2751/**
     2752 * Adds a new medium to the current media list and emits the #mediumAdded()
     2753 * signal.
     2754 *
     2755 * @sa #currentMediaList()
     2756 */
     2757void VBoxGlobal::addMedium (const VBoxMedium &aMedium)
     2758{
     2759    /* Note that we maitain the same order here as #startEnumeratingMedia() */
     2760
     2761    VBoxMediaList::iterator it = mMediaList.begin();
     2762
     2763    if (aMedium.type() == VBoxDefs::MediaType_HardDisk)
     2764    {
     2765        VBoxMediaList::iterator parent = mMediaList.end();
     2766
     2767        for (; it != mMediaList.end(); ++ it)
     2768        {
     2769            if ((*it).type() != VBoxDefs::MediaType_HardDisk)
     2770                break;
     2771
     2772            if (aMedium.parent() != NULL && parent == mMediaList.end())
     2773            {
     2774                if (&*it == aMedium.parent())
     2775                    parent = it;
     2776            }
     2777            else
     2778            {
     2779                /* break if met a parent's sibling (will insert before it) */
     2780                if (aMedium.parent() != NULL &&
     2781                    (*it).parent() == (*parent).parent())
     2782                    break;
     2783
     2784                /* compare to aMedium's siblings */
     2785                if ((*it).parent() == aMedium.parent() &&
     2786                    (*it).name().localeAwareCompare (aMedium.name()) > 0)
     2787                    break;
     2788            }
     2789        }
     2790
     2791        AssertReturnVoid (aMedium.parent() == NULL || parent != mMediaList.end());
     2792    }
     2793    else
     2794    {
     2795        for (; it != mMediaList.end(); ++ it)
     2796        {
     2797            /* skip HardDisks that come first */
     2798            if ((*it).type() == VBoxDefs::MediaType_HardDisk)
     2799                continue;
     2800
     2801            /* skip DVD when inserting Floppy */
     2802            if (aMedium.type() == VBoxDefs::MediaType_Floppy &&
     2803                (*it).type() == VBoxDefs::MediaType_DVD)
     2804                continue;
     2805
     2806            if ((*it).name().localeAwareCompare (aMedium.name()) > 0 ||
     2807                (aMedium.type() == VBoxDefs::MediaType_DVD &&
     2808                 (*it).type() == VBoxDefs::MediaType_Floppy))
     2809                break;
     2810        }
     2811    }
     2812
     2813    it = mMediaList.insert (it, aMedium);
     2814
     2815    emit mediumAdded (*it);
     2816}
     2817
     2818/**
     2819 * Updates the medium in the current media list and emits the #mediumUpdated()
     2820 * signal.
     2821 *
     2822 * @sa #currentMediaList()
     2823 */
     2824void VBoxGlobal::updateMedium (const VBoxMedium &aMedium)
     2825{
     2826    VBoxMediaList::Iterator it;
     2827    for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
     2828        if ((*it).id() == aMedium.id())
     2829            break;
     2830
     2831    AssertReturnVoid (it != mMediaList.end());
     2832
     2833    if (&*it != &aMedium)
     2834        *it = aMedium;
     2835
     2836    emit mediumUpdated (*it);
     2837}
     2838
     2839/**
     2840 * Removes the medium from the current media list and emits the #mediumRemoved()
     2841 * signal.
     2842 *
     2843 * @sa #currentMediaList()
     2844 */
     2845void VBoxGlobal::removeMedium (VBoxDefs::MediaType aType, const QUuid &aId)
     2846{
     2847    VBoxMediaList::Iterator it;
     2848    for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
     2849        if ((*it).id() == aId)
     2850            break;
     2851
     2852    AssertReturnVoid (it != mMediaList.end());
     2853
     2854#if DEBUG
     2855    /* sanity: must be no children */
     2856    {
     2857        VBoxMediaList::Iterator jt = it;
     2858        ++ jt;
     2859        AssertReturnVoid (jt == mMediaList.end() || (*jt).parent() != &*it);
     2860    }
     2861#endif
     2862
     2863    VBoxMedium *parent = (*it).parent();
     2864
     2865    /* remove the medium from the list to keep it in sync with the server "for
     2866     * free" when the medium is deleted from one of our UIs */
     2867    mMediaList.erase (it);
     2868
     2869    emit mediumRemoved (aType, aId);
     2870
     2871    /* also emit the parent update signal because some attributes like
     2872     * isReadOnly() may have been changed after child removal */
     2873    if (parent != NULL)
     2874    {
     2875        parent->refresh();
     2876        emit mediumUpdated (*parent);
     2877    }
     2878}
     2879
     2880/**
     2881 *  Searches for a VBoxMedum object representing the given COM medium object.
    23542882 *
    23552883 *  @return true if found and false otherwise.
    23562884 */
    2357 bool VBoxGlobal::findMedia (const CUnknown &aObj, VBoxMedia &aMedia) const
    2358 {
    2359     for (VBoxMediaList::ConstIterator it = media_list.begin();
    2360          it != media_list.end(); ++ it)
    2361     {
    2362         if ((*it).disk == aObj)
    2363         {
    2364             aMedia = (*it);
     2885bool VBoxGlobal::findMedium (const CMedium &aObj, VBoxMedium &aMedium) const
     2886{
     2887    for (VBoxMediaList::ConstIterator it = mMediaList.begin();
     2888         it != mMediaList.end(); ++ it)
     2889    {
     2890        if ((*it).medium() == aObj)
     2891        {
     2892            aMedium = (*it);
    23652893            return true;
    23662894        }
     
    24472975    machineStates [KMachineState_Restoring] =   tr ("Restoring", "MachineState");
    24482976    machineStates [KMachineState_Discarding] =  tr ("Discarding", "MachineState");
     2977    machineStates [KMachineState_SettingUp] =   tr ("Setting Up", "MachineState");
    24492978
    24502979    sessionStates [KSessionState_Closed] =      tr ("Closed", "SessionState");
     
    24843013    diskTypes [KHardDiskType_Writethrough] =
    24853014        tr ("Writethrough", "DiskType");
    2486 
    2487     diskStorageTypes [KHardDiskStorageType_VirtualDiskImage] =
    2488         tr ("Virtual Disk Image", "DiskStorageType");
    2489     diskStorageTypes [KHardDiskStorageType_ISCSIHardDisk] =
    2490         tr ("iSCSI", "DiskStorageType");
    2491     diskStorageTypes [KHardDiskStorageType_VMDKImage] =
    2492         tr ("VMDK Image", "DiskStorageType");
    2493     diskStorageTypes [KHardDiskStorageType_CustomHardDisk] =
    2494         tr ("Custom Hard Disk", "DiskStorageType");
    2495     diskStorageTypes [KHardDiskStorageType_VHDImage] =
    2496         tr ("VHD Image", "DiskStorageType");
     3015    diskTypes_Differencing =
     3016        tr ("Differencing", "DiskType");
    24973017
    24983018    vrdpAuthTypes [KVRDPAuthType_Null] =
     
    25833103
    25843104    mUserDefinedPortName = tr ("User-defined", "serial port");
     3105
     3106    {
     3107        QImage img =
     3108            QMessageBox::standardIcon (QMessageBox::Warning).convertToImage();
     3109        img = img.smoothScale (16, 16);
     3110        mWarningIcon.convertFromImage (img);
     3111        Assert (!mWarningIcon.isNull());
     3112
     3113        img =
     3114            QMessageBox::standardIcon (QMessageBox::Critical).convertToImage();
     3115        img = img.smoothScale (16, 16);
     3116        mErrorIcon.convertFromImage (img);
     3117        Assert (!mErrorIcon.isNull());
     3118    }
    25853119
    25863120    detailReportTemplatesReady = false;
     
    32203754
    32213755/**
     3756 * Puts soft hyphens after every path component in the given file name.
     3757 *
     3758 * @param aFileName File name (must be a full path name).
     3759 */
     3760/* static */
     3761QString VBoxGlobal::locationForHTML (const QString &aFileName)
     3762{
     3763/// @todo (dmik) remove?
     3764//    QString result = QDir::convertSeparators (fn);
     3765//#ifdef Q_OS_LINUX
     3766//    result.replace ('/', "/<font color=red>&shy;</font>");
     3767//#else
     3768//    result.replace ('\\', "\\<font color=red>&shy;</font>");
     3769//#endif
     3770//    return result;
     3771    QFileInfo fi (aFileName);
     3772    return fi.fileName();
     3773}
     3774
     3775/**
    32223776 *  Reformats the input string @a aStr so that:
    32233777 *  - strings in single quotes will be put inside <nobr> and marked
     
    37694323
    37704324/**
     4325 * Joins two pixmaps horizontally with 2px space between them and returns the
     4326 * result.
     4327 *
     4328 * @param aPM1 Left pixmap.
     4329 * @param aPM2 Right pixmap.
     4330 */
     4331/* static */
     4332QPixmap VBoxGlobal::joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2)
     4333{
     4334    if (aPM1.isNull())
     4335        return aPM2;
     4336    if (aPM2.isNull())
     4337        return aPM1;
     4338
     4339    QPixmap res;
     4340
     4341    {
     4342        QImage img (aPM1.width() + aPM2.width() + 2,
     4343                    QMAX (aPM1.height(), aPM2.height()), 32);
     4344        img.setAlphaBuffer (true);
     4345        img.fill (0);
     4346        res.convertFromImage (img);
     4347    }
     4348
     4349    copyBlt (&res, 0, 0, &aPM1);
     4350    copyBlt (&res, aPM1.width() + 2, res.height() - aPM2.height(), &aPM2);
     4351
     4352    return res;
     4353}
     4354
     4355/**
    37714356 *  Searches for a widget that with @a aName (if it is not NULL) which inherits
    37724357 *  @a aClassName (if it is not NULL) and among children of @a aParent. If @a
     
    39754560        }
    39764561
    3977         case VBoxDefs::EnumerateMediaEventType:
    3978         {
    3979             VBoxEnumerateMediaEvent *ev = (VBoxEnumerateMediaEvent *) e;
     4562        case VBoxDefs::MediaEnumEventType:
     4563        {
     4564            VBoxMediaEnumEvent *ev = (VBoxMediaEnumEvent *) e;
    39804565
    39814566            if (!ev->mLast)
    39824567            {
    3983                 if (ev->mMedia.status == VBoxMedia::Error)
    3984                     vboxProblem().cannotGetMediaAccessibility (ev->mMedia.disk);
    3985                 media_list [ev->mIndex] = ev->mMedia;
    3986                 emit mediaEnumerated (media_list [ev->mIndex], ev->mIndex);
     4568                if (ev->mMedium.state() == KMediaState_Inaccessible &&
     4569                    !ev->mMedium.result().isOk())
     4570                    vboxProblem().cannotGetMediaAccessibility (ev->mMedium);
     4571                mMediaList [ev->mIndex] = ev->mMedium;
     4572                emit mediumEnumerated (mMediaList [ev->mIndex], ev->mIndex);
    39874573            }
    39884574            else
    39894575            {
    39904576                /* the thread has posted the last message, wait for termination */
    3991                 media_enum_thread->wait();
    3992                 delete media_enum_thread;
    3993                 media_enum_thread = 0;
    3994 
    3995                 emit mediaEnumFinished (media_list);
     4577                mMediaEnumThread->wait();
     4578                delete mMediaEnumThread;
     4579                mMediaEnumThread = 0;
     4580
     4581                emit mediaEnumFinished (mMediaList);
    39964582            }
    39974583
     
    41674753        {KMachineState_Restoring, "state_restoring_16px.png"},
    41684754        {KMachineState_Discarding, "state_discarding_16px.png"},
     4755        {KMachineState_SettingUp, "settings_16px.png"},
    41694756    };
    41704757    mStateIcons.setAutoDelete (true); // takes ownership of elements
     
    41934780    vm_state_color.insert (KMachineState_Restoring,      &Qt::green);
    41944781    vm_state_color.insert (KMachineState_Discarding,     &Qt::green);
     4782    vm_state_color.insert (KMachineState_SettingUp,      &Qt::green);
    41954783
    41964784    /* Redefine default large and small icon sizes. In particular, it is
     
    43244912    }
    43254913
    4326     if (media_enum_thread)
     4914    if (mMediaEnumThread)
    43274915    {
    43284916        /* sVBoxGlobalInCleanup is true here, so just wait for the thread */
    4329         media_enum_thread->wait();
    4330         delete media_enum_thread;
    4331         media_enum_thread = 0;
     4917        mMediaEnumThread->wait();
     4918        delete mMediaEnumThread;
     4919        mMediaEnumThread = NULL;
    43324920    }
    43334921
     
    43454933    vm_os_types.clear();
    43464934    /* media list contains a lot of CUUnknown, release them */
    4347     media_list.clear();
     4935    mMediaList.clear();
    43484936    /* the last step to ensure we don't use COM any more */
    43494937    mVBox.detach();
    43504938
    4351     /* There may be VBoxEnumerateMediaEvent instances still in the message
     4939    /* There may be VBoxMediaEnumEvent instances still in the message
    43524940     * queue which reference COM objects. Remove them to release those objects
    43534941     * before uninitializing the COM subsystem. */
     
    44114999        while (en.HasMore())
    44125000        {
    4413             CHostUSBDevice iterator = en.GetNext();
    4414             CUSBDevice usb = CUnknown (iterator);
     5001            CHostUSBDevice dev = en.GetNext();
     5002            CUSBDevice usb (dev);
    44155003            int id = insertItem (vboxGlobal().details (usb));
    44165004            mUSBDevicesMap [id] = usb;
     
    44215009                    mConsole.GetUSBDevices().FindById (usb.GetId());
    44225010                setItemChecked (id, !attachedUSB.isNull());
    4423                 setItemEnabled (id, iterator.GetState() !=
     5011                setItemEnabled (id, dev.GetState() !=
    44245012                                KUSBDeviceState_Unavailable);
    44255013            }
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaComboBox.cpp

    r9487 r13580  
    2222
    2323#include "VBoxMediaComboBox.h"
    24 #include "VBoxDiskImageManagerDlg.h"
     24#include "VBoxMediaManagerDlg.h"
    2525
    2626#include <qfileinfo.h>
     
    3131#include <qlistbox.h>
    3232
    33 VBoxMediaComboBox::VBoxMediaComboBox (QWidget *aParent, const char *aName,
    34                                       int aType, bool aUseEmptyItem)
    35     : QComboBox (aParent , aName),
    36     mType (aType), mRequiredId (QUuid()), mUseEmptyItem (aUseEmptyItem)
     33VBoxMediaComboBox::
     34VBoxMediaComboBox (QWidget *aParent, const char *aName,
     35                   VBoxDefs::MediaType aType, QUuid aMachineId /*= QUuid()*/)
     36    : QComboBox (aParent , aName)
     37    , mType (aType), mLastId (QUuid())
     38    , mShowDiffs (false)
     39    , mMachineId (aMachineId)
    3740{
    3841    setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
     42
    3943    /* setup enumeration handlers */
    4044    connect (&vboxGlobal(), SIGNAL (mediaEnumStarted()),
    4145             this, SLOT (mediaEnumStarted()));
    42     connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMedia &, int)),
    43              this, SLOT (mediaEnumerated (const VBoxMedia &, int)));
     46    connect (&vboxGlobal(), SIGNAL (mediumEnumerated (const VBoxMedium &, int)),
     47             this, SLOT (mediumEnumerated (const VBoxMedium &, int)));
    4448
    4549    /* setup update handlers */
    46     connect (&vboxGlobal(), SIGNAL (mediaAdded (const VBoxMedia &)),
    47              this, SLOT (mediaAdded (const VBoxMedia &)));
    48     connect (&vboxGlobal(), SIGNAL (mediaUpdated (const VBoxMedia &)),
    49              this, SLOT (mediaUpdated (const VBoxMedia &)));
    50     connect (&vboxGlobal(), SIGNAL (mediaRemoved (VBoxDefs::DiskType, const QUuid &)),
    51              this, SLOT (mediaRemoved (VBoxDefs::DiskType, const QUuid &)));
     50    connect (&vboxGlobal(), SIGNAL (mediumAdded (const VBoxMedium &)),
     51             this, SLOT (mediumAdded (const VBoxMedium &)));
     52    connect (&vboxGlobal(), SIGNAL (mediumUpdated (const VBoxMedium &)),
     53             this, SLOT (mediumUpdated (const VBoxMedium &)));
     54    connect (&vboxGlobal(), SIGNAL (mediumRemoved (VBoxDefs::MediaType, const QUuid &)),
     55             this, SLOT (mediumRemoved (VBoxDefs::MediaType, const QUuid &)));
    5256
    5357    connect (this, SIGNAL (activated (int)),
    5458             this, SLOT (processActivated (int)));
    5559
    56     /* in some qt themes embedded list-box is not used by default, so create it */
     60    /* in some qt themes the list-box is not used by default, so create it */
    5761    if (!listBox())
    5862        setListBox (new QListBox (this));
    59     if (listBox())
    60         connect (listBox(), SIGNAL (onItem (QListBoxItem*)),
    61                  this, SLOT (processOnItem (QListBoxItem*)));
    62 
    63     /* cache pixmaps as class members */
    64     QImage img;
    65     img = QMessageBox::standardIcon (QMessageBox::Warning).convertToImage();
    66     if (!img.isNull())
    67     {
    68         img = img.smoothScale (14, 14);
    69         mPmInacc.convertFromImage (img);
    70     }
    71     img = QMessageBox::standardIcon (QMessageBox::Critical).convertToImage();
    72     if (!img.isNull())
    73     {
    74         img = img.smoothScale (14, 14);
    75         mPmError.convertFromImage (img);
    76     }
    77 }
    78 
     63
     64    AssertReturnVoid (listBox());
     65
     66    connect (listBox(), SIGNAL (onItem (QListBoxItem*)),
     67             this, SLOT (processOnItem (QListBoxItem*)));
     68}
     69
     70/**
     71 * Fills this combobox with the current media list.
     72 */
    7973void VBoxMediaComboBox::refresh()
    8074{
    81     /* clearing lists */
    82     clear(), mUuidList.clear(), mTipList.clear();
    83     /* prepend empty item if used */
    84     if (mUseEmptyItem)
    85         appendItem (tr ("<no hard disk>"), QUuid(), tr ("No hard disk"), 0);
    86     /* load current media list */
     75    /* clear lists */
     76    clear(), mMedia.clear();
     77
     78    /* load the current media list */
    8779    VBoxMediaList list = vboxGlobal().currentMediaList();
    8880    VBoxMediaList::const_iterator it;
    8981    for (it = list.begin(); it != list.end(); ++ it)
    90         mediaEnumerated (*it, 0);
    91     /* activate item selected during current list loading */
    92     processActivated (currentItem());
    93 }
    94 
     82        mediumAdded (*it);
     83
     84    if (count() == 0)
     85    {
     86        /* no media of the desired type, add the "no media" pseudo-item */
     87        addNoMediaItem();
     88    }
     89
     90    /* inform the interested parties about the possibly changed active item's
     91     * icon, text, tooltip etc. */
     92    emit activated (currentItem());
     93}
     94
     95/**
     96 * Requests the global media list enumeration and repopulates the list with its
     97 * results.
     98 */
     99void VBoxMediaComboBox::repopulate()
     100{
     101    if (!vboxGlobal().isMediaEnumerationStarted())
     102        vboxGlobal().startEnumeratingMedia();
     103    else
     104        refresh();
     105}
     106
     107QUuid VBoxMediaComboBox::id (int aIndex /*= -1*/)
     108{
     109    AssertReturn (aIndex == -1 ||
     110                  (aIndex >= 0 && (size_t) aIndex < mMedia.size()),
     111                  QUuid());
     112
     113    return mMedia [aIndex == -1 ? currentItem() : aIndex].id;
     114}
     115
     116QString VBoxMediaComboBox::location (int aIndex /*= -1*/)
     117{
     118    AssertReturn (aIndex == -1 ||
     119                  (aIndex >= 0 && (size_t) aIndex < mMedia.size()),
     120                  QString::null);
     121
     122    return mMedia [aIndex == -1 ? currentItem() : aIndex].location;
     123}
     124
     125/**
     126 * Selects a media item with the given ID or does nothing if there is no such
     127 * item. Note that this method, as opposed to QComboBox::setCurrentItem(int),
     128 * does emit the activated() signal on success.
     129 */
     130void VBoxMediaComboBox::setCurrentItem (const QUuid &aId)
     131{
     132    mLastId = aId;
     133
     134    size_t index;
     135    if (findMediaIndex (aId, index))
     136    {
     137        /* Note that the media combobox may be not populated here yet, so we
     138         * don't assert */
     139        QComboBox::setCurrentItem (index);
     140        emit activated (index);
     141    }
     142}
     143
     144void VBoxMediaComboBox::setType (VBoxDefs::MediaType aType)
     145{
     146    mType = aType;
     147}
     148
     149/**
     150 * Enables or disables the "show diffs" mode.
     151 *
     152 * In disabled "show diffs" mode, this combobox will only include base hard
     153 * disks plus differencing hard disks that are attached to the associated
     154 * machine passed to the constructor in the current state (if any). Note
     155 * that for these differencing hard disks, the details of their base hard disks
     156 * are shown instead of their own details (human-friendly mode).
     157 *
     158 * In enabled "show diffs" mode, all hard disks, base and differencing, are
     159 * shown.
     160 *
     161 * Note that you must call #refresh() in order for this change to take effect.
     162 *
     163 * @param aShowDiffs    @c true to enable "show diffs" mode.
     164 */
     165void VBoxMediaComboBox::setShowDiffs (bool aShowDiffs)
     166{
     167    AssertReturnVoid (aShowDiffs == true || !mMachineId.isNull());
     168
     169    mShowDiffs = aShowDiffs;
     170}
    95171
    96172void VBoxMediaComboBox::mediaEnumStarted()
     
    99175}
    100176
    101 void VBoxMediaComboBox::mediaEnumerated (const VBoxMedia &aMedia, int /*aIndex*/)
    102 {
    103     processMedia (aMedia);
    104 }
    105 
    106 
    107 void VBoxMediaComboBox::mediaAdded (const VBoxMedia &aMedia)
    108 {
    109     processMedia (aMedia);
    110 }
    111 
    112 void VBoxMediaComboBox::mediaUpdated (const VBoxMedia &aMedia)
    113 {
    114     processMedia (aMedia);
    115 }
    116 
    117 void VBoxMediaComboBox::mediaRemoved (VBoxDefs::DiskType aType,
    118                                       const QUuid &aId)
    119 {
    120     if (!(aType & mType))
    121         return;
    122 
    123     /* search & remove media */
    124     int index = mUuidList.findIndex (aId);
    125     if (index != -1)
    126     {
    127         removeItem (index);
    128         mUuidList.remove (mUuidList.at (index));
    129         mTipList.remove (mTipList.at (index));
    130         /* emit signal to ensure parent dialog process selection changes */
    131         emit activated (currentItem());
    132     }
    133 }
    134 
    135 
    136 void VBoxMediaComboBox::processMedia (const VBoxMedia &aMedia)
    137 {
    138     if (!(aMedia.type & mType))
    139         return;
    140 
    141     switch (aMedia.type)
    142     {
    143         case VBoxDefs::HD:
     177void VBoxMediaComboBox::mediumEnumerated (const VBoxMedium &aMedium, int /*aIndex*/)
     178{
     179    mediumUpdated (aMedium);
     180}
     181
     182void VBoxMediaComboBox::mediumAdded (const VBoxMedium &aMedium)
     183{
     184    if (mType != aMedium.type())
     185        return;
     186
     187    if (!mShowDiffs && aMedium.type() == VBoxDefs::MediaType_HardDisk)
     188    {
     189        if (aMedium.parent() != NULL)
    144190        {
    145             /* ignoring non-root disks */
    146             CHardDisk hd = aMedia.disk;
    147             if (hd.GetParent().isNull())
    148                 processHdMedia (aMedia);
    149             break;
     191            /* in !mShowDiffs mode, we ignore all diffs except ones that are
     192             * directly attached to the related VM in the current state */
     193            if (!aMedium.isAttachedInCurStateTo (mMachineId))
     194                return;
    150195        }
    151         case VBoxDefs::CD:
    152             processCdMedia (aMedia);
    153             break;
    154         case VBoxDefs::FD:
    155             processFdMedia (aMedia);
    156             break;
    157         default:
    158             AssertFailed();
    159     }
    160 }
    161 
    162 void VBoxMediaComboBox::processHdMedia (const VBoxMedia &aMedia)
    163 {
    164     QUuid mediaId;
    165     QString toolTip;
    166     CHardDisk hd = aMedia.disk;
    167     QString src = hd.GetLocation();
    168     QUuid machineId = hd.GetMachineId();
    169     /* append list only with free hd */
    170     if (machineId.isNull() || machineId == mMachineId)
    171     {
    172         mediaId = hd.GetId();
    173         toolTip = VBoxDiskImageManagerDlg::composeHdToolTip (hd, aMedia.status);
    174     }
    175     if (!mediaId.isNull())
    176         updateShortcut (src, mediaId, toolTip, aMedia.status);
    177 }
    178 
    179 void VBoxMediaComboBox::processCdMedia (const VBoxMedia &aMedia)
    180 {
    181     CDVDImage dvd = aMedia.disk;
    182     QString src = dvd.GetFilePath();
    183     QUuid mediaId = dvd.GetId();
    184     QString toolTip = VBoxDiskImageManagerDlg::composeCdToolTip (dvd, aMedia.status);
    185     updateShortcut (src, mediaId, toolTip, aMedia.status);
    186 }
    187 
    188 void VBoxMediaComboBox::processFdMedia (const VBoxMedia &aMedia)
    189 {
    190     CFloppyImage floppy = aMedia.disk;
    191     QString src = floppy.GetFilePath();
    192     QUuid mediaId = floppy.GetId();
    193     QString toolTip = VBoxDiskImageManagerDlg::composeFdToolTip (floppy, aMedia.status);
    194     updateShortcut (src, mediaId, toolTip, aMedia.status);
    195 }
    196 
    197 void VBoxMediaComboBox::updateShortcut (const QString &aSrc,
    198                                         const QUuid &aId,
    199                                         const QString &aTip,
    200                                         VBoxMedia::Status aStatus)
    201 {
    202     /* compose item's name */
    203     QFileInfo fi (aSrc);
    204     QString name = QString ("%1 (%2)").arg (fi.fileName())
    205                    .arg (QDir::convertSeparators (fi.dirPath()));
    206     /* update warning/error icons */
    207     QPixmap *pixmap = 0;
    208     if (aStatus == VBoxMedia::Inaccessible)
    209         pixmap = &mPmInacc;
    210     else if (aStatus == VBoxMedia::Error)
    211         pixmap = &mPmError;
    212 
    213     /* search media */
    214     int index = mUuidList.findIndex (aId);
    215     /* create or update media */
    216     if (index == -1)
    217         appendItem (name, aId, aTip, pixmap);
    218     else
    219         replaceItem (index, name, aTip, pixmap);
    220 
    221     /* activate required item if it was updated */
    222     if (aId == mRequiredId)
    223         setCurrentItem (aId);
    224     /* select last added item if there is no item selected */
     196    }
     197
     198    appendItem (aMedium);
     199
     200    if (aMedium.id() == mLastId)
     201    {
     202        /* activate the required item if there is any */
     203        setCurrentItem (aMedium.id());
     204    }
    225205    else if (currentText().isEmpty())
    226         QComboBox::setCurrentItem (index == -1 ? count() - 1 : index);
    227 }
    228 
    229 void VBoxMediaComboBox::processActivated (int aItem)
    230 {
    231     mRequiredId = mUuidList.isEmpty() || aItem < 0 ? QUuid() : QUuid (mUuidList [aItem]);
    232     updateToolTip (aItem);
    233 }
    234 
    235 void VBoxMediaComboBox::updateToolTip (int aItem)
    236 {
    237     /* combobox tooltip attaching */
     206    {
     207        /* select last added item if there is no item selected */
     208        QComboBox::setCurrentItem (count() - 1);
     209    }
     210}
     211
     212void VBoxMediaComboBox::mediumUpdated (const VBoxMedium &aMedium)
     213{
     214    if (mType != aMedium.type())
     215        return;
     216
     217    size_t index;
     218    if (!findMediaIndex (aMedium.id(), index))
     219        return;
     220
     221    replaceItem (index, aMedium);
     222
     223    /* emit the signal to ensure the parent dialog handles the change of
     224     * the selected item's data */
     225    emit activated (currentItem());
     226}
     227
     228void VBoxMediaComboBox::mediumRemoved (VBoxDefs::MediaType aType,
     229                                       const QUuid &aId)
     230{
     231    if (mType != aType)
     232        return;
     233
     234    size_t index;
     235    if (!findMediaIndex (aId, index))
     236        return;
     237
     238    removeItem (index);
     239
     240    mMedia.erase (mMedia.begin() + index);
     241
     242    if (count() == 0)
     243    {
     244        /* no media left, add the "no media" pseudo-item */
     245        addNoMediaItem();
     246    }
     247
     248    /* emit the signal to ensure the parent dialog handles the change of
     249     * the selected item */
     250    emit activated (currentItem());
     251}
     252
     253void VBoxMediaComboBox::processActivated (int aIndex)
     254{
     255    AssertReturnVoid (aIndex >= 0 && (size_t) aIndex < mMedia.size());
     256
     257    mLastId = mMedia [aIndex].id;
     258
     259    updateToolTip (aIndex);
     260}
     261
     262void VBoxMediaComboBox::addNoMediaItem()
     263{
     264    AssertReturnVoid (count() == 0);
     265    AssertReturnVoid (mMedia.size() == 0);
     266
     267    mMedia.append (
     268        Medium (QUuid(), QString::null,
     269                tr ("No media available. Use the Virtual Media "
     270                    "Manager to add media of the corresponding type.")));
     271    insertItem (tr ("<no media>"));
     272
     273    setCurrentItem (0);
     274}
     275
     276void VBoxMediaComboBox::updateToolTip (int aIndex)
     277{
     278    /* set the combobox tooltip */
    238279    QToolTip::remove (this);
    239     if (!mTipList.isEmpty() && aItem >= 0)
    240         QToolTip::add (this, mTipList [aItem]);
    241 }
    242 
    243 void VBoxMediaComboBox::processOnItem (QListBoxItem* aItem)
    244 {
    245     /* combobox item's tooltip attaching */
     280    if (aIndex >= 0 && (size_t) aIndex < mMedia.size())
     281        QToolTip::add (this, mMedia [aIndex].toolTip);
     282}
     283
     284void VBoxMediaComboBox::processOnItem (QListBoxItem *aItem)
     285{
     286    /* set the combobox item's tooltip */
    246287    int index = listBox()->index (aItem);
    247288    QToolTip::remove (listBox()->viewport());
    248     QToolTip::add (listBox()->viewport(), mTipList [index]);
    249 }
    250 
    251 QUuid VBoxMediaComboBox::getId (int aId)
    252 {
    253     return mUuidList.isEmpty() ? QUuid() :
    254            aId == -1 ? QUuid (mUuidList [currentItem()]) :
    255            QUuid (mUuidList [aId]);
    256 }
    257 
    258 void VBoxMediaComboBox::appendItem (const QString &aName,
    259                                     const QUuid   &aId,
    260                                     const QString &aTip,
    261                                     QPixmap       *aPixmap)
    262 {
    263     int currentIndex = currentItem();
    264 
    265     int insertPosition = -1;
    266     for (int i = 0; i < count(); ++ i)
    267         /* Searching for the first real (non-null) vdi item
    268            which have name greater than the item to be inserted.
    269            This is necessary for sorting items alphabetically. */
    270         if (text (i).localeAwareCompare (aName) > 0 &&
    271             !getId (i).isNull())
     289    QToolTip::add (listBox()->viewport(), mMedia [index].toolTip);
     290}
     291
     292void VBoxMediaComboBox::appendItem (const VBoxMedium &aMedium)
     293{
     294    if (!mShowDiffs && aMedium.parent() != NULL)
     295    {
     296        /* We are adding the direct machine diff in !mShowDiffs mode. Since its
     297         * base hard disk has been already appended (enumerated before), we want
     298         * to replace the base with the diff to avoid shownig both (both would
     299         * be labeled using the base filename and therefore look like
     300         * duplicates). Note though that these visual duplicates are still
     301         * possible in !mShowDiffs mode if the same base hard disk is attached*
     302         * to the VM through different diffs (this is why we don't assert
     303         * below on findMediaIndex() == true). However, this situation is
     304         * unavoidable so we accept it assuming that the user will switch to
     305           mShowDiffs mode if he needs clarity. */
     306        size_t index;
     307        if (findMediaIndex (aMedium.root().id(), index))
    272308        {
    273             insertPosition = i;
     309            replaceItem (index, aMedium);
     310            return;
     311        }
     312    }
     313
     314    if (count() == 1 && mMedia [0].id.isNull())
     315    {
     316        /* there is a "no media" pseudo-item, remove it */
     317        clear(), mMedia.clear();
     318    }
     319
     320    mMedia.append (Medium (aMedium.id(), aMedium.location(),
     321                           aMedium.toolTipCheckRO (!mShowDiffs)));
     322
     323    insertItem (aMedium.iconCheckRO (!mShowDiffs),
     324                aMedium.details (!mShowDiffs), -1);
     325}
     326
     327void VBoxMediaComboBox::replaceItem (int aIndex, const VBoxMedium &aMedium)
     328{
     329    AssertReturnVoid (aIndex >= 0 && (size_t) aIndex < mMedia.size());
     330
     331    mMedia [aIndex].id = aMedium.id();
     332    mMedia [aIndex].location = aMedium.location();
     333    mMedia [aIndex].toolTip = aMedium.toolTipCheckRO (!mShowDiffs);
     334
     335    changeItem (aMedium.iconCheckRO (!mShowDiffs),
     336                aMedium.details (!mShowDiffs), aIndex);
     337
     338    if (aIndex == currentItem())
     339        updateToolTip (aIndex);
     340}
     341
     342/**
     343 * Searches for a medium with the given ID in mMedia and stores its index in @a
     344 * aIndex. Returns @c true if the media was found and @c false otherwise (@a
     345 * aIndex will be set to a value >= mMedia.size() in this case).
     346 *
     347 * @param aId       Media ID to search for.
     348 * @param aIndex    Where to store the found media index.
     349 */
     350bool VBoxMediaComboBox::findMediaIndex (const QUuid &aId, size_t &aIndex)
     351{
     352    aIndex = 0;
     353
     354    for (; aIndex < mMedia.size(); ++ aIndex )
     355        if (mMedia [aIndex ].id == aId)
    274356            break;
    275         }
    276 
    277     insertPosition == -1 ? mUuidList.append (aId) :
    278         mUuidList.insert (mUuidList.at (insertPosition), aId);
    279 
    280     insertPosition == -1 ? mTipList.append (aTip) :
    281         mTipList.insert (mTipList.at (insertPosition), aTip);
    282 
    283     aPixmap ? insertItem (*aPixmap, aName, insertPosition) :
    284               insertItem (aName, insertPosition);
    285 
    286     if (insertPosition != -1 && currentIndex >= insertPosition)
    287         QComboBox::setCurrentItem (currentIndex + 1);
    288 }
    289 
    290 void VBoxMediaComboBox::replaceItem (int            aNumber,
    291                                      const QString &aName,
    292                                      const QString &aTip,
    293                                      QPixmap       *aPixmap)
    294 {
    295     aPixmap ? changeItem (*aPixmap, aName, aNumber) : changeItem (aName, aNumber);
    296     mTipList [aNumber] = aTip;
    297 }
    298 
    299 void VBoxMediaComboBox::setUseEmptyItem (bool aUseEmptyItem)
    300 {
    301     mUseEmptyItem = aUseEmptyItem;
    302 }
    303 
    304 void VBoxMediaComboBox::setBelongsTo (const QUuid &aMachineId)
    305 {
    306     mMachineId = aMachineId;
    307 }
    308 
    309 QUuid VBoxMediaComboBox::getBelongsTo()
    310 {
    311     return mMachineId;
    312 }
    313 
    314 void VBoxMediaComboBox::setCurrentItem (const QUuid &aId)
    315 {
    316     mRequiredId = aId;
    317     int index = mUuidList.findIndex (mRequiredId);
    318     if (index != -1)
    319     {
    320         QComboBox::setCurrentItem (index);
    321         emit activated (index);
    322     }
    323 }
    324 
    325 void VBoxMediaComboBox::setType (int aType)
    326 {
    327     mType = aType;
    328 }
     357
     358    return aIndex < mMedia.size();
     359}
     360
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp

    r13374 r13580  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    602602}
    603603
    604 void VBoxProblemReporter::cannotAccessUSB (const COMBase &obj)
     604void VBoxProblemReporter::cannotAccessUSB (const COMBaseWithEI &obj)
    605605{
    606606    /* If IMachine::GetUSBController(), IHost::GetUSBDevices() etc. return
     
    702702{
    703703    AssertWrapperOk (progress);
    704     CConsole console = CProgress (progress).GetInitiator();
     704    CConsole console (CProgress (progress).GetInitiator());
    705705    AssertWrapperOk (console);
    706706
     
    762762{
    763763    AssertWrapperOk (progress);
    764     CConsole console = CProgress (progress).GetInitiator();
     764    CConsole console (CProgress (progress).GetInitiator());
    765765    AssertWrapperOk (console);
    766766
     
    788788{
    789789    AssertWrapperOk (progress);
    790     CConsole console = CProgress (progress).GetInitiator();
     790    CConsole console (CProgress (progress).GetInitiator());
    791791    AssertWrapperOk (console);
    792792
     
    814814{
    815815    AssertWrapperOk (progress);
    816     CConsole console = CProgress (progress).GetInitiator();
     816    CConsole console (CProgress (progress).GetInitiator());
    817817    AssertWrapperOk (console);
    818818
     
    859859}
    860860
    861 void VBoxProblemReporter::cannotDiscardSnapshot (const CConsole &console,
    862                                                  const CSnapshot &snapshot)
    863 {
    864     message (
    865         mainWindowShown(),
    866         Error,
     861void VBoxProblemReporter::cannotDiscardSnapshot (const CConsole &aConsole,
     862                                                 const QString &aSnapshotName)
     863{
     864    message (mainWindowShown(), Error,
    867865        tr ("Failed to discard the snapshot <b>%1</b> of the virtual "
    868866            "machine <b>%2</b>.")
    869             .arg (snapshot.GetName())
    870             .arg (CConsole (console).GetMachine().GetName()),
    871         formatErrorInfo (console));
    872 }
    873 
    874 void VBoxProblemReporter::cannotDiscardSnapshot (const CProgress &progress,
    875                                                  const CSnapshot &snapshot)
    876 {
    877     CConsole console = CProgress (progress).GetInitiator();
    878 
    879     message (
    880         mainWindowShown(),
    881         Error,
     867            .arg (aSnapshotName)
     868            .arg (CConsole (aConsole).GetMachine().GetName()),
     869        formatErrorInfo (aConsole));
     870}
     871
     872void VBoxProblemReporter::cannotDiscardSnapshot (const CProgress &aProgress,
     873                                                 const QString &aSnapshotName)
     874{
     875    CConsole console (CProgress (aProgress).GetInitiator());
     876
     877    message (mainWindowShown(), Error,
    882878        tr ("Failed to discard the snapshot <b>%1</b> of the virtual "
    883879            "machine <b>%2</b>.")
    884             .arg (snapshot.GetName())
     880            .arg (aSnapshotName)
    885881            .arg (console.GetMachine().GetName()),
    886         formatErrorInfo (progress.GetErrorInfo()));
     882        formatErrorInfo (aProgress.GetErrorInfo()));
    887883}
    888884
     
    900896void VBoxProblemReporter::cannotDiscardCurrentState (const CProgress &progress)
    901897{
    902     CConsole console = CProgress (progress).GetInitiator();
     898    CConsole console (CProgress (progress).GetInitiator());
    903899
    904900    message (
     
    924920void VBoxProblemReporter::cannotDiscardCurrentSnapshotAndState (const CProgress &progress)
    925921{
    926     CConsole console = CProgress (progress).GetInitiator();
     922    CConsole console (CProgress (progress).GetInitiator());
    927923
    928924    message (
     
    10241020}
    10251021
    1026 bool VBoxProblemReporter::confirmReleaseImage (QWidget *parent,
    1027                                                const QString &usage)
    1028 {
    1029     return messageOkCancel (parent, Question,
    1030         tr ("<p>Releasing this media image will detach it from the "
    1031             "following virtual machine(s): <b>%1</b>.</p>"
    1032             "<p>Continue?</p>")
    1033             .arg (usage),
    1034         "confirmReleaseImage",
    1035         tr ("Continue", "detach image"));
    1036 }
    1037 
    1038 void VBoxProblemReporter::sayCannotOverwriteHardDiskImage (QWidget *parent,
    1039                                                            const QString &src)
    1040 {
    1041     message (parent, Info,
    1042         tr ("<p>The image file <b>%1</b> already exists. "
    1043             "You cannot create a new virtual hard disk that uses this file, "
    1044             "because it can be already used by another virtual hard disk.</p>"
    1045             "<p>Please specify a different image file name.</p>")
    1046             .arg (src));
    1047 }
    1048 
    1049 int VBoxProblemReporter::confirmHardDiskImageDeletion (QWidget *parent,
    1050                                                         const QString &src)
    1051 {
    1052     return message (parent, Question,
    1053         tr ("<p>Do you want to delete this hard disk's image file "
    1054             "<nobr><b>%1</b>?</nobr></p>"
    1055             "<p>If you select <b>Delete</b> then the image file will be permanently "
    1056             "deleted after unregistering the hard disk. This operation "
    1057             "cannot be undone.</p>"
    1058             "<p>If you select <b>Unregister</b> then the virtual hard disk will be "
    1059             "unregistered and removed from the collection, but the image file "
    1060             "will be left on your physical disk.</p>")
    1061             .arg (src),
     1022bool VBoxProblemReporter::confirmReleaseMedium (QWidget *aParent,
     1023                                                const VBoxMedium &aMedium,
     1024                                                const QString &aUsage)
     1025{
     1026    return messageOkCancel (aParent, Question,
     1027        tr ("<p>Are you sure you want to release the %1 "
     1028            "<nobr><b>%2</b></nobr>?</p>"
     1029            "<p>This will detach it from the "
     1030            "following virtual machine(s): <b>%3</b>.</p>")
     1031            .arg (toAccusative (aMedium.type()))
     1032            .arg (aMedium.location())
     1033            .arg (aUsage),
     1034        0 /* aAutoConfirmId */,
     1035        tr ("Release", "detach medium"));
     1036}
     1037
     1038bool VBoxProblemReporter::confirmRemoveMedium (QWidget *aParent,
     1039                                               const VBoxMedium &aMedium)
     1040{
     1041    QString msg =
     1042        tr ("<p>Are you sure you want to remove the %1 "
     1043            "<nobr><b>%2</b></nobr> from the list of known media?</p>")
     1044            .arg (toAccusative (aMedium.type()))
     1045            .arg (aMedium.location());
     1046
     1047    if (aMedium.type() == VBoxDefs::MediaType_HardDisk)
     1048    {
     1049        if (aMedium.state() == KMediaState_Inaccessible)
     1050            msg +=
     1051                tr ("Note that this hard disk is inaccessible so that its "
     1052                    "storage unit cannot be deleted right now.");
     1053        else
     1054            msg +=
     1055                tr ("The next dialog will let you choose whether you also "
     1056                    "want to delete the storage unit of this hard disk or "
     1057                    "keep it for later usage.");
     1058    }
     1059    else
     1060        msg +=
     1061            tr ("<p>Note that the storage unit of this medium will not be "
     1062                "deleted and therefore it will be possible to add it to "
     1063                "the list later again.</p>");
     1064
     1065    return messageOkCancel (aParent, Question, msg,
     1066        "confirmRemoveMedium", /* aAutoConfirmId */
     1067        tr ("Remove", "medium"));
     1068}
     1069
     1070void VBoxProblemReporter::sayCannotOverwriteHardDiskStorage (
     1071    QWidget *aParent, const QString &aLocation)
     1072{
     1073    message (aParent, Info,
     1074        tr ("<p>The hard disk storage unit at location <b>%1</b> already "
     1075            "exists. You cannot create a new virtual hard disk that uses this "
     1076            "location because it can be already used by another virtual hard "
     1077            "disk.</p>"
     1078            "<p>Please specify a different location.</p>")
     1079            .arg (aLocation));
     1080}
     1081
     1082int VBoxProblemReporter::confirmDeleteHardDiskStorage (
     1083    QWidget *aParent, const QString &aLocation)
     1084{
     1085    return message (aParent, Question,
     1086        tr ("<p>Do you want to delete the storage unit of the hard disk "
     1087            "<nobr><b>%1</b></nobr>?</p>"
     1088            "<p>If you select <b>Delete</b> then the specified storage unit "
     1089            "will be permanently deleted. This operation <b>cannot be "
     1090            "undone</b>.</p>"
     1091            "<p>If you select <b>Keep</b> then the hard disk will be only "
     1092            "removed from the list of known hard disks, but the storage unit "
     1093            "will be left untouched which makes it possible to add this hard "
     1094            "disk to the list later again.</p>")
     1095            .arg (aLocation),
    10621096        0, /* aAutoConfirmId */
    10631097        QIMessageBox::Yes,
    10641098        QIMessageBox::No | QIMessageBox::Default,
    10651099        QIMessageBox::Cancel | QIMessageBox::Escape,
    1066         tr ("Delete", "hard disk"),
    1067         tr ("Unregister", "hard disk"));
    1068 }
    1069 
    1070 void VBoxProblemReporter::cannotDeleteHardDiskImage (QWidget *parent,
    1071                                                      const CVirtualDiskImage &vdi)
    1072 {
    1073     /* below, we use CHardDisk (hd) to preserve current error info
     1100        tr ("Delete", "hard disk storage"),
     1101        tr ("Keep", "hard disk storage"));
     1102}
     1103
     1104void VBoxProblemReporter::cannotDeleteHardDiskStorage (QWidget *aParent,
     1105                                                       const CHardDisk2 &aHD,
     1106                                                       const CProgress &aProgress)
     1107{
     1108    /* below, we use CHardDisk2 (aHD) to preserve current error info
    10741109     * for formatErrorInfo() */
    10751110
    1076     message (parent, Error,
    1077         tr ("Failed to delete the virtual hard disk image <b>%1</b>.")
    1078             .arg (CVirtualDiskImage (vdi).GetFilePath()),
    1079         formatErrorInfo (vdi));
    1080 }
    1081 
    1082 bool VBoxProblemReporter::confirmHardDiskUnregister (QWidget *parent,
    1083                                                     const QString &src)
    1084 {
    1085     return messageOkCancel (parent, Question,
    1086         tr ("<p>Do you want to remove (unregister) the virtual hard disk "
    1087             "<nobr><b>%1</b>?</nobr></p>")
    1088             .arg (src),
    1089         0 /* aAutoConfirmId */,
    1090         tr ("Unregister", "hard disk"));
     1111    message (aParent, Error,
     1112        tr ("Failed to delete the storage unit of the hard disk <b>%1</b>.")
     1113            .arg (CHardDisk2 (aHD).GetLocation()),
     1114        !aHD.isOk() ? formatErrorInfo (aHD) :
     1115        !aProgress.isOk() ? formatErrorInfo (aProgress) :
     1116        formatErrorInfo (aProgress.GetErrorInfo()));
    10911117}
    10921118
     
    11101136            "<p>Press the <b>Create</b> button to start the <i>New Virtual "
    11111137            "Disk</i> wizard and create a new hard disk, or press the "
    1112             "<b>Select</b> button to open the <i>Virtual Disk Manager</i> "
     1138            "<b>Select</b> button to open the <i>Virtual Media Manager</i> "
    11131139            "and select what to do.</p>"),
    11141140        0, /* aAutoConfirmId */
     
    11201146}
    11211147
    1122 void VBoxProblemReporter::cannotCreateHardDiskImage (
    1123     QWidget *parent, const CVirtualBox &vbox, const QString &src,
    1124     const CVirtualDiskImage &vdi, const CProgress &progress)
    1125 {
    1126     message (parent, Error,
    1127         tr ("Failed to create the virtual hard disk image <nobr><b>%1</b>.</nobr>")
    1128             .arg (src),
    1129         !vbox.isOk() ? formatErrorInfo (vbox) :
    1130         !vdi.isOk() ? formatErrorInfo (vdi) :
    1131         formatErrorInfo (progress.GetErrorInfo()));
     1148void VBoxProblemReporter::cannotCreateHardDiskStorage (
     1149    QWidget *aParent, const CVirtualBox &aVBox, const QString &aLocation,
     1150    const CHardDisk2 &aHD, const CProgress &aProgress)
     1151{
     1152    message (aParent, Error,
     1153        tr ("Failed to create the hard disk storage <nobr><b>%1</b>.</nobr>")
     1154            .arg (aLocation),
     1155        !aVBox.isOk() ? formatErrorInfo (aVBox) :
     1156        !aHD.isOk() ? formatErrorInfo (aHD) :
     1157        !aProgress.isOk() ? formatErrorInfo (aProgress) :
     1158        formatErrorInfo (aProgress.GetErrorInfo()));
    11321159}
    11331160
    11341161void VBoxProblemReporter::cannotAttachHardDisk (
    1135     QWidget *parent, const CMachine &m, const QUuid &id,
    1136     KStorageBus bus, LONG channel, LONG dev)
    1137 {
    1138     message (parent, Error,
    1139         tr ("Failed to attach a hard disk image with UUID %1 "
    1140             "to device slot %2 on channel %3 of the %4 bus of the machine <b>%5</b>.")
    1141             .arg (id)
    1142             .arg (vboxGlobal().toString (bus, channel, dev))
    1143             .arg (vboxGlobal().toString (bus, channel))
    1144             .arg (vboxGlobal().toString (bus))
    1145             .arg (CMachine (m).GetName()),
    1146         formatErrorInfo (m));
     1162    QWidget *aParent, const CMachine &aMachine, const QString &aLocation,
     1163    KStorageBus aBus, LONG aChannel, LONG aDevice)
     1164{
     1165    message (aParent, Error,
     1166        tr ("Failed to attach the hard disk <nobr><b>%1</b></nobr> "
     1167            "to the slot <i>%2</i> of the machine <b>%3</b>.")
     1168            .arg (aLocation)
     1169            .arg (vboxGlobal().toFullString (aBus, aChannel, aDevice))
     1170            .arg (CMachine (aMachine).GetName()),
     1171        formatErrorInfo (aMachine));
    11471172}
    11481173
    11491174void VBoxProblemReporter::cannotDetachHardDisk (
    1150     QWidget *parent, const CMachine &m,
    1151     KStorageBus bus, LONG channel, LONG dev)
    1152 {
    1153     message (parent, Error,
    1154         tr ("Failed to detach a hard disk image "
    1155             "from device slot %1 on channel %2 of the %3 bus of the machine <b>%4</b>.")
    1156             .arg (vboxGlobal().toString (bus, channel, dev))
    1157             .arg (vboxGlobal().toString (bus, channel))
    1158             .arg (vboxGlobal().toString (bus))
    1159             .arg (CMachine (m).GetName()),
    1160         formatErrorInfo (m));
    1161 }
    1162 
    1163 void VBoxProblemReporter::cannotRegisterMedia (
    1164     QWidget *parent, const CVirtualBox &vbox,
    1165     VBoxDefs::DiskType type, const QString &src)
    1166 {
    1167     QString media = type == VBoxDefs::HD ? tr ("hard disk") :
    1168                     type == VBoxDefs::CD ? tr ("CD/DVD image") :
    1169                     type == VBoxDefs::FD ? tr ("floppy image") :
    1170                     QString::null;
    1171 
    1172     Assert (!media.isNull());
    1173 
    1174     message (parent, Error,
    1175         tr ("Failed to register the %1 <nobr><b>%2</b></nobr>.")
    1176             .arg (media)
    1177             .arg (src),
    1178         formatErrorInfo (vbox));
    1179 }
    1180 
    1181 void VBoxProblemReporter::cannotUnregisterMedia (
    1182     QWidget *parent, const CVirtualBox &vbox,
    1183     VBoxDefs::DiskType type, const QString &src)
    1184 {
    1185     QString media = type == VBoxDefs::HD ? tr ("hard disk") :
    1186                     type == VBoxDefs::CD ? tr ("CD/DVD image") :
    1187                     type == VBoxDefs::FD ? tr ("floppy image") :
    1188                     QString::null;
    1189 
    1190     Assert (!media.isNull());
    1191 
    1192     message (parent, Error,
    1193         tr ("Failed to unregister the %1 <nobr><b>%2</b></nobr>.")
    1194             .arg (media)
    1195             .arg (src),
    1196         formatErrorInfo (vbox));
     1175    QWidget *aParent, const CMachine &aMachine, const QString &aLocation,
     1176    KStorageBus aBus, LONG aChannel, LONG aDevice)
     1177{
     1178    message (aParent, Error,
     1179        tr ("Failed to detach the hard disk <nobr><b>%1</b></nobr> "
     1180            "from the slot <i>%2</i> of the machine <b>%3</b>.")
     1181            .arg (aLocation)
     1182            .arg (vboxGlobal().toFullString (aBus, aChannel, aDevice))
     1183            .arg (CMachine (aMachine).GetName()),
     1184         formatErrorInfo (aMachine));
     1185}
     1186
     1187void VBoxProblemReporter::
     1188cannotMountMedium (QWidget *aParent, const CMachine &aMachine,
     1189                   const VBoxMedium &aMedium, const COMResult &aResult)
     1190{
     1191    message (aParent, Error,
     1192        tr ("Failed to mount the %1 <nobr><b>%2</b></nobr> "
     1193            "to the machine <b>%3</b>.")
     1194            .arg (toAccusative (aMedium.type()))
     1195            .arg (aMedium.location())
     1196            .arg (CMachine (aMachine).GetName()),
     1197      formatErrorInfo (aResult));
     1198}
     1199
     1200void VBoxProblemReporter::
     1201cannotUnmountMedium (QWidget *aParent, const CMachine &aMachine,
     1202                     const VBoxMedium &aMedium, const COMResult &aResult)
     1203{
     1204    message (aParent, Error,
     1205        tr ("Failed to unmount the %1 <nobr><b>%2</b></nobr> "
     1206            "from the machine <b>%3</b>.")
     1207            .arg (toAccusative (aMedium.type()))
     1208            .arg (aMedium.location())
     1209            .arg (CMachine (aMachine).GetName()),
     1210      formatErrorInfo (aResult));
     1211}
     1212
     1213void VBoxProblemReporter::cannotOpenMedium (
     1214    QWidget *aParent, const CVirtualBox &aVBox,
     1215    VBoxDefs::MediaType aType, const QString &aLocation)
     1216{
     1217    message (aParent, Error,
     1218        tr ("Failed to open the %1 <nobr><b>%2</b></nobr>.")
     1219            .arg (toAccusative (aType))
     1220            .arg (aLocation),
     1221        formatErrorInfo (aVBox));
     1222}
     1223
     1224void VBoxProblemReporter::cannotCloseMedium (
     1225    QWidget *aParent, const VBoxMedium &aMedium, const COMResult &aResult)
     1226{
     1227    message (aParent, Error,
     1228        tr ("Failed to close the %1 <nobr><b>%2</b></nobr>.")
     1229            .arg (toAccusative (aMedium.type()))
     1230            .arg (aMedium.location()),
     1231        formatErrorInfo (aResult));
    11971232}
    11981233
     
    12291264}
    12301265
    1231 void VBoxProblemReporter::cannotGetMediaAccessibility (const CUnknown &unk)
    1232 {
    1233     QString src;
    1234     CHardDisk hd;
    1235     CDVDImage dvd;
    1236     CFloppyImage floppy;
    1237 
    1238     if (!(hd = unk).isNull())
    1239         src = hd.GetLocation();
    1240     else
    1241     if (!(dvd = unk).isNull())
    1242         src = dvd.GetFilePath();
    1243     else
    1244     if (!(floppy = unk).isNull())
    1245         src = floppy.GetFilePath();
    1246     else
    1247         AssertMsgFailed (("Not a valid CUnknown\n"));
    1248 
     1266void VBoxProblemReporter::cannotGetMediaAccessibility (const VBoxMedium &aMedium)
     1267{
    12491268    message (qApp->activeWindow(), Error,
    1250         tr ("Failed to get the accessibility state of the media "
    1251             "<nobr><b>%1</b></nobr>. Some of the registered media may "
    1252             "become inaccessible.")
    1253             .arg (src),
    1254         formatErrorInfo (unk));
     1269        tr ("Failed to get the accessibility state of the medium "
     1270            "<nobr><b>%1</b></nobr>.")
     1271            .arg (aMedium.location()),
     1272        formatErrorInfo (aMedium.result()));
    12551273}
    12561274
     
    16881706{
    16891707    int rc = message (&vboxGlobal().selectorWnd(), Warning,
    1690         tr ("<p>One or more of the registered virtual hard disks, CD/DVD or "
     1708        tr ("<p>One or more virtual hard disks, CD/DVD or "
    16911709            "floppy media are not currently accessible. As a result, you will "
    16921710            "not be able to operate virtual machines that use these media until "
    16931711            "they become accessible later.</p>"
    1694             "<p>Press <b>Check</b> to open the Virtual Disk Manager window and "
     1712            "<p>Press <b>Check</b> to open the Virtual Media Manager window and "
    16951713            "see what media are inaccessible, or press <b>Ignore</b> to "
    16961714            "ignore this message.</p>"),
     
    20022020}
    20032021
     2022/* static */
     2023QString VBoxProblemReporter::toAccusative (VBoxDefs::MediaType aType)
     2024{
     2025    QString type =
     2026        aType == VBoxDefs::MediaType_HardDisk ?
     2027            tr ("hard disk", "failed to close ...") :
     2028        aType == VBoxDefs::MediaType_DVD ?
     2029            tr ("CD/DVD image", "failed to close ...") :
     2030        aType == VBoxDefs::MediaType_Floppy ?
     2031            tr ("floppy image", "failed to close ...") :
     2032        QString::null;
     2033
     2034    Assert (!type.isNull());
     2035    return type;
     2036}
     2037
    20042038/**
    20052039 * Formats the given COM result code as a human-readable string.
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSelectorWnd.cpp

    r10148 r13580  
    2929#include "VBoxSnapshotsWgt.h"
    3030#include "VBoxNewVMWzd.h"
    31 #include "VBoxDiskImageManagerDlg.h"
     31#include "VBoxMediaManagerDlg.h"
    3232#include "VBoxVMSettingsDlg.h"
    3333#include "VBoxGlobalSettingsDlg.h"
     
    400400    /* actions */
    401401
    402     fileDiskMgrAction = new QAction( this, "fileDiskMgrAction" );
    403     fileDiskMgrAction->setIconSet (VBoxGlobal::iconSet ("diskim_16px.png"));
     402    fileMediaMgrAction = new QAction( this, "fileMediaMgrAction" );
     403    fileMediaMgrAction->setIconSet (VBoxGlobal::iconSet ("diskim_16px.png"));
    404404    fileSettingsAction = new QAction(this, "fileSettingsAction");
    405405    fileSettingsAction->setIconSet (VBoxGlobal::iconSet ("global_settings_16px.png"));
     
    519519
    520520    QPopupMenu *fileMenu = new QPopupMenu(this, "fileMenu");
    521     fileDiskMgrAction->addTo( fileMenu );
     521    fileMediaMgrAction->addTo( fileMenu );
    522522    fileMenu->insertSeparator();
    523523    fileSettingsAction->addTo(fileMenu);
     
    626626
    627627    /* signals and slots connections */
    628     connect (fileDiskMgrAction, SIGNAL (activated()), this, SLOT(fileDiskMgr()));
     628    connect (fileMediaMgrAction, SIGNAL (activated()), this, SLOT(fileMediaMgr()));
    629629    connect (fileSettingsAction, SIGNAL (activated()), this, SLOT(fileSettings()));
    630630    connect (fileExitAction, SIGNAL (activated()), this, SLOT (fileExit()));
     
    712712/////////////////////////////////////////////////////////////////////////////
    713713
    714 void VBoxSelectorWnd::fileDiskMgr()
    715 {
    716     VBoxDiskImageManagerDlg::showModeless();
     714void VBoxSelectorWnd::fileMediaMgr()
     715{
     716    VBoxMediaManagerDlg::showModeless();
    717717}
    718718
     
    838838    VBoxVMListBoxItem *item = (VBoxVMListBoxItem *) vmListBox->selectedItem();
    839839
    840     AssertMsgReturn (item, ("Item must be always selected here"), (void) 0);
     840    AssertMsgReturnVoid (item, ("Item must be always selected here"));
    841841
    842842    if (vboxProblem().confirmMachineDeletion (item->machine()))
     
    847847        if (item->accessible())
    848848        {
    849             /* open a direct session to modify VM settings */
     849            /* Open a direct session to modify VM settings */
    850850            CSession session = vboxGlobal().openSession (id);
    851851            if (session.isNull())
    852852                return;
    853853            CMachine machine = session.GetMachine();
    854             /* detach all hard disks before unregistering */
     854            /* Detach all attached Hard Disks */
     855            CHardDisk2AttachmentVector vec = machine.GetHardDisk2Attachments();
     856            for (uint i = 0; i < vec.size(); ++ i)
    855857            {
    856                 CHardDiskAttachmentEnumerator hen
    857                     = machine.GetHardDiskAttachments().Enumerate();
    858                 while (hen.HasMore())
    859                 {
    860                     CHardDiskAttachment att = hen.GetNext();
    861                     machine.DetachHardDisk (att.GetBus(), att.GetChannel(), att.GetDevice());
    862                 }
     858                CHardDisk2Attachment hda = vec [i];
     859                machine.DetachHardDisk2 (hda.GetBus(), hda.GetChannel(), hda.GetDevice());
     860                if (!machine.isOk())
     861                    vboxProblem().cannotDetachHardDisk (this, machine,
     862                        vboxGlobal().getMedium (CMedium (hda.GetHardDisk())).location(),
     863                        hda.GetBus(), hda.GetChannel(), hda.GetDevice());
    863864            }
    864             /* commit changes */
     865            /* Commit changes */
    865866            machine.SaveSettings();
    866867            if (!machine.isOk())
     
    11401141    vmListBoxCurrentChanged();
    11411142
    1142     fileDiskMgrAction->setMenuText (tr ("Virtual &Disk Manager..."));
    1143     fileDiskMgrAction->setAccel (tr ("Ctrl+D"));
    1144     fileDiskMgrAction->setStatusTip (tr ("Display the Virtual Disk Manager dialog"));
     1143    fileMediaMgrAction->setMenuText (tr ("&Virtual Media Manager..."));
     1144    fileMediaMgrAction->setAccel (tr ("Ctrl+D"));
     1145    fileMediaMgrAction->setStatusTip (tr ("Display the Virtual Media Manager dialog"));
    11451146
    11461147#ifdef Q_WS_MAC
     
    14351436            break;
    14361437
    1437         /* ignore the signal if a VBoxDiskImageManagerDlg window is active */
     1438        /* ignore the signal if a VBoxMediaManagerDlg window is active */
    14381439        if (qApp->activeWindow() &&
    1439             !strcmp (qApp->activeWindow()->className(), "VBoxDiskImageManagerDlg"))
     1440            !strcmp (qApp->activeWindow()->className(), "VBoxMediaManagerDlg"))
    14401441            break;
    14411442
     
    14431444        VBoxMediaList::const_iterator it;
    14441445        for (it = list.begin(); it != list.end(); ++ it)
    1445             if ((*it).status == VBoxMedia::Inaccessible)
     1446            if ((*it).state() == KMediaState_Inaccessible)
    14461447                break;
    14471448
     
    14501451            /* Show the VDM dialog but don't refresh once more after a
    14511452             * just-finished refresh */
    1452             VBoxDiskImageManagerDlg::showModeless (false /* aRefresh */);
     1453            VBoxMediaManagerDlg::showModeless (false /* aRefresh */);
    14531454        }
    14541455    }
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMListBox.cpp

    r8155 r13580  
    453453    const VBoxVMListBox *lb = vmListBox();
    454454
    455     QFontMetrics fmName = QFontMetrics (lb->nameFont());
    456     QFontMetrics fmShot = QFontMetrics (lb->shotFont());
    457     QFontMetrics fmState = QFontMetrics (lb->stateFont (mSessionState));
     455    QFontMetrics fmName (lb->nameFont());
     456    QFontMetrics fmShot (lb->shotFont());
     457    QFontMetrics fmState (lb->stateFont (mSessionState));
    458458    const int marg = lb->margin();
    459459
     
    492492    const VBoxVMListBox *lb = vmListBox();
    493493
    494     QFontMetrics fmName = QFontMetrics (lb->nameFont());
    495     QFontMetrics fmState = QFontMetrics (lb->stateFont (mSessionState));
     494    QFontMetrics fmName (lb->nameFont());
     495    QFontMetrics fmState (lb->stateFont (mSessionState));
    496496    const int marg = lb->margin();
    497497
     
    671671    const VBoxVMListBox *lb = vmListBox();
    672672
    673     QFontMetrics fmName = QFontMetrics (lb->nameFont());
    674     QFontMetrics fmShot = QFontMetrics (lb->shotFont());
    675     QFontMetrics fmState = QFontMetrics (lb->stateFont (mSessionState));
     673    QFontMetrics fmName (lb->nameFont());
     674    QFontMetrics fmShot (lb->shotFont());
     675    QFontMetrics fmState (lb->stateFont (mSessionState));
    676676    const int marg = lb->margin();
    677677
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r11822 r13580  
    244244            else
    245245            {
     246                /* pre-populate the media list before showing the main widget */
     247                vboxGlobal().startEnumeratingMedia();
     248
    246249                a.setMainWidget (&vboxGlobal().selectorWnd());
    247250                vboxGlobal().selectorWnd().show();
     
    249252                vboxGlobal().showRegistrationDialog (false /* aForce */);
    250253#endif
    251                 vboxGlobal().startEnumeratingMedia();
    252254                rc = a.exec();
    253255            }
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui

    r8183 r13580  
    275275                            <widget class="QLineEdit" row="0" column="1">
    276276                                <property name="name">
    277                                     <cstring>leVDIFolder</cstring>
     277                                    <cstring>leHardDiskFolder</cstring>
    278278                                </property>
    279279                                <property name="frameShape">
     
    284284                                </property>
    285285                                <property name="whatsThis" stdset="0">
    286                                     <string>Displays the path to the default VDI folder. This folder is used, if not explicitly specified otherwise, when adding existing or creating new virtual hard disks.</string>
     286                                    <string>Displays the path to the default hard disk folder. This folder is used, if not explicitly specified otherwise, when adding existing or creating new virtual hard disks.</string>
    287287                                </property>
    288288                            </widget>
     
    300300                                </property>
    301301                                <property name="text">
    302                                     <string>VDI files</string>
     302                                    <string>Hard Disks</string>
    303303                                </property>
    304304                            </widget>
     
    325325                            <widget class="QToolButton" row="0" column="3">
    326326                                <property name="name">
    327                                     <cstring>tbResetVDIFolder</cstring>
     327                                    <cstring>tbResetHardDiskFolder</cstring>
    328328                                </property>
    329329                                <property name="focusPolicy">
     
    340340                                </property>
    341341                                <property name="whatsThis" stdset="0">
    342                                     <string>Resets the VDI folder path to the default value. The actual default path will be displayed after accepting the changes and opening this dialog again.</string>
     342                                    <string>Resets the hard disk folder path to the default value. The actual default path will be displayed after accepting the changes and opening this dialog again.</string>
    343343                                </property>
    344344                            </widget>
     
    353353                            <widget class="QToolButton" row="0" column="2">
    354354                                <property name="name">
    355                                     <cstring>tbSelectVDIFolder</cstring>
     355                                    <cstring>tbSelectHardDiskFolder</cstring>
    356356                                </property>
    357357                                <property name="focusPolicy">
     
    371371                                </property>
    372372                                <property name="whatsThis" stdset="0">
    373                                     <string>Opens a dialog to select the default VDI folder.</string>
     373                                    <string>Opens a dialog to select the default hard disk folder.</string>
    374374                                </property>
    375375                            </widget>
     
    11631163    </connection>
    11641164    <connection>
    1165         <sender>tbResetVDIFolder</sender>
     1165        <sender>tbResetHardDiskFolder</sender>
    11661166        <signal>clicked()</signal>
    11671167        <receiver>VBoxGlobalSettingsDlg</receiver>
     
    11691169    </connection>
    11701170    <connection>
    1171         <sender>tbSelectVDIFolder</sender>
     1171        <sender>tbSelectHardDiskFolder</sender>
    11721172        <signal>clicked()</signal>
    11731173        <receiver>VBoxGlobalSettingsDlg</receiver>
     
    12561256    <tabstop>listView</tabstop>
    12571257    <tabstop>chbAutoCapture</tabstop>
    1258     <tabstop>leVDIFolder</tabstop>
    1259     <tabstop>tbSelectVDIFolder</tabstop>
    1260     <tabstop>tbResetVDIFolder</tabstop>
     1258    <tabstop>leHardDiskFolder</tabstop>
     1259    <tabstop>tbSelectHardDiskFolder</tabstop>
     1260    <tabstop>tbResetHardDiskFolder</tabstop>
    12611261    <tabstop>leMachineFolder</tabstop>
    12621262    <tabstop>tbSelectMachineFolder</tabstop>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h

    r8724 r13580  
    645645    /* default folders */
    646646
    647     leVDIFolder->setText (props.GetDefaultVDIFolder());
     647    leHardDiskFolder->setText (props.GetDefaultHardDiskFolder());
    648648    leMachineFolder->setText (props.GetDefaultMachineFolder());
    649649
     
    691691        {
    692692            CHostUSBDeviceFilter hostFilter = en.GetNext();
    693             CUSBDeviceFilter filter = CUnknown (hostFilter);
     693            CUSBDeviceFilter filter (hostFilter);
    694694            addUSBFilter (filter, false);
    695695        }
     
    726726    /* default folders */
    727727
    728     if (leVDIFolder->isModified())
    729         props.SetDefaultVDIFolder (leVDIFolder->text());
     728    if (leHardDiskFolder->isModified())
     729        props.SetDefaultHardDiskFolder (leHardDiskFolder->text());
    730730    if (props.isOk() && leMachineFolder->isModified())
    731731        props.SetDefaultMachineFolder (leMachineFolder->text());
     
    774774        filter.SetActive (uli->isOn());
    775775
    776         CHostUSBDeviceFilter insertedFilter = CUnknown (filter);
     776        CHostUSBDeviceFilter insertedFilter (filter);
    777777        if (mUSBFilterListModified)
    778778            host.InsertUSBDeviceFilter (host.GetUSBDeviceFilters().GetCount(),
     
    841841
    842842    QLineEdit *le = 0;
    843     if (tb == tbResetVDIFolder) le = leVDIFolder;
     843    if (tb == tbResetHardDiskFolder) le = leHardDiskFolder;
    844844    else if (tb == tbResetMachineFolder) le = leMachineFolder;
    845845    else if (tb == tbResetVRDPLib) le = leVRDPLib;
     
    860860
    861861    QLineEdit *le = 0;
    862     if (tb == tbSelectVDIFolder) le = leVDIFolder;
     862    if (tb == tbSelectHardDiskFolder) le = leHardDiskFolder;
    863863    else if (tb == tbSelectMachineFolder) le = leMachineFolder;
    864864    else if (tb == tbSelectVRDPLib) le = leVRDPLib;
     
    992992    hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
    993993
    994     CUSBDeviceFilter filter = CUnknown (hostFilter);
     994    CUSBDeviceFilter filter (hostFilter);
    995995    filter.SetActive (true);
    996996    addUSBFilter (filter, true);
     
    10251025    hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
    10261026
    1027     CUSBDeviceFilter filter = CUnknown (hostFilter);
     1027    CUSBDeviceFilter filter (hostFilter);
    10281028    filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
    10291029    filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxHardDiskSettings.ui

    r8395 r13580  
    5656                <widget class="QCheckBox">
    5757                    <property name="name">
    58                         <cstring>mCbSATA</cstring>
     58                        <cstring>mSATACheck</cstring>
    5959                    </property>
    6060                    <property name="text">
     
    8181                            <cstring>unnamed</cstring>
    8282                        </property>
    83                         <widget class="QListView">
    84                             <column>
     83                        <vbox>
     84                            <property name="name">
     85                                <cstring>unnamed</cstring>
     86                            </property>
     87                            <widget class="QListView">
     88                                <column>
     89                                    <property name="text">
     90                                        <string>Slot</string>
     91                                    </property>
     92                                    <property name="clickable">
     93                                        <bool>true</bool>
     94                                    </property>
     95                                    <property name="resizable">
     96                                        <bool>true</bool>
     97                                    </property>
     98                                </column>
     99                                <column>
     100                                    <property name="text">
     101                                        <string>Hard Disk</string>
     102                                    </property>
     103                                    <property name="clickable">
     104                                        <bool>true</bool>
     105                                    </property>
     106                                    <property name="resizable">
     107                                        <bool>true</bool>
     108                                    </property>
     109                                </column>
     110                                <property name="name">
     111                                    <cstring>mLvHD</cstring>
     112                                </property>
     113                                <property name="allColumnsShowFocus">
     114                                    <bool>true</bool>
     115                                </property>
     116                                <property name="resizeMode">
     117                                    <enum>LastColumn</enum>
     118                                </property>
     119                                <property name="whatsThis" stdset="0">
     120                                    <string>
     121                                      &lt;qt&gt;Lists all hard disks attached to
     122                                      this machine. Use a mouse double-click or the
     123                                      &lt;tt&gt;F2&lt;/tt&gt;/&lt;tt&gt;Space&lt;/tt&gt;
     124                                      key on the highlighted item to activate the
     125                                      drop-down list and choose the desired value.
     126                                      Use the context menu or buttons to the right
     127                                      to add or remove hard disk
     128                                      attachments.&lt;/qt&gt;
     129                                    </string>
     130                                </property>
     131                            </widget>
     132                            <widget class="QCheckBox">
     133                                <property name="name">
     134                                    <cstring>mShowDiffsCheck</cstring>
     135                                </property>
    85136                                <property name="text">
    86                                     <string>Slot</string>
    87                                 </property>
    88                                 <property name="clickable">
    89                                     <bool>true</bool>
    90                                 </property>
    91                                 <property name="resizable">
    92                                     <bool>true</bool>
    93                                 </property>
    94                             </column>
    95                             <column>
    96                                 <property name="text">
    97                                     <string>Hard Disk</string>
    98                                 </property>
    99                                 <property name="clickable">
    100                                     <bool>true</bool>
    101                                 </property>
    102                                 <property name="resizable">
    103                                     <bool>true</bool>
    104                                 </property>
    105                             </column>
    106                             <property name="name">
    107                                 <cstring>mLvHD</cstring>
    108                             </property>
    109                             <property name="allColumnsShowFocus">
    110                                 <bool>true</bool>
    111                             </property>
    112                             <property name="resizeMode">
    113                                 <enum>LastColumn</enum>
    114                             </property>
    115                             <property name="whatsThis" stdset="0">
    116                                 <string>
    117                                   &lt;qt&gt;Lists all hard disks attached to
    118                                   this machine. Use a mouse double-click or the
    119                                   &lt;tt&gt;F2&lt;/tt&gt;/&lt;tt&gt;Space&lt;/tt&gt;
    120                                   key on the highlighted item to activate the
    121                                   drop-down list and choose the desired value.
    122                                   Use the context menu or buttons to the right
    123                                   to add or remove hard disk
    124                                   attachments.&lt;/qt&gt;
    125                                 </string>
    126                             </property>
    127                         </widget>
     137                                    <string>&amp;Show Differencing Hard Disks</string>
     138                                </property>
     139                                <property name="whatsThis" stdset="0">
     140                                    <string>
     141                                      &lt;qt&gt;If checked, it will show
     142                                      differencing hard disks actually attached
     143                                      to the slots instead of their base hard
     144                                      disks (shown in case of indirect
     145                                      attachments) and will also let attach
     146                                      other differencing hard disks explicitly.
     147                                      Check this only if you need a complex hard
     148                                      disk setup.&lt;/qt&gt;
     149                                    </string>
     150                                </property>
     151                            </widget>
     152                        </vbox>
    128153                        <widget class="QLayoutWidget">
    129154                            <property name="name">
     
    218243        <property name="whatsThis" stdset="0">
    219244            <string>
    220               &lt;qt&gt;Invokes the Virtual Disk Manager to select a hard disk
     245              &lt;qt&gt;Invokes the Virtual Media Manager to select a hard disk
    221246              to attach to the currently highlighted slot.&lt;/qt&gt;
    222247            </string>
     
    241266        <signal>activated()</signal>
    242267        <receiver>VBoxHardDiskSettings</receiver>
    243         <slot>showVDM()</slot>
     268        <slot>showMediaManager()</slot>
     269    </connection>
     270    <connection>
     271        <sender>mSATACheck</sender>
     272        <signal>toggled(bool)</signal>
     273        <receiver>VBoxHardDiskSettings</receiver>
     274        <slot>onSATACheckToggled(bool)</slot>
     275    </connection>
     276    <connection>
     277        <sender>mLvHD</sender>
     278        <signal>pressed(QListViewItem*,const QPoint&amp;,int)</signal>
     279        <receiver>VBoxHardDiskSettings</receiver>
     280        <slot>moveFocus(QListViewItem*, const QPoint&amp;,int)</slot>
     281    </connection>
     282    <connection>
     283        <sender>mLvHD</sender>
     284        <signal>currentChanged(QListViewItem*)</signal>
     285        <receiver>VBoxHardDiskSettings</receiver>
     286        <slot>onCurrentChanged(QListViewItem*)</slot>
     287    </connection>
     288    <connection>
     289        <sender>mLvHD</sender>
     290        <signal>contextMenuRequested(QListViewItem*,const QPoint&amp;,int)</signal>
     291        <receiver>VBoxHardDiskSettings</receiver>
     292        <slot>onContextMenuRequested(QListViewItem*,const QPoint&amp;,int)</slot>
     293    </connection>
     294    <connection>
     295        <sender>mShowDiffsCheck</sender>
     296        <signal>toggled(bool)</signal>
     297        <receiver>VBoxHardDiskSettings</receiver>
     298        <slot>onShowDiffsCheckToggled(bool)</slot>
    244299    </connection>
    245300</connections>
     
    259314    <include location="local" impldecl="in implementation">VBoxProblemReporter.h</include>
    260315    <include location="local" impldecl="in implementation">VBoxMediaComboBox.h</include>
    261     <include location="local" impldecl="in implementation">VBoxDiskImageManagerDlg.h</include>
     316    <include location="local" impldecl="in implementation">VBoxMediaManagerDlg.h</include>
    262317    <include location="local" impldecl="in implementation">VBoxNewHDWzd.h</include>
    263318    <include location="local" impldecl="in implementation">VBoxHardDiskSettings.ui.h</include>
     
    275330<signals>
    276331    <signal>afterCurrentChanged()</signal>
    277     <signal>hddListChanged()</signal>
     332    <signal>hardDiskListChanged()</signal>
    278333</signals>
    279334<slots>
    280335    <slot>addHDItem()</slot>
    281336    <slot>delHDItem()</slot>
    282     <slot>showVDM()</slot>
     337    <slot>showMediaManager()</slot>
    283338    <slot>moveFocus( QListViewItem *, const QPoint &amp;, int )</slot>
    284339    <slot>onCurrentChanged( QListViewItem * )</slot>
    285     <slot>onToggleSATAController( bool aOn )</slot>
     340    <slot>onSATACheckToggled( bool aOn )</slot>
     341    <slot>onShowDiffsCheckToggled( bool aOn )</slot>
    286342    <slot>onAfterCurrentChanged( QListViewItem * )</slot>
    287343    <slot>onContextMenuRequested( QListViewItem *, const QPoint &amp;, int )</slot>
     
    293349    <function>putBackToMachine()</function>
    294350    <function returnType="QString">checkValidity()</function>
    295     <function access="private" returnType="HDListItem*">createItem( HDSlotUniquizer *, const CMachine &amp; )</function>
     351    <function access="private" returnType="HDListItem*">createItem()</function>
    296352    <function access="private" returnType="bool">event( QEvent * )</function>
    297353    <function access="private">showEvent( QShowEvent * )</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxHardDiskSettings.ui.h

    r8576 r13580  
    148148
    149149/**
    150  *  QComboBox class reimplementation to use as selector for IDE & SATA
    151  *  slots.
     150 * QComboBox class reimplementation to use as an editor for the device slot
     151 * column.
    152152 */
    153153class HDSlotItem : public QComboBox
     
    258258};
    259259
    260 /**
    261  *  VBoxMediaComboBox class reimplementation to use as selector for VDI
    262  *  image.
    263  */
    264 class HDVdiItem : public VBoxMediaComboBox
    265 {
    266     Q_OBJECT
    267 
    268 public:
    269 
    270     HDVdiItem (QWidget *aParent, int aType, QListViewItem *aItem)
    271         : VBoxMediaComboBox (aParent, "HDVdiItem", aType)
    272         , mItem (aItem)
    273     {
    274         setFocusPolicy (QWidget::NoFocus);
    275         connect (&vboxGlobal(),
    276                  SIGNAL (mediaRemoved (VBoxDefs::DiskType, const QUuid &)),
    277                  this, SLOT (repaintHandler()));
    278     }
    279 
    280 private slots:
    281 
    282     void repaintHandler()
    283     {
    284         mItem->repaint();
    285     }
    286 
    287 private:
    288 
    289     QListViewItem *mItem;
    290 };
    291 
    292 QValueList<HDSlot> HDSlotUniquizer::list (HDSlotItem *aSubscriber, bool aFilter)
     260QValueList <HDSlot> HDSlotUniquizer::list (HDSlotItem *aSubscriber, bool aFilter)
    293261{
    294262    QValueList<HDSlot> list = mIDEList + mSATAList;
     
    316284}
    317285
     286/**
     287 * VBoxMediaComboBox class reimplementation to use as an editor for the hard
     288 * disk column.
     289 */
     290class HDItem : public VBoxMediaComboBox
     291{
     292    Q_OBJECT
     293
     294public:
     295
     296    HDItem (QWidget *aParent, const char *aName, QUuid aMachineID,
     297            QListViewItem *aItem)
     298        : VBoxMediaComboBox (aParent, aName, VBoxDefs::MediaType_HardDisk,
     299                             aMachineID)
     300        , mItem (aItem)
     301    {
     302        setFocusPolicy (QWidget::NoFocus);
     303
     304        connect (this, SIGNAL (activated (int)),
     305                 this, SLOT (onThisActivated (int)));
     306    }
     307
     308private slots:
     309
     310    void onThisActivated (int)
     311    {
     312        mItem->repaint();
     313    }
     314
     315private:
     316
     317    QListViewItem *mItem;
     318};
     319
    318320class HDSpaceItem : public QListViewItem
    319321{
     
    337339    enum { HDListItemType = 1010 };
    338340
    339     HDListItem (VBoxHardDiskSettings *aWidget, QListView *aParent,
    340                 QListViewItem *aAfter,
    341                 HDSlotUniquizer *aUniq, const CMachine &aMachine)
     341    HDListItem (QListView *aParent, QListViewItem *aAfter,
     342                VBoxHardDiskSettings *aSettings, HDSlotUniquizer *aUniq,
     343                const QUuid &aMachineId)
    342344        : QListViewItem (aParent, aAfter)
    343         , mWidget (aWidget)
    344         , mUniq (aUniq)
    345         , mMachine (aMachine)
    346345        , mFocusColumn (-1)
    347346        , mAutoFocus (false)
    348347    {
    349         init();
    350     }
    351 
    352     HDListItem (VBoxHardDiskSettings *aWidget, QListView *aParent,
    353                 HDSlotUniquizer *aUniq, const CMachine &aMachine)
     348        init (aSettings, aUniq, aMachineId);
     349    }
     350
     351    HDListItem (QListView *aParent,
     352                VBoxHardDiskSettings *aSettings, HDSlotUniquizer *aUniq,
     353                const QUuid &aMachineId)
    354354        : QListViewItem (aParent)
    355         , mWidget (aWidget)
    356         , mUniq (aUniq)
    357         , mMachine (aMachine)
    358355        , mFocusColumn (-1)
    359     {
    360         init();
     356        , mAutoFocus (false)
     357    {
     358        init (aSettings, aUniq, aMachineId);
     359    }
     360
     361    virtual ~HDListItem()
     362    {
     363        mHDCombo->deleteLater();
     364        mSlotCombo->deleteLater();
    361365    }
    362366
    363367    int rtti() const { return HDListItemType; }
    364368
    365     QString toolTip()
    366     {
    367         return QToolTip::textFor (mVector [1]);
    368     }
    369 
    370     HDListItem* nextSibling() const
    371     {
    372         QListViewItem *item = QListViewItem::nextSibling();
    373         return item && item->rtti() == HDListItemType ?
    374             static_cast<HDListItem*> (item) : 0;
    375     }
    376 
    377     void setId (const QUuid &aId) const
    378     {
    379         static_cast<VBoxMediaComboBox*> (mVector [1])->setCurrentItem (aId);
    380     }
    381 
    382     QUuid getId() const
    383     {
    384         return static_cast<VBoxMediaComboBox*> (mVector [1])->getId();
    385     }
    386 
    387     KStorageBus bus() const
    388     {
    389         return static_cast<HDSlotItem*> (mVector [0])->currentBus();
    390     }
    391 
    392     LONG channel() const
    393     {
    394         return static_cast<HDSlotItem*> (mVector [0])->currentChannel();
    395     }
    396 
    397     LONG device() const
    398     {
    399         return static_cast<HDSlotItem*> (mVector [0])->currentDevice();
    400     }
     369    QString toolTip() { return QToolTip::textFor (mHDCombo); }
     370
     371    void setId (const QUuid &aId) { mHDCombo->setCurrentItem (aId); }
     372
     373    QUuid id() const { return mHDCombo->id(); }
     374    QString location() const { return mHDCombo->location(); }
     375
     376    KStorageBus bus() { return mSlotCombo->currentBus(); }
     377
     378    LONG channel() const { return mSlotCombo->currentChannel(); }
     379
     380    LONG device() const { return mSlotCombo->currentDevice(); }
    401381
    402382    QString text (int aColumn) const
    403383    {
    404         return mVector [aColumn]->currentText();
     384        AssertReturn (aColumn >= 0 && (size_t) aColumn < ELEMENTS (mCombos),
     385                      QString::null);
     386
     387        return mCombos [aColumn]->currentText();
     388    }
     389
     390    const QPixmap *pixmap (int aColumn) const
     391    {
     392        AssertReturn (aColumn >= 0 && (size_t) aColumn < ELEMENTS (mCombos),
     393                      NULL);
     394
     395        return mCombos [aColumn]->pixmap (mCombos [aColumn]->currentItem());
    405396    }
    406397
     
    420411    {
    421412        if (mFocusColumn >= 0)
    422             if (mVector [mFocusColumn]->count())
    423                 mVector [mFocusColumn]->popup();
     413        {
     414            AssertReturnVoid ((size_t) mFocusColumn < ELEMENTS (mCombos));
     415
     416            if (mCombos [mFocusColumn]->count())
     417                mCombos [mFocusColumn]->popup();
     418        }
    424419    }
    425420
     
    429424    }
    430425
    431     void setAttachment (const CHardDiskAttachment &aHda)
     426    void setAttachment (const CHardDisk2Attachment &aHda)
    432427    {
    433428        QString device = vboxGlobal()
    434429            .toFullString (aHda.GetBus(), aHda.GetChannel(), aHda.GetDevice());
    435430
    436         if (mVector [0]->listBox()->findItem (device, Qt::ExactMatch))
    437             static_cast<HDSlotItem*> (mVector [0])->setText (device);
    438 
    439         static_cast<VBoxMediaComboBox*> (mVector [1])->
    440             setCurrentItem (aHda.GetHardDisk().GetRoot().GetId());
    441 
    442         mVector [0]->setHidden (true);
    443         mVector [1]->setHidden (true);
    444     }
    445 
    446     int vdiCount()
    447     {
    448         return mVector [1]->count();
    449     }
    450 
    451     void tryToChooseExcluding (const QStringList &aUsedList)
    452     {
    453         for (int i = 0; i < mVector [1]->count(); ++ i)
    454         {
    455             if (!aUsedList.contains (mVector [1]->text (i)))
    456             {
    457                 setId (static_cast<HDVdiItem*> (mVector [1])->getId (i));
     431        if (mSlotCombo->listBox()->findItem (device, Qt::ExactMatch))
     432            mSlotCombo->setText (device);
     433
     434        mHDCombo->setCurrentItem (aHda.GetHardDisk().GetId());
     435    }
     436
     437    int hardDiskCount()
     438    {
     439        int count = mHDCombo->count();
     440        if (count == 1 && mHDCombo-> id (0).isNull())
     441            return 0; /* ignore the "no media" item */
     442        return count;
     443    }
     444
     445    void tryToSelectNotOneOf (const QValueList <QUuid> &aUsedList)
     446    {
     447        for (int i = 0; i < mHDCombo->count(); ++ i)
     448        {
     449            if (!aUsedList.contains (mHDCombo->id (i)))
     450            {
     451                mHDCombo->setCurrentItem (mHDCombo->id (i));
    458452                break;
    459453            }
     
    461455    }
    462456
     457    void setShowDiffs (bool aOn)
     458    {
     459        if (mHDCombo->showDiffs() != aOn)
     460        {
     461            mHDCombo->setShowDiffs (aOn);
     462            mHDCombo->refresh();
     463        }
     464    }
     465
    463466private:
    464467
    465     void init()
    466     {
     468    void init (VBoxHardDiskSettings *aSettings, HDSlotUniquizer *aUniq,
     469               const QUuid &aMachineId)
     470    {
     471        AssertReturnVoid (listView()->columns() == ELEMENTS (mCombos));
     472
    467473        setSelectable (false);
    468         mVector.setAutoDelete (true);
    469         mVector.resize (listView()->columns());
    470 
    471         QComboBox *cbslot = new HDSlotItem (listView()->viewport(), mUniq);
    472         QObject::connect (cbslot, SIGNAL (activated (int)),
    473                           mWidget, SIGNAL (hddListChanged()));
    474         mVector.insert (0, cbslot);
    475 
    476         VBoxMediaComboBox *cbvdi = new HDVdiItem (listView()->viewport(),
    477                                                   VBoxDefs::HD, this);
    478         QObject::connect (cbvdi, SIGNAL (activated (int)),
    479                           mWidget, SIGNAL (hddListChanged()));
    480         mVector.insert (1, cbvdi);
    481         cbvdi->setBelongsTo (mMachine.GetId());
    482         cbvdi->refresh();
     474
     475        mSlotCombo = new HDSlotItem (listView()->viewport(), aUniq);
     476        QObject::connect (mSlotCombo, SIGNAL (activated (int)),
     477                          aSettings, SIGNAL (hardDiskListChanged()));
     478        mCombos [0] = mSlotCombo;
     479
     480        mHDCombo = new HDItem (listView()->viewport(), "mHDCombo",
     481                               aMachineId, this);
     482        QObject::connect (mHDCombo, SIGNAL (activated (int)),
     483                          aSettings, SIGNAL (hardDiskListChanged()));
     484        mCombos [1] = mHDCombo;
     485
     486        /* populate the media combobox */
     487        mHDCombo->refresh();
     488
    483489#ifdef Q_WS_MAC
    484490        /* White background on Mac OS X */
    485         cbslot->setPaletteBackgroundColor (cbslot->parentWidget()->paletteBackgroundColor());
    486         cbvdi->setPaletteBackgroundColor (cbvdi->parentWidget()->paletteBackgroundColor());
     491        mSlotCombo->setPaletteBackgroundColor (mSlotCombo->parentWidget()->
     492                                               paletteBackgroundColor());
     493        mHDCombo->setPaletteBackgroundColor (mHDCombo->parentWidget()->
     494                                             paletteBackgroundColor());
    487495#endif /* Q_WS_MAC */
     496
     497        mSlotCombo->setHidden (true);
     498        mHDCombo->setHidden (true);
    488499    }
    489500
     
    491502                    int aColumn, int aWidth, int aAlign)
    492503    {
    493         QComboBox *cb = mVector [aColumn];
    494 
    495         int indent = 0;
    496         for (int i = 0; i < aColumn; ++ i)
    497             indent = listView()->columnWidth (i);
    498 
    499         QRect rect = listView()->itemRect (this);
    500 
    501         int xc = rect.x() + indent;
    502         int yc = rect.y();
    503         int wc = listView()->columnWidth (aColumn);
    504         int hc = rect.height();
    505 
    506         cb->move (xc, yc);
    507         cb->resize (wc, hc);
     504        AssertReturnVoid (aColumn >= 0 && (size_t) aColumn < ELEMENTS (mCombos));
     505
     506        QComboBox *cb = mCombos [aColumn];
     507
     508        /// @todo (r=dmik) show/hide functionality should be removed from here
     509        /// to the appropriate places like focus handling routines
    508510
    509511        if (aColumn == mFocusColumn)
    510512        {
     513            int indent = 0;
     514            for (int i = 0; i < aColumn; ++ i)
     515                indent = listView()->columnWidth (i);
     516
     517            QRect rect = listView()->itemRect (this);
     518
     519            int xc = rect.x() + indent;
     520            int yc = rect.y();
     521            int wc = listView()->columnWidth (aColumn);
     522            int hc = rect.height();
     523
     524            cb->move (xc, yc);
     525            cb->resize (wc, hc);
     526
    511527            if (cb->isHidden())
    512528                cb->show();
    513529            if (mAutoFocus && !cb->hasFocus())
    514530                QTimer::singleShot (0, cb, SLOT (setFocus()));
    515         }
    516         else if (aColumn != mFocusColumn && !cb->isHidden())
     531
     532            return;
     533
     534        }
     535
     536        if (aColumn != mFocusColumn && !cb->isHidden())
    517537            cb->hide();
    518538
     
    532552    }
    533553
    534     VBoxHardDiskSettings  *mWidget;
    535     HDSlotUniquizer       *mUniq;
    536     CMachine               mMachine;
    537     QPtrVector<QComboBox>  mVector;
     554    HDSlotItem            *mSlotCombo;
     555    VBoxMediaComboBox     *mHDCombo;
     556    QComboBox             *mCombos [2];
    538557    int                    mFocusColumn;
    539558    bool                   mAutoFocus;
     
    585604        (VBoxGlobal::iconSet ("select_file_16px.png", "select_file_dis_16px.png"));
    586605
    587     /* connections */
    588     connect (mCbSATA, SIGNAL (toggled (bool)),
    589              this, SLOT (onToggleSATAController (bool)));
    590     connect (mLvHD, SIGNAL (pressed (QListViewItem*, const QPoint&, int)),
    591              this, SLOT (moveFocus (QListViewItem*, const QPoint&, int)));
    592     connect (mLvHD, SIGNAL (currentChanged (QListViewItem*)),
    593              this, SLOT (onCurrentChanged (QListViewItem*)));
    594     connect (mLvHD, SIGNAL (contextMenuRequested (QListViewItem*, const QPoint&, int)),
    595              this, SLOT (onContextMenuRequested (QListViewItem*, const QPoint&, int)));
    596 
    597606    /* rest */
    598607
     
    606615void VBoxHardDiskSettings::getFromMachine (const CMachine &aMachine)
    607616{
     617    AssertReturnVoid (mMachine.isNull());
     618    AssertReturnVoid (!aMachine.isNull());
     619
    608620    mMachine = aMachine;
    609621
     
    614626            /* hide the SATA check box if the SATA controller is not available
    615627             * (i.e. in VirtualBox OSE) */
    616             mCbSATA->setHidden (true);
     628            mSATACheck->setHidden (true);
    617629        }
    618630        else
    619631        {
    620             mCbSATA->setChecked (ctl.GetEnabled());
    621         }
    622     }
    623 
    624     CHardDiskAttachmentEnumerator en =
    625         mMachine.GetHardDiskAttachments().Enumerate();
    626     while (en.HasMore())
    627     {
    628         CHardDiskAttachment hda = en.GetNext();
    629         HDListItem *item = createItem (mSlotUniquizer, mMachine);
     632            mSATACheck->setChecked (ctl.GetEnabled());
     633        }
     634    }
     635
     636    CHardDisk2AttachmentVector vec = mMachine.GetHardDisk2Attachments();
     637    for (size_t i = 0; i < vec.size(); ++ i)
     638    {
     639        CHardDisk2Attachment hda = vec [i];
     640        HDListItem *item = createItem();
    630641        item->setAttachment (hda);
    631642    }
     643
    632644    mLvHD->setSortColumn (0);
    633645    mLvHD->sort();
     
    642654    if (!ctl.isNull())
    643655    {
    644         ctl.SetEnabled (mCbSATA->isChecked());
     656        ctl.SetEnabled (mSATACheck->isChecked());
    645657    }
    646658
    647659    /* Detach all attached Hard Disks */
    648     CHardDiskAttachmentEnumerator en =
    649         mMachine.GetHardDiskAttachments().Enumerate();
    650     while (en.HasMore())
    651     {
    652         CHardDiskAttachment hda = en.GetNext();
    653         mMachine.DetachHardDisk (hda.GetBus(), hda.GetChannel(), hda.GetDevice());
     660    CHardDisk2AttachmentVector vec = mMachine.GetHardDisk2Attachments();
     661    for (size_t i = 0; i < vec.size(); ++ i)
     662    {
     663        CHardDisk2Attachment hda = vec [i];
     664        mMachine.DetachHardDisk2 (hda.GetBus(), hda.GetChannel(), hda.GetDevice());
    654665        if (!mMachine.isOk())
    655666            vboxProblem().cannotDetachHardDisk (this, mMachine,
     667                vboxGlobal().getMedium (CMedium (hda.GetHardDisk())).location(),
    656668                hda.GetBus(), hda.GetChannel(), hda.GetDevice());
    657669    }
    658670
    659     /* Sort&Attach all listed Hard Disks */
     671    /* Sort & attach all listed Hard Disks */
     672
    660673    mLvHD->setSortColumn (0);
    661674    mLvHD->sort();
    662675    LONG maxSATAPort = 1;
    663     HDListItem *item = mLvHD->firstChild() &&
    664         mLvHD->firstChild()->rtti() == HDListItem::HDListItemType ?
    665         static_cast<HDListItem*> (mLvHD->firstChild()) : 0;
    666     while (item)
    667     {
    668         if (item->bus() == KStorageBus_SATA)
    669             maxSATAPort = maxSATAPort < (item->channel()+1) ?
    670                           (item->channel()+1) : maxSATAPort;
    671         mMachine.AttachHardDisk (item->getId(),
    672             item->bus(), item->channel(), item->device());
     676
     677    for (QListViewItem *item = mLvHD->firstChild(); item;
     678         item = item->nextSibling())
     679    {
     680        if (item->rtti() != HDListItem::HDListItemType)
     681            continue;
     682
     683        HDListItem *hdi = static_cast <HDListItem *> (item);
     684
     685        if (hdi->bus() == KStorageBus_SATA)
     686            maxSATAPort = QMAX (hdi->channel() + 1, maxSATAPort);
     687        mMachine.AttachHardDisk2 (hdi->id(),
     688            hdi->bus(), hdi->channel(), hdi->device());
    673689        if (!mMachine.isOk())
    674             vboxProblem().cannotAttachHardDisk (this, mMachine, item->getId(),
    675                 item->bus(), item->channel(), item->device());
    676         item = item->nextSibling();
     690            vboxProblem().cannotAttachHardDisk (this, mMachine,
     691                hdi->location(), hdi->bus(), hdi->channel(), hdi->device());
    677692    }
    678693
    679694    if (!ctl.isNull())
    680695    {
    681         mMachine.GetSATAController().SetPortCount (maxSATAPort);
     696        ctl.SetPortCount (maxSATAPort);
    682697    }
    683698}
     
    687702    QString result;
    688703    QStringList slList;
    689     QStringList idList;
     704    QValueList <QUuid> idList;
    690705
    691706    /* Search for coincidences through all the media-id */
    692     HDListItem *item = mLvHD->firstChild() &&
    693         mLvHD->firstChild()->rtti() == HDListItem::HDListItemType ?
    694         static_cast<HDListItem*> (mLvHD->firstChild()) : 0;
    695     while (item)
    696     {
    697         QString id = item->getId().toString();
    698         if (item->getId().isNull())
     707    for (QListViewItem *item = mLvHD->firstChild(); item;
     708         item = item->nextSibling())
     709    {
     710        if (item->rtti() != HDListItem::HDListItemType)
     711            continue;
     712
     713        HDListItem *hdi = static_cast <HDListItem *> (item);
     714
     715        QUuid id = hdi->id();
     716        if (id.isNull())
    699717        {
    700718            result = tr ("No hard disk is selected for <i>%1</i>")
    701                 .arg (item->text (0));
     719                .arg (hdi->text (0));
    702720            break;
    703721        }
     
    714732            idList << id;
    715733        }
    716         item = item->nextSibling();
    717734    }
    718735
     
    722739void VBoxHardDiskSettings::addHDItem()
    723740{
    724     /* Create new item */
    725     HDListItem *item = createItem (mSlotUniquizer, mMachine);
     741    /* Create a new item */
     742    HDListItem *item = createItem();
    726743    item->moveFocusToColumn (1);
    727744    mLvHD->setCurrentItem (item);
    728745    if (!mLvHD->hasFocus())
    729746        mLvHD->setFocus();
    730     /* Qt3 isn't emits currentChanged() signal if first list-view item added */
     747
     748    /* Qt3 doesn't emit currentChanged() signal when the first item is added */
    731749    if (mLvHD->childCount() == 1)
    732750        onCurrentChanged (item);
    733751
    734     /* Search through the attachments for the used VDIs */
    735     QStringList usedList;
    736     HDListItem *it = mLvHD->firstChild()->rtti() == HDListItem::HDListItemType ?
    737         static_cast<HDListItem*> (mLvHD->firstChild()) : 0;
    738     while (it && it != item)
    739     {
    740         usedList << it->text (1);
    741         it = it->nextSibling();
    742     }
    743     item->tryToChooseExcluding (usedList);
    744 
    745     /* Ask the user for method to add new vdi */
    746     int result = mLvHD->childCount() - 1 > item->vdiCount() ?
     752    /* Search through the attachments for the used hard disks */
     753    QValueList <QUuid> usedList;
     754    for (QListViewItem *it = mLvHD->firstChild(); it;
     755         it = it->nextSibling())
     756    {
     757        if (it->rtti() != HDListItem::HDListItemType)
     758            continue;
     759
     760        HDListItem *hdi = static_cast <HDListItem *> (it);
     761
     762        usedList << hdi->id();
     763    }
     764
     765    item->tryToSelectNotOneOf (usedList);
     766
     767    /* Ask the user for a method to add a new hard disk */
     768    int result = mLvHD->childCount() - 1 > item->hardDiskCount() ?
    747769        vboxProblem().confirmRunNewHDWzdOrVDM (this) :
    748770        QIMessageBox::Cancel;
     
    752774        if (dlg.exec() == QDialog::Accepted)
    753775        {
    754             CHardDisk hd = dlg.hardDisk();
    755             VBoxMedia::Status status =
    756                 hd.GetAccessible() ? VBoxMedia::Ok :
    757                 hd.isOk() ? VBoxMedia::Inaccessible :
    758                 VBoxMedia::Error;
    759             vboxGlobal().addMedia (VBoxMedia (CUnknown (hd), VBoxDefs::HD, status));
     776            CHardDisk2 hd = dlg.hardDisk();
    760777            item->setId (dlg.hardDisk().GetId());
    761778        }
    762779    }
    763780    else if (result == QIMessageBox::No)
    764         showVDM();
    765 
    766     emit hddListChanged();
     781        showMediaManager();
     782
     783    emit hardDiskListChanged();
    767784}
    768785
     
    786803    }
    787804
    788     emit hddListChanged();
    789 }
    790 
    791 void VBoxHardDiskSettings::showVDM()
     805    emit hardDiskListChanged();
     806}
     807
     808void VBoxHardDiskSettings::showMediaManager()
    792809{
    793810    HDListItem *item = mLvHD->currentItem() &&
    794811        mLvHD->currentItem()->rtti() == HDListItem::HDListItemType ?
    795         static_cast<HDListItem*> (mLvHD->currentItem()) : 0;
    796 
    797     VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
    798                                  WType_Dialog | WShowModal);
    799 
    800     QUuid machineId = mMachine.GetId();
    801     QUuid hdId = item->getId();
    802 
    803     dlg.setup (VBoxDefs::HD, true, &machineId, true /* aRefresh */,
    804                mMachine, hdId, QUuid(), QUuid());
    805 
    806     if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
    807         item->setId (dlg.getSelectedUuid());
     812        static_cast <HDListItem *> (mLvHD->currentItem()) : 0;
     813
     814    VBoxMediaManagerDlg dlg (this, "VBoxMediaManagerDlg",
     815                             WType_Dialog | WShowModal);
     816
     817    dlg.setup (VBoxDefs::MediaType_HardDisk, true /* aDoSelect */,
     818               true /* aRefresh */, mMachine, item->id(),
     819               mShowDiffsCheck->isOn());
     820
     821    if (dlg.exec() == VBoxMediaManagerDlg::Accepted)
     822        item->setId (dlg.selectedId());
    808823}
    809824
     
    812827    if (aItem && aItem->rtti() == HDListItem::HDListItemType)
    813828    {
    814         static_cast<HDListItem*> (aItem)->moveFocusToColumn (aCol);
     829        static_cast <HDListItem *> (aItem)->moveFocusToColumn (aCol);
    815830        onAfterCurrentChanged (aItem);
    816831    }
     
    823838}
    824839
    825 void VBoxHardDiskSettings::onToggleSATAController (bool aOn)
     840void VBoxHardDiskSettings::onSATACheckToggled (bool aOn)
    826841{
    827842    if (!aOn)
    828843    {
    829         HDListItem *firstItem = mLvHD->firstChild() &&
    830             mLvHD->firstChild()->rtti() == HDListItem::HDListItemType ?
    831             static_cast<HDListItem*> (mLvHD->firstChild()) : 0;
    832 
    833         /* Search the list for the SATA ports in */
    834         HDListItem *sataItem = firstItem;
    835         while (sataItem)
    836         {
    837             if (sataItem->bus() == KStorageBus_SATA)
     844        /* Search the list for the SATA ports */
     845        HDListItem *sataItem = NULL;
     846        for (QListViewItem *item = mLvHD->firstChild(); item;
     847             item = item->nextSibling())
     848        {
     849            if (item->rtti() != HDListItem::HDListItemType)
     850                continue;
     851
     852            HDListItem *hdi = static_cast <HDListItem *> (item);
     853
     854            if (hdi->bus() == KStorageBus_SATA)
     855            {
     856                sataItem = hdi;
    838857                break;
    839             sataItem = sataItem->nextSibling();
     858            }
    840859        }
    841860
     
    847866            {
    848867                /* Switch check-box back to "on" */
    849                 mCbSATA->blockSignals (true);
    850                 mCbSATA->setChecked (true);
    851                 mCbSATA->blockSignals (false);
     868                mSATACheck->blockSignals (true);
     869                mSATACheck->setChecked (true);
     870                mSATACheck->blockSignals (false);
    852871                return;
    853872            }
     
    855874            {
    856875                /* Delete SATA items */
    857                 HDListItem *it = firstItem;
    858876                mLvHD->blockSignals (true);
    859                 while (it)
     877                for (QListViewItem *item = mLvHD->firstChild(); item;)
    860878                {
    861                     HDListItem *curIt = it;
    862                     it = it->nextSibling();
    863                     if (curIt->bus() == KStorageBus_SATA)
     879                    if (item->rtti() == HDListItem::HDListItemType)
    864880                    {
    865                         if (curIt == mLvHD->currentItem())
    866                             mPrevItem = 0;
    867                         delete curIt;
     881                        HDListItem *hdi = static_cast <HDListItem *> (item);
     882                        if (hdi->bus() == KStorageBus_SATA)
     883                        {
     884                            if (hdi == mLvHD->currentItem())
     885                                mPrevItem = NULL;
     886
     887                            item = hdi->nextSibling();
     888                            delete hdi;
     889                            continue;
     890                        }
    868891                    }
     892
     893                    item = item->nextSibling();
    869894                }
     895
    870896                mLvHD->blockSignals (false);
    871                 emit hddListChanged();
     897                emit hardDiskListChanged();
    872898            }
    873899        }
     
    879905        mSlotUniquizer->setSATAPortsCount (newSATAPortsCount);
    880906        onAfterCurrentChanged (mPrevItem);
     907    }
     908}
     909
     910void VBoxHardDiskSettings::onShowDiffsCheckToggled (bool aOn)
     911{
     912    for (QListViewItem *item = mLvHD->firstChild(); item;
     913         item = item->nextSibling())
     914    {
     915        if (item->rtti() != HDListItem::HDListItemType)
     916            continue;
     917
     918        HDListItem *hdi = static_cast <HDListItem *> (item);
     919
     920        hdi->setShowDiffs (aOn);
    881921    }
    882922}
     
    916956}
    917957
    918 HDListItem* VBoxHardDiskSettings::createItem (HDSlotUniquizer *aUniq,
    919                                               const CMachine &aMachine)
     958HDListItem *VBoxHardDiskSettings::createItem()
    920959{
    921960    QListViewItem *item = mLvHD->lastItem();
     
    923962    HDListItem *last = item->itemAbove() &&
    924963        item->itemAbove()->rtti() == HDListItem::HDListItemType ?
    925         static_cast<HDListItem*> (item->itemAbove()) : 0;
    926 
    927     return last ?
    928         new HDListItem (this, mLvHD, last, aUniq, aMachine) :
    929         new HDListItem (this, mLvHD, aUniq, aMachine);
     964        static_cast <HDListItem *> (item->itemAbove()) : 0;
     965
     966    QUuid machineId = mMachine.GetId();
     967
     968    HDListItem *newItem = last ?
     969        new HDListItem (mLvHD, last, this, mSlotUniquizer, machineId) :
     970        new HDListItem (mLvHD, this, mSlotUniquizer, machineId);
     971
     972    AssertReturn (newItem != NULL, NULL);
     973
     974    newItem->setShowDiffs (mShowDiffsCheck->isOn());
     975
     976    return newItem;
    930977}
    931978
     
    937984        case OnItemChangedEvent::Type:
    938985        {
    939             OnItemChangedEvent *e = static_cast<OnItemChangedEvent*> (aEvent);
     986            OnItemChangedEvent *e = static_cast <OnItemChangedEvent *> (aEvent);
    940987            onAfterCurrentChanged (e->mItem);
    941988            break;
     
    9741021            HDListItem *item = clickedItem &&
    9751022                clickedItem->rtti() == HDListItem::HDListItemType ?
    976                 static_cast<HDListItem*> (clickedItem) : 0;
     1023                static_cast <HDListItem *> (clickedItem) : 0;
    9771024
    9781025            if (!item && mAddAttachmentAct->isEnabled())
     
    9901037            }
    9911038
    992             QMouseEvent *e = static_cast<QMouseEvent*> (aEvent);
     1039            QMouseEvent *e = static_cast <QMouseEvent *> (aEvent);
    9931040            QListViewItem *hoveredItem = mLvHD->itemAt (e->pos());
    9941041            HDListItem *item = hoveredItem &&
    9951042                hoveredItem->rtti() == HDListItem::HDListItemType ?
    996                 static_cast<HDListItem*> (hoveredItem) : 0;
     1043                static_cast <HDListItem *> (hoveredItem) : 0;
    9971044
    9981045            QString oldTip = QToolTip::textFor (mLvHD->viewport());
     
    10141061            HDListItem *item = mLvHD->currentItem() &&
    10151062                mLvHD->currentItem()->rtti() == HDListItem::HDListItemType ?
    1016                 static_cast<HDListItem*> (mLvHD->currentItem()) : 0;
     1063                static_cast <HDListItem *> (mLvHD->currentItem()) : 0;
    10171064
    10181065            QKeyEvent *e = static_cast<QKeyEvent*> (aEvent);
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewHDWzd.ui

    r11982 r13580  
    55:folding=explicit:collapseFolds=1:
    66
    7      Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7     Copyright (C) 2006-2008 Sun Microsystems, Inc.
    88
    99     This file is part of VirtualBox Open Source Edition (OSE), as
     
    9898                        </property>
    9999                        <property name="text">
    100                             <string>&lt;p&gt;This wizard will help you to create a new virtual hard disk image for your virtual machine.&lt;/p&gt;
     100                            <string>&lt;p&gt;This wizard will help you to create a new virtual hard disk for your virtual machine.&lt;/p&gt;
    101101&lt;p&gt;Use the &lt;b&gt;Next&lt;/b&gt; button to go to the next page of the wizard
    102102and the &lt;b&gt;Back&lt;/b&gt; button to return to the previous page.&lt;/p&gt;</string>
     
    149149        </property>
    150150        <attribute name="title">
    151             <string>Virtual Disk Image Type</string>
     151            <string>Hard Disk Storage Type</string>
    152152        </attribute>
    153153        <hbox>
     
    204204                        </property>
    205205                        <property name="text">
    206                             <string>&lt;p&gt;Select the type of virtual hard disk image you want to create.&lt;/p&gt;
    207 &lt;p&gt;A &lt;b&gt;dynamically expanding image&lt;/b&gt; initially occupies a very small amount
     206                            <string>&lt;p&gt;Select the type of virtual hard disk you want to create.&lt;/p&gt;
     207&lt;p&gt;A &lt;b&gt;dynamically expanding storage&lt;/b&gt; initially occupies a very small amount
    208208of space on your physical hard disk. It will grow dynamically (up to
    209209the size specified) as the Guest OS claims disk space.&lt;/p&gt;
    210 &lt;p&gt;A &lt;b&gt;fixed-size image&lt;/b&gt; does not grow. It is stored in a file of approximately
    211 the same size as the size of the virtual hard disk. The creation of a fixed-size image may take a long
    212 time depending on the image size and the write performance of your harddisk.&lt;/p&gt;</string>
     210&lt;p&gt;A &lt;b&gt;fixed-size storage&lt;/b&gt; does not grow. It is stored in a file of approximately
     211the same size as the size of the virtual hard disk. The creation of a fixed-size storage may take a long
     212time depending on the storage size and the write performance of your harddisk.&lt;/p&gt;</string>
    213213                        </property>
    214214                        <property name="alignment">
     
    221221                        </property>
    222222                        <property name="title">
    223                             <string>Image Type</string>
     223                            <string>Storage Type</string>
    224224                        </property>
    225225                        <property name="exclusive">
     
    235235                                </property>
    236236                                <property name="text">
    237                                     <string>&amp;Dynamically expanding image</string>
     237                                    <string>&amp;Dynamically expanding storage</string>
    238238                                </property>
    239239                                <property name="checked">
     
    246246                                </property>
    247247                                <property name="text">
    248                                     <string>&amp;Fixed-size image</string>
     248                                    <string>&amp;Fixed-size storage</string>
    249249                                </property>
    250250                            </widget>
     
    329329                        </property>
    330330                        <property name="text">
    331                             <string>&lt;p&gt;Press the &lt;b&gt;Select&lt;/b&gt; button to select the location and name of the file
    332 to store the virtual hard disk image or type a file name in the entry field.&lt;/p&gt;</string>
     331                            <string>&lt;p&gt;Press the &lt;b&gt;Select&lt;/b&gt; button to select the location of a file
     332to store the hard disk data or type a file name in the entry field.&lt;/p&gt;</string>
    333333                        </property>
    334334                        <property name="alignment">
     
    341341                        </property>
    342342                        <property name="title">
    343                             <string>&amp;Image File Name</string>
     343                            <string>&amp;Location</string>
    344344                        </property>
    345345                        <hbox>
     
    393393                        </property>
    394394                        <property name="text">
    395                             <string>&lt;p&gt;Select the size of the virtual hard disk image in megabytes. This size will be reported to the Guest OS
    396 as the size of the virtual hard disk.&lt;/p&gt;</string>
     395                            <string>&lt;p&gt;Select the size of the virtual hard disk in megabytes. This size will be reported to the Guest OS
     396as the maximum size of this hard disk.&lt;/p&gt;</string>
    397397                        </property>
    398398                        <property name="alignment">
     
    405405                        </property>
    406406                        <property name="title">
    407                             <string>Image &amp;Size</string>
     407                            <string>&amp;Size</string>
    408408                        </property>
    409409                        <hbox>
     
    624624                        </property>
    625625                        <property name="text">
    626                             <string>You are going to create a new virtual hard disk image with the following parameters:</string>
     626                            <string>You are going to create a new virtual hard disk with the following parameters:</string>
    627627                        </property>
    628628                        <property name="alignment">
     
    644644                        <property name="text">
    645645                            <string>If the above settings are correct, press the &lt;b&gt;Finish&lt;/b&gt; button.
    646                             Once you press it, a new hard disk image will be created.
     646                            Once you press it, a new hard disk will be created.
    647647                            </string>
    648648                        </property>
     
    708708    <include location="global" impldecl="in implementation">qvalidator.h</include>
    709709    <include location="global" impldecl="in implementation">qlocale.h</include>
     710    <include location="global" impldecl="in implementation">iprt/path.h</include>
    710711</includes>
    711712<forwards>
     
    713714</forwards>
    714715<variables>
    715     <variable access="private">QIWidgetValidator *wvalNameAndSize;</variable>
    716     <variable access="private">CHardDisk chd;</variable>
    717     <variable access="private">int sliderScale;</variable>
    718     <variable access="private">Q_UINT64 maxVDISize;</variable>
    719     <variable access="private">Q_UINT64 currentSize;</variable>
    720     <variable access="private">QITextEdit *teSummary;</variable>
     716    <variable access="private">QIWidgetValidator *mWValNameAndSize;</variable>
     717    <variable access="private">CHardDisk2 mHD;</variable>
     718    <variable access="private">int mSliderScale;</variable>
     719    <variable access="private">Q_UINT64 mMaxVDISize;</variable>
     720    <variable access="private">Q_UINT64 mCurrentSize;</variable>
     721    <variable access="private">QITextEdit *mSummaryText;</variable>
    721722</variables>
    722723<slots>
    723     <slot>enableNext( const QIWidgetValidator * wval )</slot>
     724    <slot>enableNext( const QIWidgetValidator * )</slot>
    724725    <slot>revalidate( QIWidgetValidator * )</slot>
    725     <slot>slSize_valueChanged( int val )</slot>
    726     <slot>leSize_textChanged( const QString &amp; text )</slot>
     726    <slot>slSize_valueChanged( int )</slot>
     727    <slot>leSize_textChanged( const QString &amp; )</slot>
    727728    <slot>tbNameSelect_clicked()</slot>
    728729</slots>
     
    732733    <function>setRecommendedFileName( const QString &amp; aName )</function>
    733734    <function>setRecommendedSize( Q_UINT64 aSize )</function>
    734     <function returnType="QString">imageFileName()</function>
    735     <function returnType="Q_UINT64">imageSize()</function>
    736     <function returnType="bool">isDynamicImage()</function>
    737     <function returnType="CHardDisk">hardDisk() { return chd; }</function>
    738     <function>showPage( QWidget * page )</function>
    739     <function>updateSizeToolTip (Q_UINT64)</function>
     735    <function returnType="QString">location()</function>
     736    <function returnType="bool">isDynamicStorage()</function>
     737    <function returnType="CHardDisk2">hardDisk() { return mHD; }</function>
     738    <function>showPage( QWidget * )</function>
     739    <function>updateSizeToolTip( Q_UINT64 )</function>
    740740    <function>accept()</function>
    741741    <function access="private" returnType="bool">createHardDisk()</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewHDWzd.ui.h

    r8155 r13580  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4040
    4141/**
    42  *  Composes a file name from the given relative or full file name
    43  *  based on the home directory and the default VDI directory.
     42 * Composes a file name from the given relative or full file name based on the
     43 * home directory and the default VDI directory. See IMedum::location for
     44 * details.
    4445 */
    45 static QString composeFullFileName (const QString file)
     46static QString composeFullFileName (const QString &aName)
    4647{
    4748    CVirtualBox vbox = vboxGlobal().virtualBox();
    4849    QString homeFolder = vbox.GetHomeFolder();
    49     QString defaultFolder = vbox.GetSystemProperties().GetDefaultVDIFolder();
    50 
    51     QFileInfo fi = QFileInfo (file);
    52     if (fi.fileName() == file)
     50    QString defaultFolder = vbox.GetSystemProperties().GetDefaultHardDiskFolder();
     51
     52    /* Note: the logic below must match the logic of the IMedum::location
     53     * setter, otherwise the returned path may differ from the path actually
     54     * set for the hard disk by the VirtualBox API */
     55
     56    QFileInfo fi (aName);
     57    if (fi.fileName() == aName)
    5358    {
    5459        /* no path info at all, use defaultFolder */
    55         fi = QFileInfo (defaultFolder, file);
     60        fi = QFileInfo (defaultFolder, aName);
    5661    }
    5762    else if (fi.isRelative())
    5863    {
    5964        /* resolve relatively to homeFolder */
    60         fi = QFileInfo (homeFolder, file);
     65        fi = QFileInfo (homeFolder, aName);
    6166    }
    6267
    6368    return QDir::convertSeparators (fi.absFilePath());
    6469}
    65 
    66 /// @todo (r=dmik) not currently used
    67 #if 0
    68 class QISizeValidator : public QValidator
    69 {
    70 public:
    71 
    72     QISizeValidator (QObject * aParent,
    73                      Q_UINT64 aMinSize, Q_UINT64 aMaxSize,
    74                      const char * aName = 0) :
    75         QValidator (aParent, aName), mMinSize (aMinSize), mMaxSize (aMaxSize) {}
    76 
    77     ~QISizeValidator() {}
    78 
    79     State validate (QString &input, int &/*pos*/) const
    80     {
    81         QRegExp regexp ("^([^M^G^T^P^\\d\\s]*)(\\d+(([^\\s^\\d^M^G^T^P]+)(\\d*))?)?(\\s*)([MGTP]B?)?$");
    82         int position = regexp.search (input);
    83         if (position == -1)
    84             return Invalid;
    85         else
    86         {
    87             if (!regexp.cap (1).isEmpty() ||
    88                  regexp.cap (4).length() > 1 ||
    89                  regexp.cap (5).length() > 2 ||
    90                  regexp.cap (6).length() > 1)
    91                 return Invalid;
    92 
    93             if (regexp.cap (7).length() == 1)
    94                 return Intermediate;
    95 
    96             QString size = regexp.cap (2);
    97             if (size.isEmpty())
    98                 return Intermediate;
    99 
    100             bool result = false;
    101             bool warning = false;
    102             if (!regexp.cap (4).isEmpty() && regexp.cap (5).isEmpty())
    103             {
    104                 size += "0";
    105                 warning = true;
    106             }
    107             QLocale::system().toDouble (size, &result);
    108 
    109             Q_UINT64 sizeB = vboxGlobal().parseSize (input);
    110             if (sizeB > mMaxSize || sizeB < mMinSize)
    111                 warning = true;
    112 
    113             if (result)
    114                 return warning ? Intermediate : Acceptable;
    115             else
    116                 return Invalid;
    117         }
    118     }
    119 
    120 protected:
    121 
    122     Q_UINT64 mMinSize;
    123     Q_UINT64 mMaxSize;
    124 };
    125 #endif
    12670
    12771static inline int log2i (Q_UINT64 val)
     
    15599}
    156100
     101
     102////////////////////////////////////////////////////////////////////////////////
     103
     104
    157105void VBoxNewHDWzd::init()
    158106{
     
    175123    VBoxGlobal::adoptLabelPixmap (pmSummary);
    176124
    177     /* Image type page */
     125    /* Storage type page */
    178126
    179127    /* Name and Size page */
     
    181129    CSystemProperties sysProps = vboxGlobal().virtualBox().GetSystemProperties();
    182130
    183     maxVDISize = sysProps.GetMaxVDISize();
     131    mMaxVDISize = sysProps.GetMaxVDISize();
    184132
    185133    /* Detect how many steps to recognize between adjacent powers of 2
    186      * to ensure that the last slider step is exactly maxVDISize */
    187     sliderScale = 0;
    188     {
    189         int pow = log2i (maxVDISize);
     134     * to ensure that the last slider step is exactly mMaxVDISize */
     135    mSliderScale = 0;
     136    {
     137        int pow = log2i (mMaxVDISize);
    190138        Q_UINT64 tickMB = Q_UINT64 (1) << pow;
    191         if (tickMB < maxVDISize)
     139        if (tickMB < mMaxVDISize)
    192140        {
    193141            Q_UINT64 tickMBNext = Q_UINT64 (1) << (pow + 1);
    194             Q_UINT64 gap = tickMBNext - maxVDISize;
    195             /// @todo (r=dmik) overflow may happen if maxVDISize is TOO big
    196             sliderScale = (int) ((tickMBNext - tickMB) / gap);
     142            Q_UINT64 gap = tickMBNext - mMaxVDISize;
     143            /// @todo (r=dmik) overflow may happen if mMaxVDISize is TOO big
     144            mSliderScale = (int) ((tickMBNext - tickMB) / gap);
    197145        }
    198146    }
    199     sliderScale = QMAX (sliderScale, 8);
     147    mSliderScale = QMAX (mSliderScale, 8);
    200148
    201149    leName->setValidator (new QRegExpValidator (QRegExp( ".+" ), this));
     
    204152    leSize->setAlignment (Qt::AlignRight);
    205153
    206     wvalNameAndSize = new QIWidgetValidator (pageNameAndSize, this);
    207     connect (wvalNameAndSize, SIGNAL (validityChanged (const QIWidgetValidator *)),
     154    mWValNameAndSize = new QIWidgetValidator (pageNameAndSize, this);
     155    connect (mWValNameAndSize, SIGNAL (validityChanged (const QIWidgetValidator *)),
    208156             this, SLOT (enableNext (const QIWidgetValidator *)));
    209     connect (wvalNameAndSize, SIGNAL (isValidRequested (QIWidgetValidator *)),
     157    connect (mWValNameAndSize, SIGNAL (isValidRequested (QIWidgetValidator *)),
    210158             this, SLOT (revalidate (QIWidgetValidator *)));
    211     /* we ask revalidate only when currentSize is changed after manually
     159    /* we ask revalidate only when mCurrentSize is changed after manually
    212160     * editing the line edit field; the slider cannot produce invalid values */
    213161    connect (leSize, SIGNAL (textChanged (const QString &)),
    214              wvalNameAndSize, SLOT (revalidate()));
     162             mWValNameAndSize, SLOT (revalidate()));
    215163
    216164    /* Summary page */
    217165
    218     teSummary = new QITextEdit (pageSummary);
    219     teSummary->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
    220     teSummary->setFrameShape (QTextEdit::NoFrame);
    221     teSummary->setReadOnly (TRUE);
    222     summaryLayout->insertWidget (1, teSummary);
     166    mSummaryText = new QITextEdit (pageSummary);
     167    mSummaryText->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
     168    mSummaryText->setFrameShape (QTextEdit::NoFrame);
     169    mSummaryText->setReadOnly (TRUE);
     170    summaryLayout->insertWidget (1, mSummaryText);
    223171
    224172    /* filter out Enter keys in order to direct them to the default dlg button */
    225173    QIKeyFilter *ef = new QIKeyFilter (this, Key_Enter);
    226     ef->watchOn (teSummary);
     174    ef->watchOn (mSummaryText);
    227175
    228176    /* set initial values
    229177     * ---------------------------------------------------------------------- */
    230178
    231     /* Image type page */
     179    /* Storage type page */
    232180
    233181    /* Name and Size page */
     182
     183    /// @todo NEWMEDIA use extension as reported by CHardDiskFormat
    234184
    235185    static ulong HDNumber = 0;
     
    237187
    238188    slSize->setFocusPolicy (QWidget::StrongFocus);
    239     slSize->setPageStep (sliderScale);
    240     slSize->setLineStep (sliderScale / 8);
     189    slSize->setPageStep (mSliderScale);
     190    slSize->setLineStep (mSliderScale / 8);
    241191    slSize->setTickInterval (0);
    242     slSize->setMinValue (sizeMBToSlider (MinVDISize, sliderScale));
    243     slSize->setMaxValue (sizeMBToSlider (maxVDISize, sliderScale));
     192    slSize->setMinValue (sizeMBToSlider (MinVDISize, mSliderScale));
     193    slSize->setMaxValue (sizeMBToSlider (mMaxVDISize, mSliderScale));
    244194
    245195    txSizeMin->setText (vboxGlobal().formatSize (MinVDISize * _1M));
    246     txSizeMax->setText (vboxGlobal().formatSize (maxVDISize * _1M));
     196    txSizeMax->setText (vboxGlobal().formatSize (mMaxVDISize * _1M));
    247197
    248198    /* limit the max. size of QLineEdit (STUPID Qt has NO correct means for that) */
     
    255205    /* Summary page */
    256206
    257     teSummary->setPaper (pageSummary->backgroundBrush());
     207    mSummaryText->setPaper (pageSummary->backgroundBrush());
    258208
    259209    /* update the next button state for pages with validation
    260210     * (validityChanged() connected to enableNext() will do the job) */
    261     wvalNameAndSize->revalidate();
     211    mWValNameAndSize->revalidate();
    262212
    263213    /* the finish button on the Summary page is always enabled */
     
    302252void VBoxNewHDWzd::setRecommendedSize (Q_UINT64 aSize)
    303253{
    304     AssertReturnVoid (aSize >= MinVDISize && aSize <= maxVDISize);
    305     currentSize = aSize;
    306     slSize->setValue (sizeMBToSlider (currentSize, sliderScale));
    307     leSize->setText (vboxGlobal().formatSize (currentSize * _1M));
    308     updateSizeToolTip (currentSize * _1M);
    309 }
    310 
    311 
    312 QString VBoxNewHDWzd::imageFileName()
     254    AssertReturnVoid (aSize >= MinVDISize && aSize <= mMaxVDISize);
     255    mCurrentSize = aSize;
     256    slSize->setValue (sizeMBToSlider (mCurrentSize, mSliderScale));
     257    leSize->setText (vboxGlobal().formatSize (mCurrentSize * _1M));
     258    updateSizeToolTip (mCurrentSize * _1M);
     259}
     260
     261
     262QString VBoxNewHDWzd::location()
    313263{
    314264    QString name = QDir::convertSeparators (leName->text());
     
    320270
    321271    QString ext = QFileInfo (name).extension();
    322     /* compare against the proper case */
    323 #if defined (Q_OS_FREEBSD) || defined (Q_OS_LINUX) || defined (Q_OS_NETBSD) || defined (Q_OS_OPENBSD) || defined (Q_OS_SOLARIS)
    324 #elif defined (Q_OS_WIN) || defined (Q_OS_OS2) || defined (Q_OS_MACX)
    325     ext = ext.lower();
    326 #else
    327     #error Port me!
    328 #endif
    329 
    330     if (ext != "vdi")
     272
     273    if (RTPathCompare (ext.utf8(), "vdi") != 0)
    331274        name += ".vdi";
    332275
     
    335278
    336279
    337 Q_UINT64 VBoxNewHDWzd::imageSize()
    338 {
    339     return currentSize;
    340 }
    341 
    342 
    343 bool VBoxNewHDWzd::isDynamicImage()
     280bool VBoxNewHDWzd::isDynamicStorage()
    344281{
    345282    return rbDynamicType->isOn();
     
    362299    if (pg == pageNameAndSize)
    363300    {
    364         valid = currentSize >= MinVDISize && currentSize <= maxVDISize;
     301        valid = mCurrentSize >= MinVDISize && mCurrentSize <= mMaxVDISize;
    365302    }
    366303
     
    380317    if (currentPage() == pageNameAndSize)
    381318    {
    382         if (QFileInfo (imageFileName()).exists())
     319        if (QFileInfo (location()).exists())
    383320        {
    384             vboxProblem().sayCannotOverwriteHardDiskImage (this, imageFileName());
     321            vboxProblem().sayCannotOverwriteHardDiskStorage (this, location());
    385322            return;
    386323        }
     
    393330        type = VBoxGlobal::removeAccelMark (type);
    394331
    395         Q_UINT64 sizeB = imageSize() * _1M;
     332        Q_UINT64 sizeB = mCurrentSize * _1M;
    396333
    397334        // compose summary
     
    404341        ))
    405342            .arg (type)
    406             .arg (composeFullFileName (imageFileName()))
     343            .arg (composeFullFileName (location()))
    407344            .arg (VBoxGlobal::formatSize (sizeB))
    408345            .arg (sizeB);
    409         teSummary->setText (summary);
     346        mSummaryText->setText (summary);
    410347        /* set Finish to default */
    411348        finishButton()->setDefault (true);
     
    436373    else if (page == pageSummary)
    437374    {
    438         teSummary->setFocus();
     375        mSummaryText->setFocus();
    439376    }
    440377
     
    454391
    455392/**
    456  *  Performs steps necessary to create a hard disk. This method handles all
    457  *  errors and shows the corresponding messages when appropriate.
     393 * Performs steps necessary to create a hard disk. This method handles all
     394 * errors and shows the corresponding messages when appropriate.
    458395 *
    459  *  @return     wheter the creation was successful or not
     396 * @return Wheter the creation was successful or not.
    460397 */
    461398bool VBoxNewHDWzd::createHardDisk()
    462399{
    463     QString src = imageFileName();
    464     Q_UINT64 size = imageSize();
    465 
    466     AssertReturn (!src.isEmpty(), false);
    467     AssertReturn (size > 0, false);
     400    QString loc = location();
     401
     402    AssertReturn (!loc.isEmpty(), false);
     403    AssertReturn (mCurrentSize > 0, false);
    468404
    469405    CVirtualBox vbox = vboxGlobal().virtualBox();
    470406
    471407    CProgress progress;
    472     CHardDisk hd = vbox.CreateHardDisk (KHardDiskStorageType_VirtualDiskImage);
    473 
    474     /// @todo (dmik) later, change wrappers so that converting
    475     //  to CUnknown is not necessary for cross-assignments
    476     CVirtualDiskImage vdi = CUnknown (hd);
     408
     409    CHardDisk2 hd = vbox.CreateHardDisk2 (QString ("VDI"), loc);
    477410
    478411    if (!vbox.isOk())
    479412    {
    480         vboxProblem().cannotCreateHardDiskImage (this,
    481                                                  vbox, src, vdi, progress);
     413        vboxProblem().cannotCreateHardDiskStorage (this, vbox, loc, hd,
     414                                                   progress);
    482415        return false;
    483416    }
    484417
    485     vdi.SetFilePath (src);
    486 
    487     if (isDynamicImage())
    488         progress = vdi.CreateDynamicImage (size);
     418    if (isDynamicStorage())
     419        progress = hd.CreateDynamicStorage (mCurrentSize);
    489420    else
    490         progress = vdi.CreateFixedImage (size);
    491 
    492     if (!vdi.isOk())
    493     {
    494         vboxProblem().cannotCreateHardDiskImage (this,
    495                                                  vbox, src, vdi, progress);
     421        progress = hd.CreateFixedStorage (mCurrentSize);
     422
     423    if (!hd.isOk())
     424    {
     425        vboxProblem().cannotCreateHardDiskStorage (this, vbox, loc, hd,
     426                                                   progress);
    496427        return false;
    497428    }
     
    499430    vboxProblem().showModalProgressDialog (progress, caption(), parentWidget());
    500431
    501     if (progress.GetResultCode() != 0)
    502     {
    503         vboxProblem().cannotCreateHardDiskImage (this,
    504                                                  vbox, src, vdi, progress);
     432    if (!progress.isOk() || progress.GetResultCode() != 0)
     433    {
     434        vboxProblem().cannotCreateHardDiskStorage (this, vbox, loc, hd,
     435                                                   progress);
    505436        return false;
    506437    }
    507438
    508     vbox.RegisterHardDisk (hd);
    509     if (!vbox.isOk())
    510     {
    511         vboxProblem().cannotRegisterMedia (this, vbox, VBoxDefs::HD,
    512                                            vdi.GetFilePath());
    513         /* delete the image file on failure */
    514         vdi.DeleteImage();
    515         return false;
    516     }
    517 
    518     chd = hd;
     439    /* inform everybody there is a new medium */
     440    vboxGlobal().addMedium (VBoxMedium (CMedium (hd),
     441                                        VBoxDefs::MediaType_HardDisk,
     442                                        KMediaState_Created));
     443
     444    mHD = hd;
    519445    return true;
    520446}
     
    525451    if (focusWidget() == slSize)
    526452    {
    527         currentSize = sliderToSizeMB (val, sliderScale);
    528         leSize->setText (vboxGlobal().formatSize (currentSize * _1M));
    529         updateSizeToolTip (currentSize * _1M);
     453        mCurrentSize = sliderToSizeMB (val, mSliderScale);
     454        leSize->setText (vboxGlobal().formatSize (mCurrentSize * _1M));
     455        updateSizeToolTip (mCurrentSize * _1M);
    530456    }
    531457}
     
    536462    if (focusWidget() == leSize)
    537463    {
    538         currentSize = vboxGlobal().parseSize (text);
    539         updateSizeToolTip (currentSize);
    540         currentSize /= _1M;
    541         slSize->setValue (sizeMBToSlider (currentSize, sliderScale));
     464        mCurrentSize = vboxGlobal().parseSize (text);
     465        updateSizeToolTip (mCurrentSize);
     466        mCurrentSize /= _1M;
     467        slSize->setValue (sizeMBToSlider (mCurrentSize, mSliderScale));
    542468    }
    543469}
     
    558484    {
    559485        CVirtualBox vbox = vboxGlobal().virtualBox();
    560         fld = QFileInfo (vbox.GetSystemProperties().GetDefaultVDIFolder());
     486        fld = QFileInfo (vbox.GetSystemProperties().GetDefaultHardDiskFolder());
    561487        if (!fld.exists())
    562488            fld = vbox.GetHomeFolder();
    563489    }
    564490
    565 //    QFileDialog fd (this, "NewDiskImageDialog", TRUE);
     491//    QFileDialog fd (this, "NewMediaDialog", TRUE);
    566492//    fd.setMode (QFileDialog::AnyFile);
    567493//    fd.setViewMode (QFileDialog::List);
     
    574500        tr ("Hard disk images (*.vdi)"),
    575501        this,
    576         "NewDiskImageDialog",
     502        "NewMediaDialog",
    577503        tr ("Select a file for the new hard disk image file"));
    578504
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewVMWzd.ui

    r11982 r13580  
    66:folding=explicit:collapseFolds=1:
    77
    8      Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8     Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99
    1010     This file is part of VirtualBox Open Source Edition (OSE), as
     
    757757disk using the &lt;b&gt;New&lt;/b&gt; button or select an existing hard disk
    758758image from the drop-down list or by pressing the &lt;b&gt;Existing&lt;/b&gt;
    759 button (to invoke the Virtual Disk Manager dialog).&lt;/p&gt;
     759button (to invoke the Virtual Media Manager dialog).&lt;/p&gt;
    760760&lt;p&gt;If you need a more complicated hard disk setup, you can also skip this
    761761step and attach hard disks later using the VM Settings dialog.&lt;/p&gt;</string>
     
    789789                        </property>
    790790                        <property name="title">
    791                             <string>B&amp;oot Hard Disk (Primary Master)</string>
     791                            <string>Boot Hard &amp;Disk (Primary Master)</string>
     792                        </property>
     793                        <property name="checkable">
     794                            <bool>true</bool>
    792795                        </property>
    793796                        <grid>
     
    991994        <signal>clicked()</signal>
    992995        <receiver>VBoxNewVMWzd</receiver>
    993         <slot>showNewVDIWizard()</slot>
     996        <slot>showNewHardDiskWizard()</slot>
    994997    </connection>
    995998    <connection>
     
    9971000        <signal>clicked()</signal>
    9981001        <receiver>VBoxNewVMWzd</receiver>
    999         <slot>showVDIManager()</slot>
     1002        <slot>showHardDiskManager()</slot>
    10001003    </connection>
    10011004    <connection>
     
    10331036    <include location="local" impldecl="in implementation">VBoxUtils.h</include>
    10341037    <include location="local" impldecl="in implementation">VBoxGlobal.h</include>
    1035     <include location="local" impldecl="in implementation">VBoxDiskImageManagerDlg.h</include>
     1038    <include location="local" impldecl="in implementation">VBoxMediaManagerDlg.h</include>
    10361039    <include location="local" impldecl="in implementation">VBoxNewHDWzd.h</include>
    10371040    <include location="local" impldecl="in implementation">VBoxMediaComboBox.h</include>
     
    10451048    <variable access="private">QIWidgetValidator *wvalMemory;</variable>
    10461049    <variable access="private">QIWidgetValidator *wvalHDD;</variable>
    1047     <variable access="private">QUuid uuidHD;</variable>
    1048     <variable access="private">CHardDisk chd;</variable>
    1049     <variable access="private">CMachine cmachine;</variable>
    1050     <variable access="private">VBoxMediaComboBox *mediaCombo;</variable>
     1050    <variable access="private">CHardDisk2 mHardDisk;</variable>
     1051    <variable access="private">CMachine mMachine;</variable>
     1052    <variable access="private">VBoxMediaComboBox *mHDCombo;</variable>
    10511053    <variable access="private">QITextEdit *teSummary;</variable>
    10521054</variables>
     
    10541056    <slot>enableNext( const QIWidgetValidator * wval )</slot>
    10551057    <slot>revalidate( QIWidgetValidator * wval )</slot>
    1056     <slot>showVDIManager()</slot>
    1057     <slot>showNewVDIWizard()</slot>
     1058    <slot>showHardDiskManager()</slot>
     1059    <slot>showNewHardDiskWizard()</slot>
    10581060    <slot>slRAM_valueChanged( int val )</slot>
    10591061    <slot>leRAM_textChanged( const QString &amp; text )</slot>
    10601062    <slot>cbOS_activated( int item )</slot>
    1061     <slot>currentMediaChanged( int item )</slot>
    10621063</slots>
    10631064<functions>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewVMWzd.ui.h

    r10351 r13580  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    103103
    104104    /* HDD Images page */
    105     mediaCombo = new VBoxMediaComboBox (grbHDA, "mediaCombo", VBoxDefs::HD, true);
    106     grbHDALayout->addMultiCellWidget (mediaCombo, 0, 0, 0, 2);
    107     setTabOrder (mediaCombo, pbNewHD);
     105    mHDCombo = new VBoxMediaComboBox (grbHDA, "mHDCombo",
     106                                      VBoxDefs::MediaType_HardDisk);
     107    grbHDALayout->addMultiCellWidget (mHDCombo, 0, 0, 0, 2);
     108    setTabOrder (mHDCombo, pbNewHD);
    108109    setTabOrder (pbNewHD, pbExistingHD);
    109     connect (mediaCombo, SIGNAL (activated (int)),
    110              this, SLOT (currentMediaChanged (int)));
    111     if (!vboxGlobal().isMediaEnumerationStarted())
    112         vboxGlobal().startEnumeratingMedia();
    113     else
    114         mediaCombo->refresh();
    115 
    116     /// @todo (dmik) remove?
    117     wvalHDD = new QIWidgetValidator (pageHDD, this);
    118     connect (wvalHDD, SIGNAL (validityChanged (const QIWidgetValidator *)),
    119              this, SLOT (enableNext (const QIWidgetValidator *)));
    120     connect (wvalHDD, SIGNAL (isValidRequested (QIWidgetValidator *)),
    121              this, SLOT (revalidate (QIWidgetValidator *)));
     110
     111    /* request to check media accessibility */
     112    mHDCombo->repopulate();
    122113
    123114    /* Summary page */
     
    176167    wvalNameAndOS->revalidate();
    177168    wvalMemory->revalidate();
    178     wvalHDD->revalidate();
    179169
    180170    /* the finish button on the Summary page is always enabled */
     
    222212}
    223213
    224 
    225214void VBoxNewVMWzd::revalidate (QIWidgetValidator *wval)
    226215{
     
    229218    bool valid = wval->isOtherValid();
    230219
    231     if (wval == wvalHDD)
    232     {
    233         if (!chd.isNull() && mediaCombo->getId() != chd.GetId())
    234             ensureNewHardDiskDeleted();
    235     }
    236 
    237     wval->setOtherValid( valid );
    238 }
    239 
     220    wval->setOtherValid (valid);
     221}
    240222
    241223void VBoxNewVMWzd::showPage (QWidget *page)
     
    243225    if (page == pageSummary)
    244226    {
    245         if (!mediaCombo->currentItem())
     227        bool haveHardDisk = grbHDA->isChecked() && !mHDCombo->id().isNull();
     228
     229        if (!haveHardDisk)
    246230        {
    247231            if (!vboxProblem().confirmHardDisklessMachine (this))
     
    258242            .arg (slRAM->value());
    259243
    260         if (mediaCombo->currentItem())
     244        if (haveHardDisk)
    261245            summary += QString (tr (
    262246                "<tr><td>Boot Hard Disk:</td><td>%4</td></tr>"))
    263                 .arg (mediaCombo->currentText());
     247                .arg (mHDCombo->currentText());
    264248
    265249        teSummary->setText ("<table>" + summary + "</table>");
     
    276260    QWizard::showPage (page);
    277261
    278     /*
    279      *  fix focus on the last page. when we go to the last page
    280      *  having the Next in focus the focus goes to the Cancel
    281      *  button because when the Next hides Finish is not yet shown.
    282      */
     262    /* fix focus on the last page. when we go to the last page having the Next
     263     * in focus the focus goes to the Cancel button because when the Next hides
     264       Finish is not yet shown. */
    283265    if (page == pageSummary && focusWidget() == cancelButton())
    284266        finishButton()->setFocus();
     
    290272        slRAM->setFocus();
    291273    else if (page == pageHDD)
    292         mediaCombo->setFocus();
     274        mHDCombo->setFocus();
    293275    else if (page == pageSummary)
    294276        teSummary->setFocus();
     
    299281void VBoxNewVMWzd::accept()
    300282{
    301     /*
    302      *  Try to create the machine when the Finish button is pressed.
    303      *  On failure, the wisard will remain open to give it another try.
    304      */
     283    /* Try to create the machine when the Finish button is pressed. On
     284     * failure, the wizard will remain open to give it another try. */
    305285    if (constructMachine())
    306286        QWizard::accept();
     
    312292
    313293    /* create a machine with the default settings file location */
    314     if (cmachine.isNull())
    315     {
    316         cmachine = vbox.CreateMachine (QString(), leName->text(), QUuid());
     294    if (mMachine.isNull())
     295    {
     296        mMachine = vbox.CreateMachine (QString(), leName->text(), QUuid());
    317297        if (!vbox.isOk())
    318298        {
     
    320300            return false;
    321301        }
    322         if (uuidHD.isNull() || !chd.isNull())
    323             cmachine.SetExtraData (VBoxDefs::GUI_FirstRun, "yes");
     302
     303        /* The FirstRun wizard is to be shown only when we don't attach any hard
     304         * disk or attach a new (empty) one. Selecting an existing hard disk
     305         * will cancel the wizard. */
     306        if (mHDCombo->id().isNull() || !mHardDisk.isNull())
     307            mMachine.SetExtraData (VBoxDefs::GUI_FirstRun, "yes");
    324308    }
    325309
     
    330314    AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
    331315    QString typeId = type.GetId();
    332     cmachine.SetOSTypeId (typeId);
     316    mMachine.SetOSTypeId (typeId);
    333317
    334318    if (typeId == "os2warp3"  ||
     
    336320        typeId == "os2warp45" ||
    337321        typeId == "ecs")
    338         cmachine.SetHWVirtExEnabled (KTSBool_True);
     322        mMachine.SetHWVirtExEnabled (KTSBool_True);
    339323
    340324    /* RAM size */
    341     cmachine.SetMemorySize (slRAM->value());
     325    mMachine.SetMemorySize (slRAM->value());
    342326
    343327    /* add one network adapter (NAT) by default */
    344328    {
    345         CNetworkAdapter cadapter = cmachine.GetNetworkAdapter (0);
     329        CNetworkAdapter cadapter = mMachine.GetNetworkAdapter (0);
    346330#ifdef VBOX_WITH_E1000
    347331        /* Default to e1k on solaris */
     
    358342
    359343    /* register the VM prior to attaching hard disks */
    360     vbox.RegisterMachine (cmachine);
     344    vbox.RegisterMachine (mMachine);
    361345    if (!vbox.isOk())
    362346    {
    363         vboxProblem().cannotCreateMachine (vbox, cmachine, this);
     347        vboxProblem().cannotCreateMachine (vbox, mMachine, this);
    364348        return false;
    365349    }
    366350
    367     /* Boot hard disk (Primary Master) */
    368     if (!uuidHD.isNull())
     351    /* Boot hard disk (IDE Primary Master) */
     352    QUuid hardDiskId = mHDCombo->id();
     353    if (!hardDiskId.isNull())
    369354    {
    370355        bool ok = false;
    371         QUuid id = cmachine.GetId();
     356        QUuid id = mMachine.GetId();
    372357        CSession session = vboxGlobal().openSession (id);
    373358        if (!session.isNull())
    374359        {
    375360            CMachine m = session.GetMachine();
    376             m.AttachHardDisk (uuidHD, KStorageBus_IDE, 0, 0);
     361            m.AttachHardDisk2 (hardDiskId, KStorageBus_IDE, 0, 0);
    377362            if (m.isOk())
    378363            {
     
    384369            }
    385370            else
    386                 vboxProblem().cannotAttachHardDisk (this, m, uuidHD,
     371                vboxProblem().cannotAttachHardDisk (this, m,
     372                                                    mHDCombo->location(),
    387373                                                    KStorageBus_IDE, 0, 0);
    388374            session.Close();
     
    393379            vbox.UnregisterMachine (id);
    394380            if (vbox.isOk())
    395                 cmachine.DeleteSettings();
     381                mMachine.DeleteSettings();
    396382            return false;
    397383        }
    398384    }
    399385
    400     /* ensure we don't delete a newly created hard disk on success */
    401     chd.detach();
     386    /* ensure we don't try to delete a newly created hard disk on success */
     387    mHardDisk.detach();
    402388
    403389    return true;
     
    406392void VBoxNewVMWzd::ensureNewHardDiskDeleted()
    407393{
    408     if (!chd.isNull())
    409     {
    410         QUuid hdId = chd.GetId();
    411         CVirtualBox vbox = vboxGlobal().virtualBox();
    412         vbox.UnregisterHardDisk (chd.GetId());
    413         if (!vbox.isOk())
    414             vboxProblem().cannotUnregisterMedia (this, vbox, VBoxDefs::HD,
    415                                                  chd.GetLocation());
     394    if (!mHardDisk.isNull())
     395    {
     396        /* remember ID as it may be lost after the deletion */
     397        QUuid id = mHardDisk.GetId();
     398
     399        bool success = false;
     400
     401        CProgress progress = mHardDisk.DeleteStorage();
     402        if (mHardDisk.isOk())
     403        {
     404            vboxProblem().showModalProgressDialog (progress, caption(),
     405                                                   parentWidget());
     406            if (progress.isOk() && progress.GetResultCode() == S_OK)
     407                success = true;
     408        }
     409
     410        if (success)
     411            vboxGlobal().removeMedium (VBoxDefs::MediaType_HardDisk, id);
    416412        else
    417         {
    418             CVirtualDiskImage vdi = CUnknown (chd);
    419             if (!vdi.isNull())
    420             {
    421                 vdi.DeleteImage();
    422                 if (!vdi.isOk())
    423                     vboxProblem().cannotDeleteHardDiskImage (this, vdi);
    424             }
    425         }
    426         chd.detach();
    427         vboxGlobal().removeMedia (VBoxDefs::HD, hdId);
     413            vboxProblem().cannotDeleteHardDiskStorage (this, mHardDisk,
     414                                                       progress);
     415        mHardDisk.detach();
    428416    }
    429417}
     
    431419CMachine VBoxNewVMWzd::machine()
    432420{
    433     return cmachine;
    434 }
    435 
    436 void VBoxNewVMWzd::showVDIManager()
    437 {
    438     VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg", WType_Dialog | WShowModal);
    439     dlg.setup (VBoxDefs::HD, true);
    440     QUuid newId = dlg.exec() == VBoxDiskImageManagerDlg::Accepted ?
    441         dlg.getSelectedUuid() : mediaCombo->getId();
    442 
    443     if (uuidHD != newId)
    444     {
    445         ensureNewHardDiskDeleted();
    446         uuidHD = newId;
    447         mediaCombo->setCurrentItem (uuidHD);
    448     }
    449     mediaCombo->setFocus();
    450     /* revailidate */
    451     wvalHDD->revalidate();
    452 }
    453 
    454 void VBoxNewVMWzd::showNewVDIWizard()
     421    return mMachine;
     422}
     423
     424void VBoxNewVMWzd::showHardDiskManager()
     425{
     426    VBoxMediaManagerDlg dlg (this, "VBoxMediaManagerDlg", WType_Dialog | WShowModal);
     427    dlg.setup (VBoxDefs::MediaType_HardDisk, true);
     428
     429    if (dlg.exec() == VBoxMediaManagerDlg::Accepted)
     430    {
     431        QUuid newId = dlg.selectedId();
     432        if (mHDCombo->id() != newId)
     433        {
     434            ensureNewHardDiskDeleted();
     435            mHDCombo->setCurrentItem (newId);
     436        }
     437    }
     438
     439    mHDCombo->setFocus();
     440}
     441
     442void VBoxNewVMWzd::showNewHardDiskWizard()
    455443{
    456444    VBoxNewHDWzd dlg (this, "VBoxNewHDWzd");
     
    464452    {
    465453        ensureNewHardDiskDeleted();
    466         chd = dlg.hardDisk();
    467         /* fetch uuid and name/path */
    468         uuidHD = chd.GetId();
    469         /* update media combobox */
    470         VBoxMedia::Status status =
    471             chd.GetAccessible() == TRUE ? VBoxMedia::Ok :
    472             chd.isOk() ? VBoxMedia::Inaccessible :
    473             VBoxMedia::Error;
    474         vboxGlobal().addMedia (VBoxMedia (CUnknown (chd), VBoxDefs::HD, status));
    475         mediaCombo->setCurrentItem (uuidHD);
    476         mediaCombo->setFocus();
    477         /* revailidate */
    478         wvalHDD->revalidate();
     454        mHardDisk = dlg.hardDisk();
     455
     456        mHDCombo->setCurrentItem (mHardDisk.GetId());
     457        mHDCombo->setFocus();
    479458    }
    480459}
     
    484463    leRAM->setText (QString().setNum (val));
    485464}
    486 
    487465
    488466void VBoxNewVMWzd::leRAM_textChanged (const QString &text)
     
    505483}
    506484
    507 void VBoxNewVMWzd::currentMediaChanged (int)
    508 {
    509     uuidHD = mediaCombo->getId();
    510     /* revailidate */
    511     wvalHDD->revalidate();
    512 }
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSnapshotsWgt.ui.h

    r8155 r13580  
    556556        return;
    557557
     558    QString snapName = mMachine.GetSnapshot (snapId).GetName();
     559
    558560    CConsole console = session.GetConsole();
    559561    CProgress progress = console.DiscardSnapshot (snapId);
     
    565567
    566568        if (progress.GetResultCode() != 0)
    567             vboxProblem().cannotDiscardSnapshot (progress, mMachine.GetSnapshot (snapId));
     569            vboxProblem().cannotDiscardSnapshot (progress, snapName);
    568570    }
    569571    else
    570         vboxProblem().cannotDiscardSnapshot (console, mMachine.GetSnapshot (snapId));
     572        vboxProblem().cannotDiscardSnapshot (console, snapName);
    571573
    572574    session.Close();
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxUSBFilterSettings.ui.h

    r8155 r13580  
    8080        case VBoxUSBFilterSettings::HostType:
    8181        {
    82             const CHostUSBDeviceFilter filter = CUnknown (aFilter);
     82            const CHostUSBDeviceFilter filter (aFilter);
    8383            KUSBDeviceFilterAction action = filter.GetAction();
    8484            if (action == KUSBDeviceFilterAction_Ignore)
     
    150150            case VBoxUSBFilterSettings::HostType:
    151151            {
    152                 CHostUSBDeviceFilter filter = CUnknown (mFilter);
     152                CHostUSBDeviceFilter filter (mFilter);
    153153                filter.SetAction (vboxGlobal().toUSBDevFilterAction (
    154154                    cbAction->currentText()));
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMFirstRunWzd.ui

    r11982 r13580  
    66:folding=explicit:collapseFolds=1:
    77
    8      Copyright (C) 2007 Sun Microsystems, Inc.
     8     Copyright (C) 2007-2008 Sun Microsystems, Inc.
    99
    1010     This file is part of VirtualBox Open Source Edition (OSE), as
     
    647647        <signal>clicked()</signal>
    648648        <receiver>VBoxVMFirstRunWzd</receiver>
    649         <slot>openVdm()</slot>
     649        <slot>openMediaManager()</slot>
    650650    </connection>
    651651</connections>
     
    657657    <include location="local" impldecl="in implementation">VBoxGlobal.h</include>
    658658    <include location="local" impldecl="in implementation">VBoxMediaComboBox.h</include>
    659     <include location="local" impldecl="in implementation">VBoxDiskImageManagerDlg.h</include>
     659    <include location="local" impldecl="in implementation">VBoxMediaManagerDlg.h</include>
    660660</includes>
    661661<forwards>
     
    676676    <slot>mediaTypeChanged()</slot>
    677677    <slot>mediaSourceChanged()</slot>
    678     <slot>openVdm()</slot>
     678    <slot>openMediaManager()</slot>
    679679</slots>
    680680<functions>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMFirstRunWzd.ui.h

    r8155 r13580  
    5353
    5454    /* media page */
    55     cbImage = new VBoxMediaComboBox (bgSource, "cbImage", VBoxDefs::CD);
     55    cbImage = new VBoxMediaComboBox (bgSource, "cbImage", VBoxDefs::MediaType_DVD);
    5656    ltVdm->insertWidget (0, cbImage);
    5757    tbVdm->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
     
    110110    machine = aMachine;
    111111
    112     CHardDiskAttachmentEnumerator en = machine.GetHardDiskAttachments().Enumerate();
    113     if (en.HasMore())
     112    CHardDisk2AttachmentVector vec = machine.GetHardDisk2Attachments();
     113    if (vec.size() != 0)
    114114    {
    115115        txWelcomeHD->setHidden (true);
     
    209209        {
    210210            CDVDDrive virtualDrive = machine.GetDVDDrive();
    211             virtualDrive.MountImage (cbImage->getId());
     211            virtualDrive.MountImage (cbImage->id());
    212212        }
    213213    }
     
    227227        {
    228228            CFloppyDrive virtualDrive = machine.GetFloppyDrive();
    229             virtualDrive.MountImage (cbImage->getId());
     229            virtualDrive.MountImage (cbImage->id());
    230230        }
    231231    }
     
    283283
    284284        /* Switch media images type to CD */
    285         cbImage->setType (VBoxDefs::CD);
     285        cbImage->setType (VBoxDefs::MediaType_DVD);
    286286    }
    287287    /* Floppy Media type selected */
     
    308308
    309309        /* Switch media images type to FD */
    310         cbImage->setType (VBoxDefs::FD);
    311     }
    312     /* Update media images list */
    313     if (!vboxGlobal().isMediaEnumerationStarted())
    314         vboxGlobal().startEnumeratingMedia();
    315     else
    316         cbImage->refresh();
     310        cbImage->setType (VBoxDefs::MediaType_Floppy);
     311    }
     312
     313    /* Repopulate the media list */
     314    cbImage->repopulate();
    317315
    318316    /* Revalidate updated page */
     
    332330
    333331
    334 void VBoxVMFirstRunWzd::openVdm()
    335 {
    336     VBoxDiskImageManagerDlg vdm (this, "VBoxDiskImageManagerDlg",
    337                                  WType_Dialog | WShowModal);
    338     QUuid machineId = machine.GetId();
    339     VBoxDefs::DiskType type = rbCdType->isChecked() ? VBoxDefs::CD :
    340         rbFdType->isChecked() ? VBoxDefs::FD : VBoxDefs::InvalidType;
    341     vdm.setup (type, true, &machineId);
    342     if (vdm.exec() == VBoxDiskImageManagerDlg::Accepted)
    343     {
    344         cbImage->setCurrentItem (vdm.getSelectedUuid());
     332void VBoxVMFirstRunWzd::openMediaManager()
     333{
     334    VBoxDefs::MediaType type =
     335        rbCdType->isChecked() ? VBoxDefs::MediaType_DVD :
     336        rbFdType->isChecked() ? VBoxDefs::MediaType_Floppy :
     337        VBoxDefs::MediaType_Invalid;
     338
     339    AssertReturnVoid (type != VBoxDefs::MediaType_Invalid);
     340
     341    VBoxMediaManagerDlg dlg (this, "VBoxMediaManagerDlg",
     342                             WType_Dialog | WShowModal);
     343
     344    dlg.setup (type, true /* aDoSelect */);
     345    if (dlg.exec() == VBoxMediaManagerDlg::Accepted)
     346    {
     347        cbImage->setCurrentItem (dlg.selectedId());
    345348
    346349        /* Revalidate updated page */
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMInformationDlg.ui.h

    r9364 r13580  
    143143    connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
    144144             this, SLOT (updateDetails()));
    145     connect (mConsole, SIGNAL (mediaChanged (VBoxDefs::DiskType)),
     145    connect (mConsole, SIGNAL (mediumChanged (VBoxDefs::MediaType)),
    146146             this, SLOT (updateDetails()));
    147147    connect (mConsole, SIGNAL (sharedFoldersChanged()),
     
    435435    /* details page update */
    436436    mDetailsText->setText (
    437         vboxGlobal().detailsReport (mSession.GetMachine(), false /* isNewVM */,
    438                                     false /* withLinks */, false /* refresh */));
     437        vboxGlobal().detailsReport (mSession.GetMachine(), false /* aIsNewVM */,
     438                                    false /* aWithLinks */));
    439439}
    440440
     
    561561
    562562        /* IDE Hard Disk (Primary Master) */
    563         if (!m.GetHardDisk (KStorageBus_IDE, 0, 0).isNull())
     563        if (!m.GetHardDisk2 (KStorageBus_IDE, 0, 0).isNull())
    564564        {
    565565            hdStat += formatHardDisk (KStorageBus_IDE, 0, 0, "IDE00");
     
    568568
    569569        /* IDE Hard Disk (Primary Slave) */
    570         if (!m.GetHardDisk (KStorageBus_IDE, 0, 1).isNull())
     570        if (!m.GetHardDisk2 (KStorageBus_IDE, 0, 1).isNull())
    571571        {
    572572            hdStat += formatHardDisk (KStorageBus_IDE, 0, 1, "IDE01");
     
    575575
    576576        /* IDE Hard Disk (Secondary Slave) */
    577         if (!m.GetHardDisk (KStorageBus_IDE, 1, 1).isNull())
     577        if (!m.GetHardDisk2 (KStorageBus_IDE, 1, 1).isNull())
    578578        {
    579579            hdStat += formatHardDisk (KStorageBus_IDE, 1, 1, "IDE11");
     
    584584        for (int i = 0; i < 30; ++ i)
    585585        {
    586             if (!m.GetHardDisk (KStorageBus_SATA, i, 0).isNull())
     586            if (!m.GetHardDisk2 (KStorageBus_SATA, i, 0).isNull())
    587587            {
    588588                hdStat += formatHardDisk (KStorageBus_SATA, i, 0,
     
    649649        return QString::null;
    650650
    651     CHardDisk hd = mSession.GetMachine().GetHardDisk (aBus, aChannel, aDevice);
     651    CHardDisk2 hd = mSession.GetMachine().GetHardDisk2 (aBus, aChannel, aDevice);
    652652    QString header = "<tr><td></td><td colspan=3><nobr><u>%1</u></nobr></td></tr>";
    653653    QString name = vboxGlobal().toFullString (aBus, aChannel, aDevice);
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui

    r8497 r13580  
    16431643                                                </property>
    16441644                                                <property name="whatsThis" stdset="0">
    1645                                                     <string>Invokes the Virtual Disk Manager to select a CD/DVD image to mount.</string>
     1645                                                    <string>Invokes the Virtual Media Manager to select a CD/DVD image to mount.</string>
    16461646                                                </property>
    16471647                                            </widget>
     
    18421842                                                </property>
    18431843                                                <property name="whatsThis" stdset="0">
    1844                                                     <string>Invokes the Virtual Disk Manager to select a Floppy image to mount.</string>
     1844                                                    <string>Invokes the Virtual Media Manager to select a Floppy image to mount.</string>
    18451845                                                </property>
    18461846                                            </widget>
     
    30323032    <include location="local" impldecl="in implementation">VBoxUSBFilterSettings.h</include>
    30333033    <include location="local" impldecl="in implementation">VBoxSharedFoldersSettings.h</include>
    3034     <include location="local" impldecl="in implementation">VBoxDiskImageManagerDlg.h</include>
     3034    <include location="local" impldecl="in implementation">VBoxMediaManagerDlg.h</include>
    30353035    <include location="local" impldecl="in implementation">VBoxMediaComboBox.h</include>
    30363036    <include location="local" impldecl="in implementation">QIRichLabel.h</include>
     
    30393039<forwards>
    30403040    <forward>class VBoxMediaComboBox</forward>
    3041     <forward>class VBoxDiskImageManagerDlg</forward>
     3041    <forward>class VBoxMediaManagerDlg</forward>
    30423042    <forward>class VBoxUSBMenu</forward>
    30433043    <forward>class VBoxSharedFoldersSettings</forward>
     
    30843084    <slot>revalidate( QIWidgetValidator * wval )</slot>
    30853085    <slot>updateWhatsThis( bool gotFocus = false )</slot>
    3086     <slot>showImageManagerISODVD()</slot>
    3087     <slot>showImageManagerISOFloppy()</slot>
    3088     <slot>showVDImageManager( QUuid *id, VBoxMediaComboBox *le, QLabel *tx = NULL )</slot>
     3086    <slot>showDVDManager()</slot>
     3087    <slot>showFloppyManager()</slot>
     3088    <slot>showMediaManager( QUuid *, VBoxMediaComboBox * )</slot>
    30893089    <slot>addNetworkAdapter( const CNetworkAdapter &amp; )</slot>
    30903090    <slot>updateNetworksList()</slot>
     
    31273127    <function access="private">showEvent( QShowEvent * )</function>
    31283128    <function access="private">updateShortcuts()</function>
    3129     <function access="private" returnType="QString">getHdInfo( QGroupBox*, QUuid )</function>
    31303129    <function access="private">loadInterfacesList()</function>
    31313130    <function access="private">loadNetworksList()</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r11955 r13580  
    598598             this, SLOT (revalidate (QIWidgetValidator *)));
    599599
    600     connect (mHDSettings, SIGNAL (hddListChanged()), wvalHDD, SLOT (revalidate()));
    601     connect (mHDSettings, SIGNAL (hddListChanged()), this, SLOT (resetFirstRunFlag()));
     600    connect (mHDSettings, SIGNAL (hardDiskListChanged()), wvalHDD, SLOT (revalidate()));
     601    connect (mHDSettings, SIGNAL (hardDiskListChanged()), this, SLOT (resetFirstRunFlag()));
    602602
    603603    /* CD/DVD-ROM Drive Page */
     
    607607                         "virtual machine. Note that the CD/DVD drive is always connected to the "
    608608                         "Secondary Master IDE controller of the machine."));
    609     cbISODVD = new VBoxMediaComboBox (bgDVD, "cbISODVD", VBoxDefs::CD);
     609    cbISODVD = new VBoxMediaComboBox (bgDVD, "cbISODVD", VBoxDefs::MediaType_DVD);
    610610    cdLayout->insertWidget(0, cbISODVD);
    611611    QWhatsThis::add (cbISODVD, tr ("Displays the image file to mount to the virtual CD/DVD "
     
    622622    connect (rbISODVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
    623623    connect (cbISODVD, SIGNAL (activated (int)), this, SLOT (cdMediaChanged()));
    624     connect (tbISODVD, SIGNAL (clicked()), this, SLOT (showImageManagerISODVD()));
     624    connect (tbISODVD, SIGNAL (clicked()), this, SLOT (showDVDManager()));
    625625
    626626    /* setup iconsets -- qdesigner is not capable... */
     
    633633                     tr ("When checked, mounts the specified media to the Floppy drive of the "
    634634                         "virtual machine."));
    635     cbISOFloppy = new VBoxMediaComboBox (bgFloppy, "cbISOFloppy", VBoxDefs::FD);
     635    cbISOFloppy = new VBoxMediaComboBox (bgFloppy, "cbISOFloppy", VBoxDefs::MediaType_Floppy);
    636636    fdLayout->insertWidget(0, cbISOFloppy);
    637637    QWhatsThis::add (cbISOFloppy, tr ("Displays the image file to mount to the virtual Floppy "
     
    648648    connect (rbISOFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
    649649    connect (cbISOFloppy, SIGNAL (activated (int)), this, SLOT (fdMediaChanged()));
    650     connect (tbISOFloppy, SIGNAL (clicked()), this, SLOT (showImageManagerISOFloppy()));
     650    connect (tbISOFloppy, SIGNAL (clicked()), this, SLOT (showFloppyManager()));
    651651
    652652    /* setup iconsets -- qdesigner is not capable... */
     
    11781178{
    11791179    resetFirstRunFlag();
    1180     uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
     1180    uuidISODVD = bgDVD->isChecked() ? cbISODVD->id() : QUuid();
    11811181    /* revailidate */
    11821182    wvalDVD->revalidate();
     
    11871187{
    11881188    resetFirstRunFlag();
    1189     uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->getId() : QUuid();
     1189    uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->id() : QUuid();
    11901190    /* revailidate */
    11911191    wvalFloppy->revalidate();
    11921192}
    11931193
    1194 
    1195 QString VBoxVMSettingsDlg::getHdInfo (QGroupBox *aGroupBox, QUuid aId)
    1196 {
    1197     QString notAttached = tr ("<not attached>", "hard disk");
    1198     if (aId.isNull())
    1199         return notAttached;
    1200     return aGroupBox->isChecked() ?
    1201         vboxGlobal().details (vboxGlobal().virtualBox().GetHardDisk (aId), true) :
    1202         notAttached;
    1203 }
    12041194
    12051195void VBoxVMSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
     
    12341224}
    12351225
     1226
    12361227void VBoxVMSettingsDlg::setWarning (const QString &warning)
    12371228{
     
    12461237}
    12471238
     1239
    12481240/**
    1249  *  Sets up this dialog.
     1241 * Sets up this dialog.
    12501242 *
    1251  *  If @a aCategory is non-null, it should be one of values from the hidden
    1252  *  '[cat]' column of #listView (see VBoxVMSettingsDlg.ui in qdesigner)
    1253  *  prepended with the '#' sign. In this case, the specified category page
    1254  *  will be activated when the dialog is open.
     1243 * If @a aCategory is non-null, it should be one of values from the hidden
     1244 * '[cat]' column of #listView (see VBoxVMSettingsDlg.ui in qdesigner) prepended
     1245 * with the '#' sign. In this case, the specified category page will be
     1246 * activated when the dialog is open.
    12551247 *
    1256  *  If @a aWidget is non-null, it should be a name of one of widgets
    1257  *  from the given category page. In this case, the specified widget
    1258  *  will get focus when the dialog is open.
     1248 * If @a aWidget is non-null, it should be a name of one of widgets from the
     1249 * given category page. In this case, the specified widget will get focus when
     1250 * the dialog is open.
    12591251 *
    1260  *  @note Calling this method after the dialog is open has no sense.
     1252 * @note Calling this method after the dialog is open has no sense.
    12611253 *
    1262  *  @param  aCategory   Category to select when the dialog is open or null.
    1263  *  @param  aWidget     Category to select when the dialog is open or null.
     1254 * @param  aCategory    Category to select when the dialog is open or null.
     1255 * @param  aWidget      Category to select when the dialog is open or null.
    12641256 */
    12651257void VBoxVMSettingsDlg::setup (const QString &aCategory, const QString &aControl)
     
    13031295    }
    13041296}
     1297
    13051298
    13061299void VBoxVMSettingsDlg::listView_currentChanged (QListViewItem *item)
     
    16521645            case KDriveState_ImageMounted:
    16531646            {
    1654                 CFloppyImage img = floppy.GetImage();
    1655                 QString src = img.GetFilePath();
     1647                CFloppyImage2 img = floppy.GetImage();
     1648                QString src = img.GetLocation();
    16561649                AssertMsg (!src.isNull(), ("Image file must not be null"));
    16571650                QFileInfo fi (src);
     
    17241717            case KDriveState_ImageMounted:
    17251718            {
    1726                 CDVDImage img = dvd.GetImage();
    1727                 QString src = img.GetFilePath();
     1719                CDVDImage2 img = dvd.GetImage();
     1720                QString src = img.GetLocation();
    17281721                AssertMsg (!src.isNull(), ("Image file must not be null"));
    17291722                QFileInfo fi (src);
     
    21032096
    21042097
    2105 void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
    2106 void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
    2107 
    2108 void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
    2109 {
    2110     VBoxDefs::DiskType type = VBoxDefs::InvalidType;
    2111     if (cbb == cbISODVD)
    2112         type = VBoxDefs::CD;
    2113     else if (cbb == cbISOFloppy)
    2114         type = VBoxDefs::FD;
     2098void VBoxVMSettingsDlg::showDVDManager()
     2099{
     2100    showMediaManager (&uuidISODVD, cbISODVD);
     2101}
     2102
     2103
     2104void VBoxVMSettingsDlg::showFloppyManager()
     2105{
     2106    showMediaManager (&uuidISOFloppy, cbISOFloppy);
     2107}
     2108
     2109
     2110void VBoxVMSettingsDlg::showMediaManager (QUuid *aId, VBoxMediaComboBox *aCombo)
     2111{
     2112    VBoxDefs::MediaType type = VBoxDefs::MediaType_Invalid;
     2113
     2114    if (aCombo == cbISODVD)
     2115        type = VBoxDefs::MediaType_DVD;
     2116    else if (aCombo == cbISOFloppy)
     2117        type = VBoxDefs::MediaType_Floppy;
     2118
     2119    AssertReturnVoid (type != VBoxDefs::MediaType_Invalid);
     2120
     2121    VBoxMediaManagerDlg dlg (this, "VBoxMediaManagerDlg",
     2122                             WType_Dialog | WShowModal);
     2123
     2124    dlg.setup (type, true /* aDoSelect */, true /* aRefresh */, cmachine,
     2125               aCombo->id());
     2126
     2127    if (dlg.exec() == VBoxMediaManagerDlg::Accepted)
     2128    {
     2129        *aId = dlg.selectedId();
     2130        resetFirstRunFlag();
     2131    }
    21152132    else
    2116         type = VBoxDefs::HD;
    2117 
    2118     VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
    2119                                  WType_Dialog | WShowModal);
    2120     QUuid machineId = cmachine.GetId();
    2121     QUuid hdId = type == VBoxDefs::HD ? cbb->getId() : QUuid();
    2122     QUuid cdId = type == VBoxDefs::CD ? cbb->getId() : QUuid();
    2123     QUuid fdId = type == VBoxDefs::FD ? cbb->getId() : QUuid();
    2124     dlg.setup (type, true, &machineId, true /* aRefresh */, cmachine,
    2125                hdId, cdId, fdId);
    2126     if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
    2127     {
    2128         *id = dlg.getSelectedUuid();
    2129         resetFirstRunFlag();
    2130     }
    2131     else
    2132     {
    2133         *id = cbb->getId();
    2134     }
    2135 
    2136     cbb->setCurrentItem (*id);
    2137     cbb->setFocus();
     2133    {
     2134        *aId = aCombo->id();
     2135    }
     2136
     2137    aCombo->setCurrentItem (*aId);
     2138    aCombo->setFocus();
    21382139
    21392140    /* revalidate pages with custom validation */
    2140     wvalHDD->revalidate();
    21412141    wvalDVD->revalidate();
    21422142    wvalFloppy->revalidate();
    21432143}
     2144
    21442145
    21452146void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &aAdapter)
     
    21942195}
    21952196
     2197
    21962198void VBoxVMSettingsDlg::updateNetworksList()
    21972199{
     
    22222224    mLockNetworkListUpdate = false;
    22232225}
     2226
    22242227
    22252228void VBoxVMSettingsDlg::addSerialPort (const CSerialPort &aPort)
     
    22572260}
    22582261
     2262
    22592263void VBoxVMSettingsDlg::addParallelPort (const CParallelPort &aPort)
    22602264{
     
    22892293}
    22902294
     2295
    22912296void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
    22922297{
     
    22942299}
    22952300
     2301
    22962302void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
    22972303{
     
    22992305}
    23002306
     2307
    23012308void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
    23022309{
     
    23042311}
    23052312
     2313
    23062314void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
    23072315{
    23082316    slVRAM->setValue( text.toInt() );
    23092317}
     2318
    23102319
    23112320void VBoxVMSettingsDlg::cbOS_activated (int item)
     
    23222331}
    23232332
     2333
    23242334void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
    23252335{
     
    23322342}
    23332343
     2344
    23342345void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
    23352346{
     
    23542365}
    23552366
     2367
    23562368// USB Filter stuff
    23572369////////////////////////////////////////////////////////////////////////////////
     2370
    23582371
    23592372void VBoxVMSettingsDlg::usbAdapterToggled (bool aOn)
     
    23632376    grbUSBFilters->setEnabled (aOn);
    23642377}
     2378
    23652379
    23662380void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
     
    24052419}
    24062420
     2421
    24072422void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
    24082423{
     
    24272442}
    24282443
     2444
    24292445void VBoxVMSettingsDlg::lvUSBFilters_contextMenuRequested (QListViewItem *,
    24302446                                                           const QPoint &aPoint, int)
     
    24332449}
    24342450
     2451
    24352452void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
    24362453{
     
    24402457    item->setText (lvUSBFilters_Name, aText);
    24412458}
     2459
    24422460
    24432461void VBoxVMSettingsDlg::addUSBFilterAct_activated()
     
    24682486}
    24692487
     2488
    24702489void VBoxVMSettingsDlg::addUSBFilterFromAct_activated()
    24712490{
     
    24802499    usbDevicesMenu->exec (pos);
    24812500}
     2501
    24822502
    24832503void VBoxVMSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
     
    25132533}
    25142534
     2535
    25152536void VBoxVMSettingsDlg::removeUSBFilterAct_activated()
    25162537{
     
    25302551}
    25312552
     2553
    25322554void VBoxVMSettingsDlg::USBFilterUpAct_activated()
    25332555{
     
    25512573}
    25522574
     2575
    25532576void VBoxVMSettingsDlg::USBFilterDownAct_activated()
    25542577{
     
    25652588}
    25662589
     2590
    25672591#include "VBoxVMSettingsDlg.ui.moc"
    25682592
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