}
}
+
+static gboolean
+update_tny_account_for_account (ModestTnyAccountStore *self, ModestAccountMgr *acc_mgr,
+ const gchar *account_name, TnyAccountType type)
+{
+ ModestTnyAccountStorePrivate *priv;
+ TnyList* account_list;
+ gboolean found = FALSE;
+ TnyIterator *iter = NULL;
+
+ g_return_val_if_fail (self, FALSE);
+ g_return_val_if_fail (account_name, FALSE);
+ g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE ||
+ type == TNY_ACCOUNT_TYPE_TRANSPORT,
+ FALSE);
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+ account_list = (type == TNY_ACCOUNT_TYPE_STORE ? priv->store_accounts : priv->transport_accounts);
+
+ iter = tny_list_create_iterator (account_list);
+ while (!tny_iterator_is_done (iter) && !found) {
+ TnyAccount *tny_account;
+ tny_account = TNY_ACCOUNT (tny_iterator_get_current (iter));
+ if (tny_account) {
+ const gchar* parent_name =
+ modest_tny_account_get_parent_modest_account_name_for_server_account (tny_account);
+ if (parent_name && strcmp (parent_name, account_name) == 0) {
+ found = TRUE;
+ modest_tny_account_update_from_account (tny_account, acc_mgr, account_name, type);
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, tny_account);
+ }
+ g_object_unref (tny_account);
+ }
+ tny_iterator_next (iter);
+ }
+
+ if (iter)
+ g_object_unref (iter);
+
+ return found;
+}
+
+
static void
on_account_changed (ModestAccountMgr *acc_mgr,
- const gchar *account,
+ const gchar *account_name,
const gchar *key,
gboolean server_account,
gpointer user_data)
printf ("DEBUG: modest: %s\n", __FUNCTION__);
ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
-
+
/* Ignore the change if it's a change in the last_updated value */
if (key && g_str_has_suffix ((const gchar *) key, MODEST_ACCOUNT_LAST_UPDATED))
return;
-
- /* FIXME: make this more finegrained; changes do not really affect _all_
- * accounts
- */
-/* recreate_all_accounts (self); */
+ if (!server_account && FALSE) { /* FIXME FALSE: turned off for now */
+ if (!update_tny_account_for_account (self, acc_mgr, account_name, TNY_ACCOUNT_TYPE_STORE))
+ g_warning ("%s: failed to update store account for %s", __FUNCTION__, account_name);
+ if (!update_tny_account_for_account (self, acc_mgr, account_name, TNY_ACCOUNT_TYPE_TRANSPORT))
+ g_warning ("%s: failed to update transport account for %s", __FUNCTION__, account_name);
+ }
+
/* TODO: This doesn't actually work, because
* a) The account name is not sent correctly per key:
* b) We should test the end of the key, not the whole keym
* c) We don't seem to be getting all keys here.
- * Instead, we just forget the password for all accounts when we create them, for now.
+ * Instead, we just forget the password for all accounts when we create them,
+ * for now.
*/
- #if 0
- /* If a password has changed, then forget the previously cached password for this account: */
- if (server_account && key && g_slist_find_custom ((GSList *)keys, MODEST_ACCOUNT_PASSWORD, (GCompareFunc)strcmp)) {
- printf ("DEBUG: %s: Forgetting cached password for account ID=%s\n", __FUNCTION__, account);
- modest_tny_account_store_forget_password_in_memory (self, account);
- }
- #endif
-
- g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, account);
}
static void
* when it is a question.
* Obviously, we need tinymail to use more specific error codes instead,
* so we know what buttons to show. */
-
+
/* TODO: Do this in the main context: */
GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_window),
prompt));
/* intentionally left blank */
}
+
+
+gboolean
+modest_tny_account_update_from_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
+ const gchar *account_name, TnyAccountType type)
+{
+ ModestAccountData *account_data = NULL;
+ ModestServerAccountData *server_data = NULL;
+
+ g_return_val_if_fail (tny_account, FALSE);
+ g_return_val_if_fail (account_mgr, FALSE);
+ g_return_val_if_fail (account_name, FALSE);
+ g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT,
+ FALSE);
+
+ account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
+ if (!account_data) {
+ g_printerr ("modest: %s: cannot get account data for account %s\n",
+ __FUNCTION__, account_name);
+ return FALSE;
+ }
+
+ if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
+ server_data = account_data->store_account;
+ else if (type == TNY_ACCOUNT_TYPE_TRANSPORT && account_data->transport_account)
+ server_data = account_data->transport_account;
+ if (!server_data) {
+ g_printerr ("modest: no %s account defined for '%s'\n",
+ type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
+ account_data->display_name);
+ modest_account_mgr_free_account_data (account_mgr, account_data);
+ return FALSE;
+ }
+
+ update_tny_account (tny_account, account_mgr, server_data);
+
+ /* This name is what shows up in the folder view -- so for some POP/IMAP/... server
+ * account, we set its name to the account of which it is part. */
+
+ if (account_data->display_name)
+ tny_account_set_name (tny_account, account_data->display_name);
+
+ modest_account_mgr_free_account_data (account_mgr, account_data);
+
+ return TRUE;
+}
+
+
+
TnyAccount*
modest_tny_account_new_from_account (ModestAccountMgr *account_mgr,
const gchar *account_name,
g_return_val_if_fail (account_mgr, NULL);
g_return_val_if_fail (account_name, NULL);
g_return_val_if_fail (session, NULL);
+ g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT,
+ NULL);
account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
if (!account_data) {
tny_account_set_pass_func (tny_account,
get_pass_func ? get_pass_func: get_pass_dummy);
-
- modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account, account_name);
-
+ modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account,
+ account_name);
modest_account_mgr_free_account_data (account_mgr, account_data);
return tny_account;
void
modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAccount *self,
- const gchar* parent_modest_acount_name)
+ const gchar* parent_modest_account_name)
{
g_object_set_data_full (G_OBJECT(self), "modest_account",
- (gpointer) g_strdup (parent_modest_acount_name), g_free);
+ (gpointer) g_strdup (parent_modest_account_name), g_free);
}
gboolean
G_BEGIN_DECLS
+
+
+
+
/**
* modest_tny_account_new_from_account:
* @account_mgr: a valid account mgr instance
* @forget_pass_func: the forget-password function
*
* get a tnyaccount corresponding to the server_accounts (store or transport) for this account.
- * NOTE: this function does not set the camel session or the get/forget password functions
*
* Returns: a new TnyAccount or NULL in case of error.
*/
/**
+ * modest_tny_account_update_from_account:
+ * @tny_account: a valid tny_account
+ * @account_mgr: a valid account mgr instance
+ * @account_name: the modest account name for which to create a corresponding tny account of the given type.
+ * @type: the type of account to create (TNY_ACCOUNT_TYPE_STORE or TNY_ACCOUNT_TYPE_TRANSPORT)
+ *
+ * update a tnyaccount corresponding to the server_accounts (store or transport) for this account.
+ *
+ * Returns: a TRUE or FALSE in case of error.
+ */
+gboolean
+modest_tny_account_update_from_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
+ const gchar *account_name, TnyAccountType type);
+
+
+/**
* modest_tny_account_new_for_local_folders:
* @account_mgr: a valid account mgr instance
* @session: a tny camel session
/* 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 (!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);
+ last_updated_string = modest_text_utils_get_display_date(last_updated);
else
- last_updated_string = g_strdup (_("mcen_va_never"));
- }
- 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..."));
+ last_updated_string = g_strdup(_("..."));
}
return last_updated_string;
}
static void
-on_account_changed (ModestAccountMgr *obj, const gchar* account,
- const gchar* key, gboolean server_account,
+on_account_changed (TnyAccountStore *account_store,
+ TnyAccount *account,
gpointer user_data)
{
ModestAccountView *self;
self = MODEST_ACCOUNT_VIEW (user_data);
priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
+ g_warning ("account changed: %s", tny_account_get_id(account));
+
update_account_view (priv->account_mgr, self);
}
TnyAccount *account,
gpointer user_data);
+static void on_account_changed (TnyAccountStore *self,
+ TnyAccount *account,
+ gpointer user_data);
+
static gint cmp_rows (GtkTreeModel *tree_model,
GtkTreeIter *iter1,
GtkTreeIter *iter2,
gulong changed_signal;
gulong account_inserted_signal;
gulong account_removed_signal;
+ gulong account_changed_signal;
gulong conf_key_signal;
/* not unref this object, its a singlenton */
}
/* Simplify checks for NULLs: */
-static gboolean strings_are_equal (const gchar *a, const gchar *b)
+static gboolean
+strings_are_equal (const gchar *a, const gchar *b)
{
if (!a && !b)
return TRUE;
return FALSE;
}
-static gboolean on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
+static gboolean
+on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
GObject *instance = NULL;
gchar *previous_name;
} GetMmcAccountNameData;
-static void on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data)
+static void
+on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data)
{
/* printf ("DEBU1G: %s: account name=%s\n", __FUNCTION__, tny_account_get_name (TNY_ACCOUNT(account))); */
priv->account_inserted_signal);
g_signal_handler_disconnect (G_OBJECT(priv->account_store),
priv->account_removed_signal);
+ g_signal_handler_disconnect (G_OBJECT(priv->account_store),
+ priv->account_changed_signal);
g_object_unref (G_OBJECT(priv->account_store));
priv->account_store = NULL;
}
priv->account_removed_signal))
g_signal_handler_disconnect (G_OBJECT (priv->account_store),
priv->account_removed_signal);
-
+ if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
+ priv->account_changed_signal))
+ g_signal_handler_disconnect (G_OBJECT (priv->account_store),
+ priv->account_changed_signal);
g_object_unref (G_OBJECT (priv->account_store));
}
g_signal_connect (G_OBJECT(account_store), "account_inserted",
G_CALLBACK (on_account_inserted), self);
-
-/* g_signal_connect (G_OBJECT(account_store), "connecting_finished", */
-/* G_CALLBACK (on_accounts_reloaded), self); */
-
-/* on_accounts_reloaded (account_store, (gpointer ) self); */
+ priv->account_changed_signal =
+ g_signal_connect (G_OBJECT(account_store), "account_changed",
+ G_CALLBACK (on_account_changed), self);
modest_folder_view_update_model (MODEST_FOLDER_VIEW (self), account_store);
G_OBJECT (account));
}
+
+static void
+on_account_changed (TnyAccountStore *account_store, TnyAccount *tny_account,
+ gpointer user_data)
+{
+ g_warning ("%s: account_id = %s", __FUNCTION__, tny_account_get_id(tny_account));
+}
+
+
+
static void
on_account_removed (TnyAccountStore *account_store,
TnyAccount *account,