From 78fbe9fcba52cad4b4c36aca7c385b3a8f45824a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 17 Aug 2022 19:01:26 +0200 Subject: DataListView: Use file view. --- c/data.h | 6 ++++-- c/datalistview.cpp | 56 ++++++++++++++++++++++++++--------------------------- c/datalistview.h | 4 ++++ c/episodelistview.h | 4 ++-- c/test.cpp | 33 +++++++++++++++++++++++++++++-- 5 files changed, 69 insertions(+), 34 deletions(-) (limited to 'c') diff --git a/c/data.h b/c/data.h index 3e099ea..6d6edd3 100644 --- a/c/data.h +++ b/c/data.h @@ -13,7 +13,7 @@ * should be regarded as immutable. If the format needs to be changed * in the future, then new structs ending with B should be added. */ -/* Note that unsigned chars are 1-byte-aligned, wchar_t are +/* Note that unsigned chars are 1-byte-aligned, shorts and wchar_t are * 2-byte-aligned and ints are 4-byte-aligned (on x86 Windows). */ /* Basic episode data presented in episode list view. */ @@ -31,6 +31,8 @@ struct ElvDataA /* Extra episode data presented in data list view. */ struct DlvDataA { + unsigned char version = 'a'; + unsigned char pad[3] = {0}; wchar_t date[32] = {0}; wchar_t source[48] = {0}; wchar_t screenwriter[48] = {0}; @@ -45,7 +47,7 @@ struct CfgA unsigned char bViewWatched = 1; unsigned char bViewTVOriginal = 1; signed char iSortCol = 1; - unsigned short cEp = 0; + unsigned short cEp = 4096; unsigned short iFocus = 0; unsigned short heightDlv = 0; wchar_t limitScreenwriter[64] = {0}; diff --git a/c/datalistview.cpp b/c/datalistview.cpp index 6d3d79c..6e598f5 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -5,11 +5,11 @@ #include #include "resource.h" +#include "data.h" #include "datalistview.h" #include "episodelistview.h" #include "listview.h" #include "layout.h" -#include "pl.h" #include "wcharptr.h" DataListView::DataListView(const HWND hWndParent) @@ -53,35 +53,34 @@ void DataListView::SetHeight(int h) void DataListView::ShowEpisode(const int iEpisode) { - extern EpisodeListView* const g_elv; + const DlvDataA& d = m_fv[iEpisode]; ListView_DeleteAllItems(hWnd); - - Frame f; - const int arity = 3; - const term_t t = PL_new_term_refs(arity); - if (!PlPut(t, iEpisode)) return; - - Query q (nullptr, PL_predicate("episode_datum", arity, "episode_data"), t); - LVITEM lviKey = {LVIF_TEXT}; - LVITEM lviValue = {LVIF_TEXT}; - - for (int i = 0; q.NextSolution(std::nothrow); i++) { - WcharPtr key; - WcharPtr value; - - if (!(PlGet(t+1, &key) && PlGet(t+2, &value))) - continue; - - lviKey.iItem = i; - lviKey.iSubItem = 0; - lviKey.pszText = key; - ListView_InsertItem(hWnd, &lviKey); - - lviValue.iItem = i; - lviValue.iSubItem = 1; - lviValue.pszText = value; - ListView_SetItem(hWnd, &lviValue); + if (d.version == Version) { + const wchar_t* v[] = { + L"Date", d.date, + L"Source", d.source, + L"Hint", d.hint, + L"Screenwriter", d.screenwriter}; + + LVITEM lviKey = {LVIF_TEXT}; + LVITEM lviValue = {LVIF_TEXT}; + + for (size_t i = 0, j = 0; i < sizeof(v)/sizeof(*v); i += 2) { + if (v[i+1][0]) { + lviKey.iItem = j; + lviKey.iSubItem = 0; + lviKey.pszText = const_cast(v[i]); + ListView_InsertItem(hWnd, &lviKey); + + lviValue.iItem = j; + lviValue.iSubItem = 1; + lviValue.pszText = const_cast(v[i+1]); + ListView_SetItem(hWnd, &lviValue); + + j++; + } + } } UpdateLayout(); @@ -89,6 +88,7 @@ void DataListView::ShowEpisode(const int iEpisode) LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; + extern EpisodeListView* const g_elv; int iItem = ListView_FindItem(g_elv->hWnd, -1, &lvfi); if (iItem != -1) ListView_EnsureVisible(g_elv->hWnd, iItem, TRUE); diff --git a/c/datalistview.h b/c/datalistview.h index 26ba8c9..3a59d41 100644 --- a/c/datalistview.h +++ b/c/datalistview.h @@ -1,11 +1,14 @@ #ifndef DATALISTVIEW_H #define DATALISTVIEW_H +#include "data.h" #include "listview.h" #define DLVSIKEY 0 #define DLVSIVALUE 1 +extern CfgA& g_cfg; + struct DataListView : public ListView { DataListView(HWND hWndParent); @@ -18,6 +21,7 @@ struct DataListView : public ListView void ShowEpisode(int iEpisode); private: int m_height = 0; + FileView m_fv{L"dlvdata.dat", g_cfg.cEp+128u}; }; #endif diff --git a/c/episodelistview.h b/c/episodelistview.h index 88c8c9e..f94803c 100644 --- a/c/episodelistview.h +++ b/c/episodelistview.h @@ -12,7 +12,7 @@ #define ELVSITITLE 1 #define ELVSIRATING 2 -#define ELVMAX 8192 +extern CfgA& g_cfg; struct EpisodeListView : public ListView { @@ -35,7 +35,7 @@ struct EpisodeListView : public ListView private: signed char m_iSortCol; static int CALLBACK SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM extra); - FileView m_fv{L"elvdata.dat", ELVMAX}; + FileView m_fv{L"elvdata.dat", g_cfg.cEp+128u}; }; #endif diff --git a/c/test.cpp b/c/test.cpp index 92644ba..1054978 100644 --- a/c/test.cpp +++ b/c/test.cpp @@ -4,6 +4,8 @@ #include "util.h" #include "win.h" +extern CfgA& g_cfg; + struct Test { const char* name = {0}; @@ -115,7 +117,7 @@ TESTS return; { - FileView fv{L"tmp.dat", ELVMAX}; + FileView fv{L"tmp.dat", g_cfg.cEp+128u}; ElvDataA* p = fv; for (int iEp = 1; iEp <= cEp; iEp++) { @@ -126,7 +128,7 @@ TESTS } } { - FileView fv{L"tmp.dat", 8192}; + FileView fv{L"tmp.dat", g_cfg.cEp+128u}; ElvDataA& e = fv.At(9); if (wcscmp(e.title, L"Pro Soccer Player Blackmail Case") != 0) FAIL("title is not correct"); @@ -167,6 +169,32 @@ TESTS // Wcscpy(fvb->glob, fva->glob); // Wcscpy(fvb->url, fva->url); // } + + TEST(MigrateDlvDataFromPrologToDisk) + { + int cEp; + if (!Pl("episode_data","episode_count",&cEp)) + return; + + { + FileView fv{L"tmp.dat", g_cfg.cEp+128u}; + DlvDataA* p = fv; + + for (int iEp = 1; iEp <= cEp; iEp++) { + DlvDataA d; + FromProlog(iEp, d); + memcpy(p, &d, sizeof(d)); + p++; + } + } + { + FileView fv{L"tmp.dat", g_cfg.cEp+128u}; + DlvDataA& e = fv.At(9); + if (wcscmp(e.date, L"March 11, 1996") != 0) + FAIL("date is not correct"); + } + //DeleteFile(L"tmp.dat"); + } }; int RunTests() @@ -179,6 +207,7 @@ int RunTests() //MigrateElvDataFromPrologToDisk{}, SampleConfigurationToDisk{}, //MigrateCfg{} + MigrateDlvDataFromPrologToDisk{}, }; printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests)); -- cgit v1.2.3