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

Plasma

authorizationrule.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library 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 GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00017  * Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include "authorizationrule.h"
00021 
00022 #include "authorizationmanager.h"
00023 #include "credentials.h"
00024 #include "private/authorizationmanager_p.h"
00025 #include "private/authorizationrule_p.h"
00026 
00027 #include <QtCore/QObject>
00028 #include <QtCore/QTimer>
00029 
00030 #include <kurl.h>
00031 #include <klocalizedstring.h>
00032 
00033 namespace Plasma
00034 {
00035 
00036 AuthorizationRulePrivate::AuthorizationRulePrivate(const QString &serviceName, const QString &credentialID,
00037                                                    AuthorizationRule *rule)
00038     : q(rule),
00039       serviceName(serviceName),
00040       credentialID(credentialID),
00041       policy(AuthorizationRule::Deny),
00042       targets(AuthorizationRule::Default),
00043       persistence(AuthorizationRule::Transient)
00044 {
00045 }
00046 
00047 AuthorizationRulePrivate::~AuthorizationRulePrivate()
00048 {
00049 }
00050 
00051 bool AuthorizationRulePrivate::matches(const QString &name, const QString &id) const
00052 {
00053     if (serviceName == name && (credentialID == id)) {
00054         return true;
00055     }
00056 
00057     if (targets.testFlag(AuthorizationRule::AllUsers) && (serviceName == name)) {
00058         return true;
00059     }
00060 
00061     if (targets.testFlag(AuthorizationRule::AllServices) && (credentialID == id)) {
00062         return true;
00063     }
00064 
00065     return false;
00066 }
00067 
00068 void AuthorizationRulePrivate::scheduleChangedSignal()
00069 {
00070     QTimer::singleShot(0, q, SLOT(fireChangedSignal()));
00071 }
00072 
00073 void AuthorizationRulePrivate::fireChangedSignal()
00074 {
00075     if ((persistence == AuthorizationRule::Persistent) &&
00076         (policy != AuthorizationRule::PinRequired)) {
00077         AuthorizationManager::self()->d->saveRules();
00078     }
00079 
00080     emit q->changed(q);
00081 }
00082 
00083 AuthorizationRule::AuthorizationRule(const QString &serviceName, const QString &credentialID)
00084     : QObject(AuthorizationManager::self()),
00085       d(new AuthorizationRulePrivate(serviceName, credentialID, this))
00086 {
00087 }
00088 
00089 AuthorizationRule::~AuthorizationRule()
00090 {
00091     delete d;
00092 }
00093 
00094 QString AuthorizationRule::description() const
00095 {
00096     //i18n megafest :p
00097     if (d->targets.testFlag(AllUsers) && d->policy == Allow) {
00098         return i18n("Allow everybody access to %1.", d->serviceName);
00099     } else if (d->targets.testFlag(AllUsers) && d->policy == Deny) {
00100         return i18n("Deny everybody access to %1", d->serviceName);
00101     } else if (d->targets.testFlag(AllServices) && d->policy == Allow) {
00102         return i18n("Allow %1 access to all services.", credentials().name());
00103     } else if (d->targets.testFlag(AllServices) && d->policy == Deny) {
00104         return i18n("Deny %1 access to all services.", credentials().name());
00105     } else if (d->policy == Allow) {
00106         return i18n("Allow access to %1, by %2.", d->serviceName, credentials().name());
00107     } else if (d->policy == Deny) {
00108         return i18n("Deny access to %1, by %2.", d->serviceName, credentials().name());
00109     } else {
00110         return i18n("Allow access to %1, by %2?", d->serviceName, credentials().name());
00111     }
00112 }
00113 
00114 
00115 void AuthorizationRule::setPolicy(Policy policy)
00116 {
00117     d->policy = policy;
00118     d->scheduleChangedSignal();
00119 }
00120 
00121 AuthorizationRule::Policy AuthorizationRule::policy()
00122 {
00123     return d->policy;
00124 }
00125 
00126 void AuthorizationRule::setTargets(Targets targets)
00127 {
00128     d->targets = targets;
00129     d->scheduleChangedSignal();
00130 }
00131 
00132 AuthorizationRule::Targets AuthorizationRule::targets()
00133 {
00134     return d->targets;
00135 }
00136 
00137 void AuthorizationRule::setPersistence(Persistence persistence)
00138 {
00139     d->persistence = persistence;
00140     d->scheduleChangedSignal();
00141 }
00142 
00143 AuthorizationRule::Persistence AuthorizationRule::persistence()
00144 {
00145     return d->persistence;
00146 }
00147 
00148 void AuthorizationRule::setPin(const QString &pin)
00149 {
00150     d->pin = pin;
00151     d->scheduleChangedSignal();
00152 }
00153 
00154 QString AuthorizationRule::pin() const
00155 {
00156     return d->pin;
00157 }
00158 
00159 Credentials AuthorizationRule::credentials() const
00160 {
00161     return AuthorizationManager::self()->d->getCredentials(d->credentialID);
00162 }
00163 
00164 QString AuthorizationRule::serviceName() const
00165 {
00166     return d->serviceName;
00167 }
00168 
00169 } // Plasma namespace
00170 
00171 #include "authorizationrule.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • 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