Re: GIOChannel + GtkTreeModel length

--- Begin Message ---
Am 16 Feb 2002 10:43:33 +0100 schrieb Andreas Scherf:
> Hello, 
> i want to transfer some printing datas via a giochannel to the lpr 
> system command. Today i'm doing that via pipes and closed stdout ...
> How could i do that via the giochannel support ? Any hints ?
> 2. Is there a method for getting the number of lines from a GtkTreeModel
> like the clist->rows element in gtk1.2 ?? Thats because i want to get
> the number of lines before catching all row datas via 
>  gtk_tree_model_iter_next(GTK_TREE_MODEL(p_obj->main_list),&iter)
> So how could i get the number of rows before ??
> Thanks
> Andreas
> -- 
> Andreas Scherf
> ICQ: 52910964
> scherfa web de
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org

1. GIOChannel

You can run lpr using something like this

bRunning = g_spawn_async_with_pipes (NULL,  /* workingdir*/
                                     gargv, /* arguments*/
NULL,  /* enviroment*/                       G_SPAWN_SEARCH_PATH | /*
options */
                                     NULL,  /* creationfunc*/
                                     NULL,  /* daten */
                                     &pid,  /* pid */
                                 &in_desc,  /* stdin*/
&out_desc,  /* stdo*/
                                &err_desc,  /* stderr*/
                                    NULL);  /* error*/

Your gargv sould be something like

gchar *gargv[2] = {"lpr", NULL};

or similar.

You can also use the g_spawn_sync_with_pipes function. It depends on
what you need.

Now you can create the io_channels.

if (in_desc) {
  io_in     = g_io_channel_unix_new (in_desc);	
  event_id1 = g_io_add_watch  (io_in, G_IO_OUT, write_func, data);
  event_id2 = g_io_add_watch  (io_in, G_IO_HUP, hup_func, data);

These watches are callbacks for the io_channels. You don't have to
createe them. Again, it depends on what you need.
But keep one thing in mind. When you use g_io_add_watch you have to
remove this watch from the main event loop (or however it is called)
again using the g_source_remove function. Otherwise there will be some
problems when you close the channel again. That's why you have to store
the event_ids somewhere. You might create a structure  or an array where
you save them and pass it to the hup_func as data.

Oh yes, some variables you might need

gboolean  brunning =  FALSE;
GIOChannel  *io_in =  NULL;
gint           pid =  0,
           in_desc =  0, 
          out_desc =  0, /*don't know whether you need them*/
          err_desc =  0; /*don't know whether you need them*/

2. Tree

Don't know, sorry *g*



--- End Message ---

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