sessiondata.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00032 #ifndef SESSIONDATA_H
00033 #define SESSIONDATA_H
00034 
00035 #include <QMap>
00036 #include <QString>
00037 #include <QStringList>
00038 #include <QVariant>
00039 
00040 #include <SignOn/libsignoncommon.h>
00041 
00042 namespace SignOn {
00043 
00052 #define SIGNON_SESSION_DECLARE_PROPERTY(type_, name_) \
00053           void set##name_(const type_ &value ) { m_data.insert(QLatin1String(#name_), value); } \
00054           type_ name_() const { return m_data.value(QLatin1String(#name_)).value<type_>(); }
00055 
00061 #define SSO_ACCESS_CONTROL_TOKENS QLatin1String("AccessControlTokens")
00062 
00071 enum SignonUiPolicy {
00072     DefaultPolicy = 0,          
00073     RequestPasswordPolicy,      
00074     NoUserInteractionPolicy,    
00075     ValidationPolicy,           
00078 };
00079 
00090 class SIGNON_EXPORT SessionData
00091 {
00092 public:
00099     SessionData(const QVariantMap &data = QVariantMap()) { m_data = data; }
00100 
00105     SessionData(const SessionData &other) { m_data = other.m_data; }
00106 
00112     SessionData &operator=(const SessionData &other) {
00113         m_data = other.m_data;
00114         return *this;
00115     }
00116 
00122     SessionData &operator+=(const SessionData &other) {
00123         m_data.unite(other.m_data);
00124         return *this;
00125     }
00126 
00131     const QStringList propertyNames() const {
00132         return m_data.keys();
00133     }
00134 
00141     const QVariant getProperty(const QString &propertyName) const {
00142         return m_data.value(propertyName, QVariant());
00143     }
00144 
00149     QStringList getAccessControlTokens() const {
00150         return getProperty(SSO_ACCESS_CONTROL_TOKENS).toStringList();
00151     }
00152 
00158     template <class T> T data() const {
00159         T dataImpl;
00160         dataImpl.m_data = m_data;
00161         return dataImpl;
00162     }
00163 
00168     QVariantMap toMap() const { return m_data; }
00169 
00175     SIGNON_SESSION_DECLARE_PROPERTY(QString, Secret)
00176 
00177     
00180     SIGNON_SESSION_DECLARE_PROPERTY(QString, UserName)
00181 
00186     SIGNON_SESSION_DECLARE_PROPERTY(QString, Realm)
00187 
00192     SIGNON_SESSION_DECLARE_PROPERTY(QString, NetworkProxy)
00193 
00199     SIGNON_SESSION_DECLARE_PROPERTY(int, UiPolicy)
00200 
00209     SIGNON_SESSION_DECLARE_PROPERTY(QString, Caption)
00210 
00217     SIGNON_SESSION_DECLARE_PROPERTY(quint32, NetworkTimeout)
00218 
00223     SIGNON_SESSION_DECLARE_PROPERTY(quint32, WindowId)
00224 
00232     SIGNON_SESSION_DECLARE_PROPERTY(bool, RenewToken)
00233 
00234 protected:
00235     QVariantMap m_data;
00236 };
00237 
00238 } //namespace SignOn
00239 
00240 Q_DECLARE_METATYPE(SignOn::SessionData)
00241 #endif // SESSIONDATA_H