Basic infrastructure for file transfers
[quassel.git] / src / common / transfer.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2013 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "transfer.h"
22
23 INIT_SYNCABLE_OBJECT(Transfer)
24 Transfer::Transfer(const QUuid &uuid, QObject *parent)
25     : SyncableObject(parent),
26     _state(New),
27     _direction(Receive),
28     _port(0),
29     _fileSize(0),
30     _uuid(uuid)
31 {
32     renameObject(QString("Transfer/%1").arg(_uuid.toString()));
33 }
34
35 Transfer::Transfer(Direction direction, const QString &fileName, const QHostAddress &address, quint16 port, quint64 fileSize, QObject *parent)
36     : SyncableObject(parent),
37     _state(New),
38     _direction(direction),
39     _fileName(fileName),
40     _address(address),
41     _port(port),
42     _fileSize(fileSize),
43     _uuid(QUuid::createUuid())
44 {
45     renameObject(QString("Transfer/%1").arg(_uuid.toString()));
46 }
47
48
49 QUuid Transfer::uuid() const
50 {
51     return _uuid;
52 }
53
54
55 Transfer::State Transfer::state() const
56 {
57     return _state;
58 }
59
60
61 void Transfer::setState(Transfer::State state)
62 {
63     if (_state != state) {
64         _state = state;
65         SYNC(ARG(state));
66         emit stateChanged(state);
67     }
68 }
69
70
71
72 Transfer::Direction Transfer::direction() const
73 {
74     return _direction;
75 }
76
77
78 void Transfer::setDirection(Transfer::Direction direction)
79 {
80     if (_direction != direction) {
81         _direction = direction;
82         SYNC(ARG(direction));
83         emit directionChanged(direction);
84     }
85 }
86
87
88 QHostAddress Transfer::address() const
89 {
90     return _address;
91 }
92
93
94 void Transfer::setAddress(const QHostAddress &address)
95 {
96     if (_address != address) {
97         _address = address;
98         SYNC(ARG(address));
99         emit addressChanged(address);
100     }
101 }
102
103
104 quint16 Transfer::port() const
105 {
106     return _port;
107 }
108
109
110 void Transfer::setPort(quint16 port)
111 {
112     if (_port != port) {
113         _port = port;
114         SYNC(ARG(port));
115         emit portChanged(port);
116     }
117 }
118
119
120 QString Transfer::fileName() const
121 {
122     return _fileName;
123 }
124
125
126 void Transfer::setFileName(const QString &fileName)
127 {
128     if (_fileName != fileName) {
129         _fileName = fileName;
130         SYNC(ARG(fileName));
131         emit fileNameChanged(fileName);
132     }
133 }
134
135
136 quint64 Transfer::fileSize() const
137 {
138     return _fileSize;
139 }
140
141
142 void Transfer::setFileSize(quint64 fileSize)
143 {
144     if (_fileSize != fileSize) {
145         _fileSize = fileSize;
146         SYNC(ARG(fileSize));
147         emit fileSizeChanged(fileSize);
148     }
149 }