Commit c2ef0e90 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos

[libdocument] Move format_date function from ev-properties to ev-document-misc

parent 356536f6
...@@ -400,3 +400,26 @@ ev_document_misc_get_screen_dpi (GdkScreen *screen) ...@@ -400,3 +400,26 @@ ev_document_misc_get_screen_dpi (GdkScreen *screen)
return (dp / di); return (dp / di);
} }
/* Returns a locale specific date and time representation */
gchar *
ev_document_misc_format_date (GTime utime)
{
time_t time = (time_t) utime;
char s[256];
const char fmt_hack[] = "%c";
size_t len;
#ifdef HAVE_LOCALTIME_R
struct tm t;
if (time == 0 || !localtime_r (&time, &t)) return NULL;
len = strftime (s, sizeof (s), fmt_hack, &t);
#else
struct tm *t;
if (time == 0 || !(t = localtime (&time)) ) return NULL;
len = strftime (s, sizeof (s), fmt_hack, t);
#endif
if (len == 0 || s[0] == '\0') return NULL;
return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
}
...@@ -60,6 +60,8 @@ void ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf); ...@@ -60,6 +60,8 @@ void ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf);
gdouble ev_document_misc_get_screen_dpi (GdkScreen *screen); gdouble ev_document_misc_get_screen_dpi (GdkScreen *screen);
gchar *ev_document_misc_format_date (GTime utime);
G_END_DECLS G_END_DECLS
#endif /* EV_DOCUMENT_MISC_H */ #endif /* EV_DOCUMENT_MISC_H */
...@@ -108,29 +108,6 @@ ev_properties_view_class_init (EvPropertiesViewClass *properties_class) ...@@ -108,29 +108,6 @@ ev_properties_view_class_init (EvPropertiesViewClass *properties_class)
g_object_class->dispose = ev_properties_view_dispose; g_object_class->dispose = ev_properties_view_dispose;
} }
/* Returns a locale specific date and time representation */
static char *
ev_properties_view_format_date (GTime utime)
{
time_t time = (time_t) utime;
char s[256];
const char fmt_hack[] = "%c";
size_t len;
#ifdef HAVE_LOCALTIME_R
struct tm t;
if (time == 0 || !localtime_r (&time, &t)) return NULL;
len = strftime (s, sizeof (s), fmt_hack, &t);
#else
struct tm *t;
if (time == 0 || !(t = localtime (&time)) ) return NULL;
len = strftime (s, sizeof (s), fmt_hack, t);
#endif
if (len == 0 || s[0] == '\0') return NULL;
return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
}
/* This is cut out of gconvert.c from glib (and mildly modified). Not all /* This is cut out of gconvert.c from glib (and mildly modified). Not all
backends give valid UTF-8 for properties, so we make sure that is. backends give valid UTF-8 for properties, so we make sure that is.
*/ */
...@@ -362,12 +339,12 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo ...@@ -362,12 +339,12 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo
set_property (properties, GTK_TABLE (table), CREATOR_PROPERTY, info->creator, &row); set_property (properties, GTK_TABLE (table), CREATOR_PROPERTY, info->creator, &row);
} }
if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) { if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
text = ev_properties_view_format_date (info->creation_date); text = ev_document_misc_format_date (info->creation_date);
set_property (properties, GTK_TABLE (table), CREATION_DATE_PROPERTY, text, &row); set_property (properties, GTK_TABLE (table), CREATION_DATE_PROPERTY, text, &row);
g_free (text); g_free (text);
} }
if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) { if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
text = ev_properties_view_format_date (info->modified_date); text = ev_document_misc_format_date (info->modified_date);
set_property (properties, GTK_TABLE (table), MOD_DATE_PROPERTY, text, &row); set_property (properties, GTK_TABLE (table), MOD_DATE_PROPERTY, text, &row);
g_free (text); g_free (text);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment