Re: Key-value file parser, howto get all groups and create loop from them



I've gone through all the warning and now only get one warning on my +- 700
lines of code, now i have 3 warnings left wich I dont get away by now. Thx
for the advice to
go thorugh them, my old teacher told me we can ignore them :(.
I packed the tree into a struct and now access the parts with treedata.iter.
But when i start the programm it seems there is a problem with the iterator
in the function(works fine in the main programm).

this is my struct(which will be scalled down wen the rest works)

static struct treedata {
           GtkListStore *store;
           GtkWidget *tree;
           GtkTreeIter   iter;
           GtkTreeSelection *select;
           GtkCellRenderer *renderer;
           GtkCellRenderer *pixrender;
           GtkTreeViewColumn *column_init;
           GtkTreeViewColumn *column_mount;
           GtkTreeViewColumn *column_device;
           GtkTreeViewColumn *column_name;
           GtkTreeViewColumn *column_mountpoint;
           GtkTreeViewColumn *column_passkey;
           GdkPixbuf    *pixbuf_mapper_yes;
           GdkPixbuf    *pixbuf_mapper_no;
           GdkPixbuf    *pixbuf_mount_yes;
           GdkPixbuf    *pixbuf_mount_no;
           GdkPixbuf *pixbuf_mapper;
           GdkPixbuf *pixbuf_mount;
           GdkPixbuf *pixbuf;
            }treedata;

the function which should updat the image in the treeview:

void crypto_mount_set_pixbuf(struct treedata *treedata){

   GtkTreeIter iter = treedata->iter;
   //GtkTreeModel *store = treedata->store;

   g_print("test");

/*change DATEN into a variable loop which extracts all the rows*/
   if(crypto_mount_check("DATEN"))
   {
       treedata->pixbuf_mount = gdk_pixbuf_new_from_file("pics/mount.png",
NULL);
       gtk_list_store_set(treedata->store, &iter, MOUNT_COLUMN,
treedata->pixbuf_mount, -1);
       g_object_unref(treedata->pixbuf_mount);

   }else{

       treedata->pixbuf_mount =
gdk_pixbuf_new_from_file("pics/unmount.png", NULL);
       gtk_list_store_set(treedata->store, &iter, MOUNT_COLUMN,
treedata->pixbuf_mount, -1);
       g_object_unref(treedata->pixbuf_mount);
   }
   return;
}

and the timeout

g_timeout_add(100, crypto_mount_set_pixbuf, &treedata);

Strangely the function seems to stop, because i only get 1 test on the bash:
(cryptomaster:11056): Gtk-CRITICAL **: gtk_list_store_set: assertion
`iter->stamp == list_store->stamp' failed


I have split my project into different files, if its neccesary i could
append an tarball
to my mails, if its better for you to see a solution to my problems.

greetings

On 8/5/06, tomas tuxteam de < tomas tuxteam de> wrote:

On Sat, Aug 05, 2006 at 10:18:24AM +0200, rupert wrote:
> On 8/3/06, David Ne?as (Yeti) <yeti physics muni cz > wrote:
[...]
> but how can I pass all the Information like the treestore, itert.., with
the
> g_timeout_add(), because it only allows me one filed for data to pass.

As Yeti already pointed out, build a struct to hold it all, alloc it,
pass pointer to struct (and don't forget to free when done ;-)

Or, if you are sure that there's only one struct in use at a time, use a
static (but this is a dirty technique which will haunt you at night,
believe me).

> g_timeout_add(100, crypto_mount_set_pixbuf, pixbuf_mount);
>
> and that's all.  However, if you use some images repeatedly,
> > register them as stock icons or load the pixbufs only once
> > and reuse them.
>
>
> I have no idea how to do this.
> Could you please link me to an example,
> from reading the reference i dont get is how to use it correctly:

A quick and dirty thing I use to do (when the complexity of doing stock
item things scares me -- I'm easily scared by complexity, you know) is
something like:

| #define NRPICS 4
| typedef enum {
|   sheep,
|   cow,
|   petunia,
|   alien
| } mypic;
|
| static GdkPixbuf *getpix(mypic pic)
| {
|   /* Returns pixbuf corresponding to whohas */
|   static GdkPixbuf *pix[NRPICS];
|   static char *fname[NRPICS] = {
|     "/path/to/sheep.png",
|     "/path/to/cow.png",
|     "/path/to/petunia.png",
|     "/path/to/alien.png",
|   };
|   if(pic<0 || pic>alien) pic = alien;
|   if(!pix[pic]) /* not yet realized */
|     pix[pic] = gdk_pixbuf_new_from_file(fname[pic], NULL);
|   return pix[pic];
| }

Modify to own taste.

Of course, you can get all fancy and read the list of files from a
config file ant that -- but from some point on you might be better off
reading up about all this stock stuff (which is far more
theme-friendly), for example here:

  <http://developer.gnome.org/doc/API/2.0/gtk/gtk-Themeable-Stock-Images.html
>

HTH
-- tomÃs


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFE1LD8Bcgs9XrR2kYRAszjAJ9GVUzSV5SBUvj1rEGNTO6BbTEToQCfa99y
rfR9JFz9GVfZYDeinj+s5NE=
=YZqa
-----END PGP SIGNATURE-----





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