From aab65ff35930f7c7d33ec080ae179f09150fabe2 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Mon, 23 Apr 2007 20:15:02 +0000 Subject: [PATCH] 2007-04-23 Murray Cumming * 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. pmo-trunk-r1643 --- ChangeLog2 | 18 +++++++++++++ src/maemo/easysetup/modest-easysetup-wizard.c | 30 ++++++++++++++-------- src/maemo/modest-account-settings-dialog.c | 31 +++++++++++++++++----- src/modest-ui-actions.c | 2 +- src/widgets/modest-validating-entry.c | 34 +++++++++++++++++++++++++ src/widgets/modest-validating-entry.h | 3 +++ 6 files changed, 99 insertions(+), 19 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 0b4170f..e3cd0d9 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,23 @@ 2007-04-23 Murray Cumming + * 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 + * src/maemo/easysetup/modest-easysetup-wizard.c: (create_page_user_details), (create_page_custom_incoming), (create_page_custom_outgoing): diff --git a/src/maemo/easysetup/modest-easysetup-wizard.c b/src/maemo/easysetup/modest-easysetup-wizard.c index 14491c2..233af95 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.c +++ b/src/maemo/easysetup/modest-easysetup-wizard.c @@ -238,6 +238,12 @@ on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data) 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) @@ -359,8 +365,10 @@ 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)); @@ -382,8 +390,10 @@ create_page_user_details (ModestEasysetupWizardDialog *self) /* 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); @@ -415,8 +425,10 @@ create_page_user_details (ModestEasysetupWizardDialog *self) 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 (); @@ -442,8 +454,10 @@ create_page_user_details (ModestEasysetupWizardDialog *self) 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)); @@ -1260,7 +1274,7 @@ create_account (ModestEasysetupWizardDialog *self) /* 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, @@ -1284,12 +1298,6 @@ create_account (ModestEasysetupWizardDialog *self) 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: */ diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c index 8c2b9b6..bf54263 100644 --- a/src/maemo/modest-account-settings-dialog.c +++ b/src/maemo/modest-account-settings-dialog.c @@ -216,6 +216,14 @@ static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *s 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) { @@ -257,8 +265,10 @@ 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 ()); @@ -342,8 +352,10 @@ create_page_user_details (ModestAccountSettingsDialog *self) /* 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); @@ -377,8 +389,10 @@ create_page_user_details (ModestAccountSettingsDialog *self) 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 (); @@ -406,9 +420,10 @@ create_page_user_details (ModestAccountSettingsDialog *self) 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) @@ -662,9 +677,11 @@ static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self) 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: */ diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 13866f5..6f13855 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -1659,7 +1659,7 @@ modest_ui_actions_on_details (GtkAction *action, 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)) diff --git a/src/widgets/modest-validating-entry.c b/src/widgets/modest-validating-entry.c index b1d1191..1f5035a 100644 --- a/src/widgets/modest-validating-entry.c +++ b/src/widgets/modest-validating-entry.c @@ -28,6 +28,9 @@ struct _EasysetupValidatingEntryPrivate GList *list_prevent; gboolean prevent_whitespace; + + EasySetupValidatingEntryMaxFunc max_func; + gpointer max_func_user_data; }; static void @@ -146,6 +149,25 @@ on_insert_text(GtkEditable *editable, 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 @@ -154,6 +176,7 @@ on_insert_text(GtkEditable *editable, */ gtk_signal_emit_stop_by_name (GTK_OBJECT (self), "insert-text"); } + } static void @@ -208,3 +231,14 @@ void easysetup_validating_entry_set_unallowed_characters_whitespace (EasysetupVa 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; +} + diff --git a/src/widgets/modest-validating-entry.h b/src/widgets/modest-validating-entry.h index e442841..09fa4df 100644 --- a/src/widgets/modest-validating-entry.h +++ b/src/widgets/modest-validating-entry.h @@ -47,6 +47,9 @@ 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); +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 */ -- 1.7.9.5