summaryrefslogtreecommitdiffstats
path: root/info-gtk.c
diff options
context:
space:
mode:
Diffstat (limited to 'info-gtk.c')
-rw-r--r--info-gtk.c108
1 files changed, 89 insertions, 19 deletions
diff --git a/info-gtk.c b/info-gtk.c
index b386b9d4d..4ba9058cf 100644
--- a/info-gtk.c
+++ b/info-gtk.c
@@ -267,7 +267,7 @@ struct dive_info {
GtkTextView *notes;
};
-static void save_dive_info_changes(struct dive *dive, struct dive *master, struct dive_info *info)
+static void save_dive_info_changes(struct dive *dive, struct dive *master, struct dive_info *info, int tags_shown)
{
char *old_text, *new_text;
const char *gps_text;
@@ -346,6 +346,17 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc
if (old_text)
g_free(old_text);
}
+ if (tags_shown && dive->dive_tags != master->dive_tags) {
+ changed = 1;
+ dive->dive_tags = master->dive_tags;
+ /* if a dive is selected and we aren't showing invalid dives and it is
+ * now marked as invalid we need to deselect it to keep the selection
+ * state consistent */
+ if (!prefs.display_invalid_dives && dive->selected && dive->dive_tags & DTAG_INVALID) {
+ dive->selected = 0;
+ amount_selected--;
+ }
+ }
if (changed) {
mark_divelist_changed(TRUE);
update_dive(dive);
@@ -386,7 +397,6 @@ static void update_gps_entry(int lat, int lon)
}
}
-#if HAVE_OSM_GPS_MAP
static void update_gps_entry_callback(float lat, float lon)
{
update_gps_entry(lat * 1000000, lon * 1000000);
@@ -409,7 +419,6 @@ static gboolean gps_map_callback(GtkWidget *w, gpointer data)
show_gps_location(&fake_dive, update_gps_entry_callback);
return TRUE;
}
-#endif
/*
* If somebody sets the string by editing the text entry,
@@ -501,16 +510,25 @@ static gboolean base_data_cb(GtkWidget *w, GdkEvent *event, gpointer _data)
return FALSE;
}
-static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_info *info, gboolean multi)
+void divetag_toggle_cb(GtkWidget *widget, gpointer data)
+{
+ int togglebit = GPOINTER_TO_INT (data);
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ edit_dive.dive_tags |= togglebit;
+ else
+ edit_dive.dive_tags &= ~togglebit;
+}
+
+static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_info *info, int multi, int *show_tags)
{
- GtkWidget *hbox, *frame, *equipment, *ibox, *box;
-#if HAVE_OSM_GPS_MAP
+ GtkWidget *hbox, *frame, *equipment, *ibox, *box, *button, *sbox, *framebox;
GtkWidget *image;
-#endif
char buffer[256];
char airtemp[10];
const char *unit;
double value;
+ int i, tags;
+ struct dive *otherdive;
if (multi) {
GtkWidget *label;
@@ -518,7 +536,9 @@ static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_inf
label = gtk_label_new(buffer);
gtk_box_pack_start(GTK_BOX(obox), label, FALSE, TRUE, 0);
} else {
- GtkWidget *basedata = gtk_button_new_with_label(buffer);
+ GtkWidget *basedata;
+ snprintf(buffer, sizeof(buffer), "%s", _("Edit dive"));
+ basedata = gtk_button_new_with_label(buffer);
set_dive_button_label(basedata, dive);
g_signal_connect(G_OBJECT(basedata), "button-press-event", G_CALLBACK(base_data_cb), dive);
gtk_box_pack_start(GTK_BOX(obox), basedata, FALSE, TRUE, 0);
@@ -544,7 +564,6 @@ static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_inf
gtk_widget_add_events(GTK_WIDGET(info->gps), GDK_FOCUS_CHANGE_MASK);
g_signal_connect(G_OBJECT(info->gps), "focus-out-event", G_CALLBACK(gps_entry_change_cb), NULL);
gtk_entry_set_width_chars(info->gps, 30);
-#if HAVE_OSM_GPS_MAP
info->gps_icon = gtk_button_new_with_label(_("Pick on map"));
gtk_box_pack_start(GTK_BOX(hbox), info->gps_icon, FALSE, FALSE, 6);
image = gtk_image_new_from_pixbuf(get_gps_icon());
@@ -552,7 +571,6 @@ static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_inf
gtk_button_set_image(GTK_BUTTON(info->gps_icon), image);
g_signal_connect(G_OBJECT(info->gps_icon), "clicked", G_CALLBACK(gps_map_callback), NULL);
-#endif
hbox = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
@@ -578,6 +596,40 @@ static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_inf
airtemp[0] = '\0';
info->airtemp = single_text_entry(hbox, buffer, airtemp);
+ frame = gtk_frame_new(_("Dive Tags"));
+ gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0);
+
+ framebox = gtk_vbox_new(FALSE, 3);
+ gtk_container_add(GTK_CONTAINER(frame), framebox);
+
+ /* we only want to show the tags if we have a single dive or if all selected
+ * dives have the exact same set of tags (like none at all right after import) */
+ i = 0;
+ *show_tags = 1;
+ tags = dive->dive_tags;
+ for_each_dive(i, otherdive)
+ if (otherdive && otherdive->selected && otherdive->dive_tags != tags)
+ *show_tags = 0;
+ if (*show_tags) {
+ /* check boxes for the (currently fixed) list of tags;
+ * let's do 5 per row */
+ const int cols = 5;
+ int rows = DTAG_NR / cols + (DTAG_NR % cols) ? 1 : 0;
+ GtkWidget *table = gtk_table_new(rows, cols, TRUE);
+ for (i = 0; i < DTAG_NR; i++) {
+ int x = i % cols;
+ int y = i / cols;
+ button = gtk_check_button_new_with_label(_(dtag_names[i]));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & (1 << i));
+ gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1);
+ g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb),
+ GINT_TO_POINTER(1 << i));
+ }
+ gtk_box_pack_start(GTK_BOX(framebox), table, TRUE, FALSE, 3);
+ } else {
+ sbox = gtk_label_new(_("Tags are only shown if they are identical for all edited dives"));
+ gtk_box_pack_start(GTK_BOX(framebox), sbox, TRUE, FALSE, 3);
+ }
/* only show notes if editing a single dive */
if (multi) {
info->notes = NULL;
@@ -646,7 +698,8 @@ int edit_multi_dive_info(struct dive *single_dive)
GtkRequisition size;
struct dive_info info;
struct dive *master;
- gboolean multi;
+ int multi;
+ int tags_shown;
scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
@@ -686,7 +739,7 @@ int edit_multi_dive_info(struct dive *single_dive)
* edit widgets as we do here */
memcpy(&edit_dive, master, sizeof(struct dive));
- dive_info_widget(vbox, &edit_dive, &info, multi);
+ dive_info_widget(vbox, &edit_dive, &info, multi, &tags_shown);
save_equipment_data(&edit_dive);
gtk_widget_show_all(dialog);
viewport = gtk_widget_get_ancestor(vbox, GTK_TYPE_VIEWPORT);
@@ -710,7 +763,7 @@ int edit_multi_dive_info(struct dive *single_dive)
if (dive == master || !dive->selected)
continue;
/* copy all "info" fields */
- save_dive_info_changes(dive, &edit_dive, &info);
+ save_dive_info_changes(dive, &edit_dive, &info, tags_shown);
/* copy the cylinders / weightsystems */
update_equipment_data(dive, &edit_dive);
/* this is extremely inefficient... it loops through all
@@ -721,13 +774,20 @@ int edit_multi_dive_info(struct dive *single_dive)
}
/* Update the master dive last! */
- save_dive_info_changes(master, &edit_dive, &info);
+ save_dive_info_changes(master, &edit_dive, &info, tags_shown);
update_equipment_data(master, &edit_dive);
update_cylinder_related_info(master);
/* if there was only one dive we might also have changed dive->when
* or even the duration and depth information (in a dive without samples) */
- if (! multi)
+ if (! multi) {
update_time_depth(master, &edit_dive);
+ /* these values could have changed because of the edit - so let's
+ * recreate them */
+ master->duration.seconds = 0;
+ master->maxdepth.mm = 0;
+ master->meandepth.mm = 0;
+ (void)fixup_dive(master);
+ }
dive_list_update_dives();
}
gtk_widget_destroy(dialog);
@@ -875,8 +935,13 @@ static int dive_time_widget(struct dive *dive, edit_control_t editing)
depthinterval = 0.1;
}
depth = gtk_spin_button_new_with_range (0.0, 1000.0, depthinterval);
- if (editing != EDIT_NEW_DIVE)
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(depth), dive->dc.maxdepth.mm / 1000.0);
+ if (editing != EDIT_NEW_DIVE) {
+ if (prefs.units.length == FEET) {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(depth), mm_to_feet(dive->dc.maxdepth.mm));
+ } else {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(depth), dive->dc.maxdepth.mm / 1000.0);
+ }
+ }
gtk_box_pack_end(GTK_BOX(box), depth, FALSE, FALSE, 0);
box = frame_box(hbox, _("Avg Depth (%s):"), prefs.units.length == FEET ? _("ft") : _("m"));
@@ -886,8 +951,13 @@ static int dive_time_widget(struct dive *dive, edit_control_t editing)
depthinterval = 0.1;
}
avgdepth = gtk_spin_button_new_with_range (0.0, 1000.0, depthinterval);
- if (editing != EDIT_NEW_DIVE)
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(avgdepth), dive->dc.meandepth.mm / 1000.0);
+ if (editing != EDIT_NEW_DIVE) {
+ if (prefs.units.length == FEET) {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(avgdepth), mm_to_feet(dive->dc.meandepth.mm));
+ } else {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(avgdepth), dive->dc.meandepth.mm / 1000.0);
+ }
+ }
gtk_box_pack_end(GTK_BOX(box), avgdepth, FALSE, FALSE, 0);
}
/* All done, show it and wait for editing */