qt/utils: support full path in get_dir_entries

This commit is contained in:
Megamouse 2023-08-21 22:18:58 +02:00
parent 16c8f8c9cd
commit f3b631fbb4
3 changed files with 7 additions and 15 deletions

View File

@ -753,22 +753,14 @@ bool main_window::InstallPackages(QStringList file_paths, bool from_boot)
gui_log.notice("PKG: Trying to install packages from dir: '%s'", file_path);
const QDir dir(file_path);
const auto dir_file_infos = dir.entryInfoList(QDir::Files);
const QStringList dir_file_paths = gui::utils::get_dir_entries(dir, {}, true);
if (dir_file_infos.empty())
if (dir_file_paths.empty())
{
gui_log.notice("PKG: Could not find any files in dir: '%s'", file_path);
return true;
}
const auto dir_file_infos_count = dir_file_infos.count();
QList<QString> dir_file_paths(dir_file_infos_count);
for (int i = 0; i < dir_file_infos_count; i++)
{
dir_file_paths[i] = dir_file_infos[i].absoluteFilePath();
}
return InstallPackages(dir_file_paths, from_boot);
}
@ -848,7 +840,7 @@ bool main_window::InstallPackages(QStringList file_paths, bool from_boot)
const auto install_filetype = [&installed_rap_and_edat_count, &file_paths](const std::string extension)
{
const QString pattern = QString(".*\\.%1").arg(QString::fromStdString(extension));
for (const auto& file : file_paths.filter(QRegularExpression(pattern, QRegularExpression::PatternOption::CaseInsensitiveOption)))
for (const QString& file : file_paths.filter(QRegularExpression(pattern, QRegularExpression::PatternOption::CaseInsensitiveOption)))
{
const QFileInfo file_info(file);
const std::string filename = sstr(file_info.fileName());

View File

@ -164,13 +164,13 @@ namespace gui
return icon;
}
QStringList get_dir_entries(const QDir& dir, const QStringList& name_filters)
QStringList get_dir_entries(const QDir& dir, const QStringList& name_filters, bool full_path)
{
QFileInfoList entries = dir.entryInfoList(name_filters, QDir::Files);
QStringList res;
for (const QFileInfo &entry : entries)
for (const QFileInfo& entry : entries)
{
res.append(entry.baseName());
res.append(full_path ? entry.absoluteFilePath() : entry.baseName());
}
return res;
}

View File

@ -63,7 +63,7 @@ namespace gui
QIcon get_colorized_icon(const QIcon& old_icon, const QColor& old_color, const std::map<QIcon::Mode, QColor>& new_colors, bool use_special_masks = false, bool colorize_all = false);
// Returns a list of all base names of files in dir whose complete file names contain one of the given name_filters
QStringList get_dir_entries(const QDir& dir, const QStringList& name_filters);
QStringList get_dir_entries(const QDir& dir, const QStringList& name_filters, bool full_path = false);
// Returns the color specified by its color_role for the QLabels with object_name
QColor get_label_color(const QString& object_name, QPalette::ColorRole color_role = QPalette::WindowText);