-
Notifications
You must be signed in to change notification settings - Fork 1
/
oscarfiletransfer.h
127 lines (113 loc) · 3.97 KB
/
oscarfiletransfer.h
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
/****************************************************************************
**
** Ireen — cross-platform OSCAR protocol library
**
** Copyright © 2012 Alexey Prokhin <[email protected]>
**
*****************************************************************************
**
** $IREEN_BEGIN_LICENSE$
** This program 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 3
** of the License, or (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program. If not, see http://www.gnu.org/licenses/.
** $IREEN_END_LICENSE$
**
****************************************************************************/
#ifndef IREEN_OSCARFILETRANSFER_H
#define IREEN_OSCARFILETRANSFER_H
#include "ireen_global.h"
#include "messagehandler.h"
#include <QDateTime>
class QHostAddress;
namespace Ireen {
class Client;
class OftManager;
class OftConnectionPrivate;
class OftManagerPrivate;
class OftConnection : public QObject
{
Q_OBJECT
public:
enum ErrorType { NetworkError, Canceled, NotSupported, IOError, NoError };
enum State { Initiation, AwaitingIODevice, Started, Finished, Error };
virtual ~OftConnection();
QString uin() const;
quint64 cookie() const;
OftManager *manager() const;
Client *client() const;
quint16 localPort() const;
quint16 remotePort() const;
QHostAddress remoteAddress() const;
QString title() const;
quint32 totalSize() const;
quint16 filesCount() const;
QString currentFileName() const;
quint32 currentFileSize() const;
quint16 currentFileIndex() const;
void send();
void cancel();
void accept();
void resumeSending(QIODevice *outputDevice, const QString &name, quint32 size,
const QDateTime &lastModified = QDateTime());
void resumeReceiving(QIODevice *inputDevice);
signals:
void stateChanged(Ireen::OftConnection::State state);
void error(Ireen::OftConnection::ErrorType error, const QString &desc);
void progress(quint32 bytes);
void currentFileChanged();
void localPortChanged(quint16 port);
void remotePortChanged(quint16 port);
void remoteAddressChanged(const QHostAddress &addr);
private:
Q_PRIVATE_SLOT(d, void close())
Q_PRIVATE_SLOT(d, void startNextStage())
Q_PRIVATE_SLOT(d, void sendFileRequest())
Q_PRIVATE_SLOT(d, void connected())
Q_PRIVATE_SLOT(d, void onError(QAbstractSocket::SocketError))
Q_PRIVATE_SLOT(d, void onHeaderReaded())
Q_PRIVATE_SLOT(d, void onNewData())
Q_PRIVATE_SLOT(d, void onSendData())
Q_PRIVATE_SLOT(d, void resumeSendingImpl(quint32 checksum))
Q_PRIVATE_SLOT(d, void resumeReceivingImpl(quint32 checksum))
Q_PRIVATE_SLOT(d, void resumeFileReceivingImpl(quint32 checksum))
private:
OftConnection(const QString &uin, bool isIncoming,
quint64 cookie, OftManager *manager,
bool forceProxy, quint32 totalSize = 0,
quint16 filesCount = 1,
const QString &title = QString());
friend class OftServer;
friend class OftManager;
friend class OftManagerPrivate;
friend class OftConnectionPrivate;
QScopedPointer<OftConnectionPrivate> d;
};
class OftManager : public QObject
{
Q_OBJECT
public:
explicit OftManager(MessageHandler *messageHandler);
Client *client() const;
OftConnection *send(const QString &uin, quint32 totalSize,
quint16 filesCount = 1,
const QString &title = QString());
static void setAllowAnyServerPort(bool allowAnyServerPort);
static void setServerPorts(const QList<quint16> &ports);
signals:
void incomingConnection(Ireen::OftConnection *connection);
private:
friend class OftConnection;
friend class OftManagerPrivate;
QScopedPointer<OftManagerPrivate> d;
};
} // namespace Ireen
#endif // IREEN_OSCARFILETRANSFER_H