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

kget

btdownload.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002 
00003    Copyright (C) 2007 Lukas Appelhans <l.appelhans@gmx.de>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 */
00010 #include "btdownload.h"
00011 
00012 #include <QFile>
00013 #include <QFileInfo>
00014 
00015 #include <KDebug>
00016 #include <KStandardDirs>
00017 
00018 BTDownload::BTDownload(const KUrl &srcUrl)
00019   : m_srcUrl(srcUrl),
00020     m_destUrl(KStandardDirs::locateLocal("appdata", "tmp/"))
00021 {
00022         kDebug(5001) << "DownloadFile:" << m_srcUrl.url();
00023         KIO::TransferJob *m_copyJob = KIO::get(m_srcUrl, KIO::NoReload, KIO::HideProgressInfo);
00024         connect(m_copyJob, SIGNAL(data(KIO::Job*,const QByteArray &)), SLOT(slotData(KIO::Job*, const QByteArray&)));
00025         connect(m_copyJob, SIGNAL(result(KJob *)), SLOT(slotResult(KJob *)));
00026         connect(m_copyJob, SIGNAL(finished()), SLOT(setTorrentFileDownloaded()));
00027 }
00028 
00029 void BTDownload::slotData(KIO::Job *job, const QByteArray& data)
00030 {
00031     kDebug(5001);
00037     m_data.append(data);
00038 }
00039 
00040 void BTDownload::slotResult(KJob * job)
00041 {
00042     kDebug(5001);
00043     switch (job->error())
00044     {
00045         case 0://The download has finished
00046         {
00047             kDebug(5001) << "Downloading successfully finished" << m_destUrl.url().remove("file://") + m_srcUrl.fileName();
00048             QFile torrentFile(m_destUrl.url().remove("file://") + m_srcUrl.fileName());
00049             if (!torrentFile.open(QIODevice::WriteOnly | QIODevice::Text))
00050                 kDebug(5001) << "Thanks uwolfer";
00051             torrentFile.write(m_data);
00052             torrentFile.close();
00053             kDebug(5001) << m_data;
00054             m_data = 0;
00055             m_destUrl = QFileInfo(torrentFile).absoluteFilePath();
00056             kDebug(5001) << m_destUrl;
00057             emit finishedSuccessfully(m_destUrl);
00058             break;
00059         }
00060         case KIO::ERR_FILE_ALREADY_EXIST:
00061             kDebug(5001) << "ERROR - File already exists";
00062             m_data = 0;
00063             emit finishedSuccessfully(m_destUrl);
00064         default:
00065             kDebug(5001) << "That sucks";
00066             m_data = 0;
00067             emit finishedWithError();
00068             break;
00069     }
00070 }
00071   

kget

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

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal