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

KDECore

kauth-policy-gen-polkit1.cpp

Go to the documentation of this file.
00001 /*
00002 *   Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
00003 *   Copyright (C) 2009-2010 Dario Freddi <drf@kde.org>
00004 *
00005 *   This program is free software; you can redistribute it and/or modify
00006 *   it under the terms of the GNU Lesser General Public License as published by
00007 *   the Free Software Foundation; either version 2.1 of the License, or
00008 *   (at your option) any later version.
00009 *
00010 *   This program is distributed in the hope that it will be useful,
00011 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 *   GNU General Public License for more details.
00014 *
00015 *   You should have received a copy of the GNU Lesser General Public License
00016 *   along with this program; if not, write to the
00017 *   Free Software Foundation, Inc.,
00018 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .
00019 */
00020 
00021 #include <auth/policy-gen/policy-gen.h>
00022 
00023 #include <cstdio>
00024 #include <QDebug>
00025 #include <QTextStream>
00026 
00027 const char header[] = ""
00028                       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
00029                       "<!DOCTYPE policyconfig PUBLIC\n"
00030                       "\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n"
00031                       "\"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd\">\n"
00032                       "<policyconfig>\n";
00033 
00034 const char policy_tag[] = ""
00035                           "      <defaults>\n"
00036                           "         <allow_inactive>no</allow_inactive>\n"
00037                           "         <allow_active>%1</allow_active>\n"
00038                           "      </defaults>\n";
00039 
00040 const char dent[] = "   ";
00041 
00042 void output(QList<Action> actions, QHash<QString, QString> domain)
00043 {
00044     QTextStream out(stdout);
00045     out.setCodec("UTF-8");
00046 
00047     out << header;
00048 
00049     // Blacklisted characters + replacements
00050     QHash< QChar, QString > blacklist;
00051     blacklist.insert(QLatin1Char('&'), QLatin1String("&amp;"));
00052 
00053     if (domain.contains(QLatin1String("vendor"))) {
00054         QHash< QChar, QString >::const_iterator blI;
00055         QString vendor = domain[QLatin1String("vendor")];
00056         for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
00057             vendor.replace(blI.key(), blI.value());
00058         }
00059         out << "<vendor>" << vendor << "</vendor>\n";
00060     }
00061     if (domain.contains(QLatin1String("vendorurl"))) {
00062         out << "<vendor_url>" << domain[QLatin1String("vendorurl")] << "</vendor_url>\n";
00063     }
00064     if (domain.contains(QLatin1String("icon"))) {
00065         out << "<icon_name>" << domain[QLatin1String("icon")] << "</icon_name>\n";
00066     }
00067 
00068     foreach (const Action &action, actions) {
00069         out << dent << "<action id=\"" << action.name << "\" >\n";
00070 
00071         // Not a typo, messages and descriptions are actually inverted
00072         for (QHash< QString, QString >::const_iterator i = action.messages.constBegin(); i != action.messages.constEnd(); ++i) {
00073             out << dent << dent << "<description";
00074             if (i.key() != QLatin1String("en")) {
00075                 out << " xml:lang=\"" << i.key() << '"';
00076             }
00077 
00078             QHash< QChar, QString >::const_iterator blI;
00079             QString description = i.value();
00080             for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
00081                 description.replace(blI.key(), blI.value());
00082             }
00083 
00084             out << '>' << description << "</description>\n";
00085         }
00086 
00087             QHash< QString, QString >::const_iterator i;
00088         for (QHash< QString, QString >::const_iterator i = action.descriptions.constBegin();
00089              i != action.descriptions.constEnd();
00090              ++i) {
00091             out << dent << dent << "<message";
00092             if (i.key() != QLatin1String("en")) {
00093                 out << " xml:lang=\"" << i.key() << '"';
00094             }
00095 
00096             QHash< QChar, QString >::const_iterator blI;
00097             QString message = i.value();
00098             for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
00099                 message.replace(blI.key(), blI.value());
00100             }
00101 
00102             out << '>' << message << "</message>\n";
00103         }
00104 
00105         QString policy = action.policy;
00106         if (!action.persistence.isEmpty() && policy != QLatin1String("yes") && policy !=
00107                 QLatin1String("no")) {
00108             policy += QLatin1String("_keep");
00109         }
00110 
00111         out << QString(QLatin1String(policy_tag)).arg(policy);
00112 
00113         out << dent << "</action>\n";
00114     }
00115 
00116     out << "</policyconfig>\n";
00117 }

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal