[totem/wip/hadess/session-save: 1/2] main: Saving playlist asynchronously



commit 8ceaf80e715cfacd4e210a70cc0317f57c222743
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Feb 27 18:15:29 2020 +0100

    main: Saving playlist asynchronously

 meson.build          |  2 +-
 src/totem-playlist.c | 52 +++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/meson.build b/meson.build
index ec44bbf23..50a5a2f4a 100644
--- a/meson.build
+++ b/meson.build
@@ -128,7 +128,7 @@ gtk_req_version = '>= 3.22.0'
 gst_req_version = '>= 1.6.0'
 grilo_req_version = '>= 0.3.0'
 peas_req_version = '>= 1.1.0'
-totem_plparser_req_version = '>= 3.26.4'
+totem_plparser_req_version = '>= 3.26.5'
 
 glib_dep =  dependency('glib-2.0', version: glib_req_version)
 gobject_dep =  dependency('gobject-2.0', version: glib_req_version)
diff --git a/src/totem-playlist.c b/src/totem-playlist.c
index 6d01a12df..92453fd23 100644
--- a/src/totem-playlist.c
+++ b/src/totem-playlist.c
@@ -315,14 +315,39 @@ totem_playlist_save_iter_foreach (GtkTreeModel *model,
        return FALSE;
 }
 
+static void
+totem_playlist_save_session_playlist_cb (GObject       *source_object,
+                                        GAsyncResult  *res,
+                                        gpointer       user_data)
+{
+       g_autoptr(GError) error = NULL;
+       gboolean ret;
+
+       ret = totem_pl_parser_save_finish (TOTEM_PL_PARSER (source_object),
+                                          res, &error);
+       if (!ret && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+               g_warning ("Failed to save the session playlist: %s", error->message);
+}
+
+static void
+totem_playlist_delete_session_playlist_cb (GObject       *source_object,
+                                          GAsyncResult  *res,
+                                          gpointer       user_data)
+{
+       g_autoptr(GError) error = NULL;
+       gboolean ret;
+
+       ret = g_file_delete_finish (G_FILE (source_object), res, &error);
+       if (!ret && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+               g_warning ("Failed to delete session playlist: %s", error->message);
+}
+
 void
 totem_playlist_save_session_playlist (TotemPlaylist *playlist,
                                      GFile         *output,
                                      gint64         starttime)
 {
-       TotemPlPlaylist *pl_playlist;
-       GError *error = NULL;
-       gboolean retval;
+       g_autoptr(TotemPlPlaylist) pl_playlist = NULL;
 
        if (playlist->priv->disable_save_to_disk) {
                /* On lockdown, we do not touch the disk,
@@ -330,7 +355,7 @@ totem_playlist_save_session_playlist (TotemPlaylist *playlist,
                return;
        }
        if (PL_LEN == 0) {
-               g_file_delete (output, NULL, NULL);
+               g_file_delete_async (output, 0, NULL, totem_playlist_delete_session_playlist_cb, NULL);
                return;
        }
 
@@ -343,17 +368,14 @@ totem_playlist_save_session_playlist (TotemPlaylist *playlist,
                                totem_playlist_save_iter_foreach,
                                pl_playlist);
 
-       retval = totem_pl_parser_save (playlist->priv->parser,
-                                      pl_playlist,
-                                      output,
-                                      NULL, TOTEM_PL_PARSER_XSPF, &error);
-
-       if (retval == FALSE) {
-               g_warning ("Failed to save the session playlist: %s", error->message);
-               g_error_free (error);
-       }
-
-       g_object_unref (pl_playlist);
+       totem_pl_parser_save_async (playlist->priv->parser,
+                                   pl_playlist,
+                                   output,
+                                   NULL,
+                                   TOTEM_PL_PARSER_XSPF,
+                                   NULL,
+                                   totem_playlist_save_session_playlist_cb,
+                                   NULL);
 }
 
 static void


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