• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • kio
job.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
3  2000-2009 David Faure <faure@kde.org>
4  Waldo Bastian <bastian@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "job.h"
23 #include "job_p.h"
24 #include "clipboardupdater_p.h"
25 
26 #include <config.h>
27 
28 #include <sys/types.h>
29 #include <sys/wait.h>
30 #include <sys/stat.h>
31 
32 #include <signal.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <time.h>
36 #include <unistd.h>
37 extern "C" {
38 #include <pwd.h>
39 #include <grp.h>
40 }
41 #include <QtCore/QTimer>
42 #include <QtCore/QFile>
43 
44 #include <kauthorized.h>
45 #include <klocale.h>
46 #include <kconfig.h>
47 #include <kdebug.h>
48 #include <kde_file.h>
49 
50 #include <errno.h>
51 
52 #include "jobuidelegate.h"
53 #include "kmimetype.h"
54 #include "slave.h"
55 #include "scheduler.h"
56 #include "kdirwatch.h"
57 #include "kprotocolinfo.h"
58 #include "kprotocolmanager.h"
59 #include "filejob.h"
60 
61 #include <kdirnotify.h>
62 #include <ktemporaryfile.h>
63 
64 using namespace KIO;
65 
66 #define MAX_READ_BUF_SIZE (64 * 1024) // 64 KB at a time seems reasonable...
67 
68 static inline Slave *jobSlave(SimpleJob *job)
69 {
70  return SimpleJobPrivate::get(job)->m_slave;
71 }
72 
73 //this will update the report dialog with 5 Hz, I think this is fast enough, aleXXX
74 #define REPORT_TIMEOUT 200
75 
76 Job::Job() : KCompositeJob(*new JobPrivate, 0)
77 {
78  setCapabilities( KJob::Killable | KJob::Suspendable );
79 }
80 
81 Job::Job(JobPrivate &dd) : KCompositeJob(dd, 0)
82 {
83  setCapabilities( KJob::Killable | KJob::Suspendable );
84 }
85 
86 Job::~Job()
87 {
88 }
89 
90 JobUiDelegate *Job::ui() const
91 {
92  return static_cast<JobUiDelegate*>( uiDelegate() );
93 }
94 
95 bool Job::addSubjob(KJob *jobBase)
96 {
97  //kDebug(7007) << "addSubjob(" << jobBase << ") this=" << this;
98 
99  bool ok = KCompositeJob::addSubjob( jobBase );
100  KIO::Job *job = dynamic_cast<KIO::Job*>( jobBase );
101  if (ok && job) {
102  // Copy metadata into subjob (e.g. window-id, user-timestamp etc.)
103  Q_D(Job);
104  job->mergeMetaData(d->m_outgoingMetaData);
105 
106  // Forward information from that subjob.
107  connect(job, SIGNAL(speed(KJob*,ulong)),
108  SLOT(slotSpeed(KJob*,ulong)));
109 
110  if (ui() && job->ui()) {
111  job->ui()->setWindow( ui()->window() );
112  job->ui()->updateUserTimestamp( ui()->userTimestamp() );
113  }
114  }
115  return ok;
116 }
117 
118 bool Job::removeSubjob( KJob *jobBase )
119 {
120  //kDebug(7007) << "removeSubjob(" << jobBase << ") this=" << this << "subjobs=" << subjobs().count();
121  return KCompositeJob::removeSubjob( jobBase );
122 }
123 
124 void JobPrivate::emitMoving(KIO::Job * job, const KUrl &src, const KUrl &dest)
125 {
126  emit job->description(job, i18nc("@title job","Moving"),
127  qMakePair(i18nc("The source of a file operation", "Source"), src.pathOrUrl()),
128  qMakePair(i18nc("The destination of a file operation", "Destination"), dest.pathOrUrl()));
129 }
130 
131 void JobPrivate::emitCopying(KIO::Job * job, const KUrl &src, const KUrl &dest)
132 {
133  emit job->description(job, i18nc("@title job","Copying"),
134  qMakePair(i18nc("The source of a file operation", "Source"), src.pathOrUrl()),
135  qMakePair(i18nc("The destination of a file operation", "Destination"), dest.pathOrUrl()));
136 }
137 
138 void JobPrivate::emitCreatingDir(KIO::Job * job, const KUrl &dir)
139 {
140  emit job->description(job, i18nc("@title job","Creating directory"),
141  qMakePair(i18n("Directory"), dir.pathOrUrl()));
142 }
143 
144 void JobPrivate::emitDeleting(KIO::Job *job, const KUrl &url)
145 {
146  emit job->description(job, i18nc("@title job","Deleting"),
147  qMakePair(i18n("File"), url.pathOrUrl()));
148 }
149 
150 void JobPrivate::emitStating(KIO::Job *job, const KUrl &url)
151 {
152  emit job->description(job, i18nc("@title job","Examining"),
153  qMakePair(i18n("File"), url.pathOrUrl()));
154 }
155 
156 void JobPrivate::emitTransferring(KIO::Job *job, const KUrl &url)
157 {
158  emit job->description(job, i18nc("@title job","Transferring"),
159  qMakePair(i18nc("The source of a file operation", "Source"), url.pathOrUrl()));
160 }
161 
162 void JobPrivate::emitMounting(KIO::Job * job, const QString &dev, const QString &point)
163 {
164  emit job->description(job, i18nc("@title job","Mounting"),
165  qMakePair(i18n("Device"), dev),
166  qMakePair(i18n("Mountpoint"), point));
167 }
168 
169 void JobPrivate::emitUnmounting(KIO::Job * job, const QString &point)
170 {
171  emit job->description(job, i18nc("@title job","Unmounting"),
172  qMakePair(i18n("Mountpoint"), point));
173 }
174 
175 bool Job::doKill()
176 {
177  // kill all subjobs, without triggering their result slot
178  Q_FOREACH( KJob* it, subjobs()) {
179  it->kill( KJob::Quietly );
180  }
181  clearSubjobs();
182 
183  return true;
184 }
185 
186 bool Job::doSuspend()
187 {
188  Q_FOREACH(KJob* it, subjobs()) {
189  if (!it->suspend())
190  return false;
191  }
192 
193  return true;
194 }
195 
196 bool Job::doResume()
197 {
198  Q_FOREACH ( KJob* it, subjobs() )
199  {
200  if (!it->resume())
201  return false;
202  }
203 
204  return true;
205 }
206 
207 void JobPrivate::slotSpeed( KJob*, unsigned long speed )
208 {
209  //kDebug(7007) << speed;
210  q_func()->emitSpeed( speed );
211 }
212 
213 //Job::errorString is implemented in global.cpp
214 
215 #ifndef KDE_NO_DEPRECATED
216 void Job::showErrorDialog( QWidget *parent )
217 {
218  if ( ui() )
219  {
220  ui()->setWindow( parent );
221  ui()->showErrorMessage();
222  }
223  else
224  {
225  kError() << errorString();
226  }
227 }
228 #endif
229 
230 bool Job::isInteractive() const
231 {
232  return uiDelegate() != 0;
233 }
234 
235 void Job::setParentJob(Job* job)
236 {
237  Q_D(Job);
238  Q_ASSERT(d->m_parentJob == 0L);
239  Q_ASSERT(job);
240  d->m_parentJob = job;
241 }
242 
243 Job* Job::parentJob() const
244 {
245  return d_func()->m_parentJob;
246 }
247 
248 MetaData Job::metaData() const
249 {
250  return d_func()->m_incomingMetaData;
251 }
252 
253 QString Job::queryMetaData(const QString &key)
254 {
255  return d_func()->m_incomingMetaData.value(key, QString());
256 }
257 
258 void Job::setMetaData( const KIO::MetaData &_metaData)
259 {
260  Q_D(Job);
261  d->m_outgoingMetaData = _metaData;
262 }
263 
264 void Job::addMetaData( const QString &key, const QString &value)
265 {
266  d_func()->m_outgoingMetaData.insert(key, value);
267 }
268 
269 void Job::addMetaData( const QMap<QString,QString> &values)
270 {
271  Q_D(Job);
272  QMap<QString,QString>::const_iterator it = values.begin();
273  for(;it != values.end(); ++it)
274  d->m_outgoingMetaData.insert(it.key(), it.value());
275 }
276 
277 void Job::mergeMetaData( const QMap<QString,QString> &values)
278 {
279  Q_D(Job);
280  QMap<QString,QString>::const_iterator it = values.begin();
281  for(;it != values.end(); ++it)
282  // there's probably a faster way
283  if ( !d->m_outgoingMetaData.contains( it.key() ) )
284  d->m_outgoingMetaData.insert( it.key(), it.value() );
285 }
286 
287 MetaData Job::outgoingMetaData() const
288 {
289  return d_func()->m_outgoingMetaData;
290 }
291 
292 SimpleJob::SimpleJob(SimpleJobPrivate &dd)
293  : Job(dd)
294 {
295  d_func()->simpleJobInit();
296 }
297 
298 void SimpleJobPrivate::simpleJobInit()
299 {
300  Q_Q(SimpleJob);
301  if (!m_url.isValid())
302  {
303  q->setError( ERR_MALFORMED_URL );
304  q->setErrorText( m_url.url() );
305  QTimer::singleShot(0, q, SLOT(slotFinished()) );
306  return;
307  }
308 
309  Scheduler::doJob(q);
310 }
311 
312 
313 bool SimpleJob::doKill()
314 {
315  Q_D(SimpleJob);
316  if ((d->m_extraFlags & JobPrivate::EF_KillCalled) == 0) {
317  d->m_extraFlags |= JobPrivate::EF_KillCalled;
318  Scheduler::cancelJob(this); // deletes the slave if not 0
319  } else {
320  kWarning(7007) << this << "This is overkill.";
321  }
322  return Job::doKill();
323 }
324 
325 bool SimpleJob::doSuspend()
326 {
327  Q_D(SimpleJob);
328  if ( d->m_slave )
329  d->m_slave->suspend();
330  return Job::doSuspend();
331 }
332 
333 bool SimpleJob::doResume()
334 {
335  Q_D(SimpleJob);
336  if ( d->m_slave )
337  d->m_slave->resume();
338  return Job::doResume();
339 }
340 
341 const KUrl& SimpleJob::url() const
342 {
343  return d_func()->m_url;
344 }
345 
346 void SimpleJob::putOnHold()
347 {
348  Q_D(SimpleJob);
349  Q_ASSERT( d->m_slave );
350  if ( d->m_slave )
351  {
352  Scheduler::putSlaveOnHold(this, d->m_url);
353  }
354  // we should now be disassociated from the slave
355  Q_ASSERT(!d->m_slave);
356  kill( Quietly );
357 }
358 
359 void SimpleJob::removeOnHold()
360 {
361  Scheduler::removeSlaveOnHold();
362 }
363 
364 bool SimpleJob::isRedirectionHandlingEnabled() const
365 {
366  return d_func()->m_redirectionHandlingEnabled;
367 }
368 
369 void SimpleJob::setRedirectionHandlingEnabled(bool handle)
370 {
371  Q_D(SimpleJob);
372  d->m_redirectionHandlingEnabled = handle;
373 }
374 
375 SimpleJob::~SimpleJob()
376 {
377  Q_D(SimpleJob);
378  // last chance to remove this job from the scheduler!
379  if (d->m_schedSerial) {
380  kDebug(7007) << "Killing job" << this << "in destructor!" << kBacktrace();
381  Scheduler::cancelJob(this);
382  }
383 }
384 
385 void SimpleJobPrivate::start(Slave *slave)
386 {
387  Q_Q(SimpleJob);
388  m_slave = slave;
389 
390  // Slave::setJob can send us SSL metadata if there is a persistent connection
391  q->connect( slave, SIGNAL(metaData(KIO::MetaData)),
392  SLOT(slotMetaData(KIO::MetaData)) );
393 
394  slave->setJob(q);
395 
396  q->connect( slave, SIGNAL(error(int,QString)),
397  SLOT(slotError(int,QString)) );
398 
399  q->connect( slave, SIGNAL(warning(QString)),
400  SLOT(slotWarning(QString)) );
401 
402  q->connect( slave, SIGNAL(infoMessage(QString)),
403  SLOT(_k_slotSlaveInfoMessage(QString)) );
404 
405  q->connect( slave, SIGNAL(connected()),
406  SLOT(slotConnected()));
407 
408  q->connect( slave, SIGNAL(finished()),
409  SLOT(slotFinished()) );
410 
411  if ((m_extraFlags & EF_TransferJobDataSent) == 0) // this is a "get" job
412  {
413  q->connect( slave, SIGNAL(totalSize(KIO::filesize_t)),
414  SLOT(slotTotalSize(KIO::filesize_t)) );
415 
416  q->connect( slave, SIGNAL(processedSize(KIO::filesize_t)),
417  SLOT(slotProcessedSize(KIO::filesize_t)) );
418 
419  q->connect( slave, SIGNAL(speed(ulong)),
420  SLOT(slotSpeed(ulong)) );
421  }
422 
423  if (ui() && ui()->window())
424  {
425  m_outgoingMetaData.insert("window-id", QString::number((qptrdiff)ui()->window()->winId()));
426  }
427 
428  if (ui() && ui()->userTimestamp())
429  {
430  m_outgoingMetaData.insert("user-timestamp", QString::number(ui()->userTimestamp()));
431  }
432 
433  if (ui() == 0) // not interactive
434  {
435  m_outgoingMetaData.insert("no-auth-prompt", "true");
436  }
437 
438  if (!m_outgoingMetaData.isEmpty())
439  {
440  KIO_ARGS << m_outgoingMetaData;
441  slave->send( CMD_META_DATA, packedArgs );
442  }
443 
444  if (!m_subUrl.isEmpty())
445  {
446  KIO_ARGS << m_subUrl;
447  slave->send( CMD_SUBURL, packedArgs );
448  }
449 
450  slave->send( m_command, m_packedArgs );
451 }
452 
453 void SimpleJobPrivate::slaveDone()
454 {
455  Q_Q(SimpleJob);
456  if (m_slave) {
457  if (m_command == CMD_OPEN) {
458  m_slave->send(CMD_CLOSE);
459  }
460  q->disconnect(m_slave); // Remove all signals between slave and job
461  }
462  // only finish a job once; Scheduler::jobFinished() resets schedSerial to zero.
463  if (m_schedSerial) {
464  Scheduler::jobFinished(q, m_slave);
465  }
466 }
467 
468 void SimpleJob::slotFinished( )
469 {
470  Q_D(SimpleJob);
471  // Return slave to the scheduler
472  d->slaveDone();
473 
474  if (!hasSubjobs())
475  {
476  if ( !error() && (d->m_command == CMD_MKDIR || d->m_command == CMD_RENAME ) )
477  {
478  if ( d->m_command == CMD_MKDIR )
479  {
480  KUrl urlDir( url() );
481  urlDir.setPath( urlDir.directory() );
482  org::kde::KDirNotify::emitFilesAdded( urlDir.url() );
483  }
484  else /*if ( m_command == CMD_RENAME )*/
485  {
486  KUrl src, dst;
487  QDataStream str( d->m_packedArgs );
488  str >> src >> dst;
489  if( src.directory() == dst.directory() ) // For the user, moving isn't renaming. Only renaming is.
490  org::kde::KDirNotify::emitFileRenamed( src.url(), dst.url() );
491 
492  org::kde::KDirNotify::emitFileMoved( src.url(), dst.url() );
493  ClipboardUpdater::update(src, dst);
494  }
495  }
496  emitResult();
497  }
498 }
499 
500 void SimpleJob::slotError( int err, const QString & errorText )
501 {
502  Q_D(SimpleJob);
503  setError( err );
504  setErrorText( errorText );
505  if ((error() == ERR_UNKNOWN_HOST) && d->m_url.host().isEmpty())
506  setErrorText( QString() );
507  // error terminates the job
508  slotFinished();
509 }
510 
511 void SimpleJob::slotWarning( const QString & errorText )
512 {
513  emit warning( this, errorText );
514 }
515 
516 void SimpleJobPrivate::_k_slotSlaveInfoMessage( const QString & msg )
517 {
518  emit q_func()->infoMessage( q_func(), msg );
519 }
520 
521 void SimpleJobPrivate::slotConnected()
522 {
523  emit q_func()->connected( q_func() );
524 }
525 
526 void SimpleJobPrivate::slotTotalSize( KIO::filesize_t size )
527 {
528  Q_Q(SimpleJob);
529  if (size != q->totalAmount(KJob::Bytes))
530  {
531  q->setTotalAmount(KJob::Bytes, size);
532  }
533 }
534 
535 void SimpleJobPrivate::slotProcessedSize( KIO::filesize_t size )
536 {
537  Q_Q(SimpleJob);
538  //kDebug(7007) << KIO::number(size);
539  q->setProcessedAmount(KJob::Bytes, size);
540 }
541 
542 void SimpleJobPrivate::slotSpeed( unsigned long speed )
543 {
544  //kDebug(7007) << speed;
545  q_func()->emitSpeed( speed );
546 }
547 
548 void SimpleJobPrivate::restartAfterRedirection(KUrl *redirectionUrl)
549 {
550  Q_Q(SimpleJob);
551  // Return slave to the scheduler while we still have the old URL in place; the scheduler
552  // requires a job URL to stay invariant while the job is running.
553  slaveDone();
554 
555  m_url = *redirectionUrl;
556  redirectionUrl->clear();
557  if ((m_extraFlags & EF_KillCalled) == 0) {
558  Scheduler::doJob(q);
559  }
560 }
561 
562 int SimpleJobPrivate::requestMessageBox(int _type, const QString& text, const QString& caption,
563  const QString& buttonYes, const QString& buttonNo,
564  const QString& iconYes, const QString& iconNo,
565  const QString& dontAskAgainName,
566  const KIO::MetaData& sslMetaData)
567 {
568  JobUiDelegate* delegate = ui();
569  if (delegate) {
570  const JobUiDelegate::MessageBoxType type = static_cast<JobUiDelegate::MessageBoxType>(_type);
571  return delegate->requestMessageBox(type, text, caption, buttonYes, buttonNo,
572  iconYes, iconNo, dontAskAgainName, sslMetaData);
573  }
574  kWarning(7007) << "JobUiDelegate not set! Returing -1";
575  return -1;
576 }
577 
578 void SimpleJob::slotMetaData( const KIO::MetaData &_metaData )
579 {
580  Q_D(SimpleJob);
581  QMapIterator<QString,QString> it (_metaData);
582  while (it.hasNext()) {
583  it.next();
584  if (it.key().startsWith(QLatin1String("{internal~"), Qt::CaseInsensitive))
585  d->m_internalMetaData.insert(it.key(), it.value());
586  else
587  d->m_incomingMetaData.insert(it.key(), it.value());
588  }
589 
590  // Update the internal meta-data values as soon as possible. Waiting until
591  // the ioslave is finished has unintended consequences if the client starts
592  // a new connection without waiting for the ioslave to finish.
593  if (!d->m_internalMetaData.isEmpty()) {
594  Scheduler::updateInternalMetaData(this);
595  }
596 }
597 
598 void SimpleJob::storeSSLSessionFromJob(const KUrl &redirectionURL)
599 {
600  Q_UNUSED(redirectionURL);
601 }
602 
603 
605 class KIO::MkdirJobPrivate: public SimpleJobPrivate
606 {
607 public:
608  MkdirJobPrivate(const KUrl& url, int command, const QByteArray &packedArgs)
609  : SimpleJobPrivate(url, command, packedArgs)
610  { }
611  KUrl m_redirectionURL;
612  void slotRedirection(const KUrl &url);
613 
620  virtual void start( Slave *slave );
621 
622  Q_DECLARE_PUBLIC(MkdirJob)
623 
624  static inline MkdirJob *newJob(const KUrl& url, int command, const QByteArray &packedArgs)
625  {
626  MkdirJob *job = new MkdirJob(*new MkdirJobPrivate(url, command, packedArgs));
627  job->setUiDelegate(new JobUiDelegate);
628  return job;
629  }
630 };
631 
632 MkdirJob::MkdirJob(MkdirJobPrivate &dd)
633  : SimpleJob(dd)
634 {
635 }
636 
637 MkdirJob::~MkdirJob()
638 {
639 }
640 
641 void MkdirJobPrivate::start(Slave *slave)
642 {
643  Q_Q(MkdirJob);
644  q->connect( slave, SIGNAL(redirection(KUrl)),
645  SLOT(slotRedirection(KUrl)) );
646 
647  SimpleJobPrivate::start(slave);
648 }
649 
650 // Slave got a redirection request
651 void MkdirJobPrivate::slotRedirection( const KUrl &url)
652 {
653  Q_Q(MkdirJob);
654  kDebug(7007) << url;
655  if (!KAuthorized::authorizeUrlAction("redirect", m_url, url))
656  {
657  kWarning(7007) << "Redirection from" << m_url << "to" << url << "REJECTED!";
658  q->setError( ERR_ACCESS_DENIED );
659  q->setErrorText( url.pathOrUrl() );
660  return;
661  }
662  m_redirectionURL = url; // We'll remember that when the job finishes
663  // Tell the user that we haven't finished yet
664  emit q->redirection(q, m_redirectionURL);
665 }
666 
667 void MkdirJob::slotFinished()
668 {
669  Q_D(MkdirJob);
670 
671  if ( !d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() )
672  {
673  //kDebug(7007) << "MkdirJob: Redirection to " << m_redirectionURL;
674  if (queryMetaData("permanent-redirect")=="true")
675  emit permanentRedirection(this, d->m_url, d->m_redirectionURL);
676 
677  if ( d->m_redirectionHandlingEnabled )
678  {
679  KUrl dummyUrl;
680  int permissions;
681  QDataStream istream( d->m_packedArgs );
682  istream >> dummyUrl >> permissions;
683 
684  d->m_packedArgs.truncate(0);
685  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
686  stream << d->m_redirectionURL << permissions;
687 
688  d->restartAfterRedirection(&d->m_redirectionURL);
689  return;
690  }
691  }
692 
693  // Return slave to the scheduler
694  SimpleJob::slotFinished();
695 }
696 
697 SimpleJob *KIO::mkdir( const KUrl& url, int permissions )
698 {
699  //kDebug(7007) << "mkdir " << url;
700  KIO_ARGS << url << permissions;
701  return MkdirJobPrivate::newJob(url, CMD_MKDIR, packedArgs);
702 }
703 
704 SimpleJob *KIO::rmdir( const KUrl& url )
705 {
706  //kDebug(7007) << "rmdir " << url;
707  KIO_ARGS << url << qint8(false); // isFile is false
708  return SimpleJobPrivate::newJob(url, CMD_DEL, packedArgs);
709 }
710 
711 SimpleJob *KIO::chmod( const KUrl& url, int permissions )
712 {
713  //kDebug(7007) << "chmod " << url;
714  KIO_ARGS << url << permissions;
715  return SimpleJobPrivate::newJob(url, CMD_CHMOD, packedArgs);
716 }
717 
718 SimpleJob *KIO::chown( const KUrl& url, const QString& owner, const QString& group )
719 {
720  KIO_ARGS << url << owner << group;
721  return SimpleJobPrivate::newJob(url, CMD_CHOWN, packedArgs);
722 }
723 
724 SimpleJob *KIO::setModificationTime( const KUrl& url, const QDateTime& mtime )
725 {
726  //kDebug(7007) << "setModificationTime " << url << " " << mtime;
727  KIO_ARGS << url << mtime;
728  return SimpleJobPrivate::newJobNoUi(url, CMD_SETMODIFICATIONTIME, packedArgs);
729 }
730 
731 SimpleJob *KIO::rename( const KUrl& src, const KUrl & dest, JobFlags flags )
732 {
733  //kDebug(7007) << "rename " << src << " " << dest;
734  KIO_ARGS << src << dest << (qint8) (flags & Overwrite);
735  return SimpleJobPrivate::newJob(src, CMD_RENAME, packedArgs);
736 }
737 
738 SimpleJob *KIO::symlink( const QString& target, const KUrl & dest, JobFlags flags )
739 {
740  //kDebug(7007) << "symlink target=" << target << " " << dest;
741  KIO_ARGS << target << dest << (qint8) (flags & Overwrite);
742  return SimpleJobPrivate::newJob(dest, CMD_SYMLINK, packedArgs, flags);
743 }
744 
745 SimpleJob *KIO::special(const KUrl& url, const QByteArray & data, JobFlags flags)
746 {
747  //kDebug(7007) << "special " << url;
748  return SimpleJobPrivate::newJob(url, CMD_SPECIAL, data, flags);
749 }
750 
751 SimpleJob *KIO::mount( bool ro, const QByteArray& fstype, const QString& dev, const QString& point, JobFlags flags )
752 {
753  KIO_ARGS << int(1) << qint8( ro ? 1 : 0 )
754  << QString::fromLatin1(fstype) << dev << point;
755  SimpleJob *job = special( KUrl("file:/"), packedArgs, flags );
756  if (!(flags & HideProgressInfo)) {
757  KIO::JobPrivate::emitMounting(job, dev, point);
758  }
759  return job;
760 }
761 
762 SimpleJob *KIO::unmount( const QString& point, JobFlags flags )
763 {
764  KIO_ARGS << int(2) << point;
765  SimpleJob *job = special( KUrl("file:/"), packedArgs, flags );
766  if (!(flags & HideProgressInfo)) {
767  KIO::JobPrivate::emitUnmounting(job, point);
768  }
769  return job;
770 }
771 
772 
773 
775 
776 class KIO::StatJobPrivate: public SimpleJobPrivate
777 {
778 public:
779  inline StatJobPrivate(const KUrl& url, int command, const QByteArray &packedArgs)
780  : SimpleJobPrivate(url, command, packedArgs), m_bSource(true), m_details(2)
781  {}
782 
783  UDSEntry m_statResult;
784  KUrl m_redirectionURL;
785  bool m_bSource;
786  short int m_details;
787  void slotStatEntry( const KIO::UDSEntry & entry );
788  void slotRedirection( const KUrl &url);
789 
796  virtual void start( Slave *slave );
797 
798  Q_DECLARE_PUBLIC(StatJob)
799 
800  static inline StatJob *newJob(const KUrl& url, int command, const QByteArray &packedArgs,
801  JobFlags flags )
802  {
803  StatJob *job = new StatJob(*new StatJobPrivate(url, command, packedArgs));
804  job->setUiDelegate(new JobUiDelegate);
805  if (!(flags & HideProgressInfo)) {
806  KIO::getJobTracker()->registerJob(job);
807  emitStating(job, url);
808  }
809  return job;
810  }
811 };
812 
813 StatJob::StatJob(StatJobPrivate &dd)
814  : SimpleJob(dd)
815 {
816 }
817 
818 StatJob::~StatJob()
819 {
820 }
821 
822 #ifndef KDE_NO_DEPRECATED
823 void StatJob::setSide( bool source )
824 {
825  d_func()->m_bSource = source;
826 }
827 #endif
828 
829 void StatJob::setSide( StatSide side )
830 {
831  d_func()->m_bSource = side == SourceSide;
832 }
833 
834 void StatJob::setDetails( short int details )
835 {
836  d_func()->m_details = details;
837 }
838 
839 const UDSEntry & StatJob::statResult() const
840 {
841  return d_func()->m_statResult;
842 }
843 
844 KUrl StatJob::mostLocalUrl() const
845 {
846  if (!url().isLocalFile()) {
847  const UDSEntry& udsEntry = d_func()->m_statResult;
848  const QString path = udsEntry.stringValue( KIO::UDSEntry::UDS_LOCAL_PATH );
849  if (!path.isEmpty())
850  return KUrl(path);
851  }
852  return url();
853 }
854 
855 void StatJobPrivate::start(Slave *slave)
856 {
857  Q_Q(StatJob);
858  m_outgoingMetaData.insert( "statSide", m_bSource ? "source" : "dest" );
859  m_outgoingMetaData.insert( "details", QString::number(m_details) );
860 
861  q->connect( slave, SIGNAL(statEntry(KIO::UDSEntry)),
862  SLOT(slotStatEntry(KIO::UDSEntry)) );
863  q->connect( slave, SIGNAL(redirection(KUrl)),
864  SLOT(slotRedirection(KUrl)) );
865 
866  SimpleJobPrivate::start(slave);
867 }
868 
869 void StatJobPrivate::slotStatEntry( const KIO::UDSEntry & entry )
870 {
871  //kDebug(7007);
872  m_statResult = entry;
873 }
874 
875 // Slave got a redirection request
876 void StatJobPrivate::slotRedirection( const KUrl &url)
877 {
878  Q_Q(StatJob);
879  kDebug(7007) << m_url << "->" << url;
880  if (!KAuthorized::authorizeUrlAction("redirect", m_url, url))
881  {
882  kWarning(7007) << "Redirection from " << m_url << " to " << url << " REJECTED!";
883  q->setError( ERR_ACCESS_DENIED );
884  q->setErrorText( url.pathOrUrl() );
885  return;
886  }
887  m_redirectionURL = url; // We'll remember that when the job finishes
888  // Tell the user that we haven't finished yet
889  emit q->redirection(q, m_redirectionURL);
890 }
891 
892 void StatJob::slotFinished()
893 {
894  Q_D(StatJob);
895 
896  if ( !d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() )
897  {
898  //kDebug(7007) << "StatJob: Redirection to " << m_redirectionURL;
899  if (queryMetaData("permanent-redirect")=="true")
900  emit permanentRedirection(this, d->m_url, d->m_redirectionURL);
901 
902  if ( d->m_redirectionHandlingEnabled )
903  {
904  d->m_packedArgs.truncate(0);
905  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
906  stream << d->m_redirectionURL;
907 
908  d->restartAfterRedirection(&d->m_redirectionURL);
909  return;
910  }
911  }
912 
913  // Return slave to the scheduler
914  SimpleJob::slotFinished();
915 }
916 
917 void StatJob::slotMetaData( const KIO::MetaData &_metaData)
918 {
919  Q_D(StatJob);
920  SimpleJob::slotMetaData(_metaData);
921  storeSSLSessionFromJob(d->m_redirectionURL);
922 }
923 
924 StatJob *KIO::stat(const KUrl& url, JobFlags flags)
925 {
926  // Assume sideIsSource. Gets are more common than puts.
927  return stat( url, StatJob::SourceSide, 2, flags );
928 }
929 
930 StatJob *KIO::mostLocalUrl(const KUrl& url, JobFlags flags)
931 {
932  StatJob* job = stat( url, StatJob::SourceSide, 2, flags );
933  if (url.isLocalFile()) {
934  QTimer::singleShot(0, job, SLOT(slotFinished()));
935  Scheduler::cancelJob(job); // deletes the slave if not 0
936  }
937  return job;
938 }
939 
940 #ifndef KDE_NO_DEPRECATED
941 StatJob *KIO::stat(const KUrl& url, bool sideIsSource, short int details, JobFlags flags )
942 {
943  //kDebug(7007) << "stat" << url;
944  KIO_ARGS << url;
945  StatJob * job = StatJobPrivate::newJob(url, CMD_STAT, packedArgs, flags);
946  job->setSide( sideIsSource ? StatJob::SourceSide : StatJob::DestinationSide );
947  job->setDetails( details );
948  return job;
949 }
950 #endif
951 
952 StatJob *KIO::stat(const KUrl& url, KIO::StatJob::StatSide side, short int details, JobFlags flags )
953 {
954  //kDebug(7007) << "stat" << url;
955  KIO_ARGS << url;
956  StatJob * job = StatJobPrivate::newJob(url, CMD_STAT, packedArgs, flags);
957  job->setSide( side );
958  job->setDetails( details );
959  return job;
960 }
961 
962 SimpleJob *KIO::http_update_cache( const KUrl& url, bool no_cache, time_t expireDate)
963 {
964  Q_ASSERT(url.protocol() == "http" || url.protocol() == "https");
965  // Send http update_cache command (2)
966  KIO_ARGS << (int)2 << url << no_cache << qlonglong(expireDate);
967  SimpleJob * job = SimpleJobPrivate::newJob(url, CMD_SPECIAL, packedArgs);
968  Scheduler::setJobPriority(job, 1);
969  return job;
970 }
971 
973 
974 TransferJob::TransferJob(TransferJobPrivate &dd)
975  : SimpleJob(dd)
976 {
977  Q_D(TransferJob);
978  if (d->m_command == CMD_PUT) {
979  d->m_extraFlags |= JobPrivate::EF_TransferJobDataSent;
980  }
981 }
982 
983 TransferJob::~TransferJob()
984 {
985 }
986 
987 // Slave sends data
988 void TransferJob::slotData( const QByteArray &_data)
989 {
990  Q_D(TransferJob);
991  if (d->m_command == CMD_GET && !d->m_isMimetypeEmitted) {
992  kWarning(7007) << "mimeType() not emitted when sending first data!; job URL ="
993  << d->m_url << "data size =" << _data.size();
994  }
995  // shut up the warning, HACK: downside is that it changes the meaning of the variable
996  d->m_isMimetypeEmitted = true;
997 
998  if (d->m_redirectionURL.isEmpty() || !d->m_redirectionURL.isValid() || error()) {
999  emit data(this, _data);
1000  }
1001 }
1002 
1003 void KIO::TransferJob::setTotalSize(KIO::filesize_t bytes)
1004 {
1005  setTotalAmount(KJob::Bytes, bytes);
1006 }
1007 
1008 // Slave got a redirection request
1009 void TransferJob::slotRedirection( const KUrl &url)
1010 {
1011  Q_D(TransferJob);
1012  kDebug(7007) << url;
1013  if (!KAuthorized::authorizeUrlAction("redirect", d->m_url, url))
1014  {
1015  kWarning(7007) << "Redirection from " << d->m_url << " to " << url << " REJECTED!";
1016  return;
1017  }
1018 
1019  // Some websites keep redirecting to themselves where each redirection
1020  // acts as the stage in a state-machine. We define "endless redirections"
1021  // as 5 redirections to the same URL.
1022  if (d->m_redirectionList.count(url) > 5)
1023  {
1024  kDebug(7007) << "CYCLIC REDIRECTION!";
1025  setError( ERR_CYCLIC_LINK );
1026  setErrorText( d->m_url.pathOrUrl() );
1027  }
1028  else
1029  {
1030  d->m_redirectionURL = url; // We'll remember that when the job finishes
1031  d->m_redirectionList.append(url);
1032  QString sslInUse = queryMetaData(QLatin1String("ssl_in_use"));
1033  if (!sslInUse.isNull()) { // the key is present
1034  addMetaData(QLatin1String("ssl_was_in_use"), sslInUse);
1035  } else {
1036  addMetaData(QLatin1String("ssl_was_in_use"), QLatin1String("FALSE"));
1037  }
1038  // Tell the user that we haven't finished yet
1039  emit redirection(this, d->m_redirectionURL);
1040  }
1041 }
1042 
1043 void TransferJob::slotFinished()
1044 {
1045  Q_D(TransferJob);
1046 
1047  kDebug(7007) << d->m_url;
1048  if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid()) {
1049 
1050  //kDebug(7007) << "Redirection to" << m_redirectionURL;
1051  if (queryMetaData("permanent-redirect")=="true")
1052  emit permanentRedirection(this, d->m_url, d->m_redirectionURL);
1053 
1054  if (queryMetaData(QLatin1String("redirect-to-get")) == QLatin1String("true")) {
1055  d->m_command = CMD_GET;
1056  d->m_outgoingMetaData.remove(QLatin1String("CustomHTTPMethod"));
1057  d->m_outgoingMetaData.remove(QLatin1String("content-type"));
1058  }
1059 
1060  if (d->m_redirectionHandlingEnabled) {
1061  // Honour the redirection
1062  // We take the approach of "redirecting this same job"
1063  // Another solution would be to create a subjob, but the same problem
1064  // happens (unpacking+repacking)
1065  d->staticData.truncate(0);
1066  d->m_incomingMetaData.clear();
1067  if (queryMetaData("cache") != "reload")
1068  addMetaData("cache","refresh");
1069  d->m_internalSuspended = false;
1070  // The very tricky part is the packed arguments business
1071  QString dummyStr;
1072  KUrl dummyUrl;
1073  QDataStream istream( d->m_packedArgs );
1074  switch( d->m_command ) {
1075  case CMD_GET:
1076  case CMD_STAT:
1077  case CMD_DEL: {
1078  d->m_packedArgs.truncate(0);
1079  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
1080  stream << d->m_redirectionURL;
1081  break;
1082  }
1083  case CMD_PUT: {
1084  int permissions;
1085  qint8 iOverwrite, iResume;
1086  istream >> dummyUrl >> iOverwrite >> iResume >> permissions;
1087  d->m_packedArgs.truncate(0);
1088  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
1089  stream << d->m_redirectionURL << iOverwrite << iResume << permissions;
1090  break;
1091  }
1092  case CMD_SPECIAL: {
1093  int specialcmd;
1094  istream >> specialcmd;
1095  if (specialcmd == 1) // HTTP POST
1096  {
1097  d->m_outgoingMetaData.remove(QLatin1String("content-type"));
1098  addMetaData("cache","reload");
1099  d->m_packedArgs.truncate(0);
1100  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
1101  stream << d->m_redirectionURL;
1102  d->m_command = CMD_GET;
1103  }
1104  break;
1105  }
1106  }
1107  d->restartAfterRedirection(&d->m_redirectionURL);
1108  return;
1109  }
1110  }
1111 
1112  SimpleJob::slotFinished();
1113 }
1114 
1115 void TransferJob::setAsyncDataEnabled(bool enabled)
1116 {
1117  Q_D(TransferJob);
1118  if (enabled)
1119  d->m_extraFlags |= JobPrivate::EF_TransferJobAsync;
1120  else
1121  d->m_extraFlags &= ~JobPrivate::EF_TransferJobAsync;
1122 }
1123 
1124 void TransferJob::sendAsyncData(const QByteArray &dataForSlave)
1125 {
1126  Q_D(TransferJob);
1127  if (d->m_extraFlags & JobPrivate::EF_TransferJobNeedData)
1128  {
1129  d->m_slave->send( MSG_DATA, dataForSlave );
1130  if (d->m_extraFlags & JobPrivate::EF_TransferJobDataSent) // put job -> emit progress
1131  {
1132  KIO::filesize_t size = processedAmount(KJob::Bytes)+dataForSlave.size();
1133  setProcessedAmount(KJob::Bytes, size);
1134  }
1135  }
1136 
1137  d->m_extraFlags &= ~JobPrivate::EF_TransferJobNeedData;
1138 }
1139 
1140 #ifndef KDE_NO_DEPRECATED
1141 void TransferJob::setReportDataSent(bool enabled)
1142 {
1143  Q_D(TransferJob);
1144  if (enabled)
1145  d->m_extraFlags |= JobPrivate::EF_TransferJobDataSent;
1146  else
1147  d->m_extraFlags &= ~JobPrivate::EF_TransferJobDataSent;
1148 }
1149 #endif
1150 
1151 #ifndef KDE_NO_DEPRECATED
1152 bool TransferJob::reportDataSent() const
1153 {
1154  return (d_func()->m_extraFlags & JobPrivate::EF_TransferJobDataSent);
1155 }
1156 #endif
1157 
1158 QString TransferJob::mimetype() const
1159 {
1160  return d_func()->m_mimetype;
1161 }
1162 
1163 // Slave requests data
1164 void TransferJob::slotDataReq()
1165 {
1166  Q_D(TransferJob);
1167  QByteArray dataForSlave;
1168 
1169  d->m_extraFlags |= JobPrivate::EF_TransferJobNeedData;
1170 
1171  if (!d->staticData.isEmpty())
1172  {
1173  dataForSlave = d->staticData;
1174  d->staticData.clear();
1175  }
1176  else
1177  {
1178  emit dataReq( this, dataForSlave);
1179 
1180  if (d->m_extraFlags & JobPrivate::EF_TransferJobAsync)
1181  return;
1182  }
1183 
1184  static const int max_size = 14 * 1024 * 1024;
1185  if (dataForSlave.size() > max_size)
1186  {
1187  kDebug(7007) << "send " << dataForSlave.size() / 1024 / 1024 << "MB of data in TransferJob::dataReq. This needs to be splitted, which requires a copy. Fix the application.\n";
1188  d->staticData = QByteArray(dataForSlave.data() + max_size , dataForSlave.size() - max_size);
1189  dataForSlave.truncate(max_size);
1190  }
1191 
1192  sendAsyncData(dataForSlave);
1193 
1194  if (d->m_subJob)
1195  {
1196  // Bitburger protocol in action
1197  d->internalSuspend(); // Wait for more data from subJob.
1198  d->m_subJob->d_func()->internalResume(); // Ask for more!
1199  }
1200 }
1201 
1202 void TransferJob::slotMimetype( const QString& type )
1203 {
1204  Q_D(TransferJob);
1205  d->m_mimetype = type;
1206  if (d->m_command == CMD_GET && d->m_isMimetypeEmitted) {
1207  kWarning(7007) << "mimetype() emitted again, or after sending first data!; job URL ="
1208  << d->m_url;
1209  }
1210  d->m_isMimetypeEmitted = true;
1211  emit mimetype( this, type );
1212 }
1213 
1214 
1215 void TransferJobPrivate::internalSuspend()
1216 {
1217  m_internalSuspended = true;
1218  if (m_slave)
1219  m_slave->suspend();
1220 }
1221 
1222 void TransferJobPrivate::internalResume()
1223 {
1224  m_internalSuspended = false;
1225  if ( m_slave && !suspended )
1226  m_slave->resume();
1227 }
1228 
1229 bool TransferJob::doResume()
1230 {
1231  Q_D(TransferJob);
1232  if ( !SimpleJob::doResume() )
1233  return false;
1234  if ( d->m_internalSuspended )
1235  d->internalSuspend();
1236  return true;
1237 }
1238 
1239 bool TransferJob::isErrorPage() const
1240 {
1241  return d_func()->m_errorPage;
1242 }
1243 
1244 void TransferJobPrivate::start(Slave *slave)
1245 {
1246  Q_Q(TransferJob);
1247  Q_ASSERT(slave);
1248  JobPrivate::emitTransferring(q, m_url);
1249  q->connect( slave, SIGNAL(data(QByteArray)),
1250  SLOT(slotData(QByteArray)) );
1251 
1252  if (m_outgoingDataSource)
1253  q->connect( slave, SIGNAL(dataReq()),
1254  SLOT(slotDataReqFromDevice()) );
1255  else
1256  q->connect( slave, SIGNAL(dataReq()),
1257  SLOT(slotDataReq()) );
1258 
1259  q->connect( slave, SIGNAL(redirection(KUrl)),
1260  SLOT(slotRedirection(KUrl)) );
1261 
1262  q->connect( slave, SIGNAL(mimeType(QString)),
1263  SLOT(slotMimetype(QString)) );
1264 
1265  q->connect( slave, SIGNAL(errorPage()),
1266  SLOT(slotErrorPage()) );
1267 
1268  q->connect( slave, SIGNAL(needSubUrlData()),
1269  SLOT(slotNeedSubUrlData()) );
1270 
1271  q->connect( slave, SIGNAL(canResume(KIO::filesize_t)),
1272  SLOT(slotCanResume(KIO::filesize_t)) );
1273 
1274  if (slave->suspended())
1275  {
1276  m_mimetype = "unknown";
1277  // WABA: The slave was put on hold. Resume operation.
1278  slave->resume();
1279  }
1280 
1281  SimpleJobPrivate::start(slave);
1282  if (m_internalSuspended)
1283  slave->suspend();
1284 }
1285 
1286 void TransferJobPrivate::slotNeedSubUrlData()
1287 {
1288  Q_Q(TransferJob);
1289  // Job needs data from subURL.
1290  m_subJob = KIO::get( m_subUrl, NoReload, HideProgressInfo);
1291  internalSuspend(); // Put job on hold until we have some data.
1292  q->connect(m_subJob, SIGNAL(data(KIO::Job*,QByteArray)),
1293  SLOT(slotSubUrlData(KIO::Job*,QByteArray)));
1294  q->addSubjob(m_subJob);
1295 }
1296 
1297 void TransferJobPrivate::slotSubUrlData(KIO::Job*, const QByteArray &data)
1298 {
1299  // The Alternating Bitburg protocol in action again.
1300  staticData = data;
1301  m_subJob->d_func()->internalSuspend(); // Put job on hold until we have delivered the data.
1302  internalResume(); // Activate ourselves again.
1303 }
1304 
1305 void TransferJob::slotMetaData( const KIO::MetaData &_metaData)
1306 {
1307  Q_D(TransferJob);
1308  SimpleJob::slotMetaData(_metaData);
1309  storeSSLSessionFromJob(d->m_redirectionURL);
1310 }
1311 
1312 void TransferJobPrivate::slotErrorPage()
1313 {
1314  m_errorPage = true;
1315 }
1316 
1317 void TransferJobPrivate::slotCanResume( KIO::filesize_t offset )
1318 {
1319  Q_Q(TransferJob);
1320  emit q->canResume(q, offset);
1321 }
1322 
1323 void TransferJobPrivate::slotDataReqFromDevice()
1324 {
1325  Q_Q(TransferJob);
1326 
1327  QByteArray dataForSlave;
1328 
1329  m_extraFlags |= JobPrivate::EF_TransferJobNeedData;
1330 
1331  if (m_outgoingDataSource)
1332  dataForSlave = m_outgoingDataSource.data()->read(MAX_READ_BUF_SIZE);
1333 
1334  if (dataForSlave.isEmpty())
1335  {
1336  emit q->dataReq(q, dataForSlave);
1337  if (m_extraFlags & JobPrivate::EF_TransferJobAsync)
1338  return;
1339  }
1340 
1341  q->sendAsyncData(dataForSlave);
1342 
1343  if (m_subJob)
1344  {
1345  // Bitburger protocol in action
1346  internalSuspend(); // Wait for more data from subJob.
1347  m_subJob->d_func()->internalResume(); // Ask for more!
1348  }
1349 }
1350 
1351 void TransferJob::slotResult( KJob *job)
1352 {
1353  Q_D(TransferJob);
1354  // This can only be our suburl.
1355  Q_ASSERT(job == d->m_subJob);
1356 
1357  SimpleJob::slotResult( job );
1358 
1359  if (!error() && job == d->m_subJob)
1360  {
1361  d->m_subJob = 0; // No action required
1362  d->internalResume(); // Make sure we get the remaining data.
1363  }
1364 }
1365 
1366 void TransferJob::setModificationTime( const QDateTime& mtime )
1367 {
1368  addMetaData( "modified", mtime.toString( Qt::ISODate ) );
1369 }
1370 
1371 TransferJob *KIO::get( const KUrl& url, LoadType reload, JobFlags flags )
1372 {
1373  // Send decoded path and encoded query
1374  KIO_ARGS << url;
1375  TransferJob * job = TransferJobPrivate::newJob(url, CMD_GET, packedArgs,
1376  QByteArray(), flags);
1377  if (reload == Reload)
1378  job->addMetaData("cache", "reload");
1379  return job;
1380 }
1381 
1382 class KIO::StoredTransferJobPrivate: public TransferJobPrivate
1383 {
1384 public:
1385  StoredTransferJobPrivate(const KUrl& url, int command,
1386  const QByteArray &packedArgs,
1387  const QByteArray &_staticData)
1388  : TransferJobPrivate(url, command, packedArgs, _staticData),
1389  m_uploadOffset( 0 )
1390  {}
1391  StoredTransferJobPrivate(const KUrl& url, int command,
1392  const QByteArray &packedArgs,
1393  QIODevice* ioDevice)
1394  : TransferJobPrivate(url, command, packedArgs, ioDevice),
1395  m_uploadOffset( 0 )
1396  {}
1397 
1398  QByteArray m_data;
1399  int m_uploadOffset;
1400 
1401  void slotStoredData( KIO::Job *job, const QByteArray &data );
1402  void slotStoredDataReq( KIO::Job *job, QByteArray &data );
1403 
1404  Q_DECLARE_PUBLIC(StoredTransferJob)
1405 
1406  static inline StoredTransferJob *newJob(const KUrl &url, int command,
1407  const QByteArray &packedArgs,
1408  const QByteArray &staticData, JobFlags flags)
1409  {
1410  StoredTransferJob *job = new StoredTransferJob(
1411  *new StoredTransferJobPrivate(url, command, packedArgs, staticData));
1412  job->setUiDelegate(new JobUiDelegate);
1413  if (!(flags & HideProgressInfo))
1414  KIO::getJobTracker()->registerJob(job);
1415  return job;
1416  }
1417 
1418  static inline StoredTransferJob *newJob(const KUrl &url, int command,
1419  const QByteArray &packedArgs,
1420  QIODevice* ioDevice, JobFlags flags)
1421  {
1422  StoredTransferJob *job = new StoredTransferJob(
1423  *new StoredTransferJobPrivate(url, command, packedArgs, ioDevice));
1424  job->setUiDelegate(new JobUiDelegate);
1425  if (!(flags & HideProgressInfo))
1426  KIO::getJobTracker()->registerJob(job);
1427  return job;
1428  }
1429 };
1430 
1431 namespace KIO {
1432  class PostErrorJob : public StoredTransferJob
1433  {
1434  public:
1435 
1436  PostErrorJob(int _error, const QString& url, const QByteArray &packedArgs, const QByteArray &postData)
1437  : StoredTransferJob(*new StoredTransferJobPrivate(KUrl(), CMD_SPECIAL, packedArgs, postData))
1438  {
1439  setError( _error );
1440  setErrorText( url );
1441  }
1442 
1443  PostErrorJob(int _error, const QString& url, const QByteArray &packedArgs, QIODevice* ioDevice)
1444  : StoredTransferJob(*new StoredTransferJobPrivate(KUrl(), CMD_SPECIAL, packedArgs, ioDevice))
1445  {
1446  setError( _error );
1447  setErrorText( url );
1448  }
1449  };
1450 }
1451 
1452 static int isUrlPortBad(const KUrl& url)
1453 {
1454  int _error = 0;
1455 
1456  // filter out some malicious ports
1457  static const int bad_ports[] = {
1458  1, // tcpmux
1459  7, // echo
1460  9, // discard
1461  11, // systat
1462  13, // daytime
1463  15, // netstat
1464  17, // qotd
1465  19, // chargen
1466  20, // ftp-data
1467  21, // ftp-cntl
1468  22, // ssh
1469  23, // telnet
1470  25, // smtp
1471  37, // time
1472  42, // name
1473  43, // nicname
1474  53, // domain
1475  77, // priv-rjs
1476  79, // finger
1477  87, // ttylink
1478  95, // supdup
1479  101, // hostriame
1480  102, // iso-tsap
1481  103, // gppitnp
1482  104, // acr-nema
1483  109, // pop2
1484  110, // pop3
1485  111, // sunrpc
1486  113, // auth
1487  115, // sftp
1488  117, // uucp-path
1489  119, // nntp
1490  123, // NTP
1491  135, // loc-srv / epmap
1492  139, // netbios
1493  143, // imap2
1494  179, // BGP
1495  389, // ldap
1496  512, // print / exec
1497  513, // login
1498  514, // shell
1499  515, // printer
1500  526, // tempo
1501  530, // courier
1502  531, // Chat
1503  532, // netnews
1504  540, // uucp
1505  556, // remotefs
1506  587, // sendmail
1507  601, //
1508  989, // ftps data
1509  990, // ftps
1510  992, // telnets
1511  993, // imap/SSL
1512  995, // pop3/SSL
1513  1080, // SOCKS
1514  2049, // nfs
1515  4045, // lockd
1516  6000, // x11
1517  6667, // irc
1518  0};
1519  if (url.port() != 80)
1520  {
1521  const int port = url.port();
1522  for (int cnt=0; bad_ports[cnt] && bad_ports[cnt] <= port; ++cnt)
1523  if (port == bad_ports[cnt])
1524  {
1525  _error = KIO::ERR_POST_DENIED;
1526  break;
1527  }
1528  }
1529 
1530  if ( _error )
1531  {
1532  static bool override_loaded = false;
1533  static QList< int >* overriden_ports = NULL;
1534  if( !override_loaded ) {
1535  KConfig cfg( "kio_httprc" );
1536  overriden_ports = new QList< int >;
1537  *overriden_ports = cfg.group(QString()).readEntry( "OverriddenPorts", QList<int>() );
1538  override_loaded = true;
1539  }
1540  for( QList< int >::ConstIterator it = overriden_ports->constBegin();
1541  it != overriden_ports->constEnd();
1542  ++it ) {
1543  if( overriden_ports->contains( url.port())) {
1544  _error = 0;
1545  }
1546  }
1547  }
1548 
1549  // filter out non https? protocols
1550  if ((url.protocol() != "http") && (url.protocol() != "https" ))
1551  _error = KIO::ERR_POST_DENIED;
1552 
1553  if (!_error && !KAuthorized::authorizeUrlAction("open", KUrl(), url))
1554  _error = KIO::ERR_ACCESS_DENIED;
1555 
1556  return _error;
1557 }
1558 
1559 static KIO::PostErrorJob* precheckHttpPost( const KUrl& url, QIODevice* ioDevice, JobFlags flags )
1560 {
1561  // if request is not valid, return an invalid transfer job
1562  const int _error = isUrlPortBad(url);
1563 
1564  if (_error)
1565  {
1566  KIO_ARGS << (int)1 << url;
1567  PostErrorJob * job = new PostErrorJob(_error, url.pathOrUrl(), packedArgs, ioDevice);
1568  job->setUiDelegate(new JobUiDelegate());
1569  if (!(flags & HideProgressInfo)) {
1570  KIO::getJobTracker()->registerJob(job);
1571  }
1572  return job;
1573  }
1574 
1575  // all is ok, return 0
1576  return 0;
1577 }
1578 
1579 static KIO::PostErrorJob* precheckHttpPost( const KUrl& url, const QByteArray& postData, JobFlags flags )
1580 {
1581  // if request is not valid, return an invalid transfer job
1582  const int _error = isUrlPortBad(url);
1583 
1584  if (_error)
1585  {
1586  KIO_ARGS << (int)1 << url;
1587  PostErrorJob * job = new PostErrorJob(_error, url.pathOrUrl(), packedArgs, postData);
1588  job->setUiDelegate(new JobUiDelegate());
1589  if (!(flags & HideProgressInfo)) {
1590  KIO::getJobTracker()->registerJob(job);
1591  }
1592  return job;
1593  }
1594 
1595  // all is ok, return 0
1596  return 0;
1597 }
1598 
1599 TransferJob *KIO::http_post( const KUrl& url, const QByteArray &postData, JobFlags flags )
1600 {
1601  bool redirection = false;
1602  KUrl _url(url);
1603  if (_url.path().isEmpty())
1604  {
1605  redirection = true;
1606  _url.setPath("/");
1607  }
1608 
1609  TransferJob* job = precheckHttpPost(_url, postData, flags);
1610  if (job)
1611  return job;
1612 
1613  // Send http post command (1), decoded path and encoded query
1614  KIO_ARGS << (int)1 << _url << static_cast<qint64>(postData.size());
1615  job = TransferJobPrivate::newJob(_url, CMD_SPECIAL, packedArgs, postData, flags);
1616 
1617  if (redirection)
1618  QTimer::singleShot(0, job, SLOT(slotPostRedirection()) );
1619 
1620  return job;
1621 }
1622 
1623 TransferJob *KIO::http_post( const KUrl& url, QIODevice* ioDevice, qint64 size, JobFlags flags )
1624 {
1625  bool redirection = false;
1626  KUrl _url(url);
1627  if (_url.path().isEmpty())
1628  {
1629  redirection = true;
1630  _url.setPath("/");
1631  }
1632 
1633  TransferJob* job = precheckHttpPost(_url, ioDevice, flags);
1634  if (job)
1635  return job;
1636 
1637  // If no size is specified and the QIODevice is not a sequential one,
1638  // attempt to obtain the size information from it.
1639  Q_ASSERT(ioDevice);
1640  if (size < 0)
1641  size = ((ioDevice && !ioDevice->isSequential()) ? ioDevice->size() : -1);
1642 
1643  // Send http post command (1), decoded path and encoded query
1644  KIO_ARGS << (int)1 << _url << size;
1645  job = TransferJobPrivate::newJob(_url, CMD_SPECIAL, packedArgs, ioDevice, flags);
1646 
1647  if (redirection)
1648  QTimer::singleShot(0, job, SLOT(slotPostRedirection()) );
1649 
1650  return job;
1651 }
1652 
1653 TransferJob* KIO::http_delete(const KUrl& url, JobFlags flags)
1654 {
1655  // Send decoded path and encoded query
1656  KIO_ARGS << url;
1657  TransferJob * job = TransferJobPrivate::newJob(url, CMD_DEL, packedArgs,
1658  QByteArray(), flags);
1659  return job;
1660 }
1661 
1662 StoredTransferJob *KIO::storedHttpPost( const QByteArray& postData, const KUrl& url, JobFlags flags )
1663 {
1664  KUrl _url(url);
1665  if (_url.path().isEmpty())
1666  {
1667  _url.setPath("/");
1668  }
1669 
1670  StoredTransferJob* job = precheckHttpPost(_url, postData, flags);
1671  if (job)
1672  return job;
1673 
1674  // Send http post command (1), decoded path and encoded query
1675  KIO_ARGS << (int)1 << _url << static_cast<qint64>(postData.size());
1676  job = StoredTransferJobPrivate::newJob(_url, CMD_SPECIAL, packedArgs, postData, flags );
1677  return job;
1678 }
1679 
1680 StoredTransferJob *KIO::storedHttpPost( QIODevice* ioDevice, const KUrl& url, qint64 size, JobFlags flags )
1681 {
1682  KUrl _url(url);
1683  if (_url.path().isEmpty())
1684  {
1685  _url.setPath("/");
1686  }
1687 
1688  StoredTransferJob* job = precheckHttpPost(_url, ioDevice, flags);
1689  if (job)
1690  return job;
1691 
1692  // If no size is specified and the QIODevice is not a sequential one,
1693  // attempt to obtain the size information from it.
1694  Q_ASSERT(ioDevice);
1695  if (size < 0)
1696  size = ((ioDevice && !ioDevice->isSequential()) ? ioDevice->size() : -1);
1697 
1698  // Send http post command (1), decoded path and encoded query
1699  KIO_ARGS << (int)1 << _url << size;
1700  job = StoredTransferJobPrivate::newJob(_url, CMD_SPECIAL, packedArgs, ioDevice, flags );
1701  return job;
1702 }
1703 
1704 // http post got redirected from http://host to http://host/ by TransferJob
1705 // We must do this redirection ourselves because redirections by the
1706 // slave change post jobs into get jobs.
1707 void TransferJobPrivate::slotPostRedirection()
1708 {
1709  Q_Q(TransferJob);
1710  kDebug(7007) << "TransferJob::slotPostRedirection(" << m_url << ")";
1711  // Tell the user about the new url.
1712  emit q->redirection(q, m_url);
1713 }
1714 
1715 
1716 TransferJob *KIO::put( const KUrl& url, int permissions, JobFlags flags )
1717 {
1718  KIO_ARGS << url << qint8( (flags & Overwrite) ? 1 : 0 ) << qint8( (flags & Resume) ? 1 : 0 ) << permissions;
1719  return TransferJobPrivate::newJob(url, CMD_PUT, packedArgs, QByteArray(), flags);
1720 }
1721 
1723 
1724 StoredTransferJob::StoredTransferJob(StoredTransferJobPrivate &dd)
1725  : TransferJob(dd)
1726 {
1727  connect( this, SIGNAL(data(KIO::Job*,QByteArray)),
1728  SLOT(slotStoredData(KIO::Job*,QByteArray)) );
1729  connect( this, SIGNAL(dataReq(KIO::Job*,QByteArray&)),
1730  SLOT(slotStoredDataReq(KIO::Job*,QByteArray&)) );
1731 }
1732 
1733 StoredTransferJob::~StoredTransferJob()
1734 {
1735 }
1736 
1737 void StoredTransferJob::setData( const QByteArray& arr )
1738 {
1739  Q_D(StoredTransferJob);
1740  Q_ASSERT( d->m_data.isNull() ); // check that we're only called once
1741  Q_ASSERT( d->m_uploadOffset == 0 ); // no upload started yet
1742  d->m_data = arr;
1743  setTotalSize( d->m_data.size() );
1744 }
1745 
1746 QByteArray StoredTransferJob::data() const
1747 {
1748  return d_func()->m_data;
1749 }
1750 
1751 void StoredTransferJobPrivate::slotStoredData( KIO::Job *, const QByteArray &data )
1752 {
1753  // check for end-of-data marker:
1754  if ( data.size() == 0 )
1755  return;
1756  unsigned int oldSize = m_data.size();
1757  m_data.resize( oldSize + data.size() );
1758  memcpy( m_data.data() + oldSize, data.data(), data.size() );
1759 }
1760 
1761 void StoredTransferJobPrivate::slotStoredDataReq( KIO::Job *, QByteArray &data )
1762 {
1763  // Inspired from kmail's KMKernel::byteArrayToRemoteFile
1764  // send the data in 64 KB chunks
1765  const int MAX_CHUNK_SIZE = 64*1024;
1766  int remainingBytes = m_data.size() - m_uploadOffset;
1767  if( remainingBytes > MAX_CHUNK_SIZE ) {
1768  // send MAX_CHUNK_SIZE bytes to the receiver (deep copy)
1769  data = QByteArray( m_data.data() + m_uploadOffset, MAX_CHUNK_SIZE );
1770  m_uploadOffset += MAX_CHUNK_SIZE;
1771  //kDebug() << "Sending " << MAX_CHUNK_SIZE << " bytes ("
1772  // << remainingBytes - MAX_CHUNK_SIZE << " bytes remain)\n";
1773  } else {
1774  // send the remaining bytes to the receiver (deep copy)
1775  data = QByteArray( m_data.data() + m_uploadOffset, remainingBytes );
1776  m_data = QByteArray();
1777  m_uploadOffset = 0;
1778  //kDebug() << "Sending " << remainingBytes << " bytes\n";
1779  }
1780 }
1781 
1782 StoredTransferJob *KIO::storedGet( const KUrl& url, LoadType reload, JobFlags flags )
1783 {
1784  // Send decoded path and encoded query
1785  KIO_ARGS << url;
1786  StoredTransferJob * job = StoredTransferJobPrivate::newJob(url, CMD_GET, packedArgs, QByteArray(), flags);
1787  if (reload == Reload)
1788  job->addMetaData("cache", "reload");
1789  return job;
1790 }
1791 
1792 StoredTransferJob *KIO::storedPut( const QByteArray& arr, const KUrl& url, int permissions,
1793  JobFlags flags )
1794 {
1795  KIO_ARGS << url << qint8( (flags & Overwrite) ? 1 : 0 ) << qint8( (flags & Resume) ? 1 : 0 ) << permissions;
1796  StoredTransferJob * job = StoredTransferJobPrivate::newJob(url, CMD_PUT, packedArgs, QByteArray(), flags );
1797  job->setData( arr );
1798  return job;
1799 }
1800 
1802 
1803 class KIO::MimetypeJobPrivate: public KIO::TransferJobPrivate
1804 {
1805 public:
1806  MimetypeJobPrivate(const KUrl& url, int command, const QByteArray &packedArgs)
1807  : TransferJobPrivate(url, command, packedArgs, QByteArray())
1808  {}
1809 
1810  Q_DECLARE_PUBLIC(MimetypeJob)
1811 
1812  static inline MimetypeJob *newJob(const KUrl& url, int command, const QByteArray &packedArgs,
1813  JobFlags flags)
1814  {
1815  MimetypeJob *job = new MimetypeJob(*new MimetypeJobPrivate(url, command, packedArgs));
1816  job->setUiDelegate(new JobUiDelegate);
1817  if (!(flags & HideProgressInfo)) {
1818  KIO::getJobTracker()->registerJob(job);
1819  emitStating(job, url);
1820  }
1821  return job;
1822  }
1823 };
1824 
1825 MimetypeJob::MimetypeJob(MimetypeJobPrivate &dd)
1826  : TransferJob(dd)
1827 {
1828 }
1829 
1830 MimetypeJob::~MimetypeJob()
1831 {
1832 }
1833 
1834 void MimetypeJob::slotFinished( )
1835 {
1836  Q_D(MimetypeJob);
1837  //kDebug(7007);
1838  if ( error() == KIO::ERR_IS_DIRECTORY )
1839  {
1840  // It is in fact a directory. This happens when HTTP redirects to FTP.
1841  // Due to the "protocol doesn't support listing" code in KRun, we
1842  // assumed it was a file.
1843  kDebug(7007) << "It is in fact a directory!";
1844  d->m_mimetype = QString::fromLatin1("inode/directory");
1845  emit TransferJob::mimetype( this, d->m_mimetype );
1846  setError( 0 );
1847  }
1848 
1849  if ( !d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() && !error() )
1850  {
1851  //kDebug(7007) << "Redirection to " << m_redirectionURL;
1852  if (queryMetaData("permanent-redirect")=="true")
1853  emit permanentRedirection(this, d->m_url, d->m_redirectionURL);
1854 
1855  if (d->m_redirectionHandlingEnabled)
1856  {
1857  d->staticData.truncate(0);
1858  d->m_internalSuspended = false;
1859  d->m_packedArgs.truncate(0);
1860  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
1861  stream << d->m_redirectionURL;
1862 
1863  d->restartAfterRedirection(&d->m_redirectionURL);
1864  return;
1865  }
1866  }
1867 
1868  // Return slave to the scheduler
1869  TransferJob::slotFinished();
1870 }
1871 
1872 MimetypeJob *KIO::mimetype(const KUrl& url, JobFlags flags)
1873 {
1874  KIO_ARGS << url;
1875  return MimetypeJobPrivate::newJob(url, CMD_MIMETYPE, packedArgs, flags);
1876 }
1877 
1879 
1880 class KIO::DirectCopyJobPrivate: public KIO::SimpleJobPrivate
1881 {
1882 public:
1883  DirectCopyJobPrivate(const KUrl& url, int command, const QByteArray &packedArgs)
1884  : SimpleJobPrivate(url, command, packedArgs)
1885  {}
1886 
1893  virtual void start(Slave *slave);
1894 
1895  Q_DECLARE_PUBLIC(DirectCopyJob)
1896 };
1897 
1898 DirectCopyJob::DirectCopyJob(const KUrl &url, const QByteArray &packedArgs)
1899  : SimpleJob(*new DirectCopyJobPrivate(url, CMD_COPY, packedArgs))
1900 {
1901  setUiDelegate(new JobUiDelegate);
1902 }
1903 
1904 DirectCopyJob::~DirectCopyJob()
1905 {
1906 }
1907 
1908 void DirectCopyJobPrivate::start( Slave* slave )
1909 {
1910  Q_Q(DirectCopyJob);
1911  q->connect( slave, SIGNAL(canResume(KIO::filesize_t)),
1912  SLOT(slotCanResume(KIO::filesize_t)) );
1913  SimpleJobPrivate::start(slave);
1914 }
1915 
1916 void DirectCopyJob::slotCanResume( KIO::filesize_t offset )
1917 {
1918  emit canResume(this, offset);
1919 }
1920 
1922 
1924 class KIO::FileCopyJobPrivate: public KIO::JobPrivate
1925 {
1926 public:
1927  FileCopyJobPrivate(const KUrl& src, const KUrl& dest, int permissions,
1928  bool move, JobFlags flags)
1929  : m_sourceSize(filesize_t(-1)), m_src(src), m_dest(dest), m_moveJob(0), m_copyJob(0), m_delJob(0),
1930  m_chmodJob(0), m_getJob(0), m_putJob(0), m_permissions(permissions),
1931  m_move(move), m_mustChmod(0), m_flags(flags)
1932  {
1933  }
1934  KIO::filesize_t m_sourceSize;
1935  QDateTime m_modificationTime;
1936  KUrl m_src;
1937  KUrl m_dest;
1938  QByteArray m_buffer;
1939  SimpleJob *m_moveJob;
1940  SimpleJob *m_copyJob;
1941  SimpleJob *m_delJob;
1942  SimpleJob *m_chmodJob;
1943  TransferJob *m_getJob;
1944  TransferJob *m_putJob;
1945  int m_permissions;
1946  bool m_move:1;
1947  bool m_canResume:1;
1948  bool m_resumeAnswerSent:1;
1949  bool m_mustChmod:1;
1950  JobFlags m_flags;
1951 
1952  void startBestCopyMethod();
1953  void startCopyJob();
1954  void startCopyJob(const KUrl &slave_url);
1955  void startRenameJob(const KUrl &slave_url);
1956  void startDataPump();
1957  void connectSubjob( SimpleJob * job );
1958 
1959  void slotStart();
1960  void slotData( KIO::Job *, const QByteArray &data);
1961  void slotDataReq( KIO::Job *, QByteArray &data);
1962  void slotMimetype( KIO::Job*, const QString& type );
1968  void slotProcessedSize( KJob *job, qulonglong size );
1974  void slotTotalSize( KJob *job, qulonglong size );
1980  void slotPercent( KJob *job, unsigned long pct );
1986  void slotCanResume( KIO::Job *job, KIO::filesize_t offset );
1987 
1988  Q_DECLARE_PUBLIC(FileCopyJob)
1989 
1990  static inline FileCopyJob* newJob(const KUrl& src, const KUrl& dest, int permissions, bool move,
1991  JobFlags flags)
1992  {
1993  //kDebug(7007) << src << "->" << dest;
1994  FileCopyJob *job = new FileCopyJob(
1995  *new FileCopyJobPrivate(src, dest, permissions, move, flags));
1996  job->setProperty("destUrl", dest.url());
1997  job->setUiDelegate(new JobUiDelegate);
1998  if (!(flags & HideProgressInfo))
1999  KIO::getJobTracker()->registerJob(job);
2000  return job;
2001  }
2002 };
2003 
2004 /*
2005  * The FileCopyJob works according to the famous Bavarian
2006  * 'Alternating Bitburger Protocol': we either drink a beer or we
2007  * we order a beer, but never both at the same time.
2008  * Translated to io-slaves: We alternate between receiving a block of data
2009  * and sending it away.
2010  */
2011 FileCopyJob::FileCopyJob(FileCopyJobPrivate &dd)
2012  : Job(dd)
2013 {
2014  //kDebug(7007);
2015  QTimer::singleShot(0, this, SLOT(slotStart()));
2016 }
2017 
2018 void FileCopyJobPrivate::slotStart()
2019 {
2020  Q_Q(FileCopyJob);
2021  if (!m_move)
2022  JobPrivate::emitCopying( q, m_src, m_dest );
2023  else
2024  JobPrivate::emitMoving( q, m_src, m_dest );
2025 
2026  if ( m_move )
2027  {
2028  // The if() below must be the same as the one in startBestCopyMethod
2029  if ((m_src.protocol() == m_dest.protocol()) &&
2030  (m_src.host() == m_dest.host()) &&
2031  (m_src.port() == m_dest.port()) &&
2032  (m_src.user() == m_dest.user()) &&
2033  (m_src.pass() == m_dest.pass()) &&
2034  !m_src.hasSubUrl() && !m_dest.hasSubUrl())
2035  {
2036  startRenameJob(m_src);
2037  return;
2038  }
2039  else if (m_src.isLocalFile() && KProtocolManager::canRenameFromFile(m_dest))
2040  {
2041  startRenameJob(m_dest);
2042  return;
2043  }
2044  else if (m_dest.isLocalFile() && KProtocolManager::canRenameToFile(m_src))
2045  {
2046  startRenameJob(m_src);
2047  return;
2048  }
2049  // No fast-move available, use copy + del.
2050  }
2051  startBestCopyMethod();
2052 }
2053 
2054 void FileCopyJobPrivate::startBestCopyMethod()
2055 {
2056  if ((m_src.protocol() == m_dest.protocol()) &&
2057  (m_src.host() == m_dest.host()) &&
2058  (m_src.port() == m_dest.port()) &&
2059  (m_src.user() == m_dest.user()) &&
2060  (m_src.pass() == m_dest.pass()) &&
2061  !m_src.hasSubUrl() && !m_dest.hasSubUrl())
2062  {
2063  startCopyJob();
2064  }
2065  else if (m_src.isLocalFile() && KProtocolManager::canCopyFromFile(m_dest))
2066  {
2067  startCopyJob(m_dest);
2068  }
2069  else if (m_dest.isLocalFile() && KProtocolManager::canCopyToFile(m_src) &&
2070  !KIO::Scheduler::isSlaveOnHoldFor(m_src))
2071  {
2072  startCopyJob(m_src);
2073  }
2074  else
2075  {
2076  startDataPump();
2077  }
2078 }
2079 
2080 FileCopyJob::~FileCopyJob()
2081 {
2082 }
2083 
2084 void FileCopyJob::setSourceSize( KIO::filesize_t size )
2085 {
2086  Q_D(FileCopyJob);
2087  d->m_sourceSize = size;
2088  if (size != (KIO::filesize_t) -1)
2089  setTotalAmount(KJob::Bytes, size);
2090 }
2091 
2092 void FileCopyJob::setModificationTime( const QDateTime& mtime )
2093 {
2094  Q_D(FileCopyJob);
2095  d->m_modificationTime = mtime;
2096 }
2097 
2098 KUrl FileCopyJob::srcUrl() const
2099 {
2100  return d_func()->m_src;
2101 }
2102 
2103 KUrl FileCopyJob::destUrl() const
2104 {
2105  return d_func()->m_dest;
2106 }
2107 
2108 void FileCopyJobPrivate::startCopyJob()
2109 {
2110  startCopyJob(m_src);
2111 }
2112 
2113 void FileCopyJobPrivate::startCopyJob(const KUrl &slave_url)
2114 {
2115  Q_Q(FileCopyJob);
2116  //kDebug(7007);
2117  KIO_ARGS << m_src << m_dest << m_permissions << (qint8) (m_flags & Overwrite);
2118  m_copyJob = new DirectCopyJob(slave_url, packedArgs);
2119  if (m_modificationTime.isValid()) {
2120  m_copyJob->addMetaData( "modified", m_modificationTime.toString( Qt::ISODate ) ); // #55804
2121  }
2122  q->addSubjob( m_copyJob );
2123  connectSubjob( m_copyJob );
2124  q->connect( m_copyJob, SIGNAL(canResume(KIO::Job*,KIO::filesize_t)),
2125  SLOT(slotCanResume(KIO::Job*,KIO::filesize_t)));
2126 }
2127 
2128 void FileCopyJobPrivate::startRenameJob(const KUrl &slave_url)
2129 {
2130  Q_Q(FileCopyJob);
2131  m_mustChmod = true; // CMD_RENAME by itself doesn't change permissions
2132  KIO_ARGS << m_src << m_dest << (qint8) (m_flags & Overwrite);
2133  m_moveJob = SimpleJobPrivate::newJobNoUi(slave_url, CMD_RENAME, packedArgs);
2134  if (m_modificationTime.isValid()) {
2135  m_moveJob->addMetaData( "modified", m_modificationTime.toString( Qt::ISODate ) ); // #55804
2136  }
2137  q->addSubjob( m_moveJob );
2138  connectSubjob( m_moveJob );
2139 }
2140 
2141 void FileCopyJobPrivate::connectSubjob( SimpleJob * job )
2142 {
2143  Q_Q(FileCopyJob);
2144  q->connect( job, SIGNAL(totalSize(KJob*,qulonglong)),
2145  SLOT(slotTotalSize(KJob*,qulonglong)) );
2146 
2147  q->connect( job, SIGNAL(processedSize(KJob*,qulonglong)),
2148  SLOT(slotProcessedSize(KJob*,qulonglong)) );
2149 
2150  q->connect( job, SIGNAL(percent(KJob*,ulong)),
2151  SLOT(slotPercent(KJob*,ulong)) );
2152 
2153 }
2154 
2155 bool FileCopyJob::doSuspend()
2156 {
2157  Q_D(FileCopyJob);
2158  if (d->m_moveJob)
2159  d->m_moveJob->suspend();
2160 
2161  if (d->m_copyJob)
2162  d->m_copyJob->suspend();
2163 
2164  if (d->m_getJob)
2165  d->m_getJob->suspend();
2166 
2167  if (d->m_putJob)
2168  d->m_putJob->suspend();
2169 
2170  Job::doSuspend();
2171  return true;
2172 }
2173 
2174 bool FileCopyJob::doResume()
2175 {
2176  Q_D(FileCopyJob);
2177  if (d->m_moveJob)
2178  d->m_moveJob->resume();
2179 
2180  if (d->m_copyJob)
2181  d->m_copyJob->resume();
2182 
2183  if (d->m_getJob)
2184  d->m_getJob->resume();
2185 
2186  if (d->m_putJob)
2187  d->m_putJob->resume();
2188 
2189  Job::doResume();
2190  return true;
2191 }
2192 
2193 void FileCopyJobPrivate::slotProcessedSize( KJob *, qulonglong size )
2194 {
2195  Q_Q(FileCopyJob);
2196  q->setProcessedAmount(KJob::Bytes, size);
2197 }
2198 
2199 void FileCopyJobPrivate::slotTotalSize( KJob*, qulonglong size )
2200 {
2201  Q_Q(FileCopyJob);
2202  if (size != q->totalAmount(KJob::Bytes))
2203  {
2204  q->setTotalAmount(KJob::Bytes, size);
2205  }
2206 }
2207 
2208 void FileCopyJobPrivate::slotPercent( KJob*, unsigned long pct )
2209 {
2210  Q_Q(FileCopyJob);
2211  if ( pct > q->percent() ) {
2212  q->setPercent( pct );
2213  }
2214 }
2215 
2216 void FileCopyJobPrivate::startDataPump()
2217 {
2218  Q_Q(FileCopyJob);
2219  //kDebug(7007);
2220 
2221  m_canResume = false;
2222  m_resumeAnswerSent = false;
2223  m_getJob = 0L; // for now
2224  m_putJob = put( m_dest, m_permissions, (m_flags | HideProgressInfo) /* no GUI */);
2225  //kDebug(7007) << "m_putJob=" << m_putJob << "m_dest=" << m_dest;
2226  if ( m_modificationTime.isValid() ) {
2227  m_putJob->setModificationTime( m_modificationTime );
2228  }
2229 
2230  // The first thing the put job will tell us is whether we can
2231  // resume or not (this is always emitted)
2232  q->connect( m_putJob, SIGNAL(canResume(KIO::Job*,KIO::filesize_t)),
2233  SLOT(slotCanResume(KIO::Job*,KIO::filesize_t)));
2234  q->connect( m_putJob, SIGNAL(dataReq(KIO::Job*,QByteArray&)),
2235  SLOT(slotDataReq(KIO::Job*,QByteArray&)));
2236  q->addSubjob( m_putJob );
2237 }
2238 
2239 void FileCopyJobPrivate::slotCanResume( KIO::Job* job, KIO::filesize_t offset )
2240 {
2241  Q_Q(FileCopyJob);
2242  if ( job == m_putJob || job == m_copyJob )
2243  {
2244  //kDebug(7007) << "'can resume' from PUT job. offset=" << KIO::number(offset);
2245  if (offset)
2246  {
2247  RenameDialog_Result res = R_RESUME;
2248 
2249  if (!KProtocolManager::autoResume() && !(m_flags & Overwrite))
2250  {
2251  QString newPath;
2252  KIO::Job* job = ( q->parentJob() ) ? q->parentJob() : q;
2253  // Ask confirmation about resuming previous transfer
2254  res = ui()->askFileRename(
2255  job, i18n("File Already Exists"),
2256  m_src.url(),
2257  m_dest.url(),
2258  (RenameDialog_Mode) (M_OVERWRITE | M_RESUME | M_NORENAME), newPath,
2259  m_sourceSize, offset );
2260  }
2261 
2262  if ( res == R_OVERWRITE || (m_flags & Overwrite) )
2263  offset = 0;
2264  else if ( res == R_CANCEL )
2265  {
2266  if ( job == m_putJob ) {
2267  m_putJob->kill( FileCopyJob::Quietly );
2268  q->removeSubjob(m_putJob);
2269  m_putJob = 0;
2270  } else {
2271  m_copyJob->kill( FileCopyJob::Quietly );
2272  q->removeSubjob(m_copyJob);
2273  m_copyJob = 0;
2274  }
2275  q->setError( ERR_USER_CANCELED );
2276  q->emitResult();
2277  return;
2278  }
2279  }
2280  else
2281  m_resumeAnswerSent = true; // No need for an answer
2282 
2283  if ( job == m_putJob )
2284  {
2285  m_getJob = KIO::get( m_src, NoReload, HideProgressInfo /* no GUI */ );
2286  //kDebug(7007) << "m_getJob=" << m_getJob << m_src;
2287  m_getJob->addMetaData( "errorPage", "false" );
2288  m_getJob->addMetaData( "AllowCompressedPage", "false" );
2289  // Set size in subjob. This helps if the slave doesn't emit totalSize.
2290  if ( m_sourceSize != (KIO::filesize_t)-1 )
2291  m_getJob->setTotalAmount(KJob::Bytes, m_sourceSize);
2292  if (offset)
2293  {
2294  //kDebug(7007) << "Setting metadata for resume to" << (unsigned long) offset;
2295  // TODO KDE4: rename to seek or offset and document it
2296  // This isn't used only for resuming, but potentially also for extracting (#72302).
2297  m_getJob->addMetaData( "resume", KIO::number(offset) );
2298 
2299  // Might or might not get emitted
2300  q->connect( m_getJob, SIGNAL(canResume(KIO::Job*,KIO::filesize_t)),
2301  SLOT(slotCanResume(KIO::Job*,KIO::filesize_t)));
2302  }
2303  jobSlave(m_putJob)->setOffset( offset );
2304 
2305  m_putJob->d_func()->internalSuspend();
2306  q->addSubjob( m_getJob );
2307  connectSubjob( m_getJob ); // Progress info depends on get
2308  m_getJob->d_func()->internalResume(); // Order a beer
2309 
2310  q->connect( m_getJob, SIGNAL(data(KIO::Job*,QByteArray)),
2311  SLOT(slotData(KIO::Job*,QByteArray)) );
2312  q->connect( m_getJob, SIGNAL(mimetype(KIO::Job*,QString)),
2313  SLOT(slotMimetype(KIO::Job*,QString)) );
2314  }
2315  else // copyjob
2316  {
2317  jobSlave(m_copyJob)->sendResumeAnswer( offset != 0 );
2318  }
2319  }
2320  else if ( job == m_getJob )
2321  {
2322  // Cool, the get job said ok, we can resume
2323  m_canResume = true;
2324  //kDebug(7007) << "'can resume' from the GET job -> we can resume";
2325 
2326  jobSlave(m_getJob)->setOffset( jobSlave(m_putJob)->offset() );
2327  }
2328  else
2329  kWarning(7007) << "unknown job=" << job
2330  << "m_getJob=" << m_getJob << "m_putJob=" << m_putJob;
2331 }
2332 
2333 void FileCopyJobPrivate::slotData( KIO::Job * , const QByteArray &data)
2334 {
2335  //kDebug(7007) << "data size:" << data.size();
2336  Q_ASSERT(m_putJob);
2337  if (!m_putJob) return; // Don't crash
2338  m_getJob->d_func()->internalSuspend();
2339  m_putJob->d_func()->internalResume(); // Drink the beer
2340  m_buffer += data;
2341 
2342  // On the first set of data incoming, we tell the "put" slave about our
2343  // decision about resuming
2344  if (!m_resumeAnswerSent)
2345  {
2346  m_resumeAnswerSent = true;
2347  //kDebug(7007) << "(first time) -> send resume answer " << m_canResume;
2348  jobSlave(m_putJob)->sendResumeAnswer( m_canResume );
2349  }
2350 }
2351 
2352 void FileCopyJobPrivate::slotDataReq( KIO::Job * , QByteArray &data)
2353 {
2354  Q_Q(FileCopyJob);
2355  //kDebug(7007);
2356  if (!m_resumeAnswerSent && !m_getJob) {
2357  // This can't happen
2358  q->setError( ERR_INTERNAL );
2359  q->setErrorText( "'Put' job did not send canResume or 'Get' job did not send data!" );
2360  m_putJob->kill( FileCopyJob::Quietly );
2361  q->removeSubjob(m_putJob);
2362  m_putJob = 0;
2363  q->emitResult();
2364  return;
2365  }
2366  if (m_getJob)
2367  {
2368  m_getJob->d_func()->internalResume(); // Order more beer
2369  m_putJob->d_func()->internalSuspend();
2370  }
2371  data = m_buffer;
2372  m_buffer = QByteArray();
2373 }
2374 
2375 void FileCopyJobPrivate::slotMimetype( KIO::Job*, const QString& type )
2376 {
2377  Q_Q(FileCopyJob);
2378  emit q->mimetype( q, type );
2379 }
2380 
2381 void FileCopyJob::slotResult( KJob *job)
2382 {
2383  Q_D(FileCopyJob);
2384  //kDebug(7007) << "this=" << this << "job=" << job;
2385  removeSubjob(job);
2386  // Did job have an error ?
2387  if ( job->error() )
2388  {
2389  if ((job == d->m_moveJob) && (job->error() == ERR_UNSUPPORTED_ACTION))
2390  {
2391  d->m_moveJob = 0;
2392  d->startBestCopyMethod();
2393  return;
2394  }
2395  else if ((job == d->m_copyJob) && (job->error() == ERR_UNSUPPORTED_ACTION))
2396  {
2397  d->m_copyJob = 0;
2398  d->startDataPump();
2399  return;
2400  }
2401  else if (job == d->m_getJob)
2402  {
2403  d->m_getJob = 0L;
2404  if (d->m_putJob)
2405  {
2406  d->m_putJob->kill( Quietly );
2407  removeSubjob( d->m_putJob );
2408  }
2409  }
2410  else if (job == d->m_putJob)
2411  {
2412  d->m_putJob = 0L;
2413  if (d->m_getJob)
2414  {
2415  d->m_getJob->kill( Quietly );
2416  removeSubjob( d->m_getJob );
2417  }
2418  }
2419  setError( job->error() );
2420  setErrorText( job->errorText() );
2421  emitResult();
2422  return;
2423  }
2424 
2425  if (d->m_mustChmod)
2426  {
2427  // If d->m_permissions == -1, keep the default permissions
2428  if (d->m_permissions != -1)
2429  {
2430  d->m_chmodJob = chmod(d->m_dest, d->m_permissions);
2431  }
2432  d->m_mustChmod = false;
2433  }
2434 
2435  if (job == d->m_moveJob)
2436  {
2437  d->m_moveJob = 0; // Finished
2438  }
2439 
2440  if (job == d->m_copyJob)
2441  {
2442  d->m_copyJob = 0;
2443  if (d->m_move)
2444  {
2445  d->m_delJob = file_delete( d->m_src, HideProgressInfo/*no GUI*/ ); // Delete source
2446  addSubjob(d->m_delJob);
2447  }
2448  }
2449 
2450  if (job == d->m_getJob)
2451  {
2452  //kDebug(7007) << "m_getJob finished";
2453  d->m_getJob = 0; // No action required
2454  if (d->m_putJob)
2455  d->m_putJob->d_func()->internalResume();
2456  }
2457 
2458  if (job == d->m_putJob)
2459  {
2460  //kDebug(7007) << "m_putJob finished";
2461  d->m_putJob = 0;
2462  if (d->m_getJob)
2463  {
2464  // The get job is still running, probably after emitting data(QByteArray())
2465  // and before we receive its finished().
2466  d->m_getJob->d_func()->internalResume();
2467  }
2468  if (d->m_move)
2469  {
2470  d->m_delJob = file_delete( d->m_src, HideProgressInfo/*no GUI*/ ); // Delete source
2471  addSubjob(d->m_delJob);
2472  }
2473  }
2474 
2475  if (job == d->m_delJob)
2476  {
2477  d->m_delJob = 0; // Finished
2478  }
2479 
2480  if (job == d->m_chmodJob)
2481  {
2482  d->m_chmodJob = 0; // Finished
2483  }
2484 
2485  if ( !hasSubjobs() )
2486  emitResult();
2487 }
2488 
2489 FileCopyJob *KIO::file_copy( const KUrl& src, const KUrl& dest, int permissions,
2490  JobFlags flags )
2491 {
2492  return FileCopyJobPrivate::newJob(src, dest, permissions, false, flags);
2493 }
2494 
2495 FileCopyJob *KIO::file_move( const KUrl& src, const KUrl& dest, int permissions,
2496  JobFlags flags )
2497 {
2498  FileCopyJob* job = FileCopyJobPrivate::newJob(src, dest, permissions, true, flags);
2499  ClipboardUpdater::create(job, ClipboardUpdater::UpdateContent);
2500  return job;
2501 }
2502 
2503 SimpleJob *KIO::file_delete( const KUrl& src, JobFlags flags )
2504 {
2505  KIO_ARGS << src << qint8(true); // isFile
2506  SimpleJob* job = SimpleJobPrivate::newJob(src, CMD_DEL, packedArgs, flags);
2507  ClipboardUpdater::create(job, ClipboardUpdater::RemoveContent);
2508  return job;
2509 }
2510 
2512 
2513 class KIO::ListJobPrivate: public KIO::SimpleJobPrivate
2514 {
2515 public:
2516  ListJobPrivate(const KUrl& url, bool _recursive,
2517  const QString &prefix, const QString &displayPrefix,
2518  bool _includeHidden)
2519  : SimpleJobPrivate(url, CMD_LISTDIR, QByteArray()),
2520  recursive(_recursive), includeHidden(_includeHidden),
2521  m_prefix(prefix), m_displayPrefix(displayPrefix), m_processedEntries(0)
2522  {}
2523  bool recursive;
2524  bool includeHidden;
2525  QString m_prefix;
2526  QString m_displayPrefix;
2527  unsigned long m_processedEntries;
2528  KUrl m_redirectionURL;
2529 
2536  virtual void start( Slave *slave );
2537 
2538  void slotListEntries( const KIO::UDSEntryList& list );
2539  void slotRedirection( const KUrl &url );
2540  void gotEntries( KIO::Job * subjob, const KIO::UDSEntryList& list );
2541 
2542  Q_DECLARE_PUBLIC(ListJob)
2543 
2544  static inline ListJob *newJob(const KUrl& u, bool _recursive,
2545  const QString &prefix, const QString &displayPrefix,
2546  bool _includeHidden, JobFlags flags = HideProgressInfo)
2547  {
2548  ListJob *job = new ListJob(*new ListJobPrivate(u, _recursive, prefix, displayPrefix, _includeHidden));
2549  job->setUiDelegate(new JobUiDelegate);
2550  if (!(flags & HideProgressInfo))
2551  KIO::getJobTracker()->registerJob(job);
2552  return job;
2553  }
2554  static inline ListJob *newJobNoUi(const KUrl& u, bool _recursive,
2555  const QString &prefix, const QString &displayPrefix,
2556  bool _includeHidden)
2557  {
2558  return new ListJob(*new ListJobPrivate(u, _recursive, prefix, displayPrefix, _includeHidden));
2559  }
2560 };
2561 
2562 ListJob::ListJob(ListJobPrivate &dd)
2563  : SimpleJob(dd)
2564 {
2565  Q_D(ListJob);
2566  // We couldn't set the args when calling the parent constructor,
2567  // so do it now.
2568  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
2569  stream << d->m_url;
2570 }
2571 
2572 ListJob::~ListJob()
2573 {
2574 }
2575 
2576 void ListJobPrivate::slotListEntries( const KIO::UDSEntryList& list )
2577 {
2578  Q_Q(ListJob);
2579  // Emit progress info (takes care of emit processedSize and percent)
2580  m_processedEntries += list.count();
2581  slotProcessedSize( m_processedEntries );
2582 
2583  if (recursive) {
2584  UDSEntryList::ConstIterator it = list.begin();
2585  const UDSEntryList::ConstIterator end = list.end();
2586 
2587  for (; it != end; ++it) {
2588 
2589  const UDSEntry& entry = *it;
2590 
2591  KUrl itemURL;
2592  // const UDSEntry::ConstIterator end2 = entry.end();
2593  // UDSEntry::ConstIterator it2 = entry.find( KIO::UDSEntry::UDS_URL );
2594  // if ( it2 != end2 )
2595  if (entry.contains(KIO::UDSEntry::UDS_URL))
2596  // itemURL = it2.value().toString();
2597  itemURL = entry.stringValue(KIO::UDSEntry::UDS_URL);
2598  else { // no URL, use the name
2599  itemURL = q->url();
2600  const QString fileName = entry.stringValue(KIO::UDSEntry::UDS_NAME);
2601  Q_ASSERT(!fileName.isEmpty()); // we'll recurse forever otherwise :)
2602  itemURL.addPath(fileName);
2603  }
2604 
2605  if (entry.isDir() && !entry.isLink()) {
2606  const QString filename = itemURL.fileName();
2607  QString displayName = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
2608  if (displayName.isEmpty())
2609  displayName = filename;
2610  // skip hidden dirs when listing if requested
2611  if (filename != ".." && filename != "." && (includeHidden || filename[0] != '.')) {
2612  ListJob *job = ListJobPrivate::newJobNoUi(itemURL,
2613  true /*recursive*/,
2614  m_prefix + filename + '/',
2615  m_displayPrefix + displayName + '/',
2616  includeHidden);
2617  Scheduler::setJobPriority(job, 1);
2618  q->connect(job, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
2619  SLOT(gotEntries(KIO::Job*,KIO::UDSEntryList)));
2620  q->addSubjob(job);
2621  }
2622  }
2623  }
2624  }
2625 
2626  // Not recursive, or top-level of recursive listing : return now (send . and .. as well)
2627  // exclusion of hidden files also requires the full sweep, but the case for full-listing
2628  // a single dir is probably common enough to justify the shortcut
2629  if (m_prefix.isNull() && includeHidden) {
2630  emit q->entries(q, list);
2631  } else {
2632  // cull the unwanted hidden dirs and/or parent dir references from the listing, then emit that
2633  UDSEntryList newlist;
2634 
2635  UDSEntryList::const_iterator it = list.begin();
2636  const UDSEntryList::const_iterator end = list.end();
2637  for (; it != end; ++it) {
2638 
2639  // Modify the name in the UDSEntry
2640  UDSEntry newone = *it;
2641  const QString filename = newone.stringValue( KIO::UDSEntry::UDS_NAME );
2642  QString displayName = newone.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
2643  if (displayName.isEmpty())
2644  displayName = filename;
2645  // Avoid returning entries like subdir/. and subdir/.., but include . and .. for
2646  // the toplevel dir, and skip hidden files/dirs if that was requested
2647  if ( (m_prefix.isNull() || (filename != ".." && filename != ".") )
2648  && (includeHidden || (filename[0] != '.') ) )
2649  {
2650  // ## Didn't find a way to use the iterator instead of re-doing a key lookup
2651  newone.insert( KIO::UDSEntry::UDS_NAME, m_prefix + filename );
2652  newone.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, m_displayPrefix + displayName);
2653  newlist.append(newone);
2654  }
2655  }
2656 
2657  emit q->entries(q, newlist);
2658  }
2659 }
2660 
2661 void ListJobPrivate::gotEntries(KIO::Job *, const KIO::UDSEntryList& list )
2662 {
2663  // Forward entries received by subjob - faking we received them ourselves
2664  Q_Q(ListJob);
2665  emit q->entries(q, list);
2666 }
2667 
2668 void ListJob::slotResult( KJob * job )
2669 {
2670  if (job->error()) {
2671  // If we can't list a subdir, the result is still ok
2672  // This is why we override KCompositeJob::slotResult - to not set
2673  // an error on parent job.
2674  // Let's emit a signal about this though
2675  emit subError(this, static_cast<KIO::ListJob*>(job));
2676  }
2677  removeSubjob(job);
2678  if (!hasSubjobs())
2679  emitResult();
2680 }
2681 
2682 void ListJobPrivate::slotRedirection( const KUrl & url )
2683 {
2684  Q_Q(ListJob);
2685  if (!KAuthorized::authorizeUrlAction("redirect", m_url, url))
2686  {
2687  kWarning(7007) << "ListJob: Redirection from " << m_url << " to " << url << " REJECTED!";
2688  return;
2689  }
2690  m_redirectionURL = url; // We'll remember that when the job finishes
2691  emit q->redirection( q, m_redirectionURL );
2692 }
2693 
2694 void ListJob::slotFinished()
2695 {
2696  Q_D(ListJob);
2697 
2698  // Support for listing archives as directories
2699  if ( error() == KIO::ERR_IS_FILE && d->m_url.isLocalFile() ) {
2700  KMimeType::Ptr ptr = KMimeType::findByUrl( d->m_url, 0, true, true );
2701  if ( ptr ) {
2702  QString proto = ptr->property("X-KDE-LocalProtocol").toString();
2703  if ( !proto.isEmpty() && KProtocolInfo::isKnownProtocol( proto) ) {
2704  d->m_redirectionURL = d->m_url;
2705  d->m_redirectionURL.setProtocol( proto );
2706  setError( 0 );
2707  emit redirection(this,d->m_redirectionURL);
2708  }
2709  }
2710  }
2711 
2712  if ( !d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() && !error() ) {
2713 
2714  //kDebug(7007) << "Redirection to " << d->m_redirectionURL;
2715  if (queryMetaData("permanent-redirect")=="true")
2716  emit permanentRedirection(this, d->m_url, d->m_redirectionURL);
2717 
2718  if ( d->m_redirectionHandlingEnabled ) {
2719  d->m_packedArgs.truncate(0);
2720  QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
2721  stream << d->m_redirectionURL;
2722 
2723  d->restartAfterRedirection(&d->m_redirectionURL);
2724  return;
2725  }
2726  }
2727 
2728  // Return slave to the scheduler
2729  SimpleJob::slotFinished();
2730 }
2731 
2732 void ListJob::slotMetaData( const KIO::MetaData &_metaData)
2733 {
2734  Q_D(ListJob);
2735  SimpleJob::slotMetaData(_metaData);
2736  storeSSLSessionFromJob(d->m_redirectionURL);
2737 }
2738 
2739 ListJob *KIO::listDir( const KUrl& url, JobFlags flags, bool includeHidden )
2740 {
2741  return ListJobPrivate::newJob(url, false, QString(), QString(), includeHidden, flags);
2742 }
2743 
2744 ListJob *KIO::listRecursive( const KUrl& url, JobFlags flags, bool includeHidden )
2745 {
2746  return ListJobPrivate::newJob(url, true, QString(), QString(), includeHidden, flags);
2747 }
2748 
2749 void ListJob::setUnrestricted(bool unrestricted)
2750 {
2751  Q_D(ListJob);
2752  if (unrestricted)
2753  d->m_extraFlags |= JobPrivate::EF_ListJobUnrestricted;
2754  else
2755  d->m_extraFlags &= ~JobPrivate::EF_ListJobUnrestricted;
2756 }
2757 
2758 void ListJobPrivate::start(Slave *slave)
2759 {
2760  Q_Q(ListJob);
2761  if (!KAuthorized::authorizeUrlAction("list", m_url, m_url) &&
2762  !(m_extraFlags & EF_ListJobUnrestricted))
2763  {
2764  q->setError( ERR_ACCESS_DENIED );
2765  q->setErrorText( m_url.url() );
2766  QTimer::singleShot(0, q, SLOT(slotFinished()) );
2767  return;
2768  }
2769  q->connect( slave, SIGNAL(listEntries(KIO::UDSEntryList)),
2770  SLOT(slotListEntries(KIO::UDSEntryList)));
2771  q->connect( slave, SIGNAL(totalSize(KIO::filesize_t)),
2772  SLOT(slotTotalSize(KIO::filesize_t)) );
2773  q->connect( slave, SIGNAL(redirection(KUrl)),
2774  SLOT(slotRedirection(KUrl)) );
2775 
2776  SimpleJobPrivate::start(slave);
2777 }
2778 
2779 const KUrl& ListJob::redirectionUrl() const
2780 {
2781  return d_func()->m_redirectionURL;
2782 }
2783 
2785 
2786 class KIO::MultiGetJobPrivate: public KIO::TransferJobPrivate
2787 {
2788 public:
2789  MultiGetJobPrivate(const KUrl& url)
2790  : TransferJobPrivate(url, 0, QByteArray(), QByteArray()),
2791  m_currentEntry( 0, KUrl(), MetaData() )
2792  {}
2793  struct GetRequest {
2794  GetRequest(long _id, const KUrl &_url, const MetaData &_metaData)
2795  : id(_id), url(_url), metaData(_metaData) { }
2796  long id;
2797  KUrl url;
2798  MetaData metaData;
2799 
2800  inline bool operator==( const GetRequest& req ) const
2801  { return req.id == id; }
2802  };
2803  typedef QLinkedList<GetRequest> RequestQueue;
2804 
2805  RequestQueue m_waitQueue;
2806  RequestQueue m_activeQueue;
2807  GetRequest m_currentEntry;
2808  bool b_multiGetActive;
2809 
2816  virtual void start(Slave *slave);
2817 
2818  bool findCurrentEntry();
2819  void flushQueue(QLinkedList<GetRequest> &queue);
2820 
2821  Q_DECLARE_PUBLIC(MultiGetJob)
2822 
2823  static inline MultiGetJob *newJob(const KUrl &url)
2824  {
2825  MultiGetJob *job = new MultiGetJob(*new MultiGetJobPrivate(url));
2826  job->setUiDelegate(new JobUiDelegate);
2827  return job;
2828  }
2829 };
2830 
2831 MultiGetJob::MultiGetJob(MultiGetJobPrivate &dd)
2832  : TransferJob(dd)
2833 {
2834 }
2835 
2836 MultiGetJob::~MultiGetJob()
2837 {
2838 }
2839 
2840 void MultiGetJob::get(long id, const KUrl &url, const MetaData &metaData)
2841 {
2842  Q_D(MultiGetJob);
2843  MultiGetJobPrivate::GetRequest entry(id, url, metaData);
2844  entry.metaData["request-id"] = QString::number(id);
2845  d->m_waitQueue.append(entry);
2846 }
2847 
2848 void MultiGetJobPrivate::flushQueue(RequestQueue &queue)
2849 {
2850  // Use multi-get
2851  // Scan all jobs in m_waitQueue
2852  RequestQueue::iterator wqit = m_waitQueue.begin();
2853  const RequestQueue::iterator wqend = m_waitQueue.end();
2854  while ( wqit != wqend )
2855  {
2856  const GetRequest& entry = *wqit;
2857  if ((m_url.protocol() == entry.url.protocol()) &&
2858  (m_url.host() == entry.url.host()) &&
2859  (m_url.port() == entry.url.port()) &&
2860  (m_url.user() == entry.url.user()))
2861  {
2862  queue.append( entry );
2863  wqit = m_waitQueue.erase( wqit );
2864  }
2865  else
2866  {
2867  ++wqit;
2868  }
2869  }
2870  // Send number of URLs, (URL, metadata)*
2871  KIO_ARGS << (qint32) queue.count();
2872  RequestQueue::const_iterator qit = queue.begin();
2873  const RequestQueue::const_iterator qend = queue.end();
2874  for( ; qit != qend; ++qit )
2875  {
2876  stream << (*qit).url << (*qit).metaData;
2877  }
2878  m_packedArgs = packedArgs;
2879  m_command = CMD_MULTI_GET;
2880  m_outgoingMetaData.clear();
2881 }
2882 
2883 void MultiGetJobPrivate::start(Slave *slave)
2884 {
2885  // Add first job from m_waitQueue and add it to m_activeQueue
2886  GetRequest entry = m_waitQueue.takeFirst();
2887  m_activeQueue.append(entry);
2888 
2889  m_url = entry.url;
2890 
2891  if (!entry.url.protocol().startsWith(QLatin1String("http")))
2892  {
2893  // Use normal get
2894  KIO_ARGS << entry.url;
2895  m_packedArgs = packedArgs;
2896  m_outgoingMetaData = entry.metaData;
2897  m_command = CMD_GET;
2898  b_multiGetActive = false;
2899  }
2900  else
2901  {
2902  flushQueue(m_activeQueue);
2903  b_multiGetActive = true;
2904  }
2905 
2906  TransferJobPrivate::start(slave); // Anything else to do??
2907 }
2908 
2909 bool MultiGetJobPrivate::findCurrentEntry()
2910 {
2911  if (b_multiGetActive)
2912  {
2913  long id = m_incomingMetaData["request-id"].toLong();
2914  RequestQueue::const_iterator qit = m_activeQueue.begin();
2915  const RequestQueue::const_iterator qend = m_activeQueue.end();
2916  for( ; qit != qend; ++qit )
2917  {
2918  if ((*qit).id == id)
2919  {
2920  m_currentEntry = *qit;
2921  return true;
2922  }
2923  }
2924  m_currentEntry.id = 0;
2925  return false;
2926  }
2927  else
2928  {
2929  if ( m_activeQueue.isEmpty() )
2930  return false;
2931  m_currentEntry = m_activeQueue.first();
2932  return true;
2933  }
2934 }
2935 
2936 void MultiGetJob::slotRedirection( const KUrl &url)
2937 {
2938  Q_D(MultiGetJob);
2939  if (!d->findCurrentEntry()) return; // Error
2940  if (!KAuthorized::authorizeUrlAction("redirect", d->m_url, url))
2941  {
2942  kWarning(7007) << "MultiGetJob: Redirection from " << d->m_currentEntry.url << " to " << url << " REJECTED!";
2943  return;
2944  }
2945  d->m_redirectionURL = url;
2946  get(d->m_currentEntry.id, d->m_redirectionURL, d->m_currentEntry.metaData); // Try again
2947 }
2948 
2949 
2950 void MultiGetJob::slotFinished()
2951 {
2952  Q_D(MultiGetJob);
2953  if (!d->findCurrentEntry()) return;
2954  if (d->m_redirectionURL.isEmpty())
2955  {
2956  // No redirection, tell the world that we are finished.
2957  emit result(d->m_currentEntry.id);
2958  }
2959  d->m_redirectionURL = KUrl();
2960  setError( 0 );
2961  d->m_incomingMetaData.clear();
2962  d->m_activeQueue.removeAll(d->m_currentEntry);
2963  if (d->m_activeQueue.count() == 0)
2964  {
2965  if (d->m_waitQueue.count() == 0)
2966  {
2967  // All done
2968  TransferJob::slotFinished();
2969  }
2970  else
2971  {
2972  // return slave to pool
2973  // fetch new slave for first entry in d->m_waitQueue and call start
2974  // again.
2975  d->slaveDone();
2976 
2977  d->m_url = d->m_waitQueue.first().url;
2978  if ((d->m_extraFlags & JobPrivate::EF_KillCalled) == 0) {
2979  Scheduler::doJob(this);
2980  }
2981  }
2982  }
2983 }
2984 
2985 void MultiGetJob::slotData( const QByteArray &_data)
2986 {
2987  Q_D(MultiGetJob);
2988  if(d->m_redirectionURL.isEmpty() || !d->m_redirectionURL.isValid() || error())
2989  emit data(d->m_currentEntry.id, _data);
2990 }
2991 
2992 void MultiGetJob::slotMimetype( const QString &_mimetype )
2993 {
2994  Q_D(MultiGetJob);
2995  if (d->b_multiGetActive)
2996  {
2997  MultiGetJobPrivate::RequestQueue newQueue;
2998  d->flushQueue(newQueue);
2999  if (!newQueue.isEmpty())
3000  {
3001  d->m_activeQueue += newQueue;
3002  d->m_slave->send( d->m_command, d->m_packedArgs );
3003  }
3004  }
3005  if (!d->findCurrentEntry()) return; // Error, unknown request!
3006  emit mimetype(d->m_currentEntry.id, _mimetype);
3007 }
3008 
3009 MultiGetJob *KIO::multi_get(long id, const KUrl &url, const MetaData &metaData)
3010 {
3011  MultiGetJob * job = MultiGetJobPrivate::newJob(url);
3012  job->get(id, url, metaData);
3013  return job;
3014 }
3015 
3016 class KIO::SpecialJobPrivate: public TransferJobPrivate
3017 {
3018  SpecialJobPrivate(const KUrl& url, int command,
3019  const QByteArray &packedArgs,
3020  const QByteArray &_staticData)
3021  : TransferJobPrivate(url, command, packedArgs, _staticData)
3022  {}
3023 };
3024 
3025 SpecialJob::SpecialJob(const KUrl &url, const QByteArray &packedArgs)
3026  : TransferJob(*new TransferJobPrivate(url, CMD_SPECIAL, packedArgs, QByteArray()))
3027 {
3028 }
3029 
3030 SpecialJob::~SpecialJob()
3031 {
3032 }
3033 
3034 void SpecialJob::setArguments(const QByteArray &data)
3035 {
3036  Q_D(SpecialJob);
3037  d->m_packedArgs = data;
3038 }
3039 
3040 QByteArray SpecialJob::arguments() const
3041 {
3042  return d_func()->m_packedArgs;
3043 }
3044 
3045 // Never defined, never used - what's this code about?
3046 #ifdef CACHE_INFO
3047 CacheInfo::CacheInfo(const KUrl &url)
3048 {
3049  m_url = url;
3050 }
3051 
3052 QString CacheInfo::cachedFileName()
3053 {
3054  const QChar separator = '_';
3055 
3056  QString CEF = m_url.path();
3057 
3058  int p = CEF.find('/');
3059 
3060  while(p != -1)
3061  {
3062  CEF[p] = separator;
3063  p = CEF.find('/', p);
3064  }
3065 
3066  QString host = m_url.host().toLower();
3067  CEF = host + CEF + '_';
3068 
3069  QString dir = KProtocolManager::cacheDir();
3070  if (dir[dir.length()-1] != '/')
3071  dir += '/';
3072 
3073  int l = m_url.host().length();
3074  for(int i = 0; i < l; i++)
3075  {
3076  if (host[i].isLetter() && (host[i] != 'w'))
3077  {
3078  dir += host[i];
3079  break;
3080  }
3081  }
3082  if (dir[dir.length()-1] == '/')
3083  dir += '0';
3084 
3085  unsigned long hash = 0x00000000;
3086  QString u = m_url.url().toLatin1();
3087  for(int i = u.length(); i--;)
3088  {
3089  hash = (hash * 12211 + u[i]) % 2147483563;
3090  }
3091 
3092  QString hashString;
3093  hashString.sprintf("%08lx", hash);
3094 
3095  CEF = CEF + hashString;
3096 
3097  CEF = dir + '/' + CEF;
3098 
3099  return CEF;
3100 }
3101 
3102 QFile *CacheInfo::cachedFile()
3103 {
3104 #ifdef Q_WS_WIN
3105  const char *mode = (readWrite ? "rb+" : "rb");
3106 #else
3107  const char *mode = (readWrite ? "r+" : "r");
3108 #endif
3109 
3110  FILE *fs = KDE::fopen(CEF, mode); // Open for reading and writing
3111  if (!fs)
3112  return 0;
3113 
3114  char buffer[401];
3115  bool ok = true;
3116 
3117  // CacheRevision
3118  if (ok && (!fgets(buffer, 400, fs)))
3119  ok = false;
3120  if (ok && (strcmp(buffer, CACHE_REVISION) != 0))
3121  ok = false;
3122 
3123  time_t date;
3124  time_t currentDate = time(0);
3125 
3126  // URL
3127  if (ok && (!fgets(buffer, 400, fs)))
3128  ok = false;
3129  if (ok)
3130  {
3131  int l = strlen(buffer);
3132  if (l>0)
3133  buffer[l-1] = 0; // Strip newline
3134  if (m_.url.url() != buffer)
3135  {
3136  ok = false; // Hash collision
3137  }
3138  }
3139 
3140  // Creation Date
3141  if (ok && (!fgets(buffer, 400, fs)))
3142  ok = false;
3143  if (ok)
3144  {
3145  date = (time_t) strtoul(buffer, 0, 10);
3146  if (m_maxCacheAge && (difftime(currentDate, date) > m_maxCacheAge))
3147  {
3148  m_bMustRevalidate = true;
3149  m_expireDate = currentDate;
3150  }
3151  }
3152 
3153  // Expiration Date
3154  m_cacheExpireDateOffset = KDE_ftell(fs);
3155  if (ok && (!fgets(buffer, 400, fs)))
3156  ok = false;
3157  if (ok)
3158  {
3159  if (m_request.cache == CC_Verify)
3160  {
3161  date = (time_t) strtoul(buffer, 0, 10);
3162  // After the expire date we need to revalidate.
3163  if (!date || difftime(currentDate, date) >= 0)
3164  m_bMustRevalidate = true;
3165  m_expireDate = date;
3166  }
3167  }
3168 
3169  // ETag
3170  if (ok && (!fgets(buffer, 400, fs)))
3171  ok = false;
3172  if (ok)
3173  {
3174  m_etag = QString(buffer).trimmed();
3175  }
3176 
3177  // Last-Modified
3178  if (ok && (!fgets(buffer, 400, fs)))
3179  ok = false;
3180  if (ok)
3181  {
3182  m_lastModified = QString(buffer).trimmed();
3183  }
3184 
3185  fclose(fs);
3186 
3187  if (ok)
3188  return fs;
3189 
3190  unlink( QFile::encodeName(CEF) );
3191  return 0;
3192 
3193 }
3194 
3195 void CacheInfo::flush()
3196 {
3197  cachedFile().remove();
3198 }
3199 
3200 void CacheInfo::touch()
3201 {
3202 
3203 }
3204 void CacheInfo::setExpireDate(int);
3205 void CacheInfo::setExpireTimeout(int);
3206 
3207 
3208 int CacheInfo::creationDate();
3209 int CacheInfo::expireDate();
3210 int CacheInfo::expireTimeout();
3211 #endif
3212 
3213 #include "jobclasses.moc"
3214 #include "job_p.moc"
KIO::JobUiDelegate::setWindow
virtual void setWindow(QWidget *window)
Associate this job with a window given by window.
Definition: jobuidelegate.cpp:58
KIO::UDSEntry::UDS_URL
An alternative URL (If different from the caption).
Definition: udsentry.h:190
KIO::Scheduler::removeSlaveOnHold
static void removeSlaveOnHold()
Removes any slave that might have been put on hold.
Definition: scheduler.cpp:825
KIO::Job::mergeMetaData
void mergeMetaData(const QMap< QString, QString > &values)
Add key/value pairs to the meta data that is sent to the slave.
Definition: job.cpp:277
KIO::TransferJobPrivate::internalResume
void internalResume()
Flow control.
Definition: job.cpp:1222
KIO::StatJob::setDetails
void setDetails(short int details)
Selects the level of details we want.
Definition: job.cpp:834
i18n
QString i18n(const char *text)
KCompositeJob::kill
bool kill(KillVerbosity verbosity=Quietly)
jobSlave
static Slave * jobSlave(SimpleJob *job)
Definition: job.cpp:68
KIO::Job::showErrorDialog
void showErrorDialog(QWidget *parent=0)
Display a dialog box to inform the user of the error given by this job.
Definition: job.cpp:216
KIO::Overwrite
When set, automatically overwrite the destination if it exists already.
Definition: jobclasses.h:67
KIO::unmount
SimpleJob * unmount(const QString &point, JobFlags flags=DefaultFlags)
Unmount filesystem.
Definition: job.cpp:762
KCompositeJob::addSubjob
virtual bool addSubjob(KJob *job)
KIO::JobPrivate::emitUnmounting
static void emitUnmounting(KIO::Job *, const QString &point)
Definition: job.cpp:169
qint64
KIO::MultiGetJob::~MultiGetJob
virtual ~MultiGetJob()
Definition: job.cpp:2836
KIO::Scheduler::doJob
static void doJob(SimpleJob *job)
Register job with the scheduler.
Definition: scheduler.cpp:793
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
KIO::TransferJob::slotRedirection
virtual void slotRedirection(const KUrl &url)
Definition: job.cpp:1009
KIO::put
TransferJob * put(const KUrl &url, int permissions, JobFlags flags=DefaultFlags)
Put (a.k.a.
Definition: job.cpp:1716
KIO::special
SimpleJob * special(const KUrl &url, const QByteArray &data, JobFlags flags=DefaultFlags)
Execute any command that is specific to one slave (protocol).
Definition: job.cpp:745
KIO::MultiGetJob::data
void data(long id, const QByteArray &data)
Data from the slave has arrived.
KUrl::directory
QString directory(const DirectoryOptions &options=IgnoreTrailingSlash) const
KIO::Slave::resume
virtual void resume()
Resumes the operation of the attached kioslave.
Definition: slave.cpp:320
OrgKdeKDirNotifyInterface::emitFileRenamed
static void emitFileRenamed(const QString &src, const QString &dst)
Definition: kdirnotify.cpp:37
KIO::Job::~Job
virtual ~Job()
Definition: job.cpp:86
KIO::TransferJobPrivate::slotPostRedirection
void slotPostRedirection()
Definition: job.cpp:1707
KIO::UDSEntry::isLink
bool isLink() const
Definition: udsentry.cpp:89
KIO::SimpleJob::removeOnHold
static void removeOnHold()
Discard suspended slave.
Definition: job.cpp:359
KIO::StoredTransferJob::StoredTransferJob
StoredTransferJob(StoredTransferJobPrivate &dd)
Definition: job.cpp:1724
KIO::Job::addMetaData
void addMetaData(const QString &key, const QString &value)
Add key/value pair to the meta data that is sent to the slave.
Definition: job.cpp:264
KIO::StoredTransferJob::~StoredTransferJob
~StoredTransferJob()
Definition: job.cpp:1733
KIO::R_RESUME
Definition: renamedialog.h:61
KCompositeJob::setCapabilities
void setCapabilities(Capabilities capabilities)
KIO::MultiGetJob::get
void get(long id, const KUrl &url, const MetaData &metaData)
Get an additional file.
Definition: job.cpp:2840
kdebug.h
KIO::TransferJob::permanentRedirection
void permanentRedirection(KIO::Job *job, const KUrl &fromUrl, const KUrl &toUrl)
Signals a permanent redirection.
KIO::M_NORENAME
Definition: renamedialog.h:56
KCompositeJob::emitResult
void emitResult()
kmimetype.h
KIO::Job::setMetaData
void setMetaData(const KIO::MetaData &metaData)
Set meta data to be sent to the slave, replacing existing meta data.
Definition: job.cpp:258
KIO::CMD_CHOWN
Definition: global.h:181
KIO::TransferJobPrivate::slotNeedSubUrlData
void slotNeedSubUrlData()
Definition: job.cpp:1286
KCompositeJob::setUiDelegate
void setUiDelegate(KJobUiDelegate *delegate)
KCompositeJob::Quietly
KIO::SimpleJobPrivate::slotConnected
void slotConnected()
Called on a slave's connected signal.
Definition: job.cpp:521
KIO::TransferJobPrivate::staticData
QByteArray staticData
Definition: job_p.h:277
KIO::SimpleJobPrivate::slotSpeed
void slotSpeed(unsigned long speed)
Forward signal from the slave.
Definition: job.cpp:542
KIO::UDSEntry
Universal Directory Service.
Definition: udsentry.h:58
KIO::Scheduler::setJobPriority
static void setJobPriority(SimpleJob *job, int priority)
Changes the priority of job; jobs of the same priority run in the order in which they were created...
Definition: scheduler.cpp:805
KIO::ListJob::slotFinished
virtual void slotFinished()
Definition: job.cpp:2694
KProtocolInfo::isKnownProtocol
static bool isKnownProtocol(const KUrl &url)
KIO::TransferJob::redirection
void redirection(KIO::Job *job, const KUrl &url)
Signals a redirection.
kauthorized.h
kdirwatch.h
KIO::R_OVERWRITE
Definition: renamedialog.h:61
KIO::ERR_MALFORMED_URL
Definition: global.h:199
KIO::ListJob
A ListJob is allows you to get the get the content of a directory.
Definition: jobclasses.h:936
KIO::UDSEntry::insert
void insert(uint field, const QString &value)
insert field with numeric value
Definition: udsentry.cpp:94
KIO::SimpleJob::SimpleJob
SimpleJob(SimpleJobPrivate &dd)
Creates a new simple job.
Definition: job.cpp:292
kdirnotify.h
KIO::mimetype
MimetypeJob * mimetype(const KUrl &url, JobFlags flags=DefaultFlags)
Find mimetype for one file or directory.
Definition: job.cpp:1872
slave.h
KIO::JobPrivate::slotSpeed
void slotSpeed(KJob *job, unsigned long speed)
Definition: job.cpp:207
KIO::SimpleJobPrivate::slotProcessedSize
void slotProcessedSize(KIO::filesize_t data_size)
Forward signal from the slave.
Definition: job.cpp:535
KIO::HideProgressInfo
Hide progress information dialog, i.e.
Definition: jobclasses.h:51
kconfig.h
KIO::StoredTransferJob
StoredTransferJob is a TransferJob (for downloading or uploading data) that also stores a QByteArray ...
Definition: jobclasses.h:743
KIO::CMD_SUBURL
Definition: global.h:174
KIO::FileCopyJob::doSuspend
bool doSuspend()
Suspend this job.
Definition: job.cpp:2155
QWidget
KCompositeJob::setError
void setError(int errorCode)
KIO::CMD_STAT
Definition: global.h:161
KIO::Slave::suspended
virtual bool suspended()
Tells whether the kioslave is suspended.
Definition: slave.cpp:326
KIO::StatJob::setSide
void setSide(StatSide side)
A stat() can have two meanings.
Definition: job.cpp:829
KIO::ERR_USER_CANCELED
Definition: global.h:214
KIO::mkdir
SimpleJob * mkdir(const KUrl &url, int permissions=-1)
Creates a single directory.
Definition: job.cpp:697
KIO::get
TransferJob * get(const KUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
Get (a.k.a.
Definition: job.cpp:1371
KIO::UDSEntry::isDir
bool isDir() const
Definition: udsentry.cpp:84
KIO::SimpleJob::slotError
void slotError(int, const QString &)
Definition: job.cpp:500
KIO::TransferJobPrivate::start
virtual void start(KIO::Slave *slave)
Definition: job.cpp:1244
KIO::SimpleJob::url
const KUrl & url() const
Returns the SimpleJob's URL.
Definition: job.cpp:341
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KIO::ListJob::subError
void subError(KIO::ListJob *job, KIO::ListJob *subJob)
This signal is emitted when a sub-directory could not be listed.
KIO::FileCopyJob::slotResult
virtual void slotResult(KJob *job)
Called whenever a subjob finishes.
Definition: job.cpp:2381
KIO::stat
StatJob * stat(const KUrl &url, JobFlags flags=DefaultFlags)
Find all details for one file or directory.
Definition: job.cpp:924
KIO::CMD_OPEN
Definition: global.h:180
KIO::file_delete
SimpleJob * file_delete(const KUrl &src, JobFlags flags=DefaultFlags)
Delete a single file.
Definition: job.cpp:2503
KIO::FileCopyJob::setSourceSize
void setSourceSize(KIO::filesize_t size)
If you know the size of the source file, call this method to inform this job.
Definition: job.cpp:2084
KConfig::group
KConfigGroup group(const QByteArray &group)
KIO::JobPrivate::emitStating
static void emitStating(KIO::Job *, const KUrl &url)
Definition: job.cpp:150
KIO::FileCopyJob::doResume
bool doResume()
Resume this job.
Definition: job.cpp:2174
KIO::multi_get
MultiGetJob * multi_get(long id, const KUrl &url, const MetaData &metaData)
Creates a new multiple get job.
Definition: job.cpp:3009
KIO::FileCopyJob::FileCopyJob
FileCopyJob(FileCopyJobPrivate &dd)
Definition: job.cpp:2011
KIO::CMD_MIMETYPE
Definition: global.h:162
KIO::SpecialJob::~SpecialJob
~SpecialJob()
Definition: job.cpp:3030
KIO::ListJob::slotMetaData
virtual void slotMetaData(const KIO::MetaData &_metaData)
Definition: job.cpp:2732
KIO::StatJob
A KIO job that retrieves information about a file or directory.
Definition: jobclasses.h:440
KIO::ClipboardUpdater::UpdateContent
Definition: clipboardupdater_p.h:55
KIO::DirectCopyJob
Definition: job_p.h:345
KIO::file_move
FileCopyJob * file_move(const KUrl &src, const KUrl &dest, int permissions=-1, JobFlags flags=DefaultFlags)
Move a single file.
Definition: job.cpp:2495
KIO::StatJob::slotFinished
virtual void slotFinished()
Definition: job.cpp:892
KIO::UDSEntry::UDS_LOCAL_PATH
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
Definition: udsentry.h:166
KIO::LoadType
LoadType
Definition: job.h:29
KIO::JobPrivate::EF_ListJobUnrestricted
Definition: job_p.h:51
KIO::SimpleJobPrivate::newJob
static SimpleJob * newJob(const KUrl &url, int command, const QByteArray &packedArgs, JobFlags flags=HideProgressInfo)
Definition: job_p.h:204
KIO::FileCopyJob::destUrl
KUrl destUrl() const
Returns the destination URL.
Definition: job.cpp:2103
QString
KIO::Job::removeSubjob
virtual bool removeSubjob(KJob *job)
Mark a sub job as being done.
Definition: job.cpp:118
KIO::JobUiDelegate::requestMessageBox
int requestMessageBox(MessageBoxType type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo, const QString &iconYes=QString(), const QString &iconNo=QString(), const QString &dontAskAgainName=QString(), const KIO::MetaData &sslMetaData=KIO::MetaData())
This function allows for the delegation user prompts from the ioslaves.
Definition: jobuidelegate.cpp:200
KIO::SimpleJob::doKill
virtual bool doKill()
Abort job.
Definition: job.cpp:313
KIO::mostLocalUrl
StatJob * mostLocalUrl(const KUrl &url, JobFlags flags=DefaultFlags)
Tries to map a local URL for the given URL, using a KIO job.
Definition: job.cpp:930
KIO::TransferJobPrivate::slotSubUrlData
void slotSubUrlData(KIO::Job *, const QByteArray &)
Definition: job.cpp:1297
KIO::CMD_SPECIAL
Definition: global.h:169
KIO::StoredTransferJob::setData
void setData(const QByteArray &arr)
Set data to be uploaded.
Definition: job.cpp:1737
KIO::SpecialJob
A class that sends a special command to an ioslave.
Definition: jobclasses.h:1021
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KIO::Job::queryMetaData
QString queryMetaData(const QString &key)
Query meta data received from the slave.
Definition: job.cpp:253
KIO::TransferJobPrivate::internalSuspend
void internalSuspend()
Flow control.
Definition: job.cpp:1215
klocale.h
KIO::MSG_DATA
Definition: slaveinterface.h:68
KIO::MkdirJob::permanentRedirection
void permanentRedirection(KIO::Job *job, const KUrl &fromUrl, const KUrl &toUrl)
Signals a permanent redirection.
KIO::SimpleJobPrivate
Definition: job_p.h:79
isUrlPortBad
static int isUrlPortBad(const KUrl &url)
Definition: job.cpp:1452
KIO::TransferJob::setTotalSize
void setTotalSize(KIO::filesize_t bytes)
Set the total size of data that we are going to send in a put job.
Definition: job.cpp:1003
KIO::Job::Job
Job()
Definition: job.cpp:76
KIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:396
KIO::MultiGetJob::slotMimetype
virtual void slotMimetype(const QString &mimetype)
Definition: job.cpp:2992
KProtocolManager::canRenameToFile
static bool canRenameToFile(const KUrl &url)
Returns whether the protocol can rename (i.e.
Definition: kprotocolmanager.cpp:1142
OrgKdeKDirNotifyInterface::emitFilesAdded
static void emitFilesAdded(const QString &directory)
Definition: kdirnotify.cpp:47
filejob.h
KIO::Scheduler::updateInternalMetaData
static void updateInternalMetaData(SimpleJob *job)
Updates the internal metadata from job.
Definition: scheduler.cpp:840
KIO::StoredTransferJob::data
QByteArray data() const
Get hold of the downloaded data.
Definition: job.cpp:1746
KIO::JobPrivate::emitMounting
static void emitMounting(KIO::Job *, const QString &dev, const QString &point)
Definition: job.cpp:162
KIO::TransferJobPrivate::newJob
static TransferJob * newJob(const KUrl &url, int command, const QByteArray &packedArgs, const QByteArray &_staticData, JobFlags flags)
Definition: job_p.h:315
KUrl
KIO::Job::addSubjob
virtual bool addSubjob(KJob *job)
Add a job that has to be finished before a result is emitted.
Definition: job.cpp:95
KIO::FileCopyJob::~FileCopyJob
~FileCopyJob()
Definition: job.cpp:2080
KIO::ListJob::setUnrestricted
void setUnrestricted(bool unrestricted)
Do not apply any KIOSK restrictions to this job.
Definition: job.cpp:2749
KDialogJobUiDelegate::showErrorMessage
virtual void showErrorMessage()
KIO::Slave
Definition: slave.h:48
KIO::TransferJob::isErrorPage
bool isErrorPage() const
Checks whether we got an error page.
Definition: job.cpp:1239
KIO::TransferJobPrivate::m_outgoingDataSource
QWeakPointer< QIODevice > m_outgoingDataSource
Definition: job_p.h:283
i18nc
QString i18nc(const char *ctxt, const char *text)
KIO::CMD_META_DATA
Definition: global.h:172
kprotocolmanager.h
KUrl::setPath
void setPath(const QString &path)
KIO::Job::ui
JobUiDelegate * ui() const
Retrieves the UI delegate of this job.
Definition: job.cpp:90
MAX_READ_BUF_SIZE
#define MAX_READ_BUF_SIZE
Definition: job.cpp:66
KIO::CMD_LISTDIR
Definition: global.h:163
KIO::Job::doResume
virtual bool doResume()
Resume this job.
Definition: job.cpp:196
KIO::TransferJob::slotData
virtual void slotData(const QByteArray &data)
Definition: job.cpp:988
scheduler.h
KIO::mount
SimpleJob * mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags=DefaultFlags)
Mount filesystem.
Definition: job.cpp:751
KIO::listDir
ListJob * listDir(const KUrl &url, JobFlags flags=DefaultFlags, bool includeHidden=true)
List the contents of url, which is assumed to be a directory.
Definition: job.cpp:2739
KIO::TransferJobPrivate::m_mimetype
QString m_mimetype
Definition: job_p.h:280
KIO::JobPrivate::EF_TransferJobAsync
Definition: job_p.h:48
KIO::DirectCopyJob::~DirectCopyJob
~DirectCopyJob()
Definition: job.cpp:1904
KIO::StatJob::DestinationSide
Definition: jobclasses.h:447
KIO::ERR_UNKNOWN_HOST
Definition: global.h:208
KIO::TransferJobPrivate::slotErrorPage
void slotErrorPage()
Definition: job.cpp:1312
KIO::CMD_SETMODIFICATIONTIME
Definition: global.h:170
KIO::CMD_COPY
Definition: global.h:166
KDialogJobUiDelegate::updateUserTimestamp
void updateUserTimestamp(unsigned long time)
KIO::DirectCopyJob::DirectCopyJob
DirectCopyJob(const KUrl &url, const QByteArray &packedArgs)
Definition: job.cpp:1898
KIO::ListJob::redirection
void redirection(KIO::Job *job, const KUrl &url)
Signals a redirection.
KCompositeJob::setErrorText
void setErrorText(const QString &errorText)
KIO::TransferJobPrivate::m_errorPage
bool m_errorPage
Definition: job_p.h:276
KIO::R_CANCEL
Definition: renamedialog.h:61
KIO::TransferJob::mimetype
QString mimetype() const
Call this in the slot connected to result, and only after making sure no error happened.
Definition: job.cpp:1158
KIO::Scheduler::jobFinished
static void jobFinished(KIO::SimpleJob *job, KIO::Slave *slave)
Called when a job is done.
Definition: scheduler.cpp:815
KUrl::addPath
void addPath(const QString &txt)
KIO::MkdirJob::slotFinished
virtual void slotFinished()
Definition: job.cpp:667
KCompositeJob::speed
void speed(KJob *job, unsigned long speed)
KCompositeJob::description
void description(KJob *job, const QString &title, const QPair< QString, QString > &field1=qMakePair(QString(), QString()), const QPair< QString, QString > &field2=qMakePair(QString(), QString()))
KIO::ListJob::permanentRedirection
void permanentRedirection(KIO::Job *job, const KUrl &fromUrl, const KUrl &toUrl)
Signals a permanent redirection.
KIO::FileCopyJob::srcUrl
KUrl srcUrl() const
Returns the source URL.
Definition: job.cpp:2098
KIO::SimpleJobPrivate::newJobNoUi
static SimpleJob * newJobNoUi(const KUrl &url, int command, const QByteArray &packedArgs)
Definition: job_p.h:199
KIO::chown
SimpleJob * chown(const KUrl &url, const QString &owner, const QString &group)
Changes ownership and group of a file or directory.
Definition: job.cpp:718
KIO::file_copy
FileCopyJob * file_copy(const KUrl &src, const KUrl &dest, int permissions=-1, JobFlags flags=DefaultFlags)
Copy a single file.
Definition: job.cpp:2489
KIO::ERR_INTERNAL
Definition: global.h:198
KIO::FileCopyJob::setModificationTime
void setModificationTime(const QDateTime &mtime)
Sets the modification time of the file.
Definition: job.cpp:2092
KIO::TransferJob::sendAsyncData
void sendAsyncData(const QByteArray &data)
Provide data to the job when async data is enabled.
Definition: job.cpp:1124
KIO::Resume
When set, automatically append to the destination file if it exists already.
Definition: jobclasses.h:60
KCompositeJobPrivate::error
int error
KIO::rename
SimpleJob * rename(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
Rename a file or directory.
Definition: job.cpp:731
KIO::JobPrivate::emitCreatingDir
static void emitCreatingDir(KIO::Job *, const KUrl &dir)
Definition: job.cpp:138
KIO::TransferJob::TransferJob
TransferJob(TransferJobPrivate &dd)
Definition: job.cpp:974
KCompositeJob::setProcessedAmount
void setProcessedAmount(Unit unit, qulonglong amount)
KIO::SimpleJob::setRedirectionHandlingEnabled
void setRedirectionHandlingEnabled(bool handle)
Set handle to false to prevent the internal handling of redirections.
Definition: job.cpp:369
KIO::JobUiDelegate
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:39
KIO::TransferJobPrivate::m_internalSuspended
bool m_internalSuspended
Definition: job_p.h:275
KAuthorized::authorizeUrlAction
bool authorizeUrlAction(const QString &action, const KUrl &baseUrl, const KUrl &destUrl)
KIO::MimetypeJob::slotFinished
virtual void slotFinished()
Definition: job.cpp:1834
KUrl::protocol
QString protocol() const
KCompositeJob::slotResult
virtual void slotResult(KJob *job)
KIO::JobPrivate::m_outgoingMetaData
MetaData m_outgoingMetaData
Definition: job_p.h:60
KIO::ERR_IS_DIRECTORY
Definition: global.h:203
KIO::MkdirJob::~MkdirJob
~MkdirJob()
Definition: job.cpp:637
KIO::TransferJob::slotDataReq
virtual void slotDataReq()
Definition: job.cpp:1164
KUrl::pathOrUrl
QString pathOrUrl() const
KIO::TransferJobPrivate::m_subJob
TransferJob * m_subJob
Definition: job_p.h:282
precheckHttpPost
static KIO::PostErrorJob * precheckHttpPost(const KUrl &url, QIODevice *ioDevice, JobFlags flags)
Definition: job.cpp:1559
KIO::UDSEntry::stringValue
QString stringValue(uint field) const
Definition: udsentry.cpp:73
KIO::SimpleJobPrivate::slotTotalSize
void slotTotalSize(KIO::filesize_t data_size)
Forward signal from the slave Can also be called by the parent job, when it knows the size...
Definition: job.cpp:526
CACHE_REVISION
#define CACHE_REVISION
Definition: http_slave_defaults.h:31
KIO::MultiGetJob::slotData
virtual void slotData(const QByteArray &data)
Definition: job.cpp:2985
KIO::TransferJob::doResume
virtual bool doResume()
Reimplemented for internal reasons.
Definition: job.cpp:1229
KIO::Scheduler::cancelJob
static void cancelJob(SimpleJob *job)
Stop the execution of a job.
Definition: scheduler.cpp:810
KIO::SimpleJobPrivate::simpleJobInit
void simpleJobInit()
Definition: job.cpp:298
KIO::Scheduler::isSlaveOnHoldFor
static bool isSlaveOnHoldFor(const KUrl &url)
Returns true if there is a slave on hold for url.
Definition: scheduler.cpp:835
KIO::getJobTracker
KJobTrackerInterface * getJobTracker()
Definition: global.cpp:1246
KIO::SimpleJobPrivate::start
virtual void start(KIO::Slave *slave)
Definition: job.cpp:385
KIO::Job::metaData
MetaData metaData() const
Get meta data received from the slave.
Definition: job.cpp:248
KIO::rmdir
SimpleJob * rmdir(const KUrl &url)
Removes a single directory.
Definition: job.cpp:704
KIO::Job::parentJob
Job * parentJob() const
Returns the parent job, if there is one.
Definition: job.cpp:243
KIO::Slave::send
virtual void send(int cmd, const QByteArray &arr=QByteArray())
Sends the given command to the kioslave.
Definition: slave.cpp:332
KIO::ClipboardUpdater::RemoveContent
Definition: clipboardupdater_p.h:57
KIO::CMD_PUT
Definition: global.h:160
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KProtocolManager::canCopyFromFile
static bool canCopyFromFile(const KUrl &url)
Returns whether the protocol can copy files/objects directly from the filesystem itself.
Definition: kprotocolmanager.cpp:1113
KIO::RenameDialog_Mode
RenameDialog_Mode
M_OVERWRITE: We have an existing dest, show details about it and offer to overwrite it...
Definition: renamedialog.h:56
KCompositeJob::uiDelegate
KJobUiDelegate * uiDelegate() const
KIO::Job::doSuspend
virtual bool doSuspend()
Suspend this job.
Definition: job.cpp:186
KIO::CMD_RENAME
Definition: global.h:165
KIO::SlaveInterface::sendResumeAnswer
void sendResumeAnswer(bool resume)
Definition: slaveinterface.cpp:374
KIO::TransferJob::setModificationTime
void setModificationTime(const QDateTime &mtime)
Sets the modification time of the file to be created (by KIO::put) Note that some kioslaves might ign...
Definition: job.cpp:1366
KIO::StatJob::slotMetaData
virtual void slotMetaData(const KIO::MetaData &_metaData)
Definition: job.cpp:917
KIO::storedGet
StoredTransferJob * storedGet(const KUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
Get (a.k.a.
Definition: job.cpp:1782
KIO::SimpleJobPrivate::slaveDone
void slaveDone()
Definition: job.cpp:453
KIO::JobPrivate::EF_KillCalled
Definition: job_p.h:52
KIO::SimpleJob::slotMetaData
virtual void slotMetaData(const KIO::MetaData &_metaData)
MetaData from the slave is received.
Definition: job.cpp:578
KIO::TransferJob::slotFinished
virtual void slotFinished()
Definition: job.cpp:1043
jobuidelegate.h
KIO::move
CopyJob * move(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
Moves a file or directory src to the given destination dest.
Definition: copyjob.cpp:2184
KIO::CMD_DEL
Definition: global.h:167
KIO::symlink
SimpleJob * symlink(const QString &target, const KUrl &dest, JobFlags flags=DefaultFlags)
Create or move a symlink.
Definition: job.cpp:738
KIO::Scheduler::putSlaveOnHold
static void putSlaveOnHold(KIO::SimpleJob *job, const KUrl &url)
Puts a slave on notice.
Definition: scheduler.cpp:820
kprotocolinfo.h
KIO::Reload
Definition: job.h:29
KIO::CMD_MKDIR
Definition: global.h:164
KIO::SpecialJob::setArguments
void setArguments(const QByteArray &data)
Sets the QByteArray that is passed to SlaveBase::special() on the ioslave.
Definition: job.cpp:3034
KIO::chmod
ChmodJob * chmod(const KFileItemList &lstItems, int permissions, int mask, const QString &newOwner, const QString &newGroup, bool recursive, JobFlags flags=DefaultFlags)
Creates a job that changes permissions/ownership on several files or directories, optionally recursiv...
Definition: chmodjob.cpp:268
KIO::JobPrivate::emitTransferring
static void emitTransferring(KIO::Job *, const KUrl &url)
Definition: job.cpp:156
KIO::SimpleJob::doResume
virtual bool doResume()
Resume this job.
Definition: job.cpp:333
KIO::UDSEntry::contains
bool contains(uint field) const
check existence of a field
Definition: udsentry.cpp:118
KProtocolManager::canCopyToFile
static bool canCopyToFile(const KUrl &url)
Returns whether the protocol can copy files/objects directly to the filesystem itself.
Definition: kprotocolmanager.cpp:1123
KIO::TransferJob::slotResult
virtual void slotResult(KJob *job)
Called when m_subJob finishes.
Definition: job.cpp:1351
KIO::TransferJob::~TransferJob
~TransferJob()
Definition: job.cpp:983
KIO::JobPrivate::emitDeleting
static void emitDeleting(KIO::Job *, const KUrl &url)
Definition: job.cpp:144
KIO::JobPrivate::m_extraFlags
int m_extraFlags
Definition: job_p.h:57
KIO::DirectCopyJob::canResume
void canResume(KIO::Job *job, KIO::filesize_t offset)
KCompositeJob::clearSubjobs
void clearSubjobs()
KIO::TransferJobPrivate::slotDataReqFromDevice
virtual void slotDataReqFromDevice()
Definition: job.cpp:1323
KIO::SimpleJob::slotWarning
virtual void slotWarning(const QString &)
Definition: job.cpp:511
KIO::http_update_cache
SimpleJob * http_update_cache(const KUrl &url, bool no_cache, time_t expireDate)
HTTP cache update.
Definition: job.cpp:962
ok
KGuiItem ok()
KIO::Slave::suspend
virtual void suspend()
Suspends the operation of the attached kioslave.
Definition: slave.cpp:314
KIO::setModificationTime
SimpleJob * setModificationTime(const KUrl &url, const QDateTime &mtime)
Changes the modification time on a file or directory.
Definition: job.cpp:724
KIO::ClipboardUpdater::create
static ClipboardUpdater * create(Job *job, Mode mode)
Returns an instance of clipboard updater if QApplication::type() does not return a tty...
Definition: clipboardupdater.cpp:162
KIO::SpecialJob::arguments
QByteArray arguments() const
Returns the QByteArray data that will be sent (or has been sent) to the ioslave.
Definition: job.cpp:3040
KIO::ERR_ACCESS_DENIED
Definition: global.h:209
KIO::storedPut
StoredTransferJob * storedPut(const QByteArray &arr, const KUrl &url, int permissions, JobFlags flags=DefaultFlags)
Put (a.k.a.
Definition: job.cpp:1792
KIO::MimetypeJob::~MimetypeJob
~MimetypeJob()
Definition: job.cpp:1830
QDateTime
job.h
KIO::SimpleJob::slotFinished
virtual void slotFinished()
Called when the slave marks the job as finished.
Definition: job.cpp:468
KIO::CMD_CLOSE
Definition: global.h:185
KIO::MultiGetJob::MultiGetJob
MultiGetJob(MultiGetJobPrivate &dd)
Definition: job.cpp:2831
KIO::ERR_IS_FILE
Definition: global.h:204
job_p.h
KIO::StatJob::mostLocalUrl
KUrl mostLocalUrl() const
most local URL Call this in the slot connected to result, and only after making sure no error happene...
Definition: job.cpp:844
KIO::ClipboardUpdater::update
static void update(const KUrl &srcUrl, const KUrl &destUrl)
Convenience function that allows renaming of a single url in the clipboard.
Definition: clipboardupdater.cpp:171
KIO::Job::doKill
virtual bool doKill()
Abort this job.
Definition: job.cpp:175
KIO::JobPrivate::EF_TransferJobDataSent
Definition: job_p.h:50
KIO::SimpleJobPrivate::m_slave
Slave * m_slave
Definition: job_p.h:102
KIO::SimpleJob::doSuspend
virtual bool doSuspend()
Suspend this job.
Definition: job.cpp:325
KCompositeJob::warning
void warning(KJob *job, const QString &plain, const QString &rich=QString())
KIO::TransferJob::data
void data(KIO::Job *job, const QByteArray &data)
Data from the slave has arrived.
KConfig
KIO::SimpleJob::isRedirectionHandlingEnabled
bool isRedirectionHandlingEnabled() const
Returns true when redirections are handled internally, the default.
Definition: job.cpp:364
ktemporaryfile.h
KIO::SimpleJobPrivate::m_packedArgs
QByteArray m_packedArgs
Definition: job_p.h:103
KIO::Job::setParentJob
void setParentJob(Job *parentJob)
Set the parent Job.
Definition: job.cpp:235
KIO::SimpleJobPrivate::get
static SimpleJobPrivate * get(KIO::SimpleJob *job)
Definition: job_p.h:197
KIO::SimpleJobPrivate::requestMessageBox
int requestMessageBox(int type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo, const QString &iconYes=QString(), const QString &iconNo=QString(), const QString &dontAskAgainName=QString(), const KIO::MetaData &sslMetaData=KIO::MetaData())
Request the ui delegate to show a message box.
Definition: job.cpp:562
KIO::DirectCopyJob::slotCanResume
void slotCanResume(KIO::filesize_t offset)
Definition: job.cpp:1916
KProtocolManager::cacheDir
static QString cacheDir()
The directory which contains the cache files.
Definition: kprotocolmanager.cpp:339
KIO::CMD_CHMOD
Definition: global.h:168
KIO::http_post
TransferJob * http_post(const KUrl &url, const QByteArray &postData, JobFlags flags=DefaultFlags)
HTTP POST (for form data).
Definition: job.cpp:1599
KIO::TransferJob::setReportDataSent
void setReportDataSent(bool enabled)
When enabled, the job reports the amount of data that has been sent, instead of the amount of data th...
Definition: job.cpp:1141
KIO::ListJob::~ListJob
~ListJob()
Definition: job.cpp:2572
KRecentDirs::dir
QString dir(const QString &fileClass)
Returns the most recently used directory accociated with this file-class.
Definition: krecentdirs.cpp:68
KIO::M_OVERWRITE
Definition: renamedialog.h:56
KIO::Job::errorString
QString errorString() const
Converts an error code and a non-i18n error message into an error message in the current language...
Definition: global.cpp:159
KIO::http_delete
TransferJob * http_delete(const KUrl &url, JobFlags flags=DefaultFlags)
HTTP DELETE.
Definition: job.cpp:1653
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
KIO::SimpleJobPrivate::_k_slotSlaveInfoMessage
void _k_slotSlaveInfoMessage(const QString &s)
Called on a slave's info message.
Definition: job.cpp:516
KIO::ListJob::ListJob
ListJob(ListJobPrivate &dd)
Definition: job.cpp:2562
KIO::MkdirJob::MkdirJob
MkdirJob(MkdirJobPrivate &dd)
Definition: job.cpp:632
KIO::FileCopyJob
The FileCopyJob copies data from one place to another.
Definition: jobclasses.h:856
KIO::StatJob::StatJob
StatJob(StatJobPrivate &dd)
Definition: job.cpp:813
KIO::TransferJob::dataReq
void dataReq(KIO::Job *job, QByteArray &data)
Request for data.
KIO::CC_Verify
Validate cached entry with remote site if expired.
Definition: global.h:334
KProtocolManager::autoResume
static bool autoResume()
Returns true if partial downloads should be automatically resumed.
Definition: kprotocolmanager.cpp:968
KIO::JobUiDelegate::MessageBoxType
MessageBoxType
Message box types.
Definition: jobuidelegate.h:141
KIO::listRecursive
ListJob * listRecursive(const KUrl &url, JobFlags flags=DefaultFlags, bool includeHidden=true)
The same as the previous method, but recurses subdirectories.
Definition: job.cpp:2744
KIO::SimpleJob::storeSSLSessionFromJob
void storeSSLSessionFromJob(const KUrl &m_redirectionURL)
Definition: job.cpp:598
KIO::UDSEntry::UDS_NAME
Filename - as displayed in directory listings etc.
Definition: udsentry.h:163
KCompositeJob::setTotalAmount
void setTotalAmount(Unit unit, qulonglong amount)
KIO::TransferJobPrivate
Definition: job_p.h:257
KIO::ERR_UNSUPPORTED_ACTION
Definition: global.h:202
KIO_ARGS
#define KIO_ARGS
Definition: job_p.h:32
KIO::RenameDialog_Result
RenameDialog_Result
The result of open_RenameDialog().
Definition: renamedialog.h:61
KIO::Job
The base class for all jobs.
Definition: jobclasses.h:94
KIO::MimetypeJob
A MimetypeJob is a TransferJob that allows you to get the mime type of an URL.
Definition: jobclasses.h:837
KIO::NoReload
Definition: job.h:29
KIO::JobPrivate::emitMoving
static void emitMoving(KIO::Job *, const KUrl &src, const KUrl &dest)
Definition: job.cpp:124
KCompositeJob::subjobs
const QList< KJob * > & subjobs() const
KIO::TransferJob::slotMimetype
virtual void slotMimetype(const QString &mimetype)
Definition: job.cpp:1202
KIO::StatJob::permanentRedirection
void permanentRedirection(KIO::Job *job, const KUrl &fromUrl, const KUrl &toUrl)
Signals a permanent redirection.
KIO::MultiGetJob::slotRedirection
virtual void slotRedirection(const KUrl &url)
Definition: job.cpp:2936
KIO::SimpleJobPrivate::m_subUrl
KUrl m_subUrl
Definition: job_p.h:105
KIO::ERR_CYCLIC_LINK
Definition: global.h:213
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KIO::SimpleJobPrivate::m_schedSerial
int m_schedSerial
Definition: job_p.h:126
KIO::UDSEntry::UDS_DISPLAY_NAME
If set, contains the label to display instead of the 'real name' in UDS_NAME.
Definition: udsentry.h:211
qint32
KCompositeJob::hasSubjobs
bool hasSubjobs()
KIO::SimpleJob::putOnHold
virtual void putOnHold()
Abort job.
Definition: job.cpp:346
KIO::StatJob::StatSide
StatSide
Definition: jobclasses.h:445
KIO::ERR_POST_DENIED
Definition: global.h:267
KIO::MultiGetJob::slotFinished
virtual void slotFinished()
Definition: job.cpp:2950
KIO::TransferJob::setAsyncDataEnabled
void setAsyncDataEnabled(bool enabled)
Enable the async data mode.
Definition: job.cpp:1115
KDE::fopen
FILE * fopen(const QString &pathname, const char *mode)
KIO::SlaveInterface::setOffset
void setOffset(KIO::filesize_t offset)
Definition: slaveinterface.cpp:347
KIO::JobPrivate::EF_TransferJobNeedData
Definition: job_p.h:49
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
KIO::JobPrivate::ui
KIO::JobUiDelegate * ui() const
Definition: job_p.h:62
KIO::SpecialJob::SpecialJob
SpecialJob(const KUrl &url, const QByteArray &data=QByteArray())
Creates a KIO::SpecialJob.
Definition: job.cpp:3025
KIO::StatJob::SourceSide
Definition: jobclasses.h:446
KIO::SimpleJobPrivate::m_command
int m_command
Definition: job_p.h:106
KIO::MultiGetJob::result
void result(long id)
File transfer completed.
KJobTrackerInterface::registerJob
virtual void registerJob(KJob *job)
KIO::ListJob::redirectionUrl
const KUrl & redirectionUrl() const
Returns the ListJob's redirection URL.
Definition: job.cpp:2779
KIO::TransferJob
The transfer job pumps data into and/or out of a Slave.
Definition: jobclasses.h:555
KIO::MultiGetJob
The MultiGetJob is a TransferJob that allows you to get several files from a single server...
Definition: jobclasses.h:778
clipboardupdater_p.h
KIO::SimpleJob::~SimpleJob
~SimpleJob()
Definition: job.cpp:375
KIO::CMD_MULTI_GET
Definition: global.h:178
KIO::StatJob::statResult
const UDSEntry & statResult() const
Result of the stat operation.
Definition: job.cpp:839
KUrl::isLocalFile
bool isLocalFile() const
KIO::Slave::setJob
void setJob(KIO::SimpleJob *job)
Definition: slave.cpp:273
QIODevice
KIO::M_RESUME
Definition: renamedialog.h:56
KIO::SimpleJobPrivate::m_url
KUrl m_url
Definition: job_p.h:104
KCompositeJob::processedAmount
qulonglong processedAmount(Unit unit) const
KIO::JobPrivate
Definition: job_p.h:37
KCompositeJobPrivate::suspended
bool suspended
KIO::TransferJob::slotMetaData
virtual void slotMetaData(const KIO::MetaData &_metaData)
Definition: job.cpp:1305
KCompositeJob
KIO::SimpleJobPrivate::restartAfterRedirection
void restartAfterRedirection(KUrl *redirectionUrl)
Called by subclasses to restart the job after a redirection was signalled.
Definition: job.cpp:548
KIO::MimetypeJob::MimetypeJob
MimetypeJob(MimetypeJobPrivate &dd)
Definition: job.cpp:1825
end
const KShortcut & end()
KIO::TransferJob::reportDataSent
bool reportDataSent() const
Returns whether the job reports the amount of data that has been sent (true), or whether the job repo...
Definition: job.cpp:1152
KIO::MkdirJob
A KIO job that creates a directory.
Definition: job_p.h:220
KProtocolManager::canRenameFromFile
static bool canRenameFromFile(const KUrl &url)
Returns whether the protocol can rename (i.e.
Definition: kprotocolmanager.cpp:1132
KIO::Job::outgoingMetaData
MetaData outgoingMetaData() const
Definition: job.cpp:287
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KJob
operator==
int operator==(KSSLCertificate &x, KSSLCertificate &y)
Definition: ksslcertificate.cpp:1015
KIO::CMD_SYMLINK
Definition: global.h:173
KIO::storedHttpPost
StoredTransferJob * storedHttpPost(const QByteArray &arr, const KUrl &url, JobFlags flags=DefaultFlags)
HTTP POST (a.k.a.
Definition: job.cpp:1662
KIO::TransferJobPrivate::slotCanResume
void slotCanResume(KIO::filesize_t offset)
Definition: job.cpp:1317
KIO::Job::isInteractive
bool isInteractive() const
Returns whether the user should be asked about things when the job is unsure, like whether to overwri...
Definition: job.cpp:230
QMap< QString, QString >
QList< int >
KIO::number
QString number(KIO::filesize_t size)
Converts a size to a string representation Not unlike QString::number(...)
Definition: global.cpp:63
KIO::ListJob::slotResult
virtual void slotResult(KJob *job)
Definition: job.cpp:2668
KCompositeJob::error
int error() const
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
KCompositeJob::removeSubjob
virtual bool removeSubjob(KJob *job)
KIO::JobPrivate::emitCopying
static void emitCopying(KIO::Job *, const KUrl &src, const KUrl &dest)
Definition: job.cpp:131
OrgKdeKDirNotifyInterface::emitFileMoved
static void emitFileMoved(const QString &src, const QString &dst)
Definition: kdirnotify.cpp:42
KIO::CMD_GET
Definition: global.h:159
KIO::SimpleJob
A simple job (one url and one command).
Definition: jobclasses.h:322
KIO::StatJob::~StatJob
~StatJob()
Definition: job.cpp:818
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal