diff options
Diffstat (limited to 'kopete/protocols/yahoo/libkyahoo/sendpicturetask.cpp')
-rw-r--r-- | kopete/protocols/yahoo/libkyahoo/sendpicturetask.cpp | 116 |
1 files changed, 67 insertions, 49 deletions
diff --git a/kopete/protocols/yahoo/libkyahoo/sendpicturetask.cpp b/kopete/protocols/yahoo/libkyahoo/sendpicturetask.cpp index c1b1f5f0..84edecaa 100644 --- a/kopete/protocols/yahoo/libkyahoo/sendpicturetask.cpp +++ b/kopete/protocols/yahoo/libkyahoo/sendpicturetask.cpp @@ -2,7 +2,7 @@ Kopete Yahoo Protocol sendpicturetask.cpp - Send our picture or information about it - Copyright (c) 2005 André Duffeck <andre.duffeck@kdemail.net> + Copyright (c) 2005 André Duffeck <duffeck@kde.org> ************************************************************************* * * @@ -21,7 +21,6 @@ #include "client.h" #include <qstring.h> #include <qfile.h> -#include <qcstring.h> #include <qdatastream.h> #include <kio/global.h> #include <kio/job.h> @@ -34,7 +33,7 @@ using namespace KNetwork; SendPictureTask::SendPictureTask(Task* parent) : Task(parent) { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl; + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; m_socket = 0; } @@ -55,6 +54,7 @@ void SendPictureTask::onGo() break; case SendInformation: sendInformation(); + break; case SendStatus: sendStatus(); break; @@ -62,26 +62,27 @@ void SendPictureTask::onGo() } void SendPictureTask::initiateUpload() -{ - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl; +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; m_socket = new KBufferedSocket( "filetransfer.msg.yahoo.com", QString::number(80) ); connect( m_socket, SIGNAL( connected( const KResolverEntry& ) ), this, SLOT( connectSucceeded() ) ); connect( m_socket, SIGNAL( gotError(int) ), this, SLOT( connectFailed(int) ) ); + connect( m_socket, SIGNAL( readyRead() ), this, SLOT( readResult() ) ); m_socket->connect(); } void SendPictureTask::connectFailed( int i) { - m_socket->close(); - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << i << ": " << static_cast<const KBufferedSocket*>( sender() )->errorString() << endl; + kdDebug(YAHOO_RAW_DEBUG) << i << ": " << static_cast<const KBufferedSocket*>( sender() )->errorString() << endl; + client()->notifyError(i18n("The picture was not successfully uploaded"), QString("%1 - %2").arg(i).arg(static_cast<const KBufferedSocket*>( sender() )->errorString()), Client::Error ); - setSuccess( false ); + setError(); } void SendPictureTask::connectSucceeded() { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl; + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; YMSGTransfer t(Yahoo::ServicePictureUpload); QFile file( m_path ); @@ -90,26 +91,26 @@ void SendPictureTask::connectSucceeded() t.setParam( 1, client()->userId().local8Bit()); t.setParam( 38, 604800); t.setParam( 0, client()->userId().local8Bit()); - t.setParam( 28, file.size() ); + t.setParam( 28, file.size() ); t.setParam( 27, m_fileName.local8Bit() ); t.setParam( 14, "" ); QByteArray buffer; QByteArray paket; QDataStream stream( buffer, IO_WriteOnly ); - if ( file.open(IO_ReadOnly ) ) + if ( file.open( IO_ReadOnly ) ) { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "File successfully opened. Reading..." << endl; + kdDebug(YAHOO_RAW_DEBUG) << "File successfully opened. Reading..." << endl; } else { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Error opening file: " << file.errorString() << endl; + kdDebug(YAHOO_RAW_DEBUG) << "Error opening file: " << file.errorString() << endl; client()->notifyError(i18n("Error opening file: %1").arg(m_path), file.errorString(), Client::Error ); return; } paket = t.serialize(); - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Sizes: File (" << m_path << "): " << file.size() << " - paket: " << paket.size() << endl; + kdDebug(YAHOO_RAW_DEBUG) << "Sizes: File (" << m_path << "): " << file.size() << " - paket: " << paket.size() << endl; QString header = QString::fromLatin1("POST /notifyft HTTP/1.1\r\n" "Cookie: Y=%1; T=%2; C=%3 ;\r\n" "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n" @@ -121,43 +122,62 @@ void SendPictureTask::connectSucceeded() stream << (Q_INT8)0x32 << (Q_INT8)0x39 << (Q_INT8)0xc0 << (Q_INT8)0x80; stream.writeRawBytes( file.readAll(), file.size() ); - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Buffersize: " << buffer.size() << endl; + kdDebug(YAHOO_RAW_DEBUG) << "Buffersize: " << buffer.size() << endl; if( m_socket->writeBlock( buffer, buffer.size() ) ) { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Upload Successful." << endl; - connect( m_socket, SIGNAL( readyRead() ), this, SLOT( readResult() ) ); + kdDebug(YAHOO_RAW_DEBUG) << "Upload Successful!" << endl; + m_socket->enableRead( true ); +// setSuccess(); } else { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Upload Failed." << endl; - m_socket->close(); - setSuccess( false ); + kdDebug(YAHOO_RAW_DEBUG) << "Upload Failed!" << endl; + setError(); } } void SendPictureTask::readResult() { + kdDebug(YAHOO_RAW_DEBUG) << m_socket->bytesAvailable() << endl; + + // FIXME: to check +// m_socket->enableRead( false ); +// QByteArray buf; +// buf.resize( m_socket->bytesAvailable() ); +// m_socket->read( buf.data(), m_socket->bytesAvailable() ); +// +// if( buf.indexOf( "error", 0 ) >= 0 ) +// { +// kdDebug(YAHOO_RAW_DEBUG) << "Picture upload failed" << endl; +// setError(); +// } +// else +// { +// kdDebug(YAHOO_RAW_DEBUG) << "Picture upload acknowledged." << endl; +// setSuccess(); +// } + + // from original file QByteArray ar( m_socket->bytesAvailable() ); - m_socket->readBlock ( ar.data (), ar.size () ); - QString buf( ar ); - - m_socket->close(); - if( buf.find( "error", 0, false ) >= 0 ) - { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Picture upload failed" << endl; - setSuccess( false ); - } - else - { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Picture upload acknowledged." << endl; - setSuccess( true ); - } - + m_socket->readBlock ( ar.data (), ar.size () ); + QString buf( ar ); + + m_socket->close(); + if( buf.find( "error", 0, false ) >= 0 ) + { + kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Picture upload failed" << endl; + setSuccess( false ); + } + else + { + kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Picture upload acknowledged." << endl; + setSuccess( true ); + } } void SendPictureTask::sendChecksum() { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl; + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; YMSGTransfer *t = new YMSGTransfer(Yahoo::ServicePictureChecksum); t->setId( client()->sessionID() ); @@ -167,41 +187,39 @@ void SendPictureTask::sendChecksum() t->setParam(192, m_checksum); t->setParam(212, 1); send( t ); - - setSuccess( true ); + + setSuccess(); } void SendPictureTask::sendInformation() { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl; + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; YMSGTransfer *t = new YMSGTransfer(Yahoo::ServicePicture); t->setId( client()->sessionID() ); t->setParam(1, client()->userId().local8Bit()); - t->setParam(4, client()->userId().local8Bit()); t->setParam(13, 2 ); t->setParam(5, m_target.local8Bit() ); t->setParam(20, m_url.local8Bit() ); t->setParam(192, m_checksum); send( t ); - - setSuccess( true ); + + setSuccess(); } void SendPictureTask::sendStatus() { - kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl; + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; - YMSGTransfer *t = new YMSGTransfer(Yahoo::ServicePictureUpdate); + YMSGTransfer *t = new YMSGTransfer(Yahoo::ServicePictureStatus); t->setId( client()->sessionID() ); - t->setParam(1, client()->userId().local8Bit()); - t->setParam(5, m_target.local8Bit() ); - t->setParam(206, m_status ); + t->setParam(3, client()->userId().local8Bit()); + t->setParam(213, m_status ); send( t ); - - setSuccess( true ); + + setSuccess(); } void SendPictureTask::setType( Type type ) |