pidgin: 23913fa1: msgcolor command to change colors of mes...

sadrul at pidgin.im sadrul at pidgin.im
Sat Jun 7 01:25:45 EDT 2008


-----------------------------------------------------------------
Revision: 23913fa16455106d8848482b13e9a49b823e6051
Ancestor: ddf9a92e5eff18d5dc957a19bc6b7d918904848b
Author: sadrul at pidgin.im
Date: 2008-06-07T05:23:54
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/23913fa16455106d8848482b13e9a49b823e6051

Modified files:
        ChangeLog finch/gntconv.c finch/libgnt/gntcolors.c
        finch/libgnt/gntcolors.h

ChangeLog: 

msgcolor command to change colors of messages in conversations.

-------------- next part --------------
============================================================
--- ChangeLog	e5d7d1895de54297c3f54f89134fbfbe7dd5828f
+++ ChangeLog	61b28c31c17f56852cc8a906fffe3c6687f6db59
@@ -22,6 +22,8 @@ version 2.5.0 (??/??/2008):
 	* 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:
============================================================
--- finch/gntconv.c	dcd3cdd7ca031dc38243c954152a5eeeaf61cb64
+++ finch/gntconv.c	088bc26dadc8d897d322f22a5e5b2d1a22c69b01
@@ -1241,6 +1241,47 @@ static PurpleCmdRet
 }
 
 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 @@ void finch_conversation_init()
 	                  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 <class> <foreground> <background>: "
+				                 "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(),
============================================================
--- finch/libgnt/gntcolors.c	8829628b201259705884de48ead1eddad1a09a8d
+++ finch/libgnt/gntcolors.c	76355879e5ead1f05d0b76517b75cb075cf46808
@@ -29,6 +29,7 @@
 
 #include <glib.h>
 
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -168,7 +169,7 @@ gnt_colors_get_color(char *key)
 		color = -1;
 	else {
 		g_warning("Invalid color name: %s\n", key);
-		color = -1;
+		color = -EINVAL;
 	}
 	return color;
 }
============================================================
--- finch/libgnt/gntcolors.h	d1bb00c5ac473a505f1ddfd0b24de0c36c555785
+++ finch/libgnt/gntcolors.h	536808222410f1ed9c004e6c9f320f9249226346
@@ -91,7 +91,7 @@ void gnt_color_pairs_parse(GKeyFile *kfi
  *
  * @param kfile The string value
  *
- * @return A color
+ * @return A color. For an unknown color name, returns -EINVAL.
  *
  * @since 2.4.0
  */


More information about the Commits mailing list