#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkmessagedialog.h>
#include <hildon-widgets/hildon-caption.h>
-#include "modest-easysetup-country-combo-box.h"
-#include "modest-easysetup-provider-combo-box.h"
-#include "modest-easysetup-servertype-combo-box.h"
-#include "modest-easysetup-serversecurity-combo-box.h"
-#include "modest-easysetup-secureauth-combo-box.h"
-#include "modest-validating-entry.h"
+#include "maemo/easysetup/modest-easysetup-country-combo-box.h"
+#include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
+#include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
+#include "widgets/modest-easysetup-serversecurity-combo-box.h"
+#include "widgets/modest-easysetup-secureauth-combo-box.h"
+#include "widgets/modest-validating-entry.h"
#include "modest-text-utils.h"
#include "modest-account-mgr.h"
+#include "modest-account-mgr-helpers.h"
#include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
+#include "maemo/modest-connection-specific-smtp-window.h"
#include <gconf/gconf-client.h>
#include <string.h> /* For strlen(). */
if (priv->presets)
modest_presets_destroy (priv->presets);
+
+ if (self->specific_window)
+ gtk_widget_destroy (self->specific_window);
G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
}
static void
set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
+static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
+
static void
invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
{
/* The description widgets: */
self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
- gtk_entry_set_text( GTK_ENTRY (self->entry_account_title),
- _("mcen_ia_emailsetup_defaultname")); /* default description. */
- /* TODO: Check if an account with this default name exists, and increment if necessary. */
-
+
+ /* Set a default account title, choosing one that does not already exist: */
+ /* Note that this is irrelevant to the non-user visible name, which we will create later. */
+ gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
+ gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
+ self->account_manager, default_account_name_start);
+ g_free (default_account_name_start);
+ default_account_name_start = NULL;
+
+ gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
+ g_free (default_account_name);
+ default_account_name = NULL;
+
caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
gtk_widget_show (self->entry_account_title);
EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
}
-void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
+static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
{
ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
update_incoming_server_title (self);
/* Set the starting sensitivity: */
on_toggle_button_changed (button, widget);
}
-
+
+static void
+on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
+{
+ ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
+
+ /* Create the window, if necessary: */
+ if (!(self->specific_window)) {
+ self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
+ modest_connection_specific_smtp_window_fill_with_connections (
+ MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
+ NULL /* account_name, not known yet. */);
+ }
+
+ /* Show the window: */
+ gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
+ gtk_widget_show (self->specific_window);
+}
+
static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
{
GtkWidget *box = gtk_vbox_new (FALSE, 2);
/* Only enable the button when the checkbox is checked: */
enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
+
+ g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
+ G_CALLBACK (on_button_outgoing_smtp_servers), self);
gtk_widget_show (GTK_WIDGET (box));
/* Read in the information about known service providers: */
ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
- const gchar* filepath = "/usr/share/operator-wizard/provider-data.keyfile";
- priv->presets = modest_presets_new (filepath); /* TODO: the actual filepath. */
- if (!(priv->presets))
- {
- const gchar* filepath_hack = "./src/maemo/easysetup/provider-data-test.keyfile";
- g_warning ("Could not locate the official provider data keyfile from %s, "
- "so attempting to load it instead from %s", filepath, filepath_hack);
- priv->presets = modest_presets_new (filepath_hack); /* TODO: the actual filepath. */
+ const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
+ priv->presets = modest_presets_new (filepath);
+ if (!(priv->presets)) {
+ g_warning ("Could not locate the official provider data keyfile from %s", filepath);
}
g_assert(priv->presets);
* and create new accounts: */
self->account_manager = modest_runtime_get_account_mgr ();
g_assert (self->account_manager);
+ g_object_ref (self->account_manager);
/* Create the common pages,
*/
}
}
-gchar*
+
+static gchar*
util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
{
if (!email_address)
static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
{
+ if (!account_wizard->entry_incomingserver)
+ return;
+
/* Set a default domain for the server, based on the email address,
* if no server name was already specified.
*/
const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
- gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), util_get_default_servername_from_email_address (email_address, protocol));
+
+ gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
+ gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
+ g_free (servername);
}
/* Set a default domain for the server, based on the email address,
if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
&& account_wizard->entry_user_email) {
const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
- gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP));
+
+ gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
+ gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
+ g_free (servername);
}
}
*/
if (current_page == account_wizard->page_account_details) {
/* Check that the title is not already in use: */
- const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
- if ((!account_name) || (strlen(account_name) == 0))
+ const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
+ if ((!account_title) || (strlen(account_title) == 0))
return FALSE;
- gboolean name_in_use = FALSE;
- name_in_use = modest_account_mgr_account_exists (account_wizard->account_manager,
- account_name, TRUE /* server_account */);
-
+ /* Aavoid a clash with an existing display name: */
+ const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
+ account_wizard->account_manager, account_title);
+
if (name_in_use) {
/* Warn the user via a dialog: */
- /* TODO: The UI spec says we should increment the title,
- * as well as warning. This seems contradictory.
- */
- show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing."));
+ show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
return FALSE;
}
{
ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
- const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
+ const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
/* Some checks: */
- if (!account_name)
+ if (!display_name)
return FALSE;
/* We should have checked for this already,
* and changed that name accordingly,
* but let's check again just in case:
*/
- if (modest_account_mgr_account_exists (self->account_manager, account_name, FALSE))
+ if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
return FALSE;
+
+ /* Increment the non-user visible name if necessary,
+ * based on the display name: */
+ gchar *account_name_start = g_strdup_printf ("%sID", display_name);
+ gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
+ account_name_start, FALSE /* not a server account */);
+ g_free (account_name_start);
/* username and password (for both incoming and outgoing): */
const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
}
+ /* First we add the 2 server accounts, and then we add the account that uses them.
+ * If we don't do it in this order then we will experience a crash. */
+
+ /* Add a (incoming) server account, to be used by the account: */
+ gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
+ gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
+ store_name_start, TRUE /* server account */);
+ g_free (store_name_start);
gboolean created = modest_account_mgr_add_server_account (self->account_manager,
- account_name,
+ store_name,
servername_incoming,
username, password,
protocol_incoming,
return FALSE;
}
+ /* Sanity check: */
+ /* There must be at least one account now: */
+ GSList *account_names = modest_account_mgr_account_names (self->account_manager);
+ if(!account_names)
+ {
+ g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
+ }
+ g_slist_free (account_names);
+
+
/* Outgoing server: */
gchar* servername_outgoing = NULL;
ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
+ /* TODO:
gboolean specific = gtk_toggle_button_get_active (
GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
+ */
}
+ /* Add a (outgoing) server account to be used by the account: */
+ gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
+ gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
+ transport_name_start, TRUE /* server account */);
+ g_free (transport_name_start);
created = modest_account_mgr_add_server_account (self->account_manager,
- account_name,
+ transport_name,
servername_outgoing,
username, password,
protocol_outgoing,
/* TODO: Provide a Logical ID for the text: */
show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
return FALSE;
- }
+ }
+
+
+ /* 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. */);
+ g_free (store_name);
+ g_free (transport_name);
+
+ if (!created) {
+ /* TODO: Provide a Logical ID for the text: */
+ show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
+ return FALSE;
+ }
+ /* The user name and email address must be set additionally: */
+ const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
+ modest_account_mgr_set_string (self->account_manager, account_name,
+ MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
+
+ const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
+ modest_account_mgr_set_string (self->account_manager, account_name,
+ MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
+
+ /* Set the display name: */
+ modest_account_mgr_set_string (self->account_manager, account_name,
+ MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
+
+ /* Save the connection-specific SMTP server accounts. */
+ if (self->specific_window)
+ return modest_connection_specific_smtp_window_save_server_accounts (
+ MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
+
+ g_free (account_name);
+
return FALSE;
}