tUse login first name as default user name - vaccinewars - be a doctor and try … | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 68f6a78f348c8ef5968af44946d45e1c7dbd7305 | |
parent 6860dd12a2d0843875ee263bdd381822580a061d | |
Author: Ben Webb <[email protected]> | |
Date: Tue, 1 Dec 2020 22:58:09 -0800 | |
Use login first name as default user name | |
Use the first word of the user's full login name | |
as the default player name for the GUI client. | |
Diffstat: | |
M src/gui_client/newgamedia.c | 22 +++++++++++++++++++++- | |
1 file changed, 21 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/src/gui_client/newgamedia.c b/src/gui_client/newgamedia.c | |
t@@ -454,6 +454,26 @@ static GtkWidget *create_metaserver_view(GtkWidget **pack… | |
} | |
#endif | |
+static void set_initial_player_name(GtkEntry *entry, Player *play) | |
+{ | |
+ char *name = GetPlayerName(play); | |
+ if (*name) { | |
+ gtk_entry_set_text(entry, name); | |
+ } else { | |
+ /* If name is blank, use the first word from the user's full login name */ | |
+ char *firstspace; | |
+ name = g_strdup(g_get_real_name()); | |
+ g_strstrip(name); | |
+ firstspace = strchr(name, ' '); | |
+ if (firstspace) { | |
+ *firstspace = '\0'; | |
+ } | |
+ /* "Unknown" is returned from g_get_real_name() on error */ | |
+ gtk_entry_set_text(entry, strcmp(name, "Unknown") == 0 ? "" : name); | |
+ g_free(name); | |
+ } | |
+} | |
+ | |
#ifdef NETWORKING | |
void NewGameDialog(Player *play, NBCallBack sockstat, CurlConnection *MetaConn) | |
#else | |
t@@ -520,7 +540,7 @@ void NewGameDialog(Player *play) | |
#else | |
gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry); | |
#endif | |
- gtk_entry_set_text(GTK_ENTRY(entry), GetPlayerName(stgam.play)); | |
+ set_initial_player_name(GTK_ENTRY(entry), stgam.play); | |
gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); | |
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |