[devhelp/gnome-2-32] book manager dialog: populate tree



commit 34d4705423ae7c01093b1422d3fa504b6d357edb
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu May 20 11:12:23 2010 +0200

    book manager dialog: populate tree

 data/ui/devhelp.builder      |   14 ++++----
 src/dh-book-manager-dialog.c |   77 ++++++++++++++++++++++++++++++++++++++++-
 src/dh-book.c                |   20 +++++++++++
 src/dh-book.h                |   19 +++++-----
 4 files changed, 112 insertions(+), 18 deletions(-)
---
diff --git a/data/ui/devhelp.builder b/data/ui/devhelp.builder
index 287caeb..eafcf78 100644
--- a/data/ui/devhelp.builder
+++ b/data/ui/devhelp.builder
@@ -180,12 +180,10 @@
   </object>
   <object class="GtkListStore" id="book_manager_store">
     <columns>
-      <!-- column-name name -->
-      <column type="gchararray"/>
-      <!-- column-name title -->
-      <column type="gchararray"/>
       <!-- column-name enabled -->
       <column type="gboolean"/>
+      <!-- column-name title -->
+      <column type="gchararray"/>
       <!-- column-name book -->
       <column type="gpointer"/>
     </columns>
@@ -193,6 +191,8 @@
   <object class="GtkDialog" id="book_manager_dialog">
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Book Manager</property>
+    <property name="default_width">500</property>
+    <property name="default_height">300</property>
     <property name="type_hint">normal</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
@@ -209,7 +209,7 @@
                 <property name="hscrollbar_policy">automatic</property>
                 <property name="vscrollbar_policy">automatic</property>
                 <child>
-                  <object class="GtkTreeView" id="book-manager-treeview">
+                  <object class="GtkTreeView" id="book_manager_treeview">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="model">book_manager_store</property>
@@ -219,9 +219,9 @@
                       <object class="GtkTreeViewColumn" id="treeviewcolumn1">
                         <property name="title">Enabled</property>
                         <child>
-                          <object class="GtkCellRendererToggle" id="cellrenderertoggle1"/>
+                          <object class="GtkCellRendererToggle" id="book_manager_toggle_enabled"/>
                           <attributes>
-                            <attribute name="active">2</attribute>
+                            <attribute name="active">0</attribute>
                           </attributes>
                         </child>
                       </object>
diff --git a/src/dh-book-manager-dialog.c b/src/dh-book-manager-dialog.c
index 14f530a..18777b9 100644
--- a/src/dh-book-manager-dialog.c
+++ b/src/dh-book-manager-dialog.c
@@ -25,12 +25,22 @@
 #include "dh-book-manager-dialog.h"
 #include "ige-conf.h"
 #include "dh-base.h"
+#include "dh-link.h"
+#include "dh-book-manager.h"
+#include "dh-book.h"
 
 typedef struct {
-	GtkWidget *dialog;
-
+	GtkWidget     *dialog;
+        GtkTreeView   *treeview;
+        GtkListStore  *store;
+        DhBase        *base;
 } DhBookManagerDialog;
 
+/* List store columns... */
+#define LTCOLUMN_ENABLED  0
+#define LTCOLUMN_TITLE    1
+#define LTCOLUMN_BOOK     2
+
 #define DH_CONF_PATH                  "/apps/devhelp"
 
 static DhBookManagerDialog *prefs;
@@ -40,6 +50,8 @@ book_manager_dialog_init (void)
 {
 	if (!prefs) {
                 prefs = g_new0 (DhBookManagerDialog, 1);
+
+                prefs->base = dh_base_get ();
         }
 }
 
@@ -53,6 +65,62 @@ book_manager_dialog_close_cb (GtkButton *button, gpointer user_data)
 	prefs->dialog = NULL;
 }
 
+static void
+book_manager_tree_selection_toggled_cb (GtkCellRendererToggle *cell_renderer,
+                                        gchar *path,
+                                        gpointer user_data)
+{
+        GtkTreeIter iter;
+
+        if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (prefs->store),
+                                                 &iter,
+                                                 path))
+        {
+                gpointer book = NULL;
+                gboolean enabled;
+
+                gtk_tree_model_get (GTK_TREE_MODEL (prefs->store),
+                                    &iter,
+                                    LTCOLUMN_BOOK,       &book,
+                                    LTCOLUMN_ENABLED,    &enabled,
+                                    -1);
+
+                if (book) {
+                        /* Update book conf */
+                        dh_book_set_enabled (book, !enabled);
+
+                        gtk_list_store_set (prefs->store, &iter,
+                                            LTCOLUMN_ENABLED, !enabled,
+                                            -1);
+                }
+        }
+}
+
+static void
+book_manager_dialog_populate_store (void)
+{
+        GList         *l;
+        DhBookManager *book_manager;
+
+        book_manager = dh_base_get_book_manager (prefs->base);
+
+        for (l = dh_book_manager_get_books (book_manager);
+             l;
+             l = g_list_next (l)) {
+                GtkTreeIter  iter;
+                DhBook      *book;
+
+                book = DH_BOOK (l->data);
+
+                gtk_list_store_append (prefs->store, &iter);
+                gtk_list_store_set (prefs->store, &iter,
+                                    LTCOLUMN_ENABLED,  dh_book_get_enabled (book),
+                                    LTCOLUMN_TITLE,    dh_book_get_title (book),
+                                    LTCOLUMN_BOOK,     book,
+                                    -1);
+        }
+}
+
 void
 dh_book_manager_dialog_show (GtkWindow *parent)
 {
@@ -74,6 +142,8 @@ dh_book_manager_dialog_show (GtkWindow *parent)
                 "book_manager_dialog",
                 NULL,
                 "book_manager_dialog", &prefs->dialog,
+                "book_manager_store", &prefs->store,
+                "book_manager_treeview", &prefs->treeview,
                 NULL);
         g_free (path);
 
@@ -81,10 +151,13 @@ dh_book_manager_dialog_show (GtkWindow *parent)
                 builder,
                 prefs,
                 "book_manager_close_button", "clicked", book_manager_dialog_close_cb,
+                "book_manager_toggle_enabled", "toggled", book_manager_tree_selection_toggled_cb,
                 NULL);
 
 	g_object_unref (builder);
 
+        book_manager_dialog_populate_store ();
+
 	gtk_window_set_transient_for (GTK_WINDOW (prefs->dialog), parent);
 	gtk_widget_show_all (prefs->dialog);
 }
diff --git a/src/dh-book.c b/src/dh-book.c
index 56de271..1af4a69 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -34,6 +34,8 @@ typedef struct {
         gchar    *path;
         /* Enable or disabled? */
         gboolean  enabled;
+        /* Book title */
+        gchar    *title;
         /* Generated book tree */
         GNode    *tree;
         /* Generated list of keywords in the book */
@@ -73,6 +75,8 @@ book_finalize (GObject *object)
                 g_list_free (priv->keywords);
         }
 
+        g_free (priv->title);
+
         g_free (priv->path);
 
         G_OBJECT_CLASS (dh_book_parent_class)->finalize (object);
@@ -94,6 +98,7 @@ dh_book_init (DhBook *book)
         DhBookPriv *priv = GET_PRIVATE (book);
 
         priv->path = NULL;
+        priv->title = NULL;
         priv->enabled = TRUE;
         priv->tree = NULL;
         priv->keywords = NULL;
@@ -136,6 +141,9 @@ dh_book_new (const gchar  *book_path)
                 return NULL;
         }
 
+        /* Setup title */
+        priv->title = g_strdup (dh_link_get_name ((DhLink *)priv->tree->data));
+
         return book;
 }
 
@@ -163,6 +171,18 @@ dh_book_get_tree (DhBook *book)
         return priv->enabled ? priv->tree : NULL;
 }
 
+const gchar *
+dh_book_get_title (DhBook *book)
+{
+        DhBookPriv *priv;
+
+        g_return_val_if_fail (DH_IS_BOOK (book), NULL);
+
+        priv = GET_PRIVATE (book);
+
+        return priv->title;
+}
+
 gboolean
 dh_book_get_enabled (DhBook *book)
 {
diff --git a/src/dh-book.h b/src/dh-book.h
index 46d994c..587ba63 100644
--- a/src/dh-book.h
+++ b/src/dh-book.h
@@ -46,15 +46,16 @@ struct _DhBookClass {
         GObjectClass parent_class;
 };
 
-GType     dh_book_get_type     (void) G_GNUC_CONST;
-DhBook   *dh_book_new          (const gchar  *book_path);
-GList    *dh_book_get_keywords (DhBook *book);
-GNode    *dh_book_get_tree     (DhBook *book);
-gboolean  dh_book_get_enabled  (DhBook *book);
-void      dh_book_set_enabled  (DhBook *book,
-                                gboolean enabled);
-gint      dh_book_cmp           (const DhBook *a,
-                                 const DhBook *b);
+GType        dh_book_get_type     (void) G_GNUC_CONST;
+DhBook      *dh_book_new          (const gchar  *book_path);
+GList       *dh_book_get_keywords (DhBook *book);
+GNode       *dh_book_get_tree     (DhBook *book);
+const gchar *dh_book_get_title    (DhBook *book);
+gboolean     dh_book_get_enabled  (DhBook *book);
+void         dh_book_set_enabled  (DhBook *book,
+                                   gboolean enabled);
+gint         dh_book_cmp          (const DhBook *a,
+                                   const DhBook *b);
 
 G_END_DECLS
 



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