Merge lp:~dobey/rhythmbox-ubuntuone/update-from-trunk into lp:rhythmbox-ubuntuone/stable-3-0

Proposed by dobey on 2012-03-20
Status: Merged
Approved by: dobey on 2012-03-20
Approved revision: no longer in the source branch.
Merged at revision: 114
Proposed branch: lp:~dobey/rhythmbox-ubuntuone/update-from-trunk
Merge into: lp:rhythmbox-ubuntuone/stable-3-0
Diff against target: 158 lines (+17/-59)
2 files modified
ubuntuone/MusicStoreWidget.py (+12/-48)
ubuntuone/ubuntuone.py (+5/-11)
To merge this branch: bzr merge lp:~dobey/rhythmbox-ubuntuone/update-from-trunk
Reviewer Review Type Date Requested Status
Roberto Alsina (community) 2012-03-20 Approve on 2012-03-20
Review via email: mp+98483@code.launchpad.net

Commit Message

There Can Be Only One library path location
Remove the unnecessary symlink logic and only use U1LIBRARYPATH
Ensure plug-in is removed/added correctly when disabled and re-enabled

To post a comment you must log in.
Roberto Alsina (ralsina) wrote :

+1

review: Approve
114. By dobey on 2012-03-20

There Can Be Only One library path location
Remove the unnecessary symlink logic and only use U1LIBRARYPATH
Ensure plug-in is removed/added correctly when disabled and re-enabled

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/MusicStoreWidget.py'
2--- ubuntuone/MusicStoreWidget.py 2012-03-06 20:51:27 +0000
3+++ ubuntuone/MusicStoreWidget.py 2012-03-20 18:41:31 +0000
4@@ -24,7 +24,6 @@
5 from gi.repository.UbuntuOneUI import MusicStore as U1MusicStore
6 # pylint: enable=E0611,F0401
7
8-from dirspec import basedir
9 from gettext import lgettext as _
10
11 gettext.bindtextdomain("rhythmbox-ubuntuone", "/usr/share/locale")
12@@ -56,7 +55,6 @@
13 self.db = None
14 self.shell = None
15 self.source = None
16- self.u1_library_symlink = None
17 self.entry_type = U1EntryType()
18
19 def activate(self, shell):
20@@ -86,15 +84,10 @@
21 self.source.props.query_model = RB.RhythmDBQueryModel.new_empty(
22 self.db)
23
24- # Do these every time
25- self.add_u1_library()
26-
27 def deactivate(self, shell):
28 """Plugin shutdown."""
29 # remove source
30- # FIXME?: This API changed, but doesn't seem entirely necessary.
31- # It's not entirely clear which API to use for this now.
32- #self.source.delete_thyself()
33+ self.source.delete_thyself()
34 # delete held references
35 del self.db
36 del self.source
37@@ -108,22 +101,17 @@
38 pass
39
40 def _udf_path_to_library_uri(self, path):
41- """Calculate the path in the library.
42- Since the library is accessed via the created symlink, but the path
43- passed to us is to a file in the actual music store UDF, we need to
44- work out the path inside the library, i.e., what the path to that file
45- is via the symlink."""
46+ """Build a URI from the path for the song in the library."""
47 if path.startswith(U1LIBRARYPATH):
48- subpath = path[len(U1LIBRARYPATH):]
49+ library_path = path
50 else:
51 subpath = path
52- if subpath.startswith("/"):
53- subpath = subpath[1:]
54- library_path = os.path.join(self.u1_library_symlink, subpath)
55+ if subpath.startswith("/"):
56+ subpath = subpath[1:]
57+ library_path = os.path.join(U1LIBRARYPATH, subpath)
58 # convert path to URI. Don't use urllib for this; Python and
59 # glib escape URLs differently. gio does it the glib way.
60- library_uri = Gio.File.new_for_path(library_path).get_uri()
61- return library_uri
62+ return Gio.File.new_for_path(library_path).get_uri()
63
64 def download_finished(self, source, path):
65 """A file is finished downloading"""
66@@ -160,34 +148,7 @@
67 player = self.shell.get_property('shell-player')
68 player.stop()
69 player.play_entry(entry, self.source)
70-
71- def add_u1_library(self):
72- """Add the U1 library if not listed in RB and re-add if changed."""
73- u1_library_path_folder = basedir.save_data_path("ubuntuone")
74- # Ensure that we can write to the folder, because syncdaemon creates it
75- # with no write permissions
76- os.chmod(u1_library_path_folder,
77- os.stat(u1_library_path_folder)[stat.ST_MODE] | stat.S_IWUSR)
78- # Translators: this is the name under Music for U1 music in Rhythmbox
79- u1_library_path = os.path.join(u1_library_path_folder,
80- _("Purchased from Ubuntu One"))
81- if not os.path.islink(u1_library_path):
82- if not os.path.exists(u1_library_path):
83- print "Attempting to symlink %s to %s" % (U1LIBRARYPATH,
84- u1_library_path)
85- os.symlink(U1LIBRARYPATH, u1_library_path)
86- else:
87- # something that isn't a symlink already exists. That's not
88- # supposed to happen.
89- # Write a warning and carry on.
90- print ("Warning: library location %s existed. It should have "
91- "been a symlink to %s, and it wasn't. This isn't supposed "
92- "to happen. Carrying on anyway, on the assumption that "
93- "you know what you're doing. If this is a problem, then "
94- "delete or rename %s.") % (u1_library_path, U1LIBRARYPATH,
95- u1_library_path)
96- self.u1_library_symlink = u1_library_path
97-
98+
99
100 class U1Source(RB.Source):
101 """A Rhythmbox source widget for the U1 Music Store."""
102@@ -248,7 +209,10 @@
103 def add_music_store_widget(self):
104 """Display the music store widget in Rhythmbox."""
105 # pylint: disable=E1101
106- self.add(self.browser)
107+ if self.browser.get_property('parent') is None:
108+ self.add(self.browser)
109+ else:
110+ self.browser.reparent(self)
111 self.browser.show()
112 self.show()
113 self.browser.set_property("visible", True)
114
115=== modified file 'ubuntuone/ubuntuone.py'
116--- ubuntuone/ubuntuone.py 2012-01-27 22:34:42 +0000
117+++ ubuntuone/ubuntuone.py 2012-03-20 18:41:31 +0000
118@@ -14,14 +14,13 @@
119 # <http://www.gnu.org/licenses/>.
120 """The Ubuntu One Rhythmbox plugin."""
121
122-import os
123-
124+from dirspec.basedir import xdg_config_home
125 # pylint: disable=E0611
126-from gi.repository import Gio, GLib, GObject, Peas
127+from gi.repository import Gio, GObject, Peas
128 # pylint: enable=E0611
129
130 # pylint: disable=W0403
131-from MusicStoreWidget import U1MusicStoreWidget
132+from MusicStoreWidget import U1MusicStoreWidget, U1LIBRARYPATH
133 # pylint: enable=W0403
134
135
136@@ -33,11 +32,6 @@
137 def __init__(self):
138 GObject.GObject.__init__(self)
139
140- # The folder where files get stored
141- self.u1_library_path_url = 'file://{0}'.format(
142- os.path.join(GLib.get_home_dir(),
143- '.ubuntuone',
144- 'Purchased from Ubuntu One'))
145 # RhythmDB settings so we can handle changes
146 self.rdbconf = Gio.Settings('org.gnome.rhythmbox.rhythmdb')
147 self.rdbconf.connect('changed::locations', self._locations_changed)
148@@ -48,8 +42,8 @@
149 def _locations_changed(self, *args, **kwargs):
150 """Handle the locations setting being changed."""
151 libraries = self.rdbconf.get_strv('locations')
152- if self.u1_library_path_url not in libraries:
153- libraries.append(self.u1_library_path_url)
154+ if U1LIBRARYPATH not in libraries:
155+ libraries.append(U1LIBRARYPATH)
156 self.rdbconf.set_strv('locations', libraries)
157
158 def do_activate(self):

Subscribers

People subscribed via source and target branches

to all changes: