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/data.cpp | 2 -- c/episodelistview.cpp | 31 +++++++++++++++++-------------- c/util.h | 1 + 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/c/data.cpp b/c/data.cpp index 8d064a8..dd29ca8 100644 --- a/c/data.cpp +++ b/c/data.cpp @@ -84,7 +84,6 @@ void FetchData() /* The episode data are contained in table rows matching a * (very!) specific XPath query. This is fragile * theoretically, but unlikely to break practically. */ - HtmlDocPtr doc = ctxt->myDoc; XmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); XmlXPathObjectPtr xpathObj = xmlXPathEvalExpression( @@ -110,7 +109,6 @@ void FetchData() /* Each datum is contained within a specific cell in * the row. The child element count above ensures that * none of the following nodes are null. */ - const xmlNodePtr nodeEp = xmlFirstElementChild(node); const xmlNodePtr nodeTitle = xmlNextElementSibling(xmlNextElementSibling(nodeEp)); const xmlNodePtr nodeDate = xmlNextElementSibling(nodeTitle); 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, diff --git a/c/util.h b/c/util.h index c08050d..7c2b293 100644 --- a/c/util.h +++ b/c/util.h @@ -23,6 +23,7 @@ inline int Cmp(const int a, const int b) return -1; } +/* Generic RAII type. */ template struct Managed { -- cgit v1.2.3