From: Sergio Villar Senin Date: Fri, 8 Jun 2007 13:49:22 +0000 (+0000) Subject: * Deleted a priv .c file, it's enough with the .h file to make their methods protected X-Git-Tag: git_migration_finished~3367 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=e565f583b5b88c4e1cc330f5ed22c39f86525a32;hp=fd382dbc5face5a3cf26d4e9b3fa2f78b3afce4c * Deleted a priv .c file, it's enough with the .h file to make their methods protected * Fixed a crasher related to DBUS when setting the last update value * Added an emission of the account_removed signal * Fixes NB#56420, the account cache is now cleared when an account is removed pmo-trunk-r2132 --- diff --git a/src/Makefile.am b/src/Makefile.am index 97821b1..fb4b397 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,7 +33,6 @@ bin_PROGRAMS=\ modest_SOURCES=\ modest-account-mgr-helpers.c\ modest-account-mgr-helpers.h\ - modest-account-mgr-priv.c\ modest-account-mgr-priv.h\ modest-account-mgr.c\ modest-account-mgr.h\ diff --git a/src/modest-account-mgr-priv.c b/src/modest-account-mgr-priv.c deleted file mode 100644 index d0c80f6..0000000 --- a/src/modest-account-mgr-priv.c +++ /dev/null @@ -1,124 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#include -#include -#include -#include -#include - -gchar* -_modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account) -{ - /* Initialize input parameters: */ - if (is_account_key) - *is_account_key = FALSE; - - if (is_server_account) - *is_server_account = FALSE; - - const gchar* account_ns = MODEST_ACCOUNT_NAMESPACE "/"; - const gchar* server_account_ns = MODEST_SERVER_ACCOUNT_NAMESPACE "/"; - gchar *cursor; - gchar *account = NULL; - - /* determine whether it's an account or a server account, - * based on the prefix */ - if (g_str_has_prefix (key, account_ns)) { - - if (is_server_account) - *is_server_account = FALSE; - - account = g_strdup (key + strlen (account_ns)); - - } else if (g_str_has_prefix (key, server_account_ns)) { - - if (is_server_account) - *is_server_account = TRUE; - - account = g_strdup (key + strlen (server_account_ns)); - } else - return NULL; - - /* if there are any slashes left in the key, it's not - * the toplevel entry for an account - */ - cursor = strstr(account, "/"); - - if (is_account_key && cursor) - *is_account_key = TRUE; - - /* put a NULL where the first slash was */ - if (cursor) - *cursor = '\0'; - - if (account) { - /* The key is an escaped string, so unescape it to get the actual account name: */ - gchar *unescaped_name = modest_conf_key_unescape (account); - g_free (account); - return unescaped_name; - } else - return NULL; -} - - - -/* must be freed by caller */ -gchar * -_modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account) -{ - gchar *retval = NULL; - - gchar *namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE; - - if (!account_name) - return g_strdup (namespace); - - /* Always escape the conf keys, so that it is acceptable to gconf: */ - gchar *escaped_account_name = account_name ? modest_conf_key_escape (account_name) : NULL; - gchar *escaped_name = name ? modest_conf_key_escape (name) : NULL; - - if (escaped_account_name && escaped_name) - retval = g_strconcat (namespace, "/", escaped_account_name, "/", escaped_name, NULL); - else if (escaped_account_name) - retval = g_strconcat (namespace, "/", escaped_account_name, NULL); - - /* Sanity check: */ - if (!modest_conf_key_is_valid (retval)) { - g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__, retval); - g_free (retval); - retval = NULL; - } - - g_free (escaped_name); - g_free (escaped_account_name); - - return retval; -} diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index d1a83a0..fee90c3 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -103,9 +103,11 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint if (!account) return; - /* account was removed -- emit this, even if the account was disabled */ + /* account was removed -- emit this, even if the account was + disabled. This should not happen unless the user directly + does it in gconf */ if (is_account_key && event == MODEST_CONF_EVENT_KEY_UNSET) { - g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, + g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, account, is_server_account); g_free (account); return; @@ -514,7 +516,7 @@ modest_account_mgr_add_server_account_uri (ModestAccountMgr * self, gboolean modest_account_mgr_remove_account (ModestAccountMgr * self, - const gchar * name, gboolean server_account) + const gchar* name, gboolean server_account) { ModestAccountMgrPrivate *priv; gchar *key; @@ -529,7 +531,15 @@ modest_account_mgr_remove_account (ModestAccountMgr * self, return FALSE; } - /* in case we're not deleting an account, also delete the dependent store and transport account */ + /* Notify the observers. We need to do that here because they + could need to use the configuration keys before deleting + them, i.e., the account store will delete the cache. We + only notify about removals of modest accounts */ + if (!server_account) + g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, + name, server_account); + + /* in case we're deleting an account, also delete the dependent store and transport account */ if (!server_account) { gchar *server_account_name; @@ -1061,3 +1071,92 @@ modest_account_mgr_unset (ModestAccountMgr *self, const gchar *name, g_free (keyname); return retval; } + +gchar* +_modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account) +{ + /* Initialize input parameters: */ + if (is_account_key) + *is_account_key = FALSE; + + if (is_server_account) + *is_server_account = FALSE; + + const gchar* account_ns = MODEST_ACCOUNT_NAMESPACE "/"; + const gchar* server_account_ns = MODEST_SERVER_ACCOUNT_NAMESPACE "/"; + gchar *cursor; + gchar *account = NULL; + + /* determine whether it's an account or a server account, + * based on the prefix */ + if (g_str_has_prefix (key, account_ns)) { + + if (is_server_account) + *is_server_account = FALSE; + + account = g_strdup (key + strlen (account_ns)); + + } else if (g_str_has_prefix (key, server_account_ns)) { + + if (is_server_account) + *is_server_account = TRUE; + + account = g_strdup (key + strlen (server_account_ns)); + } else + return NULL; + + /* if there are any slashes left in the key, it's not + * the toplevel entry for an account + */ + cursor = strstr(account, "/"); + + if (is_account_key && cursor) + *is_account_key = TRUE; + + /* put a NULL where the first slash was */ + if (cursor) + *cursor = '\0'; + + if (account) { + /* The key is an escaped string, so unescape it to get the actual account name: */ + gchar *unescaped_name = modest_conf_key_unescape (account); + g_free (account); + return unescaped_name; + } else + return NULL; +} + + + +/* must be freed by caller */ +gchar * +_modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account) +{ + gchar *retval = NULL; + + gchar *namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE; + + if (!account_name) + return g_strdup (namespace); + + /* Always escape the conf keys, so that it is acceptable to gconf: */ + gchar *escaped_account_name = account_name ? modest_conf_key_escape (account_name) : NULL; + gchar *escaped_name = name ? modest_conf_key_escape (name) : NULL; + + if (escaped_account_name && escaped_name) + retval = g_strconcat (namespace, "/", escaped_account_name, "/", escaped_name, NULL); + else if (escaped_account_name) + retval = g_strconcat (namespace, "/", escaped_account_name, NULL); + + /* Sanity check: */ + if (!modest_conf_key_is_valid (retval)) { + g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__, retval); + g_free (retval); + retval = NULL; + } + + g_free (escaped_name); + g_free (escaped_account_name); + + return retval; +} diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index 969a0a2..c355017 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -56,10 +56,14 @@ struct _ModestAccountMgr { struct _ModestAccountMgrClass { GObjectClass parent_class; - void (* account_removed) (ModestAccountMgr *obj, const gchar* account, - gboolean server_account, gpointer user_data); - void (* account_changed) (ModestAccountMgr *obj, const gchar* account, - const GSList* keys, gboolean server_account, + void (* account_removed) (ModestAccountMgr *obj, + const gchar* account, + gboolean server_account, + gpointer user_data); + void (* account_changed) (ModestAccountMgr *obj, + const gchar* account, + const gchar* key, + gboolean server_account, gpointer user_data); }; diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 686aa12..da4eb43 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -809,6 +809,21 @@ compare_headers_by_date (gconstpointer a, return -1; } +static gboolean +set_last_updated_idle (gpointer data) +{ + /* It does not matter if the time is not exactly the same than + the time when this idle was called, it's just an + approximation and it won't be very different */ + modest_account_mgr_set_int (modest_runtime_get_account_mgr (), + (gchar *) data, + MODEST_ACCOUNT_LAST_UPDATED, + time(NULL), + TRUE); + + return FALSE; +} + static gpointer update_account_thread (gpointer thr_user_data) { @@ -1000,12 +1015,13 @@ update_account_thread (gpointer thr_user_data) if (!priv->error) { priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS; - /* Update the last updated key */ - modest_account_mgr_set_int (modest_runtime_get_account_mgr (), - tny_account_get_id (TNY_ACCOUNT (info->account)), - MODEST_ACCOUNT_LAST_UPDATED, - time(NULL), - TRUE); + /* Update the last updated key. TODO: this causes + sometimes an error in dbus, in order to fix this we + must call gconf from the main loop */ + g_idle_add_full (G_PRIORITY_HIGH_IDLE, + set_last_updated_idle, + g_strdup (tny_account_get_id (TNY_ACCOUNT (info->account))), + (GDestroyNotify) g_free); } out: diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index f14a5af..bd08cb1 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -317,16 +317,29 @@ on_vfs_volume_unmounted(GnomeVFSVolumeMonitor *volume_monitor, } static void -on_account_removed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean server_account, +on_account_removed (ModestAccountMgr *acc_mgr, + const gchar *account, + gboolean server_account, gpointer user_data) { ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data); - - /* FIXME: make this more finegrained; changes do not really affect _all_ - * accounts, and some do not affect tny accounts at all (such as 'last_update') + TnyAccount *store_account; + + /* Clear the account cache */ + store_account = + modest_tny_account_store_get_server_account (self, + account, + TNY_ACCOUNT_TYPE_STORE); + if (store_account) { + tny_store_account_delete_cache (TNY_STORE_ACCOUNT (store_account)); + g_object_unref (store_account); + } + + /* FIXME: make this more finegrained; changes do not + * really affect _all_ accounts, and some do not + * affect tny accounts at all (such as 'last_update') */ - if (server_account) - recreate_all_accounts (self); + recreate_all_accounts (self); g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, account);