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
1=== modified file 'rhythmbox/__init__.py'
2--- rhythmbox/__init__.py 2009-11-27 08:49:31 +0000
3+++ rhythmbox/__init__.py 2010-01-21 04:29:09 +0000
4@@ -19,6 +19,7 @@
5
6 import rb
7 import rhythmdb
8+import gobject
9 import time
10
11 from zeitgeist.client import ZeitgeistDBusInterface
12@@ -42,7 +43,13 @@
13 shell_player.connect("playing-changed", self.playing_changed)
14 shell_player.connect("playing-source-changed", self.playing_source_changed)
15 shell_player.connect("playing-song-changed", self.playing_song_changed)
16+
17+ backend_player = shell_player.get_property("player")
18+ backend_player.connect("eos", self.on_backend_eos)
19+
20+ self.__manual_switch = True
21 self.__current_song = None
22+ self._shell = shell
23
24 @staticmethod
25 def get_song_info(db, entry):
26@@ -56,37 +63,77 @@
27 return song
28
29
30+ def on_backend_eos(self, backend_player, stream_data, eos_early):
31+ print "got eos signal"
32+ # EOS signal means that the song changed because the song is over.
33+ # ie. the user did not explicitly change the song.
34+ self.__manual_switch = False
35+
36 def playing_changed(self, shell, state):
37 """ using this signal to trigger play/pause switches"""
38- print ("got playing_changed signal", shell, state)
39+ pass
40
41 def playing_source_changed(self, shell, source):
42 """ use this signal to trigger changes between local music, radio, online music etc."""
43- print ("got playing_source_changed signal", shell, source)
44+ pass
45
46 def playing_song_changed(self, shell, entry):
47 print ("got playing_song_changed signal", shell, entry)
48- db = shell.get_property("db")
49+ if self.__current_song is not None:
50+ self.send_to_zeitgeist_async(self.__current_song, Interpretation.CLOSE_EVENT)
51+
52 if entry is not None:
53- self.__current_song = entry
54- song = self.get_song_info(db, entry)
55- subject = Subject.new_for_values(
56- uri=song["location"],
57- interpretation=unicode(Interpretation.MUSIC),
58- manifestation=unicode(Manifestation.FILE),
59- #~ origin="", #TBD
60- mimetype=song["mimetype"],
61- text=" - ".join([song["title"], song["artist"], song["album"]])
62- )
63- event = Event.new_for_values(
64- timestamp=int(time.time()*1000),
65- interpretation=unicode(Interpretation.VISIT_EVENT),
66- manifestation=unicode(Manifestation.USER_ACTIVITY),
67- actor="application://rhythmbox.desktop",
68- subjects=[subject,]
69- )
70- print event
71- IFACE.InsertEvents([event,])
72+ self.send_to_zeitgeist_async(entry, Interpretation.OPEN_EVENT)
73+
74+ self.__current_song = entry
75+ gobject.idle_add(self.reset_manual_switch)
76+
77+ def reset_manual_switch(self):
78+ print "manual_switch reset to True"
79+ """
80+ After the eos signal has fired, and after the zeitgeist events have
81+ been sent asynchronously, reset the manual_switch variable.
82+ """
83+ self.__manual_switch = True
84+
85+ def send_to_zeitgeist_async(self, entry, event_type):
86+ """
87+ We do async here because the "eos" signal is fired
88+ *after* the "playing-song-changed" signal.
89+ We don't know if the song change was manual or automatic
90+ until we get get the eos signal. If the mainloop goes to
91+ idle, it means there are no more signals scheduled, so we
92+ will have already received the eos if it was coming.
93+ """
94+ gobject.idle_add(self.send_to_zeitgeist, entry, event_type)
95+
96+ def send_to_zeitgeist(self, entry, event_type):
97+ db = self._shell.get_property("db")
98+ song = self.get_song_info(db, entry)
99+
100+ if self.__manual_switch:
101+ manifest = Manifestation.USER_ACTIVITY
102+ else:
103+ manifest = Manifestation.SCHEDULED_ACTIVITY
104+
105+ subject = Subject.new_for_values(
106+ uri=song["location"],
107+ interpretation=unicode(Interpretation.MUSIC),
108+ manifestation=unicode(Manifestation.FILE),
109+ #~ origin="", #TBD
110+ mimetype=song["mimetype"],
111+ text=" - ".join([song["title"], song["artist"], song["album"]])
112+ )
113+ event = Event.new_for_values(
114+ timestamp=int(time.time()*1000),
115+ interpretation=unicode(event_type),
116+ manifestation=unicode(manifest),
117+ actor="application://rhythmbox.desktop",
118+ subjects=[subject,]
119+ )
120+ print event
121+ IFACE.InsertEvents([event,])
122
123 def deactivate(self, shell):
124 print "UNLOADING Zeitgeist plugin ......."
125+

Subscribers

People subscribed via source and target branches