[evolution] Fix bug #597082 gtk_label_set_text should not be called in a thread function. This patch makes the U



commit b76e7f1430500fa260b65970f0376860d1369e28
Author: Jeff Cai <jeff cai sun com>
Date:   Mon Feb 8 13:28:08 2010 +0800

    Fix bug #597082
    gtk_label_set_text should not be called in a thread function. This
    patch makes the UI operation is invoked in an idle function.

 mail/e-mail-migrate.c |   45 ++++++++++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/mail/e-mail-migrate.c b/mail/e-mail-migrate.c
index 9b44510..51d6e35 100644
--- a/mail/e-mail-migrate.c
+++ b/mail/e-mail-migrate.c
@@ -229,6 +229,13 @@ struct _imap_folder_info_1_0 {
 	gchar dir_sep;
 };
 
+struct _migrate_state_info {
+	gchar *label_name;
+	double progress;
+};
+static gboolean update_states_in_main_thread (const struct 
+		_migrate_state_info *info);
+
 static GHashTable *accounts_1_0 = NULL;
 static GHashTable *accounts_name_1_0 = NULL;
 
@@ -1176,10 +1183,6 @@ em_migrate_set_folder_name (const gchar *folder_name)
 	text = g_strdup_printf (_("Migrating '%s':"), folder_name);
 	gtk_label_set_text (label, text);
 	g_free (text);
-
-	gtk_progress_bar_set_fraction (progress, 0.0);
-	while (gtk_events_pending ())
-		gtk_main_iteration ();
 }
 
 static void
@@ -1544,6 +1547,7 @@ em_migrate_folder(EMMigrateSession *session, const gchar *dirname, const gchar *
 	gint index, i;
 	GString *src, *dest;
 	gboolean success = FALSE;
+	struct _migrate_state_info * info;
 
 	camel_exception_init (&ex);
 
@@ -1560,7 +1564,11 @@ em_migrate_folder(EMMigrateSession *session, const gchar *dirname, const gchar *
 
 	dest = g_string_new("");
 	uri = get_local_store_uri(dirname, &name, &index);
-	em_migrate_set_folder_name (full_name);
+	info = g_malloc (sizeof(struct _migrate_state_info));
+	info->label_name = g_strdup (full_name);
+	info->progress = 0.0;
+	g_idle_add ((GSourceFunc) update_states_in_main_thread, info);
+
 	thread_list = get_local_et_expanded (dirname);
 
 	/* Manually copy local mbox files, its much faster */
@@ -2798,9 +2806,16 @@ em_update_sa_junk_setting_2_23 (void)
 }
 
 static gboolean
-update_progress_in_main_thread (double *progress)
+update_states_in_main_thread (const struct _migrate_state_info * info)
 {
-	em_migrate_set_progress (*progress);
+	g_return_val_if_fail (info != NULL, FALSE);
+	g_return_val_if_fail (info->label_name != NULL, FALSE);
+	em_migrate_set_progress (info->progress);
+	em_migrate_set_folder_name (info->label_name);
+	g_free (info->label_name);
+	g_free ( (gpointer)info);
+	while (gtk_events_pending ())
+		gtk_main_iteration ();
 	return FALSE;
 }
 
@@ -2810,17 +2825,17 @@ migrate_folders(CamelStore *store, gboolean is_local, CamelFolderInfo *fi, const
 	CamelFolder *folder;
 
 	while (fi) {
-		gdouble progress;
-		gchar *tmp;
 
-		*nth_folder = *nth_folder + 1;
+		struct _migrate_state_info *info = g_malloc (sizeof (struct
+					_migrate_state_info));
+		info->label_name = g_strdup_printf ("%s/%s", acc,
+				fi->full_name);
 
-		tmp = g_strdup_printf ("%s/%s", acc, fi->full_name);
-		em_migrate_set_folder_name (tmp);
-		g_free (tmp);
+		*nth_folder = *nth_folder + 1;
 
-		progress = (double) (*nth_folder) / total_folders;
-		g_idle_add ((GSourceFunc) update_progress_in_main_thread, &progress);
+		info->progress = (double) (*nth_folder) / total_folders;
+		g_idle_add ((GSourceFunc) update_states_in_main_thread, 
+				&info);
 
 		if (is_local)
 				folder = camel_store_get_folder (store, fi->full_name, CAMEL_STORE_IS_MIGRATING, ex);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]