VirtualBox

Changeset 55101 in vbox


Ignore:
Timestamp:
Apr 3, 2015 8:22:01 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99396
Message:

FE/Qt: 7127: Medium-enumeration improvements: UIMedium refresh rework (step 1).

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

Legend:

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

    r55100 r55101  
    100100
    101101    m_fHidden = other.m_fHidden;
    102     m_fAttachedToHiddenMachinesOnly = other.m_fAttachedToHiddenMachinesOnly;
     102    m_fUsedByHiddenMachinesOnly = other.m_fUsedByHiddenMachinesOnly;
    103103    m_fReadOnly = other.isReadOnly();
    104104    m_fUsedInSnapshots = other.isUsedInSnapshots();
     
    110110void UIMedium::blockAndQueryState()
    111111{
     112    /* Ignore for NULL medium: */
    112113    if (m_medium.isNull())
    113114        return;
    114115
     116    /* Acquire actual medium state: */
    115117    m_state = m_medium.RefreshState();
    116118
     
    126128        m_strLastAccessError = m_medium.GetLastAccessError();
    127129
     130    /* Refresh finally: */
    128131    refresh();
    129132}
     
    131134void UIMedium::refresh()
    132135{
    133     /* Flags are 'false' by default: */
     136    /* Reset ID parameters: */
     137    m_strId = nullID();
     138    m_strRootId = nullID();
     139    m_strParentId = nullID();
     140
     141    /* Reset cache parameters: */
     142    //m_strKey = nullID();
     143
     144    /* Reset name/location parameters: */
     145    m_strName = VBoxGlobal::tr("Empty", "medium");
     146    m_strLocation = m_strSize = m_strLogicalSize = QString("--");
     147
     148    /* Reset size parameters: */
     149    m_strSize = QString();
     150    m_strLogicalSize = QString();
     151
     152    /* Reset hard drive related parameters: */
     153    m_strHardDiskType = QString();
     154    m_strHardDiskFormat = QString();
     155    m_strStorageDetails = QString();
     156
     157    /* Reset data parameters: */
     158    m_strUsage = QString();
     159    m_strToolTip = QString();
     160    m_machineIds.clear();
     161    m_curStateMachineIds.clear();
     162
     163    /* Reset m_noDiffs: */
     164    m_noDiffs.isSet = false;
     165
     166    /* Reset flags: */
    134167    m_fHidden = false;
    135     m_fAttachedToHiddenMachinesOnly = false;
     168    m_fUsedByHiddenMachinesOnly = false;
    136169    m_fReadOnly = false;
    137170    m_fUsedInSnapshots = false;
    138171    m_fHostDrive = false;
    139172
    140     /* Detect basic parameters... */
    141 
    142     m_strId = m_medium.isNull() ? nullID() : m_medium.GetId();
    143 
    144     if (m_strKey.isNull() && !m_strId.isNull())
    145         m_strKey = m_strId;
    146 
    147     m_fHostDrive = m_medium.isNull() ? false : m_medium.GetHostDrive();
    148 
    149     if (m_medium.isNull())
    150         m_strName = VBoxGlobal::tr("Empty", "medium");
    151     else if (!m_fHostDrive)
    152         m_strName = m_medium.GetName();
    153     else if (m_medium.GetDescription().isEmpty())
    154         m_strName = VBoxGlobal::tr("Host Drive '%1'", "medium").arg(QDir::toNativeSeparators(m_medium.GetLocation()));
    155     else
    156         m_strName = VBoxGlobal::tr("Host Drive %1 (%2)", "medium").arg(m_medium.GetDescription(), m_medium.GetName());
    157 
    158     m_strLocation = m_medium.isNull() || m_fHostDrive ? QString("--") :
    159                     QDir::toNativeSeparators(m_medium.GetLocation());
    160 
    161     QString tmp;
     173    /* For non NULL medium: */
    162174    if (!m_medium.isNull())
    163         tmp = m_medium.GetProperty("Special/GUI/Hints");
    164     if (!tmp.isEmpty())
    165     {
    166         QStringList tmpList(tmp.split(','));
    167         if (tmpList.contains("Hide", Qt::CaseInsensitive))
    168             m_fHidden = true;
    169     }
    170 
    171     /* Initialize parent/root IDs: */
    172     m_strParentId = nullID();
    173     m_strRootId = m_strId;
    174     if (m_type == UIMediumType_HardDisk)
    175     {
    176         m_strHardDiskFormat = m_medium.GetFormat();
    177         m_strHardDiskType = vboxGlobal().mediumTypeString(m_medium);
    178 
    179         QVector<KMediumVariant> mediumVariants = m_medium.GetVariant();
    180         qlonglong mediumVariant = 0;
    181         for (int i = 0; i < mediumVariants.size(); ++i)
    182             mediumVariant |= mediumVariants[i];
    183 
    184         m_strStorageDetails = gpConverter->toString((KMediumVariant)mediumVariant);
    185         m_fReadOnly = m_medium.GetReadOnly();
    186 
    187         /* Adjust parent/root IDs: */
    188         CMedium parentMedium = m_medium.GetParent();
    189         if (!parentMedium.isNull())
    190             m_strParentId = parentMedium.GetId();
    191         while (!parentMedium.isNull())
    192         {
    193             m_strRootId = parentMedium.GetId();
    194             parentMedium = parentMedium.GetParent();
    195         }
    196     }
    197     else
    198     {
    199         m_strHardDiskFormat = QString();
    200         m_strHardDiskType = QString();
    201         m_fReadOnly = false;
    202     }
    203 
    204     /* Detect sizes */
    205     if (m_state != KMediumState_Inaccessible && m_state != KMediumState_NotCreated && !m_fHostDrive)
    206     {
    207         m_strSize = vboxGlobal().formatSize(m_medium.GetSize());
     175    {
     176        /* Refresh medium ID: */
     177        m_strId = m_medium.GetId();
     178        /* Refresh root medium ID: */
     179        m_strRootId = m_strId;
     180
     181        /* Init medium key if necessary: */
     182        if (m_strKey.isNull())
     183            m_strKey = m_strId;
     184
     185        /* Check whether this is host-drive medium: */
     186        m_fHostDrive = m_medium.GetHostDrive();
     187
     188        /* Refresh medium name: */
     189        if (!m_fHostDrive)
     190            m_strName = m_medium.GetName();
     191        else if (m_medium.GetDescription().isEmpty())
     192            m_strName = VBoxGlobal::tr("Host Drive '%1'", "medium").arg(QDir::toNativeSeparators(m_medium.GetLocation()));
     193        else
     194            m_strName = VBoxGlobal::tr("Host Drive %1 (%2)", "medium").arg(m_medium.GetDescription(), m_medium.GetName());
     195        /* Refresh medium location: */
     196        if (!m_fHostDrive)
     197            m_strLocation = QDir::toNativeSeparators(m_medium.GetLocation());
     198
     199        /* Refresh medium size and logical size: */
     200        if (!m_fHostDrive)
     201        {
     202            /* Only for created and accessible mediums: */
     203            if (m_state != KMediumState_Inaccessible && m_state != KMediumState_NotCreated)
     204            {
     205                m_strSize = vboxGlobal().formatSize(m_medium.GetSize());
     206                if (m_type == UIMediumType_HardDisk)
     207                    m_strLogicalSize = vboxGlobal().formatSize(m_medium.GetLogicalSize());
     208                else
     209                    m_strLogicalSize = m_strSize;
     210            }
     211        }
     212
     213        /* For hard drive medium: */
    208214        if (m_type == UIMediumType_HardDisk)
    209             m_strLogicalSize = vboxGlobal().formatSize(m_medium.GetLogicalSize());
    210         else
    211             m_strLogicalSize = m_strSize;
    212     }
    213     else
    214     {
    215         m_strSize = m_strLogicalSize = QString("--");
    216     }
    217 
    218     /* Detect usage */
    219     m_strUsage = QString();
    220     if (!m_medium.isNull())
    221     {
     215        {
     216            /* Refresh hard drive disk type: */
     217            m_strHardDiskType = vboxGlobal().mediumTypeString(m_medium);
     218            /* Refresh hard drive format: */
     219            m_strHardDiskFormat = m_medium.GetFormat();
     220
     221            /* Refresh hard drive storage details: */
     222            qlonglong iMediumVariant = 0;
     223            foreach (const KMediumVariant &enmVariant, m_medium.GetVariant())
     224                iMediumVariant |= enmVariant;
     225            m_strStorageDetails = gpConverter->toString((KMediumVariant)iMediumVariant);
     226
     227            /* Check whether this is read-only hard drive: */
     228            m_fReadOnly = m_medium.GetReadOnly();
     229
     230            /* Refresh parent hard drive ID: */
     231            CMedium parentMedium = m_medium.GetParent();
     232            if (!parentMedium.isNull())
     233                m_strParentId = parentMedium.GetId();
     234
     235            /* Refresh hard drive ID: */
     236            while (!parentMedium.isNull())
     237            {
     238                m_strRootId = parentMedium.GetId();
     239                parentMedium = parentMedium.GetParent();
     240            }
     241        }
     242
     243        /* Check whether this is hidden medium: */
     244        QString strHints = m_medium.GetProperty("Special/GUI/Hints");
     245        if (!strHints.isEmpty())
     246        {
     247            QStringList hints(strHints.split(','));
     248            if (hints.contains("Hide", Qt::CaseInsensitive))
     249                m_fHidden = true;
     250        }
     251
     252        /* Refresh usage data: */
    222253        m_curStateMachineIds.clear();
    223254        m_machineIds = m_medium.GetMachineIds().toList();
    224255        if (m_machineIds.size() > 0)
    225256        {
    226             /* We assume this flag is 'true' if at least one machine present: */
    227             m_fAttachedToHiddenMachinesOnly = true;
    228 
    229             QString strUsage;
    230 
     257            /* Get CVirtualBox object: */
    231258            CVirtualBox vbox = vboxGlobal().virtualBox();
    232259
     260            /* By default we assuming that this medium is attached
     261             * to 'hidden' machines only, if at least one machine present: */
     262            m_fUsedByHiddenMachinesOnly = true;
     263
     264            /* Prepare machine usage: */
     265            QString strMachineUsage;
     266            /* Walk through all the machines this medium attached to: */
    233267            foreach (const QString &strMachineID, m_machineIds)
    234268            {
     269                /* Look for the corresponding machine: */
    235270                CMachine machine = vbox.FindMachine(strMachineID);
    236271
    237                 /* UIMedium object can wrap newly created CMedium object which belongs to
    238                  * not yet registered machine, like while creating VM clone.
    239                  * We can skip such a machines in usage string.
    240                  * CVirtualBox::FindMachine() will return null machine for such case. */
     272                /* UIMedium object can wrap newly created CMedium object
     273                 * which belongs to not yet registered machine, like while creating VM clone.
     274                 * We can skip such a machines in usage string. */
    241275                if (machine.isNull())
    242276                {
    243                     /* We can't decide for that medium yet,
    244                      * assume this flag is 'false' for now: */
    245                     m_fAttachedToHiddenMachinesOnly = false;
     277                    /* Since we can't precisely check 'hidden' status for that machine in such case,
     278                     * we have to assume that medium attached not only to 'hidden' machines: */
     279                    m_fUsedByHiddenMachinesOnly = false;
    246280                    continue;
    247281                }
    248282
    249                 /* Finally, we are checking if current machine overrides this flag: */
    250                 if (m_fAttachedToHiddenMachinesOnly && gEDataManager->showMachineInSelectorChooser(strMachineID))
    251                     m_fAttachedToHiddenMachinesOnly = false;
    252 
    253                 QString strName = machine.GetName();
    254                 QString strSnapshots;
    255 
     283                /* Finally we can precisely check if current machine is 'hidden': */
     284                if (gEDataManager->showMachineInSelectorChooser(strMachineID))
     285                    m_fUsedByHiddenMachinesOnly = false;
     286
     287                /* Prepare snapshot usage: */
     288                QString strSnapshotUsage;
     289                /* Walk through all the snapshots this medium attached to: */
    256290                foreach (const QString &strSnapshotID, m_medium.GetSnapshotIds(strMachineID))
    257291                {
     
    265299                    }
    266300
     301                    /* Look for the corresponding snapshot: */
    267302                    CSnapshot snapshot = machine.FindSnapshot(strSnapshotID);
    268                     if (!snapshot.isNull()) // can be NULL while takeSnaphot is in progress
    269                     {
    270                         if (!strSnapshots.isNull())
    271                             strSnapshots += ", ";
    272                         strSnapshots += snapshot.GetName();
    273                     }
     303
     304                    /* Snapshot can be NULL while takeSnaphot is in progress: */
     305                    if (snapshot.isNull())
     306                        continue;
     307
     308                    /* Refresh snapshot usage flag: */
     309                    m_fUsedInSnapshots = true;
     310
     311                    /* Append snapshot usage: */
     312                    if (!strSnapshotUsage.isNull())
     313                        strSnapshotUsage += ", ";
     314                    strSnapshotUsage += snapshot.GetName();
    274315                }
    275316
    276                 if (!strUsage.isNull())
    277                     strUsage += ", ";
    278 
    279                 strUsage += strName;
    280 
    281                 if (!strSnapshots.isNull())
    282                 {
    283                     strUsage += QString(" (%2)").arg(strSnapshots);
    284                     m_fUsedInSnapshots = true;
    285                 }
    286                 else
    287                     m_fUsedInSnapshots = false;
     317                /* Append machine usage: */
     318                if (!strMachineUsage.isNull())
     319                    strMachineUsage += ", ";
     320                strMachineUsage += machine.GetName();
     321
     322                /* Append snapshot usage: */
     323                if (!strSnapshotUsage.isNull())
     324                    strMachineUsage += QString(" (%2)").arg(strSnapshotUsage);
    288325            }
    289326
    290             if (!strUsage.isEmpty())
    291                 m_strUsage = strUsage;
    292         }
    293     }
    294 
    295     /* Compose the tooltip */
    296     if (!m_medium.isNull())
    297     {
     327            /* Append machine usage: */
     328            if (!strMachineUsage.isEmpty())
     329                m_strUsage += strMachineUsage;
     330        }
     331
     332        /* Refresh tool-tip: */
    298333        m_strToolTip = m_sstrRow.arg(QString("<p style=white-space:pre><b>%1</b></p>").arg(m_fHostDrive ? m_strName : m_strLocation));
    299 
    300334        if (m_type == UIMediumType_HardDisk)
    301335        {
     
    303337                                                         .arg(m_strHardDiskType).arg(m_strHardDiskFormat));
    304338        }
    305 
    306339        m_strToolTip += m_sstrRow.arg(VBoxGlobal::tr("<p>Attached to:  %1</p>", "image")
    307340                                                     .arg(m_strUsage.isNull() ? VBoxGlobal::tr("<i>Not Attached</i>", "image") : m_strUsage));
    308 
    309341        switch (m_state)
    310342        {
     
    318350                if (m_result.isOk())
    319351                {
    320                     /* Not Accessible */
     352                    /* Not Accessible: */
    321353                    m_strToolTip += m_sstrRow.arg("<hr>") + m_sstrRow.arg(VBoxGlobal::highlight(m_strLastAccessError, true /* aToolTip */));
    322354                }
     
    333365        }
    334366    }
    335 
    336     /* Reset m_noDiffs */
    337     m_noDiffs.isSet = false;
    338367}
    339368
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.h

    r55099 r55101  
    253253
    254254    /** Returns whether this medium is hidden.
    255       * @note The medium is considered hidden if it has corresponding
    256       *       medium property or is connected to hidden VMs only. */
    257     bool isHidden() const { return m_fHidden | m_fAttachedToHiddenMachinesOnly; }
     255      * @note The medium is considered 'hidden' if it has corresponding
     256      *       medium property or is connected to 'hidden' VMs only. */
     257    bool isHidden() const { return m_fHidden | m_fUsedByHiddenMachinesOnly; }
    258258
    259259    /** Returns whether this medium is read-only
     
    346346    NoDiffsCache m_noDiffs;
    347347
    348     /** Holds whether this medium is hidden by the corresponding medium property. */
    349     bool m_fHidden                       : 1;
    350     /** Holds whether this medium is hidden because it's connected to hidden VMs only. */
    351     bool m_fAttachedToHiddenMachinesOnly : 1;
     348    /** Holds whether this medium is 'hidden' by the corresponding medium property. */
     349    bool m_fHidden                   : 1;
     350    /** Holds whether this medium is 'hidden' because it's used by 'hidden' VMs only. */
     351    bool m_fUsedByHiddenMachinesOnly : 1;
    352352    /** Holds whether this medium is read-only. */
    353     bool m_fReadOnly                     : 1;
     353    bool m_fReadOnly                 : 1;
    354354    /** Holds whether this medium is attached to any VM in any snapshot. */
    355     bool m_fUsedInSnapshots              : 1;
     355    bool m_fUsedInSnapshots          : 1;
    356356    /** Holds whether this medium corresponds to real host drive. */
    357     bool m_fHostDrive                    : 1;
     357    bool m_fHostDrive                : 1;
    358358
    359359    /** Holds the NULL medium ID. */
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