From d09e7314a81210337b89bd3763c60ac3b2c2eefa Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 18 Dec 2009 20:28:43 +0100 Subject: native ftp handling & file one ported to kde functions. One step to be feature complete (at least for 0.4): I need to know if an ftp url represent a file or a dir.. --- src/application.cpp | 5 ++- src/protocolhandler.cpp | 106 ++++++++++++++++++++++++++++++------------------ src/protocolhandler.h | 23 ++++++++--- 3 files changed, 87 insertions(+), 47 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index 28d998f3..8b8234b5 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -348,7 +348,10 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) // ------------------- END WARNING -------------------------------------- // we are sure of the url now, let's add it to history - historyManager()->addHistoryEntry( loadingUrl.prettyUrl() ); + // anyway we store here just http sites because local and ftp ones are + // added trough the protocol handler and the other are ignored + if( url.protocol() == QLatin1String("http") ) + historyManager()->addHistoryEntry( loadingUrl.prettyUrl() ); if (!ReKonfig::openTabsBack()) { diff --git a/src/protocolhandler.cpp b/src/protocolhandler.cpp index 1b60d0dc..57f0492e 100644 --- a/src/protocolhandler.cpp +++ b/src/protocolhandler.cpp @@ -32,6 +32,7 @@ #include "mainwindow.h" #include "mainview.h" #include "urlbar.h" +#include "historymanager.h" // KDE Includes #include @@ -42,6 +43,8 @@ #include #include #include +#include +#include // Qt Includes #include @@ -52,8 +55,12 @@ #include -ProtocolHandler::ProtocolHandler() +ProtocolHandler::ProtocolHandler(QObject *parent) + : QObject(parent) + , _lister(new KDirLister) + , _frame(0) { + connect( _lister, SIGNAL(newItems(const KFileItemList &)), this, SLOT(showResults(const KFileItemList &))); } @@ -64,51 +71,49 @@ ProtocolHandler::~ProtocolHandler() bool ProtocolHandler::handle(const QNetworkRequest &request, QWebFrame *frame) { - KUrl url( request.url() ); + _url = request.url(); + _frame = frame; // "mailto" handling - if ( url.protocol() == QLatin1String("mailto") ) + if ( _url.protocol() == QLatin1String("mailto") ) { - KToolInvocation::invokeMailer(url); + KToolInvocation::invokeMailer(_url); return true; } // "about" handling - if ( url.protocol() == QLatin1String("about") ) + if ( _url.protocol() == QLatin1String("about") ) { - if( url == KUrl("about:closedTabs") - || url == KUrl("about:history") - || url == KUrl("about:bookmarks") - || url == KUrl("about:favorites") - || url == KUrl("about:home") + if( _url == KUrl("about:closedTabs") + || _url == KUrl("about:history") + || _url == KUrl("about:bookmarks") + || _url == KUrl("about:favorites") + || _url == KUrl("about:home") ) { NewTabPage p(frame); - p.generate(url); - + p.generate(_url); return true; } } // "ftp" handling - if(url.protocol() == QLatin1String("ftp")) + if( _url.protocol() == QLatin1String("ftp") ) { - KUrl::List list; - list.append(url); - KRun::run("dolphin %u",url,0); - + // TODO + // I need to know if the url represent a file + // and, in that case we have to just return false! + _lister->openUrl(_url); return true; } // "file" handling - if(url.protocol() == QLatin1String("file")) + if(_url.protocol() == QLatin1String("file") ) { - QFileInfo fileInfo(url.path()); + QFileInfo fileInfo( _url.path() ); if(fileInfo.isDir()) { - QString html = dirHandling(url); - frame->setHtml(html); - Application::instance()->mainWindow()->mainView()->urlBar()->setUrl(url); + _lister->openUrl(_url); return true; } } @@ -117,18 +122,20 @@ bool ProtocolHandler::handle(const QNetworkRequest &request, QWebFrame *frame) } -QString ProtocolHandler::dirHandling(const KUrl &url) +QString ProtocolHandler::dirHandling(const KFileItemList &list) { - QDir dir(url.toLocalFile()); + + KFileItem mainItem = _lister->rootItem(); + KUrl rootUrl = mainItem.url(); - if (!dir.exists()) + if (mainItem.isNull()) { - QString errStr = i18n("Error opening: %1: No such file or directory", dir.absolutePath() ); + QString errStr = i18n("Error opening: %1: No such file or directory", rootUrl.prettyUrl() ); return errStr; } - if (!dir.isReadable()) + if (!mainItem.isReadable()) { - QString errStr = i18n("Unable to read %1", dir.absolutePath() ); + QString errStr = i18n("Unable to read %1", rootUrl.prettyUrl() ); return errStr; } @@ -142,15 +149,13 @@ QString ProtocolHandler::dirHandling(const KUrl &url) return QString("rekonq error, sorry :("); } - QString title = url.path(); - QString msg = "

" + i18n("Index of ") + "file://" + url.path() + "

"; + QString title = _url.prettyUrl(); + QString msg = "

" + i18n("Index of ") + _url.prettyUrl() + "

"; - dir.setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); - QFileInfoList entries = dir.entryInfoList(); - if(!dir.isRoot()) + if(rootUrl.cd("..")) { - QString path = "file://" + dir.absoluteFilePath(".."); + QString path = rootUrl.prettyUrl(); QString uparrow = KIconLoader::global()->iconPath( "arrow-up", KIconLoader::Small ); msg += "\"up-arrow\""; msg += "" + i18n("Up to higher level directory") + "

"; @@ -158,18 +163,18 @@ QString ProtocolHandler::dirHandling(const KUrl &url) msg += ""; msg += ""; - - foreach(const QFileInfo &item, entries) + + foreach(const KFileItem &item, list) { msg += ""; - QString fullPath = QString("file://") + item.absoluteFilePath(); + QString fullPath = item.url().prettyUrl(); - QString iconName = KMimeType::defaultMimeTypePtr()->iconNameForUrl(fullPath); + QString iconName = item.iconName(); QString icon = QString("file://") + KIconLoader::global()->iconPath( iconName, KIconLoader::Small ); msg += ""; msg += ""; msg += ""; msg += ""; @@ -195,3 +200,24 @@ QString ProtocolHandler::dirHandling(const KUrl &url) return html; } + + +void ProtocolHandler::showResults(const KFileItemList &list) +{ + if(_lister->rootItem().isFile()) + { + WebPage *page = qobject_cast( _frame->page() ); + page->downloadUrl( _lister->rootItem().url() ); + return; + } + + if ( list.isEmpty() ) + return; + + QString html = dirHandling(list); + _frame->setHtml(html); + + Application::instance()->mainWindow()->mainView()->urlBar()->setUrl(_url); + Application::historyManager()->addHistoryEntry( _url.prettyUrl() ); +} + diff --git a/src/protocolhandler.h b/src/protocolhandler.h index 8628a4f7..81cda4b6 100644 --- a/src/protocolhandler.h +++ b/src/protocolhandler.h @@ -28,23 +28,34 @@ #define PROTOCOL_HANDLER_H +#include +#include + class QNetworkRequest; class QWebFrame; class QString; class KUrl; -class ProtocolHandler +class ProtocolHandler : public QObject { - +Q_OBJECT + public: - ProtocolHandler(); - ~ProtocolHandler(); + ProtocolHandler(QObject *parent = 0); + ~ProtocolHandler(); + + bool handle(const QNetworkRequest &request, QWebFrame *frame); - bool handle(const QNetworkRequest &request, QWebFrame *frame); +private slots: + void showResults(const KFileItemList &); private: - QString dirHandling(const KUrl &url); + QString dirHandling(const KFileItemList &list); + + KDirLister *_lister; + QWebFrame *_frame; + KUrl _url; }; #endif // PROTOCOL_HANDLER_H -- cgit v1.2.1
" + i18n("Name") + "" + i18n("Size") + "" + i18n("Last Modified") + "
"; msg += "\"" "; - msg += "" + item.fileName() + ""; + msg += "" + item.name() + ""; msg += ""; @@ -180,7 +185,7 @@ QString ProtocolHandler::dirHandling(const KUrl &url) msg += ""; - msg += item.lastModified().toString("dd/MM/yyyy hh:mm:ss"); + msg += item.timeString(); msg += "