[epiphany/wip/ephy-sync] bookmarks-manager: Add function to get bookmark by id



commit 24e9e6642dacd548eafa135a1fe50275e54bb185
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Mon Aug 8 21:11:34 2016 +0300

    bookmarks-manager: Add function to get bookmark by id

 src/ephy-bookmarks-manager.c |   32 ++++++++++++++++++++++++++++++++
 src/ephy-bookmarks-manager.h |    2 ++
 2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c
index fb15106..e16c969 100644
--- a/src/ephy-bookmarks-manager.c
+++ b/src/ephy-bookmarks-manager.c
@@ -304,6 +304,38 @@ ephy_bookmarks_manager_get_bookmark_by_url (EphyBookmarksManager *self,
   return g_sequence_get (iter);
 }
 
+static int
+bookmark_with_id_compare (gpointer      *ebookmark,
+                          gconstpointer  id)
+{
+  EphyBookmark *bookmark = EPHY_BOOKMARK (ebookmark);
+  const char *bookmark_id;
+
+  bookmark_id = ephy_bookmark_get_id (bookmark);
+
+  return g_strcmp0 (bookmark_id, id);
+}
+
+EphyBookmark *
+ephy_bookmarks_manager_get_bookmark_by_id (EphyBookmarksManager *self,
+                                           const char           *id)
+{
+  GSequenceIter *iter;
+
+  g_return_val_if_fail (EPHY_IS_BOOKMARKS_MANAGER (self), FALSE);
+  g_return_val_if_fail (id != NULL, FALSE);
+
+  iter = g_sequence_lookup (self->bookmarks,
+                            (gpointer)id,
+                            (GCompareDataFunc)bookmark_with_id_compare,
+                            NULL);
+
+  if (iter == NULL)
+    return NULL;
+
+  return g_sequence_get (iter);
+}
+
 void
 ephy_bookmarks_manager_add_tag (EphyBookmarksManager *self, const char *tag)
 {
diff --git a/src/ephy-bookmarks-manager.h b/src/ephy-bookmarks-manager.h
index 3fae9c5..63d35d4 100644
--- a/src/ephy-bookmarks-manager.h
+++ b/src/ephy-bookmarks-manager.h
@@ -34,6 +34,8 @@ void         ephy_bookmarks_manager_remove_bookmark        (EphyBookmarksManager
                                                             EphyBookmark         *bookmark);
 EphyBookmark *ephy_bookmarks_manager_get_bookmark_by_url   (EphyBookmarksManager *self,
                                                             const char           *url);
+EphyBookmark *ephy_bookmarks_manager_get_bookmark_by_id    (EphyBookmarksManager *self,
+                                                            const char           *id);
 
 void         ephy_bookmarks_manager_add_tag                (EphyBookmarksManager *self,
                                                             const char           *tag);


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