[Evolution-hackers] Bug #127526 Possible Fix + Questions

Tim Horton rhorton16@adelphia.net
Wed, 11 Aug 2004 21:51:22 -0400


--Apple-Mail-2-151649450
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

I have been working on Bug #127526, the "set Evolution as the default 
mail client" bounty.

I've got a very nicely working patch, with a "don't ask again" feature 
which can be toggled either when the dialog appears, or in the Mailer 
preferences pane.

The message will only appear when Evolution is _not_ the default mailer 
AND when Evolution is allowed to ask the user again.

One question I have : should I make future patches off of CVS or of the 
latest development release? This one is based off of the latest 
development release : 1.5.91. The only problem I have with applying the 
patch to the CVS copy is the Changelog (because of the 3 lines of 
context, etc...)

I was able to apply this patch by changing into the evolution-1.5.91 
directory and running 'patch -u -p 0 < ../patch-127526-2004.08.11'... I 
suppose you all know that though...

Sorry if I have done something wrong in this note, this is my first 
attempted contribution to any open source project (except my own). If 
anyone has any suggestions or comments or problems, please respond!

Tim

PATCH ---


--Apple-Mail-2-151649450
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="patch-127526-2004.08.11"
Content-Disposition: attachment;
	filename=patch-127526-2004.08.11

diff -upr ./mail/ChangeLog ../evolution-patch/mail/ChangeLog
--- ./mail/ChangeLog	2004-07-19 07:51:56.000000000 -0500
+++ ../evolution-patch/mail/ChangeLog	2004-08-11 07:48:34.000000000 -0500
@@ -1,3 +1,10 @@
+2004-08-09  Tim Horton  <rhorton16@adelphia.net>
+	* mail-component.c (mail_component_set_default,
+	mail_component_ask_default, mail_component_init): Added a dialog
+	to ask the user if they want Evolution to be set as the default
+	mail client - this then sets the proper copy of Evolution to be
+	GNOME's mailto: handler. This should fix bug #127526.
+
 2004-07-13  Jeffrey Stedfast  <fejj@novell.com>
 
 	* em-folder-view.c (emfv_message_reply): Chck that the selection
diff -upr ./mail/em-mailer-prefs.c ../evolution-patch/mail/em-mailer-prefs.c
--- ./mail/em-mailer-prefs.c	2004-06-25 21:21:09.000000000 -0500
+++ ../evolution-patch/mail/em-mailer-prefs.c	2004-08-11 18:31:59.000000000 -0500
@@ -724,6 +724,12 @@ em_mailer_prefs_construct (EMMailerPrefs
 	toggle_button_init (prefs, prefs->confirm_expunge, FALSE,
 			    "/apps/evolution/mail/prompts/expunge",
 			    G_CALLBACK (toggle_button_toggled));
+			    
+	/* Set as Default Mailer */
+	prefs->prompt_default_mailer = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkPromptDefaultMailer"));
+	toggle_button_init (prefs, prefs->prompt_default_mailer, FALSE,
+		  	  "/apps/evolution/mail/prompts/default_mailer",
+		 	   G_CALLBACK (toggle_button_toggled));
 	
 	/* New Mail Notification */
 	locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/notify/type", NULL);
diff -upr ./mail/em-mailer-prefs.h ../evolution-patch/mail/em-mailer-prefs.h
--- ./mail/em-mailer-prefs.h	2004-05-19 10:07:15.000000000 -0500
+++ ../evolution-patch/mail/em-mailer-prefs.h	2004-08-11 15:28:25.000000000 -0500
@@ -83,6 +83,9 @@ struct _EMMailerPrefs {
 	struct _GtkOptionMenu *empty_trash_days;
 	struct _GtkToggleButton *confirm_expunge;
 	
+	/* Default Mailer */
+	struct _GtkToggleButton *prompt_default_mailer;
+	
 	/* New Mail Notification */
 	struct _GtkToggleButton *notify_not;
 	struct _GtkToggleButton *notify_beep;
diff -upr ./mail/evolution-mail.schemas.in.in ../evolution-patch/mail/evolution-mail.schemas.in.in
--- ./mail/evolution-mail.schemas.in.in	2004-05-19 10:07:15.000000000 -0500
+++ ../evolution-patch/mail/evolution-mail.schemas.in.in	2004-08-11 18:32:54.000000000 -0500
@@ -645,6 +645,21 @@
          </long>
       </locale>
     </schema>
+    
+    <schema>
+      <key>/schemas/apps/evolution/mail/prompts/default_mailer</key>
+      <applyto>/apps/evolution/mail/prompts/default_mailer</applyto>
+      <owner>evolution-mail</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+         <short>Prompt when Evolution isn't the default mail client</short>
+         <long>
+          Prompt when user starts Evolution and it's not the default
+          mail client.
+         </long>
+      </locale>
+    </schema>
 
     <!-- Trash settings -->
 
@@ -811,6 +826,5 @@
          </long>
       </locale>
     </schema>
-
   </schemalist>
 </gconfschemafile>
diff -upr ./mail/mail-component.c ../evolution-patch/mail/mail-component.c
--- ./mail/mail-component.c	2004-06-25 21:21:09.000000000 -0500
+++ ../evolution-patch/mail/mail-component.c	2004-08-11 18:39:13.000000000 -0500
@@ -69,7 +69,13 @@
 
 #include "e-task-bar.h"
 
+#include <gtk/gtk.h>
+#include <gtk/gtkdialog.h>
 #include <gtk/gtklabel.h>
+#include <gtk/gtkwidget.h>
+
+#include <gconf/gconf-client.h>
+#include <gconf/gconf.h>
 
 #include <e-util/e-mktemp.h>
 
@@ -859,6 +865,72 @@ mail_component_init (MailComponent *comp
 	
 	offline = mail_offline_handler_new();
 	bonobo_object_add_interface((BonoboObject *)component, (BonoboObject *)offline);
+	
+	mail_component_ask_default();
+}
+
+void
+mail_component_ask_default()
+{
+	/* Ask the user if they want Evolution to be their default mail client */
+	
+	GConfClient *gconf_client;
+	GString *current_default_mailer;
+	gboolean *current_no_repeat;
+	gconf_init(0, NULL, NULL);
+	gconf_client = gconf_client_get_default();
+
+	current_default_mailer = g_string_new(gconf_client_get_string(gconf_client,
+		"/desktop/gnome/url-handlers/mailto/command", NULL));
+	current_no_repeat = gconf_client_get_bool(gconf_client,
+		"/apps/evolution/mail/prompts/default_mailer", NULL);
+	
+	if(!(g_string_equal(current_default_mailer, g_string_new("evolution-" BASE_VERSION " %s"))) &&
+		(current_no_repeat))
+	{
+		GtkWidget *default_mailer_dialog, *default_mailer_no_repeat_checkbox;
+		gint default_mailer_response;
+		gchar *default_mailer_message;
+	
+		default_mailer_dialog = gtk_message_dialog_new_with_markup(NULL,
+			GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, 
+			_("Would you like to make Evolution your default mail application?"));
+			
+		gtk_dialog_set_default_response(GTK_DIALOG(default_mailer_dialog), GTK_RESPONSE_YES);
+		default_mailer_no_repeat_checkbox = gtk_check_button_new_with_label(_("Don't ask me again"));
+		gtk_container_add(GTK_CONTAINER(GTK_DIALOG(default_mailer_dialog)->vbox), default_mailer_no_repeat_checkbox);
+		gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(default_mailer_dialog)->vbox), 12);
+		
+		gtk_window_set_position(GTK_WINDOW(default_mailer_dialog), GTK_WIN_POS_CENTER);
+		gtk_widget_show_all(default_mailer_dialog);
+		default_mailer_response = gtk_dialog_run((GtkDialog *)default_mailer_dialog);
+	
+		if(default_mailer_response == GTK_RESPONSE_YES)
+			mail_component_set_default();
+	
+		if(((GtkToggleButton *)default_mailer_no_repeat_checkbox)->active)
+			gconf_client_set_bool(gconf_client, "/apps/evolution/mail/prompts/default_mailer", FALSE, NULL);
+		
+		gtk_widget_destroy(default_mailer_dialog);
+	}
+	
+	g_object_unref(gconf_client);
+}
+
+void
+mail_component_set_default()
+{
+	GConfClient *gconf_client;
+	gconf_init(0, NULL, NULL);
+	gconf_client = gconf_client_get_default();
+	
+	gconf_client_set_string(gconf_client, "/desktop/gnome/url-handlers/mailto/command", "evolution-" BASE_VERSION " %s", NULL);
+	gconf_client_set_bool(gconf_client, "/desktop/gnome/url-handlers/mailto/enabled", TRUE, NULL);
+	gconf_client_set_bool(gconf_client, "/desktop/gnome/url-handlers/mailto/needs_terminal", FALSE, NULL);
+
+	g_object_unref(gconf_client);
 }
 
 /* Public API.  */
diff -upr ./mail/mail-component.h ../evolution-patch/mail/mail-component.h
--- ./mail/mail-component.h	2004-05-19 10:07:15.000000000 -0500
+++ ../evolution-patch/mail/mail-component.h	2004-08-09 14:40:20.000000000 -0500
@@ -96,4 +96,7 @@ struct _CamelStore *mail_component_peek_
 struct _CamelFolder *mail_component_get_folder(MailComponent *mc, enum _mail_component_folder_t id);
 const char *mail_component_get_folder_uri(MailComponent *mc, enum _mail_component_folder_t id);
 
+void mail_component_set_default();
+void mail_component_ask_default();
+
 #endif /* _MAIL_COMPONENT_H_ */
diff -upr ./mail/mail-config.glade ../evolution-patch/mail/mail-config.glade
--- ./mail/mail-config.glade	2004-06-25 21:21:10.000000000 -0500
+++ ../evolution-patch/mail/mail-config.glade	2004-08-11 18:38:43.000000000 -0500
@@ -5065,6 +5065,122 @@ For example: &quot;Work&quot; or &quot;P
 	      <property name="fill">False</property>
 	    </packing>
 	  </child>
+	  
+	  <child>
+	    <widget class="GtkVBox" id="DefaultMailerFrame">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">6</property>
+
+	      <child>
+		<widget class="GtkLabel" id="label496">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot;&gt;Default Mail Application&lt;/span&gt;</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">False</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xpad">0</property>
+		  <property name="ypad">0</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkHBox" id="hbox184">
+		  <property name="visible">True</property>
+		  <property name="homogeneous">False</property>
+		  <property name="spacing">12</property>
+
+		  <child>
+		    <widget class="GtkLabel" id="label542">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes"></property>
+		      <property name="use_underline">False</property>
+		      <property name="use_markup">False</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0.5</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">0</property>
+		      <property name="ypad">0</property>
+		    </widget>
+		    <packing>
+		      <property name="padding">0</property>
+		      <property name="expand">False</property>
+		      <property name="fill">False</property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkTable" id="table24">
+		      <property name="visible">True</property>
+		      <property name="n_rows">1</property>
+		      <property name="n_columns">1</property>
+		      <property name="homogeneous">False</property>
+		      <property name="row_spacing">2</property>
+		      <property name="column_spacing">6</property>
+
+		      <child>
+			<widget class="GtkVBox" id="vboxDefaultMailer">
+			  <property name="visible">True</property>
+			  <property name="homogeneous">False</property>
+			  <property name="spacing">6</property>
+			  <child>
+			    <widget class="GtkCheckButton" id="chkPromptDefaultMailer">
+			      <property name="visible">True</property>
+			      <property name="can_focus">True</property>
+			      <property name="label" translatable="yes">_Ask to set Evolution as the default mail application</property>
+			      <property name="use_underline">True</property>
+			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
+			      <property name="active">False</property>
+			      <property name="inconsistent">False</property>
+			      <property name="draw_indicator">True</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">1</property>
+			  <property name="top_attach">0</property>
+			  <property name="bottom_attach">1</property>
+			</packing>
+		      </child>
+		    </widget>
+		    <packing>
+		      <property name="padding">0</property>
+		      <property name="expand">True</property>
+		      <property name="fill">True</property>
+		    </packing>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">False</property>
+	    </packing>
+	  </child>
 
 	  <child>
 	    <widget class="GtkVBox" id="MailNotifyFrame">

--Apple-Mail-2-151649450
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed



PATCH ---
--Apple-Mail-2-151649450--