changeset 7927:1441648fe974

[gaim-migrate @ 8598] De-uglify the insert link and insert image buttons a bit. Closing the insert image dialog via the window manager now makes the insert image button un-depress itself. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 25 Dec 2003 09:23:27 +0000
parents 68900f9cb540
children dca50d465b7d
files src/dialogs.c src/gtkconv.c src/ui.h
diffstat 3 files changed, 117 insertions(+), 155 deletions(-) [+]
line wrap: on
line diff
--- a/src/dialogs.c	Wed Dec 24 01:48:25 2003 +0000
+++ b/src/dialogs.c	Thu Dec 25 09:23:27 2003 +0000
@@ -80,7 +80,6 @@
 	GtkWidget *window;
 	GtkWidget *url;
 	GtkWidget *text;
-	GtkWidget *toggle;
 	GtkWidget *entry;
 	GaimConversation *c;
 };
@@ -234,7 +233,6 @@
 	img = gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_MENU);
 	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
 	labeltext = _("<b>Anonymous warnings are less severe.</b>");
-	/* labeltext = _("Anonymous warnings are less severe."); */
 	label = gtk_label_new(NULL);
 	gtk_label_set_markup(GTK_LABEL(label), labeltext);
 	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
@@ -678,66 +676,49 @@
 }
 
 
-static void
-free_dialog(GtkWidget *w, void *data)
-{
-	g_free(data);
-}
-
 /*------------------------------------------------------*/
 /* Link Dialog                                          */
 /*------------------------------------------------------*/
 
-void cancel_link(GtkWidget *widget, GaimConversation *c)
+void dialog_link_destroy(GaimConversation *c)
 {
 	GaimGtkConversation *gtkconv;
-	GtkWidget *link_dialog;
 
 	gtkconv = GAIM_GTK_CONVERSATION(c);
 
-	if (gtkconv->toolbar.link) {
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link),
-									FALSE);
-	}
-
-	link_dialog = gtkconv->dialogs.link;
+	gtk_widget_destroy(gtkconv->dialogs.link);
 	gtkconv->dialogs.link = NULL;
-	destroy_dialog(NULL, link_dialog);
 }
 
-void do_insert_link(GtkWidget *w, int resp, struct linkdlg *b)
+static void do_insert_link(GtkWidget *w, int resp, struct linkdlg *a)
 {
 	GaimGtkConversation *gtkconv;
-	char *open_tag;
 	const char *urltext, *showtext;
 
-	gtkconv = GAIM_GTK_CONVERSATION(b->c);
+	gtkconv = GAIM_GTK_CONVERSATION(a->c);
 
 	if (resp == GTK_RESPONSE_OK) {
-
-		open_tag = g_malloc(2048);
-
-		urltext = gtk_entry_get_text(GTK_ENTRY(b->url));
-		showtext = gtk_entry_get_text(GTK_ENTRY(b->text));
+		urltext = gtk_entry_get_text(GTK_ENTRY(a->url));
+		showtext = gtk_entry_get_text(GTK_ENTRY(a->text));
 
 		if (!strlen(showtext))
 			showtext = urltext;
 
 		gtk_imhtml_insert_link(GTK_IMHTML(gtkconv->entry), urltext, showtext);
-
-		g_free(open_tag);
+		gaim_gtk_advance_past(gtkconv, "<A HREF>", "</A>");
 	}
 
-	if (gtkconv->toolbar.link) {
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link),
-									FALSE);
-	}
-
-	gtkconv->dialogs.link = NULL;
-	destroy_dialog(NULL, b->window);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link), FALSE);
 }
 
-void show_insert_link(GtkWidget *linky, GaimConversation *c)
+static void dialog_link_freedata(GtkWidget *w, gpointer user_data)
+{
+	struct linkdlg *a = user_data;
+
+	g_free(a);
+}
+
+void dialog_link_show(GaimConversation *c)
 {
 	GaimGtkConversation *gtkconv;
 	GaimGtkWindow *gtkwin;
@@ -745,82 +726,78 @@
 	GtkWidget *label;
 	GtkWidget *hbox;
 	GtkWidget *vbox;
+	struct linkdlg *a;
+	GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
 
 	gtkconv = GAIM_GTK_CONVERSATION(c);
 	gtkwin  = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
 
-	if (gtkconv->dialogs.link == NULL) {
-		struct linkdlg *a = g_new0(struct linkdlg, 1);
-		GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
+	a = g_new0(struct linkdlg, 1);
 
-		a->c = c;
-		a->window = gtk_dialog_new_with_buttons(_("Insert Link"),
-				GTK_WINDOW(gtkwin->window), 0, GTK_STOCK_CANCEL,
-				GTK_RESPONSE_CANCEL, _("_Insert"), GTK_RESPONSE_OK, NULL);
-		gtk_dialog_set_default_response(GTK_DIALOG(a->window), GTK_RESPONSE_OK);
-		g_signal_connect(G_OBJECT(a->window), "response",
-						 G_CALLBACK(do_insert_link), a);
+	a->c = c;
+	a->window = gtk_dialog_new_with_buttons(_("Insert Link"),
+			GTK_WINDOW(gtkwin->window), 0, GTK_STOCK_CANCEL,
+			GTK_RESPONSE_CANCEL, _("_Insert"), GTK_RESPONSE_OK, NULL);
+	gtk_dialog_set_default_response(GTK_DIALOG(a->window), GTK_RESPONSE_OK);
+	g_signal_connect(G_OBJECT(a->window), "response",
+					 G_CALLBACK(do_insert_link), a);
+	g_signal_connect(G_OBJECT(a->window), "destroy",
+					 G_CALLBACK(dialog_link_freedata), a);
 
-		gtk_dialog_set_default_response(GTK_DIALOG(a->window), GTK_RESPONSE_OK);
-		gtk_container_set_border_width(GTK_CONTAINER(a->window), 6);
-		gtk_window_set_resizable(GTK_WINDOW(a->window), FALSE);
-		gtk_dialog_set_has_separator(GTK_DIALOG(a->window), FALSE);
-		gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(a->window)->vbox), 12);
-		gtk_container_set_border_width(
-			GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), 6);
-		gtk_window_set_role(GTK_WINDOW(a->window), "insert_link");
-		gtk_dialog_set_response_sensitive(GTK_DIALOG(a->window), GTK_RESPONSE_OK, FALSE);
+	gtk_dialog_set_default_response(GTK_DIALOG(a->window), GTK_RESPONSE_OK);
+	gtk_container_set_border_width(GTK_CONTAINER(a->window), 6);
+	gtk_window_set_resizable(GTK_WINDOW(a->window), FALSE);
+	gtk_dialog_set_has_separator(GTK_DIALOG(a->window), FALSE);
+	gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(a->window)->vbox), 12);
+	gtk_container_set_border_width(
+		GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), 6);
+	gtk_window_set_role(GTK_WINDOW(a->window), "insert_link");
+	gtk_dialog_set_response_sensitive(GTK_DIALOG(a->window), GTK_RESPONSE_OK, FALSE);
 
-		hbox = gtk_hbox_new(FALSE, 12);
-		gtk_container_add(GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), hbox);
-		gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
-		gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
+	hbox = gtk_hbox_new(FALSE, 12);
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), hbox);
+	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
+	gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
 
-		vbox = gtk_vbox_new(FALSE, 0);
-		gtk_container_add(GTK_CONTAINER(hbox), vbox);
+	vbox = gtk_vbox_new(FALSE, 0);
+	gtk_container_add(GTK_CONTAINER(hbox), vbox);
 
-		label = gtk_label_new(_("Please enter the URL and description of "
-								"the link that you want to insert.  The "
-								"description is optional.\n"));
-		gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
-		gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
-		gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+	label = gtk_label_new(_("Please enter the URL and description of "
+							"the link that you want to insert.  The "
+							"description is optional.\n"));
+	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
 
-		table = gtk_table_new(2, 2, FALSE);
-		gtk_table_set_row_spacings(GTK_TABLE(table), 6);
-		gtk_table_set_col_spacings(GTK_TABLE(table), 6);
-		gtk_container_set_border_width(GTK_CONTAINER(table), 0);
-		gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
+	table = gtk_table_new(2, 2, FALSE);
+	gtk_table_set_row_spacings(GTK_TABLE(table), 6);
+	gtk_table_set_col_spacings(GTK_TABLE(table), 6);
+	gtk_container_set_border_width(GTK_CONTAINER(table), 0);
+	gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
 
-		label = gtk_label_new_with_mnemonic(_("_URL:"));
-		gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-		gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
+	label = gtk_label_new_with_mnemonic(_("_URL:"));
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
 
-		a->url = gtk_entry_new();
-		gtk_table_attach_defaults(GTK_TABLE(table), a->url, 1, 2, 0, 1);
-		gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(a->url));
-		gtk_widget_grab_focus(a->url);
+	a->url = gtk_entry_new();
+	gtk_table_attach_defaults(GTK_TABLE(table), a->url, 1, 2, 0, 1);
+	gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(a->url));
+	gtk_widget_grab_focus(a->url);
 
-		gtk_entry_set_activates_default (GTK_ENTRY(a->url), TRUE);
-		g_signal_connect(G_OBJECT(a->url), "changed",
-				G_CALLBACK(gaim_gtk_set_sensitive_if_input), a->window);
-
-		label = gtk_label_new_with_mnemonic(_("_Description:"));
-		gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-		gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
+	gtk_entry_set_activates_default (GTK_ENTRY(a->url), TRUE);
+	g_signal_connect(G_OBJECT(a->url), "changed",
+			G_CALLBACK(gaim_gtk_set_sensitive_if_input), a->window);
 
-		a->text = gtk_entry_new();
-		gtk_table_attach_defaults(GTK_TABLE(table), a->text, 1, 2, 1, 2);
-		gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(a->text));
-		gtk_entry_set_activates_default (GTK_ENTRY(a->text), TRUE);
+	label = gtk_label_new_with_mnemonic(_("_Description:"));
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
 
-		g_signal_connect(G_OBJECT(a->window), "destroy",
-						 G_CALLBACK(free_dialog), a);
-		dialogwindows = g_list_prepend(dialogwindows, a->window);
+	a->text = gtk_entry_new();
+	gtk_table_attach_defaults(GTK_TABLE(table), a->text, 1, 2, 1, 2);
+	gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(a->text));
+	gtk_entry_set_activates_default (GTK_ENTRY(a->text), TRUE);
 
-		a->toggle = linky;
-		gtkconv->dialogs.link = a->window;
-	}
+	gtkconv->dialogs.link = a->window;
 
 	gtk_widget_show_all(gtkconv->dialogs.link);
 	gdk_window_raise(gtkconv->dialogs.link->window);
--- a/src/gtkconv.c	Wed Dec 24 01:48:25 2003 +0000
+++ b/src/gtkconv.c	Thu Dec 25 09:23:27 2003 +0000
@@ -193,37 +193,38 @@
 }
 
 static void
-do_insert_image_cb(GObject *obj, GtkWidget *wid)
+do_insert_image_cb(GtkWidget *widget, int resp, gpointer data)
 {
-	GaimConversation *conv;
-	GaimGtkConversation *gtkconv;
-	GaimConvIm *im;
+	GaimConversation *conv = data;
+	GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
+	GaimConvIm *im = GAIM_CONV_IM(conv);
 	char *name, *filename;
-	char *buf, *data;
+	char *buf, *filedata;
 	size_t size;
-	GError *error;
+	GError *error = NULL;
 	int id;
 
-	conv    = g_object_get_data(G_OBJECT(wid), "user_data");
-	gtkconv = GAIM_GTK_CONVERSATION(conv);
-	im      = GAIM_CONV_IM(conv);
-	name    = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)));
+	if (resp != GTK_RESPONSE_OK) {
+		set_toggle(gtkconv->toolbar.image, FALSE);
+		return;
+	}
+
+	name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(widget)));
 
 	if (!name) {
-		gtk_widget_destroy(gtkconv->dialogs.image);
-		gtkconv->dialogs.image = NULL;
+		set_toggle(gtkconv->toolbar.image, FALSE);
 		return;
 	}
 
-	if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(wid))) {
+	if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(widget))) {
 		g_free(name);
+		set_toggle(gtkconv->toolbar.image, FALSE);
 		return;
 	}
 
-	gtk_widget_destroy(gtkconv->dialogs.image);
-	gtkconv->dialogs.image = NULL;
-
-	if (!g_file_get_contents(name, &data, &size, &error)) {
+	set_toggle(gtkconv->toolbar.image, FALSE);
+
+	if (!g_file_get_contents(name, &filedata, &size, &error)) {
 		gaim_notify_error(NULL, NULL, error->message, NULL);
 
 		g_error_free(error);
@@ -236,8 +237,8 @@
 	while (strchr(filename, '/'))
 		filename = strchr(filename, '/') + 1;
 
-	id = gaim_imgstore_add(data, size, filename);
-	g_free(data);
+	id = gaim_imgstore_add(filedata, size, filename);
+	g_free(filedata);
 
 	if (!id) {
 		buf = g_strdup_printf(_("Failed to store image: %s\n"), name);
@@ -256,8 +257,6 @@
 	g_free(buf);
 
 	g_free(name);
-
-	set_toggle(gtkconv->toolbar.image, FALSE);
 }
 
 static gint
@@ -289,18 +288,6 @@
 }
 
 static void
-cancel_insert_image_cb(GtkWidget *unused, GaimGtkConversation *gtkconv)
-{
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.image),
-								 FALSE);
-
-	if (gtkconv->dialogs.image)
-		gtk_widget_destroy(gtkconv->dialogs.image);
-
-	gtkconv->dialogs.image = NULL;
-}
-
-static void
 insert_image_cb(GtkWidget *save, GaimConversation *conv)
 {
 	GaimGtkConversation *gtkconv;
@@ -314,18 +301,14 @@
 		g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S, gaim_home_dir());
 		gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf);
 
-		g_object_set_data(G_OBJECT(window), "user_data", conv);
-		g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
-				"clicked", G_CALLBACK(do_insert_image_cb), window);
-		g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->cancel_button),
-						 "clicked", G_CALLBACK(cancel_insert_image_cb), gtkconv);
+		gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_OK);
+		g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)),
+				"response", G_CALLBACK(do_insert_image_cb), conv);
 
 		gtk_widget_show(window);
 		gtkconv->dialogs.image = window;
 	} else {
-		gtk_widget_grab_focus(gtkconv->entry);
-		if(gtkconv->dialogs.image)
-			gtk_widget_destroy(gtkconv->dialogs.image);
+		gtk_widget_destroy(gtkconv->dialogs.image);
 		gtkconv->dialogs.image = NULL;
 	}
 }
@@ -338,11 +321,9 @@
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
 
 	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link)))
-		show_insert_link(gtkconv->toolbar.link, conv);
-	else if (gtkconv->dialogs.link)
-		cancel_link(gtkconv->toolbar.link, conv);
+		dialog_link_show(conv);
 	else
-		gaim_gtk_advance_past(gtkconv, "<A HREF>", "</A>");
+		dialog_link_destroy(conv);
 
 	gtk_widget_grab_focus(gtkconv->entry);
 }
@@ -769,12 +750,14 @@
 	GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
     GtkWidget *table;
     GtkWidget *labelbox, *bbox;
-    GtkWidget *button, *align;
+    GtkWidget *button;
 	GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
 	GtkWidget *label, *entry;
 	struct _search *s;
+/*
 	gint signal_id;
 	GClosure *closure;
+*/
 
 	if (gtkconv->dialogs.search) {
 		gtk_window_present(GTK_WINDOW(gtkconv->dialogs.search));
@@ -867,7 +850,8 @@
 	conv    = gaim_conv_window_get_active_conversation(win);
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
 
-	show_insert_link(gtkconv->toolbar.link, conv);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link),
+		!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link)));
 }
 
 static void
@@ -3479,6 +3463,17 @@
 	sep = gtk_vseparator_new();
 	gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0);
 
+	/* Insert Link */
+	button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK);
+	gtk_size_group_add_widget(sg, button);
+	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+	gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert link"), NULL);
+
+	g_signal_connect(G_OBJECT(button), "clicked",
+					 G_CALLBACK(insert_link_cb), conv);
+
+	gtkconv->toolbar.link = button;
+
 	/* Insert IM Image */
 	button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_IMAGE);
 	gtk_size_group_add_widget(sg, button);
@@ -3490,17 +3485,6 @@
 
 	gtkconv->toolbar.image = button;
 
-	/* Insert Link */
-	button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK);
-	gtk_size_group_add_widget(sg, button);
-	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-	gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert link"), NULL);
-
-	g_signal_connect(G_OBJECT(button), "clicked",
-					 G_CALLBACK(insert_link_cb), conv);
-
-	gtkconv->toolbar.link = button;
-
 	/* Insert Smiley */
 	button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY);
 	gtk_size_group_add_widget(sg, button);
--- a/src/ui.h	Wed Dec 24 01:48:25 2003 +0000
+++ b/src/ui.h	Thu Dec 25 09:23:27 2003 +0000
@@ -131,12 +131,12 @@
 extern void cancel_fgcolor(GtkWidget *widget, GaimConversation *c);
 extern void cancel_bgcolor(GtkWidget *widget, GaimConversation *c);
 extern void create_away_mess(GtkWidget *, void *);
-extern void show_insert_link(GtkWidget *,GaimConversation *);
+extern void dialog_link_show(GaimConversation *);
+extern void dialog_link_destroy(GaimConversation *);
 extern void show_smiley_dialog(GaimConversation *, GtkWidget *);
 extern void close_smiley_dialog(GtkWidget *widget, GaimConversation *c);
 extern void set_smiley_array(GtkWidget *widget, int smiley_type);
 extern void insert_smiley_text(GtkWidget *widget, GaimConversation *c);
-extern void cancel_link(GtkWidget *, GaimConversation *);
 extern void show_font_dialog(GaimConversation *c, GtkWidget *font);
 extern void cancel_font(GtkWidget *widget, GaimConversation *c);
 extern void apply_font(GtkWidget *widget, GtkFontSelection *fontsel);
@@ -145,6 +145,7 @@
 
 /* Functions in server.c */
 /* server.c is in desperate need need of a split */
+/* pizza pizza */
 extern int find_queue_total_by_name(char *);
 
 /* Functions in session.c */