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/protocolhandler.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 4 deletions(-) (limited to 'src/protocolhandler.cpp') 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; +} -- cgit v1.2.1