accounts-qt  1.2
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 AccountServicePrivate;
57 
62 enum SettingSource
63 {
64  NONE,
65  ACCOUNT,
66  TEMPLATE
67 };
68 
69 class ACCOUNTS_EXPORT Watch: public QObject
70 {
71  Q_OBJECT
72 
73 public:
74  /* We don't want to document these.
75  * \cond
76  */
77  Watch(QObject *parent = 0);
78  ~Watch();
79 
80  void setWatch(AgAccountWatch w) { watch = w; };
81  class Private;
82  // \endcond
83 
84 Q_SIGNALS:
85  void notify(const char *key);
86 
87  // \cond
88 private:
89  AgAccountWatch watch;
90  friend class Private;
91  // \endcond
92 };
93 
94 class ACCOUNTS_EXPORT Account: public QObject
95 {
96  Q_OBJECT
97 
98 public:
99  virtual ~Account();
100 
101  AccountId id() const;
102 
103  Manager *manager() const;
104 
105  bool supportsService(const QString &serviceType) const;
106 
107  ServiceList services(const QString &serviceType = NULL) const;
108  ServiceList enabledServices() const;
109 
110  bool enabled() const;
111  void setEnabled(bool);
112 
120  uint credentialsId();
121 
128  void setCredentialsId(const uint id) {
129  setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
130  }
131 
132  QString displayName() const;
133  void setDisplayName(const QString &displayName);
134 
135  QString providerName() const;
136 
137  void selectService(const Service &service = Service());
138  Service selectedService() const;
139 
140  /* QSettings-like methods */
141  QStringList allKeys() const;
142  void beginGroup(const QString &prefix);
143  QStringList childGroups() const;
144  QStringList childKeys() const;
145  void clear();
146  bool contains(const QString &key) const;
147  void endGroup();
148  QString group() const;
149  bool isWritable() const;
150  void remove(const QString &key);
151 
152  void setValue(const QString &key, const QVariant &value);
153  SettingSource value(const QString &key, QVariant &value) const;
154  QString valueAsString(const QString &key,
155  QString default_value = QString::null,
156  SettingSource *source = 0) const;
157  int valueAsInt(const QString &key,
158  int default_value = 0,
159  SettingSource *source = 0) const;
160  quint64 valueAsUInt64(const QString &key,
161  quint64 default_value = 0,
162  SettingSource *source = 0) const;
163  bool valueAsBool(const QString &key,
164  bool default_value = false,
165  SettingSource *source = 0) const;
166 
167  Watch *watchKey(const QString &key = NULL);
168 
169  void sync();
170  bool syncAndBlock();
171 
172  void remove();
173 
174  void sign(const QString &key, const char *token);
175  bool verify(const QString &key, const char **token);
176  bool verifyWithTokens(const QString &key, QList<const char*> tokens);
177 
178 Q_SIGNALS:
179  void displayNameChanged(const QString &displayName);
180  void enabledChanged(const QString &serviceName, bool enabled);
181 
182  void error(Accounts::Error error);
183  void synced();
184 
185  void removed();
186 
187 protected:
188  // Don't include constructor in docs: \cond
189  Account(AgAccount *account, QObject *parent = 0);
190  // \endcond
191 
192 private:
193  AgAccount *account();
194  // Don't include private data in docs: \cond
195  class Private;
196  friend class Manager;
197  friend class Account::Private;
198  friend class Watch;
199  friend class AccountServicePrivate;
200 
201  Private *d;
202  // \endcond
203 };
204 
205 
206 } //namespace Accounts
207 
208 #endif // ACCOUNTS_ACCOUNT_H