aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-migrate.c
diff options
context:
space:
mode:
authorSankar P <psankar@novell.com>2008-12-22 14:23:09 +0800
committerSankarasivasubramanian Pasupathilingam <psankar@src.gnome.org>2008-12-22 14:23:09 +0800
commite00b07975e2ea8d73cdf119a21b4c8ce97cb0f1a (patch)
treee9e3eb609c8a0e556002c321c17621586323c666 /mail/em-migrate.c
parent324695cd77e3a654b24963dd6bc07c37f6f30644 (diff)
downloadgsoc2013-evolution-e00b07975e2ea8d73cdf119a21b4c8ce97cb0f1a.tar.gz
gsoc2013-evolution-e00b07975e2ea8d73cdf119a21b4c8ce97cb0f1a.tar.zst
gsoc2013-evolution-e00b07975e2ea8d73cdf119a21b4c8ce97cb0f1a.zip
** Part of fix for bug #559153
2008-12-22 Sankar P <psankar@novell.com> ** Part of fix for bug #559153 * em-migrate.c (update_progress_in_main_thread), (migrate_folders), (count_folders), (migrate_folders_to_db_thread), (migrate_to_db), (em_migrate): Migration Improvements svn path=/trunk/; revision=36924
Diffstat (limited to 'mail/em-migrate.c')
-rw-r--r--mail/em-migrate.c207
1 files changed, 139 insertions, 68 deletions
diff --git a/mail/em-migrate.c b/mail/em-migrate.c
index e22cbae273..73bb319eb8 100644
--- a/mail/em-migrate.c
+++ b/mail/em-migrate.c
@@ -2842,20 +2842,54 @@ em_update_sa_junk_setting_2_23 (void)
g_object_unref (client);
}
+static gboolean
+update_progress_in_main_thread (double *progress)
+{
+ em_migrate_set_progress (*progress);
+ return FALSE;
+}
static void
-migrate_folders(CamelStore *store, CamelFolderInfo *fi, const char *acc, CamelException *ex)
+migrate_folders(CamelStore *store, gboolean is_local, CamelFolderInfo *fi, const char *acc, CamelException *ex, gboolean *done, int *nth_folder, int total_folders)
{
CamelFolder *folder;
while (fi) {
+ double progress;
+
+ *nth_folder = *nth_folder + 1;
+
char *tmp = g_strdup_printf ("%s/%s", acc, fi->full_name);
em_migrate_set_folder_name (tmp);
g_free (tmp);
- folder = camel_store_get_folder (store, fi->full_name, 0, ex);
+
+ progress = (double) (*nth_folder) / total_folders;
+ g_idle_add ((GSourceFunc) update_progress_in_main_thread, &progress);
+
+ if (is_local)
+ folder = camel_store_get_folder (store, fi->full_name, CAMEL_STORE_IS_MIGRATING, ex);
+ else
+ folder = camel_store_get_folder (store, fi->full_name, 0, ex);
+
if (folder != NULL)
camel_folder_summary_migrate_infos (folder->summary);
- migrate_folders(store, fi->child, acc, ex);
+
+ migrate_folders(store, is_local, fi->child, acc, ex, done, nth_folder, total_folders);
+
+ fi = fi->next;
+ }
+
+ if ( (*nth_folder) == (total_folders - 1))
+ *done = TRUE;
+}
+
+/* This could be in CamelStore.ch */
+static void
+count_folders (CamelFolderInfo *fi, int *count)
+{
+ while (fi) {
+ *count = *count + 1;
+ count_folders (fi->child , count);
fi = fi->next;
}
}
@@ -2878,76 +2912,113 @@ setup_local_store (MailComponent *mc)
return store;
}
+
+struct migrate_folders_to_db_structure {
+ char *account_name;
+ CamelException ex;
+ CamelStore *store;
+ CamelFolderInfo *info;
+ gboolean done;
+ gboolean is_local_store;
+};
+
+static void migrate_folders_to_db_thread (struct migrate_folders_to_db_structure *migrate_dbs)
+{
+ int num_of_folders = 0, nth_folder = 0;
+ count_folders (migrate_dbs->info, &num_of_folders);
+ migrate_folders (migrate_dbs->store, migrate_dbs->is_local_store, migrate_dbs->info,
+ migrate_dbs->account_name, &(migrate_dbs->ex), &(migrate_dbs->done),
+ &nth_folder, num_of_folders);
+}
+
static void
migrate_to_db()
{
- EAccountList *accounts;
- EIterator *iter;
- int i=0, len;
- MailComponent *component = mail_component_peek ();
- CamelStore *store = NULL;
- CamelFolderInfo *info;
-
- if (!(accounts = mail_config_get_accounts ()))
- return;
-
- iter = e_list_get_iterator ((EList *) accounts);
- len = e_list_length ((EList *) accounts);
-
- camel_session_set_online ((CamelSession *) session, FALSE);
- em_migrate_setup_progress_dialog (_("The summary format of the Evolution mailbox "
- "folders has been moved to SQLite since Evolution 2.24.\n\nPlease be "
- "patient while Evolution migrates your folders..."));
-
- em_migrate_set_progress ( (double)i/(len+1));
- store = setup_local_store (component);
- info = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST|CAMEL_STORE_FOLDER_INFO_SUBSCRIBED, NULL);
- if (info) {
- migrate_folders(store, info, _("On This Computer"), NULL);
- }
- i++;
- em_migrate_set_progress ( (double)i/(len+1));
-
-
- while (e_iterator_is_valid (iter)) {
- EAccount *account = (EAccount *) e_iterator_get (iter);
- EAccountService *service;
- const char *name;
-
-
- service = account->source;
- name = account->name;
- em_migrate_set_progress ( (double)i/(len+1));
- if (account->enabled
- && service->url != NULL
- && service->url[0]
- && strncmp(service->url, "mbox:", 5) != 0) {
-
- CamelException ex;
-
- camel_exception_init (&ex);
- mail_component_load_store_by_uri (component, service->url, name);
-
- store = (CamelStore *) camel_session_get_service (session, service->url, CAMEL_PROVIDER_STORE, &ex);
- info = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST|CAMEL_STORE_FOLDER_INFO_SUBSCRIBED, &ex);
- if (info) {
- migrate_folders(store, info, account->name, &ex);
-
- } else
- printf("%s:%s: failed to get folder infos \n", G_STRLOC, G_STRFUNC);
- camel_exception_clear(&ex);
-
+ EAccountList *accounts;
+ EIterator *iter;
+ int i=0, len;
+ MailComponent *component = mail_component_peek ();
+ CamelStore *store = NULL;
+ CamelFolderInfo *info;
+
+ if (!(accounts = mail_config_get_accounts ()))
+ return;
+
+ iter = e_list_get_iterator ((EList *) accounts);
+ len = e_list_length ((EList *) accounts);
+
+ camel_session_set_online ((CamelSession *) session, FALSE);
+
+ em_migrate_setup_progress_dialog (_("The summary format of the Evolution mailbox "
+ "folders has been moved to SQLite since Evolution 2.24.\n\nPlease be "
+ "patient while Evolution migrates your folders..."));
+
+ store = setup_local_store (component);
+ info = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST|CAMEL_STORE_FOLDER_INFO_SUBSCRIBED, NULL);
+
+ if (info) {
+ struct migrate_folders_to_db_structure migrate_dbs;
+
+ if (g_str_has_suffix (((CamelService *)store)->url->path, ".evolution/mail/local"))
+ migrate_dbs.is_local_store = TRUE;
+ else
+ migrate_dbs.is_local_store = FALSE;
+ camel_exception_init (&migrate_dbs.ex);
+ migrate_dbs.account_name = _("On This Computer");
+ migrate_dbs.info = info;
+ migrate_dbs.store = store;
+ migrate_dbs.done = FALSE;
+
+ GThread *thread;
+ thread = g_thread_create ((GThreadFunc) migrate_folders_to_db_thread, &migrate_dbs, TRUE, NULL);
+ while (!migrate_dbs.done)
+ g_main_context_iteration (NULL, TRUE);
}
i++;
- e_iterator_next (iter);
-
- }
-
- //camel_session_set_online ((CamelSession *) session, TRUE);
-
- g_object_unref (iter);
- em_migrate_close_progress_dialog ();
+ while (e_iterator_is_valid (iter)) {
+ EAccount *account = (EAccount *) e_iterator_get (iter);
+ EAccountService *service;
+ const char *name;
+
+ service = account->source;
+ name = account->name;
+ if (account->enabled
+ && service->url != NULL
+ && service->url[0]
+ && strncmp(service->url, "mbox:", 5) != 0) {
+
+ CamelException ex;
+
+ camel_exception_init (&ex);
+ mail_component_load_store_by_uri (component, service->url, name);
+
+ store = (CamelStore *) camel_session_get_service (session, service->url, CAMEL_PROVIDER_STORE, &ex);
+ info = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST|CAMEL_STORE_FOLDER_INFO_SUBSCRIBED, &ex);
+ if (info) {
+ struct migrate_folders_to_db_structure migrate_dbs;
+
+ migrate_dbs.ex = ex;
+ migrate_dbs.account_name = account->name;
+ migrate_dbs.info = info;
+ migrate_dbs.store = store;
+ migrate_dbs.done = FALSE;
+
+ GThread *thread;
+ thread = g_thread_create ((GThreadFunc) migrate_folders_to_db_thread, &migrate_dbs, TRUE, NULL);
+ while (!migrate_dbs.done)
+ g_main_context_iteration (NULL, TRUE);
+ } else
+ printf("%s:%s: failed to get folder infos \n", G_STRLOC, G_STRFUNC);
+ camel_exception_clear(&ex);
+ }
+ i++;
+ e_iterator_next (iter);
+ }
+ //camel_session_set_online ((CamelSession *) session, TRUE);
+ g_object_unref (iter);
+ em_migrate_close_progress_dialog ();
}
+
int
em_migrate (const char *evolution_dir, int major, int minor, int revision, CamelException *ex)
@@ -3048,7 +3119,7 @@ em_migrate (const char *evolution_dir, int major, int minor, int revision, Camel
if (major < 2 || (major == 2 && minor < 24)) {
em_update_sa_junk_setting_2_23 ();
- migrate_to_db();
+ migrate_to_db ();
}
return 0;