281310ab66000866fccc97e9ab7e1d42596e7079
[tpsession] / tpsession-0.1 / tpsession / tpsession.h
1 /*
2  * This file is part of TpSession
3  *
4  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
5  * Contact Kate Alhola  kate.alholanokia.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 #ifndef TPSESSION_H
22 #define TPSESSION_H
23
24 #include <TelepathyQt4/Types>
25 #include <TelepathyQt4/Account>
26 #include <TelepathyQt4/Types>
27 #include <TelepathyQt4/PendingChannelRequest>
28 #include <TelepathyQt4/ChannelRequest>
29 #include <TelepathyQt4/PendingChannel>
30 #include <TelepathyQt4/Channel>
31 #include <TelepathyQt4/TextChannel>
32 #include <TelepathyQt4/AccountManager>
33 #include <TelepathyQt4/PendingOperation>
34 #include <TelepathyQt4/PendingReady>
35 #include <TelepathyQt4/ClientRegistrar>
36 #include <TelepathyQt4/Debug>
37
38 #include <QString>
39 #include <QVector>
40 #include <QObject>
41
42 #include "tpsessionaccount.h"
43 #include "tpsessionobserver.h"
44
45 class TpSession:public QObject
46 {
47        Q_OBJECT
48 public:
49     TpSession(QString cmname=QString(),bool synchronous=FALSE);
50
51
52     static TpSession* instance(bool synchronous=TRUE);
53     void sendMessageToAddress(QString connectionMgr,QString address,QString message);
54     TpSessionAccount* getAccount(const  QString cm, const QString protocol=QString());
55     void createChannelListener(const QString &channelType,
56                                const Tp::MethodInvocationContextPtr<> &context,
57                                const Tp::AccountPtr &account,
58                                const Tp::ChannelPtr &channel);
59     void createObserver();
60
61 signals:
62     void amReady(TpSession *);
63     void accountReady(TpSessionAccount *);
64     void channeReady(TpSessionAccount *);
65     void messageReceived(const Tp::ReceivedMessage &,TpSessionAccount *);
66 private slots:
67     void onAMReady(Tp::PendingOperation *);
68     void onAccountCreated(const QString &);
69     void onReady(Tp::PendingOperation *);
70     void onAccountReady(TpSessionAccount *tpacc);
71     void onMessageReceived(const Tp::ReceivedMessage &,TpSessionAccount *);
72 public:
73     QVector<TpSessionAccount*> accounts;
74
75 private:
76     static TpSession *instancePtr;
77     //TpSession *instancePtr;
78     QString reqCm;
79     QString reqAddress;
80     QString reqMsg;
81
82     bool sync;  // Synchronous initialization
83     QEventLoop loop;
84     Tp::AccountManagerPtr mAM;
85     QStringList channels;
86     Tp::ClientRegistrarPtr registrar;
87 };
88
89
90
91 #endif // TPSESSION_H