Commit fd8b7144 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to load all groups

parent d12d148b
Pipeline #51720 failed with stage
in 7 minutes and 48 seconds
......@@ -9,6 +9,7 @@
#include <KLocalizedString>
#include <QDebug>
#include <QDir>
#include <QStandardPaths>
......@@ -36,32 +37,33 @@ QString LoadGroupMenu::defaultWritableGroupPath()
QStringList LoadGroupMenu::defaultReadableGroupPath() const
{
return QStandardPaths::locateAll(QStandardPaths::AppLocalDataLocation, QLatin1String("/groups"), QStandardPaths::LocateFile);
return QStandardPaths::locateAll(QStandardPaths::AppLocalDataLocation, QLatin1String("/groups/"), QStandardPaths::LocateDirectory);
}
void LoadGroupMenu::init()
{
// Load all ?
mGroupNames.clear();
const QString groupPath = LoadGroupMenu::defaultWritableGroupPath();
const QStringList groupPath = defaultReadableGroupPath();
if (groupPath.isEmpty()) {
setEnabled(false);
return;
}
QDir dir(groupPath);
mGroupNames = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
if (mGroupNames.isEmpty()) {
for (const QString &dirName : groupPath) {
QDir dir(dirName);
mGroupNames = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
for (const QString &file : mGroupNames) {
QAction *act = addAction(file);
const QString fullPath = dirName + QLatin1Char('/') + file;
connect(act, &QAction::triggered, this, [this, fullPath] {
Q_EMIT loadGroupRequested(fullPath);
});
}
}
if (isEmpty()) {
setEnabled(false);
return;
}
setEnabled(true);
for (const QString &file : mGroupNames) {
QAction *act = addAction(file);
const QString fullPath = groupPath + QLatin1Char('/') + file;
connect(act, &QAction::triggered, this, [this, fullPath] {
Q_EMIT loadGroupRequested(fullPath);
});
}
addSeparator();
QAction *manageGroup = addAction(i18n("Manage Group"));
connect(manageGroup, &QAction::triggered, this, &LoadGroupMenu::manageGroupRequested);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment