KAuth

kauth-policy-gen-polkit.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Nicola Gigante <nicola.gigante@gmail.com>
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
13const 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
21const 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
28const char dent[] = " ";
29
30void output(const QList<Action> &actions, const QMap<QString, QString> &domain)
31{
32 Q_UNUSED(domain)
33
34 QTextStream out(stdout);
35 out << header;
36
37 for (const Action &action : std::as_const(actions)) {
38 out << dent << "<action id=\"" << action.name << "\" >\n";
39
40 const auto lstKeys = action.descriptions.keys();
41 for (const QString &lang : lstKeys) {
42 out << dent << dent << "<description";
43 if (lang != "en") {
44 out << " xml:lang=\"" << lang << '"';
45 }
46 out << '>' << action.messages.value(lang) << "</description>\n";
47 }
48
49 const auto lstMessagesKeys = action.messages.keys();
50 for (const QString &lang : lstMessagesKeys) {
51 out << dent << dent << "<message";
52 if (lang != "en") {
53 out << " xml:lang=\"" << lang << '"';
54 }
55 out << '>' << action.descriptions.value(lang) << "</message>\n";
56 }
57
58 QString policy = action.policy;
59 if (!action.persistence.isEmpty()) {
60 policy += "_keep_" + action.persistence;
61 }
62
63 out << QString(policy_tag).arg(policy);
64
65 out << dent << "</action>\n";
66 }
67
68 out << "</policyconfig>\n";
69}
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.