repaint_dive();
}
-static gboolean set_one_dive(GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer data)
+static const char *weekday(int wday)
+{
+ static const char wday_array[7][4] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+ };
+ return wday_array[wday];
+}
+
+static const char *monthname(int mon)
+{
+ static const char month_array[12][4] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Oct", "Sep", "Nov", "Dec",
+ };
+ return month_array[mon];
+}
+
+static void get_date(struct dive *dive, int *val, char **str)
{
- int len;
- GValue value = {0, };
- struct dive *dive;
- char buffer[256], *datestr, *depth, *duration;
struct tm *tm;
- int integer, frac;
+ time_t when = dive->when;
+ char buffer[40];
- /* Get the dive number */
- gtk_tree_model_get_value(model, iter, DIVE_INDEX, &value);
- dive = get_dive(g_value_get_int(&value));
- if (!dive)
- return TRUE;
+ /* 2038 problem */
+ *val = when;
tm = gmtime(&dive->when);
- len = snprintf(buffer, sizeof(buffer),
- "%02d.%02d.%02d %02d:%02d",
- tm->tm_mday, tm->tm_mon+1, tm->tm_year % 100,
+ snprintf(buffer, sizeof(buffer),
+ "%s, %s %d, %d %02d:%02d",
+ weekday(tm->tm_wday),
+ monthname(tm->tm_mon),
+ tm->tm_mday, tm->tm_year + 1900,
tm->tm_hour, tm->tm_min);
- datestr = malloc(len+1);
- memcpy(datestr, buffer, len+1);
+ *str = strdup(buffer);
+}
+
+static void get_depth(struct dive *dive, int *val, char **str)
+{
+ int len;
+ int depth = dive->maxdepth.mm;
+ int integer, frac = -1;
+ char buffer[10];
+ *val = depth;
+ *str = "";
switch (output_units.length) {
- unsigned int depth;
case METERS:
- depth = (dive->maxdepth.mm + 49) / 100;
+ /* To tenths of meters */
+ depth = (depth + 49) / 100;
integer = depth / 10;
frac = depth % 10;
if (integer < 20)
case FEET:
integer = to_feet(dive->maxdepth);
frac = -1;
+ break;
+ default:
+ return;
}
len = snprintf(buffer, sizeof(buffer),
"%d", integer);
if (frac >= 0)
len += snprintf(buffer+len, sizeof(buffer)-len,
".%d", frac);
- depth = malloc(len + 1);
- memcpy(depth, buffer, len+1);
+ *str = strdup(buffer);
+}
- len = snprintf(buffer, sizeof(buffer),
- "%d", dive->duration.seconds / 60);
- duration = malloc(len + 1);
- memcpy(duration, buffer, len+1);
+static void get_duration(struct dive *dive, int *val, char **str)
+{
+ unsigned int sec = dive->duration.seconds;
+ char buffer[16];
+
+ *val = sec;
+ snprintf(buffer, sizeof(buffer), "%d:%02d", sec / 60, sec % 60);
+ *str = strdup(buffer);
+}
+
+static void get_temp(struct dive *dive, int *val, char **str)
+{
+ int value = dive->watertemp.mkelvin;
+ char buffer[80];
+
+ *val = value;
+ *str = "";
+ if (value) {
+ double deg;
+ switch (output_units.temperature) {
+ case CELSIUS:
+ deg = mkelvin_to_C(value);
+ break;
+ case FAHRENHEIT:
+ deg = mkelvin_to_F(value);
+ break;
+ default:
+ return;
+ }
+ snprintf(buffer, sizeof(buffer), "%.1f", deg);
+ *str = strdup(buffer);
+ }
+}
+
+static void get_nitrox(struct dive *dive, int *val, char **str)
+{
+ int value = dive->cylinder[0].gasmix.o2.permille;
+ char buffer[80];
+
+ *val = value;
+ *str = "";
+ if (value) {
+ snprintf(buffer, sizeof(buffer), "%.1f", value/10.0);
+ *str = strdup(buffer);
+ }
+}
+
+static void get_sac(struct dive *dive, int *val, char **str)
+{
+ *val = 0;
+ *str = "";
+}
+
+static gboolean set_one_dive(GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GValue value = {0, };
+ struct dive *dive;
+ int date, depth, duration, temp, nitrox, sac;
+ char *datestr, *depthstr, *durationstr, *tempstr, *nitroxstr, *sacstr;
+
+ /* Get the dive number */
+ gtk_tree_model_get_value(model, iter, DIVE_INDEX, &value);
+ dive = get_dive(g_value_get_int(&value));
+ if (!dive)
+ return TRUE;
+
+ get_date(dive, &date, &datestr);
+ get_depth(dive, &depth, &depthstr);
+ get_duration(dive, &duration, &durationstr);
+ get_temp(dive, &temp, &tempstr);
+ get_nitrox(dive, &nitrox, &nitroxstr);
+ get_sac(dive, &sac, &sacstr);
/*
* We only set the fields that changed: the strings.
*/
gtk_list_store_set(GTK_LIST_STORE(model), iter,
DIVE_DATESTR, datestr,
- DIVE_DEPTHSTR, depth,
- DIVE_DURATIONSTR, duration,
+ DIVE_DEPTHSTR, depthstr,
+ DIVE_DURATIONSTR, durationstr,
+ DIVE_TEMPSTR, tempstr,
+ DIVE_TEMP, temp,
+ DIVE_NITROXSTR, nitroxstr,
+ DIVE_NITROX, nitrox,
+ DIVE_SACSTR, sacstr,
+ DIVE_NITROX, sac,
-1);
return FALSE;
DIVE_DEPTH, dive->maxdepth,
DIVE_DURATIONSTR, "duration",
DIVE_DURATION, dive->duration.seconds,
+ DIVE_TEMPSTR, "temp",
+ DIVE_TEMP, dive->watertemp.mkelvin,
+ DIVE_NITROXSTR, "21.0",
+ DIVE_NITROX, dive->cylinder[0].gasmix.o2,
+ DIVE_SACSTR, "sac",
+ DIVE_SAC, 0,
-1);
}