+2007-04-19 Murray Cumming <murrayc@murrayc.com>
+
+ * src/modest-account-mgr-helpers.h:
+ * src/modest-account-mgr-helpers.c:
+ (modest_account_mgr_get_unused_account_name),
+ (modest_account_mgr_get_unused_account_display_name): Added these
+ utility functions, to avoid code duplication.
+
+ * src/maemo/easysetup/modest-easysetup-wizard.c:
+ (create_page_account_details), (create_account):
+ * src/maemo/modest-connection-specific-smtp-edit-window.c:
+ (on_combo_security_changed),
+ (modest_connection_specific_smtp_edit_window_init),
+ (modest_connection_specific_smtp_edit_window_save_settings):
+ * src/maemo/modest-connection-specific-smtp-edit-window.h:
+ * src/maemo/modest-connection-specific-smtp-window.c:
+ (modest_connection_specific_smtp_window_finalize),
+ (modest_connection_specific_smtp_window_fill_with_connections),
+ (on_button_edit), (modest_connection_specific_smtp_window_init):
+ * src/maemo/modest-connection-specific-smtp-window.h:
+ Implementing saving of connection-specific server accounts.
+
+ But I need to refactor this so we can save the data for each
+ possible connection-specific account and only actually create the server accounts
+ when the easysetup finished, or the OK button is pressed on the account settings
+ dialog.
+
2007-04-18 Murray Cumming <murrayc@murrayc.com>
* src/maemo/modest-connection-specific-smtp-edit-window.c:
#include "maemo/easysetup/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>
static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
-static gchar*
-util_increment_name (const gchar* text);
-
static void
invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
{
/* 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_acount_name = g_strdup (_("mcen_ia_emailsetup_defaultname"));
- while (modest_account_mgr_account_with_display_name_exists (self->account_manager,
- default_acount_name)) {
-
- gchar * default_account_name2 = util_increment_name (default_acount_name);
- g_free (default_acount_name);
- default_acount_name = default_account_name2;
- }
+ 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_acount_name);
- g_free (default_acount_name);
- default_acount_name = 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);
}
}
+
static gchar*
util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
{
return g_strdup_printf ("%s.%s", hostname, domain);
}
-/* Add a number to the end of the text, or increment a number that is already there.
- */
-static gchar*
-util_increment_name (const gchar* text)
-{
- /* Get the end character,
- * also doing a UTF-8 validation which is required for using g_utf8_prev_char().
- */
- const gchar* end = NULL;
- if (!g_utf8_validate (text, -1, &end))
- return NULL;
-
- if (!end)
- return NULL;
-
- --end; /* Go to before the null-termination. */
-
- /* Look at each UTF-8 characer, starting at the end: */
- const gchar* p = end;
- const gchar* alpha_end = NULL;
- while (p)
- {
- /* Stop when we reach the first character that is not a numeric digit: */
- const gunichar ch = g_utf8_get_char (p);
- if (!g_unichar_isdigit (ch)) {
- alpha_end = p;
- break;
- }
-
- p = g_utf8_prev_char (p);
- }
-
- if(!alpha_end) {
- /* The text must consist completely of numeric digits. */
- alpha_end = text;
- }
- else
- ++alpha_end;
-
- /* Intepret and increment the number, if any: */
- gint num = atol (alpha_end);
- ++num;
-
- /* Get the name part: */
- gint name_len = alpha_end - text;
- gchar *name_without_number = g_malloc(name_len + 1);
- memcpy (name_without_number, text, name_len);
- name_without_number[name_len] = 0;\
-
- /* Concatenate the text part and the new number: */
- gchar *result = g_strdup_printf("%s%d", name_without_number, num);
- g_free (name_without_number);
-
- return result;
-}
-
static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
{
if (!account_wizard->entry_incomingserver)
/* Increment the non-user visible name if necessary,
* based on the display name: */
- gchar *account_name = g_strdup_printf ("%sID", display_name);
- while (modest_account_mgr_account_exists (self->account_manager,
- account_name, FALSE /* server_account */)) {
-
- gchar * account_name2 = util_increment_name (account_name);
- g_free (account_name);
- account_name = account_name2;
- }
+ 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));
* 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 = g_strconcat (account_name, "_store", NULL);
+ 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,
store_name,
servername_incoming,
}
/* Add a (outgoing) server account to be used by the account: */
- gchar *transport_name = g_strconcat (account_name, "_transport", NULL); /* What is this good for? */
+ 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,
transport_name,
servername_outgoing,
#include "maemo/easysetup/modest-easysetup-serversecurity-combo-box.h"
#include "maemo/easysetup/modest-easysetup-secureauth-combo-box.h"
#include "maemo/easysetup/modest-validating-entry.h"
+#include <modest-account-mgr-helpers.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkvbox.h>
{
ModestConnectionSpecificSmtpEditWindow *self =
MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
- ModestConnectionSpecificSmtpEditWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
-
+ ModestConnectionSpecificSmtpEditWindowPrivate *priv =
+ CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
const gint port_number =
easysetup_serversecurity_combo_box_get_active_serversecurity_port (
static void
modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
{
- ModestConnectionSpecificSmtpEditWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
+ ModestConnectionSpecificSmtpEditWindowPrivate *priv =
+ CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, 2); */
g_free (title);
}
+gboolean
+modest_connection_specific_smtp_edit_window_save_settings (
+ ModestConnectionSpecificSmtpEditWindow *window,
+ ModestAccountMgr *account_manager, const gchar* server_account_name)
+{
+ ModestConnectionSpecificSmtpEditWindowPrivate *priv =
+ CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
+
+ g_assert (server_account_name);
+
+ const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
+ gboolean test = modest_account_mgr_set_string (account_manager, server_account_name,
+ MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
+ if (!test)
+ return FALSE;
+
+ const gchar* username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
+ test = modest_account_mgr_set_string (account_manager, server_account_name,
+ MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
+ if (!test)
+ return FALSE;
+
+ const gchar* password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
+ test = modest_account_mgr_set_string (account_manager, server_account_name,
+ MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
+ if (!test)
+ return FALSE;
+
+ const ModestProtocol protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
+ EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
+ modest_server_account_set_security (account_manager, server_account_name, protocol_security_outgoing);
+
+ const ModestProtocol protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
+ EASYSETUP_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
+ modest_server_account_set_secure_auth (account_manager, server_account_name, protocol_authentication_outgoing);
+
+ /* port: */
+ const gchar * port_str = gtk_entry_get_text (GTK_ENTRY (priv->entry_port));
+ gint port_num = 0;
+ if (port_str)
+ port_num = atoi (port_str);
+ modest_account_mgr_set_int (account_manager, server_account_name,
+ MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
+
+ return TRUE;
+}
#ifndef __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW
#define __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW
+#include <modest-account-mgr.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtktreeview.h>
void modest_connection_specific_smtp_edit_window_set_connection (
ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name);
+gboolean modest_connection_specific_smtp_edit_window_save_settings (
+ ModestConnectionSpecificSmtpEditWindow *window,
+ ModestAccountMgr *account_manager, const gchar* server_account_name);
+
+
G_END_DECLS
#endif /* __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_WINDOW */
#include "modest-connection-specific-smtp-window.h"
#include "modest-connection-specific-smtp-edit-window.h"
+#include <modest-account-mgr-helpers.h>
#include <modest-runtime.h>
#include <tny-maemo-conic-device.h>
{
GtkTreeView *treeview;
GtkTreeModel *model;
+
+ ModestAccountMgr *account_manager;
+ gchar* account_name;
};
static void
ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object);
g_object_unref (G_OBJECT (priv->model));
+ g_free (priv->account_name);
G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object);
}
enum MODEL_COLS {
MODEL_COL_NAME = 0, /* libconic IAP Name: a string */
- MODEL_COL_SERVER_NAME = 1, /* a string */
- MODEL_COL_ID = 2 /* libconic IAP ID: a string */
+ MODEL_COL_ID = 1, /* libconic IAP ID: a string */
+ MODEL_COL_SERVER_ACCOUNT_NAME = 2, /* a string */
+ MODEL_COL_SERVER_NAME = 3 /* a string */
};
-static void
-fill_with_connections (ModestConnectionSpecificSmtpWindow *self)
+void
+modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self, ModestAccountMgr *account_manager,
+ const gchar* account_name)
{
- printf("debug: fill_with_connections()\n");
ModestConnectionSpecificSmtpWindowPrivate *priv =
CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
+ priv->account_manager = account_manager;
+ priv->account_name = g_strdup (account_name);
+
GtkListStore *liststore = GTK_LIST_STORE (priv->model);
TnyDevice *device = modest_runtime_get_device ();
ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
gchar *id = NULL;
- gchar *name = NULL;
+ gchar *connection_name = NULL;
+ gchar *server_account_name = NULL;
GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
GtkTreeIter iter;
GtkTreeModel *model = 0;
if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
gtk_tree_model_get (priv->model, &iter,
MODEL_COL_ID, &id,
- MODEL_COL_NAME, &name,
+ MODEL_COL_NAME, &connection_name,
+ MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
-1);
/* TODO: Is 0 an allowed libconic IAP ID?
GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ());
modest_connection_specific_smtp_edit_window_set_connection (
- MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, name);
+ MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name);
gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
gint response = gtk_dialog_run (GTK_DIALOG (window));
gtk_widget_hide (window);
+
if (response == GTK_RESPONSE_OK) {
-
+ if (server_account_name) {
+ /* Change the existing server account. */
+ modest_connection_specific_smtp_edit_window_save_settings (
+ MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window),
+ priv->account_manager, server_account_name);
+ } else {
+ /* Add a new server account, building a (non-human-visible) name: */
+ gchar *name_start = g_strdup_printf("%s_specific_%s",
+ priv->account_name, connection_name);
+ server_account_name = modest_account_mgr_get_unused_account_name (
+ priv->account_manager, name_start, TRUE /* server account. */);
+ g_free (name_start);
+
+ modest_connection_specific_smtp_edit_window_save_settings (
+ MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window),
+ priv->account_manager, server_account_name);
+
+ /* Store it in the model so it can be edited again: */
+ gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
+ MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name,
+ -1);
+ }
}
}
+
+ g_free (connection_name);
+ g_free (id);
+ g_free (server_account_name);
}
static void
* with a string for the name, a string for the server name, and an int for the ID.
* This must match our MODEL_COLS enum constants.
*/
- priv->model = GTK_TREE_MODEL (gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
+ priv->model = GTK_TREE_MODEL (gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
/* Setup the tree view: */
priv->treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model (priv->model));
gtk_tree_view_column_set_title (view_column, _("mcen_ia_optionalsmtp_servername"));
gtk_tree_view_append_column (priv->treeview, view_column);
- /* Fill the model with rows: */
- fill_with_connections (self);
+ /* The application must call modest_connection_specific_smtp_window_fill_with_connections(). */
GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
#ifndef __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_WINDOW
#define __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_WINDOW
+#include <modest-account-mgr.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtktreeview.h>
ModestConnectionSpecificSmtpWindow* modest_connection_specific_smtp_window_new (void);
+void
+modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self,
+ ModestAccountMgr *account_manager, const gchar* account_name);
+
G_END_DECLS
#endif /* __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_WINDOW */
return from;
}
+
+/* Add a number to the end of the text, or increment a number that is already there.
+ */
+static gchar*
+util_increment_name (const gchar* text)
+{
+ /* Get the end character,
+ * also doing a UTF-8 validation which is required for using g_utf8_prev_char().
+ */
+ const gchar* end = NULL;
+ if (!g_utf8_validate (text, -1, &end))
+ return NULL;
+
+ if (!end)
+ return NULL;
+
+ --end; /* Go to before the null-termination. */
+
+ /* Look at each UTF-8 characer, starting at the end: */
+ const gchar* p = end;
+ const gchar* alpha_end = NULL;
+ while (p)
+ {
+ /* Stop when we reach the first character that is not a numeric digit: */
+ const gunichar ch = g_utf8_get_char (p);
+ if (!g_unichar_isdigit (ch)) {
+ alpha_end = p;
+ break;
+ }
+
+ p = g_utf8_prev_char (p);
+ }
+
+ if(!alpha_end) {
+ /* The text must consist completely of numeric digits. */
+ alpha_end = text;
+ }
+ else
+ ++alpha_end;
+
+ /* Intepret and increment the number, if any: */
+ gint num = atol (alpha_end);
+ ++num;
+
+ /* Get the name part: */
+ gint name_len = alpha_end - text;
+ gchar *name_without_number = g_malloc(name_len + 1);
+ memcpy (name_without_number, text, name_len);
+ name_without_number[name_len] = 0;\
+
+ /* Concatenate the text part and the new number: */
+ gchar *result = g_strdup_printf("%s%d", name_without_number, num);
+ g_free (name_without_number);
+
+ return result;
+}
+
+gchar*
+modest_account_mgr_get_unused_account_name (ModestAccountMgr *self, const gchar* starting_name,
+ gboolean server_account)
+{
+ gchar *account_name = g_strdup (starting_name);
+
+ while (modest_account_mgr_account_exists (self,
+ account_name, server_account /* server_account */)) {
+
+ gchar * account_name2 = util_increment_name (account_name);
+ g_free (account_name);
+ account_name = account_name2;
+ }
+
+ return account_name;
+}
+
+gchar*
+modest_account_mgr_get_unused_account_display_name (ModestAccountMgr *self, const gchar* starting_name)
+{
+ gchar *account_name = g_strdup (starting_name);
+
+ while (modest_account_mgr_account_with_display_name_exists (self, account_name)) {
+
+ gchar * account_name2 = util_increment_name (account_name);
+ g_free (account_name);
+ account_name = account_name2;
+ }
+
+ return account_name;
+}
gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name);
+/**
+ * modest_account_mgr_get_unused_account_name
+ * @self: a #ModestAccountMgr instance
+ * @name: The initial account name
+ *
+ * get an unused account name, based on a starting string.
+ *
+ * Returns: the newly allocated name.
+ */
+gchar*
+modest_account_mgr_get_unused_account_name (ModestAccountMgr *self, const gchar* starting_name,
+ gboolean server_account);
+
+/**
+ * modest_account_mgr_get_unused_account_display name
+ * @self: a #ModestAccountMgr instance
+ * @name: The initial account display name
+ *
+ * get an unused account display name, based on a starting string.
+ *
+ * Returns: the newly allocated name.
+ */
+gchar*
+modest_account_mgr_get_unused_account_display_name (ModestAccountMgr *self, const gchar* starting_name);
+
G_END_DECLS
#endif /* __MODEST_ACCOUNT_MGR_H__ */