aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-02 13:24:45 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-02 13:24:45 +0200
commit76e346c8e5ac7067cc49063e0c11d88c23871115 (patch)
treed0bf22a28330a2feb675b7d68011f22a4473bdfd /src/util.cpp
parentSplit off UrlFilter into library (diff)
downloadsmolbote-76e346c8e5ac7067cc49063e0c11d88c23871115.tar.xz
Add Util namespace
- Util::files lists files in specified .path
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
new file mode 100644
index 0000000..5b1478b
--- /dev/null
+++ b/src/util.cpp
@@ -0,0 +1,45 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "util.h"
+#include <QDir>
+#include <QFileInfo>
+
+#define ListSeparator QLatin1Literal(";")
+
+QStringList Util::files(const QString &location, const QStringList &nameFilters)
+{
+ if(location.isEmpty())
+ return QStringList();
+
+ QStringList filelist;
+
+ // check if location is a list of locations (contains a ';')
+ if(location.contains(ListSeparator)) {
+ const QStringList locations = location.split(ListSeparator);
+
+ for(const QString &l : locations) {
+ filelist.append(Util::files(l, nameFilters));
+ }
+
+ return filelist;
+ }
+
+ const QFileInfo info(location);
+
+ // check if location is a folder
+ if(info.isDir()) {
+ for(const QFileInfo &entryInfo : QDir(info.absoluteFilePath()).entryInfoList(nameFilters, QDir::Files | QDir::Readable, QDir::Time)) {
+ filelist.append(entryInfo.absoluteFilePath());
+ }
+ } else if(info.isFile()) {
+ filelist.append(info.absoluteFilePath());
+ }
+
+ return filelist;
+} \ No newline at end of file