[totem/wip/hadess/starttime: 4/4] main: Also save unconsumed "start times" to the session playlist



commit f6a3d39eefb3deb4c3899aa2707827024e937bee
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Feb 17 02:37:53 2019 +0100

    main: Also save unconsumed "start times" to the session playlist
    
    One thing though, TOTEM_PL_PARSER_FIELD_STARTTIME is defined as being
    "parseable by totem_pl_parser_parse_duration() and this function returns
    seconds. So make totem_playlist_save_session_playlist() consume seconds.

 src/totem-playlist.c | 31 ++++++++++++++++++-------------
 src/totem-session.c  |  2 +-
 2 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/src/totem-playlist.c b/src/totem-playlist.c
index 8f3e617fd..27db471ca 100644
--- a/src/totem-playlist.c
+++ b/src/totem-playlist.c
@@ -269,10 +269,10 @@ totem_playlist_save_iter_foreach (GtkTreeModel *model,
 {
        TotemPlPlaylist *playlist = user_data;
        TotemPlPlaylistIter pl_iter;
-       gchar *uri, *title, *subtitle_uri, *mime_type;
+       gchar *uri, *title, *subtitle_uri, *mime_type, *starttime_str;
        TotemPlaylistStatus status;
        gboolean custom_title;
-       const char *starttime;
+       gint64 starttime;
 
        gtk_tree_model_get (model, iter,
                            URI_COL, &uri,
@@ -281,12 +281,20 @@ totem_playlist_save_iter_foreach (GtkTreeModel *model,
                            SUBTITLE_URI_COL, &subtitle_uri,
                            PLAYING_COL, &status,
                            MIME_TYPE_COL, &mime_type,
+                           STARTTIME_COL, &starttime,
                            -1);
 
-       if (status != TOTEM_PLAYLIST_STATUS_NONE)
-               starttime = g_object_get_data (G_OBJECT (playlist), "starttime");
-       else
-               starttime = NULL;
+       /* Prefer the current position for the starttime, if one is passed */
+       starttime_str = NULL;
+       if (status != TOTEM_PLAYLIST_STATUS_NONE) {
+               gint64 new_starttime;
+
+               new_starttime = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (playlist), "starttime"));
+               if (new_starttime != 0)
+                       starttime = new_starttime;
+       }
+       if (starttime != 0)
+               starttime_str = g_strdup_printf ("%" G_GINT64_FORMAT, starttime);
 
        totem_pl_playlist_append (playlist, &pl_iter);
        totem_pl_playlist_set (playlist, &pl_iter,
@@ -295,13 +303,14 @@ totem_playlist_save_iter_foreach (GtkTreeModel *model,
                               TOTEM_PL_PARSER_FIELD_SUBTITLE_URI, subtitle_uri,
                               TOTEM_PL_PARSER_FIELD_PLAYING, status != TOTEM_PLAYLIST_STATUS_NONE ? "true" : 
"",
                               TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, mime_type,
-                              TOTEM_PL_PARSER_FIELD_STARTTIME, starttime,
+                              TOTEM_PL_PARSER_FIELD_STARTTIME, starttime_str,
                               NULL);
 
        g_free (uri);
        g_free (title);
        g_free (subtitle_uri);
        g_free (mime_type);
+       g_free (starttime_str);
 
        return FALSE;
 }
@@ -327,12 +336,8 @@ totem_playlist_save_session_playlist (TotemPlaylist *playlist,
 
        pl_playlist = totem_pl_playlist_new ();
 
-       if (starttime > 0) {
-               char *starttime_msec;
-
-               starttime_msec = g_strdup_printf ("%" G_GINT64_FORMAT, starttime);
-               g_object_set_data_full (G_OBJECT (pl_playlist), "starttime", starttime_msec, g_free);
-       }
+       if (starttime > 0)
+               g_object_set_data (G_OBJECT (pl_playlist), "starttime", GINT_TO_POINTER (starttime));
 
        gtk_tree_model_foreach (playlist->priv->model,
                                totem_playlist_save_iter_foreach,
diff --git a/src/totem-session.c b/src/totem-session.c
index bcc64dfaa..6e2c5a2b0 100644
--- a/src/totem-session.c
+++ b/src/totem-session.c
@@ -102,7 +102,7 @@ totem_session_save (Totem *totem)
        file = get_session_file ();
        if (!totem_playing_dvd (totem->mrl))
                curr = bacon_video_widget_get_current_time (totem->bvw);
-       totem_playlist_save_session_playlist (totem->playlist, file, curr);
+       totem_playlist_save_session_playlist (totem->playlist, file, curr / 1000);
 }
 
 void


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