VirtualBox

Changeset 17384 in vbox for trunk/src


Ignore:
Timestamp:
Mar 5, 2009 10:35:59 AM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: split VBoxMedium out of VBoxGlobal

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

Legend:

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

    r17340 r17384  
    365365        src/VBoxSettingsSelector.cpp \
    366366        src/VBoxMediaManagerDlg.cpp \
     367        src/VBoxMedium.cpp \
    367368        src/VBoxImportApplianceWgt.cpp \
    368369        src/VBoxImportApplianceWzd.cpp
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r16867 r17384  
    3838#include <QLinkedList>
    3939
     40#include "VBoxMedium.h"
     41
    4042class QAction;
    4143class QLabel;
    4244class QToolButton;
    43 
    44 // Auxiliary types
    45 ////////////////////////////////////////////////////////////////////////////////
    46 
    47 /**
    48  * Media descriptor for the GUI.
    49  *
    50  * Maintains the results of the last state (accessibility) check and precomposes
    51  * string parameters such as location, size which can be used in various GUI
    52  * controls.
    53  *
    54  * Many getter methods take the boolean @a aNoDiffs argument. Unless explicitly
    55  * stated otherwise, this argument, when set to @c true, will cause the
    56  * corresponding property of this object's root medium to be returned instead of
    57  * its own one. This is useful when hard disk media is represented in the
    58  * user-friendly "don't show diffs" mode. For non-hard disk media, the value of
    59  * this argument is irrelevant because the root object for such medium is
    60  * the medium itself.
    61  *
    62  * Note that this class "abuses" the KMediaState_NotCreated state value to
    63  * indicate that the accessibility check of the given medium (see
    64  * #blockAndQueryState()) has not been done yet and therefore some parameters
    65  * such as #size() are meaningless because they can be read only from the
    66  * accessible medium. The real KMediaState_NotCreated state is not necessary
    67  * because this class is only used with created (existing) media.
    68  */
    69 class VBoxMedium
    70 {
    71 public:
    72 
    73     /**
    74      * Creates a null medium descriptor which is not associated with any medium.
    75      * The state field is set to KMediaState_NotCreated.
    76      */
    77     VBoxMedium()
    78         : mType (VBoxDefs::MediaType_Invalid)
    79         , mState (KMediaState_NotCreated)
    80         , mIsReadOnly (false), mIsUsedInSnapshots (false)
    81         , mParent (NULL) {}
    82 
    83     /**
    84      * Creates a media descriptor associated with the given medium.
    85      *
    86      * The state field remain KMediaState_NotCreated until #blockAndQueryState()
    87      * is called. All precomposed strings are filled up by implicitly calling
    88      * #refresh(), see the #refresh() details for more info.
    89      *
    90      * One of the hardDisk, dvdImage, or floppyImage members is assigned from
    91      * aMedium according to aType. @a aParent must be always NULL for non-hard
    92      * disk media.
    93      */
    94     VBoxMedium (const CMedium &aMedium, VBoxDefs::MediaType aType,
    95                 VBoxMedium *aParent = NULL)
    96         : mMedium (aMedium), mType (aType)
    97         , mState (KMediaState_NotCreated)
    98         , mIsReadOnly (false), mIsUsedInSnapshots (false)
    99         , mParent (aParent) { init(); }
    100 
    101     /**
    102      * Similar to the other non-null constructor but sets the media state to
    103      * @a aState. Suitable when the media state is known such as right after
    104      * creation.
    105      */
    106     VBoxMedium (const CMedium &aMedium, VBoxDefs::MediaType aType,
    107                 KMediaState aState)
    108         : mMedium (aMedium), mType (aType)
    109         , mState (aState)
    110         , mIsReadOnly (false), mIsUsedInSnapshots (false)
    111         , mParent (NULL) { init(); }
    112 
    113     void blockAndQueryState();
    114     void refresh();
    115 
    116     const CMedium &medium() const { return mMedium; };
    117 
    118     VBoxDefs::MediaType type() const { return mType; }
    119 
    120     /**
    121      * Media state. In "don't show diffs" mode, this is the worst state (in
    122      * terms of inaccessibility) detected on the given hard disk chain.
    123      *
    124      * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
    125      */
    126     KMediaState state (bool aNoDiffs = false) const
    127     {
    128         unconst (this)->checkNoDiffs (aNoDiffs);
    129         return aNoDiffs ? mNoDiffs.state : mState;
    130     }
    131 
    132     QString lastAccessError() const { return mLastAccessError; }
    133 
    134     /**
    135      * Result of the last blockAndQueryState() call. Will indicate an error and
    136      * contain a proper error info if the last state check fails. In "don't show
    137      * diffs" mode, this is the worst result (in terms of inaccessibility)
    138      * detected on the given hard disk chain.
    139      *
    140      * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
    141      */
    142     const COMResult &result (bool aNoDiffs = false) const
    143     {
    144         unconst (this)->checkNoDiffs (aNoDiffs);
    145         return aNoDiffs ? mNoDiffs.result : mResult;
    146     }
    147 
    148     const CHardDisk &hardDisk() const { return mHardDisk; }
    149     const CDVDImage &dvdImage() const { return mDVDImage; }
    150     const CFloppyImage &floppyImage() const { return mFloppyImage; }
    151 
    152     QUuid id() const { return mId; }
    153 
    154     QString location (bool aNoDiffs = false) const
    155         { return aNoDiffs ? root().mLocation : mLocation; }
    156     QString name (bool aNoDiffs = false) const
    157         { return aNoDiffs ? root().mName : mName; }
    158 
    159     QString size (bool aNoDiffs = false) const
    160         { return aNoDiffs ? root().mSize : mSize; }
    161 
    162     QString hardDiskFormat (bool aNoDiffs = false) const
    163         { return aNoDiffs ? root().mHardDiskFormat : mHardDiskFormat; }
    164     QString hardDiskType (bool aNoDiffs = false) const
    165         { return aNoDiffs ? root().mHardDiskType : mHardDiskType; }
    166     QString logicalSize (bool aNoDiffs = false) const
    167         { return aNoDiffs ? root().mLogicalSize : mLogicalSize; }
    168 
    169     QString usage (bool aNoDiffs = false) const
    170     { return aNoDiffs ? root().mUsage : mUsage; }
    171 
    172     /**
    173      * Returns @c true if this medium is read-only (either because it is
    174      * Immutable or because it has child hard disks). Read-only media can only
    175      * be attached indirectly.
    176      */
    177     bool isReadOnly() const { return mIsReadOnly; }
    178 
    179     /**
    180      * Returns @c true if this medium is attached to any VM (in the current
    181      * state or in a snapshot) in which case #usage() will contain a string with
    182      * comma-sparated VM names (with snapshot names, if any, in parenthesis).
    183      */
    184     bool isUsed() const { return !mUsage.isNull(); }
    185 
    186     /**
    187      * Returns @c true if this medium is attached to any VM in any snapshot.
    188      * which case #usage() will contain a string with comma-sparated VM names.
    189      */
    190     bool isUsedInSnapshots() const { return mIsUsedInSnapshots; }
    191 
    192     /**
    193      * Returns @c true if this medium is attached to the given machine in the
    194      * current state.
    195      */
    196     bool isAttachedInCurStateTo (const QUuid &aMachineId) const
    197         { return mCurStateMachineIds.indexOf (aMachineId) >= 0; }
    198 
    199     /**
    200      * Returns a vector of IDs of all machines this medium is attached
    201      * to in their current state (i.e. excluding snapshots).
    202      */
    203     const QList <QUuid> &curStateMachineIds() const
    204         { return mCurStateMachineIds; }
    205 
    206     /**
    207      * Returns a parent medium. For non-hard disk media, this is always NULL.
    208      */
    209     VBoxMedium *parent() const { return mParent; }
    210 
    211     VBoxMedium &root() const;
    212 
    213     QString toolTip(bool aNoDiffs = false, bool aCheckRO = false) const;
    214     QPixmap icon (bool aNoDiffs = false, bool aCheckRO = false) const;
    215 
    216     /** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */
    217     QString toolTipCheckRO (bool aNoDiffs = false) const
    218         { return toolTip (aNoDiffs, true); }
    219 
    220     /** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */
    221     QPixmap iconCheckRO (bool aNoDiffs = false) const
    222         { return icon (aNoDiffs, true); }
    223 
    224     QString details (bool aNoDiffs = false, bool aPredictDiff = false,
    225                      bool aUseHTML = false) const;
    226 
    227     /** Shortcut to <tt>#details (aNoDiffs, aPredictDiff, true)</tt>. */
    228     QString detailsHTML (bool aNoDiffs = false, bool aPredictDiff = false) const
    229         { return details (aNoDiffs, aPredictDiff, true); }
    230 
    231     /** Returns @c true if this media descriptor is a null object. */
    232     bool isNull() const { return mMedium.isNull(); }
    233 
    234 private:
    235 
    236     void init();
    237 
    238     void checkNoDiffs (bool aNoDiffs);
    239 
    240     CMedium mMedium;
    241 
    242     VBoxDefs::MediaType mType;
    243 
    244     KMediaState mState;
    245     QString mLastAccessError;
    246     COMResult mResult;
    247 
    248     CHardDisk mHardDisk;
    249     CDVDImage mDVDImage;
    250     CFloppyImage mFloppyImage;
    251 
    252     QUuid mId;
    253     QString mLocation;
    254     QString mName;
    255     QString mSize;
    256 
    257     QString mHardDiskFormat;
    258     QString mHardDiskType;
    259     QString mLogicalSize;
    260 
    261     QString mUsage;
    262     QString mToolTip;
    263 
    264     bool mIsReadOnly        : 1;
    265     bool mIsUsedInSnapshots : 1;
    266 
    267     QList <QUuid> mCurStateMachineIds;
    268 
    269     VBoxMedium *mParent;
    270 
    271     /**
    272      * Used to override some attributes in the user-friendly "don't show diffs"
    273      * mode.
    274      */
    275     struct NoDiffs
    276     {
    277         NoDiffs() : isSet (false), state (KMediaState_NotCreated) {}
    278 
    279         bool isSet : 1;
    280 
    281         KMediaState state;
    282         COMResult result;
    283         QString toolTip;
    284     }
    285     mNoDiffs;
    286 };
    287 
    288 typedef QLinkedList <VBoxMedium> VBoxMediaList;
    28945
    29046// VirtualBox callback events
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r17383 r17384  
    117117typedef unsigned long Q_ULONG;      /* word up to 64 bit unsigned */
    118118#endif
    119 
    120 // VBoxMedium
    121 /////////////////////////////////////////////////////////////////////////////
    122 
    123 void VBoxMedium::init()
    124 {
    125     AssertReturnVoid (!mMedium.isNull());
    126 
    127     switch (mType)
    128     {
    129         case VBoxDefs::MediaType_HardDisk:
    130         {
    131             mHardDisk = mMedium;
    132             AssertReturnVoid (!mHardDisk.isNull());
    133             break;
    134         }
    135         case VBoxDefs::MediaType_DVD:
    136         {
    137             mDVDImage = mMedium;
    138             AssertReturnVoid (!mDVDImage.isNull());
    139             Assert (mParent == NULL);
    140             break;
    141         }
    142         case VBoxDefs::MediaType_Floppy:
    143         {
    144             mFloppyImage = mMedium;
    145             AssertReturnVoid (!mFloppyImage.isNull());
    146             Assert (mParent == NULL);
    147             break;
    148         }
    149         default:
    150             AssertFailed();
    151     }
    152 
    153     refresh();
    154 }
    155 
    156 /**
    157  * Queries the medium state. Call this and then read the state field instad
    158  * of calling GetState() on medium directly as it will properly handle the
    159  * situation when GetState() itself fails by setting state to Inaccessible
    160  * and memorizing the error info describing why GetState() failed.
    161  *
    162  * As the last step, this method calls #refresh() to refresh all precomposed
    163  * strings.
    164  *
    165  * @note This method blocks for the duration of the state check. Since this
    166  *       check may take quite a while (e.g. for a medium located on a
    167  *       network share), the calling thread must not be the UI thread. You
    168  *       have been warned.
    169  */
    170 void VBoxMedium::blockAndQueryState()
    171 {
    172     mState = mMedium.GetState();
    173 
    174     /* save the result to distinguish between inaccessible and e.g.
    175      * uninitialized objects */
    176     mResult = COMResult (mMedium);
    177 
    178     if (!mResult.isOk())
    179     {
    180         mState = KMediaState_Inaccessible;
    181         mLastAccessError = QString::null;
    182     }
    183     else
    184         mLastAccessError = mMedium.GetLastAccessError();
    185 
    186     refresh();
    187 }
    188 
    189 /**
    190  * Refreshes the precomposed strings containing such media parameters as
    191  * location, size by querying the respective data from the associated
    192  * media object.
    193  *
    194  * Note that some string such as #size() are meaningless if the media state is
    195  * KMediaState_NotCreated (i.e. the medium has not yet been checked for
    196  * accessibility).
    197  */
    198 void VBoxMedium::refresh()
    199 {
    200     mId = mMedium.GetId();
    201     mLocation = mMedium.GetLocation();
    202     mName = mMedium.GetName();
    203 
    204     if (mType == VBoxDefs::MediaType_HardDisk)
    205     {
    206         /// @todo NEWMEDIA use CSystemProperties::GetHardDIskFormats to see if the
    207         /// given hard disk format is a file
    208         mLocation = QDir::toNativeSeparators (mLocation);
    209         mHardDiskFormat = mHardDisk.GetFormat();
    210         mHardDiskType = vboxGlobal().hardDiskTypeString (mHardDisk);
    211 
    212         mIsReadOnly = mHardDisk.GetReadOnly();
    213 
    214         /* adjust the parent if necessary (note that mParent must always point
    215          * to an item from VBoxGlobal::currentMediaList()) */
    216 
    217         CHardDisk parent = mHardDisk.GetParent();
    218         Assert (!parent.isNull() || mParent == NULL);
    219 
    220         if (!parent.isNull() &&
    221             (mParent == NULL || mParent->mHardDisk != parent))
    222         {
    223             /* search for the parent (must be there) */
    224             const VBoxMediaList &list = vboxGlobal().currentMediaList();
    225             for (VBoxMediaList::const_iterator it = list.begin();
    226                  it != list.end(); ++ it)
    227             {
    228                 if ((*it).mType != VBoxDefs::MediaType_HardDisk)
    229                     break;
    230 
    231                 if ((*it).mHardDisk == parent)
    232                 {
    233                     /* we unconst here because by the const list we don't mean
    234                      * const items */
    235                     mParent = unconst (&*it);
    236                     break;
    237                 }
    238             }
    239 
    240             Assert (mParent != NULL && mParent->mHardDisk == parent);
    241         }
    242     }
    243     else
    244     {
    245         mLocation = QDir::toNativeSeparators (mLocation);
    246         mHardDiskFormat = QString::null;
    247         mHardDiskType = QString::null;
    248 
    249         mIsReadOnly = false;
    250     }
    251 
    252     if (mState != KMediaState_Inaccessible &&
    253         mState != KMediaState_NotCreated)
    254     {
    255         mSize = vboxGlobal().formatSize (mMedium.GetSize());
    256         if (mType == VBoxDefs::MediaType_HardDisk)
    257             mLogicalSize = vboxGlobal()
    258                 .formatSize (mHardDisk.GetLogicalSize() * _1M);
    259         else
    260             mLogicalSize = mSize;
    261     }
    262     else
    263     {
    264         mSize = mLogicalSize = QString ("--");
    265     }
    266 
    267     /* detect usage */
    268 
    269     mUsage = QString::null; /* important: null means not used! */
    270 
    271     mCurStateMachineIds.clear();
    272 
    273     QVector <QUuid> machineIds = mMedium.GetMachineIds();
    274     if (machineIds.size() > 0)
    275     {
    276         QString usage;
    277 
    278         CVirtualBox vbox = vboxGlobal().virtualBox();
    279 
    280         for (QVector <QUuid>::ConstIterator it = machineIds.begin();
    281              it != machineIds.end(); ++ it)
    282         {
    283             CMachine machine = vbox.GetMachine (*it);
    284 
    285             QString name = machine.GetName();
    286             QString snapshots;
    287 
    288             QVector <QUuid> snapIds = mMedium.GetSnapshotIds (*it);
    289             for (QVector <QUuid>::ConstIterator jt = snapIds.begin();
    290                  jt != snapIds.end(); ++ jt)
    291             {
    292                 if (*jt == *it)
    293                 {
    294                     /* the medium is attached to the machine in the current
    295                      * state, we don't distinguish this for now by always
    296                      * giving the VM name in front of snapshot names. */
    297 
    298                     mCurStateMachineIds.push_back (*jt);
    299                     continue;
    300                 }
    301 
    302                 CSnapshot snapshot = machine.GetSnapshot (*jt);
    303                 if (!snapshots.isNull())
    304                     snapshots += ", ";
    305                 snapshots += snapshot.GetName();
    306             }
    307 
    308             if (!usage.isNull())
    309                 usage += ", ";
    310 
    311             usage += name;
    312 
    313             if (!snapshots.isNull())
    314             {
    315                 usage += QString (" (%2)").arg (snapshots);
    316                 mIsUsedInSnapshots = true;
    317             }
    318             else
    319                 mIsUsedInSnapshots = false;
    320         }
    321 
    322         Assert (!usage.isEmpty());
    323         mUsage = usage;
    324     }
    325 
    326     /* compose the tooltip (makes sense to keep the format in sync with
    327      * VBoxMediaManagerDlg::languageChangeImp() and
    328      * VBoxMediaManagerDlg::processCurrentChanged()) */
    329 
    330     mToolTip = QString ("<nobr><b>%1</b></nobr>").arg (mLocation);
    331 
    332     if (mType == VBoxDefs::MediaType_HardDisk)
    333     {
    334         mToolTip += VBoxGlobal::tr (
    335             "<br><nobr>Type&nbsp;(Format):&nbsp;&nbsp;%2&nbsp;(%3)</nobr>",
    336             "hard disk")
    337             .arg (mHardDiskType)
    338             .arg (mHardDiskFormat);
    339     }
    340 
    341     mToolTip += VBoxGlobal::tr (
    342         "<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>", "medium")
    343         .arg (mUsage.isNull() ?
    344               VBoxGlobal::tr ("<i>Not&nbsp;Attached</i>", "medium") :
    345               mUsage);
    346 
    347     switch (mState)
    348     {
    349         case KMediaState_NotCreated:
    350         {
    351             mToolTip += VBoxGlobal::tr ("<br><i>Checking accessibility...</i>",
    352                                         "medium");
    353             break;
    354         }
    355         case KMediaState_Inaccessible:
    356         {
    357             if (mResult.isOk())
    358             {
    359                 /* not accessibile */
    360                 mToolTip += QString ("<hr>%1").
    361                     arg (VBoxGlobal::highlight (mLastAccessError,
    362                                                 true /* aToolTip */));
    363             }
    364             else
    365             {
    366                 /* accessibility check (eg GetState()) itself failed */
    367                 mToolTip = VBoxGlobal::tr (
    368                     "<hr>Failed to check media accessibility.<br>%1.",
    369                     "medium").
    370                     arg (VBoxProblemReporter::formatErrorInfo (mResult));
    371             }
    372             break;
    373         }
    374         default:
    375             break;
    376     }
    377 
    378     /* reset mNoDiffs */
    379     mNoDiffs.isSet = false;
    380 }
    381 
    382 /**
    383  * Returns a root medium of this medium. For non-hard disk media, this is always
    384  * this medium itself.
    385  */
    386 VBoxMedium &VBoxMedium::root() const
    387 {
    388     VBoxMedium *root = unconst (this);
    389     while (root->mParent != NULL)
    390         root = root->mParent;
    391 
    392     return *root;
    393 }
    394 
    395 /**
    396  * Returns a tooltip for this medium.
    397  *
    398  * In "don't show diffs" mode (where the attributes of the base hard disk are
    399  * shown instead of the attributes of the differencing hard disk), extra
    400  * information will be added to the tooltip to give the user a hint that the
    401  * medium is actually a differencing hard disk.
    402  *
    403  * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
    404  * @param aCheckRO  @c true to perform the #readOnly() check and add a notice
    405  *                  accordingly.
    406  */
    407 QString VBoxMedium::toolTip (bool aNoDiffs /*= false*/,
    408                              bool aCheckRO /*= false*/) const
    409 {
    410     unconst (this)->checkNoDiffs (aNoDiffs);
    411 
    412     QString tip = aNoDiffs ? mNoDiffs.toolTip : mToolTip;
    413 
    414     if (aCheckRO && mIsReadOnly)
    415         tip += VBoxGlobal::tr (
    416             "<hr><img src=%1/>&nbsp;Attaching this hard disk will "
    417             "be performed indirectly using a newly created "
    418             "differencing hard disk.",
    419             "medium").
    420             arg (":/new_16px.png");
    421 
    422     return tip;
    423 }
    424 
    425 /**
    426  * Returns an icon corresponding to the media state. Distinguishes between
    427  * the Inaccessible state and the situation when querying the state itself
    428  * failed.
    429  *
    430  * In "don't show diffs" mode (where the attributes of the base hard disk are
    431  * shown instead of the attributes of the differencing hard disk), the most
    432  * worst media state on the given hard disk chain will be used to select the
    433  * media icon.
    434  *
    435  * @param aNoDiffs  @c true to enable user-friendly "don't show diffs" mode.
    436  * @param aCheckRO  @c true to perform the #readOnly() check and change the icon
    437  *                  accordingly.
    438  */
    439 QPixmap VBoxMedium::icon (bool aNoDiffs /*= false*/,
    440                           bool aCheckRO /*= false*/) const
    441 {
    442     QPixmap icon;
    443 
    444     if (state (aNoDiffs) == KMediaState_Inaccessible)
    445         icon = result (aNoDiffs).isOk() ?
    446             vboxGlobal().warningIcon() : vboxGlobal().errorIcon();
    447 
    448     if (aCheckRO && mIsReadOnly)
    449         icon = VBoxGlobal::
    450             joinPixmaps (icon, QPixmap (":/new_16px.png"));
    451 
    452     return icon;
    453 }
    454 
    455 /**
    456  * Returns the details of this medium as a single-line string
    457  *
    458  * For hard disks, the details include the location, type and the logical size
    459  * of the hard disk. Note that if @a aNoDiffs is @c true, these properties are
    460  * queried on the root hard disk of the given hard disk because the primary
    461  * purpose of the returned string is to be human readabile (so that seeing a
    462  * complex diff hard disk name is usually not desirable).
    463  *
    464  * For other media types, the location and the actual size are returned.
    465  * Arguments @a aPredictDiff and @a aNoRoot are ignored in this case.
    466  *
    467  * @param aNoDiffs      @c true to enable user-friendly "don't show diffs" mode.
    468  * @param aPredictDiff  @c true to mark the hard disk as differencing if
    469  *                      attaching it would create a differencing hard disk (not
    470  *                      used when @a aNoRoot is true).
    471  * @param aUseHTML      @c true to allow for emphasizing using bold and italics.
    472  *
    473  * @note Use #detailsHTML() instead of passing @c true for @a aUseHTML.
    474  *
    475  * @note The media object may become uninitialized by a third party while this
    476  *       method is reading its properties. In this case, the method will return
    477  *       an empty string.
    478  */
    479 QString VBoxMedium::details (bool aNoDiffs /*= false*/,
    480                              bool aPredictDiff /*= false*/,
    481                              bool aUseHTML /*= false */) const
    482 {
    483     // @todo *** the below check is rough; if mMedium becomes uninitialized, any
    484     // of getters called afterwards will also fail. The same relates to the
    485     // root hard disk object (that will be the hard disk itself in case of
    486     // non-differencing disks). However, this check was added to fix a
    487     // particular use case: when the hard disk is a differencing hard disk and
    488     // it happens to be discarded (and uninitialized) after this method is
    489     // called but before we read all its properties (yes, it's possible!), the
    490     // root object will be null and calling methods on it will assert in the
    491     // debug builds. This check seems to be enough as a quick solution (fresh
    492     // hard disk attachments will be re-read by a machine state change signal
    493     // after the discard operation is finished, so the user will eventually see
    494     // correct data), but in order to solve the problem properly we need to use
    495     // exceptions everywhere (or check the result after every method call). See
    496     // also Defect #2149.
    497     if (!mMedium.isOk())
    498         return QString::null;
    499 
    500     QString details, str;
    501 
    502     VBoxMedium *root = unconst (this);
    503     KMediaState state = mState;
    504 
    505     if (mType == VBoxDefs::MediaType_HardDisk)
    506     {
    507         if (aNoDiffs)
    508         {
    509             root = &this->root();
    510 
    511             bool isDiff =
    512                 (!aPredictDiff && mParent != NULL) ||
    513                 (aPredictDiff && mIsReadOnly);
    514 
    515             details = isDiff && aUseHTML ?
    516                 QString ("<i>%1</i>, ").arg (root->mHardDiskType) :
    517                 QString ("%1, ").arg (root->mHardDiskType);
    518 
    519             /* overall (worst) state */
    520             state = this->state (true /* aNoDiffs */);
    521 
    522             /* we cannot get the logical size if the root is not checked yet */
    523             if (root->mState == KMediaState_NotCreated)
    524                 state = KMediaState_NotCreated;
    525         }
    526         else
    527         {
    528             details = QString ("%1, ").arg (root->mHardDiskType);
    529         }
    530     }
    531 
    532     /// @todo prepend the details with the warning/error
    533     //  icon when not accessible
    534 
    535     switch (state)
    536     {
    537         case KMediaState_NotCreated:
    538             str = VBoxGlobal::tr ("Checking...", "medium");
    539             details += aUseHTML ? QString ("<i>%1</i>").arg (str) : str;
    540             break;
    541         case KMediaState_Inaccessible:
    542             str = VBoxGlobal::tr ("Inaccessible", "medium");
    543             details += aUseHTML ? QString ("<b>%1</b>").arg (str) : str;
    544             break;
    545         default:
    546             details += mType == VBoxDefs::MediaType_HardDisk ?
    547                        root->mLogicalSize : root->mSize;
    548             break;
    549     }
    550 
    551     details = aUseHTML ?
    552         QString ("%1 (<nobr>%2</nobr>)").
    553             arg (VBoxGlobal::locationForHTML (root->mName), details) :
    554         QString ("%1 (%2)").
    555             arg (VBoxGlobal::locationForHTML (root->mName), details);
    556 
    557     return details;
    558 }
    559 
    560 /**
    561  * Checks if mNoDiffs is filled in and does it if not.
    562  *
    563  * @param aNoDiffs  @if false, this method immediately returns.
    564  */
    565 void VBoxMedium::checkNoDiffs (bool aNoDiffs)
    566 {
    567     if (!aNoDiffs || mNoDiffs.isSet)
    568         return;
    569 
    570     /* fill mNoDiffs */
    571 
    572     mNoDiffs.toolTip = QString::null;
    573 
    574     /* detect the overall (worst) state of the given hard disk chain */
    575     mNoDiffs.state = mState;
    576     for (VBoxMedium *cur = mParent; cur != NULL;
    577          cur = cur->mParent)
    578     {
    579         if (cur->mState == KMediaState_Inaccessible)
    580         {
    581             mNoDiffs.state = cur->mState;
    582 
    583             if (mNoDiffs.toolTip.isNull())
    584                 mNoDiffs.toolTip = VBoxGlobal::tr (
    585                     "<hr>Some of the media in this hard disk chain are "
    586                     "inaccessible. Please use the Virtual Media Manager "
    587                     "in <b>Show Differencing Hard Disks</b> mode to inspect "
    588                     "these media.");
    589 
    590             if (!cur->mResult.isOk())
    591             {
    592                 mNoDiffs.result = cur->mResult;
    593                 break;
    594             }
    595 
    596             /* comtinue looking for another !cur->mResult.isOk() */
    597         }
    598     }
    599 
    600     if (mParent != NULL && !mIsReadOnly)
    601     {
    602         mNoDiffs.toolTip = VBoxGlobal::tr (
    603             "%1"
    604             "<hr>This base hard disk is indirectly attached using the "
    605             "following differencing hard disk:<br>"
    606             "%2%3").
    607             arg (root().toolTip(), mToolTip, mNoDiffs.toolTip);
    608     }
    609 
    610     if (mNoDiffs.toolTip.isNull())
    611         mNoDiffs.toolTip = mToolTip;
    612 
    613     mNoDiffs.isSet = true;
    614 }
    615119
    616120// VBoxMediaEnumEvent
     
    52234727    switch (e->type())
    52244728    {
    5225 #if defined (Q_WS_WIN)
    5226         case VBoxDefs::ShellExecuteEventType:
    5227         {
    5228             VBoxShellExecuteEvent *ev = (VBoxShellExecuteEvent *) e;
    5229             if (!ev->mOk)
    5230                 vboxProblem().cannotOpenURL (ev->mURL);
    5231             /* wait for the thread and free resources */
    5232             ev->mThread->wait();
    5233             delete ev->mThread;
    5234             return true;
    5235         }
    5236 #endif
    5237 
    52384729        case VBoxDefs::AsyncEventType:
    52394730        {
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