X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-account-view.c;h=1f6f3eab9fe424ee7a702447f20c7f10ffe9a8a5;hb=dbbefa965fe138f1ec092c128c5a49259573abf4;hp=e09f6b08c1ea5a5fa9ea1ac321ef6b5a139e8c24;hpb=a2f971fd9378912d99ca8ce97c514bba81a3c4e2;p=modest diff --git a/src/widgets/modest-account-view.c b/src/widgets/modest-account-view.c index e09f6b0..1f6f3ea 100644 --- a/src/widgets/modest-account-view.c +++ b/src/widgets/modest-account-view.c @@ -42,6 +42,7 @@ #include #include #include /* For strcmp(). */ +#include /* 'private'/'protected' functions */ static void modest_account_view_class_init (ModestAccountViewClass *klass); @@ -58,6 +59,11 @@ static void on_display_name_changed (ModestAccountMgr *self, const gchar *account, gpointer user_data); +static void modest_account_view_select_first_account (ModestAccountView *account_view); + +static void on_account_updated (ModestAccountMgr* mgr, gchar* account_name, + gpointer user_data); + typedef enum { MODEST_ACCOUNT_VIEW_NAME_COLUMN, MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, @@ -146,22 +152,32 @@ 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) +/* Get the string for the last updated time. Result must NOT be g_freed */ +static const gchar* +get_last_updated_string(ModestAccountMgr* account_mgr, ModestAccountSettings *settings) { /* 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)) { + const gchar *last_updated_string; + const gchar *store_account_name; + const gchar *account_name; + time_t last_updated; + ModestServerAccountSettings *server_settings; + + server_settings = modest_account_settings_get_store_settings (settings); + store_account_name = modest_server_account_settings_get_account_name (server_settings); + last_updated = modest_account_mgr_get_last_updated (account_mgr, store_account_name); + g_object_unref (server_settings); + account_name = modest_account_settings_get_account_name (settings); + if (!modest_account_mgr_account_is_busy(account_mgr, 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")); + last_updated_string = _("mcen_va_never"); } else { /* FIXME: There should be a logical name in the UI specs */ - last_updated_string = g_strdup(_("mcen_va_refreshing")); + last_updated_string = _("mcen_va_refreshing"); } + return last_updated_string; } @@ -193,41 +209,48 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) while (cursor) { gchar *account_name; - ModestAccountData *account_data; + ModestAccountSettings *settings; + ModestServerAccountSettings *store_settings; account_name = (gchar*)cursor->data; - account_data = modest_account_mgr_get_account_data (account_mgr, account_name); - if (!account_data) { + settings = modest_account_mgr_load_account_settings (account_mgr, account_name); + if (!settings) { g_printerr ("modest: failed to get account data for %s\n", account_name); continue; } + store_settings = modest_account_settings_get_store_settings (settings); /* don't display accounts without stores */ - if (account_data->store_account) { + if (modest_server_account_settings_get_account_name (store_settings) != NULL) { GtkTreeIter iter; + + /* don't free */ + const gchar *last_updated_string = get_last_updated_string(account_mgr, settings); - gchar *last_updated_string = get_last_updated_string(account_mgr, account_data); - - if (account_data->is_enabled) { + if (modest_account_settings_get_enabled (settings)) { const gchar *proto_name; - proto_name = modest_protocol_info_get_transport_store_protocol_name (account_data->store_account->proto); + proto_name = modest_protocol_info_get_transport_store_protocol_name + (modest_server_account_settings_get_protocol (store_settings)); gtk_list_store_insert_with_values ( model, &iter, 0, MODEST_ACCOUNT_VIEW_NAME_COLUMN, account_name, - 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_DISPLAY_NAME_COLUMN, + modest_account_settings_get_display_name (settings), + MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, + modest_account_settings_get_enabled (settings), + MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, + modest_account_settings_get_is_default (settings), MODEST_ACCOUNT_VIEW_PROTO_COLUMN, proto_name, 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); + + g_object_unref (store_settings); + g_object_unref (settings); cursor = cursor->next; } @@ -261,18 +284,17 @@ on_account_busy_changed(ModestAccountMgr *account_mgr, &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) { + ModestAccountSettings* settings = + modest_account_mgr_load_account_settings (account_mgr, account_name); + if (!settings) { g_free (cur_name); return; } - gchar* last_updated_string = get_last_updated_string(account_mgr, account_data); + const gchar* last_updated_string = get_last_updated_string(account_mgr, settings); 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); + g_object_unref (settings); found = TRUE; } g_free (cur_name); @@ -310,7 +332,15 @@ on_account_removed (TnyAccountStore *account_store, self = MODEST_ACCOUNT_VIEW (user_data); priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self); - + + gchar *selected_name = modest_account_view_get_selected_account (self); + if (selected_name == NULL) { + /* we select the first account if none is selected */ + modest_account_view_select_first_account (self); + } else { + g_free (selected_name); + } + update_account_view (priv->account_mgr, self); } @@ -372,6 +402,14 @@ on_account_default_toggled (GtkCellRendererToggle *cell_renderer, g_free (account_name); } +static void +on_account_updated (ModestAccountMgr* mgr, + gchar* account_name, + gpointer user_data) +{ + update_account_view (mgr, MODEST_ACCOUNT_VIEW (user_data)); +} + void bold_if_default_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer user_data) @@ -495,6 +533,12 @@ init_view (ModestAccountView *self) "display_name_changed", G_CALLBACK(on_display_name_changed), self); + priv->sig_handlers = + modest_signal_mgr_connect (priv->sig_handlers, + G_OBJECT (priv->account_mgr), + "account_updated", + G_CALLBACK (on_account_updated), + self); } @@ -588,6 +632,21 @@ modest_account_view_select_account (ModestAccountView *account_view, } static void +modest_account_view_select_first_account (ModestAccountView *account_view) +{ + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (account_view)); + g_return_if_fail (model != NULL); + + GtkTreeIter iter; + gtk_tree_model_get_iter_first (model, &iter); + + GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (account_view)); + g_return_if_fail (selection != NULL); + + gtk_tree_selection_select_iter (selection, &iter); +} + +static void on_default_account_changed (ModestAccountMgr *mgr, gpointer user_data) { @@ -610,7 +669,7 @@ on_default_account_changed (ModestAccountMgr *mgr, -1); /* Update the default account column */ - if (!strcmp (name, default_account_name)) + if ((default_account_name != NULL) && (!strcmp (name, default_account_name))) gtk_list_store_set (GTK_LIST_STORE (model), &iter, MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, TRUE, -1); else