clientignorelistmanager.cpp
     clientirclisthelper.cpp
     clientsettings.cpp
+    clienttransfermanager.cpp
     clientuserinputhandler.cpp
     coreaccount.cpp
     coreaccountmodel.cpp
     clientidentity.h
     clientignorelistmanager.h
     clientirclisthelper.h
+    clienttransfermanager.h
     clientuserinputhandler.h
     coreaccountmodel.h
     coreconnection.h
 
 #include "clientirclisthelper.h"
 #include "clientidentity.h"
 #include "clientignorelistmanager.h"
+#include "clienttransfermanager.h"
 #include "clientuserinputhandler.h"
 #include "coreaccountmodel.h"
 #include "coreconnection.h"
     _inputHandler(0),
     _networkConfig(0),
     _ignoreListManager(0),
+    _transferManager(0),
     _messageModel(0),
     _messageProcessor(0),
     _coreAccountModel(new CoreAccountModel(this)),
     _ignoreListManager = new ClientIgnoreListManager(this);
     signalProxy()->synchronize(ignoreListManager());
 
+    Q_ASSERT(!_transferManager);
+    _transferManager = new ClientTransferManager(this);
+    signalProxy()->synchronize(transferManager());
+
     // trigger backlog request once all active bufferviews are initialized
     connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
 
 
 class ClientBufferViewManager;
 class ClientIgnoreListManager;
 class ClientIrcListHelper;
+class ClientTransferManager;
 class ClientUserInputHandler;
 class CoreAccountModel;
 class CoreConnection;
 class IrcChannel;
 class NetworkConfig;
 class SignalProxy;
+
 struct NetworkInfo;
 
 class Client : public QObject
     static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
     static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
     static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
+    static inline ClientTransferManager *transferManager() { return instance()->_transferManager; }
 
     static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
     static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
     ClientUserInputHandler *_inputHandler;
     NetworkConfig *_networkConfig;
     ClientIgnoreListManager *_ignoreListManager;
+    ClientTransferManager *_transferManager;
 
     MessageModel *_messageModel;
     AbstractMessageProcessor *_messageProcessor;
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#include "clienttransfermanager.h"
+
+#include "client.h"
+#include "transfer.h"
+
+
+INIT_SYNCABLE_OBJECT(ClientTransferManager)
+ClientTransferManager::ClientTransferManager(QObject *parent)
+    : TransferManager(parent)
+{
+
+}
+
+
+void ClientTransferManager::onCoreTransferAdded(const QUuid &uuid)
+{
+    if (uuid.isNull()) {
+        qWarning() << Q_FUNC_INFO << "Invalid transfer uuid" << uuid.toString();
+        return;
+    }
+
+    Transfer *transfer = new Transfer(uuid, this);
+    connect(transfer, SIGNAL(initDone()), SLOT(onTransferInitDone())); // we only want to add initialized transfers
+    Client::signalProxy()->synchronize(transfer);
+}
+
+
+void ClientTransferManager::onTransferInitDone()
+{
+    Transfer *transfer = qobject_cast<Transfer *>(sender());
+    Q_ASSERT(transfer);
+    addTransfer(transfer);
+}
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#ifndef CLIENTTRANSFERMANAGER_H
+#define CLIENTTRANSFERMANAGER_H
+
+#include "transfermanager.h"
+
+#include <QUuid>
+
+class Transfer;
+
+class ClientTransferManager : public TransferManager
+{
+    Q_OBJECT
+    SYNCABLE_OBJECT
+
+public:
+    ClientTransferManager(QObject *parent = 0);
+
+public slots:
+    void onCoreTransferAdded(const QUuid &uuid);
+    void onTransferInitDone();
+
+};
+
+#endif
 
     settings.cpp
     signalproxy.cpp
     syncableobject.cpp
+    transfer.cpp
+    transfermanager.cpp
     util.cpp
 
     protocols/legacy/legacypeer.cpp
     settings.h
     signalproxy.h
     syncableobject.h
+    transfer.h
+    transfermanager.h
 
     protocols/legacy/legacypeer.h
 )
 
 #include <QLibraryInfo>
 #include <QSettings>
 #include <QTranslator>
+#include <QUuid>
 
 #include "bufferinfo.h"
 #include "identity.h"
     qRegisterMetaType<MsgId>("MsgId");
 
     qRegisterMetaType<QHostAddress>("QHostAddress");
+    qRegisterMetaType<QUuid>("QUuid");
 
     qRegisterMetaTypeStreamOperators<IdentityId>("IdentityId");
     qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#include "transfer.h"
+
+INIT_SYNCABLE_OBJECT(Transfer)
+Transfer::Transfer(const QUuid &uuid, QObject *parent)
+    : SyncableObject(parent),
+    _state(New),
+    _direction(Receive),
+    _port(0),
+    _fileSize(0),
+    _uuid(uuid)
+{
+    renameObject(QString("Transfer/%1").arg(_uuid.toString()));
+}
+
+Transfer::Transfer(Direction direction, const QString &fileName, const QHostAddress &address, quint16 port, quint64 fileSize, QObject *parent)
+    : SyncableObject(parent),
+    _state(New),
+    _direction(direction),
+    _fileName(fileName),
+    _address(address),
+    _port(port),
+    _fileSize(fileSize),
+    _uuid(QUuid::createUuid())
+{
+    renameObject(QString("Transfer/%1").arg(_uuid.toString()));
+}
+
+
+QUuid Transfer::uuid() const
+{
+    return _uuid;
+}
+
+
+Transfer::State Transfer::state() const
+{
+    return _state;
+}
+
+
+void Transfer::setState(Transfer::State state)
+{
+    if (_state != state) {
+        _state = state;
+        SYNC(ARG(state));
+        emit stateChanged(state);
+    }
+}
+
+
+
+Transfer::Direction Transfer::direction() const
+{
+    return _direction;
+}
+
+
+void Transfer::setDirection(Transfer::Direction direction)
+{
+    if (_direction != direction) {
+        _direction = direction;
+        SYNC(ARG(direction));
+        emit directionChanged(direction);
+    }
+}
+
+
+QHostAddress Transfer::address() const
+{
+    return _address;
+}
+
+
+void Transfer::setAddress(const QHostAddress &address)
+{
+    if (_address != address) {
+        _address = address;
+        SYNC(ARG(address));
+        emit addressChanged(address);
+    }
+}
+
+
+quint16 Transfer::port() const
+{
+    return _port;
+}
+
+
+void Transfer::setPort(quint16 port)
+{
+    if (_port != port) {
+        _port = port;
+        SYNC(ARG(port));
+        emit portChanged(port);
+    }
+}
+
+
+QString Transfer::fileName() const
+{
+    return _fileName;
+}
+
+
+void Transfer::setFileName(const QString &fileName)
+{
+    if (_fileName != fileName) {
+        _fileName = fileName;
+        SYNC(ARG(fileName));
+        emit fileNameChanged(fileName);
+    }
+}
+
+
+quint64 Transfer::fileSize() const
+{
+    return _fileSize;
+}
+
+
+void Transfer::setFileSize(quint64 fileSize)
+{
+    if (_fileSize != fileSize) {
+        _fileSize = fileSize;
+        SYNC(ARG(fileSize));
+        emit fileSizeChanged(fileSize);
+    }
+}
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#ifndef TRANSFER_H
+#define TRANSFER_H
+
+#include <QHostAddress>
+#include <QUuid>
+
+#include "syncableobject.h"
+
+class Transfer : public SyncableObject
+{
+    Q_OBJECT
+    SYNCABLE_OBJECT
+
+    Q_PROPERTY(QUuid uuid READ uuid);
+    Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged);
+    Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged);
+    Q_PROPERTY(QHostAddress address READ address WRITE setAddress NOTIFY addressChanged);
+    Q_PROPERTY(quint16 port READ port WRITE setPort NOTIFY portChanged);
+    Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged);
+    Q_PROPERTY(quint64 fileSize READ fileSize WRITE setFileSize NOTIFY fileSizeChanged);
+
+public:
+    enum State {
+        New,
+        Pending,
+        Transferring,
+        Paused,
+        Completed,
+        Failed,
+        Rejected
+    };
+    Q_ENUMS(State)
+
+    enum Direction {
+        Send,
+        Receive
+    };
+    Q_ENUMS(Direction)
+
+    Transfer(const QUuid &uuid, QObject *parent = 0); // for creating a syncable object client-side
+    Transfer(Direction direction, const QString &fileName, const QHostAddress &address, quint16 port, quint64 size = 0, QObject *parent = 0);
+
+    QUuid uuid() const;
+    State state() const;
+    Direction direction() const;
+    QString fileName() const;
+    QHostAddress address() const;
+    quint16 port() const;
+    quint64 fileSize() const;
+
+signals:
+    void stateChanged(State state);
+    void directionChanged(Direction direction);
+    void addressChanged(const QHostAddress &address);
+    void portChanged(quint16 port);
+    void fileNameChanged(const QString &fileName);
+    void fileSizeChanged(quint64 fileSize);
+
+protected:
+    void setState(State state);
+
+private:
+    void setDirection(Direction direction);
+    void setAddress(const QHostAddress &address);
+    void setPort(quint16 port);
+    void setFileName(const QString &fileName);
+    void setFileSize(quint64 fileSize);
+
+
+    State _state;
+    Direction _direction;
+    QString _fileName;
+    QHostAddress _address;
+    quint16 _port;
+    quint64 _fileSize;
+    QUuid _uuid;
+};
+
+#endif
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#include "transfermanager.h"
+
+#include "transfer.h"
+
+
+INIT_SYNCABLE_OBJECT(TransferManager)
+TransferManager::TransferManager(QObject *parent)
+    : SyncableObject(parent)
+{
+
+}
+
+
+void TransferManager::addTransfer(Transfer *transfer)
+{
+    QUuid uuid = transfer->uuid();
+    if (_transfers.contains(uuid)) {
+        qWarning() << "Cannot add the same file transfer twice!";
+        transfer->deleteLater();
+        return;
+    }
+    transfer->setParent(this);
+    _transfers[uuid] = transfer;
+
+    SYNC_OTHER(onCoreTransferAdded, ARG(uuid));
+    emit transferAdded(transfer);
+}
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#ifndef TRANSFERMANAGER_H
+#define TRANSFERMANAGER_H
+
+#include "syncableobject.h"
+
+#include <QUuid>
+
+class Transfer;
+
+class TransferManager : public SyncableObject
+{
+    Q_OBJECT
+    SYNCABLE_OBJECT
+
+public:
+    TransferManager(QObject *parent = 0);
+    inline virtual const QMetaObject *syncMetaObject() const { return &staticMetaObject; }
+
+    const Transfer *transfer(const QUuid &uuid) const;
+
+public slots:
+    void addTransfer(Transfer *transfer);
+
+signals:
+    void transferAdded(Transfer *transfer);
+
+protected slots:
+    virtual void onCoreTransferAdded(const QUuid &uuid) { Q_UNUSED(uuid) };
+
+private:
+    QHash<QUuid, Transfer *> _transfers;
+
+};
+
+#endif
 
     coresession.cpp
     coresessioneventprocessor.cpp
     coresettings.cpp
+    coretransfermanager.cpp
     coreuserinputhandler.cpp
     coreusersettings.cpp
     ctcpparser.cpp
     corenetworkconfig.h
     coresession.h
     coresessioneventprocessor.h
+    coretransfermanager.h
     coreuserinputhandler.h
     ctcpparser.h
     eventstringifier.h
 
 #include "corenetwork.h"
 #include "corenetworkconfig.h"
 #include "coresessioneventprocessor.h"
+#include "coretransfermanager.h"
 #include "coreusersettings.h"
 #include "ctcpparser.h"
 #include "eventstringifier.h"
     _ircListHelper(new CoreIrcListHelper(this)),
     _networkConfig(new CoreNetworkConfig("GlobalNetworkConfig", this)),
     _coreInfo(this),
+    _transferManager(new CoreTransferManager(this)),
     _eventManager(new CoreEventManager(this)),
     _eventStringifier(new EventStringifier(this)),
     _sessionEventProcessor(new CoreSessionEventProcessor(this)),
     p->synchronize(networkConfig());
     p->synchronize(&_coreInfo);
     p->synchronize(&_ignoreListManager);
+    p->synchronize(transferManager());
     // Restore session state
     if (restoreState)
         restoreSessionState();
 
 class CoreNetwork;
 class CoreNetworkConfig;
 class CoreSessionEventProcessor;
+class CoreTransferManager;
 class CtcpParser;
 class EventManager;
 class EventStringifier;
     inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
 
     inline CoreIgnoreListManager *ignoreListManager() { return &_ignoreListManager; }
+    inline CoreTransferManager *transferManager() const { return _transferManager; }
+
 //   void attachNetworkConnection(NetworkConnection *conn);
 
     //! Return necessary data for restoring the session after restarting the core
     CoreIrcListHelper *_ircListHelper;
     CoreNetworkConfig *_networkConfig;
     CoreCoreInfo _coreInfo;
+    CoreTransferManager *_transferManager;
 
     EventManager *_eventManager;
     EventStringifier *_eventStringifier; // should eventually move into client
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#include "coretransfermanager.h"
+
+#include "transfer.h"
+
+
+INIT_SYNCABLE_OBJECT(CoreTransferManager)
+CoreTransferManager::CoreTransferManager(QObject *parent)
+    : TransferManager(parent)
+{
+
+}
 
--- /dev/null
+/***************************************************************************
+ *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#ifndef CORETRANSFERMANAGER_H
+#define CORETRANSFERMANAGER_H
+
+#include "transfermanager.h"
+
+class CoreTransferManager : public TransferManager
+{
+    Q_OBJECT
+    SYNCABLE_OBJECT
+
+public:
+    CoreTransferManager(QObject *parent = 0);
+
+};
+
+#endif