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

Added /roster indent presence

This commit is contained in:
James Booth 2015-11-21 22:03:43 +00:00
parent ef0f093efd
commit 5c08bea8d0
6 changed files with 61 additions and 9 deletions

View File

@ -282,6 +282,7 @@ static struct cmd_t command_defs[] =
"/roster char contact <char>|none", "/roster char contact <char>|none",
"/roster indent contact <indent>", "/roster indent contact <indent>",
"/roster indent resource <indent>", "/roster indent resource <indent>",
"/roster indent presence <indent>",
"/roster size <percent>", "/roster size <percent>",
"/roster add <jid> [<nick>]", "/roster add <jid> [<nick>]",
"/roster remove <jid>", "/roster remove <jid>",
@ -319,7 +320,8 @@ static struct cmd_t command_defs[] =
{ "char contact <char>", "Prefix roster contacts with specificed character." }, { "char contact <char>", "Prefix roster contacts with specificed character." },
{ "char contact none", "Remove roster contact character prefix." }, { "char contact none", "Remove roster contact character prefix." },
{ "indent contact <indent>", "Indent contact line by <indent> spaces." }, { "indent contact <indent>", "Indent contact line by <indent> spaces." },
{ "indent resource <indent>", "Indent roster line by <indent> spaces." }, { "indent resource <indent>", "Indent resource line by <indent> spaces." },
{ "indent presence <indent>", "Indent presence line by <indent> spaces." },
{ "size <precent>", "Percentage of the screen taken up by the roster (1-99)." }, { "size <precent>", "Percentage of the screen taken up by the roster (1-99)." },
{ "add <jid> [<nick>]", "Add a new item to the roster." }, { "add <jid> [<nick>]", "Add a new item to the roster." },
{ "remove <jid>", "Removes an item from the roster." }, { "remove <jid>", "Removes an item from the roster." },
@ -2050,6 +2052,7 @@ cmd_init(void)
roster_indent_ac = autocomplete_new(); roster_indent_ac = autocomplete_new();
autocomplete_add(roster_indent_ac, "contact"); autocomplete_add(roster_indent_ac, "contact");
autocomplete_add(roster_indent_ac, "resource"); autocomplete_add(roster_indent_ac, "resource");
autocomplete_add(roster_indent_ac, "presence");
roster_option_ac = autocomplete_new(); roster_option_ac = autocomplete_new();
autocomplete_add(roster_option_ac, "offline"); autocomplete_add(roster_option_ac, "offline");

View File

@ -1815,6 +1815,22 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
free(err_msg); free(err_msg);
} }
} }
} else if (g_strcmp0(args[1], "presence") == 0) {
if (!args[2]) {
cons_bad_cmd_usage(command);
} else {
int intval = 0;
char *err_msg = NULL;
gboolean res = strtoi_range(args[2], &intval, 0, 10, &err_msg);
if (res) {
prefs_set_roster_presence_indent(intval);
cons_show("Roster presence indent set to: %d", intval);
rosterwin_roster();
} else {
cons_show(err_msg);
free(err_msg);
}
}
} else { } else {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
} }

View File

@ -550,6 +550,28 @@ prefs_set_roster_resource_indent(gint value)
_save_prefs(); _save_prefs();
} }
gint
prefs_get_roster_presence_indent(void)
{
if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "roster.presence.indent", NULL)) {
return 2;
}
gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.presence.indent", NULL);
if (result < 0) {
result = 0;
}
return result;
}
void
prefs_set_roster_presence_indent(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.presence.indent", value);
_save_prefs();
}
gboolean gboolean
prefs_add_alias(const char *const name, const char *const value) prefs_add_alias(const char *const name, const char *const value)
{ {

View File

@ -176,6 +176,8 @@ gint prefs_get_roster_contact_indent(void);
void prefs_set_roster_contact_indent(gint value); void prefs_set_roster_contact_indent(gint value);
gint prefs_get_roster_resource_indent(void); gint prefs_get_roster_resource_indent(void);
void prefs_set_roster_resource_indent(gint value); void prefs_set_roster_resource_indent(gint value);
gint prefs_get_roster_presence_indent(void);
void prefs_set_roster_presence_indent(gint value);
void prefs_add_login(const char *jid); void prefs_add_login(const char *jid);

View File

@ -1260,6 +1260,9 @@ cons_roster_setting(void)
gint resource_indent = prefs_get_roster_resource_indent(); gint resource_indent = prefs_get_roster_resource_indent();
cons_show("Roster resource indent (/roster) : %d", resource_indent); cons_show("Roster resource indent (/roster) : %d", resource_indent);
gint presence_indent = prefs_get_roster_presence_indent();
cons_show("Roster presence indent (/roster) : %d", presence_indent);
} }
void void

View File

@ -43,7 +43,8 @@
#include "roster_list.h" #include "roster_list.h"
static void static void
_rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, const char *presence, const char *status) _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *presence, const char *status,
int current_indent)
{ {
// don't show presence for offline contacts // don't show presence for offline contacts
gboolean is_offline = g_strcmp0(presence, "offline") == 0; gboolean is_offline = g_strcmp0(presence, "offline") == 0;
@ -55,14 +56,19 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co
gboolean by_presence = g_strcmp0(by, "presence") == 0; gboolean by_presence = g_strcmp0(by, "presence") == 0;
prefs_free_string(by); prefs_free_string(by);
int presence_indent = prefs_get_roster_presence_indent();
if (presence_indent > 0) {
current_indent += presence_indent;
}
// show only status when grouped by presence // show only status when grouped by presence
if (by_presence) { if (by_presence) {
if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
wattron(layout->subwin, theme_attrs(colour)); wattron(layout->subwin, theme_attrs(colour));
GString *msg = g_string_new(" "); GString *msg = g_string_new(" ");
while (indent > 0) { while (current_indent > 0) {
g_string_append(msg, " "); g_string_append(msg, " ");
indent--; current_indent--;
} }
g_string_append_printf(msg, "\"%s\"", status); g_string_append_printf(msg, "\"%s\"", status);
win_print_nowrap(layout->subwin, msg->str, TRUE); win_print_nowrap(layout->subwin, msg->str, TRUE);
@ -74,9 +80,9 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || (status && prefs_get_boolean(PREF_ROSTER_STATUS))) { } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || (status && prefs_get_boolean(PREF_ROSTER_STATUS))) {
wattron(layout->subwin, theme_attrs(colour)); wattron(layout->subwin, theme_attrs(colour));
GString *msg = g_string_new(" "); GString *msg = g_string_new(" ");
while (indent > 0) { while (current_indent > 0) {
g_string_append(msg, " "); g_string_append(msg, " ");
indent--; current_indent--;
} }
if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
g_string_append(msg, presence); g_string_append(msg, presence);
@ -124,7 +130,7 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_inden
wattroff(layout->subwin, theme_attrs(resource_presence_colour)); wattroff(layout->subwin, theme_attrs(resource_presence_colour));
if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
_rosterwin_presence(layout, 6, resource_presence_colour, resource_presence, resource->status); _rosterwin_presence(layout, resource_presence_colour, resource_presence, resource->status, current_indent);
} }
curr_resource = g_list_next(curr_resource); curr_resource = g_list_next(curr_resource);
@ -133,7 +139,7 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_inden
const char *presence = p_contact_presence(contact); const char *presence = p_contact_presence(contact);
const char *status = p_contact_status(contact); const char *status = p_contact_status(contact);
theme_item_t presence_colour = theme_main_presence_attrs(presence); theme_item_t presence_colour = theme_main_presence_attrs(presence);
_rosterwin_presence(layout, 4, presence_colour, presence, status); _rosterwin_presence(layout, presence_colour, presence, status, current_indent);
} }
g_list_free(resources); g_list_free(resources);
@ -171,7 +177,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact)
if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
_rosterwin_resource(layout, contact, current_indent); _rosterwin_resource(layout, contact, current_indent);
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
_rosterwin_presence(layout, 4, presence_colour, presence, status); _rosterwin_presence(layout, presence_colour, presence, status, current_indent);
} }
} }