[gtranslator] Port open tran plugin to gsettings.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Port open tran plugin to gsettings.
- Date: Tue, 7 Sep 2010 22:51:46 +0000 (UTC)
commit 9b9a3745fb911d0789b5993c72091e5e660cad47
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Sep 8 00:26:46 2010 +0200
Port open tran plugin to gsettings.
configure.ac | 1 +
plugins/open-tran/Makefile.am | 6 +
plugins/open-tran/gtr-open-tran-dialog.ui | 26 +----
plugins/open-tran/gtr-open-tran-panel.c | 67 +++++++-----
plugins/open-tran/gtr-open-tran-panel.h | 9 +-
plugins/open-tran/gtr-open-tran-plugin.c | 110 +++++---------------
...gtranslator.plugins.open-tran.gschema.xml.in.in | 14 +++
...ator.plugins.source-code-view.gschema.xml.in.in | 4 +-
8 files changed, 96 insertions(+), 141 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ae99399..8af4bbd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -279,6 +279,7 @@ plugins/fullscreen/Makefile
plugins/insert-params/Makefile
plugins/insert-tags/Makefile
plugins/open-tran/Makefile
+plugins/open-tran/org.gnome.gtranslator.plugins.open-tran.gschema.xml.in
plugins/source-code-view/Makefile
plugins/source-code-view/org.gnome.gtranslator.plugins.source-code-view.gschema.xml.in
src/Makefile
diff --git a/plugins/open-tran/Makefile.am b/plugins/open-tran/Makefile.am
index a5e0859..4a0105a 100644
--- a/plugins/open-tran/Makefile.am
+++ b/plugins/open-tran/Makefile.am
@@ -53,6 +53,12 @@ plugin_in_files = gtr-open-tran.gtranslator-plugin.desktop.in
plugin_DATA = $(plugin_in_files:.gtranslator-plugin.desktop.in=.gtranslator.plugin)
+gsettings_SCHEMAS = org.gnome.gtranslator.plugins.open-tran.gschema.xml
+
+ INTLTOOL_XML_NOMERGE_RULE@
+
+ GSETTINGS_RULES@
+
EXTRA_DIST = $(ui_DATA) $(pixmaps__DATA) $(plugin_in_files)
CLEANFILES = $(plugin_DATA)
diff --git a/plugins/open-tran/gtr-open-tran-dialog.ui b/plugins/open-tran/gtr-open-tran-dialog.ui
index ab89902..fa33f1a 100644
--- a/plugins/open-tran/gtr-open-tran-dialog.ui
+++ b/plugins/open-tran/gtr-open-tran-dialog.ui
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
@@ -13,14 +13,12 @@
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkVBox" id="main_box">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">12</property>
- <property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label1">
@@ -47,7 +45,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="invisible_char">●</property>
+ <property name="invisible_char">â??</property>
</object>
</child>
</object>
@@ -79,7 +77,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="invisible_char">●</property>
+ <property name="invisible_char">â??</property>
</object>
</child>
</object>
@@ -100,7 +98,7 @@
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
- <property name="label">gtk-cancel</property>
+ <property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -113,21 +111,6 @@
<property name="position">0</property>
</packing>
</child>
- <child>
- <object class="GtkButton" id="ok_button">
- <property name="label">gtk-ok</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
</object>
<packing>
<property name="expand">False</property>
@@ -139,7 +122,6 @@
</child>
<action-widgets>
<action-widget response="-6">cancel_button</action-widget>
- <action-widget response="-5">ok_button</action-widget>
</action-widgets>
</object>
</interface>
diff --git a/plugins/open-tran/gtr-open-tran-panel.c b/plugins/open-tran/gtr-open-tran-panel.c
index 7490bfe..f9778e9 100644
--- a/plugins/open-tran/gtr-open-tran-panel.c
+++ b/plugins/open-tran/gtr-open-tran-panel.c
@@ -30,7 +30,6 @@
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>
-#include <gconf/gconf-client.h>
#include <gtk/gtk.h>
#include <libsoup/soup.h>
@@ -50,32 +49,33 @@
#define FEDORA_ICON PIXMAPSDIR"/fedora.png"
GTR_PLUGIN_DEFINE_TYPE (GtrOpenTranPanel, gtr_open_tran_panel, GTK_TYPE_VBOX)
- struct _GtrOpenTranPanelPrivate
- {
- GConfClient *gconf_client;
- GtkWidget *treeview;
- GtkListStore *store;
+struct _GtrOpenTranPanelPrivate
+{
+ GSettings *settings;
- GtkWidget *entry;
+ GtkWidget *treeview;
+ GtkListStore *store;
- SoupSession *session;
+ GtkWidget *entry;
- GtrWindow *window;
+ SoupSession *session;
- gchar *text;
- };
+ GtrWindow *window;
- enum
- {
- ICON_COLUMN,
- TEXT_COLUMN,
- N_COLUMNS
- };
+ gchar *text;
+};
- static void
- show_error_dialog (GtrWindow * parent,
- const gchar * message_format, ...)
+enum
+{
+ ICON_COLUMN,
+ TEXT_COLUMN,
+ N_COLUMNS
+};
+
+static void
+show_error_dialog (GtrWindow * parent,
+ const gchar * message_format, ...)
{
gchar *msg = NULL;
va_list args;
@@ -306,9 +306,9 @@ open_connection (GtrOpenTranPanel * panel,
static void
entry_activate_cb (GtkEntry * entry, GtrOpenTranPanel * panel)
{
- const gchar *entry_text = NULL;
- const gchar *search_code = NULL;
- const gchar *own_code = NULL;
+ const gchar *entry_text;
+ gchar *search_code;
+ gchar *own_code;
gtk_list_store_clear (panel->priv->store);
@@ -320,8 +320,8 @@ entry_activate_cb (GtkEntry * entry, GtrOpenTranPanel * panel)
return;
}
- search_code = gconf_client_get_string (panel->priv->gconf_client,
- SEARCH_CODE_KEY, NULL);
+ search_code = g_settings_get_string (panel->priv->settings,
+ GTR_SETTINGS_SEARCH_CODE);
if (!search_code)
{
show_error_dialog (panel->priv->window,
@@ -329,8 +329,10 @@ entry_activate_cb (GtkEntry * entry, GtrOpenTranPanel * panel)
return;
}
- own_code = gconf_client_get_string (panel->priv->gconf_client,
- OWN_CODE_KEY, NULL);
+ g_free (search_code);
+
+ own_code = g_settings_get_string (panel->priv->settings,
+ GTR_SETTINGS_OWN_CODE);
if (!own_code)
{
show_error_dialog (panel->priv->window,
@@ -339,6 +341,8 @@ entry_activate_cb (GtkEntry * entry, GtrOpenTranPanel * panel)
return;
}
+ g_free (own_code);
+
open_connection (panel, entry_text, search_code, own_code);
}
@@ -431,7 +435,7 @@ gtr_open_tran_panel_init (GtrOpenTranPanel * panel)
panel->priv = GTR_OPEN_TRAN_PANEL_GET_PRIVATE (panel);
- panel->priv->gconf_client = gconf_client_get_default ();
+ panel->priv->settings = g_settings_new ("org.gnome.gtranslator.plugins.open-tran");
panel->priv->session = soup_session_async_new ();
gtr_open_tran_panel_draw (panel);
@@ -447,6 +451,13 @@ gtr_open_tran_panel_dispose (GObject * object)
g_object_unref (panel->priv->session);
panel->priv->session = NULL;
}
+
+ if (panel->priv->settings != NULL)
+ {
+ g_object_unref (panel->priv->settings);
+ panel->priv->settings = NULL;
+ }
+
G_OBJECT_CLASS (gtr_open_tran_panel_parent_class)->dispose (object);
}
diff --git a/plugins/open-tran/gtr-open-tran-panel.h b/plugins/open-tran/gtr-open-tran-panel.h
index fb1dcf3..1d62991 100644
--- a/plugins/open-tran/gtr-open-tran-panel.h
+++ b/plugins/open-tran/gtr-open-tran-panel.h
@@ -35,10 +35,11 @@ G_BEGIN_DECLS
#define GTR_IS_OPEN_TRAN_PANEL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTR_TYPE_OPEN_TRAN_PANEL))
#define GTR_IS_OPEN_TRAN_PANEL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTR_TYPE_OPEN_TRAN_PANEL))
#define GTR_OPEN_TRAN_PANEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTR_TYPE_OPEN_TRAN_PANEL, GtrOpenTranPanelClass))
-/* Gconf keys */
-#define OPEN_TRAN_BASE_KEY "/apps/gtranslator/plugins/open-tran"
-#define SEARCH_CODE_KEY OPEN_TRAN_BASE_KEY "/search_code"
-#define OWN_CODE_KEY OPEN_TRAN_BASE_KEY "/own_code"
+
+/* GSettings keys */
+#define GTR_SETTINGS_SEARCH_CODE "search_code"
+#define GTR_SETTINGS_OWN_CODE "own_code"
+
/* Private structure type */
typedef struct _GtrOpenTranPanelPrivate GtrOpenTranPanelPrivate;
diff --git a/plugins/open-tran/gtr-open-tran-plugin.c b/plugins/open-tran/gtr-open-tran-plugin.c
index 0a0aba1..f6e6877 100644
--- a/plugins/open-tran/gtr-open-tran-plugin.c
+++ b/plugins/open-tran/gtr-open-tran-plugin.c
@@ -29,7 +29,6 @@
#include "gtr-utils.h"
#include <glib/gi18n-lib.h>
-#include <gconf/gconf-client.h>
#include <gtk/gtk.h>
#define OPEN_TRAN_PLUGIN_ICON "open-tran.png"
@@ -42,7 +41,7 @@
struct _GtrOpenTranPluginPrivate
{
- GConfClient *gconf_client;
+ GSettings *settings;
/* Dialog stuff */
GtkWidget *dialog;
@@ -63,27 +62,27 @@ GTR_PLUGIN_REGISTER_TYPE_WITH_CODE (GtrOpenTranPlugin,
gtr_open_tran_panel_register_type
(module);
)
- static void gtr_open_tran_plugin_init (GtrOpenTranPlugin * plugin)
+
+static void
+gtr_open_tran_plugin_init (GtrOpenTranPlugin * plugin)
{
plugin->priv = GTR_OPEN_TRAN_PLUGIN_GET_PRIVATE (plugin);
- plugin->priv->gconf_client = gconf_client_get_default ();
-
- gconf_client_add_dir (plugin->priv->gconf_client,
- OPEN_TRAN_BASE_KEY,
- GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ plugin->priv->settings = g_settings_new ("org.gnome.gtranslator.plugins.open-tran");
}
static void
-gtr_open_tran_plugin_finalize (GObject * object)
+gtr_open_tran_plugin_dispose (GObject * object)
{
GtrOpenTranPlugin *plugin = GTR_OPEN_TRAN_PLUGIN (object);
- gconf_client_suggest_sync (plugin->priv->gconf_client, NULL);
-
- g_object_unref (G_OBJECT (plugin->priv->gconf_client));
+ if (plugin->priv->settings)
+ {
+ g_object_unref (plugin->priv->settings);
+ plugin->priv->settings = NULL;
+ }
- G_OBJECT_CLASS (gtr_open_tran_plugin_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtr_open_tran_plugin_parent_class)->dispose (object);
}
@@ -121,34 +120,6 @@ impl_deactivate (GtrPlugin * plugin, GtrWindow * window)
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
}
-static void
-get_custom_code (GtrOpenTranPlugin * plugin, gboolean own_code)
-{
- gchar *type;
- gchar *code;
-
- if (own_code)
- type = g_strdup (OWN_CODE_KEY);
- else
- type = g_strdup (SEARCH_CODE_KEY);
-
- code = gconf_client_get_string (plugin->priv->gconf_client, type, NULL);
-
- g_free (type);
-
- if (!code && !own_code)
- code = g_strdup ("en");
- else if (!code && own_code)
- code = g_strdup ("gl"); //Why gl? Just because i want.
-
- if (!own_code)
- gtk_entry_set_text (GTK_ENTRY (plugin->priv->search_code_entry), code);
- else
- gtk_entry_set_text (GTK_ENTRY (plugin->priv->own_code_entry), code);
-
- g_free (code);
-}
-
static GtkWidget *
get_configuration_dialog (GtrOpenTranPlugin * plugin)
{
@@ -178,57 +149,26 @@ get_configuration_dialog (GtrOpenTranPlugin * plugin)
//FIXME: We have to show a dialog
}
- get_custom_code (plugin, FALSE);
- get_custom_code (plugin, TRUE);
-
- return plugin->priv->dialog;
-}
-
-static void
-ok_button_pressed (GtrOpenTranPlugin * plugin)
-{
- const gchar *search_code;
- const gchar *own_code;
-
- /* We have to get the text from the entries */
- search_code =
- gtk_entry_get_text (GTK_ENTRY (plugin->priv->search_code_entry));
- own_code = gtk_entry_get_text (GTK_ENTRY (plugin->priv->own_code_entry));
-
- /* Now we store the data in gconf */
- if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
- SEARCH_CODE_KEY, NULL))
- return;
-
- gconf_client_set_string (plugin->priv->gconf_client,
- SEARCH_CODE_KEY, search_code, NULL);
+ g_settings_bind (plugin->priv->settings,
+ GTR_SETTINGS_OWN_CODE,
+ plugin->priv->own_code_entry,
+ "text",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
- if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
- OWN_CODE_KEY, NULL))
- return;
+ g_settings_bind (plugin->priv->settings,
+ GTR_SETTINGS_SEARCH_CODE,
+ plugin->priv->search_code_entry,
+ "text",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
- gconf_client_set_string (plugin->priv->gconf_client,
- OWN_CODE_KEY, own_code, NULL);
+ return plugin->priv->dialog;
}
static void
configure_dialog_response_cb (GtkWidget * widget,
gint response, GtrOpenTranPlugin * plugin)
{
- switch (response)
- {
- case GTK_RESPONSE_OK:
- {
- ok_button_pressed (plugin);
-
- gtk_widget_destroy (plugin->priv->dialog);
- break;
- }
- case GTK_RESPONSE_CANCEL:
- {
- gtk_widget_destroy (plugin->priv->dialog);
- }
- }
+ gtk_widget_destroy (plugin->priv->dialog);
}
static GtkWidget *
@@ -254,7 +194,7 @@ gtr_open_tran_plugin_class_init (GtrOpenTranPluginClass * klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtrPluginClass *plugin_class = GTR_PLUGIN_CLASS (klass);
- object_class->finalize = gtr_open_tran_plugin_finalize;
+ object_class->dispose = gtr_open_tran_plugin_dispose;
plugin_class->activate = impl_activate;
plugin_class->deactivate = impl_deactivate;
diff --git a/plugins/open-tran/org.gnome.gtranslator.plugins.open-tran.gschema.xml.in.in b/plugins/open-tran/org.gnome.gtranslator.plugins.open-tran.gschema.xml.in.in
new file mode 100644
index 0000000..6de8a8d
--- /dev/null
+++ b/plugins/open-tran/org.gnome.gtranslator.plugins.open-tran.gschema.xml.in.in
@@ -0,0 +1,14 @@
+<schemalist>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gtranslator.plugins.open-tran" path="/apps/gtranslator/plugins/open-tran/">
+ <key name="search-code" type="s">
+ <default>'en'</default>
+ <_summary>Search Code</_summary>
+ <_description>The language code to search for</_description>
+ </key>
+ <key name="own-code" type="s">
+ <default>'gl'</default>
+ <_summary>Own Code</_summary>
+ <_description>The language code in which you want the results</_description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/plugins/source-code-view/org.gnome.gtranslator.plugins.source-code-view.gschema.xml.in.in b/plugins/source-code-view/org.gnome.gtranslator.plugins.source-code-view.gschema.xml.in.in
index cb7cc32..b2adda0 100644
--- a/plugins/source-code-view/org.gnome.gtranslator.plugins.source-code-view.gschema.xml.in.in
+++ b/plugins/source-code-view/org.gnome.gtranslator.plugins.source-code-view.gschema.xml.in.in
@@ -6,12 +6,12 @@
<_description>Whether use the system editor to show the source code</_description>
</key>
<key name="program-cmd" type="s">
- <default>gedit</default>
+ <default>'gedit'</default>
<_summary>The Editor to Launch</_summary>
<_description>The command to launch the editor you want to use</_description>
</key>
<key name="line-cmd" type="s">
- <default>+</default>
+ <default>'+'</default>
<_summary>Arguments for the Command</_summary>
<_description>Arguments to pass to the program command and select the line</_description>
</key>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]