VirtualBox

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


Ignore:
Timestamp:
Apr 15, 2019 8:35:13 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
130016
Message:

FE/Qt: Make sure we always show the full media file location in the new medium wizard

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.cpp

    r76606 r78121  
    128128
    129129/* static */
    130 QString UIWizardNewVDPage3::absoluteFilePath(const QString &strFileName, const QString &strDefaultPath)
     130QString UIWizardNewVDPage3::absoluteFilePath(const QString &strFileName, const QString &strPath)
    131131{
    132132    /* Wrap file-info around received file name: */
     
    135135    if (fileInfo.fileName() == strFileName || fileInfo.isRelative())
    136136    {
    137         /* Resolve path on the basis of default path we have: */
    138         fileInfo = QFileInfo(strDefaultPath, strFileName);
     137        /* Resolve path on the basis of path we have: */
     138        fileInfo = QFileInfo(strPath, strFileName);
    139139    }
    140140    /* Return full absolute hard disk file path: */
    141141    return QDir::toNativeSeparators(fileInfo.absoluteFilePath());
     142}
     143
     144/*static */
     145QString UIWizardNewVDPage3::absoluteFilePath(const QString &strFileName, const QString &strPath, const QString &strExtension)
     146{
     147    QString strFilePath = absoluteFilePath(strFileName, strPath);
     148    if (QFileInfo(strFilePath).suffix().isEmpty())
     149        strFilePath += QString(".%1").arg(strExtension);
     150    return strFilePath;
    142151}
    143152
     
    267276    m_strDefaultExtension = defaultExtension(field("mediumFormat").value<CMediumFormat>());
    268277    /* Set default name as text for location editor: */
    269     m_pLocationEditor->setText(m_strDefaultName);
     278    m_pLocationEditor->setText(absoluteFilePath(m_strDefaultName, m_strDefaultPath, m_strDefaultExtension));
    270279}
    271280
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.h

    r76581 r78121  
    4646    /* Location-editors stuff: */
    4747    static QString toFileName(const QString &strName, const QString &strExtension);
    48     static QString absoluteFilePath(const QString &strFileName, const QString &strDefaultPath);
     48    /* Returns the full image file path except the extension. */
     49    static QString absoluteFilePath(const QString &strFileName, const QString &strPath);
     50    /* Returns the full image file path including the extension. */
     51    static QString absoluteFilePath(const QString &strFileName, const QString &strPath, const QString &strExtension);
    4952    static QString defaultExtension(const CMediumFormat &mediumFormatRef);
    5053
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.cpp

    r76606 r78121  
    1717
    1818/* Qt includes: */
     19#include <QDir>
    1920#include <QGridLayout>
    2021#include <QVBoxLayout>
     
    4748    : UIWizardNewVDPage3(strDefaultName, strDefaultPath)
    4849{
     50    /* Get default extension for new virtual-disk: */
    4951    /* Create widgets: */
    5052    QGridLayout *pMainLayout = new QGridLayout(this);
     
    5658            {
    5759                m_pLocationEditor = new QLineEdit(m_pLocationCnt);
    58                 {
    59                     m_pLocationEditor->setText(m_strDefaultName);
    60                 }
    6160                m_pLocationOpenButton = new QIToolButton(m_pLocationCnt);
    6261                {
     
    174173    registerField("mediumPath", this, "mediumPath");
    175174    registerField("mediumSize", this, "mediumSize");
     175
     176    /* Initialization of m_strDefaultExtension is done  here
     177       since first m_formats should be populated and fields should be registered: */
     178    m_strDefaultExtension = defaultExtension(mediumFormat());
     179    if (m_pLocationEditor)
     180        m_pLocationEditor->setText(absoluteFilePath(m_strDefaultName, m_strDefaultPath, m_strDefaultExtension));
    176181}
    177182
     
    202207    /* Compose virtual-disk extension: */
    203208    m_strDefaultExtension = defaultExtension(mf);
     209    /* Update m_pLocationEditor's text if necessary: */
     210    if (!m_pLocationEditor->text().isEmpty() && !m_strDefaultExtension.isEmpty())
     211    {
     212        QFileInfo fileInfo(m_pLocationEditor->text());
     213        if (fileInfo.completeSuffix() != m_strDefaultExtension)
     214        {
     215            QString strNewFilePath = QString("%1/%2.%3").arg(fileInfo.absoluteDir().absolutePath()).arg(fileInfo.baseName()).arg(m_strDefaultExtension);
     216            m_pLocationEditor->setText(strNewFilePath);
     217        }
     218    }
    204219
    205220    /* Broadcast complete-change: */
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