VirtualBox

Changeset 90937 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 27, 2021 8:40:18 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146575
Message:

FE/Qt: bugref:10067: UICommon: Reorder file-system stuff.

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

Legend:

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

    r90936 r90937  
    437437}
    438438
    439 /*static */
    440 QString UICommon::findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName)
    441 {
    442     QDir folder(strFullFolderPath);
    443     if (!folder.exists())
    444         return strBaseFileName;
    445     QFileInfoList folderContent = folder.entryInfoList();
    446     QSet<QString> fileNameSet;
    447     foreach (const QFileInfo &fileInfo, folderContent)
    448     {
    449         /* Remove the extension : */
    450         fileNameSet.insert(fileInfo.completeBaseName());
    451     }
    452     int iSuffix = 0;
    453     QString strNewName(strBaseFileName);
    454     while (fileNameSet.contains(strNewName))
    455     {
    456         strNewName = strBaseFileName + QString("_") + QString::number(++iSuffix);
    457     }
    458     return strNewName;
    459 }
    460 
    461 /* static */
    462 bool UICommon::hasAllowedExtension(const QString &strExt, const QStringList &extList)
    463 {
    464     for (int i = 0; i < extList.size(); ++i)
    465         if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
    466             return true;
    467     return false;
    468 }
    469 
    470439bool UICommon::processArgs()
    471440{
     
    14721441            return QDir::homePath();
    14731442    }
     1443}
     1444
     1445/* static */
     1446bool UICommon::hasAllowedExtension(const QString &strFileName, const QStringList &extensions)
     1447{
     1448    foreach (const QString &strExtension, extensions)
     1449        if (strFileName.endsWith(strExtension, Qt::CaseInsensitive))
     1450            return true;
     1451    return false;
     1452}
     1453
     1454/* static */
     1455QString UICommon::findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName)
     1456{
     1457    QDir folder(strFullFolderPath);
     1458    if (!folder.exists())
     1459        return strBaseFileName;
     1460    QFileInfoList folderContent = folder.entryInfoList();
     1461    QSet<QString> fileNameSet;
     1462    foreach (const QFileInfo &fileInfo, folderContent)
     1463    {
     1464        /* Remove the extension : */
     1465        fileNameSet.insert(fileInfo.completeBaseName());
     1466    }
     1467    int iSuffix = 0;
     1468    QString strNewName(strBaseFileName);
     1469    while (fileNameSet.contains(strNewName))
     1470    {
     1471        strNewName = strBaseFileName + QString("_") + QString::number(++iSuffix);
     1472    }
     1473    return strNewName;
    14741474}
    14751475
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r90936 r90937  
    213213        /** Returns value for certain branding @a strKey from custom.ini file. */
    214214        QString brandingGetKey(QString strKey);
    215         /** Returns a file name (unique up to extension) wrt. @a strFullFolderPath folder content. Starts
    216           * searching strBaseFileName and adds suffixes until a unique file name is found. */
    217         static QString findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName);
    218215    /** @} */
    219216
    220217    /** @name Process arguments stuff.
    221218     * @{ */
    222         /** Returns whether passed @a strExt ends with one of allowed extension in the @a extList. */
    223         static bool hasAllowedExtension(const QString &strExt, const QStringList &extList);
    224 
    225219        /** Process application args. */
    226220        bool processArgs();
     
    403397        /** Returns documents path. */
    404398        static QString documentsPath();
     399
     400        /** Returns whether passed @a strFileName ends with one of allowed extension in the @a extensions list. */
     401        static bool hasAllowedExtension(const QString &strFileName, const QStringList &extensions);
     402
     403        /** Returns a file name (unique up to extension) wrt. @a strFullFolderPath folder content. Starts
     404          * searching strBaseFileName and adds suffixes until a unique file name is found. */
     405        static QString findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName);
    405406    /** @} */
    406407
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