From d346fbe1a9c6615c88dfacc420f0256b5a751440 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 16 May 2002 00:34:37 +0000 Subject: Better !channel support - window items now have "visual_name" and channels and queries also have "name". Normally they're identical but with !channels the visible_name contains the short !channel name, while name contains full !ABCDEchannel name. The visible_name should be used whenever displaying the channel name, or as printtext()'s target. So, this breaks a few scripts in !channels, they need to be modified to use $channel->{visible_name} instead. Also /LAYOUT SAVE should finally work properly with !channels. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2797 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/channel-rec.h | 1 + src/core/channels.c | 31 ++++++++++++++++++++++--------- src/core/channels.h | 3 ++- src/core/chat-commands.c | 5 ++--- src/core/chat-protocols.h | 3 ++- src/core/commands.c | 13 +++++++------ src/core/expandos.c | 12 +++++++++++- src/core/queries.c | 12 ++++++++++++ src/core/query-rec.h | 1 + src/core/session.c | 6 ++++-- src/core/window-item-rec.h | 6 +++++- 11 files changed, 69 insertions(+), 24 deletions(-) (limited to 'src/core') diff --git a/src/core/channel-rec.h b/src/core/channel-rec.h index f3ec5f8d..7b806ca4 100644 --- a/src/core/channel-rec.h +++ b/src/core/channel-rec.h @@ -2,6 +2,7 @@ #include "window-item-rec.h" +char *name; char *topic; char *topic_by; time_t topic_time; diff --git a/src/core/channels.c b/src/core/channels.c index 1884c402..126c3b7e 100644 --- a/src/core/channels.c +++ b/src/core/channels.c @@ -35,24 +35,37 @@ static char *get_join_data(CHANNEL_REC *channel) return g_strdup(channel->name); } -void channel_init(CHANNEL_REC *channel, int automatic) +static const char *channel_get_target(WI_ITEM_REC *item) +{ + return ((CHANNEL_REC *) item)->name; +} + +void channel_init(CHANNEL_REC *channel, SERVER_REC *server, const char *name, + const char *visible_name, int automatic) { g_return_if_fail(channel != NULL); - g_return_if_fail(channel->name != NULL); + g_return_if_fail(name != NULL); + g_return_if_fail(server != NULL); - channels = g_slist_append(channels, channel); - if (channel->server != NULL) { - channel->server->channels = - g_slist_append(channel->server->channels, channel); - } + if (visible_name == NULL) + visible_name = name; MODULE_DATA_INIT(channel); channel->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL"); channel->destroy = (void (*) (WI_ITEM_REC *)) channel_destroy; - channel->mode = g_strdup(""); - channel->createtime = time(NULL); + channel->get_target = channel_get_target; channel->get_join_data = get_join_data; + channel->chat_type = server->chat_type; + channel->server = server; + channel->name = g_strdup(name); + channel->visible_name = g_strdup(visible_name); + channel->mode = g_strdup(""); + channel->createtime = time(NULL); + + channels = g_slist_append(channels, channel); + server->channels = g_slist_append(server->channels, channel); + signal_emit("channel created", 2, channel, GINT_TO_POINTER(automatic)); } diff --git a/src/core/channels.h b/src/core/channels.h index 98b75ee0..ff121a2c 100644 --- a/src/core/channels.h +++ b/src/core/channels.h @@ -19,7 +19,8 @@ struct _CHANNEL_REC { extern GSList *channels; /* Create new channel record */ -void channel_init(CHANNEL_REC *channel, int automatic); +void channel_init(CHANNEL_REC *channel, SERVER_REC *server, const char *name, + const char *visible_name, int automatic); void channel_destroy(CHANNEL_REC *channel); /* find channel by name, if `server' is NULL, search from all servers */ diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index 933cc3f5..838db914 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -344,9 +344,8 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) target_type = IS_CHANNEL(item) ? SEND_TARGET_CHANNEL : SEND_TARGET_NICK; - target = item->name; - } - else if (g_hash_table_lookup(optlist, "channel") != NULL) + target = (char *) window_item_get_target(item); + } else if (g_hash_table_lookup(optlist, "channel") != NULL) target_type = SEND_TARGET_CHANNEL; else if (g_hash_table_lookup(optlist, "nick") != NULL) target_type = SEND_TARGET_NICK; diff --git a/src/core/chat-protocols.h b/src/core/chat-protocols.h index ad8c64ba..95ab0937 100644 --- a/src/core/chat-protocols.h +++ b/src/core/chat-protocols.h @@ -18,7 +18,8 @@ struct _CHAT_PROTOCOL_REC { void (*destroy_server_connect) (SERVER_CONNECT_REC *); SERVER_REC *(*server_connect) (SERVER_CONNECT_REC *); - CHANNEL_REC *(*channel_create) (SERVER_REC *, const char *, int); + CHANNEL_REC *(*channel_create) (SERVER_REC *, const char *, + const char *, int); QUERY_REC *(*query_create) (const char *, const char *, int); }; diff --git a/src/core/commands.c b/src/core/commands.c index 96a74008..91e4a170 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -653,11 +653,12 @@ typedef struct { GHashTable *options; } CMD_TEMP_REC; -static char *get_optional_channel(WI_ITEM_REC *active_item, char **data, - int require_name) +static const char * +get_optional_channel(WI_ITEM_REC *active_item, char **data, int require_name) { CHANNEL_REC *chanrec; - char *tmp, *origtmp, *channel, *ret; + const char *ret; + char *tmp, *origtmp, *channel; if (active_item == NULL) { /* no active channel in window, channel required */ @@ -670,10 +671,10 @@ static char *get_optional_channel(WI_ITEM_REC *active_item, char **data, if (strcmp(channel, "*") == 0 && !require_name) { /* "*" means active channel */ cmd_get_param(data); - ret = active_item->name; + ret = window_item_get_target(active_item); } else if (!server_ischannel(active_item->server, channel)) { /* we don't have channel parameter - use active channel */ - ret = active_item->name; + ret = window_item_get_target(active_item); } else { /* Find the channel first and use it's name if found. This allows automatic !channel -> !XXXXXchannel replaces. */ @@ -730,7 +731,7 @@ int cmd_get_params(const char *data, gpointer *free_me, int count, ...) /* optional channel as first parameter */ require_name = (count & PARAM_FLAG_OPTCHAN_NAME) == PARAM_FLAG_OPTCHAN_NAME; - arg = get_optional_channel(item, &datad, require_name); + arg = (char *) get_optional_channel(item, &datad, require_name); str = (char **) va_arg(args, char **); if (str != NULL) *str = arg; diff --git a/src/core/expandos.c b/src/core/expandos.c index 2830d677..6f0f392d 100644 --- a/src/core/expandos.c +++ b/src/core/expandos.c @@ -358,7 +358,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) */ @@ -461,6 +462,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) @@ -634,6 +641,9 @@ void expandos_init(void) expando_create("chatnet", expando_chatnet, "window changed", EXPANDO_ARG_NONE, "window server changed", EXPANDO_ARG_WINDOW, NULL); + expando_create("itemname", expando_itemname, + "window changed", EXPANDO_ARG_NONE, + "window item changed", EXPANDO_ARG_WINDOW, NULL); read_settings(); diff --git a/src/core/queries.c b/src/core/queries.c index 8ae994a2..799a6320 100644 --- a/src/core/queries.c +++ b/src/core/queries.c @@ -27,6 +27,11 @@ GSList *queries; +static const char *query_get_target(WI_ITEM_REC *item) +{ + return ((QUERY_REC *) item)->name; +} + void query_init(QUERY_REC *query, int automatic) { g_return_if_fail(query != NULL); @@ -37,8 +42,10 @@ void query_init(QUERY_REC *query, int automatic) MODULE_DATA_INIT(query); query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY"); query->destroy = (void (*) (WI_ITEM_REC *)) query_destroy; + query->get_target = query_get_target; query->createtime = time(NULL); query->last_unread_msg = time(NULL); + query->visible_name = g_strdup(query->name); if (query->server_tag != NULL) { query->server = server_find_tag(query->server_tag); @@ -69,6 +76,7 @@ void query_destroy(QUERY_REC *query) g_free_not_null(query->hilight_color); g_free_not_null(query->server_tag); g_free_not_null(query->address); + g_free(query->visible_name); g_free(query->name); query->type = 0; @@ -124,6 +132,10 @@ void query_change_nick(QUERY_REC *query, const char *nick) oldnick = query->name; query->name = g_strdup(nick); + + g_free(query->visible_name); + query->visible_name = g_strdup(nick); + signal_emit("query nick changed", 2, query, oldnick); signal_emit("window item name changed", 1, query); g_free(oldnick); diff --git a/src/core/query-rec.h b/src/core/query-rec.h index fc08d2ef..ddb85ba4 100644 --- a/src/core/query-rec.h +++ b/src/core/query-rec.h @@ -2,6 +2,7 @@ #include "window-item-rec.h" +char *name; char *address; char *server_tag; time_t last_unread_msg; diff --git a/src/core/session.c b/src/core/session.c index b5419134..4e7a832c 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -146,6 +146,7 @@ static void session_save_channel(CHANNEL_REC *channel, CONFIG_REC *config, node = config_node_section(node, NULL, NODE_TYPE_BLOCK); config_node_set_str(config, node, "name", channel->name); + config_node_set_str(config, node, "visible_name", channel->visible_name); config_node_set_str(config, node, "topic", channel->topic); config_node_set_str(config, node, "topic_by", channel->topic_by); config_node_set_int(config, node, "topic_time", channel->topic_time); @@ -215,13 +216,14 @@ static void session_restore_channel_nicks(CHANNEL_REC *channel, static void session_restore_channel(SERVER_REC *server, CONFIG_NODE *node) { CHANNEL_REC *channel; - const char *name; + const char *name, *visible_name; name = config_node_get_str(node, "name", NULL); if (name == NULL) return; - channel = CHAT_PROTOCOL(server)->channel_create(server, name, TRUE); + visible_name = config_node_get_str(node, "visible_name", NULL); + channel = CHAT_PROTOCOL(server)->channel_create(server, name, visible_name, TRUE); channel->topic = g_strdup(config_node_get_str(node, "topic", NULL)); channel->topic_by = g_strdup(config_node_get_str(node, "topic_by", NULL)); channel->topic_time = config_node_get_int(node, "topic_time", 0); diff --git a/src/core/window-item-rec.h b/src/core/window-item-rec.h index eeb465f4..d7b6f7db 100644 --- a/src/core/window-item-rec.h +++ b/src/core/window-item-rec.h @@ -6,7 +6,7 @@ GHashTable *module_data; void *window; STRUCT_SERVER_REC *server; -char *name; +char *visible_name; time_t createtime; int data_level; @@ -14,4 +14,8 @@ char *hilight_color; void (*destroy)(WI_ITEM_REC *item); +const char *(*get_target)(WI_ITEM_REC *item); +#define window_item_get_target(item) \ + ((item)->get_target(item)) + #undef STRUCT_SERVER_REC -- cgit v1.2.3