aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c/episodelistview.c132
-rw-r--r--pl/cfg.pl8
2 files changed, 80 insertions, 60 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 3c0a3a5..b013bc8 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -7,12 +7,15 @@
#include "defs.h"
HWND HElv;
+int ISort;
LPLVITEM LpLviElvSelection; /* Most recently selected episode. */
+static int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM);
HWND
ElvCreate()
{
LVCOLUMN lvc;
+ term_t t;
LpLviElvSelection = malloc(sizeof(LVITEM));
if (!LpLviElvSelection) return NULL;
@@ -34,64 +37,11 @@ ElvCreate()
lvc.cx = 500;
ListView_InsertColumn(HElv, 2, &lvc);
- return HElv;
-}
+ t = T(1);
+ P("cfg","get_sort",1,t);
+ GI(t,&ISort) ISort = 1;
-/* Sort list view items, iSort being the 1-based index of the column
- * to sort by. If iSort is negative, the order is descending. */
-int CALLBACK
-ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
-{
- int iOrder;
- LVITEM lvi1, lvi2;
- lvi1.mask = lvi2.mask = LVIF_PARAM;
- lvi1.iItem = iItem1; lvi2.iItem = iItem2;
- if (!ListView_GetItem(HElv, &lvi1)) return 0;
- if (!ListView_GetItem(HElv, &lvi2)) return 0;
- switch (abs(iSort)) {
- case 1: /* Sort by episode number. */
- iOrder = lvi1.lParam > lvi2.lParam? 1: -1;
- break;
- case 2: /* Sort by rating. */
- {
- 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: iOrder = iRating1 > iRating2? 1: -1;
- break;
- }
- case 3: /* Sort by title. */
- {
- 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;
- cch1 = strlen(sz1);
- cch2 = strlen(sz2);
- cch = cch1 > cch2? cch2: cch1;
- iOrder = _strnicmp(sz1, sz2, cch);
- break;
- }
- default:
- return 0;
- }
- return iSort > 0? iOrder: iOrder*-1;
+ return HElv;
}
LRESULT
@@ -113,10 +63,13 @@ ElvHandleNotify(LPARAM lParam)
case LVN_COLUMNCLICK:
{
int iColumn, iEpFocus;
- static int iSort = 1; /* TODO: Load from cfg. */
+ term_t t;
+ t = T(1);
iColumn = lpNmLv->iSubItem+1;
- iSort = abs(iSort) == iColumn? -iSort: iColumn;
- ListView_SortItemsEx(HElv, ElvSort, iSort);
+ ISort = abs(ISort) == iColumn? -ISort: iColumn;
+ PI(t,ISort) goto s;
+ P("cfg","set_sort",1,t);
+ s: ListView_SortItemsEx(HElv, ElvSort, ISort);
iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
ListView_EnsureVisible(HElv, iEpFocus, TRUE);
@@ -231,6 +184,63 @@ s: ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED);
DlvShowEpisode(iEpisode);
}
+/* Sort list view items, iSort being the 1-based index of the column
+ * to sort by. If iSort is negative, the order is descending. */
+int CALLBACK
+ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
+{
+ int iOrder;
+ LVITEM lvi1, lvi2;
+ lvi1.mask = lvi2.mask = LVIF_PARAM;
+ lvi1.iItem = iItem1; lvi2.iItem = iItem2;
+ if (!ListView_GetItem(HElv, &lvi1)) return 0;
+ if (!ListView_GetItem(HElv, &lvi2)) return 0;
+ switch (abs(iSort)) {
+ case 1: /* Sort by episode number. */
+ iOrder = lvi1.lParam > lvi2.lParam? 1: -1;
+ break;
+ case 2: /* Sort by rating. */
+ {
+ 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: iOrder = iRating1 > iRating2? 1: -1;
+ break;
+ }
+ case 3: /* Sort by title. */
+ {
+ 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;
+ cch1 = strlen(sz1);
+ cch2 = strlen(sz2);
+ cch = cch1 > cch2? cch2: cch1;
+ iOrder = _strnicmp(sz1, sz2, cch);
+ break;
+ }
+ default:
+ return 0;
+ }
+ return iSort > 0? iOrder: iOrder*-1;
+}
+
/* Update episode list. */
void
ElvUpdate()
@@ -347,6 +357,8 @@ ElvUpdate()
_stprintf_s(tszTotal, sizeof(tszTotal), TEXT("%d"), cEp);
SendMessage(HWndStatus, SB_SETTEXT, MAKEWPARAM(2,0), (LPARAM)tszTotal);
SendMessage(HElv, WM_SETREDRAW, TRUE, 0);
+ if (ISort != 1)
+ ListView_SortItemsEx(HElv, ElvSort, ISort);
ElvRedraw();
}
diff --git a/pl/cfg.pl b/pl/cfg.pl
index 78dc267..fa17b38 100644
--- a/pl/cfg.pl
+++ b/pl/cfg.pl
@@ -45,3 +45,11 @@ get_view_tv_original(V) :-
integer(V), !
; V = 1
).
+
+set_sort(V) :- W is V + 2147483647, set_key('Sort', W).
+get_sort(V) :-
+ ( get_key('Sort', W),
+ integer(W), !,
+ V is W - 2147483647
+ ; V = 1
+ ).