00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "storedtransferjob.h"
00021
00022
using namespace KIOext;
00023
00024
#define KIO_ARGS QByteArray packedArgs; QDataStream stream( packedArgs, IO_WriteOnly ); stream
00025
00026 StoredTransferJob::StoredTransferJob(
const KURL& url,
int command,
00027
const QByteArray &packedArgs,
00028
const QByteArray &_staticData,
00029
bool showProgressInfo)
00030 : KIO::TransferJob( url, command, packedArgs, _staticData, showProgressInfo ),
00031 m_uploadOffset( 0 )
00032 {
00033 connect(
this, SIGNAL(
data( KIO::Job *,
const QByteArray & ) ),
00034 SLOT( slotData( KIO::Job *,
const QByteArray & ) ) );
00035 connect(
this, SIGNAL( dataReq( KIO::Job *,
QByteArray & ) ),
00036 SLOT( slotDataReq( KIO::Job *,
QByteArray & ) ) );
00037 }
00038
00039 void StoredTransferJob::setData(
const QByteArray& arr )
00040 {
00041 Q_ASSERT( m_data.isNull() );
00042 Q_ASSERT( m_uploadOffset == 0 );
00043 m_data = arr;
00044 }
00045
00046
void StoredTransferJob::slotData( KIO::Job *,
const QByteArray &data )
00047 {
00048
00049
if ( data.size() == 0 )
00050
return;
00051
unsigned int oldSize = m_data.size();
00052 m_data.resize( oldSize + data.size(), QGArray::SpeedOptim );
00053 memcpy( m_data.data() + oldSize, data.data(), data.size() );
00054 }
00055
00056
void StoredTransferJob::slotDataReq( KIO::Job *,
QByteArray &data )
00057 {
00058
00059
00060
const int MAX_CHUNK_SIZE = 64*1024;
00061
int remainingBytes = m_data.size() - m_uploadOffset;
00062
if( remainingBytes > MAX_CHUNK_SIZE ) {
00063
00064 data.duplicate( m_data.data() + m_uploadOffset, MAX_CHUNK_SIZE );
00065 m_uploadOffset += MAX_CHUNK_SIZE;
00066
00067
00068 }
else {
00069
00070 data.duplicate( m_data.data() + m_uploadOffset, remainingBytes );
00071 m_data =
QByteArray();
00072 m_uploadOffset = 0;
00073
00074 }
00075 }
00076
00078
00079
StoredTransferJob *KIOext::storedGet(
const KURL& url,
bool reload,
bool showProgressInfo )
00080 {
00081
00082 KIO_ARGS << url;
00083
StoredTransferJob * job =
new StoredTransferJob( url, KIO::CMD_GET, packedArgs,
QByteArray(), showProgressInfo );
00084
if (reload)
00085 job->addMetaData(
"cache",
"reload");
00086
return job;
00087 }
00088
00089 StoredTransferJob *KIOext::put(
const QByteArray& arr,
const KURL& url,
int permissions,
00090
bool overwrite,
bool resume,
bool showProgressInfo )
00091 {
00092 KIO_ARGS << url << Q_INT8( overwrite ? 1 : 0 ) << Q_INT8( resume ? 1 : 0 ) << permissions;
00093 StoredTransferJob * job =
new StoredTransferJob( url, KIO::CMD_PUT, packedArgs,
QByteArray(), showProgressInfo );
00094 job->
setData( arr );
00095
return job;
00096 }
00097
00098
#include "storedtransferjob.moc"