[evolution/wip/gsettings] Bug #632176 - Force user name on Google calendar/address book



commit 5e633737a81adfceae761589b1e464792ad51297
Author: Milan Crha <mcrha redhat com>
Date:   Mon Nov 8 17:53:30 2010 +0100

    Bug #632176 - Force user name on Google calendar/address book

 .../google-account-setup/google-contacts-source.c  |   41 +++++++++++++++++++-
 .../google-account-setup/google-contacts-source.h  |    6 +++
 plugins/google-account-setup/google-source.c       |   19 ++++++++-
 .../org-gnome-evolution-google.eplug.xml           |    4 +-
 4 files changed, 64 insertions(+), 6 deletions(-)
---
diff --git a/plugins/google-account-setup/google-contacts-source.c b/plugins/google-account-setup/google-contacts-source.c
index 5f4bf3f..0fe4991 100644
--- a/plugins/google-account-setup/google-contacts-source.c
+++ b/plugins/google-account-setup/google-contacts-source.c
@@ -94,7 +94,9 @@ on_username_entry_changed (GtkEntry *entry, gpointer user_data)
 
 	text = gtk_entry_get_text (entry);
 
-	if (strstr (text, "@")) {
+	if (!text || !*text) {
+		username = NULL;
+	} else if (strstr (text, "@")) {
 		username = g_strdup (text);
 	} else {
 		username = g_strdup_printf ("%s gmail com", text);
@@ -207,6 +209,41 @@ on_interval_combo_changed (GtkComboBox *combo, gpointer user_data)
 	g_free (value_string);
 }
 
+gpointer
+check_username_filled (ESource *source)
+{
+	gboolean res = TRUE;
+
+	g_return_val_if_fail (source != NULL, NULL);
+
+	if (g_ascii_strncasecmp (GOOGLE_BASE_URI, e_source_group_peek_base_uri (e_source_peek_group (source)), strlen (GOOGLE_BASE_URI)) == 0) {
+		gchar *username = g_strdup (e_source_get_property (source, "username"));
+
+		if (username)
+			username = g_strstrip (username);
+
+		res = username && *username;
+
+		g_free (username);
+	}
+
+	return GINT_TO_POINTER (res ? 1 : 0);
+}
+
+gpointer
+plugin_google_contacts_check (EPlugin *epl, EConfigHookPageCheckData *data)
+{
+	EABConfigTargetSource *t;
+
+	g_return_val_if_fail (data != NULL, NULL);
+	g_return_val_if_fail (data->target != NULL, NULL);
+
+	t = (EABConfigTargetSource *) data->target;
+	g_return_val_if_fail (t->source != NULL, NULL);
+
+	return 	check_username_filled (t->source);
+}
+
 struct ui_data {
 	GtkWidget *widget;
 };
@@ -262,7 +299,7 @@ plugin_google_contacts (EPlugin *epl,
 
 	g_object_set_data (G_OBJECT (epl), "gwidget", NULL);
 
-	if (g_ascii_strncasecmp ("google://", base_uri, 9) != 0)
+	if (g_ascii_strncasecmp (GOOGLE_BASE_URI, base_uri, 9) != 0)
 		return NULL;
 
 	/* Build up the UI */
diff --git a/plugins/google-account-setup/google-contacts-source.h b/plugins/google-account-setup/google-contacts-source.h
index 289ea0b..97130c1 100644
--- a/plugins/google-account-setup/google-contacts-source.h
+++ b/plugins/google-account-setup/google-contacts-source.h
@@ -21,9 +21,15 @@
 #ifndef __GOOGLE_CONTACTS_SOURCE_H__
 #define __GOOGLE_CONTACTS_SOURCE_H__
 
+#define GOOGLE_BASE_URI "google://"
+
 GtkWidget *plugin_google_contacts (EPlugin                    *epl,
                                    EConfigHookItemFactoryData *data);
 
+gpointer plugin_google_contacts_check (EPlugin *epl, EConfigHookPageCheckData *data);
+
+gpointer check_username_filled (ESource *source);
+
 void       ensure_google_contacts_source_group (void);
 
 void       remove_google_contacts_source_group (void);
diff --git a/plugins/google-account-setup/google-source.c b/plugins/google-account-setup/google-source.c
index 2f6dfdc..b5865c7 100644
--- a/plugins/google-account-setup/google-source.c
+++ b/plugins/google-account-setup/google-source.c
@@ -51,7 +51,6 @@
 
 #include "google-contacts-source.h"
 
-#define GOOGLE_BASE_URI "google://"
 #define CALENDAR_LOCATION "://www.google.com/calendar/feeds/"
 #define CALENDAR_DEFAULT_PATH "/private/full"
 #define URL_GET_SUBSCRIBED_CALENDARS "://www.google.com/calendar/feeds/default/allcalendars/full"
@@ -63,6 +62,7 @@
 /* prototypes */
 gint e_plugin_lib_enable (EPlugin *ep, gint enable);
 GtkWidget *plugin_google (EPlugin *epl, EConfigHookItemFactoryData *data);
+gpointer plugin_google_check (EPlugin *epl, EConfigHookPageCheckData *data);
 void e_calendar_google_migrate (EPlugin *epl, ECalEventTargetBackend *data);
 
 /*****************************************************************************/
@@ -223,7 +223,8 @@ update_source_uris (ESource *source, const gchar *uri)
 	e_source_set_relative_uri (source, uri);
 
 	user = e_source_get_property (source, "username");
-	g_return_if_fail (user != NULL);
+	if (!user)
+		return;
 
 	feeds = strstr (uri, "/feeds/");
 	g_return_if_fail (feeds != NULL);
@@ -571,6 +572,20 @@ retrieve_list_sensitize (GtkEntry *username_entry,
 	gtk_widget_set_sensitive (button, sensitive);
 }
 
+gpointer
+plugin_google_check (EPlugin *epl, EConfigHookPageCheckData *data)
+{
+	ECalConfigTargetSource *t;
+
+	g_return_val_if_fail (data != NULL, NULL);
+	g_return_val_if_fail (data->target != NULL, NULL);
+
+	t = (ECalConfigTargetSource *) data->target;
+	g_return_val_if_fail (t->source != NULL, NULL);
+
+	return check_username_filled (t->source);
+}
+
 GtkWidget *
 plugin_google  (EPlugin                    *epl,
 	     EConfigHookItemFactoryData *data)
diff --git a/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml b/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml
index 2148cb8..16cd61a 100644
--- a/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml
+++ b/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml
@@ -7,7 +7,7 @@
     <_description>Add Google Calendars to Evolution.</_description>
 
     <hook class="org.gnome.evolution.calendar.config:1.0">
-      <group target="source" id="org.gnome.evolution.calendar.calendarProperties">
+      <group target="source" id="org.gnome.evolution.calendar.calendarProperties" check="plugin_google_check">
         <item type="item_table" path="00.general/00.source/99.google" factory="plugin_google"/>
       </group>
     </hook>
@@ -16,7 +16,7 @@
     </hook>
 
     <hook class="org.gnome.evolution.addressbook.config:1.0">
-      <group target="source" id="com.novell.evolution.addressbook.config.accountEditor">
+      <group target="source" id="com.novell.evolution.addressbook.config.accountEditor" check="plugin_google_contacts_check">
         <item type="item" path="00.general/10.display/99.google" factory="plugin_google_contacts"/>
       </group>
     </hook>



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