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

Added /roster char header

This commit is contained in:
James Booth 2015-11-19 23:21:51 +00:00
parent 78a8487892
commit 316b6a7b8b
9 changed files with 128 additions and 12 deletions

View File

@ -278,6 +278,7 @@ static struct cmd_t command_defs[] =
"/roster hide [offline|resource|presence|status|empty|count|priority]",
"/roster by group|presence|none",
"/roster order name|presence",
"/roster char header <char>|none",
"/roster size <percent>",
"/roster add <jid> [<nick>]",
"/roster remove <jid>",
@ -310,6 +311,8 @@ static struct cmd_t command_defs[] =
{ "by none", "No grouping in the roster panel." },
{ "order name", "Order roster items by name only." },
{ "order presence", "Order roster items by presence, and then by name." },
{ "char header <char>", "Prefix roster headers with specificed character." },
{ "char header none", "Remove roster header character prefix." },
{ "size <precent>", "Percentage of the screen taken up by the roster (1-99)." },
{ "add <jid> [<nick>]", "Add a new item to the roster." },
{ "remove <jid>", "Removes an item from the roster." },
@ -1776,6 +1779,8 @@ static Autocomplete disco_ac;
static Autocomplete close_ac;
static Autocomplete wins_ac;
static Autocomplete roster_ac;
static Autocomplete roster_char_ac;
static Autocomplete roster_char_none_ac;
static Autocomplete roster_option_ac;
static Autocomplete roster_by_ac;
static Autocomplete roster_order_ac;
@ -2024,6 +2029,13 @@ cmd_init(void)
autocomplete_add(roster_ac, "by");
autocomplete_add(roster_ac, "order");
autocomplete_add(roster_ac, "size");
autocomplete_add(roster_ac, "char");
roster_char_ac = autocomplete_new();
autocomplete_add(roster_char_ac, "header");
roster_char_none_ac = autocomplete_new();
autocomplete_add(roster_char_none_ac, "none");
roster_option_ac = autocomplete_new();
autocomplete_add(roster_option_ac, "offline");
@ -2295,6 +2307,8 @@ cmd_uninit(void)
autocomplete_free(close_ac);
autocomplete_free(wins_ac);
autocomplete_free(roster_ac);
autocomplete_free(roster_char_ac);
autocomplete_free(roster_char_none_ac);
autocomplete_free(roster_option_ac);
autocomplete_free(roster_by_ac);
autocomplete_free(roster_order_ac);
@ -2482,6 +2496,8 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(close_ac);
autocomplete_reset(wins_ac);
autocomplete_reset(roster_ac);
autocomplete_reset(roster_char_ac);
autocomplete_reset(roster_char_none_ac);
autocomplete_reset(roster_option_ac);
autocomplete_reset(roster_by_ac);
autocomplete_reset(roster_order_ac);
@ -2870,6 +2886,10 @@ static char*
_roster_autocomplete(ProfWin *window, const char *const input)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, "/roster char header", roster_char_none_ac, TRUE);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/roster nick", roster_barejid_autocomplete);
if (result) {
return result;
@ -2902,6 +2922,10 @@ _roster_autocomplete(ProfWin *window, const char *const input)
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/roster char", roster_char_ac, TRUE);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE);
if (result) {
return result;

View File

@ -1750,6 +1750,25 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
// set header character
} else if (g_strcmp0(args[0], "char") == 0) {
if (g_strcmp0(args[1], "header") == 0) {
if (!args[2]) {
cons_bad_cmd_usage(command);
} else if (g_strcmp0(args[2], "none") == 0) {
prefs_clear_roster_header_char();
cons_show("Roster header char removed.");
rosterwin_roster();
} else {
prefs_set_roster_header_char(args[2][0]);
cons_show("Roster header char set to %c.", args[2][0]);
rosterwin_roster();
}
} else {
cons_bad_cmd_usage(command);
}
return TRUE;
// show/hide roster
} else if (g_strcmp0(args[0], "show") == 0) {
if (args[1] == NULL) {

View File

@ -444,6 +444,40 @@ prefs_set_pgp_char(char ch)
_save_prefs();
}
char
prefs_get_roster_header_char(void)
{
char result = 0;
char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.header.char", NULL);
if (!resultstr) {
result = 0;
} else {
result = resultstr[0];
}
free(resultstr);
return result;
}
void
prefs_set_roster_header_char(char ch)
{
char str[2];
str[0] = ch;
str[1] = '\0';
g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.header.char", str);
_save_prefs();
}
void
prefs_clear_roster_header_char(void)
{
g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.header.char", NULL);
_save_prefs();
}
gboolean
prefs_add_alias(const char *const name, const char *const value)
{

View File

@ -165,6 +165,10 @@ void prefs_set_otr_char(char ch);
char prefs_get_pgp_char(void);
void prefs_set_pgp_char(char ch);
char prefs_get_roster_header_char(void);
void prefs_set_roster_header_char(char ch);
void prefs_clear_roster_header_char(void);
void prefs_add_login(const char *jid);
gboolean prefs_add_alias(const char *const name, const char *const value);

View File

@ -469,6 +469,13 @@ _load_preferences(void)
gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL);
prefs_set_roster_size(roster_size);
}
if (g_key_file_has_key(theme, "ui", "roster.header.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_roster_header_char(ch[0]);
g_free(ch);
}
}
_set_boolean_preference("privileges", PREF_MUC_PRIVILEGES);

View File

@ -159,7 +159,12 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese
// if this group has contacts, or if we want to show empty groups
if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GString *title_str = g_string_new(title);
GString *title_str = g_string_new(" ");
char ch = prefs_get_roster_header_char();
if (ch) {
g_string_append_printf(title_str, "%c", ch);
}
g_string_append(title_str, title);
if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title_str, " (%d)", g_slist_length(contacts));
}
@ -194,7 +199,11 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GString *title = g_string_new(" -");
GString *title = g_string_new(" ");
char ch = prefs_get_roster_header_char();
if (ch) {
g_string_append_printf(title, "%c", ch);
}
g_string_append(title, group);
if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title, " (%d)", g_slist_length(contacts));
@ -228,7 +237,13 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GString *title = g_string_new(" -no group");
GString *title = g_string_new(" ");
char ch = prefs_get_roster_header_char();
if (ch) {
g_string_append_printf(title, "%c", ch);
}
g_string_append(title, "no group");
if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title, " (%d)", g_slist_length(contacts));
}
@ -257,13 +272,13 @@ rosterwin_roster(void)
char *by = prefs_get_string(PREF_ROSTER_BY);
if (g_strcmp0(by, "presence") == 0) {
werase(layout->subwin);
_rosterwin_contacts_by_presence(layout, "chat", " -Available for chat");
_rosterwin_contacts_by_presence(layout, "online", " -Online");
_rosterwin_contacts_by_presence(layout, "away", " -Away");
_rosterwin_contacts_by_presence(layout, "xa", " -Extended Away");
_rosterwin_contacts_by_presence(layout, "dnd", " -Do not disturb");
_rosterwin_contacts_by_presence(layout, "chat", "Available for chat");
_rosterwin_contacts_by_presence(layout, "online", "Online");
_rosterwin_contacts_by_presence(layout, "away", "Away");
_rosterwin_contacts_by_presence(layout, "xa", "Extended Away");
_rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb");
if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
_rosterwin_contacts_by_presence(layout, "offline", " -Offline");
_rosterwin_contacts_by_presence(layout, "offline", "Offline");
}
} else if (g_strcmp0(by, "group") == 0) {
werase(layout->subwin);
@ -289,7 +304,12 @@ rosterwin_roster(void)
werase(layout->subwin);
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GString *title = g_string_new(" -Roster");
GString *title = g_string_new(" ");
char ch = prefs_get_roster_header_char();
if (ch) {
g_string_append_printf(title, "%c", ch);
}
g_string_append(title, "Roster");
if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title, " (%d)", g_slist_length(contacts));
}

View File

@ -74,9 +74,15 @@ statuses.muc=
roster=
roster.offline=
roster.resource=
roster.by=
roster.size=
roster.presence=
roster.status=
roster.empty=
roster.by=
roster.order=
roster.count=
roster.priority=
roster.size=
roster.header.char=
occupants=
occupants.size=
occupants.jid=

View File

@ -82,6 +82,7 @@ roster.order=presence
roster.count=true
roster.priority=true
roster.size=25
roster.header.char=@
occupants=true
occupants.size=15
occupants.jid=false

View File

@ -29,6 +29,7 @@ roster.order=presence
roster.count=true
roster.priority=true
roster.size=25
roster.header.char=-
privileges=true
presence=true
intype=true