From 7e7be75d6f353df4d1c605d5df3011457f51a926 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Fri, 20 Apr 2007 10:30:11 +0000 Subject: [PATCH] 2007-04-20 Murray Cumming * src/maemo/easysetup/Makefile.am: * src/maemo/easysetup/modest-easysetup-secureauth-combo-box.c: * src/maemo/easysetup/modest-easysetup-secureauth-combo-box.h: * src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c: * src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h: * src/maemo/easysetup/modest-easysetup-wizard.c: * src/maemo/easysetup/modest-validating-entry.c: * src/maemo/easysetup/modest-validating-entry.h: * src/maemo/modest-account-settings-dialog.c: * src/maemo/modest-connection-specific-smtp-edit-window.c: * src/widgets/Makefile.am: Moved these widgets from maemo/easysetup into widgets/ because they are used outside of easysetup too. After checking in, svn will allow me to rename them too. pmo-trunk-r1609 --- ChangeLog2 | 16 ++ src/maemo/easysetup/Makefile.am | 5 +- .../modest-easysetup-secureauth-combo-box.c | 219 ---------------- .../modest-easysetup-secureauth-combo-box.h | 55 ---- .../modest-easysetup-serversecurity-combo-box.c | 270 -------------------- .../modest-easysetup-serversecurity-combo-box.h | 59 ----- src/maemo/easysetup/modest-easysetup-wizard.c | 6 +- src/maemo/easysetup/modest-validating-entry.c | 210 --------------- src/maemo/easysetup/modest-validating-entry.h | 52 ---- src/maemo/modest-account-settings-dialog.c | 6 +- .../modest-connection-specific-smtp-edit-window.c | 6 +- src/widgets/Makefile.am | 3 + .../modest-easysetup-secureauth-combo-box.c | 219 ++++++++++++++++ .../modest-easysetup-secureauth-combo-box.h | 55 ++++ .../modest-easysetup-serversecurity-combo-box.c | 270 ++++++++++++++++++++ .../modest-easysetup-serversecurity-combo-box.h | 59 +++++ src/widgets/modest-validating-entry.c | 210 +++++++++++++++ src/widgets/modest-validating-entry.h | 52 ++++ 18 files changed, 894 insertions(+), 878 deletions(-) delete mode 100644 src/maemo/easysetup/modest-easysetup-secureauth-combo-box.c delete mode 100644 src/maemo/easysetup/modest-easysetup-secureauth-combo-box.h delete mode 100644 src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c delete mode 100644 src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h delete mode 100644 src/maemo/easysetup/modest-validating-entry.c delete mode 100644 src/maemo/easysetup/modest-validating-entry.h create mode 100644 src/widgets/modest-easysetup-secureauth-combo-box.c create mode 100644 src/widgets/modest-easysetup-secureauth-combo-box.h create mode 100644 src/widgets/modest-easysetup-serversecurity-combo-box.c create mode 100644 src/widgets/modest-easysetup-serversecurity-combo-box.h create mode 100644 src/widgets/modest-validating-entry.c create mode 100644 src/widgets/modest-validating-entry.h diff --git a/ChangeLog2 b/ChangeLog2 index 0252930..d376b40 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,21 @@ 2007-04-20 Murray Cumming + * src/maemo/easysetup/Makefile.am: + * src/maemo/easysetup/modest-easysetup-secureauth-combo-box.c: + * src/maemo/easysetup/modest-easysetup-secureauth-combo-box.h: + * src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c: + * src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h: + * src/maemo/easysetup/modest-easysetup-wizard.c: + * src/maemo/easysetup/modest-validating-entry.c: + * src/maemo/easysetup/modest-validating-entry.h: + * src/maemo/modest-account-settings-dialog.c: + * src/maemo/modest-connection-specific-smtp-edit-window.c: + * src/widgets/Makefile.am: Moved these widgets from maemo/easysetup into + widgets/ because they are used outside of easysetup too. After checking in, + svn will allow me to rename them too. + +2007-04-20 Murray Cumming + * src/gnome/modest-msg-edit-window.c: (modest_msg_edit_window_set_priority_flags): Added an empty implementation to fix a linker error, to fix the build on the GNOME platform. diff --git a/src/maemo/easysetup/Makefile.am b/src/maemo/easysetup/Makefile.am index d784f71..7da26fb 100644 --- a/src/maemo/easysetup/Makefile.am +++ b/src/maemo/easysetup/Makefile.am @@ -51,10 +51,7 @@ libmodest_easysetup_la_SOURCES= \ modest-easysetup-wizard.h modest-easysetup-wizard.c \ modest-easysetup-country-combo-box.h modest-easysetup-country-combo-box.c \ modest-easysetup-provider-combo-box.h modest-easysetup-provider-combo-box.c \ - modest-easysetup-servertype-combo-box.h modest-easysetup-servertype-combo-box.c \ - modest-easysetup-serversecurity-combo-box.h modest-easysetup-serversecurity-combo-box.c \ - modest-easysetup-secureauth-combo-box.h modest-easysetup-secureauth-combo-box.c \ - modest-validating-entry.h modest-validating-entry.c + modest-easysetup-servertype-combo-box.h modest-easysetup-servertype-combo-box.c LDADD = \ $(MODEST_GSTUFF_LIBS) \ diff --git a/src/maemo/easysetup/modest-easysetup-secureauth-combo-box.c b/src/maemo/easysetup/modest-easysetup-secureauth-combo-box.c deleted file mode 100644 index c900094..0000000 --- a/src/maemo/easysetup/modest-easysetup-secureauth-combo-box.c +++ /dev/null @@ -1,219 +0,0 @@ -/* Copyright (c) 2007, Nokia Corporation - * All rights reserved. - * - */ - -#include "modest-easysetup-secureauth-combo-box.h" -#include -#include -#include -#include - -#include -#include /* For memcpy() */ - -/* Include config.h so that _() works: */ -#ifdef HAVE_CONFIG_H -#include -#endif - -G_DEFINE_TYPE (EasysetupSecureauthComboBox, easysetup_secureauth_combo_box, GTK_TYPE_COMBO_BOX); - -#define SECUREAUTH_COMBO_BOX_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBoxPrivate)) - -typedef struct _EasysetupSecureauthComboBoxPrivate EasysetupSecureauthComboBoxPrivate; - -struct _EasysetupSecureauthComboBoxPrivate -{ - GtkTreeModel *model; -}; - -static void -easysetup_secureauth_combo_box_get_property (GObject *object, guint property_id, - GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_secureauth_combo_box_set_property (GObject *object, guint property_id, - const GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_secureauth_combo_box_dispose (GObject *object) -{ - if (G_OBJECT_CLASS (easysetup_secureauth_combo_box_parent_class)->dispose) - G_OBJECT_CLASS (easysetup_secureauth_combo_box_parent_class)->dispose (object); -} - -static void -easysetup_secureauth_combo_box_finalize (GObject *object) -{ - EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (object); - - g_object_unref (G_OBJECT (priv->model)); - - G_OBJECT_CLASS (easysetup_secureauth_combo_box_parent_class)->finalize (object); -} - -static void -easysetup_secureauth_combo_box_class_init (EasysetupSecureauthComboBoxClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (EasysetupSecureauthComboBoxPrivate)); - - object_class->get_property = easysetup_secureauth_combo_box_get_property; - object_class->set_property = easysetup_secureauth_combo_box_set_property; - object_class->dispose = easysetup_secureauth_combo_box_dispose; - object_class->finalize = easysetup_secureauth_combo_box_finalize; -} - -enum MODEL_COLS { - MODEL_COL_NAME = 0, /* a string */ - MODEL_COL_ID = 1 /* an int. */ -}; - -void easysetup_secureauth_combo_box_fill (EasysetupSecureauthComboBox *combobox); - -static void -easysetup_secureauth_combo_box_init (EasysetupSecureauthComboBox *self) -{ - EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (self); - - /* Create a tree model for the combo box, - * with a string for the name, and an ID for the secureauth. - * This must match our MODEL_COLS enum constants. - */ - priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT)); - - /* Setup the combo box: */ - GtkComboBox *combobox = GTK_COMBO_BOX (self); - gtk_combo_box_set_model (combobox, priv->model); - - /* Secureauth column: - * The ID model column in not shown in the view. */ - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combobox), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, - "text", MODEL_COL_NAME, NULL); - - easysetup_secureauth_combo_box_fill (self); -} - -EasysetupSecureauthComboBox* -easysetup_secureauth_combo_box_new (void) -{ - return g_object_new (EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, NULL); -} - -/* Fill the combo box with appropriate choices. - * #combobox: The combo box. - * @protocol: IMAP or POP. - */ -void easysetup_secureauth_combo_box_fill (EasysetupSecureauthComboBox *combobox) -{ - EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (combobox); - - /* Remove any existing rows: */ - GtkListStore *liststore = GTK_LIST_STORE (priv->model); - gtk_list_store_clear (liststore); - - GtkTreeIter iter; - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_AUTH_NONE, MODEL_COL_NAME, _("mcen_fi_advsetup_smtp_none"), -1); - - /* Select the None item: */ - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter); - - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_AUTH_PASSWORD, MODEL_COL_NAME, _("mcen_fi_advsetup_smtp_login"), -1); - - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_AUTH_CRAMMD5, MODEL_COL_NAME, _("mcen_fi_advsetup_smtp_cram_md5"), -1); -} - -/** - * Returns the selected secureauth, - * or MODEST_PROTOCOL_UNKNOWN if no secureauth was selected. - */ -ModestProtocol -easysetup_secureauth_combo_box_get_active_secureauth (EasysetupSecureauthComboBox *combobox) -{ - GtkTreeIter active; - const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active); - if (found) { - EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (combobox); - - ModestProtocol secureauth = MODEST_PROTOCOL_UNKNOWN; - gtk_tree_model_get (priv->model, &active, MODEL_COL_ID, &secureauth, -1); - return secureauth; - } - - return MODEST_PROTOCOL_UNKNOWN; /* Failed. */ -} - -/* This allows us to pass more than one piece of data to the signal handler, - * and get a result: */ -typedef struct -{ - EasysetupSecureauthComboBox* self; - gint id; - gboolean found; -} ForEachData; - -static gboolean -on_model_foreach_select_id(GtkTreeModel *model, - GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) -{ - ForEachData *state = (ForEachData*)(user_data); - - /* Select the item if it has the matching ID: */ - guint id = 0; - gtk_tree_model_get (model, iter, MODEL_COL_ID, &id, -1); - if(id == state->id) { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter); - - state->found = TRUE; - return TRUE; /* Stop walking the tree. */ - } - - return FALSE; /* Keep walking the tree. */ -} - -/** - * Selects the specified secureauth, - * or MODEST_PROTOCOL_UNKNOWN if no secureauth was selected. - */ -gboolean -easysetup_secureauth_combo_box_set_active_secureauth (EasysetupSecureauthComboBox *combobox, ModestProtocol secureauth) -{ - EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (combobox); - - /* Create a state instance so we can send two items of data to the signal handler: */ - ForEachData *state = g_new0 (ForEachData, 1); - state->self = combobox; - state->id = secureauth; - state->found = FALSE; - - /* Look at each item, and select the one with the correct ID: */ - gtk_tree_model_foreach (priv->model, &on_model_foreach_select_id, state); - - const gboolean result = state->found; - - /* Free the state instance: */ - g_free(state); - - return result; -} - diff --git a/src/maemo/easysetup/modest-easysetup-secureauth-combo-box.h b/src/maemo/easysetup/modest-easysetup-secureauth-combo-box.h deleted file mode 100644 index 0a151cf..0000000 --- a/src/maemo/easysetup/modest-easysetup-secureauth-combo-box.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (c) 2007, Nokia Corporation - * All rights reserved. - * - */ - -#ifndef _EASYSETUP_SECUREAUTH_COMBO_BOX -#define _EASYSETUP_SECUREAUTH_COMBO_BOX - -#include -#include "modest-protocol-info.h" - -G_BEGIN_DECLS - -#define EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX easysetup_secureauth_combo_box_get_type() - -#define EASYSETUP_SECUREAUTH_COMBO_BOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBox)) - -#define EASYSETUP_SECUREAUTH_COMBO_BOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBoxClass)) - -#define EASYSETUP_IS_SECUREAUTH_COMBO_BOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX)) - -#define EASYSETUP_IS_SECUREAUTH_COMBO_BOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX)) - -#define EASYSETUP_SECUREAUTH_COMBO_BOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBoxClass)) - -typedef struct { - GtkComboBox parent; -} EasysetupSecureauthComboBox; - -typedef struct { - GtkComboBoxClass parent_class; -} EasysetupSecureauthComboBoxClass; - -GType easysetup_secureauth_combo_box_get_type (void); - -EasysetupSecureauthComboBox* easysetup_secureauth_combo_box_new (void); - -ModestProtocol easysetup_secureauth_combo_box_get_active_secureauth (EasysetupSecureauthComboBox *combobox); - -gboolean easysetup_secureauth_combo_box_set_active_secureauth (EasysetupSecureauthComboBox *combobox, ModestProtocol secureauth); - - -G_END_DECLS - -#endif /* _EASYSETUP_PROVIDER_COMBO_BOX */ diff --git a/src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c b/src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c deleted file mode 100644 index a85f680..0000000 --- a/src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c +++ /dev/null @@ -1,270 +0,0 @@ -/* Copyright (c) 2007, Nokia Corporation - * All rights reserved. - * - */ - -#include "modest-easysetup-serversecurity-combo-box.h" -#include -#include -#include -#include - -#include -#include /* For memcpy() */ - -/* Include config.h so that _() works: */ -#ifdef HAVE_CONFIG_H -#include -#endif - -G_DEFINE_TYPE (EasysetupServersecurityComboBox, easysetup_serversecurity_combo_box, GTK_TYPE_COMBO_BOX); - -#define SERVERSECURITY_COMBO_BOX_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBoxPrivate)) - -typedef struct _EasysetupServersecurityComboBoxPrivate EasysetupServersecurityComboBoxPrivate; - -struct _EasysetupServersecurityComboBoxPrivate -{ - GtkTreeModel *model; - ModestProtocol protocol; -}; - -static void -easysetup_serversecurity_combo_box_get_property (GObject *object, guint property_id, - GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_serversecurity_combo_box_set_property (GObject *object, guint property_id, - const GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_serversecurity_combo_box_dispose (GObject *object) -{ - if (G_OBJECT_CLASS (easysetup_serversecurity_combo_box_parent_class)->dispose) - G_OBJECT_CLASS (easysetup_serversecurity_combo_box_parent_class)->dispose (object); -} - -static void -easysetup_serversecurity_combo_box_finalize (GObject *object) -{ - EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (object); - - g_object_unref (G_OBJECT (priv->model)); - - G_OBJECT_CLASS (easysetup_serversecurity_combo_box_parent_class)->finalize (object); -} - -static void -easysetup_serversecurity_combo_box_class_init (EasysetupServersecurityComboBoxClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (EasysetupServersecurityComboBoxPrivate)); - - object_class->get_property = easysetup_serversecurity_combo_box_get_property; - object_class->set_property = easysetup_serversecurity_combo_box_set_property; - object_class->dispose = easysetup_serversecurity_combo_box_dispose; - object_class->finalize = easysetup_serversecurity_combo_box_finalize; -} - -enum MODEL_COLS { - MODEL_COL_NAME = 0, /* a string */ - MODEL_COL_ID = 1 /* an int. */ -}; - -static void -easysetup_serversecurity_combo_box_init (EasysetupServersecurityComboBox *self) -{ - EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (self); - - /* Create a tree model for the combo box, - * with a string for the name, and an ID for the serversecurity. - * This must match our MODEL_COLS enum constants. - */ - priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT)); - - /* Setup the combo box: */ - GtkComboBox *combobox = GTK_COMBO_BOX (self); - gtk_combo_box_set_model (combobox, priv->model); - - /* Serversecurity column: - * The ID model column in not shown in the view. */ - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combobox), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, - "text", MODEL_COL_NAME, NULL); - - /* The application must call easysetup_serversecurity_combo_box_fill(). - */ -} - -EasysetupServersecurityComboBox* -easysetup_serversecurity_combo_box_new (void) -{ - return g_object_new (EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, NULL); -} - -/* Fill the combo box with appropriate choices. - * #combobox: The combo box. - * @protocol: IMAP or POP. - */ -void easysetup_serversecurity_combo_box_fill (EasysetupServersecurityComboBox *combobox, ModestProtocol protocol) -{ - EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); - priv->protocol = protocol; /* Remembered for later. */ - - /* Remove any existing rows: */ - GtkListStore *liststore = GTK_LIST_STORE (priv->model); - gtk_list_store_clear (liststore); - - GtkTreeIter iter; - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_NONE, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_none"), -1); - - /* Select the None item: */ - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter); - - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_TLS, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_normal"), -1); - - /* Add security choices with protocol-specific names, as in the UI spec: - * (Note: Changing the title seems pointless. murrayc) */ - if(protocol == MODEST_PROTOCOL_STORE_POP) { - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_SSL, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_securepop3s"), -1); - } else if(protocol == MODEST_PROTOCOL_STORE_IMAP) { - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_SSL, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_secureimap4"), -1); - } else if(protocol == MODEST_PROTOCOL_TRANSPORT_SMTP) { - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_SSL, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_ssl"), -1); - } -} - -static gint get_port_for_security (ModestProtocol protocol, ModestProtocol security) -{ - /* See the UI spec, section Email Wizards, Incoming Details [MSG-WIZ001]: */ - gint result = 0; - - /* Get the default port number for this protocol with this security: */ - if(protocol == MODEST_PROTOCOL_STORE_POP) { - if ((security == MODEST_PROTOCOL_SECURITY_NONE) || (security == MODEST_PROTOCOL_SECURITY_TLS)) - result = 110; - else if (security == MODEST_PROTOCOL_SECURITY_SSL) - result = 995; - } else if (protocol == MODEST_PROTOCOL_STORE_IMAP) { - if ((security == MODEST_PROTOCOL_SECURITY_NONE) || (security == MODEST_PROTOCOL_SECURITY_TLS)) - result = 143; - else if (security == MODEST_PROTOCOL_SECURITY_SSL) - result = 993; - } else if (protocol == MODEST_PROTOCOL_TRANSPORT_SMTP) { - if ((security == MODEST_PROTOCOL_SECURITY_NONE) || (security == MODEST_PROTOCOL_SECURITY_TLS)) - result = 25; - else if (security == MODEST_PROTOCOL_SECURITY_SSL) - result = 465; - } - - return result; -} - -/** - * Returns the selected serversecurity, - * or MODEST_PROTOCOL_UNKNOWN if no serversecurity was selected. - */ -ModestProtocol -easysetup_serversecurity_combo_box_get_active_serversecurity (EasysetupServersecurityComboBox *combobox) -{ - GtkTreeIter active; - const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active); - if (found) { - EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); - - ModestProtocol serversecurity = MODEST_PROTOCOL_UNKNOWN; - gtk_tree_model_get (priv->model, &active, MODEL_COL_ID, &serversecurity, -1); - return serversecurity; - } - - return MODEST_PROTOCOL_UNKNOWN; /* Failed. */ -} - -/** - * Returns the default port to be used for the selected serversecurity, - * or 0 if no serversecurity was selected. - */ -gint -easysetup_serversecurity_combo_box_get_active_serversecurity_port (EasysetupServersecurityComboBox *combobox) -{ - EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); - - const ModestProtocol security = easysetup_serversecurity_combo_box_get_active_serversecurity - (combobox); - return get_port_for_security (priv->protocol, security); -} - -/* This allows us to pass more than one piece of data to the signal handler, - * and get a result: */ -typedef struct -{ - EasysetupServersecurityComboBox* self; - gint id; - gboolean found; -} ForEachData; - -static gboolean -on_model_foreach_select_id(GtkTreeModel *model, - GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) -{ - ForEachData *state = (ForEachData*)(user_data); - - /* Select the item if it has the matching ID: */ - guint id = 0; - gtk_tree_model_get (model, iter, MODEL_COL_ID, &id, -1); - if(id == state->id) { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter); - - state->found = TRUE; - return TRUE; /* Stop walking the tree. */ - } - - return FALSE; /* Keep walking the tree. */ -} - -/** - * Selects the specified serversecurity, - * or MODEST_PROTOCOL_UNKNOWN if no serversecurity was selected. - */ -gboolean -easysetup_serversecurity_combo_box_set_active_serversecurity (EasysetupServersecurityComboBox *combobox, ModestProtocol serversecurity) -{ - EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); - - /* Create a state instance so we can send two items of data to the signal handler: */ - ForEachData *state = g_new0 (ForEachData, 1); - state->self = combobox; - state->id = serversecurity; - state->found = FALSE; - - /* Look at each item, and select the one with the correct ID: */ - gtk_tree_model_foreach (priv->model, &on_model_foreach_select_id, state); - - const gboolean result = state->found; - - /* Free the state instance: */ - g_free(state); - - return result; -} - diff --git a/src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h b/src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h deleted file mode 100644 index b9fe567..0000000 --- a/src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (c) 2007, Nokia Corporation - * All rights reserved. - * - */ - -#ifndef _EASYSETUP_SERVERSECURITY_COMBO_BOX -#define _EASYSETUP_SERVERSECURITY_COMBO_BOX - -#include -#include "modest-protocol-info.h" - -G_BEGIN_DECLS - -#define EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX easysetup_serversecurity_combo_box_get_type() - -#define EASYSETUP_SERVERSECURITY_COMBO_BOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBox)) - -#define EASYSETUP_SERVERSECURITY_COMBO_BOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBoxClass)) - -#define EASYSETUP_IS_SERVERSECURITY_COMBO_BOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX)) - -#define EASYSETUP_IS_SERVERSECURITY_COMBO_BOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX)) - -#define EASYSETUP_SERVERSECURITY_COMBO_BOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBoxClass)) - -typedef struct { - GtkComboBox parent; -} EasysetupServersecurityComboBox; - -typedef struct { - GtkComboBoxClass parent_class; -} EasysetupServersecurityComboBoxClass; - -GType easysetup_serversecurity_combo_box_get_type (void); - -EasysetupServersecurityComboBox* easysetup_serversecurity_combo_box_new (void); - -void easysetup_serversecurity_combo_box_fill (EasysetupServersecurityComboBox *combobox, ModestProtocol protocol); - -ModestProtocol easysetup_serversecurity_combo_box_get_active_serversecurity (EasysetupServersecurityComboBox *combobox); - -gboolean easysetup_serversecurity_combo_box_set_active_serversecurity (EasysetupServersecurityComboBox *combobox, ModestProtocol serversecurity); - -gint easysetup_serversecurity_combo_box_get_active_serversecurity_port (EasysetupServersecurityComboBox *combobox); - - -G_END_DECLS - -#endif /* _EASYSETUP_PROVIDER_COMBO_BOX */ diff --git a/src/maemo/easysetup/modest-easysetup-wizard.c b/src/maemo/easysetup/modest-easysetup-wizard.c index 9ee8fdd..246a29f 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.c +++ b/src/maemo/easysetup/modest-easysetup-wizard.c @@ -18,9 +18,9 @@ #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 "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 "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" diff --git a/src/maemo/easysetup/modest-validating-entry.c b/src/maemo/easysetup/modest-validating-entry.c deleted file mode 100644 index b1d1191..0000000 --- a/src/maemo/easysetup/modest-validating-entry.c +++ /dev/null @@ -1,210 +0,0 @@ -/* Copyright (c) 2007, Nokia Corporation - * All rights reserved. - * - */ - -#include "modest-validating-entry.h" -#include /* For the gtk_signal_stop_emit_by_name() convenience function. */ -#include /* For strlen(). */ - -/* Include config.h so that _() works: */ -#ifdef HAVE_CONFIG_H -#include -#endif - -G_DEFINE_TYPE (EasysetupValidatingEntry, easysetup_validating_entry, GTK_TYPE_ENTRY); - -#define VALIDATING_ENTRY_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntryPrivate)) - -typedef struct _EasysetupValidatingEntryPrivate EasysetupValidatingEntryPrivate; - -struct _EasysetupValidatingEntryPrivate -{ - /* A list of gunichar, rather than char*, - * because gunichar is easier to deal with internally, - * but gchar* is easier to supply from the external interface. - */ - GList *list_prevent; - - gboolean prevent_whitespace; -}; - -static void -easysetup_validating_entry_get_property (GObject *object, guint property_id, - GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_validating_entry_set_property (GObject *object, guint property_id, - const GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_validating_entry_dispose (GObject *object) -{ - if (G_OBJECT_CLASS (easysetup_validating_entry_parent_class)->dispose) - G_OBJECT_CLASS (easysetup_validating_entry_parent_class)->dispose (object); -} - -static void -easysetup_validating_entry_finalize (GObject *object) -{ - EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (object); - - /* Free the list and its items: */ - if (priv->list_prevent) { - g_list_foreach (priv->list_prevent, (GFunc)&g_free, NULL); - g_list_free (priv->list_prevent); - } - - G_OBJECT_CLASS (easysetup_validating_entry_parent_class)->finalize (object); -} - -static void -easysetup_validating_entry_class_init (EasysetupValidatingEntryClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (EasysetupValidatingEntryPrivate)); - - object_class->get_property = easysetup_validating_entry_get_property; - object_class->set_property = easysetup_validating_entry_set_property; - object_class->dispose = easysetup_validating_entry_dispose; - object_class->finalize = easysetup_validating_entry_finalize; -} - -static gint -on_list_compare(gconstpointer a, gconstpointer b) -{ - gunichar* unichar_a = (gunichar*)(a); - gunichar* unichar_b = (gunichar*)(b); - if(*unichar_a == *unichar_b) - return 0; - else - return -1; /* Really, we should return > and <, but we don't use this for sorting. */ -} - -static void -on_insert_text(GtkEditable *editable, - gchar *new_text, gint new_text_length, - gint *position, - gpointer user_data) -{ - EasysetupValidatingEntry *self = EASYSETUP_VALIDATING_ENTRY (user_data); - EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self); - - if(!new_text_length) - return; - - /* Note: new_text_length is documented as the number of bytes, not characters. */ - if(!g_utf8_validate (new_text, new_text_length, NULL)) - return; - - /* Look at each UTF-8 character in the text (it could be several via a drop or a paste), - * and check them */ - gboolean allow = TRUE; - gchar *iter = new_text; /* new_text seems to be NULL-terminated, though that is not documented. */ - while (iter) - { - if(priv->list_prevent) { - /* If the character is in our prevent list, - * then do not allow this text to be entered. - * - * This prevents entry of all text, without removing the unwanted characters. - * It is debatable whether that is the best thing to do. - */ - gunichar one_char = g_utf8_get_char (iter); - GList *found = g_list_find_custom(priv->list_prevent, &one_char, &on_list_compare); - if(found) { - allow = FALSE; - break; - } - } - - if(priv->prevent_whitespace) { - /* Check for whitespace characters: */ - gunichar one_char = g_utf8_get_char (iter); - if (g_unichar_isspace (one_char)) { - allow = FALSE; - break; - } - } - - /* Crashes. Don't know why: iter = g_utf8_next_char (iter); - * Maybe it doesn't check for null-termination. */ - iter = g_utf8_find_next_char (iter, new_text + new_text_length); - } - - if(!allow) { - /* The signal documentation says - * "by connecting to this signal and then stopping the signal with - * gtk_signal_emit_stop(), it is possible to modify the inserted text, - * or prevent it from being inserted entirely." - */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (self), "insert-text"); - } -} - -static void -easysetup_validating_entry_init (EasysetupValidatingEntry *self) -{ - /* Connect to the GtkEditable::insert-text signal - * so we can filter out some characters: - * We connect _before_ so we can stop the default signal handler from running. - */ - g_signal_connect (G_OBJECT (self), "insert-text", (GCallback)&on_insert_text, self); -} - -EasysetupValidatingEntry* -easysetup_validating_entry_new (void) -{ - return g_object_new (EASYSETUP_TYPE_VALIDATING_ENTRY, NULL); -} - -/** Specify characters that may not be entered into this GtkEntry. - * - * list: A list of gchar* strings. Each one identifies a UTF-8 character. - */ -void easysetup_validating_entry_set_unallowed_characters (EasysetupValidatingEntry *self, GList *list) -{ - EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self); - - /* Free the list and its items: */ - if (priv->list_prevent) { - g_list_foreach (priv->list_prevent, (GFunc)&g_free, NULL); - g_list_free (priv->list_prevent); - } - - /* Do a deep copy of the list, converting gchar* to gunichar: */ - priv->list_prevent = NULL; - GList *iter = NULL; - for (iter = list; iter != NULL; iter = iter->next) { - gunichar *one_char = g_new0 (gunichar, 1); - if(iter->data) - *one_char = g_utf8_get_char ((gchar*)iter->data); - else - *one_char = 0; - - priv->list_prevent = g_list_append (priv->list_prevent, one_char); - } -} - -/** Specify that no whitespace characters may be entered into this GtkEntry. - * - */ -void easysetup_validating_entry_set_unallowed_characters_whitespace (EasysetupValidatingEntry *self) -{ - EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self); - priv->prevent_whitespace = TRUE; -} diff --git a/src/maemo/easysetup/modest-validating-entry.h b/src/maemo/easysetup/modest-validating-entry.h deleted file mode 100644 index e442841..0000000 --- a/src/maemo/easysetup/modest-validating-entry.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (c) 2007, Nokia Corporation - * All rights reserved. - * - */ - -#ifndef _EASYSETUP_VALIDATING_ENTRY -#define _EASYSETUP_VALIDATING_ENTRY - -#include - -G_BEGIN_DECLS - -#define EASYSETUP_TYPE_VALIDATING_ENTRY easysetup_validating_entry_get_type() - -#define EASYSETUP_VALIDATING_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntry)) - -#define EASYSETUP_VALIDATING_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntryClass)) - -#define EASYSETUP_IS_VALIDATING_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - EASYSETUP_TYPE_VALIDATING_ENTRY)) - -#define EASYSETUP_IS_VALIDATING_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - EASYSETUP_TYPE_VALIDATING_ENTRY)) - -#define EASYSETUP_VALIDATING_ENTRY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntryClass)) - -typedef struct { - GtkEntry parent; -} EasysetupValidatingEntry; - -typedef struct { - GtkEntryClass parent_class; -} EasysetupValidatingEntryClass; - -GType easysetup_validating_entry_get_type (void); - -EasysetupValidatingEntry* easysetup_validating_entry_new (void); - -void easysetup_validating_entry_set_unallowed_characters (EasysetupValidatingEntry *self, GList *list); -void easysetup_validating_entry_set_unallowed_characters_whitespace (EasysetupValidatingEntry *self); - -G_END_DECLS - -#endif /* _EASYSETUP_VALIDATING_ENTRY */ diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c index 25d74f3..31ddbf6 100644 --- a/src/maemo/modest-account-settings-dialog.c +++ b/src/maemo/modest-account-settings-dialog.c @@ -19,9 +19,9 @@ #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 "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 "widgets/modest-easysetup-serversecurity-combo-box.h" +#include "widgets/modest-easysetup-secureauth-combo-box.h" +#include "widgets/modest-validating-entry.h" #include "widgets/modest-retrieve-combo-box.h" #include "widgets/modest-limit-retrieve-combo-box.h" #include "modest-text-utils.h" diff --git a/src/maemo/modest-connection-specific-smtp-edit-window.c b/src/maemo/modest-connection-specific-smtp-edit-window.c index afb1848..4b15001 100644 --- a/src/maemo/modest-connection-specific-smtp-edit-window.c +++ b/src/maemo/modest-connection-specific-smtp-edit-window.c @@ -5,9 +5,9 @@ #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 "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 "widgets/modest-easysetup-serversecurity-combo-box.h" +#include "widgets/modest-easysetup-secureauth-combo-box.h" +#include "widgets/modest-validating-entry.h" #include #include #include diff --git a/src/widgets/Makefile.am b/src/widgets/Makefile.am index 098b732..4e90001 100644 --- a/src/widgets/Makefile.am +++ b/src/widgets/Makefile.am @@ -51,8 +51,11 @@ libmodest_widgets_la_SOURCES= \ modest-retrieve-combo-box.c \ modest-scroll-text.c \ modest-scroll-text.h \ + modest-easysetup-serversecurity-combo-box.h modest-easysetup-serversecurity-combo-box.c \ + modest-easysetup-secureauth-combo-box.h modest-easysetup-secureauth-combo-box.c \ modest-tny-stream-gtkhtml.c \ modest-tny-stream-gtkhtml.h \ + modest-validating-entry.h modest-validating-entry.c \ modest-window.c \ modest-window.h \ modest-window-mgr.h \ diff --git a/src/widgets/modest-easysetup-secureauth-combo-box.c b/src/widgets/modest-easysetup-secureauth-combo-box.c new file mode 100644 index 0000000..c900094 --- /dev/null +++ b/src/widgets/modest-easysetup-secureauth-combo-box.c @@ -0,0 +1,219 @@ +/* Copyright (c) 2007, Nokia Corporation + * All rights reserved. + * + */ + +#include "modest-easysetup-secureauth-combo-box.h" +#include +#include +#include +#include + +#include +#include /* For memcpy() */ + +/* Include config.h so that _() works: */ +#ifdef HAVE_CONFIG_H +#include +#endif + +G_DEFINE_TYPE (EasysetupSecureauthComboBox, easysetup_secureauth_combo_box, GTK_TYPE_COMBO_BOX); + +#define SECUREAUTH_COMBO_BOX_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBoxPrivate)) + +typedef struct _EasysetupSecureauthComboBoxPrivate EasysetupSecureauthComboBoxPrivate; + +struct _EasysetupSecureauthComboBoxPrivate +{ + GtkTreeModel *model; +}; + +static void +easysetup_secureauth_combo_box_get_property (GObject *object, guint property_id, + GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +easysetup_secureauth_combo_box_set_property (GObject *object, guint property_id, + const GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +easysetup_secureauth_combo_box_dispose (GObject *object) +{ + if (G_OBJECT_CLASS (easysetup_secureauth_combo_box_parent_class)->dispose) + G_OBJECT_CLASS (easysetup_secureauth_combo_box_parent_class)->dispose (object); +} + +static void +easysetup_secureauth_combo_box_finalize (GObject *object) +{ + EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (object); + + g_object_unref (G_OBJECT (priv->model)); + + G_OBJECT_CLASS (easysetup_secureauth_combo_box_parent_class)->finalize (object); +} + +static void +easysetup_secureauth_combo_box_class_init (EasysetupSecureauthComboBoxClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (EasysetupSecureauthComboBoxPrivate)); + + object_class->get_property = easysetup_secureauth_combo_box_get_property; + object_class->set_property = easysetup_secureauth_combo_box_set_property; + object_class->dispose = easysetup_secureauth_combo_box_dispose; + object_class->finalize = easysetup_secureauth_combo_box_finalize; +} + +enum MODEL_COLS { + MODEL_COL_NAME = 0, /* a string */ + MODEL_COL_ID = 1 /* an int. */ +}; + +void easysetup_secureauth_combo_box_fill (EasysetupSecureauthComboBox *combobox); + +static void +easysetup_secureauth_combo_box_init (EasysetupSecureauthComboBox *self) +{ + EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (self); + + /* Create a tree model for the combo box, + * with a string for the name, and an ID for the secureauth. + * This must match our MODEL_COLS enum constants. + */ + priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT)); + + /* Setup the combo box: */ + GtkComboBox *combobox = GTK_COMBO_BOX (self); + gtk_combo_box_set_model (combobox, priv->model); + + /* Secureauth column: + * The ID model column in not shown in the view. */ + GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combobox), renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, + "text", MODEL_COL_NAME, NULL); + + easysetup_secureauth_combo_box_fill (self); +} + +EasysetupSecureauthComboBox* +easysetup_secureauth_combo_box_new (void) +{ + return g_object_new (EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, NULL); +} + +/* Fill the combo box with appropriate choices. + * #combobox: The combo box. + * @protocol: IMAP or POP. + */ +void easysetup_secureauth_combo_box_fill (EasysetupSecureauthComboBox *combobox) +{ + EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (combobox); + + /* Remove any existing rows: */ + GtkListStore *liststore = GTK_LIST_STORE (priv->model); + gtk_list_store_clear (liststore); + + GtkTreeIter iter; + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_AUTH_NONE, MODEL_COL_NAME, _("mcen_fi_advsetup_smtp_none"), -1); + + /* Select the None item: */ + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter); + + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_AUTH_PASSWORD, MODEL_COL_NAME, _("mcen_fi_advsetup_smtp_login"), -1); + + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_AUTH_CRAMMD5, MODEL_COL_NAME, _("mcen_fi_advsetup_smtp_cram_md5"), -1); +} + +/** + * Returns the selected secureauth, + * or MODEST_PROTOCOL_UNKNOWN if no secureauth was selected. + */ +ModestProtocol +easysetup_secureauth_combo_box_get_active_secureauth (EasysetupSecureauthComboBox *combobox) +{ + GtkTreeIter active; + const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active); + if (found) { + EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (combobox); + + ModestProtocol secureauth = MODEST_PROTOCOL_UNKNOWN; + gtk_tree_model_get (priv->model, &active, MODEL_COL_ID, &secureauth, -1); + return secureauth; + } + + return MODEST_PROTOCOL_UNKNOWN; /* Failed. */ +} + +/* This allows us to pass more than one piece of data to the signal handler, + * and get a result: */ +typedef struct +{ + EasysetupSecureauthComboBox* self; + gint id; + gboolean found; +} ForEachData; + +static gboolean +on_model_foreach_select_id(GtkTreeModel *model, + GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) +{ + ForEachData *state = (ForEachData*)(user_data); + + /* Select the item if it has the matching ID: */ + guint id = 0; + gtk_tree_model_get (model, iter, MODEL_COL_ID, &id, -1); + if(id == state->id) { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter); + + state->found = TRUE; + return TRUE; /* Stop walking the tree. */ + } + + return FALSE; /* Keep walking the tree. */ +} + +/** + * Selects the specified secureauth, + * or MODEST_PROTOCOL_UNKNOWN if no secureauth was selected. + */ +gboolean +easysetup_secureauth_combo_box_set_active_secureauth (EasysetupSecureauthComboBox *combobox, ModestProtocol secureauth) +{ + EasysetupSecureauthComboBoxPrivate *priv = SECUREAUTH_COMBO_BOX_GET_PRIVATE (combobox); + + /* Create a state instance so we can send two items of data to the signal handler: */ + ForEachData *state = g_new0 (ForEachData, 1); + state->self = combobox; + state->id = secureauth; + state->found = FALSE; + + /* Look at each item, and select the one with the correct ID: */ + gtk_tree_model_foreach (priv->model, &on_model_foreach_select_id, state); + + const gboolean result = state->found; + + /* Free the state instance: */ + g_free(state); + + return result; +} + diff --git a/src/widgets/modest-easysetup-secureauth-combo-box.h b/src/widgets/modest-easysetup-secureauth-combo-box.h new file mode 100644 index 0000000..0a151cf --- /dev/null +++ b/src/widgets/modest-easysetup-secureauth-combo-box.h @@ -0,0 +1,55 @@ +/* Copyright (c) 2007, Nokia Corporation + * All rights reserved. + * + */ + +#ifndef _EASYSETUP_SECUREAUTH_COMBO_BOX +#define _EASYSETUP_SECUREAUTH_COMBO_BOX + +#include +#include "modest-protocol-info.h" + +G_BEGIN_DECLS + +#define EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX easysetup_secureauth_combo_box_get_type() + +#define EASYSETUP_SECUREAUTH_COMBO_BOX(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBox)) + +#define EASYSETUP_SECUREAUTH_COMBO_BOX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBoxClass)) + +#define EASYSETUP_IS_SECUREAUTH_COMBO_BOX(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX)) + +#define EASYSETUP_IS_SECUREAUTH_COMBO_BOX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX)) + +#define EASYSETUP_SECUREAUTH_COMBO_BOX_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + EASYSETUP_TYPE_SECUREAUTH_COMBO_BOX, EasysetupSecureauthComboBoxClass)) + +typedef struct { + GtkComboBox parent; +} EasysetupSecureauthComboBox; + +typedef struct { + GtkComboBoxClass parent_class; +} EasysetupSecureauthComboBoxClass; + +GType easysetup_secureauth_combo_box_get_type (void); + +EasysetupSecureauthComboBox* easysetup_secureauth_combo_box_new (void); + +ModestProtocol easysetup_secureauth_combo_box_get_active_secureauth (EasysetupSecureauthComboBox *combobox); + +gboolean easysetup_secureauth_combo_box_set_active_secureauth (EasysetupSecureauthComboBox *combobox, ModestProtocol secureauth); + + +G_END_DECLS + +#endif /* _EASYSETUP_PROVIDER_COMBO_BOX */ diff --git a/src/widgets/modest-easysetup-serversecurity-combo-box.c b/src/widgets/modest-easysetup-serversecurity-combo-box.c new file mode 100644 index 0000000..a85f680 --- /dev/null +++ b/src/widgets/modest-easysetup-serversecurity-combo-box.c @@ -0,0 +1,270 @@ +/* Copyright (c) 2007, Nokia Corporation + * All rights reserved. + * + */ + +#include "modest-easysetup-serversecurity-combo-box.h" +#include +#include +#include +#include + +#include +#include /* For memcpy() */ + +/* Include config.h so that _() works: */ +#ifdef HAVE_CONFIG_H +#include +#endif + +G_DEFINE_TYPE (EasysetupServersecurityComboBox, easysetup_serversecurity_combo_box, GTK_TYPE_COMBO_BOX); + +#define SERVERSECURITY_COMBO_BOX_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBoxPrivate)) + +typedef struct _EasysetupServersecurityComboBoxPrivate EasysetupServersecurityComboBoxPrivate; + +struct _EasysetupServersecurityComboBoxPrivate +{ + GtkTreeModel *model; + ModestProtocol protocol; +}; + +static void +easysetup_serversecurity_combo_box_get_property (GObject *object, guint property_id, + GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +easysetup_serversecurity_combo_box_set_property (GObject *object, guint property_id, + const GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +easysetup_serversecurity_combo_box_dispose (GObject *object) +{ + if (G_OBJECT_CLASS (easysetup_serversecurity_combo_box_parent_class)->dispose) + G_OBJECT_CLASS (easysetup_serversecurity_combo_box_parent_class)->dispose (object); +} + +static void +easysetup_serversecurity_combo_box_finalize (GObject *object) +{ + EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (object); + + g_object_unref (G_OBJECT (priv->model)); + + G_OBJECT_CLASS (easysetup_serversecurity_combo_box_parent_class)->finalize (object); +} + +static void +easysetup_serversecurity_combo_box_class_init (EasysetupServersecurityComboBoxClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (EasysetupServersecurityComboBoxPrivate)); + + object_class->get_property = easysetup_serversecurity_combo_box_get_property; + object_class->set_property = easysetup_serversecurity_combo_box_set_property; + object_class->dispose = easysetup_serversecurity_combo_box_dispose; + object_class->finalize = easysetup_serversecurity_combo_box_finalize; +} + +enum MODEL_COLS { + MODEL_COL_NAME = 0, /* a string */ + MODEL_COL_ID = 1 /* an int. */ +}; + +static void +easysetup_serversecurity_combo_box_init (EasysetupServersecurityComboBox *self) +{ + EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (self); + + /* Create a tree model for the combo box, + * with a string for the name, and an ID for the serversecurity. + * This must match our MODEL_COLS enum constants. + */ + priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT)); + + /* Setup the combo box: */ + GtkComboBox *combobox = GTK_COMBO_BOX (self); + gtk_combo_box_set_model (combobox, priv->model); + + /* Serversecurity column: + * The ID model column in not shown in the view. */ + GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combobox), renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, + "text", MODEL_COL_NAME, NULL); + + /* The application must call easysetup_serversecurity_combo_box_fill(). + */ +} + +EasysetupServersecurityComboBox* +easysetup_serversecurity_combo_box_new (void) +{ + return g_object_new (EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, NULL); +} + +/* Fill the combo box with appropriate choices. + * #combobox: The combo box. + * @protocol: IMAP or POP. + */ +void easysetup_serversecurity_combo_box_fill (EasysetupServersecurityComboBox *combobox, ModestProtocol protocol) +{ + EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); + priv->protocol = protocol; /* Remembered for later. */ + + /* Remove any existing rows: */ + GtkListStore *liststore = GTK_LIST_STORE (priv->model); + gtk_list_store_clear (liststore); + + GtkTreeIter iter; + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_NONE, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_none"), -1); + + /* Select the None item: */ + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter); + + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_TLS, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_normal"), -1); + + /* Add security choices with protocol-specific names, as in the UI spec: + * (Note: Changing the title seems pointless. murrayc) */ + if(protocol == MODEST_PROTOCOL_STORE_POP) { + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_SSL, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_securepop3s"), -1); + } else if(protocol == MODEST_PROTOCOL_STORE_IMAP) { + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_SSL, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_secureimap4"), -1); + } else if(protocol == MODEST_PROTOCOL_TRANSPORT_SMTP) { + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_SECURITY_SSL, MODEL_COL_NAME, _("mcen_fi_advsetup_other_security_ssl"), -1); + } +} + +static gint get_port_for_security (ModestProtocol protocol, ModestProtocol security) +{ + /* See the UI spec, section Email Wizards, Incoming Details [MSG-WIZ001]: */ + gint result = 0; + + /* Get the default port number for this protocol with this security: */ + if(protocol == MODEST_PROTOCOL_STORE_POP) { + if ((security == MODEST_PROTOCOL_SECURITY_NONE) || (security == MODEST_PROTOCOL_SECURITY_TLS)) + result = 110; + else if (security == MODEST_PROTOCOL_SECURITY_SSL) + result = 995; + } else if (protocol == MODEST_PROTOCOL_STORE_IMAP) { + if ((security == MODEST_PROTOCOL_SECURITY_NONE) || (security == MODEST_PROTOCOL_SECURITY_TLS)) + result = 143; + else if (security == MODEST_PROTOCOL_SECURITY_SSL) + result = 993; + } else if (protocol == MODEST_PROTOCOL_TRANSPORT_SMTP) { + if ((security == MODEST_PROTOCOL_SECURITY_NONE) || (security == MODEST_PROTOCOL_SECURITY_TLS)) + result = 25; + else if (security == MODEST_PROTOCOL_SECURITY_SSL) + result = 465; + } + + return result; +} + +/** + * Returns the selected serversecurity, + * or MODEST_PROTOCOL_UNKNOWN if no serversecurity was selected. + */ +ModestProtocol +easysetup_serversecurity_combo_box_get_active_serversecurity (EasysetupServersecurityComboBox *combobox) +{ + GtkTreeIter active; + const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active); + if (found) { + EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); + + ModestProtocol serversecurity = MODEST_PROTOCOL_UNKNOWN; + gtk_tree_model_get (priv->model, &active, MODEL_COL_ID, &serversecurity, -1); + return serversecurity; + } + + return MODEST_PROTOCOL_UNKNOWN; /* Failed. */ +} + +/** + * Returns the default port to be used for the selected serversecurity, + * or 0 if no serversecurity was selected. + */ +gint +easysetup_serversecurity_combo_box_get_active_serversecurity_port (EasysetupServersecurityComboBox *combobox) +{ + EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); + + const ModestProtocol security = easysetup_serversecurity_combo_box_get_active_serversecurity + (combobox); + return get_port_for_security (priv->protocol, security); +} + +/* This allows us to pass more than one piece of data to the signal handler, + * and get a result: */ +typedef struct +{ + EasysetupServersecurityComboBox* self; + gint id; + gboolean found; +} ForEachData; + +static gboolean +on_model_foreach_select_id(GtkTreeModel *model, + GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) +{ + ForEachData *state = (ForEachData*)(user_data); + + /* Select the item if it has the matching ID: */ + guint id = 0; + gtk_tree_model_get (model, iter, MODEL_COL_ID, &id, -1); + if(id == state->id) { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter); + + state->found = TRUE; + return TRUE; /* Stop walking the tree. */ + } + + return FALSE; /* Keep walking the tree. */ +} + +/** + * Selects the specified serversecurity, + * or MODEST_PROTOCOL_UNKNOWN if no serversecurity was selected. + */ +gboolean +easysetup_serversecurity_combo_box_set_active_serversecurity (EasysetupServersecurityComboBox *combobox, ModestProtocol serversecurity) +{ + EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox); + + /* Create a state instance so we can send two items of data to the signal handler: */ + ForEachData *state = g_new0 (ForEachData, 1); + state->self = combobox; + state->id = serversecurity; + state->found = FALSE; + + /* Look at each item, and select the one with the correct ID: */ + gtk_tree_model_foreach (priv->model, &on_model_foreach_select_id, state); + + const gboolean result = state->found; + + /* Free the state instance: */ + g_free(state); + + return result; +} + diff --git a/src/widgets/modest-easysetup-serversecurity-combo-box.h b/src/widgets/modest-easysetup-serversecurity-combo-box.h new file mode 100644 index 0000000..b9fe567 --- /dev/null +++ b/src/widgets/modest-easysetup-serversecurity-combo-box.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2007, Nokia Corporation + * All rights reserved. + * + */ + +#ifndef _EASYSETUP_SERVERSECURITY_COMBO_BOX +#define _EASYSETUP_SERVERSECURITY_COMBO_BOX + +#include +#include "modest-protocol-info.h" + +G_BEGIN_DECLS + +#define EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX easysetup_serversecurity_combo_box_get_type() + +#define EASYSETUP_SERVERSECURITY_COMBO_BOX(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBox)) + +#define EASYSETUP_SERVERSECURITY_COMBO_BOX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBoxClass)) + +#define EASYSETUP_IS_SERVERSECURITY_COMBO_BOX(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX)) + +#define EASYSETUP_IS_SERVERSECURITY_COMBO_BOX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX)) + +#define EASYSETUP_SERVERSECURITY_COMBO_BOX_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + EASYSETUP_TYPE_SERVERSECURITY_COMBO_BOX, EasysetupServersecurityComboBoxClass)) + +typedef struct { + GtkComboBox parent; +} EasysetupServersecurityComboBox; + +typedef struct { + GtkComboBoxClass parent_class; +} EasysetupServersecurityComboBoxClass; + +GType easysetup_serversecurity_combo_box_get_type (void); + +EasysetupServersecurityComboBox* easysetup_serversecurity_combo_box_new (void); + +void easysetup_serversecurity_combo_box_fill (EasysetupServersecurityComboBox *combobox, ModestProtocol protocol); + +ModestProtocol easysetup_serversecurity_combo_box_get_active_serversecurity (EasysetupServersecurityComboBox *combobox); + +gboolean easysetup_serversecurity_combo_box_set_active_serversecurity (EasysetupServersecurityComboBox *combobox, ModestProtocol serversecurity); + +gint easysetup_serversecurity_combo_box_get_active_serversecurity_port (EasysetupServersecurityComboBox *combobox); + + +G_END_DECLS + +#endif /* _EASYSETUP_PROVIDER_COMBO_BOX */ diff --git a/src/widgets/modest-validating-entry.c b/src/widgets/modest-validating-entry.c new file mode 100644 index 0000000..b1d1191 --- /dev/null +++ b/src/widgets/modest-validating-entry.c @@ -0,0 +1,210 @@ +/* Copyright (c) 2007, Nokia Corporation + * All rights reserved. + * + */ + +#include "modest-validating-entry.h" +#include /* For the gtk_signal_stop_emit_by_name() convenience function. */ +#include /* For strlen(). */ + +/* Include config.h so that _() works: */ +#ifdef HAVE_CONFIG_H +#include +#endif + +G_DEFINE_TYPE (EasysetupValidatingEntry, easysetup_validating_entry, GTK_TYPE_ENTRY); + +#define VALIDATING_ENTRY_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntryPrivate)) + +typedef struct _EasysetupValidatingEntryPrivate EasysetupValidatingEntryPrivate; + +struct _EasysetupValidatingEntryPrivate +{ + /* A list of gunichar, rather than char*, + * because gunichar is easier to deal with internally, + * but gchar* is easier to supply from the external interface. + */ + GList *list_prevent; + + gboolean prevent_whitespace; +}; + +static void +easysetup_validating_entry_get_property (GObject *object, guint property_id, + GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +easysetup_validating_entry_set_property (GObject *object, guint property_id, + const GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +easysetup_validating_entry_dispose (GObject *object) +{ + if (G_OBJECT_CLASS (easysetup_validating_entry_parent_class)->dispose) + G_OBJECT_CLASS (easysetup_validating_entry_parent_class)->dispose (object); +} + +static void +easysetup_validating_entry_finalize (GObject *object) +{ + EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (object); + + /* Free the list and its items: */ + if (priv->list_prevent) { + g_list_foreach (priv->list_prevent, (GFunc)&g_free, NULL); + g_list_free (priv->list_prevent); + } + + G_OBJECT_CLASS (easysetup_validating_entry_parent_class)->finalize (object); +} + +static void +easysetup_validating_entry_class_init (EasysetupValidatingEntryClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (EasysetupValidatingEntryPrivate)); + + object_class->get_property = easysetup_validating_entry_get_property; + object_class->set_property = easysetup_validating_entry_set_property; + object_class->dispose = easysetup_validating_entry_dispose; + object_class->finalize = easysetup_validating_entry_finalize; +} + +static gint +on_list_compare(gconstpointer a, gconstpointer b) +{ + gunichar* unichar_a = (gunichar*)(a); + gunichar* unichar_b = (gunichar*)(b); + if(*unichar_a == *unichar_b) + return 0; + else + return -1; /* Really, we should return > and <, but we don't use this for sorting. */ +} + +static void +on_insert_text(GtkEditable *editable, + gchar *new_text, gint new_text_length, + gint *position, + gpointer user_data) +{ + EasysetupValidatingEntry *self = EASYSETUP_VALIDATING_ENTRY (user_data); + EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self); + + if(!new_text_length) + return; + + /* Note: new_text_length is documented as the number of bytes, not characters. */ + if(!g_utf8_validate (new_text, new_text_length, NULL)) + return; + + /* Look at each UTF-8 character in the text (it could be several via a drop or a paste), + * and check them */ + gboolean allow = TRUE; + gchar *iter = new_text; /* new_text seems to be NULL-terminated, though that is not documented. */ + while (iter) + { + if(priv->list_prevent) { + /* If the character is in our prevent list, + * then do not allow this text to be entered. + * + * This prevents entry of all text, without removing the unwanted characters. + * It is debatable whether that is the best thing to do. + */ + gunichar one_char = g_utf8_get_char (iter); + GList *found = g_list_find_custom(priv->list_prevent, &one_char, &on_list_compare); + if(found) { + allow = FALSE; + break; + } + } + + if(priv->prevent_whitespace) { + /* Check for whitespace characters: */ + gunichar one_char = g_utf8_get_char (iter); + if (g_unichar_isspace (one_char)) { + allow = FALSE; + break; + } + } + + /* Crashes. Don't know why: iter = g_utf8_next_char (iter); + * Maybe it doesn't check for null-termination. */ + iter = g_utf8_find_next_char (iter, new_text + new_text_length); + } + + if(!allow) { + /* The signal documentation says + * "by connecting to this signal and then stopping the signal with + * gtk_signal_emit_stop(), it is possible to modify the inserted text, + * or prevent it from being inserted entirely." + */ + gtk_signal_emit_stop_by_name (GTK_OBJECT (self), "insert-text"); + } +} + +static void +easysetup_validating_entry_init (EasysetupValidatingEntry *self) +{ + /* Connect to the GtkEditable::insert-text signal + * so we can filter out some characters: + * We connect _before_ so we can stop the default signal handler from running. + */ + g_signal_connect (G_OBJECT (self), "insert-text", (GCallback)&on_insert_text, self); +} + +EasysetupValidatingEntry* +easysetup_validating_entry_new (void) +{ + return g_object_new (EASYSETUP_TYPE_VALIDATING_ENTRY, NULL); +} + +/** Specify characters that may not be entered into this GtkEntry. + * + * list: A list of gchar* strings. Each one identifies a UTF-8 character. + */ +void easysetup_validating_entry_set_unallowed_characters (EasysetupValidatingEntry *self, GList *list) +{ + EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self); + + /* Free the list and its items: */ + if (priv->list_prevent) { + g_list_foreach (priv->list_prevent, (GFunc)&g_free, NULL); + g_list_free (priv->list_prevent); + } + + /* Do a deep copy of the list, converting gchar* to gunichar: */ + priv->list_prevent = NULL; + GList *iter = NULL; + for (iter = list; iter != NULL; iter = iter->next) { + gunichar *one_char = g_new0 (gunichar, 1); + if(iter->data) + *one_char = g_utf8_get_char ((gchar*)iter->data); + else + *one_char = 0; + + priv->list_prevent = g_list_append (priv->list_prevent, one_char); + } +} + +/** Specify that no whitespace characters may be entered into this GtkEntry. + * + */ +void easysetup_validating_entry_set_unallowed_characters_whitespace (EasysetupValidatingEntry *self) +{ + EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self); + priv->prevent_whitespace = TRUE; +} diff --git a/src/widgets/modest-validating-entry.h b/src/widgets/modest-validating-entry.h new file mode 100644 index 0000000..e442841 --- /dev/null +++ b/src/widgets/modest-validating-entry.h @@ -0,0 +1,52 @@ +/* Copyright (c) 2007, Nokia Corporation + * All rights reserved. + * + */ + +#ifndef _EASYSETUP_VALIDATING_ENTRY +#define _EASYSETUP_VALIDATING_ENTRY + +#include + +G_BEGIN_DECLS + +#define EASYSETUP_TYPE_VALIDATING_ENTRY easysetup_validating_entry_get_type() + +#define EASYSETUP_VALIDATING_ENTRY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntry)) + +#define EASYSETUP_VALIDATING_ENTRY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntryClass)) + +#define EASYSETUP_IS_VALIDATING_ENTRY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + EASYSETUP_TYPE_VALIDATING_ENTRY)) + +#define EASYSETUP_IS_VALIDATING_ENTRY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + EASYSETUP_TYPE_VALIDATING_ENTRY)) + +#define EASYSETUP_VALIDATING_ENTRY_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + EASYSETUP_TYPE_VALIDATING_ENTRY, EasysetupValidatingEntryClass)) + +typedef struct { + GtkEntry parent; +} EasysetupValidatingEntry; + +typedef struct { + GtkEntryClass parent_class; +} EasysetupValidatingEntryClass; + +GType easysetup_validating_entry_get_type (void); + +EasysetupValidatingEntry* easysetup_validating_entry_new (void); + +void easysetup_validating_entry_set_unallowed_characters (EasysetupValidatingEntry *self, GList *list); +void easysetup_validating_entry_set_unallowed_characters_whitespace (EasysetupValidatingEntry *self); + +G_END_DECLS + +#endif /* _EASYSETUP_VALIDATING_ENTRY */ -- 1.7.9.5