diff options
| author | Bastien Nocera <hadess@hadess.net> | 2014-10-14 17:32:10 (GMT) |
|---|---|---|
| committer | Bastien Nocera <hadess@hadess.net> | 2014-10-14 17:32:10 (GMT) |
| commit | a85c242337e90eef5bc9fa272f8f43853deae322 (patch) | |
| tree | a4f049576946493db72a0cfd4a333b23220c74bc | |
| parent | 734936dbe166526a1e2ebdc1ffebbab64b2216ee (diff) | |
| download | grilo-plugins-a85c242337e90eef5bc9fa272f8f43853deae322.zip grilo-plugins-a85c242337e90eef5bc9fa272f8f43853deae322.tar.xz | |
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.
| -rw-r--r-- | 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); |
