TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transport.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. This file is part of Kung.
  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. */
  16. #include "transport.h"
  17. #include <kdebug.h>
  18. Transport::Transport( const TQString &url )
  19. {
  20. mUrl = url;
  21. tqDebug( "url=%s", url.latin1() );
  22. }
  23. void Transport::query( const TQString &xml )
  24. {
  25. mData.truncate( 0 );
  26. TQByteArray postData;
  27. TQDataStream stream( postData, IO_WriteOnly );
  28. stream.writeRawBytes( xml.utf8(), xml.utf8().length() );
  29. TDEIO::TransferJob* job = TDEIO::http_post( KURL( mUrl ), postData, false );
  30. if ( !job ) {
  31. kdWarning() << "Unable to create TDEIO job for " << mUrl << endl;
  32. return;
  33. }
  34. job->addMetaData( "UserAgent", "KDE Kung" );
  35. job->addMetaData( "content-type", "Content-Type: text/xml; charset=utf-8" );
  36. connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), this, TQT_SLOT( slotData( TDEIO::Job*, const TQByteArray& ) ) );
  37. connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) );
  38. }
  39. void Transport::slotData( TDEIO::Job*, const TQByteArray &data )
  40. {
  41. unsigned int oldSize = mData.size();
  42. mData.resize( oldSize + data.size() );
  43. memcpy( mData.data() + oldSize, data.data(), data.size() );
  44. }
  45. void Transport::slotResult( TDEIO::Job* job )
  46. {
  47. if ( job->error() != 0 )
  48. emit error( job->errorText() );
  49. else
  50. emit result( TQString::fromUtf8( mData.data(), mData.size() ) );
  51. }
  52. #include "transport.moc"