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

KIO

filejob.cpp

Go to the documentation of this file.
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2006 Allan Sandfeld Jensen <kde@carewolf.com>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  *
00019  **/
00020 
00021 #include "filejob.h"
00022 
00023 #include "slavebase.h"
00024 #include "connection.h"
00025 #include "scheduler.h"
00026 #include "slave.h"
00027 
00028 #include <QTimer>
00029 #include <kdebug.h>
00030 
00031 #include "job_p.h"
00032 
00033 class KIO::FileJobPrivate: public KIO::SimpleJobPrivate
00034 {
00035 public:
00036     FileJobPrivate(const KUrl& url, const QByteArray &packedArgs)
00037         : SimpleJobPrivate(url, CMD_OPEN, packedArgs), m_open(false), m_size(0)
00038         {}
00039 
00040     bool m_open;
00041     QString m_mimetype;
00042     KIO::filesize_t m_size;
00043 
00044     void slotRedirection( const KUrl &url );
00045     void slotData( const QByteArray &data );
00046     void slotMimetype( const QString &mimetype );
00047     void slotOpen( );
00048     void slotWritten( KIO::filesize_t );
00049     void slotFinished( );
00050     void slotPosition( KIO::filesize_t );
00051     void slotTotalSize( KIO::filesize_t );
00052 
00059     virtual void start(Slave *slave);
00060 
00061     Q_DECLARE_PUBLIC(FileJob)
00062 
00063     static inline FileJob *newJob(const KUrl &url, const QByteArray &packedArgs)
00064     {
00065         FileJob *job = new FileJob(*new FileJobPrivate(url, packedArgs));
00066         job->setUiDelegate(new JobUiDelegate);
00067         return job;
00068     }
00069 };
00070 
00071 using namespace KIO;
00072 
00073 #define KIO_ARGS QByteArray packedArgs; QDataStream stream( &packedArgs, QIODevice::WriteOnly ); stream
00074 #define KIO_FILESIZE_T(x) qulonglong(x)
00075 
00076 FileJob::FileJob(FileJobPrivate &dd)
00077     : SimpleJob(dd)
00078 {
00079 }
00080 
00081 FileJob::~FileJob()
00082 {
00083 }
00084 
00085 void FileJob::read(KIO::filesize_t size)
00086 {
00087     Q_D(FileJob);
00088     if (!d->m_open) return;
00089 
00090     KIO_ARGS << size;
00091     d->m_slave->send( CMD_READ, packedArgs );
00092 }
00093 
00094 
00095 void FileJob::write(const QByteArray &_data)
00096 {
00097     Q_D(FileJob);
00098     if (!d->m_open) return;
00099 
00100     d->m_slave->send( CMD_WRITE, _data );
00101 }
00102 
00103 void FileJob::seek(KIO::filesize_t offset)
00104 {
00105     Q_D(FileJob);
00106     if (!d->m_open) return;
00107 
00108     KIO_ARGS << KIO_FILESIZE_T(offset);
00109     d->m_slave->send( CMD_SEEK, packedArgs) ;
00110 }
00111 
00112 void FileJob::close()
00113 {
00114     Q_D(FileJob);
00115     if (!d->m_open) return;
00116 
00117     d->m_slave->send( CMD_CLOSE );
00118     // ###  close?
00119 }
00120 
00121 KIO::filesize_t FileJob::size()
00122 {
00123     Q_D(FileJob);
00124     if (!d->m_open) return 0;
00125 
00126     return d->m_size;
00127 }
00128 
00129 // Slave sends data
00130 void FileJobPrivate::slotData( const QByteArray &_data)
00131 {
00132     Q_Q(FileJob);
00133     emit q_func()->data(q, _data);
00134 }
00135 
00136 void FileJobPrivate::slotRedirection( const KUrl &url)
00137 {
00138     Q_Q(FileJob);
00139     kDebug(7007) << "FileJobPrivate::slotRedirection(" << url << ")";
00140     emit q->redirection(q, url);
00141 }
00142 
00143 void FileJobPrivate::slotMimetype( const QString& type )
00144 {
00145     Q_Q(FileJob);
00146     m_mimetype = type;
00147     emit q->mimetype(q, m_mimetype);
00148 }
00149 
00150 void FileJobPrivate::slotPosition( KIO::filesize_t pos )
00151 {
00152     Q_Q(FileJob);
00153     emit q->position(q, pos);
00154 }
00155 
00156 void FileJobPrivate::slotTotalSize( KIO::filesize_t t_size )
00157 {
00158     m_size = t_size;
00159 //    Q_Q(FileJob);
00160 //    emit q->totalSize(q, m_size);
00161 }
00162 
00163 void FileJobPrivate::slotOpen( )
00164 {
00165     Q_Q(FileJob);
00166     m_open = true;
00167     emit q->open( q );
00168 }
00169 
00170 void FileJobPrivate::slotWritten( KIO::filesize_t t_written )
00171 {
00172     Q_Q(FileJob);
00173     emit q->written(q, t_written);
00174 }
00175 
00176 void FileJobPrivate::slotFinished()
00177 {
00178     Q_Q(FileJob);
00179     kDebug(7007) << "FileJobPrivate::slotFinished(" << this << ", " << m_url << ")";
00180     emit q->close( q );
00181     // Return slave to the scheduler
00182     slaveDone();
00183 //     Scheduler::doJob(this);
00184     q->emitResult();
00185 }
00186 
00187 void FileJobPrivate::start(Slave *slave)
00188 {
00189     Q_Q(FileJob);
00190     q->connect( slave, SIGNAL( data( const QByteArray & ) ),
00191                 SLOT( slotData( const QByteArray & ) ) );
00192 
00193     q->connect( slave, SIGNAL( redirection(const KUrl &) ),
00194                 SLOT( slotRedirection(const KUrl &) ) );
00195 
00196     q->connect( slave, SIGNAL(mimeType( const QString& ) ),
00197                 SLOT( slotMimetype( const QString& ) ) );
00198 
00199     q->connect( slave, SIGNAL(open() ),
00200                 SLOT( slotOpen() ) );
00201 
00202     q->connect( slave, SIGNAL(position(KIO::filesize_t) ),
00203                 SLOT( slotPosition(KIO::filesize_t) ) );
00204 
00205     q->connect( slave, SIGNAL(written(KIO::filesize_t) ),
00206                 SLOT( slotWritten(KIO::filesize_t) ) );
00207 
00208     q->connect( slave, SIGNAL(totalSize(KIO::filesize_t) ),
00209                 SLOT( slotTotalSize(KIO::filesize_t) ) );
00210 
00211     SimpleJobPrivate::start(slave);
00212 }
00213 
00214 FileJob *KIO::open(const KUrl &url, QIODevice::OpenMode mode)
00215 {
00216     // Send decoded path and encoded query
00217     KIO_ARGS << url << mode;
00218     return FileJobPrivate::newJob(url, packedArgs);
00219 }
00220 
00221 #include "filejob.moc"
00222 

KIO

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   WTF
  • KJSEmbed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal