KAuth

kauth-policy-gen-polkit.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Nicola Gigante <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include <auth/policy-gen/policy-gen.h>
8 
9 #include <QDebug>
10 #include <QTextStream>
11 #include <cstdio>
12 
13 const char header[] =
14  ""
15  "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
16  "<!DOCTYPE policyconfig PUBLIC\n"
17  "\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n"
18  "\"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd\">\n"
19  "<policyconfig>\n";
20 
21 const char policy_tag[] =
22  ""
23  " <defaults>\n"
24  " <allow_inactive>no</allow_inactive>\n"
25  " <allow_active>%1</allow_active>\n"
26  " </defaults>\n";
27 
28 const char dent[] = " ";
29 
30 void output(const QList<Action> &actions, const QMap<QString, QString> &domain)
31 {
32  Q_UNUSED(domain)
33 
34  QTextStream out(stdout);
35 
36 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
37  out.setCodec("UTF-8");
38 #endif
39 
40  out << header;
41 
42  for (const Action &action : std::as_const(actions)) {
43  out << dent << "<action id=\"" << action.name << "\" >\n";
44 
45  const auto lstKeys = action.descriptions.keys();
46  for (const QString &lang : lstKeys) {
47  out << dent << dent << "<description";
48  if (lang != "en") {
49  out << " xml:lang=\"" << lang << '"';
50  }
51  out << '>' << action.messages.value(lang) << "</description>\n";
52  }
53 
54  const auto lstMessagesKeys = action.messages.keys();
55  for (const QString &lang : lstMessagesKeys) {
56  out << dent << dent << "<message";
57  if (lang != "en") {
58  out << " xml:lang=\"" << lang << '"';
59  }
60  out << '>' << action.descriptions.value(lang) << "</message>\n";
61  }
62 
63  QString policy = action.policy;
64  if (!action.persistence.isEmpty()) {
65  policy += "_keep_" + action.persistence;
66  }
67 
68  out << QString(policy_tag).arg(policy);
69 
70  out << dent << "</action>\n";
71  }
72 
73  out << "</policyconfig>\n";
74 }
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 6 2023 04:14:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.