summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/networkaccessmanager.cpp7
-rw-r--r--src/protocolhandler.cpp92
-rw-r--r--src/protocolhandler.h5
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 <klocalizedstring.h>
#include <KUrl>
#include <KRun>
#include <KToolInvocation>
+#include <KStandardDirs>
+#include <KDebug>
+#include <KMimeType>
+#include <KIconLoader>
// Qt Includes
#include <QLatin1String>
#include <QNetworkRequest>
#include <QWebFrame>
+#include <QDir>
+#include <QFile>
+#include <QDateTime>
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 = "<h1>" + url.path() + "</h1>";
+
+ dir.setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
+ QFileInfoList entries = dir.entryInfoList();
+
+ msg += "<table>";
+ msg += "<tr><th>" + i18n("Name") + "</th><th>" + i18n("Size") + "</th><th>" + i18n("Last Modified") + "</th></tr>";
+
+ foreach(const QFileInfo &item, entries)
+ {
+ msg += "<tr>";
+ 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 += "<td>";
+ msg += "<img src=\"" + icon + "\" alt=\"" + iconName + "\" /> ";
+ msg += "<a href=\"" + fullPath + "\">" + item.fileName() + "</a>";
+ msg += "</td>";
+
+ msg += "<td>";
+ msg += QString::number( item.size()/1024 ) + "KB";
+ msg += "</td>";
+
+ msg += "<td>";
+ msg += item.lastModified().toString("dd/MM/yyyy hh:mm:ss");
+ msg += "</td>";
+
+ msg += "</tr>";
+ }
+ msg += "</table>";
+
+
+ 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