1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Improve setting encryption char error handling

This commit is contained in:
Michael Vetter 2020-02-21 14:51:19 +01:00
parent 2a952cb4c5
commit 669de0ca52
3 changed files with 27 additions and 16 deletions

View File

@ -7132,8 +7132,11 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args)
cons_bad_cmd_usage(command);
return TRUE;
} else if (g_utf8_strlen(args[1], 4) == 1) {
prefs_set_pgp_char(args[1]);
cons_show("PGP char set to %s.", args[1]);
if (prefs_set_pgp_char(args[1])) {
cons_show("PGP char set to %s.", args[1]);
} else {
cons_show_error("Could not set PGP char: %s.", args[1]);
}
return TRUE;
}
cons_bad_cmd_usage(command);
@ -7369,8 +7372,11 @@ cmd_otr_char(ProfWin *window, const char *const command, gchar **args)
cons_bad_cmd_usage(command);
return TRUE;
} else if (g_utf8_strlen(args[1], 4) == 1) {
prefs_set_otr_char(args[1]);
cons_show("OTR char set to %s.", args[1]);
if (prefs_set_otr_char(args[1])) {
cons_show("OTR char set to %s.", args[1]);
} else {
cons_show_error("Could not set OTR char: %s.", args[1]);
}
return TRUE;
}
cons_bad_cmd_usage(command);
@ -8272,8 +8278,11 @@ cmd_omemo_char(ProfWin *window, const char *const command, gchar **args)
cons_bad_cmd_usage(command);
return TRUE;
} else if (g_utf8_strlen(args[1], 4) == 1) {
prefs_set_omemo_char(args[1]);
cons_show("OMEMO char set to %s.", args[1]);
if (prefs_set_omemo_char(args[1])) {
cons_show("OMEMO char set to %s.", args[1]);
} else {
cons_show_error("Could not set OMEMO char: %s.", args[1]);
}
return TRUE;
}
cons_bad_cmd_usage(command);

View File

@ -883,14 +883,16 @@ _prefs_get_encryption_char(const char *const ch, const char *const pref_group, c
return result;
}
static void
static gboolean
_prefs_set_encryption_char(const char *const ch, const char *const pref_group, const char *const key)
{
if (g_utf8_strlen(ch, 4) == 1) {
g_key_file_set_string(prefs, pref_group, key, ch);
return TRUE;
} else {
log_error("Could not set %s encryption char to: %s", key, ch);
}
return FALSE;
}
char*
@ -899,10 +901,10 @@ prefs_get_otr_char(void)
return _prefs_get_encryption_char("~", PREF_GROUP_OTR, "otr.char");
}
void
gboolean
prefs_set_otr_char(char *ch)
{
_prefs_set_encryption_char(ch, PREF_GROUP_OTR, "otr.char");
return _prefs_set_encryption_char(ch, PREF_GROUP_OTR, "otr.char");
}
char*
@ -911,10 +913,10 @@ prefs_get_pgp_char(void)
return _prefs_get_encryption_char("~", PREF_GROUP_PGP, "pgp.char");
}
void
gboolean
prefs_set_pgp_char(char *ch)
{
_prefs_set_encryption_char(ch, PREF_GROUP_PGP, "pgp.char");
return _prefs_set_encryption_char(ch, PREF_GROUP_PGP, "pgp.char");
}
char*
@ -923,10 +925,10 @@ prefs_get_omemo_char(void)
return _prefs_get_encryption_char("~", PREF_GROUP_OMEMO, "omemo.char");
}
void
gboolean
prefs_set_omemo_char(char *ch)
{
_prefs_set_encryption_char(ch, PREF_GROUP_OMEMO, "omemo.char");
return _prefs_set_encryption_char(ch, PREF_GROUP_OMEMO, "omemo.char");
}
char

View File

@ -233,11 +233,11 @@ void prefs_add_plugin(const char *const name);
void prefs_remove_plugin(const char *const name);
char* prefs_get_otr_char(void);
void prefs_set_otr_char(char *ch);
gboolean prefs_set_otr_char(char *ch);
char* prefs_get_pgp_char(void);
void prefs_set_pgp_char(char *ch);
gboolean prefs_set_pgp_char(char *ch);
char* prefs_get_omemo_char(void);
void prefs_set_omemo_char(char *ch);
gboolean prefs_set_omemo_char(char *ch);
char prefs_get_roster_header_char(void);
void prefs_set_roster_header_char(char ch);