[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:23:28 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=a408e37

The following commit has been merged in the master branch:
commit a408e37e77ee0e06ffaa470dc8e77bb70d062bd7
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Tue Feb 26 17:47:43 2013 +0000

    Move bugzilla querying into the client
    
    This allows everything to happen asynchronously, meaning we don't block the UI and we can show the message instantly
---
 filters/bugzilla/CMakeLists.txt      |  3 +++
 filters/bugzilla/bugzilla-filter.cpp | 51 +++++++++++++-----------------------
 filters/bugzilla/bugzilla-filter.h   |  4 +--
 filters/bugzilla/showBugzillaInfo.js | 35 +++++++++++++++++++++++++
 4 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/filters/bugzilla/CMakeLists.txt b/filters/bugzilla/CMakeLists.txt
index 39dbc7d..41787ec 100644
--- a/filters/bugzilla/CMakeLists.txt
+++ b/filters/bugzilla/CMakeLists.txt
@@ -24,3 +24,6 @@ install (TARGETS ktptextui_message_filter_bugzilla
 install (FILES ktptextui_message_filter_bugzilla.desktop
          DESTINATION ${SERVICES_INSTALL_DIR}
 )
+
+install (FILES showBugzillaInfo.js
+         DESTINATION ${DATA_INSTALL_DIR}/ktelepathy)
diff --git a/filters/bugzilla/bugzilla-filter.cpp b/filters/bugzilla/bugzilla-filter.cpp
index c66f30f..dda3e0c 100644
--- a/filters/bugzilla/bugzilla-filter.cpp
+++ b/filters/bugzilla/bugzilla-filter.cpp
@@ -29,15 +29,19 @@
 class BugzillaFilter::Private
 {
 public:
+    Private() {
+        filterId = 0;
+    }
+
     QRegExp bugText;
     QString sectionTemplate;
+    int filterId;
 };
 
 BugzillaFilter::BugzillaFilter(QObject *parent, const QVariantList &) :
     AbstractMessageFilter(parent), d(new Private)
 {
     d->bugText = QRegExp(QLatin1String("BUG:[ ]*(\d+)"));
-    d->sectionTemplate = QLatin1String("<br/>[BUG <a href='%1'>%2</a>] %3 - %4");
 }
 
 BugzillaFilter::~BugzillaFilter()
@@ -45,7 +49,10 @@ BugzillaFilter::~BugzillaFilter()
     delete d;
 }
 
-void BugzillaFilter::addBugDescription(KTp::Message &msg, const KUrl &baseUrl) {
+void BugzillaFilter::addBugDescription(KTp::Message &message, const KUrl &baseUrl) {
+    QString bugRequestId((QLatin1String("bug_") + QString::number(d->filterId)));
+    d->filterId++;
+
     KUrl request;
     request.setHost(baseUrl.host());
     request.setProtocol(baseUrl.protocol());
@@ -57,36 +64,11 @@ void BugzillaFilter::addBugDescription(KTp::Message &msg, const KUrl &baseUrl) {
                          QString(QLatin1String("[{\"ids\":[%1]}]")).
                          arg(baseUrl.queryItemValue(QLatin1String("id"))));
 
-    kDebug() << request;
-    KIO::StoredTransferJob *job = KIO::storedGet(request);
-    job->exec();
-
-
-    QVariantMap response = QJson::Parser().parse(job->data()).toMap();
-    if (response.contains(QLatin1String("result"))) {
-        QVariantMap result = response.value(QLatin1String("result")).toMap();
-        if (result.contains(QLatin1String("bugs"))) {
-            QVariantList bugs = result.value(QLatin1String("bugs")).toList();
-            if (!bugs.isEmpty()) {
-                QVariantMap bug = bugs.first().toMap();
-                if (bug.contains(QLatin1String("summary"))) {
-                    QString summary = bug.value(QLatin1String("summary")).toString();
-                    QString status = bug.value(QLatin1String("status")).toString();
-
-                    if (status == QLatin1String("RESOLVED")) {
-                        status += QString::fromLatin1(" (%1)").arg(bug.value(QLatin1String("resolution")).toString());
-                    }
-
-                    msg.appendMessagePart(d->sectionTemplate
-                        .arg(baseUrl.url())
-                        .arg(Qt::escape(baseUrl.queryItemValue(QLatin1String("id"))))
-                        .arg(Qt::escape(summary))
-                        .arg(status));
-                }
-            }
-        }
-    }
+    request.addQueryItem(QLatin1String("callback"), QLatin1String("showBugCallback"));
+    request.addQueryItem(QLatin1String("id"), bugRequestId);
 
+    message.appendMessagePart(QString::fromLatin1("<p><a href=\"%1\" id=\"%2\"></a></p>").arg(baseUrl.prettyUrl(), bugRequestId));
+    message.appendScript(QString::fromLatin1("showBug(\"%1\");").arg(request.prettyUrl()));
 }
 
 void BugzillaFilter::filterMessage(KTp::Message &message, const KTp::MessageContext &context)
@@ -116,12 +98,15 @@ void BugzillaFilter::filterMessage(KTp::Message &message, const KTp::MessageCont
         KUrl url = qvariant_cast<KUrl>(var);
 
         if (url.fileName() == QLatin1String("show_bug.cgi")) { //a bugzilla of some sort
-            kDebug() << "link is to a bugzilla:" << url.host();
-
             addBugDescription(message, url);
         }
     }
 }
 
+QStringList BugzillaFilter::requiredScripts()
+{
+    return QStringList() << QLatin1String("ktelepathy/showBugzillaInfo.js");
+}
+
 K_PLUGIN_FACTORY(MessageFilterFactory, registerPlugin<BugzillaFilter>();)
 K_EXPORT_PLUGIN(MessageFilterFactory("ktptextui_message_filter_bugzilla"))
diff --git a/filters/bugzilla/bugzilla-filter.h b/filters/bugzilla/bugzilla-filter.h
index 91bf3bd..e3271b3 100644
--- a/filters/bugzilla/bugzilla-filter.h
+++ b/filters/bugzilla/bugzilla-filter.h
@@ -32,9 +32,9 @@ public:
     virtual ~BugzillaFilter();
 
     virtual void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
-
+    virtual QStringList requiredScripts();
 private:
-    void addBugDescription(KTp::Message &msg, const KUrl &baseUrl);
+    void addBugDescription(KTp::Message &message, const KUrl &baseUrl);
 
     class Private;
     Private *d;
diff --git a/filters/bugzilla/showBugzillaInfo.js b/filters/bugzilla/showBugzillaInfo.js
new file mode 100644
index 0000000..1906257
--- /dev/null
+++ b/filters/bugzilla/showBugzillaInfo.js
@@ -0,0 +1,35 @@
+//add bugzilla information to the UI
+//the message processor adds a div with a specific ID to the message
+//this ID is passed to the bugzilla RPC instance as an ID, which is returned in the query
+//when this callback function is run, we extract that ID and update the contents accordingly
+
+function showBugCallback(response)
+{
+    var id = response["id"];
+    var bug = response["result"]["bugs"][0];
+
+    var bugId = bug["id"];
+
+    var summary = bug["summary"]
+    var status = bug["status"]
+    var resolution = bug["resolution"]
+
+    var html = "[BUG "+bugId+"] "+summary + " " + status;
+
+    if (status == "RESOLVED") {
+        html += " (" + resolution +")";
+    }
+
+    document.getElementById(id).innerHTML = html;
+}
+
+//use jsonp to avoid problems with web security origin
+//see http://en.wikipedia.org/wiki/JSONP
+
+//this function creates a new <script src = "http://bugs.kde.org/jsonrpc.cgi?=
+function showBug(jsonCallUrl)
+{
+    var script = document.createElement('script');
+    script.src = jsonCallUrl
+    document.getElementsByTagName('head')[0].appendChild(script);
+}

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list