diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -63,3 +63,11 @@
TEST_NAME KAuthHelperTest
LINK_LIBRARIES Qt5::Test kauth_tests_static
)
+
+########### test kauth-policy-gen ###############
+add_test(NAME KAuthPolicyGenTest
+ COMMAND kauth-policy-gen ${CMAKE_SOURCE_DIR}/autotests/foo_actions.actions
+ ${CMAKE_BINARY_DIR}/generated-foo.policy)
+add_test(KAuthPolicyGenTestCompare ${CMAKE_COMMAND} -E compare_files
+ ${CMAKE_BINARY_DIR}/generated-foo.policy ${CMAKE_SOURCE_DIR}/autotests/foo.policy)
+
diff --git a/autotests/foo.policy b/autotests/foo.policy
new file mode 100644
--- /dev/null
+++ b/autotests/foo.policy
@@ -0,0 +1,22 @@
+
+
+
+Foo Control Module
+preferences-desktop-display
+
+ Desa el tema del Foo
+ Save the Foo Theme
+ Save the Foo Theme
+ 保存 Foo 主题
+ Les polítiques del sistema impedeixen que apliqueu el tema del Foo.
+ System policies prevent you from applying the Foo theme.
+ System policies prevent you from applying the Foo theme.
+ 系统策略阻止您应用 Foo 主题。
+
+ no
+ auth_admin
+
+
+
diff --git a/autotests/foo_actions.actions b/autotests/foo_actions.actions
new file mode 100644
--- /dev/null
+++ b/autotests/foo_actions.actions
@@ -0,0 +1,23 @@
+[Domain]
+Name=Foo Control Module
+Name[ca]=Mòdul de control del Foo
+Name[ca@valencia]=Mòdul de control del Foo
+Name[en_GB]=Foo Control Module
+Name[x-test]=xxFoo Control Modulexx
+Name[zh_CN]=Foo 控制模块
+Icon=preferences-desktop-display
+
+[org.kde.kcontrol.kcmplymouth.save]
+Name=Save the Foo Theme
+Name[ca]=Desa el tema del Foo
+Name[ca@valencia]=Guarda el tema de Foo
+Name[en_GB]=Save the Foo Theme
+Name[x-test]=xxSave the Foo Themexx
+Name[zh_CN]=保存 Foo 主题
+Description=System policies prevent you from applying the Foo theme.
+Description[ca]=Les polítiques del sistema impedeixen que apliqueu el tema del Foo.
+Description[ca@valencia]=Les polítiques del sistema impedeixen que apliqueu el tema de Foo.
+Description[en_GB]=System policies prevent you from applying the Foo theme.
+Description[x-test]=xxSystem policies prevent you from applying the Foo theme.xx
+Description[zh_CN]=系统策略阻止您应用 Foo 主题。
+Policy=auth_admin
diff --git a/src/policy-gen/policy-gen.cpp b/src/policy-gen/policy-gen.cpp
--- a/src/policy-gen/policy-gen.cpp
+++ b/src/policy-gen/policy-gen.cpp
@@ -71,14 +71,19 @@
QList parse(QSettings &ini)
{
QList actions;
+
+ // example: [org.kde.kcontrol.kcmfoo.save]
const QRegularExpression actionExp(QRegularExpression::anchoredPattern(QStringLiteral("[0-9a-z]+(\\.[0-9a-z]+)*")));
- const QRegularExpression descriptionExp(QRegularExpression::anchoredPattern(QStringLiteral("description(?:\\[(\\w+)\\])?"))
- , QRegularExpression::CaseInsensitiveOption);
+ // example: Description[ca]=Mòdul de control del Foo.
+ const QRegularExpression descriptionExp(QRegularExpression::anchoredPattern(QStringLiteral("description(?:\\[(\\w+)\\])?")),
+ QRegularExpression::CaseInsensitiveOption);
- const QRegularExpression nameExp(QRegularExpression::anchoredPattern(QStringLiteral("name(?:\\[(\\w+)\\])?"))
- , QRegularExpression::CaseInsensitiveOption);
+ // example: Name[ca]=Mòdul de control del Foo
+ const QRegularExpression nameExp(QRegularExpression::anchoredPattern(QStringLiteral("name(?:\\[(\\w+)\\])?")),
+ QRegularExpression::CaseInsensitiveOption);
+ // example: Policy=auth_admin
const QRegularExpression policyExp(QRegularExpression::anchoredPattern(QStringLiteral("(?:yes|no|auth_self|auth_admin)")));
const auto listChilds = ini.childGroups();
@@ -101,16 +106,16 @@
for (const QString &key : listChildKeys) {
QRegularExpressionMatch match;
if ((match = descriptionExp.match(key)).hasMatch()) {
- QString lang = match.captured();
+ QString lang = match.captured(1);
if (lang.isEmpty()) {
lang = QString::fromLatin1("en");
}
action.descriptions.insert(lang, ini.value(key).toString());
} else if ((match = nameExp.match(key)).hasMatch()) {
- QString lang = match.captured();
+ QString lang = match.captured(1);
if (lang.isEmpty()) {
lang = QString::fromLatin1("en");