diff options
author | Iulian Radu <iulian.radu67@gmail.com> | 2017-03-31 17:43:35 +0300 |
---|---|---|
committer | Iulian Radu <iulian.radu67@gmail.com> | 2017-04-01 10:21:21 +0300 |
commit | aa05f49d5d987c5358c5f0ebddcb33c815625093 (patch) | |
tree | 7bf83fddb090d76a53c6e6a5f43e2c79b545f94c | |
parent | c9a5d2d41e2680fc6cff23ec1f91e17b7ddfc1d3 (diff) | |
download | epiphany-aa05f49d5d987c5358c5f0ebddcb33c815625093.tar.gz |
bookmarks: Fix problem causing bookmarks to disappear after an import
This fixes some bugs mainly related to importing bookmarks from Firefox.
In ephy_bookmarks_manager_add_bookmarks(), g_sequence_lookup()
was called on an unsorted sequence, which caused the function
to fail and not add bookmarks to the manager. Besides that, the compare
function used for various GSequence operations did not treat the
case where the time_added was equal for both bookmarks.
https://bugzilla.gnome.org/show_bug.cgi?id=780564
-rw-r--r-- | src/bookmarks/ephy-bookmark.c | 22 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark.h | 4 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-manager.c | 52 |
3 files changed, 50 insertions, 28 deletions
diff --git a/src/bookmarks/ephy-bookmark.c b/src/bookmarks/ephy-bookmark.c index 509276c22..ff0239b9f 100644 --- a/src/bookmarks/ephy-bookmark.c +++ b/src/bookmarks/ephy-bookmark.c @@ -490,19 +490,35 @@ ephy_bookmark_get_tags (EphyBookmark *self) } int -ephy_bookmark_bookmarks_sort_func (EphyBookmark *bookmark1, - EphyBookmark *bookmark2) +ephy_bookmark_bookmarks_compare_func (EphyBookmark *bookmark1, + EphyBookmark *bookmark2) { gint64 time1; gint64 time2; + const char *title1; + const char *title2; + int title_result; + const char *id1; + const char *id2; g_assert (EPHY_IS_BOOKMARK (bookmark1)); g_assert (EPHY_IS_BOOKMARK (bookmark2)); time1 = ephy_bookmark_get_time_added (bookmark1); time2 = ephy_bookmark_get_time_added (bookmark2); + if (time2 - time1 != 0) + return time2 - time1; - return time2 - time1; + title1 = ephy_bookmark_get_title (bookmark1); + title2 = ephy_bookmark_get_title (bookmark2); + title_result = g_strcmp0 (title1, title2); + if (title_result != 0) + return title_result; + + id1 = ephy_bookmark_get_id (bookmark1); + id2 = ephy_bookmark_get_id (bookmark2); + + return g_strcmp0 (id1, id2); } int diff --git a/src/bookmarks/ephy-bookmark.h b/src/bookmarks/ephy-bookmark.h index 8ce771eac..1f49f0433 100644 --- a/src/bookmarks/ephy-bookmark.h +++ b/src/bookmarks/ephy-bookmark.h @@ -65,8 +65,8 @@ gboolean ephy_bookmark_has_tag (EphyBookmark *self, const char *tag); GSequence *ephy_bookmark_get_tags (EphyBookmark *self); -int ephy_bookmark_bookmarks_sort_func (EphyBookmark *bookmark1, - EphyBookmark *bookmark2); +int ephy_bookmark_bookmarks_compare_func (EphyBookmark *bookmark1, + EphyBookmark *bookmark2); int ephy_bookmark_tags_compare (const char *tag1, const char *tag2); diff --git a/src/bookmarks/ephy-bookmarks-manager.c b/src/bookmarks/ephy-bookmarks-manager.c index b1be99195..c6ab5c681 100644 --- a/src/bookmarks/ephy-bookmarks-manager.c +++ b/src/bookmarks/ephy-bookmarks-manager.c @@ -285,30 +285,41 @@ ephy_bookmarks_manager_unwatch_bookmark (EphyBookmarksManager *self, g_signal_handlers_disconnect_by_func (bookmark, bookmark_tag_removed_cb, self); } +static GSequenceIter * +ephy_bookmarks_search_and_insert_bookmark (GSequence *bookmarks, + EphyBookmark *bookmark) +{ + GSequenceIter *iter; + GSequenceIter *prev_iter; + + iter = g_sequence_search (bookmarks, bookmark, + (GCompareDataFunc)ephy_bookmark_bookmarks_compare_func, + NULL); + + prev_iter = g_sequence_iter_prev (iter); + if (g_sequence_iter_is_end (prev_iter) + || ephy_bookmark_bookmarks_compare_func (g_sequence_get (prev_iter), bookmark) != 0) { + return g_sequence_insert_before (iter, bookmark); + } + + return NULL; +} + void ephy_bookmarks_manager_add_bookmark (EphyBookmarksManager *self, EphyBookmark *bookmark) { GSequenceIter *iter; - GSequenceIter *prev_iter; gint position; g_return_if_fail (EPHY_IS_BOOKMARKS_MANAGER (self)); g_return_if_fail (EPHY_IS_BOOKMARK (bookmark)); - iter = g_sequence_search (self->bookmarks, - bookmark, - (GCompareDataFunc)ephy_bookmark_bookmarks_sort_func, - NULL); - - prev_iter = g_sequence_iter_prev (iter); - if (g_sequence_iter_is_end (prev_iter) - || ephy_bookmark_get_time_added (g_sequence_get (prev_iter)) != ephy_bookmark_get_time_added (bookmark)) { - g_sequence_insert_before (iter, bookmark); - + iter = ephy_bookmarks_search_and_insert_bookmark (self->bookmarks, bookmark); + if (iter) { /* Update list */ position = g_sequence_iter_get_position (iter); - g_list_model_items_changed (G_LIST_MODEL (self), position - 1, 0, 1); + g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1); g_signal_emit (self, signals[BOOKMARK_ADDED], 0, bookmark); @@ -324,6 +335,7 @@ ephy_bookmarks_manager_add_bookmarks (EphyBookmarksManager *self, GSequence *bookmarks) { GSequenceIter *iter; + GSequenceIter *new_iter; g_return_if_fail (EPHY_IS_BOOKMARKS_MANAGER (self)); g_return_if_fail (bookmarks != NULL); @@ -333,20 +345,14 @@ ephy_bookmarks_manager_add_bookmarks (EphyBookmarksManager *self, iter = g_sequence_iter_next (iter)) { EphyBookmark *bookmark = g_sequence_get (iter); - if (!g_sequence_lookup (self->bookmarks, - bookmark, - (GCompareDataFunc)ephy_bookmark_bookmarks_sort_func, - NULL)) { - g_sequence_prepend (self->bookmarks, g_object_ref (bookmark)); + new_iter = ephy_bookmarks_search_and_insert_bookmark (self->bookmarks, + g_object_ref (bookmark)); + if (new_iter) { g_signal_emit (self, signals[BOOKMARK_ADDED], 0, bookmark); ephy_bookmarks_manager_watch_bookmark (self, bookmark); } } - g_sequence_sort (self->bookmarks, - (GCompareDataFunc)ephy_bookmark_bookmarks_sort_func, - NULL); - ephy_bookmarks_manager_save_to_file_async (self, NULL, (GAsyncReadyCallback)ephy_bookmarks_manager_save_to_file_warn_on_error_cb, NULL); @@ -525,7 +531,7 @@ ephy_bookmarks_manager_get_bookmarks_with_tag (EphyBookmarksManager *self, if (g_sequence_is_empty (ephy_bookmark_get_tags (bookmark))) { g_sequence_insert_sorted (bookmarks, g_object_ref (bookmark), - (GCompareDataFunc)ephy_bookmark_bookmarks_sort_func, + (GCompareDataFunc)ephy_bookmark_bookmarks_compare_func, NULL); } } @@ -538,7 +544,7 @@ ephy_bookmarks_manager_get_bookmarks_with_tag (EphyBookmarksManager *self, if (ephy_bookmark_has_tag (bookmark, tag)) g_sequence_insert_sorted (bookmarks, g_object_ref (bookmark), - (GCompareDataFunc)ephy_bookmark_bookmarks_sort_func, + (GCompareDataFunc)ephy_bookmark_bookmarks_compare_func, NULL); } } |