diff src/gtkrequest.c @ 10229:9aa0b6d11bbf

[gaim-migrate @ 11364] This is a heavily warmenhoved patch from Alceste Scalas. Here's what it changes: If the user drags an image file into the buddy list or conversation, it presents three options (when applicable): Set as buddy icon - sets this image to be the buddy icon for this buddy Send image file - Initiates a file transfer to send this image. Insert in message - Inserts in the gtkimhtml for use as an IM image. If the user drags a .desktop web link, it will insert a hyperlink in the conversation. All other types of .desktop files fail with an error dialog. If anyone can think of better ways to handle any of them, let me know. This also happens to implement gaim_request_choice, which had previously been unimplemented. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Mon, 22 Nov 2004 02:57:34 +0000
parents ecf3ce2e2ab1
children e8d62dc363c5
line wrap: on
line diff
--- a/src/gtkrequest.c	Sun Nov 21 20:36:15 2004 +0000
+++ b/src/gtkrequest.c	Mon Nov 22 02:57:34 2004 +0000
@@ -44,7 +44,7 @@
 	GaimRequestType type;
 
 	void *user_data;
-	GtkWidget *dialog;
+GtkWidget *dialog;
 
 	GtkWidget *ok_button;
 
@@ -134,6 +134,23 @@
 	gaim_request_close(GAIM_REQUEST_INPUT, data);
 }
 
+
+static void
+choice_response_cb(GtkDialog *dialog, gint id, GaimGtkRequestData *data)
+{
+	GtkWidget *radio = g_object_get_data(G_OBJECT(dialog), "radio");
+	GSList *group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio));
+	if (id < data->cb_count)
+		while (group) {
+			if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(group->data))) {
+				((GaimRequestChoiceCb)data->cbs[id])(data->user_data, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(group->data), "choice_id")));
+				break;
+			}
+			group = group->next;
+		}
+	gaim_request_close(GAIM_REQUEST_INPUT, data);
+}
+
 static gboolean
 field_string_focus_out_cb(GtkWidget *entry, GdkEventFocus *event,
 						  GaimRequestField *field)
@@ -404,12 +421,100 @@
 
 static void *
 gaim_gtk_request_choice(const char *title, const char *primary,
-						const char *secondary, unsigned int default_value,
-						const char *ok_text, GCallback ok_cb,
-						const char *cancel_text, GCallback cancel_cb,
-						void *user_data, size_t choice_count, va_list args)
+			const char *secondary, unsigned int default_value,
+			const char *ok_text, GCallback ok_cb,
+			const char *cancel_text, GCallback cancel_cb,
+			void *user_data, va_list args)
 {
-	return NULL;
+	GaimGtkRequestData *data;
+	GtkWidget *dialog;
+	GtkWidget *vbox, *vbox2;
+	GtkWidget *hbox;
+	GtkWidget *label;
+	GtkWidget *img;
+	GtkWidget *radio = NULL;
+	char *label_text;
+	char *radio_text;
+	
+	data            = g_new0(GaimGtkRequestData, 1);
+	data->type      = GAIM_REQUEST_ACTION;
+	data->user_data = user_data;
+
+	data->cb_count = 2;
+	data->cbs = g_new0(GCallback, 2);
+	data->cbs[0] = cancel_cb;
+	data->cbs[1] = ok_cb;
+
+	/* Create the dialog. */
+	data->dialog = dialog = gtk_dialog_new();
+
+	if (title != NULL)
+		gtk_window_set_title(GTK_WINDOW(dialog), title);
+
+
+	gtk_dialog_add_button(GTK_DIALOG(dialog),
+			      text_to_stock(cancel_text), 0);
+	
+	gtk_dialog_add_button(GTK_DIALOG(dialog),
+			      text_to_stock(ok_text), 1);
+
+	g_signal_connect(G_OBJECT(dialog), "response",
+			 G_CALLBACK(choice_response_cb), data);
+
+	/* Setup the dialog */
+	gtk_container_set_border_width(GTK_CONTAINER(dialog), 6);
+	gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
+	gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
+	gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12);
+	gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6);
+
+	/* Setup the main horizontal box */
+	hbox = gtk_hbox_new(FALSE, 12);
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
+
+	/* Dialog icon. */
+	img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
+				       GTK_ICON_SIZE_DIALOG);
+	gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
+	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
+
+	/* Vertical box */
+	vbox = gtk_vbox_new(FALSE, 12);
+	gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
+	
+	/* Descriptive label */
+	label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">"
+				      "%s</span>%s%s" : "%s%s%s"),
+				     (primary ? primary : ""),
+				     ((primary && secondary) ? "\n\n" : ""),
+				     (secondary ? secondary : ""));
+	
+	label = gtk_label_new(NULL);
+
+	gtk_label_set_markup(GTK_LABEL(label), label_text);
+	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, TRUE, TRUE, 0);
+
+	g_free(label_text);
+	
+	vbox2 = gtk_vbox_new(FALSE, 6);
+	gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 0);
+	while ((radio_text = va_arg(args, char*))) {
+		       int resp = va_arg(args, int);
+		       radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio), radio_text);
+		       gtk_box_pack_start(GTK_BOX(vbox2), radio, FALSE, FALSE, 0);
+		       g_object_set_data(G_OBJECT(radio), "choice_id", GINT_TO_POINTER(resp));
+		       if (resp == default_value)
+			       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
+	}
+	 
+	g_object_set_data(G_OBJECT(dialog), "radio", radio);
+
+	/* Show everything. */
+	gtk_widget_show_all(dialog);
+
+	return data;
 }
 
 static void *