From 2acabec65b8af9a87a822c2171fdcce2fb4dfec7 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 10 Oct 2021 08:07:56 +0300 Subject: Feeds: Added option to ignore web links --- src/bookmarks.h | 1 + src/feeds.c | 14 +++++++++++++- src/ui/util.c | 31 ++++++++++++++++++------------- 3 files changed, 32 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/bookmarks.h b/src/bookmarks.h index 13501ded..87d7694d 100644 --- a/src/bookmarks.h +++ b/src/bookmarks.h @@ -35,6 +35,7 @@ iDeclareTypeConstruction(Bookmark) /* TODO: Make the special internal tags a bitfield, separate from user's tags. */ #define headings_BookmarkTag "headings" +#define ignoreWeb_BookmarkTag "ignoreweb" #define homepage_BookmarkTag "homepage" #define linkSplit_BookmarkTag "linksplit" #define remote_BookmarkTag "remote" diff --git a/src/feeds.c b/src/feeds.c index 188fffe7..baec6870 100644 --- a/src/feeds.c +++ b/src/feeds.c @@ -85,6 +85,7 @@ struct Impl_FeedJob { iTime startTime; iBool isFirstUpdate; /* hasn't been checked ever before */ iBool checkHeadings; + iBool ignoreWeb; iGmRequest *request; iPtrArray results; }; @@ -97,6 +98,7 @@ static void init_FeedJob(iFeedJob *d, const iBookmark *bookmark) { iZap(d->startTime); d->isFirstUpdate = iFalse; d->checkHeadings = hasTag_Bookmark(bookmark, headings_BookmarkTag); + d->ignoreWeb = hasTag_Bookmark(bookmark, ignoreWeb_BookmarkTag); } static void deinit_FeedJob(iFeedJob *d) { @@ -189,6 +191,13 @@ static void trimTitle_(iString *title) { remove_Block(&title->chars, 0, start - constBegin_String(title)); } +static iBool isUrlIgnored_FeedJob_(const iFeedJob *d, iRangecc url) { + if (d->ignoreWeb) { + return startsWithCase_Rangecc(url, "http"); + } + return iFalse; +} + static void parseResult_FeedJob_(iFeedJob *d) { /* TODO: Should tell the user if the request failed. */ if (isSuccess_GmStatusCode(status_GmRequest(d->request))) { @@ -214,7 +223,10 @@ static void parseResult_FeedJob_(iFeedJob *d) { const iRangecc url = capturedRange_RegExpMatch(&m, 1); const iRangecc date = capturedRange_RegExpMatch(&m, 2); const iRangecc title = capturedRange_RegExpMatch(&m, 3); - iFeedEntry * entry = new_FeedEntry(); + if (isUrlIgnored_FeedJob_(d, url)) { + continue; + } + iFeedEntry *entry = new_FeedEntry(); entry->discovered = now; sub_Time(&now, &perEntryAdjust); entry->bookmarkId = d->bookmarkId; diff --git a/src/ui/util.c b/src/ui/util.c index 0e079efb..ab799a36 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -2782,27 +2782,27 @@ static iBool handleFeedSettingCommands_(iWidget *dlg, const char *cmd) { } int id = argLabel_Command(cmd, "bmid"); const iBool headings = isSelected_Widget(findChild_Widget(dlg, "feedcfg.type.headings")); - const iString *tags = collectNewFormat_String("subscribed%s", headings ? " headings" : ""); + const iBool ignoreWeb = isSelected_Widget(findChild_Widget(dlg, "feedcfg.ignoreweb")); if (!id) { const size_t numSubs = numSubscribed_Feeds(); const iString *url = url_DocumentWidget(document_App()); - add_Bookmarks(bookmarks_App(), - url, - feedTitle, - tags, - siteIcon_GmDocument(document_DocumentWidget(document_App()))); + id = add_Bookmarks(bookmarks_App(), + url, + feedTitle, + NULL, + siteIcon_GmDocument(document_DocumentWidget(document_App()))); if (numSubs == 0) { /* Auto-refresh after first addition. */ + /* TODO: Also when settings changed? */ postCommand_App("feeds.refresh"); } } - else { - iBookmark *bm = get_Bookmarks(bookmarks_App(), id); - if (bm) { - set_String(&bm->title, feedTitle); - set_String(&bm->tags, tags); - } - } + iBookmark *bm = get_Bookmarks(bookmarks_App(), id); + iAssert(bm); + set_String(&bm->title, feedTitle); + addOrRemoveTag_Bookmark(bm, subscribed_BookmarkTag, iTrue); + addOrRemoveTag_Bookmark(bm, headings_BookmarkTag, headings); + addOrRemoveTag_Bookmark(bm, ignoreWeb_BookmarkTag, ignoreWeb); postCommand_App("bookmarks.changed"); setupSheetTransition_Mobile(dlg, iFalse); destroy_Widget(dlg); @@ -2831,6 +2831,7 @@ iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { { format_CStr("title id:feedcfg.heading text:%s", headingText) }, { "input id:feedcfg.title text:${dlg.feed.title}" }, { "radio id:dlg.feed.entrytype", 0, 0, (const void *) typeItems }, + { "toggle id:feedcfg.ignoreweb text:${dlg.feed.ignoreweb}" }, { NULL } }, actions, iElemCount(actions)); } @@ -2849,6 +2850,8 @@ iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { addRadioButton_(types, "feedcfg.type.headings", "${dlg.feed.type.headings}", "feedcfg.type arg:1"); } addChildFlags_Widget(values, iClob(types), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); + addChild_Widget(headings, iClob(makeHeading_Widget("${dlg.feed.ignoreweb}"))); + addChild_Widget(values, iClob(makeToggle_Widget("feedcfg.ignoreweb"))); iWidget *buttons = addChild_Widget(dlg, iClob(makeDialogButtons_Widget(actions, iElemCount(actions)))); setId_Widget(child_Widget(buttons, childCount_Widget(buttons) - 1), "feedcfg.save"); @@ -2867,6 +2870,8 @@ iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { : "feedcfg.type.gemini"), selected_WidgetFlag, iTrue); + setToggle_Widget(findChild_Widget(dlg, "feedcfg.ignoreweb"), + hasTag_Bookmark(bm, ignoreWeb_BookmarkTag)); setCommandHandler_Widget(dlg, handleFeedSettingCommands_); } setupSheetTransition_Mobile(dlg, incoming_TransitionFlag); -- cgit v1.2.3