c0d8ba932210 — Josef 'Jeff' Sipek a month ago
hlog: add specified-call-only mode to recent contact listing

Instead of listing the last N contacts, allow the displaying of the last N
contacts by a specific callsign.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
3 files changed, 34 insertions(+), 11 deletions(-)

M hlog/common/recent.c
M hlog/common/recent.h
M hlog/contest.c
M hlog/common/recent.c +27 -5
@@ 34,7 34,8 @@ struct recent_line {
 	char str[];
 };
 
-int recent_init(struct recent *r, int height, int width, int row, int col)
+int recent_init(struct recent *r, int height, int width, int row, int col,
+		bool all)
 {
 	size_t i;
 

          
@@ 53,6 54,7 @@ int recent_init(struct recent *r, int he
 			goto err_free;
 	}
 
+	r->all = all;
 	r->reeval = true;
 
 	return 0;

          
@@ 81,19 83,39 @@ void recent_destroy(struct recent *r)
 	delwin(r->win);
 }
 
-void recent_refresh(struct recent *r)
+void recent_refresh(struct recent *r, struct str *call)
 {
+	struct qso *(*next)(struct index_iter_ctx *);
 	struct index_iter_ctx ctx;
 	struct qso *qso;
 	size_t i;
 
-	if (!r->reeval)
+	if (!r->reeval) {
+		str_putref(call);
 		return;
+	}
+
+	if (call) {
+		/* per-call interation with a call specified */
+		ASSERT(!r->all);
+		qso = index_iter_call_history_start(call, &ctx, false);
+		next = index_iter_call_history_next;
+
+		str_putref(call);
+	} else if (!r->all) {
+		/* per-call iteration but without a call specified */
+		qso = NULL;
+		next = NULL;
+	} else {
+		/* all-history iteration */
+		qso = index_iter_history_start(&ctx, false);
+		next = index_iter_history_next;
+	}
 
 	/* cache the text */
-	for (qso = index_iter_history_start(&ctx, false), i = 0;
+	for (i = 0;
 	     qso && (i < r->nrows);
-	     qso = index_iter_history_next(&ctx), i++) {
+	     qso = next(&ctx), i++) {
 		r->lines[i]->uuid = qso->uuid;
 		qso_line_fmt(qso, r->lines[i]->str, r->ncols);
 	}

          
M hlog/common/recent.h +3 -2
@@ 32,14 32,15 @@ struct recent {
 	size_t nrows;
 	size_t ncols;
 	struct recent_line **lines;
+	bool all;
 	bool reeval;
 };
 
 extern int recent_init(struct recent *recent, int height, int width, int row,
-		       int col);
+		       int col, bool all);
 extern void recent_destroy(struct recent *recent);
 extern void recent_invalidate(struct recent *recent);
-extern void recent_refresh(struct recent *recent);
+extern void recent_refresh(struct recent *recent, struct str *call);
 
 /*
  * Legacy recent code, to be removed in the future

          
M hlog/contest.c +4 -4
@@ 472,8 472,8 @@ static void setup_windows(void)
 
 	/* recent QSOs */
 	ret = recent_init(&recent_list, RECENT_WIN_HEIGHT, RECENT_WIN_WIDTH,
-			  RECENT_WIN_ROW, RECENT_WIN_COL);
-	recent_refresh(&recent_list);
+			  RECENT_WIN_ROW, RECENT_WIN_COL, true);
+	recent_refresh(&recent_list, NULL);
 
 	/* current QSO - full */
 	ret = xform_alloc(&current, CURRENT_WIN_HEIGHT, CURRENT_WIN_WIDTH,

          
@@ 488,7 488,7 @@ static void refresh_windows(void)
 	wrefresh(supercheck_win);
 	xform_refresh(&work);
 	status_refresh();
-	recent_refresh(&recent_list);
+	recent_refresh(&recent_list, NULL);
 	xform_refresh(&current);
 
 	/* move cursor to the active form */

          
@@ 637,7 637,7 @@ static int do_contest(lua_State *L)
 		draw_location();
 		draw_clock();
 
-		recent_refresh(&recent_list);
+		recent_refresh(&recent_list, NULL);
 		sync_current();
 		refresh_windows();
 	}