[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/generic/runners/locations
From:       Matthias Fuchs <mat69 () gmx ! net>
Date:       2010-12-05 11:11:06
Message-ID: 20101205111106.11A70AC8A4 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1203736 by mfuchs:

Allows a wider range of urls without a protocol to be accepted, like those containing \
umlauts etc., queries, or IPV4-Adresses. If no protocol has be defined, then ports \
aren't supported. Correctly handle protocols that are not a NetorkLocation or http, \
ftp. BUG:227380,228017

 M  +29 -5     locationrunner.cpp  


--- trunk/KDE/kdebase/workspace/plasma/generic/runners/locations/locationrunner.cpp \
#1203735:1203736 @@ -50,12 +50,21 @@
 static void processUrl(KUrl &url, const QString &term)
 {
     if (url.protocol().isEmpty()) {
-        int idx = term.indexOf('/');
+        const int idx = term.indexOf('/');
+
         url.clear();
         url.setHost(term.left(idx));
         if (idx != -1) {
-            url.setPath(term.mid(idx));
+            //allow queries
+            const int queryStart = term.indexOf('?', idx);
+            int pathLength = -1;
+            if ((queryStart > -1) && (idx < queryStart)) {
+                pathLength = queryStart - idx;
+                url.setQuery(term.mid(queryStart));
         }
+
+            url.setPath(term.mid(idx, pathLength));
+        }
         if (term.startsWith("ftp")) {
             url.setProtocol("ftp");
         }
@@ -78,8 +87,23 @@
     return term;
 }
 
+//Any url that has a protocol or that looks like a url is accepted
+bool couldBeUrl(const QString &term)
+{
+    //Does not support a port, as then everything that is before the colon would be \
interpreted as protocol +    static const QString \
ip4vPart("(25[0-5]|2[0-4]\\d|1?\\d\\d?)");//0-255 is allowed +    static const \
QString ipv4('(' + ip4vPart + "\\." + ip4vPart + "\\." + ip4vPart + "\\." + ip4vPart \
+ ')'); +    static const QString fqnd("([^/]+\\.[a-zA-Z]{2,})");
+    static const QString host("^(" + ipv4 + '|' + fqnd + ")");
+    static QRegExp rx(host + "(/.*)?$", Qt::CaseSensitive, QRegExp::RegExp2);
+
+    const KUrl url(term);
+    return (!url.protocol().isEmpty() || rx.exactMatch(term));
+}
+
 void LocationsRunner::match(Plasma::RunnerContext &context)
 {
+
     QString term = context.query();
     Plasma::RunnerContext::Type type = context.type();
 
@@ -111,8 +135,7 @@
         context.addMatch(term, match);
     } else if (type == Plasma::RunnerContext::NetworkLocation ||
                (type == Plasma::RunnerContext::UnknownType &&
-                (term.startsWith('#') ||
-                term.contains(QRegExp("^[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,6}"))))) {
+                (term.startsWith('#') || couldBeUrl(term)))) {
 
         KUrl url(manInfoLookup(term));
         processUrl(url, term);
@@ -173,7 +196,8 @@
     } else if (type != Plasma::RunnerContext::NetworkLocation) {
         QString path = QDir::cleanPath(KShell::tildeExpand(location));
 
-        if (path[0] != '/') {
+        //no protocol defined, might be a local folder
+        if (urlToRun.protocol().isEmpty() && (path[0] != '/')) {
             path.prepend('/').prepend(QDir::currentPath());
         }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic