diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command/command.c | 26 | ||||
-rw-r--r-- | src/command/commands.c | 55 | ||||
-rw-r--r-- | src/config/account.c | 9 | ||||
-rw-r--r-- | src/config/account.h | 3 | ||||
-rw-r--r-- | src/config/accounts.c | 27 | ||||
-rw-r--r-- | src/config/accounts.h | 2 | ||||
-rw-r--r-- | src/config/theme.c | 16 | ||||
-rw-r--r-- | src/config/theme.h | 1 | ||||
-rw-r--r-- | src/ui/console.c | 3 | ||||
-rw-r--r-- | src/ui/core.c | 19 |
10 files changed, 157 insertions, 4 deletions
diff --git a/src/command/command.c b/src/command/command.c index 3f4e4a7d..ca84591f 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -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, " "); diff --git a/src/command/commands.c b/src/command/commands.c index 7679acb4..933c65bd 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -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; } diff --git a/src/config/account.c b/src/config/account.c index da6a4317..d31f426b 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -52,7 +52,7 @@ account_new(const gchar *const name, const gchar *const jid, const gchar *const muc_service, const gchar *const muc_nick, const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic, GList *otr_always, const gchar *const pgp_keyid, const char *const startscript, - gchar *tls_policy) + const char *const theme, gchar *tls_policy) { ProfAccount *new_account = malloc(sizeof(ProfAccount)); @@ -157,6 +157,12 @@ account_new(const gchar *const name, const gchar *const jid, new_account->startscript = NULL; } + if (theme != NULL) { + new_account->theme = strdup(theme); + } else { + new_account->theme = NULL; + } + if (tls_policy != NULL) { new_account->tls_policy = strdup(tls_policy); } else { @@ -231,6 +237,7 @@ account_free(ProfAccount *account) free(account->otr_policy); free(account->pgp_keyid); free(account->startscript); + free(account->theme); free(account->tls_policy); g_list_free_full(account->otr_manual, g_free); g_list_free_full(account->otr_opportunistic, g_free); diff --git a/src/config/account.h b/src/config/account.h index 2d45bdbd..a160c3b5 100644 --- a/src/config/account.h +++ b/src/config/account.h @@ -61,6 +61,7 @@ typedef struct prof_account_t { GList *otr_always; gchar *pgp_keyid; gchar *startscript; + gchar *theme; gchar *tls_policy; } ProfAccount; @@ -72,7 +73,7 @@ ProfAccount* account_new(const gchar *const name, const gchar *const jid, const gchar *const muc_service, const gchar *const muc_nick, const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic, GList *otr_always, const gchar *const pgp_keyid, const char *const startscript, - gchar *tls_policy); + const char *const theme, gchar *tls_policy); char* account_create_full_jid(ProfAccount *account); gboolean account_eval_password(ProfAccount *account); void account_free(ProfAccount *account); diff --git a/src/config/accounts.c b/src/config/accounts.c index 385e86f3..7049039a 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -272,6 +272,11 @@ accounts_get_account(const char *const name) startscript = g_key_file_get_string(accounts, name, "script.start", NULL); } + gchar *theme = NULL; + if (g_key_file_has_key(accounts, name, "theme", NULL)) { + theme = g_key_file_get_string(accounts, name, "theme", NULL); + } + gchar *tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL); if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) && (g_strcmp0(tls_policy, "allow") != 0) && @@ -284,7 +289,7 @@ accounts_get_account(const char *const name) server, port, resource, last_presence, login_presence, priority_online, priority_chat, priority_away, priority_xa, priority_dnd, muc_service, muc_nick, otr_policy, otr_manual, - otr_opportunistic, otr_always, pgp_keyid, startscript, tls_policy); + otr_opportunistic, otr_always, pgp_keyid, startscript, theme, tls_policy); g_free(jid); g_free(password); @@ -298,6 +303,7 @@ accounts_get_account(const char *const name) g_free(otr_policy); g_free(pgp_keyid); g_free(startscript); + g_free(theme); g_free(tls_policy); return new_account; @@ -491,6 +497,15 @@ accounts_set_script_start(const char *const account_name, const char *const valu } void +accounts_set_theme(const char *const account_name, const char *const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "theme", value); + _save_accounts(); + } +} + +void accounts_clear_password(const char *const account_name) { if (accounts_account_exists(account_name)) { @@ -543,6 +558,16 @@ accounts_clear_script_start(const char *const account_name) _save_accounts(); } } + +void +accounts_clear_theme(const char *const account_name) +{ + if (accounts_account_exists(account_name)) { + g_key_file_remove_key(accounts, account_name, "theme", NULL); + _save_accounts(); + } +} + void accounts_clear_otr(const char *const account_name) { diff --git a/src/config/accounts.h b/src/config/accounts.h index 0417b6bd..a73e5c9a 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -84,6 +84,7 @@ gint accounts_get_priority_for_presence_type(const char *const account_name, resource_presence_t presence_type); void accounts_set_pgp_keyid(const char *const account_name, const char *const value); void accounts_set_script_start(const char *const account_name, const char *const value); +void accounts_set_theme(const char *const account_name, const char *const value); void accounts_clear_password(const char *const account_name); void accounts_clear_eval_password(const char *const account_name); void accounts_clear_server(const char *const account_name); @@ -91,6 +92,7 @@ void accounts_clear_port(const char *const account_name); void accounts_clear_otr(const char *const account_name); void accounts_clear_pgp_keyid(const char *const account_name); void accounts_clear_script_start(const char *const account_name); +void accounts_clear_theme(const char *const account_name); void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy); #endif diff --git a/src/config/theme.c b/src/config/theme.c index b9397a18..14c165f6 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -145,6 +145,22 @@ theme_init(const char *const theme_name) } gboolean +theme_exists(const char *const theme_name) +{ + if (g_strcmp0(theme_name, "default") == 0) { + return TRUE; + } + + GString *new_theme_file = _theme_find(theme_name); + if (new_theme_file == NULL) { + return FALSE; + } + + g_string_free(new_theme_file, TRUE); + return TRUE; +} + +gboolean theme_load(const char *const theme_name) { if (_theme_load_file(theme_name)) { diff --git a/src/config/theme.h b/src/config/theme.h index 3c0f0fa9..f4eac724 100644 --- a/src/config/theme.h +++ b/src/config/theme.h @@ -128,6 +128,7 @@ typedef enum { void theme_init(const char *const theme_name); void theme_init_colours(void); gboolean theme_load(const char *const theme_name); +gboolean theme_exists(const char *const theme_name); GSList* theme_list(void); void theme_close(void); int theme_attrs(theme_item_t attrs); diff --git a/src/ui/console.c b/src/ui/console.c index 260f6d6d..e087ae79 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -851,6 +851,9 @@ cons_show_account(ProfAccount *account) if (account->startscript) { cons_show ("Start script : %s", account->startscript); } + if (account->theme) { + cons_show ("Theme : %s", account->theme); + } if (account->otr_policy) { cons_show ("OTR policy : %s", account->otr_policy); } diff --git a/src/ui/core.c b/src/ui/core.c index a4e5814a..78a992d9 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -353,6 +353,25 @@ ui_group_removed(const char *const contact, const char *const group) void ui_handle_login_account_success(ProfAccount *account, int secured) { + if (account->theme) { + if (theme_load(account->theme)) { + 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(); + } else { + cons_show("Couldn't find account theme: %s", account->theme); + } + } + resource_presence_t resource_presence = accounts_get_login_presence(account->name); contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); cons_show_login_success(account, secured); |