[totem/wip/hadess/starttime: 3/4] main: Use new starttime column in playlist



commit 539960db4042d55e9ab1f35454f27785c585ea1e
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Feb 16 23:12:06 2019 +0100

    main: Use new starttime column in playlist
    
    First, to reimplement the "starttime" session restore. This handily
    removes a variable in the TotemObject. Then use it to implement
    starttime from any playlist.
    
    Closes: #10

 src/totem-object.c   | 25 ++++++++++++++-----------
 src/totem-playlist.c | 28 +---------------------------
 src/totem-playlist.h |  3 +--
 src/totem-private.h  |  1 -
 src/totem-session.c  |  4 +++-
 5 files changed, 19 insertions(+), 42 deletions(-)
---
diff --git a/src/totem-object.c b/src/totem-object.c
index 11478214d..879fd1874 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -1819,7 +1819,6 @@ totem_object_set_mrl (TotemObject *totem,
                      const char *subtitle)
 {
        if (totem->mrl != NULL) {
-               totem->seek_to_start = 0;
                totem->pause_start = FALSE;
 
                g_clear_pointer (&totem->mrl, g_free);
@@ -2458,7 +2457,7 @@ on_error_event (BaconVideoWidget *bvw, char *message,
 {
        /* Clear the seek if it's there, we only want to try and seek
         * the first file, even if it's not there */
-       totem->seek_to_start = 0;
+       totem_playlist_steal_current_starttime (totem->playlist);
        totem->pause_start = FALSE;
 
        if (playback_stopped)
@@ -2494,27 +2493,31 @@ static void
 update_seekable (TotemObject *totem)
 {
        gboolean seekable;
+       gboolean notify;
 
        seekable = bacon_video_widget_is_seekable (totem->bvw);
-       if (totem->seekable == seekable)
-               return;
+       notify = (totem->seekable == seekable);
        totem->seekable = seekable;
 
        /* Check if the stream is seekable */
        gtk_widget_set_sensitive (totem->seek, seekable);
 
-       /* This is for the session restore and the position saving
-        * to seek to the saved time */
        if (seekable != FALSE) {
-               if (totem->seek_to_start != 0) {
+               gint64 starttime;
+
+               starttime = totem_playlist_steal_current_starttime (totem->playlist);
+               if (starttime != 0) {
                        bacon_video_widget_seek_time (totem->bvw,
-                                                     totem->seek_to_start, FALSE, NULL);
-                       totem_object_pause (totem);
+                                                     starttime * 1000, FALSE, NULL);
+                       if (totem->pause_start) {
+                               totem_object_pause (totem);
+                               totem->pause_start = FALSE;
+                       }
                }
        }
-       totem->seek_to_start = 0;
 
-       g_object_notify (G_OBJECT (totem), "seekable");
+       if (notify)
+               g_object_notify (G_OBJECT (totem), "seekable");
 }
 
 static void
diff --git a/src/totem-playlist.c b/src/totem-playlist.c
index 7666c0e19..8f3e617fd 100644
--- a/src/totem-playlist.c
+++ b/src/totem-playlist.c
@@ -77,9 +77,6 @@ struct TotemPlaylistPrivate
        GSettings *settings;
        GSettings *lockdown_settings;
 
-       /* Current time in the track */
-       char *starttime;
-
        /* This is a scratch list for when we're removing files */
        GList *list;
        guint current_to_be_removed : 1;
@@ -756,10 +753,6 @@ totem_playlist_entry_parsed (TotemPlParser *parser,
        starttime_str = g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_STARTTIME);
        starttime = totem_pl_parser_parse_duration (starttime_str, FALSE);
        starttime = MAX (starttime, 0);
-       if (starttime_str != NULL && playing) {
-               g_free (playlist->priv->starttime);
-               playlist->priv->starttime = g_strdup (starttime_str);
-       }
        totem_playlist_add_one_mrl (playlist, uri, title, content_type, subtitle_uri, starttime, playing);
 }
 
@@ -803,7 +796,6 @@ totem_playlist_dispose (GObject *object)
        TotemPlaylist *playlist = TOTEM_PLAYLIST (object);
 
        g_clear_object (&playlist->priv->parser);
-       g_clear_pointer (&playlist->priv->starttime, g_free);
        g_clear_object (&playlist->priv->settings);
        g_clear_object (&playlist->priv->lockdown_settings);
        g_clear_pointer (&playlist->priv->current, gtk_tree_path_free);
@@ -1074,28 +1066,14 @@ totem_playlist_add_mrl_finish (TotemPlaylist *playlist, GAsyncResult *result, GE
        return FALSE;
 }
 
-static gint64
-parse_starttime (TotemPlaylist *playlist)
-{
-       gint64 ret;
-
-       if (playlist->priv->starttime == NULL)
-               return 0;
-       ret = g_ascii_strtoll (playlist->priv->starttime, NULL, 0);
-
-       return ret;
-}
-
 gboolean
 totem_playlist_add_mrl_sync (TotemPlaylist *playlist,
-                            const char    *mrl,
-                            gint64        *starttime)
+                            const char    *mrl)
 {
        GtkTreeIter iter;
        gboolean ret;
 
        g_return_val_if_fail (mrl != NULL, FALSE);
-       g_return_val_if_fail (starttime != NULL, FALSE);
 
        ret = handle_parse_result (totem_pl_parser_parse (playlist->priv->parser, mrl, FALSE), playlist, mrl, 
NULL, NULL);
        if (!ret)
@@ -1112,10 +1090,6 @@ totem_playlist_add_mrl_sync (TotemPlaylist *playlist,
                if (status == TOTEM_PLAYLIST_STATUS_PAUSED) {
                        gtk_tree_path_free (playlist->priv->current);
                        playlist->priv->current = gtk_tree_model_get_path (playlist->priv->model, &iter);
-
-                       *starttime = parse_starttime (playlist->priv->starttime);
-                       g_clear_pointer (&playlist->priv->starttime, g_free);
-
                        break;
                }
                ret = gtk_tree_model_iter_next (playlist->priv->model, &iter);
diff --git a/src/totem-playlist.h b/src/totem-playlist.h
index 13dc1e378..853a0ab32 100644
--- a/src/totem-playlist.h
+++ b/src/totem-playlist.h
@@ -96,8 +96,7 @@ gboolean totem_playlist_add_mrl_finish (TotemPlaylist *playlist,
                                         GAsyncResult  *result,
                                         GError       **error);
 gboolean totem_playlist_add_mrl_sync (TotemPlaylist *playlist,
-                                      const char *mrl,
-                                      gint64 *starttime);
+                                      const char *mrl);
 
 typedef struct TotemPlaylistMrlData TotemPlaylistMrlData;
 
diff --git a/src/totem-private.h b/src/totem-private.h
index d574da284..8e228b166 100644
--- a/src/totem-private.h
+++ b/src/totem-private.h
@@ -122,7 +122,6 @@ struct _TotemObject {
        gboolean drives_changed;
 
        /* session */
-       gint64 seek_to_start;
        gboolean pause_start;
        guint save_timeout_id;
 
diff --git a/src/totem-session.c b/src/totem-session.c
index ed4caa50c..bcc64dfaa 100644
--- a/src/totem-session.c
+++ b/src/totem-session.c
@@ -57,11 +57,13 @@ totem_session_try_restore (Totem *totem)
        char *mrl, *subtitle;
 
        totem_signal_block_by_data (totem->playlist, totem);
+       totem->pause_start = TRUE;
 
        /* Possibly the only place in Totem where it makes sense to add an MRL to the playlist synchronously, 
since we haven't yet entered
         * the GTK+ main loop, and thus can't freeze the application. */
        uri = get_session_filename ();
-       if (totem_playlist_add_mrl_sync (totem->playlist, uri, &totem->seek_to_start) == FALSE) {
+       if (totem_playlist_add_mrl_sync (totem->playlist, uri) == FALSE) {
+               totem->pause_start = FALSE;
                totem_signal_unblock_by_data (totem->playlist, totem);
                totem_object_set_mrl (totem, NULL, NULL);
                g_free (uri);


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