VirtualBox

Ignore:
Timestamp:
Jul 3, 2018 11:57:53 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: Move/rework fullMediumFormatName functionality out of VBoxGlobal to UIMediumDefs and UIConverter.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackend.h

    r71630 r72821  
    2828#include "UIDefs.h"
    2929#include "UILibraryDefs.h"
     30#include "UIMediumDefs.h"
    3031#include "UIExtraDataDefs.h"
    3132
     
    108109template<> SHARED_LIBRARY_STUFF bool canConvert<InformationElementType>();
    109110template<> SHARED_LIBRARY_STUFF bool canConvert<MaxGuestResolutionPolicy>();
     111template<> SHARED_LIBRARY_STUFF bool canConvert<UIMediumFormat>();
    110112
    111113
     
    212214template<> SHARED_LIBRARY_STUFF QString toInternalString(const MaxGuestResolutionPolicy &enmMaxGuestResolutionPolicy);
    213215template<> SHARED_LIBRARY_STUFF MaxGuestResolutionPolicy fromInternalString<MaxGuestResolutionPolicy>(const QString &strMaxGuestResolutionPolicy);
     216template<> SHARED_LIBRARY_STUFF QString toString(const UIMediumFormat &enmUIMediumFormat);
     217template<> SHARED_LIBRARY_STUFF QString toInternalString(const UIMediumFormat &enmUIMediumFormat);
     218template<> SHARED_LIBRARY_STUFF UIMediumFormat fromInternalString<UIMediumFormat>(const QString &strUIMediumFormat);
    214219
    215220
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackendGlobal.cpp

    r71427 r72821  
    7373template<> bool canConvert<InformationElementType>() { return true; }
    7474template<> bool canConvert<MaxGuestResolutionPolicy>() { return true; }
     75template<> bool canConvert<UIMediumFormat>() { return true; }
    7576
    7677
     
    18581859}
    18591860
     1861/* QString <= UIMediumFormat: */
     1862template<> QString toString(const UIMediumFormat &enmUIMediumFormat)
     1863{
     1864    QString strResult;
     1865    switch (enmUIMediumFormat)
     1866    {
     1867        case UIMediumFormat_VDI:       strResult = QApplication::translate("VBoxGlobal", "VDI (VirtualBox Disk Image)", "UIMediumFormat"); break;
     1868        case UIMediumFormat_VMDK:      strResult = QApplication::translate("VBoxGlobal", "VMDK (Virtual Machine Disk)", "UIMediumFormat"); break;
     1869        case UIMediumFormat_VHD:       strResult = QApplication::translate("VBoxGlobal", "VHD (Virtual Hard Disk)", "UIMediumFormat"); break;
     1870        case UIMediumFormat_Parallels: strResult = QApplication::translate("VBoxGlobal", "HDD (Parallels Hard Disk)", "UIMediumFormat"); break;
     1871        case UIMediumFormat_QED:       strResult = QApplication::translate("VBoxGlobal", "QED (QEMU enhanced disk)", "UIMediumFormat"); break;
     1872        case UIMediumFormat_QCOW:      strResult = QApplication::translate("VBoxGlobal", "QCOW (QEMU Copy-On-Write)", "UIMediumFormat"); break;
     1873        default:
     1874        {
     1875            AssertMsgFailed(("No text for medium format=%d", enmUIMediumFormat));
     1876            break;
     1877        }
     1878    }
     1879    return strResult;
     1880}
     1881
     1882/* QString <= UIMediumFormat: */
     1883template<> QString toInternalString(const UIMediumFormat &enmUIMediumFormat)
     1884{
     1885    QString strResult;
     1886    switch (enmUIMediumFormat)
     1887    {
     1888        case UIMediumFormat_VDI:       strResult = "VDI"; break;
     1889        case UIMediumFormat_VMDK:      strResult = "VMDK"; break;
     1890        case UIMediumFormat_VHD:       strResult = "VHD"; break;
     1891        case UIMediumFormat_Parallels: strResult = "Parallels"; break;
     1892        case UIMediumFormat_QED:       strResult = "QED"; break;
     1893        case UIMediumFormat_QCOW:      strResult = "QCOW"; break;
     1894        default:
     1895        {
     1896            AssertMsgFailed(("No text for medium format=%d", enmUIMediumFormat));
     1897            break;
     1898        }
     1899    }
     1900    return strResult;
     1901}
     1902
     1903/* UIMediumFormat <= QString: */
     1904template<> UIMediumFormat fromInternalString<UIMediumFormat>(const QString &strUIMediumFormat)
     1905{
     1906    /* Here we have some fancy stuff allowing us
     1907     * to search through the keys using 'case-insensitive' rule: */
     1908    QStringList keys;    QList<UIMediumFormat> values;
     1909    keys << "VDI";       values << UIMediumFormat_VDI;
     1910    keys << "VMDK";      values << UIMediumFormat_VMDK;
     1911    keys << "VHD";       values << UIMediumFormat_VHD;
     1912    keys << "Parallels"; values << UIMediumFormat_Parallels;
     1913    keys << "QED";       values << UIMediumFormat_QED;
     1914    keys << "QCOW";      values << UIMediumFormat_QCOW;
     1915    /* VDI format for unknown words: */
     1916    if (!keys.contains(strUIMediumFormat, Qt::CaseInsensitive))
     1917        return UIMediumFormat_VDI;
     1918    /* Corresponding format for known words: */
     1919    return values.at(keys.indexOf(QRegExp(strUIMediumFormat, Qt::CaseInsensitive)));
     1920}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r72692 r72821  
    10651065
    10661066/* static */
    1067 QString VBoxGlobal::fullMediumFormatName(const QString &strBaseMediumFormatName)
    1068 {
    1069     if (strBaseMediumFormatName == "VDI")
    1070         return tr("VDI (VirtualBox Disk Image)");
    1071     else if (strBaseMediumFormatName == "VMDK")
    1072         return tr("VMDK (Virtual Machine Disk)");
    1073     else if (strBaseMediumFormatName == "VHD")
    1074         return tr("VHD (Virtual Hard Disk)");
    1075     else if (strBaseMediumFormatName == "Parallels")
    1076         return tr("HDD (Parallels Hard Disk)");
    1077     else if (strBaseMediumFormatName == "QED")
    1078         return tr("QED (QEMU enhanced disk)");
    1079     else if (strBaseMediumFormatName == "QCOW")
    1080         return tr("QCOW (QEMU Copy-On-Write)");
    1081     return strBaseMediumFormatName;
    1082 }
    1083 
    1084 /* static */
    10851067QStringList VBoxGlobal::COMPortNames()
    10861068{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r72692 r72821  
    328328          * @param  cDecimal  Brings the number of decimal digits in result. */
    329329        static QString formatSize(quint64 uSize, uint cDecimal = 2, FormatSize enmMode = FormatSize_Round);
    330 
    331         /** Returns full medium-format name for the given @a strBaseMediumFormatName. */
    332         static QString fullMediumFormatName(const QString &strBaseMediumFormatName);
    333330
    334331        /** Returns the list of the standard COM port names (i.e. "COMx"). */
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.h

    r71630 r72821  
    3131#include <VBox/com/defs.h>
    3232
     33
     34/** Medium formats. */
     35enum UIMediumFormat
     36{
     37    UIMediumFormat_VDI,
     38    UIMediumFormat_VMDK,
     39    UIMediumFormat_VHD,
     40    UIMediumFormat_Parallels,
     41    UIMediumFormat_QED,
     42    UIMediumFormat_QCOW,
     43};
    3344
    3445/** UIMediumDefs namespace. */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVDPageBasic2.cpp

    r71027 r72821  
    2626
    2727/* GUI includes: */
     28# include "UIConverter.h"
    2829# include "UIWizardCloneVDPageBasic2.h"
    2930# include "UIWizardCloneVD.h"
     
    169170    {
    170171        QAbstractButton *pButton = buttons[i];
    171         pButton->setText(VBoxGlobal::fullMediumFormatName(m_formatNames[m_pFormatButtonGroup->id(pButton)]));
     172        UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(m_formatNames[m_pFormatButtonGroup->id(pButton)]);
     173        pButton->setText(gpConverter->toString(enmFormat));
    172174    }
    173175}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVDPageExpert.cpp

    r71948 r72821  
    3232/* GUI includes: */
    3333# include "QIToolButton.h"
     34# include "UIConverter.h"
    3435# include "UIIconPool.h"
    3536# include "UIMediaComboBox.h"
     
    265266    {
    266267        QAbstractButton *pButton = buttons[i];
    267         pButton->setText(VBoxGlobal::fullMediumFormatName(m_formatNames[m_pFormatButtonGroup->id(pButton)]));
     268        UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(m_formatNames[m_pFormatButtonGroup->id(pButton)]);
     269        pButton->setText(gpConverter->toString(enmFormat));
    268270    }
    269271    m_pVariantCnt->setTitle(UIWizardCloneVD::tr("Storage on physical hard disk"));
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic1.cpp

    r71027 r72821  
    2626
    2727/* GUI includes: */
     28# include "UIConverter.h"
    2829# include "UIWizardNewVDPageBasic1.h"
    2930# include "UIWizardNewVD.h"
     
    163164    {
    164165        QAbstractButton *pButton = buttons[i];
    165         pButton->setText(VBoxGlobal::fullMediumFormatName(m_formatNames[m_pFormatButtonGroup->id(pButton)]));
     166        UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(m_formatNames[m_pFormatButtonGroup->id(pButton)]);
     167        pButton->setText(gpConverter->toString(enmFormat));
    166168    }
    167169}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.cpp

    r71027 r72821  
    3333
    3434/* GUI includes: */
     35# include "UIConverter.h"
    3536# include "UIWizardNewVDPageExpert.h"
    3637# include "UIWizardNewVD.h"
     
    229230    {
    230231        QAbstractButton *pButton = buttons[i];
    231         pButton->setText(VBoxGlobal::fullMediumFormatName(m_formatNames[m_pFormatButtonGroup->id(pButton)]));
     232        UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(m_formatNames[m_pFormatButtonGroup->id(pButton)]);
     233        pButton->setText(gpConverter->toString(enmFormat));
    232234    }
    233235    m_pVariantCnt->setTitle(UIWizardNewVD::tr("Storage on physical hard disk"));
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