diff options
-rw-r--r-- | src/protocolhandler.cpp | 35 | ||||
-rw-r--r-- | src/protocolhandler.h | 12 | ||||
-rw-r--r-- | 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 <KIconLoader> #include <KDirLister> #include <KFileItem> +#include <KJob> +#include <kio/udsentry.h> // Qt Includes #include <QLatin1String> @@ -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<KIO::StatJob*>(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 <KDirLister> + +// Qt Includes #include <QWebFrame> +// 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 &))); } |