identityinfo.cpp
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 
00024 #include <QVariant>
00025 
00026 #include "libsignoncommon.h"
00027 #include "identityinfo.h"
00028 #include "identityinfoimpl.h"
00029 #include "identity.h"
00030 
00031 namespace SignOn {
00032 
00033 IdentityInfo::IdentityInfo():
00034     impl(new IdentityInfoImpl(this))
00035 {
00036     qRegisterMetaType<IdentityInfo>("SignOn::IdentityInfo");
00037 
00038     if (qMetaTypeId<IdentityInfo>() < QMetaType::User)
00039         BLAME() << "IdentityInfo::IdentityInfo() - "
00040             "IdentityInfo meta type not registered.";
00041 
00042     impl->m_id = 0;
00043     impl->m_storeSecret = false;
00044 }
00045 
00046 IdentityInfo::IdentityInfo(const IdentityInfo &other):
00047     impl(new IdentityInfoImpl(this))
00048 {
00049     impl->copy(*(other.impl));
00050 }
00051 
00052 IdentityInfo &IdentityInfo::operator=(const IdentityInfo &other)
00053 {
00054     impl->copy(*(other.impl));
00055     return *this;
00056 }
00057 
00058 IdentityInfo::IdentityInfo(const QString &caption,
00059                            const QString &userName,
00060                            const QMap<MethodName, MechanismsList> &methods):
00061     impl(new IdentityInfoImpl(this))
00062 {
00063     impl->m_caption = caption;
00064     impl->m_userName = userName;
00065     impl->m_isEmpty = false;
00066     impl->m_authMethods = methods;
00067 }
00068 
00069 IdentityInfo::~IdentityInfo()
00070 {
00071     if (impl) delete impl;
00072     impl = 0;
00073 }
00074 
00075 void IdentityInfo::setId(const quint32 id)
00076 {
00077     impl->m_id = id;
00078 }
00079 
00080 quint32 IdentityInfo::id() const
00081 {
00082     return impl->m_id;
00083 }
00084 
00085 void IdentityInfo::setUserName(const QString &userName)
00086 {
00087     impl->m_userName = userName;
00088     impl->m_isEmpty = false;
00089 }
00090 
00091 const QString IdentityInfo::userName() const
00092 {
00093     return impl->m_userName;
00094 }
00095 
00096 void IdentityInfo::setCaption(const QString &caption)
00097 {
00098     impl->m_caption = caption;
00099 }
00100 
00101 const QString IdentityInfo::caption() const
00102 {
00103     return impl->m_caption;
00104 }
00105 
00106 void IdentityInfo::setRealms(const QStringList &realms)
00107 {
00108     impl->m_realms = realms;
00109 }
00110 
00111 QStringList IdentityInfo::realms() const
00112 {
00113     return impl->m_realms;
00114 }
00115 
00116 void IdentityInfo::setOwner(const QString &ownerToken)
00117 {
00118     impl->m_owner = ownerToken;
00119 }
00120 
00121 QString IdentityInfo::owner() const
00122 {
00123     return impl->m_owner;
00124 }
00125 
00126 void IdentityInfo::setAccessControlList(const QStringList &accessControlList)
00127 {
00128     impl->m_accessControlList = accessControlList;
00129 }
00130 
00131 QStringList IdentityInfo::accessControlList() const
00132 {
00133     return impl->m_accessControlList;
00134 }
00135 
00136 const QString IdentityInfo::secret() const
00137 {
00138     return impl->m_secret;
00139 }
00140 
00141 void IdentityInfo::setSecret(const QString &secret, const bool storeSecret)
00142 {
00143     impl->m_secret = secret;
00144     impl->m_storeSecret = storeSecret;
00145     impl->m_isEmpty = false;
00146 }
00147 
00148 bool IdentityInfo::isStoringSecret() const
00149 {
00150     return impl->m_storeSecret;
00151 }
00152 
00153 void IdentityInfo::setStoreSecret(const bool storeSecret)
00154 {
00155     impl->m_storeSecret = storeSecret;
00156 }
00157 
00158 void IdentityInfo::setMethod(const MethodName &method,
00159                              const MechanismsList &mechanismsList)
00160 {
00161     if (impl->hasMethod(method))
00162         impl->updateMethod(method, mechanismsList);
00163     else
00164         impl->addMethod(method, mechanismsList);
00165 }
00166 
00167 void IdentityInfo::removeMethod(const MethodName &method)
00168 {
00169     impl->removeMethod(method);
00170 }
00171 
00172 void IdentityInfo::setType(IdentityInfo::CredentialsType type)
00173 {
00174     impl->setType(type);
00175 }
00176 
00177 IdentityInfo::CredentialsType IdentityInfo::type() const
00178 {
00179     return impl->type();
00180 }
00181 
00182 QList<MethodName> IdentityInfo::methods() const
00183 {
00184     return impl->m_authMethods.keys();
00185 }
00186 
00187 MechanismsList IdentityInfo::mechanisms(const MethodName &method) const
00188 {
00189     return impl->m_authMethods.value(method, QStringList());
00190 }
00191 
00192 void IdentityInfo::setRefCount(qint32 refCount)
00193 {
00194     impl->setRefCount(refCount);
00195 }
00196 
00197 qint32 IdentityInfo::refCount() const
00198 {
00199     return impl->refCount();
00200 }
00201 
00202 } //namespace SignOn