home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kio / jobclasses.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-14  |  60.3 KB  |  1,864 lines

  1. // -*- c++ -*-
  2. /* This file is part of the KDE libraries
  3.     Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
  4.                        David Faure <faure@kde.org>
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.     Boston, MA 02110-1301, USA.
  20. */
  21.  
  22. #ifndef __kio_jobclasses_h__
  23. #define __kio_jobclasses_h__
  24.  
  25. #include <qobject.h>
  26. #include <qptrlist.h>
  27. #include <qstring.h>
  28. #include <qstringlist.h>
  29. #include <qguardedptr.h>
  30.  
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33.  
  34. #include <kurl.h>
  35. #include <kio/global.h>
  36.  
  37. class Observer;
  38. class QTimer;
  39.  
  40. #define KIO_COPYJOB_HAS_SETINTERACTIVE // new in 3.4. Used by kio_trash.
  41.  
  42. namespace KIO {
  43.  
  44.     class Slave;
  45.     class SlaveInterface;
  46.  
  47.  
  48.     /**
  49.      * The base class for all jobs.
  50.      * For all jobs created in an application, the code looks like
  51.      *
  52.      * \code
  53.      *   KIO::Job * job = KIO::someoperation( some parameters );
  54.      *   connect( job, SIGNAL( result( KIO::Job * ) ),
  55.      *            this, SLOT( slotResult( KIO::Job * ) ) );
  56.      * \endcode
  57.      *   (other connects, specific to the job)
  58.      *
  59.      * And slotResult is usually at least:
  60.      *
  61.      * \code
  62.      *  if ( job->error() )
  63.      *      job->showErrorDialog( this or 0L  );
  64.      * \endcode
  65.      * @see KIO::Scheduler
  66.      * @see KIO::Slave
  67.      */
  68.     class KIO_EXPORT Job : public QObject {
  69.         Q_OBJECT
  70.  
  71.     protected:
  72.         Job( bool showProgressInfo );
  73.  
  74.     public:
  75.         virtual ~Job();
  76.  
  77.         /**
  78.          * Abort this job.
  79.          * This kills all subjobs and deletes the job.
  80.      *
  81.          * @param quietly if false, Job will emit signal result
  82.          * and ask kio_uiserver to close the progress window.
  83.          * @p quietly is set to true for subjobs. Whether applications
  84.          * should call with true or false depends on whether they rely
  85.          * on result being emitted or not.
  86.          */
  87.         virtual void kill( bool quietly = true );
  88.  
  89.         /**
  90.      * Returns the error code, if there has been an error.
  91.          * Only call this method from the slot connected to result().
  92.          * @return the error code for this job, 0 if no error.
  93.          * Error codes are defined in KIO::Error.
  94.          */
  95.         int error() const { return m_error; }
  96.  
  97.         /**
  98.      * Returns the progress id for this job.
  99.          * @return the progress id for this job, as returned by uiserver
  100.          */
  101.         int progressId() const { return m_progressId; }
  102.  
  103.         /**
  104.      * Returns the error text if there has been an error.
  105.          * Only call if error is not 0.
  106.          * This is really internal, better use errorString() or errorDialog().
  107.      *
  108.          * @return a string to help understand the error, usually the url
  109.          * related to the error. Only valid if error() is not 0.
  110.          */
  111.         const QString & errorText() const { return m_errorText; }
  112.  
  113.         /**
  114.          * Converts an error code and a non-i18n error message into an
  115.          * error message in the current language. The low level (non-i18n)
  116.          * error message (usually a url) is put into the translated error
  117.          * message using %1.
  118.          *
  119.          * Example for errid == ERR_CANNOT_OPEN_FOR_READING:
  120.      * \code
  121.          *   i18n( "Could not read\n%1" ).arg( errortext );
  122.      * \endcode
  123.          * Use this to display the error yourself, but for a dialog box
  124.          * use Job::showErrorDialog. Do not call it if error()
  125.      * is not 0.
  126.      * @return the error message and if there is no error, a message
  127.      *         telling the user that the app is broken, so check with
  128.      *         error() whether there is an error
  129.          */
  130.         QString errorString() const;
  131.  
  132.         /**
  133.          * Converts an error code and a non-i18n error message into i18n
  134.          * strings suitable for presentation in a detailed error message box.
  135.          *
  136.          * @param reqUrl the request URL that generated this error message
  137.          * @param method the method that generated this error message
  138.          * (unimplemented)
  139.          * @return the following strings: caption, error + description,
  140.      *         causes+solutions
  141.          */
  142.         QStringList detailedErrorStrings(const KURL *reqUrl = 0L,
  143.                                          int method = -1) const;
  144.  
  145.         /**
  146.          * Display a dialog box to inform the user of the error given by
  147.          * this job.
  148.          * Only call if error is not 0, and only in the slot connected
  149.          * to result.
  150.          * @param parent the parent widget for the dialog box, can be 0 for
  151.      *        top-level
  152.          */
  153.         void showErrorDialog( QWidget * parent = 0L );
  154.  
  155.         /**
  156.          * Enable or disable the automatic error handling. When automatic
  157.          * error handling is enabled and an error occurs, then showErrorDialog()
  158.          * is called with the specified @p parentWidget (if supplied) , right before
  159.          * the emission of the result signal.
  160.          *
  161.          * The default is false.
  162.          *
  163.          * @param enable enable or disable automatic error handling
  164.          * @param parentWidget the parent widget, passed to showErrorDialog.
  165.      *        Can be 0 for top-level
  166.      * @see isAutoErrorHandlingEnabled(), showErrorDialog()
  167.          */
  168.         void setAutoErrorHandlingEnabled( bool enable, QWidget *parentWidget = 0 );
  169.  
  170.         /**
  171.          * Returns whether automatic error handling is enabled or disabled.
  172.      * @return true if automatic error handling is enabled
  173.      * @see setAutoErrorHandlingEnabled()
  174.          */
  175.         bool isAutoErrorHandlingEnabled() const;
  176.  
  177.         /**
  178.          * Enable or disable the automatic warning handling. When automatic
  179.          * warning handling is enabled and an error occurs, then a message box
  180.          * is displayed with the warning message
  181.          *
  182.          * The default is true.
  183.          *
  184.          * See also isAutoWarningHandlingEnabled , showErrorDialog
  185.          *
  186.          * @param enable enable or disable automatic warning handling
  187.          * @see isAutoWarningHandlingEnabled()
  188.          * @since 3.5
  189.          */
  190.         void setAutoWarningHandlingEnabled( bool enable );
  191.  
  192.         /**
  193.          * Returns whether automatic warning handling is enabled or disabled.
  194.          * See also setAutoWarningHandlingEnabled .
  195.          * @return true if automatic warning handling is enabled
  196.          * @see setAutoWarningHandlingEnabled()
  197.          * @since 3.5
  198.          */
  199.         bool isAutoWarningHandlingEnabled() const;
  200.  
  201.         /**
  202.          * Enable or disable the message display from the job.
  203.          *
  204.          * The default is true.
  205.          * @param enable enable or disable message display
  206.          * @since 3.4.1
  207.          */
  208.         void setInteractive(bool enable);
  209.  
  210.         /**
  211.          * Returns whether message display is enabled or disabled.
  212.          * @return true if message display is enabled
  213.          * @see setInteractive()
  214.          * @since 3.4.1
  215.          */
  216.         bool isInteractive() const;
  217.         /**
  218.          * Associate this job with a window given by @p window.
  219.      * @param window the window to associate to
  220.      * @see window()
  221.          */
  222.         void setWindow(QWidget *window);
  223.  
  224.         /**
  225.          * Returns the window this job is associated with.
  226.      * @return the associated window
  227.      * @see setWindow()
  228.          */
  229.         QWidget *window() const;
  230.  
  231.         /**
  232.          * Updates the last user action timestamp to the given time.
  233.          * See KApplication::updateUserTimestamp() .
  234.          * @since 3.5.6
  235.          */
  236.         void updateUserTimestamp( unsigned long time );
  237.  
  238.         /**
  239.          * Set the parent Job.
  240.          * One example use of this is when FileCopyJob calls open_RenameDlg,
  241.          * it must pass the correct progress ID of the parent CopyJob
  242.          * (to hide the progress dialog).
  243.      * You can set the parent job only once. By default a job does not
  244.      * have a parent job.
  245.      * @param parentJob the new parent job
  246.          * @since 3.1
  247.          */
  248.         void setParentJob( Job* parentJob );
  249.  
  250.         /**
  251.      * Returns the parent job, if there is one.
  252.      * @return the parent job, or 0 if there is none
  253.          * @see setParentJob
  254.          * @since 3.1
  255.          */
  256.         Job* parentJob() const;
  257.  
  258.         /**
  259.          * Set meta data to be sent to the slave, replacing existing
  260.      * meta data.
  261.      * @param metaData the meta data to set
  262.      * @see addMetaData()
  263.      * @see mergeMetaData()
  264.          */
  265.         void setMetaData( const KIO::MetaData &metaData);
  266.  
  267.         /**
  268.          * Add key/value pair to the meta data that is sent to the slave.
  269.      * @param key the key of the meta data
  270.      * @param value the value of the meta data
  271.      * @see setMetaData()
  272.      * @see mergeMetaData()
  273.          */
  274.         void addMetaData(const QString &key, const QString &value);
  275.  
  276.         /**
  277.          * Add key/value pairs to the meta data that is sent to the slave.
  278.          * If a certain key already existed, it will be overridden.
  279.      * @param values the meta data to add
  280.      * @see setMetaData()
  281.      * @see mergeMetaData()
  282.          */
  283.         void addMetaData(const QMap<QString,QString> &values);
  284.  
  285.         /**
  286.          * Add key/value pairs to the meta data that is sent to the slave.
  287.          * If a certain key already existed, it will remain unchanged.
  288.      * @param values the meta data to merge
  289.      * @see setMetaData()
  290.      * @see addMetaData()
  291.          */
  292.         void mergeMetaData(const QMap<QString,QString> &values);
  293.  
  294.         /**
  295.          * @internal. For the scheduler. Do not use.
  296.          */
  297.         MetaData outgoingMetaData() const;
  298.  
  299.         /**
  300.          * Get meta data received from the slave.
  301.          * (Valid when first data is received and/or slave is finished)
  302.      * @return the job's meta data
  303.          */
  304.         MetaData metaData() const;
  305.  
  306.         /**
  307.          * Query meta data received from the slave.
  308.          * (Valid when first data is received and/or slave is finished)
  309.      * @param key the key of the meta data to retrieve
  310.      * @return the value of the meta data, or QString::null if the
  311.      *         @p key does not exist
  312.          */
  313.         QString queryMetaData(const QString &key);
  314.  
  315.         /**
  316.          * Returns the processed size for this job.
  317.          * @see processedSize
  318.          * @since 3.2
  319.          */
  320.         KIO::filesize_t getProcessedSize();
  321.  
  322.     signals:
  323.         /**
  324.          * Emitted when the job is finished, in any case (completed, canceled,
  325.          * failed...). Use error to know the result.
  326.      * @param job the job that emitted this signal
  327.          */
  328.         void result( KIO::Job *job );
  329.  
  330.         /**
  331.          * @deprecated. Don't use !
  332.          * Emitted when the job is canceled.
  333.          * Signal result() is emitted as well, and error() is,
  334.          * in this case, ERR_USER_CANCELED.
  335.      * @param job the job that emitted this signal
  336.          */
  337.         void canceled( KIO::Job *job );
  338.  
  339.         /**
  340.          * Emitted to display information about this job, as sent by the slave.
  341.          * Examples of message are "Resolving host", "Connecting to host...", etc.
  342.      * @param job the job that emitted this signal
  343.      * @param msg the info message
  344.          */
  345.         void infoMessage( KIO::Job *job, const QString & msg );
  346.         // KDE4: Separate rich-text string from plain-text string, for different widgets.
  347.  
  348.         /**
  349.          * Emitted to display a warning about this job, as sent by the slave.
  350.          * @param job the job that emitted this signal
  351.          * @param msg the info message
  352.          * @since 3.5
  353.          */
  354.         void warning( KIO::Job *job, const QString & msg );
  355.         // KDE4: Separate rich-text string from plain-text string, for different widgets.
  356.  
  357.         /**
  358.          * Emitted when the slave successfully connected to the host.
  359.          * There is no guarantee the slave will send this, and this is
  360.          * currently unused (in the applications).
  361.      * @param job the job that emitted this signal
  362.          */
  363.         void connected( KIO::Job *job );
  364.  
  365.         /**
  366.          * Progress signal showing the overall progress of the job
  367.          * This is valid for any kind of job, and allows using a
  368.          * a progress bar very easily. (see KProgress).
  369.      * Note that this signal is not emitted for finished jobs.
  370.      * @param job the job that emitted this signal
  371.      * @param percent the percentage
  372.          */
  373.         void percent( KIO::Job *job, unsigned long percent );
  374.  
  375.         /**
  376.          * Emitted when we know the size of this job (data size for transfers,
  377.          * number of entries for listings).
  378.      * @param job the job that emitted this signal
  379.      * @param size the total size in bytes
  380.          */
  381.         void totalSize( KIO::Job *job, KIO::filesize_t size );
  382.  
  383.         /**
  384.          * Regularly emitted to show the progress of this job
  385.          * (current data size for transfers, entries listed).
  386.      * @param job the job that emitted this signal
  387.      * @param size the processed size in bytes
  388.          */
  389.         void processedSize( KIO::Job *job, KIO::filesize_t size );
  390.  
  391.         /**
  392.          * Emitted to display information about the speed of this job.
  393.      * @param job the job that emitted this signal
  394.      * @param speed the speed in bytes/s
  395.          */
  396.         void speed( KIO::Job *job, unsigned long speed );
  397.  
  398.     protected slots:
  399.         /**
  400.          * Called whenever a subjob finishes.
  401.          * Default implementation checks for errors and propagates
  402.          * to parent job, then calls removeSubjob.
  403.          * Override if you don't want subjobs errors to be propagated.
  404.      * @param job the subjob
  405.      * @see result()
  406.          */
  407.         virtual void slotResult( KIO::Job *job );
  408.  
  409.         /**
  410.          * Forward signal from subjob.
  411.      * @param job the subjob
  412.      * @param speed the speed in bytes/s
  413.      * @see speed()
  414.          */
  415.         void slotSpeed( KIO::Job *job, unsigned long speed );
  416.         /**
  417.          * Forward signal from subjob.
  418.      * @param job the subjob
  419.      * @param msg the info message
  420.      * @see infoMessage()
  421.          */
  422.         void slotInfoMessage( KIO::Job *job, const QString &msg );
  423.  
  424.         /**
  425.          * Remove speed information.
  426.          */
  427.         void slotSpeedTimeout();
  428.  
  429.     protected:
  430.         /**
  431.          * Add a job that has to be finished before a result
  432.          * is emitted. This has obviously to be called before
  433.          * the finish signal is emitted by the slave.
  434.          *
  435.      * @param job the subjob to add
  436.          * @param inheritMetaData if true, the subjob will
  437.          * inherit the meta data from this job.
  438.          */
  439.         virtual void addSubjob( Job *job, bool inheritMetaData=true );
  440.  
  441.         /**
  442.          * Mark a sub job as being done. If it's the last to
  443.          * wait on the job will emit a result - jobs with
  444.          * two steps might want to override slotResult
  445.          * in order to avoid calling this method.
  446.      *
  447.      * @param job the subjob to add
  448.          */
  449.         virtual void removeSubjob( Job *job );
  450.         /**
  451.          * Overloaded version of removeSubjob
  452.          * @param job the subjob to remove
  453.          * @param mergeMetaData if set, the metadata received by the subjob is
  454.          *                      merged into this job.
  455.          * @param emitResultIfLast if this was the last subjob, emit result,
  456.          *                         i.e. terminate this job.
  457.          */
  458.         void removeSubjob( Job *job, bool mergeMetaData, bool emitResultIfLast ); // KDE4: merge with above, with =true to both
  459.  
  460.         /**
  461.          * Utility function for inherited jobs.
  462.          * Emits the percent signal if bigger than m_percent,
  463.          * after calculating it from the parameters.
  464.      *
  465.      * @param processedSize the processed size in bytes
  466.      * @param totalSize the total size in bytes
  467.          */
  468.         void emitPercent( KIO::filesize_t processedSize, KIO::filesize_t totalSize );
  469.  
  470.         /**
  471.          * Utility function for inherited jobs.
  472.          * Emits the speed signal and starts the timer for removing that info
  473.      *
  474.      * @param speed the speed in bytes/s
  475.          */
  476.         void emitSpeed( unsigned long speed );
  477.  
  478.         /**
  479.          * Utility function to emit the result signal, and suicide this job.
  480.          * It first tells the observer to hide the progress dialog for this job.
  481.          */
  482.         void emitResult();
  483.  
  484.         /**
  485.          * Set the processed size, does not emit processedSize
  486.          * @since 3.2
  487.          */
  488.         void setProcessedSize(KIO::filesize_t size);
  489.  
  490.         /**
  491.          * @internal
  492.          */
  493.         unsigned long userTimestamp() const;
  494.  
  495.         /**
  496.          * @internal
  497.          * Some extra storage space for jobs that don't have their own
  498.          * private d pointer.
  499.          */
  500.         enum { EF_TransferJobAsync    = (1 << 0),
  501.                EF_TransferJobNeedData = (1 << 1),
  502.                EF_TransferJobDataSent = (1 << 2),
  503.                EF_ListJobUnrestricted = (1 << 3) };
  504.         int &extraFlags();
  505.  
  506.         QPtrList<Job> subjobs;
  507.         int m_error;
  508.         QString m_errorText;
  509.         unsigned long m_percent;
  510.         int m_progressId; // for uiserver
  511.         QTimer *m_speedTimer;
  512.         QGuardedPtr<QWidget> m_window;
  513.         MetaData m_outgoingMetaData;
  514.         MetaData m_incomingMetaData;
  515.     protected:
  516.     virtual void virtual_hook( int id, void* data );
  517.     private:
  518.         class JobPrivate;
  519.         JobPrivate *d;
  520.     };
  521.  
  522.     /**
  523.      * A simple job (one url and one command).
  524.      * This is the base class for all jobs that are scheduled.
  525.      * Other jobs are high-level jobs (CopyJob, DeleteJob, FileCopyJob...)
  526.      * that manage subjobs but aren't scheduled directly.
  527.      */
  528.     class KIO_EXPORT SimpleJob : public KIO::Job {
  529.     Q_OBJECT
  530.  
  531.     public:
  532.         /**
  533.      * Creates a new simple job. You don't need to use this constructor,
  534.      * unless you create a new job that inherits from SimpleJob.
  535.      * @param url the url of the job
  536.      * @param command the command of the job
  537.      * @param packedArgs the arguments
  538.      * @param showProgressInfo true to show progress information to the user
  539.      */
  540.         SimpleJob(const KURL& url, int command, const QByteArray &packedArgs,
  541.                   bool showProgressInfo);
  542.  
  543.         ~SimpleJob();
  544.  
  545.         /**
  546.      * Returns the SimpleJob's URL
  547.      * @return the url
  548.      */
  549.         const KURL& url() const { return m_url; }
  550.  
  551.         /**
  552.          * Abort job.
  553.          * This kills all subjobs and deletes the job.
  554.          * @param quietly if true, Job will emit signal result
  555.          * Should only be set to false when the user kills the job
  556.          * (from kio_uiserver), not when you want to abort a job.
  557.          */
  558.         virtual void kill( bool quietly = true );
  559.  
  560.         /**
  561.          * Abort job.
  562.          * Suspends slave to be reused by another job for the same request.
  563.          */
  564.         virtual void putOnHold();
  565.  
  566.         /**
  567.          * Discard suspended slave.
  568.          */
  569.         static void removeOnHold();
  570.  
  571.         /**
  572.          * @internal
  573.          * Called by the scheduler when a slave gets to
  574.          * work on this job.
  575.          **/
  576.         virtual void start( Slave *slave );
  577.  
  578.         /**
  579.          * @internal
  580.          * Called to detach a slave from a job.
  581.          **/
  582.         void slaveDone();
  583.  
  584.         /**
  585.          * @internal
  586.          * Slave in use by this job.
  587.          */
  588.         Slave *slave() const { return m_slave; }
  589.  
  590.         /**
  591.          * @internal
  592.          */
  593.         int command() const { return m_command; }
  594.  
  595.     public slots:
  596.         /**
  597.          * Forward signal from the slave
  598.          * Can also be called by the parent job, when it knows the size.
  599.      * @param data_size the total size
  600.          */
  601.         void slotTotalSize( KIO::filesize_t data_size );
  602.  
  603.     protected slots:
  604.         /**
  605.          * Called when the slave marks the job
  606.          * as finished.
  607.          */
  608.         virtual void slotFinished( );
  609.  
  610.         /**
  611.          * @internal
  612.          * Called on a slave's warning.
  613.          */
  614.         void slotWarning( const QString & ); // KDE4: make virtual
  615.  
  616.         /**
  617.          * Called on a slave's info message.
  618.      * @param s the info message
  619.      * @see infoMessage()
  620.          */
  621.         void slotInfoMessage( const QString &s ); // KDE4: make virtual
  622.  
  623.         /**
  624.          * Called on a slave's connected signal.
  625.      * @see connected()
  626.          */
  627.         void slotConnected();
  628.  
  629.         /**
  630.          * Forward signal from the slave.
  631.      * @param data_size the processed size in bytes
  632.      * @see processedSize()
  633.          */
  634.         void slotProcessedSize( KIO::filesize_t data_size );
  635.         /**
  636.          * Forward signal from the slave.
  637.      * @param speed the speed in bytes/s
  638.      * @see speed()
  639.          */
  640.         void slotSpeed( unsigned long speed );
  641.  
  642.         /**
  643.          * MetaData from the slave is received.
  644.      * @param _metaData the meta data
  645.      * @see metaData()
  646.          */
  647.         virtual void slotMetaData( const KIO::MetaData &_metaData);
  648.  
  649.     public slots:
  650.         /**
  651.          * @internal
  652.          * Called on a slave's error.
  653.          * Made public for the scheduler.
  654.          */
  655.         virtual void slotError( int , const QString & );
  656.  
  657.     protected slots:
  658.         /**
  659.          * @internal
  660.          */
  661.         void slotNeedProgressId();
  662.  
  663.     protected:
  664.         Slave * m_slave;
  665.         QByteArray m_packedArgs;
  666.         KURL m_url;
  667.         KURL m_subUrl;
  668.         int m_command;
  669.         KIO::filesize_t m_totalSize;
  670.     protected:
  671.     virtual void virtual_hook( int id, void* data );
  672.     /*
  673.      * Allow jobs that inherit SimpleJob and are aware
  674.      * of redirections to store the SSL session used.
  675.      * Retrieval is handled by SimpleJob::start
  676.      * @param m_redirectionURL Reference to redirection URL,
  677.      * used instead of m_url if not empty
  678.      */
  679.     void storeSSLSessionFromJob(const KURL &m_redirectionURL);
  680.     private:
  681.     class SimpleJobPrivate* d;
  682.     };
  683.  
  684.     /**
  685.      * A KIO job that retrieves information about a file or directory.
  686.      * @see KIO::stat()
  687.      */
  688.     class KIO_EXPORT StatJob : public SimpleJob {
  689.  
  690.     Q_OBJECT
  691.  
  692.     public:
  693.         /**
  694.      * Do not use this constructor to create a StatJob, use KIO::stat() instead.
  695.      * @param url the url of the file or directory to check
  696.      * @param command the command to issue
  697.      * @param packedArgs the arguments
  698.      * @param showProgressInfo true to show progress information to the user
  699.      */
  700.         StatJob(const KURL& url, int command, const QByteArray &packedArgs, bool showProgressInfo);
  701.  
  702.         /**
  703.      * A stat() can have two meanings. Either we want to read from this URL,
  704.          * or to check if we can write to it. First case is "source", second is "dest".
  705.          * It is necessary to know what the StatJob is for, to tune the kioslave's behavior
  706.          * (e.g. with FTP).
  707.      * @param source true for "source" mode, false for "dest" mode
  708.          */
  709.         void setSide( bool source ) { m_bSource = source; }
  710.  
  711.         /**
  712.          * Selects the level of @p details we want.
  713.          * By default this is 2 (all details wanted, including modification time, size, etc.),
  714.          * setDetails(1) is used when deleting: we don't need all the information if it takes
  715.          * too much time, no need to follow symlinks etc.
  716.          * setDetails(0) is used for very simple probing: we'll only get the answer
  717.          * "it's a file or a directory, or it doesn't exist". This is used by KRun.
  718.      * @param details 2 for all details, 1 for simple, 0 for very simple
  719.          */
  720.         void setDetails( short int details ) { m_details = details; }
  721.  
  722.         /**
  723.          * Call this in the slot connected to result,
  724.          * and only after making sure no error happened.
  725.      * @return the result of the stat
  726.          */
  727.         const UDSEntry & statResult() const { return m_statResult; }
  728.  
  729.         /**
  730.      * @internal
  731.          * Called by the scheduler when a @p slave gets to
  732.          * work on this job.
  733.      * @param slave the slave that starts working on this job
  734.          */
  735.         virtual void start( Slave *slave );
  736.  
  737.     signals:
  738.         /**
  739.          * Signals a redirection.
  740.          * Use to update the URL shown to the user.
  741.          * The redirection itself is handled internally.
  742.      * @param job the job that is redirected
  743.      * @param url the new url
  744.          */
  745.         void redirection( KIO::Job *job, const KURL &url );
  746.  
  747.         /**
  748.          * Signals a permanent redirection.
  749.          * The redirection itself is handled internally.
  750.      * @param job the job that is redirected
  751.      * @param fromUrl the original URL
  752.      * @param toUrl the new URL
  753.      * @since 3.1
  754.          */
  755.         void permanentRedirection( KIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  756.  
  757.     protected slots:
  758.         void slotStatEntry( const KIO::UDSEntry & entry );
  759.         void slotRedirection( const KURL &url);
  760.         virtual void slotFinished();
  761.         virtual void slotMetaData( const KIO::MetaData &_metaData);
  762.  
  763.     protected:
  764.         UDSEntry m_statResult;
  765.         KURL m_redirectionURL;
  766.         bool m_bSource;
  767.         short int m_details;
  768.     protected:
  769.     virtual void virtual_hook( int id, void* data );
  770.     private:
  771.         class StatJobPrivate;
  772.         StatJobPrivate *d;
  773.     };
  774.  
  775.     /**
  776.      * A KIO job that creates a directory
  777.      * @see KIO::mkdir()
  778.      * @since 3.3
  779.      */
  780.     class KIO_EXPORT MkdirJob : public SimpleJob {
  781.  
  782.     Q_OBJECT
  783.  
  784.     public:
  785.         /**
  786.      * Do not use this constructor to create a MkdirJob, use KIO::mkdir() instead.
  787.      * @param url the url of the file or directory to check
  788.      * @param command the command to issue
  789.      * @param packedArgs the arguments
  790.      * @param showProgressInfo true to show progress information to the user
  791.      */
  792.         MkdirJob(const KURL& url, int command, const QByteArray &packedArgs, bool showProgressInfo);
  793.  
  794.         /**
  795.      * @internal
  796.          * Called by the scheduler when a @p slave gets to
  797.          * work on this job.
  798.      * @param slave the slave that starts working on this job
  799.          */
  800.         virtual void start( Slave *slave );
  801.  
  802.     signals:
  803.         /**
  804.          * Signals a redirection.
  805.          * Use to update the URL shown to the user.
  806.          * The redirection itself is handled internally.
  807.      * @param job the job that is redirected
  808.      * @param url the new url
  809.          */
  810.         void redirection( KIO::Job *job, const KURL &url );
  811.  
  812.         /**
  813.          * Signals a permanent redirection.
  814.          * The redirection itself is handled internally.
  815.      * @param job the job that is redirected
  816.      * @param fromUrl the original URL
  817.      * @param toUrl the new URL
  818.          */
  819.         void permanentRedirection( KIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  820.  
  821.     protected slots:
  822.         void slotRedirection( const KURL &url);
  823.         virtual void slotFinished();
  824.  
  825.     protected:
  826.         KURL m_redirectionURL;
  827.  
  828.     protected:
  829.     virtual void virtual_hook( int id, void* data );
  830.     private:
  831.         class MkdirJobPrivate;
  832.         MkdirJobPrivate *d;
  833.     };
  834.  
  835.     /**
  836.      * @internal
  837.      * Used for direct copy from or to the local filesystem (i.e. SlaveBase::copy())
  838.      */
  839.     class KIO_EXPORT DirectCopyJob : public SimpleJob {
  840.     Q_OBJECT
  841.  
  842.     public:
  843.         /**
  844.          * Do not create a DirectCopyJob. Use KIO::copy() or KIO::file_copy() instead.
  845.          */
  846.         DirectCopyJob(const KURL& url, int command, const QByteArray &packedArgs,
  847.                       bool showProgressInfo);
  848.         /**
  849.      * @internal
  850.          * Called by the scheduler when a @p slave gets to
  851.          * work on this job.
  852.      * @param slave the slave that starts working on this job
  853.          */
  854.         virtual void start(Slave *slave);
  855.  
  856.     signals:
  857.         /**
  858.          * @internal
  859.          * Emitted if the job found an existing partial file
  860.          * and supports resuming. Used by FileCopyJob.
  861.          */
  862.         void canResume( KIO::Job *job, KIO::filesize_t offset );
  863.  
  864.     private slots:
  865.         void slotCanResume( KIO::filesize_t offset );
  866.     };
  867.  
  868.  
  869.     /**
  870.      * The transfer job pumps data into and/or out of a Slave.
  871.      * Data is sent to the slave on request of the slave ( dataReq).
  872.      * If data coming from the slave can not be handled, the
  873.      * reading of data from the slave should be suspended.
  874.      */
  875.     class KIO_EXPORT TransferJob : public SimpleJob {
  876.     Q_OBJECT
  877.  
  878.     public:
  879.        /**
  880.     * Do not create a TransferJob. Use KIO::get() or KIO::put()
  881.     * instead.
  882.     * @param url the url to get or put
  883.     * @param command the command to issue
  884.     * @param packedArgs the arguments
  885.     * @param _staticData additional data to transmit (e.g. in a HTTP Post)
  886.     * @param showProgressInfo true to show progress information to the user
  887.     */
  888.         TransferJob(const KURL& url, int command,
  889.                     const QByteArray &packedArgs,
  890.                     const QByteArray &_staticData,
  891.                     bool showProgressInfo);
  892.  
  893.         /**
  894.      * @internal
  895.          * Called by the scheduler when a @p slave gets to
  896.          * work on this job.
  897.      * @param slave the slave that starts working on this job
  898.          */
  899.         virtual void start(Slave *slave);
  900.  
  901.         /**
  902.          * Called when m_subJob finishes.
  903.      * @param job the job that finished
  904.          */
  905.         virtual void slotResult( KIO::Job *job );
  906.  
  907.         /**
  908.          * Flow control. Suspend data processing from the slave.
  909.          */
  910.         void suspend();
  911.  
  912.         /**
  913.          * Flow control. Resume data processing from the slave.
  914.          */
  915.         void resume();
  916.  
  917.         /**
  918.          * Flow control.
  919.      * @return true if the job is suspended
  920.          */
  921.     bool isSuspended() const { return m_suspended; }
  922.  
  923.  
  924.         /**
  925.      * Checks whether we got an error page. This currently only happens
  926.      * with HTTP urls. Call this from your slot connected to result().
  927.      *
  928.          * @return true if we got an (HTML) error page from the server
  929.          * instead of what we asked for.
  930.          */
  931.         bool isErrorPage() const { return m_errorPage; }
  932.  
  933.         /**
  934.          * Enable the async data mode.
  935.          * When async data is enabled, data should be provided to the job by
  936.          * calling sendAsyncData() instead of returning data in the
  937.          * dataReq() signal.
  938.          * @since 3.2
  939.          */
  940.         void setAsyncDataEnabled(bool enabled);
  941.  
  942.         /**
  943.          * Provide data to the job when async data is enabled.
  944.          * Should be called exactly once after receiving a dataReq signal
  945.          * Sending an empty block indicates end of data.
  946.          * @since 3.2
  947.          */
  948.         void sendAsyncData(const QByteArray &data);
  949.  
  950.         /**
  951.          * When enabled, the job reports the amount of data that has been sent,
  952.          * instead of the amount of data that that has been received.
  953.          * @see slotProcessedSize
  954.          * @see slotSpeed
  955.          * @since 3.2
  956.          */
  957.         void setReportDataSent(bool enabled);
  958.  
  959.         /**
  960.          *  Returns whether the job reports the amount of data that has been
  961.          *  sent (true), or whether the job reports the amount of data that
  962.          * has been received (false)
  963.          * @since 3.2
  964.          */
  965.         bool reportDataSent();
  966.  
  967.     signals:
  968.         /**
  969.          * Data from the slave has arrived.
  970.          * @param job the job that emitted this signal
  971.          * @param data data received from the slave.
  972.          *
  973.          * End of data (EOD) has been reached if data.size() == 0, however, you
  974.          * should not be certain of data.size() == 0 ever happening (e.g. in case
  975.          * of an error), so you should rely on result() instead.
  976.          */
  977.         void data( KIO::Job *job, const QByteArray &data );
  978.  
  979.         /**
  980.          * Request for data.
  981.          * Please note, that you shouldn't put too large chunks
  982.          * of data in it as this requires copies within the frame
  983.          * work, so you should rather split the data you want
  984.          * to pass here in reasonable chunks (about 1MB maximum)
  985.          *
  986.      * @param job the job that emitted this signal
  987.          * @param data buffer to fill with data to send to the
  988.          * slave. An empty buffer indicates end of data. (EOD)
  989.          */
  990.         void dataReq( KIO::Job *job, QByteArray &data );
  991.  
  992.         /**
  993.          * Signals a redirection.
  994.          * Use to update the URL shown to the user.
  995.          * The redirection itself is handled internally.
  996.      * @param job the job that emitted this signal
  997.      * @param url the new URL
  998.          */
  999.         void redirection( KIO::Job *job, const KURL &url );
  1000.  
  1001.         /**
  1002.          * Signals a permanent redirection.
  1003.          * The redirection itself is handled internally.
  1004.      * @param job the job that emitted this signal
  1005.      * @param fromUrl the original URL
  1006.      * @param toUrl the new URL
  1007.      * @since 3.1
  1008.          */
  1009.         void permanentRedirection( KIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  1010.  
  1011.         /**
  1012.          * Mimetype determined.
  1013.      * @param job the job that emitted this signal
  1014.      * @param type the mime type
  1015.          */
  1016.         void mimetype( KIO::Job *job, const QString &type );
  1017.  
  1018.         /**
  1019.          * @internal
  1020.          * Emitted if the "put" job found an existing partial file
  1021.          * (in which case offset is the size of that file)
  1022.          * and emitted by the "get" job if it supports resuming to
  1023.          * the given offset - in this case @p offset is unused)
  1024.          */
  1025.         void canResume( KIO::Job *job, KIO::filesize_t offset );
  1026.  
  1027.  
  1028.     protected slots:
  1029.         virtual void slotRedirection( const KURL &url);
  1030.         virtual void slotFinished();
  1031.         virtual void slotData( const QByteArray &data);
  1032.         virtual void slotDataReq();
  1033.         virtual void slotMimetype( const QString &mimetype );
  1034.         virtual void slotNeedSubURLData();
  1035.         virtual void slotSubURLData(KIO::Job*, const QByteArray &);
  1036.         virtual void slotMetaData( const KIO::MetaData &_metaData);
  1037.         void slotErrorPage();
  1038.         void slotCanResume( KIO::filesize_t offset );
  1039.         void slotPostRedirection();
  1040.  
  1041.     protected:
  1042.         bool m_suspended;
  1043.         bool m_errorPage;
  1044.         QByteArray staticData;
  1045.         KURL m_redirectionURL;
  1046.         KURL::List m_redirectionList;
  1047.         QString m_mimetype;
  1048.         TransferJob *m_subJob;
  1049.     protected:
  1050.     virtual void virtual_hook( int id, void* data );
  1051.     private:
  1052.     class TransferJobPrivate *d;
  1053.     };
  1054.  
  1055.     /**
  1056.      * StoredTransferJob is a TransferJob (for downloading or uploading data) that
  1057.      * also stores a QByteArray with the data, making it simpler to use than the
  1058.      * standard TransferJob.
  1059.      *
  1060.      * For KIO::storedGet it puts the data into the member QByteArray, so the user
  1061.      * of this class can get hold of the whole data at once by calling data()
  1062.      * when the result signal is emitted.
  1063.      * You should only use StoredTransferJob to download data if you cannot
  1064.      * process the data by chunks while it's being downloaded, since storing
  1065.      * everything in a QByteArray can potentially require a lot of memory.
  1066.      *
  1067.      * For KIO::storedPut the user of this class simply provides the bytearray from
  1068.      * the start, and the job takes care of uploading it.
  1069.      * You should only use StoredTransferJob to upload data if you cannot
  1070.      * provide the in chunks while it's being uploaded, since storing
  1071.      * everything in a QByteArray can potentially require a lot of memory.
  1072.      *
  1073.      * @since 3.3
  1074.      */
  1075.     class KIO_EXPORT StoredTransferJob : public KIO::TransferJob {
  1076.         Q_OBJECT
  1077.  
  1078.     public:
  1079.        /**
  1080.     * Do not create a StoredTransferJob. Use storedGet() or storedPut()
  1081.     * instead.
  1082.     * @param url the url to get or put
  1083.     * @param command the command to issue
  1084.     * @param packedArgs the arguments
  1085.     * @param _staticData additional data to transmit (e.g. in a HTTP Post)
  1086.     * @param showProgressInfo true to show progress information to the user
  1087.     */
  1088.         StoredTransferJob(const KURL& url, int command,
  1089.                           const QByteArray &packedArgs,
  1090.                           const QByteArray &_staticData,
  1091.                           bool showProgressInfo);
  1092.  
  1093.         /**
  1094.          * Set data to be uploaded. This is for put jobs.
  1095.          * Automatically called by KIO::storedPut(const QByteArray &, ...),
  1096.          * do not call this yourself.
  1097.          */
  1098.         void setData( const QByteArray& arr );
  1099.  
  1100.         /**
  1101.          * Get hold of the downloaded data. This is for get jobs.
  1102.          * You're supposed to call this only from the slot connected to the result() signal.
  1103.          */
  1104.         QByteArray data() const { return m_data; }
  1105.  
  1106.     private slots:
  1107.         void slotStoredData( KIO::Job *job, const QByteArray &data );
  1108.         void slotStoredDataReq( KIO::Job *job, QByteArray &data );
  1109.     private:
  1110.         QByteArray m_data;
  1111.         int m_uploadOffset;
  1112.     };
  1113.  
  1114.     /**
  1115.      * The MultiGetJob is a TransferJob that allows you to get
  1116.      * several files from a single server. Don't create directly,
  1117.      * but use KIO::multi_get() instead.
  1118.      * @see KIO::multi_get()
  1119.      */
  1120.     class KIO_EXPORT MultiGetJob : public TransferJob {
  1121.     Q_OBJECT
  1122.  
  1123.     public:
  1124.         /**
  1125.      * Do not create a MultiGetJob directly, use KIO::multi_get()
  1126.      * instead.
  1127.      *
  1128.      * @param url the first url to get
  1129.      * @param showProgressInfo true to show progress information to the user
  1130.      */
  1131.         MultiGetJob(const KURL& url, bool showProgressInfo);
  1132.  
  1133.         /**
  1134.      * @internal
  1135.          * Called by the scheduler when a @p slave gets to
  1136.          * work on this job.
  1137.      * @param slave the slave that starts working on this job
  1138.          */
  1139.          virtual void start(Slave *slave);
  1140.  
  1141.     /**
  1142.      * Get an additional file.
  1143.      *
  1144.      * @param id the id of the file
  1145.      * @param url the url of the file to get
  1146.      * @param metaData the meta data for this request
  1147.      */
  1148.         void get(long id, const KURL &url, const MetaData &metaData);
  1149.  
  1150.     signals:
  1151.         /**
  1152.          * Data from the slave has arrived.
  1153.      * @param id the id of the request
  1154.          * @param data data received from the slave.
  1155.          * End of data (EOD) has been reached if data.size() == 0
  1156.          */
  1157.         void data( long id, const QByteArray &data);
  1158.  
  1159.         /**
  1160.          * Mimetype determined
  1161.      * @param id the id of the request
  1162.      * @param type the mime type
  1163.          */
  1164.         void mimetype( long id, const QString &type );
  1165.  
  1166.         /**
  1167.          * File transfer completed.
  1168.          *
  1169.          * When all files have been processed, result(KIO::Job *) gets
  1170.          * emitted.
  1171.      * @param id the id of the request
  1172.          */
  1173.         void result( long id);
  1174.  
  1175.     protected slots:
  1176.         virtual void slotRedirection( const KURL &url);
  1177.         virtual void slotFinished();
  1178.         virtual void slotData( const QByteArray &data);
  1179.         virtual void slotMimetype( const QString &mimetype );
  1180.     private:
  1181.         struct GetRequest {
  1182.         public:
  1183.            GetRequest(long _id, const KURL &_url, const MetaData &_metaData)
  1184.              : id(_id), url(_url), metaData(_metaData) { }
  1185.            long id;
  1186.            KURL url;
  1187.            MetaData metaData;
  1188.         };
  1189.         bool findCurrentEntry();
  1190.         void flushQueue(QPtrList<GetRequest> &queue);
  1191.  
  1192.         QPtrList<GetRequest> m_waitQueue;
  1193.         QPtrList<GetRequest> m_activeQueue;
  1194.         bool b_multiGetActive;
  1195.         GetRequest *m_currentEntry;
  1196.     protected:
  1197.     virtual void virtual_hook( int id, void* data );
  1198.     private:
  1199.     class MultiGetJobPrivate* d;
  1200.     };
  1201.  
  1202.     /**
  1203.      * A MimetypeJob is a TransferJob that  allows you to get
  1204.      * the mime type of an URL. Don't create directly,
  1205.      * but use KIO::mimetype() instead.
  1206.      * @see KIO::mimetype()
  1207.      */
  1208.     class KIO_EXPORT MimetypeJob : public TransferJob {
  1209.     Q_OBJECT
  1210.  
  1211.     public:
  1212.        /**
  1213.     * Do not create a MimetypeJob directly. Use KIO::mimetype()
  1214.     * instead.
  1215.     * @param url the url to get
  1216.     * @param command the command to issue
  1217.     * @param packedArgs the arguments
  1218.     * @param showProgressInfo true to show progress information to the user
  1219.     */
  1220.         MimetypeJob(const KURL& url, int command, const QByteArray &packedArgs, bool showProgressInfo);
  1221.  
  1222.         /**
  1223.          * Call this in the slot connected to result,
  1224.          * and only after making sure no error happened.
  1225.      * @return the mimetype of the URL
  1226.          */
  1227.          QString mimetype() const { return m_mimetype; }
  1228.  
  1229.         /**
  1230.      * @internal
  1231.          * Called by the scheduler when a slave gets to
  1232.          * work on this job.
  1233.      * @param slave the slave that works on the job
  1234.          */
  1235.         virtual void start( Slave *slave );
  1236.  
  1237.     protected slots:
  1238.         virtual void slotFinished( );
  1239.     protected:
  1240.     virtual void virtual_hook( int id, void* data );
  1241.     private:
  1242.     class MimetypeJobPrivate* d;
  1243.     };
  1244.  
  1245.     /**
  1246.      * The FileCopyJob copies data from one place to another.
  1247.      * @see KIO::file_copy()
  1248.      * @see KIO::file_move()
  1249.      */
  1250.     class KIO_EXPORT FileCopyJob : public Job {
  1251.     Q_OBJECT
  1252.  
  1253.     public:
  1254.     /**
  1255.     * Do not create a FileCopyJob directly. Use KIO::file_move()
  1256.     * or KIO::file_copy() instead.
  1257.     * @param src the source URL
  1258.     * @param dest the destination URL
  1259.     * @param permissions the permissions of the resulting resource
  1260.     * @param move true to move, false to copy
  1261.     * @param overwrite true to allow overwriting, false otherwise
  1262.     * @param resume true to resume an operation, false otherwise
  1263.     * @param showProgressInfo true to show progress information to the user
  1264.      */
  1265.         FileCopyJob( const KURL& src, const KURL& dest, int permissions,
  1266.                      bool move, bool overwrite, bool resume, bool showProgressInfo);
  1267.  
  1268.         ~FileCopyJob();
  1269.         /**
  1270.          * If you know the size of the source file, call this method
  1271.          * to inform this job. It will be displayed in the "resume" dialog.
  1272.      * @param size the size of the source file
  1273.      * @since 3.2
  1274.          */
  1275.         void setSourceSize64(KIO::filesize_t size);
  1276.  
  1277.         /**
  1278.          * Sets the modification time of the file
  1279.          *
  1280.          * Note that this is ignored if a direct copy (SlaveBase::copy) can be done,
  1281.          * in which case the mtime of the source is applied to the destination (if the protocol
  1282.          * supports the concept).
  1283.          */
  1284.         void setModificationTime( time_t mtime );
  1285.  
  1286.         /**
  1287.          * @deprecated
  1288.          */
  1289.         void setSourceSize( off_t size ) KDE_DEPRECATED;
  1290.  
  1291.     /**
  1292.      * Returns the source URL.
  1293.      * @return the source URL
  1294.      */
  1295.         KURL srcURL() const { return m_src; }
  1296.  
  1297.     /**
  1298.      * Returns the destination URL.
  1299.      * @return the destination URL
  1300.      */
  1301.         KURL destURL() const { return m_dest; }
  1302.  
  1303.     signals:
  1304.         /**
  1305.          * Mimetype determined during a file copy.
  1306.          * This is never emitted during a move, and might not be emitted during
  1307.          * a copy, depending on the slave.
  1308.          * @param job the job that emitted this signal
  1309.          * @param type the mime type
  1310.          *
  1311.          * @since 3.5.7
  1312.          */
  1313.         void mimetype( KIO::Job *job, const QString &type );
  1314.  
  1315.     public slots:
  1316.         void slotStart();
  1317.         void slotData( KIO::Job *, const QByteArray &data);
  1318.         void slotDataReq( KIO::Job *, QByteArray &data);
  1319.         void slotMimetype( KIO::Job *, const QString& type );
  1320.  
  1321.     protected slots:
  1322.         /**
  1323.          * Called whenever a subjob finishes.
  1324.      * @param job the job that emitted this signal
  1325.          */
  1326.         virtual void slotResult( KIO::Job *job );
  1327.  
  1328.         /**
  1329.          * Forward signal from subjob
  1330.      * @param job the job that emitted this signal
  1331.      * @param size the processed size in bytes
  1332.          */
  1333.         void slotProcessedSize( KIO::Job *job, KIO::filesize_t size );
  1334.         /**
  1335.          * Forward signal from subjob
  1336.      * @param job the job that emitted this signal
  1337.      * @param size the total size
  1338.          */
  1339.         void slotTotalSize( KIO::Job *job, KIO::filesize_t size );
  1340.         /**
  1341.          * Forward signal from subjob
  1342.      * @param job the job that emitted this signal
  1343.      * @param pct the percentage
  1344.          */
  1345.         void slotPercent( KIO::Job *job, unsigned long pct );
  1346.         /**
  1347.          * Forward signal from subjob
  1348.      * @param job the job that emitted this signal
  1349.      * @param offset the offset to resume from
  1350.          */
  1351.         void slotCanResume( KIO::Job *job, KIO::filesize_t offset );
  1352.  
  1353.     protected:
  1354.         void startCopyJob();
  1355.         void startCopyJob(const KURL &slave_url);
  1356.         void startRenameJob(const KURL &slave_url);
  1357.         void startDataPump();
  1358.         void connectSubjob( SimpleJob * job );
  1359.  
  1360.     private:
  1361.         void startBestCopyMethod();
  1362.  
  1363.     protected:
  1364.         KURL m_src;
  1365.         KURL m_dest;
  1366.         int m_permissions;
  1367.         bool m_move:1;
  1368.         bool m_overwrite:1;
  1369.         bool m_resume:1;
  1370.         bool m_canResume:1;
  1371.         bool m_resumeAnswerSent:1;
  1372.         QByteArray m_buffer;
  1373.         SimpleJob *m_moveJob;
  1374.         SimpleJob *m_copyJob;
  1375.         TransferJob *m_getJob;
  1376.         TransferJob *m_putJob;
  1377.         KIO::filesize_t m_totalSize;
  1378.     protected:
  1379.     virtual void virtual_hook( int id, void* data );
  1380.     private:
  1381.     class FileCopyJobPrivate;
  1382.     FileCopyJobPrivate* d;
  1383.     };
  1384.  
  1385.     /**
  1386.      * A ListJob is allows you to get the get the content of a directory.
  1387.      * Don't create the job directly, but use KIO::listRecursive() or
  1388.      * KIO::listDir() instead.
  1389.      * @see KIO::listRecursive()
  1390.      * @see KIO::listDir()
  1391.      */
  1392.     class KIO_EXPORT ListJob : public SimpleJob {
  1393.     Q_OBJECT
  1394.  
  1395.     public:
  1396.        /**
  1397.     * Do not create a ListJob directly. Use KIO::listDir() or
  1398.     * KIO::listRecursive() instead.
  1399.     * @param url the url of the directory
  1400.     * @param showProgressInfo true to show progress information to the user
  1401.     * @param recursive true to get the data recursively from child directories,
  1402.     *        false to get only the content of the specified dir
  1403.     * @param prefix the prefix of the files, or QString::null for no prefix
  1404.     * @param includeHidden true to include hidden files (those starting with '.')
  1405.     */
  1406.         ListJob(const KURL& url, bool showProgressInfo,
  1407.                 bool recursive = false, QString prefix = QString::null,
  1408.                 bool includeHidden = true);
  1409.  
  1410.         /**
  1411.      * @internal
  1412.          * Called by the scheduler when a @p slave gets to
  1413.          * work on this job.
  1414.      * @param slave the slave that starts working on this job
  1415.          */
  1416.         virtual void start( Slave *slave );
  1417.  
  1418.         /**
  1419.          * Returns the ListJob's redirection URL. This will be invalid if there
  1420.          * was no redirection.
  1421.          * @return the redirection url
  1422.          * @since 3.4.1
  1423.          */
  1424.         const KURL& redirectionURL() const { return m_redirectionURL; }
  1425.  
  1426.         /**
  1427.          * Do not apply any KIOSK restrictions to this job.
  1428.          * @since 3.2
  1429.          */
  1430.         void setUnrestricted(bool unrestricted);
  1431.  
  1432.     signals:
  1433.         /**
  1434.          * This signal emits the entry found by the job while listing.
  1435.          * The progress signals aren't specific to ListJob. It simply
  1436.          * uses SimpleJob's processedSize (number of entries listed) and
  1437.          * totalSize (total number of entries, if known),
  1438.          * as well as percent.
  1439.      * @param job the job that emitted this signal
  1440.      * @param list the list of UDSEntries
  1441.          */
  1442.         void entries( KIO::Job *job, const KIO::UDSEntryList& list);
  1443.  
  1444.         /**
  1445.          * Signals a redirection.
  1446.          * Use to update the URL shown to the user.
  1447.          * The redirection itself is handled internally.
  1448.      * @param job the job that is redirected
  1449.      * @param url the new url
  1450.          */
  1451.         void redirection( KIO::Job *job, const KURL &url );
  1452.  
  1453.         /**
  1454.          * Signals a permanent redirection.
  1455.          * The redirection itself is handled internally.
  1456.      * @param job the job that emitted this signal
  1457.      * @param fromUrl the original URL
  1458.      * @param toUrl the new URL
  1459.      * @since 3.1
  1460.          */
  1461.         void permanentRedirection( KIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  1462.  
  1463.     protected slots:
  1464.         virtual void slotFinished( );
  1465.         virtual void slotMetaData( const KIO::MetaData &_metaData);
  1466.         virtual void slotResult( KIO::Job *job );
  1467.         void slotListEntries( const KIO::UDSEntryList& list );
  1468.         void slotRedirection( const KURL &url );
  1469.         void gotEntries( KIO::Job * subjob, const KIO::UDSEntryList& list );
  1470.  
  1471.     private:
  1472.         bool recursive;
  1473.         bool includeHidden;
  1474.         QString prefix;
  1475.         unsigned long m_processedEntries;
  1476.         KURL m_redirectionURL;
  1477.     protected:
  1478.     virtual void virtual_hook( int id, void* data );
  1479.     private:
  1480.     class ListJobPrivate* d;
  1481.     };
  1482.  
  1483.     /// @internal
  1484.     struct KIO_EXPORT CopyInfo
  1485.     {
  1486.         KURL uSource;
  1487.         KURL uDest;
  1488.         QString linkDest; // for symlinks only
  1489.         int permissions;
  1490.         //mode_t type;
  1491.         time_t ctime;
  1492.         time_t mtime;
  1493.         KIO::filesize_t size; // 0 for dirs
  1494.     };
  1495.  
  1496.     /**
  1497.      * CopyJob is used to move, copy or symlink files and directories.
  1498.      * Don't create the job directly, but use KIO::copy(),
  1499.      * KIO::move(), KIO::link() and friends.
  1500.      *
  1501.      * @see KIO::copy()
  1502.      * @see KIO::copyAs()
  1503.      * @see KIO::move()
  1504.      * @see KIO::moveAs()
  1505.      * @see KIO::link()
  1506.      * @see KIO::linkAs()
  1507.      */
  1508.     class KIO_EXPORT CopyJob : public Job {
  1509.     Q_OBJECT
  1510.  
  1511.     public:
  1512.     /**
  1513.      * Defines the mode of the operation
  1514.      */
  1515.         enum CopyMode{ Copy, Move, Link };
  1516.  
  1517.     /**
  1518.      * Do not create a CopyJob directly. Use KIO::copy(),
  1519.      * KIO::move(), KIO::link() and friends instead.
  1520.      *
  1521.      * @param src the list of source URLs
  1522.      * @param dest the destination URL
  1523.      * @param mode specifies whether the job should copy, move or link
  1524.      * @param asMethod if true, behaves like KIO::copyAs(),
  1525.      * KIO::moveAs() or KIO::linkAs()
  1526.      * @param showProgressInfo true to show progress information to the user
  1527.      * @see KIO::copy()
  1528.      * @see KIO::copyAs()
  1529.      * @see KIO::move()
  1530.      * @see KIO::moveAs()
  1531.      * @see KIO::link()
  1532.      * @see KIO::linkAs()
  1533.      */
  1534.         CopyJob( const KURL::List& src, const KURL& dest, CopyMode mode, bool asMethod, bool showProgressInfo );
  1535.  
  1536.         virtual ~CopyJob();
  1537.  
  1538.     /**
  1539.      * Returns the list of source URLs.
  1540.      * @return the list of source URLs.
  1541.      */
  1542.         KURL::List srcURLs() const { return m_srcList; }
  1543.  
  1544.     /**
  1545.      * Returns the destination URL.
  1546.      * @return the destination URL
  1547.      */
  1548.         KURL destURL() const { return m_dest; }
  1549.  
  1550.         /**
  1551.          * By default the permissions of the copied files will be those of the source files.
  1552.          *
  1553.          * But when copying "template" files to "new" files, people prefer the umask
  1554.          * to apply, rather than the template's permissions.
  1555.          * For that case, call setDefaultPermissions(true)
  1556.          *
  1557.          * TODO KDE4: consider adding this as bool to copy/copyAs?
  1558.          * @since 3.2.3
  1559.          */
  1560.         void setDefaultPermissions( bool b );
  1561.  
  1562.         /**
  1563.          * When an error happens while copying/moving a file, the user will be presented with
  1564.          * a dialog for skipping the file that can't be copied/moved.
  1565.          * Or if the error is that the destination file already exists, the standard
  1566.          * rename dialog is shown.
  1567.          * If the program doesn't want CopyJob to show dialogs, but to simply fail on error,
  1568.          * call setInteractive( false ).
  1569.          *
  1570.          * KDE4: remove, already in Job
  1571.          * @since 3.4
  1572.          */
  1573.         void setInteractive( bool b );
  1574.  
  1575.     signals:
  1576.  
  1577.         /**
  1578.      * Emitted when the total number of files is known.
  1579.      * @param job the job that emitted this signal
  1580.      * @param files the total number of files
  1581.      */
  1582.         void totalFiles( KIO::Job *job, unsigned long files );
  1583.         /**
  1584.      * Emitted when the toal number of direcotries is known.
  1585.      * @param job the job that emitted this signal
  1586.      * @param dirs the total number of directories
  1587.      */
  1588.         void totalDirs( KIO::Job *job, unsigned long dirs );
  1589.  
  1590.         /**
  1591.      * Emitted when it is known which files / directories are going
  1592.      * to be created. Note that this may still change e.g. when
  1593.      * existing files with the same name are discovered.
  1594.      * @param job the job that emitted this signal
  1595.      * @param files a list of items that are about to be created.
  1596.      */
  1597.         void aboutToCreate( KIO::Job *job, const QValueList<KIO::CopyInfo> &files);
  1598.  
  1599.         /**
  1600.      * Sends the number of processed files.
  1601.      * @param job the job that emitted this signal
  1602.      * @param files the number of processed files
  1603.      */
  1604.         void processedFiles( KIO::Job *job, unsigned long files );
  1605.         /**
  1606.      * Sends the number of processed directories.
  1607.      * @param job the job that emitted this signal
  1608.      * @param dirs the number of processed dirs
  1609.      */
  1610.         void processedDirs( KIO::Job *job, unsigned long dirs );
  1611.  
  1612.         /**
  1613.          * The job is copying a file or directory.
  1614.      * @param job the job that emitted this signal
  1615.      * @param from the URl of the file or directory that is currently
  1616.      *             being copied
  1617.      * @param to the destination of the current operation
  1618.          */
  1619.         void copying( KIO::Job *job, const KURL& from, const KURL& to );
  1620.         /**
  1621.          * The job is creating a symbolic link.
  1622.      * @param job the job that emitted this signal
  1623.      * @param target the URl of the file or directory that is currently
  1624.      *             being linked
  1625.      * @param to the destination of the current operation
  1626.          */
  1627.         void linking( KIO::Job *job, const QString& target, const KURL& to );
  1628.         /**
  1629.          * The job is moving a file or directory.
  1630.      * @param job the job that emitted this signal
  1631.      * @param from the URl of the file or directory that is currently
  1632.      *             being moved
  1633.      * @param to the destination of the current operation
  1634.          */
  1635.         void moving( KIO::Job *job, const KURL& from, const KURL& to );
  1636.         /**
  1637.          * The job is creating the directory @p dir.
  1638.      * @param job the job that emitted this signal
  1639.      * @param dir the directory that is currently being created
  1640.          */
  1641.         void creatingDir( KIO::Job *job, const KURL& dir );
  1642.         /**
  1643.          * The user chose to rename @p from to @p to.
  1644.      * @param job the job that emitted this signal
  1645.      * @param from the original name
  1646.      * @param to the new name
  1647.          */
  1648.         void renamed( KIO::Job *job, const KURL& from, const KURL& to );
  1649.  
  1650.         /**
  1651.          * The job emits this signal when copying or moving a file or directory successfully finished.
  1652.          * This signal is mainly for the Undo feature.
  1653.      *
  1654.      * @param job the job that emitted this signal
  1655.          * @param from the source URL
  1656.          * @param to the destination URL
  1657.          * @param directory indicates whether a file or directory was successfully copied/moved.
  1658.      *                  true for a directoy, false for file
  1659.          * @param renamed indicates that the destination URL was created using a
  1660.          * rename operation (i.e. fast directory moving). true if is has been renamed
  1661.          */
  1662.         void copyingDone( KIO::Job *job, const KURL &from, const KURL &to, bool directory, bool renamed );
  1663.         /**
  1664.          * The job is copying or moving a symbolic link, that points to target.
  1665.          * The new link is created in @p to. The existing one is/was in @p from.
  1666.          * This signal is mainly for the Undo feature.
  1667.      * @param job the job that emitted this signal
  1668.          * @param from the source URL
  1669.      * @param target the target
  1670.          * @param to the destination URL
  1671.          */
  1672.         void copyingLinkDone( KIO::Job *job, const KURL &from, const QString& target, const KURL& to );
  1673.  
  1674.     protected:
  1675.         void statCurrentSrc();
  1676.         void statNextSrc();
  1677.  
  1678.         // Those aren't slots but submethods for slotResult.
  1679.         void slotResultStating( KIO::Job * job );
  1680.         void startListing( const KURL & src );
  1681.         void slotResultCreatingDirs( KIO::Job * job );
  1682.         void slotResultConflictCreatingDirs( KIO::Job * job );
  1683.         void createNextDir();
  1684.         void slotResultCopyingFiles( KIO::Job * job );
  1685.         void slotResultConflictCopyingFiles( KIO::Job * job );
  1686.         void copyNextFile();
  1687.         void slotResultDeletingDirs( KIO::Job * job );
  1688.         void deleteNextDir();
  1689.         void skip( const KURL & sourceURL );
  1690.         void slotResultRenaming( KIO::Job * job );
  1691.         //void slotResultSettingDirAttributes( KIO::Job * job );
  1692.         void setNextDirAttribute();
  1693.     private:
  1694.         void startRenameJob(const KURL &slave_url);
  1695.         bool shouldOverwrite( const QString& path ) const;
  1696.         bool shouldSkip( const QString& path ) const;
  1697.         void skipSrc();
  1698.  
  1699.     protected slots:
  1700.         void slotStart();
  1701.         void slotEntries( KIO::Job*, const KIO::UDSEntryList& list );
  1702.         virtual void slotResult( KIO::Job *job );
  1703.         /**
  1704.          * Forward signal from subjob
  1705.          */
  1706.         void slotProcessedSize( KIO::Job*, KIO::filesize_t data_size );
  1707.         /**
  1708.          * Forward signal from subjob
  1709.      * @param size the total size
  1710.          */
  1711.         void slotTotalSize( KIO::Job*, KIO::filesize_t size );
  1712.  
  1713.         void slotReport();
  1714.     private:
  1715.         CopyMode m_mode;
  1716.         bool m_asMethod;
  1717.         enum DestinationState { DEST_NOT_STATED, DEST_IS_DIR, DEST_IS_FILE, DEST_DOESNT_EXIST };
  1718.         DestinationState destinationState;
  1719.         enum { STATE_STATING, STATE_RENAMING, STATE_LISTING, STATE_CREATING_DIRS,
  1720.                STATE_CONFLICT_CREATING_DIRS, STATE_COPYING_FILES, STATE_CONFLICT_COPYING_FILES,
  1721.                STATE_DELETING_DIRS, STATE_SETTING_DIR_ATTRIBUTES } state;
  1722.         KIO::filesize_t m_totalSize;
  1723.         KIO::filesize_t m_processedSize;
  1724.         KIO::filesize_t m_fileProcessedSize;
  1725.         int m_processedFiles;
  1726.         int m_processedDirs;
  1727.         QValueList<CopyInfo> files;
  1728.         QValueList<CopyInfo> dirs;
  1729.         KURL::List dirsToRemove;
  1730.         KURL::List m_srcList;
  1731.         KURL::List::Iterator m_currentStatSrc;
  1732.         bool m_bCurrentSrcIsDir;
  1733.         bool m_bCurrentOperationIsLink;
  1734.         bool m_bSingleFileCopy;
  1735.         bool m_bOnlyRenames;
  1736.         KURL m_dest;
  1737.         KURL m_currentDest;
  1738.         //
  1739.         QStringList m_skipList;
  1740.         QStringList m_overwriteList;
  1741.         bool m_bAutoSkip;
  1742.         bool m_bOverwriteAll;
  1743.         int m_conflictError;
  1744.  
  1745.         QTimer *m_reportTimer;
  1746.         //these both are used for progress dialog reporting
  1747.         KURL m_currentSrcURL;
  1748.         KURL m_currentDestURL;
  1749.     protected:
  1750.     virtual void virtual_hook( int id, void* data );
  1751.     private:
  1752.     class CopyJobPrivate;
  1753.         CopyJobPrivate* d;
  1754.         friend class CopyJobPrivate; // for DestinationState
  1755.     };
  1756.  
  1757.     /**
  1758.      * A more complex Job to delete files and directories.
  1759.      * Don't create the job directly, but use KIO::del() instead.
  1760.      *
  1761.      * @see KIO::del()
  1762.      */
  1763.     class KIO_EXPORT DeleteJob : public Job {
  1764.     Q_OBJECT
  1765.  
  1766.     public:
  1767.     /**
  1768.      * Do not create a DeleteJob directly. Use KIO::del()
  1769.      * instead.
  1770.      *
  1771.      * @param src the list of URLs to delete
  1772.      * @param shred true to shred (make sure that data is not recoverable)a
  1773.      * @param showProgressInfo true to show progress information to the user
  1774.      * @see KIO::del()
  1775.      */
  1776.         DeleteJob( const KURL::List& src, bool shred, bool showProgressInfo );
  1777.  
  1778.     /**
  1779.      * Returns the list of URLs.
  1780.      * @return the list of URLs.
  1781.      */
  1782.         KURL::List urls() const { return m_srcList; }
  1783.  
  1784.     signals:
  1785.  
  1786.         /**
  1787.      * Emitted when the total number of files is known.
  1788.      * @param job the job that emitted this signal
  1789.      * @param files the total number of files
  1790.      */
  1791.         void totalFiles( KIO::Job *job, unsigned long files );
  1792.         /**
  1793.      * Emitted when the toal number of direcotries is known.
  1794.      * @param job the job that emitted this signal
  1795.      * @param dirs the total number of directories
  1796.      */
  1797.         void totalDirs( KIO::Job *job, unsigned long dirs );
  1798.  
  1799.         /**
  1800.      * Sends the number of processed files.
  1801.      * @param job the job that emitted this signal
  1802.      * @param files the number of processed files
  1803.      */
  1804.         void processedFiles( KIO::Job *job, unsigned long files );
  1805.         /**
  1806.      * Sends the number of processed directories.
  1807.      * @param job the job that emitted this signal
  1808.      * @param dirs the number of processed dirs
  1809.      */
  1810.         void processedDirs( KIO::Job *job, unsigned long dirs );
  1811.  
  1812.         /**
  1813.      * Sends the URL of the file that is currently being deleted.
  1814.      * @param job the job that emitted this signal
  1815.      * @param file the URL of the file or directory that is being
  1816.      *        deleted
  1817.      */
  1818.         void deleting( KIO::Job *job, const KURL& file );
  1819.  
  1820.     protected slots:
  1821.         void slotStart();
  1822.         void slotEntries( KIO::Job*, const KIO::UDSEntryList& list );
  1823.         virtual void slotResult( KIO::Job *job );
  1824.  
  1825.         /**
  1826.          * Forward signal from subjob
  1827.          */
  1828.         void slotProcessedSize( KIO::Job*, KIO::filesize_t data_size );
  1829.         void slotReport();
  1830.  
  1831.     private:
  1832.         void statNextSrc();
  1833.         void deleteNextFile();
  1834.         void deleteNextDir();
  1835.  
  1836.     private:
  1837.         enum { STATE_STATING, STATE_LISTING,
  1838.                STATE_DELETING_FILES, STATE_DELETING_DIRS } state;
  1839.         KIO::filesize_t m_totalSize;
  1840.         KIO::filesize_t m_processedSize;
  1841.         KIO::filesize_t m_fileProcessedSize;
  1842.         int m_processedFiles;
  1843.         int m_processedDirs;
  1844.         int m_totalFilesDirs;
  1845.         KURL m_currentURL;
  1846.         KURL::List files;
  1847.         KURL::List symlinks;
  1848.         KURL::List dirs;
  1849.         KURL::List m_srcList;
  1850.         KURL::List::Iterator m_currentStat;
  1851.     QStringList m_parentDirs;
  1852.         bool m_shred; // BIC: remove in KDE4
  1853.         QTimer *m_reportTimer;
  1854.     protected:
  1855.         /** \internal */
  1856.     virtual void virtual_hook( int id, void* data );
  1857.     private:
  1858.     class DeleteJobPrivate* d;
  1859.     };
  1860.  
  1861. }
  1862.  
  1863. #endif
  1864.