Refactor the transfer stuff
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Dec 2013 21:26:27 +0000 (22:26 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 1 Jan 2014 22:15:15 +0000 (23:15 +0100)
Well, sometimes refactorings come sooner than usual. While thinking
about the next steps, I decided to handle the actual transfer logic
inside Transfer rather than TransferManager - now that we can have
selective (peer-based) sync calls as well, that makes more sense than
outsourcing that to TransferManager. Thus, it now makes lots of sense
to have ClientTransfer and CoreTransfer, as the logic will be quite
different.

I also took the opportunity to clean up the accessors and make them
safer; you can now get a non-const CoreTransfer pointer, for example,
but still only a const ClientTransfer pointer.

Also, some useful signals have been added.

16 files changed:
src/client/CMakeLists.txt
src/client/clienttransfer.cpp [new file with mode: 0644]
src/client/clienttransfer.h [new file with mode: 0644]
src/client/clienttransfermanager.cpp
src/client/clienttransfermanager.h
src/common/transfer.cpp
src/common/transfer.h
src/common/transfermanager.cpp
src/common/transfermanager.h
src/core/CMakeLists.txt
src/core/coresessioneventprocessor.cpp
src/core/coretransfer.cpp [new file with mode: 0644]
src/core/coretransfer.h [new file with mode: 0644]
src/core/coretransfermanager.cpp
src/core/coretransfermanager.h
src/qtui/mainwin.cpp

index b5fef02..c7b3ee3 100644 (file)
@@ -33,6 +33,7 @@ set(SOURCES
     clientignorelistmanager.cpp
     clientirclisthelper.cpp
     clientsettings.cpp
     clientignorelistmanager.cpp
     clientirclisthelper.cpp
     clientsettings.cpp
+    clienttransfer.cpp
     clienttransfermanager.cpp
     clientuserinputhandler.cpp
     coreaccount.cpp
     clienttransfermanager.cpp
     clientuserinputhandler.cpp
     coreaccount.cpp
@@ -61,6 +62,7 @@ set(MOC_HDRS
     clientidentity.h
     clientignorelistmanager.h
     clientirclisthelper.h
     clientidentity.h
     clientignorelistmanager.h
     clientirclisthelper.h
+    clienttransfer.h
     clienttransfermanager.h
     clientuserinputhandler.h
     coreaccountmodel.h
     clienttransfermanager.h
     clientuserinputhandler.h
     coreaccountmodel.h
diff --git a/src/client/clienttransfer.cpp b/src/client/clienttransfer.cpp
new file mode 100644 (file)
index 0000000..aab69b3
--- /dev/null
@@ -0,0 +1,51 @@
+/***************************************************************************
+ *   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 "clienttransfer.h"
+
+INIT_SYNCABLE_OBJECT(ClientTransfer)
+ClientTransfer::ClientTransfer(const QUuid &uuid, QObject *parent)
+    : Transfer(uuid, parent)
+{
+
+}
+
+
+QString ClientTransfer::savePath() const
+{
+    return _savePath;
+}
+
+
+void ClientTransfer::accept(const QString &savePath) const
+{
+    _savePath = savePath;
+    PeerPtr ptr = 0;
+    REQUEST_OTHER(requestAccepted, ARG(ptr));
+    emit accepted();
+}
+
+
+void ClientTransfer::reject() const
+{
+    PeerPtr ptr = 0;
+    REQUEST_OTHER(requestRejected, ARG(ptr));
+    emit rejected();
+}
diff --git a/src/client/clienttransfer.h b/src/client/clienttransfer.h
new file mode 100644 (file)
index 0000000..b1ca5df
--- /dev/null
@@ -0,0 +1,48 @@
+/***************************************************************************
+ *   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 CLIENTTRANSFER_H
+#define CLIENTTRANSFER_H
+
+#include <QUuid>
+
+#include "transfer.h"
+
+class ClientTransfer : public Transfer
+{
+    Q_OBJECT
+    SYNCABLE_OBJECT
+
+public:
+    ClientTransfer(const QUuid &uuid, QObject *parent = 0);
+
+    QString savePath() const;
+
+public slots:
+    // called on the client side
+    void accept(const QString &savePath) const;
+    void reject() const;
+
+private:
+    // non-synced attributes
+    mutable QString _savePath;
+};
+
+#endif
index 7e89cca..e79c84e 100644 (file)
@@ -21,7 +21,7 @@
 #include "clienttransfermanager.h"
 
 #include "client.h"
 #include "clienttransfermanager.h"
 
 #include "client.h"
-#include "transfer.h"
+#include "clienttransfer.h"
 
 
 INIT_SYNCABLE_OBJECT(ClientTransferManager)
 
 
 INIT_SYNCABLE_OBJECT(ClientTransferManager)
@@ -32,6 +32,12 @@ ClientTransferManager::ClientTransferManager(QObject *parent)
 }
 
 
 }
 
 
+const ClientTransfer *ClientTransferManager::transfer(const QUuid &uuid) const
+{
+    return qobject_cast<const ClientTransfer *>(transfer_(uuid));
+}
+
+
 void ClientTransferManager::onCoreTransferAdded(const QUuid &uuid)
 {
     if (uuid.isNull()) {
 void ClientTransferManager::onCoreTransferAdded(const QUuid &uuid)
 {
     if (uuid.isNull()) {
@@ -39,7 +45,7 @@ void ClientTransferManager::onCoreTransferAdded(const QUuid &uuid)
         return;
     }
 
         return;
     }
 
-    Transfer *transfer = new Transfer(uuid, this);
+    ClientTransfer *transfer = new ClientTransfer(uuid, this);
     connect(transfer, SIGNAL(initDone()), SLOT(onTransferInitDone())); // we only want to add initialized transfers
     Client::signalProxy()->synchronize(transfer);
 }
     connect(transfer, SIGNAL(initDone()), SLOT(onTransferInitDone())); // we only want to add initialized transfers
     Client::signalProxy()->synchronize(transfer);
 }
@@ -55,6 +61,11 @@ void ClientTransferManager::onTransferInitDone()
 
 void ClientTransferManager::onTransferAdded(const Transfer *transfer)
 {
 
 void ClientTransferManager::onTransferAdded(const Transfer *transfer)
 {
-    // FIXME just a temporary solution
-    emit newTransfer(transfer);
+    const ClientTransfer *t = qobject_cast<const ClientTransfer *>(transfer);
+    if (!t) {
+        qWarning() << "Invalid Transfer added to ClientTransferManager!";
+        return;
+    }
+
+    emit transferAdded(t);
 }
 }
index d2483ca..505ae1e 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <QUuid>
 
 
 #include <QUuid>
 
-class Transfer;
+class ClientTransfer;
 
 class ClientTransferManager : public TransferManager
 {
 
 class ClientTransferManager : public TransferManager
 {
@@ -35,12 +35,14 @@ class ClientTransferManager : public TransferManager
 public:
     ClientTransferManager(QObject *parent = 0);
 
 public:
     ClientTransferManager(QObject *parent = 0);
 
+    const ClientTransfer *transfer(const QUuid &uuid) const;
+
 public slots:
     void onCoreTransferAdded(const QUuid &uuid);
     void onTransferInitDone();
 
 signals:
 public slots:
     void onCoreTransferAdded(const QUuid &uuid);
     void onTransferInitDone();
 
 signals:
-    void newTransfer(const Transfer *transfer);
+    void transferAdded(const ClientTransfer *transfer);
 
 private slots:
     void onTransferAdded(const Transfer *transfer);
 
 private slots:
     void onTransferAdded(const Transfer *transfer);
index 25f1e20..e9c81f7 100644 (file)
@@ -171,37 +171,3 @@ void Transfer::setNick(const QString &nick)
         emit nickChanged(nick);
     }
 }
         emit nickChanged(nick);
     }
 }
-
-
-QString Transfer::savePath() const
-{
-    return _savePath;
-}
-
-
-void Transfer::accept(const QString &savePath) const
-{
-    _savePath = savePath;
-    PeerPtr ptr = 0;
-    REQUEST_OTHER(requestAccepted, ARG(ptr));
-    emit accepted();
-}
-
-
-void Transfer::reject() const
-{
-    REQUEST_OTHER(requestRejected, NO_ARG);
-    emit rejected();
-}
-
-
-void Transfer::requestAccepted(PeerPtr peer)
-{
-    emit accepted(peer);
-}
-
-
-void Transfer::requestRejected()
-{
-    emit rejected();
-}
index e36ed15..bdbad9f 100644 (file)
@@ -61,6 +61,7 @@ public:
 
     Transfer(const QUuid &uuid, QObject *parent = 0); // for creating a syncable object client-side
     Transfer(Direction direction, const QString &nick, const QString &fileName, const QHostAddress &address, quint16 port, quint64 size = 0, QObject *parent = 0);
 
     Transfer(const QUuid &uuid, QObject *parent = 0); // for creating a syncable object client-side
     Transfer(Direction direction, const QString &nick, const QString &fileName, const QHostAddress &address, quint16 port, quint64 size = 0, QObject *parent = 0);
+    inline virtual const QMetaObject *syncMetaObject() const { return &staticMetaObject; }
 
     QUuid uuid() const;
     State state() const;
 
     QUuid uuid() const;
     State state() const;
@@ -71,16 +72,14 @@ public:
     quint64 fileSize() const;
     QString nick() const;
 
     quint64 fileSize() const;
     QString nick() const;
 
-    QString savePath() const;
-
 public slots:
     // called on the client side
 public slots:
     // called on the client side
-    void accept(const QString &savePath) const;
-    void reject() const;
+    virtual void accept(const QString &savePath) const { Q_UNUSED(savePath); }
+    virtual void reject() const {}
 
     // called on the core side through sync calls
 
     // called on the core side through sync calls
-    void requestAccepted(PeerPtr peer = 0);
-    void requestRejected();
+    virtual void requestAccepted(PeerPtr peer) { Q_UNUSED(peer); }
+    virtual void requestRejected(PeerPtr peer) { Q_UNUSED(peer); }
 
 signals:
     void stateChanged(State state);
 
 signals:
     void stateChanged(State state);
@@ -92,7 +91,7 @@ signals:
     void nickChanged(const QString &nick);
 
     void accepted(PeerPtr peer = 0) const;
     void nickChanged(const QString &nick);
 
     void accepted(PeerPtr peer = 0) const;
-    void rejected() const;
+    void rejected(PeerPtr peer = 0) const;
 
 protected:
     void setState(State state);
 
 protected:
     void setState(State state);
@@ -116,9 +115,6 @@ private:
     quint64 _fileSize;
     QString _nick;
     QUuid _uuid;
     quint64 _fileSize;
     QString _nick;
     QUuid _uuid;
-
-    // non-synced attributes
-    mutable QString _savePath;
 };
 
 #endif
 };
 
 #endif
index 92b3f6c..2e6b9b1 100644 (file)
@@ -31,7 +31,7 @@ TransferManager::TransferManager(QObject *parent)
 }
 
 
 }
 
 
-const Transfer *TransferManager::transfer(const QUuid &uuid) const
+Transfer *TransferManager::transfer_(const QUuid &uuid) const
 {
     return _transfers.value(uuid, 0);
 }
 {
     return _transfers.value(uuid, 0);
 }
index 77c864c..6686b00 100644 (file)
@@ -36,15 +36,15 @@ public:
     TransferManager(QObject *parent = 0);
     inline virtual const QMetaObject *syncMetaObject() const { return &staticMetaObject; }
 
     TransferManager(QObject *parent = 0);
     inline virtual const QMetaObject *syncMetaObject() const { return &staticMetaObject; }
 
-    const Transfer *transfer(const QUuid &uuid) const;
     QList<QUuid> transferIds() const;
 
     QList<QUuid> transferIds() const;
 
-public slots:
-    void addTransfer(Transfer *transfer);
-
 signals:
     void transferAdded(const Transfer *transfer);
 
 signals:
     void transferAdded(const Transfer *transfer);
 
+protected:
+    Transfer *transfer_(const QUuid &uuid) const;
+    void addTransfer(Transfer *transfer);
+
 protected slots:
     virtual void onCoreTransferAdded(const QUuid &uuid) { Q_UNUSED(uuid) };
 
 protected slots:
     virtual void onCoreTransferAdded(const QUuid &uuid) { Q_UNUSED(uuid) };
 
index 265ac0d..dfb0289 100644 (file)
@@ -24,6 +24,7 @@ set(SOURCES
     coresession.cpp
     coresessioneventprocessor.cpp
     coresettings.cpp
     coresession.cpp
     coresessioneventprocessor.cpp
     coresettings.cpp
+    coretransfer.cpp
     coretransfermanager.cpp
     coreuserinputhandler.cpp
     coreusersettings.cpp
     coretransfermanager.cpp
     coreuserinputhandler.cpp
     coreusersettings.cpp
@@ -59,6 +60,7 @@ set(MOC_HDRS
     corenetworkconfig.h
     coresession.h
     coresessioneventprocessor.h
     corenetworkconfig.h
     coresession.h
     coresessioneventprocessor.h
+    coretransfer.h
     coretransfermanager.h
     coreuserinputhandler.h
     ctcpparser.h
     coretransfermanager.h
     coreuserinputhandler.h
     ctcpparser.h
index 844155b..deca988 100644 (file)
@@ -23,6 +23,7 @@
 #include "coreirclisthelper.h"
 #include "corenetwork.h"
 #include "coresession.h"
 #include "coreirclisthelper.h"
 #include "corenetwork.h"
 #include "coresession.h"
+#include "coretransfer.h"
 #include "coretransfermanager.h"
 #include "ctcpevent.h"
 #include "ircevent.h"
 #include "coretransfermanager.h"
 #include "ctcpevent.h"
 #include "ircevent.h"
@@ -30,7 +31,6 @@
 #include "messageevent.h"
 #include "netsplit.h"
 #include "quassel.h"
 #include "messageevent.h"
 #include "netsplit.h"
 #include "quassel.h"
-#include "transfer.h"
 
 #ifdef HAVE_QCA2
 #  include "keyevent.h"
 
 #ifdef HAVE_QCA2
 #  include "keyevent.h"
@@ -1059,7 +1059,7 @@ void CoreSessionEventProcessor::handleCtcpDcc(CtcpEvent *e)
             }
 
             // TODO: check if target is the right thing to use for the partner
             }
 
             // TODO: check if target is the right thing to use for the partner
-            Transfer *transfer = new Transfer(Transfer::Receive, e->target(), filename, address, port, size, this);
+            CoreTransfer *transfer = new CoreTransfer(Transfer::Receive, e->target(), filename, address, port, size, this);
             coreSession()->signalProxy()->synchronize(transfer);
             coreSession()->transferManager()->addTransfer(transfer);
         }
             coreSession()->signalProxy()->synchronize(transfer);
             coreSession()->transferManager()->addTransfer(transfer);
         }
diff --git a/src/core/coretransfer.cpp b/src/core/coretransfer.cpp
new file mode 100644 (file)
index 0000000..10d609b
--- /dev/null
@@ -0,0 +1,41 @@
+/***************************************************************************
+ *   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 "coretransfer.h"
+
+INIT_SYNCABLE_OBJECT(CoreTransfer)
+
+CoreTransfer::CoreTransfer(Direction direction, const QString &nick, const QString &fileName, const QHostAddress &address, quint16 port, quint64 fileSize, QObject *parent)
+    : Transfer(direction, nick, fileName, address, port, fileSize, parent)
+{
+
+}
+
+
+void CoreTransfer::requestAccepted(PeerPtr peer)
+{
+    emit accepted(peer);
+}
+
+
+void CoreTransfer::requestRejected(PeerPtr peer)
+{
+    emit rejected(peer);
+}
diff --git a/src/core/coretransfer.h b/src/core/coretransfer.h
new file mode 100644 (file)
index 0000000..9d57db3
--- /dev/null
@@ -0,0 +1,41 @@
+/***************************************************************************
+ *   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 CORETRANSFER_H
+#define CORETRANSFER_H
+
+#include "transfer.h"
+
+class CoreTransfer : public Transfer
+{
+    Q_OBJECT
+    SYNCABLE_OBJECT
+
+public:
+    CoreTransfer(Direction direction, const QString &nick, const QString &fileName, const QHostAddress &address, quint16 port, quint64 size = 0, QObject *parent = 0);
+
+public slots:
+    // called through sync calls
+    void requestAccepted(PeerPtr peer);
+    void requestRejected(PeerPtr peer);
+
+};
+
+#endif
index a11927a..7fb37e8 100644 (file)
@@ -20,8 +20,7 @@
 
 #include "coretransfermanager.h"
 
 
 #include "coretransfermanager.h"
 
-#include "transfer.h"
-
+#include "coretransfer.h"
 
 INIT_SYNCABLE_OBJECT(CoreTransferManager)
 CoreTransferManager::CoreTransferManager(QObject *parent)
 
 INIT_SYNCABLE_OBJECT(CoreTransferManager)
 CoreTransferManager::CoreTransferManager(QObject *parent)
@@ -31,10 +30,31 @@ CoreTransferManager::CoreTransferManager(QObject *parent)
 }
 
 
 }
 
 
+CoreTransfer *CoreTransferManager::transfer(const QUuid &uuid) const
+{
+    return qobject_cast<CoreTransfer *>(transfer_(uuid));
+}
+
+
+void CoreTransferManager::addTransfer(CoreTransfer *transfer)
+{
+    TransferManager::addTransfer(transfer);
+}
+
+
 void CoreTransferManager::onTransferAdded(const Transfer *transfer)
 {
 void CoreTransferManager::onTransferAdded(const Transfer *transfer)
 {
+    // for core-side use, publishing a non-const pointer is ok
+    CoreTransfer *t = const_cast<CoreTransfer *>(qobject_cast<const CoreTransfer *>(transfer));
+    if (!t) {
+        qWarning() << "Invalid Transfer added to CoreTransferManager!";
+        return;
+    }
+
     connect(transfer, SIGNAL(accepted(PeerPtr)), SLOT(onTransferAccepted(PeerPtr)));
     connect(transfer, SIGNAL(rejected(PeerPtr)), SLOT(onTransferRejected(PeerPtr)));
     connect(transfer, SIGNAL(accepted(PeerPtr)), SLOT(onTransferAccepted(PeerPtr)));
     connect(transfer, SIGNAL(rejected(PeerPtr)), SLOT(onTransferRejected(PeerPtr)));
+
+    emit transferAdded(t);
 }
 
 
 }
 
 
index f5f47c8..1a4ddb6 100644 (file)
@@ -24,6 +24,8 @@
 #include "transfermanager.h"
 #include "types.h"
 
 #include "transfermanager.h"
 #include "types.h"
 
+class CoreTransfer;
+
 class CoreTransferManager : public TransferManager
 {
     Q_OBJECT
 class CoreTransferManager : public TransferManager
 {
     Q_OBJECT
@@ -32,6 +34,14 @@ class CoreTransferManager : public TransferManager
 public:
     CoreTransferManager(QObject *parent = 0);
 
 public:
     CoreTransferManager(QObject *parent = 0);
 
+    CoreTransfer *transfer(const QUuid &uuid) const;
+
+public slots:
+    void addTransfer(CoreTransfer *transfer);
+
+signals:
+    void transferAdded(CoreTransfer *transfer);
+
 private slots:
     void onTransferAdded(const Transfer *transfer);
     void onTransferAccepted(PeerPtr peer);
 private slots:
     void onTransferAdded(const Transfer *transfer);
     void onTransferAccepted(PeerPtr peer);
index 573728e..760f867 100644 (file)
@@ -1025,7 +1025,7 @@ void MainWin::connectedToCore()
     connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
     connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
 
     connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
     connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
 
-    connect(Client::transferManager(), SIGNAL(newTransfer(const Transfer*)), SLOT(showNewTransferDlg(const Transfer*)));
+    connect(Client::transferManager(), SIGNAL(transferAdded(const Transfer*)), SLOT(showNewTransferDlg(const Transfer*)));
 
     setConnectedState();
 }
 
     setConnectedState();
 }