• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • auth
  • backends
  • policykit
policykit/kauth-policy-gen-polkit.cpp
Go to the documentation of this file.
1/*
2* Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
3* Copyright (C) 2009-2010 Dario Freddi <drf@kde.org>
4*
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU Lesser General Public License as published by
7* the Free Software Foundation; either version 2.1 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU Lesser General Public License
16* along with this program; if not, write to the
17* Free Software Foundation, Inc.,
18* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
19*/
20
21#include <auth/policy-gen/policy-gen.h>
22
23#include <cstdio>
24#include <QDebug>
25#include <QTextStream>
26
27const char header[] = ""
28 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
29 "<!DOCTYPE policyconfig PUBLIC\n"
30 "\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n"
31 "\"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd\">\n"
32 "<policyconfig>\n";
33
34const char policy_tag[] = ""
35 " <defaults>\n"
36 " <allow_inactive>%1</allow_inactive>\n"
37 " <allow_active>%2</allow_active>\n"
38 " </defaults>\n";
39
40const char dent[] = " ";
41
42void output(QList<Action> actions, QHash<QString, QString> domain)
43{
44 QTextStream out(stdout);
45 out.setCodec("UTF-8");
46
47 out << header;
48
49 // Blacklisted characters + replacements
50 QHash< QChar, QString > blacklist;
51 blacklist.insert(QChar::fromLatin1('&'), QString::fromLatin1("&amp;"));
52
53 if (domain.contains(QLatin1String("vendor"))) {
54 QHash< QChar, QString >::const_iterator blI;
55 QString vendor = domain[QLatin1String("vendor")];
56 for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
57 vendor.replace(blI.key(), blI.value());
58 }
59 out << "<vendor>" << vendor << "</vendor>\n";
60 }
61 if (domain.contains(QLatin1String("vendorurl"))) {
62 out << "<vendor_url>" << domain[QLatin1String("vendorurl")] << "</vendor_url>\n";
63 }
64 if (domain.contains(QLatin1String("icon"))) {
65 out << "<icon_name>" << domain[QLatin1String("icon")] << "</icon_name>\n";
66 }
67
68 foreach (const Action &action, actions) {
69 out << dent << "<action id=\"" << action.name << "\" >\n";
70
71 for (QHash< QString, QString >::const_iterator i = action.messages.constBegin(); i != action.messages.constEnd(); ++i) {
72 out << dent << dent << "<description";
73 if (i.key() != QLatin1String("en")) {
74 out << " xml:lang=\"" << i.key() << '"';
75 }
76
77 QHash< QChar, QString >::const_iterator blI;
78 QString description = i.value();
79 for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
80 description.replace(blI.key(), blI.value());
81 }
82
83 out << '>' << description << "</description>\n";
84 }
85
86 for (QHash< QString, QString>::const_iterator i = action.descriptions.constBegin();
87 i != action.descriptions.constEnd();
88 ++i) {
89 out << dent << dent << "<message";
90 if (i.key() != QLatin1String("en")) {
91 out << " xml:lang=\"" << i.key() << '"';
92 }
93
94 QHash< QChar, QString >::const_iterator blI;
95 QString message = i.value();
96 for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
97 message.replace(blI.key(), blI.value());
98 }
99
100 out << '>' << message << "</message>\n";
101 }
102
103 QString policy = action.policy;
104 QString policyInactive = action.policyInactive.isEmpty() ? QLatin1String("no") : action.policyInactive;
105 if (!action.persistence.isEmpty() && policy != QLatin1String("yes") && policy != QLatin1String("no")) {
106 policy += QLatin1String("_keep_") + action.persistence;
107 }
108 if (!action.persistence.isEmpty() && policyInactive != QLatin1String("yes") &&
109 policyInactive != QLatin1String("no")) {
110 policyInactive += QLatin1String("_keep_") + action.persistence;
111 }
112
113 out << QString(QLatin1String(policy_tag)).arg(policyInactive).arg(policy);
114
115 out << dent << "</action>\n";
116 }
117
118 out << "</policyconfig>\n";
119}
QHash
Definition: ksycocafactory.h:28
QList
Definition: kaboutdata.h:33
QString
policy-gen.h
output
void output(QList< Action > actions, QHash< QString, QString > domain)
Definition: policykit/kauth-policy-gen-polkit.cpp:42
header
const char header[]
Definition: policykit/kauth-policy-gen-polkit.cpp:27
policy_tag
const char policy_tag[]
Definition: policykit/kauth-policy-gen-polkit.cpp:34
dent
const char dent[]
Definition: policykit/kauth-policy-gen-polkit.cpp:40
Action
Definition: policy-gen.h:28
Action::policyInactive
QString policyInactive
Definition: policy-gen.h:35
Action::name
QString name
Definition: policy-gen.h:29
Action::messages
QHash< QString, QString > messages
Definition: policy-gen.h:32
Action::policy
QString policy
Definition: policy-gen.h:34
Action::persistence
QString persistence
Definition: policy-gen.h:36
Action::descriptions
QHash< QString, QString > descriptions
Definition: policy-gen.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal