Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-common / core / hilight-text.c
index 4d5466e288065fd048a74b27e2065269975fdb30..4a913ee6535b0137eeb088613113287d47e95d3b 100644 (file)
@@ -112,12 +112,38 @@ static void hilights_destroy_all(void)
        hilights = NULL;
 }
 
-static void hilight_remove(HILIGHT_REC *rec)
+static void hilight_init_rec(HILIGHT_REC *rec)
+{
+#ifdef HAVE_REGEX_H
+       if (rec->regexp_compiled) regfree(&rec->preg);
+       rec->regexp_compiled = !rec->regexp ? FALSE :
+               regcomp(&rec->preg, rec->text, REG_EXTENDED|REG_ICASE) == 0;
+#endif
+}
+
+void hilight_create(HILIGHT_REC *rec)
+{
+       if (g_slist_find(hilights, rec) != NULL) {
+               hilight_remove_config(rec);
+               hilights = g_slist_remove(hilights, rec);
+       }
+
+       hilights = g_slist_append(hilights, rec);
+       hilight_add_config(rec);
+
+       hilight_init_rec(rec);
+
+       signal_emit("hilight created", 1, rec);
+}
+
+void hilight_remove(HILIGHT_REC *rec)
 {
        g_return_if_fail(rec != NULL);
 
        hilight_remove_config(rec);
        hilights = g_slist_remove(hilights, rec);
+
+       signal_emit("hilight destroyed", 1, rec);
        hilight_destroy(rec);
 }
 
@@ -253,7 +279,7 @@ static char *hilight_get_act_color(HILIGHT_REC *rec)
                        settings_get_str("hilight_act_color"));
 }
 
-static char *hilight_get_color(HILIGHT_REC *rec)
+char *hilight_get_color(HILIGHT_REC *rec)
 {
        const char *color;
 
@@ -265,7 +291,7 @@ static char *hilight_get_color(HILIGHT_REC *rec)
        return format_string_expand(color, NULL);
 }
 
-static void hilight_update_text_dest(TEXT_DEST_REC *dest, HILIGHT_REC *rec)
+void hilight_update_text_dest(TEXT_DEST_REC *dest, HILIGHT_REC *rec)
 {
        dest->level |= MSGLEVEL_HILIGHT;
 
@@ -279,6 +305,8 @@ static void hilight_update_text_dest(TEXT_DEST_REC *dest, HILIGHT_REC *rec)
                dest->hilight_color = hilight_get_act_color(rec);
 }
 
+static void hilight_print(int index, HILIGHT_REC *rec);
+
 static void sig_print_text(TEXT_DEST_REC *dest, const char *text,
                           const char *stripped)
 {
@@ -372,19 +400,15 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text,
        signal_stop();
 }
 
-char *hilight_match_nick(SERVER_REC *server, const char *channel,
+HILIGHT_REC *hilight_match_nick(SERVER_REC *server, const char *channel,
                         const char *nick, const char *address,
                         int level, const char *msg)
 {
         HILIGHT_REC *rec;
-       char *color;
 
        rec = hilight_match(server, channel, nick, address,
                            level, msg, NULL, NULL);
-       color = rec == NULL || !rec->nick ? NULL :
-               hilight_get_color(rec);
-
-       return color;
+       return (rec == NULL || !rec->nick) ? NULL : rec;
 }
 
 static void read_hilight_config(void)
@@ -435,11 +459,7 @@ static void read_hilight_config(void)
                rec->fullword = config_node_get_bool(node, "fullword", FALSE);
                rec->regexp = config_node_get_bool(node, "regexp", FALSE);
 
-#ifdef HAVE_REGEX_H
-               rec->regexp_compiled = !rec->regexp ? FALSE :
-                       regcomp(&rec->preg, rec->text,
-                               REG_EXTENDED|REG_ICASE) == 0;
-#endif
+               hilight_init_rec(rec);
 
                node = config_node_section(node, "channels", -1);
                if (node != NULL) rec->channels = config_node_get_list(node);
@@ -451,20 +471,45 @@ static void read_hilight_config(void)
 static void hilight_print(int index, HILIGHT_REC *rec)
 {
        char *chans, *levelstr;
+       GString *options;
+
+       options = g_string_new(NULL);
+       if (!rec->nick || !rec->word) {
+               if (rec->nick) g_string_append(options, "-nick ");
+               if (rec->word) g_string_append(options, "-word ");
+       }
+
+       if (rec->nickmask) g_string_append(options, "-nickmask ");
+       if (rec->fullword) g_string_append(options, "-fullword ");
+       if (rec->regexp) {
+               g_string_append(options, "-regexp ");
+#ifdef HAVE_REGEX_H
+               if (!rec->regexp_compiled)
+                       g_string_append(options, "[INVALID!] ");
+#endif
+       }
+
+       if (rec->priority != 0)
+               g_string_sprintfa(options, "-priority %d ", rec->priority);
+       if (rec->color != NULL)
+               g_string_sprintfa(options, "-color %s ", rec->color);
+       if (rec->act_color != NULL)
+               g_string_sprintfa(options, "-actcolor %s ", rec->act_color);
 
        chans = rec->channels == NULL ? NULL :
                g_strjoinv(",", rec->channels);
        levelstr = rec->level == 0 ? NULL :
                bits2level(rec->level);
+       if (levelstr != NULL)
+               levelstr = g_strconcat(levelstr, " ", NULL);
        printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
                    TXT_HILIGHT_LINE, index, rec->text,
                    chans != NULL ? chans : "",
                    levelstr != NULL ? levelstr : "",
-                   rec->nickmask ? " -mask" : "",
-                   rec->fullword ? " -full" : "",
-                   rec->regexp ? " -regexp" : "");
+                   options->str);
        g_free_not_null(chans);
        g_free_not_null(levelstr);
+       g_string_free(options, TRUE);
 }
 
 static void cmd_hilight_show(void)
@@ -527,9 +572,6 @@ static void cmd_hilight(const char *data)
                rec->channels = channels;
        } else {
                g_strfreev(channels);
-
-                hilight_remove_config(rec);
-               hilights = g_slist_remove(hilights, rec);
        }
 
        rec->level = (levelarg == NULL || *levelarg == '\0') ? 0 :
@@ -564,15 +606,7 @@ static void cmd_hilight(const char *data)
                        rec->act_color = g_strdup(actcolorarg);
        }
 
-#ifdef HAVE_REGEX_H
-       if (rec->regexp_compiled)
-               regfree(&rec->preg);
-       rec->regexp_compiled = !rec->regexp ? FALSE :
-               regcomp(&rec->preg, rec->text, REG_EXTENDED|REG_ICASE) == 0;
-#endif
-
-       hilights = g_slist_append(hilights, rec);
-       hilight_add_config(rec);
+       hilight_create(rec);
 
        hilight_print(g_slist_index(hilights, rec)+1, rec);
         cmd_params_free(free_arg);
@@ -640,14 +674,14 @@ static void hilight_nick_cache(GHashTable *list, CHANNEL_REC *channel,
 
 static void read_settings(void)
 {
-       default_hilight_level = level2bits(settings_get_str("hilight_level"));
+       default_hilight_level = settings_get_level("hilight_level");
 }
 
 void hilight_text_init(void)
 {
        settings_add_str("lookandfeel", "hilight_color", "%Y");
        settings_add_str("lookandfeel", "hilight_act_color", "%M");
-       settings_add_str("lookandfeel", "hilight_level", "PUBLIC DCCMSGS");
+       settings_add_level("lookandfeel", "hilight_level", "PUBLIC DCCMSGS");
 
         read_settings();