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

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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
@ -490,6 +496,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)
{
@ -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)
{

View File

@ -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

View File

@ -144,6 +144,22 @@ theme_init(const char *const theme_name)
g_hash_table_insert(defaults, strdup("occupants.header"), strdup("yellow"));
}
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)
{

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -126,6 +126,7 @@ void accounts_set_last_status(const char * const account_name, const char * cons
void accounts_set_last_activity(const char * const account_name) {}
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_set_tls_policy(const char * const account_name, const char * const value) {}
void accounts_set_login_presence(const char * const account_name, const char * const value)
@ -194,6 +195,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) {}
char* accounts_get_last_activity(const char *const account_name)
{

View File

@ -33,7 +33,7 @@ void cmd_account_shows_usage_when_not_connected_and_no_args(void **state)
void cmd_account_shows_account_when_connected_and_no_args(void **state)
{
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
gchar *args[] = { NULL };
will_return(jabber_get_connection_status, JABBER_CONNECTED);
@ -93,7 +93,7 @@ void cmd_account_show_shows_account_when_exists(void **state)
{
gchar *args[] = { "show", "account_name", NULL };
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
@ -409,7 +409,7 @@ void cmd_account_set_password_sets_password(void **state)
{
gchar *args[] = { "set", "a_account", "password", "a_password", NULL };
ProfAccount *account = account_new("a_account", NULL, NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
expect_any(accounts_account_exists, account_name);
@ -432,7 +432,7 @@ void cmd_account_set_eval_password_sets_eval_password(void **state)
{
gchar *args[] = { "set", "a_account", "eval_password", "a_password", NULL };
ProfAccount *account = account_new("a_account", NULL, NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
@ -453,7 +453,7 @@ void cmd_account_set_eval_password_sets_eval_password(void **state)
void cmd_account_set_password_when_eval_password_set(void **state) {
gchar *args[] = { "set", "a_account", "password", "a_password", NULL };
ProfAccount *account = account_new("a_account", NULL, NULL, "a_password",
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
@ -470,7 +470,7 @@ void cmd_account_set_password_when_eval_password_set(void **state) {
void cmd_account_set_eval_password_when_password_set(void **state) {
gchar *args[] = { "set", "a_account", "eval_password", "a_password", NULL };
ProfAccount *account = account_new("a_account", NULL, "a_password", NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
@ -800,7 +800,7 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
#ifdef HAVE_LIBGPGME
ProfAccount *account = account_new("a_account", "a_jid", NULL, NULL, TRUE, NULL, 5222, "a_resource",
NULL, NULL, 10, 10, 10, 10, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
NULL, NULL, 10, 10, 10, 10, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
will_return(jabber_get_account_name, "a_account");
expect_any(accounts_get_account, name);

View File

@ -121,7 +121,7 @@ void cmd_connect_asks_password_when_not_in_account(void **state)
{
gchar *args[] = { "jabber_org", NULL };
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
@ -368,7 +368,7 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state)
{
gchar *args[] = { "jabber_org", NULL };
ProfAccount *account = account_new("jabber_org", "user@jabber.org", "password", NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
@ -388,7 +388,7 @@ void cmd_connect_connects_with_account(void **state)
{
gchar *args[] = { "jabber_org", NULL };
ProfAccount *account = account_new("jabber_org", "me@jabber.org", "password", NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

View File

@ -70,7 +70,7 @@ void cmd_join_uses_account_mucservice_when_no_service_specified(void **state)
char *expected_room = "room@conference.server.org";
gchar *args[] = { room, "nick", nick, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
muc_init();
@ -95,7 +95,7 @@ void cmd_join_uses_supplied_nick(void **state)
char *nick = "bob";
gchar *args[] = { room, "nick", nick, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
muc_init();
@ -120,7 +120,7 @@ void cmd_join_uses_account_nick_when_not_supplied(void **state)
char *account_nick = "a_nick";
gchar *args[] = { room, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
muc_init();
@ -148,7 +148,7 @@ void cmd_join_uses_password_when_supplied(void **state)
char *expected_room = "room@a_service";
gchar *args[] = { room, "password", password, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
muc_init();

View File

@ -209,7 +209,7 @@ void cmd_otr_gen_generates_key_for_connected_account(void **state)
gchar *args[] = { "gen", NULL };
char *account_name = "myaccount";
ProfAccount *account = account_new(account_name, "me@jabber.org", NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
will_return(jabber_get_connection_status, JABBER_CONNECTED);
will_return(jabber_get_account_name, account_name);

View File

@ -56,7 +56,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
gchar *args[] = { NULL };
ProfAccount *account = account_new("testaccount", NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL,
0, 0, 0, 0, 0, strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
0, 0, 0, 0, 0, strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
will_return(jabber_get_connection_status, JABBER_CONNECTED);
will_return(jabber_get_account_name, "account_name");