Merge lp:~dobey/rhythmbox-ubuntuone/update-4-2 into lp:rhythmbox-ubuntuone/stable-4-2
- update-4-2
- Merge into stable-4-2
Proposed by
dobey
Status: | Merged |
---|---|
Approved by: | dobey |
Approved revision: | no longer in the source branch. |
Merged at revision: | 122 |
Proposed branch: | lp:~dobey/rhythmbox-ubuntuone/update-4-2 |
Merge into: | lp:rhythmbox-ubuntuone/stable-4-2 |
Diff against target: |
423 lines (+48/-291) 7 files modified
po/POTFILES.in (+0/-2) rhythmbox-ubuntuone.desktop.in (+0/-12) run-tests (+3/-0) setup.cfg (+1/-1) setup.py (+0/-1) ubuntuone/MusicStoreWidget.py (+0/-265) ubuntuone/ubuntuone.py (+44/-10) |
To merge this branch: | bzr merge lp:~dobey/rhythmbox-ubuntuone/update-4-2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Review via email: mp+142395@code.launchpad.net |
Commit message
[Rodney Dawes]
Update setup.py to remove MusicStoreWidget.py as well.
Update POTFILES.in
Remove the .desktop file as we don't need it any more
Run setup.py build and clean in the run-tests script for basic checks
Remove the UI and source for the music store
Switch to using DownloadFinished directly from syncdaemon
Description of the change
To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) : | # |
review:
Approve
- 122. By dobey
-
[r=dobey] [Rodney Dawes]
Update setup.py to remove MusicStoreWidget.py as well.
Update POTFILES.in
Remove the .desktop file as we don't need it any more
Run setup.py build and clean in the run-tests script for basic checks
Remove the UI and source for the music store
Switch to using DownloadFinished directly from syncdaemon
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'po/POTFILES.in' | |||
2 | --- po/POTFILES.in 2012-02-23 00:50:54 +0000 | |||
3 | +++ po/POTFILES.in 2013-01-08 20:17:25 +0000 | |||
4 | @@ -1,5 +1,3 @@ | |||
5 | 1 | rhythmbox-ubuntuone.desktop.in | ||
6 | 2 | ubuntuone/ubuntuone.py | 1 | ubuntuone/ubuntuone.py |
7 | 3 | ubuntuone/MusicStoreWidget.py | ||
8 | 4 | [type: gettext/ini]ubuntuone/ubuntuone.plugin.in | 2 | [type: gettext/ini]ubuntuone/ubuntuone.plugin.in |
9 | 5 | 3 | ||
10 | 6 | 4 | ||
11 | === removed file 'rhythmbox-ubuntuone.desktop.in' | |||
12 | --- rhythmbox-ubuntuone.desktop.in 2012-03-07 16:01:45 +0000 | |||
13 | +++ rhythmbox-ubuntuone.desktop.in 1970-01-01 00:00:00 +0000 | |||
14 | @@ -1,12 +0,0 @@ | |||
15 | 1 | [Desktop Entry] | ||
16 | 2 | Name=Ubuntu One Music Store | ||
17 | 3 | _Comment=Purchase music on Ubuntu One in Rhythmbox | ||
18 | 4 | Exec=rhythmbox %U | ||
19 | 5 | Terminal=false | ||
20 | 6 | Type=Application | ||
21 | 7 | Icon=rhythmbox | ||
22 | 8 | Categories=GNOME;GTK;AudioVideo; | ||
23 | 9 | MimeType=x-scheme-handler/u1ms | ||
24 | 10 | StartupNotify=true | ||
25 | 11 | X-Ubuntu-Gettext-Domain=rhythmbox-ubuntuone | ||
26 | 12 | NoDisplay=true | ||
27 | 13 | 0 | ||
28 | === modified file 'run-tests' | |||
29 | --- run-tests 2012-08-24 19:36:25 +0000 | |||
30 | +++ run-tests 2013-01-08 20:17:25 +0000 | |||
31 | @@ -14,6 +14,7 @@ | |||
32 | 14 | # | 14 | # |
33 | 15 | # You should have received a copy of the GNU General Public License along | 15 | # You should have received a copy of the GNU General Public License along |
34 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | 17 | ./setup.py build | ||
36 | 17 | export PYTHONPATH=ubuntuone | 18 | export PYTHONPATH=ubuntuone |
37 | 18 | USE_PYFLAKES=1 u1lint . | 19 | USE_PYFLAKES=1 u1lint . |
38 | 19 | if [ -x `which pep8` ]; then | 20 | if [ -x `which pep8` ]; then |
39 | @@ -22,3 +23,5 @@ | |||
40 | 22 | echo "Please install the 'pep8' package." | 23 | echo "Please install the 'pep8' package." |
41 | 23 | fi | 24 | fi |
42 | 24 | rm -rf _trial_temp | 25 | rm -rf _trial_temp |
43 | 26 | ./setup.py clean | ||
44 | 27 | |||
45 | 25 | 28 | ||
46 | === modified file 'setup.cfg' | |||
47 | --- setup.cfg 2012-02-23 00:50:54 +0000 | |||
48 | +++ setup.cfg 2013-01-08 20:17:25 +0000 | |||
49 | @@ -1,2 +1,2 @@ | |||
50 | 1 | [build_i18n] | 1 | [build_i18n] |
52 | 2 | desktop_files=[("lib/rhythmbox/plugins/ubuntuone", ("ubuntuone/ubuntuone.plugin.in",)), ("share/applications", ("rhythmbox-ubuntuone.desktop.in",))] | 2 | desktop_files=[("lib/rhythmbox/plugins/ubuntuone", ("ubuntuone/ubuntuone.plugin.in",))] |
53 | 3 | 3 | ||
54 | === modified file 'setup.py' | |||
55 | --- setup.py 2012-12-07 18:50:52 +0000 | |||
56 | +++ setup.py 2013-01-08 20:17:25 +0000 | |||
57 | @@ -15,6 +15,5 @@ | |||
58 | 15 | url='https://launchpad.net/rhythmbox-ubuntuone', | 15 | url='https://launchpad.net/rhythmbox-ubuntuone', |
59 | 16 | data_files=[('lib/rhythmbox/plugins/ubuntuone', | 16 | data_files=[('lib/rhythmbox/plugins/ubuntuone', |
60 | 17 | ['ubuntuone/ubuntuone.py', | 17 | ['ubuntuone/ubuntuone.py', |
61 | 18 | 'ubuntuone/MusicStoreWidget.py', | ||
62 | 19 | ])], | 18 | ])], |
63 | 20 | ) | 19 | ) |
64 | 21 | 20 | ||
65 | === removed file 'ubuntuone/MusicStoreWidget.py' | |||
66 | --- ubuntuone/MusicStoreWidget.py 2012-12-07 15:06:25 +0000 | |||
67 | +++ ubuntuone/MusicStoreWidget.py 1970-01-01 00:00:00 +0000 | |||
68 | @@ -1,265 +0,0 @@ | |||
69 | 1 | # Copyright (C) 2009-2012 Canonical, Ltd. | ||
70 | 2 | # | ||
71 | 3 | # This library is free software; you can redistribute it and/or modify | ||
72 | 4 | # it under the terms of the GNU Lesser General Public License | ||
73 | 5 | # version 3.0 as published by the Free Software Foundation. | ||
74 | 6 | # | ||
75 | 7 | # This library is distributed in the hope that it will be useful, | ||
76 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
77 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
78 | 10 | # GNU Lesser General Public License version 3.0 for more details. | ||
79 | 11 | # | ||
80 | 12 | # You should have received a copy of the GNU Lesser General Public | ||
81 | 13 | # License along with this library. If not, see | ||
82 | 14 | # <http://www.gnu.org/licenses/>. | ||
83 | 15 | """The Ubuntu One Rhythmbox plugin.""" | ||
84 | 16 | |||
85 | 17 | from __future__ import print_function, unicode_literals | ||
86 | 18 | |||
87 | 19 | import gettext | ||
88 | 20 | import os | ||
89 | 21 | |||
90 | 22 | # pylint: disable=E0611,F0401 | ||
91 | 23 | from gi.repository import Gio, GObject, Gtk, RB | ||
92 | 24 | from gi.repository.UbuntuOneUI import MusicStore as U1MusicStore | ||
93 | 25 | # pylint: enable=E0611,F0401 | ||
94 | 26 | |||
95 | 27 | from gettext import lgettext as _ | ||
96 | 28 | parseurl = None | ||
97 | 29 | try: | ||
98 | 30 | import urllib.parse | ||
99 | 31 | parseurl = urllib.parse.urlparse | ||
100 | 32 | except ImportError: | ||
101 | 33 | import urlparse | ||
102 | 34 | parseurl = urlparse.urlparse | ||
103 | 35 | |||
104 | 36 | gettext.bindtextdomain("rhythmbox-ubuntuone", "/usr/share/locale") | ||
105 | 37 | gettext.textdomain("rhythmbox-ubuntuone") | ||
106 | 38 | |||
107 | 39 | MUSIC_STORE_WIDGET = U1MusicStore() | ||
108 | 40 | U1LIBRARYPATH = MUSIC_STORE_WIDGET.get_library_location() | ||
109 | 41 | |||
110 | 42 | |||
111 | 43 | class U1EntryType(RB.RhythmDBEntryType): | ||
112 | 44 | """Entry type for the Ubuntu One Music Store source.""" | ||
113 | 45 | |||
114 | 46 | def __init__(self): | ||
115 | 47 | RB.RhythmDBEntryType.__init__(self, name='ubuntuone') | ||
116 | 48 | |||
117 | 49 | def do_can_sync_metadata(self, entry): | ||
118 | 50 | """Not a real source, so we can't sync metadata.""" | ||
119 | 51 | return False | ||
120 | 52 | |||
121 | 53 | def do_sync_metadata(self, entry, changes): | ||
122 | 54 | """Do nothing.""" | ||
123 | 55 | return | ||
124 | 56 | |||
125 | 57 | |||
126 | 58 | class U1MusicStoreWidget(object): | ||
127 | 59 | """The Ubuntu One Music Store.""" | ||
128 | 60 | def __init__(self, plugin): | ||
129 | 61 | self.plugin = plugin | ||
130 | 62 | self.db = None | ||
131 | 63 | self.shell = None | ||
132 | 64 | self.source = None | ||
133 | 65 | self.entry_type = U1EntryType() | ||
134 | 66 | |||
135 | 67 | def activate(self, shell): | ||
136 | 68 | """Plugin startup.""" | ||
137 | 69 | self.db = shell.get_property("db") | ||
138 | 70 | group = RB.DisplayPageGroup.get_by_id("stores") | ||
139 | 71 | |||
140 | 72 | icon = Gtk.IconTheme.get_default().load_icon( | ||
141 | 73 | "ubuntuone", 24, 0) | ||
142 | 74 | |||
143 | 75 | self.db.register_entry_type(self.entry_type) | ||
144 | 76 | |||
145 | 77 | self.source = GObject.new(U1Source, | ||
146 | 78 | shell=shell, | ||
147 | 79 | entry_type=self.entry_type, | ||
148 | 80 | pixbuf=icon, | ||
149 | 81 | plugin=self.plugin) | ||
150 | 82 | shell.register_entry_type_for_source(self.source, self.entry_type) | ||
151 | 83 | shell.append_display_page(self.source, group) | ||
152 | 84 | |||
153 | 85 | self.shell = shell | ||
154 | 86 | self.source.connect("preview-mp3", self.play_preview_mp3) | ||
155 | 87 | self.source.connect("play-library", self.play_library) | ||
156 | 88 | self.source.connect("download-finished", self.download_finished) | ||
157 | 89 | self.source.connect("url-loaded", self.url_loaded) | ||
158 | 90 | |||
159 | 91 | self.source.props.query_model = RB.RhythmDBQueryModel.new_empty( | ||
160 | 92 | self.db) | ||
161 | 93 | |||
162 | 94 | def deactivate(self, shell): | ||
163 | 95 | """Plugin shutdown.""" | ||
164 | 96 | # remove source | ||
165 | 97 | self.source.delete_thyself() | ||
166 | 98 | # delete held references | ||
167 | 99 | del self.db | ||
168 | 100 | del self.source | ||
169 | 101 | del self.shell | ||
170 | 102 | |||
171 | 103 | def url_loaded(self, source, url): | ||
172 | 104 | """A URL is loaded in the plugin""" | ||
173 | 105 | if parseurl(url)[2] == "https": | ||
174 | 106 | pass | ||
175 | 107 | else: | ||
176 | 108 | pass | ||
177 | 109 | |||
178 | 110 | def _udf_path_to_library_uri(self, path): | ||
179 | 111 | """Build a URI from the path for the song in the library.""" | ||
180 | 112 | if path.startswith(U1LIBRARYPATH): | ||
181 | 113 | library_path = path | ||
182 | 114 | else: | ||
183 | 115 | subpath = path | ||
184 | 116 | if subpath.startswith("/"): | ||
185 | 117 | subpath = subpath[1:] | ||
186 | 118 | library_path = os.path.join(U1LIBRARYPATH, subpath) | ||
187 | 119 | # convert path to URI. Don't use urllib for this; Python and | ||
188 | 120 | # glib escape URLs differently. gio does it the glib way. | ||
189 | 121 | return Gio.File.new_for_path(library_path).get_uri() | ||
190 | 122 | |||
191 | 123 | def download_finished(self, source, path): | ||
192 | 124 | """A file is finished downloading""" | ||
193 | 125 | library_uri = self._udf_path_to_library_uri(path) | ||
194 | 126 | # Import the URI | ||
195 | 127 | if not self.db.entry_lookup_by_location(library_uri): | ||
196 | 128 | self.db.add_uri(library_uri) | ||
197 | 129 | |||
198 | 130 | def play_library(self, source, path): | ||
199 | 131 | """Switch to and start playing a song from the library""" | ||
200 | 132 | uri = self._udf_path_to_library_uri(path) | ||
201 | 133 | entry = self.db.entry_lookup_by_location(uri) | ||
202 | 134 | if not entry: | ||
203 | 135 | print("couldn't find entry: %s" % uri) | ||
204 | 136 | return | ||
205 | 137 | libsrc = self.shell.props.library_source | ||
206 | 138 | artist_view, album_view = libsrc.get_property_views()[0:2] | ||
207 | 139 | song_view = libsrc.get_entry_view() | ||
208 | 140 | artist = entry.get_string(RB.RhythmDBPropType.ARTIST) | ||
209 | 141 | album = entry.get_string(RB.RhythmDBPropType.ALBUM) | ||
210 | 142 | self.shell.props.display_page_tree.select(libsrc) | ||
211 | 143 | artist_view.set_selection([artist]) | ||
212 | 144 | album_view.set_selection([album]) | ||
213 | 145 | song_view.scroll_to_entry(entry) | ||
214 | 146 | player = self.shell.get_property('shell-player') | ||
215 | 147 | player.stop() | ||
216 | 148 | player.play_entry(entry, libsrc) | ||
217 | 149 | |||
218 | 150 | def play_preview_mp3(self, source, url, title): | ||
219 | 151 | """Play a passed mp3; signal handler for preview-mp3 signal.""" | ||
220 | 152 | # create an entry, don't save it, and play it | ||
221 | 153 | entry = RB.RhythmDBEntry.new(self.db, self.entry_type, url) | ||
222 | 154 | self.db.entry_set(entry, RB.RhythmDBPropType.TITLE, title) | ||
223 | 155 | player = self.shell.get_property('shell-player') | ||
224 | 156 | player.stop() | ||
225 | 157 | player.play_entry(entry, self.source) | ||
226 | 158 | |||
227 | 159 | |||
228 | 160 | class U1Source(RB.Source): | ||
229 | 161 | """A Rhythmbox source widget for the U1 Music Store.""" | ||
230 | 162 | # gproperties required so that rb.Source is instantiable | ||
231 | 163 | __gproperties__ = { | ||
232 | 164 | str('plugin'): (GObject.GObject, str('plugin'), str('plugin'), | ||
233 | 165 | GObject.PARAM_WRITABLE | GObject.PARAM_CONSTRUCT_ONLY), | ||
234 | 166 | } | ||
235 | 167 | # we have the preview-mp3 signal; we receive it from the widget, and | ||
236 | 168 | # re-emit it so that the plugin gets it, because the plugin actually | ||
237 | 169 | # plays the mp3 | ||
238 | 170 | __gsignals__ = { | ||
239 | 171 | str("preview-mp3"): (GObject.SIGNAL_RUN_FIRST, | ||
240 | 172 | GObject.TYPE_NONE, (str, str)), | ||
241 | 173 | str("play-library"): (GObject.SIGNAL_RUN_FIRST, | ||
242 | 174 | GObject.TYPE_NONE, (str,)), | ||
243 | 175 | str("download-finished"): (GObject.SIGNAL_RUN_FIRST, | ||
244 | 176 | GObject.TYPE_NONE, (str,)), | ||
245 | 177 | str("url-loaded"): (GObject.SIGNAL_RUN_FIRST, | ||
246 | 178 | GObject.TYPE_NONE, (str,)), | ||
247 | 179 | } | ||
248 | 180 | |||
249 | 181 | def __init__(self): | ||
250 | 182 | RB.Source.__init__(self, name=_("Ubuntu One")) | ||
251 | 183 | self.browser = MUSIC_STORE_WIDGET | ||
252 | 184 | self.__activated = False | ||
253 | 185 | self.__plugin = None | ||
254 | 186 | self.add_music_store_widget() | ||
255 | 187 | |||
256 | 188 | def do_impl_activate(self): | ||
257 | 189 | """Source startup.""" | ||
258 | 190 | if self.__activated: | ||
259 | 191 | return | ||
260 | 192 | self.__activated = True | ||
261 | 193 | RB.Source.do_impl_activate(self) | ||
262 | 194 | |||
263 | 195 | def do_impl_want_uri(self, uri): | ||
264 | 196 | """I want to handle u1ms URLs""" | ||
265 | 197 | if uri.startswith("u1ms://"): | ||
266 | 198 | return 100 | ||
267 | 199 | return 0 | ||
268 | 200 | |||
269 | 201 | def do_impl_add_uri(self, uri, title, genre, callback=None, | ||
270 | 202 | callback_data=None, destroy_data=None): | ||
271 | 203 | """Handle a u1ms URL""" | ||
272 | 204 | if not uri.startswith("u1ms://"): | ||
273 | 205 | return | ||
274 | 206 | uri_to_use = uri.replace("u1ms://", "http://") | ||
275 | 207 | # pylint: disable=E1101 | ||
276 | 208 | shell = self.get_property("shell") | ||
277 | 209 | shell.props.display_page_tree.select(self) | ||
278 | 210 | self.browser.load_store_link(uri_to_use) | ||
279 | 211 | if callback is not None: | ||
280 | 212 | callback(callback_data) | ||
281 | 213 | if destroy_data is not None: | ||
282 | 214 | destroy_data(callback_data) | ||
283 | 215 | |||
284 | 216 | def add_music_store_widget(self): | ||
285 | 217 | """Display the music store widget in Rhythmbox.""" | ||
286 | 218 | # pylint: disable=E1101 | ||
287 | 219 | if self.browser.get_property('parent') is None: | ||
288 | 220 | self.add(self.browser) | ||
289 | 221 | else: | ||
290 | 222 | self.browser.reparent(self) | ||
291 | 223 | self.browser.show() | ||
292 | 224 | self.show() | ||
293 | 225 | self.browser.set_property("visible", True) | ||
294 | 226 | self.browser.connect("preview-mp3", | ||
295 | 227 | self.re_emit_preview) | ||
296 | 228 | self.browser.connect("play-library", | ||
297 | 229 | self.re_emit_playlibrary) | ||
298 | 230 | self.browser.connect("download-finished", | ||
299 | 231 | self.re_emit_downloadfinished) | ||
300 | 232 | self.browser.connect("url-loaded", | ||
301 | 233 | self.re_emit_urlloaded) | ||
302 | 234 | |||
303 | 235 | def do_impl_can_pause(self): | ||
304 | 236 | """Implementation can pause. | ||
305 | 237 | If we don't handle this, Rhythmbox segfaults.""" | ||
306 | 238 | return True # so we can pause, else we segfault | ||
307 | 239 | |||
308 | 240 | def re_emit_preview(self, widget, url, title): | ||
309 | 241 | """Handle the preview-mp3 signal and re-emit it.""" | ||
310 | 242 | # pylint: disable=E1101 | ||
311 | 243 | self.emit("preview-mp3", url, title) | ||
312 | 244 | |||
313 | 245 | def re_emit_playlibrary(self, widget, path): | ||
314 | 246 | """Handle the play-library signal and re-emit it.""" | ||
315 | 247 | # pylint: disable=E1101 | ||
316 | 248 | self.emit("play-library", path) | ||
317 | 249 | |||
318 | 250 | def re_emit_downloadfinished(self, widget, path): | ||
319 | 251 | """Handle the download-finished signal and re-emit it.""" | ||
320 | 252 | # pylint: disable=E1101 | ||
321 | 253 | self.emit("download-finished", path) | ||
322 | 254 | |||
323 | 255 | def re_emit_urlloaded(self, widget, url): | ||
324 | 256 | """Handle the url-loaded signal and re-emit it.""" | ||
325 | 257 | # pylint: disable=E1101 | ||
326 | 258 | self.emit("url-loaded", url) | ||
327 | 259 | |||
328 | 260 | def do_set_property(self, prop, value): | ||
329 | 261 | """Allow property settings to handle the plug-in call.""" | ||
330 | 262 | if prop.name == 'plugin': | ||
331 | 263 | self.__plugin = value | ||
332 | 264 | else: | ||
333 | 265 | raise AttributeError('unknown property %s' % prop.name) | ||
334 | 266 | 0 | ||
335 | === modified file 'ubuntuone/ubuntuone.py' | |||
336 | --- ubuntuone/ubuntuone.py 2012-08-24 19:36:25 +0000 | |||
337 | +++ ubuntuone/ubuntuone.py 2013-01-08 20:17:25 +0000 | |||
338 | @@ -16,13 +16,14 @@ | |||
339 | 16 | 16 | ||
340 | 17 | from __future__ import print_function, unicode_literals | 17 | from __future__ import print_function, unicode_literals |
341 | 18 | 18 | ||
343 | 19 | # pylint: disable=E0611 | 19 | import os |
344 | 20 | |||
345 | 21 | from dbus import SessionBus, DBusException | ||
346 | 22 | from dirspec.utils import user_home | ||
347 | 20 | from gi.repository import Gio, GObject, Peas | 23 | from gi.repository import Gio, GObject, Peas |
348 | 21 | # pylint: enable=E0611 | ||
349 | 22 | 24 | ||
353 | 23 | # pylint: disable=W0403 | 25 | U1LIBRARYPATH = os.path.join(user_home, '.ubuntuone', |
354 | 24 | from MusicStoreWidget import U1MusicStoreWidget, U1LIBRARYPATH | 26 | 'Purchased from Ubuntu One') |
352 | 25 | # pylint: enable=W0403 | ||
355 | 26 | 27 | ||
356 | 27 | 28 | ||
357 | 28 | class UbuntuOnePlugin (GObject.GObject, Peas.Activatable): | 29 | class UbuntuOnePlugin (GObject.GObject, Peas.Activatable): |
358 | @@ -32,14 +33,19 @@ | |||
359 | 32 | 33 | ||
360 | 33 | def __init__(self): | 34 | def __init__(self): |
361 | 34 | GObject.GObject.__init__(self) | 35 | GObject.GObject.__init__(self) |
362 | 36 | self.db = None | ||
363 | 37 | |||
364 | 38 | # Connect to the session bus | ||
365 | 39 | self._signal = None | ||
366 | 40 | try: | ||
367 | 41 | self._bus = SessionBus() | ||
368 | 42 | except DBusException: | ||
369 | 43 | return | ||
370 | 35 | 44 | ||
371 | 36 | # RhythmDB settings so we can handle changes | 45 | # RhythmDB settings so we can handle changes |
372 | 37 | self.rdbconf = Gio.Settings('org.gnome.rhythmbox.rhythmdb') | 46 | self.rdbconf = Gio.Settings('org.gnome.rhythmbox.rhythmdb') |
373 | 38 | self.rdbconf.connect('changed::locations', self._locations_changed) | 47 | self.rdbconf.connect('changed::locations', self._locations_changed) |
374 | 39 | 48 | ||
375 | 40 | # The Music Store itself | ||
376 | 41 | self.music_store_widget = U1MusicStoreWidget(plugin=self) | ||
377 | 42 | |||
378 | 43 | def _locations_changed(self, *args, **kwargs): | 49 | def _locations_changed(self, *args, **kwargs): |
379 | 44 | """Handle the locations setting being changed.""" | 50 | """Handle the locations setting being changed.""" |
380 | 45 | libraries = self.rdbconf.get_strv('locations') | 51 | libraries = self.rdbconf.get_strv('locations') |
381 | @@ -57,12 +63,40 @@ | |||
382 | 57 | libraries.remove(unescaped_path) | 63 | libraries.remove(unescaped_path) |
383 | 58 | self.rdbconf.set_strv('locations', libraries) | 64 | self.rdbconf.set_strv('locations', libraries) |
384 | 59 | 65 | ||
385 | 66 | def download_finished(self, path, info): | ||
386 | 67 | """A file is finished downloading""" | ||
387 | 68 | if not path.startswith(U1LIBRARYPATH): | ||
388 | 69 | return | ||
389 | 70 | |||
390 | 71 | # convert path to URI. Don't use urllib for this; Python and | ||
391 | 72 | # glib escape URLs differently. gio does it the glib way. | ||
392 | 73 | library_uri = Gio.File.new_for_path(path).get_uri() | ||
393 | 74 | |||
394 | 75 | # Import the URI | ||
395 | 76 | if not self.db.entry_lookup_by_location(library_uri): | ||
396 | 77 | self.db.add_uri(library_uri) | ||
397 | 78 | |||
398 | 60 | def do_activate(self): | 79 | def do_activate(self): |
399 | 61 | """Plug-in startup.""" | 80 | """Plug-in startup.""" |
400 | 62 | # Add the Ubuntu One purchased music directory if not already added | 81 | # Add the Ubuntu One purchased music directory if not already added |
401 | 63 | self._locations_changed() | 82 | self._locations_changed() |
403 | 64 | self.music_store_widget.activate(self.object) | 83 | # Get a reference to the db |
404 | 84 | self.db = self.object.get_property('db') | ||
405 | 85 | |||
406 | 86 | # Connect to the download finished from syncdaemon | ||
407 | 87 | try: | ||
408 | 88 | self._bus.add_signal_receiver(self.download_finished, | ||
409 | 89 | signal_name='DownloadFinished') | ||
410 | 90 | except DBusException: | ||
411 | 91 | return | ||
412 | 65 | 92 | ||
413 | 66 | def do_deactivate(self): | 93 | def do_deactivate(self): |
414 | 67 | """Plug-in shutdown.""" | 94 | """Plug-in shutdown.""" |
416 | 68 | self.music_store_widget.deactivate(self.object) | 95 | del self.db |
417 | 96 | |||
418 | 97 | # Disconnect the signal handler for downloads | ||
419 | 98 | try: | ||
420 | 99 | self.bus.remove_signal_handler(self.download_finished, | ||
421 | 100 | signal_name='DownloadFinished') | ||
422 | 101 | except DBusException: | ||
423 | 102 | return |