[buoh/cleanups] fixup! Port comic-list to GtkBuilder



commit 1c9ce07f3f94a5b1709cddba62e90d11e318ecfc
Author: Jan Tojnar <jtojnar gmail com>
Date:   Mon Sep 24 05:01:18 2018 +0200

    fixup! Port comic-list to GtkBuilder

 data/ui/comic-list.ui |  1 +
 src/buoh-comic-list.c | 36 +++++++++++++++++++-----------------
 src/buoh-comic-list.h |  2 ++
 src/buoh-window.c     |  3 +++
 4 files changed, 25 insertions(+), 17 deletions(-)
---
diff --git a/data/ui/comic-list.ui b/data/ui/comic-list.ui
index 75c5ac2..01900b9 100644
--- a/data/ui/comic-list.ui
+++ b/data/ui/comic-list.ui
@@ -3,6 +3,7 @@
 <interface>
   <requires lib="gtk+" version="3.20"/>
   <template class="BuohComicList" parent="GtkBin">
+    <property name="border-width">6</property>
     <child>
       <object class="GtkScrolledWindow">
         <property name="visible">1</property>
diff --git a/src/buoh-comic-list.c b/src/buoh-comic-list.c
index bb197e6..d4b9da6 100644
--- a/src/buoh-comic-list.c
+++ b/src/buoh-comic-list.c
@@ -71,7 +71,9 @@ buoh_comic_list_selection_changed (GtkTreeSelection *selection, gpointer gdata)
                 buoh_view_set_comic (comic_list->priv->view, comic);
                 buoh_debug ("selection changed: set comic");
         } else {
-                buoh_view_clear (comic_list->priv->view);
+                if (BUOH_IS_VIEW (comic_list->priv->view)) {
+                        buoh_view_clear (comic_list->priv->view);
+                }
         }
 }
 
@@ -90,23 +92,13 @@ buoh_comic_list_visible (GtkTreeModel *model,
 static void
 buoh_comic_list_init (BuohComicList *buoh_comic_list)
 {
-        GtkTreeModel      *model;
 
         buoh_comic_list->priv = buoh_comic_list_get_instance_private (buoh_comic_list);
 
         buoh_comic_list->priv->comic_manager = NULL;
         buoh_comic_list->priv->view = NULL;
 
-        model = buoh_get_comics_model (BUOH);
-        buoh_comic_list->priv->model = gtk_tree_model_filter_new (model, NULL);
-        gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (buoh_comic_list->priv->model),
-                                                buoh_comic_list_visible,
-                                                NULL, NULL);
-
         gtk_widget_init_template (GTK_WIDGET (buoh_comic_list));
-
-        gtk_tree_view_set_model (GTK_TREE_VIEW (buoh_comic_list->priv->tree_view),
-                                 buoh_comic_list->priv->model);
 }
 
 static void
@@ -190,12 +182,7 @@ buoh_comic_list_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
 GtkWidget *
 buoh_comic_list_new (void)
 {
-        GtkWidget *buoh_comic_list;
-
-        buoh_comic_list = GTK_WIDGET (g_object_new (BUOH_TYPE_COMIC_LIST,
-                                                    "border-width", 6,
-                                                    NULL));
-        return buoh_comic_list;
+        return GTK_WIDGET (g_object_new (BUOH_TYPE_COMIC_LIST, NULL));
 }
 
 void
@@ -211,6 +198,21 @@ buoh_comic_list_set_view (BuohComicList *comic_list, BuohView *view)
         comic_list->priv->view = view;
 }
 
+void
+buoh_comic_list_set_model (BuohComicList *comic_list, GtkTreeModel *model)
+{
+        g_return_if_fail (BUOH_IS_COMIC_LIST (comic_list));
+        g_return_if_fail (GTK_IS_TREE_MODEL (model));
+
+        comic_list->priv->model = gtk_tree_model_filter_new (model, NULL);
+        gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (comic_list->priv->model),
+                                                buoh_comic_list_visible,
+                                                NULL, NULL);
+
+        gtk_tree_view_set_model (GTK_TREE_VIEW (comic_list->priv->tree_view),
+                                 comic_list->priv->model);
+}
+
 GtkWidget *
 buoh_comic_list_get_list (BuohComicList *comic_list)
 {
diff --git a/src/buoh-comic-list.h b/src/buoh-comic-list.h
index ccccc34..122539a 100644
--- a/src/buoh-comic-list.h
+++ b/src/buoh-comic-list.h
@@ -52,6 +52,8 @@ GtkWidget        *buoh_comic_list_new             (void);
 
 void              buoh_comic_list_set_view        (BuohComicList *comic_list,
                                                    BuohView      *view);
+void              buoh_comic_list_set_model       (BuohComicList *comic_list,
+                                                   GtkTreeModel  *model);
 GtkWidget        *buoh_comic_list_get_list        (BuohComicList *comic_list);
 void              buoh_comic_list_clear_selection (BuohComicList *comic_list);
 BuohComicManager *buoh_comic_list_get_selected    (BuohComicList *comic_list);
diff --git a/src/buoh-window.c b/src/buoh-window.c
index c133b88..3500ba1 100644
--- a/src/buoh-window.c
+++ b/src/buoh-window.c
@@ -232,6 +232,7 @@ static void
 buoh_window_init (BuohWindow *buoh_window)
 {
         GtkWidget        *tree_view;
+        GtkTreeModel     *model;
         GtkTreeSelection *selection;
         GtkWidget        *vbox, *paned, *menubar;
         GtkWidget        *toolbar;
@@ -346,6 +347,8 @@ buoh_window_init (BuohWindow *buoh_window)
 
         /* buoh comic list */
         buoh_window->priv->comic_list = BUOH_COMIC_LIST (buoh_comic_list_new ());
+        model = buoh_get_comics_model (BUOH);
+        buoh_comic_list_set_model (buoh_window->priv->comic_list, model);
         buoh_comic_list_set_view (buoh_window->priv->comic_list, buoh_window->priv->view);
         gtk_paned_pack1 (GTK_PANED (paned), GTK_WIDGET (buoh_window->priv->comic_list),
                          TRUE, FALSE);


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