[evolution/gnome-2-32] Function to set a CamelURL's defaults based on a provider's defaults



commit 176895e4ebc119274a26436b307c258d6af4388a
Author: Federico Mena Quintero <federico novell com>
Date:   Wed Dec 1 11:48:01 2010 -0600

    Function to set a CamelURL's defaults based on a provider's defaults
    
    In http://bugs.meego.com/show_bug.cgi?id=6498, part of the problem is that
    when a mail account is created through the startup wizard in Express mode,
    that account does not receive the default values that were defined by its
    respective CamelProvider (i.e. the provider->extra_conf
    CamelProviderConfEntry structures).
    
    However, the defaults *are* used if an account is created when not in
    Express mode.  The problem is that Express mode doesn't include the
    "Receiving options" page in its mail account editor, while non-express
    mode does.  The utility functions to populate that page's widgets are the
    ones responsible for setting the provider's default values on the CamelURL
    for the new account.  Since in Express mode those widgets don't even get
    created, the provider's defaults are never even considered.
    
    Here, what we do is to pull out the logic from those functions that create
    widgets, so that we have set_provider_defaults_on_url(), a single function
    to set default values from a CamelProvider into a CamelURL.  We will use
    that function to set the defaults in both Express and non-express modes,
    instead of depending on the widget code to do that.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 mail/em-account-editor.c |   89 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/mail/em-account-editor.c b/mail/em-account-editor.c
index ade75df..32ff215 100644
--- a/mail/em-account-editor.c
+++ b/mail/em-account-editor.c
@@ -3621,6 +3621,95 @@ em_account_editor_commit (EMAccountEditor *emae)
 }
 
 static void
+set_checkbox_default (CamelProviderConfEntry *entry, CamelURL *url)
+{
+	const gchar *value;
+
+	g_assert (entry->type == CAMEL_PROVIDER_CONF_CHECKBOX);
+
+	if (atoi (entry->value) != 0)
+		value = "";
+	else
+		value = NULL;
+
+	camel_url_set_param (url, entry->name, value);
+
+	/* FIXME: do we need to call emae_uri_changed()? */
+}
+
+static void
+set_entry_default (CamelProviderConfEntry *entry, CamelURL *url)
+{
+	g_assert (entry->type == CAMEL_PROVIDER_CONF_ENTRY);
+
+	camel_url_set_param (url, entry->name, entry->value);
+	/* FIXME: This comes from emae_option_entry().  That function calls
+	 * emae_uri_changed(), but the corresponding emae_option_toggle() does
+	 * not call emae_uri_changed() when it creates the checkbuttons - do
+	 * we need to call that function at all?
+	 */
+}
+
+static void
+set_checkspin_default (CamelProviderConfEntry *entry, CamelURL *url)
+{
+	gdouble min, def, max;
+	gchar on;
+
+	g_assert (entry->type == CAMEL_PROVIDER_CONF_CHECKSPIN);
+
+	/* FIXME: this is a fugly api.  See emae_option_checkspin() */
+	if (sscanf (entry->value, "%c:%lf:%lf:%lf", &on, &min, &def, &max) != 4) {
+		min = 0.0;
+		def = 0.0;
+		max = 1.0;
+	}
+
+	if (on == 'y') {
+		gchar value[16];
+
+		sprintf (value, "%d", (gint) def);
+		camel_url_set_param (url, entry->name, value);
+	} else
+		camel_url_set_param (url, entry->name, NULL);
+
+	/* FIXME: do we need to call emae_uri_changed()? */
+}
+
+static void
+set_provider_defaults_on_url (CamelProvider *provider, CamelURL *url)
+{
+	CamelProviderConfEntry *entries;
+	int i;
+
+	entries = provider->extra_conf;
+
+	for (i = 0; entries && entries[i].type != CAMEL_PROVIDER_CONF_END; i++) {
+		switch (entries[i].type) {
+		case CAMEL_PROVIDER_CONF_CHECKBOX:
+			set_checkbox_default (entries + i, url);
+			break;
+
+		case CAMEL_PROVIDER_CONF_ENTRY:
+			set_entry_default (entries + i, url);
+			break;
+
+		case CAMEL_PROVIDER_CONF_CHECKSPIN:
+			set_checkspin_default (entries + i, url);
+			break;
+
+		default:
+			/* Other entry types don't have defaults, or so can be
+			 * inferred from emae_option_*().  But see
+			 * emae_option_options() - that *may* need something,
+			 * but that function doesn't actually modify the
+			 * CamelURL. */
+			break;
+		}
+	}
+}
+
+static void
 em_account_editor_construct (EMAccountEditor *emae, EMAccountEditorType type, const gchar *id)
 {
 	EMAccountEditorPrivate *priv = emae->priv;



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