From 6ebc23126acdfb8aec11416e4c197c6bee70bef0 Mon Sep 17 00:00:00 2001 From: Johannes Schmid Date: Sun, 17 Jun 2007 21:15:36 +0000 Subject: [PATCH] 2007-06-17 Johannes Schmid * configure.ac: Fixed build with hildon < 0.99 * src/maemo/modest-account-view-window.c: (on_edit_button_clicked): Check if the selected account is busy instead of checking all accounts * src/modest-account-mgr-priv.h: * src/modest-account-mgr.c: (modest_account_mgr_class_init), (modest_account_mgr_init), (compare_account_name), (modest_account_mgr_set_account_busy), (modest_account_mgr_account_is_busy): * src/modest-account-mgr.h: Added busy information to the account manager. It possible to set an account to busy or not busy now. * src/modest-mail-operation.c: (modest_mail_operation_finalize), (modest_mail_operation_update_account), (modest_mail_operation_notify_end): Set the account to busy/not busy depending on the operation state. * src/widgets/modest-account-view.c: (modest_account_view_finalize), (get_last_updated_string), (update_account_view), (on_account_busy_changed), (init_view): Show string \"Refreshing...\" if the account is currently busy. All this fixes projects.maemo.org bug NB#59711 pmo-trunk-r2268 --- ChangeLog2 | 31 +++++++++++++- configure.ac | 3 +- src/maemo/modest-account-view-window.c | 8 ++-- src/modest-account-mgr-priv.h | 1 + src/modest-account-mgr.c | 58 +++++++++++++++++++++++++ src/modest-account-mgr.h | 30 +++++++++++++ src/modest-mail-operation.c | 26 ++++++++++-- src/widgets/modest-account-view.c | 72 ++++++++++++++++++++++++++------ 8 files changed, 207 insertions(+), 22 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 43fad96..b5264bd 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,32 @@ +2007-06-17 Johannes Schmid + + * configure.ac: + Fixed build with hildon < 0.99 + + * src/maemo/modest-account-view-window.c: (on_edit_button_clicked): + Check if the selected account is busy instead of checking all accounts + + * src/modest-account-mgr-priv.h: + * src/modest-account-mgr.c: (modest_account_mgr_class_init), + (modest_account_mgr_init), (compare_account_name), + (modest_account_mgr_set_account_busy), + (modest_account_mgr_account_is_busy): + * src/modest-account-mgr.h: + Added busy information to the account manager. It possible to + set an account to busy or not busy now. + + * src/modest-mail-operation.c: (modest_mail_operation_finalize), + (modest_mail_operation_update_account), + (modest_mail_operation_notify_end): + Set the account to busy/not busy depending on the operation state. + + * src/widgets/modest-account-view.c: + (modest_account_view_finalize), (get_last_updated_string), + (update_account_view), (on_account_busy_changed), (init_view): + Show string "Refreshing..." if the account is currently busy. + + All this fixes projects.maemo.org bug NB#59711 + 2007-06-14 Armin Burgmeier * src/widgets/modest-attachments-view.h: @@ -23,7 +52,7 @@ Show an comfirmation dialog for the smpt-edit-window if there are unsaved changes and the user hits cancel. - (projects.maemo.org but NB#60479 + (projects.maemo.org bug NB#60479) 2007-06-14 Armin Burgmeier diff --git a/configure.ac b/configure.ac index 375932e..e3a4bf4 100644 --- a/configure.ac +++ b/configure.ac @@ -95,8 +95,7 @@ if test "x$with_platform" = "xmaemo"; then PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO, conic libtinymail-maemo-1.0 hildon-1 libosso libhildonmime osso-addressbook-1.0 wpeditor hildon-help libebook-1.2 libalarm hildon-notify libnotify) else # the old hildon - PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO, conic libtinymail-maemo-1.0 hildon-libs >= 0.12.0 libosso libossomime libossohelp osso-addressbook-1.0 libwpeditor-plus libebook-1.2 libalarm gnome-vfs-module-2.0) - AC_DEFINE_UNQUOTED(MODEST_HILDON_VERSION_0, 1, ["The Hildon version we support."]) + PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO, conic libtinymail-maemo-1.0 hildon-libs >= 0.12.0 libosso libossomime libossohelp osso-addressbook-1.0 libwpeditor-plus libebook-1.2 libalarm gnome-vfs-module-2.0 hildon-notify libnotify) AC_DEFINE_UNQUOTED(MODEST_HILDON_VERSION_0, 1, ["The Hildon version we support."]) fi AC_SUBST(MODEST_LIBTINYMAIL_MAEMO_CFLAGS) diff --git a/src/maemo/modest-account-view-window.c b/src/maemo/modest-account-view-window.c index fc40ea2..3279549 100644 --- a/src/maemo/modest-account-view-window.c +++ b/src/maemo/modest-account-view-window.c @@ -219,16 +219,16 @@ on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self) /* Check whether any connections are active, and cancel them if * the user wishes. - * TODO: Check only for connections with this account, instead of all. - * Maybe we need a queue per account. */ - ModestMailOperationQueue* queue = modest_runtime_get_mail_operation_queue (); - if (modest_mail_operation_queue_num_elements(queue)) { + ModestAccountMgr* mgr = modest_runtime_get_account_mgr (); + ModestMailOperationQueue* queue = modest_runtime_get_mail_operation_queue(); + if (modest_account_mgr_account_is_busy(mgr, account_name)) { GtkWidget *note = hildon_note_new_confirmation (GTK_WINDOW (self), _("emev_nc_disconnect_account")); const int response = gtk_dialog_run (GTK_DIALOG(note)); gtk_widget_destroy (note); if (response == GTK_RESPONSE_OK) { + /* FIXME: We should only cancel those of this account */ modest_mail_operation_queue_cancel_all(queue); } else diff --git a/src/modest-account-mgr-priv.h b/src/modest-account-mgr-priv.h index eb518d1..cc40a1d 100644 --- a/src/modest-account-mgr-priv.h +++ b/src/modest-account-mgr-priv.h @@ -54,6 +54,7 @@ struct _ModestAccountMgrPrivate { GSList *changed_conf_keys; guint timeout; gulong key_changed_handler_uid; + GSList* busy_accounts; }; #define MODEST_ACCOUNT_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 25656ab..b164eeb 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -42,6 +42,7 @@ static void modest_account_mgr_finalize (GObject * obj); enum { ACCOUNT_CHANGED_SIGNAL, ACCOUNT_REMOVED_SIGNAL, + ACCOUNT_BUSY_SIGNAL, LAST_SIGNAL }; @@ -193,6 +194,14 @@ modest_account_mgr_class_init (ModestAccountMgrClass * klass) NULL, NULL, modest_marshal_VOID__STRING_POINTER_BOOLEAN, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); + signals[ACCOUNT_BUSY_SIGNAL] = + g_signal_new ("account_busy_changed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(ModestAccountMgrClass,account_busy_changed), + NULL, NULL, + modest_marshal_VOID__STRING_BOOLEAN, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN); } @@ -203,6 +212,7 @@ modest_account_mgr_init (ModestAccountMgr * obj) MODEST_ACCOUNT_MGR_GET_PRIVATE (obj); priv->modest_conf = NULL; + priv->busy_accounts = NULL; priv->timeout = g_timeout_add (1000 /* milliseconds */, on_timeout_notify_changes, obj); } @@ -1176,3 +1186,51 @@ modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled) return accounts_exist; } + +static int +compare_account_name(gconstpointer a, gconstpointer b) +{ + const gchar* account_name = (const gchar*) a; + const gchar* account_name2 = (const gchar*) b; + return strcmp(account_name, account_name2); +} + +void +modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name, + gboolean busy) +{ + ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); + if (busy) + { + GSList *account_names = modest_account_mgr_account_names (self, + TRUE); + GSList* account = + g_slist_find_custom(account_names, account_name, (GCompareFunc) compare_account_name); + if (account && !modest_account_mgr_account_is_busy(self, account_name)) + { + priv->busy_accounts = g_slist_append(priv->busy_accounts, g_strdup(account_name)); + g_signal_emit_by_name(G_OBJECT(self), "account-busy-changed", account_name, TRUE); + } + g_slist_free(account_names); + } + else + { + GSList* account = + g_slist_find_custom(priv->busy_accounts, account_name, (GCompareFunc) compare_account_name); + if (account) + { + g_free(account->data); + priv->busy_accounts = g_slist_delete_link(priv->busy_accounts, account); + g_signal_emit_by_name(G_OBJECT(self), "account-busy-changed", account_name, FALSE); + } + } +} + +gboolean +modest_account_mgr_account_is_busy(ModestAccountMgr* self, const gchar* account_name) +{ + ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); + return (g_slist_find_custom(priv->busy_accounts, account_name, (GCompareFunc) compare_account_name) + != NULL); +} + diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index 90237c0..aaf5c06 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -65,6 +65,11 @@ struct _ModestAccountMgrClass { const GSList* key, gboolean server_account, gpointer user_data); + void (* account_busy_changed) (ModestAccountMgr *obj, + const gchar* account, + gboolean busy, + gpointer user_data); + }; /** @@ -440,6 +445,31 @@ gboolean modest_account_mgr_unset (ModestAccountMgr *self, gboolean modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled); +/** + * modest_account_mgr_set_account_busy + * @self: a ModestAccountMgr instance + * @account_name: name of the account + * @busy: whether to set busy or not busy + * + * Changes the busy flag of an account + * + */ + +void modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name, + gboolean busy); + +/** + * modest_account_mgr_account_is_busy + * @self: a ModestAccountMgr instance + * @account_name: name of the account + * + * Returns: If the account is currently busy or not + * + */ +gboolean +modest_account_mgr_account_is_busy(ModestAccountMgr* self, const gchar* account_name); + + G_END_DECLS #endif /* __MODEST_ACCOUNT_MGR_H__ */ diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 6676eec..0c2c2c3 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -84,6 +84,7 @@ enum _ModestMailOperationSignals typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate; struct _ModestMailOperationPrivate { TnyAccount *account; + gchar *account_name; guint done; guint total; GObject *source; @@ -206,6 +207,8 @@ modest_mail_operation_finalize (GObject *obj) priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj); + + if (priv->error) { g_error_free (priv->error); priv->error = NULL; @@ -635,6 +638,7 @@ typedef struct gint max_size; gint retrieve_limit; gchar *retrieve_type; + gchar *account_name; } UpdateAccountInfo; /***** I N T E R N A L F O L D E R O B S E R V E R *****/ @@ -764,7 +768,7 @@ idle_notify_progress (gpointer data) state = modest_mail_operation_clone_state (mail_op); g_signal_emit (G_OBJECT (mail_op), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL); g_slice_free (ModestMailOperationState, state); - + return TRUE; } @@ -800,7 +804,7 @@ notify_update_account_queue (gpointer data) ModestMailOperationPrivate *priv = NULL; priv = MODEST_MAIL_OPERATION_GET_PRIVATE(mail_op); - + modest_mail_operation_notify_end (mail_op); g_object_unref (mail_op); @@ -1051,7 +1055,7 @@ update_account_thread (gpointer thr_user_data) freed before this idle happens, but the mail operation will be still alive */ g_idle_add (notify_update_account_queue, g_object_ref (info->mail_op)); - + /* Frees */ g_object_unref (query); g_object_unref (all_folders); @@ -1151,6 +1155,10 @@ modest_mail_operation_update_account (ModestMailOperation *self, /* printf ("DEBUG: %s: info->retrieve_limit = %d\n", __FUNCTION__, info->retrieve_limit); */ + /* Set account busy */ + modest_account_mgr_set_account_busy(mgr, account_name, TRUE); + priv->account_name = g_strdup(account_name); + thread = g_thread_create (update_account_thread, info, FALSE, NULL); return TRUE; @@ -2101,7 +2109,19 @@ static void modest_mail_operation_notify_end (ModestMailOperation *self) { ModestMailOperationState *state; + ModestMailOperationPrivate *priv = NULL; + priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self); + + /* Set the account back to not busy */ + if (priv->account_name) + { + modest_account_mgr_set_account_busy(modest_runtime_get_account_mgr(), priv->account_name, + FALSE); + g_free(priv->account_name); + priv->account_name = NULL; + } + /* Notify the observers about the mail opertation end */ state = modest_mail_operation_clone_state (self); g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL); diff --git a/src/widgets/modest-account-view.c b/src/widgets/modest-account-view.c index 6da9f7a..236760e 100644 --- a/src/widgets/modest-account-view.c +++ b/src/widgets/modest-account-view.c @@ -71,7 +71,7 @@ enum { typedef struct _ModestAccountViewPrivate ModestAccountViewPrivate; struct _ModestAccountViewPrivate { ModestAccountMgr *account_mgr; - gulong sig1, sig2; + gulong sig1, sig2, sig3; /* When this is TRUE, we ignore configuration key changes. * This is useful when making many changes. */ @@ -149,6 +149,9 @@ modest_account_view_finalize (GObject *obj) if (priv->sig2) g_signal_handler_disconnect (priv->account_mgr, priv->sig2); + if (priv->sig3) + g_signal_handler_disconnect (priv->account_mgr, priv->sig3); + g_object_unref (G_OBJECT(priv->account_mgr)); priv->account_mgr = NULL; } @@ -156,7 +159,27 @@ modest_account_view_finalize (GObject *obj) G_OBJECT_CLASS(parent_class)->finalize (obj); } - +/* Get the string for the last updated time. Result must be g_freed */ +static gchar* +get_last_updated_string(ModestAccountMgr* account_mgr, ModestAccountData *account_data) +{ + /* FIXME: let's assume that 'last update' applies to the store account... */ + gchar* last_updated_string; + time_t last_updated = account_data->store_account->last_updated; + if (!modest_account_mgr_account_is_busy(account_mgr, account_data->account_name)) + { + if (last_updated > 0) + last_updated_string = modest_text_utils_get_display_date(last_updated); + else + last_updated_string = g_strdup (_("mcen_va_never")); + } + else + { + /* FIXME: There should be a logical name in the UI specs */ + last_updated_string = g_strdup(_("Refreshing...")); + } + return last_updated_string; +} static void update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) @@ -205,15 +228,8 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) if (account_data->store_account) { GtkTreeIter iter; - time_t last_updated; - gchar *last_updated_string; - /* FIXME: let's assume that 'last update' applies to the store account... */ - last_updated = account_data->store_account->last_updated; - if (last_updated > 0) - last_updated_string = modest_text_utils_get_display_date(last_updated); - else - last_updated_string = g_strdup (_("mcen_va_never")); + gchar *last_updated_string = get_last_updated_string(account_mgr, account_data); if (account_data->is_enabled) { gtk_list_store_insert_with_values ( @@ -222,14 +238,14 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, account_data->display_name, MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, account_data->is_enabled, MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, account_data->is_default, - + MODEST_ACCOUNT_VIEW_PROTO_COLUMN, modest_protocol_info_get_transport_store_protocol_name (account_data->store_account->proto), MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string, -1); - g_free (last_updated_string); } + g_free (last_updated_string); } modest_account_mgr_free_account_data (account_mgr, account_data); @@ -263,6 +279,36 @@ on_account_changed (ModestAccountMgr *account_mgr, update_account_view (account_mgr, self); } +static void +on_account_busy_changed(ModestAccountMgr *account_mgr, const gchar *account_name, + gboolean busy, ModestAccountView *self) +{ + GtkListStore *model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(self))); + GtkTreeIter iter; + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) + return; + do + { + gchar* cur_name; + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, + &cur_name, -1); + if (g_str_equal(cur_name, account_name)) + { + ModestAccountData* account_data = + modest_account_mgr_get_account_data (account_mgr, account_name); + if (!account_data) + return; + gchar* last_updated_string = get_last_updated_string(account_mgr, account_data); + gtk_list_store_set(model, &iter, + MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string, + -1); + g_free (last_updated_string); + modest_account_mgr_free_account_data (account_mgr, account_data); + return; + } + } + while (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter)); +} static void on_account_removed (ModestAccountMgr *account_mgr, @@ -448,6 +494,8 @@ init_view (ModestAccountView *self) G_CALLBACK(on_account_removed), self); priv->sig2 = g_signal_connect (G_OBJECT(priv->account_mgr), "account_changed", G_CALLBACK(on_account_changed), self); + priv->sig3 = g_signal_connect (G_OBJECT(priv->account_mgr), "account_busy_changed", + G_CALLBACK(on_account_busy_changed), self); } -- 1.7.9.5