! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
custom format "---" causes incorrect menu item to be activated
Status:
RESOLVED: FIXED
Product:
Xfce4-datetime-plugin
Component:
General

Comments

Description Steve 2008-05-26 12:47:10 CEST
The custom format "---" causes the separator menu item to be activated instead of the "Custom" menu item.

Reproduce by selecting custom date format in the properties dialog, entering the string "---" for the date format, clicking close.
The plugin in displays "---" for the date.
Display the properties dialog again.
The date format menu displays "---" instead of "Custom...".

I have an updated patch in the works for bug 4104 that addresses this problem.
Comment 1 Steve 2008-06-01 18:16:04 CEST
Created attachment 1656 
bug fix; the test case is now a single dash ("-")

This patch fixes this bug.

The essential test case is to configure a custom format with a single dash ("-").

I removed the RCS tag "$Id$" because it was expanded when I did an RCS checkin. They are in the other source files too.

Braces are not required around array initializers that are structs. IMO, they would not improve readability in this case.
http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Arrays-of-Structures

Patch is against trunk.
Comment 2 Diego Ongaro 2008-06-02 21:18:52 CEST
I insist that the braces are a good thing:

cc1: warnings being treated as errors
datetime-dialog.c:62: warning: missing braces around initializer
datetime-dialog.c:62: warning: (near initialization for ‘dt_combobox_date[0]’)
datetime-dialog.c:79: warning: missing braces around initializer
datetime-dialog.c:79: warning: (near initialization for ‘dt_combobox_time[0]’)
make[2]: *** [libdatetime_la-datetime-dialog.lo] Error 1
make[2]: Leaving directory `/home/ongardie/xfce/xfce4-datetime-plugin/panel-plugin'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ongardie/xfce/xfce4-datetime-plugin'
make: *** [all] Error 2
ongardie@lappy:~/xfce/xfce4-datetime-plugin$ 
Comment 3 Diego Ongaro 2008-06-02 21:53:51 CEST
In response to Comment #1:

> This patch fixes this bug.
Agreed.

> I removed the RCS tag "$Id$" because it was expanded when I did an RCS checkin.
> They are in the other source files too.
They seem to be there in many xfce modules. What do you suggest I do?

I was pretty close to checking this in, until I reread this line:
 gtk_combo_box_set_active(GTK_COMBO_BOX(date_combobox), DT_COMBOBOX_DATE_COUNT-1);
I think it largely defeats the purpose of classifying the items into different types if there's an arbitrary requirement that the custom type must be at the end.

I'm still not sure of how I'd *like* this to work.
Comment 4 Steve 2008-06-02 23:01:04 CEST
Created attachment 1657 
add braces per compiler warning; use "gchar" instead of char

Resubmitting with braces in array initialization.
This also replaces "char" with "gchar".

(In reply to comment #2)
> I insist that the braces are a good thing:

Thanks for insisting. :-)

To get those warnings, I needed to enable:
CFLAGS="$CFLAGS -Wall -Werror"
in configure.in.in.

Is there a better way?
Comment 5 Steve 2008-06-02 23:34:27 CEST
(In reply to comment #3)
> > I removed the RCS tag "$Id$" because it was expanded when I did an RCS checkin.
> > They are in the other source files too.
> They seem to be there in many xfce modules. What do you suggest I do?

They are inconsistently used:

[stephent@cedar libxfcegui4]$ pwd
/home/stephent/src/xfce/libxfcegui4-4.4.2/libxfcegui4
[stephent@cedar libxfcegui4]$ fgrep -l '$Id' *.[ch] | wc -l
22
[stephent@cedar libxfcegui4]$ fgrep -L '$Id' *.[ch] | wc -l
75

I believe they could be removed.

> I was pretty close to checking this in, until I reread this line:
>  gtk_combo_box_set_active(GTK_COMBO_BOX(date_combobox),
> DT_COMBOBOX_DATE_COUNT-1);
> I think it largely defeats the purpose of classifying the items into different
> types if there's an arbitrary requirement that the custom type must be at the
> end.

Good catch! I was aware of that and agree that it is theoretically problematic. In reality, the code has to work and be easy to maintain, so I am not really troubled. I settled this by asking myself: "How many more 'Custom' menu items does datetime need to support?".

> I'm still not sure of how I'd *like* this to work.

The "type" member could be expanded to a "flags" member that has three bits for the types and one bit for whether the item is "Custom" or not. Something like:

typedef enum {
  DT_COMBOBOX_ITEM_IS_FORMAT = (1 << 0),     /* format string that is replaced with an example date or time */
  DT_COMBOBOX_ITEM_IS_TEXT = (1 << 1),       /* literal item text, possibly with translation */
  DT_COMBOBOX_ITEM_IS_SEPARATOR = (1 << 2),  /* inactive separator */
  DT_COMBOBOX_ITEM_IS_CUSTOM = (1 << 3),     /* item enables custom format entry */
} dt_combobox_item_flags;

The "Custom" item would then be initialized with:
{ N_("Custom..."),  DT_COMBOBOX_ITEM_IS_TEXT | DT_COMBOBOX_ITEM_IS_CUSTOM      }

What do you think?
Comment 6 Steve 2008-06-03 11:36:29 CEST
Created attachment 1659 
rename menu item types; find custom item dynamically

This renames the menu item types to better describe their function.
The custom menu item is found dynamically, rather than being fixed in the last position.

In principle, the custom menu item could go anywhere now.
Comment 7 Mike Massonnet editbugs 2008-06-08 16:36:55 CEST
(In reply to comment #4)
> To get those warnings, I needed to enable:
> CFLAGS="$CFLAGS -Wall -Werror"
> in configure.in.in.
> 
> Is there a better way?

Rerun the configure script with --enable-debug.  To get the last line executed for the configure script run `head config.log'.  --enable-debug=full will fail to build on warnings.
Comment 8 Diego Ongaro 2008-06-08 21:26:45 CEST
Committed in r4919 and 4921. I took advantage of the ability to add more separators in r4920 :)

Thanks for the patches, Steve, and for being so patient. I think I'll do a release in the next couple days. I'll probably call it v1.0 to make myself feel special.
Comment 9 Steve 2008-06-09 21:31:19 CEST
(In reply to comment #7)
...
> Rerun the configure script with --enable-debug.  To get the last line executed
> for the configure script run `head config.log'.  --enable-debug=full will fail
> to build on warnings.

Thanks Mike. Your tip works fine.
$ ./configure --prefix=/usr --enable-debug=full
...
$ grep '^CFLAGS' Makefile
CFLAGS = -g -O2 -g3 -Werror -Wall -DXFCE_DISABLE_DEPRECATED


Comment 10 Steve 2008-06-09 21:41:17 CEST
(In reply to comment #8)
> Committed in r4919 and 4921. I took advantage of the ability to add more
> separators in r4920 :)
> 
> Thanks for the patches, Steve, and for being so patient. I think I'll do a
> release in the next couple days. I'll probably call it v1.0 to make myself feel
> special.

Thanks! The additional separators and new formats look great.

A 1.0 release sounds fine, but IMO, it should include a fix for Bug 4097.

Bug #4115

Reported by:
Steve
Reported on: 2008-05-26
Last modified on: 2010-11-09

People

Assignee:
Diego Ongaro
CC List:
1 user

Version

Version:
unspecified

Attachments

Additional information