From 0c248a0b16e9c159b274667c7149f50299328804 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 18 Apr 2019 20:53:02 +0200 Subject: [PATCH] Add /occupants indent command Roster has a `/roster contact indent` option. Now we have the same for occupants. So contacts in roster and in MUC can have configurable indentation. Regards https://github.com/boothj5/profanity/issues/690 --- src/command/cmd_defs.c | 6 ++++-- src/command/cmd_funcs.c | 32 ++++++++++++++++++++++++++++++++ src/config/preferences.c | 22 ++++++++++++++++++++++ src/config/preferences.h | 2 ++ src/config/theme.c | 5 +++++ src/ui/console.c | 3 +++ src/ui/occupantswin.c | 13 ++++++++++++- 7 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 15d072a4..c1797e3c 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -753,7 +753,8 @@ static struct cmd_t command_defs[] = CMD_SYN( "/occupants show|hide [jid]", "/occupants default show|hide [jid]", - "/occupants size []") + "/occupants size []", + "/occupants indent ") CMD_DESC( "Show or hide room occupants, and occupants panel display settings.") CMD_ARGS( @@ -763,7 +764,8 @@ static struct cmd_t command_defs[] = { "hide jid", "Hide jid in the occupants panel in current room." }, { "default show|hide", "Whether occupants are shown by default in new rooms." }, { "default show|hide jid", "Whether occupants jids are shown by default in new rooms." }, - { "size ", "Percentage of the screen taken by the occupants list in rooms (1-99)." }) + { "size ", "Percentage of the screen taken by the occupants list in rooms (1-99)." }, + { "indent ", "Indent contact line by spaces (0 to 10)." }) CMD_NOEXAMPLES }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index abd83492..788c2f32 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -4409,6 +4409,38 @@ cmd_occupants(ProfWin *window, const char *const command, gchar **args) ProfMucWin *mucwin = (ProfMucWin*)window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + if (g_strcmp0(args[0], "indent") == 0) { + if (!args[1]) { + cons_bad_cmd_usage(command); + return TRUE; + } else { + int intval = 0; + char *err_msg = NULL; + gboolean res = strtoi_range(args[1], &intval, 0, 10, &err_msg); + if (res) { + prefs_set_occupants_indent(intval); + cons_show("Occupants indent set to: %d", intval); + + // get the list of joined rooms + GList *rooms = muc_rooms(); + GList *curr = rooms; + while (curr) { + char* roomjid = curr->data; + ProfMucWin *mw = wins_get_muc(roomjid); + if (mw != NULL) + mucwin_update_occupants(mw); + + curr = g_list_next(curr); + } + } else { + cons_show(err_msg); + free(err_msg); + } + return TRUE; + } + } + + if (g_strcmp0(args[0], "show") == 0) { if (g_strcmp0(args[1], "jid") == 0) { mucwin->showjid = TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index 19d54304..30cd34c2 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -750,6 +750,28 @@ prefs_get_occupants_size(void) } } +gint +prefs_get_occupants_indent(void) +{ + if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "occupants.indent", NULL)) { + return 2; + } + + gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "occupants.indent", NULL); + if (result < 0) { + result = 0; + } + + return result; +} + +void +prefs_set_occupants_indent(gint value) +{ + g_key_file_set_integer(prefs, PREF_GROUP_UI, "occupants.indent", value); + _save_prefs(); +} + void prefs_set_roster_size(gint value) { diff --git a/src/config/preferences.h b/src/config/preferences.h index 614c3f0f..bfd7b3ec 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -246,6 +246,8 @@ gint prefs_get_roster_resource_indent(void); void prefs_set_roster_resource_indent(gint value); gint prefs_get_roster_presence_indent(void); void prefs_set_roster_presence_indent(gint value); +gint prefs_get_occupants_indent(void); +void prefs_set_occupants_indent(gint value); void prefs_add_login(const char *jid); diff --git a/src/config/theme.c b/src/config/theme.c index a94cfb21..4e385ead 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -452,6 +452,11 @@ _load_preferences(void) prefs_set_occupants_size(occupants_size); } + if (g_key_file_has_key(theme, "ui", "occupants.indent", NULL)) { + gint occupants_indent = g_key_file_get_integer(theme, "ui", "occupants.indent", NULL); + prefs_set_occupants_indent(occupants_indent); + } + if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) { gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL); prefs_set_roster_size(roster_size); diff --git a/src/ui/console.c b/src/ui/console.c index f4ba7eba..393caff1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1232,6 +1232,9 @@ cons_occupants_setting(void) else cons_show("Occupant jids (/occupants) : hide"); + gint occupant_indent = prefs_get_occupants_indent(); + cons_show("Occupant indent (/occupants) : %d", occupant_indent); + int size = prefs_get_occupants_size(); cons_show("Occupants size (/occupants) : %d", size); } diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index ca507394..3799046c 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -46,7 +46,18 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean sh theme_item_t presence_colour = theme_main_presence_attrs(presence_str); wattron(layout->subwin, theme_attrs(presence_colour)); - GString *msg = g_string_new(" "); + GString *msg = g_string_new(" "); + + int indent = prefs_get_occupants_indent(); + int current_indent = 0; + if (indent > 0) { + current_indent += indent; + while (indent > 0) { + g_string_append(msg, " "); + indent--; + } + } + g_string_append(msg, occupant->nick); win_sub_print(layout->subwin, msg->str, TRUE, FALSE, 0); g_string_free(msg, TRUE);