r23261 - gnucash/trunk/src/gnome-utils - Remove state saving/restoring code from gnc-tree-view

Geert Janssens gjanssens at code.gnucash.org
Mon Oct 7 10:27:50 EDT 2013


Author: gjanssens
Date: 2013-10-07 10:27:50 -0400 (Mon, 07 Oct 2013)
New Revision: 23261
Trac: http://svn.gnucash.org/trac/changeset/23261

Modified:
   gnucash/trunk/src/gnome-utils/gnc-tree-view.c
   gnucash/trunk/src/gnome-utils/gnc-tree-view.h
Log:
Remove state saving/restoring code from gnc-tree-view

This means column widths, column's visibility and view sort order
are currently no longer saved or restored for any view based on
GncTreeView.

This is done because the state code relies heavily on gconf
and unfortunately can't be mapped to gsettings in its present
form.

State save/restore  will be added again later, but likely only
after the gconf conversion is complete.

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view.c	2013-10-07 14:27:34 UTC (rev 23260)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view.c	2013-10-07 14:27:50 UTC (rev 23261)
@@ -40,7 +40,6 @@
 
 #include "gnc-tree-view.h"
 #include "gnc-engine.h"
-#include "gnc-gconf-utils.h"
 #include "gnc-gnome-utils.h"
 #include "gnc-gobject-utils.h"
 #include "gnc-cell-renderer-date.h"
@@ -86,14 +85,11 @@
                                         guint            prop_id,
                                         GValue          *value,
                                         GParamSpec      *pspec);
-static void gnc_tree_view_remove_gconf_callbacks(GncTreeView *view);
 static gboolean gnc_tree_view_drop_ok_cb (GtkTreeView *view,
         GtkTreeViewColumn *column,
         GtkTreeViewColumn *prev_column,
         GtkTreeViewColumn *next_column,
         gpointer data);
-static void gtk_tree_view_sort_column_changed_cb (GtkTreeSortable *treesortable,
-        GncTreeView *view);
 static void gnc_tree_view_build_column_menu (GncTreeView *view);
 static void gnc_tree_view_select_column_cb (GtkTreeViewColumn *column,
         GncTreeView *view);
@@ -171,7 +167,7 @@
 
 /** Initialize the class for the new base gnucash tree view.  This
  *  will set up any function pointers that override functions in the
- *  parent class, and also installs the proprieties that are unique to
+ *  parent class, and also installs the properties that are unique to
  *  this class.
  *
  *  @param klass The new class structure created by the object system.
@@ -335,10 +331,11 @@
 
     view = GNC_TREE_VIEW (object);
 
-    gnc_tree_view_remove_gconf_callbacks(view);
-
     priv = GNC_TREE_VIEW_GET_PRIVATE(view);
 
+    g_free(priv->state_section);
+    priv->state_section = NULL;
+
     if (priv->column_menu)
     {
         DEBUG("removing column selection menu");
@@ -427,50 +424,9 @@
 /************************************************************/
 /*                   Auxiliary Functions                    */
 /************************************************************/
-
 /** @name Gnc Tree View Auxiliary Functions
  @{ */
 
-/** Find a tree column given a column id number from the underlying
- *  data model.  This function should only be called by code that has
- *  visibility into the data model.  The column id numbers shouldn't
- *  be used for any other purpose.
- *
- *  This function simply runs the list of all (visible and invisible)
- *  columns looking for a match.  Column id numbers were attached to
- *  each column at the time the column was created.
- *
- *  @param view The visible tree widget.
- *
- *  @param wanted The column id number to find.
- *
- *  @internal
- */
-static GtkTreeViewColumn *
-view_column_find_by_model_id (GncTreeView *view,
-                              const gint wanted)
-{
-    GtkTreeViewColumn *column, *found = NULL;
-    GList *column_list, *tmp;
-    gint id;
-
-    // ENTER("view %p, name %s", view, name);
-    column_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
-    for (tmp = column_list; tmp; tmp = g_list_next(tmp))
-    {
-        column = tmp->data;
-        id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), MODEL_COLUMN));
-        if (id != wanted)
-            continue;
-        found = column;
-        break;
-    }
-    g_list_free(column_list);
-
-    // LEAVE("column %p", found);
-    return found;
-}
-
 /** Find a tree column given the "pref name" used with saved state.  This
  *  function simply runs the list of all (visible and invisible)
  *  columns looking for a match.  Column names were attached to each
@@ -573,199 +529,24 @@
     return TRUE;
 }
 
-/** This function is called when the sort order has changed on the
- *  underlying GtkTreeModel.  It propagates these changes to gconf to
- *  keep it in sync with the user's view of the tree.
- *
- *  @param treesortable The underlying sortable model.
- *
- *  @param view A pointer to the GncTreeView that displays the model
- *  data.
- *
- *  @internal
- */
-static void
-gtk_tree_view_sort_column_changed_cb (GtkTreeSortable *treesortable,
-                                      GncTreeView *view)
-{
-    GncTreeViewPrivate *priv;
-    GtkTreeViewColumn *column;
-    gchar        	    *column_pref_name;
-    GtkSortType  	     order;
-    gint         	     id;
-
-    g_return_if_fail(GTK_IS_TREE_SORTABLE(treesortable));
-    g_return_if_fail(GNC_IS_TREE_VIEW(view));
-
-    ENTER(" ");
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    if (!priv->state_section)
-    {
-        LEAVE("no state section");
-        return;
-    }
-
-    /* Set defaults, then extract data from the model */
-    if (!gtk_tree_sortable_get_sort_column_id(treesortable, &id, &order))
-    {
-        order = GTK_SORT_ASCENDING;
-        id = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID;
-    }
-    column = view_column_find_by_model_id (view, id);
-    column_pref_name = g_object_get_data(G_OBJECT(column), PREF_NAME);
-
-    if (!column_pref_name)
-        column_pref_name = "none";
-
-    /* Store the values in gconf */
-    gnc_gconf_set_string(priv->state_section, STATE_KEY_SORT_COLUMN,
-                         column_pref_name, NULL);
-    gnc_gconf_set_string(priv->state_section, STATE_KEY_SORT_ORDER,
-                         gnc_enum_to_nick(GTK_TYPE_SORT_TYPE, order), NULL);
-    LEAVE(" ");
-}
-
-/** This function is called when the column order has changed in the
- *  gtk tree view.  It propagates these changes to gconf to keep it in
- *  sync with the user's view of the tree.  This function runs the
- *  list of all tree column data structures, building a second list of
- *  column names.  This second list is passed to gconf for storing.
- *  Only columns that have names can be saved in this fashion.
- *
- *  @param view The tree view.
- *
- *  @param data Unused.
- *
- *  @internal
- */
-static void
-gtk_tree_view_columns_changed_cb (GncTreeView *view,
-                                  gpointer data)
-{
-    GncTreeViewPrivate *priv;
-    GList *column_list, *tmp;
-    GSList *column_names = NULL;
-    gchar *name;
-
-    //ENTER("view %p, data %p", view, data);
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    column_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
-    for (tmp = column_list; tmp; tmp = g_list_next(tmp))
-    {
-        name = g_object_get_data(tmp->data, PREF_NAME);
-        if (!name)
-            continue;
-        column_names = g_slist_append(column_names, name);
-        //DEBUG("%s", name);
-    }
-    g_list_free(column_list);
-
-    gnc_gconf_set_list(priv->state_section, STATE_KEY_COLUMN_ORDER,
-                       GCONF_VALUE_STRING, column_names, NULL);
-    g_slist_free(column_names);
-    //LEAVE(" ");
-}
-
-/** This is the helper function for gtk_tree_view_size_allocate_cb().
- *  It compares the actual column width to the width as stored in
- *  gconf.  If the two are different, it updates gconf with the
- *  actual width.  This will trigger a notification from gconf that
- *  the size has changed, and that code must be smart enough to
- *  prevent an infinite loop.  Not storing unchanged values prevents
- *  spurious callbacks from gconf and just saves processing time.
- *
- *  @param column The column whose size should be updated in gconf..
- *
- *  @param view The tree view.
- *
- *  @internal
- */
-static void
-gtk_tree_view_size_allocate_helper (GtkTreeViewColumn *column,
-                                    GncTreeView *view)
-{
-    GncTreeViewPrivate *priv;
-    const gchar *column_pref_name;
-    gint new_width, current_width;
-    gchar *key;
-
-    g_return_if_fail(GTK_IS_TREE_VIEW_COLUMN(column));
-    g_return_if_fail(GNC_IS_TREE_VIEW(view));
-
-    /* Any updates to be made? */
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    column_pref_name = g_object_get_data(G_OBJECT(column), PREF_NAME);
-    if (!column_pref_name)
-        return;
-    new_width = gtk_tree_view_column_get_width (column);
-    if (!new_width)
-        return;
-
-    /* Do it */
-    key = g_strdup_printf("%s_%s", column_pref_name, STATE_KEY_WIDTH);
-    current_width = gnc_gconf_get_int(priv->state_section, key, NULL);
-    if (new_width != current_width)
-    {
-        gnc_gconf_set_int(priv->state_section, key, new_width, NULL);
-        DEBUG("set %s width to %d", column_pref_name, new_width);
-    }
-    g_free(key);
-}
-
-/** This function is called when the tree size has been reallocated.
- *  When called, one of two events has occurred.  1) The column sizes
- *  within the tree have changed.  2) The window containing the tree
- *  has been resized.  This code is concerned with case one.  Case two
- *  is a don't care, unless the window resizing has caused a column
- *  resizing.
- *
- *  This function simply runs the list of all tree columns, calling the
- *  gtk_tree_view_size_allocate_helper() function on each column.
- *  There is no callback that can be used for notification of an
- *  individual column change.  Its this or nothing.
- *
- *  @param widget The tree view.
- *
- *  @param allocation Unused.
- *
- *  @param data Unused.
- *
- *  @internal
- */
-static void
-gtk_tree_view_size_allocate_cb (GtkWidget *widget,
-                                GtkAllocation *allocation,
-                                gpointer data)
-{
-    GncTreeView *view;
-    GList *column_list;
-
-    g_return_if_fail(GNC_IS_TREE_VIEW(widget));
-    view = GNC_TREE_VIEW(widget);
-    column_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
-    g_list_foreach(column_list, (GFunc)gtk_tree_view_size_allocate_helper, view);
-    g_list_free(column_list);
-}
-
 /** @} */
 
 /************************************************************/
-/*                  Gconf Setup / Callbacks                 */
+/*                  State Setup / Callbacks                 */
 /************************************************************/
 
-/** @name Gnc Tree View Gconf Callback / Related Functions
+/** @name Gnc Tree View state Callback / Related Functions
  @{ */
 
 /** Determine the visibility of a column.  This function first looks
  *  for columns specially marked to be always visible, or columns
  *  without a preference name.  These are always shown.  Next, this
- *  function checks to see if gconf is responsible for this view *and*
- *  that gconf visibility keys have been seen.  (This handles the
- *  'first run' case where gconf should manage a view but no keys yet
- *  exist in gconf.)  If so, the gconf visibility key is returned.
- *  Otherwise the 'default visible column' list is checked and a
- *  value of TRUE returned if the pref name is found, otherwise FALSE.
+ *  function checks to see if the column should be visible by default.
+ *  If so this column will be shown as well.
  *
+ *  FIXME This should be improved when saved state functionality is
+ *        added again.
+ *
  *  @param view A GncTreeView.
  *
  *  @param column The GtkTreeViewColumn in question.  Either this
@@ -806,21 +587,12 @@
         return TRUE;
     }
 
-    /* Using gconf? */
+    /* Using saved state ? */
     if (priv->state_section)
     {
-        if (priv->seen_state_visibility)
-        {
-            key = g_strdup_printf("%s_%s", pref_name, STATE_KEY_VISIBLE);
-            visible = gnc_gconf_get_bool(priv->state_section, key, NULL);
-            g_free(key);
-            LEAVE("%d, gconf visibility", visible);
-            return visible;
-        }
-
         visible = column ?
                   (g_object_get_data(G_OBJECT(column), DEFAULT_VISIBLE) != NULL) : FALSE;
-        LEAVE("%d, gconf but using defaults", visible);
+        LEAVE("%d, saved state but using defaults", visible);
         return visible;
     }
 
@@ -833,7 +605,7 @@
 
 /** This function updates the visibility of a single column.  It
  *  checks if the column should be visible, and if so tells the view
- *  to show the column and (if needed) updates the gconf database.
+ *  to show the column.
  *
  *  @param column The column whose visibility should be updated.
  *
@@ -864,392 +636,25 @@
             LEAVE("no pref name");
             return;
         }
-        key = g_strdup_printf("%s_%s", name, STATE_KEY_VISIBLE);
-        gnc_gconf_set_bool(priv->state_section, key, visible, NULL);
-        g_free(key);
-        LEAVE("made %s, set gconf key", visible ? "visible" : "invisible");
+        LEAVE("made %s, set state key", visible ? "visible" : "invisible");
         return;
     }
     LEAVE("made %s", visible ? "visible" : "invisible");
 }
 
-/** This function is called via the gconf notification callback when
- *  the sort order has changed in gconf.  It must update the model
- *  sort order to match what is specified in gconf.  The sort column
- *  used will be whatever is the current sort column.  This function
- *  is careful to prevent an infinite loop by blocking the
- *  "sort-column-changed" callback that is attached to the model.
- *
- *  @param view The tree view.
- *
- *  @param name The sort order enum (in string form). Either
- *  "ascending" or "descending".
- *
- *  @internal
- */
-static void
-gnc_tree_view_set_sort_order (GncTreeView *view,
-                              const gchar *name)
-{
-    GncTreeViewPrivate *priv;
-    GtkTreeModel *s_model;
-    GtkSortType order;
-    gint current;
-
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
-    if (!s_model)
-        return;
-    order = gnc_enum_from_nick(GTK_TYPE_SORT_TYPE, name, GTK_SORT_ASCENDING);
-    if (!gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(s_model),
-            &current, NULL))
-        current = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID;
-    g_signal_handler_block(s_model, priv->sort_column_changed_cb_id);
-    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(s_model),
-                                         current, order);
-    g_signal_handler_unblock(s_model, priv->sort_column_changed_cb_id);
-    DEBUG("sort_order set to %s", gnc_enum_to_nick(GTK_TYPE_SORT_TYPE, order));
-}
-
-/** This function is called via the gconf notification callback when
- *  the sort column has changed in gconf.  It must update the model
- *  sort column to match what is specified in gconf.  The sort order
- *  used for this column will be whatever sort order is in use on the
- *  current sort column.  This function is careful to prevent an
- *  infinite loop by blocking the "sort-column-changed" callback that
- *  is attached to the model.
- *
- *  @param view The tree view.
- *
- *  @param name The name of the column that should be made the sort column.
- *
- *  @internal
- */
-static void
-gnc_tree_view_set_sort_column (GncTreeView *view,
-                               const gchar *name)
-{
-    GncTreeViewPrivate *priv;
-    GtkTreeModel *s_model;
-    GtkTreeViewColumn *column;
-    GtkSortType order;
-    gint model_column, current;
-
-    s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
-    if (!s_model)
-        return;
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    column = gnc_tree_view_find_column_by_name(view, name);
-
-    if (!column)
-    {
-        g_signal_handler_block(s_model, priv->sort_column_changed_cb_id);
-        gtk_tree_sortable_set_sort_column_id(
-            GTK_TREE_SORTABLE(s_model), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
-            GTK_SORT_ASCENDING);
-        g_signal_handler_unblock(s_model, priv->sort_column_changed_cb_id);
-        return;
-    }
-
-    model_column =
-        GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), MODEL_COLUMN));
-    if (model_column == GNC_TREE_VIEW_COLUMN_DATA_NONE)
-        return;
-
-    if (!gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(s_model),
-            &current, &order))
-        order = GTK_SORT_ASCENDING;
-
-    g_signal_handler_block(s_model, priv->sort_column_changed_cb_id);
-    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(s_model),
-                                         model_column, order);
-    g_signal_handler_unblock(s_model, priv->sort_column_changed_cb_id);
-    DEBUG("sort column set to %s", name);
-}
-
-/** This function is called via the gconf notification callback when
- *  the column order has changed in gconf.  It must update the order
- *  of the columns in the model to match what is specified in gconf.
- *  This function is careful to prevent an infinite loop by blocking
- *  the "columns-changed" callback that is attached to the view.
- *
- *  @param view The tree view.
- *
- *  @param column_names A list of pointers to strings.  These strings are the
- *  names of the columns in the order they should appear.
- *
- *  @internal
- */
-static void
-gnc_tree_view_set_column_order (GncTreeView *view,
-                                const GSList *column_names)
-{
-    GncTreeViewPrivate *priv;
-    GtkTreeViewColumn *column, *prev;
-    const gchar *name;
-    const GSList *tmp;
-    GSList *columns;
-
-    /* First, convert from names to pointers */
-    ENTER(" ");
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    columns = NULL;
-    for (tmp = column_names; tmp; tmp = g_slist_next(tmp))
-    {
-        name = gconf_value_get_string(tmp->data);
-        column = gnc_tree_view_find_column_by_name(view, name);
-        if (!column)
-            continue;
-        columns = g_slist_append(columns, column);
-    }
-
-    /* Then reorder the columns */
-    g_signal_handler_block(view, priv->columns_changed_cb_id);
-    for (prev = NULL, tmp = columns; tmp; tmp = g_slist_next(tmp))
-    {
-        column = tmp->data;
-        gtk_tree_view_move_column_after(GTK_TREE_VIEW(view), column, prev);
-        prev = column;
-    }
-    g_signal_handler_unblock(view, priv->columns_changed_cb_id);
-
-    /* Clean up */
-    g_slist_free(columns);
-    LEAVE("column order set");
-}
-
-/** This function is called via the gconf notification callback when
- *  any change has occurred.  It must update the appropriate aspect of
- *  the model/view to match what is specified in gconf.  Some of the
- *  updates are handled in this function, while others are handled by
- *  other helper functions.
- *
- *  @param client A pointer to the gconf client object from which
- *  detected a change in gconf.  Unused by this function.
- *
- *  @param cnxn_id The identifier for the notification that this callback
- *  represents.  Unused since this code only has a single notification
- *  request.
- *
- *  @param entry A pointer to the key/value pair in gconf that changed.
- *
- *  @param data The tree view.
- *
- *  @internal
- */
-static void
-gnc_tree_view_gconf_changed (GConfClient *client,
-                             guint cnxn_id,
-                             GConfEntry *entry,
-                             gpointer data)
-{
-    GncTreeView *view;
-    GncTreeViewPrivate *priv;
-    GtkTreeViewColumn *column;
-    GConfValue *value;
-    const gchar *key, *local;
-    gchar *column_name, *type_name;
-    gboolean known;
-    gint width;
-
-    g_return_if_fail(GNC_IS_TREE_VIEW(data));
-
-    ENTER(" ");
-    view = GNC_TREE_VIEW(data);
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    key = gconf_entry_get_key(entry);
-    value = gconf_entry_get_value(entry);
-
-    if (!value)
-    {
-        /* Values can be unset */
-        LEAVE("Unset valued for %s", key);
-        return;
-    }
-
-    DEBUG("Key %s, value %p", key, value);
-    local = strrchr(key, '/') + 1;
-    if (strcmp(local, STATE_KEY_SORT_COLUMN) == 0)
-    {
-        gnc_tree_view_set_sort_column(view, gconf_value_get_string(value));
-    }
-    else if (strcmp(local, STATE_KEY_SORT_ORDER) == 0)
-    {
-        gnc_tree_view_set_sort_order(view, gconf_value_get_string(value));
-    }
-    else if (strcmp(local, STATE_KEY_COLUMN_ORDER) == 0)
-    {
-        gnc_tree_view_set_column_order(view, gconf_value_get_list(value));
-    }
-    else
-    {
-        /* Make a copy of the local part of the key so it can be split
-         * into column name and key type */
-        known = FALSE;
-        column_name = g_strdup(local);
-        type_name = strrchr(column_name, '_');
-        *type_name++ = '\0';
-
-        if (strcmp(type_name, STATE_KEY_VISIBLE) == 0)
-        {
-            priv->seen_state_visibility = TRUE;
-            column = gnc_tree_view_find_column_by_name(view, column_name);
-            if (column)
-            {
-                known = TRUE;
-                if (!g_object_get_data(G_OBJECT(column), ALWAYS_VISIBLE))
-                {
-                    gtk_tree_view_column_set_visible(column, gconf_value_get_bool(value));
-                }
-            }
-        }
-        else if (strcmp(type_name, STATE_KEY_WIDTH) == 0)
-        {
-            width = gconf_value_get_int(value);
-            column = gnc_tree_view_find_column_by_name(view, column_name);
-            if (column)
-            {
-                known = TRUE;
-                if (width && (width != gtk_tree_view_column_get_width(column)))
-                {
-                    gtk_tree_view_column_set_fixed_width(column, width);
-                }
-            }
-        }
-        if (!known)
-        {
-            DEBUG("Ignored key %s", key);
-        }
-        g_free(column_name);
-    }
-    LEAVE(" ");
-}
-
-/** This function is called force synchronization between the gconf
- *  database and a tree view.  It will be called for major events like
- *  assigning a gconf section to a tree view.  All values in gconf
- *  will be propagated into the view.  This function simply requests a
- *  list of all key in the section from gconf, then feeds them one at
- *  a time to gnc_tree_view_gconf_changed().
- *
- *  @param view The tree view.
- *
- *  @internal
- */
-static void
-gnc_tree_view_gconf_force_update (GncTreeView *view)
-{
-    GncTreeViewPrivate *priv;
-    GSList *all_entries, *etmp;
-    GList *columns;
-
-    ENTER("view %p", view);
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    all_entries = gnc_gconf_client_all_entries(priv->state_section);
-
-    /* Set a flag indicating that the gconf data section may be empty.
-     * It will be checked later on and appropriate action taken if its
-     * still set. */
-    priv->seen_state_visibility = FALSE;
-
-    /* Pull all the entries from gconf */
-    for (etmp = all_entries; etmp; etmp = g_slist_next(etmp))
-    {
-        gnc_tree_view_gconf_changed(NULL, 0, etmp->data, view);
-        gconf_entry_free(etmp->data);
-    }
-    g_slist_free(all_entries);
-
-    /* No visibilities seen yet.  Write out any columns we may have */
-    if (!priv->seen_state_visibility)
-    {
-        columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
-        g_list_foreach(columns, (GFunc)gnc_tree_view_update_visibility, view);
-        g_list_free(columns);
-    }
-
-    LEAVE(" ");
-}
-
-/** This internal function is called to disconnect a tree view from a
- *  gconf section.  It first disconnects any signals that are in
- *  effect on the model/view, then removes the gconf notification
- *  callback, then clears the gconf section string.  This function may
- *  be called at any time; either when the user wants to disconnect or
- *  when the view object is being destroyed.
- *
- *  @param view The tree view.
- *
- *  @internal
- */
-static void
-gnc_tree_view_remove_gconf_callbacks(GncTreeView *view)
-{
-    GncTreeViewPrivate *priv;
-    GtkTreeModel *model;
-
-    ENTER(" ");
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    if (!priv->state_section)
-    {
-        LEAVE("no gconf section");
-        return;
-    }
-
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    if (priv->sort_column_changed_cb_id)
-    {
-        model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
-        if (model)
-        {
-            DEBUG("removing sort_column_changed callback (# %ld)",
-                  priv->sort_column_changed_cb_id);
-            g_signal_handler_disconnect(GTK_TREE_SORTABLE(model),
-                                        priv->sort_column_changed_cb_id);
-            priv->sort_column_changed_cb_id = 0;
-        }
-    }
-
-    if (priv->columns_changed_cb_id)
-    {
-        DEBUG("removing columns_changed callback (# %ld)",
-              priv->columns_changed_cb_id);
-        g_signal_handler_disconnect(view, priv->columns_changed_cb_id);
-        priv->columns_changed_cb_id = 0;
-    }
-
-    if (priv->size_allocate_cb_id)
-    {
-        DEBUG("removing size_allocate callback (# %ld)",
-              priv->size_allocate_cb_id);
-        g_signal_handler_disconnect(view, priv->size_allocate_cb_id);
-        priv->size_allocate_cb_id = 0;
-    }
-
-    DEBUG("removing gconf notification");
-    gnc_gconf_remove_notification(G_OBJECT(view), priv->state_section,
-                                  GNC_TREE_VIEW_NAME);
-    g_free(priv->state_section);
-    priv->state_section = NULL;
-    LEAVE(" ");
-}
-
 /** This function is called to completely wipe the treeview's state
- *  information (column visibility, width, sorting order,..). This
- *  information is currently saved in gconf, so the gconf section
- *  associated to the tree view will be wiped. It will first disconnect
- *  the tree view from the gconf section and then removes the gconf
- *  section with keys from gconf.  This function may
+ *  information (column visibility, width, sorting order,..).  This function may
  *  be called at any time; either when the user wants to disconnect or
  *  when the view object is being destroyed.
  *
+ *  FIXME this currently does nothing because state info is not saved yet
+ *
  *  @param view The tree view.
  */
 
 void gnc_tree_view_remove_state_information(GncTreeView *view)
 {
     GncTreeViewPrivate *priv;
-    gchar *section = NULL;
 
     ENTER(" ");
     priv = GNC_TREE_VIEW_GET_PRIVATE(view);
@@ -1259,25 +664,18 @@
         return;
     }
 
-    /* Make a copy of the section name, because
-     * the call to gnc_tree_view_remove_gconf_callbacks
-     * unsets it and we still need it to really remove
-     * the gconf section itself.
-     */
-    section = g_strdup (priv->state_section);
-    gnc_tree_view_remove_gconf_callbacks (view);
-    gnc_gconf_unset_dir (section, NULL);
-    g_free (section);
+    g_free(priv->state_section);
+    priv->state_section = NULL;
     LEAVE(" ");
 }
 
 /** This function is called to set up or remove an association between
  *  a saved state section and the display of a view.  It will first remove
- *  any existing association, and then install the new one.  This
- *  involves storing the state section value, requesting notification
- *  from gconf of any changes to keys in that section, then attaching
- *  several signals to catch user changes to the view.
+ *  any existing association, and then install the new one.
  *
+ *  FIXME this currently does almost nothing because state information
+ *        is currently not stored
+ *
  *  Parameters are defined in gnc-tree-view.h
  */
 void
@@ -1291,49 +689,28 @@
     g_return_if_fail(GNC_IS_TREE_VIEW(view));
 
     ENTER("view %p, section %s", view, section);
-    gnc_tree_view_remove_gconf_callbacks(view);
 
+    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
+    g_free(priv->state_section);
+    priv->state_section = NULL;
+
     if (!section)
     {
-        LEAVE("cleared gconf section");
+        LEAVE("cleared state section");
         return;
     }
 
-    /* Catch changes in gconf. Propagate to view. */
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
+    /* Catch changes in state. Propagate to view. */
     priv->state_section = g_strdup(section);
-    gnc_gconf_add_notification(G_OBJECT(view), section,
-                               gnc_tree_view_gconf_changed,
-                               GNC_TREE_VIEW_NAME);
 
-    /* Catch changes to the sort column. Propagate to gconf. The key can
-     * be set before the model, so the code must handle that case. */
-    model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
-    if (model)
-        priv->sort_column_changed_cb_id =
-            g_signal_connect(GTK_TREE_SORTABLE(model), "sort-column-changed",
-                             (GCallback)gtk_tree_view_sort_column_changed_cb, view);
 
-    /* Catch changes to the column order. Propagate to gconf */
-    id = g_signal_connect(view, "columns-changed",
-                          (GCallback)gtk_tree_view_columns_changed_cb, NULL);
-    priv->columns_changed_cb_id = id;
-
-    /* Catch changes to the column width. Propagate to gconf */
-    id = g_signal_connect(view, "size-allocate",
-                          (GCallback)gtk_tree_view_size_allocate_cb, NULL);
-    priv->size_allocate_cb_id = id;
-
-    /* Force an update of the view with all items from gconf. */
-    gnc_tree_view_gconf_force_update(view);
-
     /* Rebuild the column visibility menu */
     gnc_tree_view_build_column_menu(view);
-    LEAVE("set gconf section");
+    LEAVE("set state section");
 }
 
 /** This function is called to get the current association between a
- *  gconf section and the display of a view.  It returns the same
+ *  state section and the display of a view.  It returns the same
  *  value passed to gnc_tree_view_set_state_section(); i.e. a string
  *  like "dialogs/edit_prices".
  *
@@ -1360,43 +737,6 @@
 /** @name Gnc Tree View Column Selection Menu Related Functions
  @{ */
 
-/** This function is called when an entry in the column selection menu
- *  is toggled.  It must update gconf with the current value of the
- *  checkbox.  This will trigger a callback to other functions which
- *  will then change the actual state of the view.
- *
- *  @param checkmenuitem A checkbox visible in the menu.
- *
- *  @param view The tree view.
- *
- *  @internal
- */
-static void
-gnc_tree_view_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
-                                 GncTreeView *view)
-{
-    GncTreeViewPrivate *priv;
-    gboolean value;
-    gchar *key;
-
-    g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(checkmenuitem));
-    g_return_if_fail(GNC_IS_TREE_VIEW(view));
-
-    ENTER("checkmenuitem %p, view %p", checkmenuitem, view);
-    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    if (!priv->state_section)
-    {
-        LEAVE("no state section");
-        return;
-    }
-
-    key = g_object_get_data(G_OBJECT(checkmenuitem), STATE_KEY);
-    value = gtk_check_menu_item_get_active(checkmenuitem);
-    gnc_gconf_set_bool(priv->state_section, key, value, NULL);
-    LEAVE("set state section %s, key %s, visible %d",
-          priv->state_section, key, value);
-}
-
 /** This function is called to create a single checkmenuitem in the
  *  column selection menu.  It is called once for each column in the
  *  view.  It creates a menu item for the corresponding column, and
@@ -1420,6 +760,7 @@
     GtkWidget *widget;
     const gchar *column_name, *pref_name;
     gchar *key;
+    GBinding *binding;
 
     // ENTER("view %p, column %p", view, column);
     priv = GNC_TREE_VIEW_GET_PRIVATE(view);
@@ -1457,9 +798,8 @@
         gtk_widget_set_sensitive(widget, FALSE);
     }
 
-    /* Set up the callback  */
-    g_signal_connect(widget, "toggled",
-		     (GCallback)gnc_tree_view_menu_item_toggled, view);
+    binding = g_object_bind_property (G_OBJECT (widget), "active", G_OBJECT (column), "visible", 0);
+    g_object_set_data (G_OBJECT (widget), "column-binding", binding);
 
     /* Store data on the widget for callbacks */
     key = g_strdup_printf("%s_%s", pref_name, STATE_KEY_VISIBLE);
@@ -1518,13 +858,7 @@
 }
 
 /** This function is called to synchronize the checkbox on a menu item
- *  with the current state visibility value for the corresponding
- *  column (which will be the visibility of the column if the rest of
- *  the code in this file is working correctly).  It simply takes the
- *  state key attached to the menu item, reads it, and sets the menu
- *  item to the retrieved value.  It does take care to block signals
- *  from the menu item to prevent updating gconf (since the value was
- *  just read from gconf).
+ *  with the current visibility for the corresponding column.
  *
  *  @param checkmenuitem The menu item to update.
  *
@@ -1551,14 +885,13 @@
     }
     else
     {
-        visible = gnc_gconf_get_bool(priv->state_section, key, NULL);
+        GBinding *binding = g_object_get_data (G_OBJECT (checkmenuitem), "column-binding");
+        GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(g_binding_get_target (binding));
+
+        visible = gtk_tree_view_column_get_visible (column);
     }
 
-    g_signal_handlers_block_by_func(checkmenuitem,
-                                    gnc_tree_view_menu_item_toggled, view);
     gtk_check_menu_item_set_active(checkmenuitem, visible);
-    g_signal_handlers_unblock_by_func(checkmenuitem,
-                                      gnc_tree_view_menu_item_toggled, view);
 }
 
 /** This function when the user clicks on the button to show the
@@ -1756,11 +1089,11 @@
 
 /** Attach a data model to a visible GncTreeView widget.  Users of
  *  this view object must use this function instead of directly
- *  calling the gtk_tree_view_set_model function.  This function takes
- *  the additional step of attaching a callback function to the model
- *  to catch any changes to the sorting of the model.  These changes
- *  are propagated into gconf by the callback function.
+ *  calling the gtk_tree_view_set_model function.
  *
+ *  FIXME Investigate if it still makes sense once saving/restoring
+ *        state is reimplemented.
+ *
  *  Parameters are defined in gnc-tree-view.h
  */
 void
@@ -1771,22 +1104,8 @@
 
     /* Remove existing callback */
     priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-    if (priv->sort_column_changed_cb_id)
-    {
-        old_model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
-        g_signal_handler_disconnect (old_model, priv->sort_column_changed_cb_id);
-        priv->sort_column_changed_cb_id = 0;
-    }
 
     gtk_tree_view_set_model (GTK_TREE_VIEW(view), model);
-
-    /* Maybe add a new callback */
-    if (model && priv->state_section)
-    {
-        priv->sort_column_changed_cb_id =
-            g_signal_connect(GTK_TREE_SORTABLE(model), "sort-column-changed",
-                             (GCallback)gtk_tree_view_sort_column_changed_cb, view);
-    }
 }
 
 static gint
@@ -1820,7 +1139,7 @@
 
     ENTER(" ");
 
-    /* Update the view and gconf */
+    /* Update the view and saved state */
     columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
     g_list_foreach(columns, (GFunc)gnc_tree_view_update_visibility, view);
     g_list_free(columns);
@@ -1914,15 +1233,9 @@
     else
     {
         priv = GNC_TREE_VIEW_GET_PRIVATE(view);
-        if (priv->state_section)
-        {
-            key = g_strdup_printf("%s_%s", pref_name, STATE_KEY_WIDTH);
-            width = gnc_gconf_get_int(priv->state_section, key, NULL);
-            g_free(key);
-        }
 
-        /* If gconf comes back with a width of zero (or there is no gconf
-         * width) the use the default width for the column.  Allow for
+        /* If saved state comes back with a width of zero (or there is no saved
+         * state width) the use the default width for the column.  Allow for
          * padding L and R of the displayed data. */
         if (width == 0)
             width = default_width + 10;

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view.h	2013-10-07 14:27:34 UTC (rev 23260)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view.h	2013-10-07 14:27:50 UTC (rev 23261)
@@ -78,18 +78,16 @@
 /* For checkbox columns, this contains the real title for the column. */
 #define REAL_TITLE  "real_title"
 
-/* The name of this column as it should appear in gconf.  This is
- * attached to the column when it is created, and used to map back and
- * forth to gconf keys.  The actual gconf keys are built from these
- * strings. */
+/* The name of this column to use when saving the view's state.  It is
+ * used internally to map this colum's properties to the saved state. */
 #define PREF_NAME  "pref-name"
 
 /* A column with this attribute set cannot be hidden from view. Valid
    values: GINT_TO_POINTER(0) and GINT_TO_POINTER(1) */
 #define ALWAYS_VISIBLE  "always-visible"
 
-/* This attribute controls visibility of a non-gconf column or a gconf
-   column before a visibility preference has been recorded. Valid values:
+/* This attribute controls visibility of a column if not state was saved
+   for this column (yet). Valid values:
    GINT_TO_POINTER(0) and GINT_TO_POINTER(1)  */
 #define DEFAULT_VISIBLE  "default-visible"
 
@@ -110,9 +108,7 @@
  *  It takes all the parameters necessary to hook a GtkTreeModel
  *  column to a GtkTreeViewColumn.  It handles creating a tooltip to
  *  show the full title name, and setting the sort and edit callback
- *  functions.  If the tree has a gconf section associated with it,
- *  this function also wires up the column so that its visibility and
- *  width are remembered.
+ *  functions.
  *
  *  @param view A pointer to a generic GncTreeView.
  *
@@ -126,8 +122,7 @@
  *
  *  @param pref_name The internal name of this column.  This name is
  *  used in several functions to look up the column, and it is also
- *  used to create the keys used to record the column width and
- *  visibility in gconf.
+ *  used when saving/restoring the view's state.
  *
  *  @param model_data_column The index of the GtkTreeModel data column
  *  used to determine whether the displayed checkbox for each row will
@@ -159,9 +154,7 @@
 
 /** This function adds a new text column to a GncTreeView base view.
  *  It takes all the parameters necessary to hook a GtkTreeModel
- *  column to a GtkTreeViewColumn.  If the tree has a gconf section
- *  associated with it, this function also wires up the column so that
- *  its visibility and width are remembered.
+ *  column to a GtkTreeViewColumn.
  *
  *  @param view A pointer to a generic GncTreeView.
  *
@@ -169,8 +162,7 @@
  *
  *  @param pref_name The internal name of this column.  This name is
  *  used in several functions to look up the column, and it is also
- *  used to create the keys used to record the column width and
- *  visibility in gconf.
+ *  used when saving/restoring the view's state.
  *
  *  @param stock_icon_name The name of the stock icon to display to
  *  the left of the text in this column.  Used for adding icons like
@@ -243,9 +235,7 @@
 
 /** This function adds a new numeric column to a GncTreeView base
  *  view.  It takes all the parameters necessary to hook a
- *  GtkTreeModel column to a GtkTreeViewColumn.  If the tree has a
- *  gconf section associated with it, this function also wires up the
- *  column so that its visibility and width are remembered.  A numeric
+ *  GtkTreeModel column to a GtkTreeViewColumn.  A numeric
  *  column is nothing more then a text column with a few extra
  *  attributes.
  *
@@ -255,8 +245,7 @@
  *
  *  @param pref_name The internal name of this column.  This name is
  *  used in several functions to look up the column, and it is also
- *  used to create the keys used to record the column width and
- *  visibility in gconf.
+ *  used when saving/restoring the view's state.
  *
  *  @param sizing_text A string used to compute the default width of
  *  the column.  This text is never displayed.
@@ -318,8 +307,7 @@
  *  this view object must use this function instead of directly
  *  calling the gtk_tree_view_set_model function.  This function takes
  *  the additional step of attaching a callback function to the model
- *  to catch any changes to the sorting of the model.  These changes
- *  are propagated into gconf by the callback function.
+ *  to catch any changes to the sorting of the model.
  *
  *  @param view The visible tree widget.
  *
@@ -328,14 +316,14 @@
 void gnc_tree_view_set_model(GncTreeView *view, GtkTreeModel *model);
 
 /** Make all the correct columns visible, respecting their default
- *  visibility setting, their "always" visibility setting, and their
- *  gconf visibility settings, if managed by gconf.
+ *  visibility setting, their "always" visibility setting, and the
+ *  last saved state if available.
  *
  *  @param view A pointer to an gnc tree view.
  */
 void gnc_tree_view_configure_columns (GncTreeView *view);
 
-/** Find a tree column given the "pref name" used with gconf.  This
+/** Find a tree column given the "pref name".  This
  *  function simply runs the list of all (visible and invisible)
  *  columns looking for a match.  Column names were attached to each
  *  column at the time the column was created.
@@ -350,48 +338,38 @@
                                    const gchar *wanted);
 
 /** This function is called to set up or remove an association between
- *  a gconf section and the display of a view.  It will first remove
- *  any existing association, and then install the new one.  This
- *  involves storing the gconf section value, requesting notification
- *  from gconf of any changes to keys in that section, then attaching
- *  several signals to catch user changes to the view.
+ *  a saved state section and the display of a view.  It will first remove
+ *  any existing association, and then install the new one.
  *
  *  @note This function currently marks the first column as autosized
- *  and all other columns as fixed size (with the size tracked by
- *  gconf).  This may change in the future.  It must change if we want
+ *  and all other columns as fixed size.
+ *  This may change in the future.  It must change if we want
  *  to take advantage of the "fixed row height" performance
  *  enhancements added to GtkTreeView in gtk-2.4
  *
  *  @param view The tree view.
  *
- *  @param section Link the view to this gconf section.  This is
- *  everything after "/apps/gnucash".  I.E. "dialogs/edit_prices".
- *  Use NULL to disconnect a gconf association.
+ *  @param section Link the view to this saved state section.
+ *  Use NULL to disconnect saved state association.
  */
 void gnc_tree_view_set_state_section (GncTreeView *view,
                                       const gchar *section);
 
 /** This function is called to get the current association between a
- *  gconf section and the display of a view.  It returns the same
- *  value passed to gnc_tree_view_set_state_section(); i.e. a string
- *  like "dialogs/edit_prices".
+ *  saved state section and the display of a view.  It returns the same
+ *  value passed to gnc_tree_view_set_state_section().
  *
  *  @param view The tree view.
  *
- *  @return The current gconf section.  This is everything after
- *  "/apps/gnucash".  I.E "dialogs/edit_prices".
+ *  @return The current state section.
  */
 const gchar *gnc_tree_view_get_state_section (GncTreeView *view);
 
 
 /** This function is called to completely wipe the treeview's state
- *  information (column visibility, width, sorting order,..). This
- *  information is currently saved in gconf, so the gconf section
- *  associated to the tree view will be wiped. It will first disconnect
- *  the tree view from the gconf section and then removes the gconf
- *  section with keys from gconf.  This function may
- *  be called at any time; either when the user wants to disconnect or
- *  when the view object is being destroyed.
+ *  information (column visibility, width, sorting order,..).
+ *  This function may be called at any time; either when the user
+ *  wants to disconnect or when the view object is being destroyed.
  *
  *  @param view The tree view.
  */



More information about the gnucash-changes mailing list