[gnome-control-center] printers: Move callbacks into .ui file



commit b842a33316f76e0ee7eb40365ef7f17488e1ff53
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Nov 23 12:18:05 2018 +1300

    printers: Move callbacks into .ui file

 panels/printers/pp-options-dialog.c  | 30 ++++++++++--------------------
 panels/printers/pp-options-dialog.ui |  7 +++++--
 2 files changed, 15 insertions(+), 22 deletions(-)
---
diff --git a/panels/printers/pp-options-dialog.c b/panels/printers/pp-options-dialog.c
index 6039262f1..10abd3147 100644
--- a/panels/printers/pp-options-dialog.c
+++ b/panels/printers/pp-options-dialog.c
@@ -49,7 +49,6 @@ struct _PpOptionsDialog {
   GtkNotebook      *notebook;
   GtkSpinner       *spinner;
   GtkStack         *stack;
-  GtkButton        *test_page_button;
 
   gchar       *printer_name;
 
@@ -483,15 +482,13 @@ tab_add (PpOptionsDialog *self,
 }
 
 static void
-category_selection_changed_cb (GtkTreeSelection *selection,
-                               gpointer          user_data)
+category_selection_changed_cb (PpOptionsDialog *self)
 {
-  PpOptionsDialog *self = (PpOptionsDialog *) user_data;
-  GtkTreeModel    *model;
-  GtkTreeIter      iter;
-  gint             id = -1;
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+  gint          id = -1;
 
-  if (gtk_tree_selection_get_selected (selection, &model, &iter))
+  if (gtk_tree_selection_get_selected (self->categories_selection, &model, &iter))
     {
       gtk_tree_model_get (model, &iter,
                          CATEGORY_IDS_COLUMN, &id,
@@ -679,10 +676,6 @@ populate_options_real (PpOptionsDialog *self)
   tab_add (self, C_("Printer Option Group", "Advanced"), advanced_tab_grid);
 
   /* Select the first option group */
-  g_signal_connect (self->categories_selection,
-                    "changed",
-                    G_CALLBACK (category_selection_changed_cb), self);
-
   if ((model = gtk_tree_view_get_model (self->categories_treeview)) != NULL &&
       gtk_tree_model_get_iter_first (model, &iter))
     gtk_tree_selection_select_iter (self->categories_selection, &iter);
@@ -842,11 +835,9 @@ print_test_page_cb (GObject      *source_object,
 }
 
 static void
-test_page_cb (GtkButton *button,
-              gpointer   user_data)
+test_page_cb (PpOptionsDialog *self)
 {
-  PpOptionsDialog *self = (PpOptionsDialog*) user_data;
-  gint             i;
+  gint i;
 
   if (self->printer_name)
     {
@@ -918,9 +909,6 @@ pp_options_dialog_new (gchar   *printer_name,
 
   self->sensitive = sensitive;
 
-  /* connect signals */
-  g_signal_connect (self->test_page_button, "clicked", G_CALLBACK (test_page_cb), self);
-
   gtk_window_set_title (GTK_WINDOW (self), printer_name);
 
   self->populating_dialog = TRUE;
@@ -975,7 +963,9 @@ pp_options_dialog_class_init (PpOptionsDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, PpOptionsDialog, notebook);
   gtk_widget_class_bind_template_child (widget_class, PpOptionsDialog, spinner);
   gtk_widget_class_bind_template_child (widget_class, PpOptionsDialog, stack);
-  gtk_widget_class_bind_template_child (widget_class, PpOptionsDialog, test_page_button);
+
+  gtk_widget_class_bind_template_callback (widget_class, category_selection_changed_cb);
+  gtk_widget_class_bind_template_callback (widget_class, test_page_cb);
 }
 
 void
diff --git a/panels/printers/pp-options-dialog.ui b/panels/printers/pp-options-dialog.ui
index 3efaa3a72..79eaf888e 100644
--- a/panels/printers/pp-options-dialog.ui
+++ b/panels/printers/pp-options-dialog.ui
@@ -13,9 +13,10 @@
       <object class="GtkHeaderBar">
         <property name="visible">True</property>
         <child>
-          <object class="GtkButton" id="test_page_button">
+          <object class="GtkButton">
             <property name="visible">True</property>
             <property name="label" translatable="yes" comments="Translators: This button triggers the 
printing of a test page.">Test Page</property>
+            <signal name="clicked" handler="test_page_cb" object="PpOptionsDialog" swapped="yes"/>
           </object>
           <packing>
             <property name="pack_type">start</property>
@@ -54,7 +55,9 @@
                             <property name="can_focus">True</property>
                             <property name="headers_visible">False</property>
                             <child internal-child="selection">
-                              <object class="GtkTreeSelection" id="categories_selection"/>
+                              <object class="GtkTreeSelection" id="categories_selection">
+                                <signal name="changed" handler="category_selection_changed_cb" 
object="PpOptionsDialog" swapped="yes"/>
+                              </object>
                             </child>
                           </object>
                         </child>


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