1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Split autocompleters for roster and rooms

This commit is contained in:
James Booth 2014-10-04 22:43:22 +01:00
parent 2d05601259
commit 719dbfaacc
2 changed files with 161 additions and 105 deletions

View File

@ -937,7 +937,8 @@ static struct cmd_t command_defs[] =
};
static Autocomplete commands_ac;
static Autocomplete who_ac;
static Autocomplete who_room_ac;
static Autocomplete who_roster_ac;
static Autocomplete help_ac;
static Autocomplete notify_ac;
static Autocomplete notify_room_ac;
@ -1152,16 +1153,32 @@ cmd_init(void)
theme_load_ac = NULL;
who_ac = autocomplete_new();
autocomplete_add(who_ac, "chat");
autocomplete_add(who_ac, "online");
autocomplete_add(who_ac, "away");
autocomplete_add(who_ac, "xa");
autocomplete_add(who_ac, "dnd");
autocomplete_add(who_ac, "offline");
autocomplete_add(who_ac, "available");
autocomplete_add(who_ac, "unavailable");
autocomplete_add(who_ac, "any");
who_roster_ac = autocomplete_new();
autocomplete_add(who_roster_ac, "chat");
autocomplete_add(who_roster_ac, "online");
autocomplete_add(who_roster_ac, "away");
autocomplete_add(who_roster_ac, "xa");
autocomplete_add(who_roster_ac, "dnd");
autocomplete_add(who_roster_ac, "offline");
autocomplete_add(who_roster_ac, "available");
autocomplete_add(who_roster_ac, "unavailable");
autocomplete_add(who_roster_ac, "any");
who_room_ac = autocomplete_new();
autocomplete_add(who_room_ac, "chat");
autocomplete_add(who_room_ac, "online");
autocomplete_add(who_room_ac, "away");
autocomplete_add(who_room_ac, "xa");
autocomplete_add(who_room_ac, "dnd");
autocomplete_add(who_room_ac, "available");
autocomplete_add(who_room_ac, "unavailable");
autocomplete_add(who_room_ac, "moderator");
autocomplete_add(who_room_ac, "participant");
autocomplete_add(who_room_ac, "visitor");
autocomplete_add(who_room_ac, "owner");
autocomplete_add(who_room_ac, "admin");
autocomplete_add(who_room_ac, "member");
autocomplete_add(who_room_ac, "outcast");
bookmark_ac = autocomplete_new();
autocomplete_add(bookmark_ac, "list");
@ -1253,7 +1270,8 @@ void
cmd_uninit(void)
{
autocomplete_free(commands_ac);
autocomplete_free(who_ac);
autocomplete_free(who_room_ac);
autocomplete_free(who_roster_ac);
autocomplete_free(help_ac);
autocomplete_free(notify_ac);
autocomplete_free(notify_message_ac);
@ -1381,7 +1399,8 @@ cmd_reset_autocomplete()
muc_autocomplete_reset(recipient);
}
autocomplete_reset(who_ac);
autocomplete_reset(who_room_ac);
autocomplete_reset(who_roster_ac);
autocomplete_reset(prefs_ac);
autocomplete_reset(log_ac);
autocomplete_reset(commands_ac);
@ -1753,8 +1772,16 @@ _sub_autocomplete(char *input, int *size)
static char *
_who_autocomplete(char *input, int *size)
{
int i = 0;
char *result = NULL;
win_type_t win_type = ui_current_win_type();
if (win_type == WIN_MUC) {
result = autocomplete_param_with_ac(input, size, "/who", who_room_ac, TRUE);
if (result != NULL) {
return result;
}
} else {
int i = 0;
gchar *group_commands[] = { "/who any", "/who online", "/who offline",
"/who chat", "/who away", "/who xa", "/who dnd", "/who available",
"/who unavailable" };
@ -1766,10 +1793,11 @@ _who_autocomplete(char *input, int *size)
}
}
result = autocomplete_param_with_ac(input, size, "/who", who_ac, TRUE);
result = autocomplete_param_with_ac(input, size, "/who", who_roster_ac, TRUE);
if (result != NULL) {
return result;
}
}
return NULL;
}

View File

@ -725,27 +725,46 @@ cmd_theme(gchar **args, struct cmd_help_t help)
static void
_who_room(gchar **args, struct cmd_help_t help)
{
char *presence = args[0];
if ((g_strv_length(args) == 2) && (args[1] != NULL)) {
cons_show("Argument group is not applicable to chat rooms.");
return;
}
// bad arg
if ((presence != NULL)
&& (strcmp(presence, "online") != 0)
&& (strcmp(presence, "available") != 0)
&& (strcmp(presence, "unavailable") != 0)
&& (strcmp(presence, "away") != 0)
&& (strcmp(presence, "chat") != 0)
&& (strcmp(presence, "xa") != 0)
&& (strcmp(presence, "dnd") != 0)
&& (strcmp(presence, "any") != 0)) {
if (args[0] != NULL &&
(g_strcmp0(args[0], "online") != 0) &&
(g_strcmp0(args[0], "available") != 0) &&
(g_strcmp0(args[0], "unavailable") != 0) &&
(g_strcmp0(args[0], "away") != 0) &&
(g_strcmp0(args[0], "chat") != 0) &&
(g_strcmp0(args[0], "xa") != 0) &&
(g_strcmp0(args[0], "dnd") != 0) &&
(g_strcmp0(args[0], "any") != 0) &&
(g_strcmp0(args[0], "moderator") != 0) &&
(g_strcmp0(args[0], "participant") != 0) &&
(g_strcmp0(args[0], "visitor") != 0) &&
(g_strcmp0(args[0], "owner") != 0) &&
(g_strcmp0(args[0], "admin") != 0) &&
(g_strcmp0(args[0], "member") != 0) &&
(g_strcmp0(args[0], "outcast") != 0)) {
cons_show("Usage: %s", help.usage);
return;
}
char *room = ui_current_recipient();
// presence filter
if (args[0] == NULL ||
(g_strcmp0(args[0], "online") == 0) ||
(g_strcmp0(args[0], "available") == 0) ||
(g_strcmp0(args[0], "unavailable") == 0) ||
(g_strcmp0(args[0], "away") == 0) ||
(g_strcmp0(args[0], "chat") == 0) ||
(g_strcmp0(args[0], "xa") == 0) ||
(g_strcmp0(args[0], "dnd") == 0) ||
(g_strcmp0(args[0], "any") == 0)) {
char *presence = args[0];
GList *list = muc_roster(room);
// no arg, show all contacts
@ -795,6 +814,40 @@ _who_room(gchar **args, struct cmd_help_t help)
ui_room_roster(room, filtered, presence);
}
// role or affiliation filter
} else {
ProfWin *window = wins_get_by_recipient(room);
if (g_strcmp0(args[0], "moderator") == 0) {
ui_show_room_role_list(window, room, MUC_ROLE_MODERATOR);
return;
}
if (g_strcmp0(args[0], "participant") == 0) {
ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
return;
}
if (g_strcmp0(args[0], "visitor") == 0) {
ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
return;
}
if (g_strcmp0(args[0], "owner") == 0) {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
return;
}
if (g_strcmp0(args[0], "admin") == 0) {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_ADMIN);
return;
}
if (g_strcmp0(args[0], "member") == 0) {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_MEMBER);
return;
}
if (g_strcmp0(args[0], "outcast") == 0) {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OUTCAST);
return;
}
}
}
static void
@ -1006,13 +1059,11 @@ cmd_who(gchar **args, struct cmd_help_t help)
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
if (win_type == WIN_MUC) {
} else if (win_type == WIN_MUC) {
_who_room(args, help);
} else {
_who_roster(args, help);
}
}
if (win_type != WIN_CONSOLE && win_type != WIN_MUC) {
ui_statusbar_new(1);
@ -2075,13 +2126,18 @@ cmd_room(gchar **args, struct cmd_help_t help)
if ((g_strcmp0(args[0], "accept") != 0) &&
(g_strcmp0(args[0], "destroy") != 0) &&
(g_strcmp0(args[0], "config") != 0) &&
// roles
(g_strcmp0(args[0], "moderators") != 0) &&
(g_strcmp0(args[0], "participants") != 0) &&
(g_strcmp0(args[0], "visitors") != 0) &&
// affiliations
(g_strcmp0(args[0], "owners") != 0) &&
(g_strcmp0(args[0], "admins") != 0) &&
(g_strcmp0(args[0], "members") != 0) &&
(g_strcmp0(args[0], "outcasts") != 0) &&
(g_strcmp0(args[0], "info") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
@ -2102,19 +2158,6 @@ cmd_room(gchar **args, struct cmd_help_t help)
return TRUE;
}
if (g_strcmp0(args[0], "moderators") == 0) {
ui_show_room_role_list(window, room, MUC_ROLE_MODERATOR);
return TRUE;
}
if (g_strcmp0(args[0], "participants") == 0) {
ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
return TRUE;
}
if (g_strcmp0(args[0], "visitors") == 0) {
ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
return TRUE;
}
if (g_strcmp0(args[0], "owners") == 0) {
if ((g_strcmp0(args[1], "add") == 0) || (g_strcmp0(args[1], "remove") == 0)) {
char *nick = args[2];
@ -2156,24 +2199,9 @@ cmd_room(gchar **args, struct cmd_help_t help)
}
jid_destroy(jidp);
return TRUE;
} else {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
}
return TRUE;
}
}
if (g_strcmp0(args[0], "admins") == 0) {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_ADMIN);
return TRUE;
}
if (g_strcmp0(args[0], "members") == 0) {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_MEMBER);
return TRUE;
}
if (g_strcmp0(args[0], "outcasts") == 0) {
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OUTCAST);
return TRUE;
}
if (g_strcmp0(args[0], "accept") == 0) {
gboolean requires_config = muc_requires_config(room);