changeset 23311:ea341703b1d3

msgcolor command to change colors of messages in conversations.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 07 Jun 2008 05:23:54 +0000
parents f3b7a07a7607
children a3759c05cc5b 2338f36b41ad
files ChangeLog finch/gntconv.c finch/libgnt/gntcolors.c finch/libgnt/gntcolors.h
diffstat 4 files changed, 56 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jun 07 01:58:23 2008 +0000
+++ b/ChangeLog	Sat Jun 07 05:23:54 2008 +0000
@@ -22,6 +22,8 @@
 	* Added "Invite..." menu to chats.
 	* Added "View All Logs" menu in the buddylist to display a list of all IM
 	  logs.
+	* Added '/msgcolor' command to change colors of different classes of
+	  messages in a conversation. See '/help msgcolor' for details.
 
 version 2.4.2 (05/17/2008):
 	libpurple:
--- a/finch/gntconv.c	Sat Jun 07 01:58:23 2008 +0000
+++ b/finch/gntconv.c	Sat Jun 07 05:23:54 2008 +0000
@@ -1241,6 +1241,47 @@
 }
 
 static PurpleCmdRet
+cmd_message_color(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data)
+{
+	int *msgclass  = NULL;
+	int fg, bg;
+
+	if (strcmp(args[0], "receive") == 0)
+		msgclass = &color_message_receive;
+	else if (strcmp(args[0], "send") == 0)
+		msgclass = &color_message_send;
+	else if (strcmp(args[0], "highlight") == 0)
+		msgclass = &color_message_highlight;
+	else if (strcmp(args[0], "action") == 0)
+		msgclass = &color_message_action;
+	else if (strcmp(args[0], "timestamp") == 0)
+		msgclass = &color_timestamp;
+	else {
+		if (error)
+			*error = g_strdup_printf(_("%s is not a valid message class. See '/help msgcolor' for valid message classes."), args[0]);
+		return PURPLE_CMD_STATUS_FAILED;
+	}
+
+	fg = gnt_colors_get_color(args[1]);
+	if (fg == -EINVAL) {
+		if (error)
+			*error = g_strdup_printf(_("%s is not a valid color. See '/help msgcolor' for valid colors."), args[1]);
+		return PURPLE_CMD_STATUS_FAILED;
+	}
+
+	bg = gnt_colors_get_color(args[2]);
+	if (bg == -EINVAL) {
+		if (error)
+			*error = g_strdup_printf(_("%s is not a valid color. See '/help msgcolor' for valid colors."), args[2]);
+		return PURPLE_CMD_STATUS_FAILED;
+	}
+
+	init_pair(*msgclass, fg, bg);
+
+	return PURPLE_CMD_STATUS_OK;
+}
+
+static PurpleCmdRet
 users_command_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data)
 {
 	FinchConv *fc = FINCH_GET_DATA(conv);
@@ -1324,6 +1365,16 @@
 	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL,
 	                  cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all);
 
+	/* Allow customizing the message colors using a command during run-time */
+	purple_cmd_register("msgcolor", "www", PURPLE_CMD_P_DEFAULT,
+			PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL,
+			cmd_message_color, _("msgcolor &lt;class&gt; &lt;foreground&gt; &lt;background&gt;: "
+				                 "Set the color for different classes of messages in the conversation window.<br>"
+				                 "    &lt;class&gt;: receive, send, highlight, action, timestamp<br>"
+				                 "    &lt;foreground/background&gt;: black, red, green, blue, white, gray, darkgray, magenta, cyan, default<br><br>"
+								 "EXAMPLE:<br>    msgcolor send cyan default"),
+			NULL);
+
 	purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(),
 					PURPLE_CALLBACK(update_buddy_typing), NULL);
 	purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(),
--- a/finch/libgnt/gntcolors.c	Sat Jun 07 01:58:23 2008 +0000
+++ b/finch/libgnt/gntcolors.c	Sat Jun 07 05:23:54 2008 +0000
@@ -29,6 +29,7 @@
 
 #include <glib.h>
 
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -168,7 +169,7 @@
 		color = -1;
 	else {
 		g_warning("Invalid color name: %s\n", key);
-		color = -1;
+		color = -EINVAL;
 	}
 	return color;
 }
--- a/finch/libgnt/gntcolors.h	Sat Jun 07 01:58:23 2008 +0000
+++ b/finch/libgnt/gntcolors.h	Sat Jun 07 05:23:54 2008 +0000
@@ -91,7 +91,7 @@
  *
  * @param kfile The string value
  *
- * @return A color
+ * @return A color. For an unknown color name, returns -EINVAL.
  *
  * @since 2.4.0
  */