1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Allow utf8 in roster room private char

This commit is contained in:
Michael Vetter 2021-10-22 16:42:57 +02:00
parent 8fc359ba2d
commit fa2881fcea
6 changed files with 22 additions and 27 deletions

View File

@ -2798,8 +2798,8 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args)
cons_show("Roster room private char removed."); cons_show("Roster room private char removed.");
rosterwin_roster(); rosterwin_roster();
} else { } else {
prefs_set_roster_room_private_char(args[3][0]); prefs_set_roster_room_private_char(args[3]);
cons_show("Roster room private char set to %c.", args[3][0]); cons_show("Roster room private char set to %s.", args[3]);
rosterwin_roster(); rosterwin_roster();
} }
return TRUE; return TRUE;

View File

@ -1206,30 +1206,22 @@ prefs_clear_roster_room_char(void)
g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.rooms.char", NULL); g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.rooms.char", NULL);
} }
char char*
prefs_get_roster_room_private_char(void) prefs_get_roster_room_private_char(void)
{ {
char result = 0; char* result = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.rooms.private.char", NULL);
char* resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.rooms.private.char", NULL);
if (!resultstr) {
result = 0;
} else {
result = resultstr[0];
}
free(resultstr);
return result; return result;
} }
void void
prefs_set_roster_room_private_char(char ch) prefs_set_roster_room_private_char(char* ch)
{ {
char str[2]; if (g_utf8_strlen(ch, 4) == 1) {
str[0] = ch; g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.rooms.private.char", ch);
str[1] = '\0'; } else {
log_error("Could not set roster resource char: %s", ch);
g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.rooms.private.char", str); }
} }
void void

View File

@ -269,8 +269,8 @@ void prefs_clear_roster_private_char(void);
char* prefs_get_roster_room_char(void); char* prefs_get_roster_room_char(void);
void prefs_set_roster_room_char(char* ch); void prefs_set_roster_room_char(char* ch);
void prefs_clear_roster_room_char(void); void prefs_clear_roster_room_char(void);
char prefs_get_roster_room_private_char(void); char* prefs_get_roster_room_private_char(void);
void prefs_set_roster_room_private_char(char ch); void prefs_set_roster_room_private_char(char* ch);
void prefs_clear_roster_room_private_char(void); void prefs_clear_roster_room_private_char(void);
char prefs_get_occupants_char(void); char prefs_get_occupants_char(void);
void prefs_set_occupants_char(char ch); void prefs_set_occupants_char(char ch);

View File

@ -456,8 +456,8 @@ _load_preferences(void)
if (g_key_file_has_key(theme, "ui", "roster.rooms.private.char", NULL)) { if (g_key_file_has_key(theme, "ui", "roster.rooms.private.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL); gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
if (ch && strlen(ch) > 0) { if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_room_private_char(ch[0]); prefs_set_roster_room_private_char(ch);
g_free(ch); g_free(ch);
} }
} }

View File

@ -1507,11 +1507,13 @@ cons_roster_setting(void)
cons_show("Roster room char (/roster) : none"); cons_show("Roster room char (/roster) : none");
} }
char room_priv_ch = prefs_get_roster_room_private_char(); char* room_priv_ch = prefs_get_roster_room_private_char();
if (room_priv_ch) if (room_priv_ch) {
cons_show("Roster room private char (/roster) : %c", room_priv_ch); cons_show("Roster room private char (/roster) : %c", room_priv_ch);
else free(room_priv_ch);
} else {
cons_show("Roster room private char (/roster) : none"); cons_show("Roster room private char (/roster) : none");
}
char* private_ch = prefs_get_roster_private_char(); char* private_ch = prefs_get_roster_private_char();
if (private_ch) { if (private_ch) {

View File

@ -857,9 +857,10 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
g_string_append_printf(privmsg, "(%d) ", privwin->unread); g_string_append_printf(privmsg, "(%d) ", privwin->unread);
} }
char ch = prefs_get_roster_room_private_char(); ch = prefs_get_roster_room_private_char();
if (ch) { if (ch) {
g_string_append_printf(privmsg, "%c", ch); g_string_append_printf(privmsg, "%s", ch);
free(ch);
} }
char* nick = privwin->fulljid + strlen(mucwin->roomjid) + 1; char* nick = privwin->fulljid + strlen(mucwin->roomjid) + 1;