accounts-qt  1.16
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-2016 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 QStringLiteral("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 = nullptr);
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 = nullptr);
101  virtual ~Account();
102 
103  static Account *fromId(Manager *manager, AccountId id,
104  QObject *parent = nullptr);
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  bool isEnabled() const;
117  void setEnabled(bool);
118 
126  uint credentialsId();
127 
134  void setCredentialsId(const uint id) {
135  setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
136  }
137 
138  QString displayName() const;
139  void setDisplayName(const QString &displayName);
140 
141  QString providerName() const;
142  Provider provider() const;
143 
144  void selectService(const Service &service = Service());
145  Service selectedService() const;
146 
147  /* QSettings-like methods */
148  QStringList allKeys() const;
149  void beginGroup(const QString &prefix);
150  QStringList childGroups() const;
151  QStringList childKeys() const;
152  void clear();
153  bool contains(const QString &key) const;
154  void endGroup();
155  QString group() const;
156  bool isWritable() const;
157  void remove(const QString &key);
158 
159  void setValue(const QString &key, const QVariant &value);
160  QVariant value(const QString &key,
161  const QVariant &defaultValue = QVariant(),
162  SettingSource *source = nullptr) const;
163  SettingSource value(const QString &key, QVariant &value) const;
164  QString valueAsString(const QString &key,
165  QString default_value = QString(),
166  SettingSource *source = nullptr) const;
167  int valueAsInt(const QString &key,
168  int default_value = 0,
169  SettingSource *source = nullptr) const;
170  quint64 valueAsUInt64(const QString &key,
171  quint64 default_value = 0,
172  SettingSource *source = nullptr) const;
173  bool valueAsBool(const QString &key,
174  bool default_value = false,
175  SettingSource *source = nullptr) const;
176 
177  Watch *watchKey(const QString &key = QString());
178 
179  void sync();
180  bool syncAndBlock();
181 
182  void remove();
183 
184  void sign(const QString &key, const char *token);
185  bool verify(const QString &key, const char **token);
186  bool verifyWithTokens(const QString &key, QList<const char*> tokens);
187 
188 Q_SIGNALS:
189  void displayNameChanged(const QString &displayName);
190  void enabledChanged(const QString &serviceName, bool enabled);
191 
192  void error(Accounts::Error error);
193  void synced();
194 
195  void removed();
196 
197 private:
198  AgAccount *account();
199  // Don't include private data in docs: \cond
200  class Private;
201  Account(Private *d, QObject *parent = nullptr);
202  friend class Manager;
203  friend class Account::Private;
204  friend class Watch;
205  friend class AccountService;
206  friend class AccountServicePrivate;
207 
208  Private *d;
209  // \endcond
210 };
211 
212 
213 } //namespace Accounts
214 
215 #endif // ACCOUNTS_ACCOUNT_H
Accounts::Error
Base object definition for accounts error handling.
Definition: error.h:44