• Skip to content
  • Skip to link menu
KDE 4.2 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 
00075 FileJob::FileJob(FileJobPrivate &dd)
00076     : SimpleJob(dd)
00077 {
00078 }
00079 
00080 FileJob::~FileJob()
00081 {
00082 }
00083 
00084 void FileJob::read(KIO::filesize_t size)
00085 {
00086     Q_D(FileJob);
00087     if (!d->m_open) return;
00088 
00089     KIO_ARGS << size;
00090     d->m_slave->send( CMD_READ, packedArgs );
00091 }
00092 
00093 
00094 void FileJob::write(const QByteArray &_data)
00095 {
00096     Q_D(FileJob);
00097     if (!d->m_open) return;
00098 
00099     d->m_slave->send( CMD_WRITE, _data );
00100 }
00101 
00102 void FileJob::seek(KIO::filesize_t offset)
00103 {
00104     Q_D(FileJob);
00105     if (!d->m_open) return;
00106 
00107     KIO_ARGS << KIO::filesize_t(offset);
00108     d->m_slave->send( CMD_SEEK, packedArgs) ;
00109 }
00110 
00111 void FileJob::close()
00112 {
00113     Q_D(FileJob);
00114     if (!d->m_open) return;
00115 
00116     d->m_slave->send( CMD_CLOSE );
00117     // ###  close?
00118 }
00119 
00120 KIO::filesize_t FileJob::size()
00121 {
00122     Q_D(FileJob);
00123     if (!d->m_open) return 0;
00124 
00125     return d->m_size;
00126 }
00127 
00128 // Slave sends data
00129 void FileJobPrivate::slotData( const QByteArray &_data)
00130 {
00131     Q_Q(FileJob);
00132     emit q_func()->data(q, _data);
00133 }
00134 
00135 void FileJobPrivate::slotRedirection( const KUrl &url)
00136 {
00137     Q_Q(FileJob);
00138     kDebug(7007) << url;
00139     emit q->redirection(q, url);
00140 }
00141 
00142 void FileJobPrivate::slotMimetype( const QString& type )
00143 {
00144     Q_Q(FileJob);
00145     m_mimetype = type;
00146     emit q->mimetype(q, m_mimetype);
00147 }
00148 
00149 void FileJobPrivate::slotPosition( KIO::filesize_t pos )
00150 {
00151     Q_Q(FileJob);
00152     emit q->position(q, pos);
00153 }
00154 
00155 void FileJobPrivate::slotTotalSize( KIO::filesize_t t_size )
00156 {
00157     m_size = t_size;
00158 //    Q_Q(FileJob);
00159 //    emit q->totalSize(q, m_size);
00160 }
00161 
00162 void FileJobPrivate::slotOpen( )
00163 {
00164     Q_Q(FileJob);
00165     m_open = true;
00166     emit q->open( q );
00167 }
00168 
00169 void FileJobPrivate::slotWritten( KIO::filesize_t t_written )
00170 {
00171     Q_Q(FileJob);
00172     emit q->written(q, t_written);
00173 }
00174 
00175 void FileJobPrivate::slotFinished()
00176 {
00177     Q_Q(FileJob);
00178     kDebug(7007) << this << m_url;
00179     emit q->close( q );
00180     // Return slave to the scheduler
00181     slaveDone();
00182 //     Scheduler::doJob(this);
00183     q->emitResult();
00184 }
00185 
00186 void FileJobPrivate::start(Slave *slave)
00187 {
00188     Q_Q(FileJob);
00189     q->connect( slave, SIGNAL( data( const QByteArray & ) ),
00190                 SLOT( slotData( const QByteArray & ) ) );
00191 
00192     q->connect( slave, SIGNAL( redirection(const KUrl &) ),
00193                 SLOT( slotRedirection(const KUrl &) ) );
00194 
00195     q->connect( slave, SIGNAL(mimeType( const QString& ) ),
00196                 SLOT( slotMimetype( const QString& ) ) );
00197 
00198     q->connect( slave, SIGNAL(open() ),
00199                 SLOT( slotOpen() ) );
00200 
00201     q->connect( slave, SIGNAL(position(KIO::filesize_t) ),
00202                 SLOT( slotPosition(KIO::filesize_t) ) );
00203 
00204     q->connect( slave, SIGNAL(written(KIO::filesize_t) ),
00205                 SLOT( slotWritten(KIO::filesize_t) ) );
00206 
00207     q->connect( slave, SIGNAL(totalSize(KIO::filesize_t) ),
00208                 SLOT( slotTotalSize(KIO::filesize_t) ) );
00209 
00210     SimpleJobPrivate::start(slave);
00211 }
00212 
00213 FileJob *KIO::open(const KUrl &url, QIODevice::OpenMode mode)
00214 {
00215     // Send decoded path and encoded query
00216     KIO_ARGS << url << mode;
00217     return FileJobPrivate::newJob(url, packedArgs);
00218 }
00219 
00220 #include "filejob.moc"
00221 

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
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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