~ubuntu-branches/ubuntu/trusty/quassel/trusty-proposed

« back to all changes in this revision

Viewing changes to src/common/transfer.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-18 23:18:25 UTC
  • mto: This revision was merged to the branch mainline in revision 98.
  • Revision ID: package-import@ubuntu.com-20140218231825-hfgaeo3nmszt2pth
Tags: upstream-0.10~beta1
ImportĀ upstreamĀ versionĀ 0.10~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005-2014 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
    init();
 
33
}
 
34
 
 
35
Transfer::Transfer(Direction direction, const QString &nick, 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
    _nick(nick),
 
44
    _uuid(QUuid::createUuid())
 
45
{
 
46
    init();
 
47
}
 
48
 
 
49
 
 
50
void Transfer::init()
 
51
{
 
52
    renameObject(QString("Transfer/%1").arg(_uuid.toString()));
 
53
    setAllowClientUpdates(true);
 
54
}
 
55
 
 
56
 
 
57
QUuid Transfer::uuid() const
 
58
{
 
59
    return _uuid;
 
60
}
 
61
 
 
62
 
 
63
Transfer::State Transfer::state() const
 
64
{
 
65
    return _state;
 
66
}
 
67
 
 
68
 
 
69
void Transfer::setState(Transfer::State state)
 
70
{
 
71
    if (_state != state) {
 
72
        _state = state;
 
73
        SYNC(ARG(state));
 
74
        emit stateChanged(state);
 
75
    }
 
76
}
 
77
 
 
78
 
 
79
 
 
80
Transfer::Direction Transfer::direction() const
 
81
{
 
82
    return _direction;
 
83
}
 
84
 
 
85
 
 
86
void Transfer::setDirection(Transfer::Direction direction)
 
87
{
 
88
    if (_direction != direction) {
 
89
        _direction = direction;
 
90
        SYNC(ARG(direction));
 
91
        emit directionChanged(direction);
 
92
    }
 
93
}
 
94
 
 
95
 
 
96
QHostAddress Transfer::address() const
 
97
{
 
98
    return _address;
 
99
}
 
100
 
 
101
 
 
102
void Transfer::setAddress(const QHostAddress &address)
 
103
{
 
104
    if (_address != address) {
 
105
        _address = address;
 
106
        SYNC(ARG(address));
 
107
        emit addressChanged(address);
 
108
    }
 
109
}
 
110
 
 
111
 
 
112
quint16 Transfer::port() const
 
113
{
 
114
    return _port;
 
115
}
 
116
 
 
117
 
 
118
void Transfer::setPort(quint16 port)
 
119
{
 
120
    if (_port != port) {
 
121
        _port = port;
 
122
        SYNC(ARG(port));
 
123
        emit portChanged(port);
 
124
    }
 
125
}
 
126
 
 
127
 
 
128
QString Transfer::fileName() const
 
129
{
 
130
    return _fileName;
 
131
}
 
132
 
 
133
 
 
134
void Transfer::setFileName(const QString &fileName)
 
135
{
 
136
    if (_fileName != fileName) {
 
137
        _fileName = fileName;
 
138
        SYNC(ARG(fileName));
 
139
        emit fileNameChanged(fileName);
 
140
    }
 
141
}
 
142
 
 
143
 
 
144
quint64 Transfer::fileSize() const
 
145
{
 
146
    return _fileSize;
 
147
}
 
148
 
 
149
 
 
150
void Transfer::setFileSize(quint64 fileSize)
 
151
{
 
152
    if (_fileSize != fileSize) {
 
153
        _fileSize = fileSize;
 
154
        SYNC(ARG(fileSize));
 
155
        emit fileSizeChanged(fileSize);
 
156
    }
 
157
}
 
158
 
 
159
 
 
160
QString Transfer::nick() const
 
161
{
 
162
    return _nick;
 
163
}
 
164
 
 
165
 
 
166
void Transfer::setNick(const QString &nick)
 
167
{
 
168
    if (_nick != nick) {
 
169
        _nick = nick;
 
170
        SYNC(ARG(nick));
 
171
        emit nickChanged(nick);
 
172
    }
 
173
}
 
174
 
 
175
 
 
176
void Transfer::setError(const QString &errorString)
 
177
{
 
178
    qWarning() << Q_FUNC_INFO << errorString;
 
179
    emit error(errorString);
 
180
    setState(Failed);
 
181
    cleanUp();
 
182
}