Improve in style, varnames, docstrings [make it readable after months have passed], a great patch by Gustavo Carneiro with which we can get currently playing music track from Rhythmbox and Muine to be shown in our status message. fixes #564

This commit is contained in:
Nikos Kouremenos 2006-09-23 13:49:33 +00:00
parent cc25e2613b
commit 65fc27e573
4 changed files with 126 additions and 4 deletions

View File

@ -125,6 +125,7 @@ class Config:
'before_nickname': [ opt_str, '' ], 'before_nickname': [ opt_str, '' ],
'after_nickname': [ opt_str, ':' ], 'after_nickname': [ opt_str, ':' ],
'send_os_info': [ opt_bool, True ], 'send_os_info': [ opt_bool, True ],
'set_status_msg_from_current_music_track': [ opt_bool, False ],
'notify_on_new_gmail_email': [ opt_bool, True ], 'notify_on_new_gmail_email': [ opt_bool, True ],
'notify_on_new_gmail_email_extra': [ opt_bool, False ], 'notify_on_new_gmail_email_extra': [ opt_bool, False ],
'usegpg': [ opt_bool, False, '', True ], 'usegpg': [ opt_bool, False, '', True ],

View File

@ -1,7 +1,7 @@
## config.py ## config.py
## ##
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
## Copyright (C) 2005-2006 Nikos Kouremenos <nkour@jabber.org> ## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
## Copyright (C) 2005 Dimitur Kirov <dkirov@gmail.com> ## Copyright (C) 2005 Dimitur Kirov <dkirov@gmail.com>
## Copyright (C) 2003-2005 Vincent Hanquez <tab@snarc.org> ## Copyright (C) 2003-2005 Vincent Hanquez <tab@snarc.org>
## ##
@ -459,11 +459,17 @@ class PreferencesWindow:
st = gajim.config.get('send_os_info') st = gajim.config.get('send_os_info')
self.xml.get_widget('send_os_info_checkbutton').set_active(st) self.xml.get_widget('send_os_info_checkbutton').set_active(st)
# set status msg from currently playing music track
st = gajim.config.get('set_status_msg_from_current_music_track')
self.xml.get_widget(
'set_status_msg_from_current_music_track_checkbutton').set_active(st)
# Notify user of new gmail e-mail messages, # Notify user of new gmail e-mail messages,
# only show checkbox if user has a gtalk account # only show checkbox if user has a gtalk account
frame_gmail = self.xml.get_widget('frame_gmail') frame_gmail = self.xml.get_widget('frame_gmail')
notify_gmail_checkbutton = self.xml.get_widget('notify_gmail_checkbutton') notify_gmail_checkbutton = self.xml.get_widget('notify_gmail_checkbutton')
notify_gmail_extra_checkbutton = self.xml.get_widget('notify_gmail_extra_checkbutton') notify_gmail_extra_checkbutton = self.xml.get_widget(
'notify_gmail_extra_checkbutton')
frame_gmail.set_no_show_all(True) frame_gmail.set_no_show_all(True)
for account in gajim.config.get_per('accounts'): for account in gajim.config.get_per('accounts'):
@ -1082,6 +1088,13 @@ class PreferencesWindow:
gajim.interface.instances['advanced_config'] = \ gajim.interface.instances['advanced_config'] = \
dialogs.AdvancedConfigurationWindow() dialogs.AdvancedConfigurationWindow()
def set_status_msg_from_current_music_track_checkbutton_toggled(self,
widget):
self.on_checkbutton_toggled(widget,
'set_status_msg_from_current_music_track')
gajim.interface.roster.enable_syncing_status_msg_from_current_music_track(
widget.get_active())
#---------- AccountModificationWindow class -------------# #---------- AccountModificationWindow class -------------#
class AccountModificationWindow: class AccountModificationWindow:
'''Class for account informations''' '''Class for account informations'''

View File

@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
## musictracklistener.py
##
## Copyright (C) 2006 Gustavo Carneiro <gjcarneiro@gmail.com>
## Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com>
##
## 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; version 2 only.
##
## 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.
##
import gobject
import dbus
import dbus.glib
class MusicTrackInfo(object):
__slots__ = ['title', 'album', 'artist', 'duration', 'track_number']
class MusicTrackListener(gobject.GObject):
__gsignals__ = { 'music-track-changed': (gobject.SIGNAL_RUN_LAST, None,
(object,)) }
_instance = None
@classmethod
def get(cls):
if cls._instance is None:
cls._instance = cls()
return cls._instance
def __init__(self):
super(MusicTrackListener, self).__init__()
bus = dbus.SessionBus()
bus.add_signal_receiver(self._muine_music_track_change_cb, 'SongChanged',
'org.gnome.Muine.Player')
bus.add_signal_receiver(self._rhythmbox_music_track_change_cb,
'playingUriChanged', 'org.gnome.Rhythmbox.Player')
def _muine_music_track_change_cb(self, arg):
d = dict((x.strip() for x in s1.split(':', 1)) for s1 in arg.split('\n'))
info = MusicTrackInfo()
info.title = d['title']
info.album = d['album']
info.artist = d['artist']
info.duration = int(d['duration'])
info.track_number = int(d['track_number'])
self.emit('music-track-changed', info)
def _rhythmbox_music_track_change_cb(self, uri):
bus = dbus.SessionBus()
rbshellobj = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Shell')
rbshell = rbshell = dbus.Interface(rbshellobj, 'org.gnome.Rhythmbox.Shell')
props = rbshell.getSongProperties(uri)
info = MusicTrackInfo()
info.title = props['title']
info.album = props['album']
info.artist = props['artist']
info.duration = int(props['duration'])
info.track_number = int(props['track-number'])
self.emit('music-track-changed', info)
# here we test :)
if __name__ == '__main__':
def music_track_change_cb(listener, music_track_info):
print music_track_info.title
MusicTrackListener.get().connect('music-track-changed', music_track_change_cb)
gobject.MainLoop().run()

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
## roster_window.py ## roster_window.py
## ##
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org> ## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
@ -38,6 +39,7 @@ from message_window import MessageWindowMgr
from chat_control import ChatControl from chat_control import ChatControl
from groupchat_control import GroupchatControl from groupchat_control import GroupchatControl
from groupchat_control import PrivateChatControl from groupchat_control import PrivateChatControl
from music_track_listener import MusicTrackListener
#(icon, name, type, jid, account, editable, second pixbuf) #(icon, name, type, jid, account, editable, second pixbuf)
( (
@ -2382,6 +2384,36 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
self.send_status(acct, status, message) self.send_status(acct, status, message)
self.update_status_combobox() self.update_status_combobox()
## enable setting status msg from currently playing music track
def enable_syncing_status_msg_from_current_music_track(self, enabled):
'''if enabled is True, we listen to events from music players about
currently played music track, and we update our
status message accordinly'''
if enabled:
if self._music_track_changed_signal is None:
listener = MusicTrackListener.get()
self._music_track_changed_signal = listener.connect(
'music-track-changed', self._music_track_changed)
else:
if self._music_track_changed_signal is not None:
listener = MusicTrackListener.get()
listener.disconnect(self._music_track_changed_signal)
self._music_track_changed_signal = None
self._music_track_changed(None, None)
def _music_track_changed(self, unused_listener, music_track_info):
accounts = gajim.connections.keys()
if music_track_info is None:
status_message = ''
else:
status_message = _('"%(title)s" by %(artist)s') % \
{'title': music_track_info.title,
'artist': music_track_info.artist }
for acct in accounts:
current_show = gajim.SHOW_LIST[gajim.connections[acct].connected]
self.send_status(acct, current_show, status_message)
def update_status_combobox(self): def update_status_combobox(self):
# table to change index in connection.connected to index in combobox # table to change index in connection.connected to index in combobox
table = {'offline':9, 'connecting':9, 'online':0, 'chat':1, 'away':2, table = {'offline':9, 'connecting':9, 'online':0, 'chat':1, 'away':2,
@ -3686,6 +3718,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
def __init__(self): def __init__(self):
self.xml = gtkgui_helpers.get_glade('roster_window.glade') self.xml = gtkgui_helpers.get_glade('roster_window.glade')
self.window = self.xml.get_widget('roster_window') self.window = self.xml.get_widget('roster_window')
self._music_track_changed_signal = None
gajim.interface.msg_win_mgr = MessageWindowMgr() gajim.interface.msg_win_mgr = MessageWindowMgr()
self.advanced_menus = [] # We keep them to destroy them self.advanced_menus = [] # We keep them to destroy them
if gajim.config.get('roster_window_skip_taskbar'): if gajim.config.get('roster_window_skip_taskbar'):
@ -3862,6 +3895,10 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
self.tooltip = tooltips.RosterTooltip() self.tooltip = tooltips.RosterTooltip()
self.draw_roster() self.draw_roster()
## Music Track notifications
self.enable_syncing_status_msg_from_current_music_track(gajim.config.get(
'set_status_msg_from_current_music_track'))
if gajim.config.get('show_roster_on_startup'): if gajim.config.get('show_roster_on_startup'):
self.window.show_all() self.window.show_all()
else: else: