2007-04-23 Murray Cumming <murrayc@murrayc.com>
+ * src/widgets/modest-validating-entry.h:
+ * src/widgets/modest-validating-entry.c: (on_insert_text),
+ Added easysetup_validating_entry_set_max_func(), used to set a callback
+ to call when the max number of characters is reached. GtkEntry has a max-length
+ already but is silent about it.
+
+ * src/maemo/easysetup/modest-easysetup-wizard.c: (on_entry_max),
+ (create_page_account_details), (create_page_user_details),
+ (create_account):
+ * src/maemo/modest-account-settings-dialog.c: (on_entry_max),
+ (create_page_account_details), (create_page_user_details),
+ (create_page_outgoing):
+ * src/modest-ui-actions.c: (modest_ui_actions_on_details):
+ Use easysetup_validating_entry_set_max_func() to show the warning dialog, as per
+ the UI spec, when the user tries to enter more than the max number of characters.
+
+2007-04-23 Murray Cumming <murrayc@murrayc.com>
+
* src/maemo/easysetup/modest-easysetup-wizard.c:
(create_page_user_details), (create_page_custom_incoming),
(create_page_custom_outgoing):
g_free (provider_id);
}
+static void
+on_entry_max (EasysetupValidatingEntry *self, gpointer user_data)
+{
+ ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
+ show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
+}
static GtkWidget*
create_page_account_details (ModestEasysetupWizardDialog *self)
g_list_free (list_prevent);
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_account_title),
+ on_entry_max, self);
gtk_widget_show (GTK_WIDGET (box));
/* Auto-capitalization is the default, so let's turn it off: */
hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_name),
+ on_entry_max, self);
GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
_("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
gtk_widget_show (self->entry_user_name);
EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_username),
+ on_entry_max, self);
/* The password widgets: */
self->entry_user_password = gtk_entry_new ();
gtk_widget_show (caption);
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_email),
+ on_entry_max, self);
gtk_widget_show (GTK_WIDGET (box));
/* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
- protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
+ protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
ModestPresetsSecurity security_outgoing =
modest_presets_get_info_server_security (priv->presets, provider_id,
protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
MODEST_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: */
return caption;
}
+
+static void
+on_entry_max (EasysetupValidatingEntry *self, gpointer user_data)
+{
+ ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
+ show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
+}
+
static GtkWidget*
create_page_account_details (ModestAccountSettingsDialog *self)
{
g_list_free (list_prevent);
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_account_title),
+ on_entry_max, self);
/* The retrieve combobox: */
self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
/* Auto-capitalization is the default, so let's turn it off: */
hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_name),
+ on_entry_max, self);
GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
_("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
gtk_widget_show (self->entry_user_name);
EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_username),
+ on_entry_max, self);
/* The password widgets: */
self->entry_user_password = gtk_entry_new ();
gtk_widget_show (caption);
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
-
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_email),
+ on_entry_max, self);
/* Signature button: */
if (!self->button_signature)
EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
/* Set max length as in the UI spec:
- * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
+ * The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
-
+ easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username),
+ on_entry_max, self);
+
/* The password widgets: */
self->entry_outgoing_password = gtk_entry_new ();
/* Auto-capitalization is the default, so let's turn it off: */
if (gtk_widget_is_focus (folder_view)) {
TnyFolder *folder;
- folder = modest_folder_view_get_selected (folder_view);
+ folder = TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
/* Show only when it's a folder */
if (!folder || !TNY_IS_FOLDER (folder))
GList *list_prevent;
gboolean prevent_whitespace;
+
+ EasySetupValidatingEntryMaxFunc max_func;
+ gpointer max_func_user_data;
};
static void
iter = g_utf8_find_next_char (iter, new_text + new_text_length);
}
+ /* Prevent more than the max characters.
+ * The regular GtkEntry does this already, but we also want to call a specified callback,
+ * so that the application can show a warning dialog. */
+ if(priv->max_func) {
+ const gint max_num = gtk_entry_get_max_length (GTK_ENTRY (self));
+ if (max_num > 0) {
+ const gchar *existing_text = gtk_entry_get_text (GTK_ENTRY(self));
+ const gint existing_length = existing_text ? g_utf8_strlen (existing_text, -1) : 0;
+ const gint new_length_chars = g_utf8_strlen (new_text, new_text_length);
+
+ if ((existing_length + new_length_chars) > max_num) {
+ priv->max_func (self, priv->max_func_user_data);
+ /* We shouldn't need to stop the signal because the underlying code will check too.
+ * Well, that would maybe be a performance optimization,
+ * but it's generally safer not to interfere too much. */
+ }
+ }
+ }
+
if(!allow) {
/* The signal documentation says
* "by connecting to this signal and then stopping the signal with
*/
gtk_signal_emit_stop_by_name (GTK_OBJECT (self), "insert-text");
}
+
}
static void
EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self);
priv->prevent_whitespace = TRUE;
}
+
+/** Set a callback to be called when the maximum number of characters have been entered.
+ * This may be used to show an informative dialog.
+ */
+void easysetup_validating_entry_set_max_func (EasysetupValidatingEntry *self, EasySetupValidatingEntryMaxFunc func, gpointer user_data)
+{
+ EasysetupValidatingEntryPrivate *priv = VALIDATING_ENTRY_GET_PRIVATE (self);
+ priv->max_func = func;
+ priv->max_func_user_data = user_data;
+}
+
void easysetup_validating_entry_set_unallowed_characters (EasysetupValidatingEntry *self, GList *list);
void easysetup_validating_entry_set_unallowed_characters_whitespace (EasysetupValidatingEntry *self);
+typedef void (* EasySetupValidatingEntryMaxFunc) (EasysetupValidatingEntry *self, gpointer user_data);
+void easysetup_validating_entry_set_max_func (EasysetupValidatingEntry *self, EasySetupValidatingEntryMaxFunc func, gpointer user_data);
+
G_END_DECLS
#endif /* _EASYSETUP_VALIDATING_ENTRY */