summaryrefslogtreecommitdiff
path: root/src/bookmarks.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bookmarks.c')
-rw-r--r--src/bookmarks.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 616e4632..f7691655 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -79,7 +79,7 @@ static int cmpTimeDescending_Bookmark_(const iBookmark **a, const iBookmark **b)
79 return iCmp(seconds_Time(&(*b)->when), seconds_Time(&(*a)->when)); 79 return iCmp(seconds_Time(&(*b)->when), seconds_Time(&(*a)->when));
80} 80}
81 81
82static int cmpTitleAscending_Bookmark_(const iBookmark **a, const iBookmark **b) { 82int cmpTitleAscending_Bookmark(const iBookmark **a, const iBookmark **b) {
83 return cmpStringCase_String(&(*a)->title, &(*b)->title); 83 return cmpStringCase_String(&(*a)->title, &(*b)->title);
84} 84}
85 85
@@ -250,7 +250,20 @@ static void load_BookmarkLoader(iBookmarkLoader *d, iFile *file) {
250iDefineTypeConstructionArgs(BookmarkLoader, (iBookmarks *b), b) 250iDefineTypeConstructionArgs(BookmarkLoader, (iBookmarks *b), b)
251 251
252/*----------------------------------------------------------------------------------------------*/ 252/*----------------------------------------------------------------------------------------------*/
253 253
254static iBool isMatchingParent_Bookmark_(void *context, const iBookmark *bm) {
255 return bm->parentId == *(const uint32_t *) context;
256}
257
258void sort_Bookmarks(iBookmarks *d, uint32_t parentId, iBookmarksCompareFunc cmp) {
259 lock_Mutex(d->mtx);
260 iConstForEach(PtrArray, i, list_Bookmarks(d, cmp, isMatchingParent_Bookmark_, &parentId)) {
261 iBookmark *bm = i.ptr;
262 bm->order = index_PtrArrayConstIterator(&i) + 1;
263 }
264 unlock_Mutex(d->mtx);
265}
266
254void load_Bookmarks(iBookmarks *d, const char *dirPath) { 267void load_Bookmarks(iBookmarks *d, const char *dirPath) {
255 clear_Bookmarks(d); 268 clear_Bookmarks(d);
256 /* Load new .ini bookmarks, if present. */ 269 /* Load new .ini bookmarks, if present. */
@@ -258,11 +271,8 @@ void load_Bookmarks(iBookmarks *d, const char *dirPath) {
258 if (!open_File(f, readOnly_FileMode | text_FileMode)) { 271 if (!open_File(f, readOnly_FileMode | text_FileMode)) {
259 /* As a fallback, try loading the v1.6 bookmarks file. */ 272 /* As a fallback, try loading the v1.6 bookmarks file. */
260 loadOldFormat_Bookmarks(d, dirPath); 273 loadOldFormat_Bookmarks(d, dirPath);
261 /* Set ordering based on titles. */ 274 /* Old format has an implicit alphabetic sort order. */
262 iConstForEach(PtrArray, i, list_Bookmarks(d, cmpTitleAscending_Bookmark_, NULL, NULL)) { 275 sort_Bookmarks(d, 0, cmpTitleAscending_Bookmark);
263 iBookmark *bm = i.ptr;
264 bm->order = index_PtrArrayConstIterator(&i) + 1;
265 }
266 return; 276 return;
267 } 277 }
268 iBookmarkLoader loader; 278 iBookmarkLoader loader;
@@ -317,7 +327,9 @@ uint32_t add_Bookmarks(iBookmarks *d, const iString *url, const iString *title,
317 iChar icon) { 327 iChar icon) {
318 lock_Mutex(d->mtx); 328 lock_Mutex(d->mtx);
319 iBookmark *bm = new_Bookmark(); 329 iBookmark *bm = new_Bookmark();
320 set_String(&bm->url, canonicalUrl_String(url)); 330 if (url) {
331 set_String(&bm->url, canonicalUrl_String(url));
332 }
321 set_String(&bm->title, title); 333 set_String(&bm->title, title);
322 if (tags) { 334 if (tags) {
323 set_String(&bm->tags, tags); 335 set_String(&bm->tags, tags);
@@ -471,7 +483,7 @@ const iString *bookmarkListPage_Bookmarks(const iBookmarks *d, enum iBookmarkLis
471 const iPtrArray *bmList = list_Bookmarks(d, 483 const iPtrArray *bmList = list_Bookmarks(d,
472 listType == listByCreationTime_BookmarkListType 484 listType == listByCreationTime_BookmarkListType
473 ? cmpTimeDescending_Bookmark_ 485 ? cmpTimeDescending_Bookmark_
474 : cmpTitleAscending_Bookmark_, 486 : cmpTitleAscending_Bookmark,
475 NULL, 487 NULL,
476 NULL); 488 NULL);
477 iConstForEach(PtrArray, i, bmList) { 489 iConstForEach(PtrArray, i, bmList) {