KDECore
kauth-policy-gen-polkit.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation; either version 2.1 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . 00018 */ 00019 00020 #include <auth/policy-gen/policy-gen.h> 00021 00022 #include <cstdio> 00023 #include <QDebug> 00024 #include <QTextStream> 00025 00026 const char header[] = "" 00027 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 00028 "<!DOCTYPE policyconfig PUBLIC\n" 00029 "\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n" 00030 "\"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd\">\n" 00031 "<policyconfig>\n"; 00032 00033 const char policy_tag[] = "" 00034 " <defaults>\n" 00035 " <allow_inactive>no</allow_inactive>\n" 00036 " <allow_active>%1</allow_active>\n" 00037 " </defaults>\n"; 00038 00039 const char dent[] = " "; 00040 00041 void output(QList<Action> actions, QHash<QString, QString> domain) 00042 { 00043 Q_UNUSED(domain) 00044 00045 QTextStream out(stdout); 00046 out.setCodec("UTF-8"); 00047 00048 out << header; 00049 00050 foreach(const Action &action, actions) { 00051 out << dent << "<action id=\"" << action.name << "\" >\n"; 00052 00053 foreach(const QString& lang, action.descriptions.keys()) { 00054 out << dent << dent << "<description"; 00055 if (lang != "en") 00056 out << " xml:lang=\"" << lang << '"'; 00057 out << '>' << action.messages.value(lang) << "</description>\n"; 00058 } 00059 00060 foreach(const QString& lang, action.messages.keys()) { 00061 out << dent << dent << "<message"; 00062 if (lang != "en") 00063 out << " xml:lang=\"" << lang << '"'; 00064 out << '>' << action.descriptions.value(lang) << "</message>\n"; 00065 } 00066 00067 QString policy = action.policy; 00068 if (!action.persistence.isEmpty()) 00069 policy += "_keep_" + action.persistence; 00070 00071 out << QString(policy_tag).arg(policy); 00072 00073 out << dent << "</action>\n"; 00074 } 00075 00076 out << "</policyconfig>\n"; 00077 }
KDE 4.6 API Reference