aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-06-02 02:27:43 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-06-02 02:27:43 +0200
commit7f37c580c4e55468ffedba910d01abffe26154f4 (patch)
tree3e50de469d1d871aa77ea23427d6d72d93c3b5cd /c/episodelistview.c
parent5b004563a06dd41e5ba474b82088b5ca516bda85 (diff)
downloadEpisodeBrowser-7f37c580c4e55468ffedba910d01abffe26154f4.tar.gz
Simplify C interface to Prolog.
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r--c/episodelistview.c134
1 files changed, 40 insertions, 94 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index ac1ac2f..1fb20e2 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -15,7 +15,6 @@ HWND
ElvCreate()
{
LVCOLUMN lvc;
- term_t t;
HElv = LvCreate((HMENU)IDC_EPISODELISTVIEW, 0);
@@ -35,9 +34,8 @@ ElvCreate()
lvc.cx = Dpi(30);
ListView_InsertColumn(HElv, ELVSIRATING, &lvc);
- t = T(1);
- P("cfg","get_sort",1,t);
- GI(t,&ISort) ISort = 1;
+ if (!Pl("cfg","get_sort","i",&ISort))
+ ISort = 1;
return HElv;
}
@@ -67,12 +65,9 @@ ElvHandleNotify(LPARAM lParam)
case LVN_COLUMNCLICK: /* Sort by column. */
{
int iColumn;
- term_t t;
- t = T(1);
iColumn = lpNmLv->iSubItem+1;
ISort = abs(ISort) == iColumn? -ISort: iColumn;
- PI(t,ISort) goto s;
- P("cfg","set_sort",1,t);
+ Pl("cfg","set_sort","I",ISort);
s: ElvDoSort();
ElvShowFocus();
break;
@@ -101,11 +96,8 @@ ElvHandleNotify(LPARAM lParam)
break;
case CDDS_ITEMPREPAINT:
{
- term_t t;
extern HFONT HfBold;
- t = T(1);
- PI(t,lpLvCd->nmcd.lItemlParam) break;
- P("track_episodes","watched",1,t) {
+ if (!Pl("track_episodes","watched","I",lpLvCd->nmcd.lItemlParam)) {
SelectObject(lpLvCd->nmcd.hdc, HfBold);
return CDRF_NEWFONT;
}
@@ -116,27 +108,25 @@ ElvHandleNotify(LPARAM lParam)
}
case NM_DBLCLK: /* Open clicked episode. */
{
- term_t t;
- t = T(1);
- PI(t,LviElvFocus.lParam) break;
- P("local_episodes","open_episode_locally",1,t)
- P("local_episodes","open_episode_online",1,t);
+ if (!Pl("local_episodes","open_episode_locally","I",
+ LviElvFocus.lParam))
+ Pl("local_episodes","open_episode_online","I",
+ LviElvFocus.lParam);
break;
}
case NM_RETURN: /* Open all selected episodes. */
{
LVITEM lvi;
- term_t t;
extern HWND HElv;
lvi.mask = LVIF_PARAM;
lvi.iItem = -1;
- t = T(1);
while ((lvi.iItem = ListView_GetNextItem(
HElv, lvi.iItem, LVNI_SELECTED)) != -1) {
if (!ListView_GetItem(HElv, &lvi)) goto b;
- PI(t,lvi.lParam) goto b;
- P("local_episodes","open_episode_locally",1,t)
- P("local_episodes","open_episode_online",1,t);
+ if (!Pl("local_episodes","open_episode_locally","I",
+ lvi.lParam))
+ Pl("local_episodes","open_episode_online","I",
+ lvi.lParam);
}
b: break;
}
@@ -178,12 +168,9 @@ ElvSelectFocus()
{
int i, iEpisode, iItem;
LVFINDINFO lvfi;
- term_t t;
- t = T(1);
iItem = 0;
- P("cfg","get_focus",1,t) goto s;
- GI(t,&iEpisode) return;
+ if (!Pl("cfg","get_focus","i",&iEpisode)) return;
lvfi.flags = LVFI_PARAM;
lvfi.lParam = iEpisode;
@@ -214,10 +201,9 @@ s: ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED);
void
ElvSelectUnwatched(int iDir)
{
- int bShift, i, iEpNew, iItemNew;
+ int i, iEpNew, iItemNew;
LVFINDINFO lvfi;
LVITEM lviFocus;
- term_t t;
/* Get focused episode. */
lviFocus.mask = LVIF_PARAM;
@@ -232,11 +218,9 @@ ElvSelectUnwatched(int iDir)
lvfi.lParam = lviFocus.lParam;
do {
- t = T(2);
- PI(t,lvfi.lParam) return;
- P("track_episodes",iDir > 0? "next_unwatched": "previous_unwatched",2,t)
+ if (!Pl("track_episodes",iDir > 0? "next_unwatched": "previous_unwatched",
+ "Ii",lvfi.lParam,&iEpNew))
return;
- GI(t+1,&iEpNew) return;
lvfi.lParam = iEpNew;
if ((iItemNew = ListView_FindItem(HElv, -1, &lvfi)) != -1) {
@@ -280,18 +264,11 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
case ELVSIRATING:
{
int iRating1, iRating2;
- term_t t, t2;
iRating1 = iSort > 0? 99: -1;
iRating2 = iSort > 0? 99: -1;
- t = T(2);
- PI(t,lvi1.lParam) goto e;
- P("episode_data","episode_rating",2,t) goto e;
- GI(t+1,&iRating1);
- e: t2 = T(2);
- PI(t2,lvi2.lParam) goto f;
- P("episode_data","episode_rating",2,t2) goto f;
- GI(t2+1,&iRating2);
- f: if (iRating1 == iRating2)
+ Pl("episode_data","episode_rating","Ii",lvi1.lParam,&iRating1);
+ Pl("episode_data","episode_rating","Ii",lvi2.lParam,&iRating2);
+ if (iRating1 == iRating2)
return Cmp(lvi1.lParam, lvi2.lParam);
return iOrder*Cmp(iRating1, iRating2);
break;
@@ -300,15 +277,10 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
{
char *sz1, *sz2;
int cch, cch1, cch2;
- term_t t, t2;
- t = T(2);
- PI(t,lvi1.lParam) return 0;
- P("episode_data","episode_title",2,t) return 0;
- GAC(t+1,&sz1) return 0;
- t2 = T(2);
- PI(t2,lvi2.lParam) return 0;
- P("episode_data","episode_title",2,t2) return 0;
- GAC(t2+1,&sz2) return 0;
+ if (!Pl("episode_data","episode_title","Is",lvi1.lParam,&sz1))
+ return 0;
+ if (!Pl("episode_data","episode_title","Is",lvi2.lParam,&sz2))
+ return 0;
cch1 = strlen(sz1);
cch2 = strlen(sz2);
cch = cch1 > cch2? cch2: cch1;
@@ -327,7 +299,6 @@ ElvUpdate()
int cEp, i, iEp, iEpFocus, iItem, iItemMark, iItemTopNew;
LVITEM lvi, lviEpisode, lviTop;
LVFINDINFO lvfi;
- term_t t;
extern HWND HWndStatus;
static TCHAR tszDisp[16], tszEpisode[16], tszTotal[16];
static int aEpSel[2048];
@@ -360,45 +331,26 @@ ElvUpdate()
SendMessage(HElv, WM_SETREDRAW, FALSE, 0);
ListView_DeleteAllItems(HElv);
- t = T(1);
- P("episode_data","ensure_episode_data",0,t) return;
- P("episode_data","episode_count",1,t) return;
- GI(t,&cEp) return;
+ if (!Pl("episode_data","ensure_episode_data","")) return;
+ if (!Pl("episode_data","episode_count","i",&cEp)) return;
for (iEp = 1, iItem = 0; iEp <= cEp; iEp++) {
extern char SzLimitScreenwriter[];
extern int BViewTVOriginal, BViewWatched;
- if (SzLimitScreenwriter[0]) {
- atom_t a1, a2;
- term_t t;
- t = T(3);
- a1 = A("Screenwriter");
- a2 = A(SzLimitScreenwriter);
- PI(t,iEp) goto a;
- PA(t+1,a1) goto a;
- PA(t+2,a2) goto a;
- P("episode_data","episode_datum",3,t) continue;
- }
-
- a: if (!BViewWatched) {
- term_t t;
- t = T(1);
- PI(t,iEp) goto b;
- P("track_episodes","watched",1,t) goto b;
- continue;
- }
+ if (SzLimitScreenwriter[0])
+ if (!Pl("episode_data","episode_datum","ISS",
+ iEp,"Screenwriter",SzLimitScreenwriter))
+ continue;
+
+ if (!BViewWatched)
+ if (Pl("track_episodes","watched","I",iEp)) continue;
- b: if (!BViewTVOriginal) {
- term_t t;
- t = T(1);
- PI(t,iEp) goto c;
- P("episode_data","tv_original",1,t) goto c;
- continue;
- }
+ if (!BViewTVOriginal)
+ if (Pl("episode_data","tv_original","I",iEp)) continue;
/* Format episode number string. */
- c: _stprintf_s(tszEpisode, sizeof(tszEpisode), TEXT("%d"), iEp);
+ _stprintf_s(tszEpisode, sizeof(tszEpisode), TEXT("%d"), iEp);
/* Insert item. */
lviEpisode.iItem = iItem++;
@@ -461,28 +413,22 @@ ElvUpdateItem(LPLVITEM lpLvi)
char *szName;
int iRating;
TCHAR *tszName;
- term_t t, t2;
static TCHAR tszRating[3];
- t = T(2);
tszName = NULL;
- PI(t,lpLvi->lParam) goto r;
- P("episode_data","episode_title",2,t) {
- P("episode_data","update_episode_data",0,t) goto r;
- P("episode_data","episode_title",2,t) goto r;
+ if (!Pl("episode_data","episode_title","Is",lpLvi->lParam,&szName)) {
+ if (!Pl("episode_data","update_episode_data","")) goto r;
+ if (!Pl("episode_data","episode_title","Is",lpLvi->lParam,&szName))
+ goto r;
}
- GAC(t+1,&szName) goto r;
tszName = TszFromSz(szName, CP_UTF8);
if (tszName)
ListView_SetItemText(HElv, lpLvi->iItem, ELVSITITLE, tszName);
-r: t2 = T(2);
- PI(t2,lpLvi->lParam) goto f;
- P("episode_data","episode_rating",2,t2) {
+r: if (!Pl("episode_data","episode_rating","Ii",lpLvi->lParam,&iRating)) {
ListView_SetItemText(HElv, lpLvi->iItem, ELVSIRATING, TEXT(""));
goto f;
}
- GI(t2+1,&iRating) goto f;
_stprintf_s(tszRating, sizeof(tszRating), TEXT("%d"), iRating);
ListView_SetItemText(HElv, lpLvi->iItem, ELVSIRATING, tszRating);