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);
{
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"
#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
{
class TorrentInterface;
-#if LIBKTORRENT_VERSION >= 0x010100
class ScanDlg : public KDialog
{
Q_OBJECT
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