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

Plasma

  • plasma
  • remote
authorizationrule.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
18 */
19
20#include "authorizationrule.h"
21
22#include "authorizationmanager.h"
23#include "credentials.h"
24#include "private/authorizationmanager_p.h"
25#include "private/authorizationrule_p.h"
26
27#include <QtCore/QObject>
28#include <QtCore/QTimer>
29
30#include <kurl.h>
31#include <klocalizedstring.h>
32
33namespace Plasma
34{
35
36AuthorizationRulePrivate::AuthorizationRulePrivate(const QString &serviceName, const QString &credentialID,
37 AuthorizationRule *rule)
38 : q(rule),
39 serviceName(serviceName),
40 credentialID(credentialID),
41 policy(AuthorizationRule::Deny),
42 targets(AuthorizationRule::Default),
43 persistence(AuthorizationRule::Transient)
44{
45}
46
47AuthorizationRulePrivate::~AuthorizationRulePrivate()
48{
49}
50
51bool AuthorizationRulePrivate::matches(const QString &name, const QString &id) const
52{
53 if (serviceName == name && (credentialID == id)) {
54 return true;
55 }
56
57 if (targets.testFlag(AuthorizationRule::AllUsers) && (serviceName == name)) {
58 return true;
59 }
60
61 if (targets.testFlag(AuthorizationRule::AllServices) && (credentialID == id)) {
62 return true;
63 }
64
65 return false;
66}
67
68void AuthorizationRulePrivate::scheduleChangedSignal()
69{
70 QTimer::singleShot(0, q, SLOT(fireChangedSignal()));
71}
72
73void AuthorizationRulePrivate::fireChangedSignal()
74{
75 if ((persistence == AuthorizationRule::Persistent) &&
76 (policy != AuthorizationRule::PinRequired)) {
77 AuthorizationManager::self()->d->saveRules();
78 }
79
80 emit q->changed(q);
81}
82
83AuthorizationRule::AuthorizationRule(const QString &serviceName, const QString &credentialID)
84 : QObject(AuthorizationManager::self()),
85 d(new AuthorizationRulePrivate(serviceName, credentialID, this))
86{
87}
88
89AuthorizationRule::~AuthorizationRule()
90{
91 delete d;
92}
93
94QString AuthorizationRule::description() const
95{
96 //i18n megafest :p
97 if (d->targets.testFlag(AllUsers) && d->policy == Allow) {
98 return i18n("Allow everybody access to %1.", d->serviceName);
99 } else if (d->targets.testFlag(AllUsers) && d->policy == Deny) {
100 return i18n("Deny everybody access to %1", d->serviceName);
101 } else if (d->targets.testFlag(AllServices) && d->policy == Allow) {
102 return i18n("Allow %1 access to all services.", credentials().name());
103 } else if (d->targets.testFlag(AllServices) && d->policy == Deny) {
104 return i18n("Deny %1 access to all services.", credentials().name());
105 } else if (d->policy == Allow) {
106 return i18n("Allow access to %1, by %2.", d->serviceName, credentials().name());
107 } else if (d->policy == Deny) {
108 return i18n("Deny access to %1, by %2.", d->serviceName, credentials().name());
109 } else {
110 return i18n("Allow access to %1, by %2?", d->serviceName, credentials().name());
111 }
112}
113
114
115void AuthorizationRule::setPolicy(Policy policy)
116{
117 d->policy = policy;
118 d->scheduleChangedSignal();
119}
120
121AuthorizationRule::Policy AuthorizationRule::policy()
122{
123 return d->policy;
124}
125
126void AuthorizationRule::setTargets(Targets targets)
127{
128 d->targets = targets;
129 d->scheduleChangedSignal();
130}
131
132AuthorizationRule::Targets AuthorizationRule::targets()
133{
134 return d->targets;
135}
136
137void AuthorizationRule::setPersistence(Persistence persistence)
138{
139 d->persistence = persistence;
140 d->scheduleChangedSignal();
141}
142
143AuthorizationRule::Persistence AuthorizationRule::persistence()
144{
145 return d->persistence;
146}
147
148void AuthorizationRule::setPin(const QString &pin)
149{
150 d->pin = pin;
151 d->scheduleChangedSignal();
152}
153
154QString AuthorizationRule::pin() const
155{
156 return d->pin;
157}
158
159Credentials AuthorizationRule::credentials() const
160{
161 return AuthorizationManager::self()->d->getCredentials(d->credentialID);
162}
163
164QString AuthorizationRule::serviceName() const
165{
166 return d->serviceName;
167}
168
169} // Plasma namespace
170
171#include "authorizationrule.moc"
authorizationmanager.h
authorizationrule.h
Plasma::AuthorizationRule::Policy
Policy
Definition: authorizationrule.h:73
Plasma::AuthorizationRule::Persistence
Persistence
Definition: authorizationrule.h:79
Plasma::Credentials
This class encapsules someone's identity.
Definition: credentials.h:43
QObject
credentials.h
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
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.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • 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