1 /***************************************************************************
2 * Copyright (C) 2007 by Joris Guisson and Ivan Vasic *
3 * joris.guisson@gmail.com *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
22 #include <QCloseEvent>
24 #include <kmessagebox.h>
25 #include <kstandardguiitem.h>
26 #include <util/error.h>
28 #include <interfaces/torrentinterface.h>
34 ScanDlg::ScanDlg(bool auto_import
,QWidget
* parent
)
35 : QDialog(parent
),bt::DataCheckerListener(auto_import
),mutex(QMutex::Recursive
)
38 m_cancel
->setGuiItem(KStandardGuiItem::cancel());
39 connect(m_cancel
,SIGNAL(clicked()),this,SLOT(onCancelPressed()));
40 connect(&timer
,SIGNAL(timeout()),this,SLOT(update()));
44 qm_controlled
= false;
50 m_progress
->setMaximum(100);
51 m_progress
->setValue(0);
62 tc
->startDataCheck(this);
66 catch (bt::Error
& err
)
68 KMessageBox::error(0,i18n("Error scanning data: %1",err
.toString()));
72 void ScanDlg::execute(bt::TorrentInterface
* tc
,bool silently
)
74 m_torrent_label
->setText(i18n("Scanning data of <b>%1</b> :",tc
->getStats().torrent_name
));
76 m_cancel
->setEnabled(true);
77 this->silently
= silently
;
83 if (auto_import
|| tc
->getStats().running
)
86 qm_controlled
= !tc
->getStats().user_controlled
;
87 qm_priority
= tc
->getPriority();
89 if (tc
->getStats().running
)
97 void ScanDlg::progress(bt::Uint32 num
,bt::Uint32 total
)
99 QMutexLocker
lock(&mutex
);
101 total_chunks
= total
;
104 void ScanDlg::status(bt::Uint32 failed
,bt::Uint32 downloaded
)
106 QMutexLocker
lock(&mutex
);
108 num_downloaded
= downloaded
;
111 void ScanDlg::finished()
113 QMutexLocker
lock(&mutex
);
129 // cancel now becomes a close button
130 m_cancel
->setGuiItem(KStandardGuiItem::close());
131 disconnect(m_cancel
,SIGNAL(clicked()),this,SLOT(onCancelPressed()));
132 connect(m_cancel
,SIGNAL(clicked()),this,SLOT(accept()));
146 void ScanDlg::closeEvent(QCloseEvent
* )
154 void ScanDlg::reject()
165 void ScanDlg::accept()
171 void ScanDlg::onCancelPressed()
176 void ScanDlg::update()
178 QMutexLocker
lock(&mutex
);
179 m_progress
->setMaximum(total_chunks
);
180 m_progress
->setValue(num_chunks
);
181 m_chunks_found
->setText(QString::number(num_downloaded
));
182 m_chunks_failed
->setText(QString::number(num_failed
));
186 #include "scandlg.moc"