changeset 17394:38c26b0bbb6e

merge of '27508136086ee6dc49a8fe0cb403e09f119ed485' and '9b63c58b247a65c39493cf29e45d001c9bb6de32'
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 25 May 2007 01:19:12 +0000
parents 99a2add7c4f2 (diff) 29e68dd7b9cc (current diff)
children 995f31f5432a
files
diffstat 2 files changed, 165 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/purple-url-handler	Fri May 25 01:17:33 2007 +0000
+++ b/libpurple/purple-url-handler	Fri May 25 01:19:12 2007 +0000
@@ -38,6 +38,150 @@
 
 cpurple = CheckedObject(purple)
 
+def extendlist(list, length, fill):
+    if len(list) < length:
+        return list + [fill] * (length - len(list))
+    else:
+        return list
+
+def findaccount(protocolname, accountname=""):
+    # prefer connected accounts
+    account = cpurple.PurpleAccountsFindConnected(accountname, protocolname)
+    if (account != 0):
+	return account
+
+    # try to get any account and connect it
+    account = cpurple.PurpleAccountsFindAny(accountname, protocolname)
+    if (account == 0):
+        print "No matching account found."
+	sys.exit(1)
+
+    purple.PurpleAccountSetStatusVargs(account, "online", 1)
+    purple.PurpleAccountConnect(account)
+    return account
+
+def goim(account, screenname, message=None):
+    # XXX: 1 == PURPLE_CONV_TYPE_IM
+    conversation = cpurple.PurpleConversationNew(1, account, screenname)
+    if message:
+        purple.PurpleConvSendConfirm(conversation, message)
+
+def gochat(account, params, message=None):
+    connection = cpurple.PurpleAccountGetConnection(account)
+    purple.ServJoinChat(connection, params)
+
+    if message != None:
+    	for i in range(20):
+            # XXX: 2 == PURPLE_CONV_TYPE_CHAT
+            conversation = purple.PurpleFindConversationWithAccount(2, params.get("channel", params.get("room")), account)
+            if conversation:
+                purple.PurpleConvSendConfirm(conversation, message)
+                break
+            else:
+                time.sleep(0.5)
+
+def addbuddy(account, screenname, group="", alias=""):
+    cpurple.PurpleBlistRequestAddBuddy(account, screenname, group, alias)
+
+
+def gg(uri):
+    protocol = "prpl-gg"
+    match = re.match(r"^gg:(.*)", uri)
+    if not match:
+        print "Invalid gg URI: %s" % uri
+        return
+
+    screenname = urllib.unquote_plus(match.group(1))
+    account = findaccount(protocol)
+    goim(account, screenname)
+
+def irc(uri):
+    protocol = "prpl-irc"
+    match = re.match(r"^irc:(//([^/]*)/)?([^?]*)(\?(.*))?", uri)
+    if not match:
+        print "Invalid irc URI: %s" % uri
+        return
+
+    server = urllib.unquote_plus(match.group(2)) or ""
+    target = match.group(3) or ""
+    query = match.group(5) or ""
+
+    modifiers = {}
+    if target:
+        for modifier in target.split(",")[1:]:
+            modifiers[modifier] = True
+
+    isnick = modifiers.has_key("isnick")
+
+    paramstring = match.group(5)
+    params = {}
+    if paramstring:
+        for param in paramstring.split("&"):
+            key, value = extendlist(param.split("=", 1), 2, "")
+            params[key] = urllib.unquote_plus(value)
+
+    account = findaccount(protocol)
+
+    if (target != ""):
+        if (isnick):
+            goim(account, urllib.unquote_plus(target.split(",")[0]), params.get("msg"))
+	else:
+            channel = urllib.unquote_plus(target.split(",")[0])
+            if channel[0] != "#":
+                channel = "#" + channel
+            gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg"))
+
+def sip(uri):
+    protocol = "prpl-simple"
+    match = re.match(r"^sip:(.*)", uri)
+    if not match:
+        print "Invalid sip URI: %s" % uri
+        return
+
+    screenname = urllib.unquote_plus(match.group(1))
+    account = findaccount(protocol)
+    goim(account, screenname)
+
+def xmpp(uri):
+    protocol = "prpl-jabber"
+    match = re.match(r"^xmpp:(//([^/?#]*)/?)?([^?#]*)(\?([^;#]*)(;([^#]*))?)?(#(.*))?", uri)
+    if not match:
+        print "Invalid xmpp URI: %s" % uri
+        return
+
+    tmp = match.group(2)
+    if (tmp):
+        accountname = urllib.unquote_plus(tmp)
+    else:
+        accountname = ""
+
+    screenname = urllib.unquote_plus(match.group(3))
+
+    tmp = match.group(5)
+    if (tmp):
+        command = urllib.unquote_plus(tmp)
+    else:
+        command = ""
+
+    paramstring = match.group(7)
+    params = {}
+    if paramstring:
+        for param in paramstring.split(";"):
+            key, value = extendlist(param.split("=", 1), 2, "")
+            params[key] = urllib.unquote_plus(value)
+
+    account = findaccount(protocol, accountname)
+
+    if command.lower() == "message":
+        goim(account, screenname, params.get("body"))
+    elif command.lower() == "join":
+        room, server = screenname.split("@")
+        gochat(account, {"room": room, "server": server})
+    elif command.lower() == "roster":
+        addbuddy(account, screenname, params.get("group", ""), params.get("name", ""))
+    else:
+        goim(account, screenname)
+
 def main(argv=sys.argv):
     if len(argv) != 2:
         print "Usage: %s URI" % argv[0]
@@ -45,10 +189,19 @@
         return
 
     uri = argv[1]
+    type = uri.split(":")[0]
 
-    print uri
     try:
-        cpurple.PurpleGotProtocolHandlerUri(uri)
+        if type == "gg":
+            gg(uri)
+        elif type == "irc":
+            irc(uri)
+        elif type == "sip":
+            sip(uri)
+        elif type == "xmpp":
+            xmpp(uri)
+        else:
+            cpurple.PurpleGotProtocolHandlerUri(uri)
     except dbus.dbus_bindings.DBusException:
         print "ERROR: Is there a libpurple-powered client (e.g. Pidgin or Finch) running?"
 
--- a/pidgin.spec.in	Fri May 25 01:17:33 2007 +0000
+++ b/pidgin.spec.in	Fri May 25 01:19:12 2007 +0000
@@ -29,7 +29,6 @@
 BuildRequires: gtk2-devel
 
 %{!?_without_startupnotification:BuildRequires: startup-notification-devel}
-%{!?_without_modularx:BuildRequires: libSM-devel, libXScrnSaver-devel}
 %{?_with_avahi:BuildRequires: avahi-compat-howl-devel}
 %{!?_without_gtkspell:BuildRequires: gtkspell-devel}
 %{?_with_howl:BuildRequires: howl-devel}
@@ -55,7 +54,10 @@
 # For Mandrake/Mandriva:
 BuildRequires: libnss3-devel, perl-devel
 Obsoletes:  libgaim-remote0
+%{!?_without_modularx:BuildRequires: libsm-devel, libxscrnsaver-devel}
 %else
+# For !Mandriva
+%{!?_without_modularx:BuildRequires: libSM-devel, libXScrnSaver-devel}
 # For SuSE, Red Hat, Fedora and others:
 %if "%{_vendor}" != "suse"
 # For Red Hat, Fedora and others:
@@ -312,7 +314,7 @@
     killall -HUP gconfd-2 &> /dev/null || :
 fi
 touch --no-create %{_datadir}/icons/hicolor || :
-%{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
+%{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor &> /dev/null || :
 
 %post -n libpurple -p /sbin/ldconfig
 
@@ -328,7 +330,7 @@
 
 %postun
 touch --no-create %{_datadir}/icons/hicolor || :
-%{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
+%{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor &> /dev/null || :
 
 %postun -n libpurple -p /sbin/ldconfig
 
@@ -447,6 +449,11 @@
 %endif
 
 %changelog
+* Thu May 24 2007 Stu Tomlinson <stu@nosnilmot.com>
+- Silence errors from gtk-update-icon-cache
+- Change Mandriva build dependencies to reflect the correct (lower case)
+  names for libSM-devel & libXScrnSaver-devel (Sunny Dubey)
+
 * Thu May 10 2007 Stu Tomlinson <stu@nosnilmot.com>
 - Add scriptlet Requires for GConf2 to fix schema installation
 - Silence harmless errors when gconfd-2 is not running at install time