aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r--c/episodelistview.c89
1 files changed, 56 insertions, 33 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 73a97ff..f533d4f 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -49,7 +49,7 @@ ElvHandleNotify(LPARAM lParam)
(lpNmLv->uNewState & LVIS_FOCUSED)) {
LpLviElvSelection->iItem = lpNmLv->iItem;
LpLviElvSelection->lParam = lpNmLv->lParam;
- ElvUpdateName(LpLviElvSelection);
+ ElvUpdateItem(LpLviElvSelection);
DlvShowEpisode(lpNmLv->lParam);
}
break;
@@ -158,7 +158,7 @@ s: ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED);
LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
LpLviElvSelection->iItem = iItem;
LpLviElvSelection->lParam = iEpisode;
- ElvUpdateName(LpLviElvSelection);
+ ElvUpdateItem(LpLviElvSelection);
DlvShowEpisode(iEpisode);
}
@@ -166,11 +166,11 @@ s: ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED);
void
ElvUpdate()
{
- int i, iEpisode, iEpisodes, iItem, iItemTopNew;
- LVITEM lviEpisode, lviSelected, lviTop;
+ int cEp, i, iEp, iEpFocus, iItem, iItemTopNew;
+ LVITEM lvi, lviEpisode, lviTop;
LVFINDINFO lvfi;
term_t t;
- static int iEpisodeSelected[2048];
+ static int rgEpSel[2048];
lviEpisode.mask = LVIF_TEXT|LVIF_PARAM;
@@ -181,15 +181,23 @@ ElvUpdate()
/* Save selected episodes. */
i = 0;
- lviSelected.mask = LVIF_PARAM;
- lviSelected.iItem = -1;
- while ((lviSelected.iItem = ListView_GetNextItem(
- HElv, lviSelected.iItem, LVNI_SELECTED)) != -1
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = -1;
+ while ((lvi.iItem = ListView_GetNextItem(
+ HElv, lvi.iItem, LVNI_SELECTED)) != -1
&& i < 2048) {
- if (!ListView_GetItem(HElv, &lviSelected)) continue;
- iEpisodeSelected[i++] = lviSelected.lParam;
+ if (!ListView_GetItem(HElv, &lvi)) continue;
+ rgEpSel[i++] = lvi.lParam;
+ }
+ rgEpSel[i] = 0;
+
+ /* Save focus. */
+ iEpFocus = 0;
+ while ((lvi.iItem = ListView_GetNextItem(
+ HElv, lvi.iItem, LVNI_FOCUSED)) != -1) {
+ if (!ListView_GetItem(HElv, &lvi)) continue;
+ iEpFocus = lvi.lParam;
}
- iEpisodeSelected[i] = 0;
SendMessage(HElv, WM_SETREDRAW, FALSE, 0);
ListView_DeleteAllItems(HElv);
@@ -197,9 +205,9 @@ ElvUpdate()
t = T(1);
P("episode_data","ensure_episode_data",0,t) return;
P("episode_data","episode_count",1,t) return;
- GI(t,&iEpisodes) return;
+ GI(t,&cEp) return;
- for (iItem = 0, iEpisode = 1; iEpisode <= iEpisodes; iEpisode++) {
+ for (iEp = 1, iItem = 0; iEp <= cEp; iEp++) {
int cb;
TCHAR *tszEpisode;
extern int BViewTVOriginal, BViewWatched;
@@ -207,7 +215,7 @@ ElvUpdate()
if (!BViewWatched) {
term_t t;
t = T(1);
- PI(t,iEpisode) goto ep;
+ PI(t,iEp) goto ep;
P("track_episodes","watched",1,t) goto ep;
continue;
}
@@ -215,7 +223,7 @@ ElvUpdate()
if (!BViewTVOriginal) {
term_t t;
t = T(1);
- PI(t,iEpisode) goto ep;
+ PI(t,iEp) goto ep;
P("episode_data","tv_original",1,t) goto ep;
continue;
}
@@ -224,15 +232,15 @@ ElvUpdate()
ep: cb = 100;
tszEpisode = malloc(cb*sizeof(TCHAR));
if (!tszEpisode) continue;
- _stprintf_s(tszEpisode, cb, TEXT("%d"), iEpisode);
+ _stprintf_s(tszEpisode, cb, TEXT("%d"), iEp);
/* Insert item. */
lviEpisode.iItem = iItem++;
lviEpisode.iSubItem = 0;
lviEpisode.pszText = tszEpisode;
- lviEpisode.lParam = iEpisode;
+ lviEpisode.lParam = iEp;
ListView_InsertItem(HElv, &lviEpisode);
- ElvUpdateName(&lviEpisode);
+ ElvUpdateItem(&lviEpisode);
free(tszEpisode);
}
@@ -249,46 +257,61 @@ ElvUpdate()
ElvSetTop(iItemTopNew);
/* Reset selection. */
- for (i = 0; iEpisodeSelected[i]; i++) {
+ for (i = 0; rgEpSel[i]; i++) {
int iSel;
- lvfi.lParam = iEpisodeSelected[i];
- if ((iSel = ListView_FindItem(HElv, -1, &lvfi)) == -1) continue;
- ListView_SetItemState(HElv, iSel, LVIS_SELECTED, LVIS_SELECTED);
+ lvfi.lParam = rgEpSel[i];
+ if ((iSel = ListView_FindItem(HElv, -1, &lvfi)) != -1)
+ ListView_SetItemState(HElv, iSel,
+ LVIS_SELECTED, LVIS_SELECTED);
+ }
+
+ /* Reset focus. */
+ if (iEpFocus) {
+ int iFocus;
+ i = 0;
+ do
+ lvfi.lParam = iEpFocus+i;
+ while ((iFocus = ListView_FindItem(HElv, -1, &lvfi)) == -1
+ && i++ < 100);
+ if (iFocus != -1)
+ ListView_SetItemState(HElv, iFocus,
+ LVIS_FOCUSED, LVIS_FOCUSED);
}
SendMessage(HElv, WM_SETREDRAW, TRUE, 0);
ElvRedraw();
}
-/* Update episode name. */
+/* Update episode name and rating. */
void
-ElvUpdateName(LPLVITEM lpLvi)
+ElvUpdateItem(LPLVITEM lpLvi)
{
char *szName;
int iRating;
- TCHAR *tszName, tszRating[10];
+ TCHAR *tszName, tszRating[3];
term_t t, t2;
t = T(2);
- PI(t,lpLvi->lParam) return;
+ tszName = NULL;
+ PI(t,lpLvi->lParam) goto r;
P("episode_data","episode_title",2,t) {
- P("episode_data","fetch_episode_data",0,t) return;
- P("episode_data","episode_title",2,t) return;
+ P("episode_data","fetch_episode_data",0,t) goto r;
+ P("episode_data","episode_title",2,t) goto r;
}
- GAC(t+1,&szName) return;
+ GAC(t+1,&szName) goto r;
tszName = TszFromSz(szName, CP_UTF8);
if (tszName)
ListView_SetItemText(HElv, lpLvi->iItem, 2, tszName);
- t2 = T(2);
+r: t2 = T(2);
PI(t2,lpLvi->lParam) goto f;
P("episode_data","episode_rating",2,t2) {
ListView_SetItemText(HElv, lpLvi->iItem, 1, TEXT(""));
goto f;
}
GI(t2+1,&iRating) goto f;
- _itot(iRating, tszRating, 10);
+ _itot(iRating % 11, tszRating, sizeof(tszRating));
ListView_SetItemText(HElv, lpLvi->iItem, 1, tszRating);
-f: free(tszName);
+f: if (tszName) free(tszName);
}