Make the Transfer::accept() and ::reject() machinery work
[quassel.git] / src / common / transfer.h
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 #ifndef TRANSFER_H
22 #define TRANSFER_H
23
24 #include <QHostAddress>
25 #include <QUuid>
26
27 #include "syncableobject.h"
28 #include "types.h"
29
30 class Transfer : public SyncableObject
31 {
32     Q_OBJECT
33     SYNCABLE_OBJECT
34
35     Q_PROPERTY(QUuid uuid READ uuid);
36     Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged);
37     Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged);
38     Q_PROPERTY(QHostAddress address READ address WRITE setAddress NOTIFY addressChanged);
39     Q_PROPERTY(quint16 port READ port WRITE setPort NOTIFY portChanged);
40     Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged);
41     Q_PROPERTY(quint64 fileSize READ fileSize WRITE setFileSize NOTIFY fileSizeChanged);
42     Q_PROPERTY(QString nick READ nick WRITE setNick NOTIFY nickChanged);
43
44 public:
45     enum State {
46         New,
47         Pending,
48         Transferring,
49         Paused,
50         Completed,
51         Failed,
52         Rejected
53     };
54     Q_ENUMS(State)
55
56     enum Direction {
57         Send,
58         Receive
59     };
60     Q_ENUMS(Direction)
61
62     Transfer(const QUuid &uuid, QObject *parent = 0); // for creating a syncable object client-side
63     Transfer(Direction direction, const QString &nick, const QString &fileName, const QHostAddress &address, quint16 port, quint64 size = 0, QObject *parent = 0);
64
65     QUuid uuid() const;
66     State state() const;
67     Direction direction() const;
68     QString fileName() const;
69     QHostAddress address() const;
70     quint16 port() const;
71     quint64 fileSize() const;
72     QString nick() const;
73
74     QString savePath() const;
75
76 public slots:
77     // called on the client side
78     void accept(const QString &savePath) const;
79     void reject() const;
80
81     // called on the core side through sync calls
82     void requestAccepted(PeerPtr peer = 0);
83     void requestRejected();
84
85 signals:
86     void stateChanged(State state);
87     void directionChanged(Direction direction);
88     void addressChanged(const QHostAddress &address);
89     void portChanged(quint16 port);
90     void fileNameChanged(const QString &fileName);
91     void fileSizeChanged(quint64 fileSize);
92     void nickChanged(const QString &nick);
93
94     void accepted(PeerPtr peer = 0) const;
95     void rejected() const;
96
97 protected:
98     void setState(State state);
99
100 private:
101     void init();
102
103     void setDirection(Direction direction);
104     void setAddress(const QHostAddress &address);
105     void setPort(quint16 port);
106     void setFileName(const QString &fileName);
107     void setFileSize(quint64 fileSize);
108     void setNick(const QString &nick);
109
110
111     State _state;
112     Direction _direction;
113     QString _fileName;
114     QHostAddress _address;
115     quint16 _port;
116     quint64 _fileSize;
117     QString _nick;
118     QUuid _uuid;
119
120     // non-synced attributes
121     mutable QString _savePath;
122 };
123
124 #endif