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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
kopetetransfermanager.h
Copyright (c) 2002-2003 by Nick Betcher <nbetcher@kde.org>
Copyright (c) 2002-2003 by Richard Smith <kopete@metafoo.co.uk>
Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#ifndef KOPETEFILETRANSFER_H
#define KOPETEFILETRANSFER_H
#include <tqobject.h>
#include <tqstring.h>
#include <tqmap.h>
#include "kopete_export.h"
#include <kio/job.h>
namespace Kopete
{
class Transfer;
class Contact;
/**
* @author Nick Betcher. <nbetcher@kde.org>
*/
class KOPETE_EXPORT FileTransferInfo
{
public:
enum KopeteTransferDirection { Incoming, Outgoing };
FileTransferInfo( Contact *, const TQString&, const unsigned long size, const TQString &, KopeteTransferDirection di, const unsigned int id, TQString internalId=TQString());
~FileTransferInfo() {}
unsigned int transferId() const { return mId; }
const Contact* contact() const { return mContact; }
TQString file() const { return mFile; }
TQString recipient() const { return mRecipient; }
unsigned long size() const { return mSize; }
TQString internalId() const { return m_intId; }
KopeteTransferDirection direction() const { return mDirection; }
private:
unsigned long mSize;
TQString mRecipient;
unsigned int mId;
Contact *mContact;
TQString mFile;
TQString m_intId;
KopeteTransferDirection mDirection;
};
/**
* Creates and manages kopete file transfers
*/
class KOPETE_EXPORT TransferManager : public TQObject
{
Q_OBJECT
TQ_OBJECT
public:
/**
* Retrieve the transfer manager instance
*/
static TransferManager* transferManager();
virtual ~TransferManager() {};
/**
* @brief Adds a file transfer to the Kopete::TransferManager
*/
Transfer *addTransfer( Contact *contact, const TQString& file, const unsigned long size, const TQString &recipient , FileTransferInfo::KopeteTransferDirection di);
int askIncomingTransfer( Contact *contact, const TQString& file, const unsigned long size, const TQString& description=TQString(), TQString internalId=TQString());
void removeTransfer( unsigned int id );
/**
* @brief Ask the user which file to send when they click Send File.
*
* Possibly ask the user which file to send when they click Send File. Sends a signal indicating KURL to
* send when the local user accepts the transfer.
* @param file If valid, the user will not be prompted for a URL, and this one will be used instead.
* If it refers to a remote file and mustBeLocal is true, the file will be transferred to the local
* filesystem.
* @param localFile file name to display if file is a valid URL
* @param fileSize file size to send if file is a valid URL
* @param mustBeLocal If the protocol can only send files on the local filesystem, this flag
* allows you to ensure the filename will be local.
* @param sendTo The object to send the signal to
* @param slot The slot to send the signal to. Signature: sendFile(const KURL &file)
*/
void sendFile( const KURL &file, const TQString &localFile, unsigned long fileSize,
bool mustBeLocal, TQObject *sendTo, const char *slot );
signals:
/** @brief Signals the transfer is done. */
void done( Kopete::Transfer* );
/** @brief Signals the transfer has been canceled. */
void canceled( Kopete::Transfer* );
/** @brief Signals the transfer has been accepted */
void accepted(Kopete::Transfer*, const TQString &fileName);
/** @brief Signals the transfer has been rejected */
void refused(const Kopete::FileTransferInfo& );
/** @brief Send a file */
void sendFile(const KURL &file, const TQString &localFile, unsigned int fileSize);
private slots:
void slotAccepted(const Kopete::FileTransferInfo&, const TQString&);
void slotComplete(KIO::Job*);
private:
TransferManager( TQObject *tqparent );
static TransferManager *s_transferManager;
int nextID;
TQMap<unsigned int, Transfer *> mTransfersMap;
};
/**
* A KIO job for a kopete file transfer.
* @author Richard Smith <kopete@metafoo.co.uk>
*/
class KOPETE_EXPORT Transfer : public KIO::Job
{
Q_OBJECT
TQ_OBJECT
public:
/**
* Constructor
*/
Transfer( const FileTransferInfo &, const TQString &localFile, bool showProgressInfo = true);
/**
* Constructor
*/
Transfer( const FileTransferInfo &, const Contact *toUser, bool showProgressInfo = true);
/**
* Destructor
*/
~Transfer();
/** @brief Get the info for this file transfer */
const FileTransferInfo &info() const { return mInfo; }
/**
* Retrieve a URL indicating where the file is being copied from.
* For display purposes only! There's no guarantee that this URL
* refers to a real file being transferred.
*/
KURL sourceURL();
/**
* Retrieve a URL indicating where the file is being copied to.
* See @ref sourceURL
*/
KURL destinationURL();
public slots:
/**
* @brief Set the file size processed so far
*/
void slotProcessed(unsigned int);
/**
* @brief Indicate that the transfer is complete
*/
void slotComplete();
/**
* @brief Inform the job that an error has occurred while transferring the file.
*
* @param error A member of the KIO::Error enumeration indicating what error occurred.
* @param errorText A string to aid understanding of the error, often the offending URL.
*/
void slotError( int error, const TQString &errorText );
signals:
/**
* @deprecated Use result() and check error() for ERR_USER_CANCELED
*/
void transferCanceled();
private:
void init( const KURL &, bool );
static KURL displayURL( const Contact *contact, const TQString &file );
FileTransferInfo mInfo;
KURL mTarget;
int mPercent;
private slots:
void slotResultEmitted();
};
}
#endif
// vim: set noet ts=4 sts=4 sw=4:
|