gnome-main-menu r379 - in trunk: . libslab



Author: sreeves
Date: Sat Jan 26 00:34:54 2008
New Revision: 379
URL: http://svn.gnome.org/viewvc/gnome-main-menu?rev=379&view=rev

Log:
Fix for BNC#258361 BNC#236463


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/libslab/document-tile.c
   trunk/libslab/libslab.pc.in

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Sat Jan 26 00:34:54 2008
@@ -93,6 +93,43 @@
 dnl ==============================================
 
 dnl ==============================================
+dnl Check strftime for %l and %k support
+dnl ==============================================
+
+AC_MSG_CHECKING(for %l and %k support in strftime)
+AC_TRY_RUN([
+#include <string.h>
+#include <time.h>
+
+int main(int argc, char **argv)
+{
+	char buf[10];
+	time_t rawtime;
+	struct tm *timeinfo;
+
+	time(&rawtime);
+	timeinfo=localtime(&rawtime);
+	buf[0] = '\0';
+	strftime(buf, 10, "%lx%k", timeinfo);
+
+	if (buf[0] == '\0' || buf[0] == 'x' || strstr(buf, "l") || strstr(buf, "k"))
+		exit(1);
+	else
+		exit(0);
+}],[
+AC_DEFINE(HAVE_LKSTRFTIME, 1, [strftime supports use of l and k])
+ac_cv_lkstrftime=yes
+],ac_cv_lkstrftime=no,ac_cv_lkstrftime=no,[
+AC_DEFINE(HAVE_LKSTRFTIME, 1, [strftime supports use of l and k])
+ac_cv_lkstrftime=yes
+])
+AC_MSG_RESULT($ac_cv_lkstrftime)
+
+dnl ==============================================
+dnl End: strftime
+dnl ==============================================
+
+dnl ==============================================
 dnl Nautilus Extension
 dnl ==============================================
 

Modified: trunk/libslab/document-tile.c
==============================================================================
--- trunk/libslab/document-tile.c	(original)
+++ trunk/libslab/document-tile.c	Sat Jan 26 00:34:54 2008
@@ -50,6 +50,8 @@
 static void load_image (DocumentTile *);
 
 static GtkWidget *create_header (const gchar *);
+
+static char      *create_subheader_string (time_t date);
 static GtkWidget *create_subheader (const gchar *);
 static void update_user_list_menu_item (DocumentTile *);
 
@@ -127,7 +129,6 @@
 
 	gchar *basename;
 
-	GDate *time_stamp;
 	gchar *time_str;
 
 	gchar *markup;
@@ -147,16 +148,9 @@
 
 	header = create_header (basename);
 
-	time_stamp = g_date_new ();
-	g_date_set_time (time_stamp, modified);
-
-	time_str = g_new0 (gchar, 256);
-
-	g_date_strftime (time_str, 256, _("Edited %m/%d/%Y"), time_stamp);
-	g_date_free (time_stamp);
-
+	time_str = create_subheader_string (modified);
 	subheader = create_subheader (time_str);
-
+	
 	filename = g_filename_from_uri (uri, NULL, NULL);
 
   	if (filename)
@@ -475,6 +469,221 @@
 		g_free (icon_id);
 }
 
+/* Next function taken from e-data-server-util.c in evolution-data-server */
+/** 
+ * e_strftime:
+ * @s: The string array to store the result in.
+ * @max: The size of array @s.
+ * @fmt: The formatting to use on @tm.
+ * @tm: The time value to format.
+ *
+ * This function is a wrapper around the strftime(3) function, which
+ * converts the &percnt;l and &percnt;k (12h and 24h) format variables if necessary.
+ *
+ * Returns: The number of characters placed in @s.
+ **/
+static size_t
+e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+#ifdef HAVE_LKSTRFTIME
+	return strftime(s, max, fmt, tm);
+#else
+	char *c, *ffmt, *ff;
+	size_t ret;
+
+	ffmt = g_strdup(fmt);
+	ff = ffmt;
+	while ((c = strstr(ff, "%l")) != NULL) {
+		c[1] = 'I';
+		ff = c;
+	}
+
+	ff = ffmt;
+	while ((c = strstr(ff, "%k")) != NULL) {
+		c[1] = 'H';
+		ff = c;
+	}
+
+#ifdef G_OS_WIN32
+	/* The Microsoft strftime() doesn't have %e either */
+	ff = ffmt;
+	while ((c = strstr(ff, "%e")) != NULL) {
+		c[1] = 'd';
+		ff = c;
+	}
+#endif
+
+	ret = strftime(s, max, ffmt, tm);
+	g_free(ffmt);
+	return ret;
+#endif
+}
+
+/* Next two functions taken from e-util.c in evolution */
+/**
+ * Function to do a last minute fixup of the AM/PM stuff if the locale
+ * and gettext haven't done it right. Most English speaking countries
+ * except the USA use the 24 hour clock (UK, Australia etc). However
+ * since they are English nobody bothers to write a language
+ * translation (gettext) file. So the locale turns off the AM/PM, but
+ * gettext does not turn on the 24 hour clock. Leaving a mess.
+ *
+ * This routine checks if AM/PM are defined in the locale, if not it
+ * forces the use of the 24 hour clock.
+ *
+ * The function itself is a front end on strftime and takes exactly
+ * the same arguments.
+ *
+ * TODO: Actually remove the '%p' from the fixed up string so that
+ * there isn't a stray space.
+ **/
+
+static size_t
+e_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+	char buf[10];
+	char *sp;
+	char *ffmt;
+	size_t ret;
+
+	if (strstr(fmt, "%p")==NULL && strstr(fmt, "%P")==NULL) {
+		/* No AM/PM involved - can use the fmt string directly */
+		ret=e_strftime(s, max, fmt, tm);
+	} else {
+		/* Get the AM/PM symbol from the locale */
+		e_strftime (buf, 10, "%p", tm);
+
+		if (buf[0]) {
+			/**
+			 * AM/PM have been defined in the locale
+			 * so we can use the fmt string directly
+			 **/
+			ret=e_strftime(s, max, fmt, tm);
+		} else {
+			/**
+			 * No AM/PM defined by locale
+			 * must change to 24 hour clock
+			 **/
+			ffmt=g_strdup(fmt);
+			for (sp=ffmt; (sp=strstr(sp, "%l")); sp++) {
+				/**
+				 * Maybe this should be 'k', but I have never
+				 * seen a 24 clock actually use that format
+				 **/
+				sp[1]='H';
+			}
+			for (sp=ffmt; (sp=strstr(sp, "%I")); sp++) {
+				sp[1]='H';
+			}
+			ret=e_strftime(s, max, ffmt, tm);
+			g_free(ffmt);
+		}
+	}
+
+	return(ret);
+}
+
+static size_t 
+e_utf8_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+	size_t sz, ret;
+	char *locale_fmt, *buf;
+
+	locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+	if (!locale_fmt)
+		return 0;
+
+	ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm);
+	if (!ret) {
+		g_free (locale_fmt);
+		return 0;
+	}
+
+	buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+	if (!buf) {
+		g_free (locale_fmt);
+		return 0;
+	}
+
+	if (sz >= max) {
+		char *tmp = buf + max - 1;
+		tmp = g_utf8_find_prev_char(buf, tmp);
+		if (tmp)
+			sz = tmp - buf;
+		else
+			sz = 0;
+	}
+	memcpy(s, buf, sz);
+	s[sz] = '\0';
+	g_free(locale_fmt);
+	g_free(buf);
+	return sz;
+}
+
+static char *
+create_subheader_string (time_t date)
+{
+	time_t nowdate = time(NULL);
+	time_t yesdate;
+	struct tm then, now, yesterday;
+	char buf[100];
+	gboolean done = FALSE;
+
+	if (date == 0) {
+		return g_strdup (_("?"));
+	}
+
+	localtime_r (&date, &then);
+	localtime_r (&nowdate, &now);
+
+	if (nowdate - date < 60 * 60 * 8 && nowdate > date) {
+		e_utf8_strftime_fix_am_pm (buf, 100, _("%l:%M %p"), &then);
+		done = TRUE;
+	}
+
+	if (!done) {
+		if (then.tm_mday == now.tm_mday &&
+		    then.tm_mon == now.tm_mon &&
+		    then.tm_year == now.tm_year) {
+			e_utf8_strftime_fix_am_pm (buf, 100, _("Today %l:%M %p"), &then);
+			done = TRUE;
+		}
+	}
+	if (!done) {
+		yesdate = nowdate - 60 * 60 * 24;
+		localtime_r (&yesdate, &yesterday);
+		if (then.tm_mday == yesterday.tm_mday &&
+		    then.tm_mon == yesterday.tm_mon &&
+		    then.tm_year == yesterday.tm_year) {
+			e_utf8_strftime_fix_am_pm (buf, 100, _("Yesterday %l:%M %p"), &then);
+			done = TRUE;
+		}
+	}
+	if (!done) {
+		int i;
+		for (i = 2; i < 7; i++) {
+			yesdate = nowdate - 60 * 60 * 24 * i;
+			localtime_r (&yesdate, &yesterday);
+			if (then.tm_mday == yesterday.tm_mday &&
+			    then.tm_mon == yesterday.tm_mon &&
+			    then.tm_year == yesterday.tm_year) {
+				e_utf8_strftime_fix_am_pm (buf, 100, _("%a %l:%M %p"), &then);
+				done = TRUE;
+				break;
+			}
+		}
+	}
+	if (!done) {
+		if (then.tm_year == now.tm_year) {
+			e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %l:%M %p"), &then);
+		} else {
+			e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %Y"), &then);
+		}
+	}
+
+	return g_strdup (g_strstrip (buf));
+}
+
 static GtkWidget *
 create_header (const gchar *name)
 {

Modified: trunk/libslab/libslab.pc.in
==============================================================================
--- trunk/libslab/libslab.pc.in	(original)
+++ trunk/libslab/libslab.pc.in	Sat Jan 26 00:34:54 2008
@@ -5,7 +5,8 @@
 
 Name: libslab
 Description: Beautiful App Slab
-Requires: glib-2.0 gobject-2.0 gtk+-2.0 gdk-2.0 gnome-desktop-2.0 librsvg-2.0 libgnome-menu pango
+Requires: glib-2.0 gobject-2.0 gtk+-2.0 gnome-desktop-2.0 libgnome-menu
+Requires.private: gdk-2.0 librsvg-2.0
 Version: @VERSION@
 Libs: -L${libdir} -lslab
 Cflags: -I${includedir}/slab



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