aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-02-16 16:29:25 +0100
committerJohn Ankarström <john@ankarstrom.se>2022-02-16 16:29:25 +0100
commit8e70cba63a8109bc663f06c9e8b79a241a968bcc (patch)
tree784938495c5449bdac8b96ae0c05384fc4044962 /c/episodelistview.c
parent4fafc8b49e3f08a87119ef62a54056efba7b6b92 (diff)
downloadEpisodeBrowser-8e70cba63a8109bc663f06c9e8b79a241a968bcc.tar.gz
Select most recently watched episode by default.
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r--c/episodelistview.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index e12da4f..d3445e8 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -34,6 +34,7 @@ ElvCreate(HWND hWnd)
ListView_InsertColumn(hListView, 1, &lvc);
ElvUpdate();
+ ElvSelectRecent();
return hListView;
}
@@ -119,6 +120,45 @@ ElvItemEpisode(int iItem) {
return lvi.lParam;
}
+/* Select most recent episode. */
+void
+ElvSelectRecent()
+{
+ fid_t f;
+ HWND hListView;
+ int iEpisode, iItem;
+ LVFINDINFO lvfi;
+ term_t t;
+
+ f = PL_open_foreign_frame(); /* Needed? */
+
+ t = PL_new_term_refs(1);
+ if (!PL_call_predicate(NULL, PL_Q_NORMAL,
+ PL_predicate("most_recently_watched", 1, "track_episodes"),
+ t))
+ goto end;
+
+ if (!PL_get_integer(t+0, &iEpisode))
+ goto end;
+
+ hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
+ lvfi.flags = LVFI_PARAM;
+ lvfi.lParam = iEpisode;
+
+ iItem = ListView_FindItem(hListView, -1, &lvfi);
+ if (iItem == -1)
+ goto end;
+
+ ListView_EnsureVisible(hListView, iItem, TRUE);
+ ListView_SetItemState(hListView, iItem, LVIS_SELECTED, LVIS_SELECTED);
+ g_iSelectedItem = iItem;
+ ElvUpdateName(iItem, iEpisode);
+ DlvShowEpisode(iEpisode);
+
+end:
+ PL_discard_foreign_frame(f);
+}
+
/* Update episode list. */
void
ElvUpdate()