Re: [evolution-patches] camel provider changes for connector



Hi Jeff/NotZed,

Thanks a lot for those review comments. I have done the changes you and NotZed had suggested. I have attached the updated patch with this mail. But, i wanted to understand what i was doing wrong, so i have a few silly questions written down in the mail. Please help me understand them better.

I would say get rid of the BUFSIZE macro.

Done
+       GtkTextIter iter;
+       g_sprintf (fname, "%s/../%s", EVOLUTION_GLADEDIR, filename);

this looks pretty dodgy.

1. don't use a static buffer for the filename
2. don't use "../" in a path, better to create a new string macro defined in configure.in or wherever for these license files - or maybe the connector can just hold onto the entire filename itself (and may in fact need to?)

Yeah, that was a lazy workaround ... now, i have modified the code so that the mail provider should directly provide the absolute file name. camel config, just uses it. Apart from that, what's this funda of static buffer ?? I did not understand why i should not be using a static buffer for the filename

+
+               count = fread (filebuf, 1, (BUFSIZE - 1), fd);

count = fread (filebuf, 1, sizeof (filebuf), fd);

Done ...

+               filebuf [count] = '\0';

get rid of this statement

Done ...

+               gtk_text_buffer_insert (buffer, &iter, filebuf, -1);

gtk_text_buffer_insert (buffer, &iter, filebuf, count);

Done ... but wanted to understand why using -1, and the null termination was wrong ..
+       }
+               accepted = gconf_client_get_bool (gconf, prov->gconf_license_bool_key, NULL);

I don't like prov->gconf_license_bool_key. a different name needs to be used and it shouldn't be a gconf key.

maybe something more like prov->license which is a string that the mailer appends to another string, "/apps/evolution/mail/licenses/%s_accepted" to get the actual gconf key.

Yeah, your solution looks pretty neat. Now, i have modified the code so that the mail providers will create their respective gconf keys when they get installed [ so there are no new changes in the evolution camel schema files ], and all the providers would have to create their own keys under /apps/evolution/mail/licenses .. with the key name being <provider_specified_name>_accepted.

+

-- 
Jeffrey Stedfast
Evolution Hacker - Novell, Inc.
fejj ximian com  - www.novell.com
        Thanks
                        --     Sarfraaz Ahmed <asarfraaz novell com>
Index: camel/camel-provider.h
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-provider.h,v
retrieving revision 1.40
diff -u -r1.40 camel-provider.h
--- camel/camel-provider.h	19 Feb 2004 07:27:35 -0000	1.40
+++ camel/camel-provider.h	22 Apr 2004 14:00:44 -0000
@@ -59,6 +59,8 @@
  * _IS_STORAGE  mail is stored there. it will appear in the folder tree.
  * _IS_EXTERNAL it appears in the folder tree but is not created by
  *                the mail component.
+ * _HAS_LICENSE  the provider configuration first needs the license to
+ *		   be accepted.
  */
 #define CAMEL_PROVIDER_IS_REMOTE	(1 << 0)
 #define CAMEL_PROVIDER_IS_LOCAL		(1 << 1)
@@ -66,6 +68,7 @@
 #define CAMEL_PROVIDER_IS_SOURCE	(1 << 3)
 #define CAMEL_PROVIDER_IS_STORAGE	(1 << 4)
 #define CAMEL_PROVIDER_SUPPORTS_SSL	(1 << 5)
+#define CAMEL_PROVIDER_HAS_LICENSE      (1 << 6)
 
 
 /* Flags for url_flags. "ALLOW" means the config dialog will let
@@ -182,6 +185,16 @@
 	 * evolution source tree).
 	 */
 	char *translation_domain;
+
+	/* This string points to the provider's gconf key value
+	 */
+	const char *license;
+	
+	/* This holds the license file name [ ascii text format ] containing
+	 * the license agreement. This should be the absolute file path. This 
+	 * is read only when the HAS_LICENSE flag is set
+	 */
+	const char *license_file;
 } CamelProvider;
 
 typedef struct _CamelProviderModule CamelProviderModule;
Index: mail/mail-account-gui.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-account-gui.c,v
retrieving revision 1.158
diff -u -r1.158 mail-account-gui.c
--- mail/mail-account-gui.c	8 Apr 2004 22:02:36 -0000	1.158
+++ mail/mail-account-gui.c	22 Apr 2004 14:01:24 -0000
@@ -27,6 +27,8 @@
 #include <config.h>
 #endif
 
+#include <glib.h>
+
 #include <string.h>
 #include <stdarg.h>
 
@@ -155,6 +157,116 @@
 	g_free (value);
 }
 
+static void 
+set_license_rejected (GtkWidget *widget, gpointer data)
+{
+	gtk_dialog_response (GTK_DIALOG (data), GTK_RESPONSE_DELETE_EVENT);
+	return;
+}
+
+static void
+set_license_accepted (GtkWidget *widget, gpointer data)
+{
+	gtk_dialog_response (GTK_DIALOG (data), GTK_RESPONSE_ACCEPT);
+	return;
+
+}
+
+static void
+check_button_state (GtkToggleButton *button, gpointer data)
+{
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button)))
+		gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE);
+	else
+		gtk_widget_set_sensitive (GTK_WIDGET (data), FALSE);
+}
+
+
+static gboolean
+populate_text_entry (GtkTextView *view, const char *filename)
+{
+	FILE *fd;
+	char *filebuf;
+	GtkTextIter iter;
+	GtkTextBuffer *buffer;
+	int count;
+
+	g_return_val_if_fail (filename != NULL , FALSE);
+
+	fd = fopen (filename, "r");
+	
+	if (!fd) {
+		/* FIXME: Should never come here */
+		return FALSE;
+	}
+	
+	filebuf = g_malloc (1024);
+
+	buffer =  gtk_text_buffer_new (NULL);
+	gtk_text_buffer_get_start_iter (buffer, &iter);
+
+	while (!feof (fd) && !ferror (fd)) {
+		count = fread (filebuf, 1, sizeof (filebuf), fd);
+		gtk_text_buffer_insert (buffer, &iter, filebuf, count);
+	}
+	gtk_text_view_set_buffer (GTK_TEXT_VIEW (view), 
+					GTK_TEXT_BUFFER (buffer));
+	fclose (fd);
+	g_free (filebuf);
+	return TRUE;
+}
+
+static gboolean
+display_license(const char *filename)
+{
+	GladeXML *xml;
+	GtkWidget *top_widget;
+	GtkTextView *text_entry;
+	GtkButton *button_yes, *button_no;
+	GtkCheckButton *check_button;
+	GtkResponseType response;
+	gboolean status;
+	
+	xml = glade_xml_new (EVOLUTION_GLADEDIR "/mail-license.glade", 
+				"lic_dialog", NULL);
+	
+	top_widget = glade_xml_get_widget (xml, "lic_dialog");
+	text_entry = GTK_TEXT_VIEW (glade_xml_get_widget (xml, "textview1"));
+	status = populate_text_entry (GTK_TEXT_VIEW (text_entry), filename);
+	if (!status)
+		goto failed;
+
+	gtk_text_view_set_editable (GTK_TEXT_VIEW (text_entry), FALSE);
+
+	button_yes = GTK_BUTTON (glade_xml_get_widget (xml, "lic_yes_button"));
+	gtk_widget_set_sensitive (GTK_WIDGET (button_yes), FALSE);
+
+	button_no = GTK_BUTTON (glade_xml_get_widget (xml, "lic_no_button"));
+
+	check_button = GTK_CHECK_BUTTON (glade_xml_get_widget (xml, 
+							"lic_checkbutton"));
+
+	g_signal_connect (check_button, "toggled", 
+				G_CALLBACK (check_button_state), button_yes);
+	g_signal_connect (button_yes, "clicked", 
+				G_CALLBACK (set_license_accepted), 
+				GTK_WIDGET (top_widget));
+	g_signal_connect (button_no, "clicked", 
+				G_CALLBACK (set_license_rejected), 
+				GTK_WIDGET (top_widget));
+
+	response = gtk_dialog_run (GTK_DIALOG (top_widget));
+	if (response == GTK_RESPONSE_ACCEPT) {
+		gtk_widget_destroy (top_widget);
+		g_object_unref (xml);
+		return TRUE;
+	}
+failed:
+	gtk_widget_destroy (top_widget);
+	g_object_unref (xml);
+	return FALSE;
+}
+
 static gboolean
 service_complete (MailAccountGuiService *service, GHashTable *extra_config, GtkWidget **incomplete)
 {
@@ -216,6 +328,41 @@
 }
 
 gboolean
+mail_account_gui_check_for_license (CamelProvider *prov)
+{
+	GConfClient *gconf;
+	gboolean accepted, status;
+	char *gconf_license_key;
+
+	if (prov->flags & CAMEL_PROVIDER_HAS_LICENSE) {
+		gconf = mail_config_get_gconf_client ();
+		gconf_license_key = g_strdup_printf (
+			"/apps/evolution/mail/licenses/%s_accepted",
+			prov->license);
+		
+		accepted = gconf_client_get_bool (gconf, gconf_license_key,
+						  NULL);
+		if (!accepted)
+		{
+			/* Since the license is not yet accepted, pop-up a 
+			 * dialog to display the license agreement and check 
+			 * if the user accepts it
+			 */
+
+			if (display_license (prov->license_file))
+				status = gconf_client_set_bool (gconf, 
+						gconf_license_key, TRUE, NULL);
+			else {
+				g_free (gconf_license_key);
+				return FALSE;
+			}
+		}
+		g_free (gconf_license_key);
+	}
+	return TRUE;
+}
+
+gboolean
 mail_account_gui_source_complete (MailAccountGui *gui, GtkWidget **incomplete)
 {
 	return service_complete (&gui->source, gui->extra_config, incomplete);
@@ -492,6 +639,7 @@
 	GtkWidget *file_entry, *label, *frame, *dwidget = NULL;
 	CamelProvider *provider;
 	gboolean writeable;
+	gboolean license_accepted = TRUE;
 	
 	provider = g_object_get_data ((GObject *) widget, "provider");
 	
@@ -521,8 +669,13 @@
 	else
 		gtk_label_set_text (gui->source.description, "");
 	
+	printf("provider found \n");
+
+	if (gui->source.provider)	
+		license_accepted = mail_account_gui_check_for_license (gui->source.provider);
+
 	frame = glade_xml_get_widget (gui->xml, "source_frame");
-	if (provider) {
+	if (provider && license_accepted) {
 		gtk_widget_show (frame);
 		
 		/* hostname */


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