• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kio
filejob.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2006 Allan Sandfeld Jensen <kde@carewolf.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 **/
20
21#include "filejob.h"
22
23#include "slavebase.h"
24#include "connection.h"
25#include "scheduler.h"
26#include "slave.h"
27
28#include <QTimer>
29#include <kdebug.h>
30
31#include "job_p.h"
32
33class KIO::FileJobPrivate: public KIO::SimpleJobPrivate
34{
35public:
36 FileJobPrivate(const KUrl& url, const QByteArray &packedArgs)
37 : SimpleJobPrivate(url, CMD_OPEN, packedArgs), m_open(false), m_size(0)
38 {}
39
40 bool m_open;
41 QString m_mimetype;
42 KIO::filesize_t m_size;
43
44 void slotRedirection( const KUrl &url );
45 void slotData( const QByteArray &data );
46 void slotMimetype( const QString &mimetype );
47 void slotOpen( );
48 void slotWritten( KIO::filesize_t );
49 void slotFinished( );
50 void slotPosition( KIO::filesize_t );
51 void slotTotalSize( KIO::filesize_t );
52
59 virtual void start(Slave *slave);
60
61 Q_DECLARE_PUBLIC(FileJob)
62
63 static inline FileJob *newJob(const KUrl &url, const QByteArray &packedArgs)
64 {
65 FileJob *job = new FileJob(*new FileJobPrivate(url, packedArgs));
66 job->setUiDelegate(new JobUiDelegate);
67 return job;
68 }
69};
70
71using namespace KIO;
72
73FileJob::FileJob(FileJobPrivate &dd)
74 : SimpleJob(dd)
75{
76}
77
78FileJob::~FileJob()
79{
80}
81
82void FileJob::read(KIO::filesize_t size)
83{
84 Q_D(FileJob);
85 if (!d->m_open) return;
86
87 KIO_ARGS << size;
88 d->m_slave->send( CMD_READ, packedArgs );
89}
90
91
92void FileJob::write(const QByteArray &_data)
93{
94 Q_D(FileJob);
95 if (!d->m_open) return;
96
97 d->m_slave->send( CMD_WRITE, _data );
98}
99
100void FileJob::seek(KIO::filesize_t offset)
101{
102 Q_D(FileJob);
103 if (!d->m_open) return;
104
105 KIO_ARGS << KIO::filesize_t(offset);
106 d->m_slave->send( CMD_SEEK, packedArgs) ;
107}
108
109void FileJob::close()
110{
111 Q_D(FileJob);
112 if (!d->m_open) return;
113
114 d->m_slave->send( CMD_CLOSE );
115 // ### close?
116}
117
118KIO::filesize_t FileJob::size()
119{
120 Q_D(FileJob);
121 if (!d->m_open) return 0;
122
123 return d->m_size;
124}
125
126// Slave sends data
127void FileJobPrivate::slotData( const QByteArray &_data)
128{
129 Q_Q(FileJob);
130 emit q_func()->data(q, _data);
131}
132
133void FileJobPrivate::slotRedirection( const KUrl &url)
134{
135 Q_Q(FileJob);
136 kDebug(7007) << url;
137 emit q->redirection(q, url);
138}
139
140void FileJobPrivate::slotMimetype( const QString& type )
141{
142 Q_Q(FileJob);
143 m_mimetype = type;
144 emit q->mimetype(q, m_mimetype);
145}
146
147void FileJobPrivate::slotPosition( KIO::filesize_t pos )
148{
149 Q_Q(FileJob);
150 emit q->position(q, pos);
151}
152
153void FileJobPrivate::slotTotalSize( KIO::filesize_t t_size )
154{
155 m_size = t_size;
156 Q_Q(FileJob);
157 q->setTotalAmount(KJob::Bytes, m_size);
158}
159
160void FileJobPrivate::slotOpen( )
161{
162 Q_Q(FileJob);
163 m_open = true;
164 emit q->open( q );
165}
166
167void FileJobPrivate::slotWritten( KIO::filesize_t t_written )
168{
169 Q_Q(FileJob);
170 emit q->written(q, t_written);
171}
172
173void FileJobPrivate::slotFinished()
174{
175 Q_Q(FileJob);
176 kDebug(7007) << this << m_url;
177 emit q->close( q );
178 // Return slave to the scheduler
179 slaveDone();
180// Scheduler::doJob(this);
181 q->emitResult();
182}
183
184void FileJobPrivate::start(Slave *slave)
185{
186 Q_Q(FileJob);
187 q->connect( slave, SIGNAL(data(QByteArray)),
188 SLOT(slotData(QByteArray)) );
189
190 q->connect( slave, SIGNAL(redirection(KUrl)),
191 SLOT(slotRedirection(KUrl)) );
192
193 q->connect( slave, SIGNAL(mimeType(QString)),
194 SLOT(slotMimetype(QString)) );
195
196 q->connect( slave, SIGNAL(open()),
197 SLOT(slotOpen()) );
198
199 q->connect( slave, SIGNAL(position(KIO::filesize_t)),
200 SLOT(slotPosition(KIO::filesize_t)) );
201
202 q->connect( slave, SIGNAL(written(KIO::filesize_t)),
203 SLOT(slotWritten(KIO::filesize_t)) );
204
205 q->connect( slave, SIGNAL(totalSize(KIO::filesize_t)),
206 SLOT(slotTotalSize(KIO::filesize_t)) );
207
208 SimpleJobPrivate::start(slave);
209}
210
211FileJob *KIO::open(const KUrl &url, QIODevice::OpenMode mode)
212{
213 // Send decoded path and encoded query
214 KIO_ARGS << url << mode;
215 return FileJobPrivate::newJob(url, packedArgs);
216}
217
218#include "filejob.moc"
219
KIO::FileJob
The file-job is an asynchronious version of normal file handling.
Definition: filejob.h:38
KIO::FileJob::size
KIO::filesize_t size()
Size.
Definition: filejob.cpp:118
KIO::FileJob::read
void read(KIO::filesize_t size)
Read block.
Definition: filejob.cpp:82
KIO::FileJob::FileJob
FileJob(FileJobPrivate &dd)
Definition: filejob.cpp:73
KIO::FileJob::write
void write(const QByteArray &data)
Write block.
Definition: filejob.cpp:92
KIO::FileJob::seek
void seek(KIO::filesize_t offset)
Seek.
Definition: filejob.cpp:100
KIO::FileJob::~FileJob
~FileJob()
Definition: filejob.cpp:78
KIO::FileJob::close
void close()
Close.
Definition: filejob.cpp:109
KIO::JobUiDelegate
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:40
KIO::SimpleJobPrivate
Definition: job_p.h:82
KIO::SimpleJobPrivate::start
virtual void start(KIO::Slave *slave)
Definition: job.cpp:385
KIO::SimpleJobPrivate::newJob
static SimpleJob * newJob(const KUrl &url, int command, const QByteArray &packedArgs, JobFlags flags=HideProgressInfo)
Definition: job_p.h:206
KIO::SimpleJobPrivate::slotTotalSize
void slotTotalSize(KIO::filesize_t data_size)
Forward signal from the slave Can also be called by the parent job, when it knows the size.
Definition: job.cpp:526
KIO::SimpleJob
A simple job (one url and one command).
Definition: jobclasses.h:322
KIO::Slave
Definition: slave.h:49
KJob::Bytes
Bytes
KJob::setUiDelegate
void setUiDelegate(KJobUiDelegate *delegate)
KUrl
connection.h
filejob.h
kDebug
#define kDebug
job_p.h
KIO_ARGS
#define KIO_ARGS
Definition: job_p.h:34
kdebug.h
open
int open(const QString &pathname, int flags, mode_t mode)
KIO
A namespace for KIO globals.
Definition: kbookmarkmenu.h:55
KIO::open
FileJob * open(const KUrl &url, QIODevice::OpenMode mode)
Open ( random access I/O )
Definition: filejob.cpp:211
KIO::CMD_READ
@ CMD_READ
Definition: global.h:182
KIO::CMD_OPEN
@ CMD_OPEN
Definition: global.h:180
KIO::CMD_WRITE
@ CMD_WRITE
Definition: global.h:183
KIO::CMD_SEEK
@ CMD_SEEK
Definition: global.h:184
KIO::CMD_CLOSE
@ CMD_CLOSE
Definition: global.h:185
KIO::mimetype
MimetypeJob * mimetype(const KUrl &url, JobFlags flags=DefaultFlags)
Find mimetype for one file or directory.
Definition: job.cpp:1856
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
scheduler.h
slave.h
slavebase.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal