aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-23 02:16:10 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-23 02:16:10 +0200
commite2eaf362ba1b48b1518e1193ca2ae2a8e6e65efa (patch)
tree620e219289c434ddc6371d2a112ac2e8bfe759d8
parent3962b1bdfb2a8a2e3a5ff4f4e51a61b0c44f2e6b (diff)
downloadEpisodeBrowser-e2eaf362ba1b48b1518e1193ca2ae2a8e6e65efa.tar.gz
Reimplement SelectUnwatched.
-rw-r--r--c/data.cpp2
-rw-r--r--c/episodelistview.cpp31
-rw-r--r--c/util.h1
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 <cassert>
#include <vector>
#include <windows.h>
#include <commctrl.h>
@@ -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 <typename T, auto F, typename U, auto E = 0>
struct Managed
{