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