From: Sergio Villar Senin Date: Fri, 27 Jul 2007 19:25:59 +0000 (+0000) Subject: * Some more changes X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=068e3c0b67ea8ba867c131f32b4d1e24be65874b;p=modest * Some more changes pmo-sessionwork-r2837 --- diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 7fc0726..8f7f969 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -103,7 +103,7 @@ static void on_queue_changed (ModestMailOperationQue static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window); -static void on_account_update (TnyAccountStore *account_store, +static void account_number_changed (TnyAccountStore *account_store, const gchar *account_name, gpointer user_data); @@ -690,7 +690,10 @@ connect_signals (ModestMainWindow *self) /* Track account changes. We need to refresh the toolbar */ g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()), - "account_update", G_CALLBACK (on_account_update), + "account_inserted", G_CALLBACK (account_number_changed), + self); + g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()), + "account_removed", G_CALLBACK (account_number_changed), self); /* Account store */ @@ -1194,7 +1197,7 @@ modest_main_window_show_toolbar (ModestWindow *self, gtk_widget_tap_and_hold_setup (GTK_WIDGET (reply_button), menu, NULL, 0); /* Set send & receive button tap and hold menu */ - on_account_update (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()), + account_number_changed (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()), NULL, self); } @@ -1218,9 +1221,9 @@ compare_display_names (ModestAccountData *a, } static void -on_account_update (TnyAccountStore *account_store, - const gchar *account_name, - gpointer user_data) +account_number_changed (TnyAccountStore *account_store, + const gchar *account_name, + gpointer user_data) { GSList *account_names, *iter, *accounts; ModestMainWindow *self; @@ -1432,7 +1435,7 @@ on_account_update (TnyAccountStore *account_store, for (i = 0; i < num_accounts; i++) { ModestAccountData *account_data = (ModestAccountData *) g_slist_nth_data (accounts, i); - if(account_data->account_name && + if(account_data->account_name && default_account && strcmp (account_data->account_name, default_account) == 0) { gchar *item_name = g_strconcat (account_data->account_name, "Menu", NULL); diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 1089275..9939943 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -1337,10 +1337,11 @@ modest_platform_create_folder_view (TnyFolderStoreQuery *query) { GtkWidget *widget = modest_folder_view_new (query); - /* Show all accounts by default */ + /* Show one account by default */ modest_folder_view_set_style (MODEST_FOLDER_VIEW (widget), MODEST_FOLDER_VIEW_STYLE_SHOW_ONE); + /* Restore settings */ modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT (widget), diff --git a/src/modest-account-mgr-helpers.c b/src/modest-account-mgr-helpers.c index 5d05bb4..6d08c40 100644 --- a/src/modest-account-mgr-helpers.c +++ b/src/modest-account-mgr-helpers.c @@ -593,9 +593,7 @@ modest_account_mgr_set_default_account (ModestAccountMgr *self, const gchar* ac conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf; - return modest_conf_set_string (conf, MODEST_CONF_DEFAULT_ACCOUNT, - account, NULL); - + return modest_conf_set_string (conf, MODEST_CONF_DEFAULT_ACCOUNT, account, NULL); } gboolean diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 3da0df3..5826c61 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -48,99 +48,98 @@ enum { LAST_SIGNAL }; - /* globals */ static GObjectClass *parent_class = NULL; static guint signals[LAST_SIGNAL] = {0}; -/* We signal key changes in batches, every X seconds: */ -static gboolean -on_timeout_notify_changes (gpointer data) -{ - ModestAccountMgr *self = MODEST_ACCOUNT_MGR (data); - ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); +/* /\* We signal key changes in batches, every X seconds: *\/ */ +/* static gboolean */ +/* on_timeout_notify_changes (gpointer data) */ +/* { */ +/* ModestAccountMgr *self = MODEST_ACCOUNT_MGR (data); */ +/* ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); */ - /* TODO: Also store the account names, and notify one list for each account, - * if anything uses the account names. */ +/* /\* TODO: Also store the account names, and notify one list for each account, */ +/* * if anything uses the account names. *\/ */ - if (priv->changed_conf_keys) { - gchar *default_account = - modest_account_mgr_get_default_account (self); +/* if (priv->changed_conf_keys) { */ +/* gchar *default_account = */ +/* modest_account_mgr_get_default_account (self); */ - /* printf ("DEBUG: %s: priv->changed_conf_key length=%d\n", - __FUNCTION__, g_slist_length (priv->changed_conf_keys)); */ - g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, - default_account, priv->changed_conf_keys, FALSE); +/* /\* printf ("DEBUG: %s: priv->changed_conf_key length=%d\n", */ +/* __FUNCTION__, g_slist_length (priv->changed_conf_keys)); *\/ */ +/* g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, */ +/* default_account, priv->changed_conf_keys, FALSE); */ - g_free (default_account); +/* g_free (default_account); */ - g_slist_foreach (priv->changed_conf_keys, (GFunc) g_free, NULL); - g_slist_free (priv->changed_conf_keys); - priv->changed_conf_keys = NULL; - } +/* g_slist_foreach (priv->changed_conf_keys, (GFunc) g_free, NULL); */ +/* g_slist_free (priv->changed_conf_keys); */ +/* priv->changed_conf_keys = NULL; */ +/* } */ - return TRUE; /* Call this again later. */ -} - -static void -on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data) -{ - ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data); - ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); - gboolean is_account_key; - gboolean is_server_account; - gchar* account = NULL; - - /* there is only one not-really-account key which will still emit - * a signal: a change in MODEST_CONF_DEFAULT_ACCOUNT */ - if (key && strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) { - /* Get the default account instead. */ +/* return TRUE; /\* Call this again later. *\/ */ +/* } */ + +/* static void */ +/* on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data) */ +/* { */ +/* ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data); */ +/* ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); */ +/* gboolean is_account_key; */ +/* gboolean is_server_account; */ +/* gchar* account = NULL; */ + +/* /\* there is only one not-really-account key which will still emit */ +/* * a signal: a change in MODEST_CONF_DEFAULT_ACCOUNT *\/ */ +/* if (key && strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) { */ +/* /\* Get the default account instead. *\/ */ - /* Store the key for later notification in our timeout callback. - * Notifying for every key change would cause unnecessary work: */ - priv->changed_conf_keys = g_slist_append (priv->changed_conf_keys, - (gpointer) g_strdup (key)); - } +/* /\* Store the key for later notification in our timeout callback. */ +/* * Notifying for every key change would cause unnecessary work: *\/ */ +/* priv->changed_conf_keys = g_slist_append (priv->changed_conf_keys, */ +/* (gpointer) g_strdup (key)); */ +/* } */ - is_account_key = FALSE; - is_server_account = FALSE; - account = _modest_account_mgr_account_from_key (key, &is_account_key, - &is_server_account); - - /* if this is not an account-related key change, ignore */ - if (!account) - return; - - /* account was removed. Do not emit an account removed signal - because it was already being done in the remove_account - method. Do not notify also the removal of the server - account keys for the same reason */ - if ((is_account_key || is_server_account) && - event == MODEST_CONF_EVENT_KEY_UNSET) { - g_free (account); - return; - } - - /* is this account enabled? */ - gboolean enabled = FALSE; - if (is_server_account) - enabled = TRUE; - else - enabled = modest_account_mgr_get_enabled (self, account); - - /* Notify is server account was changed, default account was changed - * or when enabled/disabled changes: - */ - if (enabled || - g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) || - strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) { - /* Store the key for later notification in our timeout callback. - * Notifying for every key change would cause unnecessary work: */ - priv->changed_conf_keys = g_slist_append (NULL, - (gpointer) g_strdup (key)); - } - g_free (account); -} +/* is_account_key = FALSE; */ +/* is_server_account = FALSE; */ +/* account = _modest_account_mgr_account_from_key (key, &is_account_key, */ +/* &is_server_account); */ + +/* /\* if this is not an account-related key change, ignore *\/ */ +/* if (!account) */ +/* return; */ + +/* /\* account was removed. Do not emit an account removed signal */ +/* because it was already being done in the remove_account */ +/* method. Do not notify also the removal of the server */ +/* account keys for the same reason *\/ */ +/* if ((is_account_key || is_server_account) && */ +/* event == MODEST_CONF_EVENT_KEY_UNSET) { */ +/* g_free (account); */ +/* return; */ +/* } */ + +/* /\* is this account enabled? *\/ */ +/* gboolean enabled = FALSE; */ +/* if (is_server_account) */ +/* enabled = TRUE; */ +/* else */ +/* enabled = modest_account_mgr_get_enabled (self, account); */ + +/* /\* Notify is server account was changed, default account was changed */ +/* * or when enabled/disabled changes: */ +/* *\/ */ +/* if (enabled || */ +/* g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) || */ +/* strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) { */ +/* /\* Store the key for later notification in our timeout callback. */ +/* * Notifying for every key change would cause unnecessary work: *\/ */ +/* priv->changed_conf_keys = g_slist_append (NULL, */ +/* (gpointer) g_strdup (key)); */ +/* } */ +/* g_free (account); */ +/* } */ GType @@ -238,7 +237,7 @@ modest_account_mgr_init (ModestAccountMgr * obj) priv->modest_conf = NULL; priv->busy_accounts = NULL; - priv->timeout = g_timeout_add (1000 /* milliseconds */, on_timeout_notify_changes, obj); +/* priv->timeout = g_timeout_add (1000 /\* milliseconds *\/, on_timeout_notify_changes, obj); */ } static void @@ -258,8 +257,8 @@ modest_account_mgr_finalize (GObject * obj) priv->modest_conf = NULL; } - if (priv->timeout) - g_source_remove (priv->timeout); +/* if (priv->timeout) */ +/* g_source_remove (priv->timeout); */ if (priv->changed_conf_keys) { g_slist_foreach (priv->changed_conf_keys, (GFunc) g_free, NULL); @@ -284,10 +283,10 @@ modest_account_mgr_new (ModestConf *conf) g_object_ref (G_OBJECT(conf)); priv->modest_conf = conf; - priv->key_changed_handler_uid = - g_signal_connect (G_OBJECT (conf), "key_changed", - G_CALLBACK (on_key_change), - obj); +/* priv->key_changed_handler_uid = */ +/* g_signal_connect (G_OBJECT (conf), "key_changed", */ +/* G_CALLBACK (on_key_change), */ +/* obj); */ return MODEST_ACCOUNT_MGR (obj); } @@ -381,6 +380,9 @@ modest_account_mgr_add_account (ModestAccountMgr *self, modest_account_mgr_set_enabled (self, name, enabled); + /* Notify the observers */ + g_signal_emit (self, signals[ACCOUNT_INSERTED_SIGNAL], 0, name); + /* if no default account has been defined yet, do so now */ default_account = modest_account_mgr_get_default_account (self); if (!default_account) diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index a801b28..c416442 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -87,13 +87,21 @@ static void get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type); +static void on_account_inserted (ModestAccountMgr *acc_mgr, + const gchar *account, + gpointer user_data); + +static void on_account_removed (ModestAccountMgr *acc_mgr, + const gchar *account, + gpointer user_data); + + /* list my signals */ enum { ACCOUNT_CHANGED_SIGNAL, ACCOUNT_INSERTED_SIGNAL, ACCOUNT_REMOVED_SIGNAL, - ACCOUNT_UPDATE_SIGNAL, PASSWORD_REQUESTED_SIGNAL, LAST_SIGNAL }; @@ -106,6 +114,10 @@ struct _ModestTnyAccountStorePrivate { ModestAccountMgr *account_mgr; TnySessionCamel *session; TnyDevice *device; + + gulong acc_inserted_handler; + gulong acc_changed_handler; + gulong acc_removed_handler; /* We cache the lists of accounts here. * They are created in our get_accounts_func() implementation. */ @@ -207,15 +219,6 @@ modest_tny_account_store_base_init (gpointer g_class) /* g_cclosure_marshal_VOID__VOID, */ /* G_TYPE_NONE, 0); */ - signals[ACCOUNT_UPDATE_SIGNAL] = - g_signal_new ("account_update", - MODEST_TYPE_TNY_ACCOUNT_STORE, - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(ModestTnyAccountStoreClass, account_update), - NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - signals[PASSWORD_REQUESTED_SIGNAL] = g_signal_new ("password_requested", MODEST_TYPE_TNY_ACCOUNT_STORE, @@ -343,80 +346,128 @@ recreate_all_accounts (ModestTnyAccountStore *self) static void on_vfs_volume_mounted(GnomeVFSVolumeMonitor *volume_monitor, - GnomeVFSVolume *volume, gpointer user_data) + GnomeVFSVolume *volume, + gpointer user_data) { - ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); +/* ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); */ /* Check whether this was the external MMC1 card: */ gchar *uri = gnome_vfs_volume_get_activation_uri (volume); if (uri && (strcmp (uri, MODEST_MCC1_VOLUMEPATH_URI) == 0)) { printf ("DEBUG: %s: MMC1 card mounted.\n", __FUNCTION__); - /* TODO: Just add an account and emit (and respond to) - * TnyAccountStore::accountinserted signal? - */ - recreate_all_accounts (self); - - g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, - NULL); +/* /\* TODO: Just add an account and emit (and respond to) */ +/* * TnyAccountStore::accountinserted signal? */ +/* *\/ */ +/* recreate_all_accounts (self); */ + + /* TODO */ +/* g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, */ +/* NULL); */ +/* g_signal_emit (G_OBJECT (self), */ +/* signals [ACCOUNT_INSERTED_SIGNAL], */ +/* 0, mmc_account); */ } - g_free (uri); } static void on_vfs_volume_unmounted(GnomeVFSVolumeMonitor *volume_monitor, - GnomeVFSVolume *volume, gpointer user_data) + GnomeVFSVolume *volume, + gpointer user_data) { - ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); +/* ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); */ /* Check whether this was the external MMC1 card: */ gchar *uri = gnome_vfs_volume_get_activation_uri (volume); if (uri && (strcmp (uri, MODEST_MCC1_VOLUMEPATH_URI) == 0)) { printf ("DEBUG: %s: MMC1 card unmounted.\n", __FUNCTION__); - /* TODO: Just add an account and emit (and respond to) - * TnyAccountStore::accountinserted signal? - */ - recreate_all_accounts (self); +/* /\* TODO: Just add an account and emit (and respond to) */ +/* * TnyAccountStore::accountinserted signal? */ +/* *\/ */ +/* recreate_all_accounts (self); */ - g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, - NULL); +/* g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, */ +/* NULL); */ + + /* TODO */ +/* g_signal_emit (G_OBJECT (self), */ +/* signals [ACCOUNT_REMOVED_SIGNAL], */ +/* 0, mmc_account); */ } - g_free (uri); } static void -on_account_removed (ModestAccountMgr *acc_mgr, - const gchar *account, - gpointer user_data) +on_account_inserted (ModestAccountMgr *acc_mgr, + const gchar *account, + gpointer user_data) { + ModestTnyAccountStorePrivate *priv = NULL; TnyAccount *store_account = NULL, *transport_account = NULL; - ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); + ModestTnyAccountStore *self = NULL; + self = MODEST_TNY_ACCOUNT_STORE(user_data); + priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); + /* Get the server and the transport account */ store_account = modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_STORE); transport_account = modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_TRANSPORT); - /* Clear the cache */ - tny_store_account_delete_cache (TNY_STORE_ACCOUNT (store_account)); + /* Add to the cached accounts */ + tny_list_prepend (priv->store_accounts, G_OBJECT (store_account)); + tny_list_prepend (priv->transport_accounts, G_OBJECT (transport_account)); /* Notify the observers */ - g_signal_emit (G_OBJECT (self), - signals [ACCOUNT_REMOVED_SIGNAL], - 0, store_account); - g_signal_emit (G_OBJECT (self), - signals [ACCOUNT_REMOVED_SIGNAL], - 0, transport_account); + g_signal_emit (G_OBJECT (self), signals [ACCOUNT_INSERTED_SIGNAL], 0, store_account); + g_signal_emit (G_OBJECT (self), signals [ACCOUNT_INSERTED_SIGNAL], 0, transport_account); /* Frees */ g_object_unref (store_account); g_object_unref (transport_account); } +static void +on_account_removed (ModestAccountMgr *acc_mgr, + const gchar *account, + gpointer user_data) +{ + TnyAccount *store_account = NULL, *transport_account = NULL; + ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); + + /* Get the server and the transport account */ + store_account = + modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_STORE); + transport_account = + modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_TRANSPORT); + + /* If there was any problem creating the account, for example, + with the configuration system this could not exist */ + if (store_account) { + /* Clear the cache */ + tny_store_account_delete_cache (TNY_STORE_ACCOUNT (store_account)); + + /* Notify the observers */ + g_signal_emit (G_OBJECT (self), signals [ACCOUNT_REMOVED_SIGNAL], 0, store_account); + g_object_unref (store_account); + } else { + g_warning ("There is no store account for account %s\n", account); + } + + /* If there was any problem creating the account, for example, + with the configuration system this could not exist */ + if (transport_account) { + /* Notify the observers */ + g_signal_emit (G_OBJECT (self), signals [ACCOUNT_REMOVED_SIGNAL], 0, transport_account); + g_object_unref (transport_account); + } else { + g_warning ("There is no transport account for account %s\n", account); + } +} + /** * modest_tny_account_store_forget_password_in_memory * @self: a TnyAccountStore instance @@ -437,9 +488,11 @@ modest_tny_account_store_forget_password_in_memory (ModestTnyAccountStore *self, } static void -on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account, - const GSList *keys, gboolean server_account, gpointer user_data) - +on_account_changed (ModestAccountMgr *acc_mgr, + const gchar *account, + const GSList *keys, + gboolean server_account, + gpointer user_data) { ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); @@ -476,8 +529,8 @@ on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account, } #endif - g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, - account); +/* g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, */ +/* account); */ } @@ -857,6 +910,20 @@ modest_tny_account_store_finalize (GObject *obj) destroy_password_hashtable (self); if (priv->account_mgr) { + /* Disconnect signals */ + if (g_signal_handler_is_connected (priv->account_mgr, + priv->acc_inserted_handler)) + g_signal_handler_disconnect (priv->account_mgr, + priv->acc_inserted_handler); + if (g_signal_handler_is_connected (priv->account_mgr, + priv->acc_changed_handler)) + g_signal_handler_disconnect (priv->account_mgr, + priv->acc_changed_handler); + if (g_signal_handler_is_connected (priv->account_mgr, + priv->acc_removed_handler)) + g_signal_handler_disconnect (priv->account_mgr, + priv->acc_removed_handler); + g_object_unref (G_OBJECT(priv->account_mgr)); priv->account_mgr = NULL; } @@ -914,10 +981,12 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr, TnyDevice *device) tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); /* Connect signals */ - g_signal_connect (G_OBJECT(account_mgr), "account_changed", - G_CALLBACK (on_account_changed), obj); - g_signal_connect (G_OBJECT(account_mgr), "account_removed", - G_CALLBACK (on_account_removed), obj); + priv->acc_inserted_handler = g_signal_connect (G_OBJECT(account_mgr), "account_inserted", + G_CALLBACK (on_account_inserted), obj); + priv->acc_changed_handler = g_signal_connect (G_OBJECT(account_mgr), "account_changed", + G_CALLBACK (on_account_changed), obj); + priv->acc_removed_handler = g_signal_connect (G_OBJECT(account_mgr), "account_removed", + G_CALLBACK (on_account_removed), obj); return MODEST_TNY_ACCOUNT_STORE(obj); } @@ -983,7 +1052,6 @@ get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) g_return_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT); - g_return_if_fail (list); g_return_if_fail (self); priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); @@ -1030,7 +1098,8 @@ get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) (gpointer)self); /* Append to the list and cache it */ - tny_list_append (list, G_OBJECT (tny_account)); + if (list) + tny_list_append (list, G_OBJECT (tny_account)); tny_list_append (accounts, G_OBJECT (tny_account)); } else g_printerr ("modest: failed to create account for %s\n", @@ -1069,7 +1138,8 @@ get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) priv->session, MODEST_MCC1_VOLUMEPATH); /* Append to the list and cache it */ - tny_list_prepend (list, G_OBJECT(tny_account)); + if (list) + tny_list_prepend (list, G_OBJECT(tny_account)); tny_list_append (accounts, G_OBJECT (tny_account)); } } @@ -1107,7 +1177,8 @@ get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) (gpointer)self); /* Append to the list and cache it */ - tny_list_prepend (list, G_OBJECT(tny_account)); + if (list) + tny_list_prepend (list, G_OBJECT(tny_account)); tny_list_append (accounts, G_OBJECT (tny_account)); } else g_printerr ("modest: failed to create smtp-specific account for %s\n", @@ -1143,8 +1214,9 @@ get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) /* Add them to the TnyList: */ if (priv->store_accounts_outboxes) { /* Add accounts to the lists */ - tny_list_foreach (priv->store_accounts_outboxes, - foreach_account_append_to_list, list); + if (list) + tny_list_foreach (priv->store_accounts_outboxes, + foreach_account_append_to_list, list); tny_list_foreach (priv->store_accounts_outboxes, foreach_account_append_to_list, accounts); } @@ -1160,7 +1232,8 @@ get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) } /* Append to the list and cache it */ - tny_list_append (list, G_OBJECT(tny_account)); + if (list) + tny_list_append (list, G_OBJECT(tny_account)); tny_list_append (accounts, G_OBJECT(tny_account)); } @@ -1568,10 +1641,8 @@ modest_tny_account_store_get_server_account (ModestTnyAccountStore *self, /* ******************** WARNING ******************** */ /* /\* Make sure that the tny accounts have been created: */ -/* * TODO: We might want to do this in several places. */ -/* *\/ */ -/* if (!priv->store_accounts || !priv->transport_accounts) */ -/* recreate_all_accounts (self); */ + if (!priv->store_accounts || !priv->transport_accounts) + recreate_all_accounts (self); account_list = (type == TNY_ACCOUNT_TYPE_STORE) ? priv->store_accounts : diff --git a/src/widgets/modest-account-view.c b/src/widgets/modest-account-view.c index fbac3d9..bfe7950 100644 --- a/src/widgets/modest-account-view.c +++ b/src/widgets/modest-account-view.c @@ -60,23 +60,14 @@ typedef enum { MODEST_ACCOUNT_VIEW_COLUMN_NUM } AccountViewColumns; - -/* list my signals */ -enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - typedef struct _ModestAccountViewPrivate ModestAccountViewPrivate; struct _ModestAccountViewPrivate { ModestAccountMgr *account_mgr; - gulong sig1, sig2, sig3; - - /* When this is TRUE, we ignore configuration key changes. - * This is useful when making many changes. */ - gboolean block_conf_updates; - + + /* Signal handlers */ + gulong acc_inserted_handler; + gulong acc_removed_handler; + gulong sig3; }; #define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_ACCOUNT_VIEW, \ @@ -84,9 +75,6 @@ struct _ModestAccountViewPrivate { /* globals */ static GtkTreeViewClass *parent_class = NULL; -/* uncomment the following if you have defined any signals */ -/* static guint signals[LAST_SIGNAL] = {0}; */ - GType modest_account_view_get_type (void) { @@ -131,8 +119,9 @@ modest_account_view_init (ModestAccountView *obj) priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj); priv->account_mgr = NULL; - priv->sig1 = 0; - priv->sig2 = 0; + priv->acc_inserted_handler = 0; + priv->acc_removed_handler = 0; + priv->sig3 = 0; } static void @@ -143,12 +132,15 @@ modest_account_view_finalize (GObject *obj) priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj); if (priv->account_mgr) { - if (priv->sig1) + if (g_signal_handler_is_connected (modest_runtime_get_account_store (), + priv->acc_inserted_handler)) g_signal_handler_disconnect (modest_runtime_get_account_store (), - priv->sig1); + priv->acc_inserted_handler); - if (priv->sig2) - g_signal_handler_disconnect (priv->account_mgr, priv->sig2); + if (g_signal_handler_is_connected (modest_runtime_get_account_store (), + priv->acc_removed_handler)) + g_signal_handler_disconnect (modest_runtime_get_account_store (), + priv->acc_removed_handler); if (priv->sig3) g_signal_handler_disconnect (priv->account_mgr, priv->sig3); @@ -261,28 +253,11 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) } } - static void -on_account_changed (ModestAccountMgr *account_mgr, - const gchar* account, GSList *keys, - gboolean server_account, ModestAccountView *self) -{ - /* Never update the view in response to gconf changes. - * Always do it explicitly instead. - * This is because we have no way to avoid 10 updates when changing - * 10 items, and this blocks the UI. - * - * But this block/unblock API might be useful on platforms where the - * notification does not happen so long after the key was set. - * (We have no way to know when the last key was set, to do a final update).. - */ - - update_account_view (account_mgr, self); -} - -static void -on_account_busy_changed(ModestAccountMgr *account_mgr, const gchar *account_name, - gboolean busy, ModestAccountView *self) +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; @@ -313,6 +288,20 @@ on_account_busy_changed(ModestAccountMgr *account_mgr, const gchar *account_name } static void +on_account_inserted (TnyAccountStore *account_store, + TnyAccount *account, + gpointer user_data) +{ + ModestAccountView *self; + ModestAccountViewPrivate *priv; + + self = MODEST_ACCOUNT_VIEW (user_data); + priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self); + + update_account_view (priv->account_mgr, self); +} + +static void on_account_removed (TnyAccountStore *account_store, TnyAccount *account, gpointer user_data) @@ -323,7 +312,7 @@ on_account_removed (TnyAccountStore *account_store, self = MODEST_ACCOUNT_VIEW (user_data); priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self); - update_account_view (priv->account_mgr, MODEST_ACCOUNT_VIEW (user_data)); + update_account_view (priv->account_mgr, self); } @@ -498,10 +487,14 @@ init_view (ModestAccountView *self) */ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE); - priv->sig1 = g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),"account_removed", - 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->acc_removed_handler = g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()), + "account_removed", + G_CALLBACK(on_account_removed), self); + + priv->acc_inserted_handler = g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()), + "account_inserted", + G_CALLBACK(on_account_inserted), self); + priv->sig3 = g_signal_connect (G_OBJECT(priv->account_mgr), "account_busy_changed", G_CALLBACK(on_account_busy_changed), self); } diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index 28d8808..77691da 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -69,10 +69,6 @@ static void modest_folder_view_set_account_store (TnyAccountStoreView *s static void on_selection_changed (GtkTreeSelection *sel, gpointer data); -static void on_account_update (TnyAccountStore *account_store, - const gchar *account, - gpointer user_data); - static void on_account_removed (TnyAccountStore *self, TnyAccount *account, gpointer user_data); @@ -150,7 +146,6 @@ struct _ModestFolderViewPrivate { TnyFolder *folder_to_select; /* folder to select after the next update */ - gulong account_update_signal; gulong changed_signal; gulong account_inserted_signal; gulong account_removed_signal; @@ -696,8 +691,6 @@ modest_folder_view_finalize (GObject *obj) if (priv->account_store) { g_signal_handler_disconnect (G_OBJECT(priv->account_store), - priv->account_update_signal); - g_signal_handler_disconnect (G_OBJECT(priv->account_store), priv->account_inserted_signal); g_signal_handler_disconnect (G_OBJECT(priv->account_store), priv->account_removed_signal); @@ -758,10 +751,6 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore if (G_UNLIKELY (priv->account_store)) { - if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), - priv->account_update_signal)) - g_signal_handler_disconnect (G_OBJECT (priv->account_store), - priv->account_update_signal); if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), priv->account_inserted_signal)) g_signal_handler_disconnect (G_OBJECT (priv->account_store), @@ -776,10 +765,6 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore priv->account_store = g_object_ref (G_OBJECT (account_store)); - priv->account_update_signal = - g_signal_connect (G_OBJECT(account_store), "account_update", - G_CALLBACK (on_account_update), self); - priv->account_removed_signal = g_signal_connect (G_OBJECT(account_store), "account_removed", G_CALLBACK (on_account_removed), self); @@ -804,16 +789,30 @@ on_account_inserted (TnyAccountStore *account_store, TnyAccount *account, gpointer user_data) { + ModestFolderViewPrivate *priv; GtkTreeModel *sort_model, *filter_model; - /* TODO: invalidate the cur_folder_* and folder_to_select things */ + /* Ignore transport account insertions, we're not showing them + in the folder view */ + if (TNY_IS_TRANSPORT_ACCOUNT (account)) + return; + + priv = MODEST_FOLDER_VIEW_GET_PRIVATE (user_data); + + /* If we're adding a new account, and there is no previous + one, we need to select the visible server account */ + if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE && + !priv->visible_account_id) + modest_widget_memory_restore (modest_runtime_get_conf(), + G_OBJECT (user_data), + MODEST_CONF_FOLDER_VIEW_KEY); /* Get the inner model */ filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data)); sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model)); /* Insert the account in the model */ - tny_list_append (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))), + tny_list_append (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))), G_OBJECT (account)); } @@ -822,10 +821,11 @@ on_account_removed (TnyAccountStore *account_store, TnyAccount *account, gpointer user_data) { - ModestFolderView *self = MODEST_FOLDER_VIEW (user_data); + ModestFolderView *self = NULL; ModestFolderViewPrivate *priv; GtkTreeModel *sort_model, *filter_model; + self = MODEST_FOLDER_VIEW (user_data); priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self); /* TODO: invalidate the cur_folder_* and folder_to_select things */ @@ -853,38 +853,6 @@ on_account_removed (TnyAccountStore *account_store, } } -static void -on_account_update (TnyAccountStore *account_store, - const gchar *account, - gpointer user_data) -{ - ModestFolderView *self = NULL; - ModestFolderViewPrivate *priv; - - g_return_if_fail (MODEST_IS_FOLDER_VIEW (user_data)); - self = MODEST_FOLDER_VIEW (user_data); - priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self); - - /* If we're adding a new account, and there is no previous - one, we need to select the visible server account */ - if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE && - !priv->visible_account_id) - modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self), - MODEST_CONF_FOLDER_VIEW_KEY); - - if (!modest_folder_view_update_model (self, account_store)) - g_printerr ("modest: failed to update model for changes in '%s'", - account); -} - -/* static void */ -/* on_accounts_reloaded (TnyAccountStore *account_store, */ -/* gpointer user_data) */ -/* { */ -/* g_return_if_fail (MODEST_IS_FOLDER_VIEW (user_data)); */ -/* modest_folder_view_update_model (MODEST_FOLDER_VIEW (user_data), account_store); */ -/* } */ - void modest_folder_view_set_title (ModestFolderView *self, const gchar *title) { @@ -1980,7 +1948,7 @@ on_configuration_key_changed (ModestConf* conf, } } -void +void modest_folder_view_set_style (ModestFolderView *self, ModestFolderViewStyle style) { diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index d66cc14..042ec02 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -318,8 +318,8 @@ modest_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *head if (win) *win = NULL; - g_debug ("windows in list: %d", g_list_length (priv->window_list)); - g_debug ("headers in list: %d", g_slist_length (priv->preregistered_uids)); +/* g_debug ("windows in list: %d", g_list_length (priv->window_list)); */ +/* g_debug ("headers in list: %d", g_slist_length (priv->preregistered_uids)); */ has_header = has_uid (priv->preregistered_uids, uid);