From 4b022687fa4a47ecaca6a2002ff435c769007456 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 21 Nov 2015 21:03:53 +0000 Subject: [PATCH 1/9] Added /roster indent contact --- src/command/command.c | 77 +++++++++++-------- src/command/commands.c | 23 ++++++ src/config/preferences.c | 22 ++++++ src/config/preferences.h | 3 + src/ui/console.c | 161 ++++++++++++++++++++------------------- src/ui/occupantswin.c | 12 +-- src/ui/rosterwin.c | 25 +++--- src/ui/window.c | 6 +- src/ui/window.h | 2 +- 9 files changed, 202 insertions(+), 129 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 471fcd29..47cc7d9b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -280,6 +280,7 @@ static struct cmd_t command_defs[] = "/roster order name|presence", "/roster char header |none", "/roster char contact |none", + "/roster indent contact ", "/roster size ", "/roster add []", "/roster remove ", @@ -290,38 +291,39 @@ static struct cmd_t command_defs[] = "Manage your roster, and roster display settings. " "Passing no arguments lists all contacts in your roster.") CMD_ARGS( - { "online", "Show all online contacts in your roster." }, - { "show", "Show the roster panel." }, - { "show offline", "Show offline contacts in the roster panel." }, - { "show resource", "Show contact's connected resources in the roster panel." }, - { "show presence", "Show contact's presence in the roster panel." }, - { "show status", "Show contact's status message in the roster panel." }, - { "show empty", "When grouping by presence, show empty presence groups." }, - { "show count", "Show number of contacts in group/presence." }, - { "show priority", "Show resource priority." }, - { "hide", "Hide the roster panel." }, - { "hide offline", "Hide offline contacts in the roster panel." }, - { "hide resource", "Hide contact's connected resources in the roster panel." }, - { "hide presence", "Hide contact's presence in the roster panel." }, - { "hide status", "Hide contact's status message in the roster panel." }, - { "hide empty", "When grouping by presence, hide empty presence groups." }, - { "hide count", "Hide number of contacts in group/presence." }, - { "hide priority", "Hide resource priority." }, - { "by group", "Group contacts in the roster panel by roster group." }, - { "by presence", "Group contacts in the roster panel by presence." }, - { "by none", "No grouping in the roster panel." }, - { "order name", "Order roster items by name only." }, - { "order presence", "Order roster items by presence, and then by name." }, - { "char header ", "Prefix roster headers with specificed character." }, - { "char header none", "Remove roster header character prefix." }, - { "char contact ", "Prefix roster contacts with specificed character." }, - { "char contact none", "Remove roster contact character prefix." }, - { "size ", "Percentage of the screen taken up by the roster (1-99)." }, - { "add []", "Add a new item to the roster." }, - { "remove ", "Removes an item from the roster." }, - { "remove_all contacts", "Remove all items from roster." }, - { "nick ", "Change a contacts nickname." }, - { "clearnick ", "Removes the current nickname." }) + { "online", "Show all online contacts in your roster." }, + { "show", "Show the roster panel." }, + { "show offline", "Show offline contacts in the roster panel." }, + { "show resource", "Show contact's connected resources in the roster panel." }, + { "show presence", "Show contact's presence in the roster panel." }, + { "show status", "Show contact's status message in the roster panel." }, + { "show empty", "When grouping by presence, show empty presence groups." }, + { "show count", "Show number of contacts in group/presence." }, + { "show priority", "Show resource priority." }, + { "hide", "Hide the roster panel." }, + { "hide offline", "Hide offline contacts in the roster panel." }, + { "hide resource", "Hide contact's connected resources in the roster panel." }, + { "hide presence", "Hide contact's presence in the roster panel." }, + { "hide status", "Hide contact's status message in the roster panel." }, + { "hide empty", "When grouping by presence, hide empty presence groups." }, + { "hide count", "Hide number of contacts in group/presence." }, + { "hide priority", "Hide resource priority." }, + { "by group", "Group contacts in the roster panel by roster group." }, + { "by presence", "Group contacts in the roster panel by presence." }, + { "by none", "No grouping in the roster panel." }, + { "order name", "Order roster items by name only." }, + { "order presence", "Order roster items by presence, and then by name." }, + { "char header ", "Prefix roster headers with specificed character." }, + { "char header none", "Remove roster header character prefix." }, + { "char contact ", "Prefix roster contacts with specificed character." }, + { "char contact none", "Remove roster contact character prefix." }, + { "indent contact ", "Indent contact line by spaces." }, + { "size ", "Percentage of the screen taken up by the roster (1-99)." }, + { "add []", "Add a new item to the roster." }, + { "remove ", "Removes an item from the roster." }, + { "remove_all contacts", "Remove all items from roster." }, + { "nick ", "Change a contacts nickname." }, + { "clearnick ", "Removes the current nickname." }) CMD_EXAMPLES( "/roster", "/roster add someone@contacts.org", @@ -1784,6 +1786,7 @@ static Autocomplete wins_ac; static Autocomplete roster_ac; static Autocomplete roster_char_ac; static Autocomplete roster_char_none_ac; +static Autocomplete roster_indent_ac; static Autocomplete roster_option_ac; static Autocomplete roster_by_ac; static Autocomplete roster_order_ac; @@ -2033,6 +2036,7 @@ cmd_init(void) autocomplete_add(roster_ac, "order"); autocomplete_add(roster_ac, "size"); autocomplete_add(roster_ac, "char"); + autocomplete_add(roster_ac, "indent"); roster_char_ac = autocomplete_new(); autocomplete_add(roster_char_ac, "header"); @@ -2041,6 +2045,9 @@ cmd_init(void) roster_char_none_ac = autocomplete_new(); autocomplete_add(roster_char_none_ac, "none"); + roster_indent_ac = autocomplete_new(); + autocomplete_add(roster_indent_ac, "contact"); + roster_option_ac = autocomplete_new(); autocomplete_add(roster_option_ac, "offline"); autocomplete_add(roster_option_ac, "resource"); @@ -2313,6 +2320,7 @@ cmd_uninit(void) autocomplete_free(roster_ac); autocomplete_free(roster_char_ac); autocomplete_free(roster_char_none_ac); + autocomplete_free(roster_indent_ac); autocomplete_free(roster_option_ac); autocomplete_free(roster_by_ac); autocomplete_free(roster_order_ac); @@ -2502,6 +2510,7 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(roster_ac); autocomplete_reset(roster_char_ac); autocomplete_reset(roster_char_none_ac); + autocomplete_reset(roster_indent_ac); autocomplete_reset(roster_option_ac); autocomplete_reset(roster_by_ac); autocomplete_reset(roster_order_ac); @@ -2934,6 +2943,10 @@ _roster_autocomplete(ProfWin *window, const char *const input) if (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); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index ca6a1003..37c54131 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1781,6 +1781,29 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) } 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 } else if (g_strcmp0(args[0], "show") == 0) { if (args[1] == NULL) { diff --git a/src/config/preferences.c b/src/config/preferences.c index 414de9f4..0916cf86 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -506,6 +506,28 @@ prefs_clear_roster_contact_char(void) _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 prefs_add_alias(const char *const name, const char *const value) { diff --git a/src/config/preferences.h b/src/config/preferences.h index da4eef88..374f6947 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -172,6 +172,9 @@ char prefs_get_roster_contact_char(void); void prefs_set_roster_contact_char(char ch); 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); gboolean prefs_add_alias(const char *const name, const char *const value); diff --git a/src/ui/console.c b/src/ui/console.c index ac63005e..0b9e18c4 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -960,9 +960,9 @@ cons_theme_setting(void) { char *theme = prefs_get_string(PREF_THEME); if (theme == NULL) { - cons_show("Theme (/theme) : default"); + cons_show("Theme (/theme) : default"); } else { - cons_show("Theme (/theme) : %s", theme); + cons_show("Theme (/theme) : %s", theme); } prefs_free_string(theme); } @@ -971,58 +971,58 @@ void cons_privileges_setting(void) { if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) - cons_show("MUC privileges (/privileges) : ON"); + cons_show("MUC privileges (/privileges) : ON"); else - cons_show("MUC privileges (/privileges) : OFF"); + cons_show("MUC privileges (/privileges) : OFF"); } void cons_beep_setting(void) { if (prefs_get_boolean(PREF_BEEP)) - cons_show("Terminal beep (/beep) : ON"); + cons_show("Terminal beep (/beep) : ON"); else - cons_show("Terminal beep (/beep) : OFF"); + cons_show("Terminal beep (/beep) : OFF"); } void cons_resource_setting(void) { if (prefs_get_boolean(PREF_RESOURCE_TITLE)) - cons_show("Resource title (/resource) : ON"); + cons_show("Resource title (/resource) : ON"); else - cons_show("Resource title (/resource) : OFF"); + cons_show("Resource title (/resource) : OFF"); if (prefs_get_boolean(PREF_RESOURCE_MESSAGE)) - cons_show("Resource message (/resource) : ON"); + cons_show("Resource message (/resource) : ON"); else - cons_show("Resource message (/resource) : OFF"); + cons_show("Resource message (/resource) : OFF"); } void cons_wrap_setting(void) { if (prefs_get_boolean(PREF_WRAP)) - cons_show("Word wrap (/wrap) : ON"); + cons_show("Word wrap (/wrap) : ON"); else - cons_show("Word wrap (/wrap) : OFF"); + cons_show("Word wrap (/wrap) : OFF"); } void cons_winstidy_setting(void) { if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) - cons_show("Window Auto Tidy (/wins) : ON"); + cons_show("Window Auto Tidy (/wins) : ON"); else - cons_show("Window Auto Tidy (/wins) : OFF"); + cons_show("Window Auto Tidy (/wins) : OFF"); } void cons_encwarn_setting(void) { if (prefs_get_boolean(PREF_ENC_WARN)) { - cons_show("Warn unencrypted (/encwarn) : ON"); + cons_show("Warn unencrypted (/encwarn) : ON"); } else { - cons_show("Warn unencrypted (/encwarn) : OFF"); + cons_show("Warn unencrypted (/encwarn) : OFF"); } } @@ -1030,9 +1030,9 @@ void cons_tlsshow_setting(void) { if (prefs_get_boolean(PREF_TLS_SHOW)) { - cons_show("TLS show (/tls) : ON"); + cons_show("TLS show (/tls) : ON"); } else { - cons_show("TLS show (/tls) : OFF"); + cons_show("TLS show (/tls) : OFF"); } } @@ -1040,44 +1040,44 @@ void cons_presence_setting(void) { if (prefs_get_boolean(PREF_PRESENCE)) - cons_show("Contact presence (/presence) : ON"); + cons_show("Contact presence (/presence) : ON"); else - cons_show("Contact presence (/presence) : OFF"); + cons_show("Contact presence (/presence) : OFF"); } void cons_flash_setting(void) { if (prefs_get_boolean(PREF_FLASH)) - cons_show("Terminal flash (/flash) : ON"); + cons_show("Terminal flash (/flash) : ON"); else - cons_show("Terminal flash (/flash) : OFF"); + cons_show("Terminal flash (/flash) : OFF"); } void cons_splash_setting(void) { if (prefs_get_boolean(PREF_SPLASH)) - cons_show("Splash screen (/splash) : ON"); + cons_show("Splash screen (/splash) : ON"); else - cons_show("Splash screen (/splash) : OFF"); + cons_show("Splash screen (/splash) : OFF"); } void cons_occupants_setting(void) { if (prefs_get_boolean(PREF_OCCUPANTS)) - cons_show("Occupants (/occupants) : show"); + cons_show("Occupants (/occupants) : show"); else - cons_show("Occupants (/occupants) : hide"); + cons_show("Occupants (/occupants) : hide"); if (prefs_get_boolean(PREF_OCCUPANTS_JID)) - cons_show("Occupant jids (/occupants) : show"); + cons_show("Occupant jids (/occupants) : show"); else - cons_show("Occupant jids (/occupants) : hide"); + cons_show("Occupant jids (/occupants) : hide"); int size = prefs_get_occupants_size(); - cons_show("Occupants size (/occupants) : %d", size); + cons_show("Occupants size (/occupants) : %d", size); } void @@ -1097,55 +1097,55 @@ cons_time_setting(void) { char *pref_time_console = prefs_get_string(PREF_TIME_CONSOLE); if (g_strcmp0(pref_time_console, "off") == 0) - cons_show("Time console (/time) : OFF"); + cons_show("Time console (/time) : OFF"); else - cons_show("Time console (/time) : %s", pref_time_console); + cons_show("Time console (/time) : %s", pref_time_console); prefs_free_string(pref_time_console); char *pref_time_chat = prefs_get_string(PREF_TIME_CHAT); if (g_strcmp0(pref_time_chat, "off") == 0) - cons_show("Time chat (/time) : OFF"); + cons_show("Time chat (/time) : OFF"); else - cons_show("Time chat (/time) : %s", pref_time_chat); + cons_show("Time chat (/time) : %s", pref_time_chat); prefs_free_string(pref_time_chat); char *pref_time_muc = prefs_get_string(PREF_TIME_MUC); if (g_strcmp0(pref_time_muc, "off") == 0) - cons_show("Time MUC (/time) : OFF"); + cons_show("Time MUC (/time) : OFF"); else - cons_show("Time MUC (/time) : %s", pref_time_muc); + cons_show("Time MUC (/time) : %s", pref_time_muc); prefs_free_string(pref_time_muc); char *pref_time_mucconf = prefs_get_string(PREF_TIME_MUCCONFIG); if (g_strcmp0(pref_time_mucconf, "off") == 0) - cons_show("Time MUC config (/time) : OFF"); + cons_show("Time MUC config (/time) : OFF"); else - cons_show("Time MUC config (/time) : %s", pref_time_mucconf); + cons_show("Time MUC config (/time) : %s", pref_time_mucconf); prefs_free_string(pref_time_mucconf); char *pref_time_private = prefs_get_string(PREF_TIME_PRIVATE); if (g_strcmp0(pref_time_private, "off") == 0) - cons_show("Time private (/time) : OFF"); + cons_show("Time private (/time) : OFF"); else - cons_show("Time private (/time) : %s", pref_time_private); + cons_show("Time private (/time) : %s", pref_time_private); prefs_free_string(pref_time_private); char *pref_time_xml = prefs_get_string(PREF_TIME_XMLCONSOLE); if (g_strcmp0(pref_time_xml, "off") == 0) - cons_show("Time XML Console (/time) : OFF"); + cons_show("Time XML Console (/time) : OFF"); else - cons_show("Time XML Console (/time) : %s", pref_time_xml); + cons_show("Time XML Console (/time) : %s", pref_time_xml); prefs_free_string(pref_time_xml); char *pref_time_statusbar = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(pref_time_statusbar, "off") == 0) - cons_show("Time statusbar (/time) : OFF"); + cons_show("Time statusbar (/time) : OFF"); else - cons_show("Time statusbar (/time) : %s", pref_time_statusbar); + cons_show("Time statusbar (/time) : %s", pref_time_statusbar); prefs_free_string(pref_time_statusbar); char *pref_time_lastactivity = prefs_get_string(PREF_TIME_LASTACTIVITY); - cons_show("Time last activity (/time) : %s", pref_time_lastactivity); + cons_show("Time last activity (/time) : %s", pref_time_lastactivity); prefs_free_string(pref_time_lastactivity); } @@ -1153,9 +1153,9 @@ void cons_vercheck_setting(void) { if (prefs_get_boolean(PREF_VERCHECK)) - cons_show("Version checking (/vercheck) : ON"); + cons_show("Version checking (/vercheck) : ON"); else - cons_show("Version checking (/vercheck) : OFF"); + cons_show("Version checking (/vercheck) : OFF"); } void @@ -1165,9 +1165,9 @@ cons_statuses_setting(void) char *chat = prefs_get_string(PREF_STATUSES_CHAT); char *muc = prefs_get_string(PREF_STATUSES_MUC); - cons_show("Console statuses (/statuses) : %s", console); - cons_show("Chat statuses (/statuses) : %s", chat); - cons_show("MUC statuses (/statuses) : %s", muc); + cons_show("Console statuses (/statuses) : %s", console); + cons_show("Chat statuses (/statuses) : %s", chat); + cons_show("MUC statuses (/statuses) : %s", muc); prefs_free_string(console); prefs_free_string(chat); @@ -1178,14 +1178,14 @@ void cons_titlebar_setting(void) { if (prefs_get_boolean(PREF_TITLEBAR_SHOW)) { - cons_show("Titlebar show (/titlebar) : ON"); + cons_show("Titlebar show (/titlebar) : ON"); } else { - cons_show("Titlebar show (/titlebar) : OFF"); + cons_show("Titlebar show (/titlebar) : OFF"); } if (prefs_get_boolean(PREF_TITLEBAR_GOODBYE)) { - cons_show("Titlebar goodbye (/titlebar) : ON"); + cons_show("Titlebar goodbye (/titlebar) : ON"); } else { - cons_show("Titlebar goodbye (/titlebar) : OFF"); + cons_show("Titlebar goodbye (/titlebar) : OFF"); } } @@ -1193,67 +1193,70 @@ void cons_roster_setting(void) { if (prefs_get_boolean(PREF_ROSTER)) - cons_show("Roster (/roster) : show"); + cons_show("Roster (/roster) : show"); else - cons_show("Roster (/roster) : hide"); + cons_show("Roster (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) - cons_show("Roster offline (/roster) : show"); + cons_show("Roster offline (/roster) : show"); else - cons_show("Roster offline (/roster) : hide"); + cons_show("Roster offline (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) - cons_show("Roster resource (/roster) : show"); + cons_show("Roster resource (/roster) : show"); else - cons_show("Roster resource (/roster) : hide"); + cons_show("Roster resource (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) - cons_show("Roster presence (/roster) : show"); + cons_show("Roster presence (/roster) : show"); else - cons_show("Roster presence (/roster) : hide"); + cons_show("Roster presence (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_STATUS)) - cons_show("Roster status (/roster) : show"); + cons_show("Roster status (/roster) : show"); else - cons_show("Roster status (/roster) : hide"); + cons_show("Roster status (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_EMPTY)) - cons_show("Roster empty (/roster) : show"); + cons_show("Roster empty (/roster) : show"); else - cons_show("Roster empty (/roster) : hide"); + cons_show("Roster empty (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_COUNT)) - cons_show("Roster count (/roster) : show"); + cons_show("Roster count (/roster) : show"); else - cons_show("Roster count (/roster) : hide"); + cons_show("Roster count (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) - cons_show("Roster priority (/roster) : show"); + cons_show("Roster priority (/roster) : show"); else - cons_show("Roster priority (/roster) : hide"); + cons_show("Roster priority (/roster) : hide"); char *by = prefs_get_string(PREF_ROSTER_BY); - cons_show("Roster by (/roster) : %s", by); + cons_show("Roster by (/roster) : %s", by); prefs_free_string(by); char *order = prefs_get_string(PREF_ROSTER_ORDER); - cons_show("Roster order (/roster) : %s", order); + cons_show("Roster order (/roster) : %s", order); prefs_free_string(order); int size = prefs_get_roster_size(); - cons_show("Roster size (/roster) : %d", size); + cons_show("Roster size (/roster) : %d", size); char header_ch = prefs_get_roster_header_char(); if (header_ch) - cons_show("Roster header char (/roster) : %c", header_ch); + cons_show("Roster header char (/roster) : %c", header_ch); else - cons_show("Roster header char (/roster) : none"); + cons_show("Roster header char (/roster) : none"); char contact_ch = prefs_get_roster_contact_char(); if (contact_ch) - cons_show("Roster contact char (/roster) : %c", contact_ch); + cons_show("Roster contact char (/roster) : %c", contact_ch); 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 @@ -1457,11 +1460,11 @@ cons_show_chat_prefs(void) void cons_inpblock_setting(void) { - cons_show("Input timeout (/inpblock) : %d milliseconds", prefs_get_inpblock()); + cons_show("Input timeout (/inpblock) : %d milliseconds", prefs_get_inpblock()); if (prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) { - cons_show("Dynamic timeout (/inpblock) : ON"); + cons_show("Dynamic timeout (/inpblock) : ON"); } else { - cons_show("Dynamic timeout (/inpblock) : OFF"); + cons_show("Dynamic timeout (/inpblock) : OFF"); } } diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index 36447437..71474a80 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -48,13 +48,13 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean sh GString *msg = g_string_new(" "); 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); if (showjid && occupant->jid) { GString *msg = g_string_new(" "); 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); } @@ -75,7 +75,7 @@ occupantswin_occupants(const char *const roomjid) if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { 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)); GList *roster_curr = occupants; while (roster_curr) { @@ -87,7 +87,7 @@ occupantswin_occupants(const char *const roomjid) } 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)); roster_curr = occupants; while (roster_curr) { @@ -99,7 +99,7 @@ occupantswin_occupants(const char *const roomjid) } 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)); roster_curr = occupants; while (roster_curr) { @@ -111,7 +111,7 @@ occupantswin_occupants(const char *const roomjid) } } else { 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)); GList *roster_curr = occupants; while (roster_curr) { diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index f13f5dc5..0dc1baed 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -64,7 +64,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co indent--; } 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); 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)) { 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); wattroff(layout->subwin, theme_attrs(colour)); } @@ -108,7 +108,7 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact) if (prefs_get_boolean(PREF_ROSTER_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); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); @@ -138,13 +138,20 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) theme_item_t presence_colour = theme_main_presence_attrs(presence); 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(); if (ch) { g_string_append_printf(msg, "%c", ch); } 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); 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)) { 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); 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)) { 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); 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)) { 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); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -317,7 +324,7 @@ rosterwin_roster(void) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { 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); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); diff --git a/src/ui/window.c b/src/ui/window.c index 91e8b6c2..3ca9b927 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1266,12 +1266,14 @@ win_unread(ProfWin *window) } void -win_printline_nowrap(WINDOW *win, char *msg) +win_print_nowrap(WINDOW *win, char *msg, gboolean newline) { int maxx = getmaxx(win); int cury = getcury(win); waddnstr(win, msg, maxx); - wmove(win, cury+1, 0); + if (newline) { + wmove(win, cury+1, 0); + } } diff --git a/src/ui/window.h b/src/ui/window.h index 643cdf7b..24d71ad6 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -67,7 +67,7 @@ void win_newline(ProfWin *window); void win_redraw(ProfWin *window); int win_roster_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); gboolean win_has_active_subwin(ProfWin *window); From b73ff08a72ceb3f3ffe15fd9222d8fa56c35f01c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 21 Nov 2015 21:19:28 +0000 Subject: [PATCH 2/9] Free pref strings --- src/command/commands.c | 32 ++++++++++++++++++++++++-------- src/ui/rosterwin.c | 8 ++++++-- src/xmpp/connection.c | 1 + 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 37c54131..7a97625a 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3848,7 +3848,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) { if (g_strcmp0(args[0], "lastactivity") == 0) { if (args[1] == NULL) { - cons_show("Last activity time format: '%s'.", prefs_get_string(PREF_TIME_LASTACTIVITY)); + char *format = prefs_get_string(PREF_TIME_LASTACTIVITY); + cons_show("Last activity time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_LASTACTIVITY, args[2]); @@ -3865,7 +3867,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) } } else if (g_strcmp0(args[0], "statusbar") == 0) { if (args[1] == NULL) { - cons_show("Status bar time format: '%s'.", prefs_get_string(PREF_TIME_STATUSBAR)); + char *format = prefs_get_string(PREF_TIME_STATUSBAR); + cons_show("Status bar time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_STATUSBAR, args[2]); @@ -3883,7 +3887,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) } } else if (g_strcmp0(args[0], "console") == 0) { if (args[1] == NULL) { - cons_show("Console time format: '%s'.", prefs_get_string(PREF_TIME_CONSOLE)); + char *format = prefs_get_string(PREF_TIME_CONSOLE); + cons_show("Console time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_CONSOLE, args[2]); @@ -3901,7 +3907,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) } } else if (g_strcmp0(args[0], "chat") == 0) { if (args[1] == NULL) { - cons_show("Chat time format: '%s'.", prefs_get_string(PREF_TIME_CHAT)); + char *format = prefs_get_string(PREF_TIME_CHAT); + cons_show("Chat time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_CHAT, args[2]); @@ -3919,7 +3927,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) } } else if (g_strcmp0(args[0], "muc") == 0) { if (args[1] == NULL) { - cons_show("MUC time format: '%s'.", prefs_get_string(PREF_TIME_MUC)); + char *format = prefs_get_string(PREF_TIME_MUC); + cons_show("MUC time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_MUC, args[2]); @@ -3937,7 +3947,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) } } else if (g_strcmp0(args[0], "mucconfig") == 0) { if (args[1] == NULL) { - cons_show("MUC config time format: '%s'.", prefs_get_string(PREF_TIME_MUCCONFIG)); + char *format = prefs_get_string(PREF_TIME_MUCCONFIG); + cons_show("MUC config time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_MUCCONFIG, args[2]); @@ -3955,7 +3967,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) } } else if (g_strcmp0(args[0], "private") == 0) { if (args[1] == NULL) { - cons_show("Private chat time format: '%s'.", prefs_get_string(PREF_TIME_PRIVATE)); + char *format = prefs_get_string(PREF_TIME_PRIVATE); + cons_show("Private chat time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_PRIVATE, args[2]); @@ -3973,7 +3987,9 @@ cmd_time(ProfWin *window, const char *const command, gchar **args) } } else if (g_strcmp0(args[0], "xml") == 0) { if (args[1] == NULL) { - cons_show("XML Console time format: '%s'.", prefs_get_string(PREF_TIME_XMLCONSOLE)); + char *format = prefs_get_string(PREF_TIME_XMLCONSOLE); + cons_show("XML Console time format: '%s'.", format); + prefs_free_string(format); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_XMLCONSOLE, args[2]); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 0dc1baed..c2267437 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -53,6 +53,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co char *by = prefs_get_string(PREF_ROSTER_BY); gboolean by_presence = g_strcmp0(by, "presence") == 0; + prefs_free_string(by); // show only status when grouped by presence if (by_presence) { @@ -207,6 +208,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) } else { contacts = roster_get_group(group, ROSTER_ORD_NAME, offline); } + prefs_free_string(order); if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -245,6 +247,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) } else { contacts = roster_get_nogroup(ROSTER_ORD_NAME, offline); } + prefs_free_string(order); if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -280,7 +283,7 @@ rosterwin_roster(void) ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout; assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK); - char *by = prefs_get_string(PREF_ROSTER_BY); + char *by = prefs_get_string(PREF_ROSTER_BY); if (g_strcmp0(by, "presence") == 0) { werase(layout->subwin); _rosterwin_contacts_by_presence(layout, "chat", "Available for chat"); @@ -311,6 +314,7 @@ rosterwin_roster(void) } else { contacts = roster_get_contacts(ROSTER_ORD_NAME, offline); } + prefs_free_string(order); werase(layout->subwin); @@ -338,6 +342,6 @@ rosterwin_roster(void) } g_slist_free(contacts); } - free(by); + prefs_free_string(by); } } diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 83907b49..42293c18 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -496,6 +496,7 @@ _jabber_connect(const char *const fulljid, const char *const passwd, const char if (cert_path) { xmpp_conn_tlscert_path(jabber_conn.conn, cert_path); } + prefs_free_string(cert_path); #endif #ifdef HAVE_LIBMESODE From f54c2e8ecab9134eca315313bfd269a0261e4763 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 21 Nov 2015 21:20:12 +0000 Subject: [PATCH 3/9] Tidy rosterwin --- src/ui/rosterwin.c | 130 +++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 64 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index c2267437..6320e32c 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -279,69 +279,71 @@ void rosterwin_roster(void) { ProfWin *console = wins_get_console(); - if (console) { - ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout; - assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK); - - char *by = prefs_get_string(PREF_ROSTER_BY); - if (g_strcmp0(by, "presence") == 0) { - werase(layout->subwin); - _rosterwin_contacts_by_presence(layout, "chat", "Available for chat"); - _rosterwin_contacts_by_presence(layout, "online", "Online"); - _rosterwin_contacts_by_presence(layout, "away", "Away"); - _rosterwin_contacts_by_presence(layout, "xa", "Extended Away"); - _rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb"); - if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) { - _rosterwin_contacts_by_presence(layout, "offline", "Offline"); - } - } else if (g_strcmp0(by, "group") == 0) { - werase(layout->subwin); - GSList *groups = roster_get_groups(); - GSList *curr_group = groups; - while (curr_group) { - _rosterwin_contacts_by_group(layout, curr_group->data); - curr_group = g_slist_next(curr_group); - } - g_slist_free_full(groups, free); - _rosterwin_contacts_by_no_group(layout); - } else { - GSList *contacts = NULL; - - char *order = prefs_get_string(PREF_ROSTER_ORDER); - gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE); - if (g_strcmp0(order, "presence") == 0) { - contacts = roster_get_contacts(ROSTER_ORD_PRESENCE, offline); - } else { - contacts = roster_get_contacts(ROSTER_ORD_NAME, offline); - } - prefs_free_string(order); - - werase(layout->subwin); - - wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - GString *title = g_string_new(" "); - char ch = prefs_get_roster_header_char(); - if (ch) { - g_string_append_printf(title, "%c", ch); - } - g_string_append(title, "Roster"); - if (prefs_get_boolean(PREF_ROSTER_COUNT)) { - g_string_append_printf(title, " (%d)", g_slist_length(contacts)); - } - win_print_nowrap(layout->subwin, title->str, TRUE); - g_string_free(title, TRUE); - wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - - if (contacts) { - GSList *curr_contact = contacts; - while (curr_contact) { - PContact contact = curr_contact->data; - _rosterwin_contact(layout, contact); - curr_contact = g_slist_next(curr_contact); - } - } - g_slist_free(contacts); - } - prefs_free_string(by); + if (!console) { + return; } + + ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout; + assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK); + + char *by = prefs_get_string(PREF_ROSTER_BY); + if (g_strcmp0(by, "presence") == 0) { + werase(layout->subwin); + _rosterwin_contacts_by_presence(layout, "chat", "Available for chat"); + _rosterwin_contacts_by_presence(layout, "online", "Online"); + _rosterwin_contacts_by_presence(layout, "away", "Away"); + _rosterwin_contacts_by_presence(layout, "xa", "Extended Away"); + _rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb"); + if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) { + _rosterwin_contacts_by_presence(layout, "offline", "Offline"); + } + } else if (g_strcmp0(by, "group") == 0) { + werase(layout->subwin); + GSList *groups = roster_get_groups(); + GSList *curr_group = groups; + while (curr_group) { + _rosterwin_contacts_by_group(layout, curr_group->data); + curr_group = g_slist_next(curr_group); + } + g_slist_free_full(groups, free); + _rosterwin_contacts_by_no_group(layout); + } else { + GSList *contacts = NULL; + + char *order = prefs_get_string(PREF_ROSTER_ORDER); + gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE); + if (g_strcmp0(order, "presence") == 0) { + contacts = roster_get_contacts(ROSTER_ORD_PRESENCE, offline); + } else { + contacts = roster_get_contacts(ROSTER_ORD_NAME, offline); + } + prefs_free_string(order); + + werase(layout->subwin); + + wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + GString *title = g_string_new(" "); + char ch = prefs_get_roster_header_char(); + if (ch) { + g_string_append_printf(title, "%c", ch); + } + g_string_append(title, "Roster"); + if (prefs_get_boolean(PREF_ROSTER_COUNT)) { + g_string_append_printf(title, " (%d)", g_slist_length(contacts)); + } + win_print_nowrap(layout->subwin, title->str, TRUE); + g_string_free(title, TRUE); + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + + if (contacts) { + GSList *curr_contact = contacts; + while (curr_contact) { + PContact contact = curr_contact->data; + _rosterwin_contact(layout, contact); + curr_contact = g_slist_next(curr_contact); + } + } + g_slist_free(contacts); + } + prefs_free_string(by); } From ef0f093efde451ff9c73e304bf50020385942d55 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 21 Nov 2015 21:49:12 +0000 Subject: [PATCH 4/9] Added /roster indent resource --- src/command/command.c | 3 + src/command/commands.c | 16 ++++ src/config/preferences.c | 22 ++++++ src/config/preferences.h | 2 + src/ui/console.c | 163 ++++++++++++++++++++------------------- src/ui/rosterwin.c | 18 ++++- 6 files changed, 141 insertions(+), 83 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 47cc7d9b..aaf0c555 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -281,6 +281,7 @@ static struct cmd_t command_defs[] = "/roster char header |none", "/roster char contact |none", "/roster indent contact ", + "/roster indent resource ", "/roster size ", "/roster add []", "/roster remove ", @@ -318,6 +319,7 @@ static struct cmd_t command_defs[] = { "char contact ", "Prefix roster contacts with specificed character." }, { "char contact none", "Remove roster contact character prefix." }, { "indent contact ", "Indent contact line by spaces." }, + { "indent resource ", "Indent roster line by spaces." }, { "size ", "Percentage of the screen taken up by the roster (1-99)." }, { "add []", "Add a new item to the roster." }, { "remove ", "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"); diff --git a/src/command/commands.c b/src/command/commands.c index 7a97625a..8de6a6df 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -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); } diff --git a/src/config/preferences.c b/src/config/preferences.c index 0916cf86..1de2ac64 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -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) { diff --git a/src/config/preferences.h b/src/config/preferences.h index 374f6947..8daa0a99 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -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); diff --git a/src/ui/console.c b/src/ui/console.c index 0b9e18c4..c72a34ea 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -960,9 +960,9 @@ cons_theme_setting(void) { char *theme = prefs_get_string(PREF_THEME); if (theme == NULL) { - cons_show("Theme (/theme) : default"); + cons_show("Theme (/theme) : default"); } else { - cons_show("Theme (/theme) : %s", theme); + cons_show("Theme (/theme) : %s", theme); } prefs_free_string(theme); } @@ -971,58 +971,58 @@ void cons_privileges_setting(void) { if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) - cons_show("MUC privileges (/privileges) : ON"); + cons_show("MUC privileges (/privileges) : ON"); else - cons_show("MUC privileges (/privileges) : OFF"); + cons_show("MUC privileges (/privileges) : OFF"); } void cons_beep_setting(void) { if (prefs_get_boolean(PREF_BEEP)) - cons_show("Terminal beep (/beep) : ON"); + cons_show("Terminal beep (/beep) : ON"); else - cons_show("Terminal beep (/beep) : OFF"); + cons_show("Terminal beep (/beep) : OFF"); } void cons_resource_setting(void) { if (prefs_get_boolean(PREF_RESOURCE_TITLE)) - cons_show("Resource title (/resource) : ON"); + cons_show("Resource title (/resource) : ON"); else - cons_show("Resource title (/resource) : OFF"); + cons_show("Resource title (/resource) : OFF"); if (prefs_get_boolean(PREF_RESOURCE_MESSAGE)) - cons_show("Resource message (/resource) : ON"); + cons_show("Resource message (/resource) : ON"); else - cons_show("Resource message (/resource) : OFF"); + cons_show("Resource message (/resource) : OFF"); } void cons_wrap_setting(void) { if (prefs_get_boolean(PREF_WRAP)) - cons_show("Word wrap (/wrap) : ON"); + cons_show("Word wrap (/wrap) : ON"); else - cons_show("Word wrap (/wrap) : OFF"); + cons_show("Word wrap (/wrap) : OFF"); } void cons_winstidy_setting(void) { if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) - cons_show("Window Auto Tidy (/wins) : ON"); + cons_show("Window Auto Tidy (/wins) : ON"); else - cons_show("Window Auto Tidy (/wins) : OFF"); + cons_show("Window Auto Tidy (/wins) : OFF"); } void cons_encwarn_setting(void) { if (prefs_get_boolean(PREF_ENC_WARN)) { - cons_show("Warn unencrypted (/encwarn) : ON"); + cons_show("Warn unencrypted (/encwarn) : ON"); } else { - cons_show("Warn unencrypted (/encwarn) : OFF"); + cons_show("Warn unencrypted (/encwarn) : OFF"); } } @@ -1030,9 +1030,9 @@ void cons_tlsshow_setting(void) { if (prefs_get_boolean(PREF_TLS_SHOW)) { - cons_show("TLS show (/tls) : ON"); + cons_show("TLS show (/tls) : ON"); } else { - cons_show("TLS show (/tls) : OFF"); + cons_show("TLS show (/tls) : OFF"); } } @@ -1040,44 +1040,44 @@ void cons_presence_setting(void) { if (prefs_get_boolean(PREF_PRESENCE)) - cons_show("Contact presence (/presence) : ON"); + cons_show("Contact presence (/presence) : ON"); else - cons_show("Contact presence (/presence) : OFF"); + cons_show("Contact presence (/presence) : OFF"); } void cons_flash_setting(void) { if (prefs_get_boolean(PREF_FLASH)) - cons_show("Terminal flash (/flash) : ON"); + cons_show("Terminal flash (/flash) : ON"); else - cons_show("Terminal flash (/flash) : OFF"); + cons_show("Terminal flash (/flash) : OFF"); } void cons_splash_setting(void) { if (prefs_get_boolean(PREF_SPLASH)) - cons_show("Splash screen (/splash) : ON"); + cons_show("Splash screen (/splash) : ON"); else - cons_show("Splash screen (/splash) : OFF"); + cons_show("Splash screen (/splash) : OFF"); } void cons_occupants_setting(void) { if (prefs_get_boolean(PREF_OCCUPANTS)) - cons_show("Occupants (/occupants) : show"); + cons_show("Occupants (/occupants) : show"); else - cons_show("Occupants (/occupants) : hide"); + cons_show("Occupants (/occupants) : hide"); if (prefs_get_boolean(PREF_OCCUPANTS_JID)) - cons_show("Occupant jids (/occupants) : show"); + cons_show("Occupant jids (/occupants) : show"); else - cons_show("Occupant jids (/occupants) : hide"); + cons_show("Occupant jids (/occupants) : hide"); int size = prefs_get_occupants_size(); - cons_show("Occupants size (/occupants) : %d", size); + cons_show("Occupants size (/occupants) : %d", size); } void @@ -1097,55 +1097,55 @@ cons_time_setting(void) { char *pref_time_console = prefs_get_string(PREF_TIME_CONSOLE); if (g_strcmp0(pref_time_console, "off") == 0) - cons_show("Time console (/time) : OFF"); + cons_show("Time console (/time) : OFF"); else - cons_show("Time console (/time) : %s", pref_time_console); + cons_show("Time console (/time) : %s", pref_time_console); prefs_free_string(pref_time_console); char *pref_time_chat = prefs_get_string(PREF_TIME_CHAT); if (g_strcmp0(pref_time_chat, "off") == 0) - cons_show("Time chat (/time) : OFF"); + cons_show("Time chat (/time) : OFF"); else - cons_show("Time chat (/time) : %s", pref_time_chat); + cons_show("Time chat (/time) : %s", pref_time_chat); prefs_free_string(pref_time_chat); char *pref_time_muc = prefs_get_string(PREF_TIME_MUC); if (g_strcmp0(pref_time_muc, "off") == 0) - cons_show("Time MUC (/time) : OFF"); + cons_show("Time MUC (/time) : OFF"); else - cons_show("Time MUC (/time) : %s", pref_time_muc); + cons_show("Time MUC (/time) : %s", pref_time_muc); prefs_free_string(pref_time_muc); char *pref_time_mucconf = prefs_get_string(PREF_TIME_MUCCONFIG); if (g_strcmp0(pref_time_mucconf, "off") == 0) - cons_show("Time MUC config (/time) : OFF"); + cons_show("Time MUC config (/time) : OFF"); else - cons_show("Time MUC config (/time) : %s", pref_time_mucconf); + cons_show("Time MUC config (/time) : %s", pref_time_mucconf); prefs_free_string(pref_time_mucconf); char *pref_time_private = prefs_get_string(PREF_TIME_PRIVATE); if (g_strcmp0(pref_time_private, "off") == 0) - cons_show("Time private (/time) : OFF"); + cons_show("Time private (/time) : OFF"); else - cons_show("Time private (/time) : %s", pref_time_private); + cons_show("Time private (/time) : %s", pref_time_private); prefs_free_string(pref_time_private); char *pref_time_xml = prefs_get_string(PREF_TIME_XMLCONSOLE); if (g_strcmp0(pref_time_xml, "off") == 0) - cons_show("Time XML Console (/time) : OFF"); + cons_show("Time XML Console (/time) : OFF"); else - cons_show("Time XML Console (/time) : %s", pref_time_xml); + cons_show("Time XML Console (/time) : %s", pref_time_xml); prefs_free_string(pref_time_xml); char *pref_time_statusbar = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(pref_time_statusbar, "off") == 0) - cons_show("Time statusbar (/time) : OFF"); + cons_show("Time statusbar (/time) : OFF"); else - cons_show("Time statusbar (/time) : %s", pref_time_statusbar); + cons_show("Time statusbar (/time) : %s", pref_time_statusbar); prefs_free_string(pref_time_statusbar); char *pref_time_lastactivity = prefs_get_string(PREF_TIME_LASTACTIVITY); - cons_show("Time last activity (/time) : %s", pref_time_lastactivity); + cons_show("Time last activity (/time) : %s", pref_time_lastactivity); prefs_free_string(pref_time_lastactivity); } @@ -1153,9 +1153,9 @@ void cons_vercheck_setting(void) { if (prefs_get_boolean(PREF_VERCHECK)) - cons_show("Version checking (/vercheck) : ON"); + cons_show("Version checking (/vercheck) : ON"); else - cons_show("Version checking (/vercheck) : OFF"); + cons_show("Version checking (/vercheck) : OFF"); } void @@ -1165,9 +1165,9 @@ cons_statuses_setting(void) char *chat = prefs_get_string(PREF_STATUSES_CHAT); char *muc = prefs_get_string(PREF_STATUSES_MUC); - cons_show("Console statuses (/statuses) : %s", console); - cons_show("Chat statuses (/statuses) : %s", chat); - cons_show("MUC statuses (/statuses) : %s", muc); + cons_show("Console statuses (/statuses) : %s", console); + cons_show("Chat statuses (/statuses) : %s", chat); + cons_show("MUC statuses (/statuses) : %s", muc); prefs_free_string(console); prefs_free_string(chat); @@ -1178,14 +1178,14 @@ void cons_titlebar_setting(void) { if (prefs_get_boolean(PREF_TITLEBAR_SHOW)) { - cons_show("Titlebar show (/titlebar) : ON"); + cons_show("Titlebar show (/titlebar) : ON"); } else { - cons_show("Titlebar show (/titlebar) : OFF"); + cons_show("Titlebar show (/titlebar) : OFF"); } if (prefs_get_boolean(PREF_TITLEBAR_GOODBYE)) { - cons_show("Titlebar goodbye (/titlebar) : ON"); + cons_show("Titlebar goodbye (/titlebar) : ON"); } else { - cons_show("Titlebar goodbye (/titlebar) : OFF"); + cons_show("Titlebar goodbye (/titlebar) : OFF"); } } @@ -1193,70 +1193,73 @@ void cons_roster_setting(void) { if (prefs_get_boolean(PREF_ROSTER)) - cons_show("Roster (/roster) : show"); + cons_show("Roster (/roster) : show"); else - cons_show("Roster (/roster) : hide"); + cons_show("Roster (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) - cons_show("Roster offline (/roster) : show"); + cons_show("Roster offline (/roster) : show"); else - cons_show("Roster offline (/roster) : hide"); + cons_show("Roster offline (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) - cons_show("Roster resource (/roster) : show"); + cons_show("Roster resource (/roster) : show"); else - cons_show("Roster resource (/roster) : hide"); + cons_show("Roster resource (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) - cons_show("Roster presence (/roster) : show"); + cons_show("Roster presence (/roster) : show"); else - cons_show("Roster presence (/roster) : hide"); + cons_show("Roster presence (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_STATUS)) - cons_show("Roster status (/roster) : show"); + cons_show("Roster status (/roster) : show"); else - cons_show("Roster status (/roster) : hide"); + cons_show("Roster status (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_EMPTY)) - cons_show("Roster empty (/roster) : show"); + cons_show("Roster empty (/roster) : show"); else - cons_show("Roster empty (/roster) : hide"); + cons_show("Roster empty (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_COUNT)) - cons_show("Roster count (/roster) : show"); + cons_show("Roster count (/roster) : show"); else - cons_show("Roster count (/roster) : hide"); + cons_show("Roster count (/roster) : hide"); if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) - cons_show("Roster priority (/roster) : show"); + cons_show("Roster priority (/roster) : show"); else - cons_show("Roster priority (/roster) : hide"); + cons_show("Roster priority (/roster) : hide"); char *by = prefs_get_string(PREF_ROSTER_BY); - cons_show("Roster by (/roster) : %s", by); + cons_show("Roster by (/roster) : %s", by); prefs_free_string(by); char *order = prefs_get_string(PREF_ROSTER_ORDER); - cons_show("Roster order (/roster) : %s", order); + cons_show("Roster order (/roster) : %s", order); prefs_free_string(order); int size = prefs_get_roster_size(); - cons_show("Roster size (/roster) : %d", size); + cons_show("Roster size (/roster) : %d", size); char header_ch = prefs_get_roster_header_char(); if (header_ch) - cons_show("Roster header char (/roster) : %c", header_ch); + cons_show("Roster header char (/roster) : %c", header_ch); else - cons_show("Roster header char (/roster) : none"); + cons_show("Roster header char (/roster) : none"); char contact_ch = prefs_get_roster_contact_char(); if (contact_ch) - cons_show("Roster contact char (/roster) : %c", contact_ch); + cons_show("Roster contact char (/roster) : %c", contact_ch); 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); + 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 @@ -1460,11 +1463,11 @@ cons_show_chat_prefs(void) void cons_inpblock_setting(void) { - cons_show("Input timeout (/inpblock) : %d milliseconds", prefs_get_inpblock()); + cons_show("Input timeout (/inpblock) : %d milliseconds", prefs_get_inpblock()); if (prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) { - cons_show("Dynamic timeout (/inpblock) : ON"); + cons_show("Dynamic timeout (/inpblock) : ON"); } else { - cons_show("Dynamic timeout (/inpblock) : OFF"); + cons_show("Dynamic timeout (/inpblock) : OFF"); } } diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 6320e32c..b0cc317f 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -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; @@ -104,7 +109,12 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact) 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(" "); + 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); } From 5c08bea8d075714182ca898fcb68d5ad15605f0d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 21 Nov 2015 22:03:43 +0000 Subject: [PATCH 5/9] Added /roster indent presence --- src/command/command.c | 5 ++++- src/command/commands.c | 16 ++++++++++++++++ src/config/preferences.c | 22 ++++++++++++++++++++++ src/config/preferences.h | 2 ++ src/ui/console.c | 3 +++ src/ui/rosterwin.c | 22 ++++++++++++++-------- 6 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index aaf0c555..37e963c9 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -282,6 +282,7 @@ static struct cmd_t command_defs[] = "/roster char contact |none", "/roster indent contact ", "/roster indent resource ", + "/roster indent presence ", "/roster size ", "/roster add []", "/roster remove ", @@ -319,7 +320,8 @@ static struct cmd_t command_defs[] = { "char contact ", "Prefix roster contacts with specificed character." }, { "char contact none", "Remove roster contact character prefix." }, { "indent contact ", "Indent contact line by spaces." }, - { "indent resource ", "Indent roster line by spaces." }, + { "indent resource ", "Indent resource line by spaces." }, + { "indent presence ", "Indent presence line by spaces." }, { "size ", "Percentage of the screen taken up by the roster (1-99)." }, { "add []", "Add a new item to the roster." }, { "remove ", "Removes an item from the roster." }, @@ -2050,6 +2052,7 @@ cmd_init(void) roster_indent_ac = autocomplete_new(); autocomplete_add(roster_indent_ac, "contact"); autocomplete_add(roster_indent_ac, "resource"); + autocomplete_add(roster_indent_ac, "presence"); roster_option_ac = autocomplete_new(); autocomplete_add(roster_option_ac, "offline"); diff --git a/src/command/commands.c b/src/command/commands.c index 8de6a6df..18fa1bd9 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1815,6 +1815,22 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) 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 { cons_bad_cmd_usage(command); } diff --git a/src/config/preferences.c b/src/config/preferences.c index 1de2ac64..d1adfdc4 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -550,6 +550,28 @@ prefs_set_roster_resource_indent(gint value) _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 prefs_add_alias(const char *const name, const char *const value) { diff --git a/src/config/preferences.h b/src/config/preferences.h index 8daa0a99..02ea8505 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -176,6 +176,8 @@ 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); +gint prefs_get_roster_presence_indent(void); +void prefs_set_roster_presence_indent(gint value); void prefs_add_login(const char *jid); diff --git a/src/ui/console.c b/src/ui/console.c index c72a34ea..5f1b5ec4 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1260,6 +1260,9 @@ cons_roster_setting(void) gint resource_indent = prefs_get_roster_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 diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index b0cc317f..cc31ef55 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -43,7 +43,8 @@ #include "roster_list.h" 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 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; 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 if (by_presence) { if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { wattron(layout->subwin, theme_attrs(colour)); GString *msg = g_string_new(" "); - while (indent > 0) { + while (current_indent > 0) { g_string_append(msg, " "); - indent--; + current_indent--; } g_string_append_printf(msg, "\"%s\"", status); 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))) { wattron(layout->subwin, theme_attrs(colour)); GString *msg = g_string_new(" "); - while (indent > 0) { + while (current_indent > 0) { g_string_append(msg, " "); - indent--; + current_indent--; } if (prefs_get_boolean(PREF_ROSTER_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)); 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); @@ -133,7 +139,7 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_inden const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); 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); @@ -171,7 +177,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { _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); + _rosterwin_presence(layout, presence_colour, presence, status, current_indent); } } From 7a324abcd632a30b603586a1eef80eee4140e91a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Nov 2015 00:30:42 +0000 Subject: [PATCH 6/9] Option to show presence information on single line in roster --- src/command/commands.c | 2 +- src/config/preferences.c | 2 +- src/ui/rosterwin.c | 120 ++++++++++++++++++++++++++------------- src/ui/window.c | 13 ++++- src/ui/window.h | 1 + 5 files changed, 94 insertions(+), 44 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 18fa1bd9..3aa05950 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1821,7 +1821,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) } else { int intval = 0; char *err_msg = NULL; - gboolean res = strtoi_range(args[2], &intval, 0, 10, &err_msg); + gboolean res = strtoi_range(args[2], &intval, -1, 10, &err_msg); if (res) { prefs_set_roster_presence_indent(intval); cons_show("Roster presence indent set to: %d", intval); diff --git a/src/config/preferences.c b/src/config/preferences.c index d1adfdc4..26405989 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -558,7 +558,7 @@ prefs_get_roster_presence_indent(void) } gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.presence.indent", NULL); - if (result < 0) { + if (result < -1) { result = 0; } diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index cc31ef55..f3a10257 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -65,41 +65,66 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr if (by_presence) { if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { wattron(layout->subwin, theme_attrs(colour)); - GString *msg = g_string_new(" "); - while (current_indent > 0) { - g_string_append(msg, " "); - current_indent--; + if (presence_indent == -1) { + GString *msg = g_string_new(""); + g_string_append_printf(msg, ": \"%s\"", status); + win_print_nowrap(layout->subwin, msg->str, FALSE); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(colour)); + } else { + GString *msg = g_string_new(" "); + while (current_indent > 0) { + g_string_append(msg, " "); + current_indent--; + } + g_string_append_printf(msg, "\"%s\"", status); + win_newline_lazy(layout->subwin); + win_print_nowrap(layout->subwin, msg->str, FALSE); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(colour)); } - g_string_append_printf(msg, "\"%s\"", status); - win_print_nowrap(layout->subwin, msg->str, TRUE); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(colour)); } // show both presence and status when not grouped by presence } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || (status && prefs_get_boolean(PREF_ROSTER_STATUS))) { wattron(layout->subwin, theme_attrs(colour)); - GString *msg = g_string_new(" "); - while (current_indent > 0) { - g_string_append(msg, " "); - current_indent--; - } - if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { - g_string_append(msg, presence); - if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { - g_string_append_printf(msg, " \"%s\"", status); + if (presence_indent == -1) { + GString *msg = g_string_new(""); + if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + g_string_append_printf(msg, ": %s", presence); + if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { + g_string_append_printf(msg, " \"%s\"", status); + } + } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { + g_string_append_printf(msg, ": \"%s\"", status); } - } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { - g_string_append_printf(msg, "\"%s\"", status); + win_print_nowrap(layout->subwin, msg->str, FALSE); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(colour)); + } else { + GString *msg = g_string_new(" "); + while (current_indent > 0) { + g_string_append(msg, " "); + current_indent--; + } + if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + g_string_append(msg, presence); + if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { + g_string_append_printf(msg, " \"%s\"", status); + } + } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { + g_string_append_printf(msg, "\"%s\"", status); + } + win_newline_lazy(layout->subwin); + win_print_nowrap(layout->subwin, msg->str, FALSE); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(colour)); } - win_print_nowrap(layout->subwin, msg->str, TRUE); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(colour)); } } static void -_rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_indent) +_rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent) { GList *resources = p_contact_get_available_resources(contact); if (resources) { @@ -125,7 +150,8 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_inden if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) { g_string_append_printf(msg, " [%d]", resource->priority); } - win_print_nowrap(layout->subwin, msg->str, TRUE); + win_newline_lazy(layout->subwin); + win_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); @@ -170,24 +196,28 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) g_string_append_printf(msg, "%c", ch); } g_string_append(msg, name); - win_print_nowrap(layout->subwin, msg->str, TRUE); + win_newline_lazy(layout->subwin); + win_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(presence_colour)); if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { - _rosterwin_resource(layout, contact, current_indent); + _rosterwin_resources(layout, contact, current_indent); } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { _rosterwin_presence(layout, presence_colour, presence, status, current_indent); } } static void -_rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const presence, char *title) +_rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const presence, char *title, gboolean newline) { GSList *contacts = roster_get_contacts_by_presence(presence); // if this group has contacts, or if we want to show empty groups if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { + if (newline) { + win_newline_lazy(layout->subwin); + } wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title_str = g_string_new(" "); char ch = prefs_get_roster_header_char(); @@ -198,7 +228,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title_str, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title_str->str, TRUE); + win_print_nowrap(layout->subwin, title_str->str, FALSE); g_string_free(title_str, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); } @@ -215,7 +245,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese } static void -_rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) +_rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group, gboolean newline) { GSList *contacts = NULL; @@ -229,6 +259,9 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) prefs_free_string(order); if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { + if (newline) { + win_newline_lazy(layout->subwin); + } wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title = g_string_new(" "); char ch = prefs_get_roster_header_char(); @@ -239,7 +272,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title->str, TRUE); + win_print_nowrap(layout->subwin, title->str, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -254,7 +287,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) } static void -_rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) +_rosterwin_contacts_by_no_group(ProfLayoutSplit *layout, gboolean newline) { GSList *contacts = NULL; @@ -268,6 +301,9 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) prefs_free_string(order); if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { + if (newline) { + win_newline_lazy(layout->subwin); + } wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title = g_string_new(" "); char ch = prefs_get_roster_header_char(); @@ -279,7 +315,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title->str, TRUE); + win_print_nowrap(layout->subwin, title->str, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -307,24 +343,26 @@ rosterwin_roster(void) char *by = prefs_get_string(PREF_ROSTER_BY); if (g_strcmp0(by, "presence") == 0) { werase(layout->subwin); - _rosterwin_contacts_by_presence(layout, "chat", "Available for chat"); - _rosterwin_contacts_by_presence(layout, "online", "Online"); - _rosterwin_contacts_by_presence(layout, "away", "Away"); - _rosterwin_contacts_by_presence(layout, "xa", "Extended Away"); - _rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb"); + _rosterwin_contacts_by_presence(layout, "chat", "Available for chat", FALSE); + _rosterwin_contacts_by_presence(layout, "online", "Online", TRUE); + _rosterwin_contacts_by_presence(layout, "away", "Away", TRUE); + _rosterwin_contacts_by_presence(layout, "xa", "Extended Away", TRUE); + _rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb", TRUE); if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) { - _rosterwin_contacts_by_presence(layout, "offline", "Offline"); + _rosterwin_contacts_by_presence(layout, "offline", "Offline", TRUE); } } else if (g_strcmp0(by, "group") == 0) { werase(layout->subwin); + gboolean newline = FALSE; GSList *groups = roster_get_groups(); GSList *curr_group = groups; while (curr_group) { - _rosterwin_contacts_by_group(layout, curr_group->data); + _rosterwin_contacts_by_group(layout, curr_group->data, newline); + newline = TRUE; curr_group = g_slist_next(curr_group); } g_slist_free_full(groups, free); - _rosterwin_contacts_by_no_group(layout); + _rosterwin_contacts_by_no_group(layout, newline); } else { GSList *contacts = NULL; @@ -349,7 +387,7 @@ rosterwin_roster(void) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title->str, TRUE); + win_print_nowrap(layout->subwin, title->str, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); diff --git a/src/ui/window.c b/src/ui/window.c index 3ca9b927..c40e3547 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1269,11 +1269,22 @@ void win_print_nowrap(WINDOW *win, char *msg, gboolean newline) { int maxx = getmaxx(win); + int curx = getcurx(win); int cury = getcury(win); - waddnstr(win, msg, maxx); + waddnstr(win, msg, maxx - curx); if (newline) { wmove(win, cury+1, 0); } } + +void +win_newline_lazy(WINDOW *win) +{ + int curx = getcurx(win); + if (curx > 0) { + int cury = getcury(win); + wmove(win, cury+1, 0); + } +} diff --git a/src/ui/window.h b/src/ui/window.h index 24d71ad6..0a01b37f 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -68,6 +68,7 @@ void win_redraw(ProfWin *window); int win_roster_cols(void); int win_occpuants_cols(void); void win_print_nowrap(WINDOW *win, char *msg, gboolean newline); +void win_newline_lazy(WINDOW *win); void win_mark_received(ProfWin *window, const char *const id); gboolean win_has_active_subwin(ProfWin *window); From b4482b9fe1cb121500b85e2716c561d55215afaa Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Nov 2015 00:48:18 +0000 Subject: [PATCH 7/9] Updated themes --- src/config/theme.c | 12 ++++++++++++ src/ui/rosterwin.c | 2 +- theme_template | 3 +++ themes/boothj5 | 28 +++++++++++++++------------- themes/complex | 3 +++ themes/simple | 3 +++ 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/config/theme.c b/src/config/theme.c index b875f46f..271a48c8 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -483,6 +483,18 @@ _load_preferences(void) g_free(ch); } } + if (g_key_file_has_key(theme, "ui", "roster.contact.indent", NULL)) { + gint contact_indent = g_key_file_get_integer(theme, "ui", "roster.contact.indent", NULL); + prefs_set_roster_contact_indent(contact_indent); + } + if (g_key_file_has_key(theme, "ui", "roster.resource.indent", NULL)) { + gint resource_indent = g_key_file_get_integer(theme, "ui", "roster.resource.indent", NULL); + prefs_set_roster_resource_indent(resource_indent); + } + if (g_key_file_has_key(theme, "ui", "roster.presence.indent", NULL)) { + gint presence_indent = g_key_file_get_integer(theme, "ui", "roster.presence.indent", NULL); + prefs_set_roster_presence_indent(presence_indent); + } _set_boolean_preference("privileges", PREF_MUC_PRIVILEGES); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index f3a10257..bc04511c 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -148,7 +148,7 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde } g_string_append(msg, resource->name); if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) { - g_string_append_printf(msg, " [%d]", resource->priority); + g_string_append_printf(msg, " %d", resource->priority); } win_newline_lazy(layout->subwin); win_print_nowrap(layout->subwin, msg->str, FALSE); diff --git a/theme_template b/theme_template index 7eca6ff9..14645ce0 100644 --- a/theme_template +++ b/theme_template @@ -84,6 +84,9 @@ roster.priority= roster.size= roster.header.char= roster.contact.char= +roster.contact.indent= +roster.resource.indent= +roster.presence.indent= occupants= occupants.size= occupants.jid= diff --git a/themes/boothj5 b/themes/boothj5 index 48ada774..3c4fdc1d 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -71,19 +71,21 @@ resource.message=true statuses.console=all statuses.chat=all statuses.muc=all -roster=true -roster.offline=true -roster.resource=true -roster.presence=true -roster.status=true -roster.empty=true -roster.by=group -roster.order=presence -roster.count=true -roster.priority=true -roster.size=25 -roster.header.char=@ -roster.contact.char=- +roster.by=presence +roster.offline=true +roster.empty=false +roster.presence=true +roster.order=presence +roster.status=true +roster.resource=true +roster.priority=false +roster=true +roster.count=true +roster.size=25 +roster.contact.indent=1 +roster.resource.indent=2 +roster.presence.indent=-1 +roster.header.char=@ occupants=true occupants.size=15 occupants.jid=false diff --git a/themes/complex b/themes/complex index e2667944..ba11735c 100644 --- a/themes/complex +++ b/themes/complex @@ -31,6 +31,9 @@ roster.priority=true roster.size=25 roster.header.char=- roster.contact.char=- +roster.contact.indent=2 +roster.resource.indent=2 +roster.presence.indent=2 privileges=true presence=true intype=true diff --git a/themes/simple b/themes/simple index a31c9c01..ef11247e 100644 --- a/themes/simple +++ b/themes/simple @@ -28,6 +28,9 @@ roster.order=presence roster.count=false roster.priority=false roster.size=25 +roster.contact.indent=0 +roster.resource.indent=0 +roster.presence.indent=-1 privileges=false presence=false intype=false From 3d1299eb1e9f323bb49af0c8f553cdb00752e7e2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Nov 2015 00:54:40 +0000 Subject: [PATCH 8/9] Renamed subwin functions --- src/ui/occupantswin.c | 12 ++++++------ src/ui/rosterwin.c | 34 +++++++++++++++++----------------- src/ui/window.c | 4 ++-- src/ui/window.h | 4 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index 71474a80..3c1d9dd5 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -48,13 +48,13 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean sh GString *msg = g_string_new(" "); g_string_append(msg, occupant->nick); - win_print_nowrap(layout->subwin, msg->str, TRUE); + win_sub_print_nowrap(layout->subwin, msg->str, TRUE); g_string_free(msg, TRUE); if (showjid && occupant->jid) { GString *msg = g_string_new(" "); g_string_append(msg, occupant->jid); - win_print_nowrap(layout->subwin, msg->str, TRUE); + win_sub_print_nowrap(layout->subwin, msg->str, TRUE); g_string_free(msg, TRUE); } @@ -75,7 +75,7 @@ occupantswin_occupants(const char *const roomjid) if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_print_nowrap(layout->subwin, " -Moderators", TRUE); + win_sub_print_nowrap(layout->subwin, " -Moderators", TRUE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); GList *roster_curr = occupants; while (roster_curr) { @@ -87,7 +87,7 @@ occupantswin_occupants(const char *const roomjid) } wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_print_nowrap(layout->subwin, " -Participants", TRUE); + win_sub_print_nowrap(layout->subwin, " -Participants", TRUE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); roster_curr = occupants; while (roster_curr) { @@ -99,7 +99,7 @@ occupantswin_occupants(const char *const roomjid) } wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_print_nowrap(layout->subwin, " -Visitors", TRUE); + win_sub_print_nowrap(layout->subwin, " -Visitors", TRUE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); roster_curr = occupants; while (roster_curr) { @@ -111,7 +111,7 @@ occupantswin_occupants(const char *const roomjid) } } else { wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_print_nowrap(layout->subwin, " -Occupants\n", TRUE); + win_sub_print_nowrap(layout->subwin, " -Occupants\n", TRUE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); GList *roster_curr = occupants; while (roster_curr) { diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index bc04511c..79293fc6 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -68,7 +68,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr if (presence_indent == -1) { GString *msg = g_string_new(""); g_string_append_printf(msg, ": \"%s\"", status); - win_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } else { @@ -78,8 +78,8 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr current_indent--; } g_string_append_printf(msg, "\"%s\"", status); - win_newline_lazy(layout->subwin); - win_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_newline_lazy(layout->subwin); + win_sub_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } @@ -98,7 +98,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { g_string_append_printf(msg, ": \"%s\"", status); } - win_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } else { @@ -115,8 +115,8 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { g_string_append_printf(msg, "\"%s\"", status); } - win_newline_lazy(layout->subwin); - win_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_newline_lazy(layout->subwin); + win_sub_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } @@ -150,8 +150,8 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) { g_string_append_printf(msg, " %d", resource->priority); } - win_newline_lazy(layout->subwin); - win_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_newline_lazy(layout->subwin); + win_sub_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); @@ -196,8 +196,8 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) g_string_append_printf(msg, "%c", ch); } g_string_append(msg, name); - win_newline_lazy(layout->subwin); - win_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_newline_lazy(layout->subwin); + win_sub_print_nowrap(layout->subwin, msg->str, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(presence_colour)); @@ -216,7 +216,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese // if this group has contacts, or if we want to show empty groups if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { if (newline) { - win_newline_lazy(layout->subwin); + win_sub_newline_lazy(layout->subwin); } wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title_str = g_string_new(" "); @@ -228,7 +228,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title_str, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title_str->str, FALSE); + win_sub_print_nowrap(layout->subwin, title_str->str, FALSE); g_string_free(title_str, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); } @@ -260,7 +260,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group, gboolean newl if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { if (newline) { - win_newline_lazy(layout->subwin); + win_sub_newline_lazy(layout->subwin); } wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title = g_string_new(" "); @@ -272,7 +272,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group, gboolean newl if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title->str, FALSE); + win_sub_print_nowrap(layout->subwin, title->str, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -302,7 +302,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout, gboolean newline) if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { if (newline) { - win_newline_lazy(layout->subwin); + win_sub_newline_lazy(layout->subwin); } wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title = g_string_new(" "); @@ -315,7 +315,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout, gboolean newline) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title->str, FALSE); + win_sub_print_nowrap(layout->subwin, title->str, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -387,7 +387,7 @@ rosterwin_roster(void) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_print_nowrap(layout->subwin, title->str, FALSE); + win_sub_print_nowrap(layout->subwin, title->str, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); diff --git a/src/ui/window.c b/src/ui/window.c index c40e3547..d6a87fc6 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1266,7 +1266,7 @@ win_unread(ProfWin *window) } void -win_print_nowrap(WINDOW *win, char *msg, gboolean newline) +win_sub_print_nowrap(WINDOW *win, char *msg, gboolean newline) { int maxx = getmaxx(win); int curx = getcurx(win); @@ -1280,7 +1280,7 @@ win_print_nowrap(WINDOW *win, char *msg, gboolean newline) } void -win_newline_lazy(WINDOW *win) +win_sub_newline_lazy(WINDOW *win) { int curx = getcurx(win); if (curx > 0) { diff --git a/src/ui/window.h b/src/ui/window.h index 0a01b37f..a8424369 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -67,8 +67,8 @@ void win_newline(ProfWin *window); void win_redraw(ProfWin *window); int win_roster_cols(void); int win_occpuants_cols(void); -void win_print_nowrap(WINDOW *win, char *msg, gboolean newline); -void win_newline_lazy(WINDOW *win); +void win_sub_print_nowrap(WINDOW *win, char *msg, gboolean newline); +void win_sub_newline_lazy(WINDOW *win); void win_mark_received(ProfWin *window, const char *const id); gboolean win_has_active_subwin(ProfWin *window); From 0763bfc9f49dd445502d518b530654720d2d9985 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Nov 2015 01:00:14 +0000 Subject: [PATCH 9/9] Pass wrap boolean to win_sub_print() --- src/ui/occupantswin.c | 12 ++++++------ src/ui/rosterwin.c | 20 ++++++++++---------- src/ui/window.c | 2 +- src/ui/window.h | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index 3c1d9dd5..7e22ab0b 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -48,13 +48,13 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean sh GString *msg = g_string_new(" "); g_string_append(msg, occupant->nick); - win_sub_print_nowrap(layout->subwin, msg->str, TRUE); + win_sub_print(layout->subwin, msg->str, TRUE, FALSE); g_string_free(msg, TRUE); if (showjid && occupant->jid) { GString *msg = g_string_new(" "); g_string_append(msg, occupant->jid); - win_sub_print_nowrap(layout->subwin, msg->str, TRUE); + win_sub_print(layout->subwin, msg->str, TRUE, FALSE); g_string_free(msg, TRUE); } @@ -75,7 +75,7 @@ occupantswin_occupants(const char *const roomjid) if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print_nowrap(layout->subwin, " -Moderators", TRUE); + win_sub_print(layout->subwin, " -Moderators", TRUE, FALSE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); GList *roster_curr = occupants; while (roster_curr) { @@ -87,7 +87,7 @@ occupantswin_occupants(const char *const roomjid) } wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print_nowrap(layout->subwin, " -Participants", TRUE); + win_sub_print(layout->subwin, " -Participants", TRUE, FALSE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); roster_curr = occupants; while (roster_curr) { @@ -99,7 +99,7 @@ occupantswin_occupants(const char *const roomjid) } wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print_nowrap(layout->subwin, " -Visitors", TRUE); + win_sub_print(layout->subwin, " -Visitors", TRUE, FALSE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); roster_curr = occupants; while (roster_curr) { @@ -111,7 +111,7 @@ occupantswin_occupants(const char *const roomjid) } } else { wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print_nowrap(layout->subwin, " -Occupants\n", TRUE); + win_sub_print(layout->subwin, " -Occupants\n", TRUE, FALSE); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); GList *roster_curr = occupants; while (roster_curr) { diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 79293fc6..4df9516b 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -68,7 +68,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr if (presence_indent == -1) { GString *msg = g_string_new(""); g_string_append_printf(msg, ": \"%s\"", status); - win_sub_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } else { @@ -79,7 +79,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } g_string_append_printf(msg, "\"%s\"", status); win_sub_newline_lazy(layout->subwin); - win_sub_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } @@ -98,7 +98,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { g_string_append_printf(msg, ": \"%s\"", status); } - win_sub_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } else { @@ -116,7 +116,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr g_string_append_printf(msg, "\"%s\"", status); } win_sub_newline_lazy(layout->subwin); - win_sub_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } @@ -151,7 +151,7 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde g_string_append_printf(msg, " %d", resource->priority); } win_sub_newline_lazy(layout->subwin); - win_sub_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); @@ -197,7 +197,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) } g_string_append(msg, name); win_sub_newline_lazy(layout->subwin); - win_sub_print_nowrap(layout->subwin, msg->str, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, FALSE); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(presence_colour)); @@ -228,7 +228,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title_str, " (%d)", g_slist_length(contacts)); } - win_sub_print_nowrap(layout->subwin, title_str->str, FALSE); + win_sub_print(layout->subwin, title_str->str, FALSE, FALSE); g_string_free(title_str, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); } @@ -272,7 +272,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group, gboolean newl if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_sub_print_nowrap(layout->subwin, title->str, FALSE); + win_sub_print(layout->subwin, title->str, FALSE, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -315,7 +315,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout, gboolean newline) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_sub_print_nowrap(layout->subwin, title->str, FALSE); + win_sub_print(layout->subwin, title->str, FALSE, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -387,7 +387,7 @@ rosterwin_roster(void) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_sub_print_nowrap(layout->subwin, title->str, FALSE); + win_sub_print(layout->subwin, title->str, FALSE, FALSE); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); diff --git a/src/ui/window.c b/src/ui/window.c index d6a87fc6..b8e2a59d 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1266,7 +1266,7 @@ win_unread(ProfWin *window) } void -win_sub_print_nowrap(WINDOW *win, char *msg, gboolean newline) +win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap) { int maxx = getmaxx(win); int curx = getcurx(win); diff --git a/src/ui/window.h b/src/ui/window.h index a8424369..41765276 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -67,7 +67,7 @@ void win_newline(ProfWin *window); void win_redraw(ProfWin *window); int win_roster_cols(void); int win_occpuants_cols(void); -void win_sub_print_nowrap(WINDOW *win, char *msg, gboolean newline); +void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap); void win_sub_newline_lazy(WINDOW *win); void win_mark_received(ProfWin *window, const char *const id);