libqutim  0.3.1.0
protocol.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** qutIM - instant messenger
00004 **
00005 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
00006 **
00007 *****************************************************************************
00008 **
00009 ** $QUTIM_BEGIN_LICENSE$
00010 ** This program is free software: you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation, either version 3 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 ** See the GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program.  If not, see http://www.gnu.org/licenses/.
00022 ** $QUTIM_END_LICENSE$
00023 **
00024 ****************************************************************************/
00025 
00026 #ifndef PROTOCOL_H
00027 #define PROTOCOL_H
00028 
00029 #include "configbase.h"
00030 #include <QStringList>
00031 
00032 class QWizardPage;
00033 
00034 namespace qutim_sdk_0_3
00035 {
00036 class ExtensionInfo;
00037 class Contact;
00038 class Account;
00039 class ProtocolPrivate;
00040 
00041 class Protocol;
00042 typedef QHash<QString, Protocol *> ProtocolHash;
00043 
00044 class LIBQUTIM_EXPORT AccountCreationWizard : public QObject
00045 {
00046     Q_OBJECT
00047 public:
00048     AccountCreationWizard(Protocol *protocol);
00049     virtual ~AccountCreationWizard();
00050     virtual QList<QWizardPage *> createPages(QWidget *parent) = 0;
00051     ExtensionInfo info() const;
00052 protected:
00053     void setInfo(const ExtensionInfo &info);
00054     virtual void virtual_hook(int id, void *data);
00055 };
00056 
00057 class LIBQUTIM_EXPORT Protocol : public QObject
00058 {
00059     Q_OBJECT
00060     Q_DECLARE_PRIVATE(Protocol)
00061     Q_PROPERTY(QString id READ id)
00062     Q_PROPERTY(QStringList supportedAccountParameters READ supportedAccountParameters CONSTANT)
00063     //      Q_FLAGS(DataType DataTypes)
00064     //      Q_FLAGS(RemoveFlag RemoveFlags)
00065 public:
00066     enum DataType {
00067         ProtocolIdName,
00068         ProtocolContainsContacts
00069     };
00070     enum RemoveFlag {
00071         DeleteAccount = 0x01
00072     };
00073     enum ProtocolHook {
00074         SupportedAccountParametersHook,
00075         CreateAccountHook
00076     };
00077 
00078     struct CreateAccountArgument
00079     {
00080         QString id;
00081         QVariantMap parameters;
00082         Account *account;
00083     };
00084 
00085     //      Q_DECLARE_FLAGS(RemoveFlags, RemoveFlag)
00086     //      Q_DECLARE_FLAGS(DataTypes, DataType)
00087     Protocol();
00088     Protocol(ProtocolPrivate &p);
00089     virtual ~Protocol();
00090     Config config();
00091     ConfigGroup config(const QString &group);
00092     QString id() const;
00093     QStringList supportedAccountParameters() const;
00094     Q_INVOKABLE Account *createAccount(const QString &id, const QVariantMap &parameters);
00095     Q_INVOKABLE virtual QList<qutim_sdk_0_3::Account*> accounts() const = 0;
00096     Q_INVOKABLE virtual qutim_sdk_0_3::Account *account(const QString &id) const = 0;
00097     virtual QVariant data(DataType type);
00103     virtual void removeAccount(qutim_sdk_0_3::Account *account, RemoveFlag flags = DeleteAccount);
00104     static ProtocolHash all();
00105 signals:
00106     void accountCreated(qutim_sdk_0_3::Account *);
00107     void accountRemoved(qutim_sdk_0_3::Account *);
00108 protected:
00109     virtual void virtual_hook(int id, void *data);
00110 private:
00111     virtual void loadAccounts() = 0;
00112     friend class ModuleManager;
00113 protected:
00114     QScopedPointer<ProtocolPrivate> d_ptr;
00115 };
00116 }
00117 
00118 #endif // PROTOCOL_H
00119