1
# Copyright (C) 2009-2012 Canonical, Ltd.
3
# This library is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU Lesser General Public License
5
# version 3.0 as published by the Free Software Foundation.
7
# This library is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU Lesser General Public License version 3.0 for more details.
12
# You should have received a copy of the GNU Lesser General Public
13
# License along with this library. If not, see
14
# <http://www.gnu.org/licenses/>.
15
"""The Ubuntu One Rhythmbox plugin."""
19
# pylint: disable=E0611
20
from gi.repository import Gio, GLib, GObject, Peas
21
# pylint: enable=E0611
23
# pylint: disable=W0403
24
from MusicStoreWidget import U1MusicStoreWidget
25
# pylint: enable=W0403
28
class UbuntuOnePlugin (GObject.GObject, Peas.Activatable):
29
"""Ubuntu One integration for Rhythmbox."""
30
__gtype_name__ = 'UbuntuOnePlugin'
31
object = GObject.property(type=GObject.GObject)
34
GObject.GObject.__init__(self)
36
# The folder where files get stored
37
self.u1_library_path_url = 'file://{0}'.format(
38
os.path.join(GLib.get_home_dir(),
40
'Purchased from Ubuntu One'))
41
# RhythmDB settings so we can handle changes
42
self.rdbconf = Gio.Settings('org.gnome.rhythmbox.rhythmdb')
43
self.rdbconf.connect('changed::locations', self._locations_changed)
45
# The Music Store itself
46
self.music_store_widget = U1MusicStoreWidget(plugin=self)
48
def _locations_changed(self, *args, **kwargs):
49
"""Handle the locations setting being changed."""
50
libraries = self.rdbconf.get_strv('locations')
51
if self.u1_library_path_url not in libraries:
52
libraries.append(self.u1_library_path_url)
53
self.rdbconf.set_strv('locations', libraries)
55
def do_activate(self):
56
"""Plug-in startup."""
57
# Add the Ubuntu One purchased music directory if not already added
58
self._locations_changed()
59
self.music_store_widget.activate(self.object)
61
def do_deactivate(self):
62
"""Plug-in shutdown."""
63
self.music_store_widget.deactivate(self.object)