Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Cleanup old libktorrent ifdefs

Switch to KF5::Torrent makes sure of a recent version, although the
ifdefs were obsolete by min libktorrent version already.

REVIEW: 129337
parent 97856cdb
......@@ -27,13 +27,11 @@ K_PLUGIN_FACTORY_WITH_JSON(KGetFactory, "kget_bittorrentfactory.json", registerP
BTTransferFactory::BTTransferFactory(QObject *parent, const QVariantList &args)
: TransferFactory(parent, args)
{
#if LIBKTORRENT_VERSION >= 0x010100
if (!bt::InitLibKTorrent())
{
qCCritical(KGET_DEBUG) << "Failed to initialize libktorrent";
KGet::showNotification(0, "error", i18n("Cannot initialize libktorrent. Torrent support might not work."));
}
#endif
}
BTTransferFactory::~BTTransferFactory()
......
......@@ -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()
{
qCDebug(KGET_DEBUG);
scanDlg = 0;
}
#endif
......@@ -53,9 +53,6 @@ class BTTransferHandler : public TransferHandler
private slots:
void removeAdvancedDetails();
#if LIBKTORRENT_VERSION < 0x010100
void removeScanDlg();
#endif
private:
BTTransfer * m_transfer;
......
......@@ -30,7 +30,6 @@ using namespace bt;
namespace kt
{
#if LIBKTORRENT_VERSION >= 0x010100
ScanDlg::ScanDlg(KJob *job, QWidget* parent)
: KDialog(parent), m_job(static_cast<Job*>(job))
{
......@@ -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
}
......
......@@ -25,11 +25,7 @@
#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;
QPushButton *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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment