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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • 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 
33 namespace Plasma
34 {
35 
36 AuthorizationRulePrivate::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 
47 AuthorizationRulePrivate::~AuthorizationRulePrivate()
48 {
49 }
50 
51 bool 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 
68 void AuthorizationRulePrivate::scheduleChangedSignal()
69 {
70  QTimer::singleShot(0, q, SLOT(fireChangedSignal()));
71 }
72 
73 void 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 
83 AuthorizationRule::AuthorizationRule(const QString &serviceName, const QString &credentialID)
84  : QObject(AuthorizationManager::self()),
85  d(new AuthorizationRulePrivate(serviceName, credentialID, this))
86 {
87 }
88 
89 AuthorizationRule::~AuthorizationRule()
90 {
91  delete d;
92 }
93 
94 QString 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 
115 void AuthorizationRule::setPolicy(Policy policy)
116 {
117  d->policy = policy;
118  d->scheduleChangedSignal();
119 }
120 
121 AuthorizationRule::Policy AuthorizationRule::policy()
122 {
123  return d->policy;
124 }
125 
126 void AuthorizationRule::setTargets(Targets targets)
127 {
128  d->targets = targets;
129  d->scheduleChangedSignal();
130 }
131 
132 AuthorizationRule::Targets AuthorizationRule::targets()
133 {
134  return d->targets;
135 }
136 
137 void AuthorizationRule::setPersistence(Persistence persistence)
138 {
139  d->persistence = persistence;
140  d->scheduleChangedSignal();
141 }
142 
143 AuthorizationRule::Persistence AuthorizationRule::persistence()
144 {
145  return d->persistence;
146 }
147 
148 void AuthorizationRule::setPin(const QString &pin)
149 {
150  d->pin = pin;
151  d->scheduleChangedSignal();
152 }
153 
154 QString AuthorizationRule::pin() const
155 {
156  return d->pin;
157 }
158 
159 Credentials AuthorizationRule::credentials() const
160 {
161  return AuthorizationManager::self()->d->getCredentials(d->credentialID);
162 }
163 
164 QString AuthorizationRule::serviceName() const
165 {
166  return d->serviceName;
167 }
168 
169 } // Plasma namespace
170 
171 #include "authorizationrule.moc"
Plasma::AuthorizationRule::setPersistence
void setPersistence(Persistence persistence)
Definition: authorizationrule.cpp:137
Plasma::AuthorizationRule::PinRequired
specify that the user will need to enter a pin at both sides
Definition: authorizationrule.h:76
authorizationmanager.h
Plasma::AuthorizationRule::policy
Policy policy()
Definition: authorizationrule.cpp:121
Plasma::AuthorizationRule::AllServices
specify that this rule is valid for all services
Definition: authorizationrule.h:87
Plasma::AuthorizationRule::persistence
Persistence persistence()
Definition: authorizationrule.cpp:143
Plasma::AuthorizationRule::Persistent
specify that this rule will be saved between sessions.
Definition: authorizationrule.h:81
Plasma::AuthorizationRule::Policy
Policy
Definition: authorizationrule.h:73
Plasma::AuthorizationRule::targets
Targets targets()
Definition: authorizationrule.cpp:132
Plasma::AuthorizationRule::description
QString description() const
Definition: authorizationrule.cpp:94
Plasma::AuthorizationRule::Deny
access for messages matching this rule is denied.
Definition: authorizationrule.h:74
Plasma::AuthorizationRule::serviceName
QString serviceName() const
Definition: authorizationrule.cpp:164
QObject
Plasma::AuthorizationManager::self
static AuthorizationManager * self()
Singleton pattern accessor.
Definition: authorizationmanager.cpp:64
Plasma::AuthorizationRule::~AuthorizationRule
~AuthorizationRule()
Definition: authorizationrule.cpp:89
Plasma::AuthorizationRule::credentials
Credentials credentials() const
Definition: authorizationrule.cpp:159
Plasma::AuthorizationRule::setTargets
void setTargets(Targets targets)
Definition: authorizationrule.cpp:126
credentials.h
Plasma::AuthorizationRule::AllUsers
specify that this rule is valid for all users
Definition: authorizationrule.h:86
Plasma::AuthorizationRule::Allow
access for messages matching this rule is allowed.
Definition: authorizationrule.h:75
Plasma::AuthorizationRule::setPin
void setPin(const QString &pin)
Definition: authorizationrule.cpp:148
Plasma::AuthorizationRule::Persistence
Persistence
Definition: authorizationrule.h:79
Plasma::Credentials
This class encapsules someone's identity.
Definition: credentials.h:42
Plasma::AuthorizationRule::setPolicy
void setPolicy(Policy policy)
Definition: authorizationrule.cpp:115
Plasma::AuthorizationRule::pin
QString pin() const
Definition: authorizationrule.cpp:154
authorizationrule.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:33 by doxygen 1.8.7 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 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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