From e4aa76a07e1acb2803b40433932b6fe0c39610ba Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Thu, 15 Nov 2018 23:05:20 -0600 Subject: Get the rest of the stragglers --- libpurple/data/purple3-url-handler.desktop.in.in | 14 + libpurple/purple3-remote | 266 ++++++++++++++++ libpurple/purple3-send | 31 ++ libpurple/purple3-send-async | 29 ++ libpurple/purple3-url-handler | 373 +++++++++++++++++++++++ pidgin/data/im.pidgin.Pidgin.appdata.xml.in | 39 --- pidgin/data/im.pidgin.Pidgin.desktop.in.in | 12 - pidgin/data/im.pidgin.Pidgin3.appdata.xml.in | 39 +++ pidgin/data/im.pidgin.Pidgin3.desktop.in.in | 12 + pidgin/meson.build | 6 +- 10 files changed, 767 insertions(+), 54 deletions(-) create mode 100644 libpurple/data/purple3-url-handler.desktop.in.in create mode 100755 libpurple/purple3-remote create mode 100755 libpurple/purple3-send create mode 100755 libpurple/purple3-send-async create mode 100755 libpurple/purple3-url-handler delete mode 100644 pidgin/data/im.pidgin.Pidgin.appdata.xml.in delete mode 100644 pidgin/data/im.pidgin.Pidgin.desktop.in.in create mode 100644 pidgin/data/im.pidgin.Pidgin3.appdata.xml.in create mode 100644 pidgin/data/im.pidgin.Pidgin3.desktop.in.in diff --git a/libpurple/data/purple3-url-handler.desktop.in.in b/libpurple/data/purple3-url-handler.desktop.in.in new file mode 100644 index 0000000000..09513fa627 --- /dev/null +++ b/libpurple/data/purple3-url-handler.desktop.in.in @@ -0,0 +1,14 @@ +[Desktop Entry] +Name=Pidgin +GenericName=Internet Messenger +Comment=Chat over IM. Supports AIM, Google Talk, Jabber/XMPP, and more +Exec=purple3-url-handler %u +TryExec=purple3-url-handler +Icon=pidgin +StartupNotify=false +Terminal=false +NoDisplay=true +Type=Application +Categories=Network;InstantMessaging;RemoteAccess;ConsoleOnly; +MimeType=x-scheme-handler/aim;x-scheme-handler/gg;x-scheme-handler/icq;x-scheme-handler/irc;x-scheme-handler/msnim;x-scheme-handler/sip;x-scheme-handler/xmpp;x-scheme-handler/ymsgr +@USES_MM_CHAT_SECTION@ diff --git a/libpurple/purple3-remote b/libpurple/purple3-remote new file mode 100755 index 0000000000..1f392af129 --- /dev/null +++ b/libpurple/purple3-remote @@ -0,0 +1,266 @@ +#!/usr/bin/env python + +from __future__ import absolute_import, division, print_function + +import codecs +import re +import sys +try: + from urllib.parse import unquote +except ImportError: + from urllib import unquote +import xml.dom.minidom + +import dbus + + +sys.stdin = codecs.getwriter('utf-8')(sys.stdin) +sys.stdout = codecs.getwriter('utf-8')(sys.stdout) + +xml.dom.minidom.Element.all = xml.dom.minidom.Element.getElementsByTagName + +obj = None +try: + obj = dbus.SessionBus().get_object("im.pidgin.purple.PurpleService", + "/im/pidgin/purple/PurpleObject") +except: + pass + +purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") + + +class CheckedObject(object): + def __init__(self, obj): + self.obj = obj + + def __getattr__(self, attr): + return CheckedAttribute(self, attr) + + +class CheckedAttribute(object): + def __init__(self, cobj, attr): + self.cobj = cobj + self.attr = attr + + def __call__(self, *args): + result = self.cobj.obj.__getattr__(self.attr)(*args) + if result == 0: + raise Exception("Error: %s %s returned %s" % + (self.attr, args, result)) + return result + + +def show_help(requested=False): + print("""This program uses D-Bus to communicate with purple. + +Usage: + + %s "command1" "command2" ... + +Each command is of one of the three types: + + [protocol:]commandname?param1=value1¶m2=value2&... + FunctionName?param1=value1¶m2=value2&... + FunctionName(value1,value2,...) + +The second and third form are provided for completeness but their use +is not recommended; use purple-send or purple-send-async instead. The +second form uses introspection to find out the parameter names and +their types, therefore it is rather slow. + +Examples of commands: + + jabber:goim?screenname=testone@localhost&message=hi + jabber:gochat?room=TestRoom&server=conference.localhost + jabber:getinfo?screenname=testone@localhost + jabber:addbuddy?screenname=my friend + + setstatus?status=away&message=don't disturb + getstatus + getstatusmessage + quit + + PurpleAccountsFindConnected?name=&protocol=jabber + PurpleAccountsFindConnected(,jabber) +""" % (sys.argv[0], )) + if (requested): + sys.exit(0) + else: + sys.exit(1) + + +cpurple = CheckedObject(purple) + +urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?" + + +def extendlist(list, length, fill): + if len(list) < length: + return list + [fill] * (length - len(list)) + else: + return list + + +def convert(value): + try: + return int(value) + except: + return value + + +def findaccount(accountname, protocolname): + try: + # prefer connected accounts + account = cpurple.PurpleAccountsFindConnected(accountname, + protocolname) + return account + except: + # try to get any account and connect it + account = cpurple.PurpleAccountsFindAny(accountname, protocolname) + purple.PurpleAccountSetStatusVargs(account, "online", 1) + purple.PurpleAccountConnect(account) + return account + + +def execute(uri): + match = re.match(urlregexp, uri) + protocol = match.group(2) + if protocol == "xmpp": + protocol = "jabber" + if protocol is not None: + protocol = "prpl-" + protocol + command = match.group(5) + paramstring = match.group(7) + params = {} + if paramstring is not None: + for param in paramstring.split("&"): + key, value = extendlist(param.split("=", 1), 2, "") + params[key] = unquote(value) + + accountname = params.get("account", "") + + if command == "goim": + account = findaccount(accountname, protocol) + conversation = cpurple.PurpleConversationNew(1, account, + params["screenname"]) + if "message" in params: + im = cpurple.PurpleConversationGetImData(conversation) + purple.PurpleConvImSend(im, params["message"]) + return None + + elif command == "gochat": + account = findaccount(accountname, protocol) + connection = cpurple.PurpleAccountGetConnection(account) + return purple.PurpleServJoinChat(connection, params) + + elif command == "addbuddy": + account = findaccount(accountname, protocol) + return cpurple.PurpleBlistRequestAddBuddy(account, + params["screenname"], + params.get("group", ""), + "") + + elif command == "setstatus": + current = purple.PurpleSavedstatusGetCurrent() + + if "status" in params: + status_id = params["status"] + status_type = purple.PurplePrimitiveGetTypeFromId(status_id) + else: + status_type = purple.PurpleSavedstatusGetType(current) + status_id = purple.PurplePrimitiveGetIdFromType(status_type) + + if "message" in params: + message = params["message"] + else: + message = purple.PurpleSavedstatusGetMessage(current) + + if "account" in params: + accounts = [cpurple.PurpleAccountsFindAny(accountname, protocol)] + + for account in accounts: + status = purple.PurpleAccountGetStatus(account, status_id) + type = purple.PurpleStatusGetType(status) + purple.PurpleSavedstatusSetSubstatus(current, account, type, + message) + purple.PurpleSavedstatusActivateForAccount(current, account) + else: + saved = purple.PurpleSavedstatusNew("", status_type) + purple.PurpleSavedstatusSetMessage(saved, message) + purple.PurpleSavedstatusActivate(saved) + + return None + + elif command == "getstatus": + current = purple.PurpleSavedstatusGetCurrent() + status_type = purple.PurpleSavedstatusGetType(current) + status_id = purple.PurplePrimitiveGetIdFromType(status_type) + return status_id + + elif command == "getstatusmessage": + current = purple.PurpleSavedstatusGetCurrent() + return purple.PurpleSavedstatusGetMessage(current) + + elif command == "getinfo": + account = findaccount(accountname, protocol) + connection = cpurple.PurpleAccountGetConnection(account) + return purple.ServGetInfo(connection, params["screenname"]) + + elif command == "quit": + return purple.PurpleCoreQuit() + + elif command == "uri": + return None + + else: + match = re.match(r"(\w+)\s*\(([^)]*)\)", command) + if match is not None: + name = match.group(1) + argstr = match.group(2) + if argstr == "": + args = [] + else: + args = argstr.split(",") + fargs = [] + for arg in args: + fargs.append(convert(arg.strip())) + return purple.__getattr__(name)(*fargs) + else: + # Introspect the object to get parameter names and types. This is + # slow because the entire introspection info must be downloaded. + interface = dbus.Interface(obj, + "org.freedesktop.DBus.Introspectable") + data = interface.Introspect() + introspect = xml.dom.minidom.parseString(data).documentElement + for method in introspect.all("method"): + if command == method.getAttribute("name"): + methodparams = [] + for arg in method.all("arg"): + if arg.getAttribute("direction") == "in": + value = params[arg.getAttribute("name")] + type = arg.getAttribute("type") + if type == "s": + methodparams.append(value) + elif type == "i": + methodparams.append(int(value)) + else: + raise Exception( + "Don't know how to handle type \"%s\"" % ( + type, )) + return purple.__getattr__(command)(*methodparams) + show_help() + + +if len(sys.argv) == 1: + show_help() +elif sys.argv[1] == "--help" or sys.argv[1] == "-h": + show_help(True) +elif obj is None: + print("No existing libpurple instance detected.") + sys.exit(1) + +for arg in sys.argv[1:]: + output = execute(arg) + + if output is not None: + print(output) diff --git a/libpurple/purple3-send b/libpurple/purple3-send new file mode 100755 index 0000000000..8eec0b0516 --- /dev/null +++ b/libpurple/purple3-send @@ -0,0 +1,31 @@ +#!/bin/sh + +METHOD_NAME=$1 + +if test -z "$METHOD_NAME" +then + cat < - - - - - im.pidgin.Pidgin.desktop - CC0-1.0 - GPL-2.0 - -

- Pidgin is a chat program which lets you log in to accounts on multiple - chat networks simultaneously. -

-

- This means that you can be chatting with friends on AIM, talking to a - friend on Google Talk, and sitting in an IRC chat room all at the same - time. -

-
- - im.pidgin.Pidgin.desktop - - pidgin.desktop - - - - - https://www.pidgin.im/shared/img/contact_window.png - Buddy list showing friends on different networks - - - - https://pidgin.im/ - https://developer.pidgin.im/timeline - https://developer.pidgin.im/wiki/FAQ - https://developer.pidgin.im/wiki - - devel@pidgin.im -
diff --git a/pidgin/data/im.pidgin.Pidgin.desktop.in.in b/pidgin/data/im.pidgin.Pidgin.desktop.in.in deleted file mode 100644 index 7bc5ef7f00..0000000000 --- a/pidgin/data/im.pidgin.Pidgin.desktop.in.in +++ /dev/null @@ -1,12 +0,0 @@ -[Desktop Entry] -Name=Pidgin 3 -GenericName=Internet Messenger -Comment=Chat over IM. Supports AIM, Google Talk, Jabber/XMPP, and more -Exec=pidgin3 %U -Icon=pidgin -StartupNotify=true -Terminal=false -Type=Application -Categories=Network;InstantMessaging; -MimeType=x-scheme-handler/aim;x-scheme-handler/gg;x-scheme-handler/icq;x-scheme-handler/irc;x-scheme-handler/msnim;x-scheme-handler/sip;x-scheme-handler/xmpp;x-scheme-handler/ymsgr -@USES_MM_CHAT_SECTION@ diff --git a/pidgin/data/im.pidgin.Pidgin3.appdata.xml.in b/pidgin/data/im.pidgin.Pidgin3.appdata.xml.in new file mode 100644 index 0000000000..dcc77bc72f --- /dev/null +++ b/pidgin/data/im.pidgin.Pidgin3.appdata.xml.in @@ -0,0 +1,39 @@ + + + + + + im.pidgin.Pidgin.desktop + CC0-1.0 + GPL-2.0 + +

+ Pidgin is a chat program which lets you log in to accounts on multiple + chat networks simultaneously. +

+

+ This means that you can be chatting with friends on AIM, talking to a + friend on Google Talk, and sitting in an IRC chat room all at the same + time. +

+
+ + im.pidgin.Pidgin.desktop + + pidgin.desktop + + + + + https://www.pidgin.im/shared/img/contact_window.png + Buddy list showing friends on different networks + + + + https://pidgin.im/ + https://developer.pidgin.im/timeline + https://developer.pidgin.im/wiki/FAQ + https://developer.pidgin.im/wiki + + devel@pidgin.im +
diff --git a/pidgin/data/im.pidgin.Pidgin3.desktop.in.in b/pidgin/data/im.pidgin.Pidgin3.desktop.in.in new file mode 100644 index 0000000000..7bc5ef7f00 --- /dev/null +++ b/pidgin/data/im.pidgin.Pidgin3.desktop.in.in @@ -0,0 +1,12 @@ +[Desktop Entry] +Name=Pidgin 3 +GenericName=Internet Messenger +Comment=Chat over IM. Supports AIM, Google Talk, Jabber/XMPP, and more +Exec=pidgin3 %U +Icon=pidgin +StartupNotify=true +Terminal=false +Type=Application +Categories=Network;InstantMessaging; +MimeType=x-scheme-handler/aim;x-scheme-handler/gg;x-scheme-handler/icq;x-scheme-handler/irc;x-scheme-handler/msnim;x-scheme-handler/sip;x-scheme-handler/xmpp;x-scheme-handler/ymsgr +@USES_MM_CHAT_SECTION@ diff --git a/pidgin/meson.build b/pidgin/meson.build index cd98eee6d9..f228065cfc 100644 --- a/pidgin/meson.build +++ b/pidgin/meson.build @@ -199,7 +199,7 @@ if ENABLE_GTK variables : ['plugindir=${libdir}/pidgin']) if INSTALL_I18N - DESKTOP_FILE = 'im.pidgin.Pidgin.desktop' + DESKTOP_FILE = 'im.pidgin.Pidgin3.desktop' desktop_file_in = configure_file( input : 'data/' + DESKTOP_FILE + '.in.in', output : DESKTOP_FILE + '.in', @@ -213,8 +213,8 @@ if ENABLE_GTK install_dir : get_option('datadir') + '/applications') appdata = i18n.merge_file( - input : 'data/im.pidgin.Pidgin.appdata.xml.in', - output : 'im.pidgin.Pidgin.appdata.xml', + input : 'data/im.pidgin.Pidgin3.appdata.xml.in', + output : 'im.pidgin.Pidgin3.appdata.xml', po_dir : meson.source_root() + '/po', install : true, install_dir : get_option('datadir') + '/metainfo') -- cgit v1.2.1