• 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  bool url_found = false;
73  TQString name;
74  KURL url;
75 
76  KIO::UDSEntry::iterator it = entry.begin();
77  KIO::UDSEntry::iterator end = entry.end();
78 
79  for(; it!=end; ++it)
80  {
81  KURL new_url = m_requestedURL;
82 
83  switch( (*it).m_uds )
84  {
85  case KIO::UDS_NAME:
86  name = (*it).m_str;
87  kdDebug() << "Name = " << name << endl;
88  break;
89  case KIO::UDS_URL:
90  url_found = true;
91  url = (*it).m_str;
92  if (listing)
93  {
94  new_url.addPath(url.fileName());
95  }
96  (*it).m_str = new_url.url();
97  kdDebug() << "URL = " << url << endl;
98  kdDebug() << "New URL = " << (*it).m_str << endl;
99  break;
100  }
101  }
102 
103  if ( m_processedURL.isLocalFile() )
104  {
105  KURL new_url = m_processedURL;
106  if (listing)
107  {
108  new_url.addPath( name );
109  }
110 
111  KIO::UDSAtom atom;
112  atom.m_uds = KIO::UDS_LOCAL_PATH;
113  atom.m_long = 0;
114  atom.m_str = new_url.path();
115  entry.append(atom);
116  }
117 }
118 
119 void ForwardingSlaveBase::get(const KURL &url)
120 {
121  kdDebug() << "ForwardingSlaveBase::get: " << url << endl;
122 
123  KURL new_url;
124  if ( internalRewriteURL(url, new_url) )
125  {
126  KIO::TransferJob *job = KIO::get(new_url, false, false);
127  connectTransferJob(job);
128 
129  tqApp->eventLoop()->enterLoop();
130  }
131 }
132 
133 void ForwardingSlaveBase::put(const KURL &url, int permissions,
134  bool overwrite, bool resume )
135 {
136  kdDebug() << "ForwardingSlaveBase::put: " << url << endl;
137 
138  KURL new_url;
139  if ( internalRewriteURL(url, new_url) )
140  {
141  KIO::TransferJob *job = KIO::put(new_url, permissions, overwrite,
142  resume, false);
143  connectTransferJob(job);
144 
145  tqApp->eventLoop()->enterLoop();
146  }
147 }
148 
149 void ForwardingSlaveBase::stat(const KURL &url)
150 {
151  kdDebug() << "ForwardingSlaveBase::stat: " << url << endl;
152 
153  KURL new_url;
154  if ( internalRewriteURL(url, new_url) )
155  {
156  KIO::SimpleJob *job = KIO::stat(new_url, false);
157  connectSimpleJob(job);
158 
159  tqApp->eventLoop()->enterLoop();
160  }
161 }
162 
163 void ForwardingSlaveBase::mimetype(const KURL &url)
164 {
165  kdDebug() << "ForwardingSlaveBase::mimetype: " << url << endl;
166 
167  KURL new_url;
168  if ( internalRewriteURL(url, new_url) )
169  {
170  KIO::TransferJob *job = KIO::mimetype(new_url, false);
171  connectTransferJob(job);
172 
173  tqApp->eventLoop()->enterLoop();
174  }
175 }
176 
177 void ForwardingSlaveBase::listDir(const KURL &url)
178 {
179  kdDebug() << "ForwardingSlaveBase::listDir: " << url << endl;
180 
181  KURL new_url;
182  if ( internalRewriteURL(url, new_url) )
183  {
184  KIO::ListJob *job = KIO::listDir(new_url, false);
185  connectListJob(job);
186 
187  tqApp->eventLoop()->enterLoop();
188  }
189 }
190 
191 void ForwardingSlaveBase::mkdir(const KURL &url, int permissions)
192 {
193  kdDebug() << "ForwardingSlaveBase::mkdir: " << url << endl;
194 
195  KURL new_url;
196  if ( internalRewriteURL(url, new_url) )
197  {
198  KIO::SimpleJob *job = KIO::mkdir(new_url, permissions);
199  connectSimpleJob(job);
200 
201  tqApp->eventLoop()->enterLoop();
202  }
203 }
204 
205 void ForwardingSlaveBase::rename(const KURL &src, const KURL &dest,
206  bool overwrite)
207 {
208  kdDebug() << "ForwardingSlaveBase::rename: " << src << ", " << dest << endl;
209 
210  KURL new_src, new_dest;
211  if ( internalRewriteURL(src, new_src) && internalRewriteURL(dest, new_dest) )
212  {
213  KIO::Job *job = KIO::rename(new_src, new_dest, overwrite);
214  connectJob(job);
215 
216  tqApp->eventLoop()->enterLoop();
217  }
218 }
219 
220 void ForwardingSlaveBase::symlink(const TQString &target, const KURL &dest,
221  bool overwrite)
222 {
223  kdDebug() << "ForwardingSlaveBase::symlink: " << target << ", " << dest << endl;
224 
225  KURL new_dest;
226  if ( internalRewriteURL(dest, new_dest) )
227  {
228  KIO::SimpleJob *job = KIO::symlink(target, new_dest, overwrite, false);
229  connectSimpleJob(job);
230 
231  tqApp->eventLoop()->enterLoop();
232  }
233 }
234 
235 void ForwardingSlaveBase::chmod(const KURL &url, int permissions)
236 {
237  kdDebug() << "ForwardingSlaveBase::chmod: " << url << endl;
238 
239  KURL new_url;
240  if ( internalRewriteURL(url, new_url) )
241  {
242  KIO::SimpleJob *job = KIO::chmod(new_url, permissions);
243  connectSimpleJob(job);
244 
245  tqApp->eventLoop()->enterLoop();
246  }
247 }
248 
249 void ForwardingSlaveBase::copy(const KURL &src, const KURL &dest,
250  int permissions, bool overwrite)
251 {
252  kdDebug() << "ForwardingSlaveBase::copy: " << src << ", " << dest << endl;
253 
254  KURL new_src, new_dest;
255  if ( internalRewriteURL(src, new_src) && internalRewriteURL(dest, new_dest) )
256  {
257  KIO::Job *job = KIO::file_copy(new_src, new_dest, permissions,
258  overwrite, false);
259  connectJob(job);
260 
261  tqApp->eventLoop()->enterLoop();
262  }
263 }
264 
265 void ForwardingSlaveBase::del(const KURL &url, bool isfile)
266 {
267  kdDebug() << "ForwardingSlaveBase::del: " << url << endl;
268 
269  KURL new_url;
270  if ( internalRewriteURL(url, new_url) )
271  {
272  if (isfile)
273  {
274  KIO::DeleteJob *job = KIO::del(new_url, false, false);
275  connectJob(job);
276  }
277  else
278  {
279  KIO::SimpleJob *job = KIO::rmdir(new_url);
280  connectSimpleJob(job);
281  }
282 
283  tqApp->eventLoop()->enterLoop();
284  }
285 }
286 
287 
289 
290 void ForwardingSlaveBase::connectJob(KIO::Job *job)
291 {
292  // We will forward the warning message, no need to let the job
293  // display it itself
294  job->setInteractive(false);
295 
296  // Forward metadata (e.g. modification time for put())
297  job->setMetaData( allMetaData() );
298 #if 0 // debug code
299  kdDebug() << k_funcinfo << "transferring metadata:" << endl;
300  const MetaData md = allMetaData();
301  for ( MetaData::const_iterator it = md.begin(); it != md.end(); ++it )
302  kdDebug() << it.key() << " = " << it.data() << endl;
303 #endif
304 
305  connect( job, TQT_SIGNAL( result(KIO::Job *) ),
306  this, TQT_SLOT( slotResult(KIO::Job *) ) );
307  connect( job, TQT_SIGNAL( warning(KIO::Job *, const TQString &) ),
308  this, TQT_SLOT( slotWarning(KIO::Job *, const TQString &) ) );
309  connect( job, TQT_SIGNAL( infoMessage(KIO::Job *, const TQString &) ),
310  this, TQT_SLOT( slotInfoMessage(KIO::Job *, const TQString &) ) );
311  connect( job, TQT_SIGNAL( totalSize(KIO::Job *, KIO::filesize_t) ),
312  this, TQT_SLOT( slotTotalSize(KIO::Job *, KIO::filesize_t) ) );
313  connect( job, TQT_SIGNAL( processedSize(KIO::Job *, KIO::filesize_t) ),
314  this, TQT_SLOT( slotProcessedSize(KIO::Job *, KIO::filesize_t) ) );
315  connect( job, TQT_SIGNAL( speed(KIO::Job *, unsigned long) ),
316  this, TQT_SLOT( slotSpeed(KIO::Job *, unsigned long) ) );
317 }
318 
319 void ForwardingSlaveBase::connectSimpleJob(KIO::SimpleJob *job)
320 {
321  connectJob(job);
322  connect( job, TQT_SIGNAL( redirection(KIO::Job *, const KURL &) ),
323  this, TQT_SLOT( slotRedirection(KIO::Job *, const KURL &) ) );
324 }
325 
326 void ForwardingSlaveBase::connectListJob(KIO::ListJob *job)
327 {
328  connectSimpleJob(job);
329  connect( job, TQT_SIGNAL( entries(KIO::Job *, const KIO::UDSEntryList &) ),
330  this, TQT_SLOT( slotEntries(KIO::Job *, const KIO::UDSEntryList &) ) );
331 }
332 
333 void ForwardingSlaveBase::connectTransferJob(KIO::TransferJob *job)
334 {
335  connectSimpleJob(job);
336  connect( job, TQT_SIGNAL( data(KIO::Job *, const TQByteArray &) ),
337  this, TQT_SLOT( slotData(KIO::Job *, const TQByteArray &) ) );
338  connect( job, TQT_SIGNAL( dataReq(KIO::Job *, TQByteArray &) ),
339  this, TQT_SLOT( slotDataReq(KIO::Job *, TQByteArray &) ) );
340  connect( job, TQT_SIGNAL( mimetype(KIO::Job *, const TQString &) ),
341  this, TQT_SLOT( slotMimetype(KIO::Job *, const TQString &) ) );
342  connect( job, TQT_SIGNAL( canResume(KIO::Job *, KIO::filesize_t) ),
343  this, TQT_SLOT( slotCanResume(KIO::Job *, KIO::filesize_t) ) );
344 }
345 
347 
348 void ForwardingSlaveBase::slotResult(KIO::Job *job)
349 {
350  if ( job->error() != 0)
351  {
352  error( job->error(), job->errorText() );
353  }
354  else
355  {
356  KIO::StatJob *stat_job = dynamic_cast<KIO::StatJob *>(job);
357  if ( stat_job!=0L )
358  {
359  KIO::UDSEntry entry = stat_job->statResult();
360  prepareUDSEntry(entry);
361  statEntry( entry );
362  }
363  finished();
364  }
365 
366  tqApp->eventLoop()->exitLoop();
367 }
368 
369 void ForwardingSlaveBase::slotWarning(KIO::Job* /*job*/, const TQString &msg)
370 {
371  warning(msg);
372 }
373 
374 void ForwardingSlaveBase::slotInfoMessage(KIO::Job* /*job*/, const TQString &msg)
375 {
376  infoMessage(msg);
377 }
378 
379 void ForwardingSlaveBase::slotTotalSize(KIO::Job* /*job*/, KIO::filesize_t size)
380 {
381  totalSize(size);
382 }
383 
384 void ForwardingSlaveBase::slotProcessedSize(KIO::Job* /*job*/, KIO::filesize_t size)
385 {
386  processedSize(size);
387 }
388 
389 void ForwardingSlaveBase::slotSpeed(KIO::Job* /*job*/, unsigned long bytesPerSecond)
390 {
391  speed(bytesPerSecond);
392 }
393 
394 void ForwardingSlaveBase::slotRedirection(KIO::Job *job, const KURL &url)
395 {
396  redirection(url);
397 
398  // We've been redirected stop everything.
399  job->kill( true );
400  finished();
401 
402  tqApp->eventLoop()->exitLoop();
403 }
404 
405 void ForwardingSlaveBase::slotEntries(KIO::Job* /*job*/,
406  const KIO::UDSEntryList &entries)
407 {
408  KIO::UDSEntryList final_entries = entries;
409 
410  KIO::UDSEntryList::iterator it = final_entries.begin();
411  KIO::UDSEntryList::iterator end = final_entries.end();
412 
413  for(; it!=end; ++it)
414  {
415  prepareUDSEntry(*it, true);
416  }
417 
418  listEntries( final_entries );
419 }
420 
421 void ForwardingSlaveBase::slotData(KIO::Job* /*job*/, const TQByteArray &d)
422 {
423  data(d);
424 }
425 
426 void ForwardingSlaveBase::slotDataReq(KIO::Job* /*job*/, TQByteArray &data)
427 {
428  dataReq();
429  readData(data);
430 }
431 
432 void ForwardingSlaveBase::slotMimetype (KIO::Job* /*job*/, const TQString &type)
433 {
434  mimeType(type);
435 }
436 
437 void ForwardingSlaveBase::slotCanResume (KIO::Job* /*job*/, KIO::filesize_t offset)
438 {
439  canResume(offset);
440 }
441 
442 }
443 
444 #include "forwardingslavebase.moc"
445 

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.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |