[gimp] app: add GimpLanguageComboBox and use it from the Preferences dialog



commit d2804b48fbb009ee22134cb982de5e46684ca412
Author: Sven Neumann <sven gimp org>
Date:   Wed Dec 30 22:21:54 2009 +0100

    app: add GimpLanguageComboBox and use it from the Preferences dialog

 app/config/gimprc-blurbs.h         |    2 +-
 app/dialogs/preferences-dialog.c   |   25 +++++++
 app/widgets/Makefile.am            |    2 +
 app/widgets/gimplanguagecombobox.c |  126 ++++++++++++++++++++++++++++++++++++
 app/widgets/gimplanguagecombobox.h |   50 ++++++++++++++
 app/widgets/gimplanguageentry.c    |    7 ++-
 app/widgets/gimppropwidgets.c      |   99 ++++++++++++++++++++++++++++
 app/widgets/gimppropwidgets.h      |    6 +-
 app/widgets/widgets-types.h        |    5 +-
 9 files changed, 316 insertions(+), 6 deletions(-)
---
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 58cddcf..6a269af 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -199,7 +199,7 @@ N_("Sets the level of interpolation used for scaling and other " \
 "Sets the interpreter search path."
 
 #define LANGUAGE_BLURB \
-N_("Specifies the language to use.")
+N_("Specifies the language to use for the user interface.")
 
 #define LAST_OPENED_SIZE_BLURB \
 N_("How many recently opened image filenames to keep on the File menu.")
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 1f1dddb..742684d 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1224,6 +1224,22 @@ prefs_boolean_combo_box_add (GObject      *config,
 }
 
 static GtkWidget *
+prefs_language_combo_box_add (GObject      *config,
+                              const gchar  *property_name,
+                              GtkBox       *vbox)
+{
+  GtkWidget *combo = gimp_prop_language_combo_box_new (config, property_name);
+
+  if (combo)
+    {
+      gtk_box_pack_start (vbox, combo, FALSE, FALSE, 0);
+      gtk_widget_show (combo);
+    }
+
+  return combo;
+}
+
+static GtkWidget *
 prefs_spin_button_add (GObject      *config,
                        const gchar  *property_name,
                        gdouble       step_increment,
@@ -1622,6 +1638,15 @@ prefs_dialog_new (Gimp       *gimp,
                                      &top_iter,
                                      page_index++);
 
+  /*  Language  */
+
+  /*  Only add the language entry if the iso-codes package is available.  */
+#ifdef HAVE_ISO_CODES
+  vbox2 = prefs_frame_new (_("Language"), GTK_CONTAINER (vbox), FALSE);
+
+  prefs_language_combo_box_add (object, "language", GTK_BOX (vbox2));
+#endif
+
   /*  Previews  */
   vbox2 = prefs_frame_new (_("Previews"), GTK_CONTAINER (vbox), FALSE);
 
diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am
index 4b4e81b..1bc7db3 100644
--- a/app/widgets/Makefile.am
+++ b/app/widgets/Makefile.am
@@ -197,6 +197,8 @@ libappwidgets_a_sources = \
 	gimpimageview.h			\
 	gimpitemtreeview.c		\
 	gimpitemtreeview.h		\
+	gimplanguagecombobox.c		\
+	gimplanguagecombobox.h		\
 	gimplanguageentry.c		\
 	gimplanguageentry.h		\
 	gimplanguagestore.c		\
diff --git a/app/widgets/gimplanguagecombobox.c b/app/widgets/gimplanguagecombobox.c
new file mode 100644
index 0000000..a8a767b
--- /dev/null
+++ b/app/widgets/gimplanguagecombobox.c
@@ -0,0 +1,126 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimplanguagecombobox.c
+ * Copyright (C) 2009  Sven Neumann <sven gimp org>
+ *
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* GimpLanguageComboBox is a combo-box widget to select the user
+ * interface language.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <gtk/gtk.h>
+
+#include "widgets-types.h"
+
+#include "gimplanguagecombobox.h"
+#include "gimplanguagestore.h"
+
+
+struct _GimpLanguageComboBox
+{
+  GtkComboBox parent_instance;
+};
+
+
+G_DEFINE_TYPE (GimpLanguageComboBox,
+               gimp_language_combo_box, GTK_TYPE_COMBO_BOX)
+
+#define parent_class gimp_language_combo_box_parent_class
+
+
+static void
+gimp_language_combo_box_class_init (GimpLanguageComboBoxClass *klass)
+{
+}
+
+static void
+gimp_language_combo_box_init (GimpLanguageComboBox *combo)
+{
+  GtkCellRenderer *renderer;
+
+  renderer = gtk_cell_renderer_text_new ();
+
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
+  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
+                                  "text", GIMP_LANGUAGE_STORE_LANGUAGE,
+                                  NULL);
+}
+
+GtkWidget *
+gimp_language_combo_box_new (void)
+{
+  GtkWidget    *combo;
+  GtkListStore *store;
+
+  store = gimp_language_store_new ();
+
+  combo = g_object_new (GIMP_TYPE_LANGUAGE_COMBO_BOX,
+                        "model", store,
+                        NULL);
+
+  g_object_unref (store);
+
+  return combo;
+}
+
+gchar *
+gimp_language_combo_box_get_iso_code (GimpLanguageComboBox *combo)
+{
+  GtkTreeIter  iter;
+  gchar       *code;
+
+  g_return_val_if_fail (GIMP_IS_LANGUAGE_COMBO_BOX (combo), NULL);
+
+  if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
+    return NULL;
+
+  gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo)), &iter,
+                      GIMP_LANGUAGE_STORE_ISO_639_1, &code,
+                      -1);
+
+  return code;
+}
+
+gboolean
+gimp_language_combo_box_set_iso_code (GimpLanguageComboBox *combo,
+                                      const gchar          *code)
+{
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+
+  g_return_val_if_fail (GIMP_IS_LANGUAGE_COMBO_BOX (combo), FALSE);
+
+  if (! code || ! strlen (code))
+    {
+      gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+      return TRUE;
+    }
+
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+
+  if (gimp_language_store_lookup (GIMP_LANGUAGE_STORE (model), code, &iter))
+    {
+      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
+      return TRUE;
+    }
+
+  return FALSE;
+}
diff --git a/app/widgets/gimplanguagecombobox.h b/app/widgets/gimplanguagecombobox.h
new file mode 100644
index 0000000..cfc645e
--- /dev/null
+++ b/app/widgets/gimplanguagecombobox.h
@@ -0,0 +1,50 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimplanguagecombobox.h
+ * Copyright (C) 2009  Sven Neumann <sven gimp org>
+ *
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_LANGUAGE_COMBO_BOX_H__
+#define __GIMP_LANGUAGE_COMBO_BOX_H__
+
+
+#define GIMP_TYPE_LANGUAGE_COMBO_BOX            (gimp_language_combo_box_get_type ())
+#define GIMP_LANGUAGE_COMBO_BOX(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_LANGUAGE_COMBO_BOX, GimpLanguageComboBox))
+#define GIMP_LANGUAGE_COMBO_BOX_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_LANGUAGE_COMBO_BOX, GimpLanguageComboBoxClass))
+#define GIMP_IS_LANGUAGE_COMBO_BOX(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_LANGUAGE_COMBO_BOX))
+#define GIMP_IS_LANGUAGE_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_LANGUAGE_COMBO_BOX))
+#define GIMP_LANGUAGE_COMBO_BOX_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_LANGUAGE_COMBO_BOX, GimpLanguageComboBoxClass))
+
+
+typedef struct _GimpLanguageComboBoxClass  GimpLanguageComboBoxClass;
+
+struct _GimpLanguageComboBoxClass
+{
+  GtkComboBoxClass  parent_class;
+};
+
+
+GType       gimp_language_combo_box_get_type     (void) G_GNUC_CONST;
+
+GtkWidget * gimp_language_combo_box_new          (void);
+
+gchar     * gimp_language_combo_box_get_iso_code (GimpLanguageComboBox *combo);
+gboolean    gimp_language_combo_box_set_iso_code (GimpLanguageComboBox *combo,
+                                                  const gchar          *code);
+
+
+#endif  /* __GIMP_LANGUAGE_COMBO_BOX_H__ */
diff --git a/app/widgets/gimplanguageentry.c b/app/widgets/gimplanguageentry.c
index 01d859f..a296777 100644
--- a/app/widgets/gimplanguageentry.c
+++ b/app/widgets/gimplanguageentry.c
@@ -18,6 +18,11 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/* GimpLanguageEntry is an entry widget that provides completion on
+ * translated language names. It is suited for specifying the language
+ * a text is written in.
+ */
+
 #include "config.h"
 
 #include <string.h>
@@ -26,8 +31,8 @@
 
 #include "widgets-types.h"
 
-#include "gimplanguagestore.h"
 #include "gimplanguageentry.h"
+#include "gimplanguagestore.h"
 
 
 enum
diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c
index 7724b15..21a9de3 100644
--- a/app/widgets/gimppropwidgets.c
+++ b/app/widgets/gimppropwidgets.c
@@ -39,6 +39,7 @@
 
 #include "gimpcolorpanel.h"
 #include "gimpdnd.h"
+#include "gimplanguagecombobox.h"
 #include "gimplanguageentry.h"
 #include "gimpscalebutton.h"
 #include "gimpview.h"
@@ -821,6 +822,104 @@ gimp_prop_number_pair_entry_number_pair_user_override_notify (GtkWidget
 }
 
 
+/************************/
+/*  language combo-box  */
+/************************/
+
+static void   gimp_prop_language_combo_box_callback (GtkWidget  *combo,
+                                                     GObject    *config);
+static void   gimp_prop_language_combo_box_notify   (GObject    *config,
+                                                     GParamSpec *param_spec,
+                                                     GtkWidget  *combo);
+
+GtkWidget *
+gimp_prop_language_combo_box_new (GObject     *config,
+                                  const gchar *property_name)
+{
+  GParamSpec *param_spec;
+  GtkWidget  *combo;
+  gchar      *value;
+
+  param_spec = check_param_spec_w (config, property_name,
+                                   G_TYPE_PARAM_STRING, G_STRFUNC);
+  if (! param_spec)
+    return NULL;
+
+  combo = gimp_language_combo_box_new ();
+
+  g_object_get (config,
+                property_name, &value,
+                NULL);
+
+  gimp_language_combo_box_set_iso_code (GIMP_LANGUAGE_COMBO_BOX (combo), value);
+  g_free (value);
+
+  set_param_spec (G_OBJECT (combo), combo, param_spec);
+
+  g_signal_connect (combo, "changed",
+                    G_CALLBACK (gimp_prop_language_combo_box_callback),
+                    config);
+
+  connect_notify (config, property_name,
+                  G_CALLBACK (gimp_prop_language_combo_box_notify),
+                  combo);
+
+  return combo;
+}
+
+static void
+gimp_prop_language_combo_box_callback (GtkWidget *combo,
+                                       GObject   *config)
+{
+  GParamSpec *param_spec;
+  gchar      *code;
+
+  param_spec = get_param_spec (G_OBJECT (combo));
+  if (! param_spec)
+    return;
+
+  code = gimp_language_combo_box_get_iso_code (GIMP_LANGUAGE_COMBO_BOX (combo));
+
+  g_signal_handlers_block_by_func (config,
+                                   gimp_prop_language_combo_box_notify,
+                                   combo);
+
+  g_object_set (config,
+                param_spec->name, code,
+                NULL);
+
+  g_signal_handlers_unblock_by_func (config,
+                                     gimp_prop_language_combo_box_notify,
+                                     combo);
+
+  g_free (code);
+}
+
+static void
+gimp_prop_language_combo_box_notify (GObject    *config,
+                                     GParamSpec *param_spec,
+                                     GtkWidget  *combo)
+{
+  gchar *value;
+
+  g_object_get (config,
+                param_spec->name, &value,
+                NULL);
+
+  g_signal_handlers_block_by_func (combo,
+                                   gimp_prop_language_combo_box_callback,
+                                   config);
+
+  gimp_language_combo_box_set_iso_code (GIMP_LANGUAGE_COMBO_BOX (combo), value);
+
+  g_signal_handlers_unblock_by_func (combo,
+                                     gimp_prop_language_combo_box_callback,
+                                     config);
+
+  g_free (value);
+}
+
+
 /********************/
 /*  language entry  */
 /********************/
diff --git a/app/widgets/gimppropwidgets.h b/app/widgets/gimppropwidgets.h
index 2b95c74..7493fb4 100644
--- a/app/widgets/gimppropwidgets.h
+++ b/app/widgets/gimppropwidgets.h
@@ -80,8 +80,10 @@ GtkWidget * gimp_prop_number_pair_entry_new
 
 /*  GParamString  */
 
-GtkWidget * gimp_prop_language_entry_new  (GObject     *config,
-                                           const gchar *property_name);
+GtkWidget * gimp_prop_language_combo_box_new (GObject     *config,
+                                              const gchar *property_name);
+GtkWidget * gimp_prop_language_entry_new     (GObject     *config,
+                                              const gchar *property_name);
 
 
 /*  A view on all of an object's properties  */
diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h
index 5c9ddf5..5301955 100644
--- a/app/widgets/widgets-types.h
+++ b/app/widgets/widgets-types.h
@@ -171,10 +171,11 @@ typedef struct _GimpHistogramBox             GimpHistogramBox;
 typedef struct _GimpHistogramView            GimpHistogramView;
 typedef struct _GimpImageCommentEditor       GimpImageCommentEditor;
 typedef struct _GimpImageParasiteView        GimpImageParasiteView;
-typedef struct _GimpImagePropView            GimpImagePropView;
 typedef struct _GimpImageProfileView         GimpImageProfileView;
-typedef struct _GimpLanguageStore            GimpLanguageStore;
+typedef struct _GimpImagePropView            GimpImagePropView;
+typedef struct _GimpLanguageComboBox         GimpLanguageComboBox;
 typedef struct _GimpLanguageEntry            GimpLanguageEntry;
+typedef struct _GimpLanguageStore            GimpLanguageStore;
 typedef struct _GimpMessageBox               GimpMessageBox;
 typedef struct _GimpOverlayBox               GimpOverlayBox;
 typedef struct _GimpProgressBox              GimpProgressBox;



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