diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-23 15:27:58 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-23 15:27:58 +0200 |
commit | 678ed94bf55bc15592d14aed1ace04863e5483d1 (patch) | |
tree | 4301f4ac3d7bc48db4e8c45f6646205418c679ed /src/ui/sidebarwidget.c | |
parent | e509af0fc8eee4b03766ec5c1f4faf6dae7f41b4 (diff) |
Sidebar: Populate with feed entries
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r-- | src/ui/sidebarwidget.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index f17f82a1..aac7459e 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
26 | #include "bookmarks.h" | 26 | #include "bookmarks.h" |
27 | #include "command.h" | 27 | #include "command.h" |
28 | #include "documentwidget.h" | 28 | #include "documentwidget.h" |
29 | #include "feeds.h" | ||
29 | #include "gmcerts.h" | 30 | #include "gmcerts.h" |
30 | #include "gmdocument.h" | 31 | #include "gmdocument.h" |
31 | #include "inputwidget.h" | 32 | #include "inputwidget.h" |
@@ -111,6 +112,27 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { | |||
111 | destroy_Widget(d->menu); | 112 | destroy_Widget(d->menu); |
112 | d->menu = NULL; | 113 | d->menu = NULL; |
113 | switch (d->mode) { | 114 | switch (d->mode) { |
115 | case feeds_SidebarMode: { | ||
116 | iConstForEach(PtrArray, i, listEntries_Feeds()) { | ||
117 | const iFeedEntry *entry = i.ptr; | ||
118 | /* TODO: Insert date separators. */ | ||
119 | iSidebarItem *item = new_SidebarItem(); | ||
120 | item->icon = 0; | ||
121 | const iTime visitTime = urlVisitTime_Visited(visited_App(), &entry->url); | ||
122 | if (!isValid_Time(&visitTime)) { | ||
123 | item->icon = 0x25cf; /* black circle */ | ||
124 | } | ||
125 | set_String(&item->url, &entry->url); | ||
126 | set_String(&item->label, &entry->title); | ||
127 | const iBookmark *bm = get_Bookmarks(bookmarks_App(), entry->bookmarkId); | ||
128 | if (bm) { | ||
129 | set_String(&item->meta, &bm->title); | ||
130 | } | ||
131 | addItem_ListWidget(d->list, item); | ||
132 | iRelease(item); | ||
133 | } | ||
134 | break; | ||
135 | } | ||
114 | case documentOutline_SidebarMode: { | 136 | case documentOutline_SidebarMode: { |
115 | const iGmDocument *doc = document_DocumentWidget(document_App()); | 137 | const iGmDocument *doc = document_DocumentWidget(document_App()); |
116 | iConstForEach(Array, i, headings_GmDocument(doc)) { | 138 | iConstForEach(Array, i, headings_GmDocument(doc)) { |
@@ -281,7 +303,7 @@ iBool setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) { | |||
281 | for (enum iSidebarMode i = 0; i < max_SidebarMode; i++) { | 303 | for (enum iSidebarMode i = 0; i < max_SidebarMode; i++) { |
282 | setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode); | 304 | setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode); |
283 | } | 305 | } |
284 | const float heights[max_SidebarMode] = { 1.333f, 1.333f, 3.5f, 1.2f }; | 306 | const float heights[max_SidebarMode] = { 2.5f, 1.333f, 1.333f, 3.5f, 1.2f }; |
285 | setBackgroundColor_Widget(as_Widget(d->list), | 307 | setBackgroundColor_Widget(as_Widget(d->list), |
286 | d->mode == documentOutline_SidebarMode ? tmBannerBackground_ColorId | 308 | d->mode == documentOutline_SidebarMode ? tmBannerBackground_ColorId |
287 | : uiBackground_ColorId); | 309 | : uiBackground_ColorId); |
@@ -300,6 +322,7 @@ int width_SidebarWidget(const iSidebarWidget *d) { | |||
300 | } | 322 | } |
301 | 323 | ||
302 | static const char *normalModeLabels_[max_SidebarMode] = { | 324 | static const char *normalModeLabels_[max_SidebarMode] = { |
325 | "\U00002605 Feeds", | ||
303 | "\U0001f588 Bookmarks", | 326 | "\U0001f588 Bookmarks", |
304 | "\U0001f553 History", | 327 | "\U0001f553 History", |
305 | "\U0001f464 Identities", | 328 | "\U0001f464 Identities", |
@@ -307,6 +330,7 @@ static const char *normalModeLabels_[max_SidebarMode] = { | |||
307 | }; | 330 | }; |
308 | 331 | ||
309 | static const char *tightModeLabels_[max_SidebarMode] = { | 332 | static const char *tightModeLabels_[max_SidebarMode] = { |
333 | "\U00002605", | ||
310 | "\U0001f588", | 334 | "\U0001f588", |
311 | "\U0001f553", | 335 | "\U0001f553", |
312 | "\U0001f464", | 336 | "\U0001f464", |
@@ -401,6 +425,11 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, const iSidebarItem *it | |||
401 | postCommandf_App("document.goto loc:%p", head->text.start); | 425 | postCommandf_App("document.goto loc:%p", head->text.start); |
402 | break; | 426 | break; |
403 | } | 427 | } |
428 | case feeds_SidebarMode: | ||
429 | if (!isEmpty_String(&item->url)) { | ||
430 | postCommandf_App("open url:%s", cstr_String(&item->url)); | ||
431 | } | ||
432 | break; | ||
404 | case bookmarks_SidebarMode: | 433 | case bookmarks_SidebarMode: |
405 | case history_SidebarMode: { | 434 | case history_SidebarMode: { |
406 | if (!isEmpty_String(&item->url)) { | 435 | if (!isEmpty_String(&item->url)) { |
@@ -826,6 +855,31 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect, | |||
826 | fg, | 855 | fg, |
827 | range_String(&d->label)); | 856 | range_String(&d->label)); |
828 | } | 857 | } |
858 | else if (sidebar->mode == feeds_SidebarMode) { | ||
859 | const int fg = isHover ? (isPressing ? uiTextPressed_ColorId : uiTextFramelessHover_ColorId) | ||
860 | : uiText_ColorId; | ||
861 | const int h1 = lineHeight_Text(uiLabel_FontId); | ||
862 | const int h2 = lineHeight_Text(uiContent_FontId); | ||
863 | const iRect iconArea = { addY_I2(pos, h1), init_I2(7 * gap_UI, itemHeight - h1) }; | ||
864 | if (d->icon) { | ||
865 | iString str; | ||
866 | initUnicodeN_String(&str, &d->icon, 1); | ||
867 | drawCentered_Text(uiContent_FontId, iconArea, iFalse, iconColor, "%s", cstr_String(&str)); | ||
868 | deinit_String(&str); | ||
869 | } | ||
870 | pos = add_I2(pos, init_I2(7 * gap_UI, (itemHeight - h1 - h2) / 2)); | ||
871 | draw_Text(uiLabel_FontId, | ||
872 | pos, | ||
873 | isPressing ? fg : uiHeading_ColorId, | ||
874 | "%s", | ||
875 | cstr_String(&d->meta)); | ||
876 | pos.y += h1; | ||
877 | draw_Text(uiContent_FontId, | ||
878 | pos, | ||
879 | isPressing ? fg : uiTextStrong_ColorId, | ||
880 | "%s", | ||
881 | cstr_String(&d->label)); | ||
882 | } | ||
829 | else if (sidebar->mode == bookmarks_SidebarMode) { | 883 | else if (sidebar->mode == bookmarks_SidebarMode) { |
830 | const int fg = isHover ? (isPressing ? uiTextPressed_ColorId : uiTextFramelessHover_ColorId) | 884 | const int fg = isHover ? (isPressing ? uiTextPressed_ColorId : uiTextFramelessHover_ColorId) |
831 | : uiText_ColorId; | 885 | : uiText_ColorId; |