diff options
Diffstat (limited to 'gtk-gui.c')
-rw-r--r-- | gtk-gui.c | 115 |
1 files changed, 91 insertions, 24 deletions
@@ -41,9 +41,7 @@ #include <QTextCodec> #include <QTranslator> -#if HAVE_OSM_GPS_MAP #include <osm-gps-map-source.h> -#endif class Translator: public QTranslator { @@ -84,6 +82,7 @@ const char *existing_filename; typedef enum { PANE_INFO, PANE_PROFILE, PANE_LIST, PANE_THREE } pane_conf_t; static pane_conf_t pane_conf; +int dive_mask, dtag_shown[DTAG_NR]; static struct device_info *holdnicknames = NULL; static GtkWidget *dive_profile_widget(void); static void import_files(GtkWidget *, gpointer); @@ -175,16 +174,12 @@ static GtkFileFilter *setup_filter(void) gtk_file_filter_add_pattern(filter, "*.UDCF"); gtk_file_filter_add_pattern(filter, "*.jlb"); gtk_file_filter_add_pattern(filter, "*.JLB"); -#ifdef LIBZIP gtk_file_filter_add_pattern(filter, "*.sde"); gtk_file_filter_add_pattern(filter, "*.SDE"); gtk_file_filter_add_pattern(filter, "*.dld"); gtk_file_filter_add_pattern(filter, "*.DLD"); -#endif -#ifdef SQLITE3 gtk_file_filter_add_pattern(filter, "*.DB"); gtk_file_filter_add_pattern(filter, "*.db"); -#endif gtk_file_filter_add_mime_type(filter, "text/xml"); gtk_file_filter_set_name(filter, _("XML file")); @@ -672,6 +667,7 @@ OPTIONCALLBACK(maxcns_toggle, prefs.visible_cols.maxcns) OPTIONCALLBACK(sac_toggle, prefs.visible_cols.sac) OPTIONCALLBACK(nitrox_toggle, prefs.visible_cols.nitrox) OPTIONCALLBACK(temperature_toggle, prefs.visible_cols.temperature) +OPTIONCALLBACK(display_invalid_dives_toggle, prefs.display_invalid_dives) OPTIONCALLBACK(totalweight_toggle, prefs.visible_cols.totalweight) OPTIONCALLBACK(suit_toggle, prefs.visible_cols.suit) OPTIONCALLBACK(cylinder_toggle, prefs.visible_cols.cylinder) @@ -768,7 +764,6 @@ static void pick_default_file(GtkWidget *w, GtkButton *button) gtk_widget_set_sensitive(parent, TRUE); } -#if HAVE_OSM_GPS_MAP static GtkWidget * map_provider_widget() { int i; @@ -777,27 +772,24 @@ static GtkWidget * map_provider_widget() /* several of the providers seem to be redundant or non-functional; * we may have to skip more than just the last three eventually */ - for (i = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; i < OSM_GPS_MAP_SOURCE_LAST; i++) - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), osm_gps_map_source_get_friendly_name((OsmGpsMapSource_t)i)); + for (i = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; i <= OSM_GPS_MAP_SOURCE_YAHOO_STREET; i++) + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), osm_gps_map_source_get_friendly_name(i)); #else GtkWidget *combobox = gtk_combo_box_new_text(); - for (i = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; i < OSM_GPS_MAP_SOURCE_LAST; i++) + for (i = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; i <= OSM_GPS_MAP_SOURCE_YAHOO_STREET; i++) gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), osm_gps_map_source_get_friendly_name(i)); #endif /* we don't offer choice 0 (none), so the index here is off by one */ gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), prefs.map_provider - 1); return combobox; } -#endif static void preferences_dialog(GtkWidget *w, gpointer data) { int result; GtkWidget *dialog, *notebook, *font, *frame, *box, *hbox, *vbox, *button; GtkWidget *xmlfile_button; -#if HAVE_OSM_GPS_MAP GtkWidget *map_provider; -#endif GtkWidget *entry_po2, *entry_pn2, *entry_phe, *entry_mod, *entry_gflow, *entry_gfhigh; const char *current_default, *new_default; char threshold_text[10], mod_text[10], utf8_buf[128]; @@ -898,6 +890,11 @@ static void preferences_dialog(GtkWidget *w, gpointer data) box = gtk_hbox_new(FALSE, 6); gtk_container_add(GTK_CONTAINER(frame), box); + button = gtk_check_button_new_with_label(_("Display invalid dives")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.display_invalid_dives); + gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(display_invalid_dives_toggle), NULL); + frame = gtk_frame_new(_("Default XML Data File")); gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 5); hbox = gtk_hbox_new(FALSE, 6); @@ -907,12 +904,12 @@ static void preferences_dialog(GtkWidget *w, gpointer data) g_signal_connect(G_OBJECT(xmlfile_button), "clicked", G_CALLBACK(pick_default_file), xmlfile_button); gtk_box_pack_start(GTK_BOX(hbox), xmlfile_button, FALSE, FALSE, 6); -#if HAVE_OSM_GPS_MAP + frame = gtk_frame_new(_("Map provider")); map_provider = map_provider_widget(); gtk_container_add(GTK_CONTAINER(frame), map_provider); gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3); -#endif + /* vbox that holds the second notebook page */ vbox = gtk_vbox_new(FALSE, 6); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, @@ -955,6 +952,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gtk_entry_set_max_length(GTK_ENTRY(entry_po2), 4); snprintf(threshold_text, sizeof(threshold_text), "%.1f", prefs.pp_graphs.po2_threshold); gtk_entry_set_text(GTK_ENTRY(entry_po2), threshold_text); + gtk_entry_set_activates_default(GTK_ENTRY(entry_po2), TRUE); gtk_widget_set_sensitive(entry_po2, prefs.pp_graphs.po2); gtk_container_add(GTK_CONTAINER(frame), entry_po2); @@ -974,6 +972,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gtk_entry_set_max_length(GTK_ENTRY(entry_pn2), 4); snprintf(threshold_text, sizeof(threshold_text), "%.1f", prefs.pp_graphs.pn2_threshold); gtk_entry_set_text(GTK_ENTRY(entry_pn2), threshold_text); + gtk_entry_set_activates_default(GTK_ENTRY(entry_pn2), TRUE); gtk_widget_set_sensitive(entry_pn2, prefs.pp_graphs.pn2); gtk_container_add(GTK_CONTAINER(frame), entry_pn2); @@ -991,6 +990,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gtk_entry_set_max_length(GTK_ENTRY(entry_phe), 4); snprintf(threshold_text, sizeof(threshold_text), "%.1f", prefs.pp_graphs.phe_threshold); gtk_entry_set_text(GTK_ENTRY(entry_phe), threshold_text); + gtk_entry_set_activates_default(GTK_ENTRY(entry_phe), TRUE); gtk_widget_set_sensitive(entry_phe, prefs.pp_graphs.phe); gtk_container_add(GTK_CONTAINER(frame), entry_phe); @@ -1008,6 +1008,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gtk_entry_set_max_length(GTK_ENTRY(entry_mod), 4); snprintf(mod_text, sizeof(mod_text), "%.1f", prefs.mod_ppO2); gtk_entry_set_text(GTK_ENTRY(entry_mod), mod_text); + gtk_entry_set_activates_default(GTK_ENTRY(entry_mod), TRUE); gtk_widget_set_sensitive(entry_mod, prefs.mod); gtk_container_add(GTK_CONTAINER(frame), entry_mod); @@ -1049,6 +1050,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gtk_entry_set_max_length(GTK_ENTRY(entry_gflow), 4); snprintf(threshold_text, sizeof(threshold_text), "%.0f", prefs.gflow * 100); gtk_entry_set_text(GTK_ENTRY(entry_gflow), threshold_text); + gtk_entry_set_activates_default(GTK_ENTRY(entry_gflow), TRUE); gtk_container_add(GTK_CONTAINER(frame), entry_gflow); gtk_widget_add_events(entry_gflow, GDK_FOCUS_CHANGE_MASK); g_signal_connect(G_OBJECT(entry_gflow), "event", G_CALLBACK(gflow_edit), NULL); @@ -1059,17 +1061,29 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gtk_entry_set_max_length(GTK_ENTRY(entry_gfhigh), 4); snprintf(threshold_text, sizeof(threshold_text), "%.0f", prefs.gfhigh * 100); gtk_entry_set_text(GTK_ENTRY(entry_gfhigh), threshold_text); + gtk_entry_set_activates_default(GTK_ENTRY(entry_gfhigh), TRUE); gtk_container_add(GTK_CONTAINER(frame), entry_gfhigh); gtk_widget_add_events(entry_gfhigh, GDK_FOCUS_CHANGE_MASK); g_signal_connect(G_OBJECT(entry_gfhigh), "event", G_CALLBACK(gfhigh_edit), NULL); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) { const char *po2_threshold_text, *pn2_threshold_text, *phe_threshold_text, *mod_text, *gflow_text, *gfhigh_text; + int j; + struct dive *d; + /* Make sure to flush any modified old dive data with old units */ update_dive(NULL); + /* if we turned off displaying invalid dives. de-select all + * invalid dives that were selected before hiding them */ + if (oldprefs.display_invalid_dives && !prefs.display_invalid_dives) { + for_each_dive(j, d) + if (d->selected && d->dive_tags && DTAG_INVALID) + deselect_dive(j); + } prefs.divelist_font = strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font))); set_divelist_font(prefs.divelist_font); po2_threshold_text = gtk_entry_get_text(GTK_ENTRY(entry_po2)); @@ -1103,7 +1117,6 @@ static void preferences_dialog(GtkWidget *w, gpointer data) if (strcmp(current_default, new_default)) { prefs.default_filename = new_default; } -#if HAVE_OSM_GPS_MAP /* get the map provider selected */ int i; #if GTK_CHECK_VERSION(2,24,0) @@ -1117,8 +1130,9 @@ static void preferences_dialog(GtkWidget *w, gpointer data) break; } free((void *)provider); -#endif + save_preferences(); + dive_list_update_dives(); } else if (result == GTK_RESPONSE_CANCEL) { prefs = oldprefs; set_gf(prefs.gflow, prefs.gfhigh); @@ -1154,6 +1168,56 @@ static void create_toggle(const char* label, int *on, void *_data) count++; } +static void selecttags_dialog(GtkWidget *w, gpointer data) +{ + int i, result; + GtkWidget *dialog, *frame, *vbox, *table; + struct dive *d; + + dialog = gtk_dialog_new_with_buttons(_("Only display dives with these tags:"), + GTK_WINDOW(main_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + NULL); + /* initialize the function that fills the table */ + create_toggle(NULL, NULL, NULL); + + frame = gtk_frame_new(_("Enable / Disable Tags")); + vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); + + table = gtk_table_new(1, 4, TRUE); + for (i = 0; i < DTAG_NR; i++) { + create_toggle(_(dtag_names[i]), &dtag_shown[i], table); + } + gtk_container_add(GTK_CONTAINER(frame), table); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + gtk_widget_show_all(dialog); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result == GTK_RESPONSE_ACCEPT) { + dive_mask = 0; + for (i = 0; i < DTAG_NR; i++) + if (dtag_shown[i]) + dive_mask |= (1 << i); + + /* deselect dives filtered by tags before hiding */ + for_each_dive(i, d) + if (d->selected && (d->dive_tags & dive_mask) != dive_mask) + deselect_dive(i); + + dive_list_update_dives(); + process_selected_dives(); + show_dive_stats(current_dive); + } else { + /* restore tags selection from dive_mask */ + for (i = 0; i < DTAG_NR; i++) { + dtag_shown[i] = 1 & dive_mask >> i; + } + } + gtk_widget_destroy(dialog); +} + static void selectevents_dialog(GtkWidget *w, gpointer data) { int result; @@ -1181,6 +1245,7 @@ static void selectevents_dialog(GtkWidget *w, gpointer data) gtk_container_add(GTK_CONTAINER(frame), table); } + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) { @@ -1227,6 +1292,7 @@ static void renumber_dialog(GtkWidget *w, gpointer data) gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); button = gtk_spin_button_new_with_range(1, 50000, 1); + gtk_entry_set_activates_default(GTK_ENTRY(button), TRUE); gtk_container_add(GTK_CONTAINER(frame), button); /* @@ -1237,6 +1303,7 @@ static void renumber_dialog(GtkWidget *w, gpointer data) if (dive && dive->number) gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), dive->number); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) { @@ -1546,7 +1613,7 @@ static void edit_dc_nicknames(GtkWidget *w, gpointer data) vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); gtk_container_add(GTK_CONTAINER(scroll), view); gtk_container_add(GTK_CONTAINER(vbox), - gtk_label_new(_("Edit a dive computer nickname by double-clicking the in the relevant nickname field"))); + gtk_label_new(_("Edit a dive computer nickname by double-clicking it in the relevant nickname field"))); gtk_container_add(GTK_CONTAINER(vbox), scroll); gtk_widget_set_size_request(scroll, 500, 300); gtk_widget_show_all(dialog); @@ -1611,16 +1678,16 @@ static GtkActionEntry menu_items[] = { { "Print", GTK_STOCK_PRINT, N_("Print..."), CTRLCHAR "P", NULL, G_CALLBACK(do_print) }, { "ImportFile", NULL, N_("Import File(s)..."), CTRLCHAR "I", NULL, G_CALLBACK(import_files) }, { "ExportUDDF", NULL, N_("Export UDDF..."), NULL, NULL, G_CALLBACK(export_all_dives_uddf_cb) }, + { "UploadDivelogs", NULL, N_("Upload to divelogs.de..."), NULL, NULL, G_CALLBACK(upload_all_dives_divelogs_cb) }, { "DownloadLog", NULL, N_("Download From Dive Computer..."), CTRLCHAR "D", NULL, G_CALLBACK(download_dialog) }, { "DownloadWeb", GTK_STOCK_CONNECT, N_("Download From Web Service..."), NULL, NULL, G_CALLBACK(webservice_download_dialog) }, { "AddDive", GTK_STOCK_ADD, N_("Add Dive..."), NULL, NULL, G_CALLBACK(add_dive_cb) }, { "Preferences", GTK_STOCK_PREFERENCES, N_("Preferences..."), PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) }, { "Renumber", NULL, N_("Renumber..."), NULL, NULL, G_CALLBACK(renumber_dialog) }, { "YearlyStats", NULL, N_("Yearly Statistics"), NULL, NULL, G_CALLBACK(show_yearly_stats) }, -#if HAVE_OSM_GPS_MAP { "DivesLocations", NULL, N_("Dives Locations"), CTRLCHAR "M", NULL, G_CALLBACK(show_gps_locations) }, -#endif { "SelectEvents", NULL, N_("Select Events..."), NULL, NULL, G_CALLBACK(selectevents_dialog) }, + { "SelectTags", NULL, N_("Select Tags..."), NULL, NULL, G_CALLBACK(selecttags_dialog) }, { "Quit", GTK_STOCK_QUIT, N_("Quit"), CTRLCHAR "Q", NULL, G_CALLBACK(quit) }, { "About", GTK_STOCK_ABOUT, N_("About Subsurface"), NULL, NULL, G_CALLBACK(about_dialog) }, { "UserManual", GTK_STOCK_HELP, N_("User Manual"), NULL, NULL, G_CALLBACK(show_user_manual) }, @@ -1652,8 +1719,9 @@ static const gchar* ui_string = " \ <menuitem name=\"Close\" action=\"CloseFile\" /> \ <separator name=\"Separator1\"/> \ <menuitem name=\"Import XML File\" action=\"ImportFile\" /> \ - <menuitem name=\"Export to UDDF File\" action=\"ExportUDDF\" /> \ - <separator name=\"Separator2\"/> \ + <menuitem name=\"Export to UDDF File\" action=\"ExportUDDF\" />" + "<menuitem name=\"Upload to divelogs.de\" action=\"UploadDivelogs\" />" + "<separator name=\"Separator2\"/> \ <menuitem name=\"Print\" action=\"Print\" /> \ <separator name=\"Separator3\"/> \ <menuitem name=\"Preferences\" action=\"Preferences\" /> \ @@ -1671,9 +1739,7 @@ static const gchar* ui_string = " \ <menuitem name=\"Autogroup\" action=\"Autogroup\" /> \ <menuitem name=\"Toggle Zoom\" action=\"ToggleZoom\" /> \ <menuitem name=\"YearlyStats\" action=\"YearlyStats\" />" -#if HAVE_OSM_GPS_MAP "<menuitem name=\"Dive Locations\" action=\"DivesLocations\" /> " -#endif "</menu> \ <menu name=\"ViewMenu\" action=\"ViewMenuAction\"> \ <menuitem name=\"List\" action=\"ViewList\" /> \ @@ -1685,6 +1751,7 @@ static const gchar* ui_string = " \ </menu> \ <menu name=\"FilterMenu\" action=\"FilterMenuAction\"> \ <menuitem name=\"SelectEvents\" action=\"SelectEvents\" /> \ + <menuitem name=\"SelectTags\" action=\"SelectTags\" /> \ </menu> \ <menu name=\"PlannerMenu\" action=\"PlannerMenuAction\"> \ <menuitem name=\"InputPlan\" action=\"InputPlan\" /> \ |