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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • 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 
27 const 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 
34 const char policy_tag[] = ""
35  " <defaults>\n"
36  " <allow_inactive>%1</allow_inactive>\n"
37  " <allow_active>%2</allow_active>\n"
38  " </defaults>\n";
39 
40 const char dent[] = " ";
41 
42 void 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 }
QTextStream::setCodec
void setCodec(QTextCodec *codec)
KMessage::message
void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
Display a long message of a certain type.
Definition: kmessage.cpp:92
Action::name
QString name
Definition: policy-gen.h:29
QHash::insert
iterator insert(const Key &key, const T &value)
policy_tag
const char policy_tag[]
Definition: policykit/kauth-policy-gen-polkit.cpp:34
QTextStream
QHash::constEnd
const_iterator constEnd() const
QHash< QString, QString >
policy-gen.h
QChar::fromLatin1
QChar fromLatin1(char c)
QString
QList
Definition: kaboutdata.h:33
Action
Definition: policy-gen.h:28
dent
const char dent[]
Definition: policykit/kauth-policy-gen-polkit.cpp:40
header
const char header[]
Definition: policykit/kauth-policy-gen-polkit.cpp:27
QHash::const_iterator
QString::replace
QString & replace(int position, int n, QChar after)
QHash::constBegin
const_iterator constBegin() const
QLatin1String
output
void output(QList< Action > actions, QHash< QString, QString > domain)
Definition: policykit/kauth-policy-gen-polkit.cpp:42
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QHash::contains
bool contains(const Key &key) const
Action::messages
QHash< QString, QString > messages
Definition: policy-gen.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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