VirtualBox

Changeset 548 in vbox


Ignore:
Timestamp:
Feb 2, 2007 1:57:12 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
18165
Message:

FE/Qt: Latest fixes to VDM and media enumeration process (better cooperation between media cobmoboxes, modal and modeless VDMs during the enumeration).

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

Legend:

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

    r382 r548  
    245245        return toString (aHD.GetType());
    246246    }
    247    
     247
    248248    QString toString (CEnums::DiskControllerType t, LONG d) const;
    249249
     
    321321
    322322    void startEnumeratingMedia();
    323     bool isInEnumeratingProcess() { return media_enum_thread ? true : false; }
    324 
    325     /** Returns a list of all currently enumerated media (it is empty if the
    326      *  enumeration has been finished or never been started). */
    327     VBoxMediaList currentMediaList() const { return media_list; }
     323
     324    /**
     325     *  Returns a list of all currently registered media. This list is used
     326     *  to globally track the accessiblity state of all media on a dedicated
     327     *  thread. This the list is initially empty (before the first enumeration
     328     *  process is started using #startEnumeratingMedia()).
     329     */
     330    const VBoxMediaList &currentMediaList() const { return media_list; }
     331
     332    /** Returns true if the media enumeration is in progress. */
     333    bool isMediaEnumerationStarted() const { return media_enum_thread != NULL; }
     334
     335    void addMedia (const VBoxMedia &);
     336    void updateMedia (const VBoxMedia &);
     337    void removeMedia (VBoxDefs::DiskType, const QUuid &);
    328338
    329339    /* various helpers */
     
    360370
    361371    /**
    362      *  Emitted during the enumeration process started
    363      *  by #startEnumeratingMedia(). */
    364     void mediaEnumerated (const VBoxMedia &media);
     372     *  Emitted at the beginning of the enumeration process started
     373     *  by #startEnumeratingMedia().
     374     */
     375    void mediaEnumStarted();
     376
     377    /**
     378     *  Emitted when a new media item from the list has updated
     379     *  its accessibility state.
     380     */
     381    void mediaEnumerated (const VBoxMedia &aMedia, int aIndex);
    365382
    366383    /**
     
    368385     *  by #startEnumeratingMedia().
    369386     *  @note #currentMediaList() will return an empty list
    370      *  when this signal is emitted, use the argument instead. */
    371     void mediaEnumerated (const VBoxMediaList &list);
     387     *  when this signal is emitted, use the argument instead.
     388     */
     389    void mediaEnumFinished (const VBoxMediaList &aList);
     390
     391    /** Emitted when a new media is added using #addMedia(). */
     392    void mediaAdded (const VBoxMedia &);
     393
     394    /** Emitted when the media is updated using #updateMedia(). */
     395    void mediaUpdated (const VBoxMedia &);
     396
     397    /** Emitted when the media is removed using #removeMedia(). */
     398    void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
    372399
    373400    /* signals emitted when the VirtualBox callback is called by the server
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxMediaComboBox.h

    r382 r548  
    2727
    2828#include <qcombobox.h>
    29 #include <quuid.h>
    3029
    3130class QListBoxItem;
     
    3736public:
    3837
    39     VBoxMediaComboBox (QWidget *aParent = 0,
    40                        const char *aName = 0, int aType = 0);
     38    VBoxMediaComboBox (QWidget *aParent = 0, const char *aName = 0,
     39                       int aType = 0, bool aUseEmptyItem = false);
    4140    ~VBoxMediaComboBox() {}
    4241
    4342    void  refresh();
    44     void  appendItem (const QString &, const QUuid &, const QString &);
    45     void  replaceItem (int, const QString &, const QString &);
    46     void  removeLastItem();
    47     void  setReadyForRefresh();
    48     void  setRequiredItem (const QUuid &);
    4943    void  setUseEmptyItem (bool);
    5044    void  setBelongsTo (const QUuid &);
    5145    QUuid getId();
    5246    QUuid getBelongsTo();
    53     void setCurrentItem (int);
     47    void  setCurrentItem (const QUuid &);
    5448
    5549protected slots:
    5650
    57     void mediaEnumerated (const VBoxMedia &);
    58     void listEnumerated (const VBoxMediaList &);
     51    void mediaEnumStarted();
     52    void mediaEnumerated (const VBoxMedia &, int);
     53    void mediaEnumFinished (const VBoxMediaList &);
     54    void mediaAdded (const VBoxMedia &);
     55    void mediaUpdated (const VBoxMedia &);
     56    void mediaRemoved (VBoxDefs::DiskType, const QUuid &);
    5957    void processOnItem (QListBoxItem *);
    60     void updateToolTip (int);
     58    void processActivated (int);
    6159
    6260protected:
    6361
    64     void loadCleanContent();
    65     int updateMedia (const QString &, const QUuid &, const QString &,
    66                      VBoxMedia::Status);
     62    void updateToolTip (int);
     63    void setCurrentItem (int);
     64    void processMedia (const VBoxMedia &);
     65    void processHdMedia (const VBoxMedia &);
     66    void processCdMedia (const VBoxMedia &);
     67    void processFdMedia (const VBoxMedia &);
     68    void appendItem (const QString &, const QUuid &,
     69                     const QString &, QPixmap *);
     70    void replaceItem (int, const QString &,
     71                      const QString &, QPixmap *);
     72    void updateShortcut (const QString &, const QUuid &, const QString &,
     73                          VBoxMedia::Status);
    6774
    6875    int         mType;
     
    7279    QUuid       mRequiredId;
    7380    bool        mUseEmptyItem;
    74     bool        mToBeRefreshed;
     81    QPixmap     mPmInacc;
     82    QPixmap     mPmError;
    7583};
    7684
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxSelectorWnd.h

    r382 r548  
    9191    void vmListBoxCurrentChanged (bool aRefreshDetails = true,
    9292                                  bool aRefreshSnapshots = true);
    93     void mediaEnumerated (const VBoxMediaList &list);
     93    void mediaEnumFinished (const VBoxMediaList &);
    9494
    9595    /* VirtualBox callback events we're interested in */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r382 r548  
    5252
    5353    /** Constructs a regular enum event */
    54     VBoxEnumerateMediaEvent (const VBoxMedia &m)
     54    VBoxEnumerateMediaEvent (const VBoxMedia &aMedia, int aIndex)
    5555        : QEvent ((QEvent::Type) VBoxDefs::EnumerateMediaEventType)
    56         , media (m), last (false)
     56        , mMedia (aMedia), mLast (false), mIndex (aIndex)
    5757        {}
    5858    /** Constructs the last enum event */
    5959    VBoxEnumerateMediaEvent()
    6060        : QEvent ((QEvent::Type) VBoxDefs::EnumerateMediaEventType)
    61         , last (true)
     61        , mLast (true), mIndex (-1)
    6262        {}
    6363
    6464    /** the last enumerated media (not valid when #last is true) */
    65     const VBoxMedia media;
     65    const VBoxMedia mMedia;
    6666    /** whether this is the last event for the given enumeration or not */
    67     const bool last;
     67    const bool mLast;
     68    /** last enumerated media index (-1 when #last is true) */
     69    const int mIndex;
    6870};
    6971
     
    580582
    581583    CEnums::HardDiskType type = root.GetType();
    582    
     584
    583585    if (type == CEnums::NormalHardDisk &&
    584586        (aHD != root || (aPredict && root.GetChildren().GetCount() != 0)))
     
    586588    else
    587589        details = hardDiskTypeString (root);
    588    
     590
    589591    details += ", " + formatSize (root.GetSize() * _1M);
    590    
     592
    591593    return details;
    592594}
     
    611613            details += " " + p;
    612614    }
    613     ushort r = aDevice.GetRevision();                   
     615    ushort r = aDevice.GetRevision();
    614616    if (r != 0)
    615617        details += QString().sprintf (" [%04hX]", r);
    616618
    617     return details;       
     619    return details;
    618620}
    619621
     
    642644                        .arg (vboxGlobal().toString (hostDev.GetState()));
    643645    }
    644                        
    645     return tip;       
     646
     647    return tip;
    646648}
    647649
     
    10541056 *  If the enumeration is already in progress, no new thread is started.
    10551057 *
    1056  *  @see #currentMediaList()
     1058 *  @sa #currentMediaList()
     1059 *  @sa #isMediaEnumerationStarted()
    10571060 */
    10581061void VBoxGlobal::startEnumeratingMedia()
    10591062{
    10601063    Assert (valid);
    1061     if (!valid)
    1062         return;
    1063 
    1064     // check if already started but not yet finished
     1064
     1065    /* check if already started but not yet finished */
    10651066    if (media_enum_thread)
    10661067        return;
    10671068
     1069    /* composes a list of all currently known media */
     1070    media_list.clear();
     1071    {
     1072        CHardDiskEnumerator enHD = vbox.GetHardDisks().Enumerate();
     1073        while (enHD.HasMore() && !vboxGlobal_cleanup)
     1074        {
     1075            CHardDisk hd = enHD.GetNext();
     1076            media_list += VBoxMedia (CUnknown (hd), VBoxDefs::HD, VBoxMedia::Unknown);
     1077        }
     1078        CDVDImageEnumerator enCD = vbox.GetDVDImages().Enumerate();
     1079        while (enCD.HasMore() && !vboxGlobal_cleanup)
     1080        {
     1081            CDVDImage cd = enCD.GetNext();
     1082            media_list += VBoxMedia (CUnknown (cd), VBoxDefs::CD, VBoxMedia::Unknown);
     1083        }
     1084        CFloppyImageEnumerator enFD = vbox.GetFloppyImages().Enumerate();
     1085        while (enFD.HasMore() && !vboxGlobal_cleanup)
     1086        {
     1087            CFloppyImage fd = enFD.GetNext();
     1088            media_list += VBoxMedia (CUnknown (fd), VBoxDefs::FD, VBoxMedia::Unknown);
     1089        }
     1090        if (!vboxGlobal_cleanup)
     1091            emit mediaEnumStarted();
     1092    }
     1093
     1094    /* enumeration thread class */
    10681095    class Thread : public QThread
    10691096    {
    10701097    public:
    10711098
     1099        Thread (VBoxMediaList &aList) : mList (aList) {}
     1100
    10721101        virtual void run()
    10731102        {
    10741103            LogFlow (("MediaEnumThread started.\n"));
    1075 
    10761104            COMBase::initializeCOM();
    10771105
     
    10791107            QObject *target = &vboxGlobal();
    10801108
    1081             CHardDiskEnumerator enHd = vbox.GetHardDisks().Enumerate();
    1082             while (enHd.HasMore() && !vboxGlobal_cleanup)
     1109            /* enumerating list */
     1110            int index = 0;
     1111            VBoxMediaList::Iterator it;
     1112            for (it = mList.begin();
     1113                 it != mList.end() && !vboxGlobal_cleanup;
     1114                 ++ it, ++ index)
    10831115            {
    1084                 CHardDisk hd = enHd.GetNext();
    1085                 VBoxMedia::Status status =
    1086                     hd.GetAllAccessible() == TRUE ? VBoxMedia::Ok :
    1087                     hd.isOk() ? VBoxMedia::Inaccessible :
    1088                     VBoxMedia::Error;
    1089 
    1090                 if (status == VBoxMedia::Inaccessible)
     1116                VBoxMedia &media = *it;
     1117                switch (media.type)
    10911118                {
    1092                     // correct media status if the machine using the hard disk
    1093                     // is currently running (so the disk is actually accessed by it
    1094                     // in a normal way)
    1095                     QUuid machineId = hd.GetMachineId();
    1096                     if (!machineId.isNull())
     1119                    case VBoxDefs::HD:
    10971120                    {
    1098                         CMachine machine = vbox.GetMachine (machineId);
    1099                         if (!machine.isNull() && (machine.GetState() >= CEnums::Running))
    1100                             status = VBoxMedia::Ok;
     1121                        CHardDisk hd = media.disk;
     1122                        media.status =
     1123                            hd.GetAllAccessible() == TRUE ? VBoxMedia::Ok :
     1124                            hd.isOk() ? VBoxMedia::Inaccessible :
     1125                            VBoxMedia::Error;
     1126                        if (media.status == VBoxMedia::Inaccessible)
     1127                        {
     1128                            QUuid machineId = hd.GetMachineId();
     1129                            if (!machineId.isNull())
     1130                            {
     1131                                CMachine machine = vbox.GetMachine (machineId);
     1132                                if (!machine.isNull() && (machine.GetState() >= CEnums::Running))
     1133                                    media.status = VBoxMedia::Ok;
     1134                            }
     1135                        }
     1136                        VBoxMedia newMedia (CUnknown(hd), VBoxDefs::HD, media.status);
     1137                        QApplication::postEvent (target,
     1138                            new VBoxEnumerateMediaEvent (newMedia, index));
     1139                        break;
     1140                    }
     1141                    case VBoxDefs::CD:
     1142                    {
     1143                        CDVDImage cd = media.disk;
     1144                        media.status =
     1145                            cd.GetAccessible() == TRUE ? VBoxMedia::Ok :
     1146                            cd.isOk() ? VBoxMedia::Inaccessible :
     1147                            VBoxMedia::Error;
     1148                        VBoxMedia newMedia (CUnknown(cd), VBoxDefs::CD, media.status);
     1149                        QApplication::postEvent (target,
     1150                            new VBoxEnumerateMediaEvent (newMedia, index));
     1151                        break;
     1152                    }
     1153                    case VBoxDefs::FD:
     1154                    {
     1155                        CFloppyImage fd = media.disk;
     1156                        media.status =
     1157                            fd.GetAccessible() == TRUE ? VBoxMedia::Ok :
     1158                            fd.isOk() ? VBoxMedia::Inaccessible :
     1159                            VBoxMedia::Error;
     1160                        VBoxMedia newMedia (CUnknown(fd), VBoxDefs::FD, media.status);
     1161                        QApplication::postEvent (target,
     1162                            new VBoxEnumerateMediaEvent (newMedia, index));
     1163                        break;
     1164                    }
     1165                    default:
     1166                    {
     1167                        AssertMsgFailed (("Invalid aMedia type\n"));
     1168                        break;
    11011169                    }
    11021170                }
    1103 
    1104                 VBoxMedia media =
    1105                     VBoxMedia (CUnknown (hd), VBoxDefs::HD, status);
    1106 
    1107                 QApplication::postEvent (target,
    1108                     new VBoxEnumerateMediaEvent (media));
    11091171            }
    11101172
    1111             CDVDImageEnumerator enDVD = vbox.GetDVDImages().Enumerate();
    1112             while (enDVD.HasMore() && !vboxGlobal_cleanup)
    1113             {
    1114                 CDVDImage dvd = enDVD.GetNext();
    1115                 VBoxMedia::Status status =
    1116                     dvd.GetAccessible() == TRUE ? VBoxMedia::Ok :
    1117                     dvd.isOk() ? VBoxMedia::Inaccessible :
    1118                     VBoxMedia::Error;
    1119 
    1120                 VBoxMedia media =
    1121                     VBoxMedia (CUnknown (dvd), VBoxDefs::CD, status);
    1122 
    1123                 QApplication::postEvent (target,
    1124                     new VBoxEnumerateMediaEvent (media));
    1125             }
    1126 
    1127             CFloppyImageEnumerator enFloppy = vbox.GetFloppyImages().Enumerate();
    1128             while (enFloppy.HasMore() && !vboxGlobal_cleanup)
    1129             {
    1130                 CFloppyImage floppy = enFloppy.GetNext();
    1131                 VBoxMedia::Status status =
    1132                     floppy.GetAccessible() == TRUE ? VBoxMedia::Ok :
    1133                     floppy.isOk() ? VBoxMedia::Inaccessible :
    1134                     VBoxMedia::Error;
    1135 
    1136                 VBoxMedia media =
    1137                     VBoxMedia (CUnknown (floppy), VBoxDefs::FD, status);
    1138 
    1139                 QApplication::postEvent (target,
    1140                     new VBoxEnumerateMediaEvent (media));
    1141             }
    1142 
    1143             // post the last message to indicate the end of enumeration
     1173            /* post the last message to indicate the end of enumeration */
    11441174            if (!vboxGlobal_cleanup)
    11451175                QApplication::postEvent (target, new VBoxEnumerateMediaEvent());
    11461176
    11471177            COMBase::cleanupCOM();
    1148 
    11491178            LogFlow (("MediaEnumThread finished.\n"));
    11501179        }
     1180
     1181    private:
     1182
     1183        VBoxMediaList &mList;
    11511184    };
    11521185
    1153     media_enum_thread = new Thread();
     1186    media_enum_thread = new Thread (media_list);
    11541187    media_enum_thread->start();
     1188}
     1189
     1190/**
     1191 *  Adds a new media to the current media list.
     1192 *  @note Currently, this method does nothing but emits the mediaAdded() signal.
     1193 *        Later, it will be used to synchronize the current media list with
     1194 *        the actial media list on the server after a single media opetartion
     1195 *        performed from within one of our UIs.
     1196 *  @sa #currentMediaList()
     1197 */
     1198void VBoxGlobal::addMedia (const VBoxMedia &aMedia)
     1199{
     1200    emit mediaAdded (aMedia);
     1201}
     1202
     1203/**
     1204 *  Updates the media in the current media list.
     1205 *  @note Currently, this method does nothing but emits the mediaUpdated() signal.
     1206 *        Later, it will be used to synchronize the current media list with
     1207 *        the actial media list on the server after a single media opetartion
     1208 *        performed from within one of our UIs.
     1209 *  @sa #currentMediaList()
     1210 */
     1211void VBoxGlobal::updateMedia (const VBoxMedia &aMedia)
     1212{
     1213    emit mediaUpdated (aMedia);
     1214}
     1215
     1216/**
     1217 *  Removes the media from the current media list.
     1218 *  @note Currently, this method does nothing but emits the mediaRemoved() signal.
     1219 *        Later, it will be used to synchronize the current media list with
     1220 *        the actial media list on the server after a single media opetartion
     1221 *        performed from within one of our UIs.
     1222 *  @sa #currentMediaList()
     1223 */
     1224void VBoxGlobal::removeMedia (VBoxDefs::DiskType aType, const QUuid &aId)
     1225{
     1226    emit mediaRemoved (aType, aId);
    11551227}
    11561228
     
    13571429    AssertReturnVoid (aWidget);
    13581430    AssertReturnVoid (aWidget->isTopLevel());
    1359    
     1431
    13601432    QRect deskGeo, parentGeo;
    13611433    QWidget *w = aRelative;
     
    13681440         * widgets with parents, what a shame. Use mapToGlobal() to workaround. */
    13691441        QPoint d = w->mapToGlobal (QPoint (0, 0));
    1370         d.rx() -= w->geometry().x() - w->x(); 
    1371         d.ry() -= w->geometry().y() - w->y(); 
     1442        d.rx() -= w->geometry().x() - w->x();
     1443        d.ry() -= w->geometry().y() - w->y();
    13721444        parentGeo.moveTopLeft (d);
    13731445    }
     
    13971469        framew = current->frameGeometry().width() - current->width();
    13981470        frameh = current->frameGeometry().height() - current->height();
    1399    
     1471
    14001472        extraw = QMAX (extraw, framew);
    14011473        extrah = QMAX (extrah, frameh);
     
    14131485    }
    14141486#endif
    1415    
     1487
    14161488    /* On non-X11 platforms, the following would be enough instead of the
    1417      * above workaround: */   
     1489     * above workaround: */
    14181490    // QRect geo = frameGeometry();
    14191491    QRect geo = QRect (0, 0, aWidget->width() + extraw,
     
    14221494    geo.moveCenter (QPoint (parentGeo.x() + (parentGeo.width() - 1) / 2,
    14231495                            parentGeo.y() + (parentGeo.height() - 1) / 2));
    1424    
     1496
    14251497    /* ensure the widget is within the available desktop area */
    14261498    QRect newGeo = normalizeGeometry (geo, deskGeo, aCanResize);
    1427    
     1499
    14281500    aWidget->move (newGeo.topLeft());
    1429    
     1501
    14301502    if (aCanResize &&
    14311503        (geo.width() != newGeo.width() || geo.height() != newGeo.height()))
     
    15081580        hund = hund * denom / 100;
    15091581        intg = intg * denom + hund;
    1510         return intg; 
     1582        return intg;
    15111583    }
    15121584    else
     
    15271599 *      digit number that is not greater than the result. This guarantees that
    15281600 *      converting the resulting string back to the integer value in bytes
    1529  *      will not produce a value greater that the initial \a size parameter. 
     1601 *      will not produce a value greater that the initial \a size parameter.
    15301602 *  </li>
    15311603 *  <li>When \a mode is 1, the result is rounded to the smallest two decimal
    15321604 *      digit number that is not less than the result. This guarantees that
    15331605 *      converting the resulting string back to the integer value in bytes
    1534  *      will not produce a value less that the initial \a size parameter. 
     1606 *      will not produce a value less that the initial \a size parameter.
    15351607 *  </li>
    15361608 *  </ul>
     
    15431615QString VBoxGlobal::formatSize (Q_UINT64 aSize, int aMode /* = 0 */)
    15441616{
    1545     static const char *Suffixes [] = { "B", "KB", "MB", "GB", "TB", "PB", NULL }; 
     1617    static const char *Suffixes [] = { "B", "KB", "MB", "GB", "TB", "PB", NULL };
    15461618
    15471619    Q_UINT64 denom = 0;
     
    16041676            {
    16051677                intg /= 1024;
    1606                 ++ suffix; 
     1678                ++ suffix;
    16071679            }
    16081680        }
     
    16141686        number = QString::number (intg);
    16151687    }
    1616    
     1688
    16171689    return QString ("%1 %2").arg (number).arg (Suffixes [suffix]);
    16181690}
     
    16351707QString VBoxGlobal::highlight (const QString &aStr, bool aToolTip /* = false */)
    16361708{
    1637     QString strFont; 
     1709    QString strFont;
    16381710    QString uuidFont;
    16391711    QString endFont;
     
    16441716        endFont = "</font>";
    16451717    }
    1646    
     1718
    16471719    QString text = aStr;
    16481720
     
    16821754            VBoxEnumerateMediaEvent *ev = (VBoxEnumerateMediaEvent *) e;
    16831755
    1684             if (!ev->last)
     1756            if (!ev->mLast)
    16851757            {
    1686                 // gather all media to the list
    1687                 media_list += ev->media;
    1688 
    1689                 if (ev->media.status == VBoxMedia::Error)
    1690                     vboxProblem().cannotGetMediaAccessibility (ev->media.disk);
    1691 
    1692                 emit mediaEnumerated (ev->media);
     1758                if (ev->mMedia.status == VBoxMedia::Error)
     1759                    vboxProblem().cannotGetMediaAccessibility (ev->mMedia.disk);
     1760                media_list [ev->mIndex] = ev->mMedia;
     1761                emit mediaEnumerated (media_list [ev->mIndex], ev->mIndex);
    16931762            }
    16941763            else
    16951764            {
    1696                 // the thread has posted the last message, wait for termination
     1765                /* the thread has posted the last message, wait for termination */
    16971766                media_enum_thread->wait();
    16981767                delete media_enum_thread;
    16991768                media_enum_thread = 0;
    17001769
    1701                 // this is the last event, clear the list (create a copy first)
    1702                 VBoxMediaList list = media_list;
    1703                 media_list.clear();
    1704 
    1705                 emit mediaEnumerated (list);
     1770                emit mediaEnumFinished (media_list);
    17061771            }
    17071772
     
    17091774        }
    17101775
    1711         // VirtualBox callback events
     1776        /* VirtualBox callback events */
    17121777
    17131778        case VBoxDefs::MachineStateChangeEventType:
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaComboBox.cpp

    r382 r548  
    2323#include "VBoxMediaComboBox.h"
    2424#include "VBoxDiskImageManagerDlg.h"
    25 #include "VBoxGlobal.h"
    2625
    2726#include <qfileinfo.h>
     
    3231#include <qlistbox.h>
    3332
    34 VBoxMediaComboBox::VBoxMediaComboBox (QWidget *aParent, const char *aName, int aType)
     33VBoxMediaComboBox::VBoxMediaComboBox (QWidget *aParent, const char *aName,
     34                                      int aType, bool aUseEmptyItem)
    3535    : QComboBox (aParent , aName),
    36     mType (aType), mRequiredId (QUuid()), mUseEmptyItem (false), mToBeRefreshed (false)
     36    mType (aType), mRequiredId (QUuid()), mUseEmptyItem (aUseEmptyItem)
    3737{
    3838    setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
    39     /* Media shortcuts creating */
    40     connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMedia &)),
    41              this, SLOT (mediaEnumerated (const VBoxMedia &)));
    42     connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMediaList &)),
    43              this, SLOT (listEnumerated (const VBoxMediaList &)));
     39    /* setup enumeration handlers */
     40    connect (&vboxGlobal(), SIGNAL (mediaEnumStarted()),
     41             this, SLOT (mediaEnumStarted()));
     42    connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMedia &, int)),
     43             this, SLOT (mediaEnumerated (const VBoxMedia &, int)));
     44    connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
     45             this, SLOT (mediaEnumFinished (const VBoxMediaList &)));
     46
     47    /* setup update handlers */
     48    connect (&vboxGlobal(), SIGNAL (mediaAdded (const VBoxMedia &)),
     49             this, SLOT (mediaAdded (const VBoxMedia &)));
     50    connect (&vboxGlobal(), SIGNAL (mediaUpdated (const VBoxMedia &)),
     51             this, SLOT (mediaUpdated (const VBoxMedia &)));
     52    connect (&vboxGlobal(), SIGNAL (mediaRemoved (VBoxDefs::DiskType, const QUuid &)),
     53             this, SLOT (mediaRemoved (VBoxDefs::DiskType, const QUuid &)));
     54
    4455    connect (this, SIGNAL (activated (int)),
    45              this, SLOT (updateToolTip (int)));
     56             this, SLOT (processActivated (int)));
    4657    connect (listBox(), SIGNAL (onItem (QListBoxItem*)),
    4758             this, SLOT (processOnItem (QListBoxItem*)));
    48 }
    49 
    50 void VBoxMediaComboBox::loadCleanContent()
    51 {
    52     CVirtualBox vbox = vboxGlobal().virtualBox();
    53 
    54     switch (mType)
    55     {
    56         /* load hd list */
     59
     60    /* cache pixmaps as class members */
     61    QImage img;
     62    img = QMessageBox::standardIcon (QMessageBox::Warning).convertToImage();
     63    if (!img.isNull())
     64    {
     65        img = img.smoothScale (14, 14);
     66        mPmInacc.convertFromImage (img);
     67    }
     68    img = QMessageBox::standardIcon (QMessageBox::Critical).convertToImage();
     69    if (!img.isNull())
     70    {
     71        img = img.smoothScale (14, 14);
     72        mPmError.convertFromImage (img);
     73    }
     74
     75    /* media shortcuts creating */
     76    refresh();
     77}
     78
     79void VBoxMediaComboBox::refresh()
     80{
     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    updateToolTip (currentItem());
     87    /* load current media list */
     88    VBoxMediaList list = vboxGlobal().currentMediaList();
     89    VBoxMediaList::const_iterator it;
     90    for (it = list.begin(); it != list.end(); ++ it)
     91        mediaEnumerated (*it, 0);
     92}
     93
     94
     95void VBoxMediaComboBox::mediaEnumStarted()
     96{
     97    refresh();
     98}
     99
     100void VBoxMediaComboBox::mediaEnumerated (const VBoxMedia &aMedia, int /*aIndex*/)
     101{
     102    processMedia (aMedia);
     103}
     104
     105void VBoxMediaComboBox::mediaEnumFinished (const VBoxMediaList &/*aList*/)
     106{
     107    emit activated (currentItem());
     108}
     109
     110
     111void VBoxMediaComboBox::mediaAdded (const VBoxMedia &aMedia)
     112{
     113    processMedia (aMedia);
     114}
     115
     116void VBoxMediaComboBox::mediaUpdated (const VBoxMedia &aMedia)
     117{
     118    processMedia (aMedia);
     119}
     120
     121void VBoxMediaComboBox::mediaRemoved (VBoxDefs::DiskType aType,
     122                                     const QUuid &aId)
     123{
     124    if (!(aType & mType))
     125        return;
     126
     127    /* search & remove media */
     128    int index = mUuidList.findIndex (aId);
     129    if (index != -1)
     130    {
     131        removeItem (index);
     132        mUuidList.remove (mUuidList.at (index));
     133        mTipList.remove (mTipList.at (index));
     134        updateToolTip (currentItem());
     135    }
     136}
     137
     138
     139void VBoxMediaComboBox::processMedia (const VBoxMedia &aMedia)
     140{
     141    if (!(aMedia.type & mType))
     142        return;
     143
     144    switch (aMedia.type)
     145    {
    57146        case VBoxDefs::HD:
    58         {
    59             CHardDiskEnumerator en = vbox.GetHardDisks().Enumerate();
    60             while (en.HasMore())
    61             {
    62                 QUuid mediaId;
    63                 QString toolTip;
    64                 CHardDisk hd = en.GetNext();
    65                 QString src = hd.GetLocation();
    66                 QUuid machineId = hd.GetMachineId();
    67                 /* append list only with free hd */
    68                 if (machineId.isNull() || machineId == mMachineId)
    69                 {
    70                     mediaId = hd.GetId();
    71                     toolTip = VBoxDiskImageManagerDlg::composeHdToolTip (hd, VBoxMedia::Unknown);
    72                 }
    73                 if (!mediaId.isNull()) updateMedia (src, mediaId, toolTip, VBoxMedia::Unknown);
    74             }
     147            processHdMedia (aMedia);
    75148            break;
    76         }
    77         /* load cd list */
    78149        case VBoxDefs::CD:
    79         {
    80             CDVDImageEnumerator en = vbox.GetDVDImages().Enumerate();
    81             while (en.HasMore())
    82             {
    83                 QUuid mediaId;
    84                 QString toolTip;
    85                 CDVDImage cd = en.GetNext();
    86                 QString src = cd.GetFilePath();
    87                 mediaId = cd.GetId();
    88                 toolTip = VBoxDiskImageManagerDlg::composeCdToolTip (cd, VBoxMedia::Unknown);
    89                 updateMedia (src, mediaId, toolTip, VBoxMedia::Unknown);
    90             }
     150            processCdMedia (aMedia);
    91151            break;
    92         }
    93         /* load fd list */
    94152        case VBoxDefs::FD:
    95         {
    96             CFloppyImageEnumerator en = vbox.GetFloppyImages().Enumerate();
    97             while (en.HasMore())
    98             {
    99                 QUuid mediaId;
    100                 QString toolTip;
    101                 CFloppyImage fd = en.GetNext();
    102                 QString src = fd.GetFilePath();
    103                 mediaId = fd.GetId();
    104                 toolTip = VBoxDiskImageManagerDlg::composeFdToolTip (fd, VBoxMedia::Unknown);
    105                 updateMedia (src, mediaId, toolTip, VBoxMedia::Unknown);
    106             }
     153            processFdMedia (aMedia);
    107154            break;
    108         }
    109155        default:
    110156            AssertFailed();
     
    112158}
    113159
    114 void VBoxMediaComboBox::mediaEnumerated (const VBoxMedia &aMedia)
    115 {
    116     if (!mToBeRefreshed) return;
    117     if (!(aMedia.type & mType))
    118         return;
    119 
    120     QString src;
    121     QUuid   mediaId;
     160void VBoxMediaComboBox::processHdMedia (const VBoxMedia &aMedia)
     161{
     162    QUuid mediaId;
    122163    QString toolTip;
    123 
    124     switch (aMedia.type)
    125     {
    126         case VBoxDefs::HD:
    127         {
    128             CHardDisk hd = aMedia.disk;
    129             src = hd.GetLocation();
    130             QUuid machineId = hd.GetMachineId();
    131             /* append list only with free hd */
    132             if (machineId.isNull() || machineId == mMachineId)
    133             {
    134                 mediaId = hd.GetId();
    135                 toolTip = VBoxDiskImageManagerDlg::composeHdToolTip (hd, aMedia.status);
    136             }
    137             break;
    138         }
    139         case VBoxDefs::CD:
    140         {
    141             CDVDImage dvd = aMedia.disk;
    142             src = dvd.GetFilePath();
    143             mediaId = dvd.GetId();
    144             toolTip = VBoxDiskImageManagerDlg::composeCdToolTip (dvd, aMedia.status);
    145             break;
    146         }
    147         case VBoxDefs::FD:
    148         {
    149             CFloppyImage floppy = aMedia.disk;
    150             src = floppy.GetFilePath();
    151             mediaId = floppy.GetId();
    152             toolTip = VBoxDiskImageManagerDlg::composeFdToolTip (floppy, aMedia.status);
    153             break;
    154         }
    155         default:
    156             AssertFailed();
    157     }
    158     int updatedMedia = -1;
     164    CHardDisk hd = aMedia.disk;
     165    QString src = hd.GetLocation();
     166    QUuid machineId = hd.GetMachineId();
     167    /* append list only with free hd */
     168    if (machineId.isNull() || machineId == mMachineId)
     169    {
     170        mediaId = hd.GetId();
     171        toolTip = VBoxDiskImageManagerDlg::composeHdToolTip (hd, aMedia.status);
     172    }
    159173    if (!mediaId.isNull())
    160         updatedMedia = updateMedia (src, mediaId, toolTip, aMedia.status);
    161     if (updatedMedia == -1) return;
    162 
    163     /* update warning/error icons */
    164     /// @todo (r=dmik) cache pixmaps as class members
    165     QPixmap pixmap;
    166     QImage img;
    167     if (aMedia.status == VBoxMedia::Inaccessible)
    168         img = QMessageBox::standardIcon (QMessageBox::Warning).convertToImage();
    169     else if (aMedia.status == VBoxMedia::Error)
    170         img = QMessageBox::standardIcon (QMessageBox::Critical).convertToImage();
    171     if (!img.isNull())
    172     {
    173         img = img.smoothScale (14, 14);
    174         pixmap.convertFromImage (img);
    175     }
    176     if (!pixmap.isNull())
    177         changeItem (pixmap, text (updatedMedia), updatedMedia);
    178 }
    179 
    180 int VBoxMediaComboBox::updateMedia (const QString &aSrc,
    181                                     const QUuid   &aId,
    182                                     const QString &aTip,
    183                                     VBoxMedia::Status /* aStatus */)
    184 {
    185     /* search & update media */
     174        updateShortcut (src, mediaId, toolTip, aMedia.status);
     175}
     176
     177void VBoxMediaComboBox::processCdMedia (const VBoxMedia &aMedia)
     178{
     179    CDVDImage dvd = aMedia.disk;
     180    QString src = dvd.GetFilePath();
     181    QUuid mediaId = dvd.GetId();
     182    QString toolTip = VBoxDiskImageManagerDlg::composeCdToolTip (dvd, aMedia.status);
     183    updateShortcut (src, mediaId, toolTip, aMedia.status);
     184}
     185
     186void VBoxMediaComboBox::processFdMedia (const VBoxMedia &aMedia)
     187{
     188    CFloppyImage floppy = aMedia.disk;
     189    QString src = floppy.GetFilePath();
     190    QUuid mediaId = floppy.GetId();
     191    QString toolTip = VBoxDiskImageManagerDlg::composeFdToolTip (floppy, aMedia.status);
     192    updateShortcut (src, mediaId, toolTip, aMedia.status);
     193}
     194
     195void VBoxMediaComboBox::updateShortcut (const QString &aSrc,
     196                                        const QUuid &aId,
     197                                        const QString &aTip,
     198                                        VBoxMedia::Status aStatus)
     199{
     200    /* compose item's name */
    186201    QFileInfo fi (aSrc);
    187     int index = mUuidList.findIndex (aId);
    188202    QString name = QString ("%1 (%2)").arg (fi.fileName())
    189203                   .arg (QDir::convertSeparators (fi.dirPath()));
    190     index == -1 ? appendItem (name, aId, aTip) : replaceItem (index, name, aTip);
     204    /* update warning/error icons */
     205    QPixmap *pixmap = 0;
     206    if (aStatus == VBoxMedia::Inaccessible)
     207        pixmap = &mPmInacc;
     208    else if (aStatus == VBoxMedia::Error)
     209        pixmap = &mPmError;
     210
     211    /* search media */
     212    int index = mUuidList.findIndex (aId);
     213    /* create or update media */
     214    if (index == -1)
     215        appendItem (name, aId, aTip, pixmap);
     216    else
     217        replaceItem (index, name, aTip, pixmap);
     218
    191219    if (aId == mRequiredId)
    192220    {
    193221        int activatedItem = index == -1 ? count() - 1 : index;
    194222        setCurrentItem (activatedItem);
    195         emit activated (activatedItem);
    196     }
    197     else
    198         updateToolTip (currentItem());
    199     return index == -1 ? count() - 1 : index;
    200 }
    201 
    202 void VBoxMediaComboBox::listEnumerated (const VBoxMediaList & /*aList*/)
    203 {
    204     emit activated (currentItem());
    205     mToBeRefreshed = false;
     223    }
     224}
     225
     226void VBoxMediaComboBox::processActivated (int aItem)
     227{
     228    mRequiredId = QUuid (mUuidList [aItem]);
     229    updateToolTip (aItem);
    206230}
    207231
     
    210234    /* combobox tooltip attaching */
    211235    QToolTip::remove (this);
    212     QToolTip::add (this, mTipList [aItem]);
     236    if (!mTipList.isEmpty())
     237        QToolTip::add (this, mTipList [aItem]);
    213238}
    214239
     
    221246}
    222247
    223 void VBoxMediaComboBox::setReadyForRefresh()
    224 {
    225     mToBeRefreshed = true;
    226     /* clearing media combobox */
    227     clear(), mUuidList.clear(), mTipList.clear();
    228     /* prepend empty item if used */
    229     if (mUseEmptyItem)
    230         appendItem (tr ("<no hard disk>"), QUuid(), tr ("No hard disk"));
    231     /* load all non-enumerated shortcuts */
    232     if (!vboxGlobal().isInEnumeratingProcess()) loadCleanContent();
    233     /* update already enumerated shortcuts */
    234     VBoxMediaList list = vboxGlobal().currentMediaList();
    235     for (VBoxMediaList::const_iterator it = list.begin(); it != list.end(); ++ it)
    236         mediaEnumerated (*it);
    237 }
    238 
    239 void VBoxMediaComboBox::refresh()
    240 {
    241     if (mToBeRefreshed) return;
    242     setReadyForRefresh();
    243     vboxGlobal().startEnumeratingMedia();
    244 }
    245 
    246248QUuid VBoxMediaComboBox::getId()
    247249{
     
    251253void VBoxMediaComboBox::appendItem (const QString &aName,
    252254                                    const QUuid   &aId,
    253                                     const QString &aTip)
    254 {
    255     insertItem (aName);
     255                                    const QString &aTip,
     256                                    QPixmap       *aPixmap)
     257{
     258    aPixmap ? insertItem (*aPixmap, aName) : insertItem (aName);
    256259    mUuidList << aId;
    257260    mTipList  << aTip;
    258261}
    259262
    260 void VBoxMediaComboBox::replaceItem (int aNumber,
     263void VBoxMediaComboBox::replaceItem (int            aNumber,
    261264                                     const QString &aName,
    262                                      const QString &aTip)
    263 {
    264     changeItem (aName, aNumber);
     265                                     const QString &aTip,
     266                                     QPixmap       *aPixmap)
     267{
     268    aPixmap ? changeItem (*aPixmap, aName, aNumber) : changeItem (aName, aNumber);
    265269    mTipList [aNumber] = aTip;
    266270}
    267271
    268 void VBoxMediaComboBox::removeLastItem()
    269 {
    270     if (count())
    271         removeItem (count() - 1);
    272     mUuidList.pop_back();
    273     mTipList.pop_back();
    274 }
    275 
    276 void VBoxMediaComboBox::setRequiredItem (const QUuid &aId)
     272void VBoxMediaComboBox::setUseEmptyItem (bool aUseEmptyItem)
     273{
     274    mUseEmptyItem = aUseEmptyItem;
     275}
     276
     277void VBoxMediaComboBox::setBelongsTo (const QUuid &aMachineId)
     278{
     279    mMachineId = aMachineId;
     280}
     281
     282QUuid VBoxMediaComboBox::getBelongsTo()
     283{
     284    return mMachineId;
     285}
     286
     287void VBoxMediaComboBox::setCurrentItem (int aIndex)
     288{
     289    QComboBox::setCurrentItem (aIndex);
     290    emit activated (aIndex);
     291}
     292
     293void VBoxMediaComboBox::setCurrentItem (const QUuid &aId)
    277294{
    278295    mRequiredId = aId;
    279 }
    280 
    281 void VBoxMediaComboBox::setUseEmptyItem (bool aUseEmptyItem)
    282 {
    283     mUseEmptyItem = aUseEmptyItem;
    284 }
    285 
    286 void VBoxMediaComboBox::setBelongsTo (const QUuid &aMachineId)
    287 {
    288     mMachineId = aMachineId;
    289 }
    290 
    291 QUuid VBoxMediaComboBox::getBelongsTo()
    292 {
    293     return mMachineId;
    294 }
    295 
    296 void VBoxMediaComboBox::setCurrentItem (int aIndex)
    297 {
    298     QComboBox::setCurrentItem (aIndex);
    299     updateToolTip (aIndex);
    300 }
     296    int index = mUuidList.findIndex (mRequiredId);
     297    if (index != -1)
     298        setCurrentItem (index);
     299}
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSelectorWnd.cpp

    r382 r548  
    415415
    416416    /* listen to "media enumeration finished" signals */
    417     connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMediaList &)),
    418              this, SLOT (mediaEnumerated (const VBoxMediaList &)));
     417    connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
     418             this, SLOT (mediaEnumFinished (const VBoxMediaList &)));
    419419
    420420    /* connect VirtualBox callback events */
     
    956956}
    957957
    958 void VBoxSelectorWnd::mediaEnumerated (const VBoxMediaList &list)
     958void VBoxSelectorWnd::mediaEnumFinished (const VBoxMediaList &list)
    959959{
    960960    /* refresh the current details to pick up hard disk sizes */
     
    992992     * emumeration started from main() at startup), and then disconnect
    993993     * to avoid annoying the user */
    994     disconnect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMediaList &)),
    995                 this, SLOT (mediaEnumerated (const VBoxMediaList &)));
     994    disconnect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
     995                this, SLOT (mediaEnumFinished (const VBoxMediaList &)));
    996996}
    997997
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui

    r382 r548  
    562562    <variable>QPushButton *defaultButton;</variable>
    563563    <variable access="private">static VBoxDiskImageManagerDlg *mModelessDialog;</variable>
    564     <variable access="private">bool mToBeRefreshed;</variable>
    565564    <variable access="private">QProgressBar *mProgressBar;</variable>
    566565    <variable access="private">QLabel *mProgressText;</variable>
     566    <variable access="private">QUuid hdSelectedId;</variable>
     567    <variable access="private">QUuid cdSelectedId;</variable>
     568    <variable access="private">QUuid fdSelectedId;</variable>
    567569</variables>
    568570<slots>
    569     <slot access="protected">mediaEnumerated( const VBoxMedia &amp; media )</slot>
    570     <slot access="protected">mediaEnumerated( const VBoxMediaList &amp; )</slot>
     571    <slot access="protected">mediaEnumStarted()</slot>
     572    <slot access="protected">mediaEnumerated( const VBoxMedia &amp;, int )</slot>
     573    <slot access="protected">mediaEnumFinished( const VBoxMediaList &amp; )</slot>
     574    <slot access="protected">mediaAdded( const VBoxMedia &amp; )</slot>
     575    <slot access="protected">mediaUpdated( const VBoxMedia &amp; )</slot>
     576    <slot access="protected">mediaRemoved( VBoxDefs::DiskType, const QUuid &amp; )</slot>
    571577    <slot access="protected">machineStateChanged( const VBoxMachineStateChangeEvent &amp; )</slot>
    572578    <slot>refreshAll()</slot>
     
    586592<functions>
    587593    <function access="private">init()</function>
    588     <function access="private">loadListViews()</function>
    589594    <function access="private" returnType="int">result()</function>
    590595    <function access="private">setResult( int )</function>
    591596    <function returnType="int">exec()</function>
    592597    <function access="private">done( int )</function>
    593     <function access="private">updateMedia( const VBoxMedia &amp; media )</function>
    594     <function access="private" returnType="DiskImageItem*">searchItem( QListView*, QUuid )</function>
     598    <function access="private" returnType="DiskImageItem*">searchItem( QListView*, const QUuid &amp; )</function>
    595599    <function specifier="non virtual" access="private" returnType="QString">static getDVDImageUsage( const QUuid &amp; id )</function>
    596600    <function specifier="non virtual" access="private" returnType="QString">static getFloppyImageUsage( const QUuid &amp; id )</function>
     
    601605    <function>setup( int aType, bool aDoSelect, const QUuid *aTargetVMId = NULL, const VBoxMediaList *mediaList = NULL, CMachine machine = 0 )</function>
    602606    <function access="private" returnType="QListView*">getCurrentListView()</function>
     607    <function access="private" returnType="QListView*">getListView( VBoxDefs::DiskType )</function>
    603608    <function returnType="bool">eventFilter( QObject *, QEvent * )</function>
    604609    <function access="private">addDroppedImages( QStringList* )</function>
    605     <function access="private" returnType="DiskImageItem*">addImageToList( QString aSource, VBoxDefs::DiskType aDiskType )</function>
    606     <function access="private" returnType="DiskImageItem*">createImageNode( QListView *aList, DiskImageItem *aRoot, QString aName, QString aLabel1 = QString::null, QString aLabel2 = QString::null, QString aLabel3 = QString::null, QString aLabel4 = QString::null, QString aLabel5 = QString::null, QString aLabel6 = QString::null, QString aLabel7 = QString::null )</function>
    607     <function access="private" returnType="DiskImageItem*">createHdItem( QListView*, DiskImageItem*, CHardDisk &amp;, VBoxMedia::Status )</function>
    608     <function access="private" returnType="DiskImageItem*">createCdItem( QListView*, DiskImageItem*, CDVDImage &amp;, VBoxMedia::Status )</function>
    609     <function access="private" returnType="DiskImageItem*">createFdItem( QListView*, DiskImageItem*, CFloppyImage &amp;, VBoxMedia::Status )</function>
    610     <function access="private">createHdChildren( DiskImageItem*, CHardDisk &amp;, VBoxMedia::Status )</function>
     610    <function access="private">addImageToList( QString aSource, VBoxDefs::DiskType aDiskType )</function>
     611    <function access="private" returnType="DiskImageItem*">createImageNode( QListView *aList, DiskImageItem *aRoot )</function>
     612    <function access="private">updateHdItem( DiskImageItem*, const VBoxMedia &amp; )</function>
     613    <function access="private">updateCdItem( DiskImageItem*, const VBoxMedia &amp; )</function>
     614    <function access="private">updateFdItem( DiskImageItem*, const VBoxMedia &amp; )</function>
     615    <function access="private" returnType="DiskImageItem*">createHdItem( QListView*, DiskImageItem*, const VBoxMedia &amp; )</function>
     616    <function access="private" returnType="DiskImageItem*">createCdItem( QListView*, DiskImageItem*, const VBoxMedia &amp; )</function>
     617    <function access="private" returnType="DiskImageItem*">createFdItem( QListView*, DiskImageItem*, const VBoxMedia &amp; )</function>
     618    <function access="private">createHdChildren( DiskImageItem*, const VBoxMedia &amp; )</function>
    611619    <function access="protected">showEvent( QShowEvent * )</function>
    612620    <function access="protected">resizeEvent( QResizeEvent* )</function>
     
    620628    <function specifier="non virtual" returnType="QString">static composeCdToolTip( CDVDImage &amp;, VBoxMedia::Status = VBoxMedia::Ok )</function>
    621629    <function specifier="non virtual" returnType="QString">static composeFdToolTip( CFloppyImage &amp;, VBoxMedia::Status = VBoxMedia::Ok )</function>
    622     <function access="protected">prepareToRefresh()</function>
     630    <function access="protected">prepareToRefresh( int aTotal = 0 )</function>
    623631</functions>
    624632<layoutdefaults spacing="10" margin="10"/>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui.h

    r382 r548  
    3535public:
    3636
    37     DiskImageItem (DiskImageItem *parent, QString aLabel1,
    38                    QString aLabel2 = QString::null,
    39                    QString aLabel3 = QString::null,
    40                    QString aLabel4 = QString::null,
    41                    QString aLabel5 = QString::null,
    42                    QString aLabel6 = QString::null,
    43                    QString aLabel7 = QString::null,
    44                    QString aLabel8 = QString::null) :
    45         QListViewItem (parent, aLabel1, aLabel2, aLabel3, aLabel4, aLabel5,
    46                        aLabel6, aLabel7, aLabel8),
    47         mName (aLabel1), mStatus (VBoxMedia::Unknown) {}
    48 
    49     DiskImageItem (QListView *parent, QString aLabel1,
    50                    QString aLabel2 = QString::null,
    51                    QString aLabel3 = QString::null,
    52                    QString aLabel4 = QString::null,
    53                    QString aLabel5 = QString::null,
    54                    QString aLabel6 = QString::null,
    55                    QString aLabel7 = QString::null,
    56                    QString aLabel8 = QString::null) :
    57         QListViewItem (parent, aLabel1, aLabel2, aLabel3, aLabel4, aLabel5,
    58                        aLabel6, aLabel7, aLabel8),
    59         mName (aLabel1), mStatus (VBoxMedia::Unknown) {}
     37    DiskImageItem (DiskImageItem *parent) :
     38        QListViewItem (parent), mStatus (VBoxMedia::Unknown) {}
     39
     40    DiskImageItem (QListView *parent) :
     41        QListViewItem (parent), mStatus (VBoxMedia::Unknown) {}
    6042
    6143    QString getName() { return mName; }
     
    179161        /// @todo refreshAll() may be slow, so it may be better to analyze
    180162        //  event details and update only what is changed */
    181         //connect (&vboxGlobal(), SIGNAL (machineDataChanged (const VBoxMachineDataChangeEvent &)),
    182         //         mModelessDialog, SLOT (refreshAll()));
     163        connect (&vboxGlobal(), SIGNAL (machineDataChanged (const VBoxMachineDataChangeEvent &)),
     164                 mModelessDialog, SLOT (refreshAll()));
    183165        connect (&vboxGlobal(), SIGNAL (machineRegistered (const VBoxMachineRegisteredEvent &)),
    184166                 mModelessDialog, SLOT (refreshAll()));
    185167        connect (&vboxGlobal(), SIGNAL (snapshotChanged (const VBoxSnapshotEvent &)),
    186168                 mModelessDialog, SLOT (refreshAll()));
    187 
    188         /* listen also to the machine state change because hard disks of running
    189          * VMs are inaccessible by the current design */
    190         connect (&vboxGlobal(), SIGNAL (machineStateChanged (const VBoxMachineStateChangeEvent &)),
    191                  mModelessDialog, SLOT (machineStateChanged (const VBoxMachineStateChangeEvent &)));
    192169    }
    193170
     
    203180    polished = false;
    204181
    205     mToBeRefreshed = false;
    206182    mInLoop = false;
    207183
     
    415391    mProgressBar->setMaximumWidth (100);
    416392    buttonLayout->insertWidget (3, mProgressBar);
    417 
    418     if (!vboxGlobal().isInEnumeratingProcess()) loadListViews();
    419 }
    420 
    421 
    422 void VBoxDiskImageManagerDlg::loadListViews()
    423 {
    424     /* load hd list */
    425     CHardDiskEnumerator hdEnum = vbox.GetHardDisks().Enumerate();
    426     while (hdEnum.HasMore())
    427     {
    428         CHardDisk hd = hdEnum.GetNext();
    429         DiskImageItem *item = createHdItem (hdsView, 0, hd, VBoxMedia::Unknown);
    430         createHdChildren (item, hd, VBoxMedia::Unknown);
    431     }
    432 
    433     /* load cd list */
    434     CDVDImageEnumerator cdEnum = vbox.GetDVDImages().Enumerate();
    435     while (cdEnum.HasMore())
    436     {
    437         CDVDImage cd = cdEnum.GetNext();
    438         DiskImageItem *item = createCdItem (cdsView, 0, cd, VBoxMedia::Unknown);
    439         NOREF(item);
    440     }
    441 
    442     /* load fd list */
    443     CFloppyImageEnumerator fdEnum = vbox.GetFloppyImages().Enumerate();
    444     while (fdEnum.HasMore())
    445     {
    446         CFloppyImage fd = fdEnum.GetNext();
    447         DiskImageItem *item = createFdItem (fdsView, 0, fd, VBoxMedia::Unknown);
    448         NOREF(item);
    449     }
    450393}
    451394
     
    621564}
    622565
     566QListView* VBoxDiskImageManagerDlg::getListView (VBoxDefs::DiskType aType)
     567{
     568    switch (aType)
     569    {
     570        case VBoxDefs::HD:
     571            return hdsView;
     572        case VBoxDefs::CD:
     573            return cdsView;
     574        case VBoxDefs::FD:
     575            return fdsView;
     576        default:
     577            return 0;
     578    }
     579}
     580
    623581
    624582bool VBoxDiskImageManagerDlg::eventFilter (QObject *aObject, QEvent *aEvent)
     
    697655    QListView *currentList = getCurrentListView();
    698656
    699     DiskImageItem *item = 0;
    700657    for (QStringList::Iterator it = (*aDroppedList).begin();
    701658         it != (*aDroppedList).end(); ++it)
     
    716673        }
    717674        // If media type has been determined - attach this device
    718         if (type) item = addImageToList (*it, type);
     675        if (type) addImageToList (*it, type);
    719676    }
    720677    delete aDroppedList;
    721     setCurrentItem (currentList, item);
    722 }
    723 
    724 
    725 DiskImageItem* VBoxDiskImageManagerDlg::addImageToList (QString aSource, VBoxDefs::DiskType aDiskType)
     678}
     679
     680
     681void VBoxDiskImageManagerDlg::addImageToList (QString aSource,
     682                                              VBoxDefs::DiskType aDiskType)
    726683{
    727684    if (aSource.isEmpty())
    728         return 0;
    729 
    730     DiskImageItem *item = 0;
     685        return;
     686
    731687    QUuid uuid;
     688    VBoxMedia media;
    732689    switch (aDiskType)
    733690    {
     
    737694            if (vbox.isOk())
    738695            {
    739                 CHardDisk hardDisk = CUnknown (vdi);
    740                 vbox.RegisterHardDisk (hardDisk);
     696                CHardDisk hd = CUnknown (vdi);
     697                vbox.RegisterHardDisk (hd);
    741698                if (vbox.isOk())
    742699                {
    743                     VBoxMedia::Status status = hardDisk.GetAccessible() ?
    744                         VBoxMedia::Ok : VBoxMedia::Inaccessible;
    745                     item = createHdItem (hdsView, 0, hardDisk, status);
    746                     /* synchronize modeless dialog if present */
    747                     if (mModelessDialog && mModelessDialog != this)
    748                         mModelessDialog->createHdItem (mModelessDialog->hdsView,
    749                                                        0, hardDisk, status);
     700                    VBoxMedia::Status status =
     701                        hd.GetAccessible() ? VBoxMedia::Ok :
     702                        hd.isOk() ? VBoxMedia::Inaccessible :
     703                        VBoxMedia::Error;
     704                    media = VBoxMedia (CUnknown (hd), VBoxDefs::HD, status);
    750705                }
    751706            }
     
    754709        case VBoxDefs::CD:
    755710        {
    756             CDVDImage dvdImage = vbox.OpenDVDImage (aSource, uuid);
     711            CDVDImage cd = vbox.OpenDVDImage (aSource, uuid);
    757712            if (vbox.isOk())
    758713            {
    759                 vbox.RegisterDVDImage (dvdImage);
     714                vbox.RegisterDVDImage (cd);
    760715                if (vbox.isOk())
    761716                {
    762                     VBoxMedia::Status status = dvdImage.GetAccessible() ?
    763                         VBoxMedia::Ok : VBoxMedia::Inaccessible;
    764                     item = createCdItem (cdsView, 0, dvdImage, status);
    765                     /* synchronize modeless dialog if present */
    766                     if (mModelessDialog && mModelessDialog != this)
    767                         mModelessDialog->createCdItem (mModelessDialog->cdsView,
    768                                                        0, dvdImage, status);
     717                    VBoxMedia::Status status =
     718                        cd.GetAccessible() ? VBoxMedia::Ok :
     719                        cd.isOk() ? VBoxMedia::Inaccessible :
     720                        VBoxMedia::Error;
     721                    media = VBoxMedia (CUnknown (cd), VBoxDefs::CD, status);
    769722                }
    770723            }
     
    773726        case VBoxDefs::FD:
    774727        {
    775             CFloppyImage floppyImage = vbox.OpenFloppyImage (aSource, uuid);
     728            CFloppyImage fd = vbox.OpenFloppyImage (aSource, uuid);
    776729            if (vbox.isOk())
    777730            {
    778                 vbox.RegisterFloppyImage (floppyImage);
     731                vbox.RegisterFloppyImage (fd);
    779732                if (vbox.isOk())
    780733                {
    781                     VBoxMedia::Status status = floppyImage.GetAccessible() ?
    782                         VBoxMedia::Ok : VBoxMedia::Inaccessible;
    783                     item = createFdItem (fdsView, 0, floppyImage, status);
    784                     /* synchronize modeless dialog if present */
    785                     if (mModelessDialog && mModelessDialog != this)
    786                         mModelessDialog->createFdItem (mModelessDialog->fdsView,
    787                                                        0, floppyImage, status);
     734                    VBoxMedia::Status status =
     735                        fd.GetAccessible() ? VBoxMedia::Ok :
     736                        fd.isOk() ? VBoxMedia::Inaccessible :
     737                        VBoxMedia::Error;
     738                    media = VBoxMedia (CUnknown (fd), VBoxDefs::FD, status);
    788739                }
    789740            }
     
    791742        }
    792743        default:
    793         {
    794             Assert(0);
    795         }
    796     }
    797     return item;
     744            AssertMsgFailed (("Invalid aDiskType type\n"));
     745    }
     746    if (media.type != VBoxDefs::InvalidType)
     747        vboxGlobal().addMedia (media);
    798748}
    799749
    800750
    801751DiskImageItem* VBoxDiskImageManagerDlg::createImageNode (QListView *aList,
    802                                                          DiskImageItem *aRoot,
    803                                                          QString aName,
    804                                                          QString aLabel2,
    805                                                          QString aLabel3,
    806                                                          QString aLabel4,
    807                                                          QString aLabel5,
    808                                                          QString aLabel6,
    809                                                          QString aLabel7,
    810                                                          QString aLabel8)
     752                                                         DiskImageItem *aRoot)
    811753{
    812754    DiskImageItem *item = 0;
    813755
    814756    if (aList)
    815         item = new DiskImageItem (aList, aName,
    816             aLabel2, aLabel3, aLabel4, aLabel5, aLabel6, aLabel7, aLabel8);
     757        item = new DiskImageItem (aList);
    817758    else if (aRoot)
    818         item = new DiskImageItem (aRoot, aName,
    819             aLabel2, aLabel3, aLabel4, aLabel5, aLabel6, aLabel7, aLabel8);
     759        item = new DiskImageItem (aRoot);
    820760    else
    821         Assert(0);
     761        Assert (0);
    822762
    823763    return item;
     
    11011041
    11021042
    1103 DiskImageItem* VBoxDiskImageManagerDlg::createHdItem (QListView *aList,
    1104                                                       DiskImageItem *aRoot,
    1105                                                       CHardDisk &aHd,
    1106                                                       VBoxMedia::Status aStatus)
    1107 {
    1108     DiskImageItem *item = 0;
    1109 
    1110     QUuid uuid = aHd.GetId();
    1111     QString src = aHd.GetLocation();
    1112     QUuid machineId = aHd.GetMachineId();
    1113 
     1043void VBoxDiskImageManagerDlg::updateHdItem (DiskImageItem   *aItem,
     1044                                            const VBoxMedia &aMedia)
     1045{
     1046    CHardDisk hd = aMedia.disk;
     1047    VBoxMedia::Status status = aMedia.status;
     1048
     1049    QUuid uuid = hd.GetId();
     1050    QString src = hd.GetLocation();
     1051    QUuid machineId = hd.GetMachineId();
    11141052    QString usage;
    11151053    if (!machineId.isNull())
    11161054        usage = vbox.GetMachine (machineId).GetName();
    1117     QString storageType = vboxGlobal().toString (aHd.GetStorageType());
    1118     QString hardDiskType = vboxGlobal().hardDiskTypeString (aHd);
    1119     QString virtualSize = aStatus == VBoxMedia::Ok ?
    1120         vboxGlobal().formatSize ((ULONG64)aHd.GetSize() * _1M) : QString ("--");
    1121     QString actualSize = aStatus == VBoxMedia::Ok ?
    1122         vboxGlobal().formatSize (aHd.GetActualSize()) : QString ("--");
     1055    QString storageType = vboxGlobal().toString (hd.GetStorageType());
     1056    QString hardDiskType = vboxGlobal().hardDiskTypeString (hd);
     1057    QString virtualSize = status == VBoxMedia::Ok ?
     1058        vboxGlobal().formatSize ((ULONG64)hd.GetSize() * _1M) : QString ("--");
     1059    QString actualSize = status == VBoxMedia::Ok ?
     1060        vboxGlobal().formatSize (hd.GetActualSize()) : QString ("--");
    11231061    QString snapshotName;
    1124     if (!machineId.isNull() && !aHd.GetSnapshotId().isNull())
     1062    if (!machineId.isNull() && !hd.GetSnapshotId().isNull())
    11251063    {
    11261064        CSnapshot snapshot = vbox.GetMachine (machineId).
    1127                                   GetSnapshot (aHd.GetSnapshotId());
     1065                                  GetSnapshot (hd.GetSnapshotId());
    11281066        if (!snapshot.isNull())
    11291067            snapshotName = QString ("%1").arg (snapshot.GetName());
     
    11311069    QFileInfo fi (src);
    11321070
    1133     item = createImageNode (aList, aRoot,
    1134                             fi.fileName(),
    1135                             virtualSize,
    1136                             actualSize);
    1137     item->setPath (aHd.GetStorageType() == CEnums::ISCSIHardDisk ? src :
     1071    aItem->setText (0, fi.fileName());
     1072    aItem->setText (1, virtualSize);
     1073    aItem->setText (2, actualSize);
     1074    aItem->setPath (hd.GetStorageType() == CEnums::ISCSIHardDisk ? src :
    11381075                   QDir::convertSeparators (fi.absFilePath()));
    1139     item->setUsage (usage);
    1140     item->setSnapshotName (snapshotName);
    1141     item->setDiskType (hardDiskType);
    1142     item->setStorageType (storageType);
    1143     item->setVirtualSize (virtualSize);
    1144     item->setActualSize (actualSize);
    1145     item->setUuid (uuid);
    1146     item->setMachineId (machineId);
    1147     item->setToolTip (composeHdToolTip (aHd, aStatus));
    1148     item->setStatus (aStatus);
    1149 
     1076    aItem->setUsage (usage);
     1077    aItem->setSnapshotName (snapshotName);
     1078    aItem->setDiskType (hardDiskType);
     1079    aItem->setStorageType (storageType);
     1080    aItem->setVirtualSize (virtualSize);
     1081    aItem->setActualSize (actualSize);
     1082    aItem->setUuid (uuid);
     1083    aItem->setMachineId (machineId);
     1084    aItem->setToolTip (composeHdToolTip (hd, status));
     1085    aItem->setStatus (status);
     1086
     1087    if (aMedia.status == VBoxMedia::Inaccessible)
     1088        aItem->setPixmap (0, pxInaccessible);
     1089    else if (aMedia.status == VBoxMedia::Error)
     1090        aItem->setPixmap (0, pxErroneous);
     1091}
     1092
     1093void VBoxDiskImageManagerDlg::updateCdItem (DiskImageItem   *aItem,
     1094                                            const VBoxMedia &aMedia)
     1095{
     1096    CDVDImage cd = aMedia.disk;
     1097    VBoxMedia::Status status = aMedia.status;
     1098
     1099    QUuid uuid = cd.GetId();
     1100    QString src = cd.GetFilePath();
     1101    QString usage = getDVDImageUsage (uuid);
     1102    QString size = status == VBoxMedia::Ok ?
     1103        vboxGlobal().formatSize (cd.GetSize()) : QString ("--");
     1104    QFileInfo fi (src);
     1105
     1106    aItem->setText (0, fi.fileName());
     1107    aItem->setText (1, size);
     1108    aItem->setPath (QDir::convertSeparators (fi.absFilePath ()));
     1109    aItem->setUsage (usage);
     1110    aItem->setActualSize (size);
     1111    aItem->setUuid (uuid);
     1112    aItem->setToolTip (composeCdToolTip (cd, status));
     1113    aItem->setStatus (status);
     1114
     1115    if (aMedia.status == VBoxMedia::Inaccessible)
     1116        aItem->setPixmap (0, pxInaccessible);
     1117    else if (aMedia.status == VBoxMedia::Error)
     1118        aItem->setPixmap (0, pxErroneous);
     1119}
     1120
     1121void VBoxDiskImageManagerDlg::updateFdItem (DiskImageItem   *aItem,
     1122                                            const VBoxMedia &aMedia)
     1123{
     1124    CFloppyImage fd = aMedia.disk;
     1125    VBoxMedia::Status status = aMedia.status;
     1126
     1127    QUuid uuid = fd.GetId();
     1128    QString src = fd.GetFilePath();
     1129    QString usage = getFloppyImageUsage (uuid);
     1130    QString size = status == VBoxMedia::Ok ?
     1131        vboxGlobal().formatSize (fd.GetSize()) : QString ("--");
     1132    QFileInfo fi (src);
     1133
     1134    aItem->setText (0, fi.fileName());
     1135    aItem->setText (1, size);
     1136    aItem->setPath (QDir::convertSeparators (fi.absFilePath ()));
     1137    aItem->setUsage (usage);
     1138    aItem->setActualSize (size);
     1139    aItem->setUuid (uuid);
     1140    aItem->setToolTip (composeFdToolTip (fd, status));
     1141    aItem->setStatus (status);
     1142
     1143    if (aMedia.status == VBoxMedia::Inaccessible)
     1144        aItem->setPixmap (0, pxInaccessible);
     1145    else if (aMedia.status == VBoxMedia::Error)
     1146        aItem->setPixmap (0, pxErroneous);
     1147}
     1148
     1149
     1150DiskImageItem* VBoxDiskImageManagerDlg::createHdItem (QListView       *aList,
     1151                                                      DiskImageItem   *aRoot,
     1152                                                      const VBoxMedia &aMedia)
     1153{
     1154    DiskImageItem *item = createImageNode (aList, aRoot);
     1155    updateHdItem (item, aMedia);
     1156    createHdChildren (item, aMedia);
    11501157    return item;
    11511158}
    11521159
    1153 
    1154 DiskImageItem* VBoxDiskImageManagerDlg::createCdItem (QListView *aList,
    1155                                                       DiskImageItem *aRoot,
    1156                                                       CDVDImage &aCd,
    1157                                                       VBoxMedia::Status aStatus)
    1158 {
    1159     DiskImageItem *item = 0;
    1160 
    1161     QUuid uuid = aCd.GetId();
    1162     QString src = aCd.GetFilePath();
    1163     QString usage = getDVDImageUsage (uuid);
    1164 
    1165     QString size = aStatus == VBoxMedia::Ok ?
    1166         vboxGlobal().formatSize (aCd.GetSize()) : QString ("--");
    1167     QFileInfo fi (src);
    1168 
    1169     item = createImageNode (aList, aRoot,
    1170                             fi.fileName(),
    1171                             size);
    1172     item->setPath (QDir::convertSeparators (fi.absFilePath ()));
    1173     item->setUsage (usage);
    1174     item->setActualSize (size);
    1175     item->setUuid (uuid);
    1176     item->setToolTip (composeCdToolTip (aCd, aStatus));
    1177     item->setStatus (aStatus);
    1178 
     1160DiskImageItem* VBoxDiskImageManagerDlg::createCdItem (QListView       *aList,
     1161                                                      DiskImageItem   *aRoot,
     1162                                                      const VBoxMedia &aMedia)
     1163{
     1164    DiskImageItem *item = createImageNode (aList, aRoot);
     1165    updateCdItem (item, aMedia);
    11791166    return item;
    11801167}
    11811168
    1182 
    1183 DiskImageItem* VBoxDiskImageManagerDlg::createFdItem (QListView *aList,
    1184                                                       DiskImageItem *aRoot,
    1185                                                       CFloppyImage &aFd,
    1186                                                       VBoxMedia::Status aStatus)
    1187 {
    1188     DiskImageItem *item = 0;
    1189 
    1190     QUuid uuid = aFd.GetId();
    1191     QString src = aFd.GetFilePath();
    1192     QString usage = getFloppyImageUsage (uuid);
    1193 
    1194     QString size = aStatus == VBoxMedia::Ok ?
    1195         vboxGlobal().formatSize (aFd.GetSize()) : QString ("--");
    1196     QFileInfo fi (src);
    1197 
    1198     item = createImageNode (aList, aRoot,
    1199                             fi.fileName(),
    1200                             size);
    1201     item->setPath (QDir::convertSeparators (fi.absFilePath ()));
    1202     item->setUsage (usage);
    1203     item->setActualSize (size);
    1204     item->setUuid (uuid);
    1205     item->setToolTip (composeFdToolTip (aFd, aStatus));
    1206     item->setStatus (aStatus);
    1207 
     1169DiskImageItem* VBoxDiskImageManagerDlg::createFdItem (QListView       *aList,
     1170                                                      DiskImageItem   *aRoot,
     1171                                                      const VBoxMedia &aMedia)
     1172{
     1173    DiskImageItem *item = createImageNode (aList, aRoot);
     1174    updateFdItem (item, aMedia);
    12081175    return item;
    12091176}
    12101177
    1211 
    1212 void VBoxDiskImageManagerDlg::createHdChildren (DiskImageItem *aRoot,
    1213                                                 CHardDisk &aHd,
    1214                                                 VBoxMedia::Status aStatus)
    1215 {
    1216     CHardDiskEnumerator enumerator = aHd.GetChildren().Enumerate();
     1178void VBoxDiskImageManagerDlg::createHdChildren (DiskImageItem   *aRoot,
     1179                                                const VBoxMedia &aMedia)
     1180{
     1181    CHardDisk hd = aMedia.disk;
     1182    CHardDiskEnumerator enumerator = hd.GetChildren().Enumerate();
    12171183    while (enumerator.HasMore())
    12181184    {
    12191185        CHardDisk subHd = enumerator.GetNext();
    1220         DiskImageItem *subItem = createHdItem (0, aRoot, subHd, aStatus);
    1221         createHdChildren (subItem, subHd, aStatus);
    1222     }
    1223 }
    1224 
    1225 
    1226 DiskImageItem* VBoxDiskImageManagerDlg::searchItem (QListView *aList, QUuid aId)
     1186        VBoxMedia::Status status =
     1187            subHd.GetAccessible() == TRUE ? VBoxMedia::Ok :
     1188            subHd.isOk() ? VBoxMedia::Inaccessible :
     1189            VBoxMedia::Error;
     1190        const VBoxMedia media (CUnknown (subHd), VBoxDefs::HD, status);
     1191        createHdItem (0, aRoot, media);
     1192    }
     1193}
     1194
     1195
     1196DiskImageItem* VBoxDiskImageManagerDlg::searchItem (QListView *aList,
     1197                                                    const QUuid &aId)
    12271198{
    12281199    DiskImageItem *item = 0, *iterator = 0;
     
    12391210
    12401211
    1241 void VBoxDiskImageManagerDlg::updateMedia (const VBoxMedia &aMedia)
    1242 {
    1243     /* ignore non-updated aMedia */
    1244     if (!(type & aMedia.type))
    1245         return;
    1246 
    1247     /* search for updated listview item */
    1248     DiskImageItem *item = 0;
    1249     switch (aMedia.type)
    1250     {
    1251         case VBoxDefs::HD:
    1252         {
    1253             CHardDisk hd = aMedia.disk;
    1254             item = searchItem (hdsView, hd.GetId());
    1255             delete item;
    1256             item = createHdItem (hdsView, 0, hd, aMedia.status);
    1257             createHdChildren (item, hd, aMedia.status);
    1258             break;
    1259         }
    1260         case VBoxDefs::CD:
    1261         {
    1262             CDVDImage cd = aMedia.disk;
    1263             item = searchItem (cdsView, cd.GetId());
    1264             delete item;
    1265             item = createCdItem (cdsView, 0, cd, aMedia.status);
    1266             break;
    1267         }
    1268         case VBoxDefs::FD:
    1269         {
    1270             CFloppyImage fd = aMedia.disk;
    1271             item = searchItem (fdsView, fd.GetId());
    1272             delete item;
    1273             item = createFdItem (fdsView, 0, fd, aMedia.status);
    1274             break;
    1275         }
    1276         default:
    1277         {
    1278             AssertMsgFailed (("Invalid aMedia type\n"));
    1279             break;
    1280         }
    1281     }
    1282 
    1283     if (aMedia.status == VBoxMedia::Inaccessible)
    1284         item->setPixmap (0, pxInaccessible);
    1285     else if (aMedia.status == VBoxMedia::Error)
    1286         item->setPixmap (0, pxErroneous);
    1287 
    1288     mProgressBar->setProgress (mProgressBar->progress() + 1);
    1289 }
    1290 
    1291 
    12921212void VBoxDiskImageManagerDlg::setup (int aType, bool aDoSelect,
    12931213                                     const QUuid *aTargetVMId,
     
    13111231        buttonCancel->setShown (false);
    13121232
     1233    /* listen to "media enumeration started" signals */
     1234    connect (&vboxGlobal(), SIGNAL (mediaEnumStarted()),
     1235             this, SLOT (mediaEnumStarted()));
    13131236    /* listen to "media enumeration" signals */
    1314     connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMedia &)),
    1315              this, SLOT (mediaEnumerated (const VBoxMedia &)));
     1237    connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMedia &, int)),
     1238             this, SLOT (mediaEnumerated (const VBoxMedia &, int)));
    13161239    /* listen to "media enumeration finished" signals */
    1317     connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMediaList &)),
    1318              this, SLOT (mediaEnumerated (const VBoxMediaList &)));
     1240    connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
     1241             this, SLOT (mediaEnumFinished (const VBoxMediaList &)));
     1242
     1243    /* listen to "media add" signals */
     1244    connect (&vboxGlobal(), SIGNAL (mediaAdded (const VBoxMedia &)),
     1245             this, SLOT (mediaAdded (const VBoxMedia &)));
     1246    /* listen to "media update" signals */
     1247    connect (&vboxGlobal(), SIGNAL (mediaUpdated (const VBoxMedia &)),
     1248             this, SLOT (mediaUpdated (const VBoxMedia &)));
     1249    /* listen to "media remove" signals */
     1250    connect (&vboxGlobal(), SIGNAL (mediaRemoved (VBoxDefs::DiskType, const QUuid &)),
     1251             this, SLOT (mediaRemoved (VBoxDefs::DiskType, const QUuid &)));
    13191252
    13201253    /* insert already enumerated media */
    1321     VBoxMediaList list;
     1254    VBoxMediaList list = mediaList ?
     1255        *mediaList : vboxGlobal().currentMediaList();
     1256    prepareToRefresh (list.size());
     1257    VBoxMediaList::const_iterator it;
     1258    int index = 0;
     1259    for (it = list.begin(); it != list.end(); ++ it)
     1260    {
     1261        mediaAdded (*it);
     1262        if ((*it).status != VBoxMedia::Unknown)
     1263            mProgressBar->setProgress (index ++);
     1264    }
     1265    /* select first child */
     1266    setCurrentItem (hdsView, hdsView->firstChild());
     1267    setCurrentItem (cdsView, cdsView->firstChild());
     1268    setCurrentItem (fdsView, fdsView->firstChild());
     1269
    13221270    if (mediaList)
    1323         list = *mediaList;
     1271    {
     1272        mediaEnumFinished (list);
     1273    }
    13241274    else
    1325         list = vboxGlobal().currentMediaList();
    1326 
    1327     VBoxMediaList::const_iterator it;
    1328     prepareToRefresh();
    1329     for (it = list.begin(); it != list.end(); ++ it)
    1330         updateMedia (*it);
    1331 
    1332     if (mediaList)
    1333     {
    1334         mediaEnumerated (*mediaList);
    1335     }
    1336     else
    1337     {
    1338         /* only start enumerating media if we haven't been supplied with a list
     1275    {
     1276        /* only start enumerating media if we haven't been supplied a list
    13391277         * (it's ok if the enumeration has been already started, nothing will
    13401278         * happen) */
     
    13441282
    13451283
    1346 void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMedia &aMedia)
    1347 {
    1348     if (!mToBeRefreshed) return;
    1349     updateMedia (aMedia);
     1284void VBoxDiskImageManagerDlg::mediaEnumStarted()
     1285{
     1286    VBoxMediaList list = vboxGlobal().currentMediaList();
     1287    prepareToRefresh (list.size());
     1288    /* clearing lists */
     1289    hdsView->clear(), cdsView->clear(), fdsView->clear();
     1290    /* load current media list */
     1291    VBoxMediaList::const_iterator it;
     1292    for (it = list.begin(); it != list.end(); ++ it)
     1293        mediaAdded (*it);
     1294    /* select first child */
     1295    if (!hdsView->isSelected (hdsView->currentItem()))
     1296        setCurrentItem (hdsView, hdsView->firstChild());
     1297    if (!cdsView->isSelected (cdsView->currentItem()))
     1298        setCurrentItem (cdsView, cdsView->firstChild());
     1299    if (!fdsView->isSelected (fdsView->currentItem()))
     1300        setCurrentItem (fdsView, fdsView->firstChild());
     1301
    13501302    processCurrentChanged();
    13511303}
    13521304
    1353 
    1354 void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMediaList & /*aList*/)
    1355 {
    1356     if (!mToBeRefreshed) return;
    1357 
     1305void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMedia &aMedia,
     1306                                               int aIndex)
     1307{
     1308    mediaUpdated (aMedia);
     1309    if (aMedia.status != VBoxMedia::Unknown)
     1310        mProgressBar->setProgress (aIndex);
     1311}
     1312
     1313void VBoxDiskImageManagerDlg::mediaEnumFinished (const VBoxMediaList &/* aList */)
     1314{
    13581315    mProgressBar->setHidden (true);
    13591316    mProgressText->setHidden (true);
     
    13621319    unsetCursor();
    13631320
    1364     mToBeRefreshed = false;
     1321    processCurrentChanged();
     1322}
     1323
     1324
     1325void VBoxDiskImageManagerDlg::mediaAdded (const VBoxMedia &aMedia)
     1326{
     1327    /* ignore non-interesting aMedia */
     1328    if (!(type & aMedia.type))
     1329        return;
     1330
     1331    DiskImageItem *item = 0;
     1332    switch (aMedia.type)
     1333    {
     1334        case VBoxDefs::HD:
     1335            item = createHdItem (hdsView, 0, aMedia);
     1336            if (item->getUuid() == hdSelectedId)
     1337                setCurrentItem (hdsView, item);
     1338            break;
     1339        case VBoxDefs::CD:
     1340            item = createCdItem (cdsView, 0, aMedia);
     1341            if (item->getUuid() == cdSelectedId)
     1342                setCurrentItem (cdsView, item);
     1343            break;
     1344        case VBoxDefs::FD:
     1345            item = createFdItem (fdsView, 0, aMedia);
     1346            if (item->getUuid() == fdSelectedId)
     1347                setCurrentItem (fdsView, item);
     1348            break;
     1349        default:
     1350            AssertMsgFailed (("Invalid aMedia type\n"));
     1351    }
     1352    if (!item)
     1353        return;
     1354    if (!vboxGlobal().isMediaEnumerationStarted())
     1355        setCurrentItem (getListView (aMedia.type), item);
     1356}
     1357
     1358void VBoxDiskImageManagerDlg::mediaUpdated (const VBoxMedia &aMedia)
     1359{
     1360    /* ignore non-interesting aMedia */
     1361    if (!(type & aMedia.type))
     1362        return;
     1363
     1364    DiskImageItem *item = 0;
     1365    switch (aMedia.type)
     1366    {
     1367        case VBoxDefs::HD:
     1368        {
     1369            CHardDisk hd = aMedia.disk;
     1370            item = searchItem (hdsView, hd.GetId());
     1371            if (item)
     1372                updateHdItem (item, aMedia);
     1373            break;
     1374        }
     1375        case VBoxDefs::CD:
     1376        {
     1377            CDVDImage cd = aMedia.disk;
     1378            item = searchItem (cdsView, cd.GetId());
     1379            if (item)
     1380                updateCdItem (item, aMedia);
     1381            break;
     1382        }
     1383        case VBoxDefs::FD:
     1384        {
     1385            CFloppyImage fd = aMedia.disk;
     1386            item = searchItem (fdsView, fd.GetId());
     1387            if (item)
     1388                updateFdItem (item, aMedia);
     1389            break;
     1390        }
     1391        default:
     1392            AssertMsgFailed (("Invalid aMedia type\n"));
     1393    }
     1394    if (!item)
     1395        return;
     1396    if (!vboxGlobal().isMediaEnumerationStarted())
     1397        setCurrentItem (getListView (aMedia.type), item);
     1398}
     1399
     1400void VBoxDiskImageManagerDlg::mediaRemoved (VBoxDefs::DiskType aType,
     1401                                            const QUuid &aId)
     1402{
     1403    QListView *listView = getListView (aType);
     1404    DiskImageItem *item = searchItem (listView, aId);
     1405    delete item;
     1406    setCurrentItem (listView, listView->currentItem());
    13651407}
    13661408
     
    13891431
    13901432
    1391 void VBoxDiskImageManagerDlg::prepareToRefresh()
    1392 {
    1393     if (mToBeRefreshed) return;
    1394     mToBeRefreshed = true;
    1395 
     1433void VBoxDiskImageManagerDlg::prepareToRefresh (int aTotal)
     1434{
    13961435    /* info panel clearing */
    13971436    hdsPane1->clear();
     
    14041443    if (mProgressBar)
    14051444    {
    1406         int totalSteps = 0;
    1407         if (type & VBoxDefs::HD)
    1408             totalSteps += vbox.GetHardDisks().GetCount();
    1409         if (type & VBoxDefs::CD)
    1410             totalSteps += vbox.GetDVDImages().GetCount();
    1411         if (type & VBoxDefs::FD)
    1412             totalSteps += vbox.GetFloppyImages().GetCount();
    1413         mProgressBar->setProgress (0, totalSteps);
     1445        mProgressBar->setProgress (0, aTotal);
    14141446        mProgressBar->setHidden (false);
    14151447        mProgressText->setHidden (false);
     
    14231455void VBoxDiskImageManagerDlg::refreshAll()
    14241456{
    1425     if (mToBeRefreshed) return;
    1426     prepareToRefresh();
    1427     /* lists clearing */
    1428     hdsView->clear(), cdsView->clear(), fdsView->clear();
    1429     /* load all lists */
    1430     loadListViews();
    14311457    /* start enumerating media */
    14321458    vboxGlobal().startEnumeratingMedia();
     
    14941520
    14951521
    1496 void VBoxDiskImageManagerDlg::setCurrentItem (QListView *aListView, QListViewItem *aItem)
    1497 {
    1498     aListView->setFocus();
    1499     if (aItem)
    1500     {
    1501         aListView->setCurrentItem (aItem);
    1502         aListView->setSelected (aListView->currentItem(), true);
    1503         /* it is strange repeat but it works */
    1504         aListView->adjustColumn (1);
    1505         aListView->adjustColumn (2);
    1506         aListView->adjustColumn (1);
    1507     }
    1508     processCurrentChanged (aListView->currentItem());
     1522void VBoxDiskImageManagerDlg::setCurrentItem (QListView *aListView,
     1523                                              QListViewItem *aItem)
     1524{
     1525    if (!aItem)
     1526        return;
     1527
     1528    aListView->setCurrentItem (aItem);
     1529    aListView->setSelected (aListView->currentItem(), true);
     1530    /* it is strange repeat but it works */
     1531    aListView->adjustColumn (1);
     1532    aListView->adjustColumn (2);
     1533    aListView->adjustColumn (1);
    15091534}
    15101535
     
    15141539    QListView *currentList = getCurrentListView();
    15151540    currentList->setFocus();
    1516 
    1517     QListViewItem *itemToSelect =
    1518         !currentList->isSelected (currentList->currentItem()) ?
    1519         currentList->firstChild() : currentList->currentItem();
    1520     setCurrentItem (currentList, itemToSelect);
    15211541
    15221542    /* tab stop setup */
     
    15381558    setTabOrder (buttonHelp, buttonOk);
    15391559    setTabOrder (buttonOk, twImages);
     1560
     1561    processCurrentChanged (currentList->currentItem());
    15401562}
    15411563
     
    15451567        static_cast<DiskImageItem*> (aItem) : 0;
    15461568
    1547     bool modifyEnabled  = item &&  item->getUsage().isNull() &&
     1569    bool notInEnum      = !vboxGlobal().isMediaEnumerationStarted();
     1570    bool modifyEnabled  = notInEnum &&
     1571                          item &&  item->getUsage().isNull() &&
    15481572                          !item->firstChild() && !item->getPath().isNull();
    15491573    bool releaseEnabled = item && !item->getUsage().isNull() &&
     
    15511575                          !item->parent() && !item->firstChild() &&
    15521576                          item->getSnapshotName().isNull();
    1553     bool newEnabled = getCurrentListView() == hdsView ? true : false;
     1577    bool newEnabled     = notInEnum &&
     1578                          getCurrentListView() == hdsView ? true : false;
     1579    bool addEnabled     = notInEnum;
    15541580
    15551581    // imEditAction->setEnabled (modifyEnabled);
     
    15571583    imReleaseAction->setEnabled (releaseEnabled);
    15581584    imNewAction->setEnabled (newEnabled);
     1585    imAddAction->setEnabled (addEnabled);
    15591586
    15601587    // itemMenu->setItemVisible (itemMenu->idAt(0), modifyEnabled);
     
    15741601    if (item)
    15751602    {
    1576         if (getCurrentListView() == hdsView)
     1603        if (item->listView() == hdsView)
    15771604        {
    15781605            hdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
     
    15811608            hdsPane4->setText (item->getInformation (item->getUsage()));
    15821609            hdsPane5->setText (item->getInformation (item->getSnapshotName()));
    1583         }
    1584         else if (getCurrentListView() == cdsView)
     1610            hdSelectedId = item->getUuid();
     1611        }
     1612        else if (item->listView() == cdsView)
    15851613        {
    15861614            cdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
    15871615            cdsPane2->setText (item->getInformation (item->getUsage()));
    1588         }
    1589         else if (getCurrentListView() == fdsView)
     1616            cdSelectedId = item->getUuid();
     1617        }
     1618        else if (item->listView() == fdsView)
    15901619        {
    15911620            fdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
    15921621            fdsPane2->setText (item->getInformation (item->getUsage()));
     1622            fdSelectedId = item->getUuid();
    15931623        }
    15941624    }
     
    16031633        currentList->setSelected (currentList->currentItem(), true);
    16041634    }
    1605     processCurrentChanged();
    16061635}
    16071636
     
    16161645    {
    16171646        CHardDisk hd = dlg.hardDisk();
    1618         VBoxMedia::Status status = hd.GetAccessible() ?
    1619             VBoxMedia::Ok : VBoxMedia::Inaccessible;
    1620         DiskImageItem *createdItem = createHdItem (hdsView, 0, hd, status);
    1621         setCurrentItem (hdsView, createdItem);
    1622         /* synchronize modeless dialog if present */
    1623         if (mModelessDialog && mModelessDialog != this)
    1624             mModelessDialog->createHdItem (mModelessDialog->hdsView,
    1625                                            0, hd, status);
     1647        VBoxMedia::Status status =
     1648            hd.GetAccessible() ? VBoxMedia::Ok :
     1649            hd.isOk() ? VBoxMedia::Inaccessible :
     1650            VBoxMedia::Error;
     1651        VBoxMedia media (CUnknown (hd), VBoxDefs::HD, status);
     1652        vboxGlobal().addMedia (media);
    16261653    }
    16271654}
     
    16691696                                                title);
    16701697
    1671     DiskImageItem *createdItem = addImageToList (src, type);
    1672     setCurrentItem (currentList, createdItem);
    1673 
     1698    addImageToList (src, type);
    16741699    if (!vbox.isOk())
    1675     {
    16761700        vboxProblem().cannotRegisterMedia (this, vbox, type, src);
    1677     }
    16781701}
    16791702
     
    16861709        static_cast<DiskImageItem*> (currentList->currentItem()) : 0;
    16871710    AssertMsg (item, ("Current item must not be null"));
    1688     QString removedItemName = item->getName();
    16891711
    16901712    QString src = item->getPath().stripWhiteSpace();
     
    17301752    }
    17311753
    1732     if (!vbox.isOk())
    1733     {
     1754    if (vbox.isOk())
     1755        vboxGlobal().removeMedia (type, uuid);
     1756    else
    17341757        vboxProblem().cannotUnregisterMedia (this, vbox, type, src);
    1735     }
    1736     else
    1737     {
    1738         delete item;
    1739         setCurrentItem (currentList, currentList->currentItem());
    1740         /* synchronize modeless dialog if present */
    1741         if (mModelessDialog && mModelessDialog != this)
    1742         {
    1743             DiskImageItem *itemToRemove = 0;
    1744             QListView *modelessView = 0;
    1745             if (currentList == hdsView)
    1746                 modelessView = mModelessDialog->hdsView;
    1747             else if (currentList == cdsView)
    1748                 modelessView = mModelessDialog->cdsView;
    1749             else if (currentList == fdsView)
    1750                 modelessView = mModelessDialog->fdsView;
    1751             itemToRemove = static_cast<DiskImageItem*>
    1752                 (modelessView->findItem (removedItemName, 0));
    1753             delete itemToRemove;
    1754             if (modelessView->currentItem())
    1755                 modelessView->setSelected (modelessView->currentItem(), true);
    1756             mModelessDialog->processCurrentChanged();
    1757         }
    1758     }
    17591758}
    17601759
     
    17671766        static_cast<DiskImageItem*> (currentList->currentItem()) : 0;
    17681767    AssertMsg (item, ("Current item must not be null"));
    1769     QString releasedItemName = item->getName();
    1770     QString usageAfterRelease;
    17711768
    17721769    QUuid itemId = QUuid (item->getUuid());
    17731770    AssertMsg (!itemId.isNull(), ("Current item must have uuid"));
    17741771
     1772    VBoxMedia media;
    17751773    QUuid machineId;
    17761774    /* if it is a hard disk sub-item: */
     
    17821780        {
    17831781            releaseDisk (machineId, itemId, VBoxDefs::HD);
    1784 
    1785             /* re-request current usage */
    1786             machineId = vbox.GetHardDisk (itemId).GetMachineId();
    1787             usageAfterRelease = machineId.isNull() ? QString::null :
    1788                                 vbox.GetMachine (machineId).GetName();
    1789             item->setUsage (usageAfterRelease);
     1782            CHardDisk hd = vboxGlobal().virtualBox().GetHardDisk (itemId);
     1783            media = VBoxMedia (CUnknown (hd), VBoxDefs::HD, item->getStatus());
    17901784        }
    17911785    }
     
    18041798                releaseDisk (QUuid (*it), itemId, VBoxDefs::CD);
    18051799
    1806             /* re-request current usage */
    1807             usageAfterRelease = getDVDImageUsage (itemId);
    1808             item->setUsage (usageAfterRelease);
     1800            CDVDImage cd = vboxGlobal().virtualBox().GetDVDImage (itemId);
     1801            media = VBoxMedia (CUnknown (cd), VBoxDefs::CD, item->getStatus());
    18091802        }
    18101803    }
     
    18231816                releaseDisk (QUuid (*it), itemId, VBoxDefs::FD);
    18241817
    1825             /* re-request current usage */
    1826             usageAfterRelease = getFloppyImageUsage (itemId);
    1827             item->setUsage (usageAfterRelease);
    1828         }
    1829     }
    1830     processCurrentChanged (item);
    1831 
    1832     /* processing modeless dialog */
    1833     if (mModelessDialog && mModelessDialog != this)
    1834     {
    1835         DiskImageItem *itemToRelease = 0;
    1836         QListView *modelessView = 0;
    1837         if (currentList == hdsView)
    1838             modelessView = mModelessDialog->hdsView;
    1839         else if (currentList == cdsView)
    1840             modelessView = mModelessDialog->cdsView;
    1841         else if (currentList == fdsView)
    1842             modelessView = mModelessDialog->fdsView;
    1843         itemToRelease = static_cast<DiskImageItem*>
    1844             (modelessView->findItem (releasedItemName, 0));
    1845         itemToRelease->setUsage (usageAfterRelease);
    1846         mModelessDialog->processCurrentChanged();
    1847     }
     1818            CFloppyImage fd = vboxGlobal().virtualBox().GetFloppyImage (itemId);
     1819            media = VBoxMedia (CUnknown (fd), VBoxDefs::FD, item->getStatus());
     1820        }
     1821    }
     1822    if (media.type != VBoxDefs::InvalidType)
     1823        vboxGlobal().updateMedia (media);
    18481824}
    18491825
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewVMWzd.ui.h

    r382 r548  
    9999
    100100    /* HDD Images page */
    101     mediaCombo = new VBoxMediaComboBox (grbHDA, "mediaCombo", VBoxDefs::HD);
    102     mediaCombo->setUseEmptyItem (true);
    103     mediaCombo->refresh();
     101    mediaCombo = new VBoxMediaComboBox (grbHDA, "mediaCombo", VBoxDefs::HD, true);
    104102    grbHDALayout->addMultiCellWidget (mediaCombo, 0, 0, 0, 2);
    105103    setTabOrder (mediaCombo, pbNewHD);
     
    107105    connect (mediaCombo, SIGNAL (activated (int)),
    108106             this, SLOT (currentMediaChanged (int)));
     107    vboxGlobal().startEnumeratingMedia();
    109108
    110109    /// @todo (dmik) remove?
     
    339338    if (!chd.isNull())
    340339    {
     340        QUuid hdId = chd.GetId();
    341341        CVirtualBox vbox = vboxGlobal().virtualBox();
    342342        vbox.UnregisterHardDisk (chd.GetId());
     
    355355        }
    356356        chd.detach();
    357         mediaCombo->removeLastItem();
     357        vboxGlobal().removeMedia (VBoxDefs::HD, hdId);
    358358    }
    359359}
     
    368368    VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg", WType_Dialog | WShowModal);
    369369    dlg.setup (VBoxDefs::HD, true);
    370     if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
    371     {
    372         /* fetch uuid and name/path */
    373         if (dlg.getSelectedUuid() != uuidHD)
    374         {
    375             ensureNewHardDiskDeleted();
    376             uuidHD = dlg.getSelectedUuid();
    377         }
    378         /* refresh media combobox */
    379         mediaCombo->setRequiredItem (uuidHD);
    380         mediaCombo->refresh();
    381         mediaCombo->setFocus();
    382         /* revailidate */
    383         wvalHDD->revalidate();
    384     }
     370    QUuid newId = dlg.exec() == VBoxDiskImageManagerDlg::Accepted ?
     371        dlg.getSelectedUuid() : mediaCombo->getId();
     372
     373    if (uuidHD != newId)
     374    {
     375        ensureNewHardDiskDeleted();
     376        uuidHD = newId;
     377        mediaCombo->setCurrentItem (uuidHD);
     378    }
     379    mediaCombo->setFocus();
     380    /* revailidate */
     381    wvalHDD->revalidate();
    385382}
    386383
     
    401398        uuidHD = chd.GetId();
    402399        /* update media combobox */
    403         QFileInfo fi (chd.GetLocation());
    404         mediaCombo->appendItem (QString ("%1 (%2)")
    405             .arg (fi.fileName())
    406             .arg (QDir::convertSeparators (fi.dirPath())),
    407             uuidHD, VBoxDiskImageManagerDlg::composeHdToolTip (chd));
    408         mediaCombo->setCurrentItem (mediaCombo->count() - 1);
     400        VBoxMedia::Status status =
     401            chd.GetAccessible() == TRUE ? VBoxMedia::Ok :
     402            chd.isOk() ? VBoxMedia::Inaccessible :
     403            VBoxMedia::Error;
     404        VBoxMedia media (CUnknown (chd), VBoxDefs::HD, status);
     405        vboxGlobal().addMedia (media);
     406        mediaCombo->setCurrentItem (uuidHD);
    409407        mediaCombo->setFocus();
    410408        /* revailidate */
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r441 r548  
    658658{
    659659    /* setup necessary combobox item */
    660     cbHDA->setRequiredItem (uuidHDA);
    661     cbHDB->setRequiredItem (uuidHDB);
    662     cbHDD->setRequiredItem (uuidHDD);
    663     cbISODVD->setRequiredItem (uuidISODVD);
    664     cbISOFloppy->setRequiredItem (uuidISOFloppy);
    665     /* request for refresh every combo-box */
    666     cbHDA->setReadyForRefresh();
    667     cbHDB->setReadyForRefresh();
    668     cbHDD->setReadyForRefresh();
    669     cbISODVD->setReadyForRefresh();
    670     cbISOFloppy->setReadyForRefresh();
    671     /* starting media-enumerating process */
    672     vboxGlobal().startEnumeratingMedia();
     660    cbHDA->setCurrentItem (uuidHDA);
     661    cbHDB->setCurrentItem (uuidHDB);
     662    cbHDD->setCurrentItem (uuidHDD);
     663    cbISODVD->setCurrentItem (uuidISODVD);
     664    cbISOFloppy->setCurrentItem (uuidISOFloppy);
     665    /* check if the enumeration process has been started yet */
     666    if (!vboxGlobal().isMediaEnumerationStarted())
     667        vboxGlobal().startEnumeratingMedia();
     668    else
     669    {
     670        cbHDA->refresh();
     671        cbHDB->refresh();
     672        cbHDD->refresh();
     673        cbISODVD->refresh();
     674        cbISOFloppy->refresh();
     675    }
    673676}
    674677
     
    677680{
    678681    uuidHDA = grbHDA->isChecked() ? cbHDA->getId() : QUuid();
    679     cbHDA->setRequiredItem (uuidHDA);
    680682    txHDA->setText (getHdInfo (grbHDA, uuidHDA));
    681683    /* revailidate */
     
    687689{
    688690    uuidHDB = grbHDB->isChecked() ? cbHDB->getId() : QUuid();
    689     cbHDB->setRequiredItem (uuidHDB);
    690691    txHDB->setText (getHdInfo (grbHDB, uuidHDB));
    691692    /* revailidate */
     
    697698{
    698699    uuidHDD = grbHDD->isChecked() ? cbHDD->getId() : QUuid();
    699     cbHDD->setRequiredItem (uuidHDD);
    700700    txHDD->setText (getHdInfo (grbHDD, uuidHDD));
    701701    /* revailidate */
     
    707707{
    708708    uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
    709     cbISODVD->setRequiredItem (uuidISODVD);
    710709    /* revailidate */
    711710    wvalDVD->revalidate();
     
    716715{
    717716    uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->getId() : QUuid();
    718     cbISOFloppy->setRequiredItem (uuidISOFloppy);
    719717    /* revailidate */
    720718    wvalFloppy->revalidate();
     
    12881286
    12891287    /* request for media shortcuts update */
    1290     cbHDA->setBelongsTo(machine.GetId());
    1291     cbHDB->setBelongsTo(machine.GetId());
    1292     cbHDD->setBelongsTo(machine.GetId());
     1288    cbHDA->setBelongsTo (machine.GetId());
     1289    cbHDB->setBelongsTo (machine.GetId());
     1290    cbHDD->setBelongsTo (machine.GetId());
    12931291    updateShortcuts();
    12941292
     
    15411539    QUuid machineId = cmachine.GetId();
    15421540    dlg.setup (type, true, &machineId, (const VBoxMediaList*)0, cmachine);
    1543     if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
    1544         *id = dlg.getSelectedUuid();
    1545     updateShortcuts();
     1541    *id = dlg.exec() == VBoxDiskImageManagerDlg::Accepted ?
     1542        dlg.getSelectedUuid() : cbb->getId();
     1543    cbb->setCurrentItem (*id);
    15461544    cbb->setFocus();
     1545
     1546    /* revalidate pages with custom validation */
     1547    wvalHDD->revalidate();
     1548    wvalDVD->revalidate();
     1549    wvalFloppy->revalidate();
    15471550}
    15481551
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