Changeset 90937 in vbox for trunk/src/VBox
- Timestamp:
- Aug 27, 2021 8:40:18 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 146575
- 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 437 437 } 438 438 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 470 439 bool UICommon::processArgs() 471 440 { … … 1472 1441 return QDir::homePath(); 1473 1442 } 1443 } 1444 1445 /* static */ 1446 bool 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 */ 1455 QString 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; 1474 1474 } 1475 1475 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h
r90936 r90937 213 213 /** Returns value for certain branding @a strKey from custom.ini file. */ 214 214 QString brandingGetKey(QString strKey); 215 /** Returns a file name (unique up to extension) wrt. @a strFullFolderPath folder content. Starts216 * searching strBaseFileName and adds suffixes until a unique file name is found. */217 static QString findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName);218 215 /** @} */ 219 216 220 217 /** @name Process arguments stuff. 221 218 * @{ */ 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 225 219 /** Process application args. */ 226 220 bool processArgs(); … … 403 397 /** Returns documents path. */ 404 398 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); 405 406 /** @} */ 406 407
Note:
See TracChangeset
for help on using the changeset viewer.