VirtualBox

Changeset 50368 in vbox


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

FE/Qt: 4397: Medium Manager cleanup/rework (part 10): Separate current medium-item handling for each tree-widget.

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

Legend:

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

    r50363 r50368  
    326326    repopulateTreeWidgets();
    327327
    328     /* Update current tab: */
    329     sltHandleCurrentTabChanged();
     328    /* Re-fetch all current medium-items: */
     329    refetchCurrentMediumItems();
    330330}
    331331
     
    359359    m_pActionRefresh->setEnabled(true);
    360360
    361     /* Update current tab: */
    362     sltHandleCurrentTabChanged();
     361    /* Re-fetch all current medium-items: */
     362    refetchCurrentMediumItems();
    363363}
    364364
     
    515515    {
    516516        /* This may happen if medium was already released by a third party,
    517          * update the details and silently return. */
    518         sltHandleCurrentItemChanged(pMediumItem);
    519         return;
     517         * re-fetch currently chosen medium-item and silently return. */
     518        return refetchCurrentChosenMediumItem();
    520519    }
    521520
     
    551550        pTree->setFocus();
    552551
    553     /* Make sure current medium-item is selected: */
    554     sltHandleCurrentItemChanged(pTree->currentItem());
    555 }
    556 
    557 void UIMediumManager::sltHandleCurrentItemChanged(QTreeWidgetItem *pItem)
    558 {
    559     /* If item set => make sure it's of valid type: */
    560     UIMediumItem *pMediumItem = toMediumItem(pItem);
    561     AssertReturnVoid(!pItem || pMediumItem);
    562 
    563     /* If medium-item set: */
    564     if (pMediumItem)
    565     {
    566         /* Set the file for the proxy icon: */
    567         setFileForProxyIcon(pMediumItem->location());
    568         /* Make sure current medium-item visible: */
    569         pMediumItem->treeWidget()->scrollToItem(pMediumItem, QAbstractItemView::EnsureVisible);
    570     }
    571 
    572     /* Update actions: */
    573     updateActions();
    574 
    575     /* Update current information-panes: */
    576     updateInformationPanes(currentMediumType());
     552    /* Re-fetch currently chosen medium-item: */
     553    refetchCurrentChosenMediumItem();
     554}
     555
     556void UIMediumManager::sltHandleCurrentItemChanged()
     557{
     558    /* Determine tree-widget sender: */
     559    QTreeWidget *pTreeWidget = qobject_cast<QTreeWidget*>(sender());
     560    AssertMsgReturnVoid(pTreeWidget, ("This slot should be called by tree-widget only!\n"));
     561
     562    /* Re-fetch current medium-item of required type: */
     563    refetchCurrentMediumItem(mediumType(pTreeWidget));
    577564}
    578565
     
    866853    prepareTreeWidgetFD();
    867854
    868     /* Focus current tree: */
     855    /* Focus current tree-widget: */
    869856    currentTreeWidget()->setFocus();
    870857}
     
    883870        mTwHD->setSortingEnabled(true);
    884871        connect(mTwHD, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    885                 this, SLOT(sltHandleCurrentItemChanged(QTreeWidgetItem*)));
     872                this, SLOT(sltHandleCurrentItemChanged()));
    886873        connect(mTwHD, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    887874                this, SLOT(sltHandleDoubleClick()));
     
    907894        mTwCD->setSortingEnabled(true);
    908895        connect(mTwCD, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    909                 this, SLOT(sltHandleCurrentItemChanged(QTreeWidgetItem*)));
     896                this, SLOT(sltHandleCurrentItemChanged()));
    910897        connect(mTwCD, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    911898                this, SLOT(sltHandleDoubleClick()));
     
    931918        mTwFD->setSortingEnabled(true);
    932919        connect(mTwFD, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    933                 this, SLOT(sltHandleCurrentItemChanged(QTreeWidgetItem*)));
     920                this, SLOT(sltHandleCurrentItemChanged()));
    934921        connect(mTwFD, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    935922                this, SLOT(sltHandleDoubleClick()));
     
    10201007        if (QTreeWidgetItem *pItem = pTreeWidgetFD->topLevelItem(0))
    10211008            setCurrentItem(pTreeWidgetFD, pItem);
     1009}
     1010
     1011void UIMediumManager::refetchCurrentMediumItem(UIMediumType type)
     1012{
     1013    /* Get corresponding medium-item: */
     1014    UIMediumItem *pMediumItem = mediumItem(type);
     1015
     1016    /* If medium-item set: */
     1017    if (pMediumItem)
     1018    {
     1019        /* Set the file for the proxy icon: */
     1020        setFileForProxyIcon(pMediumItem->location());
     1021        /* Make sure current medium-item visible: */
     1022        treeWidget(type)->scrollToItem(pMediumItem, QAbstractItemView::EnsureVisible);
     1023    }
     1024
     1025    /* Update actions: */
     1026    updateActions();
     1027
     1028    /* Update corresponding information-panes: */
     1029    updateInformationPanes(type);
     1030}
     1031
     1032void UIMediumManager::refetchCurrentChosenMediumItem()
     1033{
     1034    refetchCurrentMediumItem(currentMediumType());
     1035}
     1036
     1037void UIMediumManager::refetchCurrentMediumItems()
     1038{
     1039    refetchCurrentMediumItem(UIMediumType_HardDisk);
     1040    refetchCurrentMediumItem(UIMediumType_DVD);
     1041    refetchCurrentMediumItem(UIMediumType_Floppy);
    10221042}
    10231043
     
    13881408
    13891409    /* 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: */
     1410     * if there is no current medium-item yet selected
     1411     * we have to choose newly added medium-item as current one: */
    13921412    if (   !vboxGlobal().isMediumEnumerationInProgress()
    13931413        || !pTreeWidget->currentItem())
    13941414        setCurrentItem(pTreeWidget, pMediumItem);
    13951415
    1396     /* Update linked stuff if that was current medium-item created: */
    1397     if (pMediumItem == currentMediumItem())
    1398         sltHandleCurrentItemChanged(pMediumItem);
     1416    /* Re-fetch medium-item if it is current one created: */
     1417    if (pMediumItem == mediumItem(type))
     1418        refetchCurrentMediumItem(type);
    13991419}
    14001420
    14011421void UIMediumManager::updateMediumItem(const UIMedium &medium)
    14021422{
     1423    /* Get medium type: */
     1424    UIMediumType type = medium.type();
     1425
    14031426    /* Search for existing medium-item: */
    1404     UIMediumItem *pMediumItem = searchItem(treeWidget(medium.type()), CheckIfSuitableByID(medium.id()));
     1427    UIMediumItem *pMediumItem = searchItem(treeWidget(type), CheckIfSuitableByID(medium.id()));
    14051428
    14061429    /* Create medium-item (if it was not found): */
     
    14151438    updateTabIcons(pMediumItem, ItemAction_Updated);
    14161439
    1417     /* Update linked stuff if that was current medium-item updated: */
    1418     if (pMediumItem == currentMediumItem())
    1419         sltHandleCurrentItemChanged(pMediumItem);
     1440    /* Re-fetch medium-item if it is current one updated: */
     1441    if (pMediumItem == mediumItem(type))
     1442        refetchCurrentMediumItem(type);
    14201443}
    14211444
     
    14481471    LogRel2(("UIMediumManager: Medium-item with ID={%s} deleted.\n", strMediumID.toAscii().constData()));
    14491472
    1450     /* If there is no 'current' medium-item now selected
    1451      * we have to choose first-available medium-item as 'current' one: */
     1473    /* If there is no current medium-item now selected
     1474     * we have to choose first-available medium-item as current one: */
    14521475    if (!pTreeWidget->currentItem())
    14531476        setCurrentItem(pTreeWidget, pTreeWidget->topLevelItem(0));
     
    15961619}
    15971620
     1621UIMediumType UIMediumManager::mediumType(QTreeWidget *pTreeWidget) const
     1622{
     1623    /* Hard-drive tree-widget: */
     1624    if (pTreeWidget == mTwHD) return UIMediumType_HardDisk;
     1625    /* Optical-image tree-widget: */
     1626    if (pTreeWidget == mTwCD) return UIMediumType_DVD;
     1627    /* Floppy-image tree-widget: */
     1628    if (pTreeWidget == mTwFD) return UIMediumType_Floppy;
     1629    /* Invalid by default: */
     1630    AssertFailedReturn(UIMediumType_Invalid);
     1631}
     1632
    15981633UIMediumType UIMediumManager::currentMediumType() const
    15991634{
     
    16491684    AssertPtrReturnVoid(pTreeWidget);
    16501685
    1651     /* Make passed item 'current' for passed tree-widget: */
     1686    /* Make passed item current for passed tree-widget: */
    16521687    pTreeWidget->setCurrentItem(pItem);
    16531688
     
    16601695    }
    16611696
    1662     /* Update linked stuff: */
    1663     sltHandleCurrentItemChanged(pItem);
     1697    /* Re-fetch currently chosen medium-item: */
     1698    refetchCurrentChosenMediumItem();
    16641699}
    16651700
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r50363 r50368  
    8787    /* Handlers: Navigation stuff: */
    8888    void sltHandleCurrentTabChanged();
    89     void sltHandleCurrentItemChanged(QTreeWidgetItem *pItem);
     89    void sltHandleCurrentItemChanged();
    9090    void sltHandleDoubleClick();
    9191    void sltHandleContextMenuCall(const QPoint &position);
     
    119119    void repopulateTreeWidgets();
    120120
     121    /** Updates details according latest changes in current medium-item of predefined @a type. */
     122    void refetchCurrentMediumItem(UIMediumType type);
     123    /** Updates details according latest changes in current medium-item of chosen type. */
     124    void refetchCurrentChosenMediumItem();
     125    /** Updates details according latest changes in all current medium-items. */
     126    void refetchCurrentMediumItems();
     127
    121128    /** Update actions according currently chosen medium-item. */
    122129    void updateActions();
     
    154161    bool releaseFloppyDiskFrom(const UIMedium &medium, CMachine &machine);
    155162
     163    /** Determines medium type for passed @a pTreeWidget. */
     164    UIMediumType mediumType(QTreeWidget *pTreeWidget) const;
     165
    156166    /** Returns current medium type. */
    157167    UIMediumType currentMediumType() const;
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