channelDestroyed hadling, TPSESSION_DEBUG env
[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 #include <QProcessEnvironment>
38
39 #include <QString>
40 #include <QVector>
41 #include <QObject>
42
43 #include "tpsessionaccount.h"
44 #include "tpsessionobserver.h"
45
46
47 class TpSession:public QObject
48 {
49        Q_OBJECT
50 public:
51     TpSession(QString cmname=QString(),bool synchronous=FALSE);
52
53
54     static TpSession* instance(bool synchronous=TRUE);
55     static bool tpsDebug();
56     void sendMessageToAddress(QString connectionMgr,QString address,QString message);
57     TpSessionAccount* getAccount(const  QString cm, const QString protocol=QString());
58     void createChannelListener(const QString &channelType,
59                                const Tp::MethodInvocationContextPtr<> &context,
60                                const Tp::AccountPtr &account,
61                                const Tp::ChannelPtr &channel);
62     void createObserver();
63
64 signals:
65     void amReady(TpSession *);
66     void accountReady(TpSessionAccount *);
67     void channeReady(TpSessionAccount *);
68     void messageReceived(const Tp::ReceivedMessage &,TpSessionAccount *);
69 private slots:
70     void onAMReady(Tp::PendingOperation *);
71     void onAccountCreated(const QString &);
72     void onReady(Tp::PendingOperation *);
73     void onAccountReady(TpSessionAccount *tpacc);
74     void onMessageReceived(const Tp::ReceivedMessage &,TpSessionAccount *);
75 public:
76     QVector<TpSessionAccount*> accounts;
77
78 private:
79     static TpSession *instancePtr;
80     static bool tpsdebug;
81     //TpSession *instancePtr;
82     QString reqCm;
83     QString reqAddress;
84     QString reqMsg;
85
86     bool sync;  // Synchronous initialization
87     QEventLoop loop;
88     Tp::AccountManagerPtr mAM;
89     QStringList channels;
90     Tp::ClientRegistrarPtr registrar;
91 };
92
93
94
95 #endif // TPSESSION_H