mirror of
https://github.com/dguglielmi/sunny-overlay.git
synced 2025-12-06 13:52:40 +01:00
77 lines
2.5 KiB
Diff
77 lines
2.5 KiB
Diff
From a85c242337e90eef5bc9fa272f8f43853deae322 Mon Sep 17 00:00:00 2001
|
|
From: Bastien Nocera <hadess@hadess.net>
|
|
Date: Tue, 14 Oct 2014 19:32:10 +0200
|
|
Subject: bookmarks: Fix updating bookmarks
|
|
|
|
Our use of gom meant that we always ended up with a new item instead of
|
|
updating an existing one. We need to load the item from the DB to be
|
|
able to offer that.
|
|
|
|
diff --git a/src/bookmarks/grl-bookmarks.c b/src/bookmarks/grl-bookmarks.c
|
|
index b6b49f6..77ff593 100644
|
|
--- a/src/bookmarks/grl-bookmarks.c
|
|
+++ b/src/bookmarks/grl-bookmarks.c
|
|
@@ -635,6 +635,31 @@ remove_bookmark (GrlBookmarksSource *bookmarks_source,
|
|
}
|
|
}
|
|
|
|
+static GomResource *
|
|
+find_resource (const gchar *id,
|
|
+ GomRepository *repository)
|
|
+{
|
|
+ GomResource *resource;
|
|
+ GomFilter *filter;
|
|
+ GValue value = { 0, };
|
|
+
|
|
+ if (id == NULL)
|
|
+ return NULL;
|
|
+
|
|
+ g_value_init(&value, G_TYPE_INT64);
|
|
+ g_value_set_int64 (&value, g_ascii_strtoll (id, NULL, 0));
|
|
+ filter = gom_filter_new_eq (BOOKMARKS_TYPE_RESOURCE, "id", &value);
|
|
+ g_value_unset(&value);
|
|
+
|
|
+ resource = gom_repository_find_one_sync (repository,
|
|
+ BOOKMARKS_TYPE_RESOURCE,
|
|
+ filter,
|
|
+ NULL);
|
|
+ g_object_unref (filter);
|
|
+
|
|
+ return resource;
|
|
+}
|
|
+
|
|
static void
|
|
store_bookmark (GrlBookmarksSource *bookmarks_source,
|
|
GList **keylist,
|
|
@@ -659,6 +684,7 @@ store_bookmark (GrlBookmarksSource *bookmarks_source,
|
|
|
|
GRL_DEBUG ("store_bookmark");
|
|
|
|
+ str_id = (gchar *) grl_media_get_id (bookmark);
|
|
title = grl_media_get_title (bookmark);
|
|
url = grl_media_get_url (bookmark);
|
|
thumb = grl_media_get_thumbnail (bookmark);
|
|
@@ -684,11 +710,14 @@ store_bookmark (GrlBookmarksSource *bookmarks_source,
|
|
type = BOOKMARK_TYPE_STREAM;
|
|
}
|
|
|
|
- resource = g_object_new (BOOKMARKS_TYPE_RESOURCE,
|
|
- "repository", bookmarks_source->priv->repository,
|
|
- "parent", parent_id,
|
|
- "type", type,
|
|
- NULL);
|
|
+ resource = find_resource (str_id, bookmarks_source->priv->repository);
|
|
+ if (!resource) {
|
|
+ resource = g_object_new (BOOKMARKS_TYPE_RESOURCE,
|
|
+ "repository", bookmarks_source->priv->repository,
|
|
+ "parent", parent_id,
|
|
+ "type", type,
|
|
+ NULL);
|
|
+ }
|
|
|
|
if (type == BOOKMARK_TYPE_STREAM) {
|
|
g_object_set (G_OBJECT (resource), "url", url, NULL);
|
|
--
|
|
cgit v0.10.2
|
|
|