TDE personal information management applications
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

transport.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. This file is part of KDE.
  3. Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. As a special exception, permission is given to link this program
  16. with any edition of TQt, and distribute the resulting executable,
  17. without including the source code for TQt in the source distribution.
  18. */
  19. #include "transport.h"
  20. #include <kdebug.h>
  21. Transport::Transport( const TQString &url )
  22. {
  23. mUrl = url;
  24. }
  25. void Transport::query( const TQString &xml )
  26. {
  27. mData.truncate( 0 );
  28. TQByteArray postData;
  29. TQDataStream stream( postData, IO_WriteOnly );
  30. stream.writeRawBytes( xml.utf8(), xml.utf8().length() );
  31. TDEIO::TransferJob* job = TDEIO::http_post( KURL( mUrl ), postData, false );
  32. if ( !job ) {
  33. kdWarning() << "Unable to create TDEIO job for " << mUrl << endl;
  34. return;
  35. }
  36. job->addMetaData( "UserAgent", "KWSDL" );
  37. job->addMetaData( "content-type", "Content-Type: text/xml; charset=utf-8" );
  38. connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), this, TQT_SLOT( slotData( TDEIO::Job*, const TQByteArray& ) ) );
  39. connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) );
  40. }
  41. void Transport::slotData( TDEIO::Job*, const TQByteArray &data )
  42. {
  43. unsigned int oldSize = mData.size();
  44. mData.resize( oldSize + data.size() );
  45. memcpy( mData.data() + oldSize, data.data(), data.size() );
  46. }
  47. void Transport::slotResult( TDEIO::Job* job )
  48. {
  49. if ( job->error() != 0 ) {
  50. kdWarning() << "Error occurred " << job->errorText() << endl;
  51. kdWarning() << mData << endl;
  52. return;
  53. }
  54. emit result( TQString::fromUtf8( mData.data(), mData.size() ) );
  55. }
  56. #include "transport.moc"