mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
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:
parent
82ddd88578
commit
566022786d
@ -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;
|
||||
|
@ -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
|
||||
},
|
||||
|
||||
|
@ -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.");
|
||||
|
@ -772,6 +772,40 @@ prefs_set_occupants_indent(gint value)
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
char
|
||||
prefs_get_occupants_header_char(void)
|
||||
{
|
||||
char result = 0;
|
||||
|
||||
char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "occupants.header.char", NULL);
|
||||
if (!resultstr) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = resultstr[0];
|
||||
}
|
||||
free(resultstr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
prefs_set_occupants_header_char(char ch)
|
||||
{
|
||||
char str[2];
|
||||
str[0] = ch;
|
||||
str[1] = '\0';
|
||||
|
||||
g_key_file_set_string(prefs, PREF_GROUP_UI, "occupants.header.char", str);
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
void
|
||||
prefs_clear_occupants_header_char(void)
|
||||
{
|
||||
g_key_file_remove_key(prefs, PREF_GROUP_UI, "occupants.header.char", NULL);
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
void
|
||||
prefs_set_roster_size(gint value)
|
||||
{
|
||||
|
@ -239,6 +239,9 @@ void prefs_clear_roster_room_char(void);
|
||||
char prefs_get_roster_room_private_char(void);
|
||||
void prefs_set_roster_room_private_char(char ch);
|
||||
void prefs_clear_roster_room_private_char(void);
|
||||
char prefs_get_occupants_header_char(void);
|
||||
void prefs_set_occupants_header_char(char ch);
|
||||
void prefs_clear_occupants_header_char(void);
|
||||
|
||||
gint prefs_get_roster_contact_indent(void);
|
||||
void prefs_set_roster_contact_indent(gint value);
|
||||
|
@ -457,6 +457,16 @@ _load_preferences(void)
|
||||
prefs_set_occupants_indent(occupants_indent);
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "occupants.header.char", NULL)) {
|
||||
gchar *ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
|
||||
if (ch && strlen(ch) > 0) {
|
||||
prefs_set_occupants_header_char(ch[0]);
|
||||
g_free(ch);
|
||||
}
|
||||
} else {
|
||||
prefs_clear_occupants_header_char();
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) {
|
||||
gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL);
|
||||
prefs_set_roster_size(roster_size);
|
||||
|
@ -1237,6 +1237,12 @@ cons_occupants_setting(void)
|
||||
|
||||
int size = prefs_get_occupants_size();
|
||||
cons_show("Occupants size (/occupants) : %d", size);
|
||||
|
||||
char header_ch = prefs_get_occupants_header_char();
|
||||
if (header_ch)
|
||||
cons_show("Occupants header char (/occupants) : %c", header_ch);
|
||||
else
|
||||
cons_show("Occupants header char (/occupants) : none");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -90,10 +90,22 @@ occupantswin_occupants(const char *const roomjid)
|
||||
|
||||
werase(layout->subwin);
|
||||
|
||||
GString *prefix = g_string_new(" ");
|
||||
|
||||
char ch = prefs_get_occupants_header_char();
|
||||
if (ch) {
|
||||
g_string_append_printf(prefix, "%c", ch);
|
||||
}
|
||||
|
||||
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
|
||||
|
||||
GString *role = g_string_new(prefix->str);
|
||||
g_string_append(role, "Moderators");
|
||||
|
||||
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
win_sub_print(layout->subwin, " -Moderators", TRUE, FALSE, 0);
|
||||
win_sub_print(layout->subwin, role->str, TRUE, FALSE, 0);
|
||||
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
g_string_free(role, TRUE);
|
||||
GList *roster_curr = occupants;
|
||||
while (roster_curr) {
|
||||
Occupant *occupant = roster_curr->data;
|
||||
@ -103,9 +115,13 @@ occupantswin_occupants(const char *const roomjid)
|
||||
roster_curr = g_list_next(roster_curr);
|
||||
}
|
||||
|
||||
role = g_string_new(prefix->str);
|
||||
g_string_append(role, "Participants");
|
||||
|
||||
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
win_sub_print(layout->subwin, " -Participants", TRUE, FALSE, 0);
|
||||
win_sub_print(layout->subwin, role->str, TRUE, FALSE, 0);
|
||||
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
g_string_free(role, TRUE);
|
||||
roster_curr = occupants;
|
||||
while (roster_curr) {
|
||||
Occupant *occupant = roster_curr->data;
|
||||
@ -115,9 +131,13 @@ occupantswin_occupants(const char *const roomjid)
|
||||
roster_curr = g_list_next(roster_curr);
|
||||
}
|
||||
|
||||
role = g_string_new(prefix->str);
|
||||
g_string_append(role, "Visitors");
|
||||
|
||||
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
win_sub_print(layout->subwin, " -Visitors", TRUE, FALSE, 0);
|
||||
win_sub_print(layout->subwin, role->str, TRUE, FALSE, 0);
|
||||
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
g_string_free(role, TRUE);
|
||||
roster_curr = occupants;
|
||||
while (roster_curr) {
|
||||
Occupant *occupant = roster_curr->data;
|
||||
@ -127,9 +147,14 @@ occupantswin_occupants(const char *const roomjid)
|
||||
roster_curr = g_list_next(roster_curr);
|
||||
}
|
||||
} else {
|
||||
GString *role = g_string_new(prefix->str);
|
||||
g_string_append(role, "Occupants\n");
|
||||
|
||||
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
win_sub_print(layout->subwin, " -Occupants\n", TRUE, FALSE, 0);
|
||||
win_sub_print(layout->subwin, role->str, TRUE, FALSE, 0);
|
||||
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
|
||||
g_string_free(role, TRUE);
|
||||
|
||||
GList *roster_curr = occupants;
|
||||
while (roster_curr) {
|
||||
Occupant *occupant = roster_curr->data;
|
||||
@ -137,6 +162,8 @@ occupantswin_occupants(const char *const roomjid)
|
||||
roster_curr = g_list_next(roster_curr);
|
||||
}
|
||||
}
|
||||
|
||||
g_string_free(prefix, TRUE);
|
||||
}
|
||||
|
||||
g_list_free(occupants);
|
||||
|
@ -133,6 +133,7 @@ occupants=
|
||||
occupants.size=
|
||||
occupants.jid=
|
||||
occupants.indent=
|
||||
occupants.header.char=
|
||||
wins.autotidy=
|
||||
otr.char=
|
||||
pgp.char=
|
||||
|
Loading…
Reference in New Issue
Block a user