OSDN Git Service

kget: deal with FIXME related to torrent seeding
authorIvailo Monev <xakepa10@gmail.com>
Thu, 12 Aug 2021 01:23:37 +0000 (04:23 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Thu, 12 Aug 2021 01:23:37 +0000 (04:23 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kget/core/transfer.h
kget/transfer-plugins/torrent/transferTorrent.cpp
kget/transfer-plugins/torrent/transferTorrent.h

index c247158..b1bab22 100644 (file)
@@ -65,6 +65,7 @@ class KGET_EXPORT Transfer : public Job
             Tc_Group          = 0x00008000,
             Tc_Selection      = 0x00010000
         };
+        typedef int ChangesFlags;
 
         enum Capability
         {
@@ -96,7 +97,6 @@ class KGET_EXPORT Transfer : public Job
             DeleteFiles = 0x00000002
         };
         Q_DECLARE_FLAGS(DeleteOptions, DeleteOption)
-        typedef int ChangesFlags;
 
         Transfer(TransferGroup * parent, TransferFactory * factory,
                  Scheduler * scheduler, const KUrl & src, const KUrl & dest,
index 600cde4..458563f 100644 (file)
@@ -337,8 +337,6 @@ TransferTorrent::TransferTorrent(TransferGroup* parent, TransferFactory* factory
 {
     setCapabilities(Transfer::Cap_SpeedLimit | Transfer::Cap_Resuming);
 
-    // FIXME: once downloaded and KGet is restarted transfer is not seeded
-
     lt::settings_pack ltsettings;
     ltsettings.set_int(lt::settings_pack::alert_mask,
         lt::alert::status_notification
@@ -516,7 +514,7 @@ FileModel* TransferTorrent::fileModel()
     kDebug(5001) << "TransferTorrent::fileModel";
 
     if (!m_filemodel) {
-        m_filemodel = new FileModel(TransferTorrent::files(), m_dest.upUrl(), this);
+        m_filemodel = new FileModel(files(), directory(), this);
 
         // TODO: disable downloading based on check state
         // TODO: file state should not be based on global transfer state
@@ -545,6 +543,19 @@ FileModel* TransferTorrent::fileModel()
     return m_filemodel;
 }
 
+void TransferTorrent::init()
+{
+    kDebug(5001) << "TransferTorrent::init";
+
+    // start even if transfer is finished so that torrent is seeded
+    const bool shouldstart = (policy() != Job::Stop);
+    if (shouldstart) {
+        start();
+    }
+
+    kDebug(5001) << "TransferTorrent::init: should start" << shouldstart;
+}
+
 void TransferTorrent::timerEvent(QTimerEvent *event)
 {
     if (event->timerId() != m_timerid) {
index 6b891cd..6999858 100644 (file)
@@ -38,16 +38,16 @@ public:
     ~TransferTorrent();
 
 public:
+    void init() final;
     void deinit(Transfer::DeleteOptions options) final;
+    QList<KUrl> files() const final;
+    FileModel* fileModel() final;
 
     // Job reimplementations
     void start() final;
     void stop() final;
     bool isStalled() const final;
     bool isWorking() const final;
-    // Transfer reimplementations
-    QList<KUrl> files() const final;
-    FileModel* fileModel() final;
 
 protected:
     // QObject reimplementation