[grilo-plugins] bookmarks: Fix updating bookmarks
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] bookmarks: Fix updating bookmarks
- Date: Tue, 14 Oct 2014 17:56:00 +0000 (UTC)
commit a85c242337e90eef5bc9fa272f8f43853deae322
Author: Bastien Nocera <hadess hadess net>
Date: Tue Oct 14 19:32:10 2014 +0200
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.
src/bookmarks/grl-bookmarks.c | 39 ++++++++++++++++++++++++++++++++++-----
1 files changed, 34 insertions(+), 5 deletions(-)
---
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]