[gimp] app: add gimp_prop_profile_combo_box_new()



commit 20f5e25195c19a914268b82f8f1cd359d0c297fb
Author: Michael Natterer <mitch gimp org>
Date:   Sun May 8 20:38:46 2016 +0200

    app: add gimp_prop_profile_combo_box_new()
    
    and remove the same but less flexible code from the prefs dialog.

 app/dialogs/preferences-dialog.c |  143 +-------------------------------
 app/widgets/gimppropwidgets.c    |  171 +++++++++++++++++++++++++++++++++++++-
 app/widgets/gimppropwidgets.h    |    5 +
 3 files changed, 178 insertions(+), 141 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 09600c9..6899fe2 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -798,141 +798,6 @@ prefs_table_new (gint          rows,
   return table;
 }
 
-static void   prefs_profile_combo_notify (GObject                  *config,
-                                          const GParamSpec         *param_spec,
-                                          GimpColorProfileComboBox *combo);
-
-  static void
-prefs_profile_combo_changed (GimpColorProfileComboBox *combo,
-                             GObject                  *config)
-{
-  GFile *file = gimp_color_profile_combo_box_get_active_file (combo);
-  gchar *path = NULL;
-
-  if (file)
-    path = g_file_get_path (file);
-
-  if (! path)
-    g_signal_handlers_block_by_func (config,
-                                     prefs_profile_combo_notify,
-                                     combo);
-
-  g_object_set (config,
-                g_object_get_data (G_OBJECT (combo), "property-name"), path,
-                NULL);
-
-  if (! path)
-    g_signal_handlers_unblock_by_func (config,
-                                       prefs_profile_combo_notify,
-                                       combo);
-
-  g_free (path);
-
-  if (file)
-    g_object_unref (file);
-}
-
-static void
-prefs_profile_combo_notify (GObject                  *config,
-                            const GParamSpec         *param_spec,
-                            GimpColorProfileComboBox *combo)
-{
-  gchar *path;
-  GFile *file = NULL;
-
-  g_object_get (config,
-                param_spec->name, &path,
-                NULL);
-
-  if (path)
-    {
-      file = g_file_new_for_path (path);
-      g_free (path);
-    }
-
-  g_signal_handlers_block_by_func (combo,
-                                   prefs_profile_combo_changed,
-                                   config);
-
-  gimp_color_profile_combo_box_set_active_file (combo, file, NULL);
-
-  g_signal_handlers_unblock_by_func (combo,
-                                     prefs_profile_combo_changed,
-                                     config);
-
-  if (file)
-    g_object_unref (file);
-}
-
-static void
-prefs_profile_combo_add_tooltip (GtkWidget   *combo,
-                                 GObject     *config,
-                                 const gchar *property_name)
-{
-  GParamSpec  *param_spec;
-  const gchar *blurb;
-
-  param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
-                                             property_name);
-
-  blurb = g_param_spec_get_blurb (param_spec);
-
-  if (blurb)
-    gimp_help_set_help_data (combo, blurb, NULL);
-}
-
-static GtkWidget *
-prefs_profile_combo_box_new (GObject      *config,
-                             GtkListStore *store,
-                             const gchar  *label,
-                             const gchar  *property_name)
-{
-  GtkWidget *dialog;
-  GtkWidget *combo;
-  gchar     *path;
-  gchar     *notify_name;
-  GFile     *file = NULL;
-
-  dialog = gimp_color_profile_chooser_dialog_new (label, NULL,
-                                                  GTK_FILE_CHOOSER_ACTION_OPEN);
-
-  g_object_get (config, property_name, &path, NULL);
-
-  if (path)
-    {
-      file = g_file_new_for_path (path);
-      g_free (path);
-    }
-
-  combo = gimp_color_profile_combo_box_new_with_model (dialog,
-                                                       GTK_TREE_MODEL (store));
-
-  g_object_set_data (G_OBJECT (combo),
-                     "property-name", (gpointer) property_name);
-
-  gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
-                                                file, NULL);
-
-  if (file)
-    g_object_unref (file);
-
-  g_signal_connect (combo, "changed",
-                    G_CALLBACK (prefs_profile_combo_changed),
-                    config);
-
-  notify_name = g_strconcat ("notify::", property_name, NULL);
-
-  g_signal_connect_object (config, notify_name,
-                           G_CALLBACK (prefs_profile_combo_notify),
-                           combo, 0);
-
-  g_free (notify_name);
-
-  prefs_profile_combo_add_tooltip (combo, config, property_name);
-
-  return combo;
-}
-
 static GtkWidget *
 prefs_button_add (const gchar *icon_name,
                   const gchar *label,
@@ -1483,10 +1348,10 @@ prefs_dialog_new (Gimp       *gimp,
 
     for (i = 0; i < G_N_ELEMENTS (profiles); i++)
       {
-        button = prefs_profile_combo_box_new (color_config,
-                                              store,
-                                              gettext (profiles[i].fs_label),
-                                              profiles[i].property_name);
+        button = gimp_prop_profile_combo_box_new (color_config,
+                                                  profiles[i].property_name,
+                                                  store,
+                                                  gettext (profiles[i].fs_label));
 
         gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
                                    gettext (profiles[i].label), 0.0, 0.5,
diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c
index cb25f05..5d00e26 100644
--- a/app/widgets/gimppropwidgets.c
+++ b/app/widgets/gimppropwidgets.c
@@ -68,11 +68,11 @@ static GParamSpec * find_param_spec    (GObject     *object,
                                         const gchar *strloc);
 static GParamSpec * check_param_spec   (GObject     *object,
                                         const gchar *property_name,
-                                        GType         type,
+                                        GType        type,
                                         const gchar *strloc);
 static GParamSpec * check_param_spec_w (GObject     *object,
                                         const gchar *property_name,
-                                        GType         type,
+                                        GType        type,
                                         const gchar *strloc);
 
 static void         connect_notify     (GObject     *config,
@@ -1586,6 +1586,173 @@ gimp_prop_language_entry_notify (GObject    *config,
 }
 
 
+/***********************/
+/*  profile combo box  */
+/***********************/
+
+static void   gimp_prop_profile_combo_callback (GimpColorProfileComboBox *combo,
+                                                GObject                  *config);
+static void   gimp_prop_profile_combo_notify   (GObject                  *config,
+                                                const GParamSpec         *param_spec,
+                                                GimpColorProfileComboBox *combo);
+
+GtkWidget *
+gimp_prop_profile_combo_box_new  (GObject      *config,
+                                  const gchar  *property_name,
+                                  GtkListStore *profile_store,
+                                  const gchar  *dialog_title)
+{
+  GParamSpec *param_spec;
+  GtkWidget  *dialog;
+  GtkWidget  *combo;
+  GFile      *file = NULL;
+
+  param_spec = check_param_spec_w (config, property_name,
+                                   G_TYPE_PARAM_STRING, G_STRFUNC);
+  if (! param_spec)
+    {
+      param_spec = check_param_spec_w (config, property_name,
+                                       G_TYPE_PARAM_OBJECT, G_STRFUNC);
+      if (! param_spec)
+        return NULL;
+    }
+
+  dialog = gimp_color_profile_chooser_dialog_new (dialog_title, NULL,
+                                                  GTK_FILE_CHOOSER_ACTION_OPEN);
+
+  if (G_IS_PARAM_SPEC_STRING (param_spec))
+    {
+      gchar *path;
+
+      g_object_get (config, property_name, &path, NULL);
+
+      if (path)
+        {
+          file = g_file_new_for_path (path);
+          g_free (path);
+        }
+    }
+  else
+    {
+      g_object_get (config, property_name, &file, NULL);
+    }
+
+  if (profile_store)
+    combo = gimp_color_profile_combo_box_new_with_model (dialog,
+                                                         GTK_TREE_MODEL (profile_store));
+  else
+    combo = gimp_color_profile_combo_box_new (dialog, /* FIXME */ NULL);
+
+  gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
+                                                file, NULL);
+
+  if (file)
+    g_object_unref (file);
+
+  set_param_spec (G_OBJECT (combo), combo, param_spec);
+
+  g_signal_connect (combo, "changed",
+                    G_CALLBACK (gimp_prop_profile_combo_callback),
+                    config);
+
+  connect_notify (config, property_name,
+                  G_CALLBACK (gimp_prop_profile_combo_notify),
+                  combo);
+
+  return combo;
+}
+
+static void
+gimp_prop_profile_combo_callback (GimpColorProfileComboBox *combo,
+                                  GObject                  *config)
+{
+  GParamSpec *param_spec;
+  GFile      *file;
+
+  param_spec = get_param_spec (G_OBJECT (combo));
+  if (! param_spec)
+    return;
+
+  file = gimp_color_profile_combo_box_get_active_file (combo);
+
+  if (! file)
+    g_signal_handlers_block_by_func (config,
+                                     gimp_prop_profile_combo_notify,
+                                     combo);
+
+  if (G_IS_PARAM_SPEC_STRING (param_spec))
+    {
+      gchar *path = NULL;
+
+      if (file)
+        path = g_file_get_path (file);
+
+      g_object_set (config,
+                    param_spec->name, path,
+                    NULL);
+
+      g_free (path);
+    }
+  else
+    {
+      g_object_set (config,
+                    param_spec->name, file,
+                    NULL);
+    }
+
+  if (! file)
+    g_signal_handlers_unblock_by_func (config,
+                                       gimp_prop_profile_combo_notify,
+                                       combo);
+
+  if (file)
+    g_object_unref (file);
+}
+
+static void
+gimp_prop_profile_combo_notify (GObject                  *config,
+                                const GParamSpec         *param_spec,
+                                GimpColorProfileComboBox *combo)
+{
+  GFile *file = NULL;
+
+  if (G_IS_PARAM_SPEC_STRING (param_spec))
+    {
+      gchar *path;
+
+      g_object_get (config,
+                    param_spec->name, &path,
+                    NULL);
+
+      if (path)
+        {
+          file = g_file_new_for_path (path);
+          g_free (path);
+        }
+    }
+  else
+    {
+      g_object_get (config,
+                    param_spec->name, &file,
+                    NULL);
+
+    }
+
+  g_signal_handlers_block_by_func (combo,
+                                   gimp_prop_profile_combo_callback,
+                                   config);
+
+  gimp_color_profile_combo_box_set_active_file (combo, file, NULL);
+
+  g_signal_handlers_unblock_by_func (combo,
+                                     gimp_prop_profile_combo_callback,
+                                     config);
+
+  if (file)
+    g_object_unref (file);
+}
+
+
 /*****************/
 /*  icon picker  */
 /*****************/
diff --git a/app/widgets/gimppropwidgets.h b/app/widgets/gimppropwidgets.h
index 233b6f7..8592ffa 100644
--- a/app/widgets/gimppropwidgets.h
+++ b/app/widgets/gimppropwidgets.h
@@ -109,6 +109,11 @@ GtkWidget * gimp_prop_language_combo_box_new (GObject      *config,
 GtkWidget * gimp_prop_language_entry_new     (GObject      *config,
                                               const gchar  *property_name);
 
+GtkWidget * gimp_prop_profile_combo_box_new  (GObject      *config,
+                                              const gchar  *property_name,
+                                              GtkListStore *profile_store,
+                                              const gchar  *dialog_title);
+
 GtkWidget * gimp_prop_icon_picker_new        (GimpViewable *viewable,
                                               Gimp         *gimp);
 


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