dataslave.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "dataslave.h"
00024 #include "dataprotocol.h"
00025
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028
00029 #include <qtimer.h>
00030
00031 using namespace KIO;
00032
00033 #define KIO_DATA_POLL_INTERVAL 0
00034
00035 DataSlave::DataSlave() :
00036 Slave(true, 0, "data", QString::null)
00037 {
00038 _suspended = false;
00039 timer = new QTimer(this);
00040 connect(timer, SIGNAL(timeout()), SLOT(dispatchNext()));
00041 timer->start(KIO_DATA_POLL_INTERVAL);
00042 }
00043
00044 DataSlave::~DataSlave() {
00045 }
00046
00047 void DataSlave::hold(const KURL &) {
00048
00049 }
00050
00051 void DataSlave::suspend() {
00052 _suspended = true;
00053 timer->stop();
00054 }
00055
00056 void DataSlave::resume() {
00057 _suspended = false;
00058 kdDebug() << this << k_funcinfo << endl;
00059
00060
00061
00062 timer->start(KIO_DATA_POLL_INTERVAL);
00063 }
00064
00065 void DataSlave::dispatchNext() {
00066 if (dispatchQueue.empty()) return;
00067
00068 const QueueStruct &q = dispatchQueue.front();
00069
00070 switch (q.type) {
00071 case QueueMimeType: mimeType(q.s); break;
00072 case QueueTotalSize: totalSize(q.size); break;
00073 case QueueSendMetaData: sendMetaData(); break;
00074 case QueueData: data(q.ba); break;
00075 case QueueFinished:
00076 finished();
00077 kill();
00078 emit slaveDied(this);
00079
00080 return;
00081 }
00082
00083 dispatchQueue.pop_front();
00084 }
00085
00086 void DataSlave::send(int cmd, const QByteArray &arr) {
00087 QDataStream stream(arr, IO_ReadOnly);
00088
00089 KURL url;
00090
00091 switch (cmd) {
00092 case CMD_GET: {
00093 stream >> url;
00094 get(url);
00095 break;
00096 }
00097 case CMD_MIMETYPE: {
00098 stream >> url;
00099 mimetype(url);
00100 break;
00101 }
00102
00103 case CMD_META_DATA:
00104 case CMD_SUBURL:
00105 break;
00106 default:
00107 error(ERR_UNSUPPORTED_ACTION,
00108 unsupportedActionErrorString(QString::fromLatin1("data"),cmd));
00109 }
00110 }
00111
00112 bool DataSlave::suspended() {
00113 return _suspended;
00114 }
00115
00116 void DataSlave::setHost(const QString &, int ,
00117 const QString &, const QString &) {
00118
00119 }
00120
00121 void DataSlave::setConfig(const MetaData &) {
00122
00123 #if 0
00124 QByteArray data;
00125 QDataStream stream( data, IO_WriteOnly );
00126 stream << config;
00127 slaveconn.send( CMD_CONFIG, data );
00128 #endif
00129 }
00130
00131 void DataSlave::setAllMetaData(const MetaData &md) {
00132 meta_data = md;
00133 }
00134
00135 void DataSlave::sendMetaData() {
00136 emit metaData(meta_data);
00137 }
00138
00139 void DataSlave::virtual_hook( int id, void* data ) {
00140 switch (id) {
00141 case VIRTUAL_SUSPEND: suspend(); return;
00142 case VIRTUAL_RESUME: resume(); return;
00143 case VIRTUAL_SEND: {
00144 SendParams *params = reinterpret_cast<SendParams *>(data);
00145 send(params->cmd, *params->arr);
00146 return;
00147 }
00148 case VIRTUAL_HOLD: {
00149 HoldParams *params = reinterpret_cast<HoldParams *>(data);
00150 hold(*params->url);
00151 return;
00152 }
00153 case VIRTUAL_SUSPENDED: {
00154 SuspendedParams *params = reinterpret_cast<SuspendedParams *>(data);
00155 params->retval = suspended();
00156 return;
00157 }
00158 case VIRTUAL_SET_HOST: {
00159 SetHostParams *params = reinterpret_cast<SetHostParams *>(data);
00160 setHost(*params->host,params->port,*params->user,*params->passwd);
00161 return;
00162 }
00163 case VIRTUAL_SET_CONFIG: {
00164 SetConfigParams *params = reinterpret_cast<SetConfigParams *>(data);
00165 setConfig(*params->config);
00166 return;
00167 }
00168 default:
00169 KIO::Slave::virtual_hook( id, data );
00170 }
00171 }
00172
00173 #include "dataslave.moc"
This file is part of the documentation for kio Library Version 3.3.1.