diff options
author | John Ankarström <john@ankarstrom.se> | 2022-04-06 22:53:27 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-04-06 22:53:27 +0200 |
commit | 750fd640b56e169caafdbb96bef0c3c3af3dba1f (patch) | |
tree | 419adda8a8f5964c8c6642ea387c8c967fd01bd6 /c/episodelistview.c | |
parent | 4d6cbcdc97fd79befca82ed9ddc0d96ce86f744f (diff) | |
download | EpisodeBrowser-750fd640b56e169caafdbb96bef0c3c3af3dba1f.tar.gz |
Add View > Watched Episodes menu item.
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r-- | c/episodelistview.c | 99 |
1 files changed, 42 insertions, 57 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c index 26122c7..1ce49b1 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -165,80 +165,64 @@ s: void ElvUpdate() { - int iEpisodes, iTop; - LVITEM lviEpisode, lviName, lviRating; + int i, iEpisode, iEpisodes, iItem, iTopNew; + LVITEM lviEpisode, lviTop; + LVFINDINFO lvfiTopNew; term_t t; + lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; + lviTop.iItem = ListView_GetTopIndex(HElv); + lviTop.mask = LVIF_PARAM; + ListView_GetItem(HElv, &lviTop); + SendMessage(HElv, WM_SETREDRAW, FALSE, 0); - iTop = ListView_GetTopIndex(HElv); ListView_DeleteAllItems(HElv); - lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; - lviName.mask = LVIF_TEXT; - lviRating.mask = LVIF_TEXT; - t = T(1); P("episode_data","ensure_episode_data",0,t) return; P("episode_data","episode_count",1,t) return; GI(t,&iEpisodes) return; - for (int i = 0; i < iEpisodes; i++) { - char *szName; - int cb, iRating; - TCHAR *tszEpisode, *tszName, tszRating[10]; - term_t t, t2; - - tszName = NULL; - tszRating[0] = 0; - - /* Format name string. */ - t = T(2); - PI(t,i+1) return; - P("episode_data","episode_title",2,t) goto ep; - GAC(t+1,&szName) goto ep; - tszName = TszFromSz(szName, CP_UTF8); - if (!tszName) return; - - /* Format rating string. */ - t2 = T(2); - PI(t2,i+1) return; - P("episode_data","episode_rating",2,t2) goto ep; - GI(t2+1,&iRating) goto ep; - _itot(iRating, tszRating, 10); + for (iItem = 0, iEpisode = 1; iEpisode <= iEpisodes; iEpisode++) { + int cb; + TCHAR *tszEpisode; + extern int BViewWatched; + + if (!BViewWatched) { + term_t t; + t = T(1); + PI(t,iEpisode) goto ep; + P("track_episodes","watched",1,t) goto ep; + continue; + } /* Format episode number string. */ ep: cb = 100; tszEpisode = malloc(cb*sizeof(TCHAR)); - if (!tszEpisode) goto e; - _stprintf_s(tszEpisode, cb, TEXT("%d"), i+1); + if (!tszEpisode) continue; + _stprintf_s(tszEpisode, cb, TEXT("%d"), iEpisode); /* Insert item. */ - lviEpisode.iItem = i; + lviEpisode.iItem = iItem++; lviEpisode.iSubItem = 0; lviEpisode.pszText = tszEpisode; - lviEpisode.lParam = i+1; + lviEpisode.lParam = iEpisode; ListView_InsertItem(HElv, &lviEpisode); - - if (*tszRating) { - lviRating.iItem = i; - lviRating.iSubItem = 1; - lviRating.pszText = tszRating; - ListView_SetItem(HElv, &lviRating); - } - - if (tszName) { - lviName.iItem = i; - lviName.iSubItem = 2; - lviName.pszText = tszName; - ListView_SetItem(HElv, &lviName); - } + ElvUpdateName(&lviEpisode); free(tszEpisode); - e: if (tszName) free(tszName); } - /* Reset selection and scrolling position. */ - ElvSetTop(iTop); + /* Reset scrolling position (roughly). */ + i = 0; + lvfiTopNew.flags = LVFI_PARAM; + do + lvfiTopNew.lParam = lviTop.lParam+i; + while ((iTopNew = ListView_FindItem(HElv, -1, &lvfiTopNew)) == -1 && i++ < 100); + if (iTopNew != -1) + ElvSetTop(iTopNew); + + /* Reset selection. */ if (LpLviElvSelection) ListView_SetItemState(HElv, LpLviElvSelection->iItem, LVIS_SELECTED, LVIS_SELECTED); @@ -263,18 +247,19 @@ ElvUpdateName(LPLVITEM lpLvi) P("episode_data","episode_title",2,t) return; } GAC(t+1,&szName) return; - tszName = TszFromSz(szName, CP_UTF8); - if (!tszName) return; - ListView_SetItemText(HElv, lpLvi->iItem, 2, tszName); + if (tszName) + ListView_SetItemText(HElv, lpLvi->iItem, 2, tszName); t2 = T(2); - PI(t2,lpLvi->lParam) return; + PI(t2,lpLvi->lParam) goto f; P("episode_data","episode_rating",2,t2) { ListView_SetItemText(HElv, lpLvi->iItem, 1, TEXT("")); - return; + goto f; } - GI(t2+1,&iRating) return; + GI(t2+1,&iRating) goto f; _itot(iRating, tszRating, 10); ListView_SetItemText(HElv, lpLvi->iItem, 1, tszRating); + +f: free(tszName); } |