Re: [evolution-patches] [IMPROVED PATCH]bug#55208:warn user about wrong birthdate and anniversary format in contacts



This looks mostly ok - the string that's built up needs to be localized,
though, and the err1/err2 thing won't scale.  comments below.

Chris

On Wed, 2004-04-07 at 18:14 +0530, S N Tejasvi wrote:
> @@ -1661,8 +1662,41 @@
>  static gboolean
>  e_contact_editor_is_valid (EABEditor *editor)
>  {
> +

don't need the blank line.

>  	/* insert checks here (date format, for instance, etc.) */
> -	return TRUE;
> +        EContactEditor *ce = E_CONTACT_EDITOR (editor);
> +	GtkWidget *dialog,*widget;
> +	gint result,err1 = 0,err2 = 0;
> +	char *errmsg = _("The following entries are invalid:\n\n");
> +
> +        widget = glade_xml_get_widget (ce->gui, "dateedit-birthday");
> +
> +	if(!(e_date_edit_date_is_valid (E_DATE_EDIT (widget))))
> +	{		
> +		errmsg = g_strconcat (errmsg,"Birthdate:\n  Example: 04/04/2004\n\n",NULL);

You can use the e_contact api to get the localized field name, which I
suggest.  The "Example... string" needs to be localized too.

Also, don't use g_strconcat like this - you're leaking the allocated
string.  I meant the g_string_* api, not g_str.

something like:

errmsg = g_string_new (_("The following entries are invalid:\n\n"));

...

errmsg = g_string_append_printf (errmsg, "%s: %s",
                                         e_contact_pretty_name (E_CONTACT_FIELD_BIRTH_DATE),
                                         /* Example of a valid date */
                                         _("Example...."));

...

and don't forget to g_string_free the string before you return.

> +       		err1 = 1;
> +	}

you don't need err1 or err2..  just "gboolean validation_error = FALSE;"
up top, then "validation_error = TRUE;" in each of these if blocks.

> +	widget = glade_xml_get_widget (ce->gui, "dateedit-anniversary");
> +
> +	if(!(e_date_edit_date_is_valid (E_DATE_EDIT (widget))))
> +        {
> +                errmsg = g_strconcat (errmsg,"Anniversary:\n  Example: 04/04/2004\n",NULL);
> +		err2 = 1;
> +	}
> +
> +	if(err1 || err2)

"if (validation_error) {" here.

btw, '{' on the same line as the if (here and elsewhere).

> +	{
> +				dialog=gtk_message_dialog_new (GTK_WINDOW (ce->app),
> +                	                                           0,
> +                        	                                   GTK_MESSAGE_INFO,
> +                                	                           GTK_BUTTONS_OK,
> +                                        	                   errmsg);
> +                                result=gtk_dialog_run (GTK_DIALOG (dialog));
> +                                gtk_widget_destroy (dialog);
> +				return FALSE;
> +	}
> +        	else
> +                                return TRUE;
>  }




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]