showing a logfile in a Textview(like tail -f)



Which is the best way to create a textview that show me the actuall logfile
in a gtktextview?
Currently i update a buffer with gtk_text_buffer_insert_at_cursor(data,
line, -1);    in a timeout, the problem here is that the new text gets
copied at the and of the old text, i also tried gtk_text_buffer_insert, but
that gives me no text or a segfault.

This is the function that gets called by teh timeout
out_smb_status(gpointer data){

   system("smbstatus -S > /tmp/smb_status");

   FILE *fp = fopen("/tmp/smb_status", "r");
   gchar line[512];


   if (fp)
   {
       while (fgets(line, sizeof(line), fp))
       {
       gtk_text_buffer_delete(data, 1, 512);
       gtk_text_buffer_insert_at_cursor(data, line, -1);
       //gtk_text_buffer_insert (data, 1, line, -1);
       //gtk_text_buffer_set_text(data, line, -1);
       }
       fclose(fp);
   }
   return data;

}

and the rest

textview1 = gtk_text_view_new();
   puffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview1));

   g_timeout_add(500, out_smb_status, puffer);

   gtk_widget_show (textview1);
   gtk_container_add (GTK_CONTAINER (scrolledwindow2), textview1);

I had the idea that there is something wrong with my fileopening, maybe

thx

rupert



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