contest: reset the qso when the form becomes empty

Users assume that backspacing the form will reset the start time.  Let's not
surprise them.

Note that if the form has whitespace, then it is not considered empty.

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

M hlog/contest/ui-work.c
M hlog/contest/ui-work.c +25 -3
@@ 1,5 1,5 @@ 
 /*
- * Copyright (c) 2021-2022,2024 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2021-2022,2024-2025 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal

          
@@ 31,6 31,22 @@ 
 
 struct xform work; /* current QSO contest exchange */
 
+/* return whether or not the form is completely empty */
+static bool form_empty(struct xform *form)
+{
+	size_t i;
+
+	for (i = 0; i < form->nfields; i++) {
+		size_t size;
+
+		xform_field_get(form, i, &size);
+		if (size)
+			return false; /* this field is not empty */
+	}
+
+	return true;
+}
+
 static void wrapped_set_field_buffer(struct xform *form, const char *key,
 				     const char *value)
 {

          
@@ 178,13 194,19 @@ void ui_work_dispatch(struct xlua_state 
 		case '\b':
 		case 127:
 			xform_driver(form, XFORM_REQ_DEL_PREV);
-			field_changed(lua, *qso); /* inform script */
+			if (form_empty(form))
+				abort_qso(lua, qso);
+			else
+				field_changed(lua, *qso); /* inform script */
 			recent_invalidate(&recent_work_list);
 			break;
 
 		case KEY_DC:
 			xform_driver(form, XFORM_REQ_DEL_THIS);
-			field_changed(lua, *qso); /* inform script */
+			if (form_empty(form))
+				abort_qso(lua, qso);
+			else
+				field_changed(lua, *qso); /* inform script */
 			recent_invalidate(&recent_work_list);
 			break;