accounts-qt  0.31
account.h
Go to the documentation of this file.
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-2010 Nokia Corporation.
6  *
7  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
24 #ifndef ACCOUNT_H
25 #define ACCOUNT_H
26 
27 
28 #include <QObject>
29 #include <QSettings>
30 #include <QStringList>
31 
33 #include "Accounts/service.h"
34 
35 #define ACCOUNTS_KEY_CREDENTIALS_ID QLatin1String("CredentialsId")
36 
37 extern "C"
38 {
39  typedef struct _AgAccount AgAccount;
40  typedef struct _AgAccountWatch *AgAccountWatch;
41 }
42 
47 namespace Accounts
48 {
49 typedef quint64 AccountId;
50 typedef QList<AccountId> AccountIdList;
51 class Manager;
52 
58 {
62 };
63 
65 {
66  /* The value of this enum must be the same as AgError */
67  Database = 0,
70 };
71 
81 class ACCOUNTS_EXPORT Watch : public QObject
82 {
83  Q_OBJECT
84 
85 public:
86  /* We don't want to document these.
87  * \cond
88  */
89  Watch(QObject *parent = 0);
90  ~Watch();
91 
92  void setWatch(AgAccountWatch w) { watch = w; };
93  class Private;
94  // \endcond
95 
96 signals:
103  void notify(const char *key);
104 
105  // \cond
106 private:
107  AgAccountWatch watch;
108  friend class Private;
109  // \endcond
110 };
111 
138 class ACCOUNTS_EXPORT Account : public QObject
139 {
140  Q_OBJECT
141 
142 public:
143 
147  virtual ~Account();
148 
153  AccountId id() const;
154 
158  Manager *manager() const;
159 
163  bool supportsService(const QString &serviceType) const;
164 
173  ServiceList services(const QString &serviceType = NULL) const;
174 
181  ServiceList enabledServices() const;
182 
186  bool enabled() const;
187 
194  void setEnabled(bool);
195 
203  qint32 credentialsId();
204 
211  void setCredentialsId(const qint32 id) {
212  setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
213  }
214 
220  QString displayName() const;
221 
226  void setDisplayName(const QString &displayName);
227 
231  QString providerName() const;
232 
238  void selectService(const Service *service = 0);
239 
243  Service *selectedService() const;
244 
245  /* QSettings-like methods */
246 
252  QStringList allKeys() const;
253 
260  void beginGroup(const QString &prefix);
261 
267  QStringList childGroups() const;
268 
274  QStringList childKeys() const;
275 
280  void clear();
281 
288  bool contains(const QString &key) const;
289 
295  void endGroup();
296 
302  QString group() const;
303 
307  bool isWritable() const;
308 
316  void remove(const QString &key);
317 
325  void setValue(const QString &key, const QVariant &value);
326 
339  void sync();
340 
348  bool syncAndBlock();
349 
363  SettingSource value(const QString &key, QVariant &value) const;
364 
374  QString valueAsString(const QString &key,
375  QString default_value = QString::null,
376  SettingSource *source = 0) const;
377 
387  int valueAsInt(const QString &key,
388  int default_value = 0,
389  SettingSource *source = 0) const;
390 
400  quint64 valueAsUInt64(const QString &key,
401  quint64 default_value = 0,
402  SettingSource *source = 0) const;
403 
413  bool valueAsBool(const QString &key,
414  bool default_value = false,
415  SettingSource *source = 0) const;
426  Watch *watchKey(const QString &key = NULL);
427 
432  void remove();
433 
441  void sign(const QString &key, const char *token);
442 
454  bool verify(const QString &key, const char **token);
455 
468  bool verifyWithTokens(const QString &key, QList<const char*> tokens);
469 
470 signals:
471  void displayNameChanged(const QString &displayName);
472  void enabledChanged(const QString &serviceName, bool enabled);
473 
474  void error(Accounts::ErrorCode errorCode);
475  void synced();
476 
477  void removed();
478 
479 protected:
480  // Don't include constructor in docs: \cond
481  Account(AgAccount *account, QObject *parent = 0);
482  // \endcond
483 
484 private:
485  // Don't include private data in docs: \cond
486  class Private;
487  friend class Manager;
488  friend class Account::Private;
489  friend class Watch;
490 
491  Private *d;
492  // \endcond
493 };
494 
495 
496 } //namespace Accounts
497 
498 #endif // ACCOUNT_H