about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-11-21 21:49:12 +0000
committerJames Booth <boothj5@gmail.com>2015-11-21 21:49:12 +0000
commitef0f093efde451ff9c73e304bf50020385942d55 (patch)
tree52917b2ec14dbcd82eb2929e97b0e22c5c6b4765
parentf54c2e8ecab9134eca315313bfd269a0261e4763 (diff)
downloadprofani-tty-ef0f093efde451ff9c73e304bf50020385942d55.tar.gz
Added /roster indent resource
-rw-r--r--src/command/command.c3
-rw-r--r--src/command/commands.c16
-rw-r--r--src/config/preferences.c22
-rw-r--r--src/config/preferences.h2
-rw-r--r--src/ui/console.c163
-rw-r--r--src/ui/rosterwin.c18
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 <char>|none",
             "/roster char contact <char>|none",
             "/roster indent contact <indent>",
+            "/roster indent resource <indent>",
             "/roster size <percent>",
             "/roster add <jid> [<nick>]",
             "/roster remove <jid>",
@@ -318,6 +319,7 @@ static struct cmd_t command_defs[] =
             { "char contact <char>",        "Prefix roster contacts with specificed character." },
             { "char contact none",          "Remove roster contact character prefix." },
             { "indent contact <indent>",    "Indent contact line by <indent> spaces." },
+            { "indent resource <indent>",   "Indent roster line by <indent> spaces." },
             { "size <precent>",             "Percentage of the screen taken up by the roster (1-99)." },
             { "add <jid> [<nick>]",         "Add a new item to the roster." },
             { "remove <jid>",               "Removes an item from the roster." },
@@ -2047,6 +2049,7 @@ cmd_init(void)
 
     roster_indent_ac = autocomplete_new();
     autocomplete_add(roster_indent_ac, "contact");
+    autocomplete_add(roster_indent_ac, "resource");
 
     roster_option_ac = autocomplete_new();
     autocomplete_add(roster_option_ac, "offline");
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);
     }