remove actions which are not supported, this way they are also not visible in shortcu...
[kdenetwork.git] / kopete / libkopete / kopetetransfermanager.h
blob87f54bddbe4b3589aa8cc4ea25f00348d28f7335
1 /*
2 kopetetransfermanager.h
4 Copyright (c) 2002-2003 by Nick Betcher <nbetcher@kde.org>
5 Copyright (c) 2002-2003 by Richard Smith <kopete@metafoo.co.uk>
7 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
10 * *
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU Lesser General Public *
13 * License as published by the Free Software Foundation; either *
14 * version 2 of the License, or (at your option) any later version. *
15 * *
16 *************************************************************************
19 #ifndef KOPETETRANSFERMANAGER_H
20 #define KOPETETRANSFERMANAGER_H
22 #include <QtCore/QObject>
23 #include <QtCore/QString>
24 #include <QtCore/QMap>
26 #include "kopete_export.h"
28 #include <kio/job.h>
30 namespace Kopete
33 class Transfer;
34 class Contact;
35 class Message;
37 /**
38 * @author Nick Betcher. <nbetcher@kde.org>
40 class KOPETE_EXPORT FileTransferInfo
42 public:
43 enum KopeteTransferDirection { Incoming, Outgoing };
45 FileTransferInfo( Contact *, const QString&, const unsigned long size, const QString &, KopeteTransferDirection di, const unsigned int id, QString internalId=QString(), const QPixmap &preview=QPixmap() );
46 ~FileTransferInfo() {}
47 unsigned int transferId() const { return mId; }
48 Contact* contact() const { return mContact; }
49 QString file() const { return mFile; }
50 QString recipient() const { return mRecipient; }
51 unsigned long size() const { return mSize; }
52 QString internalId() const { return m_intId; }
53 KopeteTransferDirection direction() const { return mDirection; }
54 QPixmap preview() const { return mPreview; }
56 private:
57 unsigned long mSize;
58 QString mRecipient;
59 unsigned int mId;
60 Contact *mContact;
61 QString mFile;
62 QString m_intId;
63 KopeteTransferDirection mDirection;
64 QPixmap mPreview;
67 /**
68 * Creates and manages kopete file transfers
70 class KOPETE_EXPORT TransferManager : public QObject
72 Q_OBJECT
74 public:
75 /**
76 * Retrieve the transfer manager instance
78 static TransferManager* transferManager();
79 virtual ~TransferManager() {}
81 /**
82 * @brief Adds a file transfer to the Kopete::TransferManager
84 Transfer *addTransfer( Contact *contact, const QString& file, const unsigned long size, const QString &recipient , FileTransferInfo::KopeteTransferDirection di);
85 int askIncomingTransfer( Contact *contact, const QString& file, const unsigned long size, const QString& description=QString(), QString internalId=QString(), const QPixmap &preview=QPixmap());
86 void removeTransfer( unsigned int id );
88 /**
89 * @brief Ask the user which file to send when they click Send File.
91 * Possibly ask the user which file to send when they click Send File. Sends a signal indicating KUrl to
92 * send when the local user accepts the transfer.
93 * @param file If valid, the user will not be prompted for a URL, and this one will be used instead.
94 * If it refers to a remote file and mustBeLocal is true, the file will be transferred to the local
95 * filesystem.
96 * @param localFile file name to display if file is a valid URL
97 * @param fileSize file size to send if file is a valid URL
98 * @param mustBeLocal If the protocol can only send files on the local filesystem, this flag
99 * allows you to ensure the filename will be local.
100 * @param sendTo The object to send the signal to
101 * @param slot The slot to send the signal to. Signature: sendFile(const KUrl &file)
103 void sendFile( const KUrl &file, const QString &localFile, unsigned long fileSize,
104 bool mustBeLocal, QObject *sendTo, const char *slot );
106 signals:
107 /** @brief Signals the transfer is done. */
108 void done( Kopete::Transfer* );
110 /** @brief Signals the transfer has been canceled. */
111 void canceled( Kopete::Transfer* );
113 /** @brief Signals the transfer has been accepted */
114 void accepted(Kopete::Transfer*, const QString &fileName);
116 /** @brief Signals the transfer has been rejected */
117 void refused(const Kopete::FileTransferInfo& );
119 /** @brief Send a file */
120 void sendFile(const KUrl &file, const QString &localFile, unsigned int fileSize);
122 private slots:
123 void slotAccepted(const Kopete::FileTransferInfo&, const QString&);
124 void slotComplete(KJob*);
126 private:
127 TransferManager( QObject *parent );
129 int nextID;
130 QMap<unsigned int, Transfer *> mTransfersMap;
134 * A KIO job for a kopete file transfer.
135 * @author Richard Smith <kopete@metafoo.co.uk>
137 class KOPETE_EXPORT Transfer : public KIO::Job
139 Q_OBJECT
141 public:
143 * Constructor
145 Transfer( const FileTransferInfo &, const QString &localFile, bool showProgressInfo = true);
148 * Constructor
150 Transfer( const FileTransferInfo &, const Contact *toUser, bool showProgressInfo = true);
153 * Destructor
155 ~Transfer();
157 /** @brief Get the info for this file transfer */
158 const FileTransferInfo &info() const { return mInfo; }
161 * Retrieve a URL indicating where the file is being copied from.
162 * For display purposes only! There's no guarantee that this URL
163 * refers to a real file being transferred.
165 KUrl sourceURL();
168 * Retrieve a URL indicating where the file is being copied to.
169 * See @ref sourceURL
171 KUrl destinationURL();
172 protected:
173 void emitCopying(const KUrl &src, const KUrl &dest);
175 public slots:
178 * @brief Set the file size processed so far
180 void slotProcessed(unsigned int);
183 * @brief Indicate that the transfer is complete
185 void slotComplete();
188 * @brief Inform the job that an error has occurred while transferring the file.
190 * @param error A member of the KIO::Error enumeration indicating what error occurred.
191 * @param errorText A string to aid understanding of the error, often the offending URL.
193 void slotError( int error, const QString &errorText );
195 /** transfer was cancelled (but not by our user) */
196 void slotCancelled();
197 /** something interesting happened; not an error /
198 void slotInfo( int type, const QString &text ); */
200 /** display a message in the chatwindow if it exists */
201 bool showMessage( QString text );
203 signals:
205 * @deprecated Use result() and check error() for ERR_USER_CANCELED
207 void transferCanceled();
209 private:
210 void init( const KUrl &, bool );
212 static KUrl displayURL( const Contact *contact, const QString &file );
214 FileTransferInfo mInfo;
215 KUrl mTarget;
216 int mPercent;
218 private slots:
219 void slotResultEmitted();
224 #endif // KOPETETRANSFERMANAGER_H
225 // vim: set noet ts=4 sts=4 sw=4: