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

List:       kde-i18n-doc
Subject:    branches/KDE/4.4/kdebase/workspace/plasma/generic/runners/powerdevil
From:       Jacopo De Simoi <wilderkde () gmail ! com>
Date:       2010-01-11 23:09:53
Message-ID: 1263251393.705411.13803.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1073303 by jacopods:

Correctly parse strings for non-english locales as well. Thanks to the l10n team for \
allowing this fix Bonus fix: also make parsing case insensitive
BUG: 201243
BUG: 208962
CCMAIL: kde-i18n-doc@kde.org


 M  +44 -20    PowerDevilRunner.cpp  
 M  +1 -0      PowerDevilRunner.h  


--- branches/KDE/4.4/kdebase/workspace/plasma/generic/runners/powerdevil/PowerDevilRunner.cpp \
#1073302:1073303 @@ -211,20 +211,36 @@
     updateSyntaxes();
 }
 
+
+bool PowerDevilRunner::parseQuery(const QString& query, const QList<QRegExp>& \
rxList, QString& parameter) const +{
+    foreach (const QRegExp& rx, rxList) {
+        if (rx.exactMatch(query)) {
+             parameter = rx.cap(1).trimmed();
+             return true;
+        }
+    }
+    return false;
+}
+
 void PowerDevilRunner::match(Plasma::RunnerContext &context)
 {
-    const QString term = context.query().toLower();
+    const QString term = context.query();
     if (term.length() < m_shortestCommand) {
         return;
     }
 
     QList<Plasma::QueryMatch> matches;
 
-    if (term.startsWith(i18nc("Note this is a KRunner keyword", "power profile"))) {
+    QString parameter;
+
+    if (parseQuery(term,
+                   QList<QRegExp>() << QRegExp(i18nc("Note this is a KRunner \
keyword; %1 is a parameter", "power profile %1", "(.*)"), Qt::CaseInsensitive) +      \
<< QRegExp(i18nc("Note this is a KRunner keyword", "power profile"), \
Qt::CaseInsensitive), +                   parameter)) {
         foreach(const QString &profile, m_availableProfiles) {
-            const QStringList strings = term.split(' ');
-            if (strings.count() == 3) {
-                if (!profile.startsWith(strings.at(2))) {
+            if (!parameter.isEmpty()) {
+                if (!profile.startsWith(parameter, Qt::CaseInsensitive)) {
                     continue;
                 }
             }
@@ -237,12 +253,15 @@
             match.setId("ProfileChange "+profile);
             matches.append(match);
         }
-    } else if (term.startsWith(i18nc("Note this is a KRunner keyword", "cpu \
                policy")) ||
-               term.startsWith(i18nc("Note this is a KRunner keyword", "power \
governor"))) { +    } else if (parseQuery(term,
+                          QList<QRegExp>() << QRegExp(i18nc("Note this is a KRunner \
keyword; %1 is a parameter", "cpu policy %1", "(.*)"), Qt::CaseInsensitive) +         \
<< QRegExp(i18nc("Note this is a KRunner keyword", "cpu policy"), \
Qt::CaseInsensitive) +                                           << \
QRegExp(i18nc("Note this is a KRunner keyword; %1 is a parameter", "power governor \
%1", "(.*)"), Qt::CaseInsensitive) +                                           << \
QRegExp(i18nc("Note this is a KRunner keyword", "power governor"), \
Qt::CaseInsensitive), +                          parameter)) {
         foreach(const QString &ent, m_supportedGovernors) {
-            const QStringList strings = term.split(' ');
-            if (strings.count() == 3) {
-                if (!ent.startsWith(strings.at(2))) {
+            if (!parameter.isEmpty()) {
+                if (!ent.startsWith(parameter, Qt::CaseInsensitive)) {
                     continue;
                 }
             }
@@ -276,11 +295,13 @@
             match.setId("GovernorChange "+ent);
             matches.append(match);
         }
-    } else if (term.startsWith(i18nc("Note this is a KRunner keyword", "power \
scheme"))) { +    } else if (parseQuery(term,
+                   QList<QRegExp>() << QRegExp(i18nc("Note this is a KRunner \
keyword; %1 is a parameter", "power scheme %1", "(.*)"), Qt::CaseInsensitive) +       \
<< QRegExp(i18nc("Note this is a KRunner keyword", "power scheme"), \
Qt::CaseInsensitive), +                   parameter)) {
         foreach(const QString &ent, m_supportedSchemes) {
-            const QStringList strings = term.split(' ');
-            if (strings.count() == 3) {
-                if (!ent.startsWith(strings.at(2))) {
+            if (!parameter.isEmpty()) {
+                if (!ent.startsWith(parameter, Qt::CaseInsensitive)) {
                     continue;
                 }
             }
@@ -297,12 +318,15 @@
             match.setId("SchemeChange "+ent);
             matches.append(match);
         }
-    } else if (term.startsWith(i18nc("Note this is a KRunner keyword", "screen \
                brightness")) ||
-               term.startsWith(i18nc("Note this is a KRunner keyword", "dim \
                screen"))) {
-        const QStringList strings = term.split(' ');
-        if (strings.count() == 3) {
+    } else if (parseQuery(term,
+                          QList<QRegExp>() << QRegExp(i18nc("Note this is a KRunner \
keyword; %1 is a parameter", "screen brightness %1", "(.*)"), Qt::CaseInsensitive) +  \
<< QRegExp(i18nc("Note this is a KRunner keyword", "screen brightness"), \
Qt::CaseInsensitive) +                                           << \
QRegExp(i18nc("Note this is a KRunner keyword; %1 is a parameter", "dim screen %1", \
"(.*)"), Qt::CaseInsensitive) +                                           << \
QRegExp(i18nc("Note this is a KRunner keyword", "dim screen"), Qt::CaseInsensitive), \
+                          parameter)) { +        if (!parameter.isEmpty()) {
             bool test;
-            int b = strings.at(2).toInt(&test);
+            int b = parameter.toInt(&test);
             if (test) {
                 int brightness = qBound(0, b, 100);
                 Plasma::QueryMatch match(this);
@@ -314,7 +338,7 @@
                 match.setId("BrightnessChange");
                 matches.append(match);
             }
-        } else if (strings.count() == 2) {
+        } else {
             Plasma::QueryMatch match1(this);
             match1.setType(Plasma::QueryMatch::ExactMatch);
             match1.setIcon(KIcon("preferences-system-power-management"));
--- branches/KDE/4.4/kdebase/workspace/plasma/generic/runners/powerdevil/PowerDevilRunner.h \
#1073302:1073303 @@ -41,6 +41,7 @@
         void initUpdateTriggers();
         void updateSyntaxes();
         void addSuspendMatch(int value, QList<Plasma::QueryMatch> &matches);
+        bool parseQuery(const QString& query, const QList<QRegExp>& rxList, QString& \
parameter) const;  
         QDBusConnection m_dbus;
 


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

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