accounts-qt  1.7
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  Account(Manager *manager, const QString &provider, QObject *parent = 0);
101  virtual ~Account();
102 
103  static Account *fromId(Manager *manager, AccountId id,
104  QObject *parent = 0);
105 
106  AccountId id() const;
107 
108  Manager *manager() const;
109 
110  bool supportsService(const QString &serviceType) const;
111 
112  ServiceList services(const QString &serviceType = QString()) const;
113  ServiceList enabledServices() const;
114 
115  bool enabled() const;
116  void setEnabled(bool);
117 
125  uint credentialsId();
126 
133  void setCredentialsId(const uint id) {
134  setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
135  }
136 
137  QString displayName() const;
138  void setDisplayName(const QString &displayName);
139 
140  QString providerName() const;
141  Provider provider() const;
142 
143  void selectService(const Service &service = Service());
144  Service selectedService() const;
145 
146  /* QSettings-like methods */
147  QStringList allKeys() const;
148  void beginGroup(const QString &prefix);
149  QStringList childGroups() const;
150  QStringList childKeys() const;
151  void clear();
152  bool contains(const QString &key) const;
153  void endGroup();
154  QString group() const;
155  bool isWritable() const;
156  void remove(const QString &key);
157 
158  void setValue(const QString &key, const QVariant &value);
159  QVariant value(const QString &key,
160  const QVariant &defaultValue = QVariant(),
161  SettingSource *source = 0) const;
162  SettingSource value(const QString &key, QVariant &value) const;
163  QString valueAsString(const QString &key,
164  QString default_value = QString::null,
165  SettingSource *source = 0) const;
166  int valueAsInt(const QString &key,
167  int default_value = 0,
168  SettingSource *source = 0) const;
169  quint64 valueAsUInt64(const QString &key,
170  quint64 default_value = 0,
171  SettingSource *source = 0) const;
172  bool valueAsBool(const QString &key,
173  bool default_value = false,
174  SettingSource *source = 0) const;
175 
176  Watch *watchKey(const QString &key = QString());
177 
178  void sync();
179  bool syncAndBlock();
180 
181  void remove();
182 
183  void sign(const QString &key, const char *token);
184  bool verify(const QString &key, const char **token);
185  bool verifyWithTokens(const QString &key, QList<const char*> tokens);
186 
187 Q_SIGNALS:
188  void displayNameChanged(const QString &displayName);
189  void enabledChanged(const QString &serviceName, bool enabled);
190 
191  void error(Accounts::Error error);
192  void synced();
193 
194  void removed();
195 
196 private:
197  AgAccount *account();
198  // Don't include private data in docs: \cond
199  class Private;
200  Account(Private *d, QObject *parent = 0);
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