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