VirtualBox

Ignore:
Timestamp:
Nov 3, 2009 4:13:57 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
54287
Message:

FE/Qt4: VBoxMedium cumulative patch: fixed tool-tip regression (for complex tool-tips) caused by Qt bugs related to html <nobr> tag ignoring; Possible fixed crash while copying CMedium object wrapped in VBoxMedium extension.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxMedium.h

    r23585 r24294  
    3232
    3333/**
     34 * Cache used to override some attributes in the user-friendly "don't show diffs" mode.
     35 */
     36struct NoDiffsCache
     37{
     38    NoDiffsCache() : isSet (false), state (KMediumState_NotCreated) {}
     39    NoDiffsCache& operator= (const NoDiffsCache &aOther)
     40    {
     41        isSet = aOther.isSet;
     42        state = aOther.state;
     43        result = aOther.result;
     44        toolTip = aOther.toolTip;
     45        return *this;
     46    }
     47
     48    bool isSet : 1;
     49
     50    KMediumState state;
     51    COMResult result;
     52    QString toolTip;
     53};
     54
     55/**
    3456 * Media descriptor for the GUI.
    3557 *
     
    100122        , mParent (0) { refresh(); }
    101123
     124    VBoxMedium& operator= (const VBoxMedium &aOther);
     125
    102126    void blockAndQueryState();
    103127    void refresh();
     
    138162    QString name (bool aNoDiffs = false) const { return aNoDiffs ? root().mName : mName; }
    139163    QString location (bool aNoDiffs = false) const { return aNoDiffs ? root().mLocation : mLocation; }
     164
    140165    QString size (bool aNoDiffs = false) const { return aNoDiffs ? root().mSize : mSize; }
    141166    QString logicalSize (bool aNoDiffs = false) const { return aNoDiffs ? root().mLogicalSize : mLogicalSize; }
     167
    142168    QString hardDiskFormat (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskFormat : mHardDiskFormat; }
    143169    QString hardDiskType (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskType : mHardDiskType; }
     170
    144171    QString usage (bool aNoDiffs = false) const { return aNoDiffs ? root().mUsage : mUsage; }
     172    QString tip() const { return mToolTip; }
     173
     174    const NoDiffsCache& cache() const { return mNoDiffs; }
    145175
    146176    /**
     
    182212     * Returns a parent medium. For non-hard disk media, this is always NULL.
    183213     */
    184     VBoxMedium *parent() const { return mParent; }
    185 
    186     VBoxMedium &root() const;
     214    VBoxMedium* parent() const { return mParent; }
     215
     216    VBoxMedium& root() const;
    187217
    188218    QString toolTip (bool aNoDiffs = false, bool aCheckRO = false, bool aNullAllowed = false) const;
     
    216246
    217247    QString mId;
     248    QString mName;
    218249    QString mLocation;
    219     QString mName;
     250
    220251    QString mSize;
     252    QString mLogicalSize;
    221253
    222254    QString mHardDiskFormat;
    223255    QString mHardDiskType;
    224     QString mLogicalSize;
    225256
    226257    QString mUsage;
     
    235266    VBoxMedium *mParent;
    236267
    237     /**
    238      * Used to override some attributes in the user-friendly "don't show diffs"
    239      * mode.
    240      */
    241     struct NoDiffs
    242     {
    243         NoDiffs() : isSet (false), state (KMediumState_NotCreated) {}
    244 
    245         bool isSet : 1;
    246 
    247         KMediumState state;
    248         COMResult result;
    249         QString toolTip;
    250     }
    251     mNoDiffs;
     268    NoDiffsCache mNoDiffs;
     269
     270    static QString mTable;
     271    static QString mRow;
    252272};
    253273
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMedium.cpp

    r24258 r24294  
    2828#include "VBoxGlobal.h"
    2929#include "VBoxProblemReporter.h"
     30
     31QString VBoxMedium::mTable = QString ("<table>%1</table>");
     32QString VBoxMedium::mRow = QString ("<tr><td>%1</td></tr>");
     33
     34VBoxMedium& VBoxMedium::operator= (const VBoxMedium &aOther)
     35{
     36    mMedium = aOther.medium();
     37    mType = aOther.type();
     38    mState = aOther.state();
     39    mLastAccessError = aOther.lastAccessError();
     40    mResult = aOther.result();
     41
     42    mId = aOther.id();
     43    mName = aOther.name();
     44    mLocation = aOther.location();
     45
     46    mSize = aOther.size();
     47    mLogicalSize = aOther.logicalSize();
     48
     49    mHardDiskFormat = aOther.hardDiskFormat();
     50    mHardDiskType = aOther.hardDiskType();
     51
     52    mUsage = aOther.usage();
     53    mToolTip = aOther.tip();
     54
     55    mIsReadOnly = aOther.isReadOnly();
     56    mIsUsedInSnapshots = aOther.isUsedInSnapshots();
     57    mIsHostDrive = aOther.isHostDrive();
     58
     59    mCurStateMachineIds = aOther.curStateMachineIds();
     60
     61    mParent = aOther.parent();
     62
     63    mNoDiffs = aOther.cache();
     64
     65    return *this;
     66}
    3067
    3168/**
     
    97134        mIsReadOnly = mMedium.GetReadOnly();
    98135
    99         /* Adjust the parent if necessary (note that mParent must always point
    100          * to an item from VBoxGlobal::currentMediaList()) */
     136        /* Adjust the parent if its possible */
    101137        CMedium parent = mMedium.GetParent();
    102138        Assert (!parent.isNull() || mParent == NULL);
     
    104140        if (!parent.isNull() && (mParent == NULL || mParent->mMedium != parent))
    105141        {
    106             /* Search for the parent (must be there) */
     142            /* Search for the parent (might be there) */
    107143            const VBoxMediaList &list = vboxGlobal().currentMediaList();
    108144            for (VBoxMediaList::const_iterator it = list.begin(); it != list.end(); ++ it)
     
    117153                }
    118154            }
    119 
    120 //             Assert(mParent != NULL);
    121 //             Assert(mParent->mMedium == parent);
    122155        }
    123156    }
     
    167200                    if (*jt == *it)
    168201                    {
    169                         /* the medium is attached to the machine in the current
     202                        /* The medium is attached to the machine in the current
    170203                         * state, we don't distinguish this for now by always
    171204                         * giving the VM name in front of snapshot names. */
    172 
    173205                        mCurStateMachineIds.push_back (*jt);
    174206                        continue;
     
    203235    if (!mMedium.isNull())
    204236    {
    205         mToolTip = QString ("<nobr><b>%1</b></nobr>").arg (mIsHostDrive ? mName : mLocation);
     237        mToolTip = mRow.arg (QString ("<p style=white-space:pre><b>%1</b></p>").arg (mIsHostDrive ? mName : mLocation));
    206238
    207239        if (mType == VBoxDefs::MediumType_HardDisk)
    208240        {
    209             mToolTip += VBoxGlobal::tr (
    210                 "<br><nobr>Type&nbsp;(Format):&nbsp;&nbsp;%2&nbsp;(%3)</nobr>", "hard disk")
    211                 .arg (mHardDiskType).arg (mHardDiskFormat);
    212         }
    213 
    214         mToolTip += VBoxGlobal::tr (
    215             "<br><nobr>Attached&nbsp;to:&nbsp;&nbsp;%1</nobr>", "medium")
    216             .arg (mUsage.isNull() ? VBoxGlobal::tr ("<i>Not&nbsp;Attached</i>", "medium") : mUsage);
     241            mToolTip += mRow.arg (VBoxGlobal::tr ("<p style=white-space:pre>Type (Format):  %1 (%2)</p>", "medium")
     242                                                  .arg (mHardDiskType).arg (mHardDiskFormat));
     243        }
     244
     245        mToolTip += mRow.arg (VBoxGlobal::tr ("<p style=white-space:pre>Attached to:  %1</p>", "image")
     246                                              .arg (mUsage.isNull() ? VBoxGlobal::tr ("<i>Not Attached</i>", "image") : mUsage));
    217247
    218248        switch (mState)
     
    220250            case KMediumState_NotCreated:
    221251            {
    222                 mToolTip += VBoxGlobal::tr ("<br><i>Checking accessibility...</i>", "medium");
     252                mToolTip += mRow.arg (VBoxGlobal::tr ("<i>Checking accessibility...</i>", "medium"));
    223253                break;
    224254            }
     
    227257                if (mResult.isOk())
    228258                {
    229                     /* not accessibile */
    230                     mToolTip += QString ("<hr>%1").
    231                         arg (VBoxGlobal::highlight (mLastAccessError,
    232                                                     true /* aToolTip */));
     259                    /* Not Accessibile */
     260                    mToolTip += mRow.arg ("<hr>") + mRow.arg (VBoxGlobal::highlight (mLastAccessError, true /* aToolTip */));
    233261                }
    234262                else
    235263                {
    236                     /* accessibility check (eg GetState()) itself failed */
    237                     mToolTip = VBoxGlobal::tr (
    238                         "<hr>Failed to check media accessibility.<br>%1.", "medium").
    239                         arg (VBoxProblemReporter::formatErrorInfo (mResult));
     264                    /* Accessibility check (eg GetState()) itself failed */
     265                    mToolTip += mRow.arg ("<hr>") + mRow.arg (VBoxGlobal::tr ("Failed to check media accessibility.", "medium")) +
     266                                mRow.arg (VBoxProblemReporter::formatErrorInfo (mResult) + ".");
    240267                }
    241268                break;
     
    244271                break;
    245272        }
    246 
    247         mToolTip = QString ("<p style='white-space:pre'>%1</p>").arg (mToolTip);
    248     }
    249 
    250     /* reset mNoDiffs */
     273    }
     274
     275    /* Reset mNoDiffs */
    251276    mNoDiffs.isSet = false;
    252277}
     
    266291
    267292/**
    268  * Returns a tooltip for this medium.
     293 * Returns generated tooltip for this medium.
    269294 *
    270295 * In "don't show diffs" mode (where the attributes of the base hard disk are
     
    277302 *                  accordingly.
    278303 */
    279 QString VBoxMedium::toolTip (bool aNoDiffs /*= false*/, bool aCheckRO /*= false*/, bool aNullAllowed /*= false*/) const
     304QString VBoxMedium::toolTip (bool aNoDiffs /* = false */, bool aCheckRO /* = false */, bool aNullAllowed /* = false */) const
    280305{
    281306    QString tip;
     
    283308    if (mMedium.isNull())
    284309    {
    285         tip = aNullAllowed ? VBoxGlobal::tr ("<nobr><b>Not&nbsp;Set</b></nobr><br>"
    286                                              "Required virtual image or host-drive could be mounted at runtime.") :
    287                              VBoxGlobal::tr ("<nobr><b>Not&nbsp;Available</b></nobr><br>"
    288                                              "Use the Virtual Media Manager to add image of the corresponding type.");
     310        tip = aNullAllowed ? mRow.arg (VBoxGlobal::tr ("<b>Not Set</b>", "medium")) +
     311                             mRow.arg (VBoxGlobal::tr ("Required virtual image or host-drive could be mounted at runtime.")) :
     312                             mRow.arg (VBoxGlobal::tr ("<b>Not Available</b>", "medium")) +
     313                             mRow.arg (VBoxGlobal::tr ("Use the Virtual Media Manager to add image of the corresponding type."));
    289314    }
    290315    else
     
    295320
    296321        if (aCheckRO && mIsReadOnly)
    297             tip += VBoxGlobal::tr ("<hr><img src=%1/>&nbsp;Attaching this hard disk will "
    298                                    "be performed indirectly using a newly created "
    299                                    "differencing hard disk.", "medium").arg (":/new_16px.png");
    300     }
    301 
    302     return tip;
     322            tip += mRow.arg ("<hr>") +
     323                   mRow.arg (VBoxGlobal::tr ("Attaching this hard disk will be performed indirectly using "
     324                                             "a newly created differencing hard disk.", "medium"));
     325    }
     326
     327    return mTable.arg (tip);
    303328}
    304329
     
    317342 *                  accordingly.
    318343 */
    319 QPixmap VBoxMedium::icon (bool aNoDiffs /*= false*/,
    320                           bool aCheckRO /*= false*/) const
     344QPixmap VBoxMedium::icon (bool aNoDiffs /* = false */, bool aCheckRO /* = false */) const
    321345{
    322346    QPixmap icon;
     
    355379 *       an empty string.
    356380 */
    357 QString VBoxMedium::details (bool aNoDiffs /*= false*/,
    358                              bool aPredictDiff /*= false*/,
    359                              bool aUseHTML /*= false */) const
    360 {
    361     // @todo *** the below check is rough; if mMedium becomes uninitialized, any
     381QString VBoxMedium::details (bool aNoDiffs /* = false */,
     382                             bool aPredictDiff /* = false */,
     383                             bool aUseHTML /* = false */) const
     384{
     385    // @todo the below check is rough; if mMedium becomes uninitialized, any
    362386    // of getters called afterwards will also fail. The same relates to the
    363387    // root hard disk object (that will be the hard disk itself in case of
     
    397421                QString ("%1, ").arg (root->mHardDiskType);
    398422
    399             /* overall (worst) state */
    400423            state = this->state (true /* aNoDiffs */);
    401424
    402             /* we cannot get the logical size if the root is not checked yet */
    403425            if (root->mState == KMediumState_NotCreated)
    404426                state = KMediumState_NotCreated;
     
    410432    }
    411433
    412     /// @todo prepend the details with the warning/error
    413     //  icon when not accessible
     434    // @todo prepend the details with the warning/error icon when not accessible
    414435
    415436    switch (state)
     
    424445            break;
    425446        default:
    426             details += mType == VBoxDefs::MediumType_HardDisk ?
    427                        root->mLogicalSize : root->mSize;
     447            details += mType == VBoxDefs::MediumType_HardDisk ? root->mLogicalSize : root->mSize;
    428448            break;
    429449    }
    430450
    431451    details = aUseHTML ?
    432         QString ("%1 (<nobr>%2</nobr>)").
    433             arg (VBoxGlobal::locationForHTML (root->mName), details) :
    434         QString ("%1 (%2)").
    435             arg (VBoxGlobal::locationForHTML (root->mName), details);
     452        QString ("%1 (<nobr>%2</nobr>)").arg (VBoxGlobal::locationForHTML (root->mName), details) :
     453        QString ("%1 (%2)").arg (VBoxGlobal::locationForHTML (root->mName), details);
    436454
    437455    return details;
     
    448466        return;
    449467
    450     /* fill mNoDiffs */
    451 
    452468    mNoDiffs.toolTip = QString::null;
    453469
    454     /* detect the overall (worst) state of the given hard disk chain */
    455470    mNoDiffs.state = mState;
    456471    for (VBoxMedium *cur = mParent; cur != NULL; cur = cur->mParent)
     
    461476
    462477            if (mNoDiffs.toolTip.isNull())
    463                 mNoDiffs.toolTip = VBoxGlobal::tr (
    464                     "<hr>Some of the media in this hard disk chain are "
    465                     "inaccessible. Please use the Virtual Media Manager "
    466                     "in <b>Show Differencing Hard Disks</b> mode to inspect "
    467                     "these media.");
     478                mNoDiffs.toolTip = mRow.arg (VBoxGlobal::tr ("Some of the mediums in this hard disk chain "
     479                                                             "are inaccessible. Please use the Virtual Media "
     480                                                             "Manager in <b>Show Differencing Hard Disks</b> "
     481                                                             "mode to inspect these mediums.", "medium"));
    468482
    469483            if (!cur->mResult.isOk())
     
    472486                break;
    473487            }
    474 
    475             /* comtinue looking for another !cur->mResult.isOk() */
    476488        }
    477489    }
     
    479491    if (mParent != NULL && !mIsReadOnly)
    480492    {
    481         mNoDiffs.toolTip = VBoxGlobal::tr (
    482             "%1"
    483             "<hr>This base hard disk is indirectly attached using the "
    484             "following differencing hard disk:<br>"
    485             "%2%3").
    486             arg (root().toolTip(), mToolTip, mNoDiffs.toolTip);
     493        mNoDiffs.toolTip = root().tip() +
     494                           mRow.arg ("<hr>") +
     495                           mRow.arg (VBoxGlobal::tr ("This base hard disk is indirectly attached using "
     496                                                     "the following differencing hard disk:", "medium")) +
     497                           mToolTip + mNoDiffs.toolTip;
    487498    }
    488499
Note: See TracChangeset for help on using the changeset viewer.

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