[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:55 UTC 2016


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

The following commit has been merged in the master branch:
commit 8ccc35f38af1d910b8e04f5a820167d184724713
Author: Anant Kamath <kamathanant at gmail.com>
Date:   Thu May 2 16:13:50 2013 +0530

    Added plugin to expand URL Shortener urls
    REVIEW: 110255
---
 filters/CMakeLists.txt                             |  2 +-
 filters/urlexpansion/CMakeLists.txt                | 33 ++++++++
 ...extui_message_filter_urlexpansion.desktop.cmake | 15 ++++
 filters/urlexpansion/longurl.js                    | 35 ++++++++
 filters/urlexpansion/longurlServices.json          |  1 +
 filters/urlexpansion/urlexpansion-filter.cpp       | 94 ++++++++++++++++++++++
 .../urlexpansion-filter.h}                         | 17 ++--
 7 files changed, 188 insertions(+), 9 deletions(-)

diff --git a/filters/CMakeLists.txt b/filters/CMakeLists.txt
index c66e773..7a9528a 100644
--- a/filters/CMakeLists.txt
+++ b/filters/CMakeLists.txt
@@ -6,7 +6,7 @@ add_subdirectory(latex)
 add_subdirectory(searchexpansion)
 add_subdirectory(youtube)
 add_subdirectory(highlight)
-
+add_subdirectory(urlexpansion)
 
 IF (EXISTS "${KDE4_DBUS_INTERFACES_DIR}/org.kde.KSpeech.xml")
     set (HAS_KTTS TRUE)
diff --git a/filters/urlexpansion/CMakeLists.txt b/filters/urlexpansion/CMakeLists.txt
new file mode 100644
index 0000000..263f6b3
--- /dev/null
+++ b/filters/urlexpansion/CMakeLists.txt
@@ -0,0 +1,33 @@
+find_package(QJSON REQUIRED)
+
+set (ktptextui_message_filter_urlexpansion_SRCS
+     urlexpansion-filter.cpp
+)
+
+kde4_add_plugin (ktptextui_message_filter_urlexpansion
+                 ${ktptextui_message_filter_urlexpansion_SRCS}
+)
+
+target_link_libraries (ktptextui_message_filter_urlexpansion
+    ${QT_LIBRARIES}
+    ${KDE4_KIO_LIBS}
+    ${KTP_LIBRARIES}
+    ${TELEPATHY_QT4_LIBRARIES}
+    ${QJSON_LIBRARIES}
+)
+
+# Install:
+install (TARGETS ktptextui_message_filter_urlexpansion
+         DESTINATION ${PLUGIN_INSTALL_DIR}
+)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ktptextui_message_filter_urlexpansion.desktop.cmake
+               ${CMAKE_CURRENT_BINARY_DIR}/ktptextui_message_filter_urlexpansion.desktop
+               @ONLY)
+
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/ktptextui_message_filter_urlexpansion.desktop
+         DESTINATION ${SERVICES_INSTALL_DIR}
+)
+
+install (FILES longurl.js longurlServices.json
+         DESTINATION ${DATA_INSTALL_DIR}/ktelepathy)
diff --git a/filters/urlexpansion/ktptextui_message_filter_urlexpansion.desktop.cmake b/filters/urlexpansion/ktptextui_message_filter_urlexpansion.desktop.cmake
new file mode 100644
index 0000000..669692f
--- /dev/null
+++ b/filters/urlexpansion/ktptextui_message_filter_urlexpansion.desktop.cmake
@@ -0,0 +1,15 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=Short URLs
+Comment=Shows the actual URL to which a shortened URL is redirecting to
+Type=Service
+ServiceTypes=KTpTextUi/MessageFilter
+X-KDE-Library=ktptextui_message_filter_urlexpansion
+X-KDE-PluginInfo-Author=Anant Kamath
+X-KDE-PluginInfo-Email=kamathanant at gmail.org
+X-KDE-PluginInfo-Name=urlexpansion
+X-KDE-PluginInfo-Version=@KTP_TEXT_UI_VERSION@
+X-KDE-PluginInfo-Website=http://community.kde.org/KTp
+X-KDE-PluginInfo-License=LGPL
+X-KDE-PluginInfo-EnabledByDefault=true
+X-KTp-PluginInfo-Version=@KTP_MESSAGE_FILTER_FRAMEWORK_VERSION@
diff --git a/filters/urlexpansion/longurl.js b/filters/urlexpansion/longurl.js
new file mode 100644
index 0000000..622b803
--- /dev/null
+++ b/filters/urlexpansion/longurl.js
@@ -0,0 +1,35 @@
+var escapeHTML = (function() {
+    'use strict';
+    var codes = {
+        '&': '&',
+        '<': '<',
+        '>': '>',
+        '"': '"',
+        "'": '''
+    };
+    return function(string) {
+        return string.replace(/[&<>"']/g, function(char) {
+            return codes[char];
+        });
+    };
+}());
+
+var expandUrlCallbacks={};
+
+function expandUrlCallback(response,id)
+{
+    var text = response["long-url"];
+    document.getElementById(id).innerHTML += "<a href ='" + escapeHTML(text) +"'>"+ escapeHTML(text) +"</a><br />";
+}
+
+function showShortUrl(jsonCallUrl, id)
+{
+    expandUrlCallbacks[id] = function(response) { //create a new callback function
+        delete expandUrlCallbacks[id]
+        expandUrlCallback(response,id);
+        };
+
+    var script = document.createElement('script');
+    script.src = jsonCallUrl;
+    document.getElementsByTagName('head')[0].appendChild(script);
+}
diff --git a/filters/urlexpansion/longurlServices.json b/filters/urlexpansion/longurlServices.json
new file mode 100644
index 0000000..afd75b5
--- /dev/null
+++ b/filters/urlexpansion/longurlServices.json
@@ -0,0 +1 @@
+{"0rz.tw":{"domain":"0rz.tw","regex":""},"1link.in":{"domain":"1link.in","regex":""},"1url.com":{"domain":"1url.com","regex":""},"2.gp":{"domain":"2.gp","regex":""},"2big.at":{"domain":"2big.at","regex":""},"2tu.us":{"domain":"2tu.us","regex":""},"3.ly":{"domain":"3.ly","regex":""},"307.to":{"domain":"307.to","regex":""},"4ms.me":{"domain":"4ms.me","regex":""},"4sq.com":{"domain":"4sq.com","regex":""},"4url.cc":{"domain":"4url.cc","regex":""},"6url.com":{"domain":"6url.com","regex":""},"7.ly":{"domain":"7.ly","regex":""},"a.gg":{"domain":"a.gg","regex":""},"a.nf":{"domain":"a.nf","regex":""},"aa.cx":{"domain":"aa.cx","regex":""},"abcurl.net":{"domain":"abcurl.net","regex":""},"ad.vu":{"domain":"ad.vu","regex":""},"adf.ly":{"domain":"adf.ly","regex":""},"adjix.com":{"domain":"adjix.com","regex":""},"afx.cc":{"domain":"afx.cc","regex":""},"all.fuseurl.com":{"domain":"all.fuseurl.com","regex":""},"alturl.com":{"domain":"alturl.com","regex":""},"amzn.to":{"domain":"amzn.to","regex":""},"ar.gy":{"domain":"ar.gy","regex":""},"arst.ch":{"domain":"arst.ch","regex":""},"atu.ca":{"domain":"atu.ca","regex":""},"azc.cc":{"domain":"azc.cc","regex":""},"b23.ru":{"domain":"b23.ru","regex":""},"b2l.me":{"domain":"b2l.me","regex":""},"bacn.me":{"domain":"bacn.me","regex":""},"bcool.bz":{"domain":"bcool.bz","regex":""},"binged.it":{"domain":"binged.it","regex":""},"bit.ly":{"domain":"bit.ly","regex":""},"bizj.us":{"domain":"bizj.us","regex":""},"bloat.me":{"domain":"bloat.me","regex":""},"bravo.ly":{"domain":"bravo.ly","regex":""},"bsa.ly":{"domain":"bsa.ly","regex":""},"budurl.com":{"domain":"budurl.com","regex":""},"canurl.com":{"domain":"canurl.com","regex":""},"chilp.it":{"domain":"chilp.it","regex":""},"chzb.gr":{"domain":"chzb.gr","regex":""},"cl.lk":{"domain":"cl.lk","regex":""},"cl.ly":{"domain":"cl.ly","regex":""},"clck.ru":{"domain":"clck.ru","regex":""},"cli.gs":{"domain":"cli.gs","regex":""},"cliccami.info":{"domain":"cliccami.info","regex":""},"clickthru.ca":{"domain":"clickthru.ca","regex":""},"clop.in":{"domain":"clop.in","regex":""},"conta.cc":{"domain":"conta.cc","regex":""},"cort.as":{"domain":"cort.as","regex":""},"cot.ag":{"domain":"cot.ag","regex":""},"crks.me":{"domain":"crks.me","regex":""},"ctvr.us":{"domain":"ctvr.us","regex":""},"cutt.us":{"domain":"cutt.us","regex":""},"dai.ly":{"domain":"dai.ly","regex":""},"decenturl.com":{"domain":"decenturl.com","regex":""},"dfl8.me":{"domain":"dfl8.me","regex":""},"digbig.com":{"domain":"digbig.com","regex":""},"digg.com":{"domain":"digg.com","regex":"http:\\/\\/digg\.com\\/[^\\/]+$"},"disq.us":{"domain":"disq.us","regex":""},"dld.bz":{"domain":"dld.bz","regex":""},"dlvr.it":{"domain":"dlvr.it","regex":""},"do.my":{"domain":"do.my","regex":""},"doiop.com":{"domain":"doiop.com","regex":""},"dopen.us":{"domain":"dopen.us","regex":""},"easyuri.com":{"domain":"easyuri.com","regex":""},"easyurl.net":{"domain":"easyurl.net","regex":""},"eepurl.com":{"domain":"eepurl.com","regex":""},"eweri.com":{"domain":"eweri.com","regex":""},"fa.by":{"domain":"fa.by","regex":""},"fav.me":{"domain":"fav.me","regex":""},"fb.me":{"domain":"fb.me","regex":""},"fbshare.me":{"domain":"fbshare.me","regex":""},"ff.im":{"domain":"ff.im","regex":""},"fff.to":{"domain":"fff.to","regex":""},"fire.to":{"domain":"fire.to","regex":""},"firsturl.de":{"domain":"firsturl.de","regex":""},"firsturl.net":{"domain":"firsturl.net","regex":""},"flic.kr":{"domain":"flic.kr","regex":""},"flq.us":{"domain":"flq.us","regex":""},"fly2.ws":{"domain":"fly2.ws","regex":""},"fon.gs":{"domain":"fon.gs","regex":""},"freak.to":{"domain":"freak.to","regex":""},"fuseurl.com":{"domain":"fuseurl.com","regex":""},"fuzzy.to":{"domain":"fuzzy.to","regex":""},"fwd4.me":{"domain":"fwd4.me","regex":""},"fwib.net":{"domain":"fwib.net","regex":""},"g.ro.lt":{"domain":"g.ro.lt","regex":""},"gizmo.do":{"domain":"gizmo.do","regex":""},"gl.am":{"domain":"gl.am","regex":""},"go.9nl.com":{"domain":"go.9nl.com","regex":""},"go.ign.com":{"domain":"go.ign.com","regex":""},"go.usa.gov":{"domain":"go.usa.gov","regex":""},"goo.gl":{"domain":"goo.gl","regex":""},"goshrink.com":{"domain":"goshrink.com","regex":""},"gurl.es":{"domain":"gurl.es","regex":""},"hex.io":{"domain":"hex.io","regex":""},"hiderefer.com":{"domain":"hiderefer.com","regex":""},"hmm.ph":{"domain":"hmm.ph","regex":""},"href.in":{"domain":"href.in","regex":""},"hsblinks.com":{"domain":"hsblinks.com","regex":""},"htxt.it":{"domain":"htxt.it","regex":""},"huff.to":{"domain":"huff.to","regex":""},"hulu.com":{"domain":"hulu.com","regex":""},"hurl.me":{"domain":"hurl.me","regex":""},"hurl.ws":{"domain":"hurl.ws","regex":""},"icanhaz.com":{"domain":"icanhaz.com","regex":""},"idek.net":{"domain":"idek.net","regex":""},"ilix.in":{"domain":"ilix.in","regex":""},"is.gd":{"domain":"is.gd","regex":""},"its.my":{"domain":"its.my","regex":""},"ix.lt":{"domain":"ix.lt","regex":""},"j.mp":{"domain":"j.mp","regex":""},"jijr.com":{"domain":"jijr.com","regex":""},"kl.am":{"domain":"kl.am","regex":""},"klck.me":{"domain":"klck.me","regex":""},"korta.nu":{"domain":"korta.nu","regex":""},"krunchd.com":{"domain":"krunchd.com","regex":""},"l9k.net":{"domain":"l9k.net","regex":""},"lat.ms":{"domain":"lat.ms","regex":""},"liip.to":{"domain":"liip.to","regex":""},"liltext.com":{"domain":"liltext.com","regex":""},"linkbee.com":{"domain":"linkbee.com","regex":""},"linkbun.ch":{"domain":"linkbun.ch","regex":""},"liurl.cn":{"domain":"liurl.cn","regex":""},"ln-s.net":{"domain":"ln-s.net","regex":""},"ln-s.ru":{"domain":"ln-s.ru","regex":""},"lnk.gd":{"domain":"lnk.gd","regex":""},"lnk.ms":{"domain":"lnk.ms","regex":""},"lnkd.in":{"domain":"lnkd.in","regex":""},"lnkurl.com":{"domain":"lnkurl.com","regex":""},"lru.jp":{"domain":"lru.jp","regex":""},"lt.tl":{"domain":"lt.tl","regex":""},"lurl.no":{"domain":"lurl.no","regex":""},"macte.ch":{"domain":"macte.ch","regex":""},"mash.to":{"domain":"mash.to","regex":""},"merky.de":{"domain":"merky.de","regex":""},"migre.me":{"domain":"migre.me","regex":""},"miniurl.com":{"domain":"miniurl.com","regex":""},"minurl.fr":{"domain":"minurl.fr","regex":""},"mke.me":{"domain":"mke.me","regex":""},"moby.to":{"domain":"moby.to","regex":""},"moourl.com":{"domain":"moourl.com","regex":""},"mrte.ch":{"domain":"mrte.ch","regex":""},"myloc.me":{"domain":"myloc.me","regex":""},"myurl.in":{"domain":"myurl.in","regex":""},"n.pr":{"domain":"n.pr","regex":""},"nbc.co":{"domain":"nbc.co","regex":""},"nblo.gs":{"domain":"nblo.gs","regex":""},"nn.nf":{"domain":"nn.nf","regex":""},"not.my":{"domain":"not.my","regex":""},"notlong.com":{"domain":"notlong.com","regex":""},"nsfw.in":{"domain":"nsfw.in","regex":""},"nutshellurl.com":{"domain":"nutshellurl.com","regex":""},"nxy.in":{"domain":"nxy.in","regex":""},"nyti.ms":{"domain":"nyti.ms","regex":""},"o-x.fr":{"domain":"o-x.fr","regex":""},"oc1.us":{"domain":"oc1.us","regex":""},"om.ly":{"domain":"om.ly","regex":""},"omf.gd":{"domain":"omf.gd","regex":""},"omoikane.net":{"domain":"omoikane.net","regex":""},"on.cnn.com":{"domain":"on.cnn.com","regex":""},"on.mktw.net":{"domain":"on.mktw.net","regex":""},"onforb.es":{"domain":"onforb.es","regex":""},"orz.se":{"domain":"orz.se","regex":""},"ow.ly":{"domain":"ow.ly","regex":""},"ping.fm":{"domain":"ping.fm","regex":""},"pli.gs":{"domain":"pli.gs","regex":""},"pnt.me":{"domain":"pnt.me","regex":""},"politi.co":{"domain":"politi.co","regex":""},"post.ly":{"domain":"post.ly","regex":""},"pp.gg":{"domain":"pp.gg","regex":""},"profile.to":{"domain":"profile.to","regex":""},"ptiturl.com":{"domain":"ptiturl.com","regex":""},"pub.vitrue.com":{"domain":"pub.vitrue.com","regex":""},"qlnk.net":{"domain":"qlnk.net","regex":""},"qte.me":{"domain":"qte.me","regex":""},"qu.tc":{"domain":"qu.tc","regex":""},"qy.fi":{"domain":"qy.fi","regex":""},"r.im":{"domain":"r.im","regex":""},"rb6.me":{"domain":"rb6.me","regex":""},"read.bi":{"domain":"read.bi","regex":""},"readthis.ca":{"domain":"readthis.ca","regex":""},"reallytinyurl.com":{"domain":"reallytinyurl.com","regex":""},"redir.ec":{"domain":"redir.ec","regex":""},"redirects.ca":{"domain":"redirects.ca","regex":""},"redirx.com":{"domain":"redirx.com","regex":""},"retwt.me":{"domain":"retwt.me","regex":""},"ri.ms":{"domain":"ri.ms","regex":""},"rickroll.it":{"domain":"rickroll.it","regex":""},"riz.gd":{"domain":"riz.gd","regex":""},"rt.nu":{"domain":"rt.nu","regex":""},"ru.ly":{"domain":"ru.ly","regex":""},"rubyurl.com":{"domain":"rubyurl.com","regex":""},"rurl.org":{"domain":"rurl.org","regex":""},"rww.tw":{"domain":"rww.tw","regex":""},"s4c.in":{"domain":"s4c.in","regex":""},"s7y.us":{"domain":"s7y.us","regex":""},"safe.mn":{"domain":"safe.mn","regex":""},"sameurl.com":{"domain":"sameurl.com","regex":""},"sdut.us":{"domain":"sdut.us","regex":""},"shar.es":{"domain":"shar.es","regex":""},"shink.de":{"domain":"shink.de","regex":""},"shorl.com":{"domain":"shorl.com","regex":""},"short.ie":{"domain":"short.ie","regex":""},"short.to":{"domain":"short.to","regex":""},"shortlinks.co.uk":{"domain":"shortlinks.co.uk","regex":""},"shorturl.com":{"domain":"shorturl.com","regex":""},"shout.to":{"domain":"shout.to","regex":""},"show.my":{"domain":"show.my","regex":""},"shrinkify.com":{"domain":"shrinkify.com","regex":""},"shrinkr.com":{"domain":"shrinkr.com","regex":""},"shrt.fr":{"domain":"shrt.fr","regex":""},"shrt.st":{"domain":"shrt.st","regex":""},"shrten.com":{"domain":"shrten.com","regex":""},"shrunkin.com":{"domain":"shrunkin.com","regex":""},"simurl.com":{"domain":"simurl.com","regex":""},"slate.me":{"domain":"slate.me","regex":""},"smallr.com":{"domain":"smallr.com","regex":""},"smsh.me":{"domain":"smsh.me","regex":""},"smurl.name":{"domain":"smurl.name","regex":""},"sn.im":{"domain":"sn.im","regex":""},"snipr.com":{"domain":"snipr.com","regex":""},"snipurl.com":{"domain":"snipurl.com","regex":""},"snurl.com":{"domain":"snurl.com","regex":""},"sp2.ro":{"domain":"sp2.ro","regex":""},"spedr.com":{"domain":"spedr.com","regex":""},"srnk.net":{"domain":"srnk.net","regex":""},"srs.li":{"domain":"srs.li","regex":""},"starturl.com":{"domain":"starturl.com","regex":""},"su.pr":{"domain":"su.pr","regex":""},"surl.co.uk":{"domain":"surl.co.uk","regex":""},"surl.hu":{"domain":"surl.hu","regex":""},"t.cn":{"domain":"t.cn","regex":""},"t.co":{"domain":"t.co","regex":""},"t.lh.com":{"domain":"t.lh.com","regex":""},"ta.gd":{"domain":"ta.gd","regex":""},"tbd.ly":{"domain":"tbd.ly","regex":""},"tcrn.ch":{"domain":"tcrn.ch","regex":""},"tgr.me":{"domain":"tgr.me","regex":""},"tgr.ph":{"domain":"tgr.ph","regex":""},"tighturl.com":{"domain":"tighturl.com","regex":""},"tiniuri.com":{"domain":"tiniuri.com","regex":""},"tiny.cc":{"domain":"tiny.cc","regex":""},"tiny.ly":{"domain":"tiny.ly","regex":""},"tiny.pl":{"domain":"tiny.pl","regex":""},"tinylink.in":{"domain":"tinylink.in","regex":""},"tinyuri.ca":{"domain":"tinyuri.ca","regex":""},"tinyurl.com":{"domain":"tinyurl.com","regex":""},"tk.":{"domain":"tk.","regex":""},"tl.gd":{"domain":"tl.gd","regex":""},"tmi.me":{"domain":"tmi.me","regex":""},"tnij.org":{"domain":"tnij.org","regex":""},"tnw.to":{"domain":"tnw.to","regex":""},"tny.com":{"domain":"tny.com","regex":""},"to.":{"domain":"to.","regex":""},"to.ly":{"domain":"to.ly","regex":""},"togoto.us":{"domain":"togoto.us","regex":""},"totc.us":{"domain":"totc.us","regex":""},"toysr.us":{"domain":"toysr.us","regex":""},"tpm.ly":{"domain":"tpm.ly","regex":""},"tr.im":{"domain":"tr.im","regex":""},"tra.kz":{"domain":"tra.kz","regex":""},"trunc.it":{"domain":"trunc.it","regex":""},"twhub.com":{"domain":"twhub.com","regex":""},"twirl.at":{"domain":"twirl.at","regex":""},"twitclicks.com":{"domain":"twitclicks.com","regex":""},"twitterurl.net":{"domain":"twitterurl.net","regex":""},"twitterurl.org":{"domain":"twitterurl.org","regex":""},"twiturl.de":{"domain":"twiturl.de","regex":""},"twurl.cc":{"domain":"twurl.cc","regex":""},"twurl.nl":{"domain":"twurl.nl","regex":""},"u.mavrev.com":{"domain":"u.mavrev.com","regex":""},"u.nu":{"domain":"u.nu","regex":""},"u76.org":{"domain":"u76.org","regex":""},"ub0.cc":{"domain":"ub0.cc","regex":""},"ulu.lu":{"domain":"ulu.lu","regex":""},"updating.me":{"domain":"updating.me","regex":""},"ur1.ca":{"domain":"ur1.ca","regex":""},"url.az":{"domain":"url.az","regex":""},"url.co.uk":{"domain":"url.co.uk","regex":""},"url.ie":{"domain":"url.ie","regex":""},"url360.me":{"domain":"url360.me","regex":""},"url4.eu":{"domain":"url4.eu","regex":""},"urlborg.com":{"domain":"urlborg.com","regex":""},"urlbrief.com":{"domain":"urlbrief.com","regex":""},"urlcover.com":{"domain":"urlcover.com","regex":""},"urlcut.com":{"domain":"urlcut.com","regex":""},"urlenco.de":{"domain":"urlenco.de","regex":""},"urli.nl":{"domain":"urli.nl","regex":""},"urls.im":{"domain":"urls.im","regex":""},"urlshorteningservicefortwitter.com":{"domain":"urlshorteningservicefortwitter.com","regex":""},"urlx.ie":{"domain":"urlx.ie","regex":""},"urlzen.com":{"domain":"urlzen.com","regex":""},"usat.ly":{"domain":"usat.ly","regex":""},"use.my":{"domain":"use.my","regex":""},"vb.ly":{"domain":"vb.ly","regex":""},"vgn.am":{"domain":"vgn.am","regex":""},"vl.am":{"domain":"vl.am","regex":""},"vm.lc":{"domain":"vm.lc","regex":""},"w55.de":{"domain":"w55.de","regex":""},"wapo.st":{"domain":"wapo.st","regex":""},"wapurl.co.uk":{"domain":"wapurl.co.uk","regex":""},"wipi.es":{"domain":"wipi.es","regex":""},"wp.me":{"domain":"wp.me","regex":""},"x.vu":{"domain":"x.vu","regex":""},"xr.com":{"domain":"xr.com","regex":""},"xrl.in":{"domain":"xrl.in","regex":""},"xrl.us":{"domain":"xrl.us","regex":""},"xurl.es":{"domain":"xurl.es","regex":""},"xurl.jp":{"domain":"xurl.jp","regex":""},"y.ahoo.it":{"domain":"y.ahoo.it","regex":""},"yatuc.com":{"domain":"yatuc.com","regex":""},"ye.pe":{"domain":"ye.pe","regex":""},"yep.it":{"domain":"yep.it","regex":""},"yfrog.com":{"domain":"yfrog.com","regex":""},"yhoo.it":{"domain":"yhoo.it","regex":""},"yiyd.com":{"domain":"yiyd.com","regex":""},"youtu.be":{"domain":"youtu.be","regex":""},"yuarel.com":{"domain":"yuarel.com","regex":""},"z0p.de":{"domain":"z0p.de","regex":""},"zi.ma":{"domain":"zi.ma","regex":""},"zi.mu":{"domain":"zi.mu","regex":""},"zipmyurl.com":{"domain":"zipmyurl.com","regex":""},"zud.me":{"domain":"zud.me","regex":""},"zurl.ws":{"domain":"zurl.ws","regex":""},"zz.gd":{"domain":"zz.gd","regex":""},"zzang.kr":{"domain":"zzang.kr","regex":""},"\u203a.ws":{"domain":"\u203a.ws","regex":""},"\u2729.ws":{"domain":"\u2729.ws","regex":""},"\u273f.ws":{"domain":"\u273f.ws","regex":""},"\u2765.ws":{"domain":"\u2765.ws","regex":""},"\u2794.ws":{"domain":"\u2794.ws","regex":""},"\u279e.ws":{"domain":"\u279e.ws","regex":""},"\u27a1.ws":{"domain":"\u27a1.ws","regex":""},"\u27a8.ws":{"domain":"\u27a8.ws","regex":""},"\u27af.ws":{"domain":"\u27af.ws","regex":""},"\u27b9.ws":{"domain":"\u27b9.ws","regex":""},"\u27bd.ws":{"domain":"\u27bd.ws","regex":""}}
\ No newline at end of file
diff --git a/filters/urlexpansion/urlexpansion-filter.cpp b/filters/urlexpansion/urlexpansion-filter.cpp
new file mode 100644
index 0000000..b39dd5e
--- /dev/null
+++ b/filters/urlexpansion/urlexpansion-filter.cpp
@@ -0,0 +1,94 @@
+/*
+ *    Copyright (C) 2013  Anant Kamath <kamathanant at gmail.com>
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License as published by the Free Software Foundation; either
+ *    version 2.1 of the License, or (at your option) any later version.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#include "urlexpansion-filter.h"
+
+#include<QFile>
+
+#include <KPluginFactory>
+#include <KDE/KStandardDirs>
+
+#include <qjson/parser.h>
+
+class UrlExpansionFilter::Private
+{
+public:
+    Private() {
+        requestCounter = 0;
+    }
+    int requestCounter;
+    QStringList supportedServices;
+};
+
+UrlExpansionFilter::UrlExpansionFilter(QObject *parent, const QVariantList &) :
+    AbstractMessageFilter(parent), d(new Private)
+{
+    getSupportedServices();
+}
+
+UrlExpansionFilter::~UrlExpansionFilter()
+{
+    delete d;
+}
+
+void UrlExpansionFilter::getSupportedServices()
+{
+    QFile servicesFile(KGlobal::dirs()->findResource("data", QLatin1String("ktelepathy/longurlServices.json")));
+    servicesFile.open(QIODevice::ReadOnly);
+    QVariantMap response = QJson::Parser().parse(&servicesFile).toMap();
+    d->supportedServices = response.uniqueKeys();
+}
+
+void UrlExpansionFilter::addExpandedUrl(KTp::Message &message, const KUrl &url)
+{
+    d->requestCounter++;
+    QString urlId = QString((QLatin1String("url") + QString::number(d->requestCounter)));
+    QString callbackFunction = QString((QLatin1String("expandUrlCallbacks.") + urlId));
+    KUrl request = KUrl(QLatin1String("http://api.longurl.org/v2/expand"));
+    request.addQueryItem(QLatin1String("url"), url.url());
+    request.addQueryItem(QLatin1String("format"), QLatin1String("json"));
+    request.addQueryItem(QLatin1String("callback"), callbackFunction);
+    request.addQueryItem(QLatin1String("user-agent"), QLatin1String("KTp"));
+
+    message.appendMessagePart(QString::fromLatin1("<p id = \"%1\">Redirects to </p>").arg(urlId));
+    message.appendScript(QString::fromLatin1("showShortUrl(\"%1\",\"%2\");").arg(request.prettyUrl(),urlId));
+}
+
+void UrlExpansionFilter::filterMessage(KTp::Message &message, const KTp::MessageContext &context)
+{
+    //if we're hidden we don't want to make network requests that can show we're online
+    if (context.account()->currentPresence().type() == Tp::ConnectionPresenceTypeHidden) {
+        return;
+    }
+
+    Q_FOREACH (const QVariant &var, message.property("Urls").toList()) {
+        KUrl url = qvariant_cast<KUrl>(var);
+
+        if (!url.path().isEmpty() && QString::compare(url.path(),QLatin1String("/")) && d->supportedServices.contains(url.host())) {
+            addExpandedUrl(message, url);
+        }
+    }
+}
+
+QStringList UrlExpansionFilter::requiredScripts()
+{
+    return QStringList() << QLatin1String("ktelepathy/longurl.js");
+}
+
+K_PLUGIN_FACTORY(MessageFilterFactory, registerPlugin<UrlExpansionFilter>();)
+K_EXPORT_PLUGIN(MessageFilterFactory("ktptextui_message_filter_urlexpansion"))
diff --git a/filters/bugzilla/bugzilla-filter.h b/filters/urlexpansion/urlexpansion-filter.h
similarity index 71%
copy from filters/bugzilla/bugzilla-filter.h
copy to filters/urlexpansion/urlexpansion-filter.h
index e3271b3..2c57ea9 100644
--- a/filters/bugzilla/bugzilla-filter.h
+++ b/filters/urlexpansion/urlexpansion-filter.h
@@ -1,5 +1,5 @@
 /*
- *    Copyright (C) 2012  Lasath Fernando <kde at lasath.org>
+ *    Copyright (C) 2013  Anant Kamath <kamathanant at gmail.com>
  *
  *    This library is free software; you can redistribute it and/or
  *    modify it under the terms of the GNU Lesser General Public
@@ -16,28 +16,29 @@
  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */
 
-#ifndef BUGZILLA_FILTER_H
-#define BUGZILLA_FILTER_H
+#ifndef URLEXPANSION_FILTER_H
+#define URLEXPANSION_FILTER_H
 
 #include <KTp/abstract-message-filter.h>
 
 #include <KUrl>
 
-class BugzillaFilter : public KTp::AbstractMessageFilter
+class UrlExpansionFilter : public KTp::AbstractMessageFilter
 {
     Q_OBJECT
 
 public:
-    BugzillaFilter(QObject *parent, const QVariantList &);
-    virtual ~BugzillaFilter();
+    UrlExpansionFilter(QObject *parent, const QVariantList &);
+    virtual ~UrlExpansionFilter();
 
     virtual void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
     virtual QStringList requiredScripts();
 private:
-    void addBugDescription(KTp::Message &message, const KUrl &baseUrl);
+    void addExpandedUrl(KTp::Message &message, const KUrl &baseUrl);
+    void getSupportedServices();
 
     class Private;
     Private *d;
 };
 
-#endif // BUGZILLA_FILTER_H
+#endif // URLEXPANSION_FILTER_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list