78 lines
2.7 KiB
Diff
78 lines
2.7 KiB
Diff
From 5a5aa4b1786e793f457ad5a88a4e49d7469a92fa Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= <lukas@kde.org>
|
|
Date: Tue, 9 Sep 2014 22:49:27 +0200
|
|
Subject: [PATCH 2/2] Fix relative paths being turned into http urls by
|
|
fromUserInput.
|
|
|
|
Reviewed-By: (well, written by) David Faure.
|
|
---
|
|
src/filewidgets/kfilewidget.cpp | 24 ++++++++++++++++++++----
|
|
1 file changed, 20 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/filewidgets/kfilewidget.cpp b/src/filewidgets/kfilewidget.cpp
|
|
index 42320e3..58dd92e 100644
|
|
--- a/src/filewidgets/kfilewidget.cpp
|
|
+++ b/src/filewidgets/kfilewidget.cpp
|
|
@@ -325,6 +325,22 @@ static bool containsProtocolSection(const QString &string)
|
|
return false;
|
|
}
|
|
|
|
+// this string-to-url conversion function handles relative paths, full paths and URLs
|
|
+// without the http-prepending that QUrl::fromUserInput does.
|
|
+static QUrl urlFromString(const QString& str)
|
|
+{
|
|
+ if (QDir::isAbsolutePath(str)) {
|
|
+ return QUrl::fromLocalFile(str);
|
|
+ }
|
|
+ QUrl url(str);
|
|
+ if (url.isRelative()) {
|
|
+ url.clear();
|
|
+ url.setPath(str);
|
|
+ }
|
|
+ return url;
|
|
+}
|
|
+
|
|
+
|
|
KFileWidget::KFileWidget(const QUrl &_startDir, QWidget *parent)
|
|
: QWidget(parent), d(new KFileWidgetPrivate(this))
|
|
{
|
|
@@ -909,7 +925,7 @@ void KFileWidget::slotOk()
|
|
containsProtocolSection(locationEditCurrentText))) {
|
|
|
|
QString fileName;
|
|
- QUrl url = QUrl::fromUserInput(locationEditCurrentText);
|
|
+ QUrl url = urlFromString(locationEditCurrentText);
|
|
if (d->operationMode == Opening) {
|
|
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
|
|
KJobWidgets::setWindow(statJob, this);
|
|
@@ -1447,7 +1463,7 @@ void KFileWidgetPrivate::_k_urlEntered(const QUrl &url)
|
|
|
|
bool blocked = locationEdit->blockSignals(true);
|
|
if (keepLocation) {
|
|
- QUrl currentUrl = QUrl::fromUserInput(filename);
|
|
+ QUrl currentUrl = urlFromString(filename);
|
|
locationEdit->changeUrl(0, QIcon::fromTheme(KIO::iconNameForUrl(currentUrl)), currentUrl);
|
|
locationEdit->lineEdit()->setModified(true);
|
|
}
|
|
@@ -1494,7 +1510,7 @@ void KFileWidgetPrivate::_k_enterUrl(const QString &url)
|
|
{
|
|
// qDebug();
|
|
|
|
- _k_enterUrl(QUrl::fromUserInput(KUrlCompletion::replacedPath(url, true, true)));
|
|
+ _k_enterUrl(urlFromString(KUrlCompletion::replacedPath(url, true, true)));
|
|
}
|
|
|
|
bool KFileWidgetPrivate::toOverwrite(const QUrl &url)
|
|
@@ -1677,7 +1693,7 @@ QList<QUrl> KFileWidgetPrivate::tokenize(const QString &line) const
|
|
urls.append(u);
|
|
}
|
|
} else {
|
|
- urls << QUrl::fromUserInput(line);
|
|
+ urls << QUrl::fromLocalFile(line);
|
|
}
|
|
|
|
return urls;
|
|
--
|
|
2.1.0
|
|
|