1 /* 2 Kopete Groupwise Protocol 3 requesttask.cpp - Ancestor of all tasks that carry out a user request 4 5 Copyright (c) 2004 SUSE Linux AG http://www.suse.com 6 7 Based on Iris, Copyright (C) 2003 Justin Karneges <justin@affinix.com> 8 9 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> 10 11 ************************************************************************* 12 * * 13 * This library is free software; you can redistribute it and/or * 14 * modify it under the terms of the GNU Lesser General Public * 15 * License as published by the Free Software Foundation; either * 16 * version 2 of the License, or (at your option) any later version. * 17 * * 18 ************************************************************************* 19 */ 20 21 #include "requesttask.h" 22 23 #include "gwfield.h" 24 #include "client.h" 25 #include "request.h" 26 #include "response.h" 27 #include "requestfactory.h" 28 RequestTask(Task * parent)29RequestTask::RequestTask(Task *parent) 30 : Task(parent) 31 { 32 } 33 forMe(const Transfer * transfer) const34bool RequestTask::forMe(const Transfer *transfer) const 35 { 36 // see if we can down-cast transfer to a Response 37 const Response *theResponse = dynamic_cast<const Response *>(transfer); 38 return theResponse && theResponse->transactionId() == m_transactionId; 39 } 40 createTransfer(const QString & command,const Field::FieldList & fields)41void RequestTask::createTransfer(const QString &command, const Field::FieldList &fields) 42 { 43 Request *request = client()->requestFactory()->request(command); 44 m_transactionId = request->transactionId(); 45 request->setFields(fields); 46 Task::setTransfer(request); 47 } 48 onGo()49void RequestTask::onGo() 50 { 51 if (transfer()) { 52 client()->debug(QStringLiteral("%1::onGo() - sending %2 fields").arg(metaObject()->className()).arg(static_cast<Request *>(transfer())->command())); 53 send(static_cast<Request *>(transfer())); 54 } else { 55 client()->debug(QStringLiteral("RequestTask::onGo() - called prematurely, no transfer set.")); 56 } 57 } 58 take(Transfer * transfer)59bool RequestTask::take(Transfer *transfer) 60 { 61 if (forMe(transfer)) { 62 client()->debug(QStringLiteral("RequestTask::take() - Default take() Accepting transaction ack, taking no further action")); 63 Response *response = dynamic_cast<Response *>(transfer); 64 if (response->resultCode() == GroupWise::None) { 65 setSuccess(); 66 } else { 67 setError(response->resultCode()); 68 } 69 return true; 70 } else { 71 return false; 72 } 73 } 74