account.h

Go to the documentation of this file.
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 
00062 enum SettingSource
00063 {
00064     NONE,
00065     ACCOUNT,
00066     TEMPLATE
00067 };
00068 
00069 enum ErrorCode
00070 {
00071     /* The value of this enum must be the same as AgError */
00072     // TODO remove when the deprecated Error() signal using it is removed
00073     Database = 0,
00074     Disposed,
00075     Deleted,
00076 };
00077 
00087 class ACCOUNTS_EXPORT Watch : public QObject
00088 {
00089     Q_OBJECT
00090 
00091 public:
00092     /* We don't want to document these.
00093      * \cond
00094      */
00095     Watch(QObject *parent = 0);
00096     ~Watch();
00097 
00098     void setWatch(AgAccountWatch w) { watch = w; };
00099     class Private;
00100     // \endcond
00101 
00102 signals:
00109     void notify(const char *key);
00110 
00111     // \cond
00112 private:
00113     AgAccountWatch watch;
00114     friend class Private;
00115     // \endcond
00116 };
00117 
00144 class ACCOUNTS_EXPORT Account : public QObject
00145 {
00146     Q_OBJECT
00147 
00148 public:
00149 
00153     virtual ~Account();
00154 
00159     AccountId id() const;
00160 
00164     Manager *manager() const;
00165 
00169     bool supportsService(const QString &serviceType) const;
00170 
00179     ServiceList services(const QString &serviceType = NULL) const;
00180 
00187     ServiceList enabledServices() const;
00188 
00195     bool enabled() const;
00196 
00204     void setEnabled(bool);
00205 
00213     qint32 credentialsId();
00214 
00221     void setCredentialsId(const qint32 id) {
00222         setValue(ACCOUNTS_KEY_CREDENTIALS_ID, id);
00223     }
00224 
00230     QString displayName() const;
00231 
00236     void setDisplayName(const QString &displayName);
00237 
00241     QString providerName() const;
00242 
00248     void selectService(const Service *service = 0);
00249 
00253     Service *selectedService() const;
00254 
00255     /* QSettings-like methods */
00256 
00262     QStringList allKeys() const;
00263 
00270     void beginGroup(const QString &prefix);
00271 
00277     QStringList childGroups() const;
00278 
00284     QStringList childKeys() const;
00285 
00290     void clear();
00291 
00298     bool contains(const QString &key) const;
00299 
00305     void endGroup();
00306 
00312     QString group() const;
00313 
00317     bool isWritable() const;
00318 
00326     void remove(const QString &key);
00327 
00335     void setValue(const QString &key, const QVariant &value);
00336 
00349     void sync();
00350 
00358     bool syncAndBlock();
00359 
00373     SettingSource value(const QString &key, QVariant &value) const;
00374 
00384     QString valueAsString(const QString &key,
00385                           QString default_value = QString::null,
00386                           SettingSource *source = 0) const;
00387 
00397     int valueAsInt(const QString &key,
00398                    int default_value = 0,
00399                    SettingSource *source = 0) const;
00400 
00410     quint64 valueAsUInt64(const QString &key,
00411                    quint64 default_value = 0,
00412                    SettingSource *source = 0) const;
00413 
00423     bool valueAsBool(const QString &key,
00424                      bool default_value = false,
00425                      SettingSource *source = 0) const;
00436     Watch *watchKey(const QString &key = NULL);
00437 
00442     void remove();
00443 
00453     void sign(const QString &key, const char *token);
00454 
00466     bool verify(const QString &key, const char **token);
00467 
00480     bool verifyWithTokens(const QString &key, QList<const char*> tokens);
00481 
00482 signals:
00483     void displayNameChanged(const QString &displayName);
00484     void enabledChanged(const QString &serviceName, bool enabled);
00485 
00490     void error(Accounts::ErrorCode errorCode);
00491 
00495     void error(Accounts::Error error);
00496     void synced();
00497 
00498     void removed();
00499 
00500 protected:
00501     // Don't include constructor in docs: \cond
00502     Account(AgAccount *account, QObject *parent = 0);
00503     // \endcond
00504 
00505 private:
00506     // Don't include private data in docs: \cond
00507     class Private;
00508     friend class Manager;
00509     friend class Account::Private;
00510     friend class Watch;
00511 
00512     Private *d;
00513     // \endcond
00514 };
00515 
00516 
00517 } //namespace Accounts
00518 
00519 #endif // ACCOUNT_H