Re: Gtk-2 File Chooser Modification Time Display



On Sun, 12 Feb 2006 18:07:04 GMT, "Jonathan A." <invalid@xxxxxxxxxxx>
wrote:

On Sun, 12 Feb 2006 16:41:34 GMT, zentara@xxxxxxxxxxxxxx
<zentara@xxxxxxxxxxxxxx> appears to have said:

I asked about it on a Gtk2 maillist and will see what they say.

Great. I thought about subscribing to the "gtk-list" mailing list just
to ask this, and decided to try simply posting here first and see if
someone knew a simple answer I'd missed.

For what it's worth, if you are capable of compiling your own
Gtk+ c libs (there are various considerations, like version level
mis-matches), you could probably patch the file responsible for
that date string.

I compile my gtk libs locally anyhow, so that's no biggie, if it comes
to that. I've already patched the filechooser to always show the "browse
for other folders" option in the "save as..." dialog.

It's in the Gtk+ sources, in a file called

gtkfilechooserdefault.c

Just open it, and search for the word "Yesterday", and you will
find the section of code which sets this. There is a string default
formatted with %x, and I'm not familiar enough with c, to know the
various ramifications of changing it.

Me either... but I'll try anything once. Twice, if I like it. :)

Well I experimented with setting the format string from %x to %c,
which should show all file mtime info, but I was always getting
00:00 for HOURS:MINUTES. I looked into the function which
is in GLib, that they used to set the date, and it appears to me that
it ignores hours and minutes. BUT good news.....I managed to go
back to plain old stftime, and below is a sub which works.
No gaurantees as to what hidden ramifications it may have, as
filechooser interacts with other objects, but it seems to work
OK so far for me. So here is the modified sub, which returns
a nice sortable time string for all files

/* 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);
}


Good Luck. I'm using Gtk+-2.8.11
zentara



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
.



Relevant Pages

  • Re: what is the best way of passing floats into a string
    ... I do not null-terminate as snprintf takes care of this (according to ... But the easiest way to determine the size needed to format a number, ... int length_of_representation(double n,const char* format){ ... I get a nice result of -10.000000 in my char * string. ...
    (comp.unix.programmer)
  • String interpolation
    ... I'm trying to do some string interpolation -- that is, ... static char* expand(const char *format) ... strncat(string, format, pos); ...
    (comp.lang.c)
  • Re: String interpolation
    ... cigar" type questions -- as with all my others I have learnt tons, ... I'm trying to do some string interpolation -- that is, ... static char* expand(const char *format) ...
    (comp.lang.c)
  • Re: no clue
    ... > j is just the key in the outer hash. ... > 58 is the ascii number of the char ':' ... > while there is another ':' in the string ... and so could modify their format to make ...
    (comp.lang.ruby)
  • Re: Date format detection
    ... Specifies the locale for which the date string is to be formatted. ... date format for this locale. ... the system default-date format for the specified locale. ... be enclosed within single quotation marks in the date format picture. ...
    (borland.public.delphi.thirdpartytools.general)