diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-20 21:37:53 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-20 21:37:53 +0200 |
commit | f29d675303203309dcb4b772f8cc81068c0f97c0 (patch) | |
tree | f280a60c2054cbcca64a3074a9402b59108764f4 /src/ui/sidebarwidget.c | |
parent | 5dfb890cf841579edaeb2633025db218e86f45c2 (diff) |
Show unread entry count in sidebar
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r-- | src/ui/sidebarwidget.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 8c1bb60d..2cc1d899 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -99,6 +99,7 @@ struct Impl_SidebarWidget { | |||
99 | int maxButtonLabelWidth; | 99 | int maxButtonLabelWidth; |
100 | int width; | 100 | int width; |
101 | int itemFonts[2]; | 101 | int itemFonts[2]; |
102 | size_t numUnreadEntries; | ||
102 | iWidget * resizer; | 103 | iWidget * resizer; |
103 | iWidget * menu; | 104 | iWidget * menu; |
104 | iSidebarItem * contextItem; /* list item accessed in the context menu */ | 105 | iSidebarItem * contextItem; /* list item accessed in the context menu */ |
@@ -507,6 +508,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | |||
507 | iZap(d->modeScroll); | 508 | iZap(d->modeScroll); |
508 | d->side = side; | 509 | d->side = side; |
509 | d->mode = -1; | 510 | d->mode = -1; |
511 | d->numUnreadEntries = 0; | ||
510 | d->itemFonts[0] = uiContent_FontId; | 512 | d->itemFonts[0] = uiContent_FontId; |
511 | d->itemFonts[1] = uiContentBold_FontId; | 513 | d->itemFonts[1] = uiContentBold_FontId; |
512 | #if defined (iPlatformAppleMobile) | 514 | #if defined (iPlatformAppleMobile) |
@@ -587,6 +589,9 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | |||
587 | d->menu = NULL; | 589 | d->menu = NULL; |
588 | addAction_Widget(w, SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh"); | 590 | addAction_Widget(w, SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh"); |
589 | updateMetrics_SidebarWidget_(d); | 591 | updateMetrics_SidebarWidget_(d); |
592 | if (side == left_SideBarSide) { | ||
593 | postCommand_App("~sidebar.update"); /* unread count */ | ||
594 | } | ||
590 | } | 595 | } |
591 | 596 | ||
592 | void deinit_SidebarWidget(iSidebarWidget *d) { | 597 | void deinit_SidebarWidget(iSidebarWidget *d) { |
@@ -686,14 +691,19 @@ static void checkModeButtonLayout_SidebarWidget_(iSidebarWidget *d) { | |||
686 | const iBool isTight = | 691 | const iBool isTight = |
687 | (width_Rect(bounds_Widget(as_Widget(d->modeButtons[0]))) < d->maxButtonLabelWidth); | 692 | (width_Rect(bounds_Widget(as_Widget(d->modeButtons[0]))) < d->maxButtonLabelWidth); |
688 | for (int i = 0; i < max_SidebarMode; i++) { | 693 | for (int i = 0; i < max_SidebarMode; i++) { |
689 | if (!d->modeButtons[i]) continue; | 694 | iLabelWidget *button = d->modeButtons[i]; |
690 | if (isTight && ~flags_Widget(as_Widget(d->modeButtons[i])) & tight_WidgetFlag) { | 695 | if (!button) continue; |
691 | setFlags_Widget(as_Widget(d->modeButtons[i]), tight_WidgetFlag, iTrue); | 696 | setFlags_Widget(as_Widget(button), tight_WidgetFlag, isTight); |
692 | updateTextCStr_LabelWidget(d->modeButtons[i], tightModeLabels_[i]); | 697 | if (i == feeds_SidebarMode && d->numUnreadEntries) { |
698 | updateText_LabelWidget(button, | ||
699 | collectNewFormat_String("%s " uiTextAction_ColorEscape "%zu%s", | ||
700 | tightModeLabels_[i], | ||
701 | d->numUnreadEntries, | ||
702 | !isTight ? " Unread" : "")); | ||
693 | } | 703 | } |
694 | else if (!isTight && flags_Widget(as_Widget(d->modeButtons[i])) & tight_WidgetFlag) { | 704 | else { |
695 | setFlags_Widget(as_Widget(d->modeButtons[i]), tight_WidgetFlag, iFalse); | 705 | updateTextCStr_LabelWidget(button, |
696 | updateTextCStr_LabelWidget(d->modeButtons[i], normalModeLabels_[i]); | 706 | isTight ? tightModeLabels_[i] : normalModeLabels_[i]); |
697 | } | 707 | } |
698 | } | 708 | } |
699 | } | 709 | } |
@@ -814,11 +824,18 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
814 | updateItems_SidebarWidget_(d); | 824 | updateItems_SidebarWidget_(d); |
815 | scrollOffset_ListWidget(d->list, 0); | 825 | scrollOffset_ListWidget(d->list, 0); |
816 | } | 826 | } |
817 | else if (equal_Command(cmd, "sidebar.update") || | 827 | else if (equal_Command(cmd, "sidebar.update")) { |
818 | (equal_Command(cmd, "visited.changed") && | 828 | d->numUnreadEntries = numUnread_Feeds(); |
819 | (d->mode == history_SidebarMode || d->mode == feeds_SidebarMode))) { | 829 | checkModeButtonLayout_SidebarWidget_(d); |
820 | updateItems_SidebarWidget_(d); | 830 | updateItems_SidebarWidget_(d); |
821 | } | 831 | } |
832 | else if (equal_Command(cmd, "visited.changed")) { | ||
833 | d->numUnreadEntries = numUnread_Feeds(); | ||
834 | checkModeButtonLayout_SidebarWidget_(d); | ||
835 | if (d->mode == history_SidebarMode || d->mode == feeds_SidebarMode) { | ||
836 | updateItems_SidebarWidget_(d); | ||
837 | } | ||
838 | } | ||
822 | else if (equal_Command(cmd, "bookmarks.changed") && (d->mode == bookmarks_SidebarMode || | 839 | else if (equal_Command(cmd, "bookmarks.changed") && (d->mode == bookmarks_SidebarMode || |
823 | d->mode == feeds_SidebarMode)) { | 840 | d->mode == feeds_SidebarMode)) { |
824 | updateItems_SidebarWidget_(d); | 841 | updateItems_SidebarWidget_(d); |
@@ -954,8 +971,12 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
954 | } | 971 | } |
955 | return iTrue; | 972 | return iTrue; |
956 | } | 973 | } |
957 | else if (equal_Command(cmd, "feeds.update.finished") && d->mode == feeds_SidebarMode) { | 974 | else if (equal_Command(cmd, "feeds.update.finished")) { |
958 | updateItems_SidebarWidget_(d); | 975 | d->numUnreadEntries = argLabel_Command(cmd, "unread"); |
976 | checkModeButtonLayout_SidebarWidget_(d); | ||
977 | if (d->mode == feeds_SidebarMode) { | ||
978 | updateItems_SidebarWidget_(d); | ||
979 | } | ||
959 | } | 980 | } |
960 | else if (equal_Command(cmd, "feeds.markallread") && d->mode == feeds_SidebarMode) { | 981 | else if (equal_Command(cmd, "feeds.markallread") && d->mode == feeds_SidebarMode) { |
961 | iConstForEach(PtrArray, i, listEntries_Feeds()) { | 982 | iConstForEach(PtrArray, i, listEntries_Feeds()) { |