1 /***************************************************************************
2 * Copyright (C) 2005-2015 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 INIT_SYNCABLE_OBJECT(Transfer)
24 Transfer::Transfer(const QUuid &uuid, QObject *parent)
25 : SyncableObject(parent),
27 _direction(Direction::Receive),
35 Transfer::Transfer(Direction direction, const QString &nick, const QString &fileName, const QHostAddress &address, quint16 port, quint64 fileSize, QObject *parent)
36 : SyncableObject(parent),
38 _direction(direction),
44 _uuid(QUuid::createUuid())
52 static auto regTypes = []() -> bool {
53 qRegisterMetaType<State>("Transfer::State");
54 qRegisterMetaType<Direction>("Transfer::Direction");
55 qRegisterMetaTypeStreamOperators<State>("Transfer::State");
56 qRegisterMetaTypeStreamOperators<Direction>("Transfer::Direction");
61 renameObject(QString("Transfer/%1").arg(_uuid.toString()));
62 setAllowClientUpdates(true);
66 QUuid Transfer::uuid() const
72 Transfer::State Transfer::state() const
78 void Transfer::setState(Transfer::State state)
80 if (_state != state) {
83 emit stateChanged(state);
89 Transfer::Direction Transfer::direction() const
95 void Transfer::setDirection(Transfer::Direction direction)
97 if (_direction != direction) {
98 _direction = direction;
100 emit directionChanged(direction);
105 QHostAddress Transfer::address() const
111 void Transfer::setAddress(const QHostAddress &address)
113 if (_address != address) {
116 emit addressChanged(address);
121 quint16 Transfer::port() const
127 void Transfer::setPort(quint16 port)
132 emit portChanged(port);
137 QString Transfer::fileName() const
143 void Transfer::setFileName(const QString &fileName)
145 if (_fileName != fileName) {
146 _fileName = fileName;
148 emit fileNameChanged(fileName);
153 quint64 Transfer::fileSize() const
159 void Transfer::setFileSize(quint64 fileSize)
161 if (_fileSize != fileSize) {
162 _fileSize = fileSize;
164 emit fileSizeChanged(fileSize);
169 QString Transfer::nick() const
175 void Transfer::setNick(const QString &nick)
180 emit nickChanged(nick);
185 void Transfer::setError(const QString &errorString)
187 qWarning() << Q_FUNC_INFO << errorString;
188 emit error(errorString);
189 setState(State::Failed);
194 QDataStream &operator<<(QDataStream &out, Transfer::State state) {
195 out << static_cast<qint8>(state);
199 QDataStream &operator>>(QDataStream &in, Transfer::State &state) {
202 state = static_cast<Transfer::State>(s);
206 QDataStream &operator<<(QDataStream &out, Transfer::Direction direction) {
207 out << static_cast<qint8>(direction);
211 QDataStream &operator>>(QDataStream &in, Transfer::Direction &direction) {
214 direction = static_cast<Transfer::Direction>(d);