[evolution-patches] [Addressbook] Make contact editor use GtkFileChooser



This patch makes the address book's contact editor use GtkFileChooser
where available.

-- 
Hans Petter
? 57795.patch
? 58921.patch
? 60529.patch
? 62085.patch
? 62142.patch
? 62715.patch
? birthdate.patch
? ce-use-gtkfilechooser.patch
? log.diff
? out.diff
? gui/component/ldap-config.gladep
? gui/component/old
? gui/component/out
? gui/component/select-names/crap
? gui/contact-editor/hpj-contact-editor.glade
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1813
diff -u -p -r1.1813 ChangeLog
--- ChangeLog	19 Aug 2004 20:33:10 -0000	1.1813
+++ ChangeLog	20 Aug 2004 01:20:39 -0000
@@ -1,3 +1,18 @@
+2004-08-19  Hans Petter Jansson  <hpj ximian com>
+
+	Makes the contact image selector use GtkFileChooser if available.
+
+	* gui/contact-editor/e-contact-editor.c (image_selected_cb): Take just
+	the editor as an argument, so we can call from other places without
+	having to supply dummy args. Rename to image_selected, since it's no
+	longer strictly a callback. Include optional code to use the new
+	GtkFileChooser.
+	(image_cleared_cb): Ditto. Rename to image_cleared.
+	(file_chooser_response): Optional response handling for GtkFileChooser.
+	(image_clicked): Include optional code to use the new GtkFileChooser.
+	Move common strings to variables. For GtkFileSelection, swap callback
+	parameters for the modified image_selected () and image_cleared ().
+
 2004-08-19  Chris Toshok  <toshok ximian com>
 
 	[ likely fixes #61500 ]
Index: gui/contact-editor/e-contact-editor.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-editor/e-contact-editor.c,v
retrieving revision 1.214
diff -u -p -r1.214 e-contact-editor.c
--- gui/contact-editor/e-contact-editor.c	16 Aug 2004 23:43:34 -0000	1.214
+++ gui/contact-editor/e-contact-editor.c	20 Aug 2004 01:20:39 -0000
@@ -2447,12 +2447,17 @@ categories_clicked (GtkWidget *button, E
 }
 
 static void
-image_selected_cb (GtkWidget *widget, EContactEditor *editor)
+image_selected (EContactEditor *editor)
 {
-	const gchar *file_name;
-	GtkWidget   *image_chooser;
+	gchar     *file_name;
+	GtkWidget *image_chooser;
+
+#ifdef USE_GTKFILECHOOSER
+	file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (editor->file_selector));
+#else
+	file_name = (gchar *) gtk_file_selection_get_filename (GTK_FILE_SELECTION (editor->file_selector));
+#endif
 
-	file_name = gtk_file_selection_get_filename (GTK_FILE_SELECTION (editor->file_selector));
 	if (!file_name)
 		return;
 
@@ -2467,7 +2472,7 @@ image_selected_cb (GtkWidget *widget, EC
 }
 
 static void
-image_cleared_cb (GtkWidget *widget, EContactEditor *editor)
+image_cleared (EContactEditor *editor)
 {
 	GtkWidget *image_chooser;
 	gchar     *file_name;
@@ -2486,6 +2491,21 @@ image_cleared_cb (GtkWidget *widget, ECo
 	object_changed (G_OBJECT (image_chooser), editor);
 }
 
+#ifdef USE_GTKFILECHOOSER
+
+static void
+file_chooser_response (GtkWidget *widget, gint response, EContactEditor *editor)
+{
+	if (response == GTK_RESPONSE_ACCEPT)
+		image_selected (editor);
+	else if (response == GTK_RESPONSE_NO)
+		image_cleared (editor);
+
+	gtk_widget_hide (editor->file_selector);
+}
+
+#endif
+
 static gboolean
 file_selector_deleted (GtkWidget *widget)
 {
@@ -2498,23 +2518,40 @@ image_clicked (GtkWidget *button, EConta
 {
 	GtkWidget *clear_button;
 	GtkWidget *dialog;
+	const gchar *title = _("Please select an image for this contact");
+	const gchar *no_image = _("No image");
 
 	if (!editor->file_selector) {
+#ifdef USE_GTKFILECHOOSER
+		editor->file_selector = gtk_file_chooser_dialog_new (title,
+								     GTK_WINDOW (editor->app),
+								     GTK_FILE_CHOOSER_ACTION_OPEN,
+								     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+								     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+								     no_image, GTK_RESPONSE_NO,
+								     NULL);
+		gtk_dialog_set_default_response (GTK_DIALOG (editor->file_selector), GTK_RESPONSE_ACCEPT);
+
+		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (editor->file_selector), g_get_home_dir ());
+
+		g_signal_connect (editor->file_selector, "response",
+				  G_CALLBACK (file_chooser_response), editor);
+#else
 		/* Create the selector */
 
-		editor->file_selector = gtk_file_selection_new (_("Please select an image for this contact"));
+		editor->file_selector = gtk_file_selection_new (title);
 
 		dialog = GTK_FILE_SELECTION (editor->file_selector)->fileop_dialog;
 
-		clear_button = gtk_dialog_add_button (GTK_DIALOG (editor->file_selector), _("No image"), 0);
+		clear_button = gtk_dialog_add_button (GTK_DIALOG (editor->file_selector), no_image, 0);
 
-		g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (editor->file_selector)->ok_button),
-				  "clicked", G_CALLBACK (image_selected_cb), editor);
+		g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (editor->file_selector)->ok_button),
+					  "clicked", G_CALLBACK (image_selected), editor);
 
-		g_signal_connect (clear_button,
-				  "clicked", G_CALLBACK (image_cleared_cb), editor);
+		g_signal_connect_swapped (clear_button,
+					  "clicked", G_CALLBACK (image_cleared), editor);
 
-		/* Ensure that the dialog box is hidden when the user clicks a button */
+		/* Ensure that the dialog box gets hidden when the user clicks a button */
 
 		g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (editor->file_selector)->ok_button),
 					  "clicked", G_CALLBACK (gtk_widget_hide), editor->file_selector); 
@@ -2524,6 +2561,7 @@ image_clicked (GtkWidget *button, EConta
 
 		g_signal_connect_swapped (clear_button,
 					  "clicked", G_CALLBACK (gtk_widget_hide), editor->file_selector); 
+#endif
 
 		g_signal_connect_after (editor->file_selector,
 					"delete-event", G_CALLBACK (file_selector_deleted),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]