3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2006 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
13
#include "kio_ftptransport.h"
16
#include <kapplication.h>
17
#include <kdirlister.h>
18
#include <kfileitem.h>
19
#include <kio/jobclasses.h>
22
namespace BookshelfManager {
23
bool finishedDownload = false;
25
KIO_FTPTransport::KIO_FTPTransport(const char *host, sword::StatusReporter *statusReporter )
27
sword::FTPTransport(host, statusReporter),
31
KIO_FTPTransport::~KIO_FTPTransport() {}
33
char KIO_FTPTransport::getURL(const char *destPath, const char *sourceURL) {
34
qWarning("FTP: Copy %s -> %s", sourceURL, destPath);
37
KURL(QString::fromLocal8Bit(destPath)),
41
KIO::Job* job = KIO::copy(
42
KURL(QString::fromLocal8Bit(sourceURL)),
43
KURL(QString::fromLocal8Bit(destPath)),
47
//make sure to wait as long as the job is working
48
finishedDownload = false;
49
const int progressID = job->progressId();
51
job, SIGNAL(result(KIO::Job*)),
52
this, SLOT(slotCopyResult(KIO::Job*))
55
job, SIGNAL(totalSize(KIO::Job*, KIO::filesize_t)),
56
this, SLOT(slotTotalSize(KIO::Job*, KIO::filesize_t))
59
job, SIGNAL(processedSize(KIO::Job*, KIO::filesize_t)),
60
this, SLOT(slotCopyProgress(KIO::Job*, KIO::filesize_t))
63
while (!finishedDownload) {
64
KApplication::kApplication()->processEvents(1);
65
// qWarning("FTP: Copy not yet finished");
68
job->kill(false); //kill emits the result signal
73
statusReporter->statusUpdate(m_totalSize, m_totalSize); //completed
75
if (!m_copyResults.contains(progressID)) {
78
else if (m_copyResults[progressID] > 0) { //an error occurred
79
return 1; //an error occured
84
void KIO_FTPTransport::slotTotalSize(KIO::Job* /*job*/, KIO::filesize_t size) {
87
statusReporter->statusUpdate(m_totalSize, 0); //emit that we just started
91
void KIO_FTPTransport::slotCopyResult(KIO::Job *job) {
92
m_copyResults.insert(job->progressId(),job->error());
93
finishedDownload = true;
95
if ( job->error() ) {}
98
void KIO_FTPTransport::slotCopyProgress(KIO::Job* /*job*/, KIO::filesize_t processedSize) {
99
if (m_totalSize > 0) {
100
statusReporter->statusUpdate(m_totalSize, processedSize);
104
void KIO_FTPTransport::slotDirListingCanceled() {
105
m_listingCancelled = true;
108
std::vector<struct ftpparse> KIO_FTPTransport::getDirList(const char *dirURL) {
109
std::vector< struct ftpparse > ret;
111
// char* dirURL = const_cast<char*>(myDir);
112
// if (dirURL[strlen(dirURL)-1] == '/') {
113
// qWarning("setting end to 0");
114
// dirURL[strlen(dirURL)-1] = 0;
117
qWarning("listing %s", dirURL);
124
m_listingCancelled = false;
126
connect(&lister, SIGNAL(canceled()), SLOT(slotDirListingCanceled()));
127
lister.openURL(KURL(dirURL));
129
while (!lister.isFinished() && !m_listingCancelled) {
135
KApplication::kApplication()->processEvents(1);
143
KFileItemList items = lister.itemsForDir(KURL(dirURL));
145
for ( i = items.first(); i; i = items.next() ) {
146
int length = i->name().length();
147
const char* t = i->name().latin1();
150
s.name = new char[length+1];//i->name().latin1();
151
bzero(s.name, length+1);
153
s.namelen = length+1;
156
s.flagtrycwd = i->isDir(); //== 1 means a dir
161
// qWarning("push_back item");