diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-05-20 11:03:11 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-05 14:44:25 +0200 |
commit | 4fb2f4dcfb2d4dfaa3d0028ea8cd08aec7225a1f (patch) | |
tree | 8c306bd29fd037def229fdcfa10cd46904a36dce /options/globals.cpp | |
parent | 7c5b8125bd24800b890b96594672b075d4d29b83 (diff) |
options: cache the profile list
Diffstat (limited to 'options/globals.cpp')
-rw-r--r-- | options/globals.cpp | 21 |
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; } |