[console/zbrown/quick-ci-check: 2/4] tab: use {binding, signal} groups




commit 692401e173524bd72ef96558f4dbd58616deb493
Author: Zander Brown <zbrown gnome org>
Date:   Thu Aug 25 16:14:48 2022 +0100

    tab: use {binding,signal} groups
    
    replace connect_terminal with a :terminal property, allowing us to move
    more stuff to GtkBuilder
    
    introduce :settings which we connect the binding group to, thus makin
    set_pages superflous
    
    Generally make a bunch of code redundant, or moved to declarative

 src/kgx-application.c |   1 +
 src/kgx-pages.c       |   4 -
 src/kgx-simple-tab.c  |   4 +-
 src/kgx-simple-tab.ui |   1 +
 src/kgx-tab.c         | 231 +++++++++++++++++++-------------------------------
 src/kgx-tab.h         |   4 -
 src/kgx-tab.ui        |  10 +++
 7 files changed, 102 insertions(+), 153 deletions(-)
---
diff --git a/src/kgx-application.c b/src/kgx-application.c
index 48a20fa..d1a965c 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -764,6 +764,7 @@ kgx_application_add_terminal (KgxApplication *self,
 
   tab = g_object_new (KGX_TYPE_SIMPLE_TAB,
                       "application", self,
+                      "settings", self->settings,
                       "initial-work-dir", directory,
                       "command", shell != NULL ? shell : argv,
                       "tab-title", title,
diff --git a/src/kgx-pages.c b/src/kgx-pages.c
index a4c4938..3f43f17 100644
--- a/src/kgx-pages.c
+++ b/src/kgx-pages.c
@@ -381,8 +381,6 @@ page_attached (AdwTabView *view,
                     "signal::died", G_CALLBACK (died), self,
                     "signal::zoom", G_CALLBACK (zoom), self,
                     NULL);
-
-  kgx_tab_set_pages (tab, self);
 }
 
 
@@ -402,8 +400,6 @@ page_detached (AdwTabView *view,
 
   priv = kgx_pages_get_instance_private (self);
 
-  kgx_tab_set_pages (tab, NULL);
-
   g_signal_handlers_disconnect_by_data (tab, self);
 
   if (adw_tab_view_get_n_pages (ADW_TAB_VIEW (priv->view)) == 0) {
diff --git a/src/kgx-simple-tab.c b/src/kgx-simple-tab.c
index a62826b..42b8389 100644
--- a/src/kgx-simple-tab.c
+++ b/src/kgx-simple-tab.c
@@ -138,7 +138,7 @@ clear_wait_data (gpointer data)
   g_clear_weak_pointer (&self->self);
 
   g_free (self);
-} 
+}
 
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WaitData, clear_wait_data)
@@ -361,6 +361,4 @@ static void
 kgx_simple_tab_init (KgxSimpleTab *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
-
-  kgx_tab_connect_terminal (KGX_TAB (self), KGX_TERMINAL (self->terminal));
 }
diff --git a/src/kgx-simple-tab.ui b/src/kgx-simple-tab.ui
index e5bc986..aeb38d0 100644
--- a/src/kgx-simple-tab.ui
+++ b/src/kgx-simple-tab.ui
@@ -2,6 +2,7 @@
 <interface>
   <requires lib="gtk" version="4.0"/>
   <template class="KgxSimpleTab" parent="KgxTab">
+    <property name="terminal">terminal</property>
     <child type="content">
       <object class="GtkScrolledWindow">
         <property name="vexpand">1</property>
diff --git a/src/kgx-tab.c b/src/kgx-tab.c
index 983c495..cfa6b18 100644
--- a/src/kgx-tab.c
+++ b/src/kgx-tab.c
@@ -42,6 +42,7 @@ struct _KgxTabPrivate {
   guint                 id;
 
   KgxApplication       *application;
+  KgxSettings          *settings;
 
   char                 *title;
   char                 *tooltip;
@@ -58,17 +59,9 @@ struct _KgxTabPrivate {
   gboolean              search_mode_enabled;
 
   KgxTerminal          *terminal;
-  GBinding             *term_title_bind;
-  GBinding             *term_path_bind;
-  GBinding             *term_font_bind;
-  GBinding             *term_zoom_bind;
-  GBinding             *term_theme_bind;
-  GBinding             *term_scrollback_bind;
-
-  GBinding             *pages_font_bind;
-  GBinding             *pages_zoom_bind;
-  GBinding             *pages_theme_bind;
-  GBinding             *pages_scrollback_bind;
+  GSignalGroup         *terminal_signals;
+  GBindingGroup        *terminal_binds;
+  GBindingGroup        *settings_binds;
 
   GtkWidget            *stack;
   GtkWidget            *spinner_revealer;
@@ -101,6 +94,8 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (KgxTab, kgx_tab, GTK_TYPE_BOX,
 enum {
   PROP_0,
   PROP_APPLICATION,
+  PROP_SETTINGS,
+  PROP_TERMINAL,
   PROP_TAB_TITLE,
   PROP_TAB_PATH,
   PROP_TAB_STATUS,
@@ -127,32 +122,6 @@ enum {
 static guint signals[N_SIGNALS];
 
 
-static void
-size_changed (KgxTerminal *term,
-              guint        rows,
-              guint        cols,
-              KgxTab      *self)
-{
-  g_signal_emit (self, signals[SIZE_CHANGED], 0, rows, cols);
-}
-
-
-static void
-font_increase (KgxTerminal *term,
-               KgxTab      *self)
-{
-  g_signal_emit (self, signals[ZOOM], 0, KGX_ZOOM_IN);
-}
-
-
-static void
-font_decrease (KgxTerminal *term,
-               KgxTab      *self)
-{
-  g_signal_emit (self, signals[ZOOM], 0, KGX_ZOOM_OUT);
-}
-
-
 static void
 kgx_tab_dispose (GObject *object)
 {
@@ -168,21 +137,14 @@ kgx_tab_dispose (GObject *object)
   }
 
   g_clear_object (&priv->application);
+  g_clear_object (&priv->settings);
+  g_clear_object (&priv->terminal);
 
   g_clear_pointer (&priv->title, g_free);
   g_clear_pointer (&priv->tooltip, g_free);
   g_clear_object (&priv->path);
   g_clear_pointer (&priv->font, pango_font_description_free);
 
-  if (priv->terminal) {
-    g_object_disconnect (priv->terminal,
-                        "any-signal::size-changed", G_CALLBACK (size_changed), self,
-                        "any-signal::increase-font-size", G_CALLBACK (font_increase), self,
-                        "any-signal::decrease-font-size", G_CALLBACK (font_decrease), self,
-                        NULL);
-  }
-  g_clear_object (&priv->terminal);
-
   g_clear_pointer (&priv->root, g_hash_table_unref);
   g_clear_pointer (&priv->remote, g_hash_table_unref);
   g_clear_pointer (&priv->children, g_hash_table_unref);
@@ -330,6 +292,12 @@ kgx_tab_get_property (GObject    *object,
     case PROP_APPLICATION:
       g_value_set_object (value, priv->application);
       break;
+    case PROP_SETTINGS:
+      g_value_set_object (value, priv->settings);
+      break;
+    case PROP_TERMINAL:
+      g_value_set_object (value, priv->terminal);
+      break;
     case PROP_TAB_TITLE:
       g_value_set_string (value, priv->title);
       break;
@@ -417,13 +385,30 @@ kgx_tab_set_property (GObject      *object,
       priv->application = g_value_dup_object (value);
       kgx_application_add_page (priv->application, self);
       break;
+    case PROP_SETTINGS:
+      g_set_object (&priv->settings, g_value_get_object (value));
+      break;
+    case PROP_TERMINAL:
+      g_set_object (&priv->terminal, g_value_get_object (value));
+      g_binding_group_bind (priv->settings_binds, "font",
+                            priv->terminal, "font-desc",
+                            G_BINDING_SYNC_CREATE);
+      g_binding_group_bind (priv->settings_binds, "font-scale",
+                            priv->terminal, "font-scale",
+                            G_BINDING_SYNC_CREATE);
+      g_binding_group_bind (priv->settings_binds, "theme",
+                            priv->terminal, "theme",
+                            G_BINDING_SYNC_CREATE);
+      g_binding_group_bind (priv->settings_binds, "scrollback-lines",
+                            priv->terminal, "scrollback-lines",
+                            G_BINDING_SYNC_CREATE);
+      break;
     case PROP_TAB_TITLE:
       g_clear_pointer (&priv->title, g_free);
       priv->title = g_value_dup_string (value);
       break;
     case PROP_TAB_PATH:
-      g_clear_object (&priv->path);
-      priv->path = g_value_dup_object (value);
+      g_set_object (&priv->path, g_value_get_object (value));
       break;
     case PROP_TAB_STATUS:
       priv->status = g_value_get_flags (value);
@@ -565,6 +550,16 @@ kgx_tab_class_init (KgxTabClass *klass)
                          KGX_TYPE_APPLICATION,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
+  pspecs[PROP_SETTINGS] =
+    g_param_spec_object ("settings", NULL, NULL,
+                         KGX_TYPE_SETTINGS,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  pspecs[PROP_TERMINAL] =
+    g_param_spec_object ("terminal", NULL, NULL,
+                         KGX_TYPE_TERMINAL,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
   /**
    * KgxTab:tab-title:
    *
@@ -717,6 +712,9 @@ kgx_tab_class_init (KgxTabClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, KgxTab, label);
   gtk_widget_class_bind_template_child_private (widget_class, KgxTab, search_entry);
   gtk_widget_class_bind_template_child_private (widget_class, KgxTab, search_bar);
+  gtk_widget_class_bind_template_child_private (widget_class, KgxTab, terminal_signals);
+  gtk_widget_class_bind_template_child_private (widget_class, KgxTab, terminal_binds);
+  gtk_widget_class_bind_template_child_private (widget_class, KgxTab, settings_binds);
 
   gtk_widget_class_bind_template_callback (widget_class, search_enabled);
   gtk_widget_class_bind_template_callback (widget_class, search_changed);
@@ -757,6 +755,32 @@ kgx_tab_buildable_iface_init (GtkBuildableIface *iface)
 }
 
 
+static void
+size_changed (KgxTerminal *term,
+              guint        rows,
+              guint        cols,
+              KgxTab      *self)
+{
+  g_signal_emit (self, signals[SIZE_CHANGED], 0, rows, cols);
+}
+
+
+static void
+font_increase (KgxTerminal *term,
+               KgxTab      *self)
+{
+  g_signal_emit (self, signals[ZOOM], 0, KGX_ZOOM_IN);
+}
+
+
+static void
+font_decrease (KgxTerminal *term,
+               KgxTab      *self)
+{
+  g_signal_emit (self, signals[ZOOM], 0, KGX_ZOOM_OUT);
+}
+
+
 static void
 kgx_tab_init (KgxTab *self)
 {
@@ -777,6 +801,23 @@ kgx_tab_init (KgxTab *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  g_signal_group_connect (priv->terminal_signals,
+                          "size-changed", G_CALLBACK (size_changed),
+                          self),
+  g_signal_group_connect (priv->terminal_signals,
+                          "increase-font-size", G_CALLBACK (font_increase),
+                          self),
+  g_signal_group_connect (priv->terminal_signals,
+                          "decrease-font-size", G_CALLBACK (font_decrease),
+                          self),
+
+  g_binding_group_bind (priv->terminal_binds, "window-title",
+                        self, "tab-title",
+                        G_BINDING_SYNC_CREATE);
+  g_binding_group_bind (priv->terminal_binds, "path",
+                        self, "tab-path",
+                        G_BINDING_SYNC_CREATE);
+
   gtk_search_bar_connect_entry (GTK_SEARCH_BAR (priv->search_bar),
                                 GTK_EDITABLE (priv->search_entry));
 
@@ -786,65 +827,6 @@ kgx_tab_init (KgxTab *self)
 }
 
 
-void
-kgx_tab_connect_terminal (KgxTab      *self,
-                          KgxTerminal *term)
-{
-  KgxTabPrivate *priv;
-
-  g_return_if_fail (KGX_IS_TAB (self));
-  g_return_if_fail (KGX_IS_TERMINAL (term));
-
-  priv = kgx_tab_get_instance_private (self);
-
-  if (priv->terminal == term) {
-    return;
-  }
-
-  if (priv->terminal) {
-    g_object_disconnect (priv->terminal,
-                         "any-signal::size-changed", G_CALLBACK (size_changed), self,
-                         "any-signal::increase-font-size", G_CALLBACK (font_increase), self,
-                         "any-signal::decrease-font-size", G_CALLBACK (font_decrease), self,
-                         NULL);
-  }
-
-  g_clear_object (&priv->term_title_bind);
-  g_clear_object (&priv->term_path_bind);
-  g_clear_object (&priv->term_font_bind);
-  g_clear_object (&priv->term_zoom_bind);
-  g_clear_object (&priv->term_theme_bind);
-  g_clear_object (&priv->term_scrollback_bind);
-
-  g_set_object (&priv->terminal, term);
-
-  g_object_connect (term,
-                    "signal::size-changed", G_CALLBACK (size_changed), self,
-                    "signal::increase-font-size", G_CALLBACK (font_increase), self,
-                    "signal::decrease-font-size", G_CALLBACK (font_decrease), self,
-                    NULL);
-
-  priv->term_title_bind = g_object_bind_property (term, "window-title",
-                                                  self, "tab-title",
-                                                  G_BINDING_SYNC_CREATE);
-  priv->term_path_bind = g_object_bind_property (term, "path",
-                                                 self, "tab-path",
-                                                 G_BINDING_SYNC_CREATE);
-  priv->term_font_bind = g_object_bind_property (self, "font",
-                                                 term, "font-desc",
-                                                 G_BINDING_SYNC_CREATE);
-  priv->term_zoom_bind = g_object_bind_property (self, "zoom",
-                                                 term, "font-scale",
-                                                 G_BINDING_SYNC_CREATE);
-  priv->term_theme_bind = g_object_bind_property (self, "theme",
-                                                  term, "theme",
-                                                  G_BINDING_SYNC_CREATE);
-  priv->term_scrollback_bind = g_object_bind_property (self, "scrollback-lines",
-                                                       term, "scrollback-lines",
-                                                       G_BINDING_SYNC_CREATE);
-}
-
-
 void
 kgx_tab_start (KgxTab              *self,
                GAsyncReadyCallback  callback,
@@ -1174,38 +1156,3 @@ kgx_tab_set_initial_title (KgxTab     *self,
                 "tab-path", path,
                 NULL);
 }
-
-
-void
-kgx_tab_set_pages (KgxTab   *self,
-                   KgxPages *pages)
-{
-  KgxTabPrivate *priv;
-
-  g_return_if_fail (KGX_IS_TAB (self));
-  g_return_if_fail (KGX_IS_PAGES (pages) || !pages);
-
-  priv = kgx_tab_get_instance_private (self);
-
-  g_clear_object (&priv->pages_font_bind);
-  g_clear_object (&priv->pages_zoom_bind);
-  g_clear_object (&priv->pages_theme_bind);
-  g_clear_object (&priv->pages_scrollback_bind);
-
-  if (pages == NULL) {
-    return;
-  }
-
-  priv->pages_font_bind = g_object_bind_property (pages, "font",
-                                                  self, "font",
-                                                  G_BINDING_SYNC_CREATE);
-  priv->pages_zoom_bind = g_object_bind_property (pages, "zoom",
-                                                  self, "zoom",
-                                                  G_BINDING_SYNC_CREATE);
-  priv->pages_theme_bind = g_object_bind_property (pages, "theme",
-                                                   self, "theme",
-                                                   G_BINDING_SYNC_CREATE);
-  priv->pages_scrollback_bind = g_object_bind_property (pages, "scrollback-lines",
-                                                        self, "scrollback-lines",
-                                                        G_BINDING_SYNC_CREATE);
-}
diff --git a/src/kgx-tab.h b/src/kgx-tab.h
index 213442f..b0028a4 100644
--- a/src/kgx-tab.h
+++ b/src/kgx-tab.h
@@ -97,10 +97,6 @@ struct _KgxTabClass
 
 
 guint       kgx_tab_get_id           (KgxTab               *self);
-void        kgx_tab_connect_terminal (KgxTab               *self,
-                                      KgxTerminal          *term);
-void        kgx_tab_set_pages        (KgxTab               *self,
-                                      KgxPages             *pages);
 void        kgx_tab_start            (KgxTab               *self,
                                       GAsyncReadyCallback   callback,
                                       gpointer              callback_data);
diff --git a/src/kgx-tab.ui b/src/kgx-tab.ui
index 5f402f2..2252002 100644
--- a/src/kgx-tab.ui
+++ b/src/kgx-tab.ui
@@ -94,4 +94,14 @@
       </object>
     </child>
   </template>
+  <object class="GSignalGroup" id="terminal_signals">
+    <property name="target-type">KgxTerminal</property>
+    <property name="target" bind-source="KgxTab" bind-property="terminal" bind-flags="sync-create"/>
+  </object>
+  <object class="GBindingGroup" id="terminal_binds">
+    <property name="source" bind-source="KgxTab" bind-property="terminal" bind-flags="sync-create"/>
+  </object>
+  <object class="GBindingGroup" id="settings_binds">
+    <property name="source" bind-source="KgxTab" bind-property="settings" bind-flags="sync-create"/>
+  </object>
 </interface>


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