diff options
author | saturneric <[email protected]> | 2024-01-12 06:02:37 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-12 06:02:37 +0000 |
commit | bf538056b24a68b8fd235b1c50991ee8eb46a776 (patch) | |
tree | e1bab54095b80df62b321fb5bd69453f9f951b05 /src/core/utils/FilesystemUtils.cpp | |
parent | feat: improve api and ui of keys import and export (diff) | |
download | GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.tar.gz GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.zip |
refactor: use QString instead of std::string and improve threading system
Diffstat (limited to 'src/core/utils/FilesystemUtils.cpp')
-rw-r--r-- | src/core/utils/FilesystemUtils.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/core/utils/FilesystemUtils.cpp b/src/core/utils/FilesystemUtils.cpp index 84c8caf4..0d878759 100644 --- a/src/core/utils/FilesystemUtils.cpp +++ b/src/core/utils/FilesystemUtils.cpp @@ -30,26 +30,26 @@ namespace GpgFrontend { -auto GetOnlyFileNameWithPath(const std::string &path) -> std::string { +auto GetOnlyFileNameWithPath(const QString &path) -> QString { // Create a path object from given string - std::filesystem::path path_obj(path); + std::filesystem::path path_obj(path.toStdString()); // Check if file name in the path object has extension if (path_obj.has_filename()) { // Fetch the extension from path object and return - return (path_obj.parent_path() / path_obj.stem()).u8string(); + return (path_obj.parent_path() / path_obj.stem()).c_str(); } // In case of no extension return empty string return {}; } -auto GetFileExtension(const std::string &path) -> std::string { +auto GetFileExtension(const QString &path) -> QString { // Create a path object from given string - std::filesystem::path path_obj(path); + std::filesystem::path path_obj(path.toStdString()); // Check if file name in the path object has extension if (path_obj.has_extension()) { // Fetch the extension from path object and return - return path_obj.extension().u8string(); + return path_obj.extension().c_str(); } // In case of no extension return empty string return {}; @@ -60,10 +60,10 @@ auto GetFileExtension(const std::string &path) -> std::string { * */ auto GetFileSizeByPath(const std::filesystem::path &path, - const std::string &filename_pattern) -> int64_t { + const QString &filename_pattern) -> int64_t { auto dir = QDir(QString::fromStdString(path.u8string())); - QFileInfoList file_list = dir.entryInfoList( - QStringList() << QString::fromStdString(filename_pattern), QDir::Files); + QFileInfoList const file_list = + dir.entryInfoList(QStringList() << filename_pattern, QDir::Files); qint64 total_size = 0; for (const QFileInfo &file_info : file_list) { @@ -76,7 +76,7 @@ auto GetFileSizeByPath(const std::filesystem::path &path, * @brief * */ -auto GetHumanFriendlyFileSize(int64_t size) -> std::string { +auto GetHumanFriendlyFileSize(int64_t size) -> QString { auto num = static_cast<double>(size); QStringList list; list << "KB" @@ -91,7 +91,7 @@ auto GetHumanFriendlyFileSize(int64_t size) -> std::string { unit = i.next(); num /= 1024.0; } - return (QString().setNum(num, 'f', 2) + " " + unit).toStdString(); + return (QString().setNum(num, 'f', 2) + " " + unit); } /** @@ -99,11 +99,11 @@ auto GetHumanFriendlyFileSize(int64_t size) -> std::string { * */ void DeleteAllFilesByPattern(const std::filesystem::path &path, - const std::string &filename_pattern) { + const QString &filename_pattern) { auto dir = QDir(QString::fromStdString(path.u8string())); - QStringList log_files = dir.entryList( - QStringList() << QString::fromStdString(filename_pattern), QDir::Files); + QStringList const log_files = + dir.entryList(QStringList() << filename_pattern, QDir::Files); for (const auto &file : log_files) { QFile::remove(dir.absoluteFilePath(file)); |