• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • transfer-plugins
  • bittorrent
scandlg.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007 by Joris Guisson and Ivan Vasic *
3  * joris.guisson@gmail.com *
4  * ivasic@gmail.com *
5  * *
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. *
10  * *
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. *
15  * *
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  ***************************************************************************/
21 #include "scandlg.h"
22 #include <QCloseEvent>
23 #include <klocale.h>
24 #include <kmessagebox.h>
25 #include <kstandardguiitem.h>
26 #include <util/error.h>
27 #include <util/log.h>
28 #include <interfaces/torrentinterface.h>
29 using namespace bt;
30 
31 namespace kt
32 {
33 #if LIBKTORRENT_VERSION >= 0x010100
34  ScanDlg::ScanDlg(KJob *job, QWidget* parent)
35  : KDialog(parent), m_job(static_cast<Job*>(job))
36  {
37  setButtons(KDialog::None);
38  Ui::ScanDlgBase ui;
39  QWidget *widget = new QWidget(this);
40  ui.setupUi(widget);
41  setMainWidget(widget);
42  m_torrent_label = ui.torrent_label;
43  m_chunks_found = ui.chunks_found;
44  m_chunks_failed = ui.chunks_failed;
45  m_chunks_downloaded = ui.chunks_downloaded;
46  m_chunks_not_downloaded = ui.chunks_not_downloaded;
47  m_progress = ui.progress;
48  m_cancel = ui.cancel;
49  m_cancel->setGuiItem(KStandardGuiItem::cancel());
50  connect(m_cancel,SIGNAL(clicked()),this,SLOT(reject()));
51  m_progress->setMaximum(100);
52  m_progress->setValue(0);
53  connect(m_job, SIGNAL(description(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>)),
54  SLOT(description(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>)));
55  connect(m_job, SIGNAL(result(KJob*)),
56  SLOT(result(KJob*)));
57  connect(m_job, SIGNAL(percent(KJob*,ulong)),
58  SLOT(percent(KJob*,ulong)));
59  }
60  ScanDlg::~ScanDlg()
61  {
62  }
63 
64  void ScanDlg::closeEvent(QCloseEvent* )
65  {
66  if (m_job) {
67  m_job->kill(false);
68  m_job = 0;
69  }
70  else
71  accept();
72  }
73 
74  void ScanDlg::reject()
75  {
76  if (m_job) {
77  m_job->kill(false);
78  m_job = 0;
79  }
80  KDialog::reject();
81  deleteLater();
82  }
83 
84  void ScanDlg::accept()
85  {
86  KDialog::accept();
87  deleteLater();
88  }
89 
90  void ScanDlg::description(KJob *job, const QString &title, const QPair<QString, QString > &field1, const QPair< QString, QString > &field2)
91  {
92  m_chunks_found->setText(field1.first);
93  m_chunks_failed->setText(field1.second);
94  m_chunks_downloaded->setText(field1.first);
95  m_chunks_not_downloaded->setText(field2.second);
96  }
97 
98  void ScanDlg::result(KJob *job)
99  {
100  if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
101  KMessageBox::error(0,i18n("Error scanning data: %1",job->errorString()));
102  }
103  m_job = 0;
104  m_progress->setValue(100);
105  disconnect(m_cancel,SIGNAL(clicked()),this,SLOT(reject()));
106  connect(m_cancel,SIGNAL(clicked()),this,SLOT(accept()));
107  }
108 
109  void ScanDlg::percent(KJob *job, unsigned long percent)
110  {
111  m_progress->setValue(percent);
112  }
113 #else
114  ScanDlg::ScanDlg(QWidget* parent)
115  : KDialog(parent),bt::DataCheckerListener(false),mutex(QMutex::Recursive)
116  {
117  setButtons(KDialog::None);
118  Ui::ScanDlgBase ui;
119  QWidget *widget = new QWidget(this);
120  ui.setupUi(widget);
121  setMainWidget(widget);
122  m_torrent_label = ui.torrent_label;
123  m_chunks_found = ui.chunks_found;
124  m_chunks_failed = ui.chunks_failed;
125  m_chunks_downloaded = ui.chunks_downloaded;
126  m_chunks_not_downloaded = ui.chunks_not_downloaded;
127  m_progress = ui.progress;
128  m_cancel = ui.cancel;
129  m_cancel->setGuiItem(KStandardGuiItem::cancel());
130  connect(m_cancel,SIGNAL(clicked()),this,SLOT(onCancelPressed()));
131  connect(&timer,SIGNAL(timeout()),this,SLOT(update()));
132  tc = 0;
133  silently = false;
134  restart = false;
135  scanning = false;
136  num_chunks = 0;
137  total_chunks = 0;
138  num_downloaded = 0;
139  num_failed = 0;
140  num_found = 0;
141  num_not_downloaded = 0;
142  m_progress->setMaximum(100);
143  m_progress->setValue(0);
144  }
145 
146  ScanDlg::~ScanDlg()
147  {
148  }
149 
150  void ScanDlg::scan()
151  {
152  try
153  {
154  tc->startDataCheck(this);
155  timer.start(500);
156  scanning = true;
157  }
158  catch (bt::Error & err)
159  {
160  KMessageBox::error(0,i18n("Error scanning data: %1",err.toString()));
161  }
162  }
163 
164  void ScanDlg::execute(bt::TorrentInterface* tc,bool silently)
165  {
166  m_torrent_label->setText(i18n("Scanning data of <b>%1</b> :",tc->getStats().torrent_name));
167  adjustSize();
168  m_cancel->setEnabled(true);
169  this->silently = silently;
170  this->tc = tc;
171  num_chunks = 0;
172  total_chunks = 0;
173  num_downloaded = 0;
174  num_failed = 0;
175  num_found = 0;
176  num_not_downloaded = 0;
177  if (auto_import || tc->getStats().running)
178  restart = true;
179 
180  qm_priority = tc->getPriority();
181 
182  if (tc->getStats().running)
183  {
184  tc->stop();
185  }
186 
187  scan();
188  }
189 
190  void ScanDlg::progress(bt::Uint32 num,bt::Uint32 total)
191  {
192  QMutexLocker lock(&mutex);
193  num_chunks = num;
194  total_chunks = total;
195  }
196 
197  void ScanDlg::status(bt::Uint32 failed,Uint32 found,Uint32 downloaded,Uint32 not_downloaded)
198  {
199  QMutexLocker lock(&mutex);
200  num_failed = failed;
201  num_found = found;
202  num_downloaded = downloaded;
203  num_not_downloaded = not_downloaded;
204  }
205 
206  void ScanDlg::finished()
207  {
208  QMutexLocker lock(&mutex);
209  scanning = false;
210  timer.stop();
211  progress(100,100);
212  update();
213  if (!isStopped())
214  {
215  if (restart)
216  {
217  tc->start();
218  }
219 
220  if (silently)
221  accept();
222  else
223  {
224  // cancel now becomes a close button
225  m_cancel->setGuiItem(KStandardGuiItem::close());
226  disconnect(m_cancel,SIGNAL(clicked()),this,SLOT(onCancelPressed()));
227  connect(m_cancel,SIGNAL(clicked()),this,SLOT(accept()));
228  }
229  }
230  else
231  {
232  if (restart)
233  {
234  tc->start();
235  }
236 
237  KDialog::reject();
238  }
239  }
240 
241  void ScanDlg::error(const QString &message)
242  {
243  KMessageBox::error(0,i18n("Error scanning data: %1",message));
244  }
245 
246  void ScanDlg::closeEvent(QCloseEvent* )
247  {
248  if (scanning)
249  stop();
250  else
251  accept();
252  }
253 
254  void ScanDlg::reject()
255  {
256  if (scanning)
257  stop();
258  else
259  {
260  KDialog::reject();
261  deleteLater();
262  }
263  }
264 
265  void ScanDlg::accept()
266  {
267  KDialog::accept();
268  deleteLater();
269  }
270 
271  void ScanDlg::onCancelPressed()
272  {
273  stop();
274  }
275 
276  void ScanDlg::update()
277  {
278  QMutexLocker lock(&mutex);
279  m_progress->setMaximum(total_chunks);
280  m_progress->setValue(num_chunks);
281  m_chunks_found->setText(QString::number(num_downloaded));
282  m_chunks_failed->setText(QString::number(num_failed));
283  m_chunks_downloaded->setText(QString::number(num_downloaded));
284  m_chunks_not_downloaded->setText(QString::number(num_not_downloaded));
285  }
286 #endif
287 }
288 
289 #include "scandlg.moc"
290 
kt::ScanDlg::update
void update()
Updates the GUI in app thread.
Definition: scandlg.cpp:276
QWidget
kt::ScanDlg::onCancelPressed
void onCancelPressed()
Definition: scandlg.cpp:271
kt::ScanDlg::closeEvent
virtual void closeEvent(QCloseEvent *e)
Handle the close event.
Definition: scandlg.cpp:246
KDialog
scandlg.h
kt::ScanDlg::error
virtual void error(const QString &)
Definition: scandlg.cpp:241
kt::ScanDlg::progress
virtual void progress(bt::Uint32 num, bt::Uint32 total)
Update progress info, runs in scan threadnted"))
Definition: scandlg.cpp:190
kt::ScanDlg::scan
void scan()
Definition: scandlg.cpp:150
kt::ScanDlg::~ScanDlg
virtual ~ScanDlg()
Definition: scandlg.cpp:146
kt::ScanDlg::finished
virtual void finished()
Scan finished, runs in app thread.
Definition: scandlg.cpp:206
kt::ScanDlg::status
virtual void status(bt::Uint32 failed, bt::Uint32 found, bt::Uint32 downloaded, bt::Uint32 not_downloaded)
Update status info, runs in scan thread.
Definition: scandlg.cpp:197
kt::ScanDlg::accept
virtual void accept()
Definition: scandlg.cpp:265
kt::ScanDlg::execute
void execute(bt::TorrentInterface *tc, bool silently)
Starts the scan threadvent(QC.
Definition: scandlg.cpp:164
kt::ScanDlg::reject
virtual void reject()
Definition: scandlg.cpp:254
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal