1 /***************************************************************************
2 * Copyright (C) 2005-2018 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<Status>("Transfer::Status");
54 qRegisterMetaType<Direction>("Transfer::Direction");
55 qRegisterMetaTypeStreamOperators<Status>("Transfer::Status");
56 qRegisterMetaTypeStreamOperators<Direction>("Transfer::Direction");
61 renameObject(QString("Transfer/%1").arg(_uuid.toString()));
62 setAllowClientUpdates(true);
66 QUuid Transfer::uuid() const
72 Transfer::Status Transfer::status() const
78 void Transfer::setStatus(Transfer::Status status)
80 if (_status != status) {
83 emit statusChanged(status);
84 if (status == Status::Completed || status == Status::Failed) {
91 QString Transfer::prettyStatus() const
98 case Status::Connecting:
99 return tr("Connecting");
100 case Status::Transferring:
101 return tr("Transferring");
104 case Status::Completed:
105 return tr("Completed");
108 case Status::Rejected:
109 return tr("Rejected");
117 Transfer::Direction Transfer::direction() const
123 void Transfer::setDirection(Transfer::Direction direction)
125 if (_direction != direction) {
126 _direction = direction;
127 SYNC(ARG(direction));
128 emit directionChanged(direction);
133 QHostAddress Transfer::address() const
139 void Transfer::setAddress(const QHostAddress &address)
141 if (_address != address) {
144 emit addressChanged(address);
149 quint16 Transfer::port() const
155 void Transfer::setPort(quint16 port)
160 emit portChanged(port);
165 QString Transfer::fileName() const
171 void Transfer::setFileName(const QString &fileName)
173 if (_fileName != fileName) {
174 _fileName = fileName;
176 emit fileNameChanged(fileName);
181 quint64 Transfer::fileSize() const
187 void Transfer::setFileSize(quint64 fileSize)
189 if (_fileSize != fileSize) {
190 _fileSize = fileSize;
192 emit fileSizeChanged(fileSize);
197 QString Transfer::nick() const
203 void Transfer::setNick(const QString &nick)
208 emit nickChanged(nick);
213 void Transfer::setError(const QString &errorString)
215 qWarning() << Q_FUNC_INFO << errorString;
216 emit error(errorString);
217 setStatus(Status::Failed);
221 QDataStream &operator<<(QDataStream &out, Transfer::Status state) {
222 out << static_cast<qint8>(state);
226 QDataStream &operator>>(QDataStream &in, Transfer::Status &state) {
229 state = static_cast<Transfer::Status>(s);
233 QDataStream &operator<<(QDataStream &out, Transfer::Direction direction) {
234 out << static_cast<qint8>(direction);
238 QDataStream &operator>>(QDataStream &in, Transfer::Direction &direction) {
241 direction = static_cast<Transfer::Direction>(d);