summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-05-20 11:03:11 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-05-20 12:24:40 +0200
commit187d8614dd103637680d482fd7fc61f62d97d8f6 (patch)
tree9dc87a4eedab022d49b500299c851937496ec318 /options
parent65b582c01150dce7971b14c8535a80a140012e39 (diff)
options: cache the profile list
Diffstat (limited to 'options')
-rw-r--r--options/globals.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/options/globals.cpp b/options/globals.cpp
index 386ef56d..963cab90 100644
--- a/options/globals.cpp
+++ b/options/globals.cpp
@@ -3,8 +3,10 @@
#include "defs.hpp"
#include <QFile>
+#include <QFileInfo>
#include <QDir>
#include <QStandardPaths>
+#include <QDateTime>
#include <QDebug>
namespace options::globals::detail {
@@ -124,9 +126,24 @@ QString ini_combine(const QString& filename)
QStringList ini_list()
{
- QDir settings_dir(ini_directory());
+ static QMutex mtx;
+ static QStringList list;
+ QMutexLocker l{&mtx};
+
+ const QString dirname = ini_directory();
+
+ {
+ static QDateTime last_time = {};
+ auto time = QFileInfo{dirname}.lastModified();
+ if (time == last_time)
+ return list;
+ last_time = time;
+ }
+
+ QDir settings_dir(dirname);
+
using f = QDir::Filter;
- auto list = settings_dir.entryList({ QStringLiteral("*.ini") }, f::Files | f::Readable, QDir::Name);
+ list = settings_dir.entryList({ QStringLiteral("*.ini") }, f::Files | f::Readable, QDir::Name);
std::sort(list.begin(), list.end());
return list;
}