Added SILC Thread Queue API
[runtime.git] / apps / irssi / src / core / expandos.c
index 130d6025d3e2ad1bb023f9221401a8df471c02e1..0d7a6141267f29a3933a725a6c989956ff49ff1f 100644 (file)
@@ -18,6 +18,7 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#include "core.h"
 #include "module.h"
 #include "modules.h"
 #include "signals.h"
@@ -46,11 +47,12 @@ typedef struct {
         int signal_args[MAX_EXPANDO_SIGNALS];
 } EXPANDO_REC;
 
+const char *current_expando = NULL;
+
 static int timer_tag;
 
 static EXPANDO_REC *char_expandos[255];
 static GHashTable *expandos;
-static time_t client_start_time;
 static char *last_sent_msg, *last_sent_msg_body;
 static char *last_privmsg_from, *last_public_from;
 static char *sysname, *sysrelease, *sysarch;
@@ -131,7 +133,7 @@ void expando_add_signal(const char *key, const char *signal, ExpandoArg arg)
 /* Destroy expando */
 void expando_destroy(const char *key, EXPANDO_FUNC func)
 {
-       gpointer origkey;
+       gpointer origkey, value;
         EXPANDO_REC *rec;
 
        g_return_if_fail(key != NULL || *key == '\0');
@@ -144,8 +146,9 @@ void expando_destroy(const char *key, EXPANDO_FUNC func)
                        char_expandos[(int) (unsigned char) *key] = NULL;
                        g_free(rec);
                }
-       } else if (g_hash_table_lookup_extended(expandos, key, &origkey,
-                                               (gpointer *) &rec)) {
+       } else if (g_hash_table_lookup_extended(expandos, key,
+                                               &origkey, &value)) {
+               rec = value;
                if (rec->func == func) {
                        g_hash_table_remove(expandos, key);
                        g_free(origkey);
@@ -179,7 +182,8 @@ void expando_bind(const char *key, int funccount, SIGNAL_FUNC *funcs)
                func = arg < funccount ? funcs[arg] : NULL;
                if (func == NULL) func = funcs[EXPANDO_ARG_NONE];
 
-               signal_add_to_id(MODULE_NAME, 1, rec->signal_ids[n], func);
+               signal_add_full_id(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT,
+                                  rec->signal_ids[n], func, NULL);
        }
 }
 
@@ -208,7 +212,7 @@ void expando_unbind(const char *key, int funccount, SIGNAL_FUNC *funcs)
                func = arg < funccount ? funcs[arg] : NULL;
                if (func == NULL) func = funcs[EXPANDO_ARG_NONE];
 
-               signal_remove_id(rec->signal_ids[n], func);
+               signal_remove_id(rec->signal_ids[n], func, NULL);
        }
 }
 
@@ -256,6 +260,13 @@ EXPANDO_FUNC expando_find_long(const char *key)
        return rec == NULL ? NULL : rec->func;
 }
 
+static gboolean free_expando(gpointer key, gpointer value, gpointer user_data)
+{
+       g_free(key);
+       g_free(value);
+       return TRUE;
+}
+
 /* last person who sent you a MSG */
 static char *expando_lastmsg(SERVER_REC *server, void *item, int *free_ret)
 {
@@ -317,10 +328,36 @@ static char *expando_cmdchars(SERVER_REC *server, void *item, int *free_ret)
        return (char *) settings_get_str("cmdchars");
 }
 
+/* first CMDCHAR */
+static char *expando_cmdchar(SERVER_REC *server, void *item, int *free_ret)
+{
+       char str[2] = { 0, 0 };
+
+       str[0] = *settings_get_str("cmdchars");
+
+       *free_ret = TRUE;
+       return g_strdup(str);
+}
+
 /* modes of current channel, if any */
 static char *expando_chanmode(SERVER_REC *server, void *item, int *free_ret)
-{
-       return !IS_CHANNEL(item) ? NULL : CHANNEL(item)->mode;
+{ 
+       char *cmode;
+
+       *free_ret = FALSE;
+
+       if (!IS_CHANNEL(item))
+               return NULL;
+
+        if (!settings_get_bool("chanmode_expando_strip"))
+               return CHANNEL(item)->mode;
+
+       *free_ret = TRUE;
+       cmode = g_strdup(CHANNEL(item)->mode);
+       if (strchr(cmode, ' ') != NULL)
+               *(strchr(cmode, ' ')) = 0;
+
+       return cmode;
 }
 
 /* current nickname */
@@ -357,7 +394,8 @@ static char *expando_serverversion(SERVER_REC *server, void *item, int *free_ret
 /* target of current input (channel or QUERY nickname) */
 static char *expando_target(SERVER_REC *server, void *item, int *free_ret)
 {
-       return item == NULL ? "" : ((WI_ITEM_REC *) item)->name;
+       return item == NULL ? "" :
+               (char *) window_item_get_target((WI_ITEM_REC *) item);
 }
 
 /* client release date (in YYYYMMDD format) */
@@ -460,6 +498,12 @@ static char *expando_chatnet(SERVER_REC *server, void *item, int *free_ret)
        return server == NULL ? "" : server->connrec->chatnet;
 }
 
+/* visible_name of current window item */
+static char *expando_itemname(SERVER_REC *server, void *item, int *free_ret)
+{
+       return item == NULL ? "" : ((WI_ITEM_REC *) item)->visible_name;
+}
+
 static void sig_message_public(SERVER_REC *server, const char *msg,
                               const char *nick, const char *address,
                               const char *target)
@@ -537,9 +581,9 @@ void expandos_init(void)
        struct utsname un;
 #endif
        settings_add_str("misc", "STATUS_OPER", "*");
-       settings_add_str("misc", "timestamp_format", "%H:%M");
+       settings_add_str("lookandfeel", "timestamp_format", "%H:%M");
+       settings_add_bool("lookandfeel", "chanmode_expando_strip", FALSE);
 
-       client_start_time = time(NULL);
        last_sent_msg = NULL; last_sent_msg_body = NULL;
        last_privmsg_from = NULL; last_public_from = NULL;
         last_timestamp = 0;
@@ -577,12 +621,15 @@ void expandos_init(void)
                       "", EXPANDO_NEVER, NULL);
        expando_create("K", expando_cmdchars,
                       "setup changed", EXPANDO_ARG_NONE, NULL);
+       expando_create("k", expando_cmdchar,
+                      "setup changed", EXPANDO_ARG_NONE, NULL);
        expando_create("M", expando_chanmode,
                       "window changed", EXPANDO_ARG_NONE,
                       "window item changed", EXPANDO_ARG_WINDOW,
                       "channel mode changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
        expando_create("N", expando_nick,
                       "window changed", EXPANDO_ARG_NONE,
+                      "window connect changed", EXPANDO_ARG_WINDOW,
                       "window server changed", EXPANDO_ARG_WINDOW,
                        "server nick changed", EXPANDO_ARG_SERVER, NULL);
        expando_create("O", expando_statusoper,
@@ -610,6 +657,7 @@ void expandos_init(void)
        expando_create("W", expando_workdir, NULL);
        expando_create("Y", expando_realname,
                       "window changed", EXPANDO_ARG_NONE,
+                      "window connect changed", EXPANDO_ARG_WINDOW,
                       "window server changed", EXPANDO_ARG_WINDOW, NULL);
        expando_create("Z", expando_time,
                       "time changed", EXPANDO_ARG_NONE, NULL);
@@ -629,10 +677,17 @@ void expandos_init(void)
                       "query address changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
        expando_create("tag", expando_servertag,
                       "window changed", EXPANDO_ARG_NONE,
+                      "window connect changed", EXPANDO_ARG_WINDOW,
                       "window server changed", EXPANDO_ARG_WINDOW, NULL);
        expando_create("chatnet", expando_chatnet,
                       "window changed", EXPANDO_ARG_NONE,
+                      "window connect changed", EXPANDO_ARG_WINDOW,
                       "window server changed", EXPANDO_ARG_WINDOW, NULL);
+       expando_create("itemname", expando_itemname,
+                      "window changed", EXPANDO_ARG_NONE,
+                      "window item changed", EXPANDO_ARG_WINDOW,
+                      "window item name changed", EXPANDO_ARG_WINDOW_ITEM,
+                      NULL);
 
        read_settings();
 
@@ -650,13 +705,7 @@ void expandos_deinit(void)
        for (n = 0; n < sizeof(char_expandos)/sizeof(char_expandos[0]); n++)
                g_free_not_null(char_expandos[n]);
 
-       expando_destroy("sysname", expando_sysname);
-       expando_destroy("sysrelease", expando_sysrelease);
-       expando_destroy("sysarch", expando_sysarch);
-       expando_destroy("topic", expando_topic);
-       expando_destroy("tag", expando_servertag);
-       expando_destroy("chatnet", expando_chatnet);
-
+       g_hash_table_foreach_remove(expandos, free_expando, NULL);
         g_hash_table_destroy(expandos);
 
        g_free_not_null(last_sent_msg); g_free_not_null(last_sent_msg_body);