VirtualBox

Ignore:
Timestamp:
Mar 6, 2014 2:00:01 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Medium Manager rework/cleanup: Prevent current medium-item change when not really necessary.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r50706 r50712  
    422422    , m_pCenterWidget(pCenterWidget)
    423423    , m_fRefresh(fRefresh)
     424    , m_fPreventChangeCurrentItem(false)
    424425    , m_fInaccessibleHD(false)
    425426    , m_fInaccessibleCD(false)
     
    475476        return;
    476477
    477     /* Create UIMediumItem for corresponding 'medium': */
    478     createMediumItem(medium);
     478    /* Create medium-item for corresponding medium: */
     479    UIMediumItem *pMediumItem = createMediumItem(medium);
     480    AssertPtrReturnVoid(pMediumItem);
     481
     482    /* If medium-item change allowed and
     483     * 1. medium-enumeration is not currently in progress or
     484     * 2. if there is no currently medium-item selected
     485     * we have to choose newly added medium-item as current one: */
     486    if (   !m_fPreventChangeCurrentItem
     487        && (   !vboxGlobal().isMediumEnumerationInProgress()
     488            || !mediumItem(medium.type())))
     489        setCurrentItem(treeWidget(medium.type()), pMediumItem);
    479490}
    480491
     
    10871098    pTreeWidgetFD->clear();
    10881099
    1089     /* Create medium-items: */
     1100    /* Create medium-items (do not change current one): */
     1101    m_fPreventChangeCurrentItem = true;
    10901102    foreach (const QString &strMediumID, vboxGlobal().mediumIDs())
    10911103        sltHandleMediumCreated(strMediumID);
     1104    m_fPreventChangeCurrentItem = false;
    10921105
    10931106    /* Select first item as current one if nothing selected: */
     
    14451458}
    14461459
    1447 void UIMediumManager::createMediumItem(const UIMedium &medium)
     1460UIMediumItem* UIMediumManager::createMediumItem(const UIMedium &medium)
    14481461{
    14491462    /* Get medium type: */
    14501463    UIMediumType type = medium.type();
    1451     /* Get corresponding tree-widget: */
    1452     QTreeWidget *pTreeWidget = treeWidget(type);
    1453 
    1454     /* Prepare medium-item: */
     1464
     1465    /* Create medium-item: */
    14551466    UIMediumItem *pMediumItem = 0;
    14561467    switch (type)
     
    14601471        {
    14611472            pMediumItem = createHardDiskItem(mTwHD, medium);
    1462             AssertPtrReturnVoid(pMediumItem);
     1473            AssertPtrReturn(pMediumItem, 0);
    14631474            if (pMediumItem->id() == m_strSelectedIdHD)
    14641475            {
     
    14731484            pMediumItem = new UIMediumItemCD(medium, mTwCD);
    14741485            LogRel2(("UIMediumManager: Optical medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
    1475             AssertPtrReturnVoid(pMediumItem);
     1486            AssertPtrReturn(pMediumItem, 0);
    14761487            if (pMediumItem->id() == m_strSelectedIdCD)
    14771488            {
     
    14861497            pMediumItem = new UIMediumItemFD(medium, mTwFD);
    14871498            LogRel2(("UIMediumManager: Floppy medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
    1488             AssertPtrReturnVoid(pMediumItem);
     1499            AssertPtrReturn(pMediumItem, 0);
    14891500            if (pMediumItem->id() == m_strSelectedIdFD)
    14901501            {
     
    14961507        default: AssertMsgFailed(("Medium-type unknown: %d\n", type)); break;
    14971508    }
    1498     AssertPtrReturnVoid(pMediumItem);
     1509    AssertPtrReturn(pMediumItem, 0);
    14991510
    15001511    /* Update tab-icons: */
    15011512    updateTabIcons(pMediumItem, Action_Add);
    1502 
    1503     /* If medium-enumeration is not currently in progress or
    1504      * if there is no current medium-item yet selected
    1505      * we have to choose newly added medium-item as current one: */
    1506     if (   !vboxGlobal().isMediumEnumerationInProgress()
    1507         || !pTreeWidget->currentItem())
    1508         setCurrentItem(pTreeWidget, pMediumItem);
    15091513
    15101514    /* Re-fetch medium-item if it is current one created: */
    15111515    if (pMediumItem == mediumItem(type))
    15121516        refetchCurrentMediumItem(type);
     1517
     1518    /* Return created medium-item: */
     1519    return pMediumItem;
    15131520}
    15141521
     
    15181525    UIMediumType type = medium.type();
    15191526
    1520     /* Search for existing medium-item: */
     1527    /* Search for existing medium-item, create if was not found: */
    15211528    UIMediumItem *pMediumItem = searchItem(treeWidget(type), CheckIfSuitableByID(medium.id()));
    1522 
    1523     /* Create medium-item (if it was not found): */
    1524     if (!pMediumItem)
    1525         return createMediumItem(medium);
     1529    if (!pMediumItem) pMediumItem = createMediumItem(medium);
     1530    AssertPtrReturnVoid(pMediumItem);
    15261531
    15271532    /* Update medium-item: */
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r50704 r50712  
    158158
    159159    /** Creates UIMediumItem for corresponding @a medium. */
    160     void createMediumItem(const UIMedium &medium);
     160    UIMediumItem* createMediumItem(const UIMedium &medium);
    161161    /** Updates UIMediumItem for corresponding @a medium. */
    162162    void updateMediumItem(const UIMedium &medium);
     
    212212    QWidget *m_pCenterWidget;
    213213    bool m_fRefresh;
     214    bool m_fPreventChangeCurrentItem;
    214215
    215216    /* Variables: Tab-widget stuff: */
Note: See TracChangeset for help on using the changeset viewer.

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