• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kio
 

kio/kio

  • kio
  • kio
forwardingslavebase.cpp
1 /* This file is part of the KDE project
2  Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <kdebug.h>
21 #include <kio/job.h>
22 #include <kmimetype.h>
23 #include <kprotocolinfo.h>
24 
25 #include <tqapplication.h>
26 #include <tqeventloop.h>
27 
28 #include "forwardingslavebase.h"
29 
30 namespace KIO
31 {
32 
33 class ForwardingSlaveBasePrivate
34 {
35 };
36 
37 ForwardingSlaveBase::ForwardingSlaveBase(const TQCString &protocol,
38  const TQCString &poolSocket,
39  const TQCString &appSocket)
40  : TQObject(), SlaveBase(protocol, poolSocket, appSocket)
41 {
42 }
43 
44 ForwardingSlaveBase::~ForwardingSlaveBase()
45 {
46 }
47 
48 bool ForwardingSlaveBase::internalRewriteURL(const KURL &url, KURL &newURL)
49 {
50  bool result = true;
51 
52  if ( url.protocol().ascii()==mProtocol )
53  {
54  result = rewriteURL(url, newURL);
55  }
56  else
57  {
58  newURL = url;
59  }
60 
61  m_processedURL = newURL;
62  m_requestedURL = url;
63  return result;
64 }
65 
66 void ForwardingSlaveBase::prepareUDSEntry(KIO::UDSEntry &entry,
67  bool listing) const
68 {
69  kdDebug() << "ForwardingSlaveBase::prepareUDSEntry: listing=="
70  << listing << endl;
71 
72  TQString name;
73  KURL url;
74 
75  KIO::UDSEntry::iterator it = entry.begin();
76  KIO::UDSEntry::iterator end = entry.end();
77 
78  for(; it!=end; ++it)
79  {
80  KURL new_url = m_requestedURL;
81 
82  switch( (*it).m_uds )
83  {
84  case KIO::UDS_NAME:
85  name = (*it).m_str;
86  kdDebug() << "Name = " << name << endl;
87  break;
88  case KIO::UDS_URL:
89  url = (*it).m_str;
90  if (listing)
91  {
92  new_url.addPath(url.fileName());
93  }
94  (*it).m_str = new_url.url();
95  kdDebug() << "URL = " << url << endl;
96  kdDebug() << "New URL = " << (*it).m_str << endl;
97  break;
98  }
99  }
100 
101  if ( m_processedURL.isLocalFile() )
102  {
103  KURL new_url = m_processedURL;
104  if (listing)
105  {
106  new_url.addPath( name );
107  }
108 
109  KIO::UDSAtom atom;
110  atom.m_uds = KIO::UDS_LOCAL_PATH;
111  atom.m_long = 0;
112  atom.m_str = new_url.path();
113  entry.append(atom);
114  }
115 }
116 
117 void ForwardingSlaveBase::get(const KURL &url)
118 {
119  kdDebug() << "ForwardingSlaveBase::get: " << url << endl;
120 
121  KURL new_url;
122  if ( internalRewriteURL(url, new_url) )
123  {
124  KIO::TransferJob *job = KIO::get(new_url, false, false);
125  connectTransferJob(job);
126 
127  tqApp->eventLoop()->enterLoop();
128  }
129 }
130 
131 void ForwardingSlaveBase::put(const KURL &url, int permissions,
132  bool overwrite, bool resume )
133 {
134  kdDebug() << "ForwardingSlaveBase::put: " << url << endl;
135 
136  KURL new_url;
137  if ( internalRewriteURL(url, new_url) )
138  {
139  KIO::TransferJob *job = KIO::put(new_url, permissions, overwrite,
140  resume, false);
141  connectTransferJob(job);
142 
143  tqApp->eventLoop()->enterLoop();
144  }
145 }
146 
147 void ForwardingSlaveBase::stat(const KURL &url)
148 {
149  kdDebug() << "ForwardingSlaveBase::stat: " << url << endl;
150 
151  KURL new_url;
152  if ( internalRewriteURL(url, new_url) )
153  {
154  KIO::SimpleJob *job = KIO::stat(new_url, false);
155  connectSimpleJob(job);
156 
157  tqApp->eventLoop()->enterLoop();
158  }
159 }
160 
161 void ForwardingSlaveBase::mimetype(const KURL &url)
162 {
163  kdDebug() << "ForwardingSlaveBase::mimetype: " << url << endl;
164 
165  KURL new_url;
166  if ( internalRewriteURL(url, new_url) )
167  {
168  KIO::TransferJob *job = KIO::mimetype(new_url, false);
169  connectTransferJob(job);
170 
171  tqApp->eventLoop()->enterLoop();
172  }
173 }
174 
175 void ForwardingSlaveBase::listDir(const KURL &url)
176 {
177  kdDebug() << "ForwardingSlaveBase::listDir: " << url << endl;
178 
179  KURL new_url;
180  if ( internalRewriteURL(url, new_url) )
181  {
182  KIO::ListJob *job = KIO::listDir(new_url, false);
183  connectListJob(job);
184 
185  tqApp->eventLoop()->enterLoop();
186  }
187 }
188 
189 void ForwardingSlaveBase::mkdir(const KURL &url, int permissions)
190 {
191  kdDebug() << "ForwardingSlaveBase::mkdir: " << url << endl;
192 
193  KURL new_url;
194  if ( internalRewriteURL(url, new_url) )
195  {
196  KIO::SimpleJob *job = KIO::mkdir(new_url, permissions);
197  connectSimpleJob(job);
198 
199  tqApp->eventLoop()->enterLoop();
200  }
201 }
202 
203 void ForwardingSlaveBase::rename(const KURL &src, const KURL &dest,
204  bool overwrite)
205 {
206  kdDebug() << "ForwardingSlaveBase::rename: " << src << ", " << dest << endl;
207 
208  KURL new_src, new_dest;
209  if ( internalRewriteURL(src, new_src) && internalRewriteURL(dest, new_dest) )
210  {
211  KIO::Job *job = KIO::rename(new_src, new_dest, overwrite);
212  connectJob(job);
213 
214  tqApp->eventLoop()->enterLoop();
215  }
216 }
217 
218 void ForwardingSlaveBase::symlink(const TQString &target, const KURL &dest,
219  bool overwrite)
220 {
221  kdDebug() << "ForwardingSlaveBase::symlink: " << target << ", " << dest << endl;
222 
223  KURL new_dest;
224  if ( internalRewriteURL(dest, new_dest) )
225  {
226  KIO::SimpleJob *job = KIO::symlink(target, new_dest, overwrite, false);
227  connectSimpleJob(job);
228 
229  tqApp->eventLoop()->enterLoop();
230  }
231 }
232 
233 void ForwardingSlaveBase::chmod(const KURL &url, int permissions)
234 {
235  kdDebug() << "ForwardingSlaveBase::chmod: " << url << endl;
236 
237  KURL new_url;
238  if ( internalRewriteURL(url, new_url) )
239  {
240  KIO::SimpleJob *job = KIO::chmod(new_url, permissions);
241  connectSimpleJob(job);
242 
243  tqApp->eventLoop()->enterLoop();
244  }
245 }
246 
247 void ForwardingSlaveBase::copy(const KURL &src, const KURL &dest,
248  int permissions, bool overwrite)
249 {
250  kdDebug() << "ForwardingSlaveBase::copy: " << src << ", " << dest << endl;
251 
252  KURL new_src, new_dest;
253  if ( internalRewriteURL(src, new_src) && internalRewriteURL(dest, new_dest) )
254  {
255  KIO::Job *job = KIO::file_copy(new_src, new_dest, permissions,
256  overwrite, false);
257  connectJob(job);
258 
259  tqApp->eventLoop()->enterLoop();
260  }
261 }
262 
263 void ForwardingSlaveBase::del(const KURL &url, bool isfile)
264 {
265  kdDebug() << "ForwardingSlaveBase::del: " << url << endl;
266 
267  KURL new_url;
268  if ( internalRewriteURL(url, new_url) )
269  {
270  if (isfile)
271  {
272  KIO::DeleteJob *job = KIO::del(new_url, false, false);
273  connectJob(job);
274  }
275  else
276  {
277  KIO::SimpleJob *job = KIO::rmdir(new_url);
278  connectSimpleJob(job);
279  }
280 
281  tqApp->eventLoop()->enterLoop();
282  }
283 }
284 
285 
287 
288 void ForwardingSlaveBase::connectJob(KIO::Job *job)
289 {
290  // We will forward the warning message, no need to let the job
291  // display it itself
292  job->setInteractive(false);
293 
294  // Forward metadata (e.g. modification time for put())
295  job->setMetaData( allMetaData() );
296 #if 0 // debug code
297  kdDebug() << k_funcinfo << "transferring metadata:" << endl;
298  const MetaData md = allMetaData();
299  for ( MetaData::const_iterator it = md.begin(); it != md.end(); ++it )
300  kdDebug() << it.key() << " = " << it.data() << endl;
301 #endif
302 
303  connect( job, TQT_SIGNAL( result(KIO::Job *) ),
304  this, TQT_SLOT( slotResult(KIO::Job *) ) );
305  connect( job, TQT_SIGNAL( warning(KIO::Job *, const TQString &) ),
306  this, TQT_SLOT( slotWarning(KIO::Job *, const TQString &) ) );
307  connect( job, TQT_SIGNAL( infoMessage(KIO::Job *, const TQString &) ),
308  this, TQT_SLOT( slotInfoMessage(KIO::Job *, const TQString &) ) );
309  connect( job, TQT_SIGNAL( totalSize(KIO::Job *, KIO::filesize_t) ),
310  this, TQT_SLOT( slotTotalSize(KIO::Job *, KIO::filesize_t) ) );
311  connect( job, TQT_SIGNAL( processedSize(KIO::Job *, KIO::filesize_t) ),
312  this, TQT_SLOT( slotProcessedSize(KIO::Job *, KIO::filesize_t) ) );
313  connect( job, TQT_SIGNAL( speed(KIO::Job *, unsigned long) ),
314  this, TQT_SLOT( slotSpeed(KIO::Job *, unsigned long) ) );
315 }
316 
317 void ForwardingSlaveBase::connectSimpleJob(KIO::SimpleJob *job)
318 {
319  connectJob(job);
320  connect( job, TQT_SIGNAL( redirection(KIO::Job *, const KURL &) ),
321  this, TQT_SLOT( slotRedirection(KIO::Job *, const KURL &) ) );
322 }
323 
324 void ForwardingSlaveBase::connectListJob(KIO::ListJob *job)
325 {
326  connectSimpleJob(job);
327  connect( job, TQT_SIGNAL( entries(KIO::Job *, const KIO::UDSEntryList &) ),
328  this, TQT_SLOT( slotEntries(KIO::Job *, const KIO::UDSEntryList &) ) );
329 }
330 
331 void ForwardingSlaveBase::connectTransferJob(KIO::TransferJob *job)
332 {
333  connectSimpleJob(job);
334  connect( job, TQT_SIGNAL( data(KIO::Job *, const TQByteArray &) ),
335  this, TQT_SLOT( slotData(KIO::Job *, const TQByteArray &) ) );
336  connect( job, TQT_SIGNAL( dataReq(KIO::Job *, TQByteArray &) ),
337  this, TQT_SLOT( slotDataReq(KIO::Job *, TQByteArray &) ) );
338  connect( job, TQT_SIGNAL( mimetype(KIO::Job *, const TQString &) ),
339  this, TQT_SLOT( slotMimetype(KIO::Job *, const TQString &) ) );
340  connect( job, TQT_SIGNAL( canResume(KIO::Job *, KIO::filesize_t) ),
341  this, TQT_SLOT( slotCanResume(KIO::Job *, KIO::filesize_t) ) );
342 }
343 
345 
346 void ForwardingSlaveBase::slotResult(KIO::Job *job)
347 {
348  if ( job->error() != 0)
349  {
350  error( job->error(), job->errorText() );
351  }
352  else
353  {
354  KIO::StatJob *stat_job = dynamic_cast<KIO::StatJob *>(job);
355  if ( stat_job!=0L )
356  {
357  KIO::UDSEntry entry = stat_job->statResult();
358  prepareUDSEntry(entry);
359  statEntry( entry );
360  }
361  finished();
362  }
363 
364  tqApp->eventLoop()->exitLoop();
365 }
366 
367 void ForwardingSlaveBase::slotWarning(KIO::Job* /*job*/, const TQString &msg)
368 {
369  warning(msg);
370 }
371 
372 void ForwardingSlaveBase::slotInfoMessage(KIO::Job* /*job*/, const TQString &msg)
373 {
374  infoMessage(msg);
375 }
376 
377 void ForwardingSlaveBase::slotTotalSize(KIO::Job* /*job*/, KIO::filesize_t size)
378 {
379  totalSize(size);
380 }
381 
382 void ForwardingSlaveBase::slotProcessedSize(KIO::Job* /*job*/, KIO::filesize_t size)
383 {
384  processedSize(size);
385 }
386 
387 void ForwardingSlaveBase::slotSpeed(KIO::Job* /*job*/, unsigned long bytesPerSecond)
388 {
389  speed(bytesPerSecond);
390 }
391 
392 void ForwardingSlaveBase::slotRedirection(KIO::Job *job, const KURL &url)
393 {
394  redirection(url);
395 
396  // We've been redirected stop everything.
397  job->kill( true );
398  finished();
399 
400  tqApp->eventLoop()->exitLoop();
401 }
402 
403 void ForwardingSlaveBase::slotEntries(KIO::Job* /*job*/,
404  const KIO::UDSEntryList &entries)
405 {
406  KIO::UDSEntryList final_entries = entries;
407 
408  KIO::UDSEntryList::iterator it = final_entries.begin();
409  KIO::UDSEntryList::iterator end = final_entries.end();
410 
411  for(; it!=end; ++it)
412  {
413  prepareUDSEntry(*it, true);
414  }
415 
416  listEntries( final_entries );
417 }
418 
419 void ForwardingSlaveBase::slotData(KIO::Job* /*job*/, const TQByteArray &d)
420 {
421  data(d);
422 }
423 
424 void ForwardingSlaveBase::slotDataReq(KIO::Job* /*job*/, TQByteArray &data)
425 {
426  dataReq();
427  readData(data);
428 }
429 
430 void ForwardingSlaveBase::slotMimetype (KIO::Job* /*job*/, const TQString &type)
431 {
432  mimeType(type);
433 }
434 
435 void ForwardingSlaveBase::slotCanResume (KIO::Job* /*job*/, KIO::filesize_t offset)
436 {
437  canResume(offset);
438 }
439 
440 }
441 
442 #include "forwardingslavebase.moc"
443 

kio/kio

Skip menu "kio/kio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |