You can send message to different server with /MSG -<server tag> nick...

Tab-completion changes:
 - in empty line, it completed /MSG nick1 fine, but another tab press
   didn't give the next nick.
 - "/command <tab>" doesn't try to complete /command, but instead it tries
   to complete it's subcommand or first parameter.
 - /MSG completion now goes through nicks in ALL servers prefixing the nick
   with -<server tag> if needed.
 - /MSG -tag <tab> completes only nicks in "tag" server.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@388 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-06-28 20:00:39 +00:00 committed by cras
commit 8fc1e0535c
8 changed files with 181 additions and 79 deletions

View file

@ -27,6 +27,7 @@
#include "levels.h"
#include "irc.h"
#include "irc-commands.h"
#include "server.h"
#include "mode-lists.h"
#include "nicklist.h"
@ -90,6 +91,7 @@ static void cmd_query(gchar *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
static void cmd_msg(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
GHashTable *optlist;
WINDOW_REC *window;
CHANNEL_REC *channel;
NICK_REC *nickrec;
@ -99,9 +101,12 @@ static void cmd_msg(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
g_return_if_fail(data != NULL);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &msg))
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"msg", &optlist, &target, &msg))
return;
if (*target == '\0' || *msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
server = irccmd_options_get_server(optlist, server);
if (*target == '=')
{

View file

@ -201,12 +201,15 @@ static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *
static void cmd_msg(const char *data, IRC_SERVER_REC *server)
{
GHashTable *optlist;
char *target, *msg;
void *free_arg;
g_return_if_fail(data != NULL);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &msg))
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"msg", &optlist, &target, &msg))
return;
if (*target != '\0' && *msg != '\0') {
if (!ischannel(*target) && *target != '=' && server != NULL)
@ -244,12 +247,15 @@ static void sig_nick_changed(CHANNEL_REC *channel, NICK_REC *nick, const char *o
}
}
static GList *completion_msg(IRC_SERVER_REC *server, const char *nick, const char *prefix)
/* Complete /MSG from specified server */
static GList *completion_msg_server(IRC_SERVER_REC *server, const char *nick, const char *prefix)
{
GSList *tmp;
GList *list;
int len;
g_return_val_if_fail(nick != NULL, NULL);
list = NULL; len = strlen(nick);
for (tmp = server->lastmsgs; tmp != NULL; tmp = tmp->next) {
if (len == 0 || g_strncasecmp(tmp->data, nick, len) == 0) {
@ -263,6 +269,41 @@ static GList *completion_msg(IRC_SERVER_REC *server, const char *nick, const cha
return list;
}
/* Complete /MSG - if `server' is NULL, complete nicks from all servers */
static GList *completion_msg(IRC_SERVER_REC *win_server, IRC_SERVER_REC *find_server,
const char *nick, const char *prefix)
{
GSList *tmp;
GList *list, *tmplist;
char *newprefix;
g_return_val_if_fail(nick != NULL, NULL);
if (servers == NULL) return NULL;
if (find_server != NULL)
return completion_msg_server(find_server, nick, prefix);
list = NULL;
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
IRC_SERVER_REC *rec = tmp->data;
if (rec == win_server)
newprefix = g_strdup(prefix);
else {
newprefix = prefix == NULL ?
g_strdup_printf("-%s", rec->tag) :
g_strdup_printf("%s -%s", prefix, rec->tag);
}
tmplist = completion_msg_server(rec, nick, newprefix);
list = g_list_concat(list, tmplist);
g_free_not_null(newprefix);
}
return list;
}
static void complete_from_nicklist(GList **outlist, GSList *list,
const char *nick, const char *prefix)
{
@ -336,6 +377,31 @@ static GList *completion_joinlist(GList *list1, GList *list2)
return list1;
}
static IRC_SERVER_REC *line_get_server(const char *line)
{
IRC_SERVER_REC *server;
const char *ptr;
char *tag, *p;
g_return_val_if_fail(line != NULL, NULL);
ptr = strchr(line, ' ');
if (ptr == NULL) return NULL;
while (*ptr == ' ') ptr++;
if (*ptr != '-') return NULL;
/* -option found - should be server tag */
tag = g_strdup(ptr+1);
p = strchr(tag, ' ');
if (p != NULL) *p = '\0';
server = (IRC_SERVER_REC *) server_find_tag(tag);
g_free(tag);
return server;
}
static void sig_complete_word(GList **list, WINDOW_REC *window,
const char *word, const char *linestart)
{
@ -364,12 +430,13 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
/* check for /MSG completion */
cmdchars = settings_get_str("cmdchars");
if (*word == '\0' || (*linestart == '\0' && strchr(cmdchars, *word) != NULL &&
g_strcasecmp(word+1, "msg") == 0)) {
if ((*linestart == '\0' && *word == '\0') ||
(*linestart == '\0' && strchr(cmdchars, *word) != NULL &&
g_strcasecmp(word+1, "msg") == 0)) {
/* pressed TAB at the start of line - add /MSG
... or ... trying to complete /MSG command */
prefix = g_strdup_printf("%cmsg", *cmdchars);
*list = completion_msg(server, "", prefix);
*list = completion_msg(server, NULL, "", prefix);
if (*list == NULL) *list = g_list_append(*list, g_strdup(prefix));
g_free(prefix);
@ -380,7 +447,10 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
if (strchr(cmdchars, *linestart) != NULL &&
g_strcasecmp(linestart+1, "msg") == 0) {
/* completing /MSG nick */
*list = completion_msg(server, word, NULL);
IRC_SERVER_REC *msgserver;
msgserver = line_get_server(linestart);
*list = completion_msg(server, msgserver, word, NULL);
}
/* nick completion .. we could also be completing a nick after /MSG