VirtualBox

Changeset 50363 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Feb 7, 2014 1:33:58 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 4397: Medium Manager cleanup/rework (part 9): Reworking create/update/remove medium-item helpers.

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

Legend:

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

    r50353 r50363  
    273273}
    274274
    275 void UIMediumManager::refreshAll()
     275void UIMediumManager::sltRefreshAll()
    276276{
    277277    /* Start medium-enumeration: */
     
    293293        return;
    294294
    295     /* Create UIMediumItem for corresponding UIMedium: */
     295    /* Create UIMediumItem for corresponding 'medium': */
    296296    createMediumItem(medium);
    297297}
     
    299299void UIMediumManager::sltHandleMediumDeleted(const QString &strMediumID)
    300300{
    301     /* Get tree-widget / medium-item: */
    302     QList<UIMediumType> types;
    303     types << UIMediumType_HardDisk << UIMediumType_DVD << UIMediumType_Floppy;
    304     QTreeWidget *pTreeWidget = 0;
    305     UIMediumItem *pMediumItem = 0;
    306     foreach (UIMediumType type, types)
    307     {
    308         pTreeWidget = treeWidget(type);
    309         pMediumItem = searchItem(pTreeWidget, CheckIfSuitableByID(strMediumID));
    310         if (pMediumItem)
    311             break;
    312     }
    313 
    314     /* Skip further actions if medium-item was not found: */
    315     if (!pMediumItem)
    316         return;
    317 
    318     /* Update tab-icons: */
    319     updateTabIcons(pMediumItem, ItemAction_Removed);
    320 
    321     /* Delete medium-item: */
    322     delete pMediumItem;
    323 
    324     /* Make sure 'current' or at least 'first available' medium-item is currently selected, if any: */
    325     setCurrentItem(pTreeWidget, pTreeWidget->currentItem() ? pTreeWidget->currentItem() : pTreeWidget->topLevelItem(0));
     301    /* Delete UIMediumItem for corresponding 'strMediumID': */
     302    deleteMediumItem(strMediumID);
    326303}
    327304
     
    367344        return;
    368345
    369     /* Update UIMediumItem for corresponding UIMedium: */
     346    /* Update UIMediumItem for corresponding 'medium': */
    370347    updateMediumItem(medium);
    371348
     
    801778                                                          ":/refresh_22px.png", ":/refresh_16px.png",
    802779                                                          ":/refresh_disabled_22px.png", ":/refresh_disabled_16px.png"));
    803         connect(m_pActionRefresh, SIGNAL(triggered()), this, SLOT(refreshAll()));
     780        connect(m_pActionRefresh, SIGNAL(triggered()), this, SLOT(sltRefreshAll()));
    804781    }
    805782}
     
    13511328    /* Full refresh if there is at least one item present: */
    13521329    if (mTwHD->topLevelItemCount() || mTwCD->topLevelItemCount() || mTwFD->topLevelItemCount())
    1353         refreshAll();
     1330        sltRefreshAll();
    13541331}
    13551332
    13561333void UIMediumManager::createMediumItem(const UIMedium &medium)
    13571334{
     1335    /* Get medium type: */
     1336    UIMediumType type = medium.type();
     1337    /* Get corresponding tree-widget: */
     1338    QTreeWidget *pTreeWidget = treeWidget(type);
     1339
    13581340    /* Prepare medium-item: */
    13591341    UIMediumItem *pMediumItem = 0;
    1360     switch (medium.type())
     1342    switch (type)
    13611343    {
    13621344        /* Of hard-drive type: */
     
    13981380            break;
    13991381        }
    1400         default: AssertFailed();
     1382        default: AssertMsgFailed(("Medium-type unknown: %d\n", type)); break;
    14011383    }
    14021384    AssertPtrReturnVoid(pMediumItem);
     
    14051387    updateTabIcons(pMediumItem, ItemAction_Added);
    14061388
    1407     /* If medium-enumeration is not currently in progress we have to select the
    1408      * newly added item as the 'current-item' (it seems new image was added): */
    1409     if (!vboxGlobal().isMediumEnumerationInProgress())
    1410         setCurrentItem(treeWidget(medium.type()), pMediumItem);
    1411 
    1412     /* If no 'current-item' yet selected
    1413      * we have to choose newly added as the 'current-item': */
    1414     if (!treeWidget(medium.type())->currentItem())
    1415         setCurrentItem(treeWidget(medium.type()), pMediumItem);
    1416 
    1417     /* Update linked stuff if that was 'current-item' added: */
    1418     if (pMediumItem == currentTreeWidget()->currentItem())
     1389    /* If medium-enumeration is not currently in progress or
     1390     * if there is no 'current' medium-item yet selected
     1391     * we have to choose newly added medium-item as 'current' one: */
     1392    if (   !vboxGlobal().isMediumEnumerationInProgress()
     1393        || !pTreeWidget->currentItem())
     1394        setCurrentItem(pTreeWidget, pMediumItem);
     1395
     1396    /* Update linked stuff if that was current medium-item created: */
     1397    if (pMediumItem == currentMediumItem())
    14191398        sltHandleCurrentItemChanged(pMediumItem);
    14201399}
     
    14221401void UIMediumManager::updateMediumItem(const UIMedium &medium)
    14231402{
    1424     /* Search for the existing medium-item: */
     1403    /* Search for existing medium-item: */
    14251404    UIMediumItem *pMediumItem = searchItem(treeWidget(medium.type()), CheckIfSuitableByID(medium.id()));
    14261405
    1427     /* Create new if was not found: */
     1406    /* Create medium-item (if it was not found): */
    14281407    if (!pMediumItem)
    14291408        return createMediumItem(medium);
    14301409
    1431     /* Update otherwise: */
     1410    /* Update medium-item: */
    14321411    pMediumItem->setMedium(medium);
    14331412    LogRel2(("UIMediumManager: Medium-item with ID={%s} updated.\n", medium.id().toAscii().constData()));
     
    14361415    updateTabIcons(pMediumItem, ItemAction_Updated);
    14371416
    1438     /* Update linked stuff if that was 'current-item' updated: */
    1439     if (pMediumItem == currentTreeWidget()->currentItem())
     1417    /* Update linked stuff if that was current medium-item updated: */
     1418    if (pMediumItem == currentMediumItem())
    14401419        sltHandleCurrentItemChanged(pMediumItem);
     1420}
     1421
     1422void UIMediumManager::deleteMediumItem(const QString &strMediumID)
     1423{
     1424    /* Search for corresponding tree-widget: */
     1425    QList<UIMediumType> types;
     1426    types << UIMediumType_HardDisk << UIMediumType_DVD << UIMediumType_Floppy;
     1427    QTreeWidget *pTreeWidget = 0;
     1428    UIMediumItem *pMediumItem = 0;
     1429    foreach (UIMediumType type, types)
     1430    {
     1431        /* Get iterated tree-widget: */
     1432        pTreeWidget = treeWidget(type);
     1433        /* Search for existing medium-item: */
     1434        pMediumItem = searchItem(pTreeWidget, CheckIfSuitableByID(strMediumID));
     1435        if (pMediumItem)
     1436            break;
     1437    }
     1438
     1439    /* Ignore medium-item (if it was not found): */
     1440    if (!pMediumItem)
     1441        return;
     1442
     1443    /* Update tab-icons: */
     1444    updateTabIcons(pMediumItem, ItemAction_Removed);
     1445
     1446    /* Delete medium-item: */
     1447    delete pMediumItem;
     1448    LogRel2(("UIMediumManager: Medium-item with ID={%s} deleted.\n", strMediumID.toAscii().constData()));
     1449
     1450    /* If there is no 'current' medium-item now selected
     1451     * we have to choose first-available medium-item as 'current' one: */
     1452    if (!pTreeWidget->currentItem())
     1453        setCurrentItem(pTreeWidget, pTreeWidget->topLevelItem(0));
    14411454}
    14421455
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r50353 r50363  
    6565    static void showModeless(QWidget *pCenterWidget, bool fRefresh = true);
    6666
    67 public slots:
    68 
    69     /* Handler: Refresh stuff: */
    70     void refreshAll();
    71 
    7267private slots:
     68
     69    /** Fully refreshes medium manager contents. */
     70    void sltRefreshAll();
    7371
    7472    /* Handlers: Medium-processing stuff: */
     
    143141    void retranslateUi();
    144142
    145     /** Creates UIMediumItem for corresponding UIMedium. */
     143    /** Creates UIMediumItem for corresponding @a medium. */
    146144    void createMediumItem(const UIMedium &medium);
    147     /** Updates UIMediumItem for corresponding UIMedium. */
     145    /** Updates UIMediumItem for corresponding @a medium. */
    148146    void updateMediumItem(const UIMedium &medium);
     147    /** Deletes UIMediumItem for corresponding @a strMediumID. */
     148    void deleteMediumItem(const QString &strMediumID);
    149149
    150150    /* Helpers: Medium-modification 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