signon  8.58
signonidentityinfo.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00007  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00023 #ifndef SIGNONIDENTITYINFO_H
00024 #define SIGNONIDENTITYINFO_H
00025 
00026 #include <QStringList>
00027 #include <QVariantMap>
00028 
00029 #include "signond/signoncommon.h"
00030 
00031 namespace SignonDaemonNS {
00032 
00033 typedef QString MethodName;
00034 typedef QStringList MechanismsList;
00035 typedef QMap<MethodName, MechanismsList> MethodMap;
00036 
00042 struct SignonIdentityInfo: protected QVariantMap
00043 {
00044     SignonIdentityInfo();
00045     SignonIdentityInfo(const QVariantMap &info);
00046 
00047     const QVariantMap toMap() const;
00048 
00049     void update(const SignonIdentityInfo &info);
00050 
00051     void setNew() { setId(SIGNOND_NEW_IDENTITY); }
00052     bool isNew() const { return id() == SIGNOND_NEW_IDENTITY; }
00053     void setId(quint32 id) { insert(SIGNOND_IDENTITY_INFO_ID, id); }
00054     quint32 id() const { return value(SIGNOND_IDENTITY_INFO_ID, 0).toUInt(); }
00055 
00056     void setUserName(const QString &userName) {
00057         insert(SIGNOND_IDENTITY_INFO_USERNAME, userName);
00058     }
00059 
00060     QString userName() const {
00061         return value(SIGNOND_IDENTITY_INFO_USERNAME).toString();
00062     }
00063 
00064     void setUserNameSecret(bool secret) {
00065         insert(SIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET, secret);
00066     }
00067 
00068     bool isUserNameSecret() const {
00069         return value(SIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET).toBool();
00070     }
00071 
00072     void setPassword(const QString &password) {
00073         insert(SIGNOND_IDENTITY_INFO_SECRET, password);
00074     }
00075 
00076     QString password() const {
00077         return value(SIGNOND_IDENTITY_INFO_SECRET).toString();
00078     }
00079 
00080     void removeSecrets() {
00081         remove(SIGNOND_IDENTITY_INFO_SECRET);
00082         if (isUserNameSecret())
00083             remove(SIGNOND_IDENTITY_INFO_USERNAME);
00084     }
00085 
00086     bool hasSecrets() const {
00087         return contains(SIGNOND_IDENTITY_INFO_SECRET) ||
00088             (isUserNameSecret() && contains(SIGNOND_IDENTITY_INFO_USERNAME));
00089     }
00090 
00091     void setStorePassword(bool storePassword) {
00092         insert(SIGNOND_IDENTITY_INFO_STORESECRET, storePassword);
00093     }
00094 
00095     bool storePassword() const {
00096         return value(SIGNOND_IDENTITY_INFO_STORESECRET).toBool();
00097     }
00098 
00099     void setCaption(const QString &caption) {
00100         insert(SIGNOND_IDENTITY_INFO_CAPTION, caption);
00101     }
00102 
00103     QString caption() const {
00104         return value(SIGNOND_IDENTITY_INFO_CAPTION).toString();
00105     }
00106 
00107     void setRealms(const QStringList &realms) {
00108         insert(SIGNOND_IDENTITY_INFO_REALMS, realms);
00109     }
00110 
00111     QStringList realms() const {
00112         return value(SIGNOND_IDENTITY_INFO_REALMS).toStringList();
00113     }
00114 
00115     void setMethods(const MethodMap &methods) {
00116         insert(SIGNOND_IDENTITY_INFO_AUTHMETHODS, QVariant::fromValue(methods));
00117     }
00118 
00119     MethodMap methods() const {
00120         return value(SIGNOND_IDENTITY_INFO_AUTHMETHODS).value<MethodMap>();
00121     }
00122 
00123     void setAccessControlList(const QStringList &accessControlList) {
00124         insert(SIGNOND_IDENTITY_INFO_ACL, accessControlList);
00125     }
00126 
00127     QStringList accessControlList() const {
00128         return value(SIGNOND_IDENTITY_INFO_ACL).toStringList();
00129     }
00130 
00131     void setValidated(bool validated) {
00132         insert(SIGNOND_IDENTITY_INFO_VALIDATED, validated);
00133     }
00134 
00135     bool validated() const {
00136         return value(SIGNOND_IDENTITY_INFO_VALIDATED).toBool();
00137     }
00138 
00139     void setType(int type) {
00140         insert(SIGNOND_IDENTITY_INFO_TYPE, type);
00141     }
00142 
00143     int type() const {
00144         return value(SIGNOND_IDENTITY_INFO_TYPE).toInt();
00145     }
00146 
00147     void setOwnerList(const QStringList &owners) {
00148         insert(SIGNOND_IDENTITY_INFO_OWNER, owners);
00149     }
00150 
00151     QStringList ownerList() const {
00152         return value(SIGNOND_IDENTITY_INFO_OWNER).toStringList();
00153     }
00154 
00155     void setRefCount(int refCount) {
00156         insert(SIGNOND_IDENTITY_INFO_REFCOUNT, refCount);
00157     }
00158 
00159     int refCount() const {
00160         return value(SIGNOND_IDENTITY_INFO_REFCOUNT).toInt();
00161     }
00162 
00163     bool checkMethodAndMechanism(const QString &method,
00164                                  const QString &mechanism,
00165                                  QString &allowedMechanism);
00166 }; //struct SignonIdentityInfo
00167 
00168 } //namespace SignonDaemonNS
00169 
00170 Q_DECLARE_METATYPE(SignonDaemonNS::MethodMap)
00171 
00172 #endif // SIGNONIDENTITYINFO_H