From 4d6cbcdc97fd79befca82ed9ddc0d96ce86f744f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 5 Apr 2022 04:15:20 +0200 Subject: Add episode ratings. --- c/episodelistview.c | 56 ++++++++++++++++++++++++++++++++++++++++++----------- c/main.c | 50 ++++++++++++++++++++++++++++++++++------------- c/resource.h | 6 ++++++ c/resource.rc | 9 +++++++++ 4 files changed, 97 insertions(+), 24 deletions(-) (limited to 'c') diff --git a/c/episodelistview.c b/c/episodelistview.c index 6b00b31..26122c7 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -24,10 +24,15 @@ ElvCreate() lvc.cx = Dpi(42); ListView_InsertColumn(HElv, 0, &lvc); + lvc.iSubItem = 1; + lvc.pszText = TEXT("/"); + lvc.cx = Dpi(20); + ListView_InsertColumn(HElv, 1, &lvc); + lvc.iSubItem = 1; lvc.pszText = TEXT("Title"); lvc.cx = 500; - ListView_InsertColumn(HElv, 1, &lvc); + ListView_InsertColumn(HElv, 2, &lvc); return HElv; } @@ -145,7 +150,9 @@ ElvSelectRecent() iItem = ListView_FindItem(HElv, -1, &lvfi); if (iItem == -1) return; -s: ElvSetTop(iItem > 5? iItem-5: 0); +s: + ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED); + ElvSetTop(iItem > 5? iItem-5: 0); ListView_SetItemState(HElv, iItem, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); LpLviElvSelection->iItem = iItem; @@ -159,7 +166,7 @@ void ElvUpdate() { int iEpisodes, iTop; - LVITEM lviEpisode, lviName; + LVITEM lviEpisode, lviName, lviRating; term_t t; SendMessage(HElv, WM_SETREDRAW, FALSE, 0); @@ -168,6 +175,7 @@ ElvUpdate() 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; @@ -176,19 +184,28 @@ ElvUpdate() for (int i = 0; i < iEpisodes; i++) { char *szName; - int cb; - TCHAR *tszEpisode, *tszName; - term_t t; + 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; - tszName = NULL; 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); + /* Format episode number string. */ ep: cb = 100; tszEpisode = malloc(cb*sizeof(TCHAR)); @@ -202,9 +219,16 @@ ElvUpdate() lviEpisode.lParam = i+1; 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 = 1; + lviName.iSubItem = 2; lviName.pszText = tszName; ListView_SetItem(HElv, &lviName); } @@ -228,8 +252,9 @@ void ElvUpdateName(LPLVITEM lpLvi) { char *szName; - TCHAR *tszName; - term_t t; + int iRating; + TCHAR *tszName, tszRating[10]; + term_t t, t2; t = T(2); PI(t,lpLvi->lParam) return; @@ -241,6 +266,15 @@ ElvUpdateName(LPLVITEM lpLvi) tszName = TszFromSz(szName, CP_UTF8); if (!tszName) return; + ListView_SetItemText(HElv, lpLvi->iItem, 2, tszName); - ListView_SetItemText(HElv, lpLvi->iItem, 1, tszName); + t2 = T(2); + PI(t2,lpLvi->lParam) return; + P("episode_data","episode_rating",2,t2) { + ListView_SetItemText(HElv, lpLvi->iItem, 1, TEXT("")); + return; + } + GI(t2+1,&iRating) return; + _itot(iRating, tszRating, 10); + ListView_SetItemText(HElv, lpLvi->iItem, 1, tszRating); } diff --git a/c/main.c b/c/main.c index 3b370ff..a03e7b5 100644 --- a/c/main.c +++ b/c/main.c @@ -188,12 +188,8 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ElvUpdate(); break; case ID_FILE_RESET: - { - extern HWND HElv; - ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED); ElvSelectRecent(); break; - } case ID_FILE_ABOUT: DialogBox( GetModuleHandle(NULL), @@ -206,6 +202,12 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case ID_TOGGLE: case ID_FORGET: case ID_LOOKUP: + case ID_RATE5: + case ID_RATE4: + case ID_RATE3: + case ID_RATE2: + case ID_RATE1: + case ID_RATE0: { LVITEM lvi; term_t t; @@ -216,7 +218,7 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) lvi.mask = LVIF_PARAM; lvi.iItem = -1; - t = T(1); + t = T(2); while ((lvi.iItem = ListView_GetNextItem( HElv, lvi.iItem, LVNI_SELECTED)) != -1) { if (!ListView_GetItem(HElv, &lvi)) goto b; @@ -241,6 +243,27 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ElvRedraw(); DlvShowEpisode(lvi.lParam); break; + case ID_RATE5: + PI(t+1,5) break; + goto r; + case ID_RATE4: + PI(t+1,4) break; + goto r; + case ID_RATE3: + PI(t+1,3) break; + goto r; + case ID_RATE2: + PI(t+1,2) break; + goto r; + case ID_RATE1: + PI(t+1,1) break; + goto r; + case ID_RATE0: + PI(t+1,0) break; + r: P("episode_data","rate_episode",2,t); + ElvUpdateName(&lvi); + ElvRedraw(); + break; } } b: break; @@ -321,23 +344,24 @@ UpdateLayout() GetClientRect(HWnd, &rc); -#define SETCOLW(lv) \ - ListView_SetColumnWidth(lv, 0, LVSCW_AUTOSIZE); \ - cxColumn = ListView_GetColumnWidth(lv, 0)+4; \ - ListView_SetColumnWidth(lv, 0, cxColumn); \ - ListView_SetColumnWidth(lv, 1, rc.right-cxColumn-CxVScroll-4); - /* Resize data list view. */ SendMessage(HDlv, WM_SETREDRAW, FALSE, 0); cyDlv = rc.bottom - LvHeight(HDlv, 0); MoveWindow(HDlv, 0, cyDlv, rc.right, rc.bottom, TRUE); - SETCOLW(HDlv); + ListView_SetColumnWidth(HDlv, 0, LVSCW_AUTOSIZE); + cxColumn = ListView_GetColumnWidth(HDlv, 0)+4; + ListView_SetColumnWidth(HDlv, 0, cxColumn); + ListView_SetColumnWidth(HDlv, 1, rc.right-cxColumn-CxVScroll-4); SendMessage(HDlv, WM_SETREDRAW, TRUE, 0); /* Resize episode list view. */ SendMessage(HElv, WM_SETREDRAW, FALSE, 0); MoveWindow(HElv, 0, 0, rc.right, cyDlv+1, TRUE); - SETCOLW(HElv); + ListView_SetColumnWidth(HElv, 0, LVSCW_AUTOSIZE); + cxColumn = ListView_GetColumnWidth(HElv, 0)+4; + ListView_SetColumnWidth(HElv, 0, cxColumn); + cxColumn += ListView_GetColumnWidth(HElv, 1); + ListView_SetColumnWidth(HElv, 2, rc.right-cxColumn-CxVScroll-4); SendMessage(HElv, WM_SETREDRAW, TRUE, 0); #undef SETCOLW diff --git a/c/resource.h b/c/resource.h index e810a30..a7c3d28 100644 --- a/c/resource.h +++ b/c/resource.h @@ -15,5 +15,11 @@ #define ID_TOGGLE 422 #define ID_FORGET 423 #define ID_LOOKUP 424 +#define ID_RATE5 425 +#define ID_RATE4 426 +#define ID_RATE3 427 +#define ID_RATE2 428 +#define ID_RATE1 429 +#define ID_RATE0 430 #endif diff --git a/c/resource.rc b/c/resource.rc index 134fe72..de9e1dc 100644 --- a/c/resource.rc +++ b/c/resource.rc @@ -25,6 +25,15 @@ BEGIN MENUITEM "&Toggle", ID_TOGGLE MENUITEM "&Forget", ID_FORGET MENUITEM "&Lookup", ID_LOOKUP + POPUP "&Rate" + BEGIN + MENUITEM "&5", ID_RATE5 + MENUITEM "&4", ID_RATE4 + MENUITEM "&3", ID_RATE3 + MENUITEM "&2", ID_RATE2 + MENUITEM "&1", ID_RATE1 + MENUITEM "&Remove Rating", ID_RATE0 + END END END -- cgit v1.2.3