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
This commit is contained in:
Timo Sirainen 2002-05-16 00:34:37 +00:00 committed by cras
commit d346fbe1a9
44 changed files with 325 additions and 247 deletions

View file

@ -501,7 +501,9 @@ GList *completion_get_channels(SERVER_REC *server, const char *word)
for (; tmp != NULL; tmp = tmp->next) {
CHANNEL_REC *rec = tmp->data;
if (g_strncasecmp(rec->name, word, len) == 0)
if (g_strncasecmp(rec->visible_name, word, len) == 0)
list = g_list_append(list, g_strdup(rec->visible_name));
else if (g_strncasecmp(rec->name, word, len) == 0)
list = g_list_append(list, g_strdup(rec->name));
}
@ -861,7 +863,7 @@ static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
str = g_strdup_printf(IS_CHANNEL(item) ? "-channel %s %s" :
IS_QUERY(item) ? "-nick %s %s" : "%s %s",
item->name, line);
window_item_get_target(item), line);
signal_emit("command msg", 3, str, server, item);

View file

@ -70,7 +70,7 @@ static void signal_channel_destroyed(CHANNEL_REC *channel)
!channel->server->disconnected) {
/* kicked out from channel */
window_bind_add(window, channel->server->tag,
channel->name);
channel->visible_name);
} else if (!channel->joined || channel->left)
window_auto_destroy(window);
}
@ -86,7 +86,7 @@ static void sig_disconnected(SERVER_REC *server)
CHANNEL_REC *channel = tmp->data;
window = window_item_window((WI_ITEM_REC *) channel);
window_bind_add(window, server->tag, channel->name);
window_bind_add(window, server->tag, channel->visible_name);
}
}
@ -96,8 +96,9 @@ static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)
if (item == NULL) return;
if (g_slist_length(window->items) > 1 && IS_CHANNEL(item)) {
printformat(item->server, item->name, MSGLEVEL_CLIENTNOTICE,
TXT_TALKING_IN, item->name);
printformat(item->server, item->visible_name,
MSGLEVEL_CLIENTNOTICE,
TXT_TALKING_IN, item->visible_name);
signal_stop();
}
}
@ -172,7 +173,8 @@ static void cmd_channel_list_joined(void)
/* print active channel */
channel = CHANNEL(active_win->active);
if (channel != NULL)
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CURRENT_CHANNEL, channel->name);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_CURRENT_CHANNEL, channel->visible_name);
/* print list of all channels, their modes, server tags and nicks */
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANLIST_HEADER);
@ -189,7 +191,8 @@ static void cmd_channel_list_joined(void)
if (nicks->len > 1) g_string_truncate(nicks, nicks->len-1);
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANLIST_LINE,
channel->name, channel->mode, channel->server->tag, nicks->str);
channel->visible_name, channel->mode,
channel->server->tag, nicks->str);
g_slist_free(nicklist);
g_string_free(nicks, TRUE);
@ -326,13 +329,13 @@ static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist)
int *columns, cols, rows, last_col_rows, col, row, max_width;
int item_extra, linebuf_size, formatnum;
window = window_find_closest(channel->server, channel->name,
window = window_find_closest(channel->server, channel->visible_name,
MSGLEVEL_CLIENTCRAP);
max_width = window->width;
/* get the length of item extra stuff ("[ ] ") */
format = format_get_text(MODULE_NAME, NULL,
channel->server, channel->name,
channel->server, channel->visible_name,
TXT_NAMES_NICK, " ", "");
stripped = strip_codes(format);
item_extra = strlen(stripped);
@ -344,7 +347,7 @@ static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist)
max_width = settings_get_int("names_max_width");
/* remove width of the timestamp from max_width */
format_create_dest(&dest, channel->server, channel->name,
format_create_dest(&dest, channel->server, channel->visible_name,
MSGLEVEL_CLIENTCRAP, NULL);
format = format_get_line_start(current_theme, &dest, time(NULL));
if (format != NULL) {
@ -356,8 +359,9 @@ static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist)
/* remove width of the prefix from max_width */
prefix_format = format_get_text(MODULE_NAME, NULL,
channel->server, channel->name,
TXT_NAMES_PREFIX, channel->name);
channel->server, channel->visible_name,
TXT_NAMES_PREFIX,
channel->visible_name);
if (prefix_format != NULL) {
stripped = strip_codes(prefix_format);
max_width -= strlen(stripped);
@ -410,13 +414,14 @@ static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist)
rec->voice ? TXT_NAMES_NICK_VOICE :
TXT_NAMES_NICK;
format = format_get_text(MODULE_NAME, NULL,
channel->server, channel->name,
channel->server,
channel->visible_name,
formatnum, nickmode, linebuf);
g_string_append(str, format);
g_free(format);
if (++col == cols) {
printtext(channel->server, channel->name,
printtext(channel->server, channel->visible_name,
MSGLEVEL_CLIENTCRAP, "%s", str->str);
g_string_truncate(str, 0);
if (prefix_format != NULL)
@ -429,7 +434,7 @@ static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist)
}
if (str->len > strlen(prefix_format)) {
printtext(channel->server, channel->name,
printtext(channel->server, channel->visible_name,
MSGLEVEL_CLIENTCRAP, "%s", str->str);
}
@ -480,15 +485,17 @@ void fe_channels_nicklist(CHANNEL_REC *channel, int flags)
/* display the nicks */
if ((flags & CHANNEL_NICKLIST_FLAG_COUNT) == 0) {
printformat(channel->server, channel->name,
MSGLEVEL_CLIENTCRAP, TXT_NAMES, channel->name, nicks, ops, halfops, voices, normal);
printformat(channel->server, channel->visible_name,
MSGLEVEL_CLIENTCRAP, TXT_NAMES,
channel->visible_name,
nicks, ops, halfops, voices, normal);
display_sorted_nicks(channel, sorted);
}
g_slist_free(sorted);
printformat(channel->server, channel->name,
printformat(channel->server, channel->visible_name,
MSGLEVEL_CLIENTNOTICE, TXT_ENDOFNAMES,
channel->name, nicks, ops, halfops, voices, normal);
channel->visible_name, nicks, ops, halfops, voices, normal);
}
/* SYNTAX: NAMES [-count | -ops -halfops -voices -normal] [<channels> | **] */
@ -513,7 +520,7 @@ static void cmd_names(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
if (!IS_CHANNEL(item))
cmd_param_error(CMDERR_NOT_JOINED);
channel = item->name;
channel = CHANNEL(item)->name;
}
flags = 0;
@ -575,7 +582,7 @@ static void cmd_cycle(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
joindata = chanrec->get_join_data(chanrec);
window_bind_add(window_item_window(chanrec),
chanrec->server->tag, chanrec->name);
chanrec->server->tag, chanrec->visible_name);
/* FIXME: kludgy kludgy... */
signal_emit("command part", 3, data, server, item);

View file

@ -54,7 +54,7 @@ static void exec_wi_destroy(EXEC_WI_REC *rec)
window_item_destroy((WI_ITEM_REC *) rec);
MODULE_DATA_DEINIT(rec);
g_free(rec->name);
g_free(rec->visible_name);
g_free(rec);
}
@ -68,7 +68,7 @@ static EXEC_WI_REC *exec_wi_create(WINDOW_REC *window, PROCESS_REC *rec)
item = g_new0(EXEC_WI_REC, 1);
item->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "EXEC");
item->destroy = (void (*) (WI_ITEM_REC *)) exec_wi_destroy;
item->name = rec->name != NULL ? g_strdup(rec->name) :
item->visible_name = rec->name != NULL ? g_strdup(rec->name) :
g_strdup_printf("%%%d", rec->id);
item->createtime = time(NULL);
@ -411,7 +411,7 @@ static void handle_exec(const char *args, GHashTable *optlist,
/* redirect output to active channel/query */
if (item == NULL)
cmd_return_error(CMDERR_NOT_JOINED);
target = item->name;
target = (char *) window_item_get_target(item);
target_channel = IS_CHANNEL(item);
target_nick = IS_QUERY(item);
} else if (g_hash_table_lookup(optlist, "msg") != NULL) {
@ -589,7 +589,7 @@ static void sig_exec_input(PROCESS_REC *rec, const char *text)
3, str, server, item);
g_free(str);
} else if (rec->target_item != NULL) {
printtext(NULL, rec->target_item->name,
printtext(NULL, rec->target_item->visible_name,
rec->level, "%s", text);
} else {
printtext_window(rec->target_win, rec->level, "%s", text);

View file

@ -595,7 +595,7 @@ static void sig_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item)
{
LOG_REC *log;
log = logs_find_item(LOG_ITEM_TARGET, item->name,
log = logs_find_item(LOG_ITEM_TARGET, item->visible_name,
item->server == NULL ? NULL :
item->server->tag, NULL);
if (log != NULL && log->temp)

View file

@ -347,7 +347,7 @@ static void sig_message_quit(SERVER_REC *server, const char *nick,
if (!nicklist_find(rec, nick))
continue;
if (ignore_check(server, nick, address, rec->name,
if (ignore_check(server, nick, address, rec->visible_name,
reason, MSGLEVEL_QUITS)) {
count++;
continue;
@ -355,17 +355,18 @@ static void sig_message_quit(SERVER_REC *server, const char *nick,
if (print_channel == NULL ||
active_win->active == (WI_ITEM_REC *) rec)
print_channel = rec->name;
print_channel = rec->visible_name;
if (once)
g_string_sprintfa(chans, "%s,", rec->name);
g_string_sprintfa(chans, "%s,", rec->visible_name);
else {
window = window_item_window((WI_ITEM_REC *) rec);
if (g_slist_find(windows, window) == NULL) {
windows = g_slist_append(windows, window);
printformat(server, rec->name, MSGLEVEL_QUITS,
printformat(server, rec->visible_name,
MSGLEVEL_QUITS,
TXT_QUIT, nick, address, reason,
rec->name);
rec->visible_name);
}
}
count++;
@ -441,8 +442,8 @@ static void print_nick_change(SERVER_REC *server, const char *newnick,
continue;
windows = g_slist_append(windows, window);
print_nick_change_channel(server, channel->name, newnick,
oldnick, address, ownnick);
print_nick_change_channel(server, channel->visible_name,
newnick, oldnick, address, ownnick);
msgprint = TRUE;
}

View file

@ -232,12 +232,12 @@ void window_set_immortal(WINDOW_REC *window, int immortal)
}
/* return active item's name, or if none is active, window's name */
char *window_get_active_name(WINDOW_REC *window)
const char *window_get_active_name(WINDOW_REC *window)
{
g_return_val_if_fail(window != NULL, NULL);
if (window->active != NULL)
return window->active->name;
return window->active->visible_name;
return window->name;
}

View file

@ -69,7 +69,7 @@ void window_set_level(WINDOW_REC *window, int level);
void window_set_immortal(WINDOW_REC *window, int immortal);
/* return active item's name, or if none is active, window's name */
char *window_get_active_name(WINDOW_REC *window);
const char *window_get_active_name(WINDOW_REC *window);
WINDOW_REC *window_find_level(void *server, int level);
WINDOW_REC *window_find_closest(void *server, const char *name, int level);

View file

@ -64,7 +64,8 @@ static void window_print_items(WINDOW_REC *win)
type = module_find_id_str("WINDOW ITEM TYPE", item->type);
printformat_window(win, MSGLEVEL_CLIENTCRAP,
TXT_WINDOW_INFO_ITEM,
type == NULL ? "??" : type, item->name,
type == NULL ? "??" : type,
item->visible_name,
item->server == NULL ? "" :
item->server->tag);
}
@ -660,7 +661,7 @@ static void cmd_window_list(void)
levelstr = bits2level(rec->level);
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_LINE,
rec->refnum, rec->name == NULL ? "" : rec->name,
rec->active == NULL ? "" : rec->active->name,
rec->active == NULL ? "" : rec->active->visible_name,
rec->active_server == NULL ? "" : ((SERVER_REC *) rec->active_server)->tag,
levelstr);
g_free(levelstr);

View file

@ -23,6 +23,7 @@
#include "modules.h"
#include "signals.h"
#include "servers.h"
#include "channels.h"
#include "settings.h"
#include "levels.h"
@ -195,15 +196,23 @@ void window_item_next(WINDOW_REC *window)
WI_ITEM_REC *window_item_find_window(WINDOW_REC *window,
void *server, const char *name)
{
CHANNEL_REC *channel;
GSList *tmp;
for (tmp = window->items; tmp != NULL; tmp = tmp->next) {
WI_ITEM_REC *rec = tmp->data;
if ((server == NULL || rec->server == server) &&
g_strcasecmp(name, rec->name) == 0) return rec;
g_strcasecmp(name, rec->visible_name) == 0)
return rec;
}
/* try with channel name too, it's not necessarily
same as visible_name (!channels) */
channel = channel_find(server, name);
if (channel != NULL && window_item_window(channel) == window)
return (WI_ITEM_REC *) channel;
return NULL;
}
@ -259,7 +268,7 @@ void window_item_create(WI_ITEM_REC *item, int automatic)
/* is item bound to this window? */
if (item->server != NULL) {
bind = window_bind_find(rec, item->server->tag,
item->name);
item->visible_name);
if (bind != NULL) {
if (!bind->sticky)
window_bind_destroy(rec, bind);
@ -316,8 +325,9 @@ static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)
if (g_slist_length(window->items) > 1) {
/* default to printing "talking with ...",
you can override it it you wish */
printformat(item->server, item->name, MSGLEVEL_CLIENTNOTICE,
TXT_TALKING_WITH, item->name);
printformat(item->server, item->visible_name,
MSGLEVEL_CLIENTNOTICE,
TXT_TALKING_WITH, item->visible_name);
}
}

View file

@ -147,7 +147,7 @@ static void sig_layout_save_item(WINDOW_REC *window, WI_ITEM_REC *item,
iconfig_node_set_str(subnode, "type", type);
type = chat_protocol_find_id(item->chat_type)->name;
iconfig_node_set_str(subnode, "chat_type", type);
iconfig_node_set_str(subnode, "name", item->name);
iconfig_node_set_str(subnode, "name", item->visible_name);
if (item->server != NULL)
iconfig_node_set_str(subnode, "tag", item->server->tag);