OSDN Git Service

kget: remove redundant libktorrent version checks
authorIvailo Monev <xakepa10@gmail.com>
Wed, 21 Jul 2021 18:10:07 +0000 (21:10 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Wed, 21 Jul 2021 18:10:07 +0000 (21:10 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kget/transfer-plugins/bittorrent/bttransferfactory.cpp
kget/transfer-plugins/bittorrent/bttransferhandler.cpp
kget/transfer-plugins/bittorrent/bttransferhandler.h
kget/transfer-plugins/bittorrent/scandlg.cpp
kget/transfer-plugins/bittorrent/scandlg.h

index ce3b5e9..334b7b8 100644 (file)
@@ -27,13 +27,11 @@ KGET_EXPORT_PLUGIN(BTTransferFactory)
 BTTransferFactory::BTTransferFactory(QObject *parent, const QVariantList &args)
   : TransferFactory(parent, args)
 {
-#if LIBKTORRENT_VERSION >= 0x010100
     if (!bt::InitLibKTorrent())
     {
         kError(5001) << "Failed to initialize libktorrent";
         KGet::showNotification(0, "error", i18n("Cannot initialize libktorrent. Torrent support might not work."));
     }
-#endif
 }
 
 BTTransferFactory::~BTTransferFactory()
index 7e1ce8c..f6e3d1b 100644 (file)
@@ -71,31 +71,7 @@ void BTTransferHandler::createScanDlg()
 {
     if (!torrentControl())
         return;
-#if LIBKTORRENT_VERSION < 0x010100
-    if (scanDlg)
-    {
-        scanDlg->stop();
-        scanDlg->close();
-    }
-#endif
 
-#if LIBKTORRENT_VERSION >= 0x010200
     scanDlg = new kt::ScanDlg(m_transfer->torrentControl()->startDataCheck(false, 0, m_transfer->chunksTotal()), 0);//TODO: Maybe start/stop it
     scanDlg->exec();
-#elif LIBKTORRENT_VERSION >= 0x010100
-    scanDlg = new kt::ScanDlg(m_transfer->torrentControl()->startDataCheck(false), 0);//TODO: Maybe start/stop it
-    scanDlg->exec();
-#else
-    scanDlg = new kt::ScanDlg(0);
-    scanDlg->show();
-    scanDlg->execute(torrentControl(), false);
-    connect(scanDlg, SIGNAL(finished(int)), SLOT(removeScanDlg()));
-#endif
-}
-#if LIBKTORRENT_VERSION < 0x010100
-void BTTransferHandler::removeScanDlg()
-{
-    kDebug(5001);
-    scanDlg = 0;
 }
-#endif
index 320b19b..a82f8f9 100644 (file)
@@ -53,9 +53,6 @@ class BTTransferHandler : public TransferHandler
 
     private slots:
         void removeAdvancedDetails();
-#if LIBKTORRENT_VERSION < 0x010100
-        void removeScanDlg();
-#endif
 
     private:
         BTTransfer * m_transfer;
index 8a030ef..9d1df3d 100644 (file)
@@ -30,8 +30,7 @@ using namespace bt;
 
 namespace kt
 {
-#if LIBKTORRENT_VERSION >= 0x010100
-       ScanDlg::ScanDlg(KJob *job, QWidget* parent)
+    ScanDlg::ScanDlg(KJob *job, QWidget* parent)
     : KDialog(parent), m_job(static_cast<Job*>(job))
     {
         setButtons(KDialog::None);
@@ -110,180 +109,6 @@ namespace kt
        {
                m_progress->setValue(percent);
        }
-#else
-       ScanDlg::ScanDlg(QWidget* parent) 
-               : KDialog(parent),bt::DataCheckerListener(false),mutex(QMutex::Recursive)
-       {
-               setButtons(KDialog::None);
-               Ui::ScanDlgBase ui;
-               QWidget *widget = new QWidget(this);
-               ui.setupUi(widget);
-               setMainWidget(widget);
-               m_torrent_label = ui.torrent_label;
-               m_chunks_found = ui.chunks_found;
-               m_chunks_failed = ui.chunks_failed;
-               m_chunks_downloaded = ui.chunks_downloaded;
-               m_chunks_not_downloaded = ui.chunks_not_downloaded;
-               m_progress = ui.progress;
-               m_cancel = ui.cancel;
-               m_cancel->setGuiItem(KStandardGuiItem::cancel());
-               connect(m_cancel,SIGNAL(clicked()),this,SLOT(onCancelPressed()));
-               connect(&timer,SIGNAL(timeout()),this,SLOT(update()));
-               tc = 0;
-               silently = false;
-               restart = false;
-               scanning = false;
-               num_chunks = 0;
-               total_chunks = 0;
-               num_downloaded = 0;
-               num_failed = 0;
-               num_found = 0;
-               num_not_downloaded = 0;
-               m_progress->setMaximum(100);
-               m_progress->setValue(0);
-       }
-       
-       ScanDlg::~ScanDlg()
-       {
-       }
-
-       void ScanDlg::scan()
-       {
-               try
-               {
-                       tc->startDataCheck(this);
-                       timer.start(500);
-                       scanning = true;
-               }
-               catch (bt::Error & err)
-               {
-                       KMessageBox::error(0,i18n("Error scanning data: %1",err.toString()));
-               }
-       }
-
-       void ScanDlg::execute(bt::TorrentInterface* tc,bool silently)
-       {
-               m_torrent_label->setText(i18n("Scanning data of <b>%1</b> :",tc->getStats().torrent_name));
-               adjustSize();
-               m_cancel->setEnabled(true);
-               this->silently = silently;
-               this->tc = tc;
-               num_chunks = 0;
-               total_chunks = 0;
-               num_downloaded = 0;
-               num_failed = 0;
-               num_found = 0;
-               num_not_downloaded = 0;
-               if (auto_import || tc->getStats().running)
-                       restart = true;
-
-               qm_priority = tc->getPriority();
-
-               if (tc->getStats().running)
-               {
-                       tc->stop();
-               }
-               
-               scan();
-       }
-
-       void ScanDlg::progress(bt::Uint32 num,bt::Uint32 total)
-       {
-               QMutexLocker lock(&mutex);
-               num_chunks = num;
-               total_chunks = total;
-       }
-                
-       void ScanDlg::status(bt::Uint32 failed,Uint32 found,Uint32 downloaded,Uint32 not_downloaded)
-       {
-               QMutexLocker lock(&mutex);
-               num_failed = failed;
-               num_found = found;
-               num_downloaded = downloaded;
-               num_not_downloaded = not_downloaded;
-       }
-               
-       void ScanDlg::finished()
-       {
-               QMutexLocker lock(&mutex);
-               scanning = false;
-               timer.stop();
-               progress(100,100);
-               update();
-               if (!isStopped())
-               {
-                       if (restart)
-                       {
-                               tc->start();
-                       }
-                       
-                       if (silently)
-                               accept();
-                       else
-                       {
-                               // cancel now becomes a close button
-                               m_cancel->setGuiItem(KStandardGuiItem::close()); 
-                               disconnect(m_cancel,SIGNAL(clicked()),this,SLOT(onCancelPressed()));
-                               connect(m_cancel,SIGNAL(clicked()),this,SLOT(accept()));
-                       }
-               }
-               else
-               {
-                       if (restart)
-                       {
-                               tc->start();
-                       }
-                       
-                       KDialog::reject();
-               }
-       }
-       
-       void ScanDlg::error(const QString &message)
-    {
-        KMessageBox::error(0,i18n("Error scanning data: %1",message));
-    }
-                
-       void ScanDlg::closeEvent(QCloseEvent* )
-       {
-               if (scanning)
-                       stop();
-               else
-                       accept();
-       }
-
-       void ScanDlg::reject()
-       {
-               if (scanning)
-                       stop();
-               else
-               {
-                       KDialog::reject();
-                       deleteLater();
-               }
-       }
-
-       void ScanDlg::accept()
-       {
-               KDialog::accept();
-               deleteLater();
-       }
-
-       void ScanDlg::onCancelPressed()
-       {
-               stop();
-       }
-
-       void ScanDlg::update()
-       {
-               QMutexLocker lock(&mutex);
-               m_progress->setMaximum(total_chunks);
-               m_progress->setValue(num_chunks);
-               m_chunks_found->setText(QString::number(num_downloaded));
-               m_chunks_failed->setText(QString::number(num_failed));
-               m_chunks_downloaded->setText(QString::number(num_downloaded));
-               m_chunks_not_downloaded->setText(QString::number(num_not_downloaded));
-       }
-#endif
 }
 
 #include "moc_scandlg.cpp"
index bc3f0ac..9c495ca 100644 (file)
 #include <QMutex>
 #include <KDialog>
 #include <version.h>
-#if LIBKTORRENT_VERSION >= 0x010100
 #include <torrent/job.h>
-#else
-#include <datachecker/datacheckerlistener.h>
-#endif
 #include "ui_scandlg.h"
 
 namespace bt
@@ -41,7 +37,6 @@ namespace kt
 {
        class TorrentInterface;
 
-#if LIBKTORRENT_VERSION >= 0x010100
        class ScanDlg : public KDialog
        {
                Q_OBJECT
@@ -72,63 +67,6 @@ namespace kt
                QLabel *m_chunks_not_downloaded;
                QLabel *m_chunks_downloaded;
        };
-#else
-       class ScanDlg : public KDialog,public bt::DataCheckerListener
-       {
-               Q_OBJECT
-       public:
-               ScanDlg(QWidget* parent);
-               virtual ~ScanDlg();
-
-               /// Starts the scan threadvent(QC
-               void execute(bt::TorrentInterface* tc,bool silently);
-
-       protected:
-               /// Update progress info, runs in scan threadnted"))
-               virtual void progress(bt::Uint32 num,bt::Uint32 total);
-                
-               /// Update status info, runs in scan thread
-               virtual void status(bt::Uint32 failed,bt::Uint32 found,bt::Uint32 downloaded,bt::Uint32 not_downloaded);
-               
-               /// Scan finished, runs in app thread
-               virtual void finished();
-                
-               /// Handle the close event
-               virtual void closeEvent(QCloseEvent* e);
-        
-        virtual void error(const QString&);
-
-       protected slots:
-               virtual void reject();
-               virtual void accept();
-               void onCancelPressed();
-               /// Updates the GUI in app thread
-               void update();
-               void scan();
-
-       private:
-               bt::TorrentInterface* tc;
-               QMutex mutex;
-               QTimer timer;
-               bt::Uint32 num_chunks;
-               bt::Uint32 total_chunks;
-               bt::Uint32 num_downloaded;
-               bt::Uint32 num_failed;
-               bt::Uint32 num_found;
-               bt::Uint32 num_not_downloaded;
-               bool silently;
-               bool restart;
-               int qm_priority;
-               bool scanning;
-               QProgressBar *m_progress;
-               KPushButton *m_cancel;
-               QLabel *m_torrent_label;
-               QLabel *m_chunks_failed;
-               QLabel *m_chunks_found;
-               QLabel *m_chunks_not_downloaded;
-               QLabel *m_chunks_downloaded;
-       };
-#endif
 }
 
 #endif