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

Added /roster indent contact

This commit is contained in:
James Booth 2015-11-21 21:03:53 +00:00
parent 6935862195
commit 4b022687fa
9 changed files with 202 additions and 129 deletions

View File

@ -280,6 +280,7 @@ static struct cmd_t command_defs[] =
"/roster order name|presence", "/roster order name|presence",
"/roster char header <char>|none", "/roster char header <char>|none",
"/roster char contact <char>|none", "/roster char contact <char>|none",
"/roster indent contact <indent>",
"/roster size <percent>", "/roster size <percent>",
"/roster add <jid> [<nick>]", "/roster add <jid> [<nick>]",
"/roster remove <jid>", "/roster remove <jid>",
@ -316,6 +317,7 @@ static struct cmd_t command_defs[] =
{ "char header none", "Remove roster header character prefix." }, { "char header none", "Remove roster header character prefix." },
{ "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." },
{ "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." },
@ -1784,6 +1786,7 @@ static Autocomplete wins_ac;
static Autocomplete roster_ac; static Autocomplete roster_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_option_ac; static Autocomplete roster_option_ac;
static Autocomplete roster_by_ac; static Autocomplete roster_by_ac;
static Autocomplete roster_order_ac; static Autocomplete roster_order_ac;
@ -2033,6 +2036,7 @@ cmd_init(void)
autocomplete_add(roster_ac, "order"); autocomplete_add(roster_ac, "order");
autocomplete_add(roster_ac, "size"); autocomplete_add(roster_ac, "size");
autocomplete_add(roster_ac, "char"); autocomplete_add(roster_ac, "char");
autocomplete_add(roster_ac, "indent");
roster_char_ac = autocomplete_new(); roster_char_ac = autocomplete_new();
autocomplete_add(roster_char_ac, "header"); autocomplete_add(roster_char_ac, "header");
@ -2041,6 +2045,9 @@ cmd_init(void)
roster_char_none_ac = autocomplete_new(); roster_char_none_ac = autocomplete_new();
autocomplete_add(roster_char_none_ac, "none"); autocomplete_add(roster_char_none_ac, "none");
roster_indent_ac = autocomplete_new();
autocomplete_add(roster_indent_ac, "contact");
roster_option_ac = autocomplete_new(); roster_option_ac = autocomplete_new();
autocomplete_add(roster_option_ac, "offline"); autocomplete_add(roster_option_ac, "offline");
autocomplete_add(roster_option_ac, "resource"); autocomplete_add(roster_option_ac, "resource");
@ -2313,6 +2320,7 @@ cmd_uninit(void)
autocomplete_free(roster_ac); autocomplete_free(roster_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_option_ac); autocomplete_free(roster_option_ac);
autocomplete_free(roster_by_ac); autocomplete_free(roster_by_ac);
autocomplete_free(roster_order_ac); autocomplete_free(roster_order_ac);
@ -2502,6 +2510,7 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(roster_ac); autocomplete_reset(roster_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_option_ac); autocomplete_reset(roster_option_ac);
autocomplete_reset(roster_by_ac); autocomplete_reset(roster_by_ac);
autocomplete_reset(roster_order_ac); autocomplete_reset(roster_order_ac);
@ -2934,6 +2943,10 @@ _roster_autocomplete(ProfWin *window, const char *const input)
if (result) { if (result) {
return result; return result;
} }
result = autocomplete_param_with_ac(input, "/roster indent", roster_indent_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

@ -1781,6 +1781,29 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
} }
return TRUE; return TRUE;
// set indentations
} else if (g_strcmp0(args[0], "indent") == 0) {
if (g_strcmp0(args[1], "contact") == 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_contact_indent(intval);
cons_show("Roster contact indent set to: %d", intval);
rosterwin_roster();
} else {
cons_show(err_msg);
free(err_msg);
}
}
} else {
cons_bad_cmd_usage(command);
}
return TRUE;
// show/hide roster // show/hide roster
} else if (g_strcmp0(args[0], "show") == 0) { } else if (g_strcmp0(args[0], "show") == 0) {
if (args[1] == NULL) { if (args[1] == NULL) {

View File

@ -506,6 +506,28 @@ prefs_clear_roster_contact_char(void)
_save_prefs(); _save_prefs();
} }
gint
prefs_get_roster_contact_indent(void)
{
if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "roster.contact.indent", NULL)) {
return 2;
}
gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.contact.indent", NULL);
if (result < 0) {
result = 0;
}
return result;
}
void
prefs_set_roster_contact_indent(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.contact.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

@ -172,6 +172,9 @@ char prefs_get_roster_contact_char(void);
void prefs_set_roster_contact_char(char ch); void prefs_set_roster_contact_char(char ch);
void prefs_clear_roster_contact_char(void); void prefs_clear_roster_contact_char(void);
gint prefs_get_roster_contact_indent(void);
void prefs_set_roster_contact_indent(gint value);
void prefs_add_login(const char *jid); void prefs_add_login(const char *jid);
gboolean prefs_add_alias(const char *const name, const char *const value); gboolean prefs_add_alias(const char *const name, const char *const value);

View File

@ -1254,6 +1254,9 @@ cons_roster_setting(void)
cons_show("Roster contact char (/roster) : %c", contact_ch); cons_show("Roster contact char (/roster) : %c", contact_ch);
else else
cons_show("Roster contact char (/roster) : none"); cons_show("Roster contact char (/roster) : none");
gint contact_indent = prefs_get_roster_contact_indent();
cons_show("Roster contact indent (/roster) : %d", contact_indent);
} }
void void

View File

@ -48,13 +48,13 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean sh
GString *msg = g_string_new(" "); GString *msg = g_string_new(" ");
g_string_append(msg, occupant->nick); g_string_append(msg, occupant->nick);
win_printline_nowrap(layout->subwin, msg->str); win_print_nowrap(layout->subwin, msg->str, TRUE);
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
if (showjid && occupant->jid) { if (showjid && occupant->jid) {
GString *msg = g_string_new(" "); GString *msg = g_string_new(" ");
g_string_append(msg, occupant->jid); g_string_append(msg, occupant->jid);
win_printline_nowrap(layout->subwin, msg->str); win_print_nowrap(layout->subwin, msg->str, TRUE);
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
} }
@ -75,7 +75,7 @@ occupantswin_occupants(const char *const roomjid)
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
win_printline_nowrap(layout->subwin, " -Moderators"); win_print_nowrap(layout->subwin, " -Moderators", TRUE);
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
GList *roster_curr = occupants; GList *roster_curr = occupants;
while (roster_curr) { while (roster_curr) {
@ -87,7 +87,7 @@ occupantswin_occupants(const char *const roomjid)
} }
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
win_printline_nowrap(layout->subwin, " -Participants"); win_print_nowrap(layout->subwin, " -Participants", TRUE);
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
roster_curr = occupants; roster_curr = occupants;
while (roster_curr) { while (roster_curr) {
@ -99,7 +99,7 @@ occupantswin_occupants(const char *const roomjid)
} }
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
win_printline_nowrap(layout->subwin, " -Visitors"); win_print_nowrap(layout->subwin, " -Visitors", TRUE);
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
roster_curr = occupants; roster_curr = occupants;
while (roster_curr) { while (roster_curr) {
@ -111,7 +111,7 @@ occupantswin_occupants(const char *const roomjid)
} }
} else { } else {
wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
win_printline_nowrap(layout->subwin, " -Occupants\n"); win_print_nowrap(layout->subwin, " -Occupants\n", TRUE);
wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER));
GList *roster_curr = occupants; GList *roster_curr = occupants;
while (roster_curr) { while (roster_curr) {

View File

@ -64,7 +64,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co
indent--; indent--;
} }
g_string_append_printf(msg, "\"%s\"", status); g_string_append_printf(msg, "\"%s\"", status);
win_printline_nowrap(layout->subwin, msg->str); win_print_nowrap(layout->subwin, msg->str, TRUE);
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(colour)); wattroff(layout->subwin, theme_attrs(colour));
} }
@ -85,7 +85,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co
} else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
g_string_append_printf(msg, "\"%s\"", status); g_string_append_printf(msg, "\"%s\"", status);
} }
win_printline_nowrap(layout->subwin, msg->str); win_print_nowrap(layout->subwin, msg->str, TRUE);
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(colour)); wattroff(layout->subwin, theme_attrs(colour));
} }
@ -108,7 +108,7 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact)
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_printline_nowrap(layout->subwin, msg->str); win_print_nowrap(layout->subwin, msg->str, TRUE);
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));
@ -139,12 +139,19 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact)
wattron(layout->subwin, theme_attrs(presence_colour)); wattron(layout->subwin, theme_attrs(presence_colour));
GString *msg = g_string_new(" "); GString *msg = g_string_new(" ");
int indent = prefs_get_roster_contact_indent();
if (indent > 0) {
while (indent > 0) {
g_string_append(msg, " ");
indent--;
}
}
char ch = prefs_get_roster_contact_char(); char ch = prefs_get_roster_contact_char();
if (ch) { if (ch) {
g_string_append_printf(msg, "%c", ch); g_string_append_printf(msg, "%c", ch);
} }
g_string_append(msg, name); g_string_append(msg, name);
win_printline_nowrap(layout->subwin, msg->str); win_print_nowrap(layout->subwin, msg->str, TRUE);
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(presence_colour)); wattroff(layout->subwin, theme_attrs(presence_colour));
@ -172,7 +179,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese
if (prefs_get_boolean(PREF_ROSTER_COUNT)) { if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title_str, " (%d)", g_slist_length(contacts)); g_string_append_printf(title_str, " (%d)", g_slist_length(contacts));
} }
win_printline_nowrap(layout->subwin, title_str->str); win_print_nowrap(layout->subwin, title_str->str, TRUE);
g_string_free(title_str, TRUE); g_string_free(title_str, TRUE);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
} }
@ -212,7 +219,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
if (prefs_get_boolean(PREF_ROSTER_COUNT)) { if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title, " (%d)", g_slist_length(contacts)); g_string_append_printf(title, " (%d)", g_slist_length(contacts));
} }
win_printline_nowrap(layout->subwin, title->str); win_print_nowrap(layout->subwin, title->str, TRUE);
g_string_free(title, TRUE); g_string_free(title, TRUE);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
@ -251,7 +258,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
if (prefs_get_boolean(PREF_ROSTER_COUNT)) { if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title, " (%d)", g_slist_length(contacts)); g_string_append_printf(title, " (%d)", g_slist_length(contacts));
} }
win_printline_nowrap(layout->subwin, title->str); win_print_nowrap(layout->subwin, title->str, TRUE);
g_string_free(title, TRUE); g_string_free(title, TRUE);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
@ -317,7 +324,7 @@ rosterwin_roster(void)
if (prefs_get_boolean(PREF_ROSTER_COUNT)) { if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
g_string_append_printf(title, " (%d)", g_slist_length(contacts)); g_string_append_printf(title, " (%d)", g_slist_length(contacts));
} }
win_printline_nowrap(layout->subwin, title->str); win_print_nowrap(layout->subwin, title->str, TRUE);
g_string_free(title, TRUE); g_string_free(title, TRUE);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));

View File

@ -1266,12 +1266,14 @@ win_unread(ProfWin *window)
} }
void void
win_printline_nowrap(WINDOW *win, char *msg) win_print_nowrap(WINDOW *win, char *msg, gboolean newline)
{ {
int maxx = getmaxx(win); int maxx = getmaxx(win);
int cury = getcury(win); int cury = getcury(win);
waddnstr(win, msg, maxx); waddnstr(win, msg, maxx);
if (newline) {
wmove(win, cury+1, 0); wmove(win, cury+1, 0);
}
} }

View File

@ -67,7 +67,7 @@ void win_newline(ProfWin *window);
void win_redraw(ProfWin *window); void win_redraw(ProfWin *window);
int win_roster_cols(void); int win_roster_cols(void);
int win_occpuants_cols(void); int win_occpuants_cols(void);
void win_printline_nowrap(WINDOW *win, char *msg); void win_print_nowrap(WINDOW *win, char *msg, gboolean newline);
void win_mark_received(ProfWin *window, const char *const id); void win_mark_received(ProfWin *window, const char *const id);
gboolean win_has_active_subwin(ProfWin *window); gboolean win_has_active_subwin(ProfWin *window);