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

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-03-15 22:28:21 +00:00
commit f7a7277e40
10 changed files with 92 additions and 78 deletions

View File

@ -787,21 +787,11 @@ static struct cmd_t command_defs[] =
{ "/statuses console|chat|muc setting", { "/statuses console|chat|muc setting",
"----------------------------------", "----------------------------------",
"Configure how presence changes are displayed in various windows.", "Configure how presence changes are displayed in various windows.",
"Settings for the console:", "Settings:",
" all - Show all presence changes in the console", " all - Show all presence changes.",
" online - Show only when contacts log in/out.", " online - Show only online/offline changes.",
" none - Don't show any presence changes in the console.", " none - Don't show any presence changes.",
"Settings for chat windows:", "The default is 'all' for all windows.",
" all - Show all presence changes in the contact's chat window if one is open.",
" online - Show only when contacts log in/out.",
" none - Don't show any presence changes in the chat windows.",
"Settings for chat room windows:",
" on - Show presence changes in chat rooms.",
" off - Do not show presence changes in chat rooms.",
"The defaults are:",
" console - all",
" chat - all",
" muc - on",
NULL } } }, NULL } } },
{ "/away", { "/away",
@ -886,7 +876,7 @@ static Autocomplete otr_ac;
static Autocomplete otr_log_ac; static Autocomplete otr_log_ac;
static Autocomplete connect_property_ac; static Autocomplete connect_property_ac;
static Autocomplete statuses_ac; static Autocomplete statuses_ac;
static Autocomplete statuses_cons_chat_ac; static Autocomplete statuses_setting_ac;
static Autocomplete alias_ac; static Autocomplete alias_ac;
static Autocomplete aliases_ac; static Autocomplete aliases_ac;
static Autocomplete join_property_ac; static Autocomplete join_property_ac;
@ -1087,10 +1077,10 @@ cmd_init(void)
autocomplete_add(statuses_ac, "chat"); autocomplete_add(statuses_ac, "chat");
autocomplete_add(statuses_ac, "muc"); autocomplete_add(statuses_ac, "muc");
statuses_cons_chat_ac = autocomplete_new(); statuses_setting_ac = autocomplete_new();
autocomplete_add(statuses_cons_chat_ac, "all"); autocomplete_add(statuses_setting_ac, "all");
autocomplete_add(statuses_cons_chat_ac, "online"); autocomplete_add(statuses_setting_ac, "online");
autocomplete_add(statuses_cons_chat_ac, "none"); autocomplete_add(statuses_setting_ac, "none");
alias_ac = autocomplete_new(); alias_ac = autocomplete_new();
autocomplete_add(alias_ac, "add"); autocomplete_add(alias_ac, "add");
@ -1131,7 +1121,7 @@ cmd_uninit(void)
autocomplete_free(otr_log_ac); autocomplete_free(otr_log_ac);
autocomplete_free(connect_property_ac); autocomplete_free(connect_property_ac);
autocomplete_free(statuses_ac); autocomplete_free(statuses_ac);
autocomplete_free(statuses_cons_chat_ac); autocomplete_free(statuses_setting_ac);
autocomplete_free(alias_ac); autocomplete_free(alias_ac);
autocomplete_free(aliases_ac); autocomplete_free(aliases_ac);
autocomplete_free(join_property_ac); autocomplete_free(join_property_ac);
@ -1254,7 +1244,7 @@ cmd_reset_autocomplete()
autocomplete_reset(otr_log_ac); autocomplete_reset(otr_log_ac);
autocomplete_reset(connect_property_ac); autocomplete_reset(connect_property_ac);
autocomplete_reset(statuses_ac); autocomplete_reset(statuses_ac);
autocomplete_reset(statuses_cons_chat_ac); autocomplete_reset(statuses_setting_ac);
autocomplete_reset(alias_ac); autocomplete_reset(alias_ac);
autocomplete_reset(aliases_ac); autocomplete_reset(aliases_ac);
autocomplete_reset(join_property_ac); autocomplete_reset(join_property_ac);
@ -1822,17 +1812,17 @@ _statuses_autocomplete(char *input, int *size)
{ {
char *result = NULL; char *result = NULL;
result = autocomplete_param_with_ac(input, size, "/statuses console", statuses_cons_chat_ac); result = autocomplete_param_with_ac(input, size, "/statuses console", statuses_setting_ac);
if (result != NULL) { if (result != NULL) {
return result; return result;
} }
result = autocomplete_param_with_ac(input, size, "/statuses chat", statuses_cons_chat_ac); result = autocomplete_param_with_ac(input, size, "/statuses chat", statuses_setting_ac);
if (result != NULL) { if (result != NULL) {
return result; return result;
} }
result = autocomplete_param_with_func(input, size, "/statuses muc", prefs_autocomplete_boolean_choice); result = autocomplete_param_with_ac(input, size, "/statuses muc", statuses_setting_ac);
if (result != NULL) { if (result != NULL) {
return result; return result;
} }

View File

@ -2427,23 +2427,14 @@ cmd_statuses(gchar **args, struct cmd_help_t help)
strcmp(args[0], "chat") != 0 && strcmp(args[0], "chat") != 0 &&
strcmp(args[0], "muc") != 0) { strcmp(args[0], "muc") != 0) {
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
return TRUE;
} }
if (strcmp(args[0], "console") == 0 || strcmp(args[0], "chat") == 0) { if (strcmp(args[1], "all") != 0 &&
if (strcmp(args[1], "all") != 0 && strcmp(args[1], "online") != 0 &&
strcmp(args[1], "online") != 0 && strcmp(args[1], "none") != 0) {
strcmp(args[1], "none") != 0) { cons_show("Usage: %s", help.usage);
cons_show("Usage: %s", help.usage); return TRUE;
return TRUE;
}
}
if (strcmp(args[0], "muc") == 0) {
if (strcmp(args[1], "on") != 0 && strcmp(args[1], "off") != 0) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
} }
if (strcmp(args[0], "console") == 0) { if (strcmp(args[0], "console") == 0) {
@ -2469,9 +2460,16 @@ cmd_statuses(gchar **args, struct cmd_help_t help)
} }
if (strcmp(args[0], "muc") == 0) { if (strcmp(args[0], "muc") == 0) {
_cmd_set_boolean_preference(args[1], help, prefs_set_string(PREF_STATUSES_MUC, args[1]);
"Chat room presence updates", PREF_STATUSES_MUC); if (strcmp(args[1], "all") == 0) {
cons_show("All presence updates will appear in chat room windows.");
} else if (strcmp(args[1], "online") == 0) {
cons_show("Only join/leave presence updates will appear in chat room windows.");
} else {
cons_show("Presence updates will not appear in chat room windows.");
}
} }
return TRUE; return TRUE;
} }

View File

@ -490,8 +490,6 @@ _get_default_boolean(preference_t pref)
case PREF_STATUSES: case PREF_STATUSES:
case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_CHECK:
case PREF_OTR_WARN: case PREF_OTR_WARN:
case PREF_STATUSES_MUC:
return TRUE;
default: default:
return FALSE; return FALSE;
} }
@ -508,6 +506,7 @@ _get_default_string(preference_t pref)
return "redact"; return "redact";
case PREF_STATUSES_CONSOLE: case PREF_STATUSES_CONSOLE:
case PREF_STATUSES_CHAT: case PREF_STATUSES_CHAT:
case PREF_STATUSES_MUC:
return "all"; return "all";
default: default:
return NULL; return NULL;

View File

@ -474,8 +474,8 @@ handle_room_member_presence(const char * const room,
gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str); gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str);
if (updated) { if (updated) {
gboolean show_muc = prefs_get_boolean(PREF_STATUSES_MUC); char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
if (show_muc) { if (g_strcmp0(muc_status_pref, "all") == 0) {
ui_room_member_presence(room, nick, show, status); ui_room_member_presence(room, nick, show, status);
ui_current_page_off(); ui_current_page_off();
} }
@ -488,8 +488,12 @@ handle_room_member_online(const char * const room, const char * const nick,
const char * const caps_str) const char * const caps_str)
{ {
muc_add_to_roster(room, nick, show, status, caps_str); muc_add_to_roster(room, nick, show, status, caps_str);
ui_room_member_online(room, nick, show, status);
ui_current_page_off(); char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
if (g_strcmp0(muc_status_pref, "none") != 0) {
ui_room_member_online(room, nick, show, status);
ui_current_page_off();
}
} }
void void
@ -497,8 +501,12 @@ handle_room_member_offline(const char * const room, const char * const nick,
const char * const show, const char * const status) const char * const show, const char * const status)
{ {
muc_remove_from_roster(room, nick); muc_remove_from_roster(room, nick);
ui_room_member_offline(room, nick);
ui_current_page_off(); char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
if (g_strcmp0(muc_status_pref, "none") != 0) {
ui_room_member_offline(room, nick);
ui_current_page_off();
}
} }
void void

View File

@ -992,16 +992,11 @@ _cons_statuses_setting(void)
{ {
char *console = prefs_get_string(PREF_STATUSES_CONSOLE); char *console = prefs_get_string(PREF_STATUSES_CONSOLE);
char *chat = prefs_get_string(PREF_STATUSES_CHAT); char *chat = prefs_get_string(PREF_STATUSES_CHAT);
gboolean muc = prefs_get_boolean(PREF_STATUSES_MUC); char *muc = prefs_get_string(PREF_STATUSES_MUC);
cons_show("Console statuses (/statuses) : %s", console); cons_show("Console statuses (/statuses) : %s", console);
cons_show("Chat win statuses (/statuses) : %s", chat); cons_show("Chat win statuses (/statuses) : %s", chat);
cons_show("Chat room statuses (/statuses) : %s", muc);
if (muc) {
cons_show("MUC statuses (/statuses) : ON");
} else {
cons_show("MUC statuses (/statuses) : OFF");
}
} }
static void static void

View File

@ -181,36 +181,55 @@ void cmd_statuses_chat_sets_none(void **state)
free(help); free(help);
} }
void cmd_statuses_muc_sets_on(void **state) void cmd_statuses_muc_sets_all(void **state)
{ {
mock_cons_show(); mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "muc", "on", NULL }; gchar *args[] = { "muc", "all", NULL };
expect_cons_show("Chat room presence updates enabled."); expect_cons_show("All presence updates will appear in chat room windows.");
gboolean result = cmd_statuses(args, *help); gboolean result = cmd_statuses(args, *help);
gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); char *setting = prefs_get_string(PREF_STATUSES_MUC);
assert_non_null(setting); assert_non_null(setting);
assert_true(setting); assert_string_equal("all", setting);
assert_true(result); assert_true(result);
free(help); free(help);
} }
void cmd_statuses_muc_sets_off(void **state) void cmd_statuses_muc_sets_online(void **state)
{ {
mock_cons_show(); mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "muc", "off", NULL }; gchar *args[] = { "muc", "online", NULL };
expect_cons_show("Chat room presence updates disabled."); expect_cons_show("Only join/leave presence updates will appear in chat room windows.");
gboolean result = cmd_statuses(args, *help); gboolean result = cmd_statuses(args, *help);
gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); char *setting = prefs_get_string(PREF_STATUSES_MUC);
assert_false(setting); assert_non_null(setting);
assert_string_equal("online", setting);
assert_true(result);
free(help);
}
void cmd_statuses_muc_sets_none(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "muc", "none", NULL };
expect_cons_show("Presence updates will not appear in chat room windows.");
gboolean result = cmd_statuses(args, *help);
char *setting = prefs_get_string(PREF_STATUSES_MUC);
assert_non_null(setting);
assert_string_equal("none", setting);
assert_true(result); assert_true(result);
free(help); free(help);

View File

@ -8,5 +8,6 @@ void cmd_statuses_console_sets_none(void **state);
void cmd_statuses_chat_sets_all(void **state); void cmd_statuses_chat_sets_all(void **state);
void cmd_statuses_chat_sets_online(void **state); void cmd_statuses_chat_sets_online(void **state);
void cmd_statuses_chat_sets_none(void **state); void cmd_statuses_chat_sets_none(void **state);
void cmd_statuses_muc_sets_on(void **state); void cmd_statuses_muc_sets_all(void **state);
void cmd_statuses_muc_sets_off(void **state); void cmd_statuses_muc_sets_online(void **state);
void cmd_statuses_muc_sets_none(void **state);

View File

@ -24,9 +24,10 @@ void statuses_chat_defaults_to_all(void **state)
assert_string_equal("all", setting); assert_string_equal("all", setting);
} }
void statuses_muc_defaults_to_on(void **state) void statuses_muc_defaults_to_all(void **state)
{ {
gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); char *setting = prefs_get_string(PREF_STATUSES_MUC);
assert_true(setting); assert_non_null(setting);
assert_string_equal("all", setting);
} }

View File

@ -1,3 +1,3 @@
void statuses_console_defaults_to_all(void **state); void statuses_console_defaults_to_all(void **state);
void statuses_chat_defaults_to_all(void **state); void statuses_chat_defaults_to_all(void **state);
void statuses_muc_defaults_to_on(void **state); void statuses_muc_defaults_to_all(void **state);

View File

@ -331,10 +331,13 @@ int main(int argc, char* argv[]) {
unit_test_setup_teardown(cmd_statuses_chat_sets_none, unit_test_setup_teardown(cmd_statuses_chat_sets_none,
load_preferences, load_preferences,
close_preferences), close_preferences),
unit_test_setup_teardown(cmd_statuses_muc_sets_on, unit_test_setup_teardown(cmd_statuses_muc_sets_all,
load_preferences, load_preferences,
close_preferences), close_preferences),
unit_test_setup_teardown(cmd_statuses_muc_sets_off, unit_test_setup_teardown(cmd_statuses_muc_sets_online,
load_preferences,
close_preferences),
unit_test_setup_teardown(cmd_statuses_muc_sets_none,
load_preferences, load_preferences,
close_preferences), close_preferences),
@ -344,7 +347,7 @@ int main(int argc, char* argv[]) {
unit_test_setup_teardown(statuses_chat_defaults_to_all, unit_test_setup_teardown(statuses_chat_defaults_to_all,
load_preferences, load_preferences,
close_preferences), close_preferences),
unit_test_setup_teardown(statuses_muc_defaults_to_on, unit_test_setup_teardown(statuses_muc_defaults_to_all,
load_preferences, load_preferences,
close_preferences), close_preferences),