[Rhythmbox-devel] patch for the lyrics plugin



this small patch makes the plugin search for new lyrics on song change.
I simply copied the code from the coverart plugin. Also, since I don't
know a thing about python or it's syntax, there's a posibility that i've
introduced a bug or two. Seems to work here though.
-- 
ÐÐÐÑÐÑ ÐÐÐÑÑÐÑÐÐ /Viktor Kojouharov/ <vkojouharov gmail org>
Index: plugins/lyrics/lyrics.py
===================================================================
RCS file: /cvs/gnome/rhythmbox/plugins/lyrics/lyrics.py,v
retrieving revision 1.2
diff -u -r1.2 lyrics.py
--- plugins/lyrics/lyrics.py	19 May 2006 08:46:26 -0000	1.2
+++ plugins/lyrics/lyrics.py	20 May 2006 21:17:35 -0000
@@ -212,6 +212,7 @@
 	self.window = None
 
     def activate (self, shell):
+	self.shell = shell
 	self.action = gtk.Action ('ViewSongLyrics', _('Song L_yrics'),
 				  _('Display lyrics for the playing song'),
 				  'rb-song-lyrics')
@@ -227,11 +228,14 @@
 
 	sp = shell.get_player ()
 	self.pec_id = sp.connect('playing-song-changed', self.playing_entry_changed)
+	self.pc_id = sp.connect ('playing-changed', self.playing_changed)
 	self.playing_entry_changed (sp, sp.get_playing_entry ())
 
 	self.csi_id = shell.connect('create_song_info', self.create_song_info)
+	self.current_entry = None
 
     def deactivate (self, shell):
+	self.shell = None
     	
 	uim = shell.get_ui_manager()
 	uim.remove_ui (self.ui_id)
@@ -242,16 +246,36 @@
 
 	sp = shell.get_player ()
 	sp.disconnect (self.pec_id)
+	sp.disconnect (self.pc_id)
+	sp.disconnect (self.csi_id)
 
 	if self.window is not None:
 	    self.window.destroy ()
 
 
     def playing_entry_changed (self, sp, entry):
-    	if entry is not None:
-	    self.action.set_sensitive (True)
-	else:
-	    self.action.set_sensitive (False)
+	self.set_entry (entry)
+
+    def playing_changed (self, sp, playing):
+	self.set_entry(sp.get_playing_entry ())
+
+    def set_entry (self, entry):
+	if entry is None:
+	    return
+
+	if entry == self.current_entry:
+	    return
+
+	if self.window is None:
+	    return
+
+	self.current_entry = entry
+	db = self.shell.get_property ("db")
+	sp = self.shell.get_player ()
+
+        self.window.buffer.set_text("Searching for lyrics...")
+	lyrics_grabber = LyricGrabber()
+	lyrics_grabber.get_lyrics(db, entry, self.window.buffer.set_text)
 
     def show_song_lyrics (self, action, shell):
 
@@ -261,13 +285,8 @@
 	db = shell.get_property ("db")
 	sp = shell.get_player ()
 	entry = sp.get_playing_entry ()
-
-	if entry is None:
-	    return
-
 	self.window = LyricWindow(db, entry)
-	lyrics_grabber = LyricGrabber()
-	lyrics_grabber.get_lyrics(db, entry, self.window.buffer.set_text)
+	self.set_entry (entry)
 	
     def create_song_info (self, shell, song_info, is_multiple):
 

Attachment: signature.asc
Description: =?iso-8859-5?Q?=C2=DE=D2=D0?= =?iso-8859-5?Q?_=D5?= =?iso-8859-5?Q?_=E6=D8=E4=E0=DE=D2=DE?= =?iso-8859-5?Q?_=DF=DE=D4=DF=D8=E1=D0=DD=D0?= =?iso-8859-5?Q?_=E7=D0=E1=E2?= =?iso-8859-5?Q?_=DE=E2?= =?iso-8859-5?Q?_=DF=D8=E1=DC=DE=E2=DE?=



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]