VirtualBox

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


Ignore:
Timestamp:
Apr 22, 2020 2:44:48 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Shortcut for cache & cache item type inside item as well; Adding a bit of assertion paranoia here and there across related stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r83924 r83929  
    328328        int iCountOfStartedMachineItems = 0;
    329329        foreach (UIChooserItem *pItem, items(UIChooserNodeType_Machine))
    330             if (pItem->node()->toMachineNode()->cache()->isItemStarted())
     330        {
     331            AssertPtrReturnVoid(pItem);
     332            UIChooserItemMachine *pMachineItem = pItem->toMachineItem();
     333            AssertPtrReturnVoid(pMachineItem);
     334            AssertPtrReturnVoid(pMachineItem->cache());
     335            if (pMachineItem->cache()->isItemStarted())
    331336                ++iCountOfStartedMachineItems;
     337        }
    332338        /* Template: */
    333339        QString strMachineCount = tr("%n machine(s)", "Group item tool-tip / Machine info", items(UIChooserNodeType_Machine).size());
     
    731737        /* For local items: */
    732738        if (   nodeToGroupType()->groupType() == UIChooserNodeGroupType_Local
    733             && pMachineItem->nodeToMachineType()->cacheType() == UIVirtualMachineItemType_Local)
     739            && pMachineItem->cacheType() == UIVirtualMachineItemType_Local)
    734740        {
    735741            /* Make sure passed machine isn't immutable within own group: */
     
    756762        else
    757763        if (   nodeToGroupType()->groupType() == UIChooserNodeGroupType_Profile
    758             && pMachineItem->nodeToMachineType()->cacheType() == UIVirtualMachineItemType_CloudReal)
     764            && pMachineItem->cacheType() == UIVirtualMachineItemType_CloudReal)
    759765        {
    760766            /* Make sure passed item is ours: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r83924 r83929  
    6464}
    6565
     66UIVirtualMachineItem *UIChooserItemMachine::cache() const
     67{
     68    return nodeToMachineType() ? nodeToMachineType()->cache() : 0;
     69}
     70
     71UIVirtualMachineItemType UIChooserItemMachine::cacheType() const
     72{
     73    return cache() ? cache()->itemType() : UIVirtualMachineItemType_Invalid;
     74}
     75
    6676QUuid UIChooserItemMachine::id() const
    6777{
    68     return nodeToMachineType()->cache()->id();
     78    return cache() ? cache()->id() : QUuid();
    6979}
    7080
    7181bool UIChooserItemMachine::accessible() const
    7282{
    73     return nodeToMachineType()->cache()->accessible();
     83    return cache() ? cache()->accessible() : false;
    7484}
    7585
    7686void UIChooserItemMachine::recache()
    7787{
    78     nodeToMachineType()->cache()->recache();
     88    if (cache())
     89        cache()->recache();
    7990}
    8091
    8192bool UIChooserItemMachine::isLockedMachine() const
    8293{
    83     const KMachineState enmState = nodeToMachineType()->cache()->machineState();
     94    const KMachineState enmState = cacheType() == UIVirtualMachineItemType_Local
     95                                 ? cache()->machineState()
     96                                 : KMachineState_Null;
    8497    return enmState != KMachineState_PoweredOff &&
    8598           enmState != KMachineState_Saved &&
     
    159172
    160173    /* Recache and update pixmaps: */
    161     nodeToMachineType()->cache()->recachePixmap();
     174    AssertPtrReturnVoid(cache());
     175    cache()->recachePixmap();
    162176    updatePixmaps();
    163177}
     
    225239void UIChooserItemMachine::updateToolTip()
    226240{
    227     setToolTip(nodeToMachineType()->cache()->toolTipText());
     241    AssertPtrReturnVoid(cache());
     242    setToolTip(cache()->toolTipText());
    228243}
    229244
     
    302317    /* And machine-item content to take into account: */
    303318    int iTopLineWidth = m_iMinimumNameWidth;
    304     if (   nodeToMachineType()->cacheType() == UIVirtualMachineItemType_Local
    305         && !nodeToMachineType()->cache()->toLocal()->snapshotName().isEmpty())
     319    /* Only local items can have snapshots: */
     320    if (   cacheType() == UIVirtualMachineItemType_Local
     321        && !cache()->toLocal()->snapshotName().isEmpty())
    306322        iTopLineWidth += (iMinorSpacing +
    307323                          m_iMinimumSnapshotNameWidth);
     
    400416
    401417        /* No drops for cloud items: */
    402         if (   nodeToMachineType()->cacheType() != UIVirtualMachineItemType_Local
    403             || pMachineItem->nodeToMachineType()->cacheType() != UIVirtualMachineItemType_Local)
     418        if (   cacheType() != UIVirtualMachineItemType_Local
     419            || pMachineItem->cacheType() != UIVirtualMachineItemType_Local)
    404420            return false;
    405421        /* No drops for immutable item: */
     
    498514{
    499515    /* Recache and update pixmaps: */
    500     nodeToMachineType()->cache()->recachePixmap();
     516    AssertPtrReturnVoid(cache());
     517    cache()->recachePixmap();
    501518    updatePixmaps();
    502519}
     
    614631{
    615632    /* Get new pixmap and pixmap-size: */
     633    AssertPtrReturnVoid(cache());
    616634    QSize pixmapSize;
    617     QPixmap pixmap = nodeToMachineType()->cache()->osPixmap(&pixmapSize);
     635    QPixmap pixmap = cache()->osPixmap(&pixmapSize);
    618636    /* Update linked values: */
    619637    if (m_pixmapSize != pixmapSize)
     
    635653    const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    636654    /* Get new state-pixmap and state-pixmap size: */
    637     const QIcon stateIcon = nodeToMachineType()->cache()->machineStateIcon();
     655    AssertPtrReturnVoid(cache());
     656    const QIcon stateIcon = cache()->machineStateIcon();
    638657    AssertReturnVoid(!stateIcon.isNull());
    639658    const QSize statePixmapSize = QSize(iIconMetric, iIconMetric);
     
    726745    int iMinimumSnapshotNameWidth = 0;
    727746    /* Is there any snapshot exists? */
    728     if (   nodeToMachineType()->cacheType() == UIVirtualMachineItemType_Local
    729         && !nodeToMachineType()->cache()->toLocal()->snapshotName().isEmpty())
     747    if (   cacheType() == UIVirtualMachineItemType_Local
     748        && !cache()->toLocal()->snapshotName().isEmpty())
    730749    {
    731750        QFontMetrics fm(m_snapshotNameFont, model()->paintDevice());
    732751        int iBracketWidth = fm.width("()"); /* bracket width */
    733         int iActualTextWidth = fm.width(nodeToMachineType()->cache()->toLocal()->snapshotName()); /* snapshot-name width */
     752        int iActualTextWidth = fm.width(cache()->toLocal()->snapshotName()); /* snapshot-name width */
    734753        int iMinimumTextWidth = fm.width("..."); /* ellipsis width */
    735754        iMinimumSnapshotNameWidth = iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth);
     
    812831{
    813832    /* Make sure this is local machine item: */
    814     if (nodeToMachineType()->cacheType() != UIVirtualMachineItemType_Local)
     833    if (cacheType() != UIVirtualMachineItemType_Local)
    815834        return;
    816835
     
    820839    /* Calculate new visible snapshot-name: */
    821840    int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).width("()");
    822     QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, nodeToMachineType()->cache()->toLocal()->snapshotName(),
     841    QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, cache()->toLocal()->snapshotName(),
    823842                                                  m_iMaximumSnapshotNameWidth - iBracketWidth);
    824843    strVisibleSnapshotName = QString("(%1)").arg(strVisibleSnapshotName);
     
    841860{
    842861    /* Get new state-text and state-text size: */
    843     const QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), nodeToMachineType()->cache()->machineStateName());
     862    AssertPtrReturnVoid(cache());
     863    const QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), cache()->machineStateName());
    844864
    845865    /* Update linked values: */
     
    11181138
    11191139            /* Paint middle element: */
    1120             if (   nodeToMachineType()->cacheType() == UIVirtualMachineItemType_Local
    1121                 && !nodeToMachineType()->cache()->toLocal()->snapshotName().isEmpty())
     1140            if (   cacheType() == UIVirtualMachineItemType_Local
     1141                && !cache()->toLocal()->snapshotName().isEmpty())
    11221142            {
    11231143                /* Prepare variables: */
     
    11681188                int iMachineStateTextY = iBottomLineIndent + 1;
    11691189                /* Paint state text: */
     1190                AssertPtrReturnVoid(cache());
    11701191                paintText(/* Painter: */
    11711192                          pPainter,
     
    11771198                          model()->paintDevice(),
    11781199                          /* Text to paint: */
    1179                           nodeToMachineType()->cache()->machineStateName());
     1200                          cache()->machineStateName());
    11801201            }
    11811202        }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h

    r83924 r83929  
    2424/* GUI includes: */
    2525#include "UIChooserItem.h"
     26#include "UIManagerDefs.h"
    2627
    2728/* Forward declarations: */
    2829class UIChooserNodeMachine;
     30class UIVirtualMachineItem;
    2931
    3032
     
    4850        /** Returns machine node reference. */
    4951        UIChooserNodeMachine *nodeToMachineType() const;
     52
     53        /** Returns virtual machine cache instance. */
     54        UIVirtualMachineItem *cache() const;
     55        /** Returns virtual machine cache type. */
     56        UIVirtualMachineItemType cacheType() const;
    5057
    5158        /** Returns item machine id. */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r83925 r83929  
    296296    return      firstSelectedItem()
    297297             && firstSelectedItem()->firstMachineItem()
    298              && firstSelectedItem()->firstMachineItem()->node()
    299              && firstSelectedItem()->firstMachineItem()->node()->toMachineNode()
    300            ? firstSelectedItem()->firstMachineItem()->node()->toMachineNode()->cache()
     298             && firstSelectedItem()->firstMachineItem()->toMachineItem()
     299           ? firstSelectedItem()->firstMachineItem()->toMachineItem()->cache()
    301300           : 0;
    302301}
     
    312311    QList<UIVirtualMachineItem*> currentMachineList;
    313312    foreach (UIChooserItemMachine *pItem, currentMachineItemList)
    314         currentMachineList << pItem->nodeToMachineType()->cache();
     313        currentMachineList << pItem->cache();
    315314    return currentMachineList;
    316315}
     
    10561055    foreach (UIChooserItemMachine *pItem, inaccessibleMachineItemList)
    10571056    {
    1058         switch (pItem->nodeToMachineType()->cacheType())
     1057        switch (pItem->cacheType())
    10591058        {
    10601059            case UIVirtualMachineItemType_Local:
     
    10821081            {
    10831082                /* Much more simple than for local items, we are not reloading them, just refreshing: */
    1084                 pItem->nodeToMachineType()->cache()->toCloud()->updateInfoAsync(false /* delayed */);
     1083                pItem->cache()->toCloud()->updateInfoAsync(false /* delayed */);
    10851084
    10861085                break;
     
    11501149        if (fVerdict)
    11511150        {
    1152             if (pMachineItem->nodeToMachineType()->cacheType() == UIVirtualMachineItemType_Local)
    1153                 localMachinesToUnregister.append(pMachineItem->nodeToMachineType()->cache()->toLocal()->machine());
    1154             else if (pMachineItem->nodeToMachineType()->cacheType() == UIVirtualMachineItemType_CloudReal)
    1155                 cloudMachinesToUnregister.append(pMachineItem->nodeToMachineType()->cache()->toCloud()->machine());
     1151            if (pMachineItem->cacheType() == UIVirtualMachineItemType_Local)
     1152                localMachinesToUnregister.append(pMachineItem->cache()->toLocal()->machine());
     1153            else if (pMachineItem->cacheType() == UIVirtualMachineItemType_CloudReal)
     1154                cloudMachinesToUnregister.append(pMachineItem->cache()->toCloud()->machine());
    11561155        }
    11571156        else
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