sessiondata.h
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
32 #ifndef SESSIONDATA_H
33 #define SESSIONDATA_H
34 
35 #include <QMap>
36 #include <QString>
37 #include <QStringList>
38 #include <QVariant>
39 
40 #include <SignOn/libsignoncommon.h>
41 
42 namespace SignOn {
43 
52 #define SIGNON_SESSION_DECLARE_PROPERTY(type_, name_) \
53  void set##name_(const type_ &value ) { m_data.insert(QLatin1String(#name_), value); } \
54  type_ name_() const { return m_data.value(QLatin1String(#name_)).value<type_>(); }
55 
61 #define SSO_ACCESS_CONTROL_TOKENS QLatin1String("AccessControlTokens")
62 
78 };
79 
90 class SIGNON_EXPORT SessionData
91 {
92 public:
99  SessionData(const QVariantMap &data = QVariantMap()) { m_data = data; }
100 
105  SessionData(const SessionData &other) { m_data = other.m_data; }
106 
113  m_data = other.m_data;
114  return *this;
115  }
116 
123  m_data.unite(other.m_data);
124  return *this;
125  }
126 
131  const QStringList propertyNames() const {
132  return m_data.keys();
133  }
134 
141  const QVariant getProperty(const QString &propertyName) const {
142  return m_data.value(propertyName, QVariant());
143  }
144 
149  QStringList getAccessControlTokens() const {
150  return getProperty(SSO_ACCESS_CONTROL_TOKENS).toStringList();
151  }
152 
158  template <class T> T data() const {
159  T dataImpl;
160  dataImpl.m_data = m_data;
161  return dataImpl;
162  }
163 
169  SIGNON_SESSION_DECLARE_PROPERTY(QString, Secret)
170 
171 
174  SIGNON_SESSION_DECLARE_PROPERTY(QString, UserName)
175 
180  SIGNON_SESSION_DECLARE_PROPERTY(QString, Realm)
181 
186  SIGNON_SESSION_DECLARE_PROPERTY(QString, NetworkProxy)
187 
193  SIGNON_SESSION_DECLARE_PROPERTY(int, UiPolicy)
194 
203  SIGNON_SESSION_DECLARE_PROPERTY(QString, Caption)
204 
211  SIGNON_SESSION_DECLARE_PROPERTY(quint32, NetworkTimeout)
212 
217  SIGNON_SESSION_DECLARE_PROPERTY(quint32, WindowId)
218 
226  SIGNON_SESSION_DECLARE_PROPERTY(bool, RenewToken)
227 
228 protected:
229  QVariantMap m_data;
230 };
231 
232 } //namespace SignOn
233 
234 Q_DECLARE_METATYPE(SignOn::SessionData)
235 #endif // SESSIONDATA_H