summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2014-09-11 16:26:10 (GMT)
committerDavid Faure <faure@kde.org>2014-09-11 16:26:10 (GMT)
commitd98b4d920037422fe052ffa2633349d41fdbe02e (patch)
treef81ac15af289754c0bec6c7f9620cf09c6957ab5
parente28dbc6c00243442f6278546d19d1cf1b38b4ba9 (diff)
Make it possible to open URLs on the command-line again
by removing much cruft and using the shiny new QUrl::fromUserInput(2 args), but since that requires Qt 5.4, also include a copy here if Qt is too "old". Reviewed-By: Albert Makes-Happy: Lukas
-rw-r--r--shell/shellutils.cpp41
1 files changed, 17 insertions, 24 deletions
diff --git a/shell/shellutils.cpp b/shell/shellutils.cpp
index 600d3b8..57ba130 100644
--- a/shell/shellutils.cpp
+++ b/shell/shellutils.cpp
@@ -12,7 +12,9 @@
// qt/kde includes
#include <QUrl>
#include <QFile>
-#include <QRegExp>
+#include <QFileInfo>
+#include <QDir>
+#include <QDebug>
#include <QtCore/qcommandlineparser.h>
namespace ShellUtils
@@ -35,30 +37,21 @@ FileExistFunc qfileExistFunc()
QUrl urlFromArg( const QString& _arg, FileExistFunc exist_func, const QString& pageArg )
{
- /*
- Rationale for the small "cut-and-paste" work being done below:
- KCmdLineArgs::makeURL() (used by ::url() encodes any # into the URL itself,
- so we have to find it manually and build up the URL by taking its ref,
- if any.
- */
- QString arg = _arg;
- arg.replace( QRegExp( "^file:/{1,3}"), "/" );
- if ( arg != _arg )
- {
- arg = QString::fromUtf8( QByteArray::fromPercentEncoding( arg.toUtf8() ) );
- }
- QUrl url = QUrl::fromUserInput( arg.toUtf8() );
- int sharpPos = -1;
- if ( !url.isLocalFile() || !exist_func( url.toLocalFile() ) )
- {
- sharpPos = arg.lastIndexOf( QLatin1Char( '#' ) );
+ // ## TODO remove exist_func
+#if QT_VERSION >= 0x050400
+ QUrl url = QUrl::fromUserInput(_arg, QDir::currentPath());
+#else
+ // Code from QUrl::fromUserInput(QString, QString)
+ QUrl url = QUrl::fromUserInput(_arg);
+ QUrl testUrl = QUrl(_arg, QUrl::TolerantMode);
+ if (testUrl.isRelative() && !QDir::isAbsolutePath(_arg)) {
+ QFileInfo fileInfo(QDir::current(), _arg);
+ if (fileInfo.exists())
+ url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
}
- if ( sharpPos != -1 )
- {
- url = QUrl::fromUserInput( arg.left( sharpPos ).toUtf8() );
- url.setFragment( arg.mid( sharpPos + 1 ) );
- }
- else if ( !pageArg.isEmpty() )
+
+#endif
+ if ( !pageArg.isEmpty() )
{
url.setFragment( pageArg );
}