diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-06-09 18:56:27 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-07-16 01:14:43 +0800 |
commit | 858a2a884dbc243c485f1424d90675e06fa207b2 (patch) | |
tree | d9469a1bef86685b7741fdae05ff8f30605e5b96 /modules | |
parent | 51a41db621693114f5ee60d48e7e6442fc85fcc4 (diff) | |
download | gsoc2013-evolution-858a2a884dbc243c485f1424d90675e06fa207b2.tar.gz gsoc2013-evolution-858a2a884dbc243c485f1424d90675e06fa207b2.tar.zst gsoc2013-evolution-858a2a884dbc243c485f1424d90675e06fa207b2.zip |
Clean up "ensure_sources" backend routines.
Remove redundant logic (we call e_source_list_ensure_group() and then
proceed to do the same thing it just did), and use "local:" as the base
URI for the "On This Computer" group.
This requires commit 9e0845207b39f256f7e81d388741ed30a764ea7b in
Evolution-Data-Server to work properly.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/addressbook/e-book-shell-backend.c | 104 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-backend.c | 122 | ||||
-rw-r--r-- | modules/calendar/e-memo-shell-backend.c | 67 | ||||
-rw-r--r-- | modules/calendar/e-task-shell-backend.c | 71 |
4 files changed, 70 insertions, 294 deletions
diff --git a/modules/addressbook/e-book-shell-backend.c b/modules/addressbook/e-book-shell-backend.c index 652b7a5a73..0ae5dfbe61 100644 --- a/modules/addressbook/e-book-shell-backend.c +++ b/modules/addressbook/e-book-shell-backend.c @@ -57,9 +57,6 @@ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_BOOK_SHELL_BACKEND, EBookShellBackendPrivate)) -#define LDAP_BASE_URI "ldap://" -#define PERSONAL_RELATIVE_URI "system" - struct _EBookShellBackendPrivate { ESourceList *source_list; }; @@ -80,16 +77,11 @@ book_shell_backend_ensure_sources (EShellBackend *shell_backend) EBookShellBackendPrivate *priv; ESourceGroup *on_this_computer; - ESourceGroup *on_ldap_servers; ESource *personal; - GSList *groups, *iter; - const gchar *data_dir; + GSList *sources, *iter; const gchar *name; - gchar *base_uri; - gchar *filename; on_this_computer = NULL; - on_ldap_servers = NULL; personal = NULL; priv = E_BOOK_SHELL_BACKEND_GET_PRIVATE (shell_backend); @@ -99,78 +91,25 @@ book_shell_backend_ensure_sources (EShellBackend *shell_backend) return; } - data_dir = e_shell_backend_get_data_dir (shell_backend); - filename = g_build_filename (data_dir, "local", NULL); - base_uri = g_filename_to_uri (filename, NULL, NULL); - g_free (filename); - - groups = e_source_list_peek_groups (priv->source_list); - for (iter = groups; iter != NULL; iter = iter->next) { - ESourceGroup *source_group = iter->data; - const gchar *group_base_uri; - - group_base_uri = e_source_group_peek_base_uri (source_group); - - /* Compare only "file://" part. If the user's home - * changes, we do not want to create another group. */ - if (on_this_computer == NULL && - strncmp (base_uri, group_base_uri, 7) == 0) - on_this_computer = source_group; - - else if (on_ldap_servers == NULL && - strcmp (LDAP_BASE_URI, group_base_uri) == 0) - on_ldap_servers = source_group; - } - - name = _("On This Computer"); - - if (on_this_computer != NULL) { - GSList *sources; - const gchar *group_base_uri; - - /* Force the group name to the current locale. */ - e_source_group_set_name (on_this_computer, name); - - sources = e_source_group_peek_sources (on_this_computer); - group_base_uri = e_source_group_peek_base_uri (on_this_computer); + on_this_computer = e_source_list_ensure_group ( + priv->source_list, _("On This Computer"), "local:", TRUE); + e_source_list_ensure_group ( + priv->source_list, _("On LDAP Servers"), "ldap://", FALSE); - /* Make sure this group includes a "Personal" source. */ - for (iter = sources; iter != NULL; iter = iter->next) { - ESource *source = iter->data; - const gchar *relative_uri; + g_return_if_fail (on_this_computer != NULL); - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; + sources = e_source_group_peek_sources (on_this_computer); - if (strcmp (PERSONAL_RELATIVE_URI, relative_uri) != 0) - continue; + /* Make sure this group includes a "Personal" source. */ + for (iter = sources; iter != NULL; iter = iter->next) { + ESource *source = iter->data; + const gchar *relative_uri; + relative_uri = e_source_peek_relative_uri (source); + if (g_strcmp0 (relative_uri, "system") == 0) { personal = source; break; } - - /* Make sure we have the correct base URI. This can - * change when the user's home directory changes. */ - if (strcmp (base_uri, group_base_uri) != 0) { - e_source_group_set_base_uri ( - on_this_computer, base_uri); - - /* XXX We shouldn't need this sync call here as - * set_base_uri() results in synching to GConf, - * but that happens in an idle loop and too late - * to prevent the user from seeing a "Cannot - * Open ... because of invalid URI" error. */ - e_source_list_sync (priv->source_list, NULL); - } - - } else { - ESourceGroup *source_group; - - source_group = e_source_group_new (name, base_uri); - e_source_list_add_group (priv->source_list, source_group, -1); - on_this_computer = source_group; - g_object_unref (source_group); } name = _("Personal"); @@ -179,7 +118,7 @@ book_shell_backend_ensure_sources (EShellBackend *shell_backend) ESource *source; /* Create the default Personal address book. */ - source = e_source_new (name, PERSONAL_RELATIVE_URI); + source = e_source_new (name, "system"); e_source_group_add_source (on_this_computer, source, -1); e_source_set_property (source, "completion", "true"); g_object_unref (source); @@ -188,20 +127,7 @@ book_shell_backend_ensure_sources (EShellBackend *shell_backend) e_source_set_name (personal, name); } - name = _("On LDAP Servers"); - - if (on_ldap_servers == NULL) { - ESourceGroup *source_group; - - source_group = e_source_group_new (name, LDAP_BASE_URI); - e_source_list_add_group (priv->source_list, source_group, -1); - g_object_unref (source_group); - } else { - /* Force the group name to the current locale. */ - e_source_group_set_name (on_ldap_servers, name); - } - - g_free (base_uri); + g_object_unref (on_this_computer); } static void diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c index dede49c5b8..cab1f2fa3d 100644 --- a/modules/calendar/e-cal-shell-backend.c +++ b/modules/calendar/e-cal-shell-backend.c @@ -55,11 +55,6 @@ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_CAL_SHELL_BACKEND, ECalShellBackendPrivate)) -#define CONTACTS_BASE_URI "contacts://" -#define WEATHER_BASE_URI "weather://" -#define WEB_BASE_URI "webcal://" -#define PERSONAL_RELATIVE_URI "system" - struct _ECalShellBackendPrivate { ESourceList *source_list; }; @@ -85,9 +80,8 @@ cal_shell_backend_ensure_sources (EShellBackend *shell_backend) ESource *personal; EShell *shell; EShellSettings *shell_settings; - const gchar *data_dir, *name; - gchar *base_uri, base_uri_seventh; - gchar *filename; + GSList *sources, *iter; + const gchar *name; gchar *property; gboolean save_list = FALSE; @@ -104,78 +98,30 @@ cal_shell_backend_ensure_sources (EShellBackend *shell_backend) return; } - data_dir = e_shell_backend_get_data_dir (shell_backend); - filename = g_build_filename (data_dir, "local", NULL); - base_uri = g_filename_to_uri (filename, NULL, NULL); - g_free (filename); - - if (strlen (base_uri) > 7) { - /* Compare only file:// part. If user home dir name - * changes we do not want to create one more group. */ - base_uri_seventh = base_uri[7]; - base_uri[7] = 0; - } else { - base_uri_seventh = -1; - } - on_this_computer = e_source_list_ensure_group ( - priv->source_list, _("On This Computer"), base_uri, TRUE); + priv->source_list, _("On This Computer"), "local:", TRUE); contacts = e_source_list_ensure_group ( - priv->source_list, _("Contacts"), CONTACTS_BASE_URI, TRUE); + priv->source_list, _("Contacts"), "contacts://", TRUE); e_source_list_ensure_group ( - priv->source_list, _("On The Web"), WEB_BASE_URI, FALSE); + priv->source_list, _("On The Web"), "webcal://", FALSE); e_source_list_ensure_group ( - priv->source_list, _("Weather"), WEATHER_BASE_URI, FALSE); - - if (base_uri_seventh != -1) { - base_uri[7] = base_uri_seventh; - } - - name = _("On This Computer"); - - if (on_this_computer != NULL) { - GSList *sources, *iter; - const gchar *group_base_uri; - - sources = e_source_group_peek_sources (on_this_computer); - group_base_uri = e_source_group_peek_base_uri (on_this_computer); + priv->source_list, _("Weather"), "weather://", FALSE); - /* Make sure this group includes a "Personal" source. */ - for (iter = sources; iter != NULL; iter = iter->next) { - ESource *source = iter->data; - const gchar *relative_uri; + g_return_if_fail (on_this_computer != NULL); + g_return_if_fail (contacts != NULL); - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; + sources = e_source_group_peek_sources (on_this_computer); - if (strcmp (PERSONAL_RELATIVE_URI, relative_uri) != 0) - continue; + /* Make sure this group includes a "Personal" source. */ + for (iter = sources; iter != NULL; iter = iter->next) { + ESource *source = iter->data; + const gchar *relative_uri; + relative_uri = e_source_peek_relative_uri (source); + if (g_strcmp0 (relative_uri, "system") == 0) { personal = source; break; } - - /* Make sure we have the correct base URI. This can - * change when the user's home directory changes. */ - if (strcmp (base_uri, group_base_uri) != 0) { - e_source_group_set_base_uri ( - on_this_computer, base_uri); - - /* XXX We shouldn't need this sync call here as - * set_base_uri() results in synching to GConf, - * but that happens in an idle loop and too late - * to prevent the user from seeing a "Cannot - * Open ... because of invalid URI" error. */ - save_list = TRUE; - } - } else { - ESourceGroup *source_group; - - source_group = e_source_group_new (name, base_uri); - e_source_list_add_group (priv->source_list, source_group, -1); - on_this_computer = source_group; - g_object_unref (source_group); } name = _("Personal"); @@ -185,7 +131,7 @@ cal_shell_backend_ensure_sources (EShellBackend *shell_backend) GSList *selected; gchar *primary; - source = e_source_new (name, PERSONAL_RELATIVE_URI); + source = e_source_new (name, "system"); e_source_set_color_spec (source, "#BECEDD"); e_source_group_add_source (on_this_computer, source, -1); g_object_unref (source); @@ -215,29 +161,24 @@ cal_shell_backend_ensure_sources (EShellBackend *shell_backend) e_source_set_name (personal, name); } - if (contacts != NULL) { - GSList *sources; + sources = e_source_group_peek_sources (contacts); - sources = e_source_group_peek_sources (contacts); + if (sources != NULL) { + GSList *trash; - if (sources != NULL) { - GSList *trash; - - /* There is only one source under Contacts. */ - birthdays = E_SOURCE (sources->data); - sources = g_slist_next (sources); - - /* Delete any other sources in this group. - * Earlier versions allowed you to create - * additional sources under Contacts. */ - trash = g_slist_copy (sources); - while (trash != NULL) { - ESource *source = trash->data; - e_source_group_remove_source (contacts, source); - trash = g_slist_delete_link (trash, trash); - save_list = TRUE; - } + /* There is only one source under Contacts. */ + birthdays = E_SOURCE (sources->data); + sources = g_slist_next (sources); + /* Delete any other sources in this group. + * Earlier versions allowed you to create + * additional sources under Contacts. */ + trash = g_slist_copy (sources); + while (trash != NULL) { + ESource *source = trash->data; + e_source_group_remove_source (contacts, source); + trash = g_slist_delete_link (trash, trash); + save_list = TRUE; } } @@ -274,7 +215,6 @@ cal_shell_backend_ensure_sources (EShellBackend *shell_backend) g_object_unref (on_this_computer); g_object_unref (contacts); - g_free (base_uri); if (save_list) e_source_list_sync (priv->source_list, NULL); diff --git a/modules/calendar/e-memo-shell-backend.c b/modules/calendar/e-memo-shell-backend.c index 3996fa699f..8f5bf40825 100644 --- a/modules/calendar/e-memo-shell-backend.c +++ b/modules/calendar/e-memo-shell-backend.c @@ -72,10 +72,8 @@ memo_shell_backend_ensure_sources (EShellBackend *shell_backend) ESource *personal; EShell *shell; EShellSettings *shell_settings; - const gchar *data_dir; + GSList *sources, *iter; const gchar *name; - gchar *base_uri, base_uri_seventh; - gchar *filename; gboolean save_list = FALSE; personal = NULL; @@ -90,65 +88,25 @@ memo_shell_backend_ensure_sources (EShellBackend *shell_backend) return; } - data_dir = e_shell_backend_get_data_dir (shell_backend); - filename = g_build_filename (data_dir, "local", NULL); - base_uri = g_filename_to_uri (filename, NULL, NULL); - g_free (filename); - - if (strlen (base_uri) > 7) { - /* Compare only file:// part. If user home dir name - * changes we do not want to create one more group. */ - base_uri_seventh = base_uri[7]; - base_uri[7] = 0; - } else { - base_uri_seventh = -1; - } - on_this_computer = e_source_list_ensure_group ( - priv->source_list, _("On This Computer"), base_uri, TRUE); + priv->source_list, _("On This Computer"), "local:", TRUE); e_source_list_ensure_group ( - priv->source_list, _("On The Web"), WEB_BASE_URI, FALSE); - - if (base_uri_seventh != -1) { - base_uri[7] = base_uri_seventh; - } - - if (on_this_computer != NULL) { - GSList *sources, *iter; - const gchar *group_base_uri; - - sources = e_source_group_peek_sources (on_this_computer); - group_base_uri = e_source_group_peek_base_uri (on_this_computer); + priv->source_list, _("On The Web"), "webcal://", FALSE); - /* Make sure this group includes a "Personal" source. */ - for (iter = sources; iter != NULL; iter = iter->next) { - ESource *source = iter->data; - const gchar *relative_uri; + g_return_if_fail (on_this_computer); - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; + sources = e_source_group_peek_sources (on_this_computer); - if (strcmp (PERSONAL_RELATIVE_URI, relative_uri) != 0) - continue; + /* Make sure this group includes a "Personal" source. */ + for (iter = sources; iter != NULL; iter = iter->next) { + ESource *source = iter->data; + const gchar *relative_uri; + relative_uri = e_source_peek_relative_uri (source); + if (g_strcmp0 (relative_uri, "system") == 0) { personal = source; break; } - - /* Make sure we have the correct base URI. This can - * change when the user's home directory changes. */ - if (strcmp (base_uri, group_base_uri) != 0) { - e_source_group_set_base_uri ( - on_this_computer, base_uri); - - /* XXX We shouldn't need this sync call here as - * set_base_uri() results in synching to GConf, - * but that happens in an idle loop and too late - * to prevent the user from seeing a "Cannot - * Open ... because of invalid URI" error. */ - save_list = TRUE; - } } name = _("Personal"); @@ -158,7 +116,7 @@ memo_shell_backend_ensure_sources (EShellBackend *shell_backend) GSList *selected; gchar *primary; - source = e_source_new (name, PERSONAL_RELATIVE_URI); + source = e_source_new (name, "system"); e_source_set_color_spec (source, "#BECEDD"); e_source_group_add_source (on_this_computer, source, -1); g_object_unref (source); @@ -189,7 +147,6 @@ memo_shell_backend_ensure_sources (EShellBackend *shell_backend) } g_object_unref (on_this_computer); - g_free (base_uri); if (save_list) e_source_list_sync (priv->source_list, NULL); diff --git a/modules/calendar/e-task-shell-backend.c b/modules/calendar/e-task-shell-backend.c index ca2b68228c..cdd4dcc608 100644 --- a/modules/calendar/e-task-shell-backend.c +++ b/modules/calendar/e-task-shell-backend.c @@ -48,9 +48,6 @@ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_TASK_SHELL_BACKEND, ETaskShellBackendPrivate)) -#define WEB_BASE_URI "webcal://" -#define PERSONAL_RELATIVE_URI "system" - struct _ETaskShellBackendPrivate { ESourceList *source_list; }; @@ -74,10 +71,8 @@ task_shell_backend_ensure_sources (EShellBackend *shell_backend) ESource *personal; EShell *shell; EShellSettings *shell_settings; - const gchar *data_dir; + GSList *sources, *iter; const gchar *name; - gchar *base_uri, base_uri_seventh; - gchar *filename; gboolean save_list = FALSE; on_this_computer = NULL; @@ -93,66 +88,25 @@ task_shell_backend_ensure_sources (EShellBackend *shell_backend) return; } - data_dir = e_shell_backend_get_data_dir (shell_backend); - filename = g_build_filename (data_dir, "local", NULL); - base_uri = g_filename_to_uri (filename, NULL, NULL); - g_free (filename); - - if (strlen (base_uri) > 7) { - /* Compare only file:// part. If user home dir name - * changes we do not want to create one more group. */ - base_uri_seventh = base_uri[7]; - base_uri[7] = 0; - } else { - base_uri_seventh = -1; - } - on_this_computer = e_source_list_ensure_group ( - priv->source_list, _("On This Computer"), base_uri, TRUE); + priv->source_list, _("On This Computer"), "local:", TRUE); e_source_list_ensure_group ( - priv->source_list, _("On The Web"), WEB_BASE_URI, FALSE); - - if (base_uri_seventh != -1) { - base_uri[7] = base_uri_seventh; - } - - if (on_this_computer != NULL) { - GSList *sources, *iter; - const gchar *group_base_uri; - - sources = e_source_group_peek_sources (on_this_computer); - group_base_uri = e_source_group_peek_base_uri (on_this_computer); + priv->source_list, _("On The Web"), "webcal://", FALSE); - /* Make sure this group includes a "Personal" source. */ - for (iter = sources; iter != NULL; iter = iter->next) { - ESource *source = iter->data; - const gchar *relative_uri; + g_return_if_fail (on_this_computer); - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; + sources = e_source_group_peek_sources (on_this_computer); - if (strcmp (PERSONAL_RELATIVE_URI, relative_uri) != 0) - continue; + /* Make sure this group includes a "Personal" source. */ + for (iter = sources; iter != NULL; iter = iter->next) { + ESource *source = iter->data; + const gchar *relative_uri; + relative_uri = e_source_peek_relative_uri (source); + if (g_strcmp0 (relative_uri, "system") == 0) { personal = source; break; } - - /* Make sure we have the correct base URI. This can - * change when the user's home directory changes. */ - if (strcmp (base_uri, group_base_uri) != 0) { - e_source_group_set_base_uri ( - on_this_computer, base_uri); - - /* XXX We shouldn't need this sync call here as - * set_base_uri() results in synching to GConf, - * but that happens in an idle loop and too late - * to prevent the user from seeing a "Cannot - * Open ... because of invalid URI" error. */ - save_list = TRUE; - } - } name = _("Personal"); @@ -162,7 +116,7 @@ task_shell_backend_ensure_sources (EShellBackend *shell_backend) GSList *selected; gchar *primary; - source = e_source_new (name, PERSONAL_RELATIVE_URI); + source = e_source_new (name, "system"); e_source_set_color_spec (source, "#BECEDD"); e_source_group_add_source (on_this_computer, source, -1); g_object_unref (source); @@ -193,7 +147,6 @@ task_shell_backend_ensure_sources (EShellBackend *shell_backend) } g_object_unref (on_this_computer); - g_free (base_uri); if (save_list) e_source_list_sync (priv->source_list, NULL); |