# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# jobclasses.h

    00001 // -*- c++ -*-
    00002 /* This file is part of the KDE libraries
    00003     Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
    00004                        David Faure <faure@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 #ifndef __kio_jobclasses_h__
    00023 #define __kio_jobclasses_h__
    00024
    00025 #include <kurl.h>
    00026
    00027 #include <qobject.h>
    00028 #include <qptrlist.h>
    00029 #include <qstring.h>
    00030 #include <qstringlist.h>
    00031 #include <qguardedptr.h>
    00032
    00033 #include <sys/types.h>
    00034 #include <sys/stat.h>
    00035
    00036 #include <kio/global.h>
    00037
    00038 class Observer;
    00039 class QTimer;
    00040
    00041 namespace KIO {
    00042
    00043     class Slave;
    00044     class SlaveInterface;
    00045
    00046
    00066     class Job : public QObject {
    00067         Q_OBJECT
    00068
    00069     protected:
    00070         Job( bool showProgressInfo );
    00071
    00072     public:
    00073         virtual ~Job();
    00074
    00084         virtual void kill( bool quietly = true );
    00085
    00091         int error() const { return m_error; }
    00092
    00096         int progressId() const { return m_progressId; }
    00097
    00104         const QString & errorText() const { return m_errorText; }
    00105
    00117         QString errorString() const;
    00118
    00129         QStringList detailedErrorStrings(const KURL *reqUrl = 0L,
    00130                                          int method = -1) const;
    00131
    00139         void showErrorDialog( QWidget * parent = 0L );
    00140
    00154         void setAutoErrorHandlingEnabled( bool enable, QWidget *parentWidget = 0 );
    00155
    00160         bool isAutoErrorHandlingEnabled() const;
    00161
    00165         void setWindow(QWidget *window);
    00166
    00170         QWidget *window() const;
    00171
    00179         void setParentJob( Job* parentJob );
    00180
    00185         Job* parentJob() const;
    00186
    00190         void setMetaData( const KIO::MetaData &);
    00191
    00195         void addMetaData(const QString &key, const QString &value);
    00196
    00201         void addMetaData(const QMap<QString,QString> &values);
    00202
    00207         void mergeMetaData(const QMap<QString,QString> &values);
    00208
    00212         MetaData outgoingMetaData() const;
    00213
    00218         MetaData metaData() const;
    00219
    00224         QString queryMetaData(const QString &key);
    00225
    00226     signals:
    00231         void result( KIO::Job *job );
    00232
    00239         void canceled( KIO::Job *job );
    00240
    00245         void infoMessage( KIO::Job *, const QString & msg );
    00246         // KDE 3.0: Separate rich-text string from plain-text string, for different widgets.
    00247
    00253         void connected( KIO::Job * );
    00254
    00262         void percent( KIO::Job *job, unsigned long percent );
    00263
    00268         void totalSize( KIO::Job *, KIO::filesize_t size );
    00269
    00274         void processedSize( KIO::Job *, KIO::filesize_t size );
    00275
    00279         void speed( KIO::Job *, unsigned long bytes_per_second );
    00280
    00281     protected slots:
    00288         virtual void slotResult( KIO::Job *job );
    00289
    00293         void slotSpeed( KIO::Job*, unsigned long bytes_per_second );
    00297         void slotInfoMessage( KIO::Job*, const QString & );
    00298
    00302         void slotSpeedTimeout();
    00303
    00304     protected:
    00313         virtual void addSubjob( Job *job, bool inheritMetaData=true );
    00314
    00321         virtual void removeSubjob( Job *job );
    00322
    00328         void emitPercent( KIO::filesize_t processedSize, KIO::filesize_t totalSize );
    00329
    00334         void emitSpeed( unsigned long bytes_per_second );
    00335
    00340         void emitResult();
    00341
    00342         QPtrList<Job> subjobs;
    00343         int m_error;
    00344         QString m_errorText;
    00345         unsigned long m_percent;
    00346         int m_progressId; // for uiserver
    00347         QTimer *m_speedTimer;
    00348         QGuardedPtr<QWidget> m_window;
    00349         MetaData m_outgoingMetaData;
    00350         MetaData m_incomingMetaData;
    00351     protected:
    00352         virtual void virtual_hook( int id, void* data );
    00353     private:
    00354         class JobPrivate;
    00355         JobPrivate *d;
    00356     };
    00357
    00364     class SimpleJob : public KIO::Job {
    00365     Q_OBJECT
    00366
    00367     public:
    00368         SimpleJob(const KURL& url, int command, const QByteArray &packedArgs,
    00369                   bool showProgressInfo);
    00370
    00371         ~SimpleJob();
    00372
    00373         const KURL& url() const { return m_url; }
    00374
    00382         virtual void kill( bool quietly = true );
    00383
    00388         virtual void putOnHold();
    00389
    00393         static void removeOnHold();
    00394
    00400         virtual void start( Slave *slave );
    00401
    00406         void slaveDone();
    00407
    00412         Slave *slave() const { return m_slave; }
    00413
    00417         int command() const { return m_command; }
    00418
    00419     public slots:
    00424         void slotTotalSize( KIO::filesize_t data_size );
    00425
    00426     protected slots:
    00431         virtual void slotFinished( );
    00432
    00437         void slotWarning( const QString & );
    00438
    00442         void slotInfoMessage( const QString & );
    00443
    00447         void slotConnected();
    00448
    00452         void slotProcessedSize( KIO::filesize_t data_size );
    00456         void slotSpeed( unsigned long bytes_per_second );
    00457
    00461         virtual void slotMetaData( const KIO::MetaData &_metaData);
    00462
    00463     public slots:
    00469         virtual void slotError( int , const QString & );
    00470
    00471     protected slots:
    00475         void slotNeedProgressId();
    00476
    00477     protected:
    00478         Slave * m_slave;
    00479         QByteArray m_packedArgs;
    00480         KURL m_url;
    00481         KURL m_subUrl;
    00482         int m_command;
    00483         KIO::filesize_t m_totalSize;
    00484     protected:
    00485         virtual void virtual_hook( int id, void* data );
    00486     private:
    00487         class SimpleJobPrivate* d;
    00488     };
    00489
    00490     // Stat Job
    00491     class StatJob : public SimpleJob {
    00492
    00493     Q_OBJECT
    00494
    00495     public:
    00496         StatJob(const KURL& url, int command, const QByteArray &packedArgs, bool showProgressInfo);
    00497
    00503         void setSide( bool source ) { m_bSource = source; }
    00504
    00513         void setDetails( short int details ) { m_details = details; }
    00514
    00519         const UDSEntry & statResult() const { return m_statResult; }
    00520
    00525         virtual void start( Slave *slave );
    00526
    00527     signals:
    00533         void redirection( KIO::Job *, const KURL &url );
    00534
    00540         void permanentRedirection( KIO::Job *, const KURL &fromUrl, const KURL &toUrl );
    00541
    00542     protected slots:
    00543         void slotStatEntry( const KIO::UDSEntry & entry );
    00544         void slotRedirection( const KURL &url);
    00545         virtual void slotFinished();
    00546
    00547     protected:
    00548         UDSEntry m_statResult;
    00549         KURL m_redirectionURL;
    00550         bool m_bSource;
    00551         short int m_details;
    00552     protected:
    00553         virtual void virtual_hook( int id, void* data );
    00554     private:
    00555         class StatJobPrivate;
    00556         StatJobPrivate *d;
    00557     };
    00558
    00565     class TransferJob : public SimpleJob {
    00566     Q_OBJECT
    00567
    00568     public:
    00569         TransferJob(const KURL& url, int command,
    00570                     const QByteArray &packedArgs,
    00571                     const QByteArray &_staticData,
    00572                     bool showProgressInfo);
    00573
    00574         virtual void start(Slave *slave);
    00575
    00579         virtual void slotResult( KIO::Job *job );
    00580
    00584         void suspend();
    00585
    00589         void resume();
    00590
    00594         bool isSuspended() const { return m_suspended; }
    00595
    00596
    00602         bool isErrorPage() const { return m_errorPage; }
    00603
    00604
    00605     signals:
    00611         void data( KIO::Job *, const QByteArray &data);
    00612
    00624         void dataReq( KIO::Job *, QByteArray &data);
    00625
    00631         void redirection( KIO::Job *, const KURL &url );
    00632
    00638         void permanentRedirection( KIO::Job *, const KURL &fromUrl, const KURL &toUrl );
    00639
    00643         void mimetype( KIO::Job *, const QString &type );
    00644
    00652         void canResume( KIO::Job *, KIO::filesize_t offset );
    00653
    00654
    00655     protected slots:
    00656         virtual void slotRedirection( const KURL &url);
    00657         virtual void slotFinished();
    00658         virtual void slotData( const QByteArray &data);
    00659         virtual void slotDataReq();
    00660         virtual void slotMimetype( const QString &mimetype );
    00661         virtual void slotNeedSubURLData();
    00662         virtual void slotSubURLData(KIO::Job*, const QByteArray &);
    00663         void slotErrorPage();
    00664         void slotCanResume( KIO::filesize_t offset );
    00665
    00666     protected:
    00667         bool m_suspended;
    00668         bool m_errorPage;
    00669         QByteArray staticData;
    00670         KURL m_redirectionURL;
    00671         KURL::List m_redirectionList;
    00672         QString m_mimetype;
    00673         TransferJob *m_subJob;
    00674     protected:
    00675         virtual void virtual_hook( int id, void* data );
    00676     private:
    00677         class TransferJobPrivate* d;
    00678     };
    00679
    00680     // MultiGet Job
    00681     class MultiGetJob : public TransferJob {
    00682     Q_OBJECT
    00683
    00684     public:
    00685         MultiGetJob(const KURL& url, bool showProgressInfo);
    00686
    00687         virtual void start(Slave *slave);
    00688
    00689         void get(long id, const KURL &url, const MetaData &metaData);
    00690
    00691     signals:
    00697         void data( long id, const QByteArray &data);
    00698
    00702         void mimetype( long id, const QString &type );
    00703
    00710         void result( long id);
    00711
    00712     protected slots:
    00713         virtual void slotRedirection( const KURL &url);
    00714         virtual void slotFinished();
    00715         virtual void slotData( const QByteArray &data);
    00716         virtual void slotMimetype( const QString &mimetype );
    00717     private:
    00718         struct GetRequest {
    00719         public:
    00720            GetRequest(long _id, const KURL &_url, const MetaData &_metaData)
    00721              : id(_id), url(_url), metaData(_metaData) { }
    00722            long id;
    00723            KURL url;
    00724            MetaData metaData;
    00725         };
    00726         bool findCurrentEntry();
    00727         void flushQueue(QPtrList<GetRequest> &queue);
    00728
    00729         QPtrList<GetRequest> m_waitQueue;
    00730         QPtrList<GetRequest> m_activeQueue;
    00731         bool b_multiGetActive;
    00732         GetRequest *m_currentEntry;
    00733     protected:
    00734         virtual void virtual_hook( int id, void* data );
    00735     private:
    00736         class MultiGetJobPrivate* d;
    00737     };
    00738
    00739     // Mimetype Job
    00740     class MimetypeJob : public TransferJob {
    00741     Q_OBJECT
    00742
    00743     public:
    00744         MimetypeJob(const KURL& url, int command, const QByteArray &packedArgs, bool showProgressInfo);
    00745
    00750          QString mimetype() const { return m_mimetype; }
    00751
    00756         virtual void start( Slave *slave );
    00757
    00758     protected slots:
    00759         virtual void slotFinished( );
    00760     protected:
    00761         virtual void virtual_hook( int id, void* data );
    00762     private:
    00763         class MimetypeJobPrivate* d;
    00764     };
    00765
    00769     class FileCopyJob : public Job {
    00770     Q_OBJECT
    00771
    00772     public:
    00773         FileCopyJob( const KURL& src, const KURL& dest, int permissions,
    00774                      bool move, bool overwrite, bool resume, bool showProgressInfo);
    00775
    00776         ~FileCopyJob();
    00781         void setSourceSize( off_t size );
    00782
    00783         KURL srcURL() const { return m_src; }
    00784         KURL destURL() const { return m_dest; }
    00785
    00786     public slots:
    00787         void slotStart();
    00788         void slotData( KIO::Job *, const QByteArray &data);
    00789         void slotDataReq( KIO::Job *, QByteArray &data);
    00790
    00791     protected slots:
    00795         virtual void slotResult( KIO::Job *job );
    00796
    00800         void slotProcessedSize( KIO::Job*, KIO::filesize_t size );
    00804         void slotTotalSize( KIO::Job*, KIO::filesize_t size );
    00808         void slotPercent( KIO::Job*, unsigned long pct );
    00812         void slotCanResume( KIO::Job*, KIO::filesize_t offset );
    00813
    00814     protected:
    00815         void startCopyJob();
    00816         void startCopyJob(const KURL &slave_url);
    00817         void startDataPump();
    00818         void connectSubjob( SimpleJob * job );
    00819
    00820         KURL m_src;
    00821         KURL m_dest;
    00822         int m_permissions;
    00823         bool m_move:1;
    00824         bool m_overwrite:1;
    00825         bool m_resume:1;
    00826         bool m_canResume:1;
    00827         bool m_resumeAnswerSent:1;
    00828         QByteArray m_buffer;
    00829         SimpleJob *m_moveJob;
    00830         SimpleJob *m_copyJob;
    00831         TransferJob *m_getJob;
    00832         TransferJob *m_putJob;
    00833         KIO::filesize_t m_totalSize;
    00834     protected:
    00835         virtual void virtual_hook( int id, void* data );
    00836     private:
    00837         class FileCopyJobPrivate;
    00838         FileCopyJobPrivate* d;
    00839     };
    00840
    00841     class ListJob : public SimpleJob {
    00842     Q_OBJECT
    00843
    00844     public:
    00845         ListJob(const KURL& url, bool showProgressInfo,
    00846                 bool recursive = false, QString prefix = QString::null,
    00847                 bool includeHidden = true);
    00848
    00849         virtual void start( Slave *slave );
    00850
    00851     signals:
    00859         void entries( KIO::Job *, const KIO::UDSEntryList& );
    00860
    00866         void redirection( KIO::Job *, const KURL &url );
    00867
    00873         void permanentRedirection( KIO::Job *, const KURL &fromUrl, const KURL &toUrl );
    00874
    00875     protected slots:
    00876         virtual void slotFinished( );
    00877         virtual void slotResult( KIO::Job *job );
    00878         void slotListEntries( const KIO::UDSEntryList& list );
    00879         void slotRedirection( const KURL &url );
    00880         void gotEntries( KIO::Job * subjob, const KIO::UDSEntryList& list );
    00881
    00882     private:
    00883         bool recursive;
    00884         bool includeHidden;
    00885         QString prefix;
    00886         unsigned long m_processedEntries;
    00887         KURL m_redirectionURL;
    00888     protected:
    00889         virtual void virtual_hook( int id, void* data );
    00890     private:
    00891         class ListJobPrivate* d;
    00892     };
    00893
    00894     struct CopyInfo
    00895     {
    00896         KURL uSource;
    00897         KURL uDest;
    00898         QString linkDest; // for symlinks only
    00899         int permissions;
    00900         //mode_t type;
    00901         time_t ctime;
    00902         time_t mtime;
    00903         off_t size; // 0 for dirs
    00904     };
    00905
    00906     // Copy or Move, files or directories
    00907     class CopyJob : public Job {
    00908     Q_OBJECT
    00909
    00910     public:
    00911         enum CopyMode{ Copy, Move, Link };
    00912         CopyJob( const KURL::List& src, const KURL& dest, CopyMode mode, bool asMethod, bool showProgressInfo );
    00913
    00914         KURL::List srcURLs() const { return m_srcList; }
    00915         KURL destURL() const { return m_dest; }
    00916
    00917     signals:
    00918
    00919         void totalFiles( KIO::Job *, unsigned long files );
    00920         void totalDirs( KIO::Job *, unsigned long dirs );
    00921
    00922         void processedFiles( KIO::Job *, unsigned long files );
    00923         void processedDirs( KIO::Job *, unsigned long dirs );
    00924
    00928         void copying( KIO::Job *, const KURL& from, const KURL& to );
    00932         void linking( KIO::Job *, const QString& target, const KURL& to );
    00936         void moving( KIO::Job *, const KURL& from, const KURL& to );
    00940         void creatingDir( KIO::Job *, const KURL& dir );
    00944         void renamed( KIO::Job *, const KURL& from, const KURL& to );
    00945
    00955         void copyingDone( KIO::Job *, const KURL &from, const KURL &to, bool directory, bool renamed );
    00961         void copyingLinkDone( KIO::Job *, const KURL &from, const QString& target, const KURL& to );
    00962
    00963     protected:
    00964         void statNextSrc();
    00965
    00966         // Those aren't slots but submethods for slotResult.
    00967         void slotResultStating( KIO::Job * job );
    00968         void startListing( const KURL & src );
    00969         void slotResultCreatingDirs( KIO::Job * job );
    00970         void slotResultConflictCreatingDirs( KIO::Job * job );
    00971         void createNextDir();
    00972         void slotResultCopyingFiles( KIO::Job * job );
    00973         void slotResultConflictCopyingFiles( KIO::Job * job );
    00974         void copyNextFile();
    00975         void slotResultDeletingDirs( KIO::Job * job );
    00976         void deleteNextDir();
    00977         void skip( const KURL & sourceURL );
    00978
    00979     protected slots:
    00980         void slotStart();
    00981         void slotEntries( KIO::Job*, const KIO::UDSEntryList& list );
    00982         virtual void slotResult( KIO::Job *job );
    00986         void slotProcessedSize( KIO::Job*, KIO::filesize_t data_size );
    00990         void slotTotalSize( KIO::Job*, KIO::filesize_t size );
    00991
    00992         void slotReport();
    00993     private:
    00994         CopyMode m_mode;
    00995         bool m_asMethod;
    00996         enum { DEST_NOT_STATED, DEST_IS_DIR, DEST_IS_FILE, DEST_DOESNT_EXIST } destinationState;
    00997         enum { STATE_STATING, STATE_RENAMING, STATE_LISTING, STATE_CREATING_DIRS,
    00998                STATE_CONFLICT_CREATING_DIRS, STATE_COPYING_FILES, STATE_CONFLICT_COPYING_FILES,
    00999                STATE_DELETING_DIRS } state;
    01000         KIO::filesize_t m_totalSize;
    01001         KIO::filesize_t m_processedSize;
    01002         KIO::filesize_t m_fileProcessedSize;
    01003         int m_processedFiles;
    01004         int m_processedDirs;
    01005         QValueList<CopyInfo> files;
    01006         QValueList<CopyInfo> dirs;
    01007         KURL::List dirsToRemove;
    01008         KURL::List m_srcList;
    01009         KURL::List::Iterator m_currentStatSrc;
    01010         bool m_bCurrentSrcIsDir;
    01011         bool m_bCurrentOperationIsLink;
    01012         bool m_bSingleFileCopy;
    01013         bool m_bOnlyRenames;
    01014         KURL m_dest;
    01015         KURL m_currentDest;
    01016         //
    01017         QStringList m_skipList;
    01018         QStringList m_overwriteList;
    01019         bool m_bAutoSkip;
    01020         bool m_bOverwriteAll;
    01021         int m_conflictError;
    01022
    01023         QTimer *m_reportTimer;
    01024         //these both are used for progress dialog reporting
    01025         KURL m_currentSrcURL;
    01026         KURL m_currentDestURL;
    01027     protected:
    01028         virtual void virtual_hook( int id, void* data );
    01029     private:
    01030         class CopyJobPrivate* d;
    01031     };
    01032
    01036     class DeleteJob : public Job {
    01037     Q_OBJECT
    01038
    01039     public:
    01040         DeleteJob( const KURL::List& src, bool shred, bool showProgressInfo );
    01041
    01042         KURL::List urls() const { return m_srcList; }
    01043
    01044     signals:
    01045
    01046         void totalFiles( KIO::Job *, unsigned long files );
    01047         void totalDirs( KIO::Job *, unsigned long dirs );
    01048
    01049         void processedFiles( KIO::Job *, unsigned long files );
    01050         void processedDirs( KIO::Job *, unsigned long dirs );
    01051
    01052         void deleting( KIO::Job *, const KURL& file );
    01053
    01054     protected slots:
    01055         void slotStart();
    01056         void slotEntries( KIO::Job*, const KIO::UDSEntryList& list );
    01057         virtual void slotResult( KIO::Job *job );
    01058
    01062         void slotProcessedSize( KIO::Job*, KIO::filesize_t data_size );
    01063         void slotReport();
    01064
    01065     private:
    01066         void statNextSrc();
    01067         void deleteNextFile();
    01068         void deleteNextDir();
    01069
    01070     private:
    01071         enum { STATE_STATING, STATE_LISTING,
    01072                STATE_DELETING_FILES, STATE_DELETING_DIRS } state;
    01073         KIO::filesize_t m_totalSize;
    01074         KIO::filesize_t m_processedSize;
    01075         KIO::filesize_t m_fileProcessedSize;
    01076         int m_processedFiles;
    01077         int m_processedDirs;
    01078         int m_totalFilesDirs;
    01079         KURL m_currentURL;
    01080         KURL::List files;
    01081         KURL::List symlinks;
    01082         KURL::List dirs;
    01083         KURL::List m_srcList;
    01084         KURL::List::Iterator m_currentStat;
    01085         QStringList m_parentDirs;
    01086         bool m_shred;
    01087         QTimer *m_reportTimer;
    01088     protected:
    01090         virtual void virtual_hook( int id, void* data );
    01091     private:
    01092         class DeleteJobPrivate* d;
    01093     };
    01094
    01095 }
    01096
    01097 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:05 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001