plugins/yay/yay.c

changeset 2009
374cfafde641
parent 1891
ff29a9211243
child 2010
712a8802bd31
--- a/plugins/yay/yay.c	Wed Jun 13 07:26:16 2001 +0000
+++ b/plugins/yay/yay.c	Wed Jun 13 21:28:03 2001 +0000
@@ -71,6 +71,7 @@
 	char *active_id;
 	GList *conns;
 	gboolean logged_in;
+	GSList *offline;
 };
 
 static char *yahoo_name() {
@@ -431,6 +432,10 @@
 
 static void yahoo_close(struct gaim_connection *gc) {
 	struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
+	while (yd->offline) {
+		g_free(yd->offline->data);
+		yd->offline = g_slist_remove(yd->offline, yd->offline->data);
+	}
 	g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL);
 	g_hash_table_destroy(yd->hash);
 	yahoo_disconnect(yd->sess);
@@ -440,10 +445,20 @@
 
 static void yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) {
 	struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
+	GSList *l = yd->offline;
 
 	if (away || !strlen(message)) return;
 
-	yahoo_send_message(yd->sess, yd->active_id, who, message);
+	while (l) {
+		if (!strcmp(who, l->data))
+			break;
+		l = l->next;
+	}
+
+	if (l)
+		yahoo_send_message(yd->sess, yd->active_id, who, message);
+	else
+		yahoo_send_message_offline(yd->sess, yd->active_id, who, message);
 }
 
 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) {
@@ -726,6 +741,52 @@
 	yahoo_protoopt_button("Notify me of new Yahoo! Mail", user, USEROPT_MAIL, vbox);
 }
 
+static void toggle_offline(GtkToggleButton *button, struct conversation *c)
+{
+	struct gaim_connection *gc = gtk_object_get_user_data(GTK_OBJECT(button));
+	struct yahoo_data *yd = gc->proto_data;
+	GSList *l = yd->offline;
+
+	while (l) {
+		if (!strcmp(c->name, l->data))
+			break;
+		l = l->next;
+	}
+	if (l) {
+		g_free(l->data);
+		yd->offline = g_slist_remove(yd->offline, l->data);
+	} else
+		yd->offline = g_slist_append(yd->offline, g_strdup(c->name));
+}
+
+static void yahoo_insert_convo(struct gaim_connection *gc, struct conversation *c)
+{
+	GtkWidget *button;
+	struct yahoo_data *yd = gc->proto_data;
+	GSList *l = yd->offline;
+	struct buddy *b = find_buddy(gc, c->name);
+
+	button = gtk_check_button_new_with_label("Send offline message");
+	gtk_box_pack_start(GTK_BOX(c->lbox), button, FALSE, FALSE, 5);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_offline), c);
+	gtk_object_set_user_data(GTK_OBJECT(button), gc);
+	while (l) {
+		if (!strcmp(c->name, l->data))
+			break;
+		l = l->next;
+	}
+	if (l || (b && !b->present))
+		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
+	gtk_widget_show(button);
+}
+
+static void yahoo_remove_convo(struct gaim_connection *gc, struct conversation *c)
+{
+	while (GTK_BOX(c->lbox)->children)
+		gtk_container_remove(GTK_CONTAINER(c->lbox),
+				     ((GtkBoxChild *)GTK_BOX(c->lbox)->children->data)->widget);
+}
+
 static struct prpl *my_protocol = NULL;
 
 void Yahoo_init(struct prpl *ret) {
@@ -738,6 +799,8 @@
 	ret->do_action = yahoo_do_action;
 	ret->buddy_menu = yahoo_buddy_menu;
 	ret->user_opts = yahoo_user_opts;
+	ret->insert_convo = yahoo_insert_convo;
+	ret->remove_convo = yahoo_remove_convo;
 	ret->login = yahoo_login;
 	ret->close = yahoo_close;
 	ret->send_im = yahoo_send_im;

mercurial