Changeset View
Changeset View
Standalone View
Standalone View
src/policy-gen/policy-gen.cpp
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 39 | { | |||
---|---|---|---|---|---|
66 | } | 66 | } | ||
67 | 67 | | |||
68 | output(parse(ini), parseDomain(ini)); | 68 | output(parse(ini), parseDomain(ini)); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | QList<Action> parse(QSettings &ini) | 71 | QList<Action> parse(QSettings &ini) | ||
72 | { | 72 | { | ||
73 | QList<Action> actions; | 73 | QList<Action> actions; | ||
74 | const QRegularExpression actionExp(QRegularExpression::anchoredPattern(QStringLiteral("[0-9a-z]+(\\.[0-9a-z]+)*"))); | | |||
75 | 74 | | |||
76 | const QRegularExpression descriptionExp(QRegularExpression::anchoredPattern(QStringLiteral("description(?:\\[(\\w+)\\])?")) | 75 | // example: [org.kde.kcontrol.kcmfoo.save] | ||
77 | , QRegularExpression::CaseInsensitiveOption); | 76 | const QRegularExpression actionExp(QRegularExpression::anchoredPattern(QStringLiteral("[0-9a-z]+(\\.[0-9a-z]+)*"))); | ||
78 | 77 | | |||
79 | const QRegularExpression nameExp(QRegularExpression::anchoredPattern(QStringLiteral("name(?:\\[(\\w+)\\])?")) | 78 | // example: Description[ca]=Mòdul de control del Foo. | ||
80 | , QRegularExpression::CaseInsensitiveOption); | 79 | const QRegularExpression descriptionExp(QRegularExpression::anchoredPattern(QStringLiteral("description(?:\\[(\\w+)\\])?")), | ||
80 | QRegularExpression::CaseInsensitiveOption); | ||||
81 | | ||||
82 | // example: Name[ca]=Mòdul de control del Foo | ||||
83 | const QRegularExpression nameExp(QRegularExpression::anchoredPattern(QStringLiteral("name(?:\\[(\\w+)\\])?")), | ||||
84 | QRegularExpression::CaseInsensitiveOption); | ||||
81 | 85 | | |||
86 | // example: Policy=auth_admin | ||||
82 | const QRegularExpression policyExp(QRegularExpression::anchoredPattern(QStringLiteral("(?:yes|no|auth_self|auth_admin)"))); | 87 | const QRegularExpression policyExp(QRegularExpression::anchoredPattern(QStringLiteral("(?:yes|no|auth_self|auth_admin)"))); | ||
83 | 88 | | |||
84 | const auto listChilds = ini.childGroups(); | 89 | const auto listChilds = ini.childGroups(); | ||
85 | for (const QString &name : listChilds) { | 90 | for (const QString &name : listChilds) { | ||
86 | Action action; | 91 | Action action; | ||
87 | 92 | | |||
88 | if (name == QLatin1String("Domain")) { | 93 | if (name == QLatin1String("Domain")) { | ||
89 | continue; | 94 | continue; | ||
90 | } | 95 | } | ||
91 | 96 | | |||
92 | if (!actionExp.match(name).hasMatch()) { | 97 | if (!actionExp.match(name).hasMatch()) { | ||
93 | qCritical("Wrong action syntax: %s\n", name.toLatin1().data()); | 98 | qCritical("Wrong action syntax: %s\n", name.toLatin1().data()); | ||
94 | exit(1); | 99 | exit(1); | ||
95 | } | 100 | } | ||
96 | 101 | | |||
97 | action.name = name; | 102 | action.name = name; | ||
98 | ini.beginGroup(name); | 103 | ini.beginGroup(name); | ||
99 | 104 | | |||
100 | const auto listChildKeys = ini.childKeys(); | 105 | const auto listChildKeys = ini.childKeys(); | ||
101 | for (const QString &key : listChildKeys) { | 106 | for (const QString &key : listChildKeys) { | ||
102 | QRegularExpressionMatch match; | 107 | QRegularExpressionMatch match; | ||
103 | if ((match = descriptionExp.match(key)).hasMatch()) { | 108 | if ((match = descriptionExp.match(key)).hasMatch()) { | ||
104 | QString lang = match.captured(); | 109 | QString lang = match.captured(1); | ||
105 | 110 | | |||
106 | if (lang.isEmpty()) { | 111 | if (lang.isEmpty()) { | ||
107 | lang = QString::fromLatin1("en"); | 112 | lang = QString::fromLatin1("en"); | ||
108 | } | 113 | } | ||
109 | 114 | | |||
110 | action.descriptions.insert(lang, ini.value(key).toString()); | 115 | action.descriptions.insert(lang, ini.value(key).toString()); | ||
111 | 116 | | |||
112 | } else if ((match = nameExp.match(key)).hasMatch()) { | 117 | } else if ((match = nameExp.match(key)).hasMatch()) { | ||
113 | QString lang = match.captured(); | 118 | QString lang = match.captured(1); | ||
114 | 119 | | |||
115 | if (lang.isEmpty()) { | 120 | if (lang.isEmpty()) { | ||
116 | lang = QString::fromLatin1("en"); | 121 | lang = QString::fromLatin1("en"); | ||
117 | } | 122 | } | ||
118 | 123 | | |||
119 | action.messages.insert(lang, ini.value(key).toString()); | 124 | action.messages.insert(lang, ini.value(key).toString()); | ||
120 | 125 | | |||
121 | } else if (key.toLower() == QLatin1String("policy")) { | 126 | } else if (key.toLower() == QLatin1String("policy")) { | ||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |