-
Notifications
You must be signed in to change notification settings - Fork 5
/
RhythmboxFullscreenPrefs.py
149 lines (124 loc) · 5.33 KB
/
RhythmboxFullscreenPrefs.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- Mode: python; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-
#
# Copyright (C) 2013 - Benjamin Bach <benjamin@overtag.dk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
import os
from gi.repository import Gio # @UnresolvedImport
from gi.repository import GObject # @UnresolvedImport
from gi.repository import Gtk # @UnresolvedImport
from gi.repository import PeasGtk # @UnresolvedImport
import rb # @UnresolvedImport
SCHEMA_PATH = 'org.gnome.rhythmbox.plugins.rhythmboxfullscreen'
GLIB_DIR = "/usr/share/glib-2.0/schemas/"
class GSetting:
'''
This class manages the different settings that the plugins has to
access to read or write.
'''
# storage for the instance reference
__instance = None
class __impl:
""" Implementation of the singleton interface """
# below public variables and methods that can be called for GSetting
def __init__(self):
'''
Initializes the singleton interface, assigning all the constants
used to access the plugin's settings.
'''
source = Gio.SettingsSchemaSource.get_default()
if not source.lookup(SCHEMA_PATH, True):
print("Trying to run a gksudo to get the schema installed")
os.system(
'gksudo --message "Rhythmbox Fullscreen view needs to install a glib xml schema for saving preferences. Please type in your admin password. Afterwards, restart Rhythmbox." cp "%s" "%s"' % (
rb.find_plugin_file(self, "schema/org.gnome.rhythmbox.plugins.rhythmboxfullscreen.gschema.xml"),
GLIB_DIR)
)
os.system('gksudo --message "Compiling new glib schemas" glib-compile-schemas "%s"' % GLIB_DIR)
raise Exception("No glib xml schema installed")
self.Path = self._enum(PLUGIN=SCHEMA_PATH)
self.PluginKey = self._enum(USE_WINDOW='use-window')
self.setting = {}
def get_setting(self, path):
'''
Return an instance of Gio.Settings pointing at the selected path.
'''
try:
setting = self.setting[path]
except:
self.setting[path] = Gio.Settings(path)
setting = self.setting[path]
return setting
def get_value(self, path, key):
'''
Return the value saved on key from the settings path.
'''
return self.get_setting(path)[key]
def set_value(self, path, key, value):
'''
Set the passed value to key in the settings path.
'''
self.get_setting(path)[key] = value
def _enum(self, **enums):
'''
Create an enumn.
'''
return type('Enum', (), enums)
def __init__(self):
""" Create singleton instance """
# Check whether we already have an instance
if GSetting.__instance is None:
# Create and remember instance
GSetting.__instance = GSetting.__impl()
# Store instance reference as the only member in the handle
self.__dict__['_GSetting__instance'] = GSetting.__instance
def __getattr__(self, attr):
""" Delegate access to implementation """
return getattr(self.__instance, attr)
def __setattr__(self, attr, value):
""" Delegate access to implementation """
return setattr(self.__instance, attr, value)
class Preferences(GObject.Object, PeasGtk.Configurable):
'''
Preferences for the Fullscreen Plugin. It holds the settings for
the plugin and also is the responsible of creating the preferences dialog.
'''
__gtype_name__ = 'FullscreenPreferences'
object = GObject.property(type=GObject.Object) # @ReservedAssignment
def __init__(self):
'''
Initialises the preferences, getting an instance of the settings saved
by Gio.
'''
GObject.Object.__init__(self)
gs = GSetting()
self.settings = gs.get_setting(gs.Path.PLUGIN)
def do_create_configure_widget(self):
'''
Creates the plugin's preferences dialog
'''
# create the ui
builder = Gtk.Builder()
builder.add_from_file(
rb.find_plugin_file(self, 'ui/rhythmbox_fullscreen_prefs.ui')
)
builder.connect_signals(self)
gs = GSetting()
# bind the toggles to the settings
use_window = builder.get_object('use_window_checkbox')
self.settings.bind(gs.PluginKey.USE_WINDOW,
use_window, 'active', Gio.SettingsBindFlags.DEFAULT)
# return the dialog
return builder.get_object('maingrid')