about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-15 23:47:27 +0000
committerJames Booth <boothj5@gmail.com>2014-11-15 23:47:27 +0000
commit1479a5e134004568245996a22418dadb6b6da6f6 (patch)
tree89cb5b33d29f943334de794e07a8df032a5b8288
parent3a778cc974a2a561f96d926178ce18c9cc6627cb (diff)
downloadprofani-tty-1479a5e134004568245996a22418dadb6b6da6f6.tar.gz
Added /roster size and /occupants size settings
-rw-r--r--src/command/command.c16
-rw-r--r--src/command/commands.c30
-rw-r--r--src/config/preferences.c38
-rw-r--r--src/config/preferences.h7
-rw-r--r--src/ui/console.c6
-rw-r--r--src/ui/window.c5
6 files changed, 93 insertions, 9 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 83f9d660..f4add150 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -169,9 +169,9 @@ static struct cmd_t command_defs[] =
 
     { "/roster",
         cmd_roster, parse_args_with_freetext, 0, 3, NULL,
-        { "/roster [show|hide|by|add|remove|nick|clearnick] [offline|resource] [group|presence|none] [jid] [nickname]", "Manage your roster.",
-        { "/roster [show|hide|by|add|remove|nick|clearnick] [offline|resource] [group|presence|none] [jid] [nickname]",
-          "----------------------------------------------------------------------------------------------------------",
+        { "/roster [show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", "Manage your roster.",
+        { "/roster [show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]",
+          "-------------------------------------------------------------------------------------------------------------------------",
           "View, add to, and remove from your roster.",
           "Passing no arguments lists all contacts in your roster.",
           "show          - Show the roster panel in the console window.",
@@ -183,6 +183,7 @@ static struct cmd_t command_defs[] =
           "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.",
+          "size          - Percentage of the screen taken up by the roster (1-99).",
           "add           - Add a new item, jid is required, nickname is optional.",
           "remove        - Removes a contact, jid is required.",
           "nick          - Changes a contacts nickname, both jid and nickname are required,",
@@ -383,12 +384,13 @@ static struct cmd_t command_defs[] =
 
     { "/occupants",
         cmd_occupants, parse_args, 1, 2, &cons_occupants_setting,
-        { "/occupants show|hide|default [show|hide]", "Show or hide room occupants.",
-        { "/occupants show|hide|default [show|hide]",
-          "----------------------------------------",
+        { "/occupants show|hide|default|size [show|hide] [percent]", "Show or hide room occupants.",
+        { "/occupants show|hide|default|size [show|hide] [percent]",
+          "-------------------------------------------------------",
           "show    - Show the occupants panel in chat rooms.",
           "hide    - Hide the occupants panel in chat rooms.",
           "default - Whether occupants are shown by default in new rooms, 'show' or 'hide'",
+          "size    - Percentage of the screen taken by the occupants list in rooms (1-99).",
           NULL } } },
 
     { "/form",
@@ -1244,6 +1246,7 @@ cmd_init(void)
     autocomplete_add(roster_ac, "show");
     autocomplete_add(roster_ac, "hide");
     autocomplete_add(roster_ac, "by");
+    autocomplete_add(roster_ac, "size");
 
     roster_option_ac = autocomplete_new();
     autocomplete_add(roster_option_ac, "offline");
@@ -1388,6 +1391,7 @@ cmd_init(void)
     autocomplete_add(occupants_ac, "show");
     autocomplete_add(occupants_ac, "hide");
     autocomplete_add(occupants_ac, "default");
+    autocomplete_add(occupants_ac, "size");
 
     occupants_default_ac = autocomplete_new();
     autocomplete_add(occupants_default_ac, "show");
diff --git a/src/command/commands.c b/src/command/commands.c
index cfc10024..3ae0015d 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1330,6 +1330,23 @@ cmd_roster(gchar **args, struct cmd_help_t help)
         cons_show_roster(list);
         return TRUE;
 
+    // set roster size
+    } else if (g_strcmp0(args[0], "size") == 0) {
+        int intval = 0;
+        if (!args[1]) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        } else if (_strtoi(args[1], &intval, 1, 99) == 0) {
+            prefs_set_roster_size(intval);
+            cons_show("Roster screen size set to: %d%%", intval);
+            if (prefs_get_boolean(PREF_ROSTER)) {
+                wins_resize_all();
+            }
+            return TRUE;
+        } else {
+            return TRUE;
+        }
+
     // show/hide roster
     } else if (g_strcmp0(args[0], "show") == 0) {
         if (args[1] == NULL) {
@@ -2491,6 +2508,19 @@ cmd_occupants(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
+    if (g_strcmp0(args[0], "size") == 0) {
+        int intval = 0;
+        if (!args[1]) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        } else if (_strtoi(args[1], &intval, 1, 99) == 0) {
+            prefs_set_occupants_size(intval);
+            cons_show("Occupants screen size set to: %d%%", intval);
+            wins_resize_all();
+            return TRUE;
+        }
+    }
+
     if (g_strcmp0(args[0], "default") == 0) {
         if (g_strcmp0(args[1], "show") == 0) {
             cons_show("Occupant list enabled.");
diff --git a/src/config/preferences.c b/src/config/preferences.c
index c5ec842e..60d6d831 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -316,6 +316,44 @@ prefs_set_autoaway_time(gint value)
     _save_prefs();
 }
 
+void
+prefs_set_occupants_size(gint value)
+{
+    g_key_file_set_integer(prefs, PREF_GROUP_UI, "occupants.size", value);
+    _save_prefs();
+}
+
+gint
+prefs_get_occupants_size(void)
+{
+    gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "occupants.size", NULL);
+
+    if (result > 99 || result < 1) {
+        return 20;
+    } else {
+        return result;
+    }
+}
+
+void
+prefs_set_roster_size(gint value)
+{
+    g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.size", value);
+    _save_prefs();
+}
+
+gint
+prefs_get_roster_size(void)
+{
+    gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.size", NULL);
+
+    if (result > 99 || result < 1) {
+        return 20;
+    } else {
+        return result;
+    }
+}
+
 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 ec697845..b1536507 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -58,7 +58,9 @@ typedef enum {
     PREF_HISTORY,
     PREF_MOUSE,
     PREF_OCCUPANTS,
+    PREF_OCCUPANTS_SIZE,
     PREF_ROSTER,
+    PREF_ROSTER_SIZE,
     PREF_ROSTER_OFFLINE,
     PREF_ROSTER_RESOURCE,
     PREF_ROSTER_BY,
@@ -121,6 +123,11 @@ gint prefs_get_reconnect(void);
 void prefs_set_autoping(gint value);
 gint prefs_get_autoping(void);
 
+void prefs_set_occupants_size(gint value);
+gint prefs_get_occupants_size(void);
+void prefs_set_roster_size(gint value);
+gint prefs_get_roster_size(void);
+
 gint prefs_get_autoaway_time(void);
 void prefs_set_autoaway_time(gint value);
 
diff --git a/src/ui/console.c b/src/ui/console.c
index d4f6bcc9..9f9b9e2a 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -883,6 +883,9 @@ _cons_occupants_setting(void)
         cons_show("Occupants (/occupants)        : show");
     else
         cons_show("Occupants (/occupants)        : hide");
+
+    int size = prefs_get_occupants_size();
+    cons_show("Occupants size (/occupants)   : %d", size);
 }
 
 static void
@@ -958,6 +961,9 @@ _cons_roster_setting(void)
         cons_show("Roster resource (/roster)     : show");
     else
         cons_show("Roster resource (/roster)     : hide");
+
+    int size = prefs_get_roster_size();
+    cons_show("Roster size (/roster)         : %d", size);
 }
 
 static void
diff --git a/src/ui/window.c b/src/ui/window.c
index 13b84b73..4cd2af66 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -53,9 +53,6 @@
 
 #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
 
-static int roster_win_percent = 20;
-static int occupants_win_percent = 20;
-
 static void _win_print(ProfWin *window, const char show_char, const char * const date_fmt,
     int flags, int attrs, const char * const from, const char * const message);
 static void _win_print_wrapped(WINDOW *win, const char * const message);
@@ -63,6 +60,7 @@ static void _win_print_wrapped(WINDOW *win, const char * const message);
 int
 win_roster_cols(void)
 {
+    int roster_win_percent = prefs_get_roster_size();
     int cols = getmaxx(stdscr);
     return CEILING( (((double)cols) / 100) * roster_win_percent);
 }
@@ -70,6 +68,7 @@ win_roster_cols(void)
 int
 win_occpuants_cols(void)
 {
+    int occupants_win_percent = prefs_get_occupants_size();
     int cols = getmaxx(stdscr);
     return CEILING( (((double)cols) / 100) * occupants_win_percent);
 }