pan-devel
[Top][All Lists]
Advanced

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

Re: [Pan-devel] Re: Re: Want to fix memory consumption issues


From: Evan Martin
Subject: Re: [Pan-devel] Re: Re: Want to fix memory consumption issues
Date: Wed, 16 Jun 2004 11:54:11 -0700
User-agent: Mutt/1.5.6i

On Fri, Jun 04, 2004 at 06:51:36PM -0600, K. Haley wrote:
> >Cool.  So if that is the case, then it makes it easier to slap a DB
> >backend in place, as the GUI already seems to be reading in header
> >information into widgets in a piecemeal fashion.. which is what one wants.
> >
> The GUI should be requesting data from the Article as it's needed for 
> display.  If it's not then I would consider that to be a bug.

To do this:

 - create your GtkTreeModel with only one "column", a pointer to the Article

 - create your GtkTreeView with multiple columns that each has a custom
   "cell data" function:

cell_renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column, cell_renderer, TRUE);
gtk_tree_view_column_set_cell_data_func(column, cell_renderer,
                                        username_data_func, NULL, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);

  - that "username_data_func", when called, updates the cell with the
    relevant data.  Here, I use the pointer stored to set the text, foreground,
    and background of the cell:

static void
username_data_func(GtkTreeViewColumn *tree_column,
                    GtkCellRenderer   *cell,
                    GtkTreeModel      *model,
                    GtkTreeIter       *iter,
                    gpointer           data)
{
    LJFriend *friend;
    GdkColor fg = {0}, bg = {0};

    gtk_tree_model_get(model, iter,
            0, &friend, 
            -1);
    
    rgb_to_gdkcolor(friend->foreground, &fg);
    rgb_to_gdkcolor(friend->background, &bg);
    
    g_object_set(cell,
            "text", friend->username,
            "foreground-gdk", &fg,
            "background-gdk", &bg,
            NULL);
}

  - additionally, set up a custom sort function so clicking on the
    column headers will sort.  the function uses gtk_tree_model_get to
    get the pointer to the backing data (Article in your case) then
    behaves like strcmp.  attach it with
      gtk_tree_sortable_set_sort_func

  - finally, to allow searching (via ctl-f or ctl-s, depending on
    whether you're using gtk or emacs keys), do something like:
gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(view),
    search_equal_cb, NULL, NULL);
gtk_tree_view_set_search_column(GTK_TREE_VIEW(view), ...);
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), TRUE);
    where that search_equal func can be figured ou


(Can you tell I spent a while figuring this all out?)

Another option would be implementing the GtkTreeModel interface on your
article list.  This, however, seems to be quite a lot of work.  I've
been working on a GtkTreeModel that works with an array (not list!) of
pointers that seems to be quite fast.  I typically update in large
batches, so I can reallocate the array once, and I delete rarely; for
other operations the array is much more efficient.


The other major optimization you can do is to use a GTK 2.4-specific
API that sets all of the rows to the same height; this cuts down on
computations significantly.  You lose support of differing-height (think
different languages) rows, but that may be acceptable (I don't know
enough about NNTP to know whether you can have non-ascii names/subjects,
etc).

-- 
Evan Martin
address@hidden
http://neugierig.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]