diff options
Diffstat (limited to 'qt4/examples/file-transfer/file-receiver-handler.cpp')
-rw-r--r-- | qt4/examples/file-transfer/file-receiver-handler.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/qt4/examples/file-transfer/file-receiver-handler.cpp b/qt4/examples/file-transfer/file-receiver-handler.cpp new file mode 100644 index 000000000..15e5ca937 --- /dev/null +++ b/qt4/examples/file-transfer/file-receiver-handler.cpp @@ -0,0 +1,96 @@ +/* + * This file is part of TelepathyQt4 + * + * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright (C) 2011 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 "file-receiver-handler.h" +#include "_gen/file-receiver-handler.moc.hpp" + +#include "pending-file-receive.h" + +#include <TelepathyQt4/Channel> +#include <TelepathyQt4/ChannelClassSpec> +#include <TelepathyQt4/ChannelClassSpecList> +#include <TelepathyQt4/ChannelRequest> +#include <TelepathyQt4/Connection> +#include <TelepathyQt4/MethodInvocationContext> +#include <TelepathyQt4/IncomingFileTransferChannel> + +#include <QDateTime> +#include <QDebug> + +FileReceiverHandler::FileReceiverHandler() + : QObject(), + AbstractClientHandler(ChannelClassSpecList() << ChannelClassSpec::incomingFileTransfer(), + AbstractClientHandler::Capabilities(), false) +{ +} + +FileReceiverHandler::~FileReceiverHandler() +{ +} + +bool FileReceiverHandler::bypassApproval() const +{ + return false; +} + +void FileReceiverHandler::handleChannels(const MethodInvocationContextPtr<> &context, + const AccountPtr &account, + const ConnectionPtr &connection, + const QList<ChannelPtr> &channels, + const QList<ChannelRequestPtr> &requestsSatisfied, + const QDateTime &userActionTime, + const HandlerInfo &handlerInfo) +{ + // We should always receive one channel to handle, + // otherwise either MC or tp-qt4 itself is bogus, so let's assert in case they are + Q_ASSERT(channels.size() == 1); + ChannelPtr chan = channels.first(); + + if (!chan->isValid()) { + qWarning() << "Channel received to handle is invalid, ignoring channel"; + context->setFinishedWithError(TP_QT4_ERROR_INVALID_ARGUMENT, + QLatin1String("Channel received to handle is invalid")); + return; + } + + // We should always receive incoming channels of type FileTransfer, as set by our filter, + // otherwise either MC or tp-qt4 itself is bogus, so let's assert in case they are + Q_ASSERT(chan->channelType() == TP_QT4_IFACE_CHANNEL_TYPE_FILE_TRANSFER); + Q_ASSERT(!chan->isRequested()); + + IncomingFileTransferChannelPtr transferChannel = IncomingFileTransferChannelPtr::qObjectCast(chan); + Q_ASSERT(transferChannel); + + context->setFinished(); + + PendingFileReceive *receiveOperation = new PendingFileReceive(transferChannel, + SharedPtr<RefCounted>::dynamicCast(AbstractClientPtr(this))); + connect(receiveOperation, + SIGNAL(finished(Tp::PendingOperation*)), + SLOT(onReceiveFinished(Tp::PendingOperation*))); +} + +void FileReceiverHandler::onReceiveFinished(PendingOperation *op) +{ + PendingFileReceive *receiveOperation = qobject_cast<PendingFileReceive*>(op); + qDebug() << "Closing channel"; + receiveOperation->channel()->requestClose(); +} |