1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
Copyright (C) 2004 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef STOREDTRANSFERJOB_H
#define STOREDTRANSFERJOB_H
#include <kio/job.h>
// To be moved to KIO?
namespace TDEIOext {
/**
* StoredTransferJob is a TransferJob (for downloading or uploading data) that
* also stores a TQByteArray with the data, making it simpler to use than the
* standard TransferJob.
*
* For TDEIO::get it puts the data into the member TQByteArray, so the user
* of this class can get hold of the whole data at once by calling data()
* when the result signal is emitted.
* You should only use StoredTransferJob to download data if you cannot
* process the data by chunks while it's being downloaded, since storing
* everything in a TQByteArray can potentially require a lot of memory.
*
* For TDEIO::put the user of this class simply provides the bytearray from
* the start, and the job takes care of uploading it.
* You should only use StoredTransferJob to upload data if you cannot
* provide the in chunks while it's being uploaded, since storing
* everything in a TQByteArray can potentially require a lot of memory.
*
*/
class StoredTransferJob : public TDEIO::TransferJob {
Q_OBJECT
public:
/**
* Do not create a StoredTransferJob. Use storedGet() or storedPut()
* instead.
* @param url the url to get or put
* @param command the command to issue
* @param packedArgs the arguments
* @param _staticData additional data to transmit (e.g. in a HTTP Post)
* @param showProgressInfo true to show progress information to the user
*/
StoredTransferJob(const KURL& url, int command,
const TQByteArray &packedArgs,
const TQByteArray &_staticData,
bool showProgressInfo);
/**
* Set data to be uploaded. This is for put jobs.
* Automatically called by KIOext::put(const TQByteArray &, ...), do not call this yourself.
*/
void setData( const TQByteArray& arr );
/**
* Get hold of the downloaded data. This is for get jobs.
* You're supposed to call this only from the slot connected to the result() signal.
*/
TQByteArray data() const { return m_data; }
private slots:
void slotData( TDEIO::Job *job, const TQByteArray &data );
void slotDataReq( TDEIO::Job *job, TQByteArray &data );
private:
TQByteArray m_data;
int m_uploadOffset;
};
/**
* Get (a.k.a. read), into a single TQByteArray.
* @see StoredTransferJob
*
* @param url the URL of the file
* @param reload true to reload the file, false if it can be taken from the cache
* @param showProgressInfo true to show progress information
* @return the job handling the operation.
*/
StoredTransferJob *storedGet( const KURL& url, bool reload=false, bool showProgressInfo = true );
/**
* Put (a.k.a. write) data from a single TQByteArray.
* @see StoredTransferJob
*
* @param url Where to write data.
* @param permissions May be -1. In this case no special permission mode is set.
* @param overwrite If true, any existing file will be overwritten.
* @param resume true to resume, false otherwise
* @param showProgressInfo true to show progress information
* @return the job handling the operation.
* @see multi_get()
*/
StoredTransferJob *put( const TQByteArray& arr, const KURL& url, int permissions,
bool overwrite, bool resume, bool showProgressInfo = true );
} // namespace
#endif
|