Added account theme property

This commit is contained in:
James Booth
2016-01-22 01:06:28 +00:00
parent 72bbb5c2b9
commit 53fc89f711
16 changed files with 175 additions and 20 deletions

View File

@@ -1644,6 +1644,7 @@ static struct cmd_t command_defs[] =
"/account set <account> pgpkeyid <pgpkeyid>",
"/account set <account> startscript <script>",
"/account set <account> tls force|allow|disable",
"/account set <account> theme <theme>",
"/account clear <account> password",
"/account clear <account> eval_password",
"/account clear <account> server",
@@ -1681,13 +1682,15 @@ static struct cmd_t command_defs[] =
{ "set <account> tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." },
{ "set <account> tls allow", "Use TLS for the connection if it is available." },
{ "set <account> tls disable", "Disable TLS for the connection." },
{ "set <account> <theme>", "Set the UI theme for the account." },
{ "clear <account> server", "Remove the server setting for this account." },
{ "clear <account> port", "Remove the port setting for this account." },
{ "clear <account> password", "Remove the password setting for this account." },
{ "clear <account> eval_password", "Remove the eval_password setting for this account." },
{ "clear <account> otr", "Remove the OTR policy setting for this account." },
{ "clear <account> pgpkeyid", "Remove pgpkeyid associated with this account." },
{ "clear <account> startscript", "Remove startscript associated with this account." })
{ "clear <account> startscript", "Remove startscript associated with this account." },
{ "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." })
CMD_EXAMPLES(
"/account add me",
"/account set me jid me@chatty",
@@ -2145,6 +2148,7 @@ cmd_init(void)
autocomplete_add(account_set_ac, "pgpkeyid");
autocomplete_add(account_set_ac, "startscript");
autocomplete_add(account_set_ac, "tls");
autocomplete_add(account_set_ac, "theme");
account_clear_ac = autocomplete_new();
autocomplete_add(account_clear_ac, "password");
@@ -2154,6 +2158,7 @@ cmd_init(void)
autocomplete_add(account_clear_ac, "otr");
autocomplete_add(account_clear_ac, "pgpkeyid");
autocomplete_add(account_clear_ac, "startscript");
autocomplete_add(account_clear_ac, "theme");
account_default_ac = autocomplete_new();
autocomplete_add(account_default_ac, "set");
@@ -4442,6 +4447,25 @@ _account_autocomplete(ProfWin *window, const char *const input)
g_strfreev(args);
return found;
}
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "theme")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
if (theme_load_ac == NULL) {
theme_load_ac = autocomplete_new();
GSList *themes = theme_list();
GSList *curr = themes;
while (curr) {
autocomplete_add(theme_load_ac, curr->data);
curr = g_slist_next(curr);
}
g_slist_free_full(themes, g_free);
autocomplete_add(theme_load_ac, "default");
}
found = autocomplete_param_with_ac(input, beginning->str, theme_load_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
return found;
}
#ifdef HAVE_LIBGPGME
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "pgpkeyid")) == 0) {
g_string_append(beginning, " ");

View File

@@ -668,6 +668,34 @@ cmd_account(ProfWin *window, const char *const command, gchar **args)
} else if (strcmp(property, "startscript") == 0) {
accounts_set_script_start(account_name, value);
cons_show("Updated start script for account %s: %s", account_name, value);
} else if (strcmp(property, "theme") == 0) {
if (theme_exists(value)) {
accounts_set_theme(account_name, value);
if (jabber_get_connection_status() == JABBER_CONNECTED) {
ProfAccount *account = accounts_get_account(jabber_get_account_name());
if (account) {
if (g_strcmp0(account->name, account_name) == 0) {
theme_load(value);
ui_load_colours();
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();
} else {
ui_hide_roster();
}
if (prefs_get_boolean(PREF_OCCUPANTS)) {
ui_show_all_room_rosters();
} else {
ui_hide_all_room_rosters();
}
ui_redraw();
}
account_free(account);
}
}
cons_show("Updated theme for account %s: %s", account_name, value);
} else {
cons_show("Theme does not exist: %s", value);
}
} else if (strcmp(property, "tls") == 0) {
if ((g_strcmp0(value, "force") != 0)
&& (g_strcmp0(value, "allow") != 0)
@@ -764,6 +792,10 @@ cmd_account(ProfWin *window, const char *const command, gchar **args)
accounts_clear_script_start(account_name);
cons_show("Removed start script for account %s", account_name);
cons_show("");
} else if (strcmp(property, "theme") == 0) {
accounts_clear_theme(account_name);
cons_show("Removed theme for account %s", account_name);
cons_show("");
} else {
cons_show("Invalid property: %s", property);
cons_show("");
@@ -992,6 +1024,29 @@ cmd_disconnect(ProfWin *window, const char *const command, gchar **args)
cl_ev_disconnect();
char *theme = prefs_get_string(PREF_THEME);
if (theme) {
gboolean res = theme_load(theme);
prefs_free_string(theme);
if (!res) {
theme_load("default");
}
} else {
theme_load("default");
}
ui_load_colours();
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();
} else {
ui_hide_roster();
}
if (prefs_get_boolean(PREF_OCCUPANTS)) {
ui_show_all_room_rosters();
} else {
ui_hide_all_room_rosters();
}
ui_redraw();
return TRUE;
}