VirtualBox

Changeset 77238 in vbox


Ignore:
Timestamp:
Feb 10, 2019 1:48:07 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128745
Message:

FE/Qt: bugref:9340. Trying make hdd and floppy disk names unique in creation dialogs.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r77217 r77238  
    431431    QSettings settings(m_strBrandingConfigFilePath, QSettings::IniFormat);
    432432    return settings.value(QString("%1").arg(strKey)).toString();
     433}
     434
     435/*static */
     436QString VBoxGlobal::findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName)
     437{
     438    QDir folder(strFullFolderPath);
     439    if (!folder.exists())
     440        return strBaseFileName;
     441    QFileInfoList folderContent = folder.entryInfoList();
     442    QSet<QString> fileNameSet;
     443    foreach (const QFileInfo &fileInfo, folderContent)
     444    {
     445        /* Remove the extension : */
     446        fileNameSet.insert(fileInfo.baseName());
     447    }
     448    int iSuffix = 0;
     449    QString strNewName(strBaseFileName);
     450    while (fileNameSet.contains(strNewName))
     451    {
     452        strNewName = strBaseFileName + QString("_") + QString::number(++iSuffix);
     453    }
     454    return strNewName;
    433455}
    434456
     
    27932815
    27942816QUuid VBoxGlobal::createHDWithNewHDWizard(QWidget *pParent, const QString &strMachineGuestOSTypeId,
     2817                                          const QString &strMachineName,
    27952818                                          const QString &strMachineFolder)
    27962819{
    27972820    /* Initialize variables: */
    27982821    const CGuestOSType comGuestOSType = virtualBox().GetGuestOSType(strMachineGuestOSTypeId);
    2799     const QFileInfo fileInfo(strMachineFolder);
     2822    QString strDiskName = findUniqueFileName(strMachineFolder, strMachineName);
    28002823    /* Show New VD wizard: */
    2801     UISafePointerWizardNewVD pWizard = new UIWizardNewVD(pParent, QString(), fileInfo.absolutePath(), comGuestOSType.GetRecommendedHDD());
     2824    UISafePointerWizardNewVD pWizard = new UIWizardNewVD(pParent, strDiskName, strMachineFolder, comGuestOSType.GetRecommendedHDD());
    28022825
    28032826    if (!pWizard)
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r77217 r77238  
    185185        /** Returns value for certain branding @a strKey from custom.ini file. */
    186186        QString brandingGetKey(QString strKey);
     187        /** Returns a file name (unique up to extension) wrt. @a strFullFolderPath folder content. Starts
     188          * searching strBaseFileName and adds suffixes until a unique file name is found. */
     189        static QString findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName);
    187190    /** @} */
    188191
     
    528531          * @param  parent                    Passes the parent of the wizard,
    529532          * @param  strMachineGuestOSTypeId   Passes the string of machine's guest OS type ID,
     533          * @param  strMachineName            Passes the name of the machine,
    530534          * @param  strMachineFolder          Passes the machine folder,
    531535          * returns the ID of the  created hard disk if successful, a null QUuid otherwise.*/
    532         QUuid createHDWithNewHDWizard(QWidget *pParent, const QString &strMachineGuestOSTypeId, const QString &strMachineFolder);
     536        QUuid createHDWithNewHDWizard(QWidget *pParent, const QString &strMachineGuestOSTypeId,
     537                                      const QString &strMachineName, const QString &strMachineFolder);
    533538
    534539        /** Prepares storage menu according passed parameters.
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.cpp

    r77216 r77238  
    163163        return strInitialPath;
    164164
    165     strInitialPath = QDir(strInitialPath).absoluteFilePath(m_strMachineName + "." + strPreferredExtension);
     165    QString strDiskname = VBoxGlobal::findUniqueFileName(m_strMachineFolder, m_strMachineName);
     166
     167    strInitialPath = QDir(strInitialPath).absoluteFilePath(strDiskname + "." + strPreferredExtension);
    166168    return strInitialPath;
    167169}
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp

    r77217 r77238  
    449449        uMediumId = vboxGlobal().showCreateFloppyDiskDialog(this, m_strMachineName, m_strMachineFolder);
    450450    else if (m_enmMediumType == UIMediumDeviceType_HardDisk)
    451         uMediumId = vboxGlobal().createHDWithNewHDWizard(this, m_strMachineGuestOSTypeId, m_strMachineFolder);
     451        uMediumId = vboxGlobal().createHDWithNewHDWizard(this, m_strMachineGuestOSTypeId, m_strMachineName, m_strMachineFolder);
    452452    else if (m_enmMediumType == UIMediumDeviceType_DVD)
    453453        uMediumId = vboxGlobal().createVisoMediumWithVisoCreator(this, m_strMachineName, m_strMachineFolder);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp

    r77217 r77238  
    30823082void UIMachineSettingsStorage::sltCreateNewHardDisk()
    30833083{
    3084     const QUuid uMediumId = vboxGlobal().createHDWithNewHDWizard(this, m_strMachineGuestOSTypeId, m_strMachineSettingsFilePath);
     3084    const QUuid uMediumId = vboxGlobal().createHDWithNewHDWizard(this, m_strMachineGuestOSTypeId,
     3085                                                                 m_strMachineName, m_strMachineSettingsFilePath);
    30853086
    30863087    if (!uMediumId.isNull())
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