improving the file mtime in gtkfilechooserdefault.c
- From: zentara <zentara zentara net>
- To: gtk-list gnome org
- Subject: improving the file mtime in gtkfilechooserdefault.c
- Date: Sun, 12 Feb 2006 19:44:34 -0500
Hi,
I'm a Perl hacker, more than a c person, but I've
been finding that I need to dig into the Gtk+ c libs
to really understand what is going on.
Anyways, a question came up in a newsgroup today
about the inadequacy of the mtime printout in the
filechooserdialog. You know, it has "Today, Yesterday,
and a y/m/d date string, without hours, minutes, and seconds.
I thought about what level of accuracy I would like to see as default,
in my set of libs, and I had to agree with the poster.
So I started digging around in the
gtkfilechooserdefault.c
file from the Gtk+-2.8.11 sources. The section which sets
it up, has a line
##############################################################
else
format = "%x"; /* Any other date */
if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
strcpy (buf, _("Unknown"));
}
###########################################################
The first thing I did, was try to change the %x to a %c ( and a few other
formats), but I always ended up with 00:00 for the hour and minute.
It appeared that I could not get hour, minutes, and seconds out of
the g_date_* set of functions.
So I went back to just using the plain strftime function, and it seems to
work ok. Here is my modified list_mtime_data_func
#######################################################################
/* Tree column data callback for the file list; fetches the mtime of a file */
static void
list_mtime_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
GtkFileChooserDefault *impl;
const GtkFileInfo *info;
GtkFileTime time_mtime;
char buf[216];
struct tm *cal_time;
gboolean sensitive = TRUE;
impl = data;
info = get_list_file_info (impl, iter);
if (!info)
{
g_object_set (cell,
"text", "",
"sensitive", TRUE,
NULL);
return;
}
time_mtime = gtk_file_info_get_modification_time (info);
if (time_mtime == 0)
strcpy (buf, _("Unknown"));
else
{
cal_time = localtime(&time_mtime);
char *format;
/* format = "%y/%m/%d(%a) %H:%M"; Any other date */
format = "%F %T";
/* if (g_date_strftime(buf, sizeof (buf), format, &mtime) == 0)
strcpy (buf, _("Unknown"));
*/
strftime(buf, sizeof buf, format , cal_time);
}
###################################################################
So what I'm looking for is comments on whether:
1. will I be breaking something by this change
2. is there a way to get the hours, minutes and seconds to display
using the g_date_strftime set of functions
3. I think this may be a useful configure option, especially if a choice
of format string, could be put in the gtkrc style for the filechooserdialog,
like in gtkrc have a line
format = "%y/%m/%d(%a) %H:%M";
or if that is too involved, maybe a configure option to use the full time string,
or the current "user-friendly" design.
Like I said, a far better Perl hacker, than c hacker, so I'm looking for
any improvements.
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]