libaccounts-qt  1.1
account.h
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  *
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  */
00028 #ifndef ACCOUNT_H
00029 #define ACCOUNT_H
00030 
00031 
00032 #include <QObject>
00033 #include <QSettings>
00034 #include <QStringList>
00035 
00036 #include "Accounts/accountscommon.h"
00037 #include "Accounts/error.h"
00038 #include "Accounts/service.h"
00039 
00040 #define ACCOUNTS_KEY_CREDENTIALS_ID QLatin1String("CredentialsId")
00041 
00042 extern "C"
00043 {
00044     typedef struct _AgAccount AgAccount;
00045     typedef struct _AgAccountWatch *AgAccountWatch;
00046 }
00047 
00052 namespace Accounts
00053 {
00054 typedef quint32 AccountId;
00055 typedef QList<AccountId> AccountIdList;
00056 class Manager;
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     virtual ~Account();
00101 
00102     AccountId id() const;
00103 
00104     Manager *manager() const;
00105 
00106     bool supportsService(const QString &serviceType) const;
00107 
00108     ServiceList services(const QString &serviceType = NULL) const;
00109     ServiceList enabledServices() const;
00110 
00111     bool enabled() const;
00112     void setEnabled(bool);
00113 
00121     qint32 credentialsId();
00122 
00129     void setCredentialsId(const qint32 id) {
00130         setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
00131     }
00132 
00133     QString displayName() const;
00134     void setDisplayName(const QString &displayName);
00135 
00136     QString providerName() const;
00137 
00138     void selectService(const Service *service = 0);
00139 
00140     Service *selectedService() const;
00141 
00142     /* QSettings-like methods */
00143     QStringList allKeys() const;
00144     void beginGroup(const QString &prefix);
00145     QStringList childGroups() const;
00146     QStringList childKeys() const;
00147     void clear();
00148     bool contains(const QString &key) const;
00149     void endGroup();
00150     QString group() const;
00151     bool isWritable() const;
00152     void remove(const QString &key);
00153 
00154     void setValue(const QString &key, const QVariant &value);
00155 
00156     void sync();
00157     bool syncAndBlock();
00158 
00159     SettingSource value(const QString &key, QVariant &value) const;
00160 
00161     QString valueAsString(const QString &key,
00162                           QString default_value = QString::null,
00163                           SettingSource *source = 0) const;
00164     int valueAsInt(const QString &key,
00165                    int default_value = 0,
00166                    SettingSource *source = 0) const;
00167     quint64 valueAsUInt64(const QString &key,
00168                    quint64 default_value = 0,
00169                    SettingSource *source = 0) const;
00170     bool valueAsBool(const QString &key,
00171                      bool default_value = false,
00172                      SettingSource *source = 0) const;
00173 
00174     Watch *watchKey(const QString &key = NULL);
00175 
00176     void remove();
00177 
00178     void sign(const QString &key, const char *token);
00179     bool verify(const QString &key, const char **token);
00180     bool verifyWithTokens(const QString &key, QList<const char*> tokens);
00181 
00182 Q_SIGNALS:
00183     void displayNameChanged(const QString &displayName);
00184     void enabledChanged(const QString &serviceName, bool enabled);
00185 
00186     void error(Accounts::Error error);
00187     void synced();
00188 
00189     void removed();
00190 
00191 protected:
00192     // Don't include constructor in docs: \cond
00193     Account(AgAccount *account, QObject *parent = 0);
00194     // \endcond
00195 
00196 private:
00197     AgAccount *account();
00198     // Don't include private data in docs: \cond
00199     class Private;
00200     friend class Manager;
00201     friend class Account::Private;
00202     friend class Watch;
00203     friend class AccountServicePrivate;
00204 
00205     Private *d;
00206     // \endcond
00207 };
00208 
00209 
00210 } //namespace Accounts
00211 
00212 #endif // ACCOUNT_H