Add occupants header char

`/occupants header char` now sets a character that is displayed before
the role (moderator, visitor..) in a room. Similar to `/roster header
char` is displaying a char for the roster.

Regards https://github.com/boothj5/profanity/issues/690
This commit is contained in:
Michael Vetter
2019-04-23 13:50:58 +02:00
parent 82ddd88578
commit 566022786d
9 changed files with 155 additions and 6 deletions

View File

@@ -183,6 +183,8 @@ static Autocomplete form_field_multi_ac;
static Autocomplete occupants_ac;
static Autocomplete occupants_default_ac;
static Autocomplete occupants_show_ac;
static Autocomplete occupants_header_ac;
static Autocomplete occupants_char_ac;
static Autocomplete time_ac;
static Autocomplete time_format_ac;
static Autocomplete resource_ac;
@@ -684,6 +686,7 @@ cmd_ac_init(void)
autocomplete_add(occupants_ac, "default");
autocomplete_add(occupants_ac, "size");
autocomplete_add(occupants_ac, "indent");
autocomplete_add(occupants_ac, "header");
occupants_default_ac = autocomplete_new();
autocomplete_add(occupants_default_ac, "show");
@@ -692,6 +695,12 @@ cmd_ac_init(void)
occupants_show_ac = autocomplete_new();
autocomplete_add(occupants_show_ac, "jid");
occupants_header_ac = autocomplete_new();
autocomplete_add(occupants_header_ac, "char");
occupants_char_ac = autocomplete_new();
autocomplete_add(occupants_char_ac, "none");
time_ac = autocomplete_new();
autocomplete_add(time_ac, "console");
autocomplete_add(time_ac, "chat");
@@ -1107,6 +1116,8 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(occupants_ac);
autocomplete_reset(occupants_default_ac);
autocomplete_reset(occupants_show_ac);
autocomplete_reset(occupants_header_ac);
autocomplete_reset(occupants_char_ac);
autocomplete_reset(time_ac);
autocomplete_reset(time_format_ac);
autocomplete_reset(resource_ac);
@@ -1237,6 +1248,7 @@ cmd_ac_uninit(void)
autocomplete_free(occupants_ac);
autocomplete_free(occupants_default_ac);
autocomplete_free(occupants_show_ac);
autocomplete_free(occupants_header_ac);
autocomplete_free(time_ac);
autocomplete_free(time_format_ac);
autocomplete_free(resource_ac);
@@ -2570,6 +2582,16 @@ _occupants_autocomplete(ProfWin *window, const char *const input, gboolean previ
return found;
}
found = autocomplete_param_with_ac(input, "/occupants header char", roster_char_ac, TRUE, previous);
if (found) {
return found;
}
found = autocomplete_param_with_ac(input, "/occupants header", occupants_header_ac, TRUE, previous);
if (found) {
return found;
}
found = autocomplete_param_with_ac(input, "/occupants", occupants_ac, TRUE, previous);
if (found) {
return found;

View File

@@ -754,7 +754,8 @@ static struct cmd_t command_defs[] =
"/occupants show|hide [jid]",
"/occupants default show|hide [jid]",
"/occupants size [<percent>]",
"/occupants indent <indent>")
"/occupants indent <indent>",
"/occupants header char <char>|none")
CMD_DESC(
"Show or hide room occupants, and occupants panel display settings.")
CMD_ARGS(
@@ -765,7 +766,9 @@ static struct cmd_t command_defs[] =
{ "default show|hide", "Whether occupants are shown by default in new rooms." },
{ "default show|hide jid", "Whether occupants jids are shown by default in new rooms." },
{ "size <percent>", "Percentage of the screen taken by the occupants list in rooms (1-99)." },
{ "indent <indent>", "Indent contact line by <indent> spaces (0 to 10)." })
{ "indent <indent>", "Indent contact line by <indent> spaces (0 to 10)." },
{ "header char <char>", "Prefix roster headers with specified character." },
{ "header char none", "Remove roster header character prefix." })
CMD_NOEXAMPLES
},

View File

@@ -4426,6 +4426,49 @@ cmd_occupants(ProfWin *window, const char *const command, gchar **args)
}
}
// header settings
if (g_strcmp0(args[0], "header") == 0) {
if (g_strcmp0(args[1], "char") == 0) {
if (!args[2]) {
cons_bad_cmd_usage(command);
} else if (g_strcmp0(args[2], "none") == 0) {
prefs_clear_occupants_header_char();
cons_show("Occupants header char removed.");
// get the list of joined rooms
GList *rooms = muc_rooms();
GList *curr = rooms;
while (curr) {
char* roomjid = curr->data;
ProfMucWin *mw = wins_get_muc(roomjid);
if (mw != NULL)
mucwin_update_occupants(mw);
curr = g_list_next(curr);
}
} else {
prefs_set_occupants_header_char(args[2][0]);
cons_show("Occupants header char set to %c.", args[2][0]);
//TODO:func like rosterwin_roster();
// get the list of joined rooms
GList *rooms = muc_rooms();
GList *curr = rooms;
while (curr) {
char* roomjid = curr->data;
ProfMucWin *mw = wins_get_muc(roomjid);
if (mw != NULL)
mucwin_update_occupants(mw);
curr = g_list_next(curr);
}
}
} else {
cons_bad_cmd_usage(command);
}
return TRUE;
}
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");