2006/8/20, Le Boulanger Yann <[EMAIL PROTECTED]>:
Joel Dimbernat wrote:
> 2006/8/20, Le Boulanger Yann <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>>:
>
>     Joel Dimbernat wrote:
>     > Hello,
>     >
>     > I'd like to write something that does the same that gtalk does (i.e
>     > update status with the played song) for gajim and rhythmbox.
>     >
>     > Gajim has a class that do that very well, named gajim-remote, I've
>     seen
>     > some examples. But all these examples were plugins for the music
>     player,
>     > and I don't think (in my very humble opinion) it's the right way
>     to do it.
>     >
>     > Rhythmbox has it's own Dbus API, and I think Gajim should connect
>     to it
>     > and recieve events from it.
>     >
>     > So i'm asking you if I'm right or wrong about it?
>     >
>     > And is Gajim using other Dbus connection from another program (to have
>     > some example)?
>     >
>     > Thanks
>     >
>
>     What you'd like is that gajim knows every dbus interface of every player
>     nd handle them ? I don't think it's a good idea. there are too many, and
>     what if a player changes his API ?
>
>     --
>     Yann
>
>
> I understand you right, but on the other hand should every music player
> implement every dbus interface of every IM program and handle them?
> Gtalk choosed to handle 3 or 4 music players...
>
> Maybe you're right and I should implement it as a rhythmbox plugin, but
> I really think it has its place in Gajim especially to make it take
> place in the GUI.
>
> I worked a bit on it yesterday and it works not so bad but lacks a bit
> of polish yet, I'll post it as soon as it's ok, then you'll be free to
> do whatever you want with it.
>
> I was impressed by how clear and how easy it was to hack the code,
> thanks for it guys!

thanks for sending it here, we'll add it to trac for the moment.

--
Yann


So, here it is...

The image is supposed to go in data/pixmaps.

I hope it will work for you. Just change the status to "show listened track" when listening to Rhythmbox.

The only problem I have and dunno how to solve is that it launches rhythmbox if it's not running when you choose to display the listened track... Dbus is still a lot of mysteries to me.

Joel
Index: src/roster_window.py
===================================================================
--- src/roster_window.py	(révision 6658)
+++ src/roster_window.py	(copie de travail)
@@ -18,6 +18,9 @@
 import gobject
 import os
 import time
+import dbus
+import dbus.glib
+import gobject
 
 import common.sleepy
 import history_window
@@ -2223,7 +2226,7 @@
 	def get_status_message(self, show):
 		if (show == 'online' and not gajim.config.get('ask_online_status')) or \
 			(show == 'offline' and not gajim.config.get('ask_offline_status')) or \
-			show == 'invisible':
+			show == 'invisible' or show == 'song':
 			return ''
 		dlg = dialogs.ChangeStatusMessageDialog(show)
 		message = dlg.run()
@@ -2252,11 +2255,13 @@
 				on_response_ok = (change, account, status))
 		else:
 			change(None, account, status)
+		
 
 	def on_status_combobox_changed(self, widget):
 		'''When we change our status via the combobox'''
 		model = self.status_combobox.get_model()
 		active = self.status_combobox.get_active()
+
 		if active == -1: # no active item
 			return
 		if not self.combobox_callback_active:
@@ -2269,7 +2274,6 @@
 			self.update_status_combobox()
 			return
 		status = model[active][2].decode('utf-8')
-
 		if active == 7: # We choose change status message (7 is that)
 			# do not change show, just show change status dialog
 			status = model[self.previous_status_combobox_active][2].decode('utf-8')
@@ -2309,7 +2313,39 @@
 				if dialog.get_response() != gtk.RESPONSE_OK:
 					self.update_status_combobox()
 					return
+		
+		
 		message = self.get_status_message(status)
+
+		#Establish a connection through dbus with rhythmbox and change
+		#the status with the title and the artist of the listened song.
+		if status == 'song':
+			bus = dbus.SessionBus()
+			rbshellobj = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Shell')
+			rbshell = dbus.Interface(rbshellobj, 'org.gnome.Rhythmbox.Shell')
+			rbplayerobj = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
+			rbplayer = dbus.Interface(rbplayerobj, 'org.gnome.Rhythmbox.Player')
+
+			
+			def playing_uri_changed(uri):
+				props = rbshell.getSongProperties(uri)
+	   			for prop in props:
+					if prop == 'title':
+						title = props[prop]
+					if prop == 'artist':
+						artist = props[prop]
+					
+				for acct in accounts:
+					current_show = gajim.SHOW_LIST[gajim.connections[acct].connected]
+					self.send_status(acct, current_show, title + " by " + artist)
+			
+			#Connecting to the "On song changed" signal
+			try:	
+				rbplayer.connect_to_signal('playingUriChanged', playing_uri_changed)
+			except Exception, e:
+				print "Rhythmbox not running"
+
+
 		if message is None: # user pressed Cancel to change status message dialog
 			self.update_status_combobox()
 			return
@@ -2333,7 +2369,7 @@
 	def update_status_combobox(self):
 		# table to change index in connection.connected to index in combobox
 		table = {'offline':9, 'connecting':9, 'online':0, 'chat':1, 'away':2,
-			'xa':3, 'dnd':4, 'invisible':5}
+			'xa':3, 'dnd':4, 'invisible':5, 'song':10}
 		show = helpers.get_global_show()
 		# temporarily block signal in order not to send status that we show
 		# in the combobox
@@ -3718,6 +3754,12 @@
 		# sensitivity to False because by default we're offline
 		self.status_message_menuitem_iter = liststore.append(
 			[_('Change Status Message...'), img, '', False])
+
+		path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'song.png')
+		img = gtk.Image()
+		img.set_from_file(path)
+		liststore.append([_('Show listened track'), img , 'song', True])
+
 		# Add a Separator (self.iter_is_separator() checks on string SEPARATOR)
 		liststore.append(['SEPARATOR', None, '', True])
 
@@ -3726,7 +3768,7 @@
 			'offline', True])
 
 		status_combobox_items = ['online', 'chat', 'away', 'xa', 'dnd', 'invisible',
-			'separator1', 'change_status_msg', 'separator2', 'offline']
+			'separator1', 'change_status_msg', 'song', 'separator2', 'offline']
 		self.status_combobox.set_model(liststore)
 
 		# default to offline
Index: src/common/helpers.py
===================================================================
--- src/common/helpers.py	(révision 6658)
+++ src/common/helpers.py	(copie de travail)
@@ -237,6 +237,13 @@
 			uf_show = _('_Invisible')
 		else:
 			uf_show = _('Invisible')
+	
+	elif show == 'song':
+		if use_mnemonic:
+			uf_show = _('_Song')
+		else:
+			uf_show = _('Song')
+	
 	elif show == 'not in roster':
 		uf_show = _('Not in Roster')
 	elif show == 'requested':
Index: src/common/gajim.py
===================================================================
--- src/common/gajim.py	(révision 6658)
+++ src/common/gajim.py	(copie de travail)
@@ -123,7 +123,7 @@
 status_before_autoaway = {}
 
 SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
-	'invisible']
+	'invisible','song']
 
 def get_nick_from_jid(jid):
 	pos = jid.find('@')

Attachment: song.png
Description: PNG image

_______________________________________________
Gajim-devel mailing list
Gajim-devel@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/gajim-devel

Reply via email to