[gnome-media/gstreamer-1.0: 7/8] grecord: use GDateTime instead of time_t



commit 4c1e4d8a020eefea8434dab5e71dcd353c5cda13
Author: Oleksij Rempel <bug-track fisher-privat net>
Date:   Wed Jul 4 11:28:53 2012 +0200

    grecord: use GDateTime instead of time_t
    
    To create DstDateTime tag we will need GDateTime.
    So we can use same time two times.
    
    Signed-off-by: Oleksij Rempel <bug-track fisher-privat net>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679380

 grecord/src/gnome-recorder.c |    2 +-
 grecord/src/gsr-window.c     |   29 +++++++++++++++++++----------
 2 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/grecord/src/gnome-recorder.c b/grecord/src/gnome-recorder.c
index b37a2b8..8f12535 100644
--- a/grecord/src/gnome-recorder.c
+++ b/grecord/src/gnome-recorder.c
@@ -131,7 +131,7 @@ gsr_open_window (const char *filename)
 	gchar *name;
 
 	if (filename == NULL) {
-		name = gsr_generate_filename ();
+		name = gsr_generate_filename (NULL);
 	} else {
 		name = g_strdup (filename);
 	}
diff --git a/grecord/src/gsr-window.c b/grecord/src/gsr-window.c
index 1fc52b5..0a1b357 100644
--- a/grecord/src/gsr-window.c
+++ b/grecord/src/gsr-window.c
@@ -121,6 +121,8 @@ struct _GSRWindowPrivate {
 	int len_secs; /* In seconds */
 	int get_length_attempts;
 
+	GDateTime *datetime;
+
 	/* ATOMIC access */
 	struct {
 		gint n_channels;
@@ -1221,6 +1223,8 @@ record_cb (GtkAction *action,
 		if (priv->filename)
 			g_free (priv->filename);
 
+		priv->filename = gsr_generate_filename (window);
+
 		g_print ("%s", priv->record_filename);
 		g_object_set (G_OBJECT (priv->record->sink),
 			      "location", priv->record_filename,
@@ -1570,17 +1574,24 @@ record_eos_msg_cb (GstBus * bus, GstMessage * msg, GSRWindow * window)
 }
 
 gchar*
-gsr_generate_filename (void)
+gsr_generate_filename (GSRWindow *window)
 {
-	struct tm *ptr;
-	time_t tm;
+	gchar *string;
+	GDateTime *datetime;
+
+	datetime = g_date_time_new_now_local ();
+	g_assert (datetime != NULL);
 
-	gchar *date = g_malloc (18);
-	tm  = time (NULL);
-	ptr = localtime (&tm);
-	strftime (date, 18, "%Y-%m-%d-%H%M%S", ptr);
+	if (window) {
+		if (window->priv->datetime)
+			g_date_time_unref (window->priv->datetime);
+		window->priv->datetime = g_date_time_ref (datetime);
+	}
+
+	string = g_date_time_format (datetime, "%Y-%m-%d-%H%M%S");
+	g_date_time_unref (datetime);
 
-	return date;
+	return string;
 }
 
 static gboolean
@@ -1591,8 +1602,6 @@ record_start (gpointer user_data)
 
 	g_assert (window->priv->tick_id == 0);
 
-	g_free (window->priv->filename);
-	window->priv->filename = gsr_generate_filename ();
 	gtk_label_set_text (GTK_LABEL (window->priv->name_label),
 						window->priv->filename);
 	title = g_strdup_printf (_("%s â Sound Recorder"),



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