summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-12-17 13:07:58 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-12-17 13:07:58 +0200
commitd8a95f267f4f1865a58cbed15e6b45349e9d2c09 (patch)
tree5501245d7ef1209319a10ad824ac29b33e26a428 /src
parent48ba3598db53f249f3a8bfd577ca95afde52c760 (diff)
Added "about:bookmarks"
A simple way to export all or some of your bookmarks.
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks.c36
-rw-r--r--src/bookmarks.h19
-rw-r--r--src/gmrequest.c4
3 files changed, 52 insertions, 7 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 54b0407f..6d7302c0 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -70,6 +70,10 @@ static int cmpTimeDescending_Bookmark_(const iBookmark **a, const iBookmark **b)
70 return iCmp(seconds_Time(&(*b)->when), seconds_Time(&(*a)->when)); 70 return iCmp(seconds_Time(&(*b)->when), seconds_Time(&(*a)->when));
71} 71}
72 72
73static int cmpTitleAscending_Bookmark_(const iBookmark **a, const iBookmark **b) {
74 return cmpStringCase_String(&(*a)->title, &(*b)->title);
75}
76
73/*----------------------------------------------------------------------------------------------*/ 77/*----------------------------------------------------------------------------------------------*/
74 78
75static const char *fileName_Bookmarks_ = "bookmarks.txt"; 79static const char *fileName_Bookmarks_ = "bookmarks.txt";
@@ -222,3 +226,35 @@ const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp,
222 sort_Array(list, (int (*)(const void *, const void *)) cmp); 226 sort_Array(list, (int (*)(const void *, const void *)) cmp);
223 return list; 227 return list;
224} 228}
229
230const iString *bookmarkListPage_Bookmarks(const iBookmarks *d) {
231 iString *str = collectNew_String();
232 setCStr_String(str, "Here are all your bookmarks. "
233 "You can save this page to export them, or you can copy them to "
234 "the clipboard.\n");
235 lock_Mutex(d->mtx);
236 iConstForEach(PtrArray, i, list_Bookmarks(d, cmpTitleAscending_Bookmark_, NULL, NULL)) {
237 const iBookmark *bm = i.ptr;
238 appendFormat_String(str, "\n=> %s %s\n", cstr_String(&bm->url), cstr_String(&bm->title));
239 iRangecc tag = iNullRange;
240 while (nextSplit_Rangecc(range_String(&bm->tags), " ", &tag)) {
241 if (!isEmpty_Range(&tag)) {
242 appendCStr_String(str, "* ");
243 appendRange_String(str, tag);
244 appendChar_String(str, '\n');
245 }
246 }
247 }
248 unlock_Mutex(d->mtx);
249 appendCStr_String(str,
250 "\nPAGE FORMAT: "
251 "Text lines and preformatted text are comments and should be ignored. "
252 "Each link line represents a bookmark. "
253 "Folder structure is defined by headings. "
254 "All links before the first heading are root level bookmarks. "
255 "Bullet lines following a link are used for tags; each tag gets its own "
256 "bullet line. Quotes are reserved for additional information about a "
257 "bookmark.\n");
258 appendCStr_String(str, "\nLagrange v" LAGRANGE_APP_VERSION "\n");
259 return str;
260}
diff --git a/src/bookmarks.h b/src/bookmarks.h
index 9a1ecba3..4768af9f 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -45,17 +45,20 @@ iBool hasTag_Bookmark (const iBookmark *d, const char *tag);
45void addTag_Bookmark (iBookmark *d, const char *tag); 45void addTag_Bookmark (iBookmark *d, const char *tag);
46void removeTag_Bookmark (iBookmark *d, const char *tag); 46void removeTag_Bookmark (iBookmark *d, const char *tag);
47 47
48/*----------------------------------------------------------------------------------------------*/
49
48iDeclareType(Bookmarks) 50iDeclareType(Bookmarks)
49iDeclareTypeConstruction(Bookmarks) 51iDeclareTypeConstruction(Bookmarks)
50 52
51void clear_Bookmarks (iBookmarks *); 53void clear_Bookmarks (iBookmarks *);
52void load_Bookmarks (iBookmarks *, const char *dirPath); 54void load_Bookmarks (iBookmarks *, const char *dirPath);
53void save_Bookmarks (const iBookmarks *, const char *dirPath); 55void save_Bookmarks (const iBookmarks *, const char *dirPath);
54 56
55void add_Bookmarks (iBookmarks *, const iString *url, const iString *title, const iString *tags, iChar icon); 57void add_Bookmarks (iBookmarks *, const iString *url, const iString *title,
56iBool remove_Bookmarks (iBookmarks *, uint32_t id); 58 const iString *tags, iChar icon);
57iBookmark *get_Bookmarks (iBookmarks *, uint32_t id); 59iBool remove_Bookmarks (iBookmarks *, uint32_t id);
58uint32_t findUrl_Bookmarks (const iBookmarks *, const iString *url); /* O(n) */ 60iBookmark * get_Bookmarks (iBookmarks *, uint32_t id);
61uint32_t findUrl_Bookmarks (const iBookmarks *, const iString *url); /* O(n) */
59 62
60typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *); 63typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *);
61typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **); 64typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **);
@@ -75,3 +78,5 @@ iBool filterTagsRegExp_Bookmarks (void *regExp, const iBookmark *);
75 */ 78 */
76const iPtrArray *list_Bookmarks(const iBookmarks *, iBookmarksCompareFunc cmp, 79const iPtrArray *list_Bookmarks(const iBookmarks *, iBookmarksCompareFunc cmp,
77 iBookmarksFilterFunc filter, void *context); 80 iBookmarksFilterFunc filter, void *context);
81
82const iString * bookmarkListPage_Bookmarks (const iBookmarks *);
diff --git a/src/gmrequest.c b/src/gmrequest.c
index 1f922142..97634bd4 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
27#include "app.h" /* dataDir_App() */ 27#include "app.h" /* dataDir_App() */
28#include "mimehooks.h" 28#include "mimehooks.h"
29#include "feeds.h" 29#include "feeds.h"
30#include "bookmarks.h"
30#include "ui/text.h" 31#include "ui/text.h"
31#include "embedded.h" 32#include "embedded.h"
32#include "defs.h" 33#include "defs.h"
@@ -298,6 +299,9 @@ static const iBlock *aboutPageSource_(iRangecc path) {
298 if (equalCase_Rangecc(path, "feeds")) { 299 if (equalCase_Rangecc(path, "feeds")) {
299 return utf8_String(entryListPage_Feeds()); 300 return utf8_String(entryListPage_Feeds());
300 } 301 }
302 if (equalCase_Rangecc(path, "bookmarks")) {
303 return utf8_String(bookmarkListPage_Bookmarks(bookmarks_App()));
304 }
301 if (equalCase_Rangecc(path, "blank")) { 305 if (equalCase_Rangecc(path, "blank")) {
302 return utf8_String(collectNewCStr_String("\n")); 306 return utf8_String(collectNewCStr_String("\n"));
303 } 307 }