File indexing completed on 2024-05-05 09:11:19
0001 /*************************************************************************** 0002 * Copyright (C) 2007 by Joris Guisson and Ivan Vasic * 0003 * joris.guisson@gmail.com * 0004 * ivasic@gmail.com * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0020 ***************************************************************************/ 0021 #include "scandlg.h" 0022 #include <interfaces/torrentinterface.h> 0023 #include <util/error.h> 0024 #include <util/log.h> 0025 0026 #include <KIO/Global> 0027 #include <KLocalizedString> 0028 #include <KMessageBox> 0029 #include <KStandardGuiItem> 0030 0031 #include <KConfigGroup> 0032 #include <QCloseEvent> 0033 #include <QDialogButtonBox> 0034 #include <QPushButton> 0035 #include <QVBoxLayout> 0036 0037 using namespace bt; 0038 0039 namespace kt 0040 { 0041 ScanDlg::ScanDlg(KJob *job, QWidget *parent) 0042 : QDialog(parent) 0043 , m_job(static_cast<Job *>(job)) 0044 { 0045 Ui::ScanDlgBase ui; 0046 auto *widget = new QWidget(this); 0047 auto *mainLayout = new QVBoxLayout; 0048 ui.setupUi(widget); 0049 mainLayout->addWidget(widget); 0050 m_torrent_label = ui.torrent_label; 0051 m_chunks_found = ui.chunks_found; 0052 m_chunks_failed = ui.chunks_failed; 0053 m_chunks_downloaded = ui.chunks_downloaded; 0054 m_chunks_not_downloaded = ui.chunks_not_downloaded; 0055 m_progress = ui.progress; 0056 m_cancel = ui.cancel; 0057 KGuiItem::assign(m_cancel, KStandardGuiItem::cancel()); 0058 connect(m_cancel, &QPushButton::clicked, this, &ScanDlg::reject); 0059 m_progress->setMaximum(100); 0060 m_progress->setValue(0); 0061 connect(m_job, &KJob::description, this, &ScanDlg::description); 0062 connect(m_job, &KJob::result, this, &ScanDlg::result); 0063 connect(m_job, &KJob::percentChanged, this, &ScanDlg::percent); 0064 } 0065 ScanDlg::~ScanDlg() 0066 { 0067 } 0068 0069 void ScanDlg::closeEvent(QCloseEvent *) 0070 { 0071 if (m_job) { 0072 m_job->kill(false); 0073 m_job = nullptr; 0074 } else 0075 accept(); 0076 } 0077 0078 void ScanDlg::reject() 0079 { 0080 if (m_job) { 0081 m_job->kill(false); 0082 m_job = nullptr; 0083 } 0084 QDialog::reject(); 0085 deleteLater(); 0086 } 0087 0088 void ScanDlg::accept() 0089 { 0090 QDialog::accept(); 0091 deleteLater(); 0092 } 0093 0094 void ScanDlg::description(KJob *job, const QString &title, const QPair<QString, QString> &field1, const QPair<QString, QString> &field2) 0095 { 0096 m_chunks_found->setText(field1.first); 0097 m_chunks_failed->setText(field1.second); 0098 m_chunks_downloaded->setText(field1.first); 0099 m_chunks_not_downloaded->setText(field2.second); 0100 } 0101 0102 void ScanDlg::result(KJob *job) 0103 { 0104 if (job->error() && job->error() != KIO::ERR_USER_CANCELED) { 0105 KMessageBox::error(nullptr, i18n("Error scanning data: %1", job->errorString())); 0106 } 0107 m_job = nullptr; 0108 m_progress->setValue(100); 0109 disconnect(m_cancel, &QPushButton::clicked, this, &ScanDlg::reject); 0110 connect(m_cancel, &QPushButton::clicked, this, &ScanDlg::accept); 0111 } 0112 0113 void ScanDlg::percent(KJob *job, unsigned long percent) 0114 { 0115 m_progress->setValue(percent); 0116 } 0117 } 0118 0119 #include "moc_scandlg.cpp"