2007-04-30 Murray Cumming <murrayc@murrayc.com>
+ * src/modest-account-mgr-helpers.h:
+ * src/modest-account-mgr-helpers.c:
+ Added modest_account_mgr_unset_default_account(),
+ Added modest_account_mgr_set_first_account_as_default().
+
+ * src/modest-account-mgr.c: (modest_account_mgr_remove_account):
+ If it was the default account, unset the default account name.
+
+ * src/maemo/modest-account-view-window.c:
+ (on_delete_button_clicked): If it was the default account,
+ set the first remaining account as the default instead.
+
+ * src/maemo/modest-main-window.c: (on_account_update): Do not try to use
+ a NULL account or a NULL default account, to prevent a crash. This should
+ not happen now anyway. Bug #55343 in projects.maemo.org/bugzilla.
+
+
+2007-04-30 Murray Cumming <murrayc@murrayc.com>
+
* src/widgets/modest-recpt-editor.c:
(modest_recpt_editor_on_key_press_event): Put an #ifdef around the
use of gtk_text_buffer_get_has_selection() (from GTK+ 2.10), and add a
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
/* Remove account. If succeeded it removes also
the account from the ModestAccountView */
+
+ gboolean is_default = FALSE;
+ gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
+ if (default_account_name && (strcmp (default_account_name, account_name) == 0))
+ is_default = TRUE;
+ g_free (default_account_name);
+
removed = modest_account_mgr_remove_account (account_mgr,
- account_name,
- FALSE);
+ account_name,
+ FALSE);
+
+ if (removed && is_default) {
+ /* Set a different account as the default, so there is always at least one default:
+ * This is not specified, and might be the wrong behaviour. murrayc. */
+ modest_account_mgr_set_first_account_as_default (account_mgr);
+ }
+
if (removed) {
/* Show confirmation dialog ??? */
} else {
default_account = modest_account_mgr_get_default_account (mgr);
do {
- TnyAccount *acc;
- const gchar *acc_name;
- gchar *display_name;
+ TnyAccount *acc = NULL;
+ const gchar *acc_name = NULL;
/* Create tool item */
acc = TNY_ACCOUNT (tny_iterator_get_current (iter));
- acc_name = tny_account_get_name (acc);
+ if (acc)
+ acc_name = tny_account_get_name (acc);
/* Create display name */
- if (!strcmp (default_account, acc_name))
- display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_default"), acc_name);
+ gchar *display_name = NULL;
+ if (acc_name) {
+ if (default_account && !(strcmp (default_account, acc_name) == 0))
+ display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_default"), acc_name);
+ else
+ display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_mailbox_n"), acc_name);
+ }
else
- display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_mailbox_n"), acc_name);
+ {
+ /* TODO: This probably should never happen: */
+ display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_default"), "");
+ }
+
item = gtk_menu_item_new_with_label (display_name);
}
+gboolean
+modest_account_mgr_unset_default_account (ModestAccountMgr *self)
+{
+ ModestConf *conf;
+
+ g_return_val_if_fail (self, FALSE);
+
+ conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf;
+
+ return modest_conf_remove_key (conf, MODEST_CONF_DEFAULT_ACCOUNT, NULL /* err */);
+
+}
+
+gboolean
+modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self)
+{
+ gboolean result = FALSE;
+ GSList *account_names = modest_account_mgr_account_names (self);
+ if(account_names)
+ {
+ const gchar* account_name = (const gchar*)account_names->data;
+ if (account_name)
+ result = modest_account_mgr_set_default_account (self, account_name);
+ }
+
+ /* TODO: Free the strings too? */
+ g_slist_free (account_names);
+
+ return result;
+}
+
gchar*
modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name)
{
gchar* modest_account_mgr_get_default_account (ModestAccountMgr *self);
/**
- * modest_account_mgr_get_default_account:
+ * modest_account_mgr_set_default_account:
* @self: a ModestAccountMgr instance
* @account: the name of an existing account
*
const gchar* account);
/**
+ * modest_account_mgr_unset_default_account:
+ * @self: a ModestAccountMgr instance
+ * @account: the name of an account
+ *
+ * Unset the default account name, so that no account is the default.
+ *
+ * Returns: TRUE if succeeded, FALSE otherwise
+ */
+gboolean modest_account_mgr_unset_default_account (ModestAccountMgr *self);
+
+/**
+ * modest_account_mgr_set_first_account_as_default:
+ * @self: a ModestAccountMgr instance
+ *
+ * Guarantees that at least one account, if there are any accounts, is the default,
+ * so that modest_account_mgr_get_default_account() will return non-NULL if there
+ * are any accounts.
+ *
+ * Returns: TRUE if succeeded, FALSE otherwise
+ */
+gboolean
+modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self);
+
+/**
* modest_account_mgr_free_account_data:
* @self: a ModestAccountMgr instance
* @data: a ModestAccountData instance
g_printerr ("modest: error removing key: %s\n", err->message);
g_error_free (err);
}
+
+ /* If this was the default, then remove that setting: */
+ if (!server_account) {
+ gchar *default_account_name = modest_account_mgr_get_default_account (self);
+ if (default_account_name && (strcmp (default_account_name, name) == 0))
+ modest_account_mgr_unset_default_account (self);
+ g_free (default_account_name);
+ }
return retval;
}