From: Jordi Albornoz Date: Sun, 5 Jan 2003 18:25:56 +0000 (+0000) Subject: Patch from Dani Carbonell. Fix memory leak in winlist.c. More UTF-8 conversion fixes... X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=4d9fa1f83a33b2b13a133a8e8c2284f1cd935106;p=gtetrinet Patch from Dani Carbonell. Fix memory leak in winlist.c. More UTF-8 conversion fixes. Add a horizontal scrollbar to the player list. Port gtk_object_get_data to g_object_get_data. --- diff --git a/ChangeLog b/ChangeLog index 90763f2..2805a3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2003-01-05 Dani Carbonell + + * TODO: updated. + + * src/tetrinet.c (tetrinet_inmessage): converted reason to disconnect + to UTF-8 so it can be displayed properly. + + * src/winlist.c (winlist_additem): fixed memory leak. + + * src/misc.c (nocolor): it wasn't doing anything, reverted to its + previous behaviour, but now it doesn't cut accented characters ( < 0 ). + + * src/fields.c (fields_setlabel): now displays correctly all the UTF-8 + characters, applying the nocolor () function to the ASCII strings + before recoding them to UTF-8. + + * src/partyline.c (partyline_namelabel): likewise. + (partyline_page_new): added a horizontal scrollbar to the playerlist. + + * src/gtetrinet.c (keypress): string "Playing Fields" wasn't been + translated, and gtk_object_get_data ported to g_object_get_data. + (keyreleased): likewise. + 2003-01-05 Jordi Mallach * TODO: updated. diff --git a/TODO b/TODO index e864330..72a7544 100644 --- a/TODO +++ b/TODO @@ -9,5 +9,8 @@ GTetrinet's TODO list + problem when typing composed letters (รก) in fields messages + add real tooltips + port deprecated widgets (-DGTK_DISABLE_DEPRECATED) + + pressing a key when a game is in progress, but you are not playing it, + causes a Gtk-CRITICAL + + detaching and reattaching the Menu Bar causes two Bonobo-CRITICAL - Make gtetrinet resizeable (at least the fields messages bit) - Write a User Manual diff --git a/src/fields.c b/src/fields.c index f3f0c76..4d7b981 100644 --- a/src/fields.c +++ b/src/fields.c @@ -411,13 +411,13 @@ void fields_setlabel (int field, char *name, char *team, int num) gtk_label_set (GTK_LABEL(fieldlabels[field][5]), ""); } else { - name_utf8 = g_locale_to_utf8 (name, -1, NULL, NULL, NULL); + name_utf8 = g_locale_to_utf8 (nocolor (name), -1, NULL, NULL, NULL); gtk_widget_show (fieldlabels[field][0]); gtk_widget_show (fieldlabels[field][1]); gtk_widget_show (fieldlabels[field][2]); gtk_widget_hide (fieldlabels[field][3]); gtk_label_set (GTK_LABEL(fieldlabels[field][0]), buf); - gtk_label_set (GTK_LABEL(fieldlabels[field][2]), nocolor(name_utf8)); + gtk_label_set (GTK_LABEL(fieldlabels[field][2]), name_utf8); gtk_label_set (GTK_LABEL(fieldlabels[field][3]), ""); if (team == NULL || team[0] == 0) { gtk_widget_hide (fieldlabels[field][4]); @@ -425,10 +425,10 @@ void fields_setlabel (int field, char *name, char *team, int num) gtk_label_set (GTK_LABEL(fieldlabels[field][5]), ""); } else { - team_utf8 = g_locale_to_utf8 (team, -1, NULL, NULL, NULL); + team_utf8 = g_locale_to_utf8 (nocolor (team), -1, NULL, NULL, NULL); gtk_widget_show (fieldlabels[field][4]); gtk_widget_show (fieldlabels[field][5]); - gtk_label_set (GTK_LABEL(fieldlabels[field][5]), nocolor(team_utf8)); + gtk_label_set (GTK_LABEL(fieldlabels[field][5]), team_utf8); g_free (team_utf8); } g_free (name_utf8); diff --git a/src/fields.h b/src/fields.h index f935019..17a8a27 100644 --- a/src/fields.h +++ b/src/fields.h @@ -1,4 +1,5 @@ #include + extern GtkWidget *fields_page_new (void); extern void fields_page_destroy_contents (void); extern void fields_init (void); diff --git a/src/gtetrinet.c b/src/gtetrinet.c index de57573..798a9d3 100644 --- a/src/gtetrinet.c +++ b/src/gtetrinet.c @@ -325,8 +325,8 @@ gint keypress (GtkWidget *widget, GdkEventKey *key) /* Sub-window - find out which */ char *title = NULL; - title = gtk_object_get_data(GTK_OBJECT(widget), "title"); - game_area = title && !strcmp( title, "Playing Fields" ); + title = g_object_get_data(G_OBJECT(widget), "title"); + game_area = title && !strcmp( title, _("Playing Fields")); } if (game_area) @@ -334,16 +334,22 @@ gint keypress (GtkWidget *widget, GdkEventKey *key) if (keytimeoutid && key->time == k.time) gtk_timeout_remove (keytimeoutid); } + if (gtetrinet_key(key->keyval, key->state & (GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK))) - goto keyprocessed; - if (game_area && tetrinet_key (key->keyval, key->string)) goto keyprocessed; + { + gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_press_event"); + return TRUE; + } + if (game_area && tetrinet_key (key->keyval, key->string)) + { + gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_press_event"); + return TRUE; + } + return FALSE; -keyprocessed: - gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_press_event"); - return TRUE; } gint keyrelease (GtkWidget *widget, GdkEventKey *key) @@ -363,8 +369,8 @@ gint keyrelease (GtkWidget *widget, GdkEventKey *key) /* Sub-window - find out which */ char *title = NULL; - title = gtk_object_get_data(GTK_OBJECT(widget), "title"); - game_area = title && !strcmp( title, "Playing Fields" ); + title = g_object_get_data(G_OBJECT(widget), "title"); + game_area = title && !strcmp( title, _("Playing Fields")); } if (game_area) diff --git a/src/misc.c b/src/misc.c index f41d55e..fb5e43b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -119,8 +119,6 @@ void textbox_setup (void) gtet_text_tags[n].t_c = gtk_text_buffer_create_tag (buffer, NULL, "foreground-gdk", >et_text_tags[n].c, -// "background", -// "white", NULL); t_bold = gtk_text_buffer_create_tag (buffer, NULL, @@ -295,6 +293,11 @@ char *nocolor (char *str) g_string_assign(ret, str); p = scan = ret->str; + while (*scan != 0) + { + if ((*scan > 0x1F) || (*scan < 0x0)) *p++ = *scan; + scan++; + } if (scan != p) g_string_truncate(ret, len - (scan - p)); diff --git a/src/partyline.c b/src/partyline.c index 1733c62..129bab7 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -35,7 +35,7 @@ /* widgets that we have to do stuff with */ static GtkWidget *playerlist, *textbox, *entrybox, - *namelabel, *teamlabel, *infolabel, *textboxscroll; + *namelabel, *teamlabel, *infolabel, *textboxscroll, *playerlist_scroll; /* some more widgets for layout */ static GtkWidget *table, *leftbox, *rightbox; @@ -82,7 +82,7 @@ GtkWidget *partyline_page_new (void) gtk_box_pack_start (GTK_BOX(leftbox), entrybox, FALSE, FALSE, 0); gtk_widget_show (leftbox); - /* player list */ + /* player list with scrollbar */ playerlist = GTK_WIDGET (gtk_tree_view_new_with_model (GTK_TREE_MODEL (playerlist_model))); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (playerlist), -1, "", renderer, "text", 0, NULL); @@ -90,9 +90,15 @@ GtkWidget *partyline_page_new (void) "text", 1, NULL); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (playerlist), -1, _("Team"), renderer, "text", 2, NULL); - gtk_widget_set_usize (playerlist, 150, 200); gtk_widget_show (playerlist); - + playerlist_scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (playerlist_scroll), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_NEVER); + gtk_container_add (GTK_CONTAINER(playerlist_scroll), playerlist); + gtk_widget_set_usize (playerlist_scroll, 150, 200); + gtk_widget_show (playerlist_scroll); + /* right box */ box = gtk_vbox_new (FALSE, 2); @@ -131,7 +137,7 @@ GtkWidget *partyline_page_new (void) gtk_table_attach (GTK_TABLE(table), leftbox, 0, 1, 0, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0); - gtk_table_attach (GTK_TABLE(table), playerlist, 1, 2, 0, 1, + gtk_table_attach (GTK_TABLE(table), playerlist_scroll, 1, 2, 0, 1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0); gtk_table_attach (GTK_TABLE(table), rightbox, 1, 2, 1, 2, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0); @@ -160,15 +166,15 @@ void partyline_namelabel (char *nick, char *team) if (nick) { - nick_utf8 = g_locale_to_utf8 (nick, -1, NULL, NULL, NULL); - gtk_label_set (GTK_LABEL(namelabel), nocolor(nick_utf8)); + nick_utf8 = g_locale_to_utf8 (nocolor (nick), -1, NULL, NULL, NULL); + gtk_label_set (GTK_LABEL(namelabel), nick_utf8); g_free (nick_utf8); } else gtk_label_set (GTK_LABEL(namelabel), ""); if (team) { - team_utf8 = g_locale_to_utf8 (team, -1, NULL, NULL, NULL); - gtk_label_set (GTK_LABEL(teamlabel), nocolor(team_utf8)); + team_utf8 = g_locale_to_utf8 (nocolor (team), -1, NULL, NULL, NULL); + gtk_label_set (GTK_LABEL(teamlabel), team_utf8); g_free (team_utf8); } else gtk_label_set (GTK_LABEL(teamlabel), ""); diff --git a/src/tetrinet.c b/src/tetrinet.c index 9dee5e8..b341914 100644 --- a/src/tetrinet.c +++ b/src/tetrinet.c @@ -205,12 +205,15 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) connecterror: { GtkWidget *dialog; + gchar *data_utf8; connectingdialog_destroy (); GTET_O_STRCPY (buf, _("Error connecting: ")); - GTET_O_STRCAT (buf, data); + data_utf8 = g_locale_to_utf8 (data, -1, NULL, NULL, NULL); + GTET_O_STRCAT (buf, data_utf8); dialog = gnome_message_box_new (buf, GNOME_MESSAGE_BOX_ERROR, GNOME_STOCK_BUTTON_OK, NULL); gtk_widget_show (dialog); + g_free (data_utf8); } break; case IN_PLAYERNUM: diff --git a/src/winlist.c b/src/winlist.c index 7a491c4..e1e582a 100644 --- a/src/winlist.c +++ b/src/winlist.c @@ -85,4 +85,5 @@ void winlist_additem (int team, char *name, int score) 1, name_utf8, 2, item[2], -1); + g_free (name_utf8); }