Ryan
Ryan

Reputation: 12113

I'm trying to figure out how to use dbus with pidgin

My problem is I'm not sure how to interface them. Do I need to have pidgin installed in a particular way in order for dbus to interface with it? and if not does the pidgin gui have to be running in order for dbus to utilize it?

Upvotes: 4

Views: 2271

Answers (5)

Marwan Alsabbagh
Marwan Alsabbagh

Reputation: 26778

The code below has an example of showing the buddy list when it is hidden and another example of starting an IM conversation with a specific contact.

import dbus
BUS_ARGS = ('im.pidgin.purple.PurpleService', '/im/pidgin/purple/PurpleObject')
obj = dbus.SessionBus().get_object(*BUS_ARGS)
purple = dbus.Interface(obj, 'im.pidgin.purple.PurpleInterface')

# show buddy list if it is hidden
purple.PurpleBlistSetVisible(1)

# start IM conversation with specific contact
account = purple.PurpleAccountsFindConnected('', '')
conversation = purple.PurpleConversationNew(1, account, '[email protected]')

I can recommend a number of useful resources relating to using dbus with pidgin:

  • Riding the D-Bus with Pidgin - Has three separate python dbus examples.
  • purple-remote - It's a python script that was installed on my ubuntu machine when I installed pidgin. Its a single file and pretty easy to read through.
  • dbus-monitor - Great program to monitor dbus calls. It can help you discover what calls are being used by programs you use when you can't find them documented.
  • qdbusviewer - Great graphical tool that can list pidgins dbus methods. You can also call them from the tool itself.

qdbusviewer

Upvotes: 2

abbot
abbot

Reputation: 27850

You do not need to do any special configuration of Pidgin to use D-Bus, however it must be running if you want to use it. You can check the script I'm using to control Pidgin status from the NetworkManager-dispatcher (part 1, part 2) as a sample how to interface Pidgin via D-Bus from python.

Upvotes: 0

Tim Kryger
Tim Kryger

Reputation: 11246

A really useful tool to use when getting started with using DBUS to interface with Pidgin is D-Feet. You can see all the available methods you can call and even execute them directly from the GUI.

Upvotes: 2

markuz
markuz

Reputation: 919

import dbus
from dbus.mainloop.glib import DBusGMainLoop

main_loop = DBusGMainLoop()
session_bus = dbus.SessionBus(mainloop = main_loop)
obj = session_bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

Then you can use the purple object to call some methods like this:

status = purple.PurpleSavedstatusNew("", current)
purple.PurpleSavedstatusSetMessage(status, message)
purple.PurpleSavedstatusActivate(status)

Upvotes: 4

Kevin Boyd
Kevin Boyd

Reputation: 12379

As per this source you could do the following :

#!/usr/bin/env python

def cb_func(account, rec, message):
    #change message here somehow? 
    print message

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

bus.add_signal_receiver(cb_func,
dbus_interface="im.pidgin.purple.PurpleInterface",
signal_name="SendingImMsg")

loop = gobject.MainLoop()
loop.run()

Probably you can get started with this lead.

Upvotes: 5

Related Questions