diff options
author | John Ankarström <john@ankarstrom.se> | 2022-04-04 01:22:58 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-04-04 01:22:58 +0200 |
commit | 0c996d6836defcc190a4f071437d95cb1f5140cb (patch) | |
tree | 3af475d4e6f8730279ade1fcd66cf7d33f950a3e /c/datalistview.c | |
parent | 12176831abde1f4545fae95ee9edd5688f8cc584 (diff) | |
download | EpisodeBrowser-0c996d6836defcc190a4f071437d95cb1f5140cb.tar.gz |
Rewrite episode data code.
TODO: Ignore duplicate hints.
Diffstat (limited to 'c/datalistview.c')
-rw-r--r-- | c/datalistview.c | 77 |
1 files changed, 30 insertions, 47 deletions
diff --git a/c/datalistview.c b/c/datalistview.c index fe16913..829f6d6 100644 --- a/c/datalistview.c +++ b/c/datalistview.c @@ -36,6 +36,7 @@ DlvShowEpisode(int iEpisode) { LVITEM lviKey, lviValue; term_t t; + qid_t q; ListView_DeleteAllItems(HDlv); @@ -44,54 +45,36 @@ DlvShowEpisode(int iEpisode) t = T(3); PI(t,iEpisode) return; - P("episode_data","lookup_episode_local",3,t) return; - - /* The episode data is a list of unary compounds, whose - * functor is the key and whose argument is the value. - * (Perhaps this should really be implemented in Prolog.) */ - - { - term_t tHead, tList; - - tHead = PL_new_term_ref(); - tList = PL_copy_term_ref(t+2); - - for (int i = 0; PL_get_list(tList, tHead, tList); i++) { - atom_t aKey; - const char *szKey; - char *szValue; - TCHAR *tszKey, *tszValue; - term_t tValue; - size_t iArity; - - if (!PL_get_name_arity(tHead,&aKey,&iArity)) continue; - szKey = PL_atom_chars(aKey); - if (!szKey) continue; - - tValue = PL_new_term_ref(); - if (!PL_get_arg(1, tHead, tValue)) continue; - GAC(tValue,&szValue) continue; - - tszKey = TszFromSz(szKey, CP_UTF8); - if (!tszKey) continue; - tszValue = TszFromSz(szValue, CP_UTF8); - if (!tszValue) goto c; - - lviKey.mask = LVIF_TEXT; - lviKey.iItem = i; - lviKey.iSubItem = 0; - lviKey.pszText = tszKey; - ListView_InsertItem(HDlv, &lviKey); - - lviValue.iItem = i; - lviValue.iSubItem = 1; - lviValue.pszText = tszValue; - ListView_SetItem(HDlv, &lviValue); - - free(tszValue); - c: free(tszKey); - } + q = Q("episode_data","episode_datum",3,t); + + for (int i = 0; Qn(q); i++) { + char *szKey; + char *szValue; + TCHAR *tszKey, *tszValue; + + GAC(t+1,&szKey) continue; + GAC(t+2,&szValue) continue; + + tszKey = TszFromSz(szKey, CP_UTF8); + if (!tszKey) continue; + tszValue = TszFromSz(szValue, CP_UTF8); + if (!tszValue) goto c; + + lviKey.mask = LVIF_TEXT; + lviKey.iItem = i; + lviKey.iSubItem = 0; + lviKey.pszText = tszKey; + ListView_InsertItem(HDlv, &lviKey); + + lviValue.iItem = i; + lviValue.iSubItem = 1; + lviValue.pszText = tszValue; + ListView_SetItem(HDlv, &lviValue); + + free(tszValue); + c: free(tszKey); } + Qc(q); UpdateLayout(); } |