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\
+++ /dev/null
-/* 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 <modest-account-mgr-priv.h>
-#include <modest-defs.h>
-#include <string.h>
-#include <modest-conf.h>
-#include <stdio.h>
-
-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;
-}
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;
gboolean
modest_account_mgr_remove_account (ModestAccountMgr * self,
- const gchar * name, gboolean server_account)
+ const gchar* name, gboolean server_account)
{
ModestAccountMgrPrivate *priv;
gchar *key;
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;
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;
+}
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);
};
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)
{
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:
}
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);