• 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
  • core
download.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2007 Lukas Appelhans <l.appelhans@gmx.de>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 */
10 #include "download.h"
11 
12 #include <QFile>
13 #include <QFileInfo>
14 
15 #include <KDebug>
16 
17 Download::Download(const KUrl &srcUrl, const KUrl &destUrl)
18  : m_srcUrl(srcUrl),
19  m_destUrl(destUrl)
20 {
21  kDebug(5001) << "DownloadFile: " << m_srcUrl.url() << " to dest: " << m_destUrl.url();
22  m_copyJob = KIO::get(m_srcUrl, KIO::NoReload, KIO::HideProgressInfo);
23  connect(m_copyJob, SIGNAL(data(KIO::Job*,QByteArray)), SLOT(slotData(KIO::Job*,QByteArray)));
24  connect(m_copyJob, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*)));
25 }
26 
27 Download::~Download()
28 {
29 }
30 
31 void Download::slotData(KIO::Job *job, const QByteArray& data)
32 {
33  Q_UNUSED(job)
34  kDebug(5001);
40  m_data.append(data);
41 }
42 
43 void Download::slotResult(KJob * job)
44 {
45  kDebug(5001);
46  switch (job->error())
47  {
48  case 0://The download has finished
49  {
50  kDebug(5001) << "Downloading successfully finished" << m_destUrl.url();
51  QFile torrentFile(m_destUrl.toLocalFile());
52  if (!torrentFile.open(QIODevice::WriteOnly | QIODevice::Text)) {}
53  //TODO: Do a Message box here
54  torrentFile.write(m_data);
55  torrentFile.close();
56  emit finishedSuccessfully(m_destUrl, m_data);
57  m_data = 0;
58  break;
59  }
60  case KIO::ERR_FILE_ALREADY_EXIST:
61  {
62  kDebug(5001) << "ERROR - File already exists";
63  QFile file(m_destUrl.toLocalFile());
64  emit finishedSuccessfully(m_destUrl, file.readAll());
65  m_data = 0;
66  break;
67  }
68  default:
69  kDebug(5001) << "We are sorry to say you, that there were errors while downloading :(";
70  m_data = 0;
71  emit finishedWithError();
72  break;
73  }
74 }
75 
Download
Definition: download.h:23
Download::~Download
~Download()
Definition: download.cpp:27
download.h
Download::finishedSuccessfully
void finishedSuccessfully(KUrl dest, QByteArray data)
Download::Download
Download(const KUrl &srcUrl, const KUrl &destUrl)
Definition: download.cpp:17
Download::finishedWithError
void finishedWithError()
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