From 644d6b6f5b4997227691513d0654584a9e9a24c7 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 10 Aug 2009 14:46:49 +0200 Subject: Removing unuseful QUrl class from guessUrlFromString method --- src/application.cpp | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'src/application.cpp') diff --git a/src/application.cpp b/src/application.cpp index 3817098d..ebd99004 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -201,29 +201,24 @@ KUrl Application::guessUrlFromString(const QString &string) QString urlStr = string.trimmed(); QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*")); + // Might be a file. + if (QFile::exists(urlStr)) + { + QFileInfo info(urlStr); + return KUrl::fromPath(info.absoluteFilePath()); + } + // Check if it looks like a qualified URL. Try parsing it and see. - bool hasSchema = test.exactMatch(urlStr); - - if (hasSchema) + if (test.exactMatch(urlStr)) { - QUrl qurl(urlStr, QUrl::TolerantMode); - KUrl url(qurl); - + KUrl url(urlStr); + if (url.isValid()) { return url; } } - - // Might be a file. - if (QFile::exists(urlStr)) - { - QFileInfo info(urlStr); - return KUrl::fromPath(info.absoluteFilePath()); - } - - // Might be a shorturl - try to detect the schema. - if (!hasSchema) + else // Might be a shorturl - try to detect the schema. { int dotIndex = urlStr.indexOf(QLatin1Char('.')); @@ -240,17 +235,10 @@ KUrl Application::guessUrlFromString(const QString &string) } } } - + // Fall back to QUrl's own tolerant parser. - QUrl qurl = QUrl(string, QUrl::TolerantMode); - KUrl url(qurl); + KUrl url = KUrl(string); - // finally for cases where the user just types in a hostname add http - if (qurl.scheme().isEmpty()) - { - qurl = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode); - url = KUrl(qurl); - } return url; } -- cgit v1.2.1