about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-10 19:10:10 +0000
committerJames Booth <boothj5@gmail.com>2015-01-10 19:10:10 +0000
commit31c0f2ba788b19d776da5e7368280091c8d3bbdf (patch)
tree853f4556b2fd37c299c7dc3b0f1a3f9459f021ea
parentc3ad3c0ba692613c6b26203d1328e42899775b0f (diff)
downloadprofani-tty-31c0f2ba788b19d776da5e7368280091c8d3bbdf.tar.gz
Added preferences for showing resource in titlebar and messages
-rw-r--r--src/command/command.c28
-rw-r--r--src/command/commands.c25
-rw-r--r--src/config/preferences.c6
-rw-r--r--src/config/preferences.h4
-rw-r--r--src/ui/console.c14
-rw-r--r--src/ui/core.c4
-rw-r--r--src/ui/titlebar.c2
-rw-r--r--src/ui/ui.h1
-rw-r--r--tests/ui/stub_ui.c1
9 files changed, 70 insertions, 15 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 7fd1616e..b225f45d 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -278,13 +278,15 @@ static struct cmd_t command_defs[] =
           NULL } } },
 
     { "/resource",
-        cmd_resource, parse_args, 1, 2, NULL,
-        { "/resource set|off [resource]", "Set the contact's resource.",
-        { "/resource set|off [resource]",
-          "----------------------------",
-          "Set the resource to use when chatting to a contact.",
-          "set resource - Set the resource.",
-          "off          - Let the server choose which resource to route messages to.",
+        cmd_resource, parse_args, 1, 2, &cons_resource_setting,
+        { "/resource set|off|title|message [resource]", "Set the contact's resource.",
+        { "/resource set|off|title|message [resource]",
+          "------------------------------------------",
+          "Set the resource to use when chatting to a contact and manage resource display settings.",
+          "set resource   - Set the resource.",
+          "off            - Let the server choose which resource to route messages to.",
+          "title on|off   - Show or hide the current resource in the titlebar.",
+          "message on|off - Show or hide the resource from which a message was recieved.",
           NULL } } },
 
     { "/join",
@@ -1455,6 +1457,8 @@ cmd_init(void)
     resource_ac = autocomplete_new();
     autocomplete_add(resource_ac, "set");
     autocomplete_add(resource_ac, "off");
+    autocomplete_add(resource_ac, "title");
+    autocomplete_add(resource_ac, "message");
 
     cmd_history_init();
 }
@@ -2462,6 +2466,16 @@ _resource_autocomplete(char *input, int *size)
         }
     }
 
+    found = autocomplete_param_with_func(input, size, "/resource title", prefs_autocomplete_boolean_choice);
+    if (found != NULL) {
+        return found;
+    }
+
+    found = autocomplete_param_with_func(input, size, "/resource message", prefs_autocomplete_boolean_choice);
+    if (found != NULL) {
+        return found;
+    }
+
     found = autocomplete_param_with_ac(input, size, "/resource", resource_ac, FALSE);
     if (found != NULL) {
         return found;
diff --git a/src/command/commands.c b/src/command/commands.c
index 7f902836..12c6ba48 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1582,16 +1582,33 @@ cmd_roster(gchar **args, struct cmd_help_t help)
 gboolean
 cmd_resource(gchar **args, struct cmd_help_t help)
 {
+    char *cmd = args[0];
+    char *setting = NULL;
+    if (g_strcmp0(cmd, "message") == 0) {
+        setting = args[1];
+        if (!setting) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        } else {
+            return _cmd_set_boolean_preference(setting, help, "Message resource", PREF_RESOURCE_MESSAGE);
+        }
+    } else if (g_strcmp0(cmd, "title") == 0) {
+        setting = args[1];
+        if (!setting) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        } else {
+            return _cmd_set_boolean_preference(setting, help, "Title resource", PREF_RESOURCE_TITLE);
+        }
+    }
+
     ProfWin *current = wins_get_current();
     if (current->type != WIN_CHAT) {
-        cons_show("The /resource command is only valid in chat windows.");
+        cons_show("Resource can only be changed in chat windows.");
         return TRUE;
     }
-
     ProfChatWin *chatwin = (ProfChatWin*)current;
 
-    char *cmd = args[0];
-
     if (g_strcmp0(cmd, "set") == 0) {
         char *resource = args[1];
         if (!resource) {
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 22e80874..aeff94f1 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -514,6 +514,8 @@ _get_group(preference_t pref)
         case PREF_ROSTER_OFFLINE:
         case PREF_ROSTER_RESOURCE:
         case PREF_ROSTER_BY:
+        case PREF_RESOURCE_TITLE:
+        case PREF_RESOURCE_MESSAGE:
             return PREF_GROUP_UI;
         case PREF_STATES:
         case PREF_OUTTYPE:
@@ -647,6 +649,10 @@ _get_key(preference_t pref)
             return "roster.resource";
         case PREF_ROSTER_BY:
             return "roster.by";
+        case PREF_RESOURCE_TITLE:
+            return "resource.title";
+        case PREF_RESOURCE_MESSAGE:
+            return "resource.message";
         default:
             return NULL;
     }
diff --git a/src/config/preferences.h b/src/config/preferences.h
index c8b206ef..54b4cefe 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -95,7 +95,9 @@ typedef enum {
     PREF_LOG_SHARED,
     PREF_OTR_LOG,
     PREF_OTR_WARN,
-    PREF_OTR_POLICY
+    PREF_OTR_POLICY,
+    PREF_RESOURCE_TITLE,
+    PREF_RESOURCE_MESSAGE
 } preference_t;
 
 typedef struct prof_alias_t {
diff --git a/src/ui/console.c b/src/ui/console.c
index 3d3a5d8b..52ccf990 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -841,6 +841,19 @@ cons_beep_setting(void)
 }
 
 void
+cons_resource_setting(void)
+{
+    if (prefs_get_boolean(PREF_RESOURCE_TITLE))
+        cons_show("Resource title (/resource)    : ON");
+    else
+        cons_show("Resource title (/resource)    : OFF");
+    if (prefs_get_boolean(PREF_RESOURCE_MESSAGE))
+        cons_show("Message title (/resource)     : ON");
+    else
+        cons_show("Message title (/resource)     : OFF");
+}
+
+void
 cons_wrap_setting(void)
 {
     if (prefs_get_boolean(PREF_WRAP))
@@ -991,6 +1004,7 @@ cons_show_ui_prefs(void)
     cons_splash_setting();
     cons_wrap_setting();
     cons_time_setting();
+    cons_resource_setting();
     cons_vercheck_setting();
     cons_mouse_setting();
     cons_statuses_setting();
diff --git a/src/ui/core.c b/src/ui/core.c
index 08f45fb5..4866a8f2 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -341,10 +341,10 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
             g_string_append(user, barejid);
         }
     } else {
-        g_string_append(user,barejid);
+        g_string_append(user, barejid);
     }
 
-    if (resource) {
+    if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
         g_string_append(user, "/");
         g_string_append(user, resource);
     }
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index 21e904ac..326dbf8b 100644
--- a/src/ui/titlebar.c
+++ b/src/ui/titlebar.c
@@ -316,7 +316,7 @@ _show_contact_presence(ProfChatWin *chatwin)
     } else if (session && session->resource) {
         resource = session->resource;
     }
-    if (resource) {
+    if (resource && prefs_get_boolean(PREF_RESOURCE_TITLE)) {
         wprintw(win, "/");
         wprintw(win, resource);
     }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 08d67ec6..0056b7af 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -286,6 +286,7 @@ void cons_show_received_subs(void);
 void cons_show_sent_subs(void);
 void cons_alert(void);
 void cons_theme_setting(void);
+void cons_resource_setting(void);
 void cons_privileges_setting(void);
 void cons_beep_setting(void);
 void cons_flash_setting(void);
diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c
index e13d9cea..5465e68d 100644
--- a/tests/ui/stub_ui.c
+++ b/tests/ui/stub_ui.c
@@ -436,6 +436,7 @@ void cons_beep_setting(void) {}
 void cons_flash_setting(void) {}
 void cons_splash_setting(void) {}
 void cons_vercheck_setting(void) {}
+void cons_resource_setting(void) {}
 void cons_occupants_setting(void) {}
 void cons_roster_setting(void) {}
 void cons_presence_setting(void) {}