Merge lp:~laszlok/zeitgeist-datasources/trunk into lp:zeitgeist-datasources/0.8

Proposed by Laszlo Pandy
Status: Merged
Merge reported by: Seif Lotfy
Merged at revision: not available
Proposed branch: lp:~laszlok/zeitgeist-datasources/trunk
Merge into: lp:zeitgeist-datasources/0.8
Diff against target: 125 lines (+69/-22)
1 file modified
rhythmbox/__init__.py (+69/-22)
To merge this branch: bzr merge lp:~laszlok/zeitgeist-datasources/trunk
Reviewer Review Type Date Requested Status
Seif Lotfy Approve
Review via email: mp+17803@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Seif Lotfy (seif) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'rhythmbox/__init__.py'
--- rhythmbox/__init__.py 2009-11-27 08:49:31 +0000
+++ rhythmbox/__init__.py 2010-01-21 04:29:09 +0000
@@ -19,6 +19,7 @@
1919
20import rb20import rb
21import rhythmdb21import rhythmdb
22import gobject
22import time23import time
2324
24from zeitgeist.client import ZeitgeistDBusInterface25from zeitgeist.client import ZeitgeistDBusInterface
@@ -42,7 +43,13 @@
42 shell_player.connect("playing-changed", self.playing_changed)43 shell_player.connect("playing-changed", self.playing_changed)
43 shell_player.connect("playing-source-changed", self.playing_source_changed)44 shell_player.connect("playing-source-changed", self.playing_source_changed)
44 shell_player.connect("playing-song-changed", self.playing_song_changed)45 shell_player.connect("playing-song-changed", self.playing_song_changed)
46
47 backend_player = shell_player.get_property("player")
48 backend_player.connect("eos", self.on_backend_eos)
49
50 self.__manual_switch = True
45 self.__current_song = None51 self.__current_song = None
52 self._shell = shell
46 53
47 @staticmethod54 @staticmethod
48 def get_song_info(db, entry):55 def get_song_info(db, entry):
@@ -56,37 +63,77 @@
56 return song63 return song
57 64
58 65
66 def on_backend_eos(self, backend_player, stream_data, eos_early):
67 print "got eos signal"
68 # EOS signal means that the song changed because the song is over.
69 # ie. the user did not explicitly change the song.
70 self.__manual_switch = False
71
59 def playing_changed(self, shell, state):72 def playing_changed(self, shell, state):
60 """ using this signal to trigger play/pause switches"""73 """ using this signal to trigger play/pause switches"""
61 print ("got playing_changed signal", shell, state)74 pass
62 75
63 def playing_source_changed(self, shell, source):76 def playing_source_changed(self, shell, source):
64 """ use this signal to trigger changes between local music, radio, online music etc."""77 """ use this signal to trigger changes between local music, radio, online music etc."""
65 print ("got playing_source_changed signal", shell, source)78 pass
66 79
67 def playing_song_changed(self, shell, entry):80 def playing_song_changed(self, shell, entry):
68 print ("got playing_song_changed signal", shell, entry)81 print ("got playing_song_changed signal", shell, entry)
69 db = shell.get_property("db")82 if self.__current_song is not None:
83 self.send_to_zeitgeist_async(self.__current_song, Interpretation.CLOSE_EVENT)
84
70 if entry is not None:85 if entry is not None:
71 self.__current_song = entry86 self.send_to_zeitgeist_async(entry, Interpretation.OPEN_EVENT)
72 song = self.get_song_info(db, entry)87
73 subject = Subject.new_for_values(88 self.__current_song = entry
74 uri=song["location"],89 gobject.idle_add(self.reset_manual_switch)
75 interpretation=unicode(Interpretation.MUSIC),90
76 manifestation=unicode(Manifestation.FILE),91 def reset_manual_switch(self):
77 #~ origin="", #TBD92 print "manual_switch reset to True"
78 mimetype=song["mimetype"],93 """
79 text=" - ".join([song["title"], song["artist"], song["album"]])94 After the eos signal has fired, and after the zeitgeist events have
80 ) 95 been sent asynchronously, reset the manual_switch variable.
81 event = Event.new_for_values(96 """
82 timestamp=int(time.time()*1000),97 self.__manual_switch = True
83 interpretation=unicode(Interpretation.VISIT_EVENT),98
84 manifestation=unicode(Manifestation.USER_ACTIVITY),99 def send_to_zeitgeist_async(self, entry, event_type):
85 actor="application://rhythmbox.desktop",100 """
86 subjects=[subject,]101 We do async here because the "eos" signal is fired
87 )102 *after* the "playing-song-changed" signal.
88 print event103 We don't know if the song change was manual or automatic
89 IFACE.InsertEvents([event,])104 until we get get the eos signal. If the mainloop goes to
105 idle, it means there are no more signals scheduled, so we
106 will have already received the eos if it was coming.
107 """
108 gobject.idle_add(self.send_to_zeitgeist, entry, event_type)
109
110 def send_to_zeitgeist(self, entry, event_type):
111 db = self._shell.get_property("db")
112 song = self.get_song_info(db, entry)
113
114 if self.__manual_switch:
115 manifest = Manifestation.USER_ACTIVITY
116 else:
117 manifest = Manifestation.SCHEDULED_ACTIVITY
118
119 subject = Subject.new_for_values(
120 uri=song["location"],
121 interpretation=unicode(Interpretation.MUSIC),
122 manifestation=unicode(Manifestation.FILE),
123 #~ origin="", #TBD
124 mimetype=song["mimetype"],
125 text=" - ".join([song["title"], song["artist"], song["album"]])
126 )
127 event = Event.new_for_values(
128 timestamp=int(time.time()*1000),
129 interpretation=unicode(event_type),
130 manifestation=unicode(manifest),
131 actor="application://rhythmbox.desktop",
132 subjects=[subject,]
133 )
134 print event
135 IFACE.InsertEvents([event,])
90 136
91 def deactivate(self, shell):137 def deactivate(self, shell):
92 print "UNLOADING Zeitgeist plugin ......."138 print "UNLOADING Zeitgeist plugin ......."
139

Subscribers

People subscribed via source and target branches