From 533769b663fee1ba99364c7c0c3431b72b8e9abe Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 21 Dec 2009 00:40:43 +0100 Subject: Improvements in ftp handling: - show dirs - download files --- src/protocolhandler.cpp | 35 +++++++++++++++++++++++++++++------ src/protocolhandler.h | 12 ++++++++++-- src/webpage.cpp | 3 +++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/protocolhandler.cpp b/src/protocolhandler.cpp index 57f0492e..a40cc0f9 100644 --- a/src/protocolhandler.cpp +++ b/src/protocolhandler.cpp @@ -45,6 +45,8 @@ #include #include #include +#include +#include // Qt Includes #include @@ -97,17 +99,19 @@ bool ProtocolHandler::handle(const QNetworkRequest &request, QWebFrame *frame) } } - // "ftp" handling + // "ftp" handling. A little bit "hard" handling this. Hope I found + // the best solution. + // My idea is: webkit cannot handle in any way ftp. So we have surely to return true here. + // We start trying to guess what the url represent: it's a dir? show its contents (and download them). + // it's a file? download it. It's another thing? beat me, but I don't know what to do... if( _url.protocol() == QLatin1String("ftp") ) { - // TODO - // I need to know if the url represent a file - // and, in that case we have to just return false! - _lister->openUrl(_url); + KIO::StatJob *job = KIO::stat(_url); + connect(job, SIGNAL(result(KJob*)), this, SLOT( slotMostLocalUrlResult(KJob*) )); return true; } - // "file" handling + // "file" handling. This is quite trivial :) if(_url.protocol() == QLatin1String("file") ) { QFileInfo fileInfo( _url.path() ); @@ -133,6 +137,7 @@ QString ProtocolHandler::dirHandling(const KFileItemList &list) QString errStr = i18n("Error opening: %1: No such file or directory", rootUrl.prettyUrl() ); return errStr; } + if (!mainItem.isReadable()) { QString errStr = i18n("Unable to read %1", rootUrl.prettyUrl() ); @@ -221,3 +226,21 @@ void ProtocolHandler::showResults(const KFileItemList &list) Application::historyManager()->addHistoryEntry( _url.prettyUrl() ); } + +void ProtocolHandler::slotMostLocalUrlResult(KJob *job) +{ + if(job->error()) + { + // TODO + kDebug() << "error"; + } + else + { + KIO::StatJob *statJob = static_cast(job); + KIO::UDSEntry entry = statJob->statResult(); + if( entry.isDir() ) + _lister->openUrl(_url); + else + emit downloadUrl(_url); + } +} diff --git a/src/protocolhandler.h b/src/protocolhandler.h index 81cda4b6..532bd9c9 100644 --- a/src/protocolhandler.h +++ b/src/protocolhandler.h @@ -27,14 +27,18 @@ #ifndef PROTOCOL_HANDLER_H #define PROTOCOL_HANDLER_H - +// KDE Includes #include + +// Qt Includes #include +// Forward Declarations class QNetworkRequest; class QWebFrame; class QString; class KUrl; +class KJob; class ProtocolHandler : public QObject @@ -47,9 +51,13 @@ public: bool handle(const QNetworkRequest &request, QWebFrame *frame); +signals: + void downloadUrl( const KUrl &); + private slots: void showResults(const KFileItemList &); - + void slotMostLocalUrlResult(KJob *); + private: QString dirHandling(const KFileItemList &list); diff --git a/src/webpage.cpp b/src/webpage.cpp index 00f71805..cdb72caa 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -80,6 +80,9 @@ WebPage::WebPage(QObject *parent) connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); + + // protocol handler signals + connect(&m_protHandler, SIGNAL(downloadUrl(const KUrl &)), this, SLOT(downloadUrl(const KUrl &))); } -- cgit v1.2.1