File indexing completed on 2024-05-05 16:05:15
0001 /* 0002 SPDX-FileCopyrightText: 2008 Nicola Gigante <nicola.gigante@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include <auth/policy-gen/policy-gen.h> 0008 0009 #include <QDebug> 0010 #include <QTextStream> 0011 #include <cstdio> 0012 0013 const char header[] = 0014 "" 0015 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 0016 "<!DOCTYPE policyconfig PUBLIC\n" 0017 "\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n" 0018 "\"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd\">\n" 0019 "<policyconfig>\n"; 0020 0021 const char policy_tag[] = 0022 "" 0023 " <defaults>\n" 0024 " <allow_inactive>no</allow_inactive>\n" 0025 " <allow_active>%1</allow_active>\n" 0026 " </defaults>\n"; 0027 0028 const char dent[] = " "; 0029 0030 void output(const QList<Action> &actions, const QMap<QString, QString> &domain) 0031 { 0032 Q_UNUSED(domain) 0033 0034 QTextStream out(stdout); 0035 0036 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0037 out.setCodec("UTF-8"); 0038 #endif 0039 0040 out << header; 0041 0042 for (const Action &action : std::as_const(actions)) { 0043 out << dent << "<action id=\"" << action.name << "\" >\n"; 0044 0045 const auto lstKeys = action.descriptions.keys(); 0046 for (const QString &lang : lstKeys) { 0047 out << dent << dent << "<description"; 0048 if (lang != "en") { 0049 out << " xml:lang=\"" << lang << '"'; 0050 } 0051 out << '>' << action.messages.value(lang) << "</description>\n"; 0052 } 0053 0054 const auto lstMessagesKeys = action.messages.keys(); 0055 for (const QString &lang : lstMessagesKeys) { 0056 out << dent << dent << "<message"; 0057 if (lang != "en") { 0058 out << " xml:lang=\"" << lang << '"'; 0059 } 0060 out << '>' << action.descriptions.value(lang) << "</message>\n"; 0061 } 0062 0063 QString policy = action.policy; 0064 if (!action.persistence.isEmpty()) { 0065 policy += "_keep_" + action.persistence; 0066 } 0067 0068 out << QString(policy_tag).arg(policy); 0069 0070 out << dent << "</action>\n"; 0071 } 0072 0073 out << "</policyconfig>\n"; 0074 }