[gnome-color-manager] trivial: move a chunk of common code from GcmProfile to GcmUtils



commit 4c2229634fcb57de6a102468ddcac02eb1642180
Author: Richard Hughes <richard hughsie com>
Date:   Thu Dec 10 17:38:38 2009 +0000

    trivial: move a chunk of common code from GcmProfile to GcmUtils

 src/gcm-profile.c |   71 +++------------------------------------------------
 src/gcm-utils.c   |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcm-utils.h   |    6 ++++
 3 files changed, 84 insertions(+), 67 deletions(-)
---
diff --git a/src/gcm-profile.c b/src/gcm-profile.c
index 0ef4b9c..cee0958 100644
--- a/src/gcm-profile.c
+++ b/src/gcm-profile.c
@@ -37,6 +37,7 @@
 #include "egg-debug.h"
 
 #include "gcm-profile.h"
+#include "gcm-utils.h"
 #include "gcm-xyz.h"
 
 static void     gcm_profile_finalize	(GObject     *object);
@@ -669,63 +670,6 @@ out:
 }
 
 /**
- * gcm_parser_get_month:
- **/
-static const gchar *
-gcm_parser_get_month (guint idx)
-{
-	if (idx == 1) {
-		/* TRANSLATORS: the month */
-		return _("January");
-	}
-	if (idx == 2) {
-		/* TRANSLATORS: the month */
-		return _("February");
-	}
-	if (idx == 3) {
-		/* TRANSLATORS: the month */
-		return _("March");
-	}
-	if (idx == 4) {
-		/* TRANSLATORS: the month */
-		return _("April");
-	}
-	if (idx == 5) {
-		/* TRANSLATORS: the month */
-		return _("May");
-	}
-	if (idx == 6) {
-		/* TRANSLATORS: the month */
-		return _("June");
-	}
-	if (idx == 7) {
-		/* TRANSLATORS: the month */
-		return _("July");
-	}
-	if (idx == 8) {
-		/* TRANSLATORS: the month */
-		return _("August");
-	}
-	if (idx == 9) {
-		/* TRANSLATORS: the month (my birthday) */
-		return _("September");
-	}
-	if (idx == 10) {
-		/* TRANSLATORS: the month */
-		return _("October");
-	}
-	if (idx == 11) {
-		/* TRANSLATORS: the month */
-		return _("November");
-	}
-	if (idx == 12) {
-		/* TRANSLATORS: the month */
-		return _("December");
-	}
-	return NULL;
-}
-
-/**
  * gcm_parser_get_date_time:
  **/
 static gchar *
@@ -737,8 +681,6 @@ gcm_parser_get_date_time (const guint8 *data)
 	guint hours;	/* 6..7 */
 	guint minutes;	/* 8..9 */
 	guint seconds;	/* 10..11 */
-	const gchar *month_text;
-	gchar *text = NULL;
 
 	years = gcm_parser_decode_16 (data + 0x00);
 	months = gcm_parser_decode_16 (data + 0x02);
@@ -749,15 +691,10 @@ gcm_parser_get_date_time (const guint8 *data)
 
 	/* invalid / unknown */
 	if (years == 0)
-		goto out;
+		return NULL;
 
-	/* write the month as a word to avoid locale confusion */
-	month_text = gcm_parser_get_month (months);
-
-	/* TRANSLATORS: please re-arrange: days, months (in text), years, hours, minutes, seconds */
-	text = g_strdup_printf (_("%i %s %04i, %02i:%02i:%02i"), days, month_text, years, hours, minutes, seconds);
-out:
-	return text;
+	/* localise */
+	return gcm_utils_format_date_time (years, months, days, hours, minutes, seconds);
 }
 
 /**
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 89f1dc3..203466c 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -649,6 +649,80 @@ gcm_utils_device_type_to_profile_type (GcmDeviceType type)
 	return profile_type;
 }
 
+
+/**
+ * gcm_utils_month_to_localized_text:
+ **/
+static const gchar *
+gcm_utils_month_to_localized_text (guint idx)
+{
+	if (idx == 1) {
+		/* TRANSLATORS: the month */
+		return _("January");
+	}
+	if (idx == 2) {
+		/* TRANSLATORS: the month */
+		return _("February");
+	}
+	if (idx == 3) {
+		/* TRANSLATORS: the month */
+		return _("March");
+	}
+	if (idx == 4) {
+		/* TRANSLATORS: the month */
+		return _("April");
+	}
+	if (idx == 5) {
+		/* TRANSLATORS: the month */
+		return _("May");
+	}
+	if (idx == 6) {
+		/* TRANSLATORS: the month */
+		return _("June");
+	}
+	if (idx == 7) {
+		/* TRANSLATORS: the month */
+		return _("July");
+	}
+	if (idx == 8) {
+		/* TRANSLATORS: the month */
+		return _("August");
+	}
+	if (idx == 9) {
+		/* TRANSLATORS: the month (my birthday) */
+		return _("September");
+	}
+	if (idx == 10) {
+		/* TRANSLATORS: the month */
+		return _("October");
+	}
+	if (idx == 11) {
+		/* TRANSLATORS: the month */
+		return _("November");
+	}
+	if (idx == 12) {
+		/* TRANSLATORS: the month */
+		return _("December");
+	}
+	return NULL;
+}
+
+/**
+ * gcm_utils_format_date_time:
+ **/
+gchar *
+gcm_utils_format_date_time (guint years, guint months, guint days,
+			    guint hours, guint minutes, guint seconds)
+{
+	const gchar *month_text;
+
+	/* write the month as a word to avoid locale confusion */
+	month_text = gcm_utils_month_to_localized_text (months);
+
+	/* TRANSLATORS: please re-arrange: days, months (in text), years, hours, minutes, seconds */
+	return g_strdup_printf (_("%i %s %04i, %02i:%02i:%02i"), days, month_text, years, hours, minutes, seconds);
+}
+
 /***************************************************************************
  ***                          MAKE CHECK TESTS                           ***
  ***************************************************************************/
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 8e1a8b1..bc3ad9d 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -51,6 +51,12 @@ void		 gcm_utils_alphanum_lcase		(gchar			*string);
 void		 gcm_utils_ensure_sensible_filename	(gchar			*string);
 gchar		*gcm_utils_get_default_config_location	(void);
 GcmProfileType	 gcm_utils_device_type_to_profile_type	(GcmDeviceType		 type);
+gchar		*gcm_utils_format_date_time		(guint			 years,
+							 guint			 months,
+							 guint			 days,
+							 guint			 hours,
+							 guint			 minutes,
+							 guint			 seconds);
 
 #endif /* __GCM_UTILS_H */
 



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