[epiphany] ephy-bookmark: Add ephy_bookmark_generate_random_id()
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] ephy-bookmark: Add ephy_bookmark_generate_random_id()
- Date: Tue, 28 Jan 2020 20:05:54 +0000 (UTC)
commit f67101b09eff0b2f1d4e217a57720128636a82f5
Author: Yetizone <andreii lisita gmail com>
Date: Tue Jan 28 21:28:33 2020 +0200
ephy-bookmark: Add ephy_bookmark_generate_random_id()
src/bookmarks/ephy-bookmark.c | 21 +++++++++++++++++++++
src/bookmarks/ephy-bookmark.h | 1 +
2 files changed, 22 insertions(+)
---
diff --git a/src/bookmarks/ephy-bookmark.c b/src/bookmarks/ephy-bookmark.c
index 5d84213ef..0185377cb 100644
--- a/src/bookmarks/ephy-bookmark.c
+++ b/src/bookmarks/ephy-bookmark.c
@@ -22,7 +22,9 @@
#include "ephy-bookmark.h"
#include "ephy-bookmarks-manager.h"
+#include "ephy-shell.h"
#include "ephy-synchronizable.h"
+#include "ephy-sync-utils.h"
#include <string.h>
@@ -517,6 +519,25 @@ ephy_bookmark_tags_compare (const char *tag1,
return result;
}
+char *
+ephy_bookmark_generate_random_id (void)
+{
+ char *id = NULL;
+ EphyBookmarksManager *manager;
+
+ manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
+
+ while (!id) {
+ id = ephy_sync_utils_get_random_sync_id ();
+
+ /* Check if the generated id isn't used already. */
+ if (ephy_bookmarks_manager_get_bookmark_by_id (manager, id))
+ g_clear_pointer (&id, g_free);
+ }
+
+ return id;
+}
+
static JsonNode *
serializable_serialize_property (JsonSerializable *serializable,
const char *name,
diff --git a/src/bookmarks/ephy-bookmark.h b/src/bookmarks/ephy-bookmark.h
index f8504db38..3231234c4 100644
--- a/src/bookmarks/ephy-bookmark.h
+++ b/src/bookmarks/ephy-bookmark.h
@@ -59,5 +59,6 @@ int ephy_bookmark_bookmarks_compare_func (EphyBookmark *bookmar
EphyBookmark *bookmark2);
int ephy_bookmark_tags_compare (const char *tag1,
const char *tag2);
+char *ephy_bookmark_generate_random_id (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]