accounts-qt
1.13
|
00001 /* vi: set et sw=4 ts=4 cino=t0,(0: */ 00002 /* 00003 * This file is part of libaccounts-qt 00004 * 00005 * Copyright (C) 2009-2011 Nokia Corporation. 00006 * Copyright (C) 2012 Canonical Ltd. 00007 * 00008 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public License 00012 * version 2.1 as published by the Free Software Foundation. 00013 * 00014 * This library is distributed in the hope that it will be useful, but 00015 * WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00022 * 02110-1301 USA 00023 */ 00029 #ifndef ACCOUNTS_ACCOUNT_H 00030 #define ACCOUNTS_ACCOUNT_H 00031 00032 #include "Accounts/accountscommon.h" 00033 #include "Accounts/error.h" 00034 #include "Accounts/service.h" 00035 00036 #define ACCOUNTS_KEY_CREDENTIALS_ID QLatin1String("CredentialsId") 00037 #include <QObject> 00038 #include <QStringList> 00039 #include <QVariant> 00040 00041 extern "C" 00042 { 00043 typedef struct _AgAccount AgAccount; 00044 typedef struct _AgAccountWatch *AgAccountWatch; 00045 } 00046 00051 namespace Accounts 00052 { 00053 typedef quint32 AccountId; 00054 typedef QList<AccountId> AccountIdList; 00055 class Manager; 00056 class Provider; 00057 class AccountServicePrivate; 00058 00063 enum SettingSource 00064 { 00065 NONE, 00066 ACCOUNT, 00067 TEMPLATE 00068 }; 00069 00070 class ACCOUNTS_EXPORT Watch: public QObject 00071 { 00072 Q_OBJECT 00073 00074 public: 00075 /* We don't want to document these. 00076 * \cond 00077 */ 00078 Watch(QObject *parent = 0); 00079 ~Watch(); 00080 00081 void setWatch(AgAccountWatch w) { watch = w; }; 00082 class Private; 00083 // \endcond 00084 00085 Q_SIGNALS: 00086 void notify(const char *key); 00087 00088 // \cond 00089 private: 00090 AgAccountWatch watch; 00091 friend class Private; 00092 // \endcond 00093 }; 00094 00095 class ACCOUNTS_EXPORT Account: public QObject 00096 { 00097 Q_OBJECT 00098 00099 public: 00100 Account(Manager *manager, const QString &provider, QObject *parent = 0); 00101 virtual ~Account(); 00102 00103 static Account *fromId(Manager *manager, AccountId id, 00104 QObject *parent = 0); 00105 00106 AccountId id() const; 00107 00108 Manager *manager() const; 00109 00110 bool supportsService(const QString &serviceType) const; 00111 00112 ServiceList services(const QString &serviceType = QString()) const; 00113 ServiceList enabledServices() const; 00114 00115 bool enabled() const; 00116 bool isEnabled() const; 00117 void setEnabled(bool); 00118 00126 uint credentialsId(); 00127 00134 void setCredentialsId(const uint id) { 00135 setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id); 00136 } 00137 00138 QString displayName() const; 00139 void setDisplayName(const QString &displayName); 00140 00141 QString providerName() const; 00142 Provider provider() const; 00143 00144 void selectService(const Service &service = Service()); 00145 Service selectedService() const; 00146 00147 /* QSettings-like methods */ 00148 QStringList allKeys() const; 00149 void beginGroup(const QString &prefix); 00150 QStringList childGroups() const; 00151 QStringList childKeys() const; 00152 void clear(); 00153 bool contains(const QString &key) const; 00154 void endGroup(); 00155 QString group() const; 00156 bool isWritable() const; 00157 void remove(const QString &key); 00158 00159 void setValue(const QString &key, const QVariant &value); 00160 QVariant value(const QString &key, 00161 const QVariant &defaultValue = QVariant(), 00162 SettingSource *source = 0) const; 00163 SettingSource value(const QString &key, QVariant &value) const; 00164 QString valueAsString(const QString &key, 00165 QString default_value = QString::null, 00166 SettingSource *source = 0) const; 00167 int valueAsInt(const QString &key, 00168 int default_value = 0, 00169 SettingSource *source = 0) const; 00170 quint64 valueAsUInt64(const QString &key, 00171 quint64 default_value = 0, 00172 SettingSource *source = 0) const; 00173 bool valueAsBool(const QString &key, 00174 bool default_value = false, 00175 SettingSource *source = 0) const; 00176 00177 Watch *watchKey(const QString &key = QString()); 00178 00179 void sync(); 00180 bool syncAndBlock(); 00181 00182 void remove(); 00183 00184 void sign(const QString &key, const char *token); 00185 bool verify(const QString &key, const char **token); 00186 bool verifyWithTokens(const QString &key, QList<const char*> tokens); 00187 00188 Q_SIGNALS: 00189 void displayNameChanged(const QString &displayName); 00190 void enabledChanged(const QString &serviceName, bool enabled); 00191 00192 void error(Accounts::Error error); 00193 void synced(); 00194 00195 void removed(); 00196 00197 private: 00198 AgAccount *account(); 00199 // Don't include private data in docs: \cond 00200 class Private; 00201 Account(Private *d, QObject *parent = 0); 00202 friend class Manager; 00203 friend class Account::Private; 00204 friend class Watch; 00205 friend class AccountService; 00206 friend class AccountServicePrivate; 00207 00208 Private *d; 00209 // \endcond 00210 }; 00211 00212 00213 } //namespace Accounts 00214 00215 #endif // ACCOUNTS_ACCOUNT_H