libaccounts-qt  1.6
account.h
1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /*
3  * This file is part of libaccounts-qt
4  *
5  * Copyright (C) 2009-2011 Nokia Corporation.
6  * Copyright (C) 2012 Canonical Ltd.
7  *
8  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * version 2.1 as published by the Free Software Foundation.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  */
29 #ifndef ACCOUNTS_ACCOUNT_H
30 #define ACCOUNTS_ACCOUNT_H
31 
32 #include "Accounts/accountscommon.h"
33 #include "Accounts/error.h"
34 #include "Accounts/service.h"
35 
36 #define ACCOUNTS_KEY_CREDENTIALS_ID QLatin1String("CredentialsId")
37 #include <QObject>
38 #include <QStringList>
39 #include <QVariant>
40 
41 extern "C"
42 {
43  typedef struct _AgAccount AgAccount;
44  typedef struct _AgAccountWatch *AgAccountWatch;
45 }
46 
51 namespace Accounts
52 {
53 typedef quint32 AccountId;
54 typedef QList<AccountId> AccountIdList;
55 class Manager;
56 class Provider;
57 class AccountServicePrivate;
58 
63 enum SettingSource
64 {
65  NONE,
66  ACCOUNT,
67  TEMPLATE
68 };
69 
70 class ACCOUNTS_EXPORT Watch: public QObject
71 {
72  Q_OBJECT
73 
74 public:
75  /* We don't want to document these.
76  * \cond
77  */
78  Watch(QObject *parent = 0);
79  ~Watch();
80 
81  void setWatch(AgAccountWatch w) { watch = w; };
82  class Private;
83  // \endcond
84 
85 Q_SIGNALS:
86  void notify(const char *key);
87 
88  // \cond
89 private:
90  AgAccountWatch watch;
91  friend class Private;
92  // \endcond
93 };
94 
95 class ACCOUNTS_EXPORT Account: public QObject
96 {
97  Q_OBJECT
98 
99 public:
100  virtual ~Account();
101 
102  AccountId id() const;
103 
104  Manager *manager() const;
105 
106  bool supportsService(const QString &serviceType) const;
107 
108  ServiceList services(const QString &serviceType = NULL) const;
109  ServiceList enabledServices() const;
110 
111  bool enabled() const;
112  void setEnabled(bool);
113 
121  uint credentialsId();
122 
129  void setCredentialsId(const uint id) {
130  setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
131  }
132 
133  QString displayName() const;
134  void setDisplayName(const QString &displayName);
135 
136  QString providerName() const;
137  Provider provider() const;
138 
139  void selectService(const Service &service = Service());
140  Service selectedService() const;
141 
142  /* QSettings-like methods */
143  QStringList allKeys() const;
144  void beginGroup(const QString &prefix);
145  QStringList childGroups() const;
146  QStringList childKeys() const;
147  void clear();
148  bool contains(const QString &key) const;
149  void endGroup();
150  QString group() const;
151  bool isWritable() const;
152  void remove(const QString &key);
153 
154  void setValue(const QString &key, const QVariant &value);
155  QVariant value(const QString &key,
156  const QVariant &defaultValue = QVariant(),
157  SettingSource *source = 0) const;
158  SettingSource value(const QString &key, QVariant &value) const;
159  QString valueAsString(const QString &key,
160  QString default_value = QString::null,
161  SettingSource *source = 0) const;
162  int valueAsInt(const QString &key,
163  int default_value = 0,
164  SettingSource *source = 0) const;
165  quint64 valueAsUInt64(const QString &key,
166  quint64 default_value = 0,
167  SettingSource *source = 0) const;
168  bool valueAsBool(const QString &key,
169  bool default_value = false,
170  SettingSource *source = 0) const;
171 
172  Watch *watchKey(const QString &key = NULL);
173 
174  void sync();
175  bool syncAndBlock();
176 
177  void remove();
178 
179  void sign(const QString &key, const char *token);
180  bool verify(const QString &key, const char **token);
181  bool verifyWithTokens(const QString &key, QList<const char*> tokens);
182 
183 Q_SIGNALS:
184  void displayNameChanged(const QString &displayName);
185  void enabledChanged(const QString &serviceName, bool enabled);
186 
187  void error(Accounts::Error error);
188  void synced();
189 
190  void removed();
191 
192 protected:
193  // Don't include constructor in docs: \cond
194  Account(AgAccount *account, QObject *parent = 0);
195  // \endcond
196 
197 private:
198  AgAccount *account();
199  // Don't include private data in docs: \cond
200  class Private;
201  friend class Manager;
202  friend class Account::Private;
203  friend class Watch;
204  friend class AccountService;
205  friend class AccountServicePrivate;
206 
207  Private *d;
208  // \endcond
209 };
210 
211 
212 } //namespace Accounts
213 
214 #endif // ACCOUNTS_ACCOUNT_H