-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
79 lines (70 loc) · 2.6 KB
/
plugin.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'''
5th march 2017 sunday
file=plugin.py lang=python3.5.2
'''
# imports
import rb
from gi.repository import GObject, Peas, RB, Gio, Gtk
import dropbox
from source import DropboxSource
from lib import DropboxLibrary
'''
attributes
object
a reference to the shell object
source
contains all entries of songs from dropbox
'''
class DropboxPlugin(GObject.Object, Peas.Activatable):
'''attributes'''
# the following object is a reference to the shell object
__gtype_name = 'DropboxPlugin'
object = GObject.property(type=GObject.GObject)
#source = None
def __init__(self):
# inherit from GObject.GObject
GObject.Object.__init__(self)
'''
about
called by rhythmbox when the plugin is activated. it creates the plugin's
source and connects signals to manage the plugin's preferences
'''
def do_activate(self):
print("plugin activating...")
#self.do_deactivate()
# get a reference to the DropboxPlugin object
shell = self.object
# add folder dropbox-music/icons for getting the icon
rb.append_plugin_source_path(self, 'icons')
# get a database reference for shell database
db = shell.props.db # the RB.RhythmDB
# query model for sorting by artist, album...
# new_empty() constructs a new empty query model
model = RB.RhythmDBQueryModel.new_empty(db)
# setup dropbox source
# GObject.new() takes * parameters
# a. object_type <- this is my source
# b. parameters <- can be multiple
# parameters is an array of GObject.Parameter
self.source = GObject.new(DropboxLibrary,
shell=shell,
name=_('Dropbox'),
query_model=model,
plugin=self,
icon=Gio.ThemedIcon.new('dropboxO'))
# setup source
print("setting up source...")
self.source.setup()
print("source setup completed...")
# get the group from the shell
group = RB.DisplayPageGroup.get_by_id('library')
# add the source to the music library
shell.append_display_page(self.source, group)
print("plugin activated...")
# deactivate the plugin
def do_deactivate(self):
print("deactivating the plugin...")
self.source.delete_thyself()
self.source = None # avoid dangling pointer
# register the source or it will produce segmentation fault later...
GObject.type_register(DropboxLibrary)