#!/usr/bin/env python # -*- coding: utf-8 -*- # Quod Libet gamin.py Source # Copyright 2005-2006 Sergey Fedoseev # Copyright 2007 Simon Morgan # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # Exaile imstatus.py Source # Copyright 2007 Ingelrest François # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. ############################################################################### # ql_imstatus.py is an amalgamation of gamin.py from QuodLibet and imstatus.py # from exaile for Quod Libet # Copyright 2008 Sam Black # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 18/01/2008 00:58:08 # 0.1.0 tested to work with Pidgin and Gajim, testers with Gossip welcome! from string import join import gtk import dbus from plugins.events import EventPlugin from parse import Pattern from qltk import Frame import config class IMStatusMessage(EventPlugin): PLUGIN_ID = 'IM Client status message' PLUGIN_NAME = _('IM Client status message') PLUGIN_DESC = _("Change your IM status message according to what " "you are currently listening to.\n" "Supported clients:\n" "Pidgin, Gajim and Gossip" ) PLUGIN_VERSION = '0.1.0' supported_clients = { 'pidgin' : { 'dbus_service' : 'im.pidgin.purple.PurpleService', 'dbus_object' : '/im/pidgin/purple/PurpleObject', 'dbus_interface' : 'im.pidgin.purple.PurpleInterface'}, 'gajim' : { 'dbus_service' : 'org.gajim.dbus', 'dbus_object' : '/org/gajim/dbus/RemoteObject', 'dbus_interface' : 'org.gajim.dbus.RemoteInterface'}, 'gossip' : { 'dbus_service' : 'org.gnome.Gossip', 'dbus_object' : '/org/gnome/Gossip', 'dbus_interface' : 'org.gnome.Gossip'} } c_paused = __name__+'_paused' c_away = __name__ + '_away' c_pattern = __name__+'_pattern' def __init__(self): try: self.paused = config.getboolean('plugins', self.c_paused) except: self.paused = True config.set('plugins', self.c_paused, 'True') try: self.away = config.getboolean('plugins', self.c_away) except: self.away = True config.set('plugins', self.c_away, 'True') if self.away: self.statuses = ['online', 'chat', 'away', 'xa', 'available', 'unavailable', 'extended_away', 'busy'] else: self.statuses = ['online', 'chat', 'available'] try: self.pattern = config.get('plugins', self.c_pattern) except: self.pattern = ' - ' config.set('plugins', self.c_pattern, self.pattern) gtk.quit_add(0, self.quit) self.imclientlist = [] activeServices = dbus.SessionBus().get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames() for client in self.supported_clients : tmp = self.supported_clients[client] if tmp['dbus_service'] in activeServices : try: obj = dbus.SessionBus().get_object(tmp['dbus_service'], tmp['dbus_object']) interface = dbus.Interface(obj, tmp['dbus_interface']) self.imclientlist.append([client, interface]) except dbus.DBusException: print "Cannot add %s as a client" % client self.current = '' def quit(self): if self.current != '': self.change_status('') def change_status(self, status_message): for client in self.imclientlist: interface = client[1] if "pidgin" in client: try: current = interface.PurpleSavedstatusGetCurrent() statusType = interface.PurpleSavedstatusGetType(current) statusId = interface.PurplePrimitiveGetIdFromType(statusType) if statusId in self.statuses or status_message == '': saved = interface.PurpleSavedstatusNew('', statusType) interface.PurpleSavedstatusSetMessage(saved, status_message) interface.PurpleSavedstatusActivate(saved) except dbus.DBusException: continue elif "gajim" in client: try: account_list = dict([(tmpaccount, False) for tmpaccount in interface.list_accounts()]) for account in account_list: status = interface.get_status(account) if status in self.statuses or status_message == '': interface.change_status(status, status_message, account) except dbus.DBusException: continue elif "gossip" in client: try: status = None status, msg = interface.GetPresence('') if status != None: if status in self.statuses or status_message == '': interface.SetPresence(status, status_message) except dbus.DBusException: continue else: print "Error, cannot transmit message to %s" % client def plugin_on_song_started(self, song): if song: self.current = Pattern(self.pattern) % song else: self.current = '' self.change_status(self.current) def plugin_on_paused(self): if self.paused and self.current != '': self.change_status(self.current + " [paused]") def plugin_on_unpaused(self): self.change_status(self.current) def pattern_changed(self, entry): self.pattern = entry.get_text() config.set('plugins', self.c_pattern, self.pattern) def paused_changed(self, c): config.set('plugins', self.c_paused, str(c.get_active())) def away_changed(self, b): config.set('plugins', self.c_away, str(b.get_active())) if b.get_active(): self.away = True self.statuses = ['online', 'chat', 'away', 'xa', 'available', 'unavailable', 'extended_away', 'busy'] self.change_status(self.current) else: self.away = False self.statuses = ['online', 'chat', 'available'] self.change_status('') def PluginPreferences(self, parent): vb = gtk.VBox(spacing = 3) tooltips = gtk.Tooltips().set_tip pattern_box = gtk.HBox(spacing = 3) pattern_box.set_border_width(3) pattern = gtk.Entry() pattern.set_text(self.pattern) pattern.connect('changed', self.pattern_changed) pattern_box.pack_start(gtk.Label("Pattern:"), expand = False) pattern_box.pack_start(pattern) pause_e = gtk.CheckButton(label="Add '[paused]'") pause_e.set_active(self.paused) pause_e.connect('toggled', self.paused_changed) tooltips(pause_e, "If checked, '[paused]' will be added to your " "status message when Quod Libet is paused") away_e = gtk.CheckButton(label="Change status message whilst away") away_e.set_active(self.away) away_e.connect('toggled', self.away_changed) tooltips(away_e, "If checked, your status message will be updated " "whilst you are away") vb.pack_start(pattern_box) vb.pack_start(pause_e) vb.pack_start(away_e) return vb