[Evolution-hackers] [PATCH 1/2] e_cal_new_system_foo() should create corresponding source in GConf

2011-04-15 Thread David Woodhouse
---
 calendar/libecal/e-cal.c |   56 +++--
 1 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index 6835d45..69ff9c7 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -1023,6 +1023,56 @@ e_cal_new_from_uri (const gchar *uri, ECalSourceType 
type)
return cal;
 }
 
+static ECal *
+get_local_source (ECalSourceType type)
+{
+   ESourceList *sources;
+   ESourceGroup *on_this_computer;
+   GSList *local_sources, *iter;
+   gchar *source_uri = NULL;
+   ECal *ecal;
+
+   if (!e_cal_get_sources (sources, type, NULL)) {
+   g_warning (Could not get task sources from GConf!);
+   goto out;
+   }
+
+   on_this_computer = e_source_list_ensure_group (sources,
+  _(On This Computer),
+  local:, TRUE);
+   if (!on_this_computer) {
+   g_object_unref (sources);
+   goto out;
+   }
+
+   local_sources = e_source_group_peek_sources (on_this_computer);
+   for (iter = local_sources; !source_uri  iter != NULL; iter = 
iter-next) {
+   ESource *source = iter-data;
+   gchar *uri;
+
+   uri = e_source_get_uri (source);
+   if (g_strcmp0 (uri, local:system) == 0)
+   source_uri = uri;
+   else
+   g_free (uri);
+   }
+   if (!source_uri) {
+   ESource *source;
+   source = e_source_new (_(Personal), system);
+   e_source_set_color_spec (source, #BECEDD);
+   e_source_group_add_source (on_this_computer, source, -1);
+   g_object_unref (source);
+
+   if (!e_source_list_sync (sources, NULL))
+   g_warning (Cannot add system source to GConf!);
+   }
+   g_object_unref (on_this_computer);
+   g_object_unref (sources);
+ out:
+   ecal = e_cal_new_from_uri (source_uri?:local:system, type);
+   g_free (source_uri);
+   return ecal;
+}
 /**
  * e_cal_new_system_calendar:
  *
@@ -1036,7 +1086,7 @@ e_cal_new_from_uri (const gchar *uri, ECalSourceType type)
 ECal *
 e_cal_new_system_calendar (void)
 {
-   return e_cal_new_from_uri (local:system, E_CAL_SOURCE_TYPE_EVENT);
+   return get_local_source (E_CAL_SOURCE_TYPE_EVENT);
 }
 
 /**
@@ -1052,7 +1102,7 @@ e_cal_new_system_calendar (void)
 ECal *
 e_cal_new_system_tasks (void)
 {
-   return e_cal_new_from_uri (local:system, E_CAL_SOURCE_TYPE_TODO);
+   return get_local_source (E_CAL_SOURCE_TYPE_TODO);
 }
 
 /**
@@ -1068,7 +1118,7 @@ e_cal_new_system_tasks (void)
 ECal *
 e_cal_new_system_memos (void)
 {
-   return e_cal_new_from_uri (local:system, E_CAL_SOURCE_TYPE_JOURNAL);
+   return get_local_source (E_CAL_SOURCE_TYPE_JOURNAL);
 }
 
 /**
-- 
1.7.4.2



___
evolution-hackers mailing list
evolution-hackers@gnome.org
To change your list options or unsubscribe, visit ...
http://mail.gnome.org/mailman/listinfo/evolution-hackers


[Evolution-hackers] [PATCH 2/2] Fix comparison of URI in e_cal_new_from_uri().

2011-04-15 Thread David Woodhouse
If the URI only had a relative_uri property, it should build the full URI
for comparison rather than just skipping it.
---
 calendar/libecal/e-cal.c |   11 ++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index 69ff9c7..a60abfb 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -988,8 +988,17 @@ check_uri (ESource *source, gpointer uri)
g_return_val_if_fail (uri != NULL, FALSE);
 
suri = e_source_peek_absolute_uri (source);
+   if (suri)
+   return !g_ascii_strcasecmp (suri, uri);
+   else {
+   gboolean ret;
+   gchar *suri2;
 
-   return suri  g_ascii_strcasecmp (suri, uri) == 0;
+   suri2 = e_source_get_uri (source);
+   ret = !g_ascii_strcasecmp (suri2, uri);
+   g_free (suri2);
+   return ret;
+   }
 }
 
 /**
-- 
1.7.4.2


___
evolution-hackers mailing list
evolution-hackers@gnome.org
To change your list options or unsubscribe, visit ...
http://mail.gnome.org/mailman/listinfo/evolution-hackers


Re: [Evolution-hackers] [PATCH 2/2] Fix comparison of URI in e_cal_new_from_uri().

2011-04-15 Thread David Woodhouse
On Fri, 2011-04-15 at 12:37 +0100, David Woodhouse wrote:
 If the URI only had a relative_uri property, it should build the full
 URI
 for comparison rather than just skipping it. 

We have the opposite problem in the file backend, in the hack that sets
the cache dir for the system source to system instead of the uid:

source_dir = e_source_peek_relative_uri (source);
if (!source_dir || !g_str_equal (source_dir, system))
source_dir = e_source_peek_uid (source);

But if we fix that, we risk changing the storage directory of existing
sources. So I suppose that has to remain as it was.

-- 
David WoodhouseOpen Source Technology Centre
david.woodho...@intel.com  Intel Corporation

___
evolution-hackers mailing list
evolution-hackers@gnome.org
To change your list options or unsubscribe, visit ...
http://mail.gnome.org/mailman/listinfo/evolution-hackers