[eog] EogPreferencesDialog: Convert to GtkBuilder template



commit f96947cf5749a78cdd3848ed8bc5e7bfe883d0b0
Author: Felix Riemann <friemann gnome org>
Date:   Sat May 3 20:22:31 2014 +0200

    EogPreferencesDialog: Convert to GtkBuilder template
    
    Also embed the plugin manager into the template directly.

 data/Makefile.am               |    2 +-
 data/eog-preferences-dialog.ui |   24 +++--
 src/eog-preferences-dialog.c   |  205 +++++++++++++++++++++-------------------
 src/eog-preferences-dialog.h   |    7 +-
 src/eog-window.c               |    4 +-
 src/eog.gresource.xml          |    1 +
 6 files changed, 129 insertions(+), 114 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 4099708..96c63cd 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -26,7 +26,6 @@ gsettingsconvert_DATA = eog.convert
 uidir = $(pkgdatadir)
 ui_DATA = \
        eog-multiple-save-as-dialog.ui \
-       eog-preferences-dialog.ui \
        eog-toolbar.xml
 
 pkgconfigdir = $(libdir)/pkgconfig
@@ -37,6 +36,7 @@ EXTRA_DIST =                  \
        eog.css                 \
        eog-app-menu.xml        \
        eog-image-properties-dialog.ui  \
+       eog-preferences-dialog.ui \
        eog-ui.xml              \
        $(DESKTOP_IN_FILES)     \
        $(appdata_in_files)     \
diff --git a/data/eog-preferences-dialog.ui b/data/eog-preferences-dialog.ui
index 4b4044b..37bbcc3 100644
--- a/data/eog-preferences-dialog.ui
+++ b/data/eog-preferences-dialog.ui
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.0 -->
+<!-- Generated with glade 3.18.2 -->
 <interface>
-  <requires lib="gtk+" version="3.6"/>
+  <requires lib="gtk+" version="3.10"/>
+  <requires lib="libpeas-gtk" version="1.0"/>
   <object class="GtkAdjustment" id="adjustment1">
     <property name="lower">1</property>
     <property name="upper">100</property>
@@ -9,20 +10,18 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
-  <object class="GtkDialog" id="eog_preferences_dialog">
+  <template class="EogPreferencesDialog" parent="GtkDialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Preferences</property>
     <property name="type_hint">dialog</property>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
-        <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="layout_style">end</property>
             <child>
@@ -321,7 +320,7 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkColorButton" id="color_button">
+                                  <object class="GtkColorButton" id="transp_color_button">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
@@ -570,7 +569,16 @@
                 <property name="border_width">12</property>
                 <property name="orientation">vertical</property>
                 <child>
-                  <placeholder/>
+                  <object class="PeasGtkPluginManager" id="plugin_manager">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="orientation">vertical</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
                 </child>
               </object>
               <packing>
@@ -601,5 +609,5 @@
       <action-widget response="-11">help_button</action-widget>
       <action-widget response="-7">close_button</action-widget>
     </action-widgets>
-  </object>
+  </template>
 </interface>
diff --git a/src/eog-preferences-dialog.c b/src/eog-preferences-dialog.c
index d82b9af..d80c8b1 100644
--- a/src/eog-preferences-dialog.c
+++ b/src/eog-preferences-dialog.c
@@ -43,11 +43,27 @@
 struct _EogPreferencesDialogPrivate {
        GSettings     *view_settings;
        GSettings     *fullscreen_settings;
+
+       GtkWidget     *interpolate_check;
+       GtkWidget     *extrapolate_check;
+       GtkWidget     *autorotate_check;
+       GtkWidget     *bg_color_check;
+       GtkWidget     *bg_color_button;
+       GtkWidget     *color_radio;
+       GtkWidget     *checkpattern_radio;
+       GtkWidget     *background_radio;
+       GtkWidget     *transp_color_button;
+
+       GtkWidget     *upscale_check;
+       GtkWidget     *loop_check;
+       GtkWidget     *seconds_scale;
+
+       GtkWidget     *plugin_manager;
 };
 
 static GObject *instance = NULL;
 
-G_DEFINE_TYPE_WITH_PRIVATE (EogPreferencesDialog, eog_preferences_dialog, EOG_TYPE_DIALOG);
+G_DEFINE_TYPE_WITH_PRIVATE (EogPreferencesDialog, eog_preferences_dialog, GTK_TYPE_DIALOG);
 
 static gboolean
 pd_string_to_rgba_mapping (GValue   *value,
@@ -123,110 +139,122 @@ eog_preferences_response_cb (GtkDialog *dlg, gint res_id, gpointer data)
        }
 }
 
-static GObject *
-eog_preferences_dialog_constructor (GType type,
-                                   guint n_construct_properties,
-                                   GObjectConstructParam *construct_params)
+static void
+eog_preferences_dialog_class_init (EogPreferencesDialogClass *klass)
+{
+       GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
+
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/eog/ui/eog-preferences-dialog.ui");
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     interpolate_check);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     extrapolate_check);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     autorotate_check);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     bg_color_check);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     bg_color_button);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     color_radio);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     checkpattern_radio);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     background_radio);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     transp_color_button);
+
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     upscale_check);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     loop_check);
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     seconds_scale);
+
+       gtk_widget_class_bind_template_child_private (widget_class,
+                                                     EogPreferencesDialog,
+                                                     plugin_manager);
+}
 
+static void
+eog_preferences_dialog_init (EogPreferencesDialog *pref_dlg)
 {
        EogPreferencesDialogPrivate *priv;
-       GtkWidget *dlg;
-       GtkWidget *interpolate_check;
-       GtkWidget *extrapolate_check;
-       GtkWidget *autorotate_check;
-       GtkWidget *bg_color_check;
-       GtkWidget *bg_color_button;
-       GtkWidget *color_radio;
-       GtkWidget *checkpattern_radio;
-       GtkWidget *background_radio;
-       GtkWidget *color_button;
-       GtkWidget *upscale_check;
-       GtkWidget *loop_check;
-       GtkWidget *seconds_scale;
-       GtkWidget *plugin_manager;
-       GtkWidget *plugin_manager_container;
        GtkAdjustment *scale_adjustment;
-       GObject *object;
 
-       object = G_OBJECT_CLASS (eog_preferences_dialog_parent_class)->constructor
-                       (type, n_construct_properties, construct_params);
+       pref_dlg->priv = eog_preferences_dialog_get_instance_private (pref_dlg);
+       priv = pref_dlg->priv;
 
-       priv = EOG_PREFERENCES_DIALOG (object)->priv;
+       gtk_widget_init_template (GTK_WIDGET (pref_dlg));
 
        priv->view_settings = g_settings_new (EOG_CONF_VIEW);
        priv->fullscreen_settings = g_settings_new (EOG_CONF_FULLSCREEN);
 
-       eog_dialog_construct (EOG_DIALOG (object),
-                             "eog-preferences-dialog.ui",
-                             "eog_preferences_dialog");
-
-       eog_dialog_get_controls (EOG_DIALOG (object),
-                                "eog_preferences_dialog", &dlg,
-                                "interpolate_check", &interpolate_check,
-                                "extrapolate_check", &extrapolate_check,
-                                "autorotate_check", &autorotate_check,
-                                "bg_color_check", &bg_color_check,
-                                "bg_color_button", &bg_color_button,
-                                "color_radio", &color_radio,
-                                "checkpattern_radio", &checkpattern_radio,
-                                "background_radio", &background_radio,
-                                "color_button", &color_button,
-                                "upscale_check", &upscale_check,
-                                "loop_check", &loop_check,
-                                "seconds_scale", &seconds_scale,
-                                "plugin_manager_container", &plugin_manager_container,
-                                NULL);
-
-       g_signal_connect (G_OBJECT (dlg),
+       g_signal_connect (G_OBJECT (pref_dlg),
                          "response",
                          G_CALLBACK (eog_preferences_response_cb),
-                         dlg);
+                         pref_dlg);
 
        g_settings_bind (priv->view_settings, EOG_CONF_VIEW_INTERPOLATE,
-                        interpolate_check, "active", G_SETTINGS_BIND_DEFAULT);
+                        priv->interpolate_check, "active",
+                        G_SETTINGS_BIND_DEFAULT);
        g_settings_bind (priv->view_settings, EOG_CONF_VIEW_EXTRAPOLATE,
-                        extrapolate_check, "active", G_SETTINGS_BIND_DEFAULT);
+                        priv->extrapolate_check, "active",
+                        G_SETTINGS_BIND_DEFAULT);
        g_settings_bind (priv->view_settings, EOG_CONF_VIEW_AUTOROTATE,
-                        autorotate_check, "active", G_SETTINGS_BIND_DEFAULT);
+                        priv->autorotate_check, "active",
+                        G_SETTINGS_BIND_DEFAULT);
        g_settings_bind (priv->view_settings, EOG_CONF_VIEW_USE_BG_COLOR,
-                        bg_color_check, "active", G_SETTINGS_BIND_DEFAULT);
-
+                        priv->bg_color_check, "active",
+                        G_SETTINGS_BIND_DEFAULT);
        g_settings_bind_with_mapping (priv->view_settings,
                                      EOG_CONF_VIEW_BACKGROUND_COLOR,
-                                     bg_color_button, "rgba",
+                                     priv->bg_color_button, "rgba",
                                      G_SETTINGS_BIND_DEFAULT,
                                      pd_string_to_rgba_mapping,
                                      pd_rgba_to_string_mapping,
                                      NULL, NULL);
-
-       g_object_set_data (G_OBJECT (color_radio),
+       g_object_set_data (G_OBJECT (priv->color_radio),
                           GCONF_OBJECT_VALUE,
                           GINT_TO_POINTER (EOG_TRANSP_COLOR));
 
-       g_signal_connect (G_OBJECT (color_radio),
+       g_signal_connect (G_OBJECT (priv->color_radio),
                          "toggled",
                          G_CALLBACK (pd_transp_radio_toggle_cb),
                          priv->view_settings);
 
-       g_object_set_data (G_OBJECT (checkpattern_radio),
+       g_object_set_data (G_OBJECT (priv->checkpattern_radio),
                           GCONF_OBJECT_VALUE,
                           GINT_TO_POINTER (EOG_TRANSP_CHECKED));
 
-       g_signal_connect (G_OBJECT (checkpattern_radio),
+       g_signal_connect (G_OBJECT (priv->checkpattern_radio),
                          "toggled",
                          G_CALLBACK (pd_transp_radio_toggle_cb),
                          priv->view_settings);
 
-       g_object_set_data (G_OBJECT (background_radio),
+       g_object_set_data (G_OBJECT (priv->background_radio),
                           GCONF_OBJECT_VALUE,
                           GINT_TO_POINTER (EOG_TRANSP_BACKGROUND));
 
-       g_signal_connect (G_OBJECT (background_radio),
+       g_signal_connect (G_OBJECT (priv->background_radio),
                          "toggled",
                          G_CALLBACK (pd_transp_radio_toggle_cb),
                          priv->view_settings);
 
-       g_signal_connect (G_OBJECT (seconds_scale), "format-value",
+       g_signal_connect (G_OBJECT (priv->seconds_scale), "format-value",
                          G_CALLBACK (pd_seconds_scale_format_value_cb),
                          NULL);
 
@@ -234,75 +262,54 @@ eog_preferences_dialog_constructor (GType type,
                                     EOG_CONF_VIEW_TRANSPARENCY))
        {
        case EOG_TRANSP_COLOR:
-               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (color_radio), TRUE);
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->color_radio), TRUE);
                break;
        case EOG_TRANSP_CHECKED:
-               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkpattern_radio), TRUE);
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkpattern_radio), TRUE);
                break;
        default:
                // Log a warning and use EOG_TRANSP_BACKGROUND as fallback
                g_warn_if_reached();
        case EOG_TRANSP_BACKGROUND:
-               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (background_radio), TRUE);
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->background_radio), TRUE);
                break;
        }
 
        g_settings_bind_with_mapping (priv->view_settings,
                                      EOG_CONF_VIEW_TRANS_COLOR,
-                                     color_button, "rgba",
+                                     priv->transp_color_button, "rgba",
                                      G_SETTINGS_BIND_DEFAULT,
                                      pd_string_to_rgba_mapping,
                                      pd_rgba_to_string_mapping,
                                      NULL, NULL);
 
        g_settings_bind (priv->fullscreen_settings, EOG_CONF_FULLSCREEN_UPSCALE,
-                        upscale_check, "active", G_SETTINGS_BIND_DEFAULT);
+                        priv->upscale_check, "active",
+                        G_SETTINGS_BIND_DEFAULT);
 
        g_settings_bind (priv->fullscreen_settings, EOG_CONF_FULLSCREEN_LOOP,
-                        loop_check, "active", G_SETTINGS_BIND_DEFAULT);
+                        priv->loop_check, "active",
+                        G_SETTINGS_BIND_DEFAULT);
 
-       scale_adjustment = gtk_range_get_adjustment (GTK_RANGE (seconds_scale));
+       scale_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->seconds_scale));
 
        g_settings_bind (priv->fullscreen_settings, EOG_CONF_FULLSCREEN_SECONDS,
-                        scale_adjustment, "value", G_SETTINGS_BIND_DEFAULT);
-
-        plugin_manager = peas_gtk_plugin_manager_new (NULL);
-
-        g_assert (plugin_manager != NULL);
-
-        gtk_box_pack_start (GTK_BOX (plugin_manager_container),
-                            plugin_manager,
-                            TRUE,
-                            TRUE,
-                            0);
+                        scale_adjustment, "value",
+                        G_SETTINGS_BIND_DEFAULT);
 
-        gtk_widget_show_all (plugin_manager);
+       gtk_widget_show_all (priv->plugin_manager);
 
-       return object;
 }
 
-static void
-eog_preferences_dialog_class_init (EogPreferencesDialogClass *class)
-{
-       GObjectClass *g_object_class = (GObjectClass *) class;
-
-       g_object_class->constructor = eog_preferences_dialog_constructor;
-}
-
-static void
-eog_preferences_dialog_init (EogPreferencesDialog *pref_dlg)
-{
-       pref_dlg->priv = eog_preferences_dialog_get_instance_private (pref_dlg);
-}
-
-GObject *
-eog_preferences_dialog_get_instance (GtkWindow *parent)
+GtkWidget *eog_preferences_dialog_get_instance(GtkWindow *parent)
 {
        if (instance == NULL) {
                instance = g_object_new (EOG_TYPE_PREFERENCES_DIALOG,
-                                        "parent-window", parent,
                                         NULL);
        }
 
-       return instance;
+       if (parent)
+               gtk_window_set_transient_for (GTK_WINDOW (instance), parent);
+
+       return GTK_WIDGET(instance);
 }
diff --git a/src/eog-preferences-dialog.h b/src/eog-preferences-dialog.h
index e915d2e..91bfa9d 100644
--- a/src/eog-preferences-dialog.h
+++ b/src/eog-preferences-dialog.h
@@ -22,7 +22,6 @@
 #ifndef __EOG_PREFERENCES_DIALOG_H__
 #define __EOG_PREFERENCES_DIALOG_H__
 
-#include "eog-dialog.h"
 #include "eog-image.h"
 #include "eog-thumb-view.h"
 
@@ -44,20 +43,20 @@ typedef struct _EogPreferencesDialogPrivate EogPreferencesDialogPrivate;
 #define EOG_PREFERENCES_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  
EOG_TYPE_PREFERENCES_DIALOG, EogPreferencesDialogClass))
 
 struct _EogPreferencesDialog {
-       EogDialog dialog;
+       GtkDialog dialog;
 
        EogPreferencesDialogPrivate *priv;
 };
 
 struct _EogPreferencesDialogClass {
-       EogDialogClass parent_class;
+       GtkDialogClass parent_class;
 };
 
 G_GNUC_INTERNAL
 GType      eog_preferences_dialog_get_type       (void) G_GNUC_CONST;
 
 G_GNUC_INTERNAL
-GObject    *eog_preferences_dialog_get_instance          (GtkWindow   *parent);
+GtkWidget  *eog_preferences_dialog_get_instance          (GtkWindow   *parent);
 
 G_END_DECLS
 
diff --git a/src/eog-window.c b/src/eog-window.c
index 98c1539..5c0a12a 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -6177,13 +6177,13 @@ eog_window_show_about_dialog (EogWindow *window)
 void
 eog_window_show_preferences_dialog (EogWindow *window)
 {
-       GObject *pref_dlg;
+       GtkWidget *pref_dlg;
 
        g_return_if_fail (window != NULL);
 
        pref_dlg = eog_preferences_dialog_get_instance (GTK_WINDOW (window));
 
-       eog_dialog_show (EOG_DIALOG (pref_dlg));
+       gtk_widget_show (pref_dlg);
 }
 
 void
diff --git a/src/eog.gresource.xml b/src/eog.gresource.xml
index bf53694..a445e61 100644
--- a/src/eog.gresource.xml
+++ b/src/eog.gresource.xml
@@ -4,6 +4,7 @@
     <file>eog.css</file>
     <file compressed="true" preprocess="xml-stripblanks">eog-app-menu.xml</file>
     <file compressed="true" preprocess="xml-stripblanks">eog-image-properties-dialog.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">eog-preferences-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">eog-ui.xml</file>
   </gresource>
 </gresources>


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