View Single Post
b666m's Avatar
Posts: 1,090 | Thanked: 476 times | Joined on Jan 2010 @ Ingolstadt, Germany
#57
Originally Posted by qwerty12 View Post
Here's the major difference: The function takes a struct; the method call takes an PurpleAccount in the form of an int32, which is what the RecievedImMsg signal gives you.
omg ^^

mhm... if you want to you can take the C-code and improve it *laugh*

i have already rewritten the code with the use of python and it's much easier, cleaner and smaller

here's what i've got so far:
Code:
#!/usr/bin/env python

#def cb (Notification=None, action=None, Data=None):
	#pass

def my_func(account, sender, message, conversation, flags):
	
	buddy = bus.pidginbus.PurpleFindBuddy(account,str(sender.split("@")[0]))
	name = bus.pidginbus.PurpleBuddyGetAlias(buddy)
	icon = bus.pidginbus.PurpleBuddyGetIcon(buddy)
	icon_path = bus.pidginbus.PurpleBuddyIconGetFullPath(icon)

	print name, "("+sender+") said \""+message+"\" with icon at", icon_path

        # it's only commented out for test-reasons because i only try it on ubuntu and console with print
        # pynotify.init(os.path.splitext(os.path.basename(sys.argv[0]))[0])
	# n = pynotify.Notification(name, "\""+message+"\"", icon_path)
        # -------------------------
        # maybe the next two lines can be used for bringing the conversation window to the foreground 
        # when the notification is being clicked by the user
        # if that is not possible: comment them out or delete them (no use for them)
	# n.set_hint_string("dbus-callback-default", "com.nokia.osso_browser /com/nokia/osso_browser com.nokia.osso_browser open_new_window string:\"callto://666\"")
	#n.add_action("default", "call", cb)
        # or do i have to make an "add_action" for the notification?
        # maybe i can just put three NULL arguments there ^^
        # ------------------------
	#n.show()

import os
import sys
import gobject, dbus
import pynotify

from dbus.mainloop.glib import DBusGMainLoop

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
bus.pidginbus = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

bus.add_signal_receiver(my_func,
                        dbus_interface="im.pidgin.purple.PurpleInterface",
                        signal_name="ReceivedImMsg")

loop = gobject.MainLoop()
loop.run()
for example save it as "pidginnotifyd.py".
then you can run it via "python pidginnotifyd.py" in your console.
(if you have the right packages installed of course ^^)

that's what the output looks like:
Code:
b666m@xb666mx:~/pidgin$ python python/pidginnotifyd.py 
ICH (xxx597xxx) said "test 123" with icon at /home/b666m/.purple/icons/5b9c4725ac17458f93a6960b0e05368ec9fa382f.jpg
as you can see we have the alias, the account(id), the message and the icon path.
so we can create a nice notification with "Alias (Account)" on top and with "Message" below.
of course we can use the buddys icon/avatar as picture for the notification.
(maybe the icon requires some more work when you can't give the notification absolute paths - but i have some ideas in mind of how to solve it)

Last edited by b666m; 2010-06-24 at 18:32.
 

The Following User Says Thank You to b666m For This Useful Post: