diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-26 17:43:49 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-26 17:43:49 +0200 |
commit | 7787cdd1c32ab1f48f5aee50024409702864a2e7 (patch) | |
tree | 0aa04bb3f1ef59e4a341fa8c357980e5d7ae6c89 /src | |
parent | 57bd24d57826e0fe6ca49b9e378bd2ddb90278c2 (diff) |
Feeds: Manual refresh
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 15 | ||||
-rw-r--r-- | src/feeds.c | 12 | ||||
-rw-r--r-- | src/feeds.h | 4 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 3 | ||||
-rw-r--r-- | src/ui/window.c | 34 |
5 files changed, 55 insertions, 13 deletions
@@ -1246,6 +1246,21 @@ iBool handleCommand_App(const char *cmd) { | |||
1246 | save_Bookmarks(d->bookmarks, dataDir_App_); | 1246 | save_Bookmarks(d->bookmarks, dataDir_App_); |
1247 | return iFalse; | 1247 | return iFalse; |
1248 | } | 1248 | } |
1249 | else if (equal_Command(cmd, "feeds.refresh")) { | ||
1250 | refresh_Feeds(); | ||
1251 | return iTrue; | ||
1252 | } | ||
1253 | else if (equal_Command(cmd, "feeds.update.started")) { | ||
1254 | setFlags_Widget(findWidget_App("feeds.progress"), hidden_WidgetFlag, iFalse); | ||
1255 | refresh_App(); | ||
1256 | return iFalse; | ||
1257 | } | ||
1258 | else if (equal_Command(cmd, "feeds.update.finished")) { | ||
1259 | setFlags_Widget(findWidget_App("feeds.progress"), hidden_WidgetFlag, iTrue); | ||
1260 | refreshFinished_Feeds(); | ||
1261 | refresh_App(); | ||
1262 | return iFalse; | ||
1263 | } | ||
1249 | else if (equal_Command(cmd, "visited.changed")) { | 1264 | else if (equal_Command(cmd, "visited.changed")) { |
1250 | save_Visited(d->visited, dataDir_App_); | 1265 | save_Visited(d->visited, dataDir_App_); |
1251 | return iFalse; | 1266 | return iFalse; |
diff --git a/src/feeds.c b/src/feeds.c index 9538d948..1af42477 100644 --- a/src/feeds.c +++ b/src/feeds.c | |||
@@ -259,7 +259,7 @@ static const iPtrArray *listSubscriptions_(void) { | |||
259 | 259 | ||
260 | static iBool startWorker_Feeds_(iFeeds *d) { | 260 | static iBool startWorker_Feeds_(iFeeds *d) { |
261 | if (d->worker) { | 261 | if (d->worker) { |
262 | return iFalse; /* Oops? */ | 262 | return iFalse; /* Refresh is already ongoing. */ |
263 | } | 263 | } |
264 | /* Queue up all the subscriptions for the worker. */ | 264 | /* Queue up all the subscriptions for the worker. */ |
265 | iConstForEach(PtrArray, i, listSubscriptions_()) { | 265 | iConstForEach(PtrArray, i, listSubscriptions_()) { |
@@ -449,6 +449,14 @@ void deinit_Feeds(void) { | |||
449 | deinit_SortedArray(&d->entries); | 449 | deinit_SortedArray(&d->entries); |
450 | } | 450 | } |
451 | 451 | ||
452 | void refresh_Feeds(void) { | ||
453 | startWorker_Feeds_(&feeds_); | ||
454 | } | ||
455 | |||
456 | void refreshFinished_Feeds(void) { | ||
457 | stopWorker_Feeds_(&feeds_); | ||
458 | } | ||
459 | |||
452 | static int cmpTimeDescending_FeedEntryPtr_(const void *a, const void *b) { | 460 | static int cmpTimeDescending_FeedEntryPtr_(const void *a, const void *b) { |
453 | const iFeedEntry * const *e1 = a, * const *e2 = b; | 461 | const iFeedEntry * const *e1 = a, * const *e2 = b; |
454 | return -cmp_Time(&(*e1)->timestamp, &(*e2)->timestamp); | 462 | return -cmp_Time(&(*e1)->timestamp, &(*e2)->timestamp); |
@@ -470,7 +478,7 @@ const iPtrArray *listEntries_Feeds(void) { | |||
470 | const iString *entryListPage_Feeds(void) { | 478 | const iString *entryListPage_Feeds(void) { |
471 | iFeeds *d = &feeds_; | 479 | iFeeds *d = &feeds_; |
472 | iString *src = collectNew_String(); | 480 | iString *src = collectNew_String(); |
473 | format_String(src, "# Aggregated Gemini feeds\n"); | 481 | format_String(src, "# Feed entries\n\n"); |
474 | lock_Mutex(d->mtx); | 482 | lock_Mutex(d->mtx); |
475 | const iPtrArray *subs = listSubscriptions_(); | 483 | const iPtrArray *subs = listSubscriptions_(); |
476 | int elapsed = elapsedSeconds_Time(&d->lastRefreshedAt) / 60; | 484 | int elapsed = elapsedSeconds_Time(&d->lastRefreshedAt) / 60; |
diff --git a/src/feeds.h b/src/feeds.h index 7ad6c2aa..eb516690 100644 --- a/src/feeds.h +++ b/src/feeds.h | |||
@@ -36,7 +36,9 @@ struct Impl_FeedEntry { | |||
36 | 36 | ||
37 | void init_Feeds (const char *saveDir); | 37 | void init_Feeds (const char *saveDir); |
38 | void deinit_Feeds (void); | 38 | void deinit_Feeds (void); |
39 | void refresh_Feeds (void); | ||
39 | 40 | ||
40 | const iPtrArray * listEntries_Feeds (void); | 41 | void refreshFinished_Feeds (void); /* called on "feeds.update.finished" */ |
41 | 42 | ||
43 | const iPtrArray * listEntries_Feeds (void); | ||
42 | const iString * entryListPage_Feeds (void); | 44 | const iString * entryListPage_Feeds (void); |
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 3fdfe190..3bd0f229 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -690,6 +690,9 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
690 | (d->mode == history_SidebarMode || d->mode == feeds_SidebarMode)) { | 690 | (d->mode == history_SidebarMode || d->mode == feeds_SidebarMode)) { |
691 | updateItems_SidebarWidget_(d); | 691 | updateItems_SidebarWidget_(d); |
692 | } | 692 | } |
693 | else if (equal_Command(cmd, "feeds.update.finished") && d->mode == feeds_SidebarMode) { | ||
694 | updateItems_SidebarWidget_(d); | ||
695 | } | ||
693 | else if (equal_Command(cmd, "bookmarks.changed") && d->mode == bookmarks_SidebarMode) { | 696 | else if (equal_Command(cmd, "bookmarks.changed") && d->mode == bookmarks_SidebarMode) { |
694 | updateItems_SidebarWidget_(d); | 697 | updateItems_SidebarWidget_(d); |
695 | } | 698 | } |
diff --git a/src/ui/window.c b/src/ui/window.c index 6e046bdc..b4b8fff6 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -159,8 +159,9 @@ static const iMenuItem viewMenuItems_[] = { | |||
159 | static iMenuItem bookmarksMenuItems_[] = { | 159 | static iMenuItem bookmarksMenuItems_[] = { |
160 | { "Bookmark This Page...", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, | 160 | { "Bookmark This Page...", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, |
161 | { "---", 0, 0, NULL }, | 161 | { "---", 0, 0, NULL }, |
162 | { "Subscribe as Feed", 0, 0, "bookmark.addtag tag:subscribed" }, | 162 | { "Subscribe to This Page", 0, 0, "bookmark.addtag tag:subscribed" }, |
163 | { "---", 0, 0, NULL }, | 163 | { "---", 0, 0, NULL }, |
164 | { "Show Feed Entries", 0, 0, "open url:about:feeds" }, | ||
164 | { "Refresh Feeds", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" }, | 165 | { "Refresh Feeds", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" }, |
165 | }; | 166 | }; |
166 | 167 | ||
@@ -401,16 +402,29 @@ static void setupUserInterface_Window(iWindow *d) { | |||
401 | setNotifyEdits_InputWidget(url, iTrue); | 402 | setNotifyEdits_InputWidget(url, iTrue); |
402 | setTextCStr_InputWidget(url, "gemini://"); | 403 | setTextCStr_InputWidget(url, "gemini://"); |
403 | addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); | 404 | addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); |
404 | /* Download progress indicator is inside the input field, but hidden normally. */ | ||
405 | setPadding_Widget(as_Widget(url),0, 0, gap_UI * 1, 0); | 405 | setPadding_Widget(as_Widget(url),0, 0, gap_UI * 1, 0); |
406 | iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 MB", NULL); | 406 | /* Feeds refresh indicator is inside the input field. */ { |
407 | setId_Widget(as_Widget(progress), "document.progress"); | 407 | iLabelWidget *fprog = new_LabelWidget(uiTextCaution_ColorEscape |
408 | setAlignVisually_LabelWidget(progress, iTrue); | 408 | "\u2605 Refreshing Feeds...", NULL); |
409 | shrink_Rect(&as_Widget(progress)->rect, init_I2(0, gap_UI)); | 409 | setId_Widget(as_Widget(fprog), "feeds.progress"); |
410 | addChildFlags_Widget(as_Widget(url), | 410 | setBackgroundColor_Widget(as_Widget(fprog), uiBackground_ColorId); |
411 | iClob(progress), | 411 | setAlignVisually_LabelWidget(fprog, iTrue); |
412 | moveToParentRightEdge_WidgetFlag); | 412 | shrink_Rect(&as_Widget(fprog)->rect, init_I2(0, gap_UI)); |
413 | setBackgroundColor_Widget(as_Widget(progress), uiBackground_ColorId); | 413 | addChildFlags_Widget(as_Widget(url), |
414 | iClob(fprog), | ||
415 | moveToParentRightEdge_WidgetFlag | hidden_WidgetFlag); | ||
416 | } | ||
417 | /* Download progress indicator is also inside the input field, but hidden normally. | ||
418 | TODO: It shouldn't overlap the feeds indicator... */ { | ||
419 | iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 MB", NULL); | ||
420 | setId_Widget(as_Widget(progress), "document.progress"); | ||
421 | setBackgroundColor_Widget(as_Widget(progress), uiBackground_ColorId); | ||
422 | setAlignVisually_LabelWidget(progress, iTrue); | ||
423 | shrink_Rect(&as_Widget(progress)->rect, init_I2(0, gap_UI)); | ||
424 | addChildFlags_Widget(as_Widget(url), | ||
425 | iClob(progress), | ||
426 | moveToParentRightEdge_WidgetFlag); | ||
427 | } | ||
414 | } | 428 | } |
415 | setId_Widget(addChild_Widget( | 429 | setId_Widget(addChild_Widget( |
416 | navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), | 430 | navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), |