mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Merge pull request #779 from srazi/master
File/Ftp SchemeHandlers: Clickable title for easier navigation, also using native separator in file's title.
This commit is contained in:
commit
f19cb64163
|
@ -9,6 +9,8 @@ h1 {color:#1a4ba4;font-size:120%;margin-bottom:0px;word-wrap:break-word;}
|
|||
a{text-decoration:none;}
|
||||
a:hover{text-decoration:underline;}
|
||||
p{margin-bottom:0;}
|
||||
h1 a{ border-bottom: 1px solid rgba(0, 130, 217, 0.196); color: #0082D9;}
|
||||
h1 a:hover{ text-decoration:none; border-bottom: 1px solid rgba(0, 130, 217, 1); color: #0082D9;}
|
||||
|
||||
.dir-up{float:%LEFT_STR%;padding-%LEFT_STR%:22px;font-size:105%;height:30px;background:transparent url(data:image/png;base64,%UP-IMG%) no-repeat;}
|
||||
.show-hidden{float:%RIGHT_STR%;font-size:105%;height:30px;}
|
||||
|
@ -47,7 +49,7 @@ function showHidden()
|
|||
</head>
|
||||
<body>
|
||||
<div id="box">
|
||||
<h1>%TITLE%</h1>
|
||||
<h1>%CLICKABLE-TITLE%</h1>
|
||||
|
||||
<p class="dir-up" style="display:%UP-DIR-DISPLAY%"><a href="%UP-DIR-LINK%">%UP-DIR-TEXT%</a></p>
|
||||
<p class="show-hidden" style="display:%SHOW-HIDDEN-DISPLAY%"><label><input type="checkbox" onchange="showHidden()">%SHOW-HIDDEN-TEXT%</label></p>
|
||||
|
|
|
@ -168,7 +168,10 @@ QString FileSchemeReply::loadDirectory()
|
|||
}
|
||||
|
||||
QString page = sPage;
|
||||
page.replace(QLatin1String("%TITLE%"), tr("Index for %1").arg(request().url().toLocalFile()));
|
||||
QString title = request().url().toLocalFile();
|
||||
title.replace(QLatin1Char('/'), QDir::separator());
|
||||
page.replace(QLatin1String("%TITLE%"), tr("Index for %1").arg(title));
|
||||
page.replace(QLatin1String("%CLICKABLE-TITLE%"), tr("Index for %1").arg(clickableSections(title)));
|
||||
|
||||
QString upDirDisplay = QLatin1String("none");
|
||||
QString showHiddenDisplay = QLatin1String("none");
|
||||
|
@ -222,3 +225,28 @@ QString FileSchemeReply::loadDirectory()
|
|||
|
||||
return page;
|
||||
}
|
||||
|
||||
QString FileSchemeReply::clickableSections(const QString &path)
|
||||
{
|
||||
QString title = path;
|
||||
const QString dirSeparator = QDir::separator();
|
||||
QStringList sections = title.split(dirSeparator, QString::SkipEmptyParts);
|
||||
if (sections.isEmpty()) {
|
||||
return QString("<a href=\"%1\">%1</a>").arg(path);
|
||||
}
|
||||
|
||||
title.clear();
|
||||
#ifndef Q_OS_WIN
|
||||
title = QString("<a href=\"%1\">%1</a>").arg(dirSeparator);
|
||||
#endif
|
||||
for (int i = 0; i < sections.size(); ++i) {
|
||||
QStringList currentParentSections = sections.mid(0, i + 1);
|
||||
QString localFile = currentParentSections.join(QLatin1String("/"));
|
||||
#ifndef Q_OS_WIN
|
||||
localFile.prepend(dirSeparator);
|
||||
#endif
|
||||
title += QString("<a href=\"%1\">%2</a>%3").arg(QUrl::fromLocalFile(localFile).toEncoded(), sections.at(i), dirSeparator);
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ private slots:
|
|||
|
||||
private:
|
||||
QString loadDirectory();
|
||||
QString clickableSections(const QString &path);
|
||||
|
||||
QBuffer m_buffer;
|
||||
QString m_pageName;
|
||||
|
|
|
@ -272,6 +272,7 @@ QString FtpSchemeReply::loadDirectory()
|
|||
title = QString::fromLatin1(titleByteArray);
|
||||
}
|
||||
page.replace(QLatin1String("%TITLE%"), tr("Index for %1").arg(title));
|
||||
page.replace(QLatin1String("%CLICKABLE-TITLE%"), tr("Index for %1").arg(clickableSections(title)));
|
||||
|
||||
QString upDirDisplay = QLatin1String("none");
|
||||
QString tBody;
|
||||
|
@ -344,6 +345,26 @@ QString FtpSchemeReply::loadDirectory()
|
|||
return page;
|
||||
}
|
||||
|
||||
QString FtpSchemeReply::clickableSections(const QString &path)
|
||||
{
|
||||
QString title = path;
|
||||
title.remove(QLatin1String("ftp://"));
|
||||
QStringList sections = title.split(QLatin1Char('/'), QString::SkipEmptyParts);
|
||||
if (sections.isEmpty()) {
|
||||
return QString("<a href=\"%1\">%1</a>").arg(path);
|
||||
}
|
||||
sections[0].prepend(QLatin1String("ftp://"));
|
||||
|
||||
title.clear();
|
||||
for (int i = 0; i < sections.size(); ++i) {
|
||||
QStringList currentParentSections = sections.mid(0, i + 1);
|
||||
QUrl currentParentUrl = QUrl(currentParentSections.join(QLatin1String("/")));
|
||||
title += QString("<a href=\"%1\">%2</a>/").arg(currentParentUrl.toEncoded(), sections.at(i));
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
void FtpSchemeReply::ftpReplyErrorHandler(int id)
|
||||
{
|
||||
if (m_ftpLoginId == id) {
|
||||
|
|
|
@ -73,6 +73,7 @@ private slots:
|
|||
private:
|
||||
void setContent();
|
||||
void ftpReplyErrorHandler(int id);
|
||||
QString clickableSections(const QString &path);
|
||||
|
||||
QFtp* m_ftp;
|
||||
QList<QUrlInfo> m_items;
|
||||
|
|
Loading…
Reference in New Issue
Block a user