inputname.c: consistent indentation
This commit is contained in:
parent
9cf177147d
commit
2a361fec55
158
src/inputname.c
158
src/inputname.c
@ -21,95 +21,99 @@ static GtkWidget *_dialog = NULL;
|
||||
static gchar _last_player_name[15] = "";
|
||||
static gint _saved_score = 0;
|
||||
|
||||
void read_entry(GtkWidget *widget, gpointer data) {
|
||||
struct score_board current_entry;
|
||||
time_t current_time;
|
||||
struct tm *timeptr;
|
||||
gint pos, fbn;
|
||||
gsize br, bw;
|
||||
gchar *tstr = NULL;
|
||||
struct score_board b[10];
|
||||
struct score_board_full *bf = NULL;
|
||||
void read_entry(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
struct score_board current_entry;
|
||||
time_t current_time;
|
||||
struct tm *timeptr;
|
||||
gint pos, fbn;
|
||||
gsize br, bw;
|
||||
gchar *tstr = NULL;
|
||||
struct score_board b[10];
|
||||
struct score_board_full *bf = NULL;
|
||||
|
||||
tstr = (gchar*)gtk_entry_get_text(GTK_ENTRY(data));
|
||||
strncpy(current_entry.name, tstr && *tstr ? tstr : _("Anonymous"), sizeof(current_entry.name));
|
||||
strncpy(_last_player_name, current_entry.name, sizeof(_last_player_name));
|
||||
current_entry.score = _saved_score;
|
||||
current_time = time(NULL);
|
||||
timeptr = localtime(¤t_time);
|
||||
if(!timeptr) {
|
||||
ut_simple_message_box(_("Unable to determine current date.\n"));
|
||||
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
||||
} else {
|
||||
if(!strftime(current_entry.date, sizeof(current_entry.date), _("%a %b %d %H:%M %Y"), timeptr)) {
|
||||
ut_simple_message_box(_("Unable to determine current date.\n"));
|
||||
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
||||
} else {
|
||||
tstr = g_locale_to_utf8(current_entry.date, -1, &br, &bw, NULL);
|
||||
if(!tstr) {
|
||||
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
||||
} else {
|
||||
strncpy(current_entry.date, tstr, sizeof(current_entry.date));
|
||||
g_free(tstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
tstr = (gchar*)gtk_entry_get_text(GTK_ENTRY(data));
|
||||
strncpy(current_entry.name, tstr && *tstr ? tstr : _("Anonymous"), sizeof(current_entry.name));
|
||||
strncpy(_last_player_name, current_entry.name, sizeof(_last_player_name));
|
||||
current_entry.score = _saved_score;
|
||||
current_time = time(NULL);
|
||||
timeptr = localtime(¤t_time);
|
||||
|
||||
if(!read_score(b, &bf, &fbn)) {
|
||||
ut_simple_message_box (_("Unable to read score.\n"));
|
||||
} else {
|
||||
pos = insert_entry_in_score_board(b, current_entry);
|
||||
if(!write_score(b, bf, fbn)) {
|
||||
ut_simple_message_box(_("Unable to save score.\n"));
|
||||
}
|
||||
/*FIXME: free bf here */
|
||||
free_score_board_full(bf, fbn);
|
||||
if(pos != -1) {
|
||||
pos++;
|
||||
show_hall_of_fame(NULL, (gpointer)pos, b);
|
||||
}
|
||||
}
|
||||
if (!timeptr) {
|
||||
ut_simple_message_box(_("Unable to determine current date.\n"));
|
||||
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
||||
} else {
|
||||
if (!strftime(current_entry.date, sizeof(current_entry.date), _("%a %b %d %H:%M %Y"), timeptr)) {
|
||||
ut_simple_message_box(_("Unable to determine current date.\n"));
|
||||
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
||||
} else {
|
||||
tstr = g_locale_to_utf8(current_entry.date, -1, &br, &bw, NULL);
|
||||
if (!tstr) {
|
||||
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
||||
} else {
|
||||
strncpy(current_entry.date, tstr, sizeof(current_entry.date));
|
||||
g_free(tstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy(_dialog);
|
||||
/* show scores to let user see if (s)he's on top ;) */
|
||||
if (!read_score(b, &bf, &fbn)) {
|
||||
ut_simple_message_box (_("Unable to read score.\n"));
|
||||
} else {
|
||||
pos = insert_entry_in_score_board(b, current_entry);
|
||||
if (!write_score(b, bf, fbn)) {
|
||||
ut_simple_message_box(_("Unable to save score.\n"));
|
||||
}
|
||||
/*FIXME: free bf here */
|
||||
free_score_board_full(bf, fbn);
|
||||
if (pos != -1) {
|
||||
pos++;
|
||||
show_hall_of_fame(NULL, (gpointer)pos, b);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy(_dialog);
|
||||
/* show scores to let user see if (s)he's on top ;) */
|
||||
}
|
||||
|
||||
void input_name_dialog(void) {
|
||||
GtkWidget *prompt_label, * vbox;
|
||||
GtkWidget *name;
|
||||
GtkWidget *button;
|
||||
gchar *s;
|
||||
|
||||
/* we have to save score, because they will be set to 0 in new_game() */
|
||||
_saved_score = game_get_score();
|
||||
void input_name_dialog(void)
|
||||
{
|
||||
GtkWidget * prompt_label, * vbox;
|
||||
GtkWidget * name;
|
||||
GtkWidget * button;
|
||||
gchar * s;
|
||||
|
||||
_dialog = gtk_dialog_new();
|
||||
gtk_window_set_role(GTK_WINDOW(_dialog), "GtkBalls_Inputname");
|
||||
/* we have to save score, because they will be set to 0 in new_game() */
|
||||
_saved_score = game_get_score();
|
||||
|
||||
vbox = gtk_dialog_get_content_area (GTK_DIALOG (_dialog));
|
||||
gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
|
||||
_dialog = gtk_dialog_new();
|
||||
gtk_window_set_role(GTK_WINDOW(_dialog), "GtkBalls_Inputname");
|
||||
|
||||
prompt_label = gtk_label_new(_("Enter your name"));
|
||||
gtk_box_pack_start (GTK_BOX(vbox), prompt_label, TRUE, TRUE, 0);
|
||||
vbox = gtk_dialog_get_content_area (GTK_DIALOG (_dialog));
|
||||
gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
|
||||
|
||||
name = gtk_entry_new();
|
||||
gtk_entry_set_max_length(GTK_ENTRY(name), 14);
|
||||
g_signal_connect(G_OBJECT(name), "activate", G_CALLBACK(read_entry), name);
|
||||
prompt_label = gtk_label_new(_("Enter your name"));
|
||||
gtk_box_pack_start (GTK_BOX(vbox), prompt_label, TRUE, TRUE, 0);
|
||||
|
||||
/* restore the last player's name */
|
||||
if(!(*_last_player_name)) {
|
||||
if((s = getenv("USER"))) {
|
||||
strncpy(_last_player_name, s, sizeof(_last_player_name));
|
||||
}
|
||||
}
|
||||
gtk_entry_set_text(GTK_ENTRY(name), _last_player_name);
|
||||
gtk_editable_select_region(GTK_EDITABLE(name), 0, -1);
|
||||
gtk_box_pack_start (GTK_BOX(vbox), name, TRUE, TRUE, 5);
|
||||
name = gtk_entry_new();
|
||||
gtk_entry_set_max_length(GTK_ENTRY(name), 14);
|
||||
g_signal_connect(G_OBJECT(name), "activate", G_CALLBACK(read_entry), name);
|
||||
|
||||
button=ut_button_new_stock(GTK_STOCK_OK, read_entry, name, GTK_DIALOG(_dialog)->action_area);
|
||||
/* restore the last player's name */
|
||||
if (!(*_last_player_name)) {
|
||||
if ((s = getenv("USER"))) {
|
||||
strncpy(_last_player_name, s, sizeof(_last_player_name));
|
||||
}
|
||||
}
|
||||
gtk_entry_set_text(GTK_ENTRY(name), _last_player_name);
|
||||
gtk_editable_select_region(GTK_EDITABLE(name), 0, -1);
|
||||
gtk_box_pack_start (GTK_BOX(vbox), name, TRUE, TRUE, 5);
|
||||
|
||||
gtk_widget_grab_focus(name);
|
||||
button=ut_button_new_stock(GTK_STOCK_OK, read_entry, name, GTK_DIALOG(_dialog)->action_area);
|
||||
|
||||
gtk_widget_grab_default(button);
|
||||
gtk_widget_show_all(_dialog);
|
||||
gtk_widget_grab_focus(name);
|
||||
|
||||
gtk_widget_grab_default(button);
|
||||
gtk_widget_show_all(_dialog);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user