mirror of
https://github.com/irssi/irssi.git
synced 2026-08-18 08:02:13 +02:00
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:
parent
ee80e7601a
commit
d346fbe1a9
44 changed files with 325 additions and 247 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "window-item-rec.h"
|
||||
|
||||
char *name;
|
||||
char *topic;
|
||||
char *topic_by;
|
||||
time_t topic_time;
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "window-item-rec.h"
|
||||
|
||||
char *name;
|
||||
char *address;
|
||||
char *server_tag;
|
||||
time_t last_unread_msg;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue