accounts-qt  1.14
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 #if QT_VERSION < QT_VERSION_CHECK(5 ,0 ,0)
37 #define ACCOUNTS_KEY_CREDENTIALS_ID QString::fromUtf8("CredentialsId")
38 #else
39 #define ACCOUNTS_KEY_CREDENTIALS_ID QStringLiteral("CredentialsId")
40 #endif
41 #include <QObject>
42 #include <QStringList>
43 #include <QVariant>
44 
45 extern "C"
46 {
47  typedef struct _AgAccount AgAccount;
48  typedef struct _AgAccountWatch *AgAccountWatch;
49 }
50 
55 namespace Accounts
56 {
57 typedef quint32 AccountId;
58 typedef QList<AccountId> AccountIdList;
59 class Manager;
60 class Provider;
61 class AccountServicePrivate;
62 
67 enum SettingSource
68 {
69  NONE,
70  ACCOUNT,
71  TEMPLATE
72 };
73 
74 class ACCOUNTS_EXPORT Watch: public QObject
75 {
76  Q_OBJECT
77 
78 public:
79  /* We don't want to document these.
80  * \cond
81  */
82  Watch(QObject *parent = 0);
83  ~Watch();
84 
85  void setWatch(AgAccountWatch w) { watch = w; };
86  class Private;
87  // \endcond
88 
89 Q_SIGNALS:
90  void notify(const char *key);
91 
92  // \cond
93 private:
94  AgAccountWatch watch;
95  friend class Private;
96  // \endcond
97 };
98 
99 class ACCOUNTS_EXPORT Account: public QObject
100 {
101  Q_OBJECT
102 
103 public:
104  Account(Manager *manager, const QString &provider, QObject *parent = 0);
105  virtual ~Account();
106 
107  static Account *fromId(Manager *manager, AccountId id,
108  QObject *parent = 0);
109 
110  AccountId id() const;
111 
112  Manager *manager() const;
113 
114  bool supportsService(const QString &serviceType) const;
115 
116  ServiceList services(const QString &serviceType = QString()) const;
117  ServiceList enabledServices() const;
118 
119  bool enabled() const;
120  bool isEnabled() const;
121  void setEnabled(bool);
122 
130  uint credentialsId();
131 
138  void setCredentialsId(const uint id) {
139  setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
140  }
141 
142  QString displayName() const;
143  void setDisplayName(const QString &displayName);
144 
145  QString providerName() const;
146  Provider provider() const;
147 
148  void selectService(const Service &service = Service());
149  Service selectedService() const;
150 
151  /* QSettings-like methods */
152  QStringList allKeys() const;
153  void beginGroup(const QString &prefix);
154  QStringList childGroups() const;
155  QStringList childKeys() const;
156  void clear();
157  bool contains(const QString &key) const;
158  void endGroup();
159  QString group() const;
160  bool isWritable() const;
161  void remove(const QString &key);
162 
163  void setValue(const QString &key, const QVariant &value);
164  QVariant value(const QString &key,
165  const QVariant &defaultValue = QVariant(),
166  SettingSource *source = 0) const;
167  SettingSource value(const QString &key, QVariant &value) const;
168  QString valueAsString(const QString &key,
169  QString default_value = QString::null,
170  SettingSource *source = 0) const;
171  int valueAsInt(const QString &key,
172  int default_value = 0,
173  SettingSource *source = 0) const;
174  quint64 valueAsUInt64(const QString &key,
175  quint64 default_value = 0,
176  SettingSource *source = 0) const;
177  bool valueAsBool(const QString &key,
178  bool default_value = false,
179  SettingSource *source = 0) const;
180 
181  Watch *watchKey(const QString &key = QString());
182 
183  void sync();
184  bool syncAndBlock();
185 
186  void remove();
187 
188  void sign(const QString &key, const char *token);
189  bool verify(const QString &key, const char **token);
190  bool verifyWithTokens(const QString &key, QList<const char*> tokens);
191 
192 Q_SIGNALS:
193  void displayNameChanged(const QString &displayName);
194  void enabledChanged(const QString &serviceName, bool enabled);
195 
196  void error(Accounts::Error error);
197  void synced();
198 
199  void removed();
200 
201 private:
202  AgAccount *account();
203  // Don't include private data in docs: \cond
204  class Private;
205  Account(Private *d, QObject *parent = 0);
206  friend class Manager;
207  friend class Account::Private;
208  friend class Watch;
209  friend class AccountService;
210  friend class AccountServicePrivate;
211 
212  Private *d;
213  // \endcond
214 };
215 
216 
217 } //namespace Accounts
218 
219 #endif // ACCOUNTS_ACCOUNT_H
Manager of accounts, services and providers.
Definition: manager.h:51
Account settings for a specific service.
Monitors an account key or group of keys.
Definition: account.h:74
Representation of an account provider.
Definition: provider.h:48
Representation of an account service.
Definition: service.h:48
Base object definition for accounts error handling.
Definition: error.h:42
void setCredentialsId(const uint id)
Sets the accounts credentials ID.
Definition: account.h:138