[totem] Port Python plugins to GSettings



commit 551f901dd0ac62cc438b5b6d8590fef08688482a
Author: Philip Withnall <philip tecnocode co uk>
Date:   Wed Aug 18 22:59:07 2010 +0100

    Port Python plugins to GSettings

 configure.in                                       |    3 +
 po/POTFILES.in                                     |    3 +
 po/POTFILES.skip                                   |    3 +
 src/plugins/jamendo/Makefile.am                    |   15 ++++-
 src/plugins/jamendo/jamendo.convert                |    3 +
 src/plugins/jamendo/jamendo.py                     |   57 +++++---------------
 ...g.gnome.totem.plugins.jamendo.gschema.xml.in.in |   20 +++++++
 src/plugins/opensubtitles/Makefile.am              |   15 ++++-
 src/plugins/opensubtitles/opensubtitles.convert    |    2 +
 src/plugins/opensubtitles/opensubtitles.py         |   24 ++------
 ...e.totem.plugins.opensubtitles.gschema.xml.in.in |   10 ++++
 src/plugins/pythonconsole/Makefile.am              |   15 ++++-
 ...e.totem.plugins.pythonconsole.gschema.xml.in.in |   10 ++++
 src/plugins/pythonconsole/pythonconsole.convert    |    3 +
 src/plugins/pythonconsole/pythonconsole.py         |    8 ++--
 15 files changed, 116 insertions(+), 75 deletions(-)
---
diff --git a/configure.in b/configure.in
index edf32f3..23df7c1 100644
--- a/configure.in
+++ b/configure.in
@@ -798,6 +798,7 @@ src/plugins/lirc/Makefile
 src/plugins/media-player-keys/Makefile
 src/plugins/mythtv/Makefile
 src/plugins/opensubtitles/Makefile
+src/plugins/opensubtitles/org.gnome.totem.plugins.opensubtitles.gschema.xml.in
 src/plugins/properties/Makefile
 src/plugins/sidebar-test/Makefile
 src/plugins/skipto/Makefile
@@ -807,9 +808,11 @@ src/plugins/thumbnail/Makefile
 src/plugins/tracker/Makefile
 src/plugins/youtube/Makefile
 src/plugins/pythonconsole/Makefile
+src/plugins/pythonconsole/org.gnome.totem.plugins.pythonconsole.gschema.xml.in
 src/plugins/publish/Makefile
 src/plugins/publish/org.gnome.totem.plugins.publish.gschema.xml.in
 src/plugins/jamendo/Makefile
+src/plugins/jamendo/org.gnome.totem.plugins.jamendo.gschema.xml.in
 src/plugins/brasero-disc-recorder/Makefile
 src/plugins/chapters/Makefile
 src/backend/Makefile
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fba63df..67ccd5b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -59,6 +59,7 @@ src/plugins/iplayer/iplayer2.py
 [type: gettext/glade]src/plugins/jamendo/jamendo.ui
 [type: gettext/ini]src/plugins/jamendo/jamendo.totem-plugin.in
 src/plugins/jamendo/jamendo.py
+src/plugins/jamendo/org.gnome.totem.plugins.jamendo.gschema.xml.in.in
 [type: gettext/ini]src/plugins/lirc/lirc.totem-plugin.in
 src/plugins/lirc/totem-lirc.c
 [type: gettext/ini]src/plugins/media-player-keys/media-player-keys.totem-plugin.in
@@ -66,6 +67,7 @@ src/plugins/mythtv/totem-mythtv.c
 [type: gettext/glade]src/plugins/opensubtitles/opensubtitles.ui
 [type: gettext/ini]src/plugins/opensubtitles/opensubtitles.totem-plugin.in
 src/plugins/opensubtitles/opensubtitles.py
+src/plugins/opensubtitles/org.gnome.totem.plugins.opensubtitles.gschema.xml.in.in
 [type: gettext/ini]src/plugins/ontop/ontop.totem-plugin.in
 src/plugins/properties/totem-movie-properties.c
 src/plugins/properties/bacon-video-widget-properties.c
@@ -74,6 +76,7 @@ src/plugins/publish/org.gnome.totem.plugins.publish.gschema.xml.in.in
 src/plugins/publish/totem-publish.c
 [type: gettext/ini]src/plugins/publish/publish.totem-plugin.in
 [type: gettext/glade]src/plugins/publish/publish-plugin.ui
+src/plugins/pythonconsole/org.gnome.totem.plugins.pythonconsole.gschema.xml.in.in
 [type: gettext/ini]src/plugins/screensaver/screensaver.totem-plugin.in
 src/plugins/screensaver/totem-screensaver.c
 [type: gettext/ini]src/plugins/screenshot/screenshot.totem-plugin.in
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 980bbd4..40c2209 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -15,7 +15,10 @@ src/backend/gstscreenshot.c
 src/totem-video-indexer.c
 src/totem-video-thumbnailer.c
 src/plugins/iplayer/httplib2.py
+src/plugins/jamendo/org.gnome.totem.plugins.jamendo.gschema.xml.in
+src/plugins/opensubtitles/org.gnome.totem.plugins.opensubtitles.gschema.xml.in
 src/plugins/publish/org.gnome.totem.plugins.publish.gschema.xml.in
 src/plugins/publish/publish-plugin.glade
+src/plugins/pythonconsole/org.gnome.totem.plugins.pythonconsole.gschema.xml.in
 src/plugins/sample-python/sample-python.totem-plugin.in
 src/plugins/sample-vala/sample-vala.totem-plugin.in
diff --git a/src/plugins/jamendo/Makefile.am b/src/plugins/jamendo/Makefile.am
index f6fe181..0c30c7b 100644
--- a/src/plugins/jamendo/Makefile.am
+++ b/src/plugins/jamendo/Makefile.am
@@ -8,7 +8,16 @@ plugin_in_files = jamendo.totem-plugin.in
 plugin_DATA = $(plugin_in_files:.totem-plugin.in=.totem-plugin)
 ui_DATA = jamendo.ui
 
-EXTRA_DIST = $(plugin_in_files) $(ui_DATA) jamendo.py
+gsettings_SCHEMAS = org.gnome.totem.plugins.jamendo.gschema.xml
 
-CLEANFILES = $(plugin_DATA)
-DISTCLEANFILES = $(plugin_DATA)
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
+
+convertdir = $(datadir)/GConf/gsettings
+convert_DATA = jamendo.convert
+
+EXTRA_DIST = $(plugin_in_files) $(ui_DATA) jamendo.py org.gnome.totem.plugins.jamendo.gschema.xml.in.in jamendo.convert
+
+CLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
+DISTCLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
+MAINTAINERCLEANFILES = $(gsettings_SCHEMAS:.xml=.valid)
diff --git a/src/plugins/jamendo/jamendo.convert b/src/plugins/jamendo/jamendo.convert
new file mode 100644
index 0000000..5acafaa
--- /dev/null
+++ b/src/plugins/jamendo/jamendo.convert
@@ -0,0 +1,3 @@
+[org.gnome.totem.plugins.jamendo]
+num-per-page = /apps/totem/plugins/jamendo/num_per_page
+format = /apps/totem/plugins/jamendo/format
diff --git a/src/plugins/jamendo/jamendo.py b/src/plugins/jamendo/jamendo.py
index e0db439..8df3bc1 100644
--- a/src/plugins/jamendo/jamendo.py
+++ b/src/plugins/jamendo/jamendo.py
@@ -32,7 +32,7 @@ TODO:
 
 import os
 import gobject
-from gi.repository import GConf
+from gi.repository import Gio
 from gi.repository import Peas
 from gi.repository import PeasUI
 from gi.repository import Gtk
@@ -62,7 +62,6 @@ except ImportError:
 
 socket.setdefaulttimeout(30)
 gobject.threads_init()
-gconf_key = '/apps/totem/plugins/jamendo'
 
 class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasUI.Configurable):
     __gtype_name__ = 'JamendoPlugin'
@@ -82,8 +81,9 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasUI.Configurable):
         self.debug = True
         self.gstreamer_plugins_present = True
         self.totem = self.object
-        self.gconf = GConf.Client.get_default()
-        self.init_settings()
+        self.settings = Gio.Settings.new ('org.gnome.totem.plugins.jamendo')
+        self.settings.connect ('changed::format', self.on_format_changed)
+        self.settings.connect ('changed::num-per-page', self.on_num_per_page_changed)
 
     def do_activate(self):
         """
@@ -139,45 +139,29 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasUI.Configurable):
         """
         builder = Totem.plugin_load_interface ('jamendo', 'jamendo.ui', True, None, self)
         print builder
-        gconf = GConf.Client.get_default()
         config_widget = builder.get_object ('config_widget')
         config_widget.connect ('destroy', self.on_config_widget_destroy)
         print config_widget
-        format = gconf.get_string('%s/format' % gconf_key)
-        num_per_page = gconf.get_int('%s/num_per_page' % gconf_key)
+        format = self.settings.get_enum ('format')
+        num_per_page = self.settings.get_int ('num-per-page')
 
         combo = builder.get_object('preferred_format_combo')
-        combo.set_active(self.AUDIO_FORMATS.index(format))
-        combo.connect ('changed', self.on_preferred_format_combo_changed)
+        combo.set_active(format)
+        self.settings.bind ('format', combo, 'active', Gio.SettingsBindFlags.DEFAULT)
 
         spinbutton = builder.get_object('album_num_spinbutton')
         spinbutton.set_value(num_per_page)
-        spinbutton.connect ('value-changed', self.on_album_num_spinbutton_value_changed)
+        self.settings.bind ('num-per-page', spinbutton, 'value', Gio.SettingsBindFlags.DEFAULT)
 
         return config_widget
 
-    def on_preferred_format_combo_changed (self, combo):
-        """
-        Called when the preferred audio format combo box is changed in the configuration dialogue
-        """
-        gconf = GConf.Client.get_default()
-        format = self.AUDIO_FORMATS[combo.get_active()]
-        gconf.set_string('%s/format' % gconf_key, format)
+    def on_format_changed (self, settings, key)
+        JamendoService.AUDIO_FORMAT = self.settings.get_enum ('format')
 
-    def on_album_num_spinbutton_value_changed (self, spinbutton):
-        """
-        Called when the number-of-albums spinbutton is changed in the configuration dialogue
-        """
-        gconf = GConf.Client.get_default()
-        num_per_page = int(spinbutton.get_value())
-        gconf.set_int('%s/num_per_page' % gconf_key, num_per_page)
+    def on_num_per_page_changed (self, settings, key)
+        JamendoService.NUM_PER_PAGE = self.settings.get_int ('num-per-page')
 
     def on_config_widget_destroy (self, widget):
-        """
-        FIXME: The GConf stuff should be refactored so that it listens to notifications and doesn't update manually.
-        This function is hacky and should go away.
-        """
-        self.init_settings()
         try:
             self.reset()
         except:
@@ -207,21 +191,6 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasUI.Configurable):
             tv.get_model().clear()
         self._update_buttons_state()
 
-    def init_settings(self):
-        """
-        Initialize plugin settings.
-        """
-        format = self.gconf.get_string('%s/format' % gconf_key)
-        if not format:
-            format = 'ogg2'
-            self.gconf.set_string('%s/format' % gconf_key, format)
-        num_per_page = self.gconf.get_int('%s/num_per_page' % gconf_key)
-        if not num_per_page:
-            num_per_page = 10
-            self.gconf.set_int('%s/num_per_page' % gconf_key, num_per_page)
-        JamendoService.AUDIO_FORMAT = format
-        JamendoService.NUM_PER_PAGE = num_per_page
-
     def setup_treeviews(self):
         """
         Setup the 3 treeview: result, popular and latest
diff --git a/src/plugins/jamendo/org.gnome.totem.plugins.jamendo.gschema.xml.in.in b/src/plugins/jamendo/org.gnome.totem.plugins.jamendo.gschema.xml.in.in
new file mode 100644
index 0000000..4e61b21
--- /dev/null
+++ b/src/plugins/jamendo/org.gnome.totem.plugins.jamendo.gschema.xml.in.in
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+	<enum id="org.gnome.totem.plugins.jamendo.Format">
+		<value nick="ogg" value="0"/>
+		<value nick="mp3" value="1"/>
+	</enum>
+
+	<schema id="org.gnome.totem.plugins.jamendo" path="/apps/totem/plugins/jamendo/" gettext-domain="@GETTEXT_PACKAGE@">
+		<key name="num-per-page" type="u">
+			<default>10</default>
+			<_summary>Number of results per page</_summary>
+			<_description>The number of Jamendo search results to display in each page of results.</_description>
+		</key>
+		<key name="format" enum="org.gnome.totem.plugins.jamendo.Format">
+			<default>'ogg'</default>
+			<_summary>Audio format to download from Jamendo</_summary>
+			<_description>The preferred audio format to download tracks from Jamendo in.</_description>
+		</key>
+	</schema>
+</schemalist>
diff --git a/src/plugins/opensubtitles/Makefile.am b/src/plugins/opensubtitles/Makefile.am
index a53b983..b0f895b 100644
--- a/src/plugins/opensubtitles/Makefile.am
+++ b/src/plugins/opensubtitles/Makefile.am
@@ -9,7 +9,16 @@ plugin_in_files = opensubtitles.totem-plugin.in
 plugin_DATA = $(plugin_in_files:.totem-plugin.in=.totem-plugin)
 ui_DATA = opensubtitles.ui
 
-EXTRA_DIST = $(plugin_in_files) $(ui_DATA) opensubtitles.py hash.py
+gsettings_SCHEMAS = org.gnome.totem.plugins.opensubtitles.gschema.xml
 
-CLEANFILES = $(plugin_DATA)
-DISTCLEANFILES = $(plugin_DATA) 
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
+
+convertdir = $(datadir)/GConf/gsettings
+convert_DATA = opensubtitles.convert
+
+EXTRA_DIST = $(plugin_in_files) $(ui_DATA) opensubtitles.py hash.py org.gnome.totem.plugins.opensubtitles.gschema.xml.in.in opensubtitles.convert
+
+CLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
+DISTCLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
+MAINTAINERCLEANFILES = $(gsettings_SCHEMAS:.xml=.valid)
diff --git a/src/plugins/opensubtitles/opensubtitles.convert b/src/plugins/opensubtitles/opensubtitles.convert
new file mode 100644
index 0000000..7a8e6f8
--- /dev/null
+++ b/src/plugins/opensubtitles/opensubtitles.convert
@@ -0,0 +1,2 @@
+[org.gnome.totem.plugins.opensubtitles]
+language = /apps/totem/plugins/opensubtitles/language
diff --git a/src/plugins/opensubtitles/opensubtitles.py b/src/plugins/opensubtitles/opensubtitles.py
index cf767e4..6907609 100644
--- a/src/plugins/opensubtitles/opensubtitles.py
+++ b/src/plugins/opensubtitles/opensubtitles.py
@@ -2,7 +2,6 @@ from gi.repository import Peas
 from gi.repository import Gtk
 from gi.repository import Gdk
 from gi.repository import Gio
-from gi.repository import GConf
 from gi.repository import Pango
 from gi.repository import Totem
 import gobject
@@ -302,9 +301,7 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
     def __init__(self):
         self.dialog = None
         self.totem = self.object
-        self.gconf_client = GConf.Client.get_default()
-        self.GCONF_BASE_DIR = "/apps/totem/plugins/opensubtitles/"
-        self.GCONF_LANGUAGE = "language"
+        self.settings = Gio.Settings.new ('org.gnome.totem.plugins.opensubtitles')
 
     # totem.Plugin methods
 
@@ -357,7 +354,10 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
         combobox.pack_start(renderer, True)
         combobox.add_attribute(renderer, 'text', 0)
 
-        self.model.lang = self.gconf_get_str (self.GCONF_BASE_DIR + self.GCONF_LANGUAGE, self.model.lang)
+        lang = self.settings.get_string ('language')
+        if lang is not None:
+            self.model.lang = lang
+
         for lang in LANGUAGES_STR:
             it = languages.append(lang)
             if LANGUAGES[lang[1]] == self.model.lang:
@@ -643,8 +643,7 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
     def on_combobox__changed(self, combobox):
         iter = combobox.get_active_iter()
         self.model.lang = LANGUAGES[combobox.get_model().get_value(iter, 1)]
-        self.gconf_set_str(self.GCONF_BASE_DIR + self.GCONF_LANGUAGE,
-                           self.model.lang)
+        self.settings.set_string('language', self.model.lang)
 
     def on_close_clicked(self, data):
         self.dialog.destroy()
@@ -661,14 +660,3 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
 
         self.os_get_results()
 
-    def gconf_get_str(self, key, default = ""):
-        val = self.gconf_client.get(key)
-        
-        if val is not None and val.type == gconf.VALUE_STRING:
-            return val.get_string()
-        else:
-            return default
-
-    def gconf_set_str(self, key, val):
-        self.gconf_client.set_string(key, val)
-
diff --git a/src/plugins/opensubtitles/org.gnome.totem.plugins.opensubtitles.gschema.xml.in.in b/src/plugins/opensubtitles/org.gnome.totem.plugins.opensubtitles.gschema.xml.in.in
new file mode 100644
index 0000000..c25d334
--- /dev/null
+++ b/src/plugins/opensubtitles/org.gnome.totem.plugins.opensubtitles.gschema.xml.in.in
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+	<schema id="org.gnome.totem.plugins.opensubtitles" path="/apps/totem/plugins/opensubtitles/" gettext-domain="@GETTEXT_PACKAGE@">
+		<key name="language" type="s">
+			<default>''</default>
+			<_summary>Subtitle language</_summary>
+			<_description>The language to search for subtitles for movies in.</_description>
+		</key>
+	</schema>
+</schemalist>
diff --git a/src/plugins/pythonconsole/Makefile.am b/src/plugins/pythonconsole/Makefile.am
index f755b42..88bd68d 100644
--- a/src/plugins/pythonconsole/Makefile.am
+++ b/src/plugins/pythonconsole/Makefile.am
@@ -7,7 +7,16 @@ plugin_in_files = pythonconsole.totem-plugin.in
 
 plugin_DATA = $(plugin_in_files:.totem-plugin.in=.totem-plugin)
 
-EXTRA_DIST = $(plugin_in_files) pythonconsole.py console.py
+gsettings_SCHEMAS = org.gnome.totem.plugins.pythonconsole.gschema.xml
 
-CLEANFILES = $(plugin_DATA)
-DISTCLEANFILES = $(plugin_DATA)
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
+
+convertdir = $(datadir)/GConf/gsettings
+convert_DATA = pythonconsole.convert
+
+EXTRA_DIST = $(plugin_in_files) pythonconsole.py console.py org.gnome.totem.plugins.pythonconsole.gschema.xml.in.in pythonconsole.convert
+
+CLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
+DISTCLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
+MAINTAINERCLEANFILES = $(gsettings_SCHEMAS:.xml=.valid)
diff --git a/src/plugins/pythonconsole/org.gnome.totem.plugins.pythonconsole.gschema.xml.in.in b/src/plugins/pythonconsole/org.gnome.totem.plugins.pythonconsole.gschema.xml.in.in
new file mode 100644
index 0000000..c5ed1be
--- /dev/null
+++ b/src/plugins/pythonconsole/org.gnome.totem.plugins.pythonconsole.gschema.xml.in.in
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+	<schema id="org.gnome.totem.plugins.pythonconsole" path="/apps/totem/plugins/pythonconsole/" gettext-domain="@GETTEXT_PACKAGE@">
+		<key name="rpdb2-password" type="s">
+			<default>''</default>
+			<_summary>rpdb2 password</_summary>
+			<_description>A password to protect the rpdb2 server for debugging Totem from unauthorized remote access. If this is empty, a default of 'totem' will be used.</_description>
+		</key>
+	</schema>
+</schemalist>
diff --git a/src/plugins/pythonconsole/pythonconsole.convert b/src/plugins/pythonconsole/pythonconsole.convert
new file mode 100644
index 0000000..5acafaa
--- /dev/null
+++ b/src/plugins/pythonconsole/pythonconsole.convert
@@ -0,0 +1,3 @@
+[org.gnome.totem.plugins.jamendo]
+num-per-page = /apps/totem/plugins/jamendo/num_per_page
+format = /apps/totem/plugins/jamendo/format
diff --git a/src/plugins/pythonconsole/pythonconsole.py b/src/plugins/pythonconsole/pythonconsole.py
index f02461e..ed88aef 100644
--- a/src/plugins/pythonconsole/pythonconsole.py
+++ b/src/plugins/pythonconsole/pythonconsole.py
@@ -39,7 +39,7 @@ __all__ = ('PythonConsole', 'OutFile')
 from gi.repository import Peas
 from gi.repository import Gtk
 from gi.repository import Totem
-from gi.repository import GConf
+from gi.repository import Gio
 import gobject
 try:
 	import rpdb2
@@ -126,11 +126,11 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 			self.window.grab_focus()
 
 	def enable_debugging(self, action):
-		msg = _("After you press OK, Totem will wait until you connect to it with winpdb or rpdb2. If you have not set a debugger password in GConf, it will use the default password ('totem').")
+		msg = _("After you press OK, Totem will wait until you connect to it with winpdb or rpdb2. If you have not set a debugger password in DConf, it will use the default password ('totem').")
 		dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonType.OK_CANCEL, msg)
 		if dialog.run() == Gtk.ResponseType.OK:
-			gconfclient = GConf.Client.get_default()
-			password = gconfclient.get_string('/apps/totem/plugins/pythonconsole/rpdb2_password') or "totem"
+			settings = Gio.Settings.new ('org.gnome.totem.plugins.pythonconsole')
+			password = settings.get_string('rpdb2-password') or "totem"
 			def start_debugger(password):
 				rpdb2.start_embedded_debugger(password)
 				return False



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]