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

Added /roster resource join

This commit is contained in:
James Booth 2015-11-22 16:37:05 +00:00
parent 0a0226186a
commit 0f22179eef
5 changed files with 79 additions and 17 deletions

View File

@ -284,6 +284,7 @@ static struct cmd_t command_defs[] =
"/roster indent contact <indent>", "/roster indent contact <indent>",
"/roster indent resource <indent>", "/roster indent resource <indent>",
"/roster indent presence <indent>", "/roster indent presence <indent>",
"/roster resource join on|off",
"/roster size <percent>", "/roster size <percent>",
"/roster wrap on|off", "/roster wrap on|off",
"/roster add <jid> [<nick>]", "/roster add <jid> [<nick>]",
@ -326,6 +327,7 @@ static struct cmd_t command_defs[] =
{ "indent contact <indent>", "Indent contact line by <indent> spaces (0 to 10)." }, { "indent contact <indent>", "Indent contact line by <indent> spaces (0 to 10)." },
{ "indent resource <indent>", "Indent resource line by <indent> spaces (0 to 10)." }, { "indent resource <indent>", "Indent resource line by <indent> spaces (0 to 10)." },
{ "indent presence <indent>", "Indent presence line by <indent> spaces (-1 to 10), a value of -1 will show presence on the previous line." }, { "indent presence <indent>", "Indent presence line by <indent> spaces (-1 to 10), a value of -1 will show presence on the previous line." },
{ "resource join on|off", "Join resource with previous line when only one available resource." },
{ "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)." },
{ "wrap on|off", "Enabled or disanle line wrapping in roster panel." }, { "wrap on|off", "Enabled or disanle line wrapping in roster panel." },
{ "add <jid> [<nick>]", "Add a new item to the roster." }, { "add <jid> [<nick>]", "Add a new item to the roster." },
@ -1793,6 +1795,7 @@ static Autocomplete disco_ac;
static Autocomplete close_ac; static Autocomplete close_ac;
static Autocomplete wins_ac; static Autocomplete wins_ac;
static Autocomplete roster_ac; static Autocomplete roster_ac;
static Autocomplete roster_resource_ac;
static Autocomplete roster_char_ac; static Autocomplete roster_char_ac;
static Autocomplete roster_char_none_ac; static Autocomplete roster_char_none_ac;
static Autocomplete roster_indent_ac; static Autocomplete roster_indent_ac;
@ -2047,6 +2050,10 @@ cmd_init(void)
autocomplete_add(roster_ac, "char"); autocomplete_add(roster_ac, "char");
autocomplete_add(roster_ac, "indent"); autocomplete_add(roster_ac, "indent");
autocomplete_add(roster_ac, "wrap"); autocomplete_add(roster_ac, "wrap");
autocomplete_add(roster_ac, "resource");
roster_resource_ac = autocomplete_new();
autocomplete_add(roster_resource_ac, "join");
roster_char_ac = autocomplete_new(); roster_char_ac = autocomplete_new();
autocomplete_add(roster_char_ac, "header"); autocomplete_add(roster_char_ac, "header");
@ -2331,6 +2338,7 @@ cmd_uninit(void)
autocomplete_free(close_ac); autocomplete_free(close_ac);
autocomplete_free(wins_ac); autocomplete_free(wins_ac);
autocomplete_free(roster_ac); autocomplete_free(roster_ac);
autocomplete_free(roster_resource_ac);
autocomplete_free(roster_char_ac); autocomplete_free(roster_char_ac);
autocomplete_free(roster_char_none_ac); autocomplete_free(roster_char_none_ac);
autocomplete_free(roster_indent_ac); autocomplete_free(roster_indent_ac);
@ -2521,6 +2529,7 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(close_ac); autocomplete_reset(close_ac);
autocomplete_reset(wins_ac); autocomplete_reset(wins_ac);
autocomplete_reset(roster_ac); autocomplete_reset(roster_ac);
autocomplete_reset(roster_resource_ac);
autocomplete_reset(roster_char_ac); autocomplete_reset(roster_char_ac);
autocomplete_reset(roster_char_none_ac); autocomplete_reset(roster_char_none_ac);
autocomplete_reset(roster_indent_ac); autocomplete_reset(roster_indent_ac);
@ -2912,6 +2921,10 @@ static char*
_roster_autocomplete(ProfWin *window, const char *const input) _roster_autocomplete(ProfWin *window, const char *const input)
{ {
char *result = NULL; char *result = NULL;
result = autocomplete_param_with_func(input, "/roster resource join", prefs_autocomplete_boolean_choice);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/roster char header", roster_char_none_ac, TRUE); result = autocomplete_param_with_ac(input, "/roster char header", roster_char_none_ac, TRUE);
if (result) { if (result) {
return result; return result;
@ -2968,6 +2981,10 @@ _roster_autocomplete(ProfWin *window, const char *const input)
if (result) { if (result) {
return result; return result;
} }
result = autocomplete_param_with_ac(input, "/roster resource", roster_resource_ac, TRUE);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE); result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE);
if (result) { if (result) {
return result; return result;

View File

@ -1761,6 +1761,17 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
return res; return res;
} }
// roster join with previous line
} else if (g_strcmp0(args[0], "resource") == 0) {
if (g_strcmp0(args[1], "join") == 0) {
int res = _cmd_set_boolean_preference(args[2], command, "Roster join", PREF_ROSTER_RESOURCE_JOIN);
rosterwin_roster();
return res;
} else {
cons_bad_cmd_usage(command);
return TRUE;
}
// set header character // set header character
} else if (g_strcmp0(args[0], "char") == 0) { } else if (g_strcmp0(args[0], "char") == 0) {
if (g_strcmp0(args[1], "header") == 0) { if (g_strcmp0(args[1], "header") == 0) {

View File

@ -767,6 +767,7 @@ _get_group(preference_t pref)
case PREF_ROSTER_COUNT: case PREF_ROSTER_COUNT:
case PREF_ROSTER_PRIORITY: case PREF_ROSTER_PRIORITY:
case PREF_ROSTER_WRAP: case PREF_ROSTER_WRAP:
case PREF_ROSTER_RESOURCE_JOIN:
case PREF_RESOURCE_TITLE: case PREF_RESOURCE_TITLE:
case PREF_RESOURCE_MESSAGE: case PREF_RESOURCE_MESSAGE:
case PREF_ENC_WARN: case PREF_ENC_WARN:
@ -952,6 +953,8 @@ _get_key(preference_t pref)
return "roster.priority"; return "roster.priority";
case PREF_ROSTER_WRAP: case PREF_ROSTER_WRAP:
return "roster.wrap"; return "roster.wrap";
case PREF_ROSTER_RESOURCE_JOIN:
return "roster.resource.join";
case PREF_RESOURCE_TITLE: case PREF_RESOURCE_TITLE:
return "resource.title"; return "resource.title";
case PREF_RESOURCE_MESSAGE: case PREF_RESOURCE_MESSAGE:
@ -1005,6 +1008,7 @@ _get_default_boolean(preference_t pref)
case PREF_ROSTER_EMPTY: case PREF_ROSTER_EMPTY:
case PREF_ROSTER_COUNT: case PREF_ROSTER_COUNT:
case PREF_ROSTER_PRIORITY: case PREF_ROSTER_PRIORITY:
case PREF_ROSTER_RESOURCE_JOIN:
case PREF_TLS_SHOW: case PREF_TLS_SHOW:
case PREF_LASTACTIVITY: case PREF_LASTACTIVITY:
return TRUE; return TRUE;

View File

@ -72,6 +72,7 @@ typedef enum {
PREF_ROSTER_COUNT, PREF_ROSTER_COUNT,
PREF_ROSTER_PRIORITY, PREF_ROSTER_PRIORITY,
PREF_ROSTER_WRAP, PREF_ROSTER_WRAP,
PREF_ROSTER_RESOURCE_JOIN,
PREF_MUC_PRIVILEGES, PREF_MUC_PRIVILEGES,
PREF_PRESENCE, PREF_PRESENCE,
PREF_WRAP, PREF_WRAP,

View File

@ -128,45 +128,74 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr
static void static void
_rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent) _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent)
{ {
gboolean join = prefs_get_boolean(PREF_ROSTER_RESOURCE_JOIN);
GList *resources = p_contact_get_available_resources(contact); GList *resources = p_contact_get_available_resources(contact);
if (resources) { if (resources) {
int resource_indent = prefs_get_roster_resource_indent(); if (join && (g_list_length(resources) == 1)) {
if (resource_indent > 0) { Resource *resource = resources->data;
current_indent += resource_indent;
}
GList *curr_resource = resources;
while (curr_resource) {
Resource *resource = curr_resource->data;
const char *resource_presence = string_from_resource_presence(resource->presence); const char *resource_presence = string_from_resource_presence(resource->presence);
theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence);
wattron(layout->subwin, theme_attrs(resource_presence_colour)); wattron(layout->subwin, theme_attrs(resource_presence_colour));
GString *msg = g_string_new(" "); GString *msg = g_string_new("");
int this_indent = current_indent;
while (this_indent > 0) {
g_string_append(msg, " ");
this_indent--;
}
char ch = prefs_get_roster_resource_char(); char ch = prefs_get_roster_resource_char();
if (ch) { if (ch) {
g_string_append_printf(msg, "%c", ch); g_string_append_printf(msg, "%c", ch);
} else {
g_string_append(msg, " ");
} }
g_string_append(msg, resource->name); g_string_append(msg, resource->name);
if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) { if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) {
g_string_append_printf(msg, " %d", resource->priority); g_string_append_printf(msg, " %d", resource->priority);
} }
win_sub_newline_lazy(layout->subwin);
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); win_sub_print(layout->subwin, msg->str, FALSE, wrap, 0);
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
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, resource_presence_colour, resource_presence, resource->status, current_indent); _rosterwin_presence(layout, resource_presence_colour, resource_presence, resource->status, current_indent);
} }
} else {
int resource_indent = prefs_get_roster_resource_indent();
if (resource_indent > 0) {
current_indent += resource_indent;
}
curr_resource = g_list_next(curr_resource); GList *curr_resource = resources;
while (curr_resource) {
Resource *resource = curr_resource->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence);
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--;
}
char ch = prefs_get_roster_resource_char();
if (ch) {
g_string_append_printf(msg, "%c", ch);
}
g_string_append(msg, resource->name);
if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) {
g_string_append_printf(msg, " %d", resource->priority);
}
win_sub_newline_lazy(layout->subwin);
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(resource_presence_colour));
if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
_rosterwin_presence(layout, resource_presence_colour, resource_presence, resource->status, current_indent);
}
curr_resource = g_list_next(curr_resource);
}
} }
} 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)) {
const char *presence = p_contact_presence(contact); const char *presence = p_contact_presence(contact);