Hi,
I seem to have a similar problem to this case:
I made recent_title a global variable as explained in the link. But I still get gibberish message. Parts of code:
gtk/xboard.h
extern GtkRecentInfo *recents_ptr[RECENTS_COUNT+1];
extern gchar recent_title[20];
gtk/xboard.c
GtkRecentInfo *recents_ptr[RECENTS_COUNT+1];
gchar recent_title[20];
[...]
void show_message_dialog(const gchar * const message)
{
GtkWidget* dialog = gtk_message_dialog_new (GTK_WINDOW(mainwindow),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"Message: %s",
message);
/* Destroy the dialog when the user responds to it (e.g. clicks a button) */
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
dialog);
gtk_widget_show_all (dialog);
return;
}
void show_message_dialog_event(GtkWidget*label_1,gpointer message)
{
show_message_dialog(message);
return;
}
gtk/xoptions.c
[...]
produce_recent_items();
for(i=0; i<RECENTS_COUNT && recents_ptr[i] ; i++)
{
GtkRecentInfo *recent_wid=recents_ptr[i];
g_stpcpy(recent_title,"TTT3_\n");
show_message_dialog(recent_title); // Works OK
const gchar *fn;
fn=gtk_recent_info_get_uri(recent_wid);
//show_message_dialog(fn); // TODO broken
g_signal_connect(G_OBJECT(recent_wid),"activate"
,G_CALLBACK(show_message_dialog_event),(gpointer)recent_title);// recent_title shows gibberish
}
backend.c
void produce_recent_items(void)
{
#include <stdbool.h>
GtkRecentManager *recent_files;
GtkRecentInfo *ri;
GList *rf_list;
const gchar *rf_str;
//GtkWidget *rf_widget;
GtkRecentInfo *rf_widget;
recent_files=gtk_recent_manager_get_default();
gtk_recent_manager_set_limit(recent_files,RECENTS_COUNT);
rf_list=gtk_recent_manager_get_items(recent_files);
int i;
for(i=0; i<RECENTS_COUNT; )
{
recents_ptr[i]=NULL;
if(rf_list==NULL)
break;
ri=rf_list->data;
bool this_app ;
gchar * name = gtk_recent_info_last_application(ri);
if(strstr(name,"xboard"))
this_app=true;
else
this_app=false;
if(this_app)
{
rf_str=gtk_recent_info_get_uri(ri);
rf_widget=gtk_menu_item_new_with_label(rf_str); // TODO warning here
recents_ptr[i]=rf_widget;
i++;
}
rf_list=rf_list->next;
}
return;
}
What to do ?
Thanks.