Implementing a ListStore


#1

I need to display a list of articles taken from a database.
The list is large (more than 300 articles and the number will grow up)
and
I use ActiveRecord to dialog with the DB.

My problem is that saving each article in the ListStore is a bit slow
and
taking inspiration from the article
http://www.kdedevelopers.org/node/2670 I
thought
I could write my own ListStore that internally use the articels list get
from
ActiveRecord.

The problem is that I don’t know which methods I have to re-define to
make
my
StoreList work. Which interface I have to implement?
Here there is an example:

####################################################################

require ‘gtk2’

class MyListStore < Gtk::ListStore
def initialize(model)
@model = model
super(String)
end

these are the method that I didn’r re-define

exclude = %w{object_id send id}

In this way I re-define all the methods

and each method raise a NotImplementedError,

in this way I thought to know which method

the View uses to get the data from the store,

but no exception is thrown and In the wiew

no row is shown

instance_methods(true).each do |method|
a << method
if(exclude.find(){|el| el == method}.nil?)
str = %{
def #{method}()
raise NotImplementedError.new(’#{method}’)
end}
module_eval(str)
end
end
end

The controller set up the connection with the DB

controller = Controller::Controller.new(File::dirname(FILE))

@window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
@window.set_default_size(900, 400)
@window.set_border_width(10)
@window.signal_connect(‘delete_event’) {Gtk.main_quit}

articles = Article.find(:all)
table_store = MyListStore.new(articles)
table_view = Gtk::TreeView.new(table_store)

renderer = Gtk::CellRendererText.new
renderer.xalign = 0.5
renderer.yalign = 0.5
col = Gtk::TreeViewColumn.new(‘Barcode’, renderer, :text => 0)
col.alignment = 0.5
table_view.append_column(col)
@window.add(table_view)
@window.show_all
Gtk.main
####################################################################

The table view is displaied but no rows is present. I’ve redefined all
the
methods
of MyListStore to throw an exception, in this way I whought to know
which
methods
the View uses to get the data from the Store, but no exception was
thrown.

Thank you,

Gendag