mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Added /roster indent resource
This commit is contained in:
parent
f54c2e8eca
commit
ef0f093efd
@ -281,6 +281,7 @@ static struct cmd_t command_defs[] =
|
||||
"/roster char header <char>|none",
|
||||
"/roster char contact <char>|none",
|
||||
"/roster indent contact <indent>",
|
||||
"/roster indent resource <indent>",
|
||||
"/roster size <percent>",
|
||||
"/roster add <jid> [<nick>]",
|
||||
"/roster remove <jid>",
|
||||
@ -318,6 +319,7 @@ static struct cmd_t command_defs[] =
|
||||
{ "char contact <char>", "Prefix roster contacts with specificed character." },
|
||||
{ "char contact none", "Remove roster contact character prefix." },
|
||||
{ "indent contact <indent>", "Indent contact line by <indent> spaces." },
|
||||
{ "indent resource <indent>", "Indent roster line by <indent> spaces." },
|
||||
{ "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." },
|
||||
@ -2047,6 +2049,7 @@ cmd_init(void)
|
||||
|
||||
roster_indent_ac = autocomplete_new();
|
||||
autocomplete_add(roster_indent_ac, "contact");
|
||||
autocomplete_add(roster_indent_ac, "resource");
|
||||
|
||||
roster_option_ac = autocomplete_new();
|
||||
autocomplete_add(roster_option_ac, "offline");
|
||||
|
@ -1799,6 +1799,22 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
|
||||
free(err_msg);
|
||||
}
|
||||
}
|
||||
} else if (g_strcmp0(args[1], "resource") == 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_resource_indent(intval);
|
||||
cons_show("Roster resource indent set to: %d", intval);
|
||||
rosterwin_roster();
|
||||
} else {
|
||||
cons_show(err_msg);
|
||||
free(err_msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
|
@ -528,6 +528,28 @@ prefs_set_roster_contact_indent(gint value)
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
gint
|
||||
prefs_get_roster_resource_indent(void)
|
||||
{
|
||||
if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "roster.resource.indent", NULL)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.resource.indent", NULL);
|
||||
if (result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
prefs_set_roster_resource_indent(gint value)
|
||||
{
|
||||
g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.resource.indent", value);
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
gboolean
|
||||
prefs_add_alias(const char *const name, const char *const value)
|
||||
{
|
||||
|
@ -174,6 +174,8 @@ void prefs_clear_roster_contact_char(void);
|
||||
|
||||
gint prefs_get_roster_contact_indent(void);
|
||||
void prefs_set_roster_contact_indent(gint value);
|
||||
gint prefs_get_roster_resource_indent(void);
|
||||
void prefs_set_roster_resource_indent(gint value);
|
||||
|
||||
void prefs_add_login(const char *jid);
|
||||
|
||||
|
@ -1257,6 +1257,9 @@ cons_roster_setting(void)
|
||||
|
||||
gint contact_indent = prefs_get_roster_contact_indent();
|
||||
cons_show("Roster contact indent (/roster) : %d", contact_indent);
|
||||
|
||||
gint resource_indent = prefs_get_roster_resource_indent();
|
||||
cons_show("Roster resource indent (/roster) : %d", resource_indent);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -93,10 +93,15 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co
|
||||
}
|
||||
|
||||
static void
|
||||
_rosterwin_resource(ProfLayoutSplit *layout, PContact contact)
|
||||
_rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_indent)
|
||||
{
|
||||
GList *resources = p_contact_get_available_resources(contact);
|
||||
if (resources) {
|
||||
int resource_indent = prefs_get_roster_resource_indent();
|
||||
if (resource_indent > 0) {
|
||||
current_indent += resource_indent;
|
||||
}
|
||||
|
||||
GList *curr_resource = resources;
|
||||
while (curr_resource) {
|
||||
Resource *resource = curr_resource->data;
|
||||
@ -105,6 +110,11 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact)
|
||||
|
||||
wattron(layout->subwin, theme_attrs(resource_presence_colour));
|
||||
GString *msg = g_string_new(" ");
|
||||
int this_indent = current_indent;
|
||||
while (this_indent > 0) {
|
||||
g_string_append(msg, " ");
|
||||
this_indent--;
|
||||
}
|
||||
g_string_append(msg, resource->name);
|
||||
if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) {
|
||||
g_string_append_printf(msg, " [%d]", resource->priority);
|
||||
@ -141,7 +151,9 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact)
|
||||
wattron(layout->subwin, theme_attrs(presence_colour));
|
||||
GString *msg = g_string_new(" ");
|
||||
int indent = prefs_get_roster_contact_indent();
|
||||
int current_indent = 0;
|
||||
if (indent > 0) {
|
||||
current_indent += indent;
|
||||
while (indent > 0) {
|
||||
g_string_append(msg, " ");
|
||||
indent--;
|
||||
@ -157,7 +169,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact)
|
||||
wattroff(layout->subwin, theme_attrs(presence_colour));
|
||||
|
||||
if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
|
||||
_rosterwin_resource(layout, contact);
|
||||
_rosterwin_resource(layout, contact, current_indent);
|
||||
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
|
||||
_rosterwin_presence(layout, 4, presence_colour, presence, status);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user