changeset 1504:cac3efeb4d9c

[gaim-migrate @ 1514] added NICK and QUIT to irc; added rename_chat_buddy to buddy_chat to facilitate NICK committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 25 Feb 2001 23:02:11 +0000
parents 1a1a58499a1c
children 171c64f70b66
files plugins/irc.c src/buddy_chat.c
diffstat 2 files changed, 132 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/irc.c	Sun Feb 25 20:09:31 2001 +0000
+++ b/plugins/irc.c	Sun Feb 25 23:02:11 2001 +0000
@@ -612,6 +612,75 @@
 		return;
 	}
 
+	if ((strstr(buf, " NICK ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
+
+		gchar old[128];
+		gchar new[128];
+
+		GList *templist;
+
+		struct irc_channel *channel;
+		int id;
+		int j;
+
+		for (j = 0, i = 1; buf[i] != '!'; j++, i++) {
+			old[j] = buf[i];
+		}
+
+		old[j] = '\0';
+		i++;
+
+		for (j = 0; buf[i] != ':'; j++, i++) {
+		}
+
+		i++;
+		strcpy(new, buf + i);
+
+		g_strchomp(new);
+
+		templist = ((struct irc_data *)gc->proto_data)->channels;
+
+		while (templist) {
+			struct conversation *convo = NULL;
+			channel = templist->data;
+
+			convo = find_conversation_by_id(gc, channel->id);
+
+			rename_chat_buddy(convo, old, new);
+
+			templist = templist->next;
+		}
+	}
+
+	if ((strstr(buf, "QUIT ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
+
+		gchar u_nick[128];
+
+		GList *templist;
+
+		struct irc_channel *channel;
+		int j;
+
+		for (j = 0, i = 1; buf[i] != '!'; j++, i++) {
+			u_nick[j] = buf[i];
+		}
+
+		u_nick[j] = '\0';
+
+		templist = ((struct irc_data *)gc->proto_data)->channels;
+
+		while (templist) {
+			struct conversation *convo = NULL;
+			channel = templist->data;
+
+			convo = find_conversation_by_id(gc, channel->id);
+
+			remove_chat_buddy(convo, u_nick);
+
+			templist = templist->next;
+		}
+	}
+
 	if ((strstr(buf, " PART ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
 
 		gchar u_channel[128];
--- a/src/buddy_chat.c	Sun Feb 25 20:09:31 2001 +0000
+++ b/src/buddy_chat.c	Sun Feb 25 23:02:11 2001 +0000
@@ -542,6 +542,66 @@
 }
 
 
+void rename_chat_buddy(struct conversation *b, char *old, char *new)
+{
+	GList *names = b->in_room;
+	GList *items = GTK_LIST(b->list)->children;
+
+	char *name = g_strdup(new);
+	GtkWidget *list_item;
+	int pos;
+	GList *ignored = b->ignored;
+
+	char tmp[BUF_LONG];
+
+	while (names) {
+		if (!strcasecmp((char *)names->data, old)) {
+			char *tmp2 = names->data;
+			b->in_room = g_list_remove(b->in_room, names->data);
+			while (items) {
+				if (tmp2 == gtk_object_get_user_data(items->data)) {
+					gtk_list_remove_items(GTK_LIST(b->list),
+							      g_list_append(NULL, items->data));
+					break;
+				}
+				items = items->next;
+			}
+			g_free(tmp2);
+			break;
+		}
+		names = names->next;
+	}
+
+	if (!names)
+		return;
+
+	b->in_room = g_list_insert_sorted(b->in_room, name, insertname);
+
+	while (ignored) {
+		if (!strcasecmp(old, ignored->data))
+			break;
+		ignored = ignored->next;
+	}
+
+	if (ignored) {
+		b->ignored = g_list_remove(b->ignored, ignored->data);
+		b->ignored = g_list_append(b->ignored, name);
+		g_snprintf(tmp, sizeof(tmp), "X %s", name);
+		list_item = gtk_list_item_new_with_label(tmp);
+	} else
+		list_item = gtk_list_item_new_with_label(name);
+
+	gtk_object_set_user_data(GTK_OBJECT(list_item), name);
+	gtk_signal_connect(GTK_OBJECT(list_item), "button_press_event",
+			   GTK_SIGNAL_FUNC(right_click_chat), b);
+	gtk_list_insert_items(GTK_LIST(b->list), g_list_append(NULL, list_item), pos);
+	gtk_widget_show(list_item);
+
+	if (display_options & OPT_DISP_CHAT_LOGON) {
+		g_snprintf(tmp, sizeof(tmp), _("<B>%s is now known as %s</B>"), old, new);
+		write_to_conv(b, tmp, WFLAG_SYSTEM, NULL);
+	}
+}
 
 
 void remove_chat_buddy(struct conversation *b, char *buddy)
@@ -571,6 +631,9 @@
 		names = names->next;
 	}
 
+	if (!names)
+		return;
+
 	g_snprintf(tmp, sizeof(tmp), _("%d %s in room"), g_list_length(b->in_room), g_list_length(b->in_room) == 1 ? "person" : "people");
 	gtk_label_set_text(GTK_LABEL(b->count), tmp);