kio Library API Documentation

job.cpp

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
00003                        David Faure <faure@kde.org>
00004                        Waldo Bastian <bastian@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <config.h>
00023 
00024 #include <sys/types.h>
00025 #include <sys/wait.h>
00026 #include <sys/stat.h>
00027 
00028 #include <assert.h>
00029 
00030 #include <signal.h>
00031 #include <stdlib.h>
00032 #include <stdio.h>
00033 #include <time.h>
00034 #include <unistd.h>
00035 extern "C" {
00036 #include <pwd.h>
00037 #include <grp.h>
00038 }
00039 #include <qtimer.h>
00040 #include <qfile.h>
00041 
00042 #include <kapplication.h>
00043 #include <kglobal.h>
00044 #include <klocale.h>
00045 #include <ksimpleconfig.h>
00046 #include <kdebug.h>
00047 #include <kdialog.h>
00048 #include <kmessagebox.h>
00049 #include <kdatastream.h>
00050 #include <kmainwindow.h>
00051 
00052 #include <errno.h>
00053 
00054 #include "slave.h"
00055 #include "kio/job.h"
00056 #include "scheduler.h"
00057 #include "kdirwatch.h"
00058 #include "kmimemagic.h"
00059 #include "kprotocolinfo.h"
00060 #include "kprotocolmanager.h"
00061 
00062 #include "kio/observer.h"
00063 
00064 #include <kdirnotify_stub.h>
00065 #include <ktempfile.h>
00066 #include <dcopclient.h>
00067 
00068 using namespace KIO;
00069 template class QPtrList<KIO::Job>;
00070 
00071 //this will update the report dialog with 5 Hz, I think this is fast enough, aleXXX
00072 #define REPORT_TIMEOUT 200
00073 
00074 #define KIO_ARGS QByteArray packedArgs; QDataStream stream( packedArgs, IO_WriteOnly ); stream
00075 
00076 class Job::JobPrivate
00077 {
00078 public:
00079     JobPrivate() : m_autoErrorHandling( false ), m_parentJob( 0L ) {}
00080 
00081     bool m_autoErrorHandling;
00082     QGuardedPtr<QWidget> m_errorParentWidget;
00083     // Maybe we could use the QObject parent/child mechanism instead
00084     // (requires a new ctor, and moving the ctor code to some init()).
00085     Job* m_parentJob;
00086 };
00087 
00088 Job::Job(bool showProgressInfo) : QObject(0, "job"), m_error(0), m_percent(0)
00089    , m_progressId(0), m_speedTimer(0), d( new JobPrivate )
00090 {
00091     // All jobs delete themselves after emiting 'result'.
00092 
00093     // Notify the UI Server and get a progress id
00094     if ( showProgressInfo )
00095     {
00096         m_progressId = Observer::self()->newJob( this, true );
00097         //kdDebug(7007) << "Created job " << this << " with progress info -- m_progressId=" << m_progressId << endl;
00098         // Connect global progress info signals
00099         connect( this, SIGNAL( percent( KIO::Job*, unsigned long ) ),
00100                  Observer::self(), SLOT( slotPercent( KIO::Job*, unsigned long ) ) );
00101         connect( this, SIGNAL( infoMessage( KIO::Job*, const QString & ) ),
00102                  Observer::self(), SLOT( slotInfoMessage( KIO::Job*, const QString & ) ) );
00103         connect( this, SIGNAL( totalSize( KIO::Job*, KIO::filesize_t ) ),
00104                  Observer::self(), SLOT( slotTotalSize( KIO::Job*, KIO::filesize_t ) ) );
00105         connect( this, SIGNAL( processedSize( KIO::Job*, KIO::filesize_t ) ),
00106                  Observer::self(), SLOT( slotProcessedSize( KIO::Job*, KIO::filesize_t ) ) );
00107         connect( this, SIGNAL( speed( KIO::Job*, unsigned long ) ),
00108                  Observer::self(), SLOT( slotSpeed( KIO::Job*, unsigned long ) ) );
00109     }
00110     // Don't exit while this job is running
00111     kapp->ref();
00112 }
00113 
00114 Job::~Job()
00115 {
00116     delete m_speedTimer;
00117     delete d;
00118     kapp->deref();
00119 }
00120 
00121 void Job::addSubjob(Job *job, bool inheritMetaData)
00122 {
00123     //kdDebug(7007) << "addSubjob(" << job << ") this = " << this << endl;
00124     subjobs.append(job);
00125 
00126     connect( job, SIGNAL(result(KIO::Job*)),
00127              SLOT(slotResult(KIO::Job*)) );
00128 
00129     // Forward information from that subjob.
00130     connect( job, SIGNAL(speed( KIO::Job*, unsigned long )),
00131              SLOT(slotSpeed(KIO::Job*, unsigned long)) );
00132 
00133     connect( job, SIGNAL(infoMessage( KIO::Job*, const QString & )),
00134              SLOT(slotInfoMessage(KIO::Job*, const QString &)) );
00135 
00136     if (inheritMetaData)
00137        job->mergeMetaData(m_outgoingMetaData);
00138 }
00139 
00140 void Job::removeSubjob( Job *job )
00141 {
00142     //kdDebug(7007) << "removeSubjob(" << job << ") this = " << this << "  subjobs = " << subjobs.count() << endl;
00143     subjobs.remove(job);
00144     if (subjobs.isEmpty())
00145         emitResult();
00146 }
00147 
00148 void Job::emitPercent( KIO::filesize_t processedSize, KIO::filesize_t totalSize )
00149 {
00150   // calculate percents
00151   unsigned long ipercent = m_percent;
00152 
00153   if ( totalSize == 0 )
00154     m_percent = 100;
00155   else
00156     m_percent = (unsigned long)(( (float)(processedSize) / (float)(totalSize) ) * 100.0);
00157 
00158   if ( m_percent != ipercent || m_percent == 100 /* for those buggy total sizes that grow */ ) {
00159     emit percent( this, m_percent );
00160     //kdDebug(7007) << "Job::emitPercent - percent =  " << (unsigned int) m_percent << endl;
00161   }
00162 }
00163 
00164 void Job::emitSpeed( unsigned long bytes_per_second )
00165 {
00166   //kdDebug(7007) << "Job " << this << " emitSpeed " << bytes_per_second << endl;
00167   if ( !m_speedTimer )
00168   {
00169     m_speedTimer = new QTimer();
00170     connect( m_speedTimer, SIGNAL( timeout() ), SLOT( slotSpeedTimeout() ) );
00171   }
00172   emit speed( this, bytes_per_second );
00173   m_speedTimer->start( 5000 );   // 5 seconds interval should be enough
00174 }
00175 
00176 void Job::emitResult()
00177 {
00178   // If we are displaying a progress dialog, remove it first.
00179   if ( m_progressId ) // Did we get an ID from the observer ?
00180     Observer::self()->jobFinished( m_progressId );
00181   if ( m_error && d->m_autoErrorHandling )
00182     showErrorDialog( d->m_errorParentWidget );
00183   emit result(this);
00184   delete this;
00185 }
00186 
00187 void Job::kill( bool quietly )
00188 {
00189   kdDebug(7007) << "Job::kill this=" << this << " m_progressId=" << m_progressId << " quietly=" << quietly << endl;
00190   // kill all subjobs, without triggering their result slot
00191   QPtrListIterator<Job> it( subjobs );
00192   for ( ; it.current() ; ++it )
00193      (*it)->kill( true );
00194   subjobs.clear();
00195 
00196   if ( ! quietly ) {
00197     m_error = ERR_USER_CANCELED;
00198     emit canceled( this ); // Not very useful (deprecated)
00199     emitResult();
00200   } else
00201   {
00202     if ( m_progressId ) // in both cases we want to hide the progress window
00203       Observer::self()->jobFinished( m_progressId );
00204     delete this;
00205   }
00206 }
00207 
00208 void Job::slotResult( Job *job )
00209 {
00210     // Did job have an error ?
00211     if ( job->error() && !m_error )
00212     {
00213         // Store it in the parent only if first error
00214         m_error = job->error();
00215         m_errorText = job->errorText();
00216     }
00217     removeSubjob(job);
00218 }
00219 
00220 void Job::slotSpeed( KIO::Job*, unsigned long bytes_per_second )
00221 {
00222   //kdDebug(7007) << "Job::slotSpeed " << bytes_per_second << endl;
00223   emitSpeed( bytes_per_second );
00224 }
00225 
00226 void Job::slotInfoMessage( KIO::Job*, const QString & msg )
00227 {
00228   emit infoMessage( this, msg );
00229 }
00230 
00231 void Job::slotSpeedTimeout()
00232 {
00233   //kdDebug(7007) << "slotSpeedTimeout()" << endl;
00234   // send 0 and stop the timer
00235   // timer will be restarted only when we receive another speed event
00236   emit speed( this, 0 );
00237   m_speedTimer->stop();
00238 }
00239 
00240 //Job::errorString is implemented in global.cpp
00241 
00242 void Job::showErrorDialog( QWidget * parent )
00243 {
00244   //kdDebug(7007) << "Job::showErrorDialog parent=" << parent << endl;
00245   kapp->enableStyles();
00246   // Show a message box, except for "user canceled" or "no content"
00247   if ( (m_error != ERR_USER_CANCELED) && (m_error != ERR_NO_CONTENT) ) {
00248     //old plain error message
00249     kdDebug() << "Default language: " << KGlobal::locale()->defaultLanguage() << endl;
00250     if ( 1 )
00251       KMessageBox::queuedMessageBox( parent, KMessageBox::Error, errorString() );
00252 #if 0
00253     } else {
00254       QStringList errors = detailedErrorStrings();
00255       QString caption, err, detail;
00256       QStringList::iterator it = errors.begin();
00257       if ( it != errors.end() )
00258         caption = *(it++);
00259       if ( it != errors.end() )
00260         err = *(it++);
00261       if ( it != errors.end() )
00262         detail = *it;
00263       KMessageBox::queuedDetailedError( parent, err, detail, caption );
00264     }
00265 #endif
00266   }
00267 }
00268 
00269 void Job::setAutoErrorHandlingEnabled( bool enable, QWidget *parentWidget )
00270 {
00271   d->m_autoErrorHandling = enable;
00272   d->m_errorParentWidget = parentWidget;
00273 }
00274 
00275 bool Job::isAutoErrorHandlingEnabled() const
00276 {
00277   return d->m_autoErrorHandling;
00278 }
00279 
00280 void Job::setWindow(QWidget *window)
00281 {
00282   m_window = window;
00283   KIO::Scheduler::registerWindow(window);
00284 }
00285 
00286 QWidget *Job::window() const
00287 {
00288   return m_window;
00289 }
00290 
00291 void Job::setParentJob(Job* job)
00292 {
00293   Q_ASSERT(d->m_parentJob == 0L);
00294   Q_ASSERT(job);
00295   d->m_parentJob = job;
00296 }
00297 
00298 Job* Job::parentJob() const
00299 {
00300   return d->m_parentJob;
00301 }
00302 
00303 MetaData Job::metaData() const
00304 {
00305     return m_incomingMetaData;
00306 }
00307 
00308 QString Job::queryMetaData(const QString &key)
00309 {
00310     if (!m_incomingMetaData.contains(key))
00311        return QString::null;
00312     return m_incomingMetaData[key];
00313 }
00314 
00315 void Job::setMetaData( const KIO::MetaData &_metaData)
00316 {
00317     m_outgoingMetaData = _metaData;
00318 }
00319 
00320 void Job::addMetaData( const QString &key, const QString &value)
00321 {
00322     m_outgoingMetaData.insert(key, value);
00323 }
00324 
00325 void Job::addMetaData( const QMap<QString,QString> &values)
00326 {
00327     QMapConstIterator<QString,QString> it = values.begin();
00328     for(;it != values.end(); ++it)
00329       m_outgoingMetaData.insert(it.key(), it.data());
00330 }
00331 
00332 void Job::mergeMetaData( const QMap<QString,QString> &values)
00333 {
00334     QMapConstIterator<QString,QString> it = values.begin();
00335     for(;it != values.end(); ++it)
00336       m_outgoingMetaData.insert(it.key(), it.data(), false);
00337 }
00338 
00339 MetaData Job::outgoingMetaData() const
00340 {
00341     return m_outgoingMetaData;
00342 }
00343 
00344 
00345 SimpleJob::SimpleJob(const KURL& url, int command, const QByteArray &packedArgs,
00346                      bool showProgressInfo )
00347   : Job(showProgressInfo), m_slave(0), m_packedArgs(packedArgs),
00348     m_url(url), m_command(command), m_totalSize(0)
00349 {
00350     if (m_url.isMalformed())
00351     {
00352         m_error = ERR_MALFORMED_URL;
00353         m_errorText = m_url.url();
00354         QTimer::singleShot(0, this, SLOT(slotFinished()) );
00355         return;
00356     }
00357 
00358     if ((m_command == CMD_LISTDIR) && !kapp->authorizeURLAction("list", m_url, m_url))
00359     {
00360         m_error = ERR_ACCESS_DENIED;
00361         m_errorText = m_url.url();
00362         QTimer::singleShot(0, this, SLOT(slotFinished()) );
00363         return;
00364     }
00365 
00366     if (m_url.hasSubURL())
00367     {
00368        KURL::List list = KURL::split(m_url);
00369        KURL::List::Iterator it = list.fromLast();
00370        m_url = *it;
00371        list.remove(it);
00372        m_subUrl = KURL::join(list);
00373        //kdDebug(7007) << "New URL = "  << m_url.url() << endl;
00374        //kdDebug(7007) << "Sub URL = "  << m_subUrl.url() << endl;
00375     }
00376 
00377     Scheduler::doJob(this);
00378 }
00379 
00380 void SimpleJob::kill( bool quietly )
00381 {
00382     Scheduler::cancelJob( this ); // deletes the slave if not 0
00383     m_slave = 0; // -> set to 0
00384     Job::kill( quietly );
00385 }
00386 
00387 void SimpleJob::putOnHold()
00388 {
00389     Scheduler::putSlaveOnHold(this, m_url);
00390     m_slave = 0;
00391     kill(true);
00392 }
00393 
00394 void SimpleJob::removeOnHold()
00395 {
00396     Scheduler::removeSlaveOnHold();
00397 }
00398 
00399 SimpleJob::~SimpleJob()
00400 {
00401     if (m_slave) // was running
00402     {
00403         kdDebug(7007) << "SimpleJob::~SimpleJob: Killing running job in destructor!"  << endl;
00404 #if 0
00405         m_slave->kill();
00406         Scheduler::jobFinished( this, m_slave ); // deletes the slave
00407 #endif
00408         Scheduler::cancelJob( this );
00409         m_slave = 0; // -> set to 0
00410     }
00411 }
00412 
00413 void SimpleJob::start(Slave *slave)
00414 {
00415     m_slave = slave;
00416 
00417     connect( m_slave, SIGNAL( error( int , const QString & ) ),
00418              SLOT( slotError( int , const QString & ) ) );
00419 
00420     connect( m_slave, SIGNAL( warning( const QString & ) ),
00421              SLOT( slotWarning( const QString & ) ) );
00422 
00423     connect( m_slave, SIGNAL( infoMessage( const QString & ) ),
00424              SLOT( slotInfoMessage( const QString & ) ) );
00425 
00426     connect( m_slave, SIGNAL( connected() ),
00427              SLOT( slotConnected() ) );
00428 
00429     connect( m_slave, SIGNAL( finished() ),
00430              SLOT( slotFinished() ) );
00431 
00432     connect( m_slave, SIGNAL( totalSize( KIO::filesize_t ) ),
00433              SLOT( slotTotalSize( KIO::filesize_t ) ) );
00434 
00435     connect( m_slave, SIGNAL( processedSize( KIO::filesize_t ) ),
00436              SLOT( slotProcessedSize( KIO::filesize_t ) ) );
00437 
00438     connect( m_slave, SIGNAL( speed( unsigned long ) ),
00439              SLOT( slotSpeed( unsigned long ) ) );
00440 
00441     connect( slave, SIGNAL( needProgressId() ),
00442              SLOT( slotNeedProgressId() ) );
00443 
00444     connect( slave, SIGNAL(metaData( const KIO::MetaData& ) ),
00445              SLOT( slotMetaData( const KIO::MetaData& ) ) );
00446 
00447     if (m_window)
00448     {
00449        QString id;
00450        addMetaData("window-id", id.setNum(m_window->winId()));
00451     }
00452 
00453     if (!m_outgoingMetaData.isEmpty())
00454     {
00455        KIO_ARGS << m_outgoingMetaData;
00456        slave->connection()->send( CMD_META_DATA, packedArgs );
00457     }
00458 
00459     if (!m_subUrl.isEmpty())
00460     {
00461        KIO_ARGS << m_subUrl;
00462        m_slave->connection()->send( CMD_SUBURL, packedArgs );
00463     }
00464 
00465     m_slave->connection()->send( m_command, m_packedArgs );
00466 }
00467 
00468 void SimpleJob::slaveDone()
00469 {
00470    if (!m_slave) return;
00471    disconnect(m_slave); // Remove all signals between slave and job
00472    Scheduler::jobFinished( this, m_slave );
00473    m_slave = 0;
00474 }
00475 
00476 void SimpleJob::slotFinished( )
00477 {
00478     // Return slave to the scheduler
00479     slaveDone();
00480 
00481     if (subjobs.isEmpty())
00482     {
00483         if ( !m_error )
00484         {
00485             KDirNotify_stub allDirNotify( "*", "KDirNotify*" );
00486             if ( m_command == CMD_MKDIR )
00487             {
00488                 KURL urlDir( url() );
00489                 urlDir.setPath( urlDir.directory() );
00490                 allDirNotify.FilesAdded( urlDir );
00491             }
00492             else if ( m_command == CMD_RENAME )
00493             {
00494                 KURL src, dst;
00495                 QDataStream str( m_packedArgs, IO_ReadOnly );
00496                 str >> src >> dst;
00497                 if ( src.directory() == dst.directory() ) // For the user, moving isn't renaming. Only renaming is.
00498                     allDirNotify.FileRenamed( src, dst );
00499             }
00500         }
00501         emitResult();
00502     }
00503 }
00504 
00505 void SimpleJob::slotError( int error, const QString & errorText )
00506 {
00507     m_error = error;
00508     m_errorText = errorText;
00509     // error terminates the job
00510     slotFinished();
00511 }
00512 
00513 void SimpleJob::slotWarning( const QString & errorText )
00514 {
00515     static uint msgBoxDisplayed = 0;
00516     if ( msgBoxDisplayed == 0 ) // don't bomb the user with message boxes, only one at a time
00517     {
00518         msgBoxDisplayed++;
00519         KMessageBox::information( 0L, errorText );
00520         msgBoxDisplayed--;
00521     }
00522     // otherwise just discard it.
00523 }
00524 
00525 void SimpleJob::slotInfoMessage( const QString & msg )
00526 {
00527     emit infoMessage( this, msg );
00528 }
00529 
00530 void SimpleJob::slotConnected()
00531 {
00532     emit connected( this );
00533 }
00534 
00535 void SimpleJob::slotNeedProgressId()
00536 {
00537     if ( !m_progressId )
00538         m_progressId = Observer::self()->newJob( this, false );
00539     m_slave->setProgressId( m_progressId );
00540 }
00541 
00542 void SimpleJob::slotTotalSize( KIO::filesize_t size )
00543 {
00544     m_totalSize = size;
00545     emit totalSize( this, size );
00546 }
00547 
00548 void SimpleJob::slotProcessedSize( KIO::filesize_t size )
00549 {
00550     //kdDebug(7007) << "SimpleJob::slotProcessedSize " << KIO::number(size) << endl;
00551     emit processedSize( this, size );
00552     if ( size > m_totalSize ) {
00553         slotTotalSize(size); // safety
00554     }
00555     emitPercent( size, m_totalSize );
00556 }
00557 
00558 void SimpleJob::slotSpeed( unsigned long bytes_per_second )
00559 {
00560     //kdDebug(7007) << "SimpleJob::slotSpeed( " << bytes_per_second << " )" << endl;
00561     emitSpeed( bytes_per_second );
00562 }
00563 
00564 void SimpleJob::slotMetaData( const KIO::MetaData &_metaData)
00565 {
00566     m_incomingMetaData += _metaData;
00567 }
00568 
00569 SimpleJob *KIO::mkdir( const KURL& url, int permissions )
00570 {
00571     //kdDebug(7007) << "mkdir " << url.prettyURL() << endl;
00572     KIO_ARGS << url << permissions;
00573     return new SimpleJob(url, CMD_MKDIR, packedArgs, false);
00574 }
00575 
00576 SimpleJob *KIO::rmdir( const KURL& url )
00577 {
00578     //kdDebug(7007) << "rmdir " << url.prettyURL() << endl;
00579     KIO_ARGS << url << Q_INT8(false); // isFile is false
00580     return new SimpleJob(url, CMD_DEL, packedArgs, false);
00581 }
00582 
00583 SimpleJob *KIO::chmod( const KURL& url, int permissions )
00584 {
00585     //kdDebug(7007) << "chmod " << url.prettyURL() << endl;
00586     KIO_ARGS << url << permissions;
00587     return new SimpleJob(url, CMD_CHMOD, packedArgs, false);
00588 }
00589 
00590 SimpleJob *KIO::rename( const KURL& src, const KURL & dest, bool overwrite )
00591 {
00592     //kdDebug(7007) << "rename " << src.prettyURL() << " " << dest.prettyURL() << endl;
00593     KIO_ARGS << src << dest << (Q_INT8) overwrite;
00594     return new SimpleJob(src, CMD_RENAME, packedArgs, false);
00595 }
00596 
00597 SimpleJob *KIO::symlink( const QString& target, const KURL & dest, bool overwrite, bool showProgressInfo )
00598 {
00599     //kdDebug(7007) << "symlink target=" << target << " " << dest.prettyURL() << endl;
00600     KIO_ARGS << target << dest << (Q_INT8) overwrite;
00601     return new SimpleJob(dest, CMD_SYMLINK, packedArgs, showProgressInfo);
00602 }
00603 
00604 SimpleJob *KIO::special(const KURL& url, const QByteArray & data, bool showProgressInfo)
00605 {
00606     //kdDebug(7007) << "special " << url.prettyURL() << endl;
00607     return new SimpleJob(url, CMD_SPECIAL, data, showProgressInfo);
00608 }
00609 
00610 SimpleJob *KIO::mount( bool ro, const char *fstype, const QString& dev, const QString& point, bool showProgressInfo )
00611 {
00612     KIO_ARGS << int(1) << Q_INT8( ro ? 1 : 0 )
00613              << QString::fromLatin1(fstype) << dev << point;
00614     SimpleJob *job = special( KURL("file:/"), packedArgs, showProgressInfo );
00615     if ( showProgressInfo )
00616          Observer::self()->mounting( job, dev, point );
00617     return job;
00618 }
00619 
00620 SimpleJob *KIO::unmount( const QString& point, bool showProgressInfo )
00621 {
00622     KIO_ARGS << int(2) << point;
00623     SimpleJob *job = special( KURL("file:/"), packedArgs, showProgressInfo );
00624     if ( showProgressInfo )
00625          Observer::self()->unmounting( job, point );
00626     return job;
00627 }
00628 
00630 
00631 StatJob::StatJob( const KURL& url, int command,
00632                   const QByteArray &packedArgs, bool showProgressInfo )
00633     : SimpleJob(url, command, packedArgs, showProgressInfo),
00634     m_bSource(true), m_details(2)
00635 {
00636 }
00637 
00638 void StatJob::start(Slave *slave)
00639 {
00640     m_outgoingMetaData.replace( "statSide", m_bSource ? "source" : "dest" );
00641     m_outgoingMetaData.replace( "details", QString::number(m_details) );
00642 
00643     SimpleJob::start(slave);
00644 
00645     connect( m_slave, SIGNAL( statEntry( const KIO::UDSEntry& ) ),
00646              SLOT( slotStatEntry( const KIO::UDSEntry & ) ) );
00647     connect( slave, SIGNAL( redirection(const KURL &) ),
00648              SLOT( slotRedirection(const KURL &) ) );
00649 }
00650 
00651 void StatJob::slotStatEntry( const KIO::UDSEntry & entry )
00652 {
00653     //kdDebug(7007) << "StatJob::slotStatEntry" << endl;
00654     m_statResult = entry;
00655 }
00656 
00657 // Slave got a redirection request
00658 void StatJob::slotRedirection( const KURL &url)
00659 {
00660      kdDebug(7007) << "StatJob::slotRedirection(" << url.prettyURL() << ")" << endl;
00661      if (!kapp->authorizeURLAction("redirect", m_url, url))
00662      {
00663        kdWarning(7007) << "StatJob: Redirection from " << m_url.prettyURL() << " to " << url.prettyURL() << " REJECTED!" << endl;
00664        return;
00665      }
00666      m_redirectionURL = url; // We'll remember that when the job finishes
00667      if (m_url.hasUser() && !url.hasUser() && (m_url.host().lower() == url.host().lower()))
00668         m_redirectionURL.setUser(m_url.user()); // Preserve user
00669      // Tell the user that we haven't finished yet
00670      emit redirection(this, m_redirectionURL);
00671 }
00672 
00673 void StatJob::slotFinished()
00674 {
00675     if ( m_redirectionURL.isEmpty() || m_redirectionURL.isMalformed())
00676     {
00677         // Return slave to the scheduler
00678         SimpleJob::slotFinished();
00679     } else {
00680         //kdDebug(7007) << "StatJob: Redirection to " << m_redirectionURL.prettyURL() << endl;
00681         if (queryMetaData("permanent-redirect")=="true")
00682             emit permanentRedirection(this, m_url, m_redirectionURL);
00683         m_url = m_redirectionURL;
00684         m_redirectionURL = KURL();
00685         m_packedArgs.truncate(0);
00686         QDataStream stream( m_packedArgs, IO_WriteOnly );
00687         stream << m_url;
00688 
00689         // Return slave to the scheduler
00690         slaveDone();
00691         Scheduler::doJob(this);
00692     }
00693 }
00694 
00695 StatJob *KIO::stat(const KURL& url, bool showProgressInfo)
00696 {
00697     // Assume sideIsSource. Gets are more common than puts.
00698     return stat( url, true, 2, showProgressInfo );
00699 }
00700 
00701 StatJob *KIO::stat(const KURL& url, bool sideIsSource, short int details, bool showProgressInfo)
00702 {
00703     kdDebug(7007) << "stat " << url.prettyURL() << endl;
00704     KIO_ARGS << url;
00705     StatJob * job = new StatJob(url, CMD_STAT, packedArgs, showProgressInfo );
00706     job->setSide( sideIsSource );
00707     job->setDetails( details );
00708     if ( showProgressInfo )
00709       Observer::self()->stating( job, url );
00710     return job;
00711 }
00712 
00713 SimpleJob *KIO::http_update_cache( const KURL& url, bool no_cache, time_t expireDate)
00714 {
00715     assert( (url.protocol() == "http") || (url.protocol() == "https") );
00716     // Send http update_cache command (2)
00717     KIO_ARGS << (int)2 << url << no_cache << expireDate;
00718     SimpleJob * job = new SimpleJob( url, CMD_SPECIAL, packedArgs, false );
00719     Scheduler::scheduleJob(job);
00720     return job;
00721 }
00722 
00724 
00725 TransferJob::TransferJob( const KURL& url, int command,
00726                           const QByteArray &packedArgs,
00727                           const QByteArray &_staticData,
00728                           bool showProgressInfo)
00729     : SimpleJob(url, command, packedArgs, showProgressInfo), staticData( _staticData)
00730 {
00731     m_suspended = false;
00732     m_errorPage = false;
00733     m_subJob = 0L;
00734     if ( showProgressInfo )
00735         Observer::self()->slotTransferring( this, url );
00736 }
00737 
00738 // Slave sends data
00739 void TransferJob::slotData( const QByteArray &_data)
00740 {
00741     if(m_redirectionURL.isEmpty() || m_redirectionURL.isMalformed() || m_error)
00742       emit data( this, _data);
00743 }
00744 
00745 // Slave got a redirection request
00746 void TransferJob::slotRedirection( const KURL &url)
00747 {
00748     kdDebug(7007) << "TransferJob::slotRedirection(" << url.prettyURL() << ")" << endl;
00749      if (!kapp->authorizeURLAction("redirect", m_url, url))
00750      {
00751        kdWarning(7007) << "TransferJob: Redirection from " << m_url.prettyURL() << " to " << url.prettyURL() << " REJECTED!" << endl;
00752        return;
00753      }
00754 
00755     // Some websites keep redirecting to themselves where each redirection
00756     // acts as the stage in a state-machine. We define "endless redirections"
00757     // as 5 redirections to the same URL.
00758     if (m_redirectionList.contains(url) > 5)
00759     {
00760        kdDebug(7007) << "TransferJob::slotRedirection: CYCLIC REDIRECTION!" << endl;
00761        m_error = ERR_CYCLIC_LINK;
00762        m_errorText = m_url.prettyURL();
00763     }
00764     else
00765     {
00766        m_redirectionURL = url; // We'll remember that when the job finishes
00767        if (m_url.hasUser() && !url.hasUser() && (m_url.host().lower() == url.host().lower()))
00768           m_redirectionURL.setUser(m_url.user()); // Preserve user
00769        m_redirectionList.append(url);
00770        m_outgoingMetaData["ssl_was_in_use"] = m_incomingMetaData["ssl_in_use"];
00771        // Tell the user that we haven't finished yet
00772        emit redirection(this, m_redirectionURL);
00773     }
00774 }
00775 
00776 void TransferJob::slotFinished()
00777 {
00778    //kdDebug(7007) << "TransferJob::slotFinished(" << this << ", " << m_url.prettyURL() << ")" << endl;
00779     if (m_redirectionURL.isEmpty() || m_redirectionURL.isMalformed())
00780         SimpleJob::slotFinished();
00781     else {
00782         //kdDebug(7007) << "TransferJob: Redirection to " << m_redirectionURL.prettyURL() << endl;
00783         if (queryMetaData("permanent-redirect")=="true")
00784             emit permanentRedirection(this, m_url, m_redirectionURL);
00785         // Honour the redirection
00786         // We take the approach of "redirecting this same job"
00787         // Another solution would be to create a subjob, but the same problem
00788         // happens (unpacking+repacking)
00789         staticData.truncate(0);
00790         m_incomingMetaData.clear();
00791         if (queryMetaData("cache") != "reload")
00792             addMetaData("cache","refresh");
00793         m_suspended = false;
00794         m_url = m_redirectionURL;
00795         m_redirectionURL = KURL();
00796         // The very tricky part is the packed arguments business
00797         QString dummyStr;
00798         KURL dummyUrl;
00799         QDataStream istream( m_packedArgs, IO_ReadOnly );
00800         switch( m_command ) {
00801             case CMD_GET: {
00802                 m_packedArgs.truncate(0);
00803                 QDataStream stream( m_packedArgs, IO_WriteOnly );
00804                 stream << m_url;
00805                 break;
00806             }
00807             case CMD_PUT: {
00808                 int permissions;
00809                 Q_INT8 iOverwrite, iResume;
00810                 istream >> dummyUrl >> iOverwrite >> iResume >> permissions;
00811                 m_packedArgs.truncate(0);
00812                 QDataStream stream( m_packedArgs, IO_WriteOnly );
00813                 stream << m_url << iOverwrite << iResume << permissions;
00814                 break;
00815             }
00816             case CMD_SPECIAL: {
00817                 int specialcmd;
00818                 istream >> specialcmd;
00819                 if (specialcmd == 1) // Assume HTTP POST
00820                 {
00821                    addMetaData("cache","reload");
00822                    m_packedArgs.truncate(0);
00823                    QDataStream stream( m_packedArgs, IO_WriteOnly );
00824                    stream << m_url;
00825                    m_command = CMD_GET;
00826                 }
00827                 break;
00828             }
00829         }
00830 
00831         // Return slave to the scheduler
00832         slaveDone();
00833         Scheduler::doJob(this);
00834     }
00835 }
00836 
00837 // Slave requests data
00838 void TransferJob::slotDataReq()
00839 {
00840     QByteArray dataForSlave;
00841     if (!staticData.isEmpty())
00842     {
00843        dataForSlave = staticData;
00844        staticData = QByteArray();
00845     }
00846     else
00847         emit dataReq( this, dataForSlave);
00848 
00849     static const size_t max_size = 14 * 1024 * 1024;
00850     if (dataForSlave.size() > max_size) {
00851         kdDebug() << "send " << dataForSlave.size() / 1024 / 1024 << "MB of data in TransferJob::dataReq. This needs to be splitted, which requires a copy. Fix the application.\n";
00852         staticData.duplicate(dataForSlave.data() + max_size ,  dataForSlave.size() - max_size);
00853         dataForSlave.truncate(max_size);
00854     }
00855 
00856     m_slave->connection()->send( MSG_DATA, dataForSlave );
00857     if (m_subJob)
00858     {
00859        // Bitburger protocol in action
00860        suspend(); // Wait for more data from subJob.
00861        m_subJob->resume(); // Ask for more!
00862     }
00863 }
00864 
00865 void TransferJob::slotMimetype( const QString& type )
00866 {
00867     m_mimetype = type;
00868     emit mimetype( this, m_mimetype);
00869 }
00870 
00871 
00872 void TransferJob::suspend()
00873 {
00874     m_suspended = true;
00875     if (m_slave)
00876        m_slave->connection()->suspend();
00877 }
00878 
00879 void TransferJob::resume()
00880 {
00881     m_suspended = false;
00882     if (m_slave)
00883        m_slave->connection()->resume();
00884 }
00885 
00886 void TransferJob::start(Slave *slave)
00887 {
00888     assert(slave);
00889     connect( slave, SIGNAL( data( const QByteArray & ) ),
00890              SLOT( slotData( const QByteArray & ) ) );
00891 
00892     connect( slave, SIGNAL( dataReq() ),
00893              SLOT( slotDataReq() ) );
00894 
00895     connect( slave, SIGNAL( redirection(const KURL &) ),
00896              SLOT( slotRedirection(const KURL &) ) );
00897 
00898     connect( slave, SIGNAL(mimeType( const QString& ) ),
00899              SLOT( slotMimetype( const QString& ) ) );
00900 
00901     connect( slave, SIGNAL(errorPage() ),
00902              SLOT( slotErrorPage() ) );
00903 
00904     connect( slave, SIGNAL( needSubURLData() ),
00905              SLOT( slotNeedSubURLData() ) );
00906 
00907     connect( slave, SIGNAL(canResume( KIO::filesize_t ) ),
00908              SLOT( slotCanResume( KIO::filesize_t ) ) );
00909 
00910     if (slave->suspended())
00911     {
00912        m_mimetype = "unknown";
00913        // WABA: The slave was put on hold. Resume operation.
00914        slave->resume();
00915     }
00916 
00917     SimpleJob::start(slave);
00918     if (m_suspended)
00919        slave->connection()->suspend();
00920 }
00921 
00922 void TransferJob::slotNeedSubURLData()
00923 {
00924     // Job needs data from subURL.
00925     m_subJob = KIO::get( m_subUrl, false, false);
00926     suspend(); // Put job on hold until we have some data.
00927     connect(m_subJob, SIGNAL( data(KIO::Job*,const QByteArray &)),
00928             SLOT( slotSubURLData(KIO::Job*,const QByteArray &)));
00929     addSubjob(m_subJob);
00930 }
00931 
00932 void TransferJob::slotSubURLData(KIO::Job*, const QByteArray &data)
00933 {
00934     // The Alternating Bitburg protocol in action again.
00935     staticData = data;
00936     m_subJob->suspend(); // Put job on hold until we have delivered the data.
00937     resume(); // Activate ourselves again.
00938 }
00939 
00940 void TransferJob::slotErrorPage()
00941 {
00942     m_errorPage = true;
00943 }
00944 
00945 void TransferJob::slotCanResume( KIO::filesize_t offset )
00946 {
00947     emit canResume(this, offset);
00948 }
00949 
00950 void TransferJob::slotResult( KIO::Job *job)
00951 {
00952    // This can only be our suburl.
00953    assert(job == m_subJob);
00954    // Did job have an error ?
00955    if ( job->error() )
00956    {
00957       m_error = job->error();
00958       m_errorText = job->errorText();
00959 
00960       emitResult();
00961       return;
00962    }
00963 
00964    if (job == m_subJob)
00965    {
00966       m_subJob = 0; // No action required
00967       resume(); // Make sure we get the remaining data.
00968    }
00969    subjobs.remove(job); // Remove job, but don't kill this job.
00970 }
00971 
00972 TransferJob *KIO::get( const KURL& url, bool reload, bool showProgressInfo )
00973 {
00974     // Send decoded path and encoded query
00975     KIO_ARGS << url;
00976     TransferJob * job = new TransferJob( url, CMD_GET, packedArgs, QByteArray(), showProgressInfo );
00977     if (reload)
00978        job->addMetaData("cache", "reload");
00979     return job;
00980 }
00981 
00982 class PostErrorJob : public TransferJob
00983 {
00984 public:
00985 
00986   PostErrorJob(QString url, const QByteArray &packedArgs, const QByteArray &postData, bool showProgressInfo) : TransferJob("", CMD_SPECIAL, packedArgs, postData, showProgressInfo)
00987   {
00988     m_error = KIO::ERR_POST_DENIED;
00989     m_errorText = url;
00990   }
00991 
00992 };
00993 
00994 TransferJob *KIO::http_post( const KURL& url, const QByteArray &postData, bool showProgressInfo )
00995 {
00996     bool valid = true;
00997 
00998     // filter out non https? protocols
00999     if ((url.protocol() != "http") && (url.protocol() != "https" ))
01000         valid = false;
01001 
01002     // filter out some malicious ports
01003     static const int bad_ports[] = {
01004         1,   // tcpmux
01005         7,   // echo
01006         9,   // discard
01007         11,   // systat
01008         13,   // daytime
01009         15,   // netstat
01010         17,   // qotd
01011         19,   // chargen
01012         20,   // ftp-data
01013         21,   // ftp-cntl
01014         22,   // ssh
01015         23,   // telnet
01016         25,   // smtp
01017         37,   // time
01018         42,   // name
01019         43,   // nicname
01020         53,   // domain
01021         77,   // priv-rjs
01022         79,   // finger
01023         87,   // ttylink
01024         95,   // supdup
01025         101,  // hostriame
01026         102,  // iso-tsap
01027         103,  // gppitnp
01028         104,  // acr-nema
01029         109,  // pop2
01030         110,  // pop3
01031         111,  // sunrpc
01032         113,  // auth
01033         115,  // sftp
01034         117,  // uucp-path
01035         119,  // nntp
01036         123,  // NTP
01037         135,  // loc-srv / epmap
01038         139,  // netbios
01039         143,  // imap2
01040         179,  // BGP
01041         389,  // ldap
01042         512,  // print / exec
01043         513,  // login
01044         514,  // shell
01045         515,  // printer
01046         526,  // tempo
01047         530,  // courier
01048         531,  // Chat
01049         532,  // netnews
01050         540,  // uucp
01051         556,  // remotefs
01052         587,  // sendmail
01053         601,  //
01054         989,  // ftps data
01055         990,  // ftps
01056         992,  // telnets
01057         993,  // imap/SSL
01058         995,  // pop3/SSL
01059         1080, // SOCKS
01060         2049, // nfs
01061         4045, // lockd
01062         6000, // x11
01063         6667, // irc
01064         0};
01065     for (int cnt=0; bad_ports[cnt]; ++cnt)
01066         if (url.port() == bad_ports[cnt])
01067         {
01068             valid = false;
01069             break;
01070         }
01071 
01072     if( !valid )
01073     {
01074     static bool override_loaded = false;
01075     static QValueList< int >* overriden_ports = NULL;
01076     if( !override_loaded )
01077     {
01078         KConfig cfg( "kio_httprc", true );
01079         overriden_ports = new QValueList< int >;
01080         *overriden_ports = cfg.readIntListEntry( "OverriddenPorts" );
01081         override_loaded = true;
01082     }
01083     for( QValueList< int >::ConstIterator it = overriden_ports->begin();
01084          it != overriden_ports->end();
01085          ++it )
01086     if( overriden_ports->contains( url.port()))
01087         valid = true;
01088     }
01089 
01090     // if request is not valid, return an invalid transfer job
01091     if (!valid)
01092     {
01093         KIO_ARGS << (int)1 << url;
01094         TransferJob * job = new PostErrorJob(url.url(), packedArgs, postData, showProgressInfo);
01095         return job;
01096     }
01097 
01098     // Send http post command (1), decoded path and encoded query
01099     KIO_ARGS << (int)1 << url;
01100     TransferJob * job = new TransferJob( url, CMD_SPECIAL,
01101                                          packedArgs, postData, showProgressInfo );
01102     return job;
01103 }
01104 
01105 
01106 
01107 TransferJob *KIO::put( const KURL& url, int permissions,
01108                   bool overwrite, bool resume, bool showProgressInfo )
01109 {
01110     KIO_ARGS << url << Q_INT8( overwrite ? 1 : 0 ) << Q_INT8( resume ? 1 : 0 ) << permissions;
01111     TransferJob * job = new TransferJob( url, CMD_PUT, packedArgs, QByteArray(), showProgressInfo );
01112     return job;
01113 }
01114 
01116 
01117 MimetypeJob::MimetypeJob( const KURL& url, int command,
01118                   const QByteArray &packedArgs, bool showProgressInfo )
01119     : TransferJob(url, command, packedArgs, QByteArray(), showProgressInfo)
01120 {
01121 }
01122 
01123 void MimetypeJob::start(Slave *slave)
01124 {
01125     TransferJob::start(slave);
01126 }
01127 
01128 
01129 void MimetypeJob::slotFinished( )
01130 {
01131     kdDebug(7007) << "MimetypeJob::slotFinished()" << endl;
01132     if ( m_error == KIO::ERR_IS_DIRECTORY )
01133     {
01134         // It is in fact a directory. This happens when HTTP redirects to FTP.
01135         // Due to the "protocol doesn't support listing" code in KRun, we
01136         // assumed it was a file.
01137         kdDebug(7007) << "It is in fact a directory!" << endl;
01138         m_mimetype = QString::fromLatin1("inode/directory");
01139         emit TransferJob::mimetype( this, m_mimetype );
01140         m_error = 0;
01141     }
01142     if ( m_redirectionURL.isEmpty() || m_redirectionURL.isMalformed() || m_error )
01143     {
01144         // Return slave to the scheduler
01145         TransferJob::slotFinished();
01146     } else {
01147         //kdDebug(7007) << "MimetypeJob: Redirection to " << m_redirectionURL.prettyURL() << endl;
01148         if (queryMetaData("permanent-redirect")=="true")
01149             emit permanentRedirection(this, m_url, m_redirectionURL);
01150         staticData.truncate(0);
01151         m_suspended = false;
01152         m_url = m_redirectionURL;
01153         m_redirectionURL = KURL();
01154         m_packedArgs.truncate(0);
01155         QDataStream stream( m_packedArgs, IO_WriteOnly );
01156         stream << m_url;
01157 
01158         // Return slave to the scheduler
01159         slaveDone();
01160         Scheduler::doJob(this);
01161     }
01162 }
01163 
01164 MimetypeJob *KIO::mimetype(const KURL& url, bool showProgressInfo )
01165 {
01166     KIO_ARGS << url;
01167     MimetypeJob * job = new MimetypeJob(url, CMD_MIMETYPE, packedArgs, showProgressInfo);
01168     if ( showProgressInfo )
01169       Observer::self()->stating( job, url );
01170     return job;
01171 }
01172 
01174 
01175 
01176 class FileCopyJob::FileCopyJobPrivate
01177 {
01178 public:
01179     off_t m_sourceSize;
01180     SimpleJob *m_delJob;
01181 };
01182 
01183 /*
01184  * The FileCopyJob works according to the famous Bayern
01185  * 'Alternating Bitburger Protocol': we either drink a beer or we
01186  * we order a beer, but never both at the same time.
01187  * Tranlated to io-slaves: We alternate between receiving a block of data
01188  * and sending it away.
01189  */
01190 FileCopyJob::FileCopyJob( const KURL& src, const KURL& dest, int permissions,
01191                           bool move, bool overwrite, bool resume, bool showProgressInfo)
01192     : Job(showProgressInfo), m_src(src), m_dest(dest),
01193       m_permissions(permissions), m_move(move), m_overwrite(overwrite), m_resume(resume),
01194       m_totalSize(0)
01195 {
01196    if (showProgressInfo && !move)
01197       Observer::self()->slotCopying( this, src, dest );
01198    else if (showProgressInfo && move)
01199       Observer::self()->slotMoving( this, src, dest );
01200 
01201     //kdDebug(7007) << "FileCopyJob::FileCopyJob()" << endl;
01202     m_moveJob = 0;
01203     m_copyJob = 0;
01204     m_getJob = 0;
01205     m_putJob = 0;
01206     d = new FileCopyJobPrivate;
01207     d->m_delJob = 0;
01208     d->m_sourceSize = (off_t) -1;
01209     QTimer::singleShot(0, this, SLOT(slotStart()));
01210 }
01211 
01212 void FileCopyJob::slotStart()
01213 {
01214     if ((m_src.protocol() == m_dest.protocol()) &&
01215         (m_src.host() == m_dest.host()) &&
01216         (m_src.port() == m_dest.port()) &&
01217         (m_src.user() == m_dest.user()) &&
01218         (m_src.pass() == m_dest.pass()))
01219     {
01220        if (m_move)
01221        {
01222           m_moveJob = KIO::rename( m_src, m_dest, m_overwrite );
01223           addSubjob( m_moveJob );
01224           connectSubjob( m_moveJob );
01225        }
01226        else
01227        {
01228           startCopyJob();
01229        }
01230     }
01231     else
01232     {
01233        if (!m_move &&
01234            (m_src.isLocalFile() && KProtocolInfo::canCopyFromFile(m_dest))
01235           )
01236        {
01237           startCopyJob(m_dest);
01238        }
01239        else if (!m_move &&
01240            (m_dest.isLocalFile() && KProtocolInfo::canCopyToFile(m_src))
01241           )
01242        {
01243           startCopyJob(m_src);
01244        }
01245        else
01246        {
01247           startDataPump();
01248        }
01249     }
01250 }
01251 
01252 FileCopyJob::~FileCopyJob()
01253 {
01254     delete d;
01255 }
01256 
01257 void FileCopyJob::setSourceSize( off_t size )
01258 {
01259     d->m_sourceSize = size;
01260     m_totalSize = size;
01261 }
01262 
01263 void FileCopyJob::startCopyJob()
01264 {
01265     startCopyJob(m_src);
01266 }
01267 
01268 void FileCopyJob::startCopyJob(const KURL &slave_url)
01269 {
01270     //kdDebug(7007) << "FileCopyJob::startCopyJob()" << endl;
01271     KIO_ARGS << m_src << m_dest << m_permissions << (Q_INT8) m_overwrite;
01272     m_copyJob = new SimpleJob(slave_url, CMD_COPY, packedArgs, false);
01273     addSubjob( m_copyJob );
01274     connectSubjob( m_copyJob );
01275 }
01276 
01277 void FileCopyJob::connectSubjob( SimpleJob * job )
01278 {
01279     connect( job, SIGNAL(totalSize( KIO::Job*, KIO::filesize_t )),
01280              this, SLOT( slotTotalSize(KIO::Job*, KIO::filesize_t)) );
01281 
01282     connect( job, SIGNAL(processedSize( KIO::Job*, KIO::filesize_t )),
01283              this, SLOT( slotProcessedSize(KIO::Job*, KIO::filesize_t)) );
01284 
01285     connect( job, SIGNAL(percent( KIO::Job*, unsigned long )),
01286              this, SLOT( slotPercent(KIO::Job*, unsigned long)) );
01287 
01288 }
01289 
01290 void FileCopyJob::slotProcessedSize( KIO::Job *, KIO::filesize_t size )
01291 {
01292     emit processedSize( this, size );
01293     if ( size > m_totalSize ) {
01294         slotTotalSize( this, size ); // safety
01295     }
01296     emitPercent( size, m_totalSize );
01297 }
01298 
01299 void FileCopyJob::slotTotalSize( KIO::Job*, KIO::filesize_t size )
01300 {
01301     m_totalSize = size;
01302     emit totalSize( this, m_totalSize );
01303 }
01304 
01305 void FileCopyJob::slotPercent( KIO::Job*, unsigned long pct )
01306 {
01307     if ( pct > m_percent )
01308     {
01309         m_percent = pct;
01310         emit percent( this, m_percent );
01311     }
01312 }
01313 
01314 void FileCopyJob::startDataPump()
01315 {
01316     //kdDebug(7007) << "FileCopyJob::startDataPump()" << endl;
01317 
01318     m_canResume = false;
01319     m_resumeAnswerSent = false;
01320     m_getJob = 0L; // for now
01321     m_putJob = put( m_dest, m_permissions, m_overwrite, m_resume, false /* no GUI */);
01322     //kdDebug(7007) << "FileCopyJob: m_putJob = " << m_putJob << " m_dest=" << m_dest.prettyURL() << endl;
01323 
01324     // The first thing the put job will tell us is whether we can
01325     // resume or not (this is always emitted)
01326     connect( m_putJob, SIGNAL(canResume(KIO::Job *, KIO::filesize_t)),
01327              SLOT( slotCanResume(KIO::Job *, KIO::filesize_t)));
01328     connect( m_putJob, SIGNAL(dataReq(KIO::Job *, QByteArray&)),
01329              SLOT( slotDataReq(KIO::Job *, QByteArray&)));
01330     addSubjob( m_putJob );
01331 }
01332 
01333 void FileCopyJob::slotCanResume( KIO::Job* job, KIO::filesize_t offset )
01334 {
01335     if ( job == m_putJob )
01336     {
01337         kdDebug(7007) << "FileCopyJob::slotCanResume from PUT job. offset=" << KIO::number(offset) << endl;
01338         if (offset)
01339         {
01340             RenameDlg_Result res = R_RESUME;
01341 
01342             if (!KProtocolManager::autoResume())
01343             {
01344                 QString newPath;
01345                 KIO::Job* job = ( !m_progressId && parentJob() ) ? parentJob() : this;
01346                 // Ask confirmation about resuming previous transfer
01347                 res = Observer::self()->open_RenameDlg(
01348                       job, i18n("File Already Exists"),
01349                       m_src.prettyURL(0, KURL::StripFileProtocol),
01350                       m_dest.prettyURL(0, KURL::StripFileProtocol),
01351                       (RenameDlg_Mode) (M_OVERWRITE | M_RESUME | M_NORENAME), newPath,
01352                       d->m_sourceSize, offset );
01353             }
01354 
01355             if ( res == R_OVERWRITE )
01356               offset = 0;
01357             else if ( res == R_CANCEL )
01358             {
01359                 m_putJob->kill(true);
01360                 m_error = ERR_USER_CANCELED;
01361                 emitResult();
01362                 return;
01363             }
01364         }
01365         else
01366             m_resumeAnswerSent = true; // No need for an answer
01367 
01368         m_getJob = get( m_src, false, false /* no GUI */ );
01369         //kdDebug(7007) << "FileCopyJob: m_getJob = " << m_getJob << endl;
01370         m_getJob->addMetaData( "errorPage", "false" );
01371         m_getJob->addMetaData( "AllowCompressedPage", "false" );
01372         // Set size in subjob. This helps if the slave doesn't emit totalSize.
01373         if ( d->m_sourceSize != (off_t)-1 )
01374             m_getJob->slotTotalSize( d->m_sourceSize );
01375         if (offset)
01376         {
01377             kdDebug(7007) << "Setting metadata for resume to " << (unsigned long) offset << endl;
01378             m_getJob->addMetaData( "resume", KIO::number(offset) );
01379 
01380             // Might or might not get emitted
01381             connect( m_getJob, SIGNAL(canResume(KIO::Job *, KIO::filesize_t)),
01382                      SLOT( slotCanResume(KIO::Job *, KIO::filesize_t)));
01383         }
01384         m_putJob->slave()->setOffset( offset );
01385 
01386         m_putJob->suspend();
01387         addSubjob( m_getJob );
01388         connectSubjob( m_getJob ); // Progress info depends on get
01389         m_getJob->resume(); // Order a beer
01390 
01391         connect( m_getJob, SIGNAL(data(KIO::Job *, const QByteArray&)),
01392                  SLOT( slotData(KIO::Job *, const QByteArray&)));
01393     }
01394     else if ( job == m_getJob )
01395     {
01396         // Cool, the get job said ok, we can resume
01397         m_canResume = true;
01398         kdDebug(7007) << "FileCopyJob::slotCanResume from the GET job -> we can resume" << endl;
01399 
01400         m_getJob->slave()->setOffset( m_putJob->slave()->offset() );
01401     }
01402     else
01403         kdWarning(7007) << "FileCopyJob::slotCanResume from unknown job=" << job
01404                         << " m_getJob=" << m_getJob << " m_putJob=" << m_putJob << endl;
01405 }
01406 
01407 void FileCopyJob::slotData( KIO::Job * , const QByteArray &data)
01408 {
01409    //kdDebug(7007) << "FileCopyJob::slotData" << endl;
01410    //kdDebug(7007) << " data size : " << data.size() << endl;
01411    assert(m_putJob);
01412    m_getJob->suspend();
01413    m_putJob->resume(); // Drink the beer
01414    m_buffer = data;
01415 
01416    // On the first set of data incoming, we tell the "put" slave about our
01417    // decision about resuming
01418    if (!m_resumeAnswerSent)
01419    {
01420        m_resumeAnswerSent = true;
01421        kdDebug(7007) << "FileCopyJob::slotData (first time) -> send resume answer " << m_canResume << endl;
01422        m_putJob->slave()->sendResumeAnswer( m_canResume );
01423    }
01424 }
01425 
01426 void FileCopyJob::slotDataReq( KIO::Job * , QByteArray &data)
01427 {
01428    //kdDebug(7007) << "FileCopyJob::slotDataReq" << endl;
01429    if (!m_resumeAnswerSent && !m_getJob)
01430    {
01431        // This can't happen (except as a migration bug on 12/10/2000)
01432        m_error = ERR_INTERNAL;
01433        m_errorText = "'Put' job didn't send canResume or 'Get' job didn't send data!";
01434        m_putJob->kill(true);
01435        emitResult();
01436        return;
01437    }
01438    if (m_getJob)
01439    {
01440       m_getJob->resume(); // Order more beer
01441       m_putJob->suspend();
01442    }
01443    data = m_buffer;
01444    m_buffer = QByteArray();
01445 }
01446 
01447 void FileCopyJob::slotResult( KIO::Job *job)
01448 {
01449    //kdDebug(7007) << "FileCopyJob this=" << this << " ::slotResult(" << job << ")" << endl;
01450    // Did job have an error ?
01451    if ( job->error() )
01452    {
01453       if ((job == m_moveJob) && (job->error() == ERR_UNSUPPORTED_ACTION))
01454       {
01455          m_moveJob = 0;
01456          startCopyJob();
01457          removeSubjob(job);
01458          return;
01459       }
01460       else if ((job == m_copyJob) && (job->error() == ERR_UNSUPPORTED_ACTION))
01461       {
01462          m_copyJob = 0;
01463          startDataPump();
01464          removeSubjob(job);
01465          return;
01466       }
01467       else if (job == m_getJob)
01468       {
01469         m_getJob = 0L;
01470         if (m_putJob)
01471           m_putJob->kill(true);
01472       }
01473       else if (job == m_putJob)
01474       {
01475         m_putJob = 0L;
01476         if (m_getJob)
01477           m_getJob->kill(true);
01478       }
01479       m_error = job->error();
01480       m_errorText = job->errorText();
01481       emitResult();
01482       return;
01483    }
01484 
01485    if (job == m_moveJob)
01486    {
01487       m_moveJob = 0; // Finished
01488    }
01489 
01490    if (job == m_copyJob)
01491    {
01492       m_copyJob = 0;
01493       if (m_move)
01494       {
01495          d->m_delJob = file_delete( m_src, false/*no GUI*/ ); // Delete source
01496          addSubjob(d->m_delJob);
01497       }
01498    }
01499 
01500    if (job == m_getJob)
01501    {
01502       m_getJob = 0; // No action required
01503       if (m_putJob)
01504          m_putJob->resume();
01505    }
01506 
01507    if (job == m_putJob)
01508    {
01509       //kdDebug(7007) << "FileCopyJob: m_putJob finished " << endl;
01510       m_putJob = 0;
01511       if (m_getJob)
01512       {
01513          kdWarning(7007) << "WARNING ! Get still going on..." << endl;
01514          m_getJob->resume();
01515       }
01516       if (m_move)
01517       {
01518          d->m_delJob = file_delete( m_src, false/*no GUI*/ ); // Delete source
01519          addSubjob(d->m_delJob);
01520       }
01521    }
01522 
01523    if (job == d->m_delJob)
01524    {
01525       d->m_delJob = 0; // Finished
01526    }
01527    removeSubjob(job);
01528 }
01529 
01530 FileCopyJob *KIO::file_copy( const KURL& src, const KURL& dest, int permissions,
01531                              bool overwrite, bool resume, bool showProgressInfo)
01532 {
01533    return new FileCopyJob( src, dest, permissions, false, overwrite, resume, showProgressInfo );
01534 }
01535 
01536 FileCopyJob *KIO::file_move( const KURL& src, const KURL& dest, int permissions,
01537                              bool overwrite, bool resume, bool showProgressInfo)
01538 {
01539    return new FileCopyJob( src, dest, permissions, true, overwrite, resume, showProgressInfo );
01540 }
01541 
01542 SimpleJob *KIO::file_delete( const KURL& src, bool showProgressInfo)
01543 {
01544     KIO_ARGS << src << Q_INT8(true); // isFile
01545     return new SimpleJob(src, CMD_DEL, packedArgs, showProgressInfo );
01546 }
01547 
01549 
01550 ListJob::ListJob(const KURL& u, bool showProgressInfo, bool _recursive, QString _prefix, bool _includeHidden) :
01551     SimpleJob(u, CMD_LISTDIR, QByteArray(), showProgressInfo),
01552     recursive(_recursive), includeHidden(_includeHidden), prefix(_prefix), m_processedEntries(0)
01553 {
01554     // We couldn't set the args when calling the parent constructor,
01555     // so do it now.
01556     QDataStream stream( m_packedArgs, IO_WriteOnly );
01557     stream << u;
01558 }
01559 
01560 void ListJob::slotListEntries( const KIO::UDSEntryList& list )
01561 {
01562     // Emit progress info (takes care of emit processedSize and percent)
01563     m_processedEntries += list.count();
01564     slotProcessedSize( m_processedEntries );
01565 
01566     if (recursive) {
01567         UDSEntryListConstIterator it = list.begin();
01568         UDSEntryListConstIterator end = list.end();
01569 
01570         for (; it != end; ++it) {
01571             bool isDir = false;
01572             bool isLink = false;
01573             QString filename;
01574 
01575             UDSEntry::ConstIterator it2 = (*it).begin();
01576             UDSEntry::ConstIterator end2 = (*it).end();
01577             for( ; it2 != end2; it2++ ) {
01578                 switch( (*it2).m_uds ) {
01579                     case UDS_FILE_TYPE:
01580                         isDir = S_ISDIR((*it2).m_long);
01581                         break;
01582                     case UDS_NAME:
01583                         filename = (*it2).m_str;
01584                         break;
01585                     case UDS_LINK_DEST:
01586                         // This is a link !!! Don't follow !
01587                         isLink = !(*it2).m_str.isEmpty();
01588                         break;
01589                     default:
01590                         break;
01591                 }
01592             }
01593             if (isDir && !isLink) {
01594                 // skip hidden dirs when listing if requested
01595                 if (filename != ".." && filename != "." && (includeHidden || filename[0] != '.')) {
01596                     KURL newone = url();
01597                     newone.addPath(filename);
01598                     ListJob *job = new ListJob(newone, m_progressId!=0, true, prefix + filename + "/",includeHidden);
01599                     Scheduler::scheduleJob(job);
01600                     connect(job, SIGNAL(entries( KIO::Job *,
01601                                                  const KIO::UDSEntryList& )),
01602                             SLOT( gotEntries( KIO::Job*,
01603                                               const KIO::UDSEntryList& )));
01604                     addSubjob(job);
01605                 }
01606             }
01607         }
01608     }
01609 
01610     // Not recursive, or top-level of recursive listing : return now (send . and .. as well)
01611     // exclusion of hidden files also requires the full sweep, but the case for full-listing
01612     // a single dir is probably common enough to justify the shortcut
01613     if (prefix.isNull() && includeHidden) {
01614         emit entries(this, list);
01615     } else {
01616         // cull the unwanted hidden dirs and/or parent dir references from the listing, then emit that
01617         UDSEntryList newlist;
01618 
01619         UDSEntryListConstIterator it = list.begin();
01620         UDSEntryListConstIterator end = list.end();
01621         for (; it != end; ++it) {
01622 
01623             UDSEntry newone = *it;
01624             UDSEntry::Iterator it2 = newone.begin();
01625             QString filename;
01626             for( ; it2 != newone.end(); it2++ ) {
01627                 if ((*it2).m_uds == UDS_NAME) {
01628                     filename = (*it2).m_str;
01629                     (*it2).m_str = prefix + filename;
01630                 }
01631             }
01632             // Avoid returning entries like subdir/. and subdir/.., but include . and .. for
01633             // the the toplevel dir, and skip hidden files/dirs if that was requested
01634             if (  (prefix.isNull() || (filename != ".." && filename != ".") )
01635                && (includeHidden || (filename[0] != '.') )  )
01636                 newlist.append(newone);
01637         }
01638 
01639         emit entries(this, newlist);
01640     }
01641 }
01642 
01643 void ListJob::gotEntries(KIO::Job *, const KIO::UDSEntryList& list )
01644 {
01645     // Forward entries received by subjob - faking we received them ourselves
01646     emit entries(this, list);
01647 }
01648 
01649 void ListJob::slotResult( KIO::Job * job )
01650 {
01651     // If we can't list a subdir, the result is still ok
01652     // This is why we override Job::slotResult() - to skip error checking
01653     removeSubjob( job );
01654 }
01655 
01656 void ListJob::slotRedirection( const KURL & url )
01657 {
01658      if (!kapp->authorizeURLAction("redirect", m_url, url))
01659      {
01660        kdWarning(7007) << "ListJob: Redirection from " << m_url.prettyURL() << " to " << url.prettyURL() << " REJECTED!" << endl;
01661        return;
01662      }
01663     m_redirectionURL = url; // We'll remember that when the job finishes
01664     if (m_url.hasUser() && !url.hasUser() && (m_url.host().lower() == url.host().lower()))
01665         m_redirectionURL.setUser(m_url.user()); // Preserve user
01666     emit redirection( this, url );
01667 }
01668 
01669 void ListJob::slotFinished()
01670 {
01671     if ( m_redirectionURL.isEmpty() || m_redirectionURL.isMalformed() || m_error )
01672     {
01673         // Return slave to the scheduler
01674         SimpleJob::slotFinished();
01675     } else {
01676         kdDebug(7007) << "ListJob: Redirection to " << m_redirectionURL.prettyURL() << endl;
01677         if (queryMetaData("permanent-redirect")=="true")
01678             emit permanentRedirection(this, m_url, m_redirectionURL);
01679         m_url = m_redirectionURL;
01680         m_redirectionURL = KURL();
01681         m_packedArgs.truncate(0);
01682         QDataStream stream( m_packedArgs, IO_WriteOnly );
01683         stream << m_url;
01684 
01685         // Return slave to the scheduler
01686         slaveDone();
01687         Scheduler::doJob(this);
01688     }
01689 }
01690 
01691 ListJob *KIO::listDir( const KURL& url, bool showProgressInfo, bool includeHidden )
01692 {
01693     ListJob * job = new ListJob(url, showProgressInfo,false,QString::null,includeHidden);
01694     return job;
01695 }
01696 
01697 ListJob *KIO::listRecursive( const KURL& url, bool showProgressInfo, bool includeHidden )
01698 {
01699     ListJob * job = new ListJob(url, showProgressInfo, true,QString::null,includeHidden);
01700     return job;
01701 }
01702 
01703 void ListJob::start(Slave *slave)
01704 {
01705     connect( slave, SIGNAL( listEntries( const KIO::UDSEntryList& )),
01706              SLOT( slotListEntries( const KIO::UDSEntryList& )));
01707     connect( slave, SIGNAL( totalSize( KIO::filesize_t ) ),
01708              SLOT( slotTotalSize( KIO::filesize_t ) ) );
01709     connect( slave, SIGNAL( redirection(const KURL &) ),
01710              SLOT( slotRedirection(const KURL &) ) );
01711 
01712     SimpleJob::start(slave);
01713 }
01714 
01715 
01716 CopyJob::CopyJob( const KURL::List& src, const KURL& dest, CopyMode mode, bool asMethod, bool showProgressInfo )
01717   : Job(showProgressInfo), m_mode(mode), m_asMethod(asMethod),
01718     destinationState(DEST_NOT_STATED), state(STATE_STATING),
01719     m_totalSize(0), m_processedSize(0), m_fileProcessedSize(0),
01720     m_processedFiles(0), m_processedDirs(0),
01721     m_srcList(src), m_currentStatSrc(m_srcList.begin()),
01722     m_bCurrentOperationIsLink(false), m_bSingleFileCopy(false), m_bOnlyRenames(mode==Move),
01723     m_dest(dest), m_bAutoSkip( false ), m_bOverwriteAll( false ),
01724     m_conflictError(0), m_reportTimer(0)
01725 {
01726     if ( showProgressInfo ) {
01727         connect( this, SIGNAL( totalFiles( KIO::Job*, unsigned long ) ),
01728                  Observer::self(), SLOT( slotTotalFiles( KIO::Job*, unsigned long ) ) );
01729 
01730         connect( this, SIGNAL( totalDirs( KIO::Job*, unsigned long ) ),
01731                  Observer::self(), SLOT( slotTotalDirs( KIO::Job*, unsigned long ) ) );
01732     }
01733     QTimer::singleShot(0, this, SLOT(slotStart()));
01734 }
01735 
01736 void CopyJob::slotStart()
01737 {
01743     m_reportTimer = new QTimer(this);
01744 
01745     connect(m_reportTimer,SIGNAL(timeout()),this,SLOT(slotReport()));
01746     m_reportTimer->start(REPORT_TIMEOUT,false);
01747 
01748     // Stat the dest
01749     KIO::Job * job = KIO::stat( m_dest, false, 2, false );
01750     //kdDebug(7007) << "CopyJob:stating the dest " << m_dest.prettyURL() << endl;
01751     addSubjob(job);
01752 }
01753 
01754 void CopyJob::slotResultStating( Job *job )
01755 {
01756     //kdDebug(7007) << "CopyJob::slotResultStating" << endl;
01757     // Was there an error while stating the src ?
01758     if (job->error() && destinationState != DEST_NOT_STATED )
01759     {
01760         KURL srcurl = ((SimpleJob*)job)->url();
01761         if ( !srcurl.isLocalFile() )
01762         {
01763             // Probably : src doesn't exist. Well, over some protocols (e.g. FTP)
01764             // this info isn't really reliable (thanks to MS FTP servers).
01765             // We'll assume a file, and try to download anyway.
01766             kdDebug(7007) << "Error while stating source. Activating hack" << endl;
01767             subjobs.remove( job );
01768             assert ( subjobs.isEmpty() ); // We should have only one job at a time ...
01769             struct CopyInfo info;
01770             info.permissions = (mode_t) -1;
01771             info.mtime = (time_t) -1;
01772             info.ctime = (time_t) -1;
01773             info.size = (off_t)-1;
01774             info.uSource = srcurl;
01775             info.uDest = m_dest;
01776             // Append filename or dirname to destination URL, if allowed
01777             if ( destinationState == DEST_IS_DIR && !m_asMethod )
01778                 info.uDest.addPath( srcurl.fileName() );
01779 
01780             files.append( info );
01781             ++m_currentStatSrc;
01782             statNextSrc();
01783             return;
01784         }
01785         // Local file. If stat fails, the file definitely doesn't exist.
01786         Job::slotResult( job ); // will set the error and emit result(this)
01787         return;
01788     }
01789 
01790     // Is it a file or a dir ?
01791     UDSEntry entry = ((StatJob*)job)->statResult();
01792     bool bDir = false;
01793     bool bLink = false;
01794     UDSEntry::ConstIterator it2 = entry.begin();
01795     for( ; it2 != entry.end(); it2++ ) {
01796         if ( ((*it2).m_uds) == UDS_FILE_TYPE )
01797             bDir = S_ISDIR( (mode_t)(*it2).m_long );
01798         else if ( ((*it2).m_uds) == UDS_LINK_DEST )
01799             bLink = !((*it2).m_str.isEmpty());
01800     }
01801 
01802     if ( destinationState == DEST_NOT_STATED )
01803         // we were stating the dest
01804     {
01805         if (job->error())
01806             destinationState = DEST_DOESNT_EXIST;
01807         else {
01808             // Treat symlinks to dirs as dirs here, so no test on bLink
01809             destinationState = bDir ? DEST_IS_DIR : DEST_IS_FILE;
01810             //kdDebug(7007) << "CopyJob::slotResultStating dest is dir:" << bDir << endl;
01811         }
01812         subjobs.remove( job );
01813         assert ( subjobs.isEmpty() );
01814 
01815         // After knowing what the dest is, we can start stat'ing the first src.
01816         statNextSrc();
01817         return;
01818     }
01819     // We were stating the current source URL
01820     m_currentDest = m_dest; // used by slotEntries
01821     // Create a dummy list with it, for slotEntries
01822     UDSEntryList lst;
01823     lst.append(entry);
01824 
01825     // There 6 cases, and all end up calling slotEntries(job, lst) first :
01826     // 1 - src is a dir, destination is a directory,
01827     // slotEntries will append the source-dir-name to the destination
01828     // 2 - src is a dir, destination is a file, ERROR (done later on)
01829     // 3 - src is a dir, destination doesn't exist, then it's the destination dirname,
01830     // so slotEntries will use it as destination.
01831 
01832     // 4 - src is a file, destination is a directory,
01833     // slotEntries will append the filename to the destination.
01834     // 5 - src is a file, destination is a file, m_dest is the exact destination name
01835     // 6 - src is a file, destination doesn't exist, m_dest is the exact destination name
01836     // Tell slotEntries not to alter the src url
01837     m_bCurrentSrcIsDir = false;
01838     slotEntries(job, lst);
01839 
01840     KURL srcurl = ((SimpleJob*)job)->url();
01841 
01842     subjobs.remove( job );
01843     assert ( subjobs.isEmpty() ); // We should have only one job at a time ...
01844 
01845     if ( bDir
01846          && !bLink // treat symlinks as files (no recursion)
01847          && m_mode != Link ) // No recursion in Link mode either.
01848     {
01849         //kdDebug(7007) << " Source is a directory " << endl;
01850 
01851         m_bCurrentSrcIsDir = true; // used by slotEntries
01852         if ( destinationState == DEST_IS_DIR ) // (case 1)
01853             // Use <desturl>/<directory_copied> as destination, from now on
01854             m_currentDest.addPath( srcurl.fileName() );
01855         else if ( destinationState == DEST_IS_FILE ) // (case 2)
01856         {
01857             m_error = ERR_IS_FILE;
01858             m_errorText = m_dest.prettyURL();
01859             emitResult();
01860             return;
01861         }
01862         else // (case 3)
01863         {
01864             // otherwise dest is new name for toplevel dir
01865             // so the destination exists, in fact, from now on.
01866             // (This even works with other src urls in the list, since the
01867             //  dir has effectively been created)
01868             destinationState = DEST_IS_DIR;
01869         }
01870 
01871         startListing( srcurl );
01872     }
01873     else
01874     {
01875         //kdDebug(7007) << " Source is a file (or a symlink), or we are linking -> no recursive listing " << endl;
01876         ++m_currentStatSrc;
01877         statNextSrc();
01878     }
01879 }
01880 
01881 void CopyJob::slotReport()
01882 {
01883     // If showProgressInfo was set, m_progressId is > 0.
01884     Observer * observer = m_progressId ? Observer::self() : 0L;
01885     switch (state) {
01886         case STATE_COPYING_FILES:
01887             emit processedFiles( this, m_processedFiles );
01888             if (observer) observer->slotProcessedFiles(this,m_processedFiles);
01889             if (m_mode==Move)
01890             {
01891                 if (observer) observer->slotMoving( this, m_currentSrcURL,m_currentDestURL);
01892                 emit moving( this, m_currentSrcURL, m_currentDestURL);
01893             }
01894             else if (m_mode==Link)
01895             {
01896                 if (observer) observer->slotCopying( this, m_currentSrcURL, m_currentDestURL ); // we don't have a slotLinking
01897                 emit linking( this, m_currentSrcURL.path(), m_currentDestURL );
01898             }
01899             else
01900             {
01901                 if (observer) observer->slotCopying( this, m_currentSrcURL, m_currentDestURL );
01902                 emit copying( this, m_currentSrcURL, m_currentDestURL );
01903             };
01904             break;
01905 
01906         case STATE_CREATING_DIRS:
01907             if (observer) {
01908                 observer->slotProcessedDirs( this, m_processedDirs );
01909                 observer->slotCreatingDir( this,m_currentDestURL);
01910             }
01911             emit processedDirs( this, m_processedDirs );
01912             emit creatingDir( this, m_currentDestURL );
01913             break;
01914 
01915         case STATE_STATING:
01916         case STATE_LISTING:
01917             if (observer) observer->slotCopying( this, m_currentSrcURL, m_currentDestURL );
01918             emit totalSize( this, m_totalSize );
01919             emit totalFiles( this, files.count() );
01920             emit totalDirs( this, dirs.count() );
01921             break;
01922 
01923         default:
01924             break;
01925     }
01926 }
01927 
01928 void CopyJob::slotEntries(KIO::Job* job, const UDSEntryList& list)
01929 {
01930     UDSEntryListConstIterator it = list.begin();
01931     UDSEntryListConstIterator end = list.end();
01932     for (; it != end; ++it) {
01933         UDSEntry::ConstIterator it2 = (*it).begin();
01934         struct CopyInfo info;
01935         info.permissions = -1;
01936         info.mtime = (time_t) -1;
01937         info.ctime = (time_t) -1;
01938         info.size = (off_t)-1;
01939         QString relName;
01940         bool isDir = false;
01941         for( ; it2 != (*it).end(); it2++ ) {
01942             switch ((*it2).m_uds) {
01943                 case UDS_FILE_TYPE:
01944                     //info.type = (mode_t)((*it2).m_long);
01945                     isDir = S_ISDIR( (mode_t)((*it2).m_long) );
01946                     break;
01947                 case UDS_NAME:
01948                     relName = (*it2).m_str;
01949                     break;
01950                 case UDS_LINK_DEST:
01951                     info.linkDest = (*it2).m_str;
01952                     break;
01953                 case UDS_ACCESS:
01954                     info.permissions = ((*it2).m_long);
01955                     break;
01956                 case UDS_SIZE:
01957                     info.size = (off_t)((*it2).m_long);
01958                     m_totalSize += info.size;
01959                     break;
01960                 case UDS_MODIFICATION_TIME:
01961                     info.mtime = (time_t)((*it2).m_long);
01962                     break;
01963                 case UDS_CREATION_TIME:
01964                     info.ctime = (time_t)((*it2).m_long);
01965                 default:
01966                     break;
01967             }
01968         }
01969         if (relName != ".." && relName != ".")
01970         {
01971             //kdDebug(7007) << "CopyJob::slotEntries '" << relName << "'" << endl;
01972             info.uSource = ((SimpleJob *)job)->url();
01973             if ( m_bCurrentSrcIsDir ) // Only if src is a directory. Otherwise uSource is fine as is
01974                 info.uSource.addPath( relName );
01975             info.uDest = m_currentDest;
01976             //kdDebug(7007) << "uDest(1)=" << info.uDest.prettyURL() << endl;
01977             // Append filename or dirname to destination URL, if allowed
01978             if ( destinationState == DEST_IS_DIR && !m_asMethod )
01979             {
01980                 // Here we _really_ have to add some filename to the dest.
01981                 // Otherwise, we end up with e.g. dest=..../Desktop/ itself.
01982                 // (This can happen when dropping a link to a webpage with no path)
01983                 if ( relName.isEmpty() )
01984                     info.uDest.addPath( KIO::encodeFileName( info.uSource.prettyURL() ) );
01985                 else
01986                     info.uDest.addPath( relName );
01987             }
01988             //kdDebug(7007) << "uDest(2)=" << info.uDest.prettyURL() << endl;
01989             if ( info.linkDest.isEmpty() && (isDir /*S_ISDIR(info.type)*/) && m_mode != Link ) // Dir
01990             {
01991                 dirs.append( info ); // Directories
01992                 if (m_mode == Move)
01993                     dirsToRemove.append( info.uSource );
01994             }
01995             else {
01996                 files.append( info ); // Files and any symlinks
01997             }
01998         }
01999     }
02000 }
02001 
02002 void CopyJob::statNextSrc()
02003 {
02004     if ( m_currentStatSrc != m_srcList.end() )
02005     {
02006         m_currentSrcURL = (*m_currentStatSrc);
02007         if ( m_mode == Link )
02008         {
02009             // Skip the "stating the source" stage, we don't need it for linking
02010             m_currentDest = m_dest;
02011             struct CopyInfo info;
02012             info.permissions = -1;
02013             info.mtime = (time_t) -1;
02014             info.ctime = (time_t) -1;
02015             info.size = (off_t)-1;
02016             info.uSource = m_currentSrcURL;
02017             info.uDest = m_currentDest;
02018             // Append filename or dirname to destination URL, if allowed
02019             if ( destinationState == DEST_IS_DIR && !m_asMethod )
02020             {
02021                 if (
02022                     (m_currentSrcURL.protocol() == info.uDest.protocol()) &&
02023                     (m_currentSrcURL.host() == info.uDest.host()) &&
02024                     (m_currentSrcURL.port() == info.uDest.port()) &&
02025                     (m_currentSrcURL.user() == info.uDest.user()) &&
02026                     (m_currentSrcURL.pass() == info.uDest.pass()) )
02027                 {
02028                     // This is the case of creating a real symlink
02029                     info.uDest.addPath( m_currentSrcURL.fileName() );
02030                 }
02031                 else
02032                 {
02033                     // Different protocols, we'll create a .desktop file
02034                     // We have to change the extension anyway, so while we're at it,
02035                     // name the file like the URL
02036                     info.uDest.addPath( KIO::encodeFileName( m_currentSrcURL.prettyURL() )+".desktop" );
02037                 }
02038             }
02039             files.append( info ); // Files and any symlinks
02040             ++m_currentStatSrc;
02041             statNextSrc(); // we could use a loop instead of a recursive call :)
02042         }
02043         // If moving, before going for the full stat+[list+]copy+del thing, try to rename
02044         else if ( m_mode == Move &&
02045                   (m_currentSrcURL.protocol() == m_dest.protocol()) &&
02046                   (m_currentSrcURL.host() == m_dest.host()) &&
02047                   (m_currentSrcURL.port() == m_dest.port()) &&
02048                   (m_currentSrcURL.user() == m_dest.user()) &&
02049                   (m_currentSrcURL.pass() == m_dest.pass()) )
02050         {
02051             KURL dest = m_dest;
02052             // Append filename or dirname to destination URL, if allowed
02053             if ( destinationState == DEST_IS_DIR && !m_asMethod )
02054                 dest.addPath( m_currentSrcURL.fileName() );
02055             kdDebug(7007) << "This seems to be a suitable case for trying to rename before stat+[list+]copy+del" << endl;
02056             state = STATE_RENAMING;
02057             SimpleJob * newJob = KIO::rename( m_currentSrcURL, dest, false /*no overwrite */);
02058             Scheduler::scheduleJob(newJob);
02059             addSubjob( newJob );
02060             if ( m_currentSrcURL.directory() != dest.directory() ) // For the user, moving isn't renaming. Only renaming is.
02061                 m_bOnlyRenames = false;
02062         }
02063         else
02064         {
02065             // if the file system doesn't support deleting, we do not even stat
02066             if (m_mode == Move && !KProtocolInfo::supportsDeleting(m_currentSrcURL)) {
02067                 KMessageBox::information( 0, buildErrorString(ERR_CANNOT_DELETE, m_currentSrcURL.prettyURL()));
02068         ++m_currentStatSrc;
02069                 statNextSrc(); // we could use a loop instead of a recursive call :)
02070                 return;
02071             }
02072             // Stat the next src url
02073             Job * job = KIO::stat( m_currentSrcURL, true, 2, false );
02074             //kdDebug(7007) << "KIO::stat on " << (*it).prettyURL() << endl;
02075             state = STATE_STATING;
02076             addSubjob(job);
02077             m_currentDestURL=m_dest;
02078             m_bOnlyRenames = false;
02079         }
02080     } else
02081     {
02082         // Finished the stat'ing phase
02083         // First make sure that the totals were correctly emitted
02084         state = STATE_STATING;
02085         slotReport();
02086         // Check if we are copying a single file
02087         m_bSingleFileCopy = ( files.count() == 1 && dirs.isEmpty() );
02088         // Then start copying things
02089         state = STATE_CREATING_DIRS;
02090         createNextDir();
02091     }
02092 }
02093 
02094 
02095 void CopyJob::startListing( const KURL & src )
02096 {
02097     state = STATE_LISTING;
02098     ListJob * newjob = listRecursive( src, false );
02099     connect(newjob, SIGNAL(entries( KIO::Job *,
02100                                     const KIO::UDSEntryList& )),
02101             SLOT( slotEntries( KIO::Job*,
02102                                const KIO::UDSEntryList& )));
02103     addSubjob( newjob );
02104 }
02105 
02106 void CopyJob::skip( const KURL & sourceUrl )
02107 {
02108     // Check if this is one if toplevel sources
02109     // IF yes, remove it from m_srcList, for a correct FilesRemoved() signal
02110     //kdDebug(7007) << "CopyJob::skip: looking for " << sourceUrl.prettyURL() << endl;
02111     KURL::List::Iterator sit = m_srcList.find( sourceUrl );
02112     if ( sit != m_srcList.end() )
02113     {
02114         //kdDebug(7007) << "CopyJob::skip: removing " << sourceUrl.prettyURL() << " from list" << endl;
02115         m_srcList.remove( sit );
02116     }
02117     dirsToRemove.remove( sourceUrl );
02118 }
02119 
02120 void CopyJob::slotResultCreatingDirs( Job * job )
02121 {
02122     // The dir we are trying to create:
02123     QValueList<CopyInfo>::Iterator it = dirs.begin();
02124     // Was there an error creating a dir ?
02125     if ( job->error() )
02126     {
02127         m_conflictError = job->error();
02128         if ( (m_conflictError == ERR_DIR_ALREADY_EXIST)
02129              || (m_conflictError == ERR_FILE_ALREADY_EXIST) )
02130         {
02131             KURL oldURL = ((SimpleJob*)job)->url();
02132             // Should we skip automatically ?
02133             if ( m_bAutoSkip ) {
02134                 // We dont want to copy files in this directory, so we put it on the skip list
02135                 m_skipList.append( oldURL.path( 1 ) );
02136                 skip( oldURL );
02137                 dirs.remove( it ); // Move on to next dir
02138             } else if ( m_bOverwriteAll ) { // overwrite all => just skip
02139                 dirs.remove( it ); // Move on to next dir
02140             } else
02141             {
02142                 assert( ((SimpleJob*)job)->url().url() == (*it).uDest.url() );
02143                 subjobs.remove( job );
02144                 assert ( subjobs.isEmpty() ); // We should have only one job at a time ...
02145 
02146                 // We need to stat the existing dir, to get its last-modification time
02147                 KURL existingDest( (*it).uDest );
02148                 SimpleJob * newJob = KIO::stat( existingDest, false, 2, false );
02149     Scheduler::scheduleJob(newJob);
02150                 kdDebug(7007) << "KIO::stat for resolving conflict on " << existingDest.prettyURL() << endl;
02151                 state = STATE_CONFLICT_CREATING_DIRS;
02152                 addSubjob(newJob);
02153                 return; // Don't move to next dir yet !
02154             }
02155         }
02156         else
02157         {
02158             // Severe error, abort
02159             Job::slotResult( job ); // will set the error and emit result(this)
02160             return;
02161         }
02162     }
02163     else // no error : remove from list, to move on to next dir
02164     {
02165        //this is required for the undo feature
02166         emit copyingDone( this, (*it).uSource, (*it).uDest, true, false );
02167         dirs.remove( it );
02168     }
02169 
02170     m_processedDirs++;
02171     //emit processedDirs( this, m_processedDirs );
02172     subjobs.remove( job );
02173     assert ( subjobs.isEmpty() ); // We should have only one job at a time ...
02174     createNextDir();
02175 }
02176 
02177 void CopyJob::slotResultConflictCreatingDirs( KIO::Job * job )
02178 {
02179     // We come here after a conflict has been detected and we've stated the existing dir
02180 
02181     // The dir we were trying to create:
02182     QValueList<CopyInfo>::Iterator it = dirs.begin();
02183     // Its modification time:
02184     time_t destmtime = (time_t)-1;
02185     time_t destctime = (time_t)-1;
02186     KIO::filesize_t destsize = 0;
02187     UDSEntry entry = ((KIO::StatJob*)job)->statResult();
02188     KIO::UDSEntry::ConstIterator it2 = entry.begin();
02189     for( ; it2 != entry.end(); it2++ ) {
02190         switch ((*it2).m_uds) {
02191             case UDS_MODIFICATION_TIME:
02192                 destmtime = (time_t)((*it2).m_long);
02193                 break;
02194             case UDS_CREATION_TIME:
02195                 destctime = (time_t)((*it2).m_long);
02196                 break;
02197             case UDS_SIZE:
02198                 destsize = (*it2).m_long;
02199                 break;
02200         }
02201     }
02202     subjobs.remove( job );
02203     assert ( subjobs.isEmpty() ); // We should have only one job at a time ...
02204 
02205     // Always multi and skip (since there are files after that)
02206     RenameDlg_Mode mode = (RenameDlg_Mode)( M_MULTI | M_SKIP );
02207     // Overwrite only if the existing thing is a dir (no chance with a file)
02208     if ( m_conflictError == ERR_DIR_ALREADY_EXIST )
02209         mode = (RenameDlg_Mode)( mode | M_OVERWRITE );
02210 
02211     QString existingDest = (*it).uDest.path();
02212     QString newPath;
02213     if (m_reportTimer)
02214         m_reportTimer->stop();
02215     RenameDlg_Result r = Observer::self()->open_RenameDlg( this, i18n("Directory Already Exists"),
02216                                          (*it).uSource.prettyURL(0, KURL::StripFileProtocol),
02217                                          (*it).uDest.prettyURL(0, KURL::StripFileProtocol),
02218                                          mode, newPath,
02219                                          (*it).size, destsize,
02220                                          (*it).ctime, destctime,
02221                                          (*it).mtime, destmtime );
02222     if (m_reportTimer)
02223         m_reportTimer->start(REPORT_TIMEOUT,false);
02224     switch ( r ) {
02225         case R_CANCEL:
02226             m_error = ERR_USER_CANCELED;
02227             emitResult();
02228             return;
02229         case R_RENAME:
02230         {
02231             QString oldPath = (*it).uDest.path( 1 );
02232             KURL newUrl( (*it).uDest );
02233             newUrl.setPath( newPath );
02234             emit renamed( this, (*it).uDest, newUrl ); // for e.g. kpropsdlg
02235 
02236             // Change the current one and strip the trailing '/'
02237             (*it).uDest = newUrl.path( -1 );
02238             newPath = newUrl.path( 1 ); // With trailing slash
02239             QValueList<CopyInfo>::Iterator renamedirit = it;
02240             renamedirit++;
02241             // Change the name of subdirectories inside the directory
02242             for( ; renamedirit != dirs.end() ; ++renamedirit )
02243             {
02244                 QString path = (*renamedirit).uDest.path();
02245                 if ( path.left(oldPath.length()) == oldPath )
02246                     (*renamedirit).uDest.setPath( path.replace( 0, oldPath.length(), newPath ) );
02247             }
02248             // Change filenames inside the directory
02249             QValueList<CopyInfo>::Iterator renamefileit = files.begin();
02250             for( ; renamefileit != files.end() ; ++renamefileit )
02251             {
02252                 QString path = (*renamefileit).uDest.path();
02253                 if ( path.left(oldPath.length()) == oldPath )
02254                     (*renamefileit).uDest.setPath( path.replace( 0, oldPath.length(), newPath ) );
02255             }
02256         }
02257         break;
02258         case R_AUTO_SKIP:
02259             m_bAutoSkip = true;
02260             // fall through
02261         case R_SKIP:
02262             m_skipList.append( existingDest );
02263             skip( (*it).uSource );
02264             // Move on to next dir
02265             dirs.remove( it );
02266             break;
02267         case R_OVERWRITE:
02268             m_overwriteList.append( existingDest );
02269             // Move on to next dir
02270             dirs.remove( it );
02271             break;
02272         case R_OVERWRITE_ALL:
02273             m_bOverwriteAll = true;
02274             // Move on to next dir
02275             dirs.remove( it );
02276             break;
02277         default:
02278             assert( 0 );
02279     }
02280     state = STATE_CREATING_DIRS;
02281     m_processedDirs++;
02282     //emit processedDirs( this, m_processedDirs );
02283     createNextDir();
02284 }
02285 
02286 void CopyJob::createNextDir()
02287 {
02288     KURL udir;
02289     if ( !dirs.isEmpty() )
02290     {
02291         // Take first dir to create out of list
02292         QValueList<CopyInfo>::Iterator it = dirs.begin();
02293         // Is this URL on the skip list or the overwrite list ?
02294         while( it != dirs.end() && udir.isEmpty() )
02295         {
02296             QString dir = (*it).uDest.path();
02297             bool bCreateDir = true; // we'll create it if it's not in any list
02298 
02299             QStringList::Iterator sit = m_skipList.begin();
02300             for( ; sit != m_skipList.end() && bCreateDir; sit++ )
02301                 // Is dir a subdirectory of *sit ?
02302                 if ( *sit == dir.left( (*sit).length() ) )
02303                     bCreateDir = false; // skip this dir
02304 
02305             if ( !bCreateDir ) {
02306                 dirs.remove( it );
02307                 it = dirs.begin();
02308             } else
02309                 udir = (*it).uDest;
02310         }
02311     }
02312     if ( !udir.isEmpty() ) // any dir to create, finally ?
02313     {
02314         // Create the directory - with default permissions so that we can put files into it
02315         // TODO : change permissions once all is finished
02316         KIO::SimpleJob *newjob = KIO::mkdir( udir, -1 );
02317         Scheduler::scheduleJob(newjob);
02318 
02319         m_currentDestURL = udir;
02320 
02321         addSubjob(newjob);
02322         return;
02323     }
02324     else // we have finished creating dirs
02325     {
02326         state = STATE_COPYING_FILES;
02327         m_processedFiles++; // Ralf wants it to start a 1, not 0
02328         copyNextFile();
02329     }
02330 }
02331 
02332 void CopyJob::slotResultCopyingFiles( Job * job )
02333 {
02334     // The file we were trying to copy:
02335     QValueList<CopyInfo>::Iterator it = files.begin();
02336     if ( job->error() )
02337     {
02338         // Should we skip automatically ?
02339         if ( m_bAutoSkip )
02340         {
02341             skip( (*it).uSource );
02342             files.remove( it ); // Move on to next file
02343         }
02344         else
02345         {
02346             m_conflictError = job->error(); // save for later
02347             // Existing dest ?
02348             if ( ( m_conflictError == ERR_FILE_ALREADY_EXIST )
02349                  || ( m_conflictError == ERR_DIR_ALREADY_EXIST ) )
02350             {
02351                 subjobs.remove( job );
02352                 assert ( subjobs.isEmpty() );
02353                 // We need to stat the existing file, to get its last-modification time
02354                 KURL existingFile( (*it).uDest );
02355                 SimpleJob * newJob = KIO::stat( existingFile, false, 2, false );
02356                 Scheduler::scheduleJob(newJob);
02357                 kdDebug(7007) << "KIO::stat for resolving conflict on " << existingFile.prettyURL() << endl;
02358                 state = STATE_CONFLICT_COPYING_FILES;
02359                 addSubjob(newJob);
02360                 return; // Don't move to next file yet !
02361             }
02362             else
02363             {
02364                 if ( m_bCurrentOperationIsLink && job->inherits( "KIO::DeleteJob" ) )
02365                 {
02366                     // Very special case, see a few lines below
02367                     // We are deleting the source of a symlink we successfully moved... ignore error
02368                     files.remove( it );
02369                 } else {
02370                     // Go directly to the conflict resolution, there is nothing to stat
02371                     slotResultConflictCopyingFiles( job );
02372                     return;
02373                 }
02374             }
02375         }
02376     } else // no error
02377     {
02378         // Special case for moving links. That operation needs two jobs, unlike others.
02379         if ( m_bCurrentOperationIsLink && m_mode == Move
02380              && !job->inherits( "KIO::DeleteJob" ) // Deleting source not already done
02381              )
02382         {
02383             subjobs.remove( job );
02384             assert ( subjobs.isEmpty() );
02385             // The only problem with this trick is that the error handling for this del operation
02386             // is not going to be right... see 'Very special case' above.
02387             KIO::Job * newjob = KIO::del( (*it).uSource, false /*don't shred*/, false /*no GUI*/ );
02388             addSubjob( newjob );
02389             return; // Don't move to next file yet !
02390         }
02391 
02392         if ( m_bCurrentOperationIsLink )
02393         {
02394             QString target = ( m_mode == Link ? (*it).uSource.path() : (*it).linkDest );
02395             //required for the undo feature
02396             emit copyingLinkDone( this, (*it).uSource, target, (*it).uDest );
02397         }
02398         else
02399             //required for the undo feature
02400             emit copyingDone( this, (*it).uSource, (*it).uDest, false, false );
02401         // remove from list, to move on to next file
02402         files.remove( it );
02403     }
02404     m_processedFiles++;
02405 
02406     // clear processed size for last file and add it to overall processed size
02407     m_processedSize += m_fileProcessedSize;
02408     m_fileProcessedSize = 0;
02409 
02410     //kdDebug(7007) << files.count() << " files remaining" << endl;
02411     subjobs.remove( job );
02412     assert ( subjobs.isEmpty() ); // We should have only one job at a time ...
02413     copyNextFile();
02414 }
02415 
02416 void CopyJob::slotResultConflictCopyingFiles( KIO::Job * job )
02417 {
02418     // We come here after a conflict has been detected and we've stated the existing file
02419     // The file we were trying to create:
02420     QValueList<CopyInfo>::Iterator it = files.begin();
02421 
02422     RenameDlg_Result res;
02423     QString newPath;
02424 
02425     if (m_reportTimer)
02426         m_reportTimer->stop();
02427 
02428     if ( ( m_conflictError == ERR_FILE_ALREADY_EXIST )
02429       || ( m_conflictError == ERR_DIR_ALREADY_EXIST ) )
02430     {
02431         // Its modification time:
02432         time_t destmtime = (time_t)-1;
02433         time_t destctime = (time_t)-1;
02434         KIO::filesize_t destsize = 0;
02435         UDSEntry entry = ((KIO::StatJob*)job)->statResult();
02436         KIO::UDSEntry::ConstIterator it2 = entry.begin();
02437         for( ; it2 != entry.end(); it2++ ) {
02438             switch ((*it2).m_uds) {
02439                 case UDS_MODIFICATION_TIME:
02440                     destmtime = (time_t)((*it2).m_long);
02441                     break;
02442                 case UDS_CREATION_TIME:
02443                     destctime = (time_t)((*it2).m_long);
02444                     break;
02445                 case UDS_SIZE:
02446                     destsize = (*it2).m_long;
02447                     break;
02448             }
02449         }
02450 
02451         // Offer overwrite only if the existing thing is a file
02452         // If src==dest, use "overwrite-itself"
02453         RenameDlg_Mode mode = (RenameDlg_Mode)
02454             ( ( m_conflictError == ERR_DIR_ALREADY_EXIST ? 0 :
02455              ( (*it).uSource == (*it).uDest ) ? M_OVERWRITE_ITSELF : M_OVERWRITE ) );
02456         if ( files.count() > 0 ) // Not last one
02457             mode = (RenameDlg_Mode) ( mode | M_MULTI | M_SKIP );
02458         else
02459             mode = (RenameDlg_Mode) ( mode | M_SINGLE );
02460         res = Observer::self()->open_RenameDlg( this, m_conflictError == ERR_FILE_ALREADY_EXIST ?
02461                                 i18n("File Already Exists") : i18n("Already Exists as a Directory"),
02462                                 (*it).uSource.prettyURL(0, KURL::StripFileProtocol),
02463                                 (*it).uDest.prettyURL(0, KURL::StripFileProtocol),
02464                                 mode, newPath,
02465                               (*it).size, destsize,
02466                               (*it).ctime, destctime,
02467                               (*it).mtime, destmtime );
02468 
02469     }
02470     else
02471     {
02472         if ( job->error() == ERR_USER_CANCELED )
02473             res = R_CANCEL;
02474         else
02475         {
02476             SkipDlg_Result skipResult = Observer::self()->open_SkipDlg( this, files.count() > 0,
02477                                                                         job->errorString() );
02478 
02479             // Convert the return code from SkipDlg into a RenameDlg code
02480             res = ( skipResult == S_SKIP ) ? R_SKIP :
02481                          ( skipResult == S_AUTO_SKIP ) ? R_AUTO_SKIP :
02482                                         R_CANCEL;
02483         }
02484     }
02485 
02486     if (m_reportTimer)
02487         m_reportTimer->start(REPORT_TIMEOUT,false);
02488 
02489     subjobs.remove( job );
02490     assert ( subjobs.isEmpty() );
02491     switch ( res ) {
02492         case R_CANCEL:
02493             m_error = ERR_USER_CANCELED;
02494             emitResult();
02495             return;
02496         case R_RENAME:
02497         {
02498             KURL newUrl( (*it).uDest );
02499             newUrl.setPath( newPath );
02500             emit renamed( this, (*it).uDest, newUrl ); // for e.g. kpropsdlg
02501             (*it).uDest = newUrl;
02502         }
02503         break;
02504         case R_AUTO_SKIP:
02505             m_bAutoSkip = true;
02506             // fall through
02507         case R_SKIP:
02508             // Move on to next file
02509             skip( (*it).uSource );
02510             files.remove( it );
02511             break;
02512        case R_OVERWRITE_ALL:
02513             m_bOverwriteAll = true;
02514             break;
02515         case R_OVERWRITE:
02516             // Add to overwrite list, so that copyNextFile knows to overwrite
02517             m_overwriteList.append( (*it).uDest.path() );
02518             break;
02519         default:
02520             assert( 0 );
02521     }
02522     state = STATE_COPYING_FILES;
02523     m_processedFiles++;
02524     //emit processedFiles( this, m_processedFiles );
02525     copyNextFile();
02526 }
02527 
02528 void CopyJob::copyNextFile()
02529 {
02530     bool bCopyFile = false;
02531     //kdDebug(7007) << "CopyJob::copyNextFile()" << endl;
02532     // Take the first file in the list
02533     QValueList<CopyInfo>::Iterator it = files.begin();
02534     // Is this URL on the skip list ?
02535     while (it != files.end() && !bCopyFile)
02536     {
02537         bCopyFile = true;
02538         QString destFile = (*it).uDest.path();
02539 
02540         QStringList::Iterator sit = m_skipList.begin();
02541         for( ; sit != m_skipList.end() && bCopyFile; sit++ )
02542             // Is destFile in *sit (or a subdirectory of *sit) ?
02543             if ( *sit == destFile.left( (*sit).length() ) )
02544                 bCopyFile = false; // skip this file
02545 
02546         if (!bCopyFile) {
02547             files.remove( it );
02548             it = files.begin();
02549         }
02550     }
02551 
02552     if (bCopyFile) // any file to create, finally ?
02553     {
02554         // Do we set overwrite ?
02555         bool bOverwrite = m_bOverwriteAll; // yes if overwrite all
02556         QString destFile = (*it).uDest.path();
02557         if ( (*it).uDest == (*it).uSource )
02558             bOverwrite = false;
02559         else
02560         {
02561             // or if on the overwrite list
02562             QStringList::Iterator sit = m_overwriteList.begin();
02563             for( ; sit != m_overwriteList.end() && !bOverwrite; sit++ )
02564                 if ( *sit == destFile.left( (*sit).length() ) )
02565                     bOverwrite = true;
02566         }
02567 
02568         m_bCurrentOperationIsLink = false;
02569         KIO::Job * newjob = 0L;
02570         if ( m_mode == Link )
02571         {
02572             //kdDebug(7007) << "Linking" << endl;
02573             if (
02574                 ((*it).uSource.protocol() == (*it).uDest.protocol()) &&
02575                 ((*it).uSource.host() == (*it).uDest.host()) &&
02576                 ((*it).uSource.port() == (*it).uDest.port()) &&
02577                 ((*it).uSource.user() == (*it).uDest.user()) &&
02578                 ((*it).uSource.pass() == (*it).uDest.pass()) )
02579             {
02580                 // This is the case of creating a real symlink
02581                 KIO::SimpleJob *newJob = KIO::symlink( (*it).uSource.path(), (*it).uDest, bOverwrite, false /*no GUI*/ );
02582                 newjob = newJob;
02583                 Scheduler::scheduleJob(newJob);
02584                 kdDebug(7007) << "CopyJob::copyNextFile : Linking target=" << (*it).uSource.path() << " link=" << (*it).uDest.prettyURL() << endl;
02585                 //emit linking( this, (*it).uSource.path(), (*it).uDest );
02586                 m_bCurrentOperationIsLink = true;
02587                 m_currentSrcURL=(*it).uSource;
02588                 m_currentDestURL=(*it).uDest;
02589                 //Observer::self()->slotCopying( this, (*it).uSource, (*it).uDest ); // should be slotLinking perhaps
02590             } else {
02591                 kdDebug(7007) << "CopyJob::copyNextFile : Linking URL=" << (*it).uSource.prettyURL() << " link=" << (*it).uDest.prettyURL() << endl;
02592                 if ( (*it).uDest.isLocalFile() )
02593                 {
02594                     bool devicesOk=false;
02595 
02596                     // if the source is a devices url, handle it a littlebit special
02597                     if ((*it).uSource.protocol()==QString::fromLatin1("devices"))
02598                     {
02599                        QByteArray data;
02600                        QByteArray param;
02601                        QCString retType;
02602                        QDataStream streamout(param,IO_WriteOnly);
02603                        streamout<<(*it).uSource;
02604                        streamout<<(*it).uDest;
02605                        if ( kapp->dcopClient()->call( "kded",
02606                             "mountwatcher", "createLink(KURL, KURL)", param,retType,data,false ) )
02607                        {
02608                           QDataStream streamin(data,IO_ReadOnly);
02609                           streamin>>devicesOk;
02610                        }
02611                        if (devicesOk)
02612                        {
02613                            files.remove( it );
02614                            m_processedFiles++;
02615                            //emit processedFiles( this, m_processedFiles );
02616                            copyNextFile();
02617                            return;
02618                        }
02619                     }
02620 
02621                     if (!devicesOk)
02622                     {
02623                        QString path = (*it).uDest.path();
02624                        kdDebug(7007) << "CopyJob::copyNextFile path=" << path << endl;
02625                        QFile f( path );
02626                        if ( f.open( IO_ReadWrite ) )
02627                        {
02628                            f.close();
02629                            KSimpleConfig config( path );
02630                            config.setDesktopGroup();
02631                            KURL url = (*it).uSource;
02632                            url.setPass( "" );
02633                            config.writeEntry( QString::fromLatin1("URL"), url.url() );
02634                            config.writeEntry( QString::fromLatin1("Type"), QString::fromLatin1("Link") );
02635                            QString protocol = (*it).uSource.protocol();
02636                            if ( protocol == QString::fromLatin1("ftp") )
02637                                config.writeEntry( QString::fromLatin1("Icon"), QString::fromLatin1("ftp") );
02638                            else if ( protocol == QString::fromLatin1("http") )
02639                                config.writeEntry( QString::fromLatin1("Icon"), QString::fromLatin1("www") );
02640                            else if ( protocol == QString::fromLatin1("info") )
02641                                config.writeEntry( QString::fromLatin1("Icon"), QString::fromLatin1("info") );
02642                            else if ( protocol == QString::fromLatin1("mailto") )   // sven:
02643                                config.writeEntry( QString::fromLatin1("Icon"), QString::fromLatin1("kmail") ); // added mailto: support
02644                            else
02645                                config.writeEntry( QString::fromLatin1("Icon"), QString::fromLatin1("unknown") );
02646                            config.sync();
02647                            files.remove( it );
02648                            m_processedFiles++;
02649                            //emit processedFiles( this, m_processedFiles );
02650                            copyNextFile();
02651                            return;
02652                        }
02653                        else
02654                        {
02655                            kdDebug(7007) << "CopyJob::copyNextFile ERR_CANNOT_OPEN_FOR_WRITING" << endl;
02656                            m_error = ERR_CANNOT_OPEN_FOR_WRITING;
02657                            m_errorText = (*it).uDest.path();
02658                            emitResult();
02659                            return;
02660                        }
02661                     }
02662                 } else {
02663                     // Todo: not show "link" on remote dirs if the src urls are not from the same protocol+host+...
02664                     m_error = ERR_CANNOT_SYMLINK;
02665                     m_errorText = (*it).uDest.prettyURL();
02666                     emitResult();
02667                     return;
02668                 }
02669             }
02670         }
02671         else if ( !(*it).linkDest.isEmpty() &&
02672                   ((*it).uSource.protocol() == (*it).uDest.protocol()) &&
02673                   ((*it).uSource.host() == (*it).uDest.host()) &&
02674                   ((*it).uSource.port() == (*it).uDest.port()) &&
02675                   ((*it).uSource.user() == (*it).uDest.user()) &&
02676                   ((*it).uSource.pass() == (*it).uDest.pass()))
02677             // Copying a symlink - only on the same protocol/host/etc. (#5601, downloading an FTP file through its link),
02678         {
02679             KIO::SimpleJob *newJob = KIO::symlink( (*it).linkDest, (*it).uDest, bOverwrite, false /*no GUI*/ );
02680             Scheduler::scheduleJob(newJob);
02681             newjob = newJob;
02682             kdDebug(7007) << "CopyJob::copyNextFile : Linking target=" << (*it).linkDest << " link=" << (*it).uDest.prettyURL() << endl;
02683             //emit linking( this, (*it).linkDest, (*it).uDest );
02684             m_currentSrcURL=(*it).linkDest;
02685             m_currentDestURL=(*it).uDest;
02686             //Observer::self()->slotCopying( this, (*it).linkDest, (*it).uDest ); // should be slotLinking perhaps
02687             m_bCurrentOperationIsLink = true;
02688             // NOTE: if we are moving stuff, the deletion of the source will be done in slotResultCopyingFiles
02689         } else if (m_mode == Move) // Moving a file
02690         {
02691             KIO::FileCopyJob * moveJob = KIO::file_move( (*it).uSource, (*it).uDest, (*it).permissions, bOverwrite, false, false/*no GUI*/ );
02692             moveJob->setSourceSize( (*it).size );
02693             newjob = moveJob;
02694             //kdDebug(7007) << "CopyJob::copyNextFile : Moving " << (*it).uSource.prettyURL() << " to " << (*it).uDest.prettyURL() << endl;
02695             //emit moving( this, (*it).uSource, (*it).uDest );
02696             m_currentSrcURL=(*it).uSource;
02697             m_currentDestURL=(*it).uDest;
02698             //Observer::self()->slotMoving( this, (*it).uSource, (*it).uDest );
02699         }
02700         else // Copying a file
02701         {
02702             // If source isn't local and target is local, we ignore the original permissions
02703             // Otherwise, files downloaded from HTTP end up with -r--r--r--
02704             // But for files coming from TAR, we want to preserve permissions -> we use default perms only if from remote
02705             // The real fix would be KProtocolInfo::inputType(protocol) == T_FILESYSTEM, but we can't access ksycoca from here !
02706             bool remoteSource = !(*it).uSource.isLocalFile() && ((*it).uSource.protocol() != "tar"); // HACK
02707             int permissions = ( remoteSource && (*it).uDest.isLocalFile() ) ? -1 : (*it).permissions;
02708             KIO::FileCopyJob * copyJob = KIO::file_copy( (*it).uSource, (*it).uDest, permissions, bOverwrite, false, false/*no GUI*/ );
02709             copyJob->setParentJob( this ); // in case of rename dialog
02710             copyJob->setSourceSize( (*it).size );
02711             newjob = copyJob;
02712             //kdDebug(7007) << "CopyJob::copyNextFile : Copying " << (*it).uSource.prettyURL() << " to " << (*it).uDest.prettyURL() << endl;
02713             m_currentSrcURL=(*it).uSource;
02714             m_currentDestURL=(*it).uDest;
02715         }
02716         addSubjob(newjob);
02717         connect( newjob, SIGNAL( processedSize( KIO::Job*, KIO::filesize_t ) ),
02718                  this, SLOT( slotProcessedSize( KIO::Job*, KIO::filesize_t ) ) );
02719         connect( newjob, SIGNAL( totalSize( KIO::Job*, KIO::filesize_t ) ),
02720                  this, SLOT( slotTotalSize( KIO::Job*, KIO::filesize_t ) ) );
02721     }
02722     else
02723     {
02724         // We're done
02725         //kdDebug(7007) << "copyNextFile finished" << endl;
02726         deleteNextDir();
02727     }
02728 }
02729 
02730 void CopyJob::deleteNextDir()
02731 {
02732     if ( m_mode == Move && !dirsToRemove.isEmpty() ) // some dirs to delete ?
02733     {
02734         state = STATE_DELETING_DIRS;
02735         // Take first dir to delete out of list - last ones first !
02736         KURL::List::Iterator it = dirsToRemove.fromLast();
02737         SimpleJob *job = KIO::rmdir( *it );
02738         Scheduler::scheduleJob(job);
02739         dirsToRemove.remove(it);
02740         addSubjob( job );
02741     }
02742     else
02743     {
02744         // Finished - tell the world
02745         if ( !m_bOnlyRenames )
02746         {
02747             KDirNotify_stub allDirNotify("*", "KDirNotify*");
02748             KURL url( m_dest );
02749             if ( destinationState != DEST_IS_DIR || m_asMethod )
02750                 url.setPath( url.directory() );
02751             //kdDebug(7007) << "KDirNotify'ing FilesAdded " << url.prettyURL() << endl;
02752             allDirNotify.FilesAdded( url );
02753 
02754             if ( m_mode == Move && !m_srcList.isEmpty() )
02755                 allDirNotify.FilesRemoved( m_srcList );
02756         }
02757         if (m_reportTimer!=0)
02758             m_reportTimer->stop();
02759         emitResult();
02760     }
02761 }
02762 
02763 void CopyJob::slotProcessedSize( KIO::Job*, KIO::filesize_t data_size )
02764 {
02765   //kdDebug(7007) << "CopyJob::slotProcessedSize " << (unsigned long)data_size << endl;
02766   m_fileProcessedSize = data_size;
02767 
02768   if ( m_processedSize + m_fileProcessedSize > m_totalSize )
02769   {
02770     m_totalSize = m_processedSize + m_fileProcessedSize;
02771     //kdDebug(7007) << "Adjusting m_totalSize to " << (unsigned long) m_totalSize << endl;
02772     emit totalSize( this, m_totalSize ); // safety
02773   }
02774   //kdDebug(7007) << "emit processedSize " << (unsigned long) (m_processedSize + m_fileProcessedSize) << endl;
02775   emit processedSize( this, m_processedSize + m_fileProcessedSize );
02776   emitPercent( m_processedSize + m_fileProcessedSize, m_totalSize );
02777 }
02778 
02779 void CopyJob::slotTotalSize( KIO::Job*, KIO::filesize_t size )
02780 {
02781   // Special case for copying a single file
02782   // This is because some protocols don't implement stat properly
02783   // (e.g. HTTP), and don't give us a size in some cases (redirection)
02784   // so we'd rather rely on the size given for the transfer
02785   if ( m_bSingleFileCopy )
02786   {
02787     //kdDebug(7007) << "Single file -> updating totalsize to " << (long)size << endl;
02788     m_totalSize = size;
02789     emit totalSize( this, size );
02790   }
02791 }
02792 
02793 void CopyJob::slotResultDeletingDirs( Job * job )
02794 {
02795     if (job->error())
02796     {
02797         // Couldn't remove directory. Well, perhaps it's not empty
02798         // because the user pressed Skip for a given file in it.
02799         // Let's not display "Could not remove dir ..." for each of those dir !
02800     }
02801     subjobs.remove( job );
02802     assert ( subjobs.isEmpty() );
02803     deleteNextDir();
02804 }
02805 
02806 void CopyJob::slotResult( Job *job )
02807 {
02808     //kdDebug(7007) << "CopyJob::slotResult() state=" << (int) state << endl;
02809     // In each case, what we have to do is :
02810     // 1 - check for errors and treat them
02811     // 2 - subjobs.remove(job);
02812     // 3 - decide what to do next
02813 
02814     switch ( state ) {
02815         case STATE_STATING: // We were trying to stat a src url or the dest
02816             slotResultStating( job );
02817             break;
02818         case STATE_RENAMING: // We were trying to do a direct renaming, before even stat'ing
02819         {
02820             int err = job->error();
02821             subjobs.remove( job );
02822             assert ( subjobs.isEmpty() );
02823             // Determine dest again
02824             KURL dest = m_dest;
02825             if ( destinationState == DEST_IS_DIR && !m_asMethod )
02826                 dest.addPath( m_currentSrcURL.fileName() );
02827             if ( err )
02828             {
02829                 // Direct renaming didn't work. Try renaming to a temp name,
02830                 // this can help e.g. when renaming 'a' to 'A' on a VFAT partition.
02831                 // In that case it's the _same_ dir, we don't want to copy+del (data loss!)
02832                 if ( m_currentSrcURL.isLocalFile() &&
02833                      m_currentSrcURL.url(-1).lower() == dest.url(-1).lower() &&
02834                      ( job->error() == ERR_FILE_ALREADY_EXIST || job->error() == ERR_DIR_ALREADY_EXIST ) )
02835                 {
02836                     kdDebug(7007) << "Couldn't rename directly, dest already exists. Detected special case of lower/uppercase renaming in same dir, try with 2 rename calls" << endl;
02837                     QCString _src( QFile::encodeName(m_currentSrcURL.path()) );
02838                     QCString _dest( QFile::encodeName(dest.path()) );
02839                     KTempFile tmpFile( m_currentSrcURL.directory() );
02840                     QCString _tmp( QFile::encodeName(tmpFile.name()) );
02841                     kdDebug() << "CopyJob::slotResult KTempFile status:" << tmpFile.status() << " using " << _tmp << " as intermediary" << endl;
02842                     tmpFile.unlink();
02843                     if ( ::rename( _src, _tmp ) == 0 )
02844                     {
02845                         if ( ::rename( _tmp, _dest ) == 0 )
02846                         {
02847                             kdDebug(7007) << "Success." << endl;
02848                             err = 0;
02849                         }
02850                         else
02851                         {
02852                             // Revert back to original name!
02853                             bool b = ::rename( QFile::encodeName(tmpFile.name()), _src );
02854                             if (!b) {
02855                                 kdError(7007) << "Couldn't rename " << tmpFile.name() << " back to " << _src << " !" << endl;
02856                                 // Severe error, abort
02857                                 Job::slotResult( job ); // will set the error and emit result(this)
02858                                 return;
02859                             }
02860                         }
02861                     }
02862                 }
02863             }
02864             if ( err )
02865             {
02866                 m_currentSrcURL=*m_currentStatSrc;
02867                 m_currentDestURL=m_dest;
02868                 kdDebug(7007) << "Couldn't rename, reverting to normal way, starting with stat" << endl;
02869                 Job * job = KIO::stat( m_currentSrcURL, true, 2, false );
02870                 //kdDebug(7007) << "KIO::stat on " << (*it).prettyURL() << endl;
02871                 state = STATE_STATING;
02872                 addSubjob(job);
02873                 m_bOnlyRenames = false;
02874             }
02875             else
02876             {
02877                 kdDebug(7007) << "Renaming succeeded, move on" << endl;
02878                 emit copyingDone( this, *m_currentStatSrc, dest, true, true );
02879                 ++m_currentStatSrc;
02880                 statNextSrc();
02881             }
02882         }
02883         break;
02884         case STATE_LISTING: // recursive listing finished
02885             //kdDebug(7007) << "totalSize: " << (unsigned int) m_totalSize << " files: " << files.count() << " dirs: " << dirs.count() << endl;
02886             // Was there an error ?
02887             if (job->error())
02888             {
02889                 Job::slotResult( job ); // will set the error and emit result(this)
02890                 return;
02891             }
02892 
02893             subjobs.remove( job );
02894             assert ( subjobs.isEmpty() );
02895 
02896             ++m_currentStatSrc;
02897             statNextSrc();
02898             break;
02899         case STATE_CREATING_DIRS:
02900             slotResultCreatingDirs( job );
02901             break;
02902         case STATE_CONFLICT_CREATING_DIRS:
02903             slotResultConflictCreatingDirs( job );
02904             break;
02905         case STATE_COPYING_FILES:
02906             slotResultCopyingFiles( job );
02907             break;
02908         case STATE_CONFLICT_COPYING_FILES:
02909             slotResultConflictCopyingFiles( job );
02910             break;
02911         case STATE_DELETING_DIRS:
02912             slotResultDeletingDirs( job );
02913             break;
02914         default:
02915             assert( 0 );
02916     }
02917 }
02918 
02919 CopyJob *KIO::copy(const KURL& src, const KURL& dest, bool showProgressInfo )
02920 {
02921     //kdDebug() << "KIO::copy src=" << src.url() << " dest=" << dest.url() << endl;
02922     KURL::List srcList;
02923     srcList.append( src );
02924     return new CopyJob( srcList, dest, CopyJob::Copy, false, showProgressInfo );
02925 }
02926 
02927 CopyJob *KIO::copyAs(const KURL& src, const KURL& dest, bool showProgressInfo )
02928 {
02929     //kdDebug() << "KIO::copyAs src=" << src.url() << " dest=" << dest.url() << endl;
02930     KURL::List srcList;
02931     srcList.append( src );
02932     return new CopyJob( srcList, dest, CopyJob::Copy, true, showProgressInfo );
02933 }
02934 
02935 CopyJob *KIO::copy( const KURL::List& src, const KURL& dest, bool showProgressInfo )
02936 {
02937     return new CopyJob( src, dest, CopyJob::Copy, false, showProgressInfo );
02938 }
02939 
02940 CopyJob *KIO::move(const KURL& src, const KURL& dest, bool showProgressInfo )
02941 {
02942     KURL::List srcList;
02943     srcList.append( src );
02944     return new CopyJob( srcList, dest, CopyJob::Move, false, showProgressInfo );
02945 }
02946 
02947 CopyJob *KIO::moveAs(const KURL& src, const KURL& dest, bool showProgressInfo )
02948 {
02949     KURL::List srcList;
02950     srcList.append( src );
02951     return new CopyJob( srcList, dest, CopyJob::Move, true, showProgressInfo );
02952 }
02953 
02954 CopyJob *KIO::move( const KURL::List& src, const KURL& dest, bool showProgressInfo )
02955 {
02956     return new CopyJob( src, dest, CopyJob::Move, false, showProgressInfo );
02957 }
02958 
02959 CopyJob *KIO::link(const KURL& src, const KURL& destDir, bool showProgressInfo )
02960 {
02961     KURL::List srcList;
02962     srcList.append( src );
02963     return new CopyJob( srcList, destDir, CopyJob::Link, false, showProgressInfo );
02964 }
02965 
02966 CopyJob *KIO::link(const KURL::List& srcList, const KURL& destDir, bool showProgressInfo )
02967 {
02968     return new CopyJob( srcList, destDir, CopyJob::Link, false, showProgressInfo );
02969 }
02970 
02971 CopyJob *KIO::linkAs(const KURL& src, const KURL& destDir, bool showProgressInfo )
02972 {
02973     KURL::List srcList;
02974     srcList.append( src );
02975     return new CopyJob( srcList, destDir, CopyJob::Link, false, showProgressInfo );
02976 }
02977 
02979 
02980 DeleteJob::DeleteJob( const KURL::List& src, bool shred, bool showProgressInfo )
02981 : Job(showProgressInfo), m_totalSize( 0 ), m_processedSize( 0 ), m_fileProcessedSize( 0 ),
02982   m_processedFiles( 0 ), m_processedDirs( 0 ), m_totalFilesDirs( 0 ),
02983   m_srcList(src), m_currentStat(m_srcList.begin()), m_shred(shred), m_reportTimer(0)
02984 {
02985   if ( showProgressInfo ) {
02986 
02987      connect( this, SIGNAL( totalFiles( KIO::Job*, unsigned long ) ),
02988               Observer::self(), SLOT( slotTotalFiles( KIO::Job*, unsigned long ) ) );
02989 
02990      connect( this, SIGNAL( totalDirs( KIO::Job*, unsigned long ) ),
02991               Observer::self(), SLOT( slotTotalDirs( KIO::Job*, unsigned long ) ) );
02992 
02993      // See slotReport
02994      /*connect( this, SIGNAL( processedFiles( KIO::Job*, unsigned long ) ),
02995       m_observer, SLOT( slotProcessedFiles( KIO::Job*, unsigned long ) ) );
02996 
02997       connect( this, SIGNAL( processedDirs( KIO::Job*, unsigned long ) ),
02998       m_observer, SLOT( slotProcessedDirs( KIO::Job*, unsigned long ) ) );
02999 
03000       connect( this, SIGNAL( deleting( KIO::Job*, const KURL& ) ),
03001       m_observer, SLOT( slotDeleting( KIO::Job*, const KURL& ) ) );*/
03002 
03003      m_reportTimer=new QTimer(this);
03004      connect(m_reportTimer,SIGNAL(timeout()),this,SLOT(slotReport()));
03005      //this will update the report dialog with 5 Hz, I think this is fast enough, aleXXX
03006      m_reportTimer->start(REPORT_TIMEOUT,false);
03007   }
03008 
03009   QTimer::singleShot(0, this, SLOT(slotStart()));
03010 }
03011 
03012 void DeleteJob::slotStart()
03013 {
03014   statNextSrc();
03015 }
03016 
03017 //this is called often, so calling the functions
03018 //from Observer here directly might improve the performance a little bit
03019 //aleXXX
03020 void DeleteJob::slotReport()
03021 {
03022    if (m_progressId==0)
03023       return;
03024 
03025    Observer * observer = Observer::self();
03026 
03027    emit deleting( this, m_currentURL );
03028    observer->slotDeleting(this,m_currentURL);
03029 
03030    switch( state ) {
03031         case STATE_STATING:
03032         case STATE_LISTING:
03033             emit totalSize( this, m_totalSize );
03034             emit totalFiles( this, files.count() );
03035             emit totalDirs( this, dirs.count() );
03036             break;
03037         case STATE_DELETING_DIRS:
03038             emit processedDirs( this, m_processedDirs );
03039             observer->slotProcessedDirs(this,m_processedDirs);
03040             emitPercent( m_processedFiles + m_processedDirs, m_totalFilesDirs );
03041             break;
03042         case STATE_DELETING_FILES:
03043             observer->slotProcessedFiles(this,m_processedFiles);
03044             emit processedFiles( this, m_processedFiles );
03045             if (!m_shred)
03046                emitPercent( m_processedFiles, m_totalFilesDirs );
03047             break;
03048    }
03049 }
03050 
03051 
03052 void DeleteJob::slotEntries(KIO::Job* job, const UDSEntryList& list)
03053 {
03054    UDSEntryListConstIterator it = list.begin();
03055    UDSEntryListConstIterator end = list.end();
03056    for (; it != end; ++it)
03057    {
03058       UDSEntry::ConstIterator it2 = (*it).begin();
03059       bool bDir = false;
03060       bool bLink = false;
03061       QString relName;
03062       int atomsFound(0);
03063       for( ; it2 != (*it).end(); it2++ )
03064       {
03065          switch ((*it2).m_uds)
03066          {
03067          case UDS_FILE_TYPE:
03068             bDir = S_ISDIR((*it2).m_long);
03069             atomsFound++;
03070             break;
03071          case UDS_NAME:
03072             relName = ((*it2).m_str);
03073             atomsFound++;
03074             break;
03075          case UDS_LINK_DEST:
03076             bLink = !(*it2).m_str.isEmpty();
03077             atomsFound++;
03078             break;
03079          case UDS_SIZE:
03080             m_totalSize += (off_t)((*it2).m_long);
03081             atomsFound++;
03082             break;
03083          default:
03084             break;
03085          }
03086          if (atomsFound==4) break;
03087       }
03088       assert(!relName.isEmpty());
03089       if (relName != ".." && relName != ".")
03090       {
03091          KURL url = ((SimpleJob *)job)->url(); // assumed to be a dir
03092          url.addPath( relName );
03093          //kdDebug(7007) << "DeleteJob::slotEntries " << relName << " (" << url.prettyURL() << ")" << endl;
03094          if ( bLink )
03095             symlinks.append( url );
03096          else if ( bDir )
03097             dirs.append( url );
03098          else
03099             files.append( url );
03100       }
03101    }
03102 }
03103 
03104 
03105 void DeleteJob::statNextSrc()
03106 {
03107     //kdDebug(7007) << "statNextSrc" << endl;
03108     if ( m_currentStat != m_srcList.end() )
03109     {
03110         m_currentURL = (*m_currentStat);
03111 
03112         // if the file system doesn't support deleting, we do not even stat
03113         if (!KProtocolInfo::supportsDeleting(m_currentURL)) {
03114             KMessageBox::information( 0, buildErrorString(ERR_CANNOT_DELETE, m_currentURL.prettyURL()));
03115             ++m_currentStat;
03116             statNextSrc(); // we could use a loop instead of a recursive call :)
03117             return;
03118         }
03119         // Stat it
03120         state = STATE_STATING;
03121         KIO::SimpleJob * job = KIO::stat( m_currentURL, true, 1, false );
03122         Scheduler::scheduleJob(job);
03123         //kdDebug(7007) << "KIO::stat (DeleteJob) " << m_currentURL.prettyURL() << endl;
03124         addSubjob(job);
03125         //if ( m_progressId ) // Did we get an ID from the observer ?
03126         //  Observer::self()->slotDeleting( this, *it ); // show asap
03127     } else
03128     {
03129         m_totalFilesDirs = files.count()+symlinks.count() + dirs.count();
03130         slotReport();
03131         // Now we know which dirs hold the files we're going to delete.
03132         // To speed things up and prevent double-notification, we disable KDirWatch
03133         // on those dirs temporarily (using KDirWatch::self, that's the instanced
03134         // used by e.g. kdirlister).
03135         for ( QStringList::Iterator it = m_parentDirs.begin() ; it != m_parentDirs.end() ; ++it )
03136             KDirWatch::self()->stopDirScan( *it );
03137         state = STATE_DELETING_FILES;
03138     deleteNextFile();
03139     }
03140 }
03141 
03142 void DeleteJob::deleteNextFile()
03143 {
03144     //kdDebug(7007) << "deleteNextFile" << endl;
03145     if ( !files.isEmpty() || !symlinks.isEmpty() )
03146     {
03147         SimpleJob *job;
03148         do {
03149             // Take first file to delete out of list
03150             KURL::List::Iterator it = files.begin();
03151             bool isLink = false;
03152             if ( it == files.end() ) // No more files
03153             {
03154                 it = symlinks.begin(); // Pick up a symlink to delete
03155                 isLink = true;
03156             }
03157             // Use shredding ?
03158             if ( m_shred && (*it).isLocalFile() && !isLink )
03159             {
03160                 // KShred your KTie
03161                 KIO_ARGS << int(3) << (*it).path();
03162                 job = KIO::special(KURL("file:/"), packedArgs, false /*no GUI*/);
03163                 Scheduler::scheduleJob(job);
03164                 m_currentURL=(*it);
03165                 connect( job, SIGNAL( processedSize( KIO::Job*, KIO::filesize_t ) ),
03166                          this, SLOT( slotProcessedSize( KIO::Job*, KIO::filesize_t ) ) );
03167             } else
03168             {
03169                 // Normal deletion
03170                 // If local file, try do it directly
03171                 if ( (*it).isLocalFile() && unlink( QFile::encodeName((*it).path()) ) == 0 ) {
03172                     job = 0;
03173                     m_processedFiles++;
03174                     if ( m_processedFiles % 300 == 0 ) { // update progress info every 300 files
03175                         m_currentURL = *it;
03176                         slotReport();
03177                     }
03178                 } else
03179                 { // if remote - or if unlink() failed (we'll use the job's error handling in that case)
03180                     job = KIO::file_delete( *it, false /*no GUI*/);
03181                     Scheduler::scheduleJob(job);
03182                     m_currentURL=(*it);
03183                 }
03184             }
03185             if ( isLink )
03186                 symlinks.remove(it);
03187             else
03188                 files.remove(it);
03189             if ( job ) {
03190                 addSubjob(job);
03191                 return;
03192             }
03193             // loop only if direct deletion worked (job=0) and there is something else to delete
03194         } while (!job && (!files.isEmpty() || !symlinks.isEmpty()));
03195     }
03196     state = STATE_DELETING_DIRS;
03197     deleteNextDir();
03198 }
03199 
03200 void DeleteJob::deleteNextDir()
03201 {
03202     if ( !dirs.isEmpty() ) // some dirs to delete ?
03203     {
03204         do {
03205             // Take first dir to delete out of list - last ones first !
03206             KURL::List::Iterator it = dirs.fromLast();
03207             // If local dir, try to rmdir it directly
03208             if ( (*it).isLocalFile() && ::rmdir( QFile::encodeName((*it).path()) ) == 0 ) {
03209 
03210                 m_processedDirs++;
03211                 if ( m_processedDirs % 100 == 0 ) { // update progress info every 100 dirs
03212                     m_currentURL = *it;
03213                     slotReport();
03214                 }
03215             } else
03216             {
03217                 SimpleJob *job = KIO::rmdir( *it );
03218                 Scheduler::scheduleJob(job);
03219                 dirs.remove(it);
03220                 addSubjob( job );
03221                 return;
03222             }
03223             dirs.remove(it);
03224         } while ( !dirs.isEmpty() );
03225     }
03226 
03227     // Re-enable watching on the dirs that held the deleted files
03228     for ( QStringList::Iterator it = m_parentDirs.begin() ; it != m_parentDirs.end() ; ++it )
03229         KDirWatch::self()->restartDirScan( *it );
03230 
03231     // Finished - tell the world
03232     if ( !m_srcList.isEmpty() )
03233     {
03234         KDirNotify_stub allDirNotify("*", "KDirNotify*");
03235         allDirNotify.FilesRemoved( m_srcList );
03236     }
03237     if (m_reportTimer!=0)
03238        m_reportTimer->stop();
03239     emitResult();
03240 }
03241 
03242 void DeleteJob::slotProcessedSize( KIO::Job*, KIO::filesize_t data_size )
03243 {
03244    // Note: this is the same implementation as CopyJob::slotProcessedSize but
03245    // it's different from FileCopyJob::slotProcessedSize - which is why this
03246    // is not in Job.
03247 
03248    m_fileProcessedSize = data_size;
03249 
03250    //kdDebug(7007) << "DeleteJob::slotProcessedSize " << (unsigned int) (m_processedSize + m_fileProcessedSize) << endl;
03251 
03252    emit processedSize( this, m_processedSize + m_fileProcessedSize );
03253 
03254    // calculate percents
03255    unsigned long ipercent = m_percent;
03256 
03257    if ( m_totalSize == 0 )
03258       m_percent = 100;
03259    else
03260       m_percent = (unsigned long)(( (float)(m_processedSize + m_fileProcessedSize) / (float)m_totalSize ) * 100.0);
03261 
03262    if ( m_percent > ipercent )
03263    {
03264       emit percent( this, m_percent );
03265       //kdDebug(7007) << "DeleteJob::slotProcessedSize - percent =  " << (unsigned int) m_percent << endl;
03266    }
03267 
03268 }
03269 
03270 void DeleteJob::slotResult( Job *job )
03271 {
03272    switch ( state )
03273    {
03274    case STATE_STATING:
03275       {
03276          // Was there an error while stating ?
03277          if (job->error() )
03278          {
03279             // Probably : doesn't exist
03280             Job::slotResult( job ); // will set the error and emit result(this)
03281             return;
03282          }
03283 
03284          // Is it a file or a dir ?
03285          UDSEntry entry = ((StatJob*)job)->statResult();
03286          bool bDir = false;
03287          bool bLink = false;
03288          KIO::filesize_t size = (KIO::filesize_t)-1;
03289          UDSEntry::ConstIterator it2 = entry.begin();
03290          int atomsFound(0);
03291          for( ; it2 != entry.end(); it2++ )
03292          {
03293             if ( ((*it2).m_uds) == UDS_FILE_TYPE )
03294             {
03295                bDir = S_ISDIR( (mode_t)(*it2).m_long );
03296                atomsFound++;
03297             }
03298             else if ( ((*it2).m_uds) == UDS_LINK_DEST )
03299             {
03300                bLink = !((*it2).m_str.isEmpty());
03301                atomsFound++;
03302             }
03303             else if ( ((*it2).m_uds) == UDS_SIZE )
03304             {
03305                size = (*it2).m_long;
03306                atomsFound++;
03307             };
03308             if (atomsFound==3) break;
03309          }
03310 
03311          KURL url = ((SimpleJob*)job)->url();
03312 
03313          subjobs.remove( job );
03314          assert( subjobs.isEmpty() );
03315 
03316          if (bDir && !bLink)
03317          {
03318             // Add toplevel dir in list of dirs
03319             dirs.append( url );
03320             if ( url.isLocalFile() && !m_parentDirs.contains( url.path(-1) ) )
03321                 m_parentDirs.append( url.path(-1) );
03322 
03323             //kdDebug(7007) << " Target is a directory " << endl;
03324             // List it
03325             state = STATE_LISTING;
03326             ListJob *newjob = listRecursive( url, false );
03327             Scheduler::scheduleJob(newjob);
03328             connect(newjob, SIGNAL(entries( KIO::Job *,
03329                                             const KIO::UDSEntryList& )),
03330                     SLOT( slotEntries( KIO::Job*,
03331                                        const KIO::UDSEntryList& )));
03332             addSubjob(newjob);
03333          }
03334          else
03335          {
03336             if ( bLink ) {
03337                 //kdDebug(7007) << " Target is a symlink" << endl;
03338                 symlinks.append( url );
03339             } else {
03340                 //kdDebug(7007) << " Target is a file" << endl;
03341                 files.append( url );
03342             }
03343             if ( url.isLocalFile() && !m_parentDirs.contains( url.directory(-1) ) )
03344                 m_parentDirs.append( url.directory(-1) );
03345             ++m_currentStat;
03346             statNextSrc();
03347          }
03348       }
03349       break;
03350    case STATE_LISTING:
03351       if ( job->error() )
03352       {
03353          // Try deleting nonetheless, it may be empty (and non-listable)
03354       }
03355       subjobs.remove( job );
03356       assert( subjobs.isEmpty() );
03357       ++m_currentStat;
03358       statNextSrc();
03359       break;
03360    case STATE_DELETING_FILES:
03361       if ( job->error() )
03362       {
03363          Job::slotResult( job ); // will set the error and emit result(this)
03364          return;
03365       }
03366       subjobs.remove( job );
03367       assert( subjobs.isEmpty() );
03368       m_processedFiles++;
03369 
03370       deleteNextFile();
03371       break;
03372    case STATE_DELETING_DIRS:
03373       if ( job->error() )
03374       {
03375          Job::slotResult( job ); // will set the error and emit result(this)
03376          return;
03377       }
03378       subjobs.remove( job );
03379       assert( subjobs.isEmpty() );
03380       m_processedDirs++;
03381       //emit processedDirs( this, m_processedDirs );
03382       //if (!m_shred)
03383          //emitPercent( m_processedFiles + m_processedDirs, m_totalFilesDirs );
03384 
03385       deleteNextDir();
03386       break;
03387    default:
03388       assert(0);
03389    }
03390 }
03391 
03392 DeleteJob *KIO::del( const KURL& src, bool shred, bool showProgressInfo )
03393 {
03394   KURL::List srcList;
03395   srcList.append( src );
03396   DeleteJob *job = new DeleteJob( srcList, shred, showProgressInfo );
03397   return job;
03398 }
03399 
03400 DeleteJob *KIO::del( const KURL::List& src, bool shred, bool showProgressInfo )
03401 {
03402   DeleteJob *job = new DeleteJob( src, shred, showProgressInfo );
03403   return job;
03404 }
03405 
03406 MultiGetJob::MultiGetJob(const KURL& url,
03407                          bool showProgressInfo)
03408  : TransferJob(url, 0, QByteArray(), QByteArray(), showProgressInfo)
03409 {
03410    m_waitQueue.setAutoDelete(true);
03411    m_activeQueue.setAutoDelete(true);
03412    m_currentEntry = 0;
03413 }
03414 
03415 void MultiGetJob::get(long id, const KURL &url, const MetaData &metaData)
03416 {
03417    GetRequest *entry = new GetRequest(id, url, metaData);
03418    entry->metaData["request-id"] = QString("%1").arg(id);
03419    m_waitQueue.append(entry);
03420 }
03421 
03422 void MultiGetJob::flushQueue(QPtrList<GetRequest> &queue)
03423 {
03424    GetRequest *entry;
03425    // Use multi-get
03426    // Scan all jobs in m_waitQueue
03427    for(entry = m_waitQueue.first(); entry; )
03428    {
03429       if ((m_url.protocol() == entry->url.protocol()) &&
03430           (m_url.host() == entry->url.host()) &&
03431           (m_url.port() == entry->url.port()) &&
03432           (m_url.user() == entry->url.user()))
03433       {
03434          m_waitQueue.take();
03435          queue.append(entry);
03436          entry = m_waitQueue.current();
03437       }
03438       else
03439       {
03440          entry = m_waitQueue.next();
03441       }
03442    }
03443    // Send number of URLs, (URL, metadata)*
03444    KIO_ARGS << (Q_INT32) queue.count();
03445    for(entry = queue.first(); entry; entry = queue.next())
03446    {
03447       stream << entry->url << entry->metaData;
03448    }
03449    m_packedArgs = packedArgs;
03450    m_command = CMD_MULTI_GET;
03451    m_outgoingMetaData.clear();
03452 }
03453 
03454 void MultiGetJob::start(Slave *slave)
03455 {
03456    // Add first job from m_waitQueue and add it to m_activeQueue
03457    GetRequest *entry = m_waitQueue.take(0);
03458    m_activeQueue.append(entry);
03459 
03460    m_url = entry->url;
03461 
03462    if (!entry->url.protocol().startsWith("http"))
03463    {
03464       // Use normal get
03465       KIO_ARGS << entry->url;
03466       m_packedArgs = packedArgs;
03467       m_outgoingMetaData = entry->metaData;
03468       m_command = CMD_GET;
03469       b_multiGetActive = false;
03470    }
03471    else
03472    {
03473       flushQueue(m_activeQueue);
03474       b_multiGetActive = true;
03475    }
03476 
03477    TransferJob::start(slave); // Anything else to do??
03478 }
03479 
03480 bool MultiGetJob::findCurrentEntry()
03481 {
03482    if (b_multiGetActive)
03483    {
03484       long id = m_incomingMetaData["request-id"].toLong();
03485       for(GetRequest *entry = m_activeQueue.first(); entry; entry = m_activeQueue.next())
03486       {
03487          if (entry->id == id)
03488          {
03489             m_currentEntry = entry;
03490             return true;
03491          }
03492       }
03493       m_currentEntry = 0;
03494       return false;
03495    }
03496    else
03497    {
03498       m_currentEntry = m_activeQueue.first();
03499       return (m_currentEntry != 0);
03500    }
03501 }
03502 
03503 void MultiGetJob::slotRedirection( const KURL &url)
03504 {
03505   if (!findCurrentEntry()) return; // Error
03506   if (!kapp->authorizeURLAction("redirect", m_url, url))
03507   {
03508      kdWarning(7007) << "MultiGetJob: Redirection from " << m_currentEntry->url.prettyURL() << " to " << url.prettyURL() << " REJECTED!" << endl;
03509      return;
03510   }
03511   m_redirectionURL = url;
03512   if (m_currentEntry->url.hasUser() && !url.hasUser() && (m_currentEntry->url.host().lower() == url.host().lower()))
03513       m_redirectionURL.setUser(m_currentEntry->url.user()); // Preserve user
03514   get(m_currentEntry->id, m_redirectionURL, m_currentEntry->metaData); // Try again
03515 }
03516 
03517 
03518 void MultiGetJob::slotFinished()
03519 {
03520   if (!findCurrentEntry()) return;
03521   if (m_redirectionURL.isEmpty())
03522   {
03523      // No redirection, tell the world that we are finished.
03524      emit result(m_currentEntry->id);
03525   }
03526   m_redirectionURL = KURL();
03527   m_error = 0;
03528   m_incomingMetaData.clear();
03529   m_activeQueue.removeRef(m_currentEntry);
03530   if (m_activeQueue.count() == 0)
03531   {
03532      if (m_waitQueue.count() == 0)
03533      {
03534         // All done
03535         TransferJob::slotFinished();
03536      }
03537      else
03538      {
03539         // return slave to pool
03540         // fetch new slave for first entry in m_waitQueue and call start
03541         // again.
03542         GetRequest *entry = m_waitQueue.at(0);
03543         m_url = entry->url;
03544         slaveDone();
03545         Scheduler::doJob(this);
03546      }
03547   }
03548 }
03549 
03550 void MultiGetJob::slotData( const QByteArray &_data)
03551 {
03552   if(!m_currentEntry) return;// Error, unknown request!
03553   if(m_redirectionURL.isEmpty() || m_redirectionURL.isMalformed() || m_error)
03554      emit data(m_currentEntry->id, _data);
03555 }
03556 
03557 void MultiGetJob::slotMimetype( const QString &_mimetype )
03558 {
03559   if (b_multiGetActive)
03560   {
03561      QPtrList<GetRequest> newQueue;
03562      flushQueue(newQueue);
03563      if (!newQueue.isEmpty())
03564      {
03565         while(!newQueue.isEmpty())
03566            m_activeQueue.append(newQueue.take(0));
03567         m_slave->connection()->send( m_command, m_packedArgs );
03568      }
03569   }
03570   if (!findCurrentEntry()) return; // Error, unknown request!
03571   emit mimetype(m_currentEntry->id, _mimetype);
03572 }
03573 
03574 MultiGetJob *KIO::multi_get(long id, const KURL &url, const MetaData &metaData)
03575 {
03576     MultiGetJob * job = new MultiGetJob( url, false );
03577     job->get(id, url, metaData);
03578     return job;
03579 }
03580 
03581 
03582 #ifdef CACHE_INFO
03583 CacheInfo::CacheInfo(const KURL &url)
03584 {
03585     m_url = url;
03586 }
03587 
03588 QString CacheInfo::cachedFileName()
03589 {
03590    const QChar seperator = '_';
03591 
03592    QString CEF = m_url.path();
03593 
03594    int p = CEF.find('/');
03595 
03596    while(p != -1)
03597    {
03598       CEF[p] = seperator;
03599       p = CEF.find('/', p);
03600    }
03601 
03602    QString host = m_url.host().lower();
03603    CEF = host + CEF + '_';
03604 
03605    QString dir = KProtocolManager::cacheDir();
03606    if (dir[dir.length()-1] != '/')
03607       dir += "/";
03608 
03609    int l = m_url.host().length();
03610    for(int i = 0; i < l; i++)
03611    {
03612       if (host[i].isLetter() && (host[i] != 'w'))
03613       {
03614          dir += host[i];
03615          break;
03616       }
03617    }
03618    if (dir[dir.length()-1] == '/')
03619       dir += "0";
03620 
03621    unsigned long hash = 0x00000000;
03622    QCString u = m_url.url().latin1();
03623    for(int i = u.length(); i--;)
03624    {
03625       hash = (hash * 12211 + u[i]) % 2147483563;
03626    }
03627 
03628    QString hashString;
03629    hashString.sprintf("%08lx", hash);
03630 
03631    CEF = CEF + hashString;
03632 
03633    CEF = dir + "/" + CEF;
03634 
03635    return CEF;
03636 }
03637 
03638 QFile *CacheInfo::cachedFile()
03639 {
03640    const char *mode = (readWrite ? "r+" : "r");
03641 
03642    FILE *fs = fopen( CEF.latin1(), mode); // Open for reading and writing
03643    if (!fs)
03644       return 0;
03645 
03646    char buffer[401];
03647    bool ok = true;
03648 
03649   // CacheRevision
03650   if (ok && (!fgets(buffer, 400, fs)))
03651       ok = false;
03652    if (ok && (strcmp(buffer, CACHE_REVISION) != 0))
03653       ok = false;
03654 
03655    time_t date;
03656    time_t currentDate = time(0);
03657 
03658    // URL
03659    if (ok && (!fgets(buffer, 400, fs)))
03660       ok = false;
03661    if (ok)
03662    {
03663       int l = strlen(buffer);
03664       if (l>0)
03665          buffer[l-1] = 0; // Strip newline
03666       if (m_.url.url() != buffer)
03667       {
03668          ok = false; // Hash collision
03669       }
03670    }
03671 
03672    // Creation Date
03673    if (ok && (!fgets(buffer, 400, fs)))
03674       ok = false;
03675    if (ok)
03676    {
03677       date = (time_t) strtoul(buffer, 0, 10);
03678       if (m_maxCacheAge && (difftime(currentDate, date) > m_maxCacheAge))
03679       {
03680          m_bMustRevalidate = true;
03681          m_expireDate = currentDate;
03682       }
03683    }
03684 
03685    // Expiration Date
03686    m_cacheExpireDateOffset = ftell(fs);
03687    if (ok && (!fgets(buffer, 400, fs)))
03688       ok = false;
03689    if (ok)
03690    {
03691       if (m_request.cache == CC_Verify)
03692       {
03693          date = (time_t) strtoul(buffer, 0, 10);
03694          // After the expire date we need to revalidate.
03695          if (!date || difftime(currentDate, date) >= 0)
03696             m_bMustRevalidate = true;
03697          m_expireDate = date;
03698       }
03699    }
03700 
03701    // ETag
03702    if (ok && (!fgets(buffer, 400, fs)))
03703       ok = false;
03704    if (ok)
03705    {
03706       m_etag = QString(buffer).stripWhiteSpace();
03707    }
03708 
03709    // Last-Modified
03710    if (ok && (!fgets(buffer, 400, fs)))
03711       ok = false;
03712    if (ok)
03713    {
03714       m_lastModified = QString(buffer).stripWhiteSpace();
03715    }
03716 
03717    fclose(fs);
03718 
03719    if (ok)
03720       return fs;
03721 
03722    unlink( CEF.latin1());
03723    return 0;
03724 
03725 }
03726 
03727 void CacheInfo::flush()
03728 {
03729     cachedFile().remove();
03730 }
03731 
03732 void CacheInfo::touch()
03733 {
03734 
03735 }
03736 void CacheInfo::setExpireDate(int);
03737 void CacheInfo::setExpireTimeout(int);
03738 
03739 
03740 int CacheInfo::creationDate();
03741 int CacheInfo::expireDate();
03742 int CacheInfo::expireTimeout();
03743 #endif
03744 
03745 void Job::virtual_hook( int, void* )
03746 { /*BASE::virtual_hook( id, data );*/ }
03747 
03748 void SimpleJob::virtual_hook( int id, void* data )
03749 { KIO::Job::virtual_hook( id, data ); }
03750 
03751 void StatJob::virtual_hook( int id, void* data )
03752 { SimpleJob::virtual_hook( id, data ); }
03753 
03754 void TransferJob::virtual_hook( int id, void* data )
03755 { SimpleJob::virtual_hook( id, data ); }
03756 
03757 void MultiGetJob::virtual_hook( int id, void* data )
03758 { TransferJob::virtual_hook( id, data ); }
03759 
03760 void MimetypeJob::virtual_hook( int id, void* data )
03761 { TransferJob::virtual_hook( id, data ); }
03762 
03763 void FileCopyJob::virtual_hook( int id, void* data )
03764 { Job::virtual_hook( id, data ); }
03765 
03766 void ListJob::virtual_hook( int id, void* data )
03767 { SimpleJob::virtual_hook( id, data ); }
03768 
03769 void CopyJob::virtual_hook( int id, void* data )
03770 { Job::virtual_hook( id, data ); }
03771 
03772 void DeleteJob::virtual_hook( int id, void* data )
03773 { Job::virtual_hook( id, data ); }
03774 
03775 
03776 #include "jobclasses.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Mar 16 18:44:13 2005 by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-2001