/
channellistener.cpp
174 lines (148 loc) · 5.26 KB
/
channellistener.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/******************************************************************************
**
** This file is part of commhistory-daemon.
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Reto Zingg <reto.zingg@nokia.com>
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the GNU Lesser General Public License version 2.1 as
** published by the Free Software Foundation.
**
** This library is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
** License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this library; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
******************************************************************************/
#include "channellistener.h"
#include "constants.h"
#include "debug.h"
#include <CommHistory/EventModel>
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/TextChannel>
#include <TelepathyQt/StreamedMediaChannel>
#include <TelepathyQt/Channel>
#include <TelepathyQt/ContactManager>
#include <TelepathyQt/PendingContacts>
#include <TelepathyQt/Types>
#include <TelepathyQt/Contact>
using namespace RTComLogger;
ChannelListener::ChannelListener(const Tp::AccountPtr &account,
const Tp::ChannelPtr &channel,
const Tp::MethodInvocationContextPtr<> &context,
QObject *parent)
: QObject(parent), m_Account(account), m_Channel(channel), m_InvocationContext(context),
m_pEventModel(0)
{
connect(m_Account.data(),
SIGNAL(invalidated(Tp::DBusProxy*, const QString&, const QString&)),
this,
SLOT(invalidated(Tp::DBusProxy*, const QString&, const QString&)));
}
void ChannelListener::slotChannelReady(Tp::PendingOperation* operation)
{
qCDebug(lcCommhistoryd) << __PRETTY_FUNCTION__ << channel();
if (!checkIfError(operation) && m_Channel) {
m_Direction = m_Channel->isRequested() ?
CommHistory::Event::Outbound :
CommHistory::Event::Inbound;
m_Connection = m_Channel->connection(); //ready channel has ready connection
channelReady();
} else {
qCritical() << "Channel is not ready";
}
}
bool ChannelListener::checkIfError(Tp::PendingOperation* operation)
{
bool error = true;
if (operation && !operation->isError()) {
error = false;
} else if (operation) {
finishedWithError(operation->errorName(),
operation->errorMessage());
}
return error;
}
void ChannelListener::invalidated(Tp::DBusProxy *proxy,
const QString &errorName, const QString &errorMessage)
{
qCDebug(lcCommhistoryd) << __PRETTY_FUNCTION__ << proxy->objectPath();
Q_UNUSED(proxy)
finishedWithError(errorName, errorMessage);
}
void ChannelListener::finishedWithError(const QString& errorName,
const QString& errorMessage)
{
if (!m_InvocationContext.isNull()) {
m_InvocationContext->setFinishedWithError(errorName, errorMessage);
}
closed();
}
ChannelListener::~ChannelListener()
{
}
QString ChannelListener::channel() const
{
QString channel;
if (!m_Channel.isNull()) {
channel = m_Channel->objectPath();
}
return channel;
}
void ChannelListener::closed()
{
qCDebug(lcCommhistoryd) << "channelClosed";
emit channelClosed(this);
}
void ChannelListener::makeChannelReady(const Tp::Features &features)
{
if (m_Channel) {
connect(m_Channel->becomeReady(features),
SIGNAL(finished(Tp::PendingOperation*)),
this,
SLOT(slotChannelReady(Tp::PendingOperation*)));
connect(m_Channel.data(),
SIGNAL( invalidated(Tp::DBusProxy*, const QString&, const QString& ) ),
this,
SLOT( invalidated(Tp::DBusProxy*, const QString&, const QString& ) ) );
} else {
qCritical() << Q_FUNC_INFO << "NULL channel provided to listener";
}
}
void ChannelListener::invocationContextFinished()
{
if (!m_InvocationContext.isNull()) {
m_InvocationContext->setFinished();
}
}
void ChannelListener::invocationContextError()
{
finishedWithError(QLatin1String(TP_QT_ERROR_INVALID_ARGUMENT),QString());
}
CommHistory::EventModel& ChannelListener::eventModel()
{
if (!m_pEventModel) {
m_pEventModel = new CommHistory::EventModel(this);
}
return *m_pEventModel;
}
QString ChannelListener::targetId() const
{
QString targetId;
QVariantMap properties = m_Channel->immutableProperties();
if (properties.contains(TELEPATHY_CHANNEL_INTERFACE_PERSISTENT_ID)) {
targetId = properties.value(TELEPATHY_CHANNEL_INTERFACE_PERSISTENT_ID).toString();
} else if (properties.contains(TP_QT_IFACE_CHANNEL+QLatin1String(".TargetID"))) {
targetId = properties.value(TP_QT_IFACE_CHANNEL+QLatin1String(".TargetID")).toString();
}
return targetId;
}
void ChannelListener::channelReady()
{
qCDebug(lcCommhistoryd) << Q_FUNC_INFO << "not implemented";
}