Little post about a useful design pattern in GLib and GTK, written down after a question on the #gtk+ channel
While I’m not Philip and I won’t go as far as talking about this in public, I wrote down a simple design pattern for lazy loading stuff from a list into a GtkTreeView
without blocking your interface or using threads.
There is a typo in cleanup_load_items in the g_assert. It should probably be == not =.
What do you do if you need to use your GtkTreeView before it’s completely loaded? How would you force the load?
Also, is the state definition really necessary, since the state transitions are effectively managed internally by the idle function manager?
Nitpick: doesn’t g_idle_add_full actually take 5 parameters?
aleksey: fixed, thanks :-)
mike: I’d use the same pattern shown by philip van hoof: proxy objects and loading only stuff that is effectively shown. the state definition is just to make clear we are using a state machine; it’s also useful for checking the internal state, and for avoiding multiple reloads. as for the g_idle_add_full(): no, it takes 4 parameters: the priority, the callback, the data to pass to the callback and the function to be called when the idle is removed.
I’ve put this on http://live.gnome.org/GnomeRecipes
Duh… I was looking at gtk_idle_add_full.
I believe you meant to pass “data” rather than “store” for the third parameter of g_idle_add_full. Thanks for the example code!
nelson: thanks!
matthias: yep, fixed that :-)