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 ***************************************************************************/
25 Transfer::Transfer(const QUuid &uuid, QObject *parent)
26 : SyncableObject(parent),
28 _direction(Direction::Receive),
36 Transfer::Transfer(Direction direction, QString nick, QString fileName, const QHostAddress &address, quint16 port, quint64 fileSize, QObject *parent)
37 : SyncableObject(parent),
39 _direction(direction),
40 _fileName(std::move(fileName)),
44 _nick(std::move(nick)),
45 _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 renameObject(QString("Transfer/%1").arg(_uuid.toString()));
63 setAllowClientUpdates(true);
67 QUuid Transfer::uuid() const
73 Transfer::Status Transfer::status() const
79 void Transfer::setStatus(Transfer::Status status)
81 if (_status != status) {
84 emit statusChanged(status);
85 if (status == Status::Completed || status == Status::Failed) {
92 QString Transfer::prettyStatus() const
99 case Status::Connecting:
100 return tr("Connecting");
101 case Status::Transferring:
102 return tr("Transferring");
105 case Status::Completed:
106 return tr("Completed");
109 case Status::Rejected:
110 return tr("Rejected");
118 Transfer::Direction Transfer::direction() const
124 void Transfer::setDirection(Transfer::Direction direction)
126 if (_direction != direction) {
127 _direction = direction;
128 SYNC(ARG(direction));
129 emit directionChanged(direction);
134 QHostAddress Transfer::address() const
140 void Transfer::setAddress(const QHostAddress &address)
142 if (_address != address) {
145 emit addressChanged(address);
150 quint16 Transfer::port() const
156 void Transfer::setPort(quint16 port)
161 emit portChanged(port);
166 QString Transfer::fileName() const
172 void Transfer::setFileName(const QString &fileName)
174 if (_fileName != fileName) {
175 _fileName = fileName;
177 emit fileNameChanged(fileName);
182 quint64 Transfer::fileSize() const
188 void Transfer::setFileSize(quint64 fileSize)
190 if (_fileSize != fileSize) {
191 _fileSize = fileSize;
193 emit fileSizeChanged(fileSize);
198 QString Transfer::nick() const
204 void Transfer::setNick(const QString &nick)
209 emit nickChanged(nick);
214 void Transfer::setError(const QString &errorString)
216 qWarning() << Q_FUNC_INFO << errorString;
217 emit error(errorString);
218 setStatus(Status::Failed);
222 QDataStream &operator<<(QDataStream &out, Transfer::Status state) {
223 out << static_cast<qint8>(state);
227 QDataStream &operator>>(QDataStream &in, Transfer::Status &state) {
230 state = static_cast<Transfer::Status>(s);
234 QDataStream &operator<<(QDataStream &out, Transfer::Direction direction) {
235 out << static_cast<qint8>(direction);
239 QDataStream &operator>>(QDataStream &in, Transfer::Direction &direction) {
242 direction = static_cast<Transfer::Direction>(d);