2
* This file is part of TelepathyQt
4
* @copyright Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
5
* @copyright Copyright (C) 2011 Nokia Corporation
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include "TelepathyQt/request-temporary-handler-internal.h"
25
#include "TelepathyQt/_gen/request-temporary-handler-internal.moc.hpp"
27
#include "TelepathyQt/debug-internal.h"
29
#include <TelepathyQt/ChannelClassSpecList>
34
SharedPtr<RequestTemporaryHandler> RequestTemporaryHandler::create(const AccountPtr &account)
36
return SharedPtr<RequestTemporaryHandler>(new RequestTemporaryHandler(account));
39
RequestTemporaryHandler::RequestTemporaryHandler(const AccountPtr &account)
42
AbstractClientHandler(ChannelClassSpecList(), AbstractClientHandler::Capabilities(), false),
44
mQueueChannelReceived(true),
45
dbusHandlerInvoked(false)
49
RequestTemporaryHandler::~RequestTemporaryHandler()
53
void RequestTemporaryHandler::handleChannels(
54
const MethodInvocationContextPtr<> &context,
55
const AccountPtr &account,
56
const ConnectionPtr &connection,
57
const QList<ChannelPtr> &channels,
58
const QList<ChannelRequestPtr> &requestsSatisfied,
59
const QDateTime &userActionTime,
60
const HandlerInfo &handlerInfo)
62
Q_ASSERT(dbusHandlerInvoked);
66
ChannelPtr oldChannel = channel();
67
if (channels.size() != 1 || requestsSatisfied.size() != 1) {
68
errorMessage = QLatin1String("Only one channel and one channel request should be given "
70
} else if (account != mAccount) {
71
errorMessage = QLatin1String("Account received is not the same as the account which made "
73
} else if (oldChannel && oldChannel != channels.first()) {
74
errorMessage = QLatin1String("Received a channel that is not the same as the first "
78
if (!errorMessage.isEmpty()) {
79
warning() << "Handling channel failed with" << TP_QT_ERROR_SERVICE_CONFUSED << ":" <<
82
// Only emit error if we didn't receive any channel yet.
84
emit error(TP_QT_ERROR_SERVICE_CONFUSED, errorMessage);
86
context->setFinishedWithError(TP_QT_ERROR_SERVICE_CONFUSED, errorMessage);
90
ChannelRequestPtr channelRequest = requestsSatisfied.first();
93
mChannel = WeakPtr<Channel>(channels.first());
94
emit channelReceived(channel(), userActionTime, channelRequest->hints());
96
if (mQueueChannelReceived) {
97
mChannelReceivedQueue.enqueue(qMakePair(userActionTime, channelRequest->hints()));
99
emit channelReceived(oldChannel, userActionTime, channelRequest->hints());
103
context->setFinished();
106
void RequestTemporaryHandler::setQueueChannelReceived(bool queue)
108
mQueueChannelReceived = queue;
110
processChannelReceivedQueue();
114
void RequestTemporaryHandler::setDBusHandlerInvoked()
116
dbusHandlerInvoked = true;
119
void RequestTemporaryHandler::setDBusHandlerErrored(const QString &errorName, const QString &errorMessage)
121
Q_ASSERT(dbusHandlerInvoked);
123
emit error(errorName, errorMessage);
127
void RequestTemporaryHandler::processChannelReceivedQueue()
129
while (!mChannelReceivedQueue.isEmpty()) {
130
QPair<QDateTime, ChannelRequestHints> info = mChannelReceivedQueue.dequeue();
131
emit channelReceived(channel(), info.first, info.second);