changeset 1298:af035a304bec

colorable muc nick fix When ctrl+l is pressed, no error message is printed Added command to recolor someone
author Michal 'vorner' Vaner <vorner@ucw.cz>
date Tue, 28 Aug 2007 18:56:50 +0200
parents 60663a1f9e8d
children 3b338a5c01fc
files mcabber/doc/help/en/hlp_color.txt mcabber/src/screen.c
diffstat 2 files changed, 42 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/doc/help/en/hlp_color.txt	Tue Aug 28 17:13:29 2007 +0200
+++ b/mcabber/doc/help/en/hlp_color.txt	Tue Aug 28 18:56:50 2007 +0200
@@ -11,8 +11,8 @@
  Set a color rule (or overwrite, if it already exists). The status is string containing all statuses the roster item can have for the rule to match, or * if any status is OK. Wildcard is the file-matching wildcard that will be applied to JID. Color is the wanted color.
  If color is -, the rule is removed.
  If more than one rule matches, the color from the last created (not overwritten) is used.
-/color mucnick nick (color|-)
- Marks the nick to be colored by given color. If a muc has colored nicks, this one will be used. If color is -, the color is marked as chosen automatically, which means it will not be used in 'preset' coloring mode, but will stay the same in 'on' coloring mode.
+/color mucnick nick (color|-|!)
+ Marks the nick to be colored by given color. If a muc has colored nicks, this one will be used. If color is -, the color is marked as chosen automatically, which means it will not be used in 'preset' coloring mode, but will stay the same in 'on' coloring mode. If the color is !, a new color is randomly choosen and marked automatic.
 /color muc (jid|.|*) [on|preset|off|-]
  Sets a muc nick coloring mode. If a jid (. means currently selected jid) is provided, the mode will apply to this specific MUC. If * is used, it will be applied to all MUCs, except the ones set by their jid.
  Mode 'on' colors all nicks, 'preset' only the ones manually set by /color mucnick command and 'off' colors none. If not specified, defaults to 'on' Mode '-' removes the mode from given JID, which means the global one will apply. You can not remove the global mode.
--- a/mcabber/src/screen.c	Tue Aug 28 17:13:29 2007 +0200
+++ b/mcabber/src/screen.c	Tue Aug 28 18:56:50 2007 +0200
@@ -317,6 +317,15 @@
     g_free(snick);//They are not saved in the hash
     g_free(mnick);
     need_update = true;
+  } else if (!strcmp(color, "!")) {
+    if (nickcolors) {
+      g_free(g_hash_table_lookup(nickcolors, snick));
+      g_hash_table_remove(nickcolors, snick);
+      g_hash_table_remove(nickcolors, mnick);
+    }
+    g_free(snick);//They are not saved in the hash
+    g_free(mnick);
+    need_update = true;
   } else {
     int cl = get_user_color(color);
     if (cl < 0) {
@@ -507,39 +516,41 @@
     if (i >= COLOR_BLACK_BOLD_FG)
       COLOR_ATTRIB[i] = A_BOLD;
   }
-  char *ncolors = g_strdup(settings_opt_get("nick_colors")),
-      *ncolor_start = ncolors;
-  if (ncolors) {
-    while (*ncolors) {
-      if ((*ncolors == ' ') || (*ncolors == '\t')) {
-        ncolors ++;
-      } else {
-        char *end = ncolors;
-        bool ended = false;
-        while (*end && (*end != ' ') && (*end != '\t'))
-          end++;
-        if (!end)
-          ended = true;
-        *end = '\0';
-        int cl = get_user_color(ncolors);
-        if (cl < 0) {
-          scr_LogPrint(LPRINT_NORMAL, "Unknown color %s", ncolors);
+  if (!nickcols) {
+    char *ncolors = g_strdup(settings_opt_get("nick_colors")),
+         *ncolor_start = ncolors;
+    if (ncolors) {
+      while (*ncolors) {
+        if ((*ncolors == ' ') || (*ncolors == '\t')) {
+          ncolors ++;
         } else {
-          nickcols = g_realloc(nickcols, (++nickcolcount) * sizeof *nickcols);
-          nickcols[nickcolcount-1] = cl;
+          char *end = ncolors;
+          bool ended = false;
+          while (*end && (*end != ' ') && (*end != '\t'))
+            end++;
+          if (!end)
+            ended = true;
+          *end = '\0';
+          int cl = get_user_color(ncolors);
+          if (cl < 0) {
+            scr_LogPrint(LPRINT_NORMAL, "Unknown color %s", ncolors);
+          } else {
+            nickcols = g_realloc(nickcols, (++nickcolcount) * sizeof *nickcols);
+            nickcols[nickcolcount-1] = cl;
+          }
+          if (ended)
+            ncolors = NULL;
+          else
+            ncolors = end+1;
         }
-        if (ended)
-          ncolors = NULL;
-        else
-          ncolors = end+1;
       }
+      g_free(ncolor_start);
     }
-    g_free(ncolor_start);
-  }
-  if (!nickcols) {//Fallback to have something
-    nickcolcount = 1;
-    nickcols = g_new(int, 1);
-    *nickcols = COLOR_GENERAL;
+    if (!nickcols) {//Fallback to have something
+      nickcolcount = 1;
+      nickcols = g_new(int, 1);
+      *nickcols = COLOR_GENERAL;
+    }
   }
 }