accounts-qt
0.31
|
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-2010 Nokia Corporation. 00006 * 00007 * Contact: Alberto Mardegan <alberto.mardegan@nokia.com> 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public License 00011 * version 2.1 as published by the Free Software Foundation. 00012 * 00013 * This library is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA 00022 */ 00023 00024 #ifndef ACCOUNT_H 00025 #define ACCOUNT_H 00026 00027 00028 #include <QObject> 00029 #include <QSettings> 00030 #include <QStringList> 00031 00032 #include "Accounts/accountscommon.h" 00033 #include "Accounts/service.h" 00034 00035 #define ACCOUNTS_KEY_CREDENTIALS_ID QLatin1String("CredentialsId") 00036 00037 extern "C" 00038 { 00039 typedef struct _AgAccount AgAccount; 00040 typedef struct _AgAccountWatch *AgAccountWatch; 00041 } 00042 00047 namespace Accounts 00048 { 00049 typedef quint64 AccountId; 00050 typedef QList<AccountId> AccountIdList; 00051 class Manager; 00052 00057 enum SettingSource 00058 { 00059 NONE, 00060 ACCOUNT, 00061 TEMPLATE 00062 }; 00063 00064 enum ErrorCode 00065 { 00066 /* The value of this enum must be the same as AgError */ 00067 Database = 0, 00068 Disposed, 00069 Deleted, 00070 }; 00071 00081 class ACCOUNTS_EXPORT Watch : public QObject 00082 { 00083 Q_OBJECT 00084 00085 public: 00086 /* We don't want to document these. 00087 * \cond 00088 */ 00089 Watch(QObject *parent = 0); 00090 ~Watch(); 00091 00092 void setWatch(AgAccountWatch w) { watch = w; }; 00093 class Private; 00094 // \endcond 00095 00096 signals: 00103 void notify(const char *key); 00104 00105 // \cond 00106 private: 00107 AgAccountWatch watch; 00108 friend class Private; 00109 // \endcond 00110 }; 00111 00138 class ACCOUNTS_EXPORT Account : public QObject 00139 { 00140 Q_OBJECT 00141 00142 public: 00143 00147 virtual ~Account(); 00148 00153 AccountId id() const; 00154 00158 Manager *manager() const; 00159 00163 bool supportsService(const QString &serviceType) const; 00164 00173 ServiceList services(const QString &serviceType = NULL) const; 00174 00181 ServiceList enabledServices() const; 00182 00186 bool enabled() const; 00187 00194 void setEnabled(bool); 00195 00203 qint32 credentialsId(); 00204 00211 void setCredentialsId(const qint32 id) { 00212 setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id); 00213 } 00214 00220 QString displayName() const; 00221 00226 void setDisplayName(const QString &displayName); 00227 00231 QString providerName() const; 00232 00238 void selectService(const Service *service = 0); 00239 00243 Service *selectedService() const; 00244 00245 /* QSettings-like methods */ 00246 00252 QStringList allKeys() const; 00253 00260 void beginGroup(const QString &prefix); 00261 00267 QStringList childGroups() const; 00268 00274 QStringList childKeys() const; 00275 00280 void clear(); 00281 00288 bool contains(const QString &key) const; 00289 00295 void endGroup(); 00296 00302 QString group() const; 00303 00307 bool isWritable() const; 00308 00316 void remove(const QString &key); 00317 00325 void setValue(const QString &key, const QVariant &value); 00326 00339 void sync(); 00340 00348 bool syncAndBlock(); 00349 00363 SettingSource value(const QString &key, QVariant &value) const; 00364 00374 QString valueAsString(const QString &key, 00375 QString default_value = QString::null, 00376 SettingSource *source = 0) const; 00377 00387 int valueAsInt(const QString &key, 00388 int default_value = 0, 00389 SettingSource *source = 0) const; 00390 00400 quint64 valueAsUInt64(const QString &key, 00401 quint64 default_value = 0, 00402 SettingSource *source = 0) const; 00403 00413 bool valueAsBool(const QString &key, 00414 bool default_value = false, 00415 SettingSource *source = 0) const; 00426 Watch *watchKey(const QString &key = NULL); 00427 00432 void remove(); 00433 00441 void sign(const QString &key, const char *token); 00442 00454 bool verify(const QString &key, const char **token); 00455 00468 bool verifyWithTokens(const QString &key, QList<const char*> tokens); 00469 00470 signals: 00471 void displayNameChanged(const QString &displayName); 00472 void enabledChanged(const QString &serviceName, bool enabled); 00473 00474 void error(Accounts::ErrorCode errorCode); 00475 void synced(); 00476 00477 void removed(); 00478 00479 protected: 00480 // Don't include constructor in docs: \cond 00481 Account(AgAccount *account, QObject *parent = 0); 00482 // \endcond 00483 00484 private: 00485 // Don't include private data in docs: \cond 00486 class Private; 00487 friend class Manager; 00488 friend class Account::Private; 00489 friend class Watch; 00490 00491 Private *d; 00492 // \endcond 00493 }; 00494 00495 00496 } //namespace Accounts 00497 00498 #endif // ACCOUNT_H