LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to parse log files into text view using GLADE (https://www.linuxquestions.org/questions/programming-9/how-to-parse-log-files-into-text-view-using-glade-409975/)

shandy^^^ 01-31-2006 07:38 AM

How to parse log files into text view using GLADE
 
hi to all,

i want to display the contents of log files (e.g. /var/log/messages) in the textview of the GUI, but i don't know how to do that. i'm using GLADE for the gui.

please help me...:confused:

con 01-31-2006 12:07 PM

Code:

/* This line gets a pointer to the text widget */
 GtkWidget * textview = lookup_widget(GTK_WIDGET(button), "textview1");

/* ...and thils line prints the the text into the text box */
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)), _(text_2_be_printed), -1);

working on something similar myself. Hope this helps:)

shandy^^^ 01-31-2006 10:52 PM

Hello,
Thanx for the info..

*****gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)), _(text_2_be_printed), -1);******

i just want to know if it is possible that i could have the text to be printed from a certain folder. (e.g from var/log/messages) i want to display the messages in the textview.

con 02-01-2006 12:22 AM

First you gotta read the file into a variable, there is a great function for this in glib called g_file_get_contents() then do the code I posted above.
http://developer.gnome.org/doc/API/2...e-get-contents

shandy^^^ 02-01-2006 06:52 AM

hello,

I've read the API with the link that u gave. I just want to ask if there is anything that i should add in my main.c inorder to use this function.
I'm also confused on where to put this function, is it in callbacks.c, interface.c or main.c.

Thank you very much for ur help, i just badly need it.

con 02-01-2006 02:21 PM

That I think depends on how you want the program to work i.e if you want it to display the text when the user pushes a button. But most likely it will go into a function in callbacks.c.

shandy^^^ 02-02-2006 09:46 AM

hello,

thanks again, i can already view the contents of the file into the textview provided that the log file or any file will be place in the src folder of my project folder.
i would have wanted to display a log file from any directory (e.g. from /var/log/messages.log) without copying this to my src file. would that be possible?

con 02-02-2006 09:55 AM

Quote:

thanks again,
You're welcome
Quote:

would have wanted to display a log file from any directory
just pass the full path to the file, to the function that reads the file...and do some reading on file I/O :)

shandy^^^ 02-07-2006 08:13 PM

Thanks con,

I can already display the contents of any file when i inserted g_file_get_contents()in my interface.c
But when i tried to have it in my main.c or callbacks.c, its compilation is successful but when i run the program, it would display an error like this:

The Application "myFilename" has quit unexpectedly.

Hope u can help me with this.


All times are GMT -5. The time now is 04:28 PM.