aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-04-25 01:40:31 +0800
committerMilan Crha <mcrha@redhat.com>2009-04-25 01:40:31 +0800
commit2403bbcdd196745314786af3b6318de56ef3948e (patch)
treea40b172dec814a8f7c214979c7735a46d2c73c08 /calendar
parent23df769955ea54f756a579c19964df87ae6fd5c8 (diff)
downloadgsoc2013-evolution-2403bbcdd196745314786af3b6318de56ef3948e.tar.gz
gsoc2013-evolution-2403bbcdd196745314786af3b6318de56ef3948e.tar.zst
gsoc2013-evolution-2403bbcdd196745314786af3b6318de56ef3948e.zip
Use new ESourceList API (simplifies code)
** Part of fix for bug #569652
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog9
-rw-r--r--calendar/gui/calendar-component.c85
-rw-r--r--calendar/gui/memos-component.c58
-rw-r--r--calendar/gui/tasks-component.c58
4 files changed, 56 insertions, 154 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 6d4023c97f..f461af6832 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,5 +1,14 @@
2009-04-24 Milan Crha <mcrha@redhat.com>
+ ** Part of fix for bug #569652
+
+ * gui/calendar-component.c: (ensure_sources):
+ * gui/memos-component.c: (ensure_sources):
+ * gui/tasks-component.c: (ensure_sources):
+ Use new ESourceList API (simplifies code).
+
+2009-04-24 Milan Crha <mcrha@redhat.com>
+
** Part of fix for bug #381132
* gui/apps_evolution_calendar.schemas.in:
diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c
index a44b279f19..942960bff5 100644
--- a/calendar/gui/calendar-component.c
+++ b/calendar/gui/calendar-component.c
@@ -158,23 +158,15 @@ calcomp_vpane_resized (GtkWidget *vpane, GdkEventButton *e, CalendarComponentVie
static void
ensure_sources (CalendarComponent *component)
{
- GSList *groups;
ESourceList *source_list;
- ESourceGroup *group;
ESourceGroup *on_this_computer;
- ESourceGroup *on_the_web;
ESourceGroup *contacts;
- ESourceGroup *weather;
ESource *personal_source;
ESource *birthdays_source;
- char *base_uri, *base_uri_proto;
+ char *base_uri, *base_uri_proto, base_uri_proto_seventh;
const gchar *base_dir;
gchar *create_source;
- on_this_computer = NULL;
- on_the_web = NULL;
- contacts = NULL;
- weather = NULL;
personal_source = NULL;
birthdays_source = NULL;
@@ -187,28 +179,22 @@ ensure_sources (CalendarComponent *component)
base_uri = g_build_filename (base_dir, "local", NULL);
base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL);
+ if (strlen (base_uri_proto) > 7) {
+ /* compare only file:// part. If user home dir name changes we do not want to create
+ one more group */
+ base_uri_proto_seventh = base_uri_proto[7];
+ base_uri_proto[7] = 0;
+ } else {
+ base_uri_proto_seventh = -1;
+ }
- groups = e_source_list_peek_groups (source_list);
- if (groups) {
- /* groups are already there, we need to search for things... */
- GSList *g;
-
- for (g = groups; g; g = g->next) {
-
- group = E_SOURCE_GROUP (g->data);
-
- /* compare only file:// part. If user home dir name changes we do not want to create
- one more group */
+ on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE);
+ contacts = e_source_list_ensure_group (source_list, _("Contacts"), CONTACTS_BASE_URI, TRUE);
+ e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE);
+ e_source_list_ensure_group (source_list, _("Weather"), WEATHER_BASE_URI, FALSE);
- if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7))
- on_this_computer = group;
- else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group)))
- on_the_web = group;
- else if (!contacts && !strcmp (CONTACTS_BASE_URI, e_source_group_peek_base_uri (group)))
- contacts = group;
- else if (!weather && !strcmp (WEATHER_BASE_URI, e_source_group_peek_base_uri (group)))
- weather = group;
- }
+ if (base_uri_proto_seventh != -1) {
+ base_uri_proto[7] = base_uri_proto_seventh;
}
if (on_this_computer) {
@@ -238,16 +224,6 @@ ensure_sources (CalendarComponent *component)
and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/
e_source_list_sync (source_list,NULL);
}
-
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (on_this_computer, _("On This Computer"));
- }
- else {
- /* create the local source group */
- group = e_source_group_new (_("On This Computer"), base_uri_proto);
- e_source_list_add_group (source_list, group, -1);
-
- on_this_computer = group;
}
if (personal_source) {
@@ -282,17 +258,6 @@ ensure_sources (CalendarComponent *component)
e_source_set_color_spec (personal_source, "#BECEDD");
}
- if (on_the_web) {
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (on_the_web, _("On The Web"));
- } else {
- /* Create the On the web source group */
- group = e_source_group_new (_("On The Web"), WEB_BASE_URI);
- e_source_list_add_group (source_list, group, -1);
-
- on_the_web = group;
- }
-
if (contacts) {
GSList *sources = e_source_group_peek_sources (contacts);
if (sources) {
@@ -311,14 +276,6 @@ ensure_sources (CalendarComponent *component)
g_slist_free (l);
}
}
-
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (contacts, _("Contacts"));
- } else {
- /* Create the contacts group */
- group = e_source_group_new (_("Contacts"), CONTACTS_BASE_URI);
- e_source_list_add_group (source_list, group, -1);
- contacts = group;
}
create_source = e_source_group_get_property (contacts, "create_source");
@@ -341,18 +298,10 @@ ensure_sources (CalendarComponent *component)
if (e_source_peek_color_spec (birthdays_source) == NULL)
e_source_set_color_spec (birthdays_source, "#DDBECE");
- if (weather) {
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (weather, _("Weather"));
- } else {
- /* Create the weather group */
- group = e_source_group_new (_("Weather"), WEATHER_BASE_URI);
- e_source_list_add_group (source_list, group, -1);
- weather = group;
- }
-
component->priv->source_list = source_list;
+ g_object_unref (on_this_computer);
+ g_object_unref (contacts);
g_free (base_uri_proto);
g_free (base_uri);
}
diff --git a/calendar/gui/memos-component.c b/calendar/gui/memos-component.c
index 3fbebd7e3e..0e422d548d 100644
--- a/calendar/gui/memos-component.c
+++ b/calendar/gui/memos-component.c
@@ -123,17 +123,12 @@ struct _MemosComponentPrivate {
static void
ensure_sources (MemosComponent *component)
{
- GSList *groups;
ESourceList *source_list;
- ESourceGroup *group;
ESourceGroup *on_this_computer;
- ESourceGroup *on_the_web;
ESource *personal_source;
- char *base_uri, *base_uri_proto;
+ char *base_uri, *base_uri_proto, base_uri_proto_seventh;
const gchar *base_dir;
- on_this_computer = NULL;
- on_the_web = NULL;
personal_source = NULL;
if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_JOURNAL, NULL)) {
@@ -145,24 +140,20 @@ ensure_sources (MemosComponent *component)
base_uri = g_build_filename (base_dir, "local", NULL);
base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL);
+ if (strlen (base_uri_proto) > 7) {
+ /* compare only file:// part. If user home dir name changes we do not want to create
+ one more group */
+ base_uri_proto_seventh = base_uri_proto[7];
+ base_uri_proto[7] = 0;
+ } else {
+ base_uri_proto_seventh = -1;
+ }
- groups = e_source_list_peek_groups (source_list);
- if (groups) {
- /* groups are already there, we need to search for things... */
- GSList *g;
-
- for (g = groups; g; g = g->next) {
-
- group = E_SOURCE_GROUP (g->data);
-
- /* compare only file:// part. If user home dir name changes we do not want to create
- one more group */
+ on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE);
+ e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE);
- if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7))
- on_this_computer = group;
- else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group)))
- on_the_web = group;
- }
+ if (base_uri_proto_seventh != -1) {
+ base_uri_proto[7] = base_uri_proto_seventh;
}
if (on_this_computer) {
@@ -192,16 +183,6 @@ ensure_sources (MemosComponent *component)
and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/
e_source_list_sync (source_list,NULL);
}
-
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (on_this_computer, _("On This Computer"));
- }
- else {
- /* create the local source group */
- group = e_source_group_new (_("On This Computer"), base_uri_proto);
- e_source_list_add_group (source_list, group, -1);
-
- on_this_computer = group;
}
if (personal_source) {
@@ -235,18 +216,9 @@ ensure_sources (MemosComponent *component)
personal_source = source;
}
- if (on_the_web) {
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (on_the_web, _("On The Web"));
- } else {
- /* Create the source group */
- group = e_source_group_new (_("On The Web"), WEB_BASE_URI);
- e_source_list_add_group (source_list, group, -1);
-
- on_the_web = group;
- }
-
component->priv->source_list = source_list;
+
+ g_object_unref (on_this_computer);
g_free (base_uri_proto);
g_free (base_uri);
}
diff --git a/calendar/gui/tasks-component.c b/calendar/gui/tasks-component.c
index 7564c1bf92..9ed21d5186 100644
--- a/calendar/gui/tasks-component.c
+++ b/calendar/gui/tasks-component.c
@@ -120,17 +120,12 @@ struct _TasksComponentPrivate {
static void
ensure_sources (TasksComponent *component)
{
- GSList *groups;
ESourceList *source_list;
- ESourceGroup *group;
ESourceGroup *on_this_computer;
- ESourceGroup *on_the_web;
ESource *personal_source;
- char *base_uri, *base_uri_proto;
+ char *base_uri, *base_uri_proto, base_uri_proto_seventh;
const gchar *base_dir;
- on_this_computer = NULL;
- on_the_web = NULL;
personal_source = NULL;
if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_TODO, NULL)) {
@@ -142,24 +137,20 @@ ensure_sources (TasksComponent *component)
base_uri = g_build_filename (base_dir, "local", NULL);
base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL);
+ if (strlen (base_uri_proto) > 7) {
+ /* compare only file:// part. If user home dir name changes we do not want to create
+ one more group */
+ base_uri_proto_seventh = base_uri_proto[7];
+ base_uri_proto[7] = 0;
+ } else {
+ base_uri_proto_seventh = -1;
+ }
- groups = e_source_list_peek_groups (source_list);
- if (groups) {
- /* groups are already there, we need to search for things... */
- GSList *g;
-
- for (g = groups; g; g = g->next) {
-
- group = E_SOURCE_GROUP (g->data);
-
- /* compare only file:// part. If user home dir name changes we do not want to create
- one more group */
+ on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE);
+ e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE);
- if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7))
- on_this_computer = group;
- else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group)))
- on_the_web = group;
- }
+ if (base_uri_proto_seventh != -1) {
+ base_uri_proto[7] = base_uri_proto_seventh;
}
if (on_this_computer) {
@@ -189,16 +180,6 @@ ensure_sources (TasksComponent *component)
and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/
e_source_list_sync (source_list,NULL);
}
-
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (on_this_computer, _("On This Computer"));
- }
- else {
- /* create the local source group */
- group = e_source_group_new (_("On This Computer"), base_uri_proto);
- e_source_list_add_group (source_list, group, -1);
-
- on_this_computer = group;
}
if (personal_source) {
@@ -232,18 +213,9 @@ ensure_sources (TasksComponent *component)
personal_source = source;
}
- if (!on_the_web) {
- /* Create the LDAP source group */
- group = e_source_group_new (_("On The Web"), WEB_BASE_URI);
- e_source_list_add_group (source_list, group, -1);
-
- on_the_web = group;
- } else {
- /* ensure the group name is in current locale, not read from configuration */
- e_source_group_set_name (on_the_web, _("On The Web"));
- }
-
component->priv->source_list = source_list;
+
+ g_object_unref (on_this_computer);
g_free (base_uri_proto);
g_free (base_uri);
}