summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-24 19:00:02 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-24 19:00:02 +0300
commit1480fff5e633d9a2d0c8cb1efb2fd517e2c25a99 (patch)
tree16a8aef0406737632e7d04475754b4cd7444bd8b
parent286a707693f3ac4695279291482a7f142863b452 (diff)
Bookmarks: Export page uses folders
-rw-r--r--src/bookmarks.c42
-rw-r--r--src/bookmarks.h1
2 files changed, 35 insertions, 8 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index f7691655..35e16d9a 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -462,6 +462,16 @@ const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp,
462 return list; 462 return list;
463} 463}
464 464
465size_t count_Bookmarks(const iBookmarks *d) {
466 size_t n = 0;
467 iConstForEach(Hash, i, &d->bookmarks) {
468 if (!isFolder_Bookmark((const iBookmark *) i.value)) {
469 n++;
470 }
471 }
472 return n;
473}
474
465const iString *bookmarkListPage_Bookmarks(const iBookmarks *d, enum iBookmarkListType listType) { 475const iString *bookmarkListPage_Bookmarks(const iBookmarks *d, enum iBookmarkListType listType) {
466 iString *str = collectNew_String(); 476 iString *str = collectNew_String();
467 lock_Mutex(d->mtx); 477 lock_Mutex(d->mtx);
@@ -474,21 +484,37 @@ const iString *bookmarkListPage_Bookmarks(const iBookmarks *d, enum iBookmarkLis
474 appendFormat_String(str, 484 appendFormat_String(str,
475 "%s\n\n" 485 "%s\n\n"
476 "${bookmark.export.saving}\n\n", 486 "${bookmark.export.saving}\n\n",
477 formatCStrs_Lang("bookmark.export.count.n", size_Hash(&d->bookmarks))); 487 formatCStrs_Lang("bookmark.export.count.n", count_Bookmarks(d)));
478 } 488 }
479 else if (listType == listByTag_BookmarkListType) { 489 else if (listType == listByTag_BookmarkListType) {
480 appendFormat_String(str, "${bookmark.export.taginfo}\n\n"); 490 appendFormat_String(str, "${bookmark.export.taginfo}\n\n");
481 } 491 }
482 iStringSet *tags = new_StringSet(); 492 iStringSet *tags = new_StringSet();
483 const iPtrArray *bmList = list_Bookmarks(d, 493 const iPtrArray *bmList =
484 listType == listByCreationTime_BookmarkListType 494 list_Bookmarks(d,
485 ? cmpTimeDescending_Bookmark_ 495 listType == listByCreationTime_BookmarkListType ? cmpTimeDescending_Bookmark_
486 : cmpTitleAscending_Bookmark, 496 : listType == listByTag_BookmarkListType ? cmpTitleAscending_Bookmark
487 NULL, 497 : cmpTree_Bookmark,
488 NULL); 498 NULL, NULL);
499 if (listType == listByFolder_BookmarkListType) {
500 iConstForEach(PtrArray, i, bmList) {
501 const iBookmark *bm = i.ptr;
502 if (!isFolder_Bookmark(bm) && !bm->parentId) {
503 appendFormat_String(str, "=> %s %s\n", cstr_String(&bm->url), cstr_String(&bm->title));
504 }
505 }
506 }
489 iConstForEach(PtrArray, i, bmList) { 507 iConstForEach(PtrArray, i, bmList) {
490 const iBookmark *bm = i.ptr; 508 const iBookmark *bm = i.ptr;
491 if (listType == listByFolder_BookmarkListType) { 509 if (isFolder_Bookmark(bm)) {
510 if (listType == listByFolder_BookmarkListType) {
511 const int depth = depth_Bookmark(bm);
512 appendFormat_String(str, "\n%s %s\n",
513 depth == 0 ? "##" : "###", cstr_String(&bm->title));
514 }
515 continue;
516 }
517 if (listType == listByFolder_BookmarkListType && bm->parentId) {
492 appendFormat_String(str, "=> %s %s\n", cstr_String(&bm->url), cstr_String(&bm->title)); 518 appendFormat_String(str, "=> %s %s\n", cstr_String(&bm->url), cstr_String(&bm->title));
493 } 519 }
494 else if (listType == listByCreationTime_BookmarkListType) { 520 else if (listType == listByCreationTime_BookmarkListType) {
diff --git a/src/bookmarks.h b/src/bookmarks.h
index 40170062..61a5c102 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -56,6 +56,7 @@ struct Impl_Bookmark {
56iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } 56iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; }
57iLocalDef iBool isFolder_Bookmark (const iBookmark *d) { return isEmpty_String(&d->url); } 57iLocalDef iBool isFolder_Bookmark (const iBookmark *d) { return isEmpty_String(&d->url); }
58 58
59int depth_Bookmark (const iBookmark *);
59iBool hasTag_Bookmark (const iBookmark *, const char *tag); 60iBool hasTag_Bookmark (const iBookmark *, const char *tag);
60void addTag_Bookmark (iBookmark *, const char *tag); 61void addTag_Bookmark (iBookmark *, const char *tag);
61void removeTag_Bookmark (iBookmark *, const char *tag); 62void removeTag_Bookmark (iBookmark *, const char *tag);