diff options
Diffstat (limited to 'plugins/exchange-operations')
-rw-r--r-- | plugins/exchange-operations/ChangeLog | 14 | ||||
-rw-r--r-- | plugins/exchange-operations/exchange-calendar.c | 52 | ||||
-rw-r--r-- | plugins/exchange-operations/exchange-config-listener.c | 262 | ||||
-rw-r--r-- | plugins/exchange-operations/exchange-contacts.c | 104 | ||||
-rw-r--r-- | plugins/exchange-operations/exchange-operations.c | 21 | ||||
-rw-r--r-- | plugins/exchange-operations/exchange-operations.h | 2 |
6 files changed, 136 insertions, 319 deletions
diff --git a/plugins/exchange-operations/ChangeLog b/plugins/exchange-operations/ChangeLog index 35b78be998..4f2d072abe 100644 --- a/plugins/exchange-operations/ChangeLog +++ b/plugins/exchange-operations/ChangeLog @@ -1,3 +1,17 @@ +2005-07-22 Praveen Kumar <kpraveen@novell.com> + + * exchange-calendar.c : Handling the rename of calendars. This + addresses the bug 310433 + * exchange-config-listener.c : Removed the functions + add_folder_esource and remove_folder_esource + * exchange-contacts.c : Handling the rename of addressbooks. Also + modified the way of Exchange addressbook ESource URI handling to be + the same way as calendar ESource URI handling + * exchange-operations.c (exchange_operations_update_child_esources) : + Added new to handle the rename of the ESources of all child folders + in the case of parent folder being renamed. + * exchange-operations.h : Added prototype for the new function + 2005-07-21 Sarfraaz Ahmed <asarfraaz@novell.com> * exchange-calendar.c (e_exchange_calendar_get_calendars): Rescan the diff --git a/plugins/exchange-operations/exchange-calendar.c b/plugins/exchange-operations/exchange-calendar.c index ab3726d990..3f793b502d 100644 --- a/plugins/exchange-operations/exchange-calendar.c +++ b/plugins/exchange-operations/exchange-calendar.c @@ -43,6 +43,9 @@ enum { NUM_COLS }; +gboolean calendar_src_exists = FALSE; +gchar *calendar_old_source_uri = NULL; + GPtrArray *e_exchange_calendar_get_calendars (ECalSourceType *ftype); void e_exchange_calendar_pcalendar_on_change (GtkTreeView *treeview, ESource *source); GtkWidget *e_exchange_calendar_pcalendar (EPlugin *epl, EConfigHookItemFactoryData *data); @@ -142,7 +145,6 @@ e_exchange_calendar_pcalendar (EPlugin *epl, EConfigHookItemFactoryData *data) gchar *ruri; gchar *account_name; gchar *uri_text; - gboolean src_exists = TRUE; int row, i; if (!hidden) @@ -167,8 +169,13 @@ e_exchange_calendar_pcalendar (EPlugin *epl, EConfigHookItemFactoryData *data) e_uri_free (uri); g_free (uri_text); - if (!strlen (e_source_peek_relative_uri (t->source))) { - src_exists = FALSE; + if (strlen (e_source_peek_relative_uri (t->source))) { + calendar_src_exists = TRUE; + g_free (calendar_old_source_uri); + calendar_old_source_uri = g_strdup (e_source_peek_relative_uri (t->source)); + } + else { + calendar_src_exists = FALSE; } parent = data->parent; @@ -211,7 +218,7 @@ e_exchange_calendar_pcalendar (EPlugin *epl, EConfigHookItemFactoryData *data) gtk_table_attach (GTK_TABLE (parent), scrw_pcalendar, 0, 2, row+1, row+2, GTK_EXPAND|GTK_FILL, 0, 0, 0); gtk_widget_show_all (scrw_pcalendar); - if (src_exists) { + if (calendar_src_exists) { gchar *uri_prefix, *sruri, *tmpruri; int prefix_len; GtkTreeSelection *selection; @@ -260,7 +267,7 @@ e_exchange_calendar_commit (EPlugin *epl, EConfigTarget *target) { ECalConfigTargetSource *t = (ECalConfigTargetSource *) target; ESource *source = t->source; - gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix; + gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix, *oldpath=NULL; int prefix_len; ExchangeAccount *account; @@ -291,11 +298,37 @@ e_exchange_calendar_commit (EPlugin *epl, EConfigTarget *target) gname = (gchar*) e_source_peek_name (source); gruri = (gchar*) e_source_peek_relative_uri (source); - ruri = g_strconcat (gruri, "/", gname, NULL); + if (calendar_src_exists) { + gchar *tmpruri, *tmpdelimit; + tmpruri = g_strdup (gruri); + tmpdelimit = g_strrstr (tmpruri, "/"); + tmpdelimit[0] = '\0'; + ruri = g_strconcat (tmpruri, "/", gname, NULL); + g_free (tmpruri); + } + else { + ruri = g_strconcat (gruri, "/", gname, NULL); + } e_source_set_relative_uri (source, ruri); - path = g_strdup_printf ("/%s", ruri+prefix_len); - result = exchange_account_create_folder (account, path, ftype); + path = g_strdup_printf ("/%s", ruri+prefix_len); + + if (!calendar_src_exists) { + /* Create the new folder */ + result = exchange_account_create_folder (account, path, ftype); + } + else if (strcmp (e_source_peek_relative_uri (source), calendar_old_source_uri)) { + /* Rename the folder */ + oldpath = g_strdup_printf ("/%s", calendar_old_source_uri+prefix_len); + result = exchange_account_xfer_folder (account, oldpath, path, TRUE); + exchange_operations_update_child_esources (source, + calendar_old_source_uri, + ruri); + } + else { + /* Nothing happened specific to exchange; just return */ + return; + } switch (result) { /* TODO: Modify all these error messages using e_error */ @@ -329,4 +362,7 @@ e_exchange_calendar_commit (EPlugin *epl, EConfigTarget *target) g_free (ruri); g_free (path); g_free (ftype); + g_free (oldpath); + g_free (calendar_old_source_uri); + calendar_old_source_uri = NULL; } diff --git a/plugins/exchange-operations/exchange-config-listener.c b/plugins/exchange-operations/exchange-config-listener.c index 41134c0887..2138e9d638 100644 --- a/plugins/exchange-operations/exchange-config-listener.c +++ b/plugins/exchange-operations/exchange-config-listener.c @@ -355,145 +355,6 @@ done: g_object_unref (client); } -void -add_folder_esource (ExchangeAccount *account, - FolderType folder_type, - const char *folder_name, - const char *physical_uri) -{ - ESource *source = NULL; - ESourceGroup *source_group = NULL; - char *relative_uri = NULL, *username = NULL; - GSList *ids; - GConfClient *client; - gboolean is_contacts_folder = TRUE, group_new = FALSE, source_new = FALSE; - const char *offline = NULL; - int mode; - ESourceList *source_list = NULL; - - client = gconf_client_get_default (); - - username = exchange_account_get_username (account); - - if (folder_type == EXCHANGE_CONTACTS_FOLDER) { - source_list = e_source_list_new_for_gconf ( client, - CONF_KEY_CONTACTS); - } - else if (folder_type == EXCHANGE_CALENDAR_FOLDER) { - source_list = e_source_list_new_for_gconf ( client, - CONF_KEY_CAL); - relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX)); - is_contacts_folder = FALSE; - } - else if (folder_type == EXCHANGE_TASKS_FOLDER) { - source_list = e_source_list_new_for_gconf ( client, - CONF_KEY_TASKS); - relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX)); - is_contacts_folder = FALSE; - } - - exchange_account_is_offline_sync_set (account, &mode); - - if ((source_group = e_source_list_peek_group_by_name (source_list, - account->account_name)) == NULL) { - source_group = e_source_group_new (account->account_name, - EXCHANGE_URI_PREFIX); - if (!e_source_list_add_group (source_list, source_group, -1)) { - g_object_unref (source_list); - g_object_unref (source_group); - g_object_unref (client); - g_free (relative_uri); - return; - } - if (is_contacts_folder) - source = e_source_new_with_absolute_uri (folder_name, - physical_uri); - else - source = e_source_new (folder_name, relative_uri); - - if (mode == OFFLINE_MODE) { - /* If account is marked for offline sync during account - * creation, mark all the folders for offline sync - */ - e_source_set_property (source, "offline_sync", "1"); - } - if (username) - e_source_set_property (source, "username", username); - e_source_group_add_source (source_group, source, -1); - e_source_list_sync (source_list, NULL); - group_new = source_new = TRUE; - } - else { - /* source group already exists*/ - if((source = e_source_group_peek_source_by_name (source_group, - folder_name)) == NULL) { - printf("old group, new source\n"); - if (is_contacts_folder) - source = e_source_new_with_absolute_uri ( - folder_name, physical_uri); - else - source = e_source_new (folder_name, relative_uri); - - if (mode == OFFLINE_MODE) - e_source_set_property (source, "offline_sync", "1"); - if (username) - e_source_set_property (source, "username", username); - - e_source_group_add_source (source_group, source, -1); - source_new = TRUE; - e_source_list_sync (source_list, NULL); - } else { - /* source group and source both already exist */ - offline = e_source_get_property (source, "offline_sync"); - if (!offline) { - /* Folder doesn't have any offline property set */ - if (mode == OFFLINE_MODE) - e_source_set_property (source, "offline_sync", "1"); - } - } - } - - if (source && !is_contacts_folder) { - - /* Select the folder created */ - if (folder_type == EXCHANGE_CALENDAR_FOLDER) { - ids = gconf_client_get_list (client, - CONF_KEY_SELECTED_CAL_SOURCES, - GCONF_VALUE_STRING, NULL); - ids = g_slist_append (ids, - g_strdup (e_source_peek_uid (source))); - gconf_client_set_list (client, - CONF_KEY_SELECTED_CAL_SOURCES, - GCONF_VALUE_STRING, ids, NULL); - g_slist_foreach (ids, (GFunc) g_free, NULL); - g_slist_free (ids); - } - else if (folder_type == EXCHANGE_TASKS_FOLDER) { - - ids = gconf_client_get_list (client, - CONF_KEY_SELECTED_TASKS_SOURCES, - GCONF_VALUE_STRING, NULL); - - ids = g_slist_append (ids, - g_strdup (e_source_peek_uid (source))); - gconf_client_set_list (client, - CONF_KEY_SELECTED_TASKS_SOURCES, - GCONF_VALUE_STRING, ids, NULL); - g_slist_foreach (ids, (GFunc) g_free, NULL); - g_slist_free (ids); - } - } - - g_free (relative_uri); - - if (source_new) - g_object_unref (source); - if (group_new) - g_object_unref (source_group); - g_object_unref (source_list); - g_object_unref (client); -} - static void add_new_sources (ExchangeAccount *account) { @@ -695,129 +556,6 @@ remove_account_esource (ExchangeAccount *account, g_object_unref (client); } -void -remove_folder_esource (ExchangeAccount *account, - FolderType folder_type, - const char *physical_uri) -{ - ESourceGroup *group; - ESource *source; - GSList *groups; - GSList *sources; - gboolean found_group, is_contacts_folder = TRUE; - char *relative_uri = NULL; - const char *source_uid; - GSList *ids, *temp_ids, *node_to_be_deleted; - GConfClient *client; - ESourceList *source_list = NULL; - - client = gconf_client_get_default (); - - /* Remove ESource for a given folder */ - if (folder_type == EXCHANGE_CONTACTS_FOLDER) { - source_list = e_source_list_new_for_gconf ( client, - CONF_KEY_CONTACTS); - } - else if (folder_type == EXCHANGE_CALENDAR_FOLDER) { - source_list = e_source_list_new_for_gconf ( client, - CONF_KEY_CAL); - relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX)); - is_contacts_folder = FALSE; - } - else if (folder_type == EXCHANGE_TASKS_FOLDER) { - source_list = e_source_list_new_for_gconf ( client, - CONF_KEY_TASKS); - relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX)); - is_contacts_folder = FALSE; - } - - groups = e_source_list_peek_groups (source_list); - found_group = FALSE; - - for ( ; groups != NULL && !found_group; groups = g_slist_next (groups)) { - group = E_SOURCE_GROUP (groups->data); - - if (strcmp (e_source_group_peek_name (group), account->account_name) == 0 - && - strcmp (e_source_group_peek_base_uri (group), EXCHANGE_URI_PREFIX) == 0) { - - sources = e_source_group_peek_sources (group); - - for( ; sources != NULL; sources = g_slist_next (sources)) { - - source = E_SOURCE (sources->data); - - if (((!is_contacts_folder && - strcmp (e_source_peek_relative_uri (source), - relative_uri) == 0)) || - (is_contacts_folder && - strcmp (e_source_peek_absolute_uri (source), - physical_uri) == 0)) { - - source_uid = e_source_peek_uid (source); - /* Folder Deleted - Remove only the source */ - /* - e_source_group_remove_source_by_uid ( - group, - source_uid); - */ - e_source_group_remove_source ( - group, - source); - e_source_list_sync (source_list, NULL); - if (!is_contacts_folder) { - /* Remove from the selected folders */ - if (folder_type == EXCHANGE_CALENDAR_FOLDER) { - ids = gconf_client_get_list ( - client, - CONF_KEY_SELECTED_CAL_SOURCES, - GCONF_VALUE_STRING, NULL); - if (ids) { - node_to_be_deleted = g_slist_find_custom (ids, - source_uid, - (GCompareFunc) strcmp); - if (node_to_be_deleted) { - g_free (node_to_be_deleted->data); - ids = g_slist_delete_link (ids, - node_to_be_deleted); - } - } - temp_ids = ids; - for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids)) - g_free (temp_ids->data); - g_slist_free (ids); - } - else if (folder_type == EXCHANGE_TASKS_FOLDER) { - ids = gconf_client_get_list (client, - CONF_KEY_SELECTED_TASKS_SOURCES, - GCONF_VALUE_STRING, NULL); - if (ids) { - node_to_be_deleted = g_slist_find_custom (ids, - source_uid, - (GCompareFunc) strcmp); - if (node_to_be_deleted) { - g_free (node_to_be_deleted->data); - ids = g_slist_delete_link (ids, - node_to_be_deleted); - } - } - temp_ids = ids; - for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids)) - g_free (temp_ids->data); - g_slist_free (ids); - } - } - found_group = TRUE; - break; - } - } - } - } - g_object_unref (source_list); - g_free (relative_uri); - g_object_unref (client); -} - static void remove_account_esources (ExchangeAccount *account) { diff --git a/plugins/exchange-operations/exchange-contacts.c b/plugins/exchange-operations/exchange-contacts.c index a0a9bf87a4..c775a1f480 100644 --- a/plugins/exchange-operations/exchange-contacts.c +++ b/plugins/exchange-operations/exchange-contacts.c @@ -45,7 +45,9 @@ enum { NUM_COLS }; -gchar *contacts_uri=NULL; +gboolean contacts_src_exists = FALSE; +gchar *contacts_old_src_uri = NULL; + GPtrArray *e_exchange_contacts_get_contacts (void); void e_exchange_contacts_pcontacts_on_change (GtkTreeView *treeview, ESource *source); @@ -107,14 +109,9 @@ e_exchange_contacts_pcontacts_on_change (GtkTreeView *treeview, ESource *source) gchar *ruri; gtk_tree_model_get (model, &iter, CONTACTSRURI_COL, &ruri, -1); - es_ruri = g_strconcat ("exchange://", account->account_filename, "/", ruri, NULL); + es_ruri = g_strconcat (account->account_filename, "/", ruri, NULL); e_source_set_relative_uri (source, es_ruri); - /* - if (contacts_uri) { - g_free (contacts_uri); - } - contacts_uri = g_strdup (es_ruri); - */ + g_free (ruri); g_free (es_ruri); } @@ -131,18 +128,12 @@ e_exchange_contacts_pcontacts (EPlugin *epl, EConfigHookItemFactoryData *data) ExchangeAccount *account; int i; - gboolean src_exists=FALSE; EABConfigTargetSource *t = (EABConfigTargetSource *) data->target; ESource *source = t->source; if (data->old) { - /* FIXME: Review this */ - /* - gtk_widget_destroy (lbl_pcontacts); - gtk_widget_destroy (scrw_pcontacts); - gtk_widget_destroy (tv_pcontacts); - */ + gtk_widget_destroy (vb_pcontacts); } uri_text = e_source_get_uri (source); @@ -153,17 +144,14 @@ e_exchange_contacts_pcontacts (EPlugin *epl, EConfigHookItemFactoryData *data) g_free (uri_text); - if (e_source_peek_absolute_uri (source)) { - src_exists = TRUE; + if (strcmp (e_source_peek_relative_uri (source), e_source_peek_uid (source))) { + contacts_src_exists = TRUE; + g_free (contacts_old_src_uri); + contacts_old_src_uri = g_strdup (e_source_peek_relative_uri (source)); } else { + contacts_src_exists = FALSE; e_source_set_relative_uri (source, ""); /* FIXME: Nasty hack */ - /* - if (contacts_uri) { - g_free (contacts_uri); - contacts_uri = NULL; - } - */ } account = exchange_operations_get_exchange_account (); @@ -206,16 +194,15 @@ e_exchange_contacts_pcontacts (EPlugin *epl, EConfigHookItemFactoryData *data) gtk_box_pack_start (GTK_BOX (vb_pcontacts), scrw_pcontacts, FALSE, FALSE, 0); gtk_widget_show_all (vb_pcontacts); - if (src_exists) { + if (contacts_src_exists) { gchar *uri_prefix, *sruri, *tmpruri; int prefix_len; GtkTreeSelection *selection; - uri_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL); + tmpruri = (gchar*)e_source_peek_relative_uri (t->source); + uri_prefix = g_strconcat (account->account_filename, "/", NULL); prefix_len = strlen (uri_prefix); - tmpruri = (gchar*)e_source_peek_absolute_uri (t->source); - if (g_str_has_prefix (tmpruri, uri_prefix)) { sruri = g_strdup (tmpruri+prefix_len); } @@ -224,7 +211,11 @@ e_exchange_contacts_pcontacts (EPlugin *epl, EConfigHookItemFactoryData *data) } selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv_pcontacts)); - exchange_operations_cta_select_node_from_tree (ts_pcontacts, NULL, sruri, sruri, selection); + exchange_operations_cta_select_node_from_tree (ts_pcontacts, + NULL, + sruri, + sruri, + selection); gtk_widget_set_sensitive (tv_pcontacts, FALSE); g_free (uri_prefix); @@ -244,7 +235,6 @@ e_exchange_contacts_check (EPlugin *epl, EConfigHookPageCheckData *data) if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) { if (!strlen (e_source_peek_relative_uri (t->source))) { - //if (!contacts_uri) { return FALSE; } } @@ -257,7 +247,7 @@ e_exchange_contacts_commit (EPlugin *epl, EConfigTarget *target) { EABConfigTargetSource *t = (EABConfigTargetSource *) target; ESource *source = t->source; - gchar *uri_text, *gname, *gruri, *ruri, *path, *path_prefix; + gchar *uri_text, *gname, *gruri, *ruri, *path, *path_prefix, *oldpath=NULL; int prefix_len; ExchangeAccount *account; @@ -268,29 +258,46 @@ e_exchange_contacts_commit (EPlugin *epl, EConfigTarget *target) g_free (uri_text); return ; } - g_free (uri_text); - + account = exchange_operations_get_exchange_account (); - path_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL); + path_prefix = g_strconcat (account->account_filename, "/", NULL); prefix_len = strlen (path_prefix); + g_free (path_prefix); gname = (gchar*) e_source_peek_name (source); gruri = (gchar*) e_source_peek_relative_uri (source); - ruri = g_strconcat (gruri, "/", gname, NULL); - //ruri = g_strconcat (contacts_uri, "/", gname, NULL); - - g_print ("Setting absolute URI to %s\n", ruri); - - e_source_set_absolute_uri (source, ruri); - - g_print ("Read absolute URI as %s\n", e_source_peek_absolute_uri(source)); - - /* FIXME: This creates some problem. Identify the cause */ - //e_source_set_relative_uri (source, ""); /* FIXME: Nasty hack */ + if (contacts_src_exists) { + gchar *tmpruri, *tmpdelimit; + tmpruri = g_strdup (gruri); + tmpdelimit = g_strrstr (tmpruri, "/"); + tmpdelimit[0] = '\0'; + ruri = g_strconcat (tmpruri, "/", gname, NULL); + g_free (tmpruri); + } + else { + ruri = g_strconcat (gruri, "/", gname, NULL); + } + e_source_set_relative_uri (source, ruri); path = g_strdup_printf ("/%s", ruri+prefix_len); - result = exchange_account_create_folder (account, path, "contacts"); + + if (!contacts_src_exists) { + /* Create the new folder */ + result = exchange_account_create_folder (account, path, "contacts"); + } + else if (strcmp (e_source_peek_relative_uri (source), contacts_old_src_uri)) { + /* Rename the folder */ + oldpath = g_strdup_printf ("/%s", contacts_old_src_uri+prefix_len); + result = exchange_account_xfer_folder (account, oldpath, path, TRUE); + exchange_operations_update_child_esources (source, + contacts_old_src_uri, + ruri); + } + else { + /* Nothing happened specific to exchange; just return */ + return; + } switch (result) { /* TODO: Modify all these error messages using e_error */ @@ -319,10 +326,9 @@ e_exchange_contacts_commit (EPlugin *epl, EConfigTarget *target) g_print ("Generic error\n"); break; } - /* - g_free (contacts_uri); - contacts_uri = NULL; - */ g_free (ruri); g_free (path); + g_free (oldpath); + g_free (contacts_old_src_uri); + contacts_old_src_uri = NULL; } diff --git a/plugins/exchange-operations/exchange-operations.c b/plugins/exchange-operations/exchange-operations.c index 24756008c9..c3e7eb446f 100644 --- a/plugins/exchange-operations/exchange-operations.c +++ b/plugins/exchange-operations/exchange-operations.c @@ -218,3 +218,24 @@ exchange_operations_report_error (ExchangeAccount *account, ExchangeAccountResul g_free (error_string); } +void exchange_operations_update_child_esources (ESource *source, const gchar *old_path, const gchar *new_path) +{ + ESourceGroup *group; + GSList *sources, *tsource; + group = e_source_peek_group (source); + sources = e_source_group_peek_sources (group); + for (tsource = sources; tsource != NULL; tsource = tsource->next) { + gchar *ruri; + ruri = e_source_peek_relative_uri (tsource->data); + if (g_strrstr (ruri, old_path)) { + /* This ESource points to one of the child folders */ + gchar **tmpv, *truri; + /* A nasty search and replace */ + tmpv = g_strsplit (ruri, old_path, -1); + truri = g_strjoinv (new_path, tmpv); + e_source_set_relative_uri (tsource->data, truri); + g_strfreev (tmpv); + g_free (truri); + } + } +} diff --git a/plugins/exchange-operations/exchange-operations.h b/plugins/exchange-operations/exchange-operations.h index bf41b3088f..e2a4f2815a 100644 --- a/plugins/exchange-operations/exchange-operations.h +++ b/plugins/exchange-operations/exchange-operations.h @@ -46,6 +46,8 @@ void exchange_operations_cta_select_node_from_tree (GtkTreeStore *store, GtkTree void exchange_operations_report_error (ExchangeAccount *account, ExchangeAccountResult result); +void exchange_operations_update_child_esources (ESource *source, const gchar *old_path, const gchar *new_path); + #ifdef __cplusplus } #endif /* __cplusplus */ |