changeset 2986:1c6a3516e1ff

[gaim-migrate @ 2999] Funky :) Editable buddy pouncen committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Sat, 23 Feb 2002 23:41:50 +0000
parents 32c78c57b351
children 634a252a000a
files src/buddy.c src/dialogs.c src/gaim.h src/ui.h
diffstat 4 files changed, 120 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddy.c	Sat Feb 23 23:28:49 2002 +0000
+++ b/src/buddy.c	Sat Feb 23 23:41:50 2002 +0000
@@ -1538,11 +1538,17 @@
 static void new_bp_callback(GtkWidget *w, struct buddy *b)
 {
 	if (b)
-		show_new_bp(b->name, b->gc, b->idle, b->uc & UC_UNAVAILABLE);
+		show_new_bp(b->name, b->gc, b->idle, b->uc & UC_UNAVAILABLE, NULL);
 	else
-		show_new_bp(NULL, NULL, 0, 0);
+		show_new_bp(NULL, NULL, 0, 0, NULL);
 }
 
+static void edit_bp_callback(GtkWidget *w, struct buddy_pounce *b)
+{
+  show_new_bp(NULL, NULL, 0, 0, b);
+}
+
+static GtkTooltips *bp_tooltip = NULL;
 void do_bp_menu()
 {
 	GtkWidget *menuitem, *mess, *messmenu;
@@ -1553,6 +1559,10 @@
 	struct buddy_pounce *b;
 	GList *bp = buddy_pounces;
 
+	/* Tooltip for editing bp's */
+	if(!bp_tooltip)
+		bp_tooltip = gtk_tooltips_new();
+
 	l = gtk_container_children(GTK_CONTAINER(bpmenu));
 
 	while (l) {
@@ -1608,8 +1618,9 @@
 
 		mess = gtk_menu_item_new_with_label(b->message);
 		gtk_menu_append(GTK_MENU(messmenu), mess);
+		gtk_tooltips_set_tip(bp_tooltip, GTK_WIDGET(mess), _("[Click to edit]"), NULL);
 		gtk_widget_show(mess);
-
+		gtk_signal_connect(GTK_OBJECT(mess), "activate", GTK_SIGNAL_FUNC(edit_bp_callback), b);
 		bp = bp->next;
 
 	}
--- a/src/dialogs.c	Sat Feb 23 23:28:49 2002 +0000
+++ b/src/dialogs.c	Sat Feb 23 23:41:50 2002 +0000
@@ -154,6 +154,7 @@
 	GtkWidget *soundentry;
 
 	struct aim_user *user;
+	struct buddy_pounce *buddy_pounce;
 };
 
 struct findbyemail {
@@ -1077,14 +1078,19 @@
 
 void do_new_bp(GtkWidget *w, struct addbp *b)
 {
-	struct buddy_pounce *bp = g_new0(struct buddy_pounce, 1);
-
+	struct buddy_pounce *bp;
+	
 	if (strlen(gtk_entry_get_text(GTK_ENTRY(b->nameentry))) == 0) {
 		do_error_dialog(_("Please enter a buddy to pounce."), _("Buddy Pounce Error"));
-		g_free(bp);
 		return;
 	}
 
+        if(!b->buddy_pounce)
+		bp = g_new0(struct buddy_pounce, 1);
+	else
+		bp = b->buddy_pounce;
+
+	
 	g_snprintf(bp->name, 80, "%s", gtk_entry_get_text(GTK_ENTRY(b->nameentry)));
 	g_snprintf(bp->message, 2048, "%s", gtk_entry_get_text(GTK_ENTRY(b->messentry)));
 	g_snprintf(bp->command, 2048, "%s", gtk_entry_get_text(GTK_ENTRY(b->commentry)));
@@ -1122,7 +1128,8 @@
 	if (GTK_TOGGLE_BUTTON(b->save)->active)
 		bp->options |= OPT_POUNCE_SAVE;
 
-	buddy_pounces = g_list_append(buddy_pounces, bp);
+	if(!b->buddy_pounce)
+		buddy_pounces = g_list_append(buddy_pounces, bp);
 
 	do_bp_menu();
 
@@ -1179,7 +1186,7 @@
 }
 
 
-void show_new_bp(char *name, struct gaim_connection *gc, int idle, int away)
+void show_new_bp(char *name, struct gaim_connection *gc, int idle, int away, struct buddy_pounce *edit_bp)
 {
 	GtkWidget *label;
 	GtkWidget *bbox;
@@ -1190,7 +1197,14 @@
 	GtkWidget *optmenu;
 
 	struct addbp *b = g_new0(struct addbp, 1);
-	b->user = gc ? gc->user : aim_users->data;
+	
+	if(edit_bp) {
+		b->buddy_pounce = edit_bp;
+		b->user = find_user(edit_bp->pouncer, edit_bp->protocol);
+	} else {
+		b->user = gc ? gc->user : aim_users->data;
+		b->buddy_pounce = NULL;
+	}
 
 	GAIM_DIALOG(b->window);
 	dialogwindows = g_list_prepend(dialogwindows, b->window);
@@ -1236,6 +1250,8 @@
 	gtk_table_attach(GTK_TABLE(table), b->nameentry, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 	if (name !=NULL)
 		gtk_entry_set_text(GTK_ENTRY(b->nameentry), name);
+	else if(edit_bp)
+		gtk_entry_set_text(GTK_ENTRY(b->nameentry), edit_bp->name);
 	gtk_window_set_focus(GTK_WINDOW(b->window), b->nameentry);
 	gtk_widget_show(b->nameentry);
 	/* </pounce type="who"> */
@@ -1253,19 +1269,29 @@
 	gtk_widget_show(table);
 	
 	b->p_signon = gtk_check_button_new_with_label(_("Pounce on sign on"));
-	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->p_signon), TRUE);
+	if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->p_signon), 
+		                           (edit_bp->options & OPT_POUNCE_SIGNON) ? TRUE : FALSE);
+	else
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->p_signon), TRUE);
 	gtk_table_attach(GTK_TABLE(table), b->p_signon, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
 	gtk_widget_show(b->p_signon);
 
 	b->p_unaway = gtk_check_button_new_with_label(_("Pounce on return from away"));
 	if (away)
 		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->p_unaway), TRUE);
+	else if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->p_unaway), 
+					   (edit_bp->options & OPT_POUNCE_UNAWAY) ? TRUE : FALSE);
 	gtk_table_attach(GTK_TABLE(table), b->p_unaway, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 	gtk_widget_show(b->p_unaway);
 
 	b->p_unidle = gtk_check_button_new_with_label(_("Pounce on return from idle"));
 	if (idle)
 		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->p_unidle), TRUE);
+	else if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->p_unidle), 
+				           (edit_bp->options & OPT_POUNCE_UNIDLE) ? TRUE : FALSE);
 	gtk_table_attach(GTK_TABLE(table), b->p_unidle, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
 	gtk_widget_show(b->p_unidle);
 
@@ -1287,59 +1313,95 @@
 	gtk_widget_show(table);
 	
 	b->openwindow = gtk_check_button_new_with_label(_("Open IM Window"));
-	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->openwindow), FALSE);
+	if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->openwindow), 
+			                   (edit_bp->options & OPT_POUNCE_POPUP) ? TRUE : FALSE);
+	else
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->openwindow), FALSE);
 	gtk_table_attach(GTK_TABLE(table), b->openwindow, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
 	gtk_widget_show(b->openwindow);
-
+	
 	b->popupnotify = gtk_check_button_new_with_label(_("Popup Notification"));
-	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->popupnotify), FALSE);
+	if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->popupnotify), 
+					   (edit_bp->options & OPT_POUNCE_NOTIFY) ? TRUE : FALSE);
+	else
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->popupnotify), FALSE);
 	gtk_table_attach(GTK_TABLE(table), b->popupnotify, 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
 	gtk_widget_show(b->popupnotify);
 
 	b->sendim = gtk_check_button_new_with_label(_("Send Message"));
-	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->sendim), TRUE);
+	if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->sendim), 
+					   (edit_bp->options & OPT_POUNCE_SEND_IM) ? TRUE : FALSE);
+	else
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->sendim), TRUE);
 	gtk_table_attach(GTK_TABLE(table), b->sendim, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
 	gtk_widget_show(b->sendim);
 
 	b->messentry = gtk_entry_new();
 	gtk_table_attach(GTK_TABLE(table), b->messentry, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 	gtk_signal_connect(GTK_OBJECT(b->messentry), "activate", GTK_SIGNAL_FUNC(do_new_bp), b);
+	if(edit_bp) {
+		gtk_widget_set_sensitive(GTK_WIDGET(b->messentry), 
+					(edit_bp->options & OPT_POUNCE_SEND_IM) ? TRUE : FALSE);
+		gtk_entry_set_text(GTK_ENTRY(b->messentry), edit_bp->message);
+	}
 	gtk_widget_show(b->messentry);
 
-	gtk_signal_connect(GTK_OBJECT(b->sendim), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), 
-			b->messentry);
+	gtk_signal_connect(GTK_OBJECT(b->sendim), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive),	b->messentry);
 
 	b->command = gtk_check_button_new_with_label(_("Execute command on pounce"));
 	gtk_table_attach(GTK_TABLE(table), b->command, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
+	if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->command),
+					   (edit_bp->options & OPT_POUNCE_COMMAND) ? TRUE : FALSE);
+	else
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->command), FALSE);
 	gtk_widget_show(b->command);
 
 	b->commentry = gtk_entry_new();
 	gtk_table_attach(GTK_TABLE(table), b->commentry, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 	gtk_signal_connect(GTK_OBJECT(b->commentry), "activate", GTK_SIGNAL_FUNC(do_new_bp), b);
+	if(edit_bp) {
+		gtk_widget_set_sensitive(GTK_WIDGET(b->commentry), 
+					(edit_bp->options & OPT_POUNCE_COMMAND) ? TRUE : FALSE);
+		gtk_entry_set_text(GTK_ENTRY(b->commentry), edit_bp->command);
+	}
+	else
+		gtk_widget_set_sensitive(GTK_WIDGET(b->commentry), FALSE);
 	gtk_widget_show(b->commentry);
-
-	gtk_widget_set_sensitive(b->commentry, FALSE);
-	gtk_signal_connect(GTK_OBJECT(b->command), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive),
-			   b->commentry);
-
+	gtk_signal_connect(GTK_OBJECT(b->command), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), b->commentry);
+	
 	b->sound = gtk_check_button_new_with_label(_("Play sound on pounce"));
-	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->sound), FALSE);
+	if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->sound), 
+					   (edit_bp->options & OPT_POUNCE_SOUND) ? TRUE : FALSE);
+	else
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->sound), FALSE);
 	gtk_table_attach(GTK_TABLE(table), b->sound, 0, 1, 3, 4, GTK_FILL, 0, 0, 0);
 	gtk_widget_show(b->sound);
 
 	b->soundentry = gtk_entry_new();
 	gtk_table_attach(GTK_TABLE(table), b->soundentry, 1, 2, 3, 4, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 	gtk_signal_connect(GTK_OBJECT(b->soundentry), "activate", GTK_SIGNAL_FUNC(do_new_bp), b);
+	if(edit_bp) {
+		gtk_widget_set_sensitive(GTK_WIDGET(b->soundentry), 
+					(edit_bp->options & OPT_POUNCE_SOUND) ? TRUE : FALSE);
+		gtk_entry_set_text(GTK_ENTRY(b->soundentry), edit_bp->sound);
+	} else 
+		gtk_widget_set_sensitive(GTK_WIDGET(b->soundentry), FALSE);
 	gtk_widget_show(b->soundentry);
-
-	gtk_widget_set_sensitive(b->soundentry, FALSE);
-	gtk_signal_connect(GTK_OBJECT(b->sound), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive),
-			   b->soundentry);
+	gtk_signal_connect(GTK_OBJECT(b->sound), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), b->soundentry);
 	/* </pounce type="action"> */
 
 	b->save = gtk_check_button_new_with_label(_("Save this pounce after activation"));
 	gtk_container_set_border_width(GTK_CONTAINER(b->save), 7);
-	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->save), FALSE);
+	if(edit_bp)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->save),
+					   (edit_bp->options & OPT_POUNCE_SAVE) ? TRUE : FALSE);
+	else
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->save), FALSE);
 	gtk_box_pack_start(GTK_BOX(vbox), b->save, FALSE, FALSE, 0);
 	gtk_widget_show(b->save);
 
--- a/src/gaim.h	Sat Feb 23 23:28:49 2002 +0000
+++ b/src/gaim.h	Sat Feb 23 23:41:50 2002 +0000
@@ -159,18 +159,6 @@
 
 #define OPT_POUNCE_NOTIFY	0x200
 
-struct buddy_pounce {
-        char name[80];
-        char message[2048];
-	char command[2048];
-	char sound[2048];
-	
-	char pouncer[80];
-	int protocol;
-
-	int options;
-};
-
 #define CONVERSATION_TITLE "%s - Gaim"
 #define LOG_CONVERSATION_TITLE "%s - Gaim (logged)"
 
--- a/src/ui.h	Sat Feb 23 23:28:49 2002 +0000
+++ b/src/ui.h	Sat Feb 23 23:41:50 2002 +0000
@@ -194,6 +194,25 @@
 	char message[2048];
 };
 
+/****************************
+ * I thought I'd place these here by the same reasoning used above (for away_message)
+ * This helps aleviate warnings from dialogs.c where the show_new_bp function references
+ * buddy_pounce in the parameter list when ui.h doesn't know about buddy_pounce
+ * **************************
+ */
+struct buddy_pounce {
+        char name[80];
+        char message[2048];
+        char command[2048];
+        char sound[2048];
+        
+        char pouncer[80];
+        int protocol;
+
+        int options;
+};
+
+
 /* this is used for queuing messages received while away. This is really a UI function
  * which is why the struct is here. */
 struct queued_message {
@@ -392,7 +411,7 @@
 extern void destroy_all_dialogs();
 extern void show_import_dialog();
 extern void show_export_dialog();
-extern void show_new_bp(char *, struct gaim_connection *, int, int);
+extern void show_new_bp(char *, struct gaim_connection *, int, int, struct buddy_pounce *);
 extern void show_log(char *);
 extern void show_log_dialog(struct conversation *);
 extern void show_fgcolor_dialog(struct conversation *c, GtkWidget *color);