[totem/wip/hadess/session-save: 2/2] main: Saving playlist asynchronously
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/hadess/session-save: 2/2] main: Saving playlist asynchronously
- Date: Thu, 27 Feb 2020 18:21:53 +0000 (UTC)
commit f62d51ad30b58c9f9397f37d236ab1a6c6f37eab
Author: Bastien Nocera <hadess hadess net>
Date: Thu Feb 27 18:15:29 2020 +0100
main: Saving playlist asynchronously
src/totem-playlist.c | 52 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 37 insertions(+), 15 deletions(-)
---
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]