1 /***************************************************************************
2 * Copyright (C) 2005-2020 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 ***************************************************************************/
25 Transfer::Transfer(const QUuid& uuid, QObject* parent)
26 : SyncableObject(parent)
27 , _status(Status::New)
28 , _direction(Direction::Receive)
37 Direction direction, QString nick, QString fileName, const QHostAddress& address, quint16 port, quint64 fileSize, QObject* parent)
38 : SyncableObject(parent)
39 , _status(Status::New)
40 , _direction(direction)
41 , _fileName(std::move(fileName))
45 , _nick(std::move(nick))
46 , _uuid(QUuid::createUuid())
53 static auto regTypes = []() -> bool {
54 qRegisterMetaType<Status>("Transfer::Status");
55 qRegisterMetaType<Direction>("Transfer::Direction");
56 qRegisterMetaTypeStreamOperators<Status>("Transfer::Status");
57 qRegisterMetaTypeStreamOperators<Direction>("Transfer::Direction");
62 setObjectName(QString("Transfer/%1").arg(_uuid.toString()));
63 setAllowClientUpdates(true);
66 QUuid Transfer::uuid() const
71 Transfer::Status Transfer::status() const
76 void Transfer::setStatus(Transfer::Status status)
78 if (_status != status) {
81 emit statusChanged(status);
82 if (status == Status::Completed || status == Status::Failed) {
88 QString Transfer::prettyStatus() const
95 case Status::Connecting:
96 return tr("Connecting");
97 case Status::Transferring:
98 return tr("Transferring");
101 case Status::Completed:
102 return tr("Completed");
105 case Status::Rejected:
106 return tr("Rejected");
112 Transfer::Direction Transfer::direction() const
117 void Transfer::setDirection(Transfer::Direction direction)
119 if (_direction != direction) {
120 _direction = direction;
121 SYNC(ARG(direction));
122 emit directionChanged(direction);
126 QHostAddress Transfer::address() const
131 void Transfer::setAddress(const QHostAddress& address)
133 if (_address != address) {
136 emit addressChanged(address);
140 quint16 Transfer::port() const
145 void Transfer::setPort(quint16 port)
150 emit portChanged(port);
154 QString Transfer::fileName() const
159 void Transfer::setFileName(const QString& fileName)
161 if (_fileName != fileName) {
162 _fileName = fileName;
164 emit fileNameChanged(fileName);
168 quint64 Transfer::fileSize() const
173 void Transfer::setFileSize(quint64 fileSize)
175 if (_fileSize != fileSize) {
176 _fileSize = fileSize;
178 emit fileSizeChanged(fileSize);
182 QString Transfer::nick() const
187 void Transfer::setNick(const QString& nick)
192 emit nickChanged(nick);
196 void Transfer::setError(const QString& errorString)
198 qWarning() << Q_FUNC_INFO << errorString;
199 emit error(errorString);
200 setStatus(Status::Failed);
203 QDataStream& operator<<(QDataStream& out, Transfer::Status state)
205 out << static_cast<qint8>(state);
209 QDataStream& operator>>(QDataStream& in, Transfer::Status& state)
213 state = static_cast<Transfer::Status>(s);
217 QDataStream& operator<<(QDataStream& out, Transfer::Direction direction)
219 out << static_cast<qint8>(direction);
223 QDataStream& operator>>(QDataStream& in, Transfer::Direction& direction)
227 direction = static_cast<Transfer::Direction>(d);