From a8f5272dde15fc085ff3c81f65b441e52b41b12c Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 15 Dec 2009 12:34:41 +0100 Subject: We have file management :D --- src/networkaccessmanager.cpp | 7 +--- src/protocolhandler.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++-- src/protocolhandler.h | 5 +++ 3 files changed, 95 insertions(+), 9 deletions(-) diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index 1f8b8281..7d6bf434 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -48,17 +48,14 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR kDebug() << outgoingDataByteArray; kDebug() << "*************************************************************************"; } - - QNetworkRequest request(req); - request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); // Adblock if (op == QNetworkAccessManager::GetOperation) { - QNetworkReply *reply = Application::adblockManager()->block(request); + QNetworkReply *reply = Application::adblockManager()->block(req); if (reply) return reply; } - return AccessManager::createRequest(op,request,outgoingData); + return AccessManager::createRequest(op,req,outgoingData); } diff --git a/src/protocolhandler.cpp b/src/protocolhandler.cpp index fb01b266..677618dc 100644 --- a/src/protocolhandler.cpp +++ b/src/protocolhandler.cpp @@ -30,14 +30,22 @@ #include "newtabpage.h" // KDE Includes +#include #include #include #include +#include +#include +#include +#include // Qt Includes #include #include #include +#include +#include +#include ProtocolHandler::ProtocolHandler() @@ -54,13 +62,14 @@ bool ProtocolHandler::handle(const QNetworkRequest &request, QWebFrame *frame) { KUrl url( request.url() ); - // mailto handling + // "mailto" handling if ( url.protocol() == QLatin1String("mailto") ) { KToolInvocation::invokeMailer(url); return true; } + // "about" handling if ( url.protocol() == QLatin1String("about") ) { if( url == KUrl("about:closedTabs") @@ -90,12 +99,87 @@ bool ProtocolHandler::handle(const QNetworkRequest &request, QWebFrame *frame) // "file" handling if(url.protocol() == QLatin1String("file")) { - KUrl::List list; - list.append(url); - KRun::run("dolphin %u",url,0); + QString html = fileHandling(url); + kDebug() << html; + frame->setHtml( html ); +// KUrl::List list; +// list.append(url); +// KRun::run("dolphin %u",url,0); return true; } return false; } + + +QString ProtocolHandler::fileHandling(const KUrl &url) +{ + QDir dir(url.toLocalFile()); + + if (!dir.exists()) + { + QString errStr = i18n("Error opening: %1: No such file or directory", dir.absolutePath() ); + return errStr; + } + if (!dir.isReadable()) + { + QString errStr = i18n("Unable to read %1", dir.absolutePath() ); + return errStr; + } + + // display "not found" page + QString notfoundFilePath = KStandardDirs::locate("data", "rekonq/htmls/notfound.html"); + QFile file(notfoundFilePath); + + bool isOpened = file.open(QIODevice::ReadOnly); + if (!isOpened) + { + return QString("rekonq error, sorry :("); + } + + QString title = url.path(); + QString imagesPath = QString("file://") + KGlobal::dirs()->findResourceDir("data", "rekonq/pics/bg.png") + QString("rekonq/pics"); + QString msg = "

" + url.path() + "

"; + + dir.setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); + QFileInfoList entries = dir.entryInfoList(); + + msg += ""; + msg += ""; + + foreach(const QFileInfo &item, entries) + { + msg += ""; + QString fullPath = QString("file://") + item.absoluteFilePath(); + + QString iconName = KMimeType::defaultMimeTypePtr()->iconNameForUrl(fullPath); + kDebug() << "***************************************" << iconName << "********************************"; + QString icon = QString("file://") + KIconLoader::global()->iconPath( iconName, KIconLoader::Small ); + + msg += ""; + + msg += ""; + + msg += ""; + + msg += ""; + } + msg += "
" + i18n("Name") + "" + i18n("Size") + "" + i18n("Last Modified") + "
"; + msg += "\"" "; + msg += "" + item.fileName() + ""; + msg += ""; + msg += QString::number( item.size()/1024 ) + "KB"; + msg += ""; + msg += item.lastModified().toString("dd/MM/yyyy hh:mm:ss"); + msg += "
"; + + + QString html = QString(QLatin1String(file.readAll())) + .arg(title) + .arg(imagesPath) + .arg(msg) + ; + + return html; +} diff --git a/src/protocolhandler.h b/src/protocolhandler.h index b857f27b..09a28c21 100644 --- a/src/protocolhandler.h +++ b/src/protocolhandler.h @@ -30,6 +30,8 @@ class QNetworkRequest; class QWebFrame; +class QString; +class KUrl; class ProtocolHandler @@ -40,6 +42,9 @@ public: ~ProtocolHandler(); bool handle(const QNetworkRequest &request, QWebFrame *frame); + +private: + QString fileHandling(const KUrl &url); }; #endif // PROTOCOL_HANDLER_H -- cgit v1.2.1