aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c/episodelistview.c62
1 files changed, 21 insertions, 41 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 28274ef..3c0a3a5 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -37,26 +37,27 @@ ElvCreate()
return HElv;
}
+/* 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
-ElvSortNum(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
{
int iOrder;
LVITEM lvi1, lvi2;
lvi1.mask = lvi2.mask = LVIF_PARAM;
- lvi1.iItem = lParam1;
- lvi2.iItem = lParam2;
+ lvi1.iItem = iItem1; lvi2.iItem = iItem2;
if (!ListView_GetItem(HElv, &lvi1)) return 0;
if (!ListView_GetItem(HElv, &lvi2)) return 0;
- switch (abs(lParamSort)) {
- case 1:
+ switch (abs(iSort)) {
+ case 1: /* Sort by episode number. */
iOrder = lvi1.lParam > lvi2.lParam? 1: -1;
break;
- case 2:
+ case 2: /* Sort by rating. */
{
int iRating1, iRating2;
term_t t, t2;
- iRating1 = lParamSort > 0? 99: -1;
- iRating2 = lParamSort > 0? 99: -1;
+ 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;
@@ -68,22 +69,7 @@ ElvSortNum(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
f: iOrder = iRating1 > iRating2? 1: -1;
break;
}
- }
- return lParamSort > 0? iOrder: iOrder*-1;
-}
-
-int CALLBACK
-ElvSortAlpha(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
-{
- int iOrder;
- LVITEM lvi1, lvi2;
- lvi1.mask = lvi2.mask = LVIF_PARAM;
- lvi1.iItem = lParam1;
- lvi2.iItem = lParam2;
- if (!ListView_GetItem(HElv, &lvi1)) return 0;
- if (!ListView_GetItem(HElv, &lvi2)) return 0;
- switch (abs(lParamSort)) {
- case 3:
+ case 3: /* Sort by title. */
{
char *sz1, *sz2;
int cch, cch1, cch2;
@@ -91,11 +77,11 @@ ElvSortAlpha(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
t = T(2);
PI(t,lvi1.lParam) return 0;
P("episode_data","episode_title",2,t) return 0;
- GAC(t+1,&sz1);
+ 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);
+ GAC(t2+1,&sz2) return 0;
cch1 = strlen(sz1);
cch2 = strlen(sz2);
cch = cch1 > cch2? cch2: cch1;
@@ -105,7 +91,7 @@ ElvSortAlpha(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
default:
return 0;
}
- return lParamSort > 0? iOrder: iOrder*-1;
+ return iSort > 0? iOrder: iOrder*-1;
}
LRESULT
@@ -126,20 +112,14 @@ ElvHandleNotify(LPARAM lParam)
break;
case LVN_COLUMNCLICK:
{
- static int iSort = 1;
- if (abs(iSort) == lpNmLv->iSubItem+1)
- iSort = -iSort;
- else
- iSort = lpNmLv->iSubItem+1;
- switch (lpNmLv->iSubItem) {
- case 0:
- case 1:
- ListView_SortItemsEx(HElv, ElvSortNum, iSort);
- break;
- case 2:
- ListView_SortItemsEx(HElv, ElvSortAlpha, iSort);
- break;
- }
+ int iColumn, iEpFocus;
+ static int iSort = 1; /* TODO: Load from cfg. */
+ iColumn = lpNmLv->iSubItem+1;
+ iSort = abs(iSort) == iColumn? -iSort: iColumn;
+ ListView_SortItemsEx(HElv, ElvSort, iSort);
+ iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
+ if (iEpFocus == -1) break;
+ ListView_EnsureVisible(HElv, iEpFocus, TRUE);
break;
}
case NM_CUSTOMDRAW: /* Make unwatched episodes bold. */