+2007-05-02 Murray Cumming <murrayc@murrayc.com>
+
+ * src/modest-account-mgr.h:
+ * src/modest-account-mgr.c:
+ (modest_account_mgr_account_names): Add a gboolean enabled_only
+ parameter, so we can get lists of onlt the enabled accounts.
+
+ (modest_account_mgr_add_account),,
+ (modest_account_mgr_account_with_display_name_exists):
+ * src/maemo/modest-msg-edit-window.c: (get_transports):
+ * src/modest-account-mgr-helpers.c:
+ (modest_account_mgr_set_first_account_as_default):
+ * src/modest-init.c: (init_default_account_maybe):
+ * src/modest-tny-account-store.c: (get_accounts):
+ * src/modest-ui-actions.c: (modest_ui_actions_on_accounts),
+ (do_send_receive_auto), (modest_ui_actions_on_send_receive):
+ * tests/check_account-mgr.c: (START_TEST):
+ Provide the extra parameter, as appropriate.
+
+ * src/widgets/modest-account-view.c: (update_account_view):
+ Do not show disabled accounts (meaning that there is no way to
+ enable/disable accounts in the UI (the feature is not in our UI
+ specification), so we can use this internally only to mark unfinished
+ or temporary account data.
+
+ * src/maemo/easysetup/modest-easysetup-wizard.c:
+ (create_account): Add boolean enable parameter, so we can specify FALSE
+ to create the temporary account.
+ (on_button_edit_advanced_settings): Create the temporary account as disabled.
+ (on_before_next): When finishing, when there is a temporary account, just
+ set it as enabled.
+ Also, use a timeout to delay the showing of the dialog until gconf is likely
+ to return correct information, due to a maemo gconf bug that is fixed in
+ osso 1.1, but not yet in Bora.
+ However, the dialog stays on screen after it is destroyed.
+
+ * src/maemo/modest-account-settings-dialog.c: on_response(): Do not check
+ for invalid data when cancelling. Use a hildon note instead of a dialog
+ to complain about invalid data. Do not show the account-saved note if the
+ account is disabled (a temporary account that will not really be saved for use
+ until later.)
+
2007-04-30 Murray Cumming <murrayc@murrayc.com>
* src/modest-account-mgr-helpers.h:
show_error (GtkWindow *parent_window, const gchar* text);
static gboolean
-create_account (ModestEasysetupWizardDialog *self);
+create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
static void
create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
return GTK_WIDGET (box);
}
+static gboolean
+on_timeout_show_advanced_edit(gpointer user_data)
+{
+ ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
+
+ if (!(self->saved_account_name))
+ return FALSE;
+
+ /* Show the Account Settings window: */
+ ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
+ modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
+
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+
+ /* TODO: The hide() is not necessary.
+ * It is just here to show that it doesn't work,
+ * just as destroy doesn't work.
+ */
+ gtk_widget_hide (GTK_WIDGET(dialog));
+
+ /* TODO: The dialog remains on screen, not allowing any interaction.
+ * But gtk_widget_destroy() should always destroy.
+ */
+ printf("debug: destroying settings dialog\n");
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ printf("debug: after destroying settings dialog (doesn't seem to work).\n");
+
+ return FALSE; /* Do not call this timeout callback again. */
+}
static void
on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
* without recoding it to use non-gconf information.
* This account will be deleted if Finish is never actually clicked. */
- const gboolean saved = create_account (self);
+ gboolean saved = TRUE;
+ gboolean was_already_saved = TRUE;
+ if (!(self->saved_account_name)) {
+ saved = create_account (self, FALSE);
+ was_already_saved = FALSE;
+ }
+
if (!saved)
return;
return;
/* Show the Account Settings window: */
- ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
- modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
-
- gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
- printf ("debug: before run\n");
- gtk_dialog_run (GTK_DIALOG (dialog));
- printf ("debug: after run\n");
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ if (was_already_saved) {
+ /* Just show the dialog immediately: */
+ on_timeout_show_advanced_edit(self);
+ }
+ else
+ {
+ printf ("debug: waiting for gconf to update its local cache. "
+ "This is a hack to work around a maemo gconf bug in maemo bora.\n");
+
+ g_timeout_add (5000, on_timeout_show_advanced_edit, self);
+ }
}
static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
{
*/
if(!next_page) /* This is NULL when this is a click on Finish. */
{
- create_account (account_wizard);
+ if (account_wizard->saved_account_name) {
+ /* Just enable the already-saved account (temporarily created when
+ * editing advanced settings): */
+ modest_account_mgr_set_enabled (account_wizard->account_manager,
+ account_wizard->saved_account_name, TRUE);
+ } else {
+ create_account (account_wizard, TRUE /* enabled */);
+ }
}
enable_next = FALSE;
}
- /* Enable the buttons,
- * identifying them via their associated response codes:
- */
- GtkDialog *dialog_base = GTK_DIALOG (dialog);
- gtk_dialog_set_response_sensitive (dialog_base,
- MODEST_WIZARD_DIALOG_NEXT,
- enable_next);
-
+ /* Enable the buttons,
+ * identifying them via their associated response codes: */
+
/* Disable the Finish button until we are on the last page,
* because HildonWizardDialog enables this for all but the first page: */
GtkNotebook *notebook = NULL;
+ GtkDialog *dialog_base = GTK_DIALOG (dialog);
g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
gint current = gtk_notebook_get_current_page (notebook);
gint last = gtk_notebook_get_n_pages (notebook) - 1;
- gboolean is_last = (current == last);
+ const gboolean is_last = (current == last);
if(!is_last) {
gtk_dialog_set_response_sensitive (dialog_base,
MODEST_WIZARD_DIALOG_FINISH,
FALSE);
+ } else
+ {
+ /* Disable Next on the last page: */
+ enable_next = FALSE;
}
+
+ gtk_dialog_set_response_sensitive (dialog_base,
+ MODEST_WIZARD_DIALOG_NEXT,
+ enable_next);
}
static void
* @result: TRUE if the account was successfully created.
*/
gboolean
-create_account (ModestEasysetupWizardDialog *self)
+create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
{
ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
/* Sanity check: */
/* There must be at least one account now: */
- GSList *account_names = modest_account_mgr_account_names (self->account_manager);
+ /* Note, when this fails is is caused by a Maemo gconf bug that has been
+ * fixed in versions after 3.1. */
+ GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
if(!account_names)
{
g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
/* Create the account, which will contain the two "server accounts": */
created = modest_account_mgr_add_account (self->account_manager, account_name,
store_name, /* The name of our POP/IMAP server account. */
- transport_name /* The name of our SMTP server account. */);
+ transport_name, /* The name of our SMTP server account. */
+ enabled);
g_free (store_name);
g_free (transport_name);
/* Warn about unsaved changes: */
if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
- GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
- (GtkDialogFlags)0,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
- _("imum_nc_wizard_confirm_lose_changes") ));
+ GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
+ _("imum_nc_wizard_confirm_lose_changes")));
+ /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
const gint dialog_response = gtk_dialog_run (dialog);
gtk_widget_destroy (GTK_WIDGET (dialog));
prevent_response = TRUE;
}
/* Check for invalid input: */
- else if (!check_data (self)) {
+ else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
prevent_response = TRUE;
}
return;
}
-
if (response_id == GTK_RESPONSE_OK) {
/* Try to save the changes: */
const gboolean saved = save_configuration (self);
- if (saved)
- show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
+ if (saved) {
+ /* Do not show the account-saved dialog if we are just saving this
+ * temporarily, because from the user's point of view it will not
+ * really be saved (saved + enabled) until later.
+ */
+ const gboolean enabled =
+ modest_account_mgr_get_enabled (self->account_manager, self->account_name);
+ if (enabled)
+ show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
+ }
else
show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
}
static void
show_error (GtkWindow *parent_window, const gchar* text)
{
+ printf("debug: show_error\n");
GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
/*
GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
static void
show_ok (GtkWindow *parent_window, const gchar* text)
{
+ printf("debug: show_ok\n");
GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
/*
GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
GSList *cursor, *accounts;
account_mgr = modest_runtime_get_account_mgr();
- cursor = accounts = modest_account_mgr_account_names (account_mgr);
+ cursor = accounts = modest_account_mgr_account_names (account_mgr,
+ TRUE /* only enabled accounts. */);
while (cursor) {
gchar *account_name = (gchar*)cursor->data;
gchar *from_string = modest_account_mgr_get_from_string (account_mgr,
modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self)
{
gboolean result = FALSE;
- GSList *account_names = modest_account_mgr_account_names (self);
+ GSList *account_names = modest_account_mgr_account_names (self, TRUE /* only enabled */);
if(account_names)
{
const gchar* account_name = (const gchar*)account_names->data;
modest_account_mgr_add_account (ModestAccountMgr *self,
const gchar *name,
const gchar *store_account,
- const gchar *transport_account)
+ const gchar *transport_account,
+ gboolean enabled)
{
ModestAccountMgrPrivate *priv;
gchar *key;
return FALSE;
}
}
- modest_account_mgr_set_enabled (self, name, TRUE);
+ modest_account_mgr_set_enabled (self, name, enabled);
/* if no default account has been defined yet, do so now */
default_account = modest_account_mgr_get_default_account (self);
GSList*
-modest_account_mgr_account_names (ModestAccountMgr * self)
+modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled)
{
GSList *accounts;
ModestAccountMgrPrivate *priv;
}
strip_prefix_from_elements (accounts, prefix_len);
- return accounts;
+
+ GSList *result = NULL;
+
+ /* Filter-out the disabled accounts if requested: */
+ if (only_enabled) {
+ GSList *iter = accounts;
+ while (iter) {
+ if (!(iter->data))
+ continue;
+
+ const gchar* account_name = (const gchar*)iter->data;
+ if (account_name && modest_account_mgr_get_enabled (self, account_name))
+ result = g_slist_append (result, g_strdup (account_name));
+
+ iter = g_slist_next (iter);
+ }
+
+ /* TODO: Free the strings too? */
+ g_slist_free (accounts);
+ accounts = NULL;
+ }
+ else
+ result = accounts;
+
+
+ return result;
}
GSList *account_names = NULL;
GSList *cursor = NULL;
- cursor = account_names = modest_account_mgr_account_names (self);
+ cursor = account_names = modest_account_mgr_account_names (self,
+ TRUE /* enabled accounts, because disabled accounts are not user visible. */);
gboolean found = FALSE;
* @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
* @store_name: the store account (ie. POP/IMAP)
* @transport_name: the transport account (ie. sendmail/SMTP)
- * @err: a GError ptr, or NULL to ignore.
+ * @enabled: Whether the account should be enabled initially.
*
* Create a new account. The account with @name should not already exist. The @name will
* be used as the initial display name of the new account.
*
* Returns: TRUE if the creation succeeded, FALSE otherwise,
- * @err gives details in case of error
*/
gboolean modest_account_mgr_add_account (ModestAccountMgr *self,
const gchar* name,
const gchar* store_name,
- const gchar* transport_name);
+ const gchar* transport_name,
+ gboolean enabled);
/**
* modest_account_mgr_add_server_account:
/**
* modest_account_mgr_account_names:
* @self: a ModestAccountMgr instance
+ * @only_enabled: Whether only enabled accounts should be returned.
*
* list all account names
*
* because this is implemented via gconf_client_all_dirs() which also requires a deep free,
* though that's not documented. murrayc.
*/
-GSList* modest_account_mgr_account_names (ModestAccountMgr *self);
+GSList* modest_account_mgr_account_names (ModestAccountMgr *self,
+ gboolean only_enabled);
/**
}
-
+/* TODO: This is a duplicate of modest_account_mgr_set_first_account_as_default(). */
/**
* init_default_account_maybe:
*
gchar *default_account;
gboolean retval = TRUE;
- all_accounts = modest_account_mgr_account_names (acc_mgr);
+ all_accounts = modest_account_mgr_account_names (acc_mgr, TRUE /* enabled accounts only */);
if (all_accounts) { /* if there are any accounts, there should be a default one */
default_account =
modest_account_mgr_get_default_account (acc_mgr);
priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
- account_names = modest_account_mgr_account_names (priv->account_mgr);
+ account_names = modest_account_mgr_account_names (priv->account_mgr,
+ TRUE /* including disabled accounts */);
for (cursor = account_names; cursor; cursor = cursor->next) {
* because it requires a providers preset file which is not publically available.
*/
#ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
- GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr());
+ GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
+ TRUE /* enabled accounts only */);
gboolean accounts_exist = account_names != NULL;
g_slist_free (account_names);
-/* To test, while modest_account_mgr_account_names() is broken: accounts_exist = TRUE; */
if (!accounts_exist) {
/* If there are no accounts yet, just show the easy-setup wizard, as per the UI spec: */
ModestEasysetupWizardDialog *wizard = modest_easysetup_wizard_dialog_new ();
tny_device_is_online(modest_runtime_get_device()) ? "yes":"no");
/* TODO: Delete the item->data strings as well as the list? */
- GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr());
+ GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
+ TRUE /* enabled accounts only */);
GSList *iter = account_names;
while (iter) {
const gchar * account_name = (const char*) iter->data;
modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
{
/* Check that at least one account exists: */
- GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr());
+ GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
+ TRUE /* enabled accounts only */);
gboolean accounts_exist = account_names != NULL;
g_slist_free (account_names);
model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(view)));
gtk_list_store_clear (model);
- cursor = account_names = modest_account_mgr_account_names (account_mgr);
+ /* Note: We do not show disabled accounts.
+ * Of course, this means that there is no UI to enable or disable
+ * accounts. That is OK for maemo where no such feature or UI is
+ * specified, so the "enabled" property is used internally to avoid
+ * showing unfinished accounts. If a user-visible "enabled" is
+ * needed in the future, we must use a second property for the
+ * current use instead */
+ cursor = account_names = modest_account_mgr_account_names (account_mgr,
+ TRUE /* only enabled accounts. */);
if(account_names == NULL)
{
else
last_updated_string = g_strdup (_("Never"));
- gtk_list_store_insert_with_values (
- model, &iter, 0,
- MODEST_ACCOUNT_VIEW_NAME_COLUMN, account_name,
- MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, account_data->display_name,
- MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, account_data->is_enabled,
- MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, account_data->is_default,
-
- MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
- modest_protocol_info_get_protocol_name (account_data->store_account->proto),
-
- MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
- -1);
- g_free (last_updated_string);
+ if (account_data->is_enabled) {
+ gtk_list_store_insert_with_values (
+ model, &iter, 0,
+ MODEST_ACCOUNT_VIEW_NAME_COLUMN, account_name,
+ MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, account_data->display_name,
+ MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, account_data->is_enabled,
+ MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, account_data->is_default,
+
+ MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
+ modest_protocol_info_get_protocol_name (account_data->store_account->proto),
+
+ MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
+ -1);
+ g_free (last_updated_string);
+ }
}
modest_account_mgr_free_account_data (account_mgr, account_data);
result = modest_account_mgr_add_account (account_mgr,
name,
store_account,
- transport_account);
+ transport_account, TRUE);
fail_unless (result,
"modest_account_mgr_add_account failed:\n" \
"name: %s\nstore: %s\ntransport: %s\n",
- name, store_account, transport_account);
+ name, store_account, transport_account, TRUE);
g_free (store_account);
g_free (transport_account);
result = modest_account_mgr_add_account (NULL,
TEST_MODEST_ACCOUNT_NAME,
"store_account",
- "transport_account");
+ "transport_account", TRUE);
fail_unless (!result,
"modest_account_mgr_add_account does not return FALSE when" \
"passing a NULL ModestAccountMgr");
result = modest_account_mgr_add_account (account_mgr,
NULL,
"store_account",
- "transport_account");
+ "transport_account", TRUE);
fail_unless (!result,
"modest_account_mgr_add_account does not return FALSE when" \
"passing a NULL account name");
result = modest_account_mgr_add_account (account_mgr,
"ïnválid//accountñ//nÄméç",
"store_account",
- "transport_account");
+ "transport_account", TRUE);
fail_unless (!result,
"modest_account_mgr_add_account does not return FALSE when" \
"passing an invalid account name");