Re: fileselection question



Hi, I think you're comparing pointers when you should be comparing strings.

Add the selected filename to your list with

   my_selection_list = g_list_prepend( my_selection_list,
       g_strdup( file_selected ) );

(prepend is faster than append, and you need to strdup pointers you get 
back from _get_filename())

Test for is-filename-there-already by looping along your list and 
strcmp()ing each element. You can use g_list_find_custom for this:

   if( g_list_find_custom( my_selection_list,
       file_selected, strcmp ) ) {

HTH, John

A R Hummaida wrote:

> i have the following
> 
> 
> GList *my_selection_list; //global
> 
> // call back for ok button on file selection
> 
> void on_file_selection_ok_button_clicked (GtkWidget * w,  gpointer 
> user_data)
> {
> .
> .
> gchar *file_selected ;
> 
>  file_selected =
>    gtk_file_selection_get_filename (GTK_FILE_SELECTION  
> (file_selection_widget));
> .
> .
> .
> if (g_list_find(my_selection_list,file_selected)==NULL)
>        {        my_selection_list=g_list_append 
> (my_selection_list,file_selected);
> g_print("file selected is %s\n",file_selected);
> .
> .
> 
>       }
> }
> 
> so i want a file to be selected only once.this works the first time as 
> the list is empty but next tries don't
> print the file name even though a different file is selected. i have 
> tried many of these glist functions to no avail. please help




========================================================== 
Coming soon: 
Aelbert Cuyp 13 February - 12 May 2002 

For information and tickets: 
http://www.nationalgallery.org.uk



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