From e2eaf362ba1b48b1518e1193ca2ae2a8e6e65efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 23 Aug 2022 02:16:10 +0200 Subject: Reimplement SelectUnwatched. --- c/episodelistview.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'c/episodelistview.cpp') diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 14aa192..645c11f 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -176,20 +177,11 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) } case NM_DBLCLK: /* Open clicked episode. */ - { - LVITEM lvi = {LVIF_PARAM, -1}; - if (FindNextItem(&lvi, LVNI_FOCUSED)) - Pl("local_episodes","open_episode_locally",lvi.lParam) - || Pl("local_episodes","open_episode_online",lvi.lParam); - return 0; - } - case NM_RETURN: /* Open all selected episodes. */ { LVITEM lvi = {LVIF_PARAM, -1}; while (FindNextItem(&lvi, LVNI_SELECTED)) - Pl("local_episodes","open_episode_locally",lvi.lParam) - || Pl("local_episodes","open_episode_online",lvi.lParam); + OpenLocally(lvi.lParam) || OpenOnline(lvi.lParam); return 0; } @@ -270,6 +262,8 @@ void EpisodeListView::SetTop(const int iItem) void EpisodeListView::SelectUnwatched(int dir) { + dir = dir > 0? 1: -1; + /* Get focused episode. */ LVITEM lviFocus = {LVIF_PARAM, -1}; if (!FindNextItem(&lviFocus, LVNI_FOCUSED)) @@ -282,13 +276,22 @@ void EpisodeListView::SelectUnwatched(int dir) lvfi.lParam = lviFocus.lParam; do { - if (!Pl("track_episodes",dir > 0? "next_unwatched": "previous_unwatched", - lvfi.lParam,&iEpNew)) - return; + /* Loop through episodes to find next/previous + * unwatched episode. */ + iEpNew = lvfi.lParam; + for (;;) { + iEpNew += dir; + if (iEpNew == 0 || iEpNew == g_cfg.cEp || !g_fvElv[iEpNew-1].siEp[0]) + return; + if (!g_fvElv[iEpNew-1].bWatched) + break; + } + /* Select the episode, if it is in the list view. If + * not, try again a thousand times. */ lvfi.lParam = iEpNew; if ((iItemNew = ListView_FindItem(hWnd, -1, &lvfi)) != -1) { - ListView_SetItemState(hWnd,-1,LVIF_STATE,LVIS_SELECTED); + ListView_SetItemState(hWnd, -1, LVIF_STATE, LVIS_SELECTED); ListView_SetSelectionMark(hWnd, iItemNew); ListView_SetItemState(hWnd, iItemNew, LVIS_SELECTED|LVIS_FOCUSED, -- cgit v1.2.3