~ubuntu-branches/ubuntu/precise/rhythmbox-ubuntuone/precise-proposed

« back to all changes in this revision

Viewing changes to ubuntuone/ubuntuone.py

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2012-02-03 17:51:00 UTC
  • Revision ID: package-import@ubuntu.com-20120203175100-oethgj2ksx2b1yef
Tags: upstream-2.99.3
ImportĀ upstreamĀ versionĀ 2.99.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009-2012 Canonical, Ltd.
 
2
#
 
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.
 
6
#
 
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.
 
11
#
 
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."""
 
16
 
 
17
import os
 
18
 
 
19
# pylint: disable=E0611
 
20
from gi.repository import Gio, GLib, GObject, Peas
 
21
# pylint: enable=E0611
 
22
 
 
23
# pylint: disable=W0403
 
24
from MusicStoreWidget import U1MusicStoreWidget
 
25
# pylint: enable=W0403
 
26
 
 
27
 
 
28
class UbuntuOnePlugin (GObject.GObject, Peas.Activatable):
 
29
    """Ubuntu One integration for Rhythmbox."""
 
30
    __gtype_name__ = 'UbuntuOnePlugin'
 
31
    object = GObject.property(type=GObject.GObject)
 
32
 
 
33
    def __init__(self):
 
34
        GObject.GObject.__init__(self)
 
35
 
 
36
        # The folder where files get stored
 
37
        self.u1_library_path_url = 'file://{0}'.format(
 
38
            os.path.join(GLib.get_home_dir(),
 
39
                         '.ubuntuone',
 
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)
 
44
 
 
45
        # The Music Store itself
 
46
        self.music_store_widget = U1MusicStoreWidget(plugin=self)
 
47
 
 
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)
 
54
 
 
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)
 
60
 
 
61
    def do_deactivate(self):
 
62
        """Plug-in shutdown."""
 
63
        self.music_store_widget.deactivate(self.object)