aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conversions.h16
-rw-r--r--dive.h2
-rw-r--r--divelist.c1
-rw-r--r--download-dialog.c465
-rw-r--r--equipment.c1555
-rw-r--r--gps.c264
-rw-r--r--gtk-gui.c2610
-rw-r--r--libdivecomputer.c18
-rw-r--r--linux.c26
-rw-r--r--macos.c213
-rw-r--r--planner.c214
-rw-r--r--planner.h3
-rw-r--r--print.c1127
-rw-r--r--subsurfacestartup.c3
-rw-r--r--uemis-downloader.c90
-rw-r--r--webservice.c409
-rw-r--r--windows.c233
17 files changed, 4 insertions, 7245 deletions
diff --git a/conversions.h b/conversions.h
deleted file mode 100644
index f59fcc96b..000000000
--- a/conversions.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * conversions.h
- *
- * Helpers to convert between different units
- *
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void convert_volume_pressure(int ml, int mbar, double *v, double *p);
-int convert_pressure(int mbar, double *p);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/dive.h b/dive.h
index f2d8f236d..a6347b897 100644
--- a/dive.h
+++ b/dive.h
@@ -694,9 +694,7 @@ typedef enum {
} os_feature_t;
extern const char *existing_filename;
-extern const char *subsurface_gettext_domainpath(char *);
extern bool subsurface_os_feature_available(os_feature_t);
-extern bool subsurface_launch_for_uri(const char *);
extern void subsurface_command_line_init(int *, char ***);
extern void subsurface_command_line_exit(int *, char ***);
diff --git a/divelist.c b/divelist.c
index e0ad204b7..1e4e344c1 100644
--- a/divelist.c
+++ b/divelist.c
@@ -46,7 +46,6 @@
#include "dive.h"
#include "divelist.h"
#include "display.h"
-#include "webservice.h"
static short dive_list_changed = FALSE;
diff --git a/download-dialog.c b/download-dialog.c
deleted file mode 100644
index b5632d593..000000000
--- a/download-dialog.c
+++ /dev/null
@@ -1,465 +0,0 @@
-#include "dive.h"
-#include "divelist.h"
-#include "display.h"
-#include "libdivecomputer.h"
-
-const char *default_dive_computer_vendor;
-const char *default_dive_computer_product;
-const char *default_dive_computer_device;
-
-
-
-struct vendor *dc_list;
-
-#if USE_GTK_UI
-static void render_dc_vendor(GtkCellLayout *cell,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- const char *vendor;
-
- gtk_tree_model_get(model, iter, 0, &vendor, -1);
- g_object_set(renderer, "text", vendor, NULL);
-}
-
-static void render_dc_product(GtkCellLayout *cell,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- dc_descriptor_t *descriptor = NULL;
- const char *product;
-
- gtk_tree_model_get(model, iter, 0, &descriptor, -1);
- product = dc_descriptor_get_product(descriptor);
- g_object_set(renderer, "text", product, NULL);
-}
-#endif
-
-int is_default_dive_computer(const char *vendor, const char *product)
-{
- return default_dive_computer_vendor && !strcmp(vendor, default_dive_computer_vendor) &&
- default_dive_computer_product && !strcmp(product, default_dive_computer_product);
-}
-
-int is_default_dive_computer_device(const char *name)
-{
- return default_dive_computer_device && !strcmp(name, default_dive_computer_device);
-}
-
-void set_default_dive_computer(const char *vendor, const char *product)
-{
- if (!vendor || !*vendor)
- return;
- if (!product || !*product)
- return;
- if (is_default_dive_computer(vendor, product))
- return;
- if (default_dive_computer_vendor)
- free((void *)default_dive_computer_vendor);
- if (default_dive_computer_product)
- free((void *)default_dive_computer_product);
- default_dive_computer_vendor = strdup(vendor);
- default_dive_computer_product = strdup(product);
- subsurface_set_conf("dive_computer_vendor", vendor);
- subsurface_set_conf("dive_computer_product", product);
-}
-
-void set_default_dive_computer_device(const char *name)
-{
- if (!name || !*name)
- return;
- if (is_default_dive_computer_device(name))
- return;
- if (default_dive_computer_device)
- free((void *)default_dive_computer_device);
- default_dive_computer_device = strdup(name);
- subsurface_set_conf("dive_computer_device", name);
-}
-
-#if USE_GTK_UI
-static void dive_computer_selector_changed(GtkWidget *combo, gpointer data)
-{
- GtkWidget *import, *button;
-
-#if DC_VERSION_CHECK(0, 4, 0)
- GtkTreeIter iter;
- if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) {
- GtkTreeModel *model;
- dc_descriptor_t *descriptor;
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(combo));
- gtk_tree_model_get(model, &iter, 0, &descriptor, -1);
- gtk_widget_set_sensitive(GTK_WIDGET(data), dc_descriptor_get_transport (descriptor) == DC_TRANSPORT_SERIAL);
- }
-#endif
-
- import = gtk_widget_get_ancestor(combo, GTK_TYPE_DIALOG);
- button = gtk_dialog_get_widget_for_response(GTK_DIALOG(import), GTK_RESPONSE_ACCEPT);
- gtk_widget_set_sensitive(button, TRUE);
-}
-
-static GtkListStore **product_model;
-static void dive_computer_vendor_changed(GtkComboBox *vendorcombo, GtkComboBox *productcombo)
-{
- int vendor = gtk_combo_box_get_active(vendorcombo);
- gtk_combo_box_set_model(productcombo, GTK_TREE_MODEL(product_model[vendor + 1]));
- gtk_combo_box_set_active(productcombo, -1);
-}
-
-static GtkWidget *import_dive_computer(device_data_t *data, GtkDialog *dialog)
-{
- GError *error;
- GtkWidget *vbox, *info, *container, *label, *button;
-
- /* HACK to simply include the Uemis Zurich in the list */
- if (! strcmp(data->vendor, "Uemis") && ! strcmp(data->product, "Zurich")) {
- error = uemis_download(data->devname, &data->progress, data->dialog, data->force_download);
- } else {
- error = do_import(data);
- }
- if (!error)
- return NULL;
-
- button = gtk_dialog_get_widget_for_response(dialog, GTK_RESPONSE_ACCEPT);
- gtk_button_set_use_stock(GTK_BUTTON(button), 0);
- gtk_button_set_label(GTK_BUTTON(button), _("Retry"));
-
- vbox = gtk_dialog_get_content_area(dialog);
-
- info = gtk_info_bar_new();
- container = gtk_info_bar_get_content_area(GTK_INFO_BAR(info));
- label = gtk_label_new(error->message);
- gtk_container_add(GTK_CONTAINER(container), label);
- gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
- return info;
-}
-#endif
-
-/* create a list of lists and keep the elements sorted */
-void add_dc(const char *vendor, const char *product, dc_descriptor_t *descriptor)
-{
- struct vendor *dcl = dc_list;
- struct vendor **dclp = &dc_list;
- struct product *pl, **plp;
-
- if (!vendor || !product)
- return;
- while (dcl && strcmp(dcl->vendor, vendor) < 0) {
- dclp = &dcl->next;
- dcl = dcl->next;
- }
- if (!dcl || strcmp(dcl->vendor, vendor)) {
- dcl = calloc(sizeof(struct vendor), 1);
- dcl->next = *dclp;
- *dclp = dcl;
- dcl->vendor = strdup(vendor);
- }
- /* we now have a pointer to the requested vendor */
- plp = &dcl->productlist;
- pl = *plp;
- while (pl && strcmp(pl->product, product) < 0) {
- plp = &pl->next;
- pl = pl->next;
- }
- if (!pl || strcmp(pl->product, product)) {
- pl = calloc(sizeof(struct product), 1);
- pl->next = *plp;
- *plp = pl;
- pl->product = strdup(product);
- }
- /* one would assume that the vendor / product combinations are unique,
- * but that is not the case. At the time of this writing, there are two
- * flavors of the Oceanic OC1 - but looking at the code in libdivecomputer
- * they are handled exactly the same, so we ignore this issue for now
- *
- if (pl->descriptor && memcmp(pl->descriptor, descriptor, sizeof(struct mydescriptor)))
- printf("duplicate entry with different descriptor for %s - %s\n", vendor, product);
- else
- */
- pl->descriptor = descriptor;
-}
-
-#if USE_GTK_UI
-/* fill the vendors and create and fill the respective product stores; return the longest product name
- * and also the indices of the default vendor / product */
-static int fill_computer_list(GtkListStore *vendorstore, GtkListStore ***productstore, int *vendor_index, int *product_index)
-{
- int i, j, numvendor, width = 10;
- GtkTreeIter iter;
- dc_iterator_t *iterator = NULL;
- dc_descriptor_t *descriptor = NULL;
- struct mydescriptor *mydescriptor;
- struct vendor *dcl;
- struct product *pl;
- GtkListStore **pstores;
-
- dc_descriptor_iterator(&iterator);
- while (dc_iterator_next (iterator, &descriptor) == DC_STATUS_SUCCESS) {
- const char *vendor = dc_descriptor_get_vendor(descriptor);
- const char *product = dc_descriptor_get_product(descriptor);
- add_dc(vendor, product, descriptor);
- if (product && strlen(product) > width)
- width = strlen(product);
- }
- dc_iterator_free(iterator);
- /* and add the Uemis Zurich which we are handling internally
- THIS IS A HACK as we magically have a data structure here that
- happens to match a data structure that is internal to libdivecomputer;
- this WILL BREAK if libdivecomputer changes the dc_descriptor struct...
- eventually the UEMIS code needs to move into libdivecomputer, I guess */
- mydescriptor = malloc(sizeof(struct mydescriptor));
- mydescriptor->vendor = "Uemis";
- mydescriptor->product = "Zurich";
- mydescriptor->type = DC_FAMILY_NULL;
- mydescriptor->model = 0;
- add_dc("Uemis", "Zurich", (dc_descriptor_t *)mydescriptor);
- dcl = dc_list;
- numvendor = 0;
- while (dcl) {
- numvendor++;
- dcl = dcl->next;
- }
- /* we need an extra vendor for the empty one */
- numvendor += 1;
- dcl = dc_list;
- i = 0;
- *vendor_index = *product_index = -1;
- if (*productstore)
- free(*productstore);
- pstores = *productstore = malloc(numvendor * sizeof(GtkListStore *));
- while (dcl) {
- gtk_list_store_append(vendorstore, &iter);
- gtk_list_store_set(vendorstore, &iter,
- 0, dcl->vendor,
- -1);
- pl = dcl->productlist;
- pstores[i + 1] = gtk_list_store_new(1, G_TYPE_POINTER);
- j = 0;
- while (pl) {
- gtk_list_store_append(pstores[i + 1], &iter);
- gtk_list_store_set(pstores[i + 1], &iter,
- 0, pl->descriptor,
- -1);
- if (is_default_dive_computer(dcl->vendor, pl->product)) {
- *vendor_index = i;
- *product_index = j;
- }
- j++;
- pl = pl->next;
- }
- i++;
- dcl = dcl->next;
- }
- /* now add the empty product list in case no vendor is selected */
- pstores[0] = gtk_list_store_new(1, G_TYPE_POINTER);
-
- return width;
-}
-
-static GtkComboBox *dive_computer_selector(GtkWidget *vbox)
-{
- GtkWidget *hbox, *vendor_combo_box, *product_combo_box, *frame;
- GtkListStore *vendor_model;
- GtkCellRenderer *vendor_renderer, *product_renderer;
- int vendor_default_index, product_default_index, width;
-
- hbox = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
-
- vendor_model = gtk_list_store_new(1, G_TYPE_POINTER);
-
- width = fill_computer_list(vendor_model, &product_model, &vendor_default_index, &product_default_index);
-
- frame = gtk_frame_new(_("Dive computer vendor and product"));
- gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
-
- hbox = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(frame), hbox);
-
- vendor_combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(vendor_model));
- product_combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(product_model[vendor_default_index + 1]));
-
- g_signal_connect(G_OBJECT(vendor_combo_box), "changed", G_CALLBACK(dive_computer_vendor_changed), product_combo_box);
- gtk_box_pack_start(GTK_BOX(hbox), vendor_combo_box, FALSE, FALSE, 3);
- gtk_box_pack_start(GTK_BOX(hbox), product_combo_box, FALSE, FALSE, 3);
-
- vendor_renderer = gtk_cell_renderer_text_new();
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(vendor_combo_box), vendor_renderer, TRUE);
- gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(vendor_combo_box), vendor_renderer, render_dc_vendor, NULL, NULL);
-
- product_renderer = gtk_cell_renderer_text_new();
- gtk_cell_renderer_set_fixed_size(product_renderer, 10 * width, -1);
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(product_combo_box), product_renderer, TRUE);
- gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(product_combo_box), product_renderer, render_dc_product, NULL, NULL);
-
- gtk_combo_box_set_active(GTK_COMBO_BOX(vendor_combo_box), vendor_default_index);
- gtk_combo_box_set_active(GTK_COMBO_BOX(product_combo_box), product_default_index);
-
- return GTK_COMBO_BOX(product_combo_box);
-}
-
-static GtkComboBox *dc_device_selector(GtkWidget *vbox)
-{
- GtkWidget *hbox, *combo_box, *frame;
- GtkListStore *model;
- GtkCellRenderer *renderer;
- int default_index;
-
- hbox = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
-
- model = gtk_list_store_new(1, G_TYPE_STRING);
- default_index = subsurface_fill_device_list(model);
-
- frame = gtk_frame_new(_("Device or mount point"));
- gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
-
- combo_box = combo_box_with_model_and_entry(model);
- gtk_container_add(GTK_CONTAINER(frame), combo_box);
-
- renderer = gtk_cell_renderer_text_new();
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
-
- if (default_index != -1)
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), default_index);
- else
- if (default_dive_computer_device)
- set_active_text(GTK_COMBO_BOX(combo_box), default_dive_computer_device);
-
- return GTK_COMBO_BOX(combo_box);
-}
-
-/* this prevents clicking the [x] button, while the import thread is still running */
-static void download_dialog_delete(GtkWidget *w, gpointer data)
-{
- /* a no-op */
-}
-
-void download_dialog(GtkWidget *w, gpointer data)
-{
- int result;
- char *devname, *ns, *ne;
- GtkWidget *dialog, *button, *okbutton, *hbox, *vbox, *label, *info = NULL;
- GtkComboBox *computer, *device;
- GtkTreeIter iter;
- device_data_t devicedata = {
- .devname = NULL,
- };
-
- dialog = gtk_dialog_new_with_buttons(_("Download From Dive Computer"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL);
- g_signal_connect(dialog, "delete-event", G_CALLBACK(download_dialog_delete), NULL);
-
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- label = gtk_label_new(_(" Please select dive computer and device. "));
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 3);
- computer = dive_computer_selector(vbox);
- device = dc_device_selector(vbox);
- g_signal_connect(G_OBJECT(computer), "changed", G_CALLBACK(dive_computer_selector_changed), device);
-
- hbox = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 3);
- devicedata.progress.bar = gtk_progress_bar_new();
- gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress.bar);
-
- force_download = FALSE;
- button = gtk_check_button_new_with_label(_("Force download of all dives"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
- gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(force_toggle), NULL);
-
- prefer_downloaded = FALSE;
- button = gtk_check_button_new_with_label(_("Always prefer downloaded dive"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
- gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(prefer_dl_toggle), NULL);
-
- okbutton = gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
- if (!gtk_combo_box_get_active_iter(computer, &iter))
- gtk_widget_set_sensitive(okbutton, FALSE);
-
-repeat:
- gtk_widget_show_all(dialog);
- gtk_widget_set_sensitive(okbutton, TRUE);
- result = gtk_dialog_run(GTK_DIALOG(dialog));
- switch (result) {
- dc_descriptor_t *descriptor;
- GtkTreeModel *model;
-
- case GTK_RESPONSE_ACCEPT:
- /* once the accept event is triggered the dialog becomes non-modal.
- * lets re-set that */
- gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
- if (info)
- gtk_widget_destroy(info);
- const char *vendor, *product;
-
- if (!gtk_combo_box_get_active_iter(computer, &iter))
- break;
-
- gtk_widget_set_sensitive(okbutton, FALSE);
-
- model = gtk_combo_box_get_model(computer);
- gtk_tree_model_get(model, &iter,
- 0, &descriptor,
- -1);
-
- vendor = dc_descriptor_get_vendor(descriptor);
- product = dc_descriptor_get_product(descriptor);
-
- devicedata.descriptor = descriptor;
- devicedata.vendor = vendor;
- devicedata.product = product;
- set_default_dive_computer(vendor, product);
-
- /* get the device name from the combo box entry and set as default */
- devname = strdup(get_active_text(device));
- set_default_dive_computer_device(devname);
- /* clear leading and trailing white space from the device name and also
- * everything after (and including) the first '(' char. */
- ns = devname;
- while (*ns == ' ' || *ns == '\t')
- ns++;
- ne = ns;
- while (*ne && *ne != '(')
- ne++;
- *ne = '\0';
- if (ne > ns)
- while (*(--ne) == ' ' || *ne == '\t')
- *ne = '\0';
- devicedata.devname = ns;
- devicedata.dialog = GTK_DIALOG(dialog);
- devicedata.force_download = force_download;
- force_download = FALSE; /* when retrying we don't want to restart */
- info = import_dive_computer(&devicedata, GTK_DIALOG(dialog));
- free((void *)devname);
- if (info)
- goto repeat;
- report_dives(TRUE, prefer_downloaded);
- break;
- default:
- /* it's possible that some dives were downloaded */
- report_dives(TRUE, prefer_downloaded);
- break;
- }
- gtk_widget_destroy(dialog);
-}
-
-void update_progressbar(progressbar_t *progress, double value)
-{
- gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value);
-}
-
-void update_progressbar_text(progressbar_t *progress, const char *text)
-{
- gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), text);
-}
-#endif
diff --git a/equipment.c b/equipment.c
index 5485b2101..9d6ab40f9 100644
--- a/equipment.c
+++ b/equipment.c
@@ -13,453 +13,10 @@
#include <stdarg.h>
#include <time.h>
#include "gettext.h"
-#define QT_TR_NOOP(arg) arg
#include "dive.h"
#include "display.h"
-#if USE_GTK_UI
-#include "display-gtk.h"
-#endif
#include "divelist.h"
-#include "conversions.h"
-#if USE_GTK_UI
-#include "display-gtk.h"
-static GtkListStore *cylinder_model, *weightsystem_model;
-
-enum {
- CYL_DESC,
- CYL_SIZE,
- CYL_WORKP,
- CYL_STARTP,
- CYL_ENDP,
- CYL_O2,
- CYL_HE,
- CYL_COLUMNS
-};
-
-enum {
- WS_DESC,
- WS_WEIGHT,
- WS_COLUMNS
-};
-
-struct equipment_list {
- int max_index;
- GtkListStore *model;
- GtkTreeView *tree_view;
- GtkWidget *edit, *add, *del;
-};
-
-static struct equipment_list cylinder_list[2], weightsystem_list[2];
-
-struct dive edit_dive;
-
-struct cylinder_widget {
- int index, changed;
- const char *name;
- GtkWidget *hbox;
- GtkComboBox *description;
- GtkSpinButton *size, *pressure;
- GtkWidget *start, *end, *pressure_button;
- GtkWidget *o2, *he, *gasmix_button;
- int w_idx;
-};
-
-struct ws_widget {
- int index, changed;
- const char *name;
- GtkWidget *hbox;
- GtkComboBox *description;
- GtkSpinButton *weight;
- int w_idx;
-};
-#endif /* USE_GTK_UI */
-
-/* we want bar - so let's not use our unit functions */
-int convert_pressure(int mbar, double *p)
-{
- int decimals = 1;
- double pressure;
-
- if (prefs.units.pressure == PSI) {
- pressure = mbar_to_PSI(mbar);
- decimals = 0;
- } else {
- pressure = mbar / 1000.0;
- }
-
- *p = pressure;
- return decimals;
-}
-
-void convert_volume_pressure(int ml, int mbar, double *v, double *p)
-{
- double volume, pressure;
-
- volume = ml / 1000.0;
- if (mbar) {
- if (prefs.units.volume == CUFT) {
- volume = ml_to_cuft(ml);
- volume *= bar_to_atm(mbar / 1000.0);
- }
-
- if (prefs.units.pressure == PSI)
- pressure = mbar_to_PSI(mbar);
- else
- pressure = mbar / 1000.0;
- *p = pressure;
- } else {
- *p = 0;
- }
- *v = volume;
-}
-
-int convert_weight(int grams, double *m)
-{
- int decimals = 1; /* not sure - do people do less than whole lbs/kg ? */
- double weight;
-
- if (prefs.units.weight == LBS)
- weight = grams_to_lbs(grams);
- else
- weight = grams / 1000.0;
- *m = weight;
- return decimals;
-}
-
-#if USE_GTK_UI
-static void set_cylinder_description(struct cylinder_widget *cylinder, const char *desc)
-{
- set_active_text(cylinder->description, desc);
-}
-
-
-static void set_cylinder_type_spinbuttons(struct cylinder_widget *cylinder, int ml, int mbar)
-{
- double volume, pressure;
-
- convert_volume_pressure(ml, mbar, &volume, &pressure);
- gtk_spin_button_set_value(cylinder->size, volume);
- gtk_spin_button_set_value(cylinder->pressure, pressure);
-}
-
-static void set_cylinder_pressure_spinbuttons(struct cylinder_widget *cylinder, cylinder_t *cyl)
-{
- int set;
- unsigned int start, end;
- double pressure;
-
- start = cyl->start.mbar;
- end = cyl->end.mbar;
- set = start || end;
- if (!set) {
- start = cyl->sample_start.mbar;
- end = cyl->sample_end.mbar;
- }
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button), set);
- gtk_widget_set_sensitive(cylinder->start, set);
- gtk_widget_set_sensitive(cylinder->end, set);
-
- convert_pressure(start, &pressure);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->start), pressure);
- convert_pressure(end, &pressure);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->end), pressure);
-}
-
-static void set_weight_description(struct ws_widget *ws_widget, const char *desc)
-{
- set_active_text(ws_widget->description, desc);
-}
-
-static void set_weight_weight_spinbutton(struct ws_widget *ws_widget, int grams)
-{
- double weight;
-
- convert_weight(grams, &weight);
- gtk_spin_button_set_value(ws_widget->weight, weight);
-}
-
-/*
- * The gtk_tree_model_foreach() interface is bad. It could have
- * returned whether the callback ever returned true
- */
-static GtkTreeIter *found_match = NULL;
-static GtkTreeIter match_iter;
-
-static bool match_desc(GtkTreeModel *model, GtkTreePath *path,
- GtkTreeIter *iter, gpointer data)
-{
- int match;
- gchar *name;
- const char *desc = data;
-
- gtk_tree_model_get(model, iter, 0, &name, -1);
- match = !strcmp(desc, name);
- g_free(name);
- if (match) {
- match_iter = *iter;
- found_match = &match_iter;
- }
- return match;
-}
-
-static int get_active_item(GtkComboBox *combo_box, GtkTreeIter *iter, GtkListStore *model)
-{
- const char *desc;
-
- if (gtk_combo_box_get_active_iter(combo_box, iter))
- return TRUE;
-
- desc = get_active_text(combo_box);
-
- found_match = NULL;
- gtk_tree_model_foreach(GTK_TREE_MODEL(model), match_desc, (void *)desc);
-
- if (!found_match)
- return FALSE;
-
- *iter = *found_match;
- gtk_combo_box_set_active_iter(combo_box, iter);
- return TRUE;
-}
-
-static void cylinder_cb(GtkComboBox *combo_box, gpointer data)
-{
- GtkTreeIter iter;
- GtkTreeModel *model = gtk_combo_box_get_model(combo_box);
- int ml, mbar;
- struct cylinder_widget *cylinder = data;
- struct dive *dive;
- cylinder_t *cyl;
-
- if (cylinder->w_idx == W_IDX_PRIMARY)
- dive = current_dive;
- else
- dive = &edit_dive;
- cyl = dive->cylinder + cylinder->index;
-
- /* Did the user set it to some non-standard value? */
- if (!get_active_item(combo_box, &iter, cylinder_model)) {
- cylinder->changed = 1;
- return;
- }
-
- /*
- * We get "change" signal callbacks just because we set
- * the description by hand. Whatever. So ignore them if
- * they are no-ops.
- */
- if (!cylinder->changed && cyl->type.description) {
- int same;
- const char *desc = get_active_text(combo_box);
-
- same = !strcmp(desc, cyl->type.description);
- if (same)
- return;
- }
- cylinder->changed = 1;
-
- gtk_tree_model_get(model, &iter,
- CYL_SIZE, &ml,
- CYL_WORKP, &mbar,
- -1);
-
- set_cylinder_type_spinbuttons(cylinder, ml, mbar);
-}
-
-static void weight_cb(GtkComboBox *combo_box, gpointer data)
-{
- GtkTreeIter iter;
- GtkTreeModel *model = gtk_combo_box_get_model(combo_box);
- int weight;
- struct ws_widget *ws_widget = data;
- struct dive *dive;
- weightsystem_t *ws;
- if (ws_widget->w_idx == W_IDX_PRIMARY)
- dive = current_dive;
- else
- dive = &edit_dive;
- ws = dive->weightsystem + ws_widget->index;
-
- /* Did the user set it to some non-standard value? */
- if (!get_active_item(combo_box, &iter, weightsystem_model)) {
- ws_widget->changed = 1;
- return;
- }
-
- /*
- * We get "change" signal callbacks just because we set
- * the description by hand. Whatever. So ignore them if
- * they are no-ops.
- */
- if (!ws_widget->changed && ws->description) {
- int same;
- const char *desc = get_active_text(combo_box);
-
- same = !strcmp(desc, ws->description);
- if (same)
- return;
- }
- ws_widget->changed = 1;
-
- gtk_tree_model_get(model, &iter,
- WS_WEIGHT, &weight,
- -1);
-
- set_weight_weight_spinbutton(ws_widget, weight);
-}
-
-static GtkTreeIter *add_cylinder_type(const char *desc, int ml, int mbar, GtkTreeIter *iter)
-{
- GtkTreeModel *model;
-
- /* Don't even bother adding stuff without a size */
- if (!ml)
- return NULL;
-
- found_match = NULL;
- model = GTK_TREE_MODEL(cylinder_model);
- gtk_tree_model_foreach(model, match_desc, (void *)desc);
-
- if (!found_match) {
- GtkListStore *store = GTK_LIST_STORE(model);
-
- gtk_list_store_append(store, iter);
- gtk_list_store_set(store, iter,
- 0, desc,
- 1, ml,
- 2, mbar,
- -1);
- return iter;
- }
- return found_match;
-}
-
-static GtkTreeIter *add_weightsystem_type(const char *desc, int weight, GtkTreeIter *iter)
-{
- GtkTreeModel *model;
-
- found_match = NULL;
- model = GTK_TREE_MODEL(weightsystem_model);
- gtk_tree_model_foreach(model, match_desc, (void *)desc);
-
- if (found_match) {
- gtk_list_store_set(GTK_LIST_STORE(model), found_match,
- WS_WEIGHT, weight,
- -1);
- } else if (desc && desc[0]) {
- gtk_list_store_append(GTK_LIST_STORE(model), iter);
- gtk_list_store_set(GTK_LIST_STORE(model), iter,
- WS_DESC, desc,
- WS_WEIGHT, weight,
- -1);
- return iter;
- }
- return found_match;
-}
-
-/*
- * When adding a dive, we'll add all the pre-existing cylinder
- * information from that dive to our cylinder model.
- */
-void add_cylinder_description(cylinder_type_t *type)
-{
- GtkTreeIter iter;
- const char *desc;
- unsigned int size, workp;
-
- desc = type->description;
- if (!desc)
- return;
- size = type->size.mliter;
- workp = type->workingpressure.mbar;
- add_cylinder_type(desc, size, workp, &iter);
-}
-
-static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int ml, int mbar)
-{
- GtkTreeIter iter;
-
- cylinder->name = desc;
- add_cylinder_type(desc, ml, mbar, &iter);
-}
-
-void add_weightsystem_description(weightsystem_t *weightsystem)
-{
- GtkTreeIter iter;
- const char *desc;
- unsigned int weight;
-
- desc = weightsystem->description;
- if (!desc)
- return;
- weight = weightsystem->weight.grams;
- add_weightsystem_type(desc, weight, &iter);
-}
-
-static void add_weightsystem(struct ws_widget *ws_widget, const char *desc, int weight)
-{
- GtkTreeIter iter;
-
- ws_widget->name = desc;
- add_weightsystem_type(desc, weight, &iter);
-}
-
-static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
-{
- const char *desc;
- int ml, mbar;
- int gasmix;
- double o2, he;
-
- /* Don't show uninitialized cylinder widgets */
- if (!cylinder->description)
- return;
-
- desc = cyl->type.description;
- if (!desc)
- desc = "";
- ml = cyl->type.size.mliter;
- mbar = cyl->type.workingpressure.mbar;
- add_cylinder(cylinder, desc, ml, mbar);
-
- set_cylinder_description(cylinder, desc);
- set_cylinder_type_spinbuttons(cylinder,
- cyl->type.size.mliter, cyl->type.workingpressure.mbar);
- set_cylinder_pressure_spinbuttons(cylinder, cyl);
-
- gasmix = cyl->gasmix.o2.permille || cyl->gasmix.he.permille;
- gtk_widget_set_sensitive(cylinder->o2, gasmix);
- gtk_widget_set_sensitive(cylinder->he, gasmix);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button), gasmix);
-
- o2 = cyl->gasmix.o2.permille / 10.0;
- he = cyl->gasmix.he.permille / 10.0;
- if (!o2)
- o2 = O2_IN_AIR / 10.0;
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->he), he);
-}
-
-static void show_weightsystem(weightsystem_t *ws, struct ws_widget *weightsystem_widget)
-{
- const char *desc;
- int grams;
-
- /* Don't show uninitialized widgets */
- if (!weightsystem_widget->description)
- return;
-
- desc = ws->description;
- if (!desc)
- desc = "";
- grams = ws->weight.grams;
- add_weightsystem(weightsystem_widget, desc, grams);
-
- set_weight_description(weightsystem_widget, desc);
- set_weight_weight_spinbutton(weightsystem_widget, ws->weight.grams);
-}
-#else
/* placeholders for a few functions that we need to redesign for the Qt UI */
void add_cylinder_description(cylinder_type_t *type)
{
@@ -490,8 +47,6 @@ void add_weightsystem_description(weightsystem_t *weightsystem)
}
}
-#endif /* USE_GTK_UI */
-
bool cylinder_nodata(cylinder_t *cyl)
{
return !cyl->type.size.mliter &&
@@ -555,277 +110,6 @@ bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2)
return TRUE;
}
-#if USE_GTK_UI
-static void set_one_cylinder(void *_data, GtkListStore *model, GtkTreeIter *iter)
-{
- cylinder_t *cyl = _data;
- unsigned int start, end;
-
- start = cyl->start.mbar ? : cyl->sample_start.mbar;
- end = cyl->end.mbar ? : cyl->sample_end.mbar;
- gtk_list_store_set(model, iter,
- CYL_DESC, cyl->type.description ? : "",
- CYL_SIZE, cyl->type.size.mliter,
- CYL_WORKP, cyl->type.workingpressure.mbar,
- CYL_STARTP, start,
- CYL_ENDP, end,
- CYL_O2, cyl->gasmix.o2.permille,
- CYL_HE, cyl->gasmix.he.permille,
- -1);
-}
-
-static void set_one_weightsystem(void *_data, GtkListStore *model, GtkTreeIter *iter)
-{
- weightsystem_t *ws = _data;
-
- gtk_list_store_set(model, iter,
- WS_DESC, ws->description ? : _("unspecified"),
- WS_WEIGHT, ws->weight.grams,
- -1);
-}
-
-static void *cyl_ptr(struct dive *dive, int idx)
-{
- if (idx < 0 || idx >= MAX_CYLINDERS)
- return NULL;
- return &dive->cylinder[idx];
-}
-
-static void *ws_ptr(struct dive *dive, int idx)
-{
- if (idx < 0 || idx >= MAX_WEIGHTSYSTEMS)
- return NULL;
- return &dive->weightsystem[idx];
-}
-
-static void show_equipment(struct dive *dive, int max,
- struct equipment_list *equipment_list,
- void*(*ptr_function)(struct dive*, int),
- bool(*none_function)(void *),
- void(*set_one_function)(void*, GtkListStore*, GtkTreeIter *))
-{
- int i, used;
- void *data;
- GtkTreeIter iter;
- GtkListStore *model = equipment_list->model;
-
- if (! model)
- return;
- if (! dive) {
- gtk_widget_set_sensitive(equipment_list->edit, 0);
- gtk_widget_set_sensitive(equipment_list->del, 0);
- gtk_widget_set_sensitive(equipment_list->add, 0);
- clear_equipment_widgets();
- return;
- }
- gtk_list_store_clear(model);
- used = max;
- do {
- data = ptr_function(dive, used-1);
- if (!none_function(data))
- break;
- } while (--used);
-
- equipment_list->max_index = used;
-
- gtk_widget_set_sensitive(equipment_list->edit, 0);
- gtk_widget_set_sensitive(equipment_list->del, 0);
- gtk_widget_set_sensitive(equipment_list->add, used < max);
-
- for (i = 0; i < used; i++) {
- data = ptr_function(dive, i);
- gtk_list_store_append(model, &iter);
- set_one_function(data, model, &iter);
- }
-}
-
-void show_dive_equipment(struct dive *dive, int w_idx)
-{
- show_equipment(dive, MAX_CYLINDERS, &cylinder_list[w_idx],
- &cyl_ptr, &cylinder_none, &set_one_cylinder);
- show_equipment(dive, MAX_WEIGHTSYSTEMS, &weightsystem_list[w_idx],
- &ws_ptr, &weightsystem_none, &set_one_weightsystem);
-}
-
-int select_cylinder(struct dive *dive, int when)
-{
- GtkWidget *dialog, *vbox, *label;
- GtkWidget *buttons[MAX_CYLINDERS] = { NULL, };
- GSList *group = NULL;
- int i, success, nr, selected = -1;
- char buffer[256];
-
- nr = MAX_CYLINDERS - 1;
- while (nr >= 0 && cylinder_nodata(cyl_ptr(dive, nr)))
- nr--;
-
- if (nr == -1) {
- dialog = gtk_dialog_new_with_buttons(_("Cannot add gas change"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- NULL);
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- label = gtk_label_new(_("No cylinders listed for this dive."));
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- gtk_widget_show_all(dialog);
- success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
- goto bail;
- }
- snprintf(buffer, sizeof(buffer), _("Add gaschange event at %d:%02u"), FRACTION(when, 60));
- dialog = gtk_dialog_new_with_buttons(buffer,
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
- NULL);
-
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- label = gtk_label_new(_("Available gases"));
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- for (i = 0; i <= nr; i++) {
- char gas_buf[80];
- cylinder_t *cyl = cyl_ptr(dive, i);
- get_gas_string(cyl->gasmix.o2.permille, cyl->gasmix.he.permille, gas_buf, sizeof(gas_buf));
- snprintf(buffer, sizeof(buffer), "%s: %s",
- dive->cylinder[i].type.description ?: _("unknown"), gas_buf);
- buttons[i] = gtk_radio_button_new_with_label(group, buffer);
- group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(buttons[i]));
- gtk_box_pack_start(GTK_BOX(vbox), buttons[i], FALSE, FALSE, 0);
- }
- gtk_widget_show_all(dialog);
- success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
- if (success) {
- for (i = 0; i <= nr; i++)
- if (buttons[i] && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(buttons[i])))
- selected = i;
- }
- for (i = 0; i <= nr; i++)
- if (buttons[i])
- gtk_widget_destroy(buttons[i]);
-bail:
- gtk_widget_destroy(dialog);
-
- return selected;
-
-}
-
-static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name, double min, double max, double incr)
-{
- GtkWidget *frame, *hbox, *button;
-
- frame = gtk_frame_new(name);
- gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, FALSE, 0);
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_container_add(GTK_CONTAINER(frame), hbox);
-
- button = gtk_spin_button_new_with_range(min, max, incr);
- gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
-
- gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
-
- return button;
-}
-
-static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl, const char *desc,
- double volume, double pressure, double start, double end, int o2, int he)
-{
- int mbar, ml;
-
- if (prefs.units.pressure == PSI) {
- pressure = psi_to_bar(pressure);
- start = psi_to_bar(start);
- end = psi_to_bar(end);
- }
-
- mbar = pressure * 1000 + 0.5;
- if (mbar && prefs.units.volume == CUFT) {
- volume = cuft_to_l(volume);
- volume /= bar_to_atm(pressure);
- }
-
- ml = volume * 1000 + 0.5;
-
- /* Ignore obviously crazy He values */
- if (o2 + he > 1000)
- he = 0;
-
- /* We have a rule that normal air is all zeroes */
- if (!he && o2 > 208 && o2 < 211)
- o2 = 0;
-
- cyl->type.description = desc;
- cyl->type.size.mliter = ml;
- cyl->type.workingpressure.mbar = mbar;
- cyl->start.mbar = start * 1000 + 0.5;
- cyl->end.mbar = end * 1000 + 0.5;
- cyl->gasmix.o2.permille = o2;
- cyl->gasmix.he.permille = he;
-
- /*
- * Also, insert it into the model if it doesn't already exist
- */
- // WARNING: GTK-Specific Code.
- add_cylinder(cylinder, desc, ml, mbar);
-}
-
-static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cylinder)
-{
- const gchar *desc;
- GtkComboBox *box;
- double volume, pressure, start, end;
- int o2, he;
-
- /* Ignore uninitialized cylinder widgets */
- box = cylinder->description;
- if (!box)
- return;
-
- desc = strdup(get_active_text(box));
- volume = gtk_spin_button_get_value(cylinder->size);
- pressure = gtk_spin_button_get_value(cylinder->pressure);
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button))) {
- start = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->start));
- end = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->end));
- } else {
- start = end = 0;
- }
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button))) {
- o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->o2))*10 + 0.5;
- he = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->he))*10 + 0.5;
- } else {
- o2 = 0;
- he = 0;
- }
- fill_cylinder_info(cylinder, cyl, desc, volume, pressure, start, end, o2, he);
-}
-
-static void record_weightsystem_changes(weightsystem_t *ws, struct ws_widget *weightsystem_widget)
-{
- const gchar *desc;
- GtkComboBox *box;
- int grams;
- double value;
- GtkTreeIter iter;
-
- /* Ignore uninitialized cylinder widgets */
- box = weightsystem_widget->description;
- if (!box)
- return;
-
- desc = strdup(get_active_text(box));
- value = gtk_spin_button_get_value(weightsystem_widget->weight);
-
- if (prefs.units.weight == LBS)
- grams = lbs_to_grams(value);
- else
- grams = value * 1000;
- ws->weight.grams = grams;
- ws->description = desc;
- add_weightsystem_type(desc, grams, &iter);
-}
-#endif /* USE_GTK_UI */
/*
* We hardcode the most common standard cylinders,
* we should pick up any other names from the dive
@@ -877,53 +161,6 @@ struct tank_info_t tank_info[100] = {
{ NULL, }
};
-#if USE_GTK_UI
-static void fill_tank_list(GtkListStore *store)
-{
- GtkTreeIter iter;
- struct tank_info *info = tank_info;
-
- for (info = tank_info ; info->name; info++) {
- int ml = info->ml;
- int cuft = info->cuft;
- int psi = info->psi;
- int mbar;
- double bar = info->bar;
-
- if (psi && bar)
- goto bad_tank_info;
- if (ml && cuft)
- goto bad_tank_info;
- if (cuft && !psi)
- goto bad_tank_info;
-
- /* Is it in cuft and psi? */
- if (psi)
- bar = psi_to_bar(psi);
-
- if (cuft) {
- double airvolume = cuft_to_l(cuft) * 1000.0;
- double atm = bar_to_atm(bar);
-
- ml = airvolume / atm + 0.5;
- }
-
- mbar = bar * 1000 + 0.5;
-
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- 0, info->name,
- 1, ml,
- 2, mbar,
- -1);
- continue;
-
-bad_tank_info:
- fprintf(stderr, "Bad tank info for '%s'\n", info->name);
- }
-}
-#endif /* USE_GTK_UI */
-
/*
* We hardcode the most common weight system types
* This is a bit odd as the weight system types don't usually encode weight
@@ -936,351 +173,6 @@ struct ws_info_t ws_info[100] = {
{ QT_TR_NOOP("clip-on"), 0 },
};
-#if USE_GTK_UI
-static void fill_ws_list(GtkListStore *store)
-{
- GtkTreeIter iter;
- struct ws_info_t *info = ws_info;
-
- while (info->name) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- 0, _(info->name),
- 1, info->grams,
- -1);
- info++;
- }
-}
-
-static void gasmix_cb(GtkToggleButton *button, gpointer data)
-{
- struct cylinder_widget *cylinder = data;
- int state;
-
- state = gtk_toggle_button_get_active(button);
- gtk_widget_set_sensitive(cylinder->o2, state);
- gtk_widget_set_sensitive(cylinder->he, state);
-}
-
-static void pressure_cb(GtkToggleButton *button, gpointer data)
-{
- struct cylinder_widget *cylinder = data;
- int state;
-
- state = gtk_toggle_button_get_active(button);
- gtk_widget_set_sensitive(cylinder->start, state);
- gtk_widget_set_sensitive(cylinder->end, state);
-}
-
-static void cylinder_activate_cb(GtkComboBox *combo_box, gpointer data)
-{
- struct cylinder_widget *cylinder = data;
- cylinder_cb(cylinder->description, data);
-}
-
-/* Return a frame containing a hbox inside a hbox */
-static GtkWidget *frame_box(const char *title, GtkWidget *vbox)
-{
- GtkWidget *hbox, *frame;
-
- hbox = gtk_hbox_new(FALSE, 10);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 0);
-
- frame = gtk_frame_new(title);
- gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 0);
-
- hbox = gtk_hbox_new(FALSE, 10);
- gtk_container_add(GTK_CONTAINER(frame), hbox);
-
- return hbox;
-}
-
-static GtkWidget *labeled_spinbutton(GtkWidget *box, const char *name, double min, double max, double incr)
-{
- GtkWidget *hbox, *label, *button;
-
- hbox = gtk_hbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, FALSE, 0);
-
- label = gtk_label_new(name);
- gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0);
-
- button = gtk_spin_button_new_with_range(min, max, incr);
- gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
-
- gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
-
- return button;
-}
-
-static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, GtkListStore *model)
-{
- GtkWidget *frame, *hbox;
- GtkWidget *widget;
-
- /*
- * Cylinder type: description, size and
- * working pressure
- */
- frame = gtk_frame_new(_("Cylinder"));
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_container_add(GTK_CONTAINER(frame), hbox);
-
- widget = combo_box_with_model_and_entry(model);
- gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
-
- cylinder->description = GTK_COMBO_BOX(widget);
- g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder);
-
- g_signal_connect(get_entry(GTK_COMBO_BOX(widget)), "activate", G_CALLBACK(cylinder_activate_cb), cylinder);
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
-
- widget = create_spinbutton(hbox, _("Size"), 0, 300, 0.1);
- cylinder->size = GTK_SPIN_BUTTON(widget);
-
- widget = create_spinbutton(hbox, _("Pressure"), 0, 5000, 1);
- cylinder->pressure = GTK_SPIN_BUTTON(widget);
-
- /*
- * Cylinder start/end pressures
- */
- hbox = frame_box(_("Pressure"), vbox);
-
- widget = labeled_spinbutton(hbox, _("Start"), 0, 5000, 1);
- cylinder->start = widget;
-
- widget = labeled_spinbutton(hbox, _("End"), 0, 5000, 1);
- cylinder->end = widget;
-
- cylinder->pressure_button = gtk_check_button_new();
- gtk_box_pack_start(GTK_BOX(hbox), cylinder->pressure_button, FALSE, FALSE, 3);
- g_signal_connect(cylinder->pressure_button, "toggled", G_CALLBACK(pressure_cb), cylinder);
-
- /*
- * Cylinder gas mix: Air, Nitrox or Trimix
- */
- hbox = frame_box(_("Gasmix"), vbox);
-
- widget = labeled_spinbutton(hbox, "O"UTF8_SUBSCRIPT_2 "%", 1, 100, 0.1);
- cylinder->o2 = widget;
- widget = labeled_spinbutton(hbox, "He%", 0, 100, 0.1);
- cylinder->he = widget;
- cylinder->gasmix_button = gtk_check_button_new();
- gtk_box_pack_start(GTK_BOX(hbox), cylinder->gasmix_button, FALSE, FALSE, 3);
- g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(gasmix_cb), cylinder);
-}
-
-static void weight_activate_cb(GtkComboBox *combo_box, gpointer data)
-{
- struct ws_widget *ws_widget = data;
- weight_cb(ws_widget->description, data);
-}
-
-static void ws_widget(GtkWidget *vbox, struct ws_widget *ws_widget, GtkListStore *model)
-{
- GtkWidget *frame, *hbox;
- GtkWidget *widget;
- GtkEntry *entry;
-
- /*
- * weight_system: description and weight
- */
- frame = gtk_frame_new(_("Weight"));
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_container_add(GTK_CONTAINER(frame), hbox);
-
- widget = combo_box_with_model_and_entry(model);
- gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
-
- ws_widget->description = GTK_COMBO_BOX(widget);
- g_signal_connect(widget, "changed", G_CALLBACK(weight_cb), ws_widget);
-
- entry = get_entry(GTK_COMBO_BOX(widget));
- g_signal_connect(entry, "activate", G_CALLBACK(weight_activate_cb), ws_widget);
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
-
- if (prefs.units.weight == KG)
- widget = create_spinbutton(hbox, _("kg"), 0, 50, 0.5);
- else
- widget = create_spinbutton(hbox, _("lbs"), 0, 110, 1);
- ws_widget->weight = GTK_SPIN_BUTTON(widget);
-}
-
-static int edit_cylinder_dialog(GtkWidget *w, int index, cylinder_t *cyl, int w_idx)
-{
- int success;
- GtkWidget *dialog, *vbox, *parent;
- struct cylinder_widget cylinder;
- struct dive *dive;
-
- cylinder.index = index;
- cylinder.w_idx = w_idx;
- cylinder.changed = 0;
-
- if (w_idx == W_IDX_PRIMARY)
- dive = current_dive;
- else
- dive = &edit_dive;
- if (!dive)
- return 0;
- *cyl = dive->cylinder[index];
-
- dialog = gtk_dialog_new_with_buttons(_("Cylinder"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
- NULL);
-
- parent = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG);
- if (parent) {
- gtk_widget_set_sensitive(parent, FALSE);
- gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
- }
-
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- cylinder_widget(vbox, &cylinder, cylinder_model);
-
- show_cylinder(cyl, &cylinder);
-
- gtk_widget_show_all(dialog);
- success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
- if (success) {
- record_cylinder_changes(cyl, &cylinder);
- dive->cylinder[index] = *cyl;
- if (w_idx == W_IDX_PRIMARY) {
- mark_divelist_changed(TRUE);
- update_cylinder_related_info(dive);
- flush_divelist(dive);
- }
- }
-
- gtk_widget_destroy(dialog);
- if (parent)
- gtk_widget_set_sensitive(parent, TRUE);
- return success;
-}
-
-static int edit_weightsystem_dialog(GtkWidget *w, int index, weightsystem_t *ws, int w_idx)
-{
- int success;
- GtkWidget *dialog, *vbox, *parent;
- struct ws_widget weightsystem_widget;
- struct dive *dive;
-
- weightsystem_widget.index = index;
- weightsystem_widget.w_idx = w_idx;
- weightsystem_widget.changed = 0;
-
- if (w_idx == W_IDX_PRIMARY)
- dive = current_dive;
- else
- dive = &edit_dive;
- if (!dive)
- return 0;
- *ws = dive->weightsystem[index];
-
- dialog = gtk_dialog_new_with_buttons(_("Weight System"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
- NULL);
-
- parent = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG);
- if (parent) {
- gtk_widget_set_sensitive(parent, FALSE);
- gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
- }
-
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- ws_widget(vbox, &weightsystem_widget, weightsystem_model);
-
- show_weightsystem(ws, &weightsystem_widget);
-
- gtk_widget_show_all(dialog);
- success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
- if (success) {
- record_weightsystem_changes(ws, &weightsystem_widget);
- dive->weightsystem[index] = *ws;
- if (w_idx == W_IDX_PRIMARY) {
- mark_divelist_changed(TRUE);
- flush_divelist(dive);
- }
- }
-
- gtk_widget_destroy(dialog);
- if (parent)
- gtk_widget_set_sensitive(parent, TRUE);
- return success;
-}
-
-static int get_model_index(GtkListStore *model, GtkTreeIter *iter)
-{
- int *p, index;
- GtkTreePath *path;
-
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(model), iter);
- p = gtk_tree_path_get_indices(path);
- index = p ? *p : 0;
- gtk_tree_path_free(path);
- return index;
-}
-
-static void edit_cb(GtkWidget *w, int w_idx)
-{
- int index;
- GtkTreeIter iter;
- GtkListStore *model = cylinder_list[w_idx].model;
- GtkTreeView *tree_view = cylinder_list[w_idx].tree_view;
- GtkTreeSelection *selection;
- cylinder_t cyl;
-
- selection = gtk_tree_view_get_selection(tree_view);
-
- /* Nothing selected? This shouldn't happen, since the button should be inactive */
- if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
- return;
-
- index = get_model_index(model, &iter);
- if (!edit_cylinder_dialog(w, index, &cyl, w_idx))
- return;
-
- set_one_cylinder(&cyl, model, &iter);
- repaint_dive();
-}
-
-static void add_cb(GtkWidget *w, int w_idx)
-{
- int index = cylinder_list[w_idx].max_index;
- GtkTreeIter iter;
- GtkListStore *model = cylinder_list[w_idx].model;
- GtkTreeView *tree_view = cylinder_list[w_idx].tree_view;
- GtkTreeSelection *selection;
- cylinder_t cyl;
-
- if (!edit_cylinder_dialog(w, index, &cyl, w_idx))
- return;
-
- gtk_list_store_append(model, &iter);
- set_one_cylinder(&cyl, model, &iter);
-
- selection = gtk_tree_view_get_selection(tree_view);
- gtk_tree_selection_select_iter(selection, &iter);
-
- cylinder_list[w_idx].max_index++;
- gtk_widget_set_sensitive(cylinder_list[w_idx].add, cylinder_list[w_idx].max_index < MAX_CYLINDERS);
-}
-#endif /* USE_GTK_UI */
-
void remove_cylinder(struct dive *dive, int idx)
{
cylinder_t *cyl = dive->cylinder + idx;
@@ -1296,450 +188,3 @@ void remove_weightsystem(struct dive *dive, int idx)
memmove(ws, ws + 1, nr * sizeof(*ws));
memset(ws + nr, 0, sizeof(*ws));
}
-
-
-#if USE_GTK_UI
-static void del_cb(GtkButton *button, int w_idx)
-{
- int index, nr;
- GtkTreeIter iter;
- GtkListStore *model = cylinder_list[w_idx].model;
- GtkTreeView *tree_view = cylinder_list[w_idx].tree_view;
- GtkTreeSelection *selection;
- struct dive *dive;
- cylinder_t *cyl;
-
- selection = gtk_tree_view_get_selection(tree_view);
-
- /* Nothing selected? This shouldn't happen, since the button should be inactive */
- if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
- return;
-
- index = get_model_index(model, &iter);
-
- if (w_idx == W_IDX_PRIMARY)
- dive = current_dive;
- else
- dive = &edit_dive;
- if (!dive)
- return;
- cyl = dive->cylinder + index;
- nr = cylinder_list[w_idx].max_index - index - 1;
-
- gtk_list_store_remove(model, &iter);
-
- cylinder_list[w_idx].max_index--;
- memmove(cyl, cyl+1, nr*sizeof(*cyl));
- memset(cyl+nr, 0, sizeof(*cyl));
-
- mark_divelist_changed(TRUE);
- flush_divelist(dive);
-
- gtk_widget_set_sensitive(cylinder_list[w_idx].edit, 0);
- gtk_widget_set_sensitive(cylinder_list[w_idx].del, 0);
- gtk_widget_set_sensitive(cylinder_list[w_idx].add, 1);
-}
-
-static void ws_edit_cb(GtkWidget *w, int w_idx)
-{
- int index;
- GtkTreeIter iter;
- GtkListStore *model = weightsystem_list[w_idx].model;
- GtkTreeView *tree_view = weightsystem_list[w_idx].tree_view;
- GtkTreeSelection *selection;
- weightsystem_t ws;
-
- selection = gtk_tree_view_get_selection(tree_view);
-
- /* Nothing selected? This shouldn't happen, since the button should be inactive */
- if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
- return;
-
- index = get_model_index(model, &iter);
- if (!edit_weightsystem_dialog(w, index, &ws, w_idx))
- return;
-
- set_one_weightsystem(&ws, model, &iter);
- repaint_dive();
-}
-
-static void ws_add_cb(GtkWidget *w, int w_idx)
-{
- int index = weightsystem_list[w_idx].max_index;
- GtkTreeIter iter;
- GtkListStore *model = weightsystem_list[w_idx].model;
- GtkTreeView *tree_view = weightsystem_list[w_idx].tree_view;
- GtkTreeSelection *selection;
- weightsystem_t ws;
-
- if (!edit_weightsystem_dialog(w, index, &ws, w_idx))
- return;
-
- gtk_list_store_append(model, &iter);
- set_one_weightsystem(&ws, model, &iter);
-
- selection = gtk_tree_view_get_selection(tree_view);
- gtk_tree_selection_select_iter(selection, &iter);
-
- weightsystem_list[w_idx].max_index++;
- gtk_widget_set_sensitive(weightsystem_list[w_idx].add, weightsystem_list[w_idx].max_index < MAX_WEIGHTSYSTEMS);
-}
-
-static void ws_del_cb(GtkButton *button, int w_idx)
-{
- int index, nr;
- GtkTreeIter iter;
- GtkListStore *model = weightsystem_list[w_idx].model;
- GtkTreeView *tree_view = weightsystem_list[w_idx].tree_view;
- GtkTreeSelection *selection;
- struct dive *dive;
- weightsystem_t *ws;
-
- selection = gtk_tree_view_get_selection(tree_view);
-
- /* Nothing selected? This shouldn't happen, since the button should be inactive */
- if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
- return;
-
- index = get_model_index(model, &iter);
-
- if (w_idx == W_IDX_PRIMARY)
- dive = current_dive;
- else
- dive = &edit_dive;
- if (!dive)
- return;
- ws = dive->weightsystem + index;
- nr = weightsystem_list[w_idx].max_index - index - 1;
-
- gtk_list_store_remove(model, &iter);
-
- weightsystem_list[w_idx].max_index--;
- memmove(ws, ws+1, nr*sizeof(*ws));
- memset(ws+nr, 0, sizeof(*ws));
-
- mark_divelist_changed(TRUE);
- flush_divelist(dive);
-
- gtk_widget_set_sensitive(weightsystem_list[w_idx].edit, 0);
- gtk_widget_set_sensitive(weightsystem_list[w_idx].del, 0);
- gtk_widget_set_sensitive(weightsystem_list[w_idx].add, 1);
-}
-
-static GtkListStore *create_tank_size_model(void)
-{
- GtkListStore *model;
-
- model = gtk_list_store_new(3,
- G_TYPE_STRING, /* Tank name */
- G_TYPE_INT, /* Tank size in mliter */
- G_TYPE_INT, /* Tank working pressure in mbar */
- -1);
-
- fill_tank_list(model);
- return model;
-}
-
-static GtkListStore *create_weightsystem_model(void)
-{
- GtkListStore *model;
-
- model = gtk_list_store_new(2,
- G_TYPE_STRING, /* Weightsystem description */
- G_TYPE_INT, /* Weight in grams */
- -1);
-
- fill_ws_list(model);
- return model;
-}
-
-static void size_data_func(GtkTreeViewColumn *col,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- int ml, mbar;
- double size, pressure;
- char buffer[64];
-
- gtk_tree_model_get(model, iter, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
- convert_volume_pressure(ml, mbar, &size, &pressure);
- if (size)
- snprintf(buffer, sizeof(buffer), "%.1f", size);
- else
- strcpy(buffer, _("unkn"));
- g_object_set(renderer, "text", buffer, NULL);
-}
-
-static void weight_data_func(GtkTreeViewColumn *col,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- int idx = (long)data;
- int grams, decimals;
- double value;
- char buffer[64];
-
- gtk_tree_model_get(model, iter, idx, &grams, -1);
- decimals = convert_weight(grams, &value);
- if (grams)
- snprintf(buffer, sizeof(buffer), "%.*f", decimals, value);
- else
- strcpy(buffer, _("unkn"));
- g_object_set(renderer, "text", buffer, NULL);
-}
-
-static void pressure_data_func(GtkTreeViewColumn *col,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- int index = (long)data;
- int mbar, decimals;
- double pressure;
- char buffer[10];
-
- gtk_tree_model_get(model, iter, index, &mbar, -1);
- decimals = convert_pressure(mbar, &pressure);
- if (mbar)
- snprintf(buffer, sizeof(buffer), "%.*f", decimals, pressure);
- else
- *buffer = 0;
- g_object_set(renderer, "text", buffer, NULL);
-}
-
-static void percentage_data_func(GtkTreeViewColumn *col,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- int index = (long)data;
- int permille;
- char buffer[10];
-
- gtk_tree_model_get(model, iter, index, &permille, -1);
- if (permille)
- snprintf(buffer, sizeof(buffer), "%.1f%%", permille / 10.0);
- else
- *buffer = 0;
- g_object_set(renderer, "text", buffer, NULL);
-}
-
-static void selection_cb(GtkTreeSelection *selection, struct equipment_list *list)
-{
- GtkTreeIter iter;
- int selected;
-
- selected = gtk_tree_selection_get_selected(selection, NULL, &iter);
- gtk_widget_set_sensitive(list->edit, selected);
- gtk_widget_set_sensitive(list->del, selected);
-}
-
-static void row_activated_cb(GtkTreeView *tree_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- int w_idx)
-{
- edit_cb(GTK_WIDGET(tree_view), w_idx);
-}
-
-static void ws_row_activated_cb(GtkTreeView *tree_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- int w_idx)
-{
- ws_edit_cb(GTK_WIDGET(tree_view), w_idx);
-}
-
-static GtkWidget *cylinder_list_widget(int w_idx)
-{
- GtkListStore *model = cylinder_list[w_idx].model;
- GtkWidget *tree_view;
- GtkTreeSelection *selection;
-
- tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
- gtk_widget_set_can_focus(tree_view, FALSE);
-
- g_signal_connect(tree_view, "row-activated", G_CALLBACK(row_activated_cb), GINT_TO_POINTER(w_idx));
-
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
- gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
- g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), &cylinder_list[w_idx]);
-
- g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
- "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH,
- NULL);
-
- tree_view_column(tree_view, CYL_DESC, _("Type"), NULL, ALIGN_LEFT | UNSORTABLE);
- tree_view_column(tree_view, CYL_SIZE, _("Size"), size_data_func, ALIGN_RIGHT | UNSORTABLE);
- tree_view_column(tree_view, CYL_WORKP, _("MaxPress"), pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
- tree_view_column(tree_view, CYL_STARTP, _("Start"), pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
- tree_view_column(tree_view, CYL_ENDP, _("End"), pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
- tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
- tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
- return tree_view;
-}
-
-static GtkWidget *weightsystem_list_widget(int w_idx)
-{
- GtkListStore *model = weightsystem_list[w_idx].model;
- GtkWidget *tree_view;
- GtkTreeSelection *selection;
-
- tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
- gtk_widget_set_can_focus(tree_view, FALSE);
- g_signal_connect(tree_view, "row-activated", G_CALLBACK(ws_row_activated_cb), GINT_TO_POINTER(w_idx));
-
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
- gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
- g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), &weightsystem_list[w_idx]);
-
- g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
- "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH,
- NULL);
-
- tree_view_column(tree_view, WS_DESC, _("Type"), NULL, ALIGN_LEFT | UNSORTABLE);
- tree_view_column(tree_view, WS_WEIGHT, _("weight"),
- weight_data_func, ALIGN_RIGHT | UNSORTABLE);
-
- return tree_view;
-}
-
-static GtkWidget *cylinder_list_create(int w_idx)
-{
- GtkListStore *model;
-
- model = gtk_list_store_new(CYL_COLUMNS,
- G_TYPE_STRING, /* CYL_DESC: utf8 */
- G_TYPE_INT, /* CYL_SIZE: mliter */
- G_TYPE_INT, /* CYL_WORKP: mbar */
- G_TYPE_INT, /* CYL_STARTP: mbar */
- G_TYPE_INT, /* CYL_ENDP: mbar */
- G_TYPE_INT, /* CYL_O2: permille */
- G_TYPE_INT /* CYL_HE: permille */
- );
- cylinder_list[w_idx].model = model;
- return cylinder_list_widget(w_idx);
-}
-
-static GtkWidget *weightsystem_list_create(int w_idx)
-{
- GtkListStore *model;
-
- model = gtk_list_store_new(WS_COLUMNS,
- G_TYPE_STRING, /* WS_DESC: utf8 */
- G_TYPE_INT /* WS_WEIGHT: grams */
- );
- weightsystem_list[w_idx].model = model;
- return weightsystem_list_widget(w_idx);
-}
-
-GtkWidget *equipment_widget(int w_idx)
-{
- GtkWidget *vbox, *hbox, *frame, *framebox, *tree_view;
- GtkWidget *add, *del, *edit;
-
- vbox = gtk_vbox_new(FALSE, 3);
-
- /*
- * We create the cylinder size (and weightsystem) models
- * at startup for the primary cylinder / weightsystem widget,
- * since we're going to share it across all cylinders and all
- * dives. So if you add a new cylinder type or weightsystem in
- * one dive, it will show up when you edit the cylinder types
- * or weightsystems for another dive.
- */
- if (w_idx == W_IDX_PRIMARY)
- cylinder_model = create_tank_size_model();
- tree_view = cylinder_list_create(w_idx);
- cylinder_list[w_idx].tree_view = GTK_TREE_VIEW(tree_view);
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
-
- frame = gtk_frame_new(_("Cylinders"));
- gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 3);
-
- framebox = gtk_vbox_new(FALSE, 3);
- gtk_container_add(GTK_CONTAINER(frame), framebox);
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
-
- gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3);
-
- hbox = gtk_hbox_new(TRUE, 3);
- gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
-
- edit = gtk_button_new_from_stock(GTK_STOCK_EDIT);
- add = gtk_button_new_from_stock(GTK_STOCK_ADD);
- del = gtk_button_new_from_stock(GTK_STOCK_DELETE);
- gtk_widget_set_sensitive(edit, FALSE);
- gtk_widget_set_sensitive(add, FALSE);
- gtk_widget_set_sensitive(del, FALSE);
- gtk_box_pack_start(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), add, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), del, FALSE, FALSE, 0);
-
- cylinder_list[w_idx].edit = edit;
- cylinder_list[w_idx].add = add;
- cylinder_list[w_idx].del = del;
-
- g_signal_connect(edit, "clicked", G_CALLBACK(edit_cb), GINT_TO_POINTER(w_idx));
- g_signal_connect(add, "clicked", G_CALLBACK(add_cb), GINT_TO_POINTER(w_idx));
- g_signal_connect(del, "clicked", G_CALLBACK(del_cb), GINT_TO_POINTER(w_idx));
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
-
- if (w_idx == W_IDX_PRIMARY)
- weightsystem_model = create_weightsystem_model();
- tree_view = weightsystem_list_create(w_idx);
- weightsystem_list[w_idx].tree_view = GTK_TREE_VIEW(tree_view);
-
- frame = gtk_frame_new(_("Weight"));
- gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 3);
-
- framebox = gtk_vbox_new(FALSE, 3);
- gtk_container_add(GTK_CONTAINER(frame), framebox);
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
-
- gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3);
-
- hbox = gtk_hbox_new(TRUE, 3);
- gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
-
- edit = gtk_button_new_from_stock(GTK_STOCK_EDIT);
- add = gtk_button_new_from_stock(GTK_STOCK_ADD);
- del = gtk_button_new_from_stock(GTK_STOCK_DELETE);
- gtk_widget_set_sensitive(edit, FALSE);
- gtk_widget_set_sensitive(add, FALSE);
- gtk_widget_set_sensitive(del, FALSE);
- gtk_box_pack_start(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), add, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), del, FALSE, FALSE, 0);
-
- weightsystem_list[w_idx].edit = edit;
- weightsystem_list[w_idx].add = add;
- weightsystem_list[w_idx].del = del;
-
- g_signal_connect(edit, "clicked", G_CALLBACK(ws_edit_cb), GINT_TO_POINTER(w_idx));
- g_signal_connect(add, "clicked", G_CALLBACK(ws_add_cb), GINT_TO_POINTER(w_idx));
- g_signal_connect(del, "clicked", G_CALLBACK(ws_del_cb), GINT_TO_POINTER(w_idx));
-
- return vbox;
-}
-
-void clear_equipment_widgets()
-{
- gtk_list_store_clear(cylinder_list[W_IDX_PRIMARY].model);
- gtk_list_store_clear(weightsystem_list[W_IDX_PRIMARY].model);
-}
-#endif /* USE_GTK_UI */
diff --git a/gps.c b/gps.c
deleted file mode 100644
index 6f62b624e..000000000
--- a/gps.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/* gps.c */
-/* Creates the UI displaying the dives locations on a map.
- */
-#include <glib/gi18n.h>
-
-#include "osm-gps-map.h"
-
-#include "dive.h"
-#include "display.h"
-#include "display-gtk.h"
-#include "divelist.h"
-
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include <gdk-pixbuf/gdk-pixdata.h>
-#include "flag.h"
-
-static GtkWidget *window = NULL;
-static OsmGpsMap *map = NULL;
-
-static void on_close(GtkWidget *widget, gpointer user_data)
-{
- GtkWidget **window = user_data;
- gtk_grab_remove(widget);
- gtk_widget_destroy(widget);
- *window = NULL;
-}
-
-struct maplocation {
- OsmGpsMap *map;
- double x,y;
- void (* callback)(float, float);
- GtkWidget *mapwindow;
-};
-
-static void add_location_cb(GtkWidget *widget, gpointer data)
-{
- struct maplocation *maplocation = data;
- OsmGpsMap *map = maplocation->map;
- OsmGpsMapPoint *pt = osm_gps_map_point_new_degrees(0.0, 0.0);
- float mark_lat, mark_lon;
-
- osm_gps_map_convert_screen_to_geographic(map, maplocation->x, maplocation->y, pt);
- osm_gps_map_point_get_degrees(pt, &mark_lat, &mark_lon);
- maplocation->callback(mark_lat, mark_lon);
- gtk_widget_destroy(gtk_widget_get_parent(maplocation->mapwindow));
-}
-
-static void map_popup_menu_cb(GtkWidget *w, gpointer data)
-{
- GtkWidget *menu, *menuitem, *image;
-
- menu = gtk_menu_new();
- menuitem = gtk_image_menu_item_new_with_label(_("Mark location here"));
- image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
- g_signal_connect(menuitem, "activate", G_CALLBACK(add_location_cb), data);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
- gtk_widget_show_all(menu);
- gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
- 3, gtk_get_current_event_time());
-}
-
-static gboolean button_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
-{
- static struct maplocation maplocation = {};
- if (data && event->type == GDK_BUTTON_PRESS && event->button == 3) {
- maplocation.map = (OsmGpsMap *)widget;
- maplocation.x = event->x;
- maplocation.y = event->y;
- maplocation.callback = data;
- maplocation.mapwindow = widget;
- map_popup_menu_cb(widget, &maplocation);
- }
- return FALSE;
-}
-
-/* the osm gps map default is to scroll-and-recenter around the mouse position
- * that is BAT SHIT CRAZY.
- * So let's do our own scroll handling instead */
-static gboolean scroll_cb(GtkWidget *widget, GdkEventScroll *event, gpointer data)
-{
- OsmGpsMap *map = (OsmGpsMap *)widget;
- OsmGpsMapPoint *pt, *lt, *rb, *target;
- float target_lat, target_lon;
- gint ltx, lty, rbx, rby, target_x, target_y;
- gint zoom, max_zoom, min_zoom;
-
- g_object_get(widget, "max-zoom", &max_zoom, "zoom", &zoom, "min-zoom", &min_zoom, NULL);
-
- pt = osm_gps_map_point_new_degrees(0.0, 0.0);
- lt = osm_gps_map_point_new_degrees(0.0, 0.0);
- rb = osm_gps_map_point_new_degrees(0.0, 0.0);
- target = osm_gps_map_point_new_degrees(0.0, 0.0);
-
- osm_gps_map_convert_screen_to_geographic(map, event->x, event->y, pt);
-
- osm_gps_map_get_bbox(map, lt, rb);
- osm_gps_map_convert_geographic_to_screen(map, lt, &ltx, &lty);
- osm_gps_map_convert_geographic_to_screen(map, rb, &rbx, &rby);
-
- if (event->direction == GDK_SCROLL_UP) {
- if (zoom == max_zoom)
- return TRUE;
-
- target_x = event->x + ((ltx + rbx) / 2.0 - (gint)(event->x)) / 2;
- target_y = event->y + ((lty + rby) / 2.0 - (gint)(event->y)) / 2;
-
- osm_gps_map_convert_screen_to_geographic(map, target_x, target_y, target);
- osm_gps_map_point_get_degrees(target, &target_lat, &target_lon);
-
- osm_gps_map_zoom_in(map);
- osm_gps_map_set_center(map, target_lat, target_lon);
- } else if (event->direction == GDK_SCROLL_DOWN) {
- if (zoom == min_zoom)
- return TRUE;
-
- target_x = event->x + ((ltx + rbx) / 2.0 - (gint)(event->x)) * 2;
- target_y = event->y + ((lty + rby) / 2.0 - (gint)(event->y)) * 2;
-
- osm_gps_map_convert_screen_to_geographic(map, target_x, target_y, target);
- osm_gps_map_point_get_degrees(target, &target_lat, &target_lon);
-
- osm_gps_map_zoom_out(map);
- osm_gps_map_set_center(map, target_lat, target_lon);
- }
- /* don't allow the insane default handler to get its hands on this event */
- return TRUE;
-}
-
-static void add_gps_point(OsmGpsMap *map, float latitude, float longitude)
-{
- OsmGpsMapTrack *track;
- GdkColor dotColor = { 0, 0xFFFF, 0xFFFF, 0x4444 };
-
- track = g_object_new(OSM_TYPE_GPS_MAP_TRACK,
- "color", &dotColor,
- "line-width", (gfloat) 10,
- "alpha", (gfloat) 0.7,
- NULL);
-
- OsmGpsMapPoint *point = osm_gps_map_point_new_degrees(latitude, longitude);
- osm_gps_map_track_add_point(track, point);
- osm_gps_map_track_add(map, track);
- free((void *)point);
-}
-
-static void key_press_event(GtkWidget *window, GdkEventKey *event, gpointer data)
-{
- if ((event->string != NULL && event->keyval == GDK_Escape) ||
- (event->string != NULL && event->keyval == GDK_w && (event->state & GDK_CONTROL_MASK))) {
- gtk_widget_destroy(window);
- }
-}
-
-OsmGpsMap *init_map(void)
-{
- OsmGpsMap *map;
- OsmGpsMapLayer *osd;
- char *cachedir, *cachebasedir;
-
- cachebasedir = osm_gps_map_get_default_cache_directory();
- cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO);
-
- map = g_object_new(OSM_TYPE_GPS_MAP,
- "map-source", prefs.map_provider,
- "tile-cache", cachedir,
- "tile-cache-base", cachebasedir,
- "proxy-uri", g_getenv("http_proxy"),
- NULL);
- osd = g_object_new(OSM_TYPE_GPS_MAP_OSD,
- "show-scale", TRUE,
- "show-coordinates", TRUE,
- "show-crosshair", FALSE,
- "show-dpad", TRUE,
- "show-zoom", TRUE,
- "show-gps-in-dpad", TRUE,
- "show-gps-in-zoom", FALSE,
- "dpad-radius", 30,
- NULL);
-
- osm_gps_map_layer_add(OSM_GPS_MAP(map), osd);
- g_object_unref(G_OBJECT(osd));
- free((void*)cachebasedir);
- free((void*)cachedir);
- return map;
-}
-
-void show_map(OsmGpsMap *map, GtkWidget **window, struct dive *dive, void (*callback)(float, float))
-{
- if (!*window) {
- /* Enable keyboard navigation */
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_FULLSCREEN, GDK_F11);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_UP, GDK_Up);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_DOWN, GDK_Down);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_LEFT, GDK_Left);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_RIGHT, GDK_Right);
-
- *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_MOUSE);
- gtk_window_set_default_size(GTK_WINDOW(*window), 560, 360);
- gtk_container_set_border_width(GTK_CONTAINER(*window), 5);
- gtk_window_set_resizable(GTK_WINDOW(*window), TRUE);
- gtk_container_add(GTK_CONTAINER(*window), GTK_WIDGET(map));
- gtk_window_set_transient_for(GTK_WINDOW(*window), GTK_WINDOW(main_window));
- gtk_window_set_modal(GTK_WINDOW(*window), TRUE);
- g_signal_connect(*window, "destroy", G_CALLBACK(on_close), (gpointer)window);
- g_signal_connect(G_OBJECT(map), "scroll-event", G_CALLBACK(scroll_cb), NULL);
- g_signal_connect(*window, "key_press_event", G_CALLBACK (key_press_event), NULL);
- }
- if (callback) {
- g_signal_connect(G_OBJECT(map), "button-press-event", G_CALLBACK(button_cb), callback);
- gtk_window_set_title(GTK_WINDOW(*window), _("Use right click to mark dive location at cursor"));
- } else {
- gtk_window_set_title(GTK_WINDOW(*window), _("Dive locations"));
- }
- gtk_widget_show_all(*window);
- if (callback)
- gtk_grab_add(*window);
-}
-
-void show_gps_location(struct dive *dive, void (*callback)(float, float))
-{
- GdkPixbuf *picture;
- GError *gerror = NULL;
-
- double lat = dive->latitude.udeg / 1000000.0;
- double lng = dive->longitude.udeg / 1000000.0;
-
- if (!map || !window)
- map = init_map();
- if (lat != 0 || lng != 0) {
- add_gps_point(map, lat, lng);
- osm_gps_map_set_center_and_zoom(map, lat, lng, 9);
- picture = gdk_pixbuf_from_pixdata(&flag_pixbuf, TRUE, NULL);
- if (picture) {
- osm_gps_map_image_add_with_alignment(map, lat, lng, picture, 0, 1);
- g_object_unref(picture);
- } else {
- printf("error message: %s\n", gerror->message);
- }
- } else {
- osm_gps_map_set_center_and_zoom(map, 0, 0, 1);
- }
- show_map(map, &window, dive, callback);
-}
-
-void show_gps_locations()
-{
- struct dive *dive;
- int idx;
-
- if (!window || !map)
- map = init_map();
-
- for_each_dive(idx, dive) {
- if (dive_has_gps_location(dive)) {
- add_gps_point(map, dive->latitude.udeg / 1000000.0,
- dive->longitude.udeg / 1000000.0);
- }
- }
- osm_gps_map_set_center_and_zoom(map, 0, 0, 1);
-
- show_map(map, &window, NULL, NULL);
-}
diff --git a/gtk-gui.c b/gtk-gui.c
deleted file mode 100644
index 7ec3d8819..000000000
--- a/gtk-gui.c
+++ /dev/null
@@ -1,2610 +0,0 @@
-/* gtk-gui.c */
-/* gtk UI implementation */
-/* creates the window and overall layout
- * divelist, dive info, equipment and printing are handled in their own source files
- */
-/*
- * This is the former qt-gui.cpp - so it already contains some Qt related
- * functions. It's renamed back to gtk-ui.c to keep the old Gtk code
- * around for reference in case we still need it... all that has now been
- * ripped out of qt-gui.cpp */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <ctype.h>
-
-#include "dive.h"
-#include "divelist.h"
-#include "display.h"
-#include "display-gtk.h"
-#include "callbacks-gtk.h"
-#include "uemis.h"
-#include "device.h"
-#include "webservice.h"
-#include "version.h"
-#include "libdivecomputer.h"
-#include "qt-ui/mainwindow.h"
-
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include <gdk-pixbuf/gdk-pixdata.h>
-
-#include <QApplication>
-#include <QFileDialog>
-#include <QFileInfo>
-#include <QStringList>
-#include <QTextCodec>
-#include <QTranslator>
-
-#include <osm-gps-map-source.h>
-
-class Translator: public QTranslator
-{
- Q_OBJECT
-
-public:
- Translator(QObject *parent = 0);
- ~Translator() {}
-
- virtual QString translate(const char *context, const char *sourceText,
- const char *disambiguation = NULL) const;
-};
-
-Translator::Translator(QObject *parent):
- QTranslator(parent)
-{
-}
-
-QString Translator::translate(const char *context, const char *sourceText,
- const char *disambiguation) const
-{
- return gettext(sourceText);
-}
-
-static const GdkPixdata subsurface_icon_pixbuf = {};
-
-GtkWidget *main_window;
-GtkWidget *main_vbox;
-GtkWidget *error_info_bar;
-GtkWidget *error_label;
-GtkWidget *vpane, *hpane;
-GtkWidget *notebook;
-static QApplication *application = NULL;
-
-int error_count;
-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);
-
-static void remember_dc(const char *model, uint32_t deviceid, const char *nickname)
-{
- struct device_info *nn_entry;
-
- nn_entry = create_device_info(model, deviceid);
- if (!nn_entry)
- return;
- if (!nickname || !*nickname) {
- nn_entry->nickname = NULL;
- return;
- }
- nn_entry->nickname = strdup(nickname);
-}
-
-static GtkWidget *dive_profile;
-
-GtkActionGroup *action_group;
-
-void repaint_dive(void)
-{
- update_dive(current_dive);
- if (dive_profile)
- gtk_widget_queue_draw(dive_profile);
-}
-
-static gboolean need_icon = TRUE;
-
-static void on_info_bar_response(GtkWidget *widget, gint response,
- gpointer data)
-{
- if (response == GTK_RESPONSE_OK)
- {
- gtk_widget_destroy(widget);
- error_info_bar = NULL;
- }
-}
-
-void report_error(GError* error)
-{
- qDebug("Warning: Calling GTK-Specific Code.");
- if (error == NULL)
- {
- return;
- }
-
- if (error_info_bar == NULL)
- {
- error_count = 1;
- error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- NULL);
- g_signal_connect(error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
- gtk_info_bar_set_message_type(GTK_INFO_BAR(error_info_bar),
- GTK_MESSAGE_ERROR);
-
- error_label = gtk_label_new(error->message);
- GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(error_info_bar));
- gtk_container_add(GTK_CONTAINER(container), error_label);
-
- gtk_box_pack_start(GTK_BOX(main_vbox), error_info_bar, FALSE, FALSE, 0);
- gtk_widget_show_all(main_vbox);
- }
- else
- {
- error_count++;
- char buffer[256];
- snprintf(buffer, sizeof(buffer), _("Failed to open %i files."), error_count);
- gtk_label_set_text(GTK_LABEL(error_label), buffer);
- }
-}
-
-static GtkFileFilter *setup_filter(void)
-{
- GtkFileFilter *filter = gtk_file_filter_new();
- gtk_file_filter_add_pattern(filter, "*.xml");
- gtk_file_filter_add_pattern(filter, "*.XML");
- gtk_file_filter_add_pattern(filter, "*.uddf");
- gtk_file_filter_add_pattern(filter, "*.UDDF");
- gtk_file_filter_add_pattern(filter, "*.udcf");
- gtk_file_filter_add_pattern(filter, "*.UDCF");
- gtk_file_filter_add_pattern(filter, "*.jlb");
- gtk_file_filter_add_pattern(filter, "*.JLB");
- 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");
- gtk_file_filter_add_pattern(filter, "*.DB");
- gtk_file_filter_add_pattern(filter, "*.db");
-
- gtk_file_filter_add_mime_type(filter, "text/xml");
- gtk_file_filter_set_name(filter, _("XML file"));
-
- return filter;
-}
-
-static void file_save_as(GtkWidget *w, gpointer data)
-{
- GtkWidget *dialog;
- char *filename = NULL;
- char *current_file;
- char *current_dir;
-
- dialog = gtk_file_chooser_dialog_new(_("Save File As"),
- GTK_WINDOW(main_window),
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
-
- if (existing_filename) {
- current_dir = g_path_get_dirname(existing_filename);
- current_file = g_path_get_basename(existing_filename);
- } else {
- const char *current_default = prefs.default_filename;
- current_dir = g_path_get_dirname(current_default);
- current_file = g_path_get_basename(current_default);
- }
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), current_dir);
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), current_file);
-
- free(current_dir);
- free(current_file);
-
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
- }
- gtk_widget_destroy(dialog);
-
- if (filename){
- save_dives(filename);
- set_filename(filename, TRUE);
- g_free(filename);
- mark_divelist_changed(FALSE);
- }
-}
-
-static void file_save(GtkWidget *w, gpointer data)
-{
- const char *current_default;
-
- if (!existing_filename)
- return file_save_as(w, data);
-
- current_default = prefs.default_filename;
- if (strcmp(existing_filename, current_default) == 0) {
- /* if we are using the default filename the directory
- * that we are creating the file in may not exist */
- char *current_def_dir;
- struct stat sb;
-
- current_def_dir = g_path_get_dirname(existing_filename);
- if (stat(current_def_dir, &sb) != 0) {
- g_mkdir(current_def_dir, S_IRWXU);
- }
- free(current_def_dir);
- }
- save_dives(existing_filename);
- mark_divelist_changed(FALSE);
-}
-
-static gboolean ask_save_changes()
-{
- //WARNING: Porting to Qt
- qDebug("This method is being ported to Qt, please, stop using it. ");
- GtkWidget *dialog, *label, *content;
- gboolean quit = TRUE;
- dialog = gtk_dialog_new_with_buttons(_("Save Changes?"),
- GTK_WINDOW(main_window), GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_NO, GTK_RESPONSE_NO,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL);
- content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-
- if (!existing_filename){
- label = gtk_label_new (
- _("You have unsaved changes\nWould you like to save those before closing the datafile?"));
- } else {
- char *label_text = (char*) malloc(sizeof(char) *
- (strlen(_("You have unsaved changes to file: %s \nWould you like to save those before closing the datafile?")) +
- strlen(existing_filename)));
- sprintf(label_text,
- _("You have unsaved changes to file: %s \nWould you like to save those before closing the datafile?"),
- existing_filename);
- label = gtk_label_new (label_text);
- free(label_text);
- }
- gtk_container_add (GTK_CONTAINER (content), label);
- gtk_widget_show_all (dialog);
- gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
- gint outcode = gtk_dialog_run(GTK_DIALOG(dialog));
- if (outcode == GTK_RESPONSE_ACCEPT) {
- file_save(NULL,NULL);
- } else if (outcode == GTK_RESPONSE_CANCEL || outcode == GTK_RESPONSE_DELETE_EVENT) {
- quit = FALSE;
- }
- gtk_widget_destroy(dialog);
- return quit;
-}
-
-static void file_close(GtkWidget *w, gpointer data)
-{
- qDebug("Calling an already ported-to-qt Gtk method");
- if (unsaved_changes())
- if (ask_save_changes() == FALSE)
- return;
-
- if (existing_filename)
- free((void *)existing_filename);
- existing_filename = NULL;
-
- /* free the dives and trips */
- while (dive_table.nr)
- delete_single_dive(0);
- mark_divelist_changed(FALSE);
-
- /* clear the selection and the statistics */
- selected_dive = -1;
- process_selected_dives();
- clear_stats_widgets();
- clear_events();
- show_dive_stats(NULL);
-
- /* clear the equipment page */
- clear_equipment_widgets();
-
- /* redraw the screen */
- dive_list_update_dives();
- show_dive_info(NULL);
-}
-
-//#####################################################################
-//###### ALREAADY PORTED TO Qt. DELETE ME WHEN NOT MORE USERFUL. #
-//#####################################################################
-static void file_open(GtkWidget *w, gpointer data)
-{
- qDebug("Calling an already ported-to-qt Gtk method.");
- GtkWidget *dialog;
- GtkFileFilter *filter;
- const char *current_default;
-
- dialog = gtk_file_chooser_dialog_new(_("Open File"),
- GTK_WINDOW(main_window),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- current_default = prefs.default_filename;
- gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), current_default);
- /* when opening the data file we should allow only one file to be chosen */
- gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
-
- filter = setup_filter();
- gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
-
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- GSList *fn_glist;
- char *filename;
-
- /* first, close the existing file, if any, and forget its name */
- file_close(w, data);
- free((void *)existing_filename);
- existing_filename = NULL;
-
- /* we know there is only one filename */
- fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
-
- GError *error = NULL;
- filename = (char *)fn_glist->data;
- parse_file(filename, &error);
- set_filename(filename, TRUE);
- if (error != NULL)
- {
- report_error(error);
- g_error_free(error);
- error = NULL;
- }
- g_free(filename);
- g_slist_free(fn_glist);
- report_dives(FALSE, FALSE);
- }
- gtk_widget_destroy(dialog);
-}
-
-void save_pane_position()
-{
- gint vpane_position = gtk_paned_get_position(GTK_PANED(vpane));
- gint hpane_position = gtk_paned_get_position(GTK_PANED(hpane));
- gboolean is_maximized = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(main_window))) &
- GDK_WINDOW_STATE_MAXIMIZED;
-
- if (pane_conf == PANE_THREE){
- if (is_maximized) {
- subsurface_set_conf_int("vpane_position_maximized", vpane_position);
- subsurface_set_conf_int("hpane_position_maximized", hpane_position);
- } else {
- subsurface_set_conf_int("vpane_position", vpane_position);
- subsurface_set_conf_int("hpane_position", hpane_position);
- }
- }
-}
-
-/* Since we want direct control of what set of parameters to retrive, this function
- * has an input argument. */
-void restore_pane_position(gboolean maximized)
-{
- if (maximized) {
- gtk_paned_set_position(GTK_PANED(vpane), subsurface_get_conf_int("vpane_position_maximized"));
- gtk_paned_set_position(GTK_PANED(hpane), subsurface_get_conf_int("hpane_position_maximized"));
- } else {
- gtk_paned_set_position(GTK_PANED(vpane), subsurface_get_conf_int("vpane_position"));
- gtk_paned_set_position(GTK_PANED(hpane), subsurface_get_conf_int("hpane_position"));
- }
-}
-
-void save_window_geometry(void)
-{
- /* GDK_GRAVITY_NORTH_WEST assumed ( it is the default ) */
- int window_width, window_height;
- gboolean is_maximized;
-
- gtk_window_get_size(GTK_WINDOW(main_window), &window_width, &window_height);
- is_maximized = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(main_window))) &
- GDK_WINDOW_STATE_MAXIMIZED;
- subsurface_set_conf_int("window_width", window_width);
- subsurface_set_conf_int("window_height", window_height);
- subsurface_set_conf_bool("window_maximized", is_maximized);
- save_pane_position();
- subsurface_flush_conf();
-}
-
-void restore_window_geometry(void)
-{
- int window_width, window_height;
- gboolean is_maximized = subsurface_get_conf_bool("window_maximized") > 0;
-
- window_height = subsurface_get_conf_int("window_height");
- window_width = subsurface_get_conf_int("window_width");
-
- window_height == -1 ? window_height = 300 : window_height;
- window_width == -1 ? window_width = 700 : window_width;
-
- restore_pane_position(is_maximized);
- /* don't resize the window if in maximized state */
- if (is_maximized)
- gtk_window_maximize(GTK_WINDOW(main_window));
- else
- gtk_window_resize(GTK_WINDOW(main_window), window_width, window_height);
-}
-
-gboolean on_delete(GtkWidget* w, gpointer data)
-{
- /* Make sure to flush any modified dive data */
- update_dive(NULL);
-
- gboolean quit = TRUE;
- if (unsaved_changes())
- quit = ask_save_changes();
-
- if (quit){
- save_window_geometry();
- return FALSE; /* go ahead, kill the program, we're good now */
- } else {
- return TRUE; /* We are not leaving */
- }
-}
-
-static void on_destroy(GtkWidget* w, gpointer data)
-{
- dive_list_destroy();
- info_widget_destroy();
- gtk_main_quit();
-}
-
-/* This "window-state-event" callback will be called after the actual action, such
- * as maximize or restore. This means that if you have methods here that check
- * for the current window state, they will obtain the already updated state... */
-static gboolean on_state(GtkWidget *widget, GdkEventWindowState *event, gpointer user_data)
-{
- gint vpane_position, hpane_position;
- if (event->changed_mask & GDK_WINDOW_STATE_WITHDRAWN ||
- event->changed_mask & GDK_WINDOW_STATE_ICONIFIED)
- return TRUE; /* do nothing if the window is shown for the first time or minimized */
- if (pane_conf == PANE_THREE) {
- hpane_position = gtk_paned_get_position(GTK_PANED(hpane));
- vpane_position = gtk_paned_get_position(GTK_PANED(vpane));
- if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) { /* maximize */
- subsurface_set_conf_int("vpane_position", vpane_position);
- subsurface_set_conf_int("hpane_position", hpane_position);
- restore_pane_position(TRUE);
- } else if (event->new_window_state == 0) { /* restore */
- subsurface_set_conf_int("vpane_position_maximized", vpane_position);
- subsurface_set_conf_int("hpane_position_maximized", hpane_position);
- restore_pane_position(FALSE);
- }
- }
- return TRUE;
-}
-
-static void quit(GtkWidget *w, gpointer data)
-{
- /* Make sure to flush any modified dive data */
- update_dive(NULL);
-
- gboolean quit = TRUE;
- if (unsaved_changes())
- quit = ask_save_changes();
-
- if (quit){
- save_window_geometry();
- dive_list_destroy();
- gtk_main_quit();
- }
-}
-
-GtkTreeViewColumn *tree_view_column_add_pixbuf(GtkWidget *tree_view, data_func_t data_func, GtkTreeViewColumn *col)
-{
- GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new();
- gtk_tree_view_column_pack_start(col, renderer, FALSE);
- gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, NULL, NULL);
- g_signal_connect(tree_view, "button-press-event", G_CALLBACK(icon_click_cb), col);
- return col;
-}
-
-GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
- data_func_t data_func, unsigned int flags)
-{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *col;
- double xalign = 0.0; /* left as default */
- PangoAlignment align;
- gboolean visible;
-
- align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
- (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
- PANGO_ALIGN_CENTER;
- visible = !(flags & INVISIBLE);
-
- renderer = gtk_cell_renderer_text_new();
- col = gtk_tree_view_column_new();
-
- if (flags & EDITABLE) {
- g_object_set(renderer, "editable", TRUE, NULL);
- g_signal_connect(renderer, "edited", (GCallback) data_func, tree_view);
- data_func = NULL;
- }
-
- gtk_tree_view_column_set_title(col, title);
- if (!(flags & UNSORTABLE))
- gtk_tree_view_column_set_sort_column_id(col, index);
- gtk_tree_view_column_set_resizable(col, TRUE);
- /* all but one column have only one renderer - so packing from the end
- * makes no difference; for the location column we want to be able to
- * prepend the icon in front of the text - so this works perfectly */
- gtk_tree_view_column_pack_end(col, renderer, TRUE);
- if (data_func)
- gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, (void *)(long)index, NULL);
- else
- gtk_tree_view_column_add_attribute(col, renderer, "text", index);
- switch (align) {
- case PANGO_ALIGN_LEFT:
- xalign = 0.0;
- break;
- case PANGO_ALIGN_CENTER:
- xalign = 0.5;
- break;
- case PANGO_ALIGN_RIGHT:
- xalign = 1.0;
- break;
- }
- gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
- gtk_tree_view_column_set_visible(col, visible);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
- return col;
-}
-
-/* Helper functions for gtk combo boxes */
-GtkEntry *get_entry(GtkComboBox *combo_box)
-{
- return GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
-}
-
-const char *get_active_text(GtkComboBox *combo_box)
-{
- return gtk_entry_get_text(get_entry(combo_box));
-}
-
-void set_active_text(GtkComboBox *combo_box, const char *text)
-{
- gtk_entry_set_text(get_entry(combo_box), text);
-}
-
-GtkWidget *combo_box_with_model_and_entry(GtkListStore *model)
-{
- GtkWidget *widget;
- GtkEntryCompletion *completion;
-
-#if GTK_CHECK_VERSION(2,24,0)
- widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(model));
- gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(widget), 0);
-#else
- widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
- gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(widget), 0);
-#endif
-
- completion = gtk_entry_completion_new();
- gtk_entry_completion_set_text_column(completion, 0);
- gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
- gtk_entry_completion_set_inline_completion(completion, TRUE);
- gtk_entry_completion_set_inline_selection(completion, TRUE);
- gtk_entry_completion_set_popup_single_match(completion, FALSE);
- gtk_entry_set_completion(get_entry(GTK_COMBO_BOX(widget)), completion);
- g_object_unref(completion);
-
- return widget;
-}
-
-static void create_radio(GtkWidget *vbox, const char *w_name, ...)
-{
- va_list args;
- GtkRadioButton *group = NULL;
- GtkWidget *box, *label;
-
- box = gtk_hbox_new(TRUE, 10);
- gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0);
-
- label = gtk_label_new(w_name);
- gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
-
- va_start(args, w_name);
- for (;;) {
- int enabled;
- const char *name;
- GtkWidget *button;
- void *callback_fn;
-
- name = va_arg(args, char *);
- if (!name)
- break;
- callback_fn = va_arg(args, void *);
- enabled = va_arg(args, int);
-
- button = gtk_radio_button_new_with_label_from_widget(group, name);
- group = GTK_RADIO_BUTTON(button);
- gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), enabled);
- g_signal_connect(button, "toggled", G_CALLBACK(callback_fn), NULL);
- }
- va_end(args);
-}
-
-void update_screen()
-{
- update_dive_list_units();
- repaint_dive();
- update_dive_list_col_visibility();
-}
-
-UNITCALLBACK(set_meter, length, units::METERS)
-UNITCALLBACK(set_feet, length, units::FEET)
-UNITCALLBACK(set_bar, pressure, units::BAR)
-UNITCALLBACK(set_psi, pressure, units::PSI)
-UNITCALLBACK(set_liter, volume, units::LITER)
-UNITCALLBACK(set_cuft, volume, units::CUFT)
-UNITCALLBACK(set_celsius, temperature, units::CELSIUS)
-UNITCALLBACK(set_fahrenheit, temperature, units::FAHRENHEIT)
-UNITCALLBACK(set_kg, weight, units::KG)
-UNITCALLBACK(set_lbs, weight, units::LBS)
-
-OPTIONCALLBACK(otu_toggle, prefs.visible_cols.otu)
-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)
-OPTIONCALLBACK(po2_toggle, prefs.pp_graphs.po2)
-OPTIONCALLBACK(pn2_toggle, prefs.pp_graphs.pn2)
-OPTIONCALLBACK(phe_toggle, prefs.pp_graphs.phe)
-OPTIONCALLBACK(mod_toggle, prefs.mod)
-OPTIONCALLBACK(ead_toggle, prefs.ead)
-OPTIONCALLBACK(red_ceiling_toggle, prefs.profile_red_ceiling)
-OPTIONCALLBACK(calc_ceiling_toggle, prefs.profile_calc_ceiling)
-OPTIONCALLBACK(calc_ceiling_3m_toggle, prefs.calc_ceiling_3m_incr)
-
-static gboolean gflow_edit(GtkWidget *w, GdkEvent *event, gpointer _data)
-{
- double gflow;
- const char *buf;
- if (event->type == GDK_FOCUS_CHANGE) {
- buf = gtk_entry_get_text(GTK_ENTRY(w));
- sscanf(buf, "%lf", &gflow);
- prefs.gflow = gflow / 100.0;
- set_gf(prefs.gflow, -1.0);
- update_screen();
- }
- return FALSE;
-}
-
-static gboolean gfhigh_edit(GtkWidget *w, GdkEvent *event, gpointer _data)
-{
- double gfhigh;
- const char *buf;
- if (event->type == GDK_FOCUS_CHANGE) {
- buf = gtk_entry_get_text(GTK_ENTRY(w));
- sscanf(buf, "%lf", &gfhigh);
- prefs.gfhigh = gfhigh / 100.0;
- set_gf(-1.0, prefs.gfhigh);
- update_screen();
- }
- return FALSE;
-}
-
-static void event_toggle(GtkWidget *w, gpointer _data)
-{
- gboolean *plot_ev = (gboolean *)_data;
-
- *plot_ev = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
-}
-
-static void pick_default_file(GtkWidget *w, GtkButton *button)
-{
- GtkWidget *fs_dialog, *parent;
- const char *current_default;
- char *current_def_file, *current_def_dir;
- GtkFileFilter *filter;
- struct stat sb;
-
- fs_dialog = gtk_file_chooser_dialog_new(_("Choose Default XML File"),
- GTK_WINDOW(main_window),
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- NULL);
- parent = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG);
- gtk_widget_set_sensitive(parent, FALSE);
- gtk_window_set_transient_for(GTK_WINDOW(fs_dialog), GTK_WINDOW(parent));
-
- current_default = prefs.default_filename;
- current_def_dir = g_path_get_dirname(current_default);
- current_def_file = g_path_get_basename(current_default);
-
- /* it's possible that the directory doesn't exist (especially for the default)
- * For gtk's file select box to make sense we create it */
- if (stat(current_def_dir, &sb) != 0)
- g_mkdir(current_def_dir, S_IRWXU);
-
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs_dialog), current_def_dir);
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fs_dialog), current_def_file);
- gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(fs_dialog), FALSE);
- filter = setup_filter();
- gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs_dialog), filter);
- gtk_widget_show_all(fs_dialog);
- if (gtk_dialog_run(GTK_DIALOG(fs_dialog)) == GTK_RESPONSE_ACCEPT) {
- GSList *list;
-
- list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fs_dialog));
- if (g_slist_length(list) == 1)
- gtk_button_set_label(button, (const gchar *)list->data);
- g_slist_free(list);
- }
-
- free(current_def_dir);
- free(current_def_file);
- gtk_widget_destroy(fs_dialog);
-
- gtk_widget_set_sensitive(parent, TRUE);
-}
-
-static GtkWidget * map_provider_widget()
-{
- int i;
-#if GTK_CHECK_VERSION(2,24,0)
- GtkWidget *combobox = gtk_combo_box_text_new();
-
- /* 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_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_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;
-}
-
-static void preferences_dialog(GtkWidget *w, gpointer data)
-{
- int result;
- GtkWidget *dialog, *notebook, *font, *frame, *box, *hbox, *vbox, *button;
- GtkWidget *xmlfile_button;
- GtkWidget *map_provider;
- 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];
- struct preferences oldprefs = prefs;
-
- dialog = gtk_dialog_new_with_buttons(_("Preferences"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL);
-
- /* create the notebook for the preferences and attach it to dialog */
- notebook = gtk_notebook_new();
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- gtk_box_pack_start(GTK_BOX(vbox), notebook, FALSE, FALSE, 5);
-
- /* vbox that holds the first notebook page */
- vbox = gtk_vbox_new(FALSE, 6);
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
- gtk_label_new(_("General Settings")));
- frame = gtk_frame_new(_("Units"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
-
- box = gtk_vbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(frame), box);
-
- create_radio(box, _("Depth:"),
- _("Meter"), set_meter, (prefs.units.length == units::METERS),
- _("Feet"), set_feet, (prefs.units.length == units::FEET),
- NULL);
-
- create_radio(box, _("Pressure:"),
- _("Bar"), set_bar, (prefs.units.pressure == units::BAR),
- _("PSI"), set_psi, (prefs.units.pressure == units::PSI),
- NULL);
-
- create_radio(box, _("Volume:"),
- _("Liter"), set_liter, (prefs.units.volume == units::LITER),
- _("CuFt"), set_cuft, (prefs.units.volume == units::CUFT),
- NULL);
-
- create_radio(box, _("Temperature:"),
- _("Celsius"), set_celsius, (prefs.units.temperature == units::CELSIUS),
- _("Fahrenheit"), set_fahrenheit, (prefs.units.temperature == units::FAHRENHEIT),
- NULL);
-
- create_radio(box, _("Weight:"),
- _("kg"), set_kg, (prefs.units.weight == units::KG),
- _("lbs"), set_lbs, (prefs.units.weight == units::LBS),
- NULL);
-
- frame = gtk_frame_new(_("Show Columns"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(frame), box);
-
- button = gtk_check_button_new_with_label(_("Temp"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.temperature);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(temperature_toggle), NULL);
-
- button = gtk_check_button_new_with_label(_("Cyl"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.cylinder);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(cylinder_toggle), NULL);
-
- button = gtk_check_button_new_with_label("O" UTF8_SUBSCRIPT_2 "%");
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.nitrox);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(nitrox_toggle), NULL);
-
- button = gtk_check_button_new_with_label(_("SAC"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.sac);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(sac_toggle), NULL);
-
- button = gtk_check_button_new_with_label(_("Weight"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.totalweight);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(totalweight_toggle), NULL);
-
- button = gtk_check_button_new_with_label(_("Suit"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.suit);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(suit_toggle), NULL);
-
- frame = gtk_frame_new(_("Divelist Font"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
-
- font = gtk_font_button_new_with_font(prefs.divelist_font);
- gtk_container_add(GTK_CONTAINER(frame),font);
-
- frame = gtk_frame_new(_("Misc. Options"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
-
- 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);
- gtk_container_add(GTK_CONTAINER(frame), hbox);
- current_default = prefs.default_filename;
- xmlfile_button = gtk_button_new_with_label(current_default);
- 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);
-
- 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);
-
- /* vbox that holds the second notebook page */
- vbox = gtk_vbox_new(FALSE, 6);
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
- gtk_label_new(_("Tec Settings")));
-
- frame = gtk_frame_new(_("Show Columns"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(frame), box);
-
- button = gtk_check_button_new_with_label(_("OTU"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.otu);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(otu_toggle), NULL);
-
- button = gtk_check_button_new_with_label(_("maxCNS"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.visible_cols.maxcns);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(maxcns_toggle), NULL);
-
- frame = gtk_frame_new(_("Profile Settings"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
-
- vbox = gtk_vbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(frame), vbox);
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- sprintf(utf8_buf, _("Show pO%s graph"), UTF8_SUBSCRIPT_2);
- button = gtk_check_button_new_with_label(utf8_buf);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.pp_graphs.po2);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(po2_toggle), &entry_po2);
-
- sprintf(utf8_buf, _("pO%s threshold"), UTF8_SUBSCRIPT_2);
- frame = gtk_frame_new(utf8_buf);
- gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 6);
- entry_po2 = gtk_entry_new();
- 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);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- sprintf(utf8_buf, _("Show pN%s graph"), UTF8_SUBSCRIPT_2);
- button = gtk_check_button_new_with_label(utf8_buf);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.pp_graphs.pn2);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(pn2_toggle), &entry_pn2);
-
- sprintf(utf8_buf, _("pN%s threshold"), UTF8_SUBSCRIPT_2);
- frame = gtk_frame_new(utf8_buf);
- gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 6);
- entry_pn2 = gtk_entry_new();
- 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);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- button = gtk_check_button_new_with_label(_("Show pHe graph"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.pp_graphs.phe);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(phe_toggle), &entry_phe);
-
- frame = gtk_frame_new(_("pHe threshold"));
- gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 6);
- entry_phe = gtk_entry_new();
- 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);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- button = gtk_check_button_new_with_label(_("Show MOD"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.mod);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(mod_toggle), &entry_mod);
-
- frame = gtk_frame_new(_("max ppO2"));
- gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 6);
- entry_mod = gtk_entry_new();
- 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);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- button = gtk_check_button_new_with_label(_("Show EAD, END, EADD"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.ead);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(ead_toggle), NULL);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- button = gtk_check_button_new_with_label(_("Show dc reported ceiling in red"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.profile_red_ceiling);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(red_ceiling_toggle), NULL);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- button = gtk_check_button_new_with_label(_("Show calculated ceiling"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.profile_calc_ceiling);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(calc_ceiling_toggle), NULL);
-
- button = gtk_check_button_new_with_label(_("3m increments for calculated ceiling"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), prefs.calc_ceiling_3m_incr);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(calc_ceiling_3m_toggle), NULL);
-
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(vbox), box);
-
- frame = gtk_frame_new(_("GFlow"));
- gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 6);
- entry_gflow = gtk_entry_new();
- 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);
-
- frame = gtk_frame_new(_("GFhigh"));
- gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 6);
- entry_gfhigh = gtk_entry_new();
- 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));
- sscanf(po2_threshold_text, "%lf", &prefs.pp_graphs.po2_threshold);
- pn2_threshold_text = gtk_entry_get_text(GTK_ENTRY(entry_pn2));
- sscanf(pn2_threshold_text, "%lf", &prefs.pp_graphs.pn2_threshold);
- phe_threshold_text = gtk_entry_get_text(GTK_ENTRY(entry_phe));
- sscanf(phe_threshold_text, "%lf", &prefs.pp_graphs.phe_threshold);
- mod_text = gtk_entry_get_text(GTK_ENTRY(entry_mod));
- sscanf(mod_text, "%lf", &prefs.mod_ppO2);
- gflow_text = gtk_entry_get_text(GTK_ENTRY(entry_gflow));
- sscanf(gflow_text, "%lf", &prefs.gflow);
- gfhigh_text = gtk_entry_get_text(GTK_ENTRY(entry_gfhigh));
- sscanf(gfhigh_text, "%lf", &prefs.gfhigh);
- prefs.gflow /= 100.0;
- prefs.gfhigh /= 100.0;
- set_gf(prefs.gflow, prefs.gfhigh);
-
- update_screen();
-
- new_default = strdup(gtk_button_get_label(GTK_BUTTON(xmlfile_button)));
-
- /* if we opened the default file and are changing its name,
- * update existing_filename */
- if (existing_filename) {
- if (strcmp(current_default, existing_filename) == 0) {
- free((void *)existing_filename);
- existing_filename = strdup(new_default);
- }
- }
- if (strcmp(current_default, new_default)) {
- prefs.default_filename = new_default;
- }
- /* get the map provider selected */
- int i;
-#if GTK_CHECK_VERSION(2,24,0)
- char *provider = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(map_provider));
-#else
- char *provider = gtk_combo_box_get_active_text(GTK_COMBO_BOX(map_provider));
-#endif
- for (i = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; i <= OSM_GPS_MAP_SOURCE_YAHOO_STREET; i++)
- if (!strcmp(provider,osm_gps_map_source_get_friendly_name((OsmGpsMapSource_t)i))) {
- prefs.map_provider = i;
- break;
- }
- free((void *)provider);
-
- save_preferences();
- dive_list_update_dives();
- } else if (result == GTK_RESPONSE_CANCEL) {
- prefs = oldprefs;
- set_gf(prefs.gflow, prefs.gfhigh);
- update_screen();
- }
- gtk_widget_destroy(dialog);
-}
-
-static void create_toggle(const char* label, int *on, void *_data)
-{
- GtkWidget *button, *table = GTK_WIDGET(_data);
- int rows, cols, x, y;
- static int count;
-
- if (table == NULL) {
- /* magic way to reset the number of toggle buttons
- * that we have already added - call this before you
- * create the dialog */
- count = 0;
- return;
- }
- g_object_get(G_OBJECT(table), "n-columns", &cols, "n-rows", &rows, NULL);
- if (count > rows * cols) {
- gtk_table_resize(GTK_TABLE(table),rows+1,cols);
- rows++;
- }
- x = count % cols;
- y = count / cols;
- button = gtk_check_button_new_with_label(label);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *on);
- gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(event_toggle), on);
- 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;
- GtkWidget *dialog, *frame, *vbox, *table, *label;
-
- dialog = gtk_dialog_new_with_buttons(_("Select Events"),
- 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 Events"));
- 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);
- if (!evn_foreach(&create_toggle, table)) {
- g_object_ref_sink(G_OBJECT(table));
- label = gtk_label_new(_("\nNo Events\n"));
- gtk_container_add(GTK_CONTAINER(frame), label);
- } else {
- 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) {
- repaint_dive();
- }
- gtk_widget_destroy(dialog);
-}
-
-static void autogroup_cb(GtkWidget *w, gpointer data)
-{
- autogroup = !autogroup;
- if (! autogroup)
- remove_autogen_trips();
- dive_list_update_dives();
-}
-
-void set_autogroup(gboolean value)
-{
- GtkAction *autogroup_action;
-
- if (value == autogroup)
- return;
-
- autogroup_action = gtk_action_group_get_action(action_group, "Autogroup");
- gtk_action_activate(autogroup_action);
-}
-
-static void renumber_dialog(GtkWidget *w, gpointer data)
-{
- int result;
- struct dive *dive;
- GtkWidget *dialog, *frame, *button, *vbox;
-
- dialog = gtk_dialog_new_with_buttons(_("Renumber"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
- NULL);
-
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
-
- frame = gtk_frame_new(_("New starting number"));
- 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);
-
- /*
- * Do we have a number for the first dive already? Use that
- * as the default.
- */
- dive = get_dive(0);
- 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) {
- int nr = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button));
- renumber_dives(nr);
- repaint_dive();
- }
- gtk_widget_destroy(dialog);
-}
-
-static void about_dialog_link_cb(GtkAboutDialog *dialog, const gchar *link, gpointer data)
-{
- subsurface_launch_for_uri(link);
-}
-
-static void about_dialog(GtkWidget *w, gpointer data)
-{
- const char *logo_property = NULL;
- GdkPixbuf *logo = NULL;
- GtkWidget *dialog;
-
- if (need_icon) {
- logo_property = "logo";
- logo = gdk_pixbuf_from_pixdata(&subsurface_icon_pixbuf, TRUE, NULL);
- }
- dialog = gtk_about_dialog_new();
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
- gtk_about_dialog_set_url_hook(about_dialog_link_cb, NULL, NULL); /* deprecated since GTK 2.24 */
-#else
- g_signal_connect(GTK_ABOUT_DIALOG(dialog), "activate-link", G_CALLBACK(about_dialog_link_cb), NULL);
-#endif
- g_object_set(GTK_OBJECT(dialog),
- "title", _("About Subsurface"),
- "program-name", "Subsurface",
- "comments", _("Multi-platform divelog software in C"),
- "website", "http://subsurface.hohndel.org",
- "license", "GNU General Public License, version 2\nhttp://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
- "version", VERSION_STRING,
- "copyright", _("Linus Torvalds, Dirk Hohndel, and others, 2011, 2012, 2013"),
- /*++GETTEXT the term translator-credits is magic - list the names of the tranlators here */
- "translator_credits", _("translator-credits"),
- "logo-icon-name", "subsurface",
- /* Must be last: */
- logo_property, logo,
- NULL);
- if (logo)
- g_object_unref(logo);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
-}
-
-static void show_user_manual(GtkWidget *w, gpointer data)
-{
- subsurface_launch_for_uri("http://subsurface.hohndel.org/documentation/user-manual/");
-}
-
-static void view_list(GtkWidget *w, gpointer data)
-{
- save_pane_position();
- gtk_paned_set_position(GTK_PANED(vpane), 0);
- pane_conf = PANE_LIST;
-}
-
-static void view_profile(GtkWidget *w, gpointer data)
-{
- save_pane_position();
- gtk_paned_set_position(GTK_PANED(hpane), 0);
- gtk_paned_set_position(GTK_PANED(vpane), 65535);
- pane_conf = PANE_PROFILE;
-}
-
-static void view_info(GtkWidget *w, gpointer data)
-{
-
- save_pane_position();
- gtk_paned_set_position(GTK_PANED(vpane), 65535);
- gtk_paned_set_position(GTK_PANED(hpane), 65535);
- pane_conf = PANE_INFO;
-}
-
-static void view_three(GtkWidget *w, gpointer data)
-{
- GtkAllocation alloc;
- GtkRequisition requisition;
-
- int vpane_position = subsurface_get_conf_int("vpane_position");
- int hpane_position = subsurface_get_conf_int("hpane_position");
-
- gtk_widget_get_allocation(hpane, &alloc);
-
- if (hpane_position)
- gtk_paned_set_position(GTK_PANED(hpane), hpane_position);
- else
- gtk_paned_set_position(GTK_PANED(hpane), alloc.width/2);
-
- gtk_widget_get_allocation(vpane, &alloc);
- gtk_widget_size_request(notebook, &requisition);
- /* pick the requested size for the notebook plus 6 pixels for frame */
- if (vpane_position)
- gtk_paned_set_position(GTK_PANED(vpane), vpane_position);
- else
- gtk_paned_set_position(GTK_PANED(vpane), requisition.height + 6);
-
- pane_conf = PANE_THREE;
-}
-
-static void toggle_zoom(GtkWidget *w, gpointer data)
-{
- zoomed_plot = (zoomed_plot)?0 : 1;
- /*Update dive*/
- repaint_dive();
-}
-
-static void prev_dc(GtkWidget *w, gpointer data)
-{
- dc_number--;
- /* If the dc number underflows, we'll "wrap around" and use the last dc */
- repaint_dive();
-}
-
-static void next_dc(GtkWidget *w, gpointer data)
-{
- dc_number++;
- /* If the dc number overflows, we'll "wrap around" and zero it */
- repaint_dive();
-}
-
-
-/* list columns for nickname edit treeview */
-enum {
- NE_MODEL,
- NE_ID_STR,
- NE_NICKNAME,
- NE_NCOL
-};
-
-/* delete a selection of nicknames */
-static void edit_dc_delete_rows(GtkTreeView *view)
-{
- GtkTreeModel *model;
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkTreeRowReference *ref;
- GtkTreeSelection *selection;
- GList *selected_rows, *list, *row_references = NULL;
- guint len;
- /* params for delete op */
- const char *model_str;
- const char *deviceid_string; /* convert to deviceid */
- uint32_t deviceid;
-
- selection = gtk_tree_view_get_selection(view);
- selected_rows = gtk_tree_selection_get_selected_rows(selection, &model);
-
- for (list = selected_rows; list; list = g_list_next(list)) {
- path = (GtkTreePath *)list->data;
- ref = gtk_tree_row_reference_new(model, path);
- row_references = g_list_append(row_references, ref);
- }
- len = g_list_length(row_references);
- if (len == 0)
- /* Warn about empty selection? */
- return;
-
- for (list = row_references; list; list = g_list_next(list)) {
- path = gtk_tree_row_reference_get_path((GtkTreeRowReference *)(list->data));
- gtk_tree_model_get_iter(model, &iter, path);
- gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
- NE_MODEL, &model_str,
- NE_ID_STR, &deviceid_string,
- -1);
- if (sscanf(deviceid_string, "0x%x8", &deviceid) == 1)
- remove_dc(model_str, deviceid);
-
- gtk_list_store_remove(GTK_LIST_STORE (model), &iter);
- gtk_tree_path_free(path);
- }
- g_list_free(selected_rows);
- g_list_free(row_references);
- g_list_free(list);
-
- if (gtk_tree_model_get_iter_first(model, &iter))
- gtk_tree_selection_select_iter(selection, &iter);
-}
-
-/* repopulate the edited nickname cell of a DC */
-static void cell_edited_cb(GtkCellRendererText *cell, gchar *path,
- gchar *new_text, gpointer store)
-{
- GtkTreeIter iter;
- const char *model;
- const char *deviceid_string;
- uint32_t deviceid;
- int matched;
-
- gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, path);
- /* display new text */
- gtk_list_store_set(GTK_LIST_STORE(store), &iter, NE_NICKNAME, new_text, -1);
- /* and new_text */
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
- NE_MODEL, &model,
- NE_ID_STR, &deviceid_string,
- -1);
- /* extract deviceid */
- matched = sscanf(deviceid_string, "0x%x8", &deviceid);
-
- /* remember pending commit
- * Need to extend list rather than wipe and store only one result */
- if (matched == 1){
- if (holdnicknames == NULL){
- holdnicknames = (struct device_info *) malloc(sizeof(struct device_info));
- holdnicknames->model = strdup(model);
- holdnicknames->deviceid = deviceid;
- holdnicknames->serial_nr = NULL;
- holdnicknames->firmware = NULL;
- holdnicknames->nickname = strdup(new_text);
- holdnicknames->next = NULL;
- } else {
- struct device_info * top;
- struct device_info * last = holdnicknames;
- top = (struct device_info *) malloc(sizeof(struct device_info));
- top->model = strdup(model);
- top->deviceid = deviceid;
- top->serial_nr = NULL;
- top->firmware = NULL;
- top->nickname = strdup(new_text);
- top->next = last;
- holdnicknames = top;
- }
- }
-}
-
-#define SUB_RESPONSE_DELETE 1 /* no delete response in gtk+2 */
-#define SUB_DONE 2 /* enable escape when done */
-
-/* show the dialog to edit dc nicknames */
-static void edit_dc_nicknames(GtkWidget *w, gpointer data)
-{
- const gchar *C_INACTIVE = "#e8e8ee", *C_ACTIVE = "#ffffff"; /* cell colours */
- GtkWidget *dialog, *confirm, *view, *scroll, *vbox;
- GtkCellRenderer *renderer;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkListStore *store;
- GtkTreeIter iter;
- gint res = -1;
- char id_string[11] = {0};
- struct device_info * nnl;
-
- dialog = gtk_dialog_new_with_buttons(_("Edit Dive Computer Nicknames"),
- GTK_WINDOW(main_window),
- GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
- GTK_STOCK_DELETE,
- SUB_RESPONSE_DELETE,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- GTK_STOCK_APPLY,
- GTK_RESPONSE_APPLY,
- NULL);
- gtk_widget_set_size_request(dialog, 700, 400);
-
- scroll = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-
- view = gtk_tree_view_new();
- store = gtk_list_store_new(NE_NCOL, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
- model = GTK_TREE_MODEL(store);
-
- /* columns */
- renderer = gtk_cell_renderer_text_new();
- g_object_set(renderer, "background", C_INACTIVE, NULL);
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, _("Model"),
- renderer, "text", NE_MODEL, NULL);
-
- renderer = gtk_cell_renderer_text_new();
- g_object_set(renderer, "background", C_INACTIVE, NULL);
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, _("Device Id"),
- renderer, "text", NE_ID_STR, NULL);
-
- renderer = gtk_cell_renderer_text_new();
- g_object_set(renderer, "background", C_INACTIVE, NULL);
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, _("Nickname"),
- renderer, "text", NE_NICKNAME, NULL);
- g_object_set(renderer, "editable", TRUE, NULL);
- g_object_set(renderer, "background", C_ACTIVE, NULL);
- g_signal_connect(renderer, "edited", G_CALLBACK(cell_edited_cb), store);
-
- gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
- g_object_unref(model);
-
- /* populate list store from device_info_list */
- nnl = head_of_device_info_list();
- while (nnl) {
- sprintf(&id_string[0], "%#08x", nnl->deviceid);
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- NE_MODEL, nnl->model,
- NE_ID_STR, id_string,
- NE_NICKNAME, nnl->nickname,
- -1);
- nnl = nnl->next;
- }
-
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
- gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE);
-
- 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 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);
-
- do {
- res = gtk_dialog_run(GTK_DIALOG(dialog));
- if (res == SUB_RESPONSE_DELETE) {
- confirm = gtk_dialog_new_with_buttons(_("Delete a dive computer information entry"),
- GTK_WINDOW(dialog),
- GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
- GTK_STOCK_YES,
- GTK_RESPONSE_YES,
- GTK_STOCK_NO,
- GTK_RESPONSE_NO,
- NULL);
- gtk_widget_set_size_request(confirm, 350, 90);
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(confirm));
- gtk_container_add(GTK_CONTAINER(vbox),
- gtk_label_new(_("Ok to delete the selected entry?")));
- gtk_widget_show_all(confirm);
- if (gtk_dialog_run(GTK_DIALOG(confirm)) == GTK_RESPONSE_YES) {
- edit_dc_delete_rows(GTK_TREE_VIEW(view));
- res = SUB_DONE; /* want to close ** both ** dialogs now */
- }
- mark_divelist_changed(TRUE);
- gtk_widget_destroy(confirm);
- }
- if (res == GTK_RESPONSE_APPLY && holdnicknames && holdnicknames->model != NULL) {
- struct device_info * walk = holdnicknames;
- struct device_info * release = holdnicknames;
- struct device_info * track = holdnicknames->next;
- while (walk) {
- remember_dc(walk->model, walk->deviceid, walk->nickname);
- walk = walk->next;
- }
- /* clear down list */
- while (release){
- free(release);
- release = track;
- if (track)
- track = track->next;
- }
- holdnicknames = NULL;
- mark_divelist_changed(TRUE);
- }
- } while (res != SUB_DONE && res != GTK_RESPONSE_CANCEL && res != GTK_RESPONSE_DELETE_EVENT && res != GTK_RESPONSE_APPLY);
- gtk_widget_destroy(dialog);
-}
-
-static GtkActionEntry menu_items[] = {
- { "FileMenuAction", NULL, N_("File"), NULL, NULL, NULL},
- { "LogMenuAction", NULL, N_("Log"), NULL, NULL, NULL},
- { "ViewMenuAction", NULL, N_("View"), NULL, NULL, NULL},
- { "FilterMenuAction", NULL, N_("Filter"), NULL, NULL, NULL},
- { "PlannerMenuAction", NULL, N_("Planner"), NULL, NULL, NULL},
- { "HelpMenuAction", NULL, N_("Help"), NULL, NULL, NULL},
- { "NewFile", GTK_STOCK_NEW, N_("New"), CTRLCHAR "N", NULL, G_CALLBACK(file_close) },
- { "OpenFile", GTK_STOCK_OPEN, N_("Open..."), CTRLCHAR "O", NULL, G_CALLBACK(file_open) },
- { "SaveFile", GTK_STOCK_SAVE, N_("Save..."), CTRLCHAR "S", NULL, G_CALLBACK(file_save) },
- { "SaveAsFile", GTK_STOCK_SAVE_AS, N_("Save As..."), SHIFTCHAR CTRLCHAR "S", NULL, G_CALLBACK(file_save_as) },
- { "CloseFile", GTK_STOCK_CLOSE, N_("Close"), NULL, NULL, G_CALLBACK(file_close) },
- { "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) },
- { "DivesLocations", NULL, N_("Dives Locations"), CTRLCHAR "M", NULL, G_CALLBACK(show_gps_locations) },
- { "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) },
- { "ViewList", NULL, N_("List"), CTRLCHAR "1", NULL, G_CALLBACK(view_list) },
- { "ViewProfile", NULL, N_("Profile"), CTRLCHAR "2", NULL, G_CALLBACK(view_profile) },
- { "ViewInfo", NULL, N_("Info"), CTRLCHAR "3", NULL, G_CALLBACK(view_info) },
- { "ViewThree", NULL, N_("Three"), CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
- { "EditNames", NULL, N_("Edit Device Names"), CTRLCHAR "E", NULL, G_CALLBACK(edit_dc_nicknames) },
- { "PrevDC", NULL, N_("Prev DC"), NULL, NULL, G_CALLBACK(prev_dc) },
- { "NextDC", NULL, N_("Next DC"), NULL, NULL, G_CALLBACK(next_dc) },
- { "InputPlan", NULL, N_("Input Plan"), NULL, NULL, G_CALLBACK(input_plan) },
-};
-static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
-
-static GtkToggleActionEntry toggle_items[] = {
- { "Autogroup", NULL, N_("Autogroup"), NULL, NULL, G_CALLBACK(autogroup_cb), FALSE },
- { "ToggleZoom", NULL, N_("Toggle Zoom"), CTRLCHAR "0", NULL, G_CALLBACK(toggle_zoom), FALSE },
-};
-static gint ntoggle_items = sizeof (toggle_items) / sizeof (toggle_items[0]);
-
-static const gchar* ui_string = " \
- <ui> \
- <menubar name=\"MainMenu\"> \
- <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
- <menuitem name=\"New\" action=\"NewFile\" /> \
- <menuitem name=\"Open\" action=\"OpenFile\" /> \
- <menuitem name=\"Save\" action=\"SaveFile\" /> \
- <menuitem name=\"Save As\" action=\"SaveAsFile\" /> \
- <menuitem name=\"Close\" action=\"CloseFile\" /> \
- <separator name=\"Separator1\"/> \
- <menuitem name=\"Import XML File\" action=\"ImportFile\" /> \
- <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\" /> \
- <separator name=\"Separator4\"/> \
- <menuitem name=\"Quit\" action=\"Quit\" /> \
- </menu> \
- <menu name=\"LogMenu\" action=\"LogMenuAction\"> \
- <menuitem name=\"Download From Dive Computer\" action=\"DownloadLog\" /> \
- <menuitem name=\"Download From Web Service\" action=\"DownloadWeb\" /> \
- <menuitem name=\"Edit Dive Computer Names\" action=\"EditNames\" /> \
- <separator name=\"Separator1\"/> \
- <menuitem name=\"Add Dive\" action=\"AddDive\" /> \
- <separator name=\"Separator2\"/> \
- <menuitem name=\"Renumber\" action=\"Renumber\" /> \
- <menuitem name=\"Autogroup\" action=\"Autogroup\" /> \
- <menuitem name=\"Toggle Zoom\" action=\"ToggleZoom\" /> \
- <menuitem name=\"YearlyStats\" action=\"YearlyStats\" />"
- "<menuitem name=\"Dive Locations\" action=\"DivesLocations\" /> "
- "</menu> \
- <menu name=\"ViewMenu\" action=\"ViewMenuAction\"> \
- <menuitem name=\"List\" action=\"ViewList\" /> \
- <menuitem name=\"Profile\" action=\"ViewProfile\" /> \
- <menuitem name=\"Info\" action=\"ViewInfo\" /> \
- <menuitem name=\"Paned\" action=\"ViewThree\" /> \
- <menuitem name=\"PrevDC\" action=\"PrevDC\" /> \
- <menuitem name=\"NextDC\" action=\"NextDC\" /> \
- </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\" /> \
- </menu> \
- <menu name=\"Help\" action=\"HelpMenuAction\"> \
- <menuitem name=\"About\" action=\"About\" /> \
- <menuitem name=\"UserManual\" action=\"UserManual\" /> \
- </menu> \
- </menubar> \
- </ui> \
-";
-
-static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
-{
- action_group = gtk_action_group_new("Menu");
- gtk_action_group_set_translation_domain(action_group, "subsurface");
- gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
- toggle_items[0].is_active = autogroup;
- gtk_action_group_add_toggle_actions(action_group, toggle_items, ntoggle_items, 0);
-
- gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
- GError* error = 0;
- gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
-
- gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
- GtkWidget* menu = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
-
- return menu;
-}
-
-static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
-{
- repaint_dive();
-}
-
-static gboolean on_key_press(GtkWidget *w, GdkEventKey *event, GtkWidget *divelist)
-{
- if (event->type != GDK_KEY_PRESS || event->state != 0)
- return FALSE;
- switch (event->keyval) {
- case GDK_Up:
- select_prev_dive();
- return TRUE;
- case GDK_Down:
- select_next_dive();
- return TRUE;
- case GDK_Left:
- prev_dc(NULL, NULL);
- return TRUE;
- case GDK_Right:
- next_dc(NULL, NULL);
- return TRUE;
- }
- return FALSE;
-}
-
-static gboolean notebook_tooltip (GtkWidget *widget, gint x, gint y,
- gboolean keyboard_mode, GtkTooltip *tooltip, gpointer data)
-{
- if (amount_selected > 0 && gtk_notebook_get_current_page(GTK_NOTEBOOK(widget)) == 0) {
- gtk_tooltip_set_text(tooltip, _("To edit dive information\ndouble click on it in the dive list"));
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-#if NEEDS_TO_MOVE_TO_QT_UI
-/* this appears to have moved - but it's very different in qt-ui */
-
-class MainWindow: public QMainWindow, private Ui::MainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow(QWidget *parent = 0);
- ~MainWindow() {}
-
- void setCurrentFileName(const QString &fileName);
-
-private Q_SLOTS:
- void on_actionNew_triggered() { on_actionClose_triggered(); }
- void on_actionOpen_triggered();
- void on_actionSave_triggered() { file_save(NULL, NULL); }
- void on_actionSaveAs_triggered() { file_save_as(NULL, NULL); }
- void on_actionClose_triggered();
-
-private:
- QStringList fileNameFilters() const;
-
-private:
- QString m_currentFileName;
-};
-
-MainWindow::MainWindow(QWidget *parent):
- QMainWindow(parent)
-{
- setupUi(this);
-}
-
-void MainWindow::setCurrentFileName(const QString &fileName)
-{
- if (fileName == m_currentFileName) return;
- m_currentFileName = fileName;
-
- QString title = tr("Subsurface");
- if (!m_currentFileName.isEmpty()) {
- QFileInfo fileInfo(m_currentFileName);
- title += " - " + fileInfo.fileName();
- }
- setWindowTitle(title);
-}
-
-void MainWindow::on_actionOpen_triggered()
-{
- QString defaultFileName = prefs.default_filename;
- QFileInfo fileInfo(defaultFileName);
-
- QFileDialog dialog(this, tr("Open File"), fileInfo.path());
- dialog.setFileMode(QFileDialog::ExistingFile);
- dialog.selectFile(defaultFileName);
- dialog.setNameFilters(fileNameFilters());
- if (dialog.exec()) {
- /* first, close the existing file, if any */
- file_close(NULL, NULL);
-
- /* we know there is only one filename */
- QString fileName = dialog.selectedFiles().first();
- GError *error = NULL;
- parse_file(fileName.toUtf8().constData(), &error);
- if (error != NULL) {
- report_error(error);
- g_error_free(error);
- error = NULL;
- } else {
- setCurrentFileName(fileName);
- }
- report_dives(FALSE, FALSE);
- }
-}
-
-void MainWindow::on_actionClose_triggered()
-{
- if (unsaved_changes())
- if (ask_save_changes() == FALSE)
- return;
-
- setCurrentFileName(QString());
-
- /* free the dives and trips */
- while (dive_table.nr)
- delete_single_dive(0);
- mark_divelist_changed(FALSE);
-
- /* clear the selection and the statistics */
- selected_dive = -1;
- process_selected_dives();
- clear_stats_widgets();
- clear_events();
- show_dive_stats(NULL);
-
- /* clear the equipment page */
- clear_equipment_widgets();
-
- /* redraw the screen */
- dive_list_update_dives();
- show_dive_info(NULL);
-}
-
-QStringList MainWindow::fileNameFilters() const
-{
- QStringList filters;
-
- filters << "*.xml *.uddf *.udcf *.jlb"
-#ifdef LIBZIP
- " *.sde *.dld"
-#endif
-#ifdef SQLITE3
- " *.db"
-#endif
- ;
- return filters;
-}
-#endif /* NEEDS_TO_MOVE_TO_QT_UI */
-
-void init_qt_ui(int *argcp, char ***argvp)
-{
- application->installTranslator(new Translator(application));
- MainWindow *window = new MainWindow();
- window->show();
-}
-
-void init_ui(int *argcp, char ***argvp)
-{
- application = new QApplication(*argcp, *argvp);
-
-#if QT_VERSION < 0x050000
- // ask QString in Qt 4 to interpret all char* as UTF-8,
- // like Qt 5 does.
- // 106 is "UTF-8", this is faster than lookup by name
- // [http://www.iana.org/assignments/character-sets/character-sets.xml]
- QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106));
-#endif
-
- GtkWidget *win;
- GtkWidget *nb_page;
- GtkWidget *dive_list;
- GtkWidget *menubar;
- GtkWidget *vbox;
- GtkWidget *scrolled;
- GdkScreen *screen;
- GtkIconTheme *icon_theme=NULL;
- GtkSettings *settings;
- GtkUIManager *ui_manager;
-
- gtk_init(argcp, argvp);
- settings = gtk_settings_get_default();
- gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", 10, "subsurface setting");
- gtk_settings_set_long_property(settings, "gtk-menu-images", 1, "subsurface setting");
- gtk_settings_set_long_property(settings, "gtk-button-images", 1, "subsurface setting");
-
- /* check if utf8 stars are available as a default OS feature */
- if (!subsurface_os_feature_available(UTF8_FONT_WITH_STARS)) {
- star_strings[0] = " ";
- star_strings[1] = "* ";
- star_strings[2] = "** ";
- star_strings[3] = "*** ";
- star_strings[4] = "**** ";
- star_strings[5] = "*****";
- }
-#if !GLIB_CHECK_VERSION(2,3,6)
- g_type_init();
-#endif
- subsurface_open_conf();
-
- load_preferences();
-
- default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor");
- default_dive_computer_product = subsurface_get_conf("dive_computer_product");
- default_dive_computer_device = subsurface_get_conf("dive_computer_device");
- error_info_bar = NULL;
- win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- g_set_application_name ("subsurface");
- /* Let's check if the subsurface icon has been installed or if
- * we need to try to load it from the current directory */
- screen = gdk_screen_get_default();
- if (screen)
- icon_theme = gtk_icon_theme_get_for_screen(screen);
- if (icon_theme) {
- if (gtk_icon_theme_has_icon(icon_theme, "subsurface")) {
- need_icon = FALSE;
- gtk_window_set_default_icon_name ("subsurface");
- }
- }
- if (need_icon) {
- const char *icon_name = subsurface_icon_name();
- if (!access(icon_name, R_OK))
- gtk_window_set_icon_from_file(GTK_WINDOW(win), icon_name, NULL);
- }
- g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
- g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
- g_signal_connect(G_OBJECT(win), "window-state-event", G_CALLBACK(on_state), NULL);
- main_window = win;
-
- vbox = gtk_vbox_new(FALSE, 0);
- gtk_container_add(GTK_CONTAINER(win), vbox);
- main_vbox = vbox;
-
- ui_manager = gtk_ui_manager_new();
- menubar = get_menubar_menu(win, ui_manager);
-
- subsurface_ui_setup(settings, menubar, vbox, ui_manager);
-
- vpane = gtk_vpaned_new();
- gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 3);
- hpane = gtk_hpaned_new();
- gtk_paned_add1(GTK_PANED(vpane), hpane);
- g_signal_connect_after(G_OBJECT(vbox), "realize", G_CALLBACK(view_three), NULL);
-
- /* Notebook for dive info vs profile vs .. */
- notebook = gtk_notebook_new();
- scrolled = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- gtk_paned_add1(GTK_PANED(hpane), scrolled);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), notebook);
- g_signal_connect(notebook, "switch-page", G_CALLBACK(switch_page), NULL);
-
- /* Create the actual divelist */
- dive_list = dive_list_create();
- gtk_widget_set_name(dive_list, "Dive List");
- gtk_paned_add2(GTK_PANED(vpane), dive_list);
-
- /* Frame for dive profile */
- dive_profile = dive_profile_widget();
- gtk_widget_set_name(dive_profile, "Dive Profile");
- gtk_paned_add2(GTK_PANED(hpane), dive_profile);
-
- /* Frame for extended dive info */
- nb_page = extended_dive_info_widget();
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new(_("Dive Notes")));
-
- /* Frame for dive equipment */
- nb_page = equipment_widget(W_IDX_PRIMARY);
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new(_("Equipment")));
-
- /* Frame for single dive statistics */
- nb_page = single_stats_widget();
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new(_("Dive Info")));
-
- /* Frame for total dive statistics */
- nb_page = total_stats_widget();
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new(_("Stats")));
-
- /* add tooltip that tells people how to edit things */
- g_object_set(notebook, "has-tooltip", TRUE, NULL);
- g_signal_connect(notebook, "query-tooltip", G_CALLBACK(notebook_tooltip), NULL);
-
- /* handle some keys globally (to deal with gtk focus issues) */
- g_signal_connect (G_OBJECT (win), "key_press_event", G_CALLBACK (on_key_press), dive_list);
-
- gtk_widget_set_app_paintable(win, TRUE);
- restore_window_geometry();
- gtk_widget_show_all(win);
-
- return;
-}
-
-void run_ui(void)
-{
- application->exec();
-}
-
-void exit_ui(void)
-{
- delete application;
- subsurface_close_conf();
- if (existing_filename)
- free((void *)existing_filename);
- if (default_dive_computer_device)
- free((void *)default_dive_computer_device);
-}
-
-typedef struct {
- cairo_rectangle_t rect;
- const char *text;
- struct event *event;
-} tooltip_record_t;
-
-static tooltip_record_t *tooltip_rects;
-static int tooltips;
-
-void attach_tooltip(int x, int y, int w, int h, const char *text, struct event *event)
-{
- cairo_rectangle_t *rect;
- tooltip_rects = (tooltip_record_t *)
- realloc(tooltip_rects, (tooltips + 1) * sizeof(tooltip_record_t));
- rect = &tooltip_rects[tooltips].rect;
- rect->x = x;
- rect->y = y;
- rect->width = w;
- rect->height = h;
- tooltip_rects[tooltips].text = strdup(text);
- tooltip_rects[tooltips].event = event;
- tooltips++;
-}
-
-#define INSIDE_RECT(_r,_x,_y) ((_r.x <= _x) && (_r.x + _r.width >= _x) && \
- (_r.y <= _y) && (_r.y + _r.height >= _y))
-#define INSIDE_RECT_X(_r, _x) ((_r.x <= _x) && (_r.x + _r.width >= _x))
-
-static gboolean profile_tooltip (GtkWidget *widget, gint x, gint y,
- gboolean keyboard_mode, GtkTooltip *tooltip, struct graphics_context *gc)
-{
- int i;
- cairo_rectangle_t *drawing_area = &gc->drawing_area;
- gint tx = x - drawing_area->x; /* get transformed coordinates */
- gint ty = y - drawing_area->y;
- gint width, height, time = -1;
- char buffer[2048], plot[1024];
- const char *event = "";
-
- if (tx < 0 || ty < 0)
- return FALSE;
-
- /* don't draw a tooltip if nothing is there */
- if (amount_selected == 0 || gc->pi.nr == 0)
- return FALSE;
-
- width = drawing_area->width - 2*drawing_area->x;
- height = drawing_area->height - 2*drawing_area->y;
- if (width <= 0 || height <= 0)
- return FALSE;
-
- if (tx > width || ty > height)
- return FALSE;
-
- time = (tx * gc->maxtime) / width;
-
- /* are we over an event marker ? */
- for (i = 0; i < tooltips; i++) {
- if (INSIDE_RECT(tooltip_rects[i].rect, tx, ty)) {
- event = tooltip_rects[i].text;
- break;
- }
- }
- get_plot_details(gc, time, plot, sizeof(plot));
-
- snprintf(buffer, sizeof(buffer), "@ %d:%02d%c%s%c%s", time / 60, time % 60,
- *plot ? '\n' : ' ', plot,
- *event ? '\n' : ' ', event);
- gtk_tooltip_set_text(tooltip, buffer);
- return TRUE;
-
-}
-
-static double zoom_factor = 1.0;
-static int zoom_x = -1, zoom_y = -1;
-
-static void common_drawing_function(GtkWidget *widget, struct graphics_context *gc)
-{
- int i = 0;
- struct dive *dive = current_dive;
-
- gc->drawing_area.x = MIN(50,gc->drawing_area.width / 20.0);
- gc->drawing_area.y = MIN(50,gc->drawing_area.height / 20.0);
-
- g_object_set(widget, "has-tooltip", TRUE, NULL);
- g_signal_connect(widget, "query-tooltip", G_CALLBACK(profile_tooltip), gc);
- init_profile_background(gc);
- cairo_paint(gc->cr);
-
- if (zoom_factor > 1.0) {
- double n = -(zoom_factor-1);
- cairo_translate(gc->cr, n*zoom_x, n*zoom_y);
- cairo_scale(gc->cr, zoom_factor, zoom_factor);
- }
-
- if (dive) {
- if (tooltip_rects) {
- while (i < tooltips) {
- if (tooltip_rects[i].text)
- free((void *)tooltip_rects[i].text);
- i++;
- }
- free(tooltip_rects);
- tooltip_rects = NULL;
- }
- tooltips = 0;
- plot(gc, dive, SC_SCREEN);
- }
-}
-
-#if GTK_CHECK_VERSION(3,0,0)
-
-static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
-{
- guint width, height;
- static struct graphics_context gc = { .printer = 0 };
-
- width = gtk_widget_get_allocated_width(widget);
- height = gtk_widget_get_allocated_height(widget);
-
- gc.drawing_area.width = width;
- gc.drawing_area.height = height;
- gc.cr = cr;
-
- common_drawing_function(widget, &gc);
- return FALSE;
-}
-
-#else /* gtk2 */
-
-static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
-{
- GtkAllocation allocation;
- static struct graphics_context gc = { 0 };
-
- /* the drawing area gives TOTAL width * height - x,y is used as the topx/topy offset
- * so effective drawing area is width-2x * height-2y */
- gtk_widget_get_allocation(widget, &allocation);
- gc.drawing_area.width = allocation.width;
- gc.drawing_area.height = allocation.height;
- gc.cr = gdk_cairo_create(gtk_widget_get_window(widget));
-
- common_drawing_function(widget, &gc);
- cairo_destroy(gc.cr);
- return FALSE;
-}
-
-#endif
-
-static void zoom_event(int x, int y, double inc)
-{
- zoom_x = x;
- zoom_y = y;
- inc += zoom_factor;
- if (inc < 1.0)
- inc = 1.0;
- else if (inc > 10)
- inc = 10;
- zoom_factor = inc;
-}
-
-static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
-{
- switch (event->direction) {
- case GDK_SCROLL_UP:
- zoom_event(event->x, event->y, 0.1);
- break;
- case GDK_SCROLL_DOWN:
- zoom_event(event->x, event->y, -0.1);
- break;
- default:
- return TRUE;
- }
- gtk_widget_queue_draw(widget);
- return TRUE;
-}
-
-static void add_gas_change_cb(GtkWidget *menuitem, gpointer data)
-{
- double *x = (double *)data;
- int when = x_to_time(*x);
- int cylnr = select_cylinder(current_dive, when);
- if (cylnr >= 0) {
- cylinder_t *cyl = &current_dive->cylinder[cylnr];
- int value = cyl->gasmix.o2.permille / 10 | ((cyl->gasmix.he.permille / 10) << 16);
- add_event(current_dc, when, 25, 0, value, "gaschange");
- mark_divelist_changed(TRUE);
- report_dives(FALSE, FALSE);
- dive_list_update_dives();
- }
-}
-
-int confirm_dialog(int when, char *action_text, char *event_text)
-{
- GtkWidget *dialog, *vbox, *label;
- int confirmed;
- char title[80];
-
- snprintf(title, sizeof(title), "%s %s", action_text, event_text);
- dialog = gtk_dialog_new_with_buttons(title,
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
- NULL);
-
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- label = create_label(_("%s event at %d:%02u"), title, FRACTION(when, 60));
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- gtk_widget_show_all(dialog);
- confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
-
- gtk_widget_destroy(dialog);
-
- return confirmed;
-}
-
-static void add_bookmark_cb(GtkWidget *menuitem, gpointer data)
-{
- double *x = (double *)data;
- int when = x_to_time(*x);
-
- if (confirm_dialog(when, _("Add"), _("bookmark"))){
- add_event(current_dc, when, 8, 0, 0, "bookmark");
- mark_divelist_changed(TRUE);
- report_dives(FALSE, FALSE);
- }
-}
-
-static struct event *event_at_x(double rel_x)
-{
- /* is there an event marker at this x coordinate */
- struct event *ret = NULL;
- int i;
- int x = x_abs(rel_x);
-
- for (i = 0; i < tooltips; i++) {
- if (INSIDE_RECT_X(tooltip_rects[i].rect, x)) {
- ret = tooltip_rects[i].event;
- break;
- }
- }
- return ret;
-}
-
-static void remove_event_cb(GtkWidget *menuitem, gpointer data)
-{
- struct event *event = (struct event *)data;
- if (confirm_dialog(event->time.seconds, _("Remove"), _(event->name))){
- struct event **ep = &current_dc->events;
- while (ep && *ep != event)
- ep = &(*ep)->next;
- if (ep) {
- *ep = event->next;
- free(event);
- }
- mark_divelist_changed(TRUE);
- report_dives(FALSE, FALSE);
- }
-}
-
-static void popup_profile_menu(GtkWidget *widget, GdkEventButton *gtk_event)
-{
- GtkWidget *menu, *menuitem, *image;
- static double x;
- struct event *event;
-
- if (!gtk_event || !current_dive)
- return;
- x = gtk_event->x;
- menu = gtk_menu_new();
- menuitem = gtk_image_menu_item_new_with_label(_("Add gas change event here"));
- image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
- g_signal_connect(menuitem, "activate", G_CALLBACK(add_gas_change_cb), &x);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
- menuitem = gtk_image_menu_item_new_with_label(_("Add bookmark event here"));
- image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
- g_signal_connect(menuitem, "activate", G_CALLBACK(add_bookmark_cb), &x);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
- if ((event = event_at_x(x)) != NULL) {
- menuitem = gtk_image_menu_item_new_with_label(_("Remove event here"));
- image = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
- g_signal_connect(menuitem, "activate", G_CALLBACK(remove_event_cb), event);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
- }
-
- gtk_widget_show_all(menu);
-
- gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
- gtk_event->button, gtk_get_current_event_time());
-
-}
-
-static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
-{
- switch (event->button) {
- case 1:
- zoom_x = event->x;
- zoom_y = event->y;
- zoom_factor = 2.5;
- break;
- case 3:
- popup_profile_menu(widget, event);
- break;
- default:
- return TRUE;
- }
- gtk_widget_queue_draw(widget);
- return TRUE;
-}
-
-static gboolean released(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
-{
- switch (event->button) {
- case 1:
- zoom_x = zoom_y = -1;
- zoom_factor = 1.0;
- break;
- default:
- return TRUE;
- }
- gtk_widget_queue_draw(widget);
- return TRUE;
-}
-
-static gboolean motion(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
-{
- if (zoom_x < 0)
- return TRUE;
-
- zoom_x = event->x;
- zoom_y = event->y;
- gtk_widget_queue_draw(widget);
- return TRUE;
-}
-
-static GtkWidget *dive_profile_widget(void)
-{
- GtkWidget *da;
-
- da = gtk_drawing_area_new();
- gtk_widget_set_size_request(da, 350, 250);
-#if GTK_CHECK_VERSION(3,0,0)
- g_signal_connect(da, "draw", G_CALLBACK (draw_callback), NULL);
-#else
- g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
-#endif
- g_signal_connect(da, "button-press-event", G_CALLBACK(clicked), NULL);
- g_signal_connect(da, "scroll-event", G_CALLBACK(scroll_event), NULL);
- g_signal_connect(da, "button-release-event", G_CALLBACK(released), NULL);
- g_signal_connect(da, "motion-notify-event", G_CALLBACK(motion), NULL);
- gtk_widget_add_events(da, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK);
-
- return da;
-}
-
-static void do_import_file(gpointer data, gpointer user_data)
-{
- GError *error = NULL;
- parse_file((const char *)data, &error);
-
- if (error != NULL)
- {
- report_error(error);
- g_error_free(error);
- error = NULL;
- }
-}
-
-static void import_files(GtkWidget *w, gpointer data)
-{
- GtkWidget *fs_dialog;
- const char *current_default;
- char *current_def_dir;
- GtkFileFilter *filter;
- struct stat sb;
- GSList *filenames = NULL;
-
- fs_dialog = gtk_file_chooser_dialog_new(_("Choose XML Files To Import Into Current Data File"),
- GTK_WINDOW(main_window),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
-
- /* I'm not sure what the best default path should be... */
- if (existing_filename) {
- current_def_dir = g_path_get_dirname(existing_filename);
- } else {
- current_default = prefs.default_filename;
- current_def_dir = g_path_get_dirname(current_default);
- }
-
- /* it's possible that the directory doesn't exist (especially for the default)
- * For gtk's file select box to make sense we create it */
- if (stat(current_def_dir, &sb) != 0)
- g_mkdir(current_def_dir, S_IRWXU);
-
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs_dialog), current_def_dir);
- gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(fs_dialog), TRUE);
- filter = setup_filter();
- gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs_dialog), filter);
- gtk_widget_show_all(fs_dialog);
- if (gtk_dialog_run(GTK_DIALOG(fs_dialog)) == GTK_RESPONSE_ACCEPT) {
- /* grab the selected file list, import each file and update the list */
- filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fs_dialog));
- if (filenames) {
- g_slist_foreach(filenames, do_import_file, NULL);
- report_dives(TRUE, FALSE);
- g_slist_free(filenames);
- }
- }
-
- free(current_def_dir);
- gtk_widget_destroy(fs_dialog);
-}
-
-void set_filename(const char *filename, gboolean force)
-{
- if (!force && existing_filename)
- return;
- free((void *)existing_filename);
- if (filename)
- existing_filename = strdup(filename);
- else
- existing_filename = NULL;
-}
-
-const char *get_dc_nickname(const char *model, uint32_t deviceid)
-{
- struct device_info *known = get_device_info(model, deviceid);
- if (known) {
- if (known->nickname && *known->nickname)
- return known->nickname;
- else
- return known->model;
- }
- return NULL;
-}
-
-void set_dc_nickname(struct dive *dive)
-{
- GtkWidget *dialog, *vbox, *entry, *frame, *label;
- char nickname[160] = "";
- char dialogtext[2048];
- const char *name = nickname;
- struct divecomputer *dc = &dive->dc;
-
- if (!dive)
- return;
- while (dc) {
-#if NICKNAME_DEBUG & 16
- fprintf(debugfile, "set_dc_nickname for model %s deviceid %8x\n", dc->model ? : "", dc->deviceid);
-#endif
- if (get_dc_nickname(dc->model, dc->deviceid) == NULL) {
- struct device_info *nn_entry = get_different_device_info(dc->model, dc->deviceid);
- if (nn_entry) {
- dialog = gtk_dialog_new_with_buttons(
- _("Dive Computer Nickname"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL);
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- snprintf(dialogtext, sizeof(dialogtext),
- _("You already have a dive computer of this model\n"
- "named %s\n"
- "Subsurface can maintain a nickname for this device to "
- "distinguish it from the existing one. "
- "The default is the model and device ID as shown below.\n"
- "If you don't want to name this dive computer click "
- "'Cancel' and Subsurface will simply display its model "
- "as its name (which may mean that you cannot tell the two "
- "dive computers apart in the logs)."),
- nn_entry->nickname && *nn_entry->nickname ? nn_entry->nickname :
- (nn_entry->model && *nn_entry->model ? nn_entry->model : _("(nothing)")));
- label = gtk_label_new(dialogtext);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 3);
- frame = gtk_frame_new(_("Nickname"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, TRUE, 3);
- entry = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(frame), entry);
- gtk_entry_set_max_length(GTK_ENTRY(entry), 68);
- snprintf(nickname, sizeof(nickname), "%s (%08x)", dc->model, dc->deviceid);
- gtk_entry_set_text(GTK_ENTRY(entry), nickname);
- gtk_widget_show_all(dialog);
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- if (strcmp(dc->model, gtk_entry_get_text(GTK_ENTRY(entry)))) {
- name = gtk_entry_get_text(GTK_ENTRY(entry));
- remember_dc(dc->model, dc->deviceid, name);
- mark_divelist_changed(TRUE);
- }
- } else {
- /* Remember that we declined the nickname */
- remember_dc(dc->model, dc->deviceid, NULL);
- }
- gtk_widget_destroy(dialog);
- } else {
- remember_dc(dc->model, dc->deviceid, NULL);
- }
- }
- dc = dc->next;
- }
-}
-
-gdouble get_screen_dpi(void)
-{
- const gdouble mm_per_inch = 25.4;
- GdkScreen *scr = gdk_screen_get_default();
- gdouble h_mm = gdk_screen_get_height_mm(scr);
- gdouble h = gdk_screen_get_height(scr);
- gdouble dpi_h = floor((h / h_mm) * mm_per_inch);
- return dpi_h;
-}
-
-#include "qt-gui.moc"
diff --git a/libdivecomputer.c b/libdivecomputer.c
index a60131614..0569689ec 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -7,9 +7,6 @@
#include "device.h"
#include "divelist.h"
#include "display.h"
-#ifdef USE_GTK_UI
-#include "display-gtk.h"
-#endif
#include "libdivecomputer.h"
#include "libdivecomputer/version.h"
@@ -28,21 +25,6 @@ double progress_bar_fraction = 0.0;
static int stoptime, stopdepth, ndl, po2, cns;
static bool in_deco, first_temp_is_air;
-#if USE_GTK_UI
-static GError *error(const char *fmt, ...)
-{
- va_list args;
- GError *error;
-
- va_start(args, fmt);
- error = g_error_new_valist(
- g_quark_from_string("subsurface"),
- DIVE_ERROR_PARSE, fmt, args);
- va_end(args);
- return error;
-}
-#endif
-
static dc_status_t create_parser(device_data_t *devdata, dc_parser_t **parser)
{
return dc_parser_new(parser, devdata->device);
diff --git a/linux.c b/linux.c
index 070a091fe..159e02d6a 100644
--- a/linux.c
+++ b/linux.c
@@ -9,21 +9,6 @@
const char system_divelist_default_font[] = "Sans 8";
-void subsurface_flush_conf(void)
-{
- /* this is a no-op */
-}
-
-void subsurface_close_conf(void)
-{
- /* this is a no-op */
-}
-
-const char *subsurface_icon_name()
-{
- return "subsurface-icon.svg";
-}
-
const char *system_default_filename(void)
{
const char *home, *user;
@@ -38,17 +23,6 @@ const char *system_default_filename(void)
return buffer;
}
-const char *subsurface_gettext_domainpath(char *argv0)
-{
- if (argv0[0] == '.') {
- /* we're starting a local copy */
- return "./share/locale";
- } else {
- /* subsurface is installed, so system dir should be fine */
- return NULL;
- }
-}
-
void subsurface_command_line_init(int *argc, char ***argv)
{
/* this is a no-op */
diff --git a/macos.c b/macos.c
index 4f41970b6..ac5faf0e8 100644
--- a/macos.c
+++ b/macos.c
@@ -5,9 +5,6 @@
#include <fnmatch.h>
#include "dive.h"
#include "display.h"
-#if USE_GTK_UI
-#include "display-gtk.h"
-#endif /* USE_GTK_UI */
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <mach-o/dyld.h>
@@ -27,142 +24,6 @@
const char system_divelist_default_font[] = "Arial 10";
-void subsurface_open_conf(void)
-{
- /* nothing at this time */
-}
-
-void subsurface_unset_conf(const char *name)
-{
- CFPreferencesSetAppValue(CFSTR_VAR(name), NULL, SUBSURFACE_PREFERENCES);
-}
-
-void subsurface_set_conf(const char *name, const char *value)
-{
- CFPreferencesSetAppValue(CFSTR_VAR(name), CFSTR_VAR(value), SUBSURFACE_PREFERENCES);
-}
-
-void subsurface_set_conf_bool(const char *name, bool value)
-{
- CFPreferencesSetAppValue(CFSTR_VAR(name),
- value ? kCFBooleanTrue : kCFBooleanFalse, SUBSURFACE_PREFERENCES);
-}
-
-void subsurface_set_conf_int(const char *name, int value)
-{
- CFNumberRef numRef = CFNumberCreate(NULL, kCFNumberIntType, &value);
- CFPreferencesSetAppValue(CFSTR_VAR(name), numRef, SUBSURFACE_PREFERENCES);
-}
-
-const char *subsurface_get_conf(const char *name)
-{
- CFPropertyListRef strpref;
-
- strpref = CFPreferencesCopyAppValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES);
- if (!strpref)
- return NULL;
- return strdup(CFStringGetCStringPtr(strpref, kCFStringEncodingMacRoman));
-}
-
-int subsurface_get_conf_bool(const char *name)
-{
- Boolean boolpref, exists;
-
- boolpref = CFPreferencesGetAppBooleanValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES, &exists);
- if (!exists)
- return -1;
- return boolpref;
-}
-
-int subsurface_get_conf_int(const char *name)
-{
- Boolean exists;
- CFIndex value;
-
- value = CFPreferencesGetAppIntegerValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES, &exists);
- if (!exists)
- return -1;
- return value;
-}
-
-void subsurface_flush_conf(void)
-{
- int ok = CFPreferencesAppSynchronize(SUBSURFACE_PREFERENCES);
- if (!ok)
- fprintf(stderr,"Could not save preferences\n");
-}
-
-void subsurface_close_conf(void)
-{
- /* Nothing */
-}
-
-#if USE_GTK_UI
-int subsurface_fill_device_list(GtkListStore *store)
-{
- int i = 0;
- int index = -1;
- GtkTreeIter iter;
- GDir *dev;
- const char *name;
-
- dev = g_dir_open("/dev", 0, NULL);
- while (dev && (name = g_dir_read_name(dev)) != NULL) {
- if (strstr(name, "usbserial") ||
- (strstr(name, "SerialPort") && strstr(name, "cu"))) {
- int len = strlen(name) + 6;
- char *devicename = malloc(len);
- snprintf(devicename, len, "/dev/%s", name);
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- 0, devicename, -1);
- if (is_default_dive_computer_device(devicename))
- index = i;
- i++;
- }
- }
- if (dev)
- g_dir_close(dev);
- dev = g_dir_open("/Volumes", 0, NULL);
- while (dev && (name = g_dir_read_name(dev)) != NULL) {
- if (strstr(name, "UEMISSDA")) {
- int len = strlen(name) + 10;
- char *devicename = malloc(len);
- snprintf(devicename, len, "/Volumes/%s", name);
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- 0, devicename, -1);
- if (is_default_dive_computer_device(devicename))
- index = i;
- i++;
- }
- }
- if (dev)
- g_dir_close(dev);
- if (i == 0) {
- /* if we can't find anything, use the default */
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- 0, "/dev/tty.SLAB_USBtoUART", -1);
- if (is_default_dive_computer_device("/dev/tty.SLAB_USBtoUART"))
- index = i;
- }
- return index;
-}
-#endif
-
-const char *subsurface_icon_name()
-{
- static char path[PATH_MAX];
-
-#if USE_GTK_UI
- snprintf(path, sizeof(path), "%s/%s", gtkosx_application_get_resource_path(), ICON_NAME);
-#else
- /* need Qt path */
-#endif
- return path;
-}
-
const char *system_default_filename(void)
{
const char *home, *user;
@@ -177,71 +38,6 @@ const char *system_default_filename(void)
return buffer;
}
-const char *subsurface_gettext_domainpath(char *argv0)
-{
- /* on a Mac we ignore the argv0 argument and instead use the resource_path
- * to figure out where to find the translation files */
-#if USE_GTK_UI
- static char buffer[PATH_MAX];
- const char *resource_path = gtkosx_application_get_resource_path();
- if (resource_path) {
- snprintf(buffer, sizeof(buffer), "%s/share/locale", resource_path);
- return buffer;
- }
-#endif /* USE_GTK_UI */
- return "./share/locale";
-}
-
-#if USE_GTK_UI
-static void show_main_window(GtkWidget *w, gpointer data)
-{
- gtk_widget_show(main_window);
- gtk_window_present(GTK_WINDOW(main_window));
-}
-
-void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
- GtkWidget *vbox, GtkUIManager *ui_manager)
-{
- GtkWidget *menu_item, *sep;
- static char path[PATH_MAX];
-
- snprintf(path, sizeof(path), "%s/xslt", gtkosx_application_get_resource_path());
- setenv("SUBSURFACE_XSLT_PATH", path, TRUE);
-
- g_object_set(G_OBJECT(settings), "gtk-font-name", UI_FONT, NULL);
-
- osx_app = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
- gtk_widget_hide (menubar);
- gtkosx_application_set_menu_bar(osx_app, GTK_MENU_SHELL(menubar));
-
- sep = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Separator3");
- if (sep)
- gtk_widget_destroy(sep);
-
- menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Quit");
- gtk_widget_hide (menu_item);
- menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/Help/About");
- gtkosx_application_insert_app_menu_item(osx_app, menu_item, 0);
-
- sep = gtk_separator_menu_item_new();
- g_object_ref(sep);
- gtkosx_application_insert_app_menu_item (osx_app, sep, 1);
-
- menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Preferences");
- gtkosx_application_insert_app_menu_item(osx_app, menu_item, 2);
-
- sep = gtk_separator_menu_item_new();
- g_object_ref(sep);
- gtkosx_application_insert_app_menu_item (osx_app, sep, 3);
-
- gtkosx_application_set_use_quartz_accelerators(osx_app, TRUE);
- g_signal_connect(osx_app,"NSApplicationDidBecomeActive",G_CALLBACK(show_main_window),NULL);
- g_signal_connect(osx_app, "NSApplicationBlockTermination", G_CALLBACK(on_delete), NULL);
-
- gtkosx_application_ready(osx_app);
-}
-#endif /* UES_GTK_UI */
-
void subsurface_command_line_init(int *argc, char ***argv)
{
/* this is a no-op */
@@ -257,15 +53,6 @@ bool subsurface_os_feature_available(os_feature_t f)
return TRUE;
}
-bool subsurface_launch_for_uri(const char* uri)
-{
- CFURLRef urlref = CFURLCreateWithBytes(NULL, uri, strlen(uri), kCFStringEncodingMacRoman, NULL);
- OSStatus status = LSOpenCFURLRef(urlref, NULL);
- if (status)
- return FALSE;
- return TRUE;
-}
-
int enumerate_devices (device_callback_t callback, void *userdata)
{
int index = -1;
diff --git a/planner.c b/planner.c
index bddb5a737..4139052fc 100644
--- a/planner.c
+++ b/planner.c
@@ -496,7 +496,7 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
return stoplevels;
}
-#if USE_GTK_UI
+#if DO_WE_WANT_THIS_IN_QT
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
{
char buffer[20000];
@@ -722,12 +722,11 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b
record_dive(dive);
stopidx--;
}
-#if USE_GTK_UI
+
+#if DO_WE_WANT_THIS_IN_QT
add_plan_to_notes(diveplan, dive);
- /* now make the dive visible in the dive list */
- report_dives(FALSE, FALSE);
- show_and_select_dive(dive);
#endif
+
error_exit:
free(stoplevels);
free(gaschanges);
@@ -761,30 +760,6 @@ static int get_tenths(const char *begin, const char **endp)
return value;
}
-static int get_thousandths(const char *begin, const char **endp)
-{
- char *end;
- int value = strtol(begin, &end, 10);
-
- if (begin == end)
- return -1;
- value *= 1000;
-
- /* now deal with up to three more digits after decimal point */
- if (*end == '.') {
- int factor = 100;
- do {
- ++end;
- if (!isdigit(*end))
- break;
- value += (*end - '0') * factor;
- factor /= 10;
- } while (factor);
- }
- *endp = end;
- return value;
-}
-
static int get_permille(const char *begin, const char **end)
{
int value = get_tenths(begin, end);
@@ -835,112 +810,6 @@ int validate_gas(const char *text, int *o2_p, int *he_p)
return 1;
}
-int validate_time(const char *text, int *sec_p, int *rel_p)
-{
- int min, sec, rel;
- char *end;
-
- if (!text)
- return 0;
-
- while (isspace(*text))
- text++;
-
- rel = 1;
- if (*text == '+') {
- rel = 1;
- text++;
- while (isspace(*text))
- text++;
- } else if (*text == '@') {
- rel = 0;
- text++;
- while (isspace(*text))
- text++;
- }
-
- min = strtol(text, &end, 10);
- if (text == end)
- return 0;
-
- if (min < 0 || min > 1000)
- return 0;
-
- /* Ok, minutes look ok */
- text = end;
- sec = 0;
- if (*text == ':') {
- text++;
- sec = strtol(text, &end, 10);
- if (end != text+2)
- return 0;
- if (sec < 0)
- return 0;
- text = end;
- if (*text == ':') {
- if (sec >= 60)
- return 0;
- min = min*60 + sec;
- text++;
- sec = strtol(text, &end, 10);
- if (end != text+2)
- return 0;
- if (sec < 0)
- return 0;
- text = end;
- }
- }
-
- /* Maybe we should accept 'min' at the end? */
- if (isspace(*text))
- text++;
- if (*text)
- return 0;
-
- *sec_p = min*60 + sec;
- *rel_p = rel;
- return 1;
-}
-
-int validate_depth(const char *text, int *mm_p)
-{
- int depth, imperial;
-
- if (!text)
- return 0;
-
- depth = get_tenths(text, &text);
- if (depth < 0)
- return 0;
-
- while (isspace(*text))
- text++;
-
- imperial = get_units()->length == FEET;
- if (*text == 'm') {
- imperial = 0;
- text++;
- } else if (!strcasecmp(text, tr("ft"))) {
- imperial = 1;
- text += 2;
- }
- while (isspace(*text))
- text++;
- if (*text)
- return 0;
-
- if (imperial) {
- depth = feet_to_mm(depth / 10.0);
- } else {
- depth *= 100;
- }
- *mm_p = depth;
- /* we don't support extreme depths */
- if (depth > 400000)
- return 0;
- return 1;
-}
-
int validate_po2(const char *text, int *mbar_po2)
{
int po2;
@@ -964,78 +833,3 @@ int validate_po2(const char *text, int *mbar_po2)
return 1;
}
-int validate_volume(const char *text, int *sac)
-{
- int volume, imperial;
-
- if (!text)
- return 0;
-
- volume = get_thousandths(text, &text);
- if (volume < 0)
- return 0;
-
- while (isspace(*text))
- text++;
-
- imperial = get_units()->volume == CUFT;
- if (*text == 'l') {
- imperial = 0;
- text++;
- } else if (!strncasecmp(text, tr("cuft"), 4)) {
- imperial = 1;
- text += 4;
- }
- while (isspace(*text) || *text == '/')
- text++;
- if (!strncasecmp(text, tr("min"), 3))
- text += 3;
- while (isspace(*text))
- text++;
- if (*text)
- return 0;
- if (imperial)
- volume = cuft_to_l(volume) + 0.5; /* correct for mcuft -> ml */
- *sac = volume;
- return 1;
-}
-
-#if USE_GTK_UI
-struct diveplan diveplan = {};
-char *cache_data = NULL;
-struct dive *planned_dive = NULL;
-
-/* make a copy of the diveplan so far and display the corresponding dive */
-void show_planned_dive(char **error_string_p)
-{
- struct diveplan tempplan;
- struct divedatapoint *dp, **dpp;
-
- memcpy(&tempplan, &diveplan, sizeof(struct diveplan));
- dpp = &tempplan.dp;
- dp = diveplan.dp;
- while (dp && *dpp) {
- *dpp = malloc(sizeof(struct divedatapoint));
- memcpy(*dpp, dp, sizeof(struct divedatapoint));
- dp = dp->next;
- dpp = &(*dpp)->next;
- }
-#if DEBUG_PLAN & 1
- printf("in show_planned_dive:\n");
- dump_plan(&tempplan);
-#endif
- plan(&tempplan, &cache_data, &planned_dive, error_string_p);
- free_dps(tempplan.dp);
-}
-
-/* Subsurface follows the lead of most divecomputers to use times
- * without timezone - so all times are implicitly assumed to be
- * local time of the dive location; so in order to give the current
- * time in that way we actually need to add the timezone offset */
-timestamp_t current_time_notz(void)
-{
- time_t now = time(NULL);
- struct tm *local = localtime(&now);
- return utc_mktime(local);
-}
-#endif
diff --git a/planner.h b/planner.h
index b61d76b7d..201a2fcd5 100644
--- a/planner.h
+++ b/planner.h
@@ -7,10 +7,7 @@ extern "C" {
#endif
extern int validate_gas(const char *text, int *o2_p, int *he_p);
-extern int validate_time(const char *text, int *sec_p, int *rel_p);
-extern int validate_depth(const char *text, int *mm_p);
extern int validate_po2(const char *text, int *mbar_po2);
-extern int validate_volume(const char *text, int *sac);
extern timestamp_t current_time_notz(void);
extern void show_planned_dive(char **error_string_p);
extern int add_duration_to_nth_dp(struct diveplan *diveplan, int idx, int duration, bool is_rel);
diff --git a/print.c b/print.c
deleted file mode 100644
index e5b85c47f..000000000
--- a/print.c
+++ /dev/null
@@ -1,1127 +0,0 @@
-#include <glib/gi18n.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <gtk/gtk.h>
-
-#include "dive.h"
-#include "display.h"
-#include "display-gtk.h"
-
-#define FONT_NORMAL (12)
-#define FONT_SMALL (FONT_NORMAL / 1.2)
-#define FONT_LARGE (FONT_NORMAL * 1.2)
-
-static double rel_width[] = { 0.333, 1.166, 0.5, 0.5, 1.0, 1.0, 1.8 };
-static int last_page_paginated, last_dive_paginated;
-/* dynamically growing array of the first dive to be printed on each
- * page in table mode */
-static int *first_dive;
-
-static struct options print_options = {PRETTY, 0, 2, FALSE, 65, 15, 12};
-
-typedef struct _Print_params {
- int rotation, dives;
- double w_scale, h_scale;
-} Print_params;
-
-/* Return the 'i'th dive for printing, taking our dive selection into account */
-static struct dive *get_dive_for_printing(int idx)
-{
- if (print_options.print_selected) {
- int i;
- struct dive *dive;
- for_each_dive(i, dive) {
- if (!dive->selected)
- continue;
- if (!idx)
- return dive;
- idx--;
- }
- return NULL;
- }
- return get_dive(idx);
-}
-
-static void set_font(PangoLayout *layout, PangoFontDescription *font,
- double size, int align)
-{
- pango_font_description_set_size(font, size * PANGO_SCALE * SCALE_PRINT);
- pango_layout_set_font_description(layout, font);
- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
- pango_layout_set_alignment(layout, align);
-}
-
-/*
- * You know what? Maybe somebody can do a real Pango layout thing.
- * This is hacky.
- */
-
-/*
- * Show a header for the dive containing minimal data
- */
-static void show_dive_header(struct dive *dive, cairo_t *cr, double w,
- double h, PangoFontDescription *font, double w_scale_factor)
-{
- double depth;
- const char *unit;
- int len, decimals, width, height, maxwidth, maxheight;
- PangoLayout *layout;
- PangoRectangle ink_ext, logic_ext;
- struct tm tm;
- char buffer[512], divenr[80], *people;
-
- maxwidth = w * PANGO_SCALE;
- maxheight = h * PANGO_SCALE * 0.9;
- cairo_save(cr);
- layout = pango_cairo_create_layout(cr);
- pango_layout_set_width(layout, maxwidth);
- pango_layout_set_height(layout, maxheight);
-
- *divenr = 0;
- if (dive->number)
- snprintf(divenr, sizeof(divenr), _("Dive #%d - "), dive->number);
-
- utc_mkdate(dive->when, &tm);
- len = snprintf(buffer, sizeof(buffer),
- /*++GETTEXT 80 chars: lead text ("" or localized "Dive #%d - ") weekday, monthname, day, year, hour, min */
- _("%1$s%2$s, %3$s %4$d, %5$d %6$d:%7$02d"),
- divenr,
- weekday(tm.tm_wday),
- monthname(tm.tm_mon),
- tm.tm_mday, tm.tm_year + 1900,
- tm.tm_hour, tm.tm_min);
- set_font(layout, font, FONT_LARGE *(1.5/w_scale_factor), PANGO_ALIGN_LEFT);
- pango_layout_set_text(layout, buffer, len);
- pango_layout_get_size(layout, &width, &height);
- cairo_move_to(cr, 0, 0);
- pango_cairo_show_layout(cr, layout);
-
- people = dive->buddy;
- if (!people || !*people) {
- people = dive->divemaster;
- if (!people)
- people = "";
- }
-
- depth = get_depth_units(dive->maxdepth.mm, &decimals, &unit);
- snprintf(buffer, sizeof(buffer),
- _("Max depth: %.*f %s\nDuration: %d min\n%s"),
- decimals, depth, unit,
- (dive->duration.seconds+59) / 60,
- people);
- set_font(layout, font, FONT_NORMAL*(1.5/w_scale_factor), PANGO_ALIGN_RIGHT);
- pango_layout_set_text(layout, buffer, -1);
- cairo_move_to(cr, 0, 0);
- pango_cairo_show_layout(cr, layout);
-
- /*
- * Show the dive location
- *
- * .. or at least a space to get the size.
- *
- * Move down by the size of the date, and limit the
- * width to the same width as the date string.
- */
- pango_layout_get_extents (layout, &ink_ext, &logic_ext);
- cairo_translate (cr, 0, ink_ext.height /(1.5 * PANGO_SCALE));
- pango_layout_set_height(layout, 1);
- pango_layout_set_width(layout, width);
- set_font(layout, font, FONT_LARGE*(1.5/w_scale_factor), PANGO_ALIGN_LEFT);
- pango_layout_set_text(layout, dive->location ? : " ", -1);
- cairo_move_to(cr, 0, 0);
- pango_cairo_show_layout(cr, layout);
-
- g_object_unref(layout);
- cairo_restore(cr);
-}
-/*
- * Show the dive notes
- */
-static void show_dive_notes(struct dive *dive, cairo_t *cr, double w,
- double h, PangoFontDescription *font, double w_scale_factor)
-{
- int maxwidth, maxheight;
- PangoLayout *layout;
-
- maxwidth = w * PANGO_SCALE;
- maxheight = h * PANGO_SCALE * 0.9;
- layout = pango_cairo_create_layout(cr);
- if (dive->notes) {
- pango_layout_set_height(layout, maxheight);
- pango_layout_set_width(layout, maxwidth);
- set_font(layout, font, FONT_NORMAL*(1.5/w_scale_factor), PANGO_ALIGN_LEFT);
- pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
- pango_layout_set_justify(layout, 1);
- pango_layout_set_text(layout, dive->notes, -1);
-
- cairo_move_to(cr, 0, 0);
- pango_cairo_show_layout(cr, layout);
- }
- g_object_unref(layout);
-}
-/* Print the used gas mix */
-static void print_ean_trimix (cairo_t *cr, PangoLayout *layout, int O2, int He){
-
- char buffer[64];
-
- if (He){
- snprintf(buffer, sizeof(buffer), "Tx%d/%d", O2, He);
- }else{
- if (O2){
- if (O2 == 100){
- snprintf(buffer, sizeof(buffer), _("Oxygen"));
- }else{
- snprintf(buffer, sizeof(buffer), "EAN%d", O2);
- }
- }else{
- snprintf(buffer, sizeof(buffer), _("air"));
- }
- }
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
-}
-
-static unsigned start_pressure(cylinder_t *cyl)
-{
- return cyl->start.mbar ? : cyl->sample_start.mbar;
-}
-
-static unsigned end_pressure(cylinder_t *cyl)
-{
- return cyl->end.mbar ? : cyl->sample_end.mbar;
-}
-
-/* Print the tank data */
-static void print_tanks (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth, int maxheight,
- int tank_count, int first_tank, PangoFontDescription *font,
- double w_scale_factor)
-{
- int curwidth, n, i, counter, height_count = 0;
- char buffer[80], dataheader1[3][80]= { N_("Cylinder"), N_("Gasmix"),
- /*++GETTEXT Gas Used is amount used */
- N_("Gas Used")};
- PangoRectangle logic_ext;
-
- cairo_save(cr);
-
- /* First create a header */
- curwidth = 0;
- pango_layout_get_extents(layout, NULL, &logic_ext);
-
- for (i = 0; i < 3; i++) {
- cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
- pango_layout_set_text(layout, _(dataheader1[i]), -1);
- pango_layout_set_justify(layout, 0);
- pango_cairo_show_layout(cr, layout);
- curwidth = curwidth + maxwidth/ 3;
- }
- /* Then the cylinder stuff */
- n = first_tank;
- counter = 0;
- pango_layout_get_extents(layout, NULL, &logic_ext);
- cairo_translate (cr, 0, logic_ext.height / (double) PANGO_SCALE);
-
- while (n < tank_count && n < first_tank + 4) {
- int decimals;
- const char *unit, *desc;
- double gas_usage;
- cylinder_t *cyl = dive->cylinder + n;
-
- /* Get the cylinder gas use in mbar */
- gas_usage = start_pressure(cyl) - end_pressure(cyl);
-
- /* Can we turn it into a volume? */
- if (cyl->type.size.mliter) {
- gas_usage = bar_to_atm(gas_usage / 1000);
- gas_usage *= cyl->type.size.mliter;
- gas_usage = get_volume_units(gas_usage, &decimals, &unit);
- } else {
- gas_usage = get_pressure_units(gas_usage, &unit);
- decimals = 0;
- }
-
- curwidth = 0;
- cairo_move_to (cr, curwidth / (double) PANGO_SCALE, 0);
- desc = cyl->type.description ? : "";
- snprintf(buffer, sizeof(buffer), "%s", desc);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- pango_layout_get_extents(layout, NULL, &logic_ext);
- if (logic_ext.height > height_count)
- height_count = logic_ext.height;
-
- curwidth += (maxwidth/ 3);
-
- cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
- print_ean_trimix (cr, layout,
- cyl->gasmix.o2.permille/10,
- cyl->gasmix.he.permille/10);
- pango_layout_get_extents(layout, NULL, &logic_ext);
- if (logic_ext.height > height_count)
- height_count = logic_ext.height;
-
- curwidth += (maxwidth/ 3);
-
- cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
- snprintf(buffer, sizeof(buffer), _("%.*f %s"),
- decimals,
- gas_usage,
- unit);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- pango_layout_get_extents(layout, NULL, &logic_ext);
- if (logic_ext.height > height_count)
- height_count = logic_ext.height;
-
- curwidth += (maxwidth/ 3);
- n++;
- counter++;
-
- cairo_translate (cr, 0, height_count / (double) PANGO_SCALE);
- }
- g_object_unref (layout);
- cairo_restore(cr);
-}
-
-/* Print weight system */
-static void print_weight_data (struct dive *dive, cairo_t *cr, int maxwidth, int maxheight,
- PangoFontDescription *font, double w_scale_factor)
-{
- int decimals,i;
- double totalweight, systemweight, weightsystemcounter;
- const char *unit_weight, *desc;
- char buffer[80];
- PangoLayout *layout;
- PangoRectangle ink_extents, logical_extents;
-
- cairo_save(cr);
-
- layout = pango_cairo_create_layout(cr);
- pango_layout_set_height(layout,maxheight);
- pango_layout_set_width(layout, maxwidth);
- pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
- set_font(layout, font, FONT_SMALL*(1.5/w_scale_factor), PANGO_ALIGN_CENTER);
-
- /* Header for the weight system */
- cairo_move_to(cr, 0, 0);
- snprintf (buffer, sizeof(buffer),_("Weight System"));
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
-
- /* Detail of the weight */
- pango_layout_get_extents(layout, &ink_extents, &logical_extents);
- cairo_translate (cr, 0, logical_extents.height / (double) PANGO_SCALE);
- set_font(layout, font, FONT_SMALL*(1.5/w_scale_factor), PANGO_ALIGN_LEFT);
- weightsystemcounter = 0;
- for (i=0; i< MAX_WEIGHTSYSTEMS; i++){
- systemweight = get_weight_units(dive->weightsystem[i].weight.grams, &decimals, &unit_weight);
- if (systemweight != 0){
- cairo_move_to(cr, 0, 0);
- desc = dive->weightsystem[i].description ? : _("unknown");
- snprintf(buffer, sizeof(buffer), _("%s"), desc);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- cairo_move_to(cr,(2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), _("%.*f %s"),
- decimals,
- systemweight,
- unit_weight);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- weightsystemcounter++;
- pango_layout_get_extents(layout, &ink_extents, &logical_extents);
- cairo_translate (cr, 0, logical_extents.height / (double) PANGO_SCALE);
- }
- }
- /* Total weight of the system */
- totalweight = get_weight_units(total_weight(dive), &decimals, &unit_weight);
- cairo_move_to (cr, 0, 0);
- snprintf(buffer, sizeof(buffer), _("Total Weight:"));
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- cairo_move_to(cr,(2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), _("%.*f %s\n"),
- decimals,
- totalweight,
- unit_weight);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- g_object_unref (layout);
-
- cairo_restore(cr);
-}
-
-/* Print the dive OTUs */
-static void print_otus (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth)
-{
- char buffer[128];
-
- cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), _("OTU"));
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- cairo_move_to (cr, (2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), "%d", dive->otu);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
-}
-
-/* Print the dive maxCNS */
-static void print_cns (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth)
-{
- char buffer[128];
-
-
- cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), _("Max. CNS"));
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- cairo_move_to (cr, (2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), "%d", dive->maxcns);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
-}
-
-/* Print the SAC */
-static void print_SAC (struct dive *dive, cairo_t *cr, PangoLayout *layout, int maxwidth)
-{
- double sac;
- int decimals;
- const char *unit;
- char buffer[128];
-
- cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
- snprintf(buffer, sizeof(buffer), _("SAC"));
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- cairo_move_to (cr, maxwidth / (3 * (double) PANGO_SCALE), 0);
- /* Need to change the width, and align because of the size of units string */
- pango_layout_set_width(layout, 3*maxwidth/4);
- pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
- sac = get_volume_units(dive->sac, &decimals, &unit);
- snprintf(buffer, sizeof(buffer), "%.*f %s/min",
- decimals,
- sac,
- unit);
- pango_layout_set_text(layout, buffer, -1);
- pango_cairo_show_layout(cr, layout);
- pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
-}
-
-/*
- * Show the tanks used in the dive, the mix, and the gas consumed
- * as pressures are shown in the plot. And other data if we used
- * less than four cilynders.
- */
-static void show_dive_tanks(struct dive *dive, cairo_t *cr, double w,
- double h, PangoFontDescription *font, double w_scale_factor)
-{
- int maxwidth, maxheight, tank_count;
- double line_height, line_width;
- PangoLayout *layout;
-
- maxwidth = w * PANGO_SCALE;
- maxheight = h * PANGO_SCALE * 0.9;
-
- /* We need to know how many cylinders we used*/
- for (tank_count = 0; tank_count < MAX_CYLINDERS; tank_count++){
- if (cylinder_nodata(dive->cylinder+tank_count)) {
- break;
- }
- }
-
- /*Create a frame to separate tank area, note the scaling*/
- cairo_set_line_width(cr, 0.01);
- cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
- cairo_rectangle(cr, 0, 0, 2*w, h);
- cairo_move_to(cr, w, 0);
- cairo_line_to(cr, w, h);
- cairo_stroke(cr);
-
- layout = pango_cairo_create_layout(cr);
- pango_layout_set_height(layout,maxheight);
- pango_layout_set_width(layout, maxwidth/3);
- pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
- set_font(layout, font, (FONT_SMALL*(1.5/w_scale_factor)), PANGO_ALIGN_CENTER);
- print_tanks (dive, cr, layout, maxwidth, maxheight, tank_count, 0, font, w_scale_factor);
-
- /* If there are more than 4 tanks use the full width, else print other data*/
- if (tank_count > 4){
- cairo_save(cr);
- cairo_translate (cr, w, 0);
- layout = pango_cairo_create_layout(cr);
- pango_layout_set_height(layout,maxheight);
- pango_layout_set_width(layout, maxwidth/3);
- pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
- set_font(layout, font, (FONT_SMALL*(1.5/w_scale_factor)), PANGO_ALIGN_CENTER);
- print_tanks (dive, cr, layout, maxwidth, maxheight, tank_count, 4, font, w_scale_factor);
- cairo_restore(cr);
- } else {
- /* Plot a grid for the data */
- line_height = h / 4;
- line_width = w / 2;
- cairo_move_to(cr, 3 * line_width, 0);
- cairo_line_to (cr, 3 * line_width, h);
- cairo_move_to (cr, w, line_height);
- cairo_line_to (cr, 3 * line_width, line_height);
- cairo_move_to (cr, w, 2 * line_height);
- cairo_line_to (cr, 3 * line_width, 2 * line_height);
- cairo_move_to (cr, w, 3 * line_height);
- cairo_line_to (cr, 3 * line_width, 3 * line_height);
- cairo_stroke (cr);
- cairo_save (cr);
-
- /* and print OTUs, CNS and weight */
- cairo_translate (cr, (3.05 * line_width),0);
- print_weight_data (dive, cr, maxwidth * 0.90/2 , maxheight, font, w_scale_factor);
- cairo_restore (cr);
- cairo_save(cr);
-
- layout = pango_cairo_create_layout(cr);
- pango_layout_set_height(layout, maxheight);
- pango_layout_set_width(layout, maxwidth);
- pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
- set_font(layout, font, FONT_SMALL*(1.5/w_scale_factor), PANGO_ALIGN_LEFT);
-
- cairo_translate (cr, w, line_height/4);
- print_SAC (dive, cr, layout, maxwidth * 0.90/2);
- cairo_translate (cr, 0, line_height);
- print_cns (dive, cr, layout, maxwidth * 0.90/2);
- cairo_translate (cr,0, line_height);
- print_otus (dive, cr, layout, maxwidth * 0.90/2);
- cairo_restore (cr);
- }
- g_object_unref (layout);
-}
-
-static void show_table_header(cairo_t *cr, PangoLayout *layout, double w, gboolean paginate)
-{
- int i;
- double maxwidth, colwidth, curwidth;
- char headers[7][80]= { N_("Dive#"), N_("Date"), N_("Depth"), N_("Duration"), N_("Master"),
- N_("Buddy"), N_("Location") };
-
- maxwidth = w * PANGO_SCALE;
- colwidth = maxwidth / 7;
-
- cairo_move_to(cr, 0, 0);
-
- curwidth = 0;
- for (i = 0; i < 7; i++) {
- cairo_move_to(cr, curwidth / PANGO_SCALE, 0);
- pango_layout_set_width(layout, colwidth * rel_width[i]);
- curwidth = curwidth + (colwidth * rel_width[i]);
- pango_layout_set_text(layout, _(headers[i]), -1);
- pango_layout_set_justify(layout, 0);
- if (!paginate)
- pango_cairo_show_layout(cr, layout);
- }
- cairo_move_to(cr, 0, 0);
-}
-
-static int show_table_cell(int i, cairo_t *cr, PangoLayout *layout, double colwidth, int height_count,
- char *buffer, int len, double *curwidth, double y, gboolean paginate)
-{
- PangoRectangle logic_ext;
- double inner_colwidth = 0.95 * colwidth;
- cairo_move_to(cr, *curwidth / PANGO_SCALE, y);
- pango_layout_set_width(layout, inner_colwidth * rel_width[i]);
- pango_layout_set_text(layout, buffer, len);
- pango_layout_set_justify(layout, 0);
- if (!paginate)
- pango_cairo_show_layout(cr, layout);
- *curwidth += colwidth * rel_width[i];
- pango_layout_get_extents(layout, NULL, &logic_ext);
- if (logic_ext.height > height_count)
- height_count = logic_ext.height;
- return height_count;
-}
-
-static int show_dive_table(struct dive *dive, cairo_t *cr, PangoLayout *layout, double w, double dy, gboolean paginate)
-{
- double depth;
- const char *unit;
- int len, decimals;
- double maxwidth = w * PANGO_SCALE;
- double colwidth = maxwidth / 7;
- double curwidth = 0;
- int height_count = 0;
- struct tm tm;
- char buffer[300];
-
- cairo_move_to(cr, 0, dy);
-
- // Col 1: Dive # (1/3 of the regular width)
- *buffer = 0;
- len = 0;
- if (dive->number)
- len = snprintf(buffer, sizeof(buffer), "#%d", dive->number);
- height_count = show_table_cell(0, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy, paginate);
-
- // Col 2: Date # (1 + 1/6 of the regular width)
- utc_mkdate(dive->when, &tm);
- len = snprintf(buffer, sizeof(buffer),
- /*++GETTEXT 160 chars: weekday, monthname, day, year, hour, min */
- _("%1$s, %2$s %3$d, %4$d %5$dh%6$02d"),
- weekday(tm.tm_wday),
- monthname(tm.tm_mon),
- tm.tm_mday, tm.tm_year + 1900,
- tm.tm_hour, tm.tm_min
- );
- height_count = show_table_cell(1, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy, paginate);
-
- // Col 3: Depth (1/2 width)
- depth = get_depth_units(dive->maxdepth.mm, &decimals, &unit);
- len = snprintf(buffer, sizeof(buffer),
- "%.*f %s", decimals, depth, unit);
- height_count = show_table_cell(2, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy, paginate);
-
- // Col 4: Duration (1/2 width)
- len = snprintf(buffer, sizeof(buffer),
- _("%d min"),(dive->duration.seconds + 59) / 60);
- height_count = show_table_cell(3, cr, layout, colwidth, height_count, buffer, len, &curwidth, dy, paginate);
-
- // Col 5: Master
- height_count = show_table_cell(4, cr, layout, colwidth, height_count, dive->divemaster ? : "", -1, &curwidth, dy, paginate);
-
- // Col 6: Buddy
- height_count = show_table_cell(5, cr, layout, colwidth, height_count, dive->buddy ? : "", -1, &curwidth, dy, paginate);
-
- // Col 7: Location
- height_count = show_table_cell(6, cr, layout, colwidth, height_count, dive->location ? : "", -1, &curwidth, dy, paginate);
-
- /* Return the biggest column height, will be used to plot the frame and
- * and translate the next row */
- return (height_count);
-}
-
-static void show_dive_profile(struct dive *dive, cairo_t *cr, double w,
- double h)
-{
- int color = print_options.color_selected == 1 ? 2 : 1; /* 1 for B/W, 2 for color */
- struct graphics_context gc = {
- .printer = color,
- .cr = cr,
- .drawing_area = { w/20.0, h/20.0, w, h},
- };
- cairo_save(cr);
- plot(&gc, dive, SC_PRINT);
- cairo_restore(cr);
-}
-
-#define NOTES_BLOCK() \
-{\
- show_dive_header(dive, cr, w*2, dive_header_height, font, w_scale_factor);\
- cairo_translate(cr, 0, dive_header_height); \
- show_dive_tanks (dive, cr, w*1, dive_tanks_height, font, w_scale_factor);\
- cairo_translate(cr, 0, dive_tanks_height);\
- show_dive_notes(dive, cr, w*2, dive_notes_height, font, w_scale_factor);\
- cairo_translate(cr, 0, dive_notes_height);\
-}
-
-#define PROFILE_BLOCK() \
-{\
- show_dive_profile(dive, cr, w*2, dive_profile_height);\
- cairo_translate(cr, 0, dive_profile_height);\
-}
-
-static void print(int divenr, cairo_t *cr, double x, double y, double w,
- double h, PangoFontDescription *font, double w_scale_factor)
-{
- struct dive *dive;
-
- dive = get_dive_for_printing(divenr);
- if (!dive)
- return;
- cairo_save(cr);
-
- /*Create a frame for each print x,y are provided in draw_page()*/
- cairo_rectangle(cr, x, y, w, h);
- cairo_set_line_width(cr, 0.01);
- cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
- cairo_stroke(cr);
- cairo_translate(cr, x, y);
-
- /* Plus 5% on all sides */
- cairo_translate(cr, w/20, h/20);
- w *= 0.9; h *= 0.9;
-
- /* We actually want to scale the text and the lines now */
- cairo_scale(cr, 0.5, 0.5);
-
- /* 7.5% for the header, 92.5% for the rest */
- double dive_header_height = h * 0.15;
- double dive_tanks_height = h * ((double) print_options.tanks_height / 108.1 * 2);
- double dive_notes_height = h * ((double) print_options.notes_height / 108.1 * 2);
- double dive_profile_height = h * ((double) print_options.profile_height / 108.1 * 2);
-
- if (!print_options.notes_up)
- PROFILE_BLOCK()
- NOTES_BLOCK()
- if (print_options.notes_up)
- PROFILE_BLOCK()
-
- cairo_restore(cr);
-}
-
-/* Plot a grid por each dive */
-static void print_table_frame(cairo_t *cr, double x, double y, double w, double h)
-{
- double curwidth, maxwidth;
- int i;
-
- maxwidth = w*2;
- curwidth = x;
- cairo_rectangle(cr, x, y, maxwidth*0.90, h);
- cairo_set_line_width(cr, 0.01);
- cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
- cairo_stroke(cr);
- for (i = 0; i < 6; i++) {
- curwidth += maxwidth / 7 * rel_width[i];
- cairo_move_to(cr, curwidth, y);
- cairo_line_to(cr, curwidth, y + h);
- cairo_set_line_width (cr, 0.01);
- cairo_stroke(cr);
- }
-}
-
-/* Positioning factor for height 0,0,1,1,2 ... */
-static int pos_h_factor (int z)
-{
- int factor = z/2;
- return (factor);
-}
-
-/* Positioning factor for width 0,1,0,1 ... */
-static int pos_w_factor (int z)
-{
- int factor;
- if (z == 0 || z==2 || z==4){
- factor = 0;
- } else {
- factor = 1;
- }
- return (factor);
-}
-
-static void cutting_line (cairo_t *cr, double x, double y, double w, double h)
-{
- const double dashes[] = {0.05, 0.10};
-
- cairo_save (cr);
- cairo_translate (cr, x, y);
- cairo_set_line_width (cr,0.01);
- cairo_set_dash (cr, dashes,1,0);
- cairo_move_to (cr, w*1.05,0);
- cairo_line_to (cr, w*1.05, h*1.05);
- cairo_move_to (cr, 0, h*1.05);
- cairo_line_to (cr, w*1.05, h*1.05);
- cairo_stroke (cr);
- cairo_set_dash(cr,0,0,0);
- cairo_restore (cr);
-}
-
-static void draw_page(GtkPrintOperation *operation,
- GtkPrintContext *context,
- gint page_nr,
- Print_params *print_params)
-{
- int nr, i, dives_per_print;
- cairo_t *cr;
- double w, h;
- PangoFontDescription *font;
-
- cr = gtk_print_context_get_cairo_context(context);
- font = pango_font_description_from_string("Sans");
- /* scale the width and height by defined factors */
- w = gtk_print_context_get_width(context)/print_params->w_scale;
- h = gtk_print_context_get_height(context)/print_params->h_scale;
- /* set the nº of dives to show */
- dives_per_print = print_params->dives;
- nr = page_nr * dives_per_print;
- /* choose if rotate the layouts 90º in rad */
- if (print_params->rotation == 1){
- cairo_translate (cr, 0, h*print_params->h_scale);
- cairo_rotate (cr, -1.57);
- }
-
- /*
- * Calls print () as many times as defined.
- * In two prints option leaves room between prints and plot
- * a dashed line for cutting.
- */
- for (i = 0; i < dives_per_print; i++)
- {
- double pos_w = pos_w_factor(i);
- double pos_h = pos_h_factor(i);
-
- if (i == 1 && dives_per_print == 2)
- pos_w = 1.1;
- if (dives_per_print == 2)
- cutting_line (cr, w*pos_w, h*pos_h, w, h);
- print(nr+i, cr, w*pos_w, h*pos_h, w, h, font, print_params->w_scale);
- }
- pango_font_description_free(font);
-}
-
-static void draw_table(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data)
-{
- int i, nr, maxwidth, maxheight;
- cairo_t *cr;
- double w, h, max_ext, delta_y, y;
- struct dive *dive;
- PangoFontDescription *font;
- PangoLayout *layout;
- PangoRectangle logic_ext;
- gboolean paginate = TRUE;
-
- if (user_data) {
- paginate = FALSE;
- } else {
- first_dive = realloc(first_dive, (page_nr + 1) * sizeof(int));
- first_dive[page_nr] = last_dive_paginated + 1;
- }
- nr = first_dive[page_nr];
- cr = gtk_print_context_get_cairo_context(context);
- font = pango_font_description_from_string("Sans");
- cairo_save(cr);
-
- w = gtk_print_context_get_width(context);
- h = gtk_print_context_get_height(context);
- maxwidth = w * PANGO_SCALE;
- /* let's limit the height so we can fit at least 35 dives */
- maxheight = h * PANGO_SCALE * 0.9 / 35;
-
- layout = pango_cairo_create_layout(cr);
- pango_layout_set_height(layout, maxheight);
- pango_layout_set_width (layout, maxwidth);
- pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
- set_font(layout, font, FONT_LARGE*1.2, PANGO_ALIGN_LEFT);
-
- /* We actually want to scale the text and the lines now */
- cairo_scale(cr, 0.5, 0.5);
-
- pango_layout_get_extents(layout, NULL, &logic_ext);
- cairo_translate (cr, w/10, 2.0 * logic_ext.height / PANGO_SCALE);
- y = 2.0 * logic_ext.height / PANGO_SCALE;
- show_table_header(cr, layout, w*2, paginate);
- set_font(layout, font, FONT_NORMAL*1.2, PANGO_ALIGN_LEFT);
- /* We wanted the header ellipsized but not the data */
- pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
-
- /* Get the height for an only line but move two down */
- pango_layout_get_extents(layout, NULL, &logic_ext);
- delta_y = logic_ext.height;
- cairo_translate (cr, 0, 3.0 * delta_y / PANGO_SCALE);
- y += 3.0 * delta_y / PANGO_SCALE;
- for (i = 0; i < dive_table.nr - nr; i++) {
- dive = get_dive_for_printing(nr+i);
- if (!dive)
- continue;
- /* Write the dive data and get the max. height of the row */
- max_ext = show_dive_table(dive, cr, layout, w*2, delta_y / 4 / PANGO_SCALE, paginate);
- /* Draw a frame for each row */
- if (user_data)
- print_table_frame (cr, -0.05, 0, w, (max_ext + delta_y / 2) / PANGO_SCALE);
- /* and move down by the max. height of it */
- cairo_translate (cr, 0, (max_ext + delta_y / 2) / PANGO_SCALE);
- y += (max_ext + delta_y / 2) / PANGO_SCALE;
- if (y > 1.95 * h)
- break;
- }
- if (paginate)
- last_dive_paginated += i + 1;
- cairo_restore (cr);
- pango_font_description_free(font);
- g_object_unref (layout);
-}
-
-static int nr_selected_dives(void)
-{
- int i, dives;
- struct dive *dive;
-
- dives = 0;
- for_each_dive(i, dive)
- dives += dive->selected;
- return dives;
-}
-
-static void begin_print(GtkPrintOperation *operation, gpointer user_data)
-{
- int pages, dives;
- int dives_per_page;
-
- dives = nr_selected_dives();
- if (!print_options.print_selected)
- dives = dive_table.nr;
-
- if (print_options.type == PRETTY) {
- dives_per_page = 6;
- } else if (print_options.type == TWOPERPAGE) {
- dives_per_page = 2;
- } else {
- /* set it to one page - gets update during pagination */
- dives_per_page = dives;
- }
- pages = (dives + dives_per_page - 1) / dives_per_page;
- gtk_print_operation_set_n_pages(operation, pages);
-}
-
-#define OPTIONCALLBACK(name, type, value) \
-static void name(GtkWidget *w, gpointer data) \
-{\
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) \
- print_options.type = value; \
-}
-
-OPTIONCALLBACK(set_pretty, type, PRETTY)
-OPTIONCALLBACK(set_table, type, TABLE)
-OPTIONCALLBACK(set_twoperpage, type, TWOPERPAGE)
-OPTIONCALLBACK(set_notes_up, notes_up, TRUE)
-OPTIONCALLBACK(set_profile_up, notes_up, FALSE)
-
-#define OPTIONSELECTEDCALLBACK(name, option) \
-static void name(GtkWidget *w, gpointer data) \
-{ \
- option = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); \
-}
-
-OPTIONSELECTEDCALLBACK(print_selection_toggle, print_options.print_selected)
-OPTIONSELECTEDCALLBACK(color_selection_toggle, print_options.color_selected)
-
-/*
- * Hardcoded minimum and maximum values for the scaling spin_buttons
- */
-#define profile_height_min (40)
-#define tanks_height_min (8)
-#define notes_height_min (0)
-#define profile_height_max (83)
-#define tanks_height_max (17)
-#define notes_height_max (52)
-
-/*
- * Callback function that sets the values of the heigths for profile
- * and tanks. If changed recalculates height for notes.
- */
-#define SCALECALLBACK(name, scale1, scale2)\
-static void name(GtkWidget *hscale, gpointer *data)\
-{ \
- print_options.scale1 = gtk_range_get_value(GTK_RANGE(hscale)); \
- print_options.notes_height = 100 - print_options.scale1 - print_options.scale2; \
- gtk_range_set_value (GTK_RANGE(data), print_options.notes_height); \
-}
-
-SCALECALLBACK (prof_hscale, profile_height, tanks_height)
-SCALECALLBACK (tanks_hscale, tanks_height, profile_height)
-
-
-GtkWidget *create_label(const char *fmt, ...)
-{
- char buf[256];
- va_list args;
-
- va_start(args, fmt);
- vsnprintf(buf, sizeof(buf), fmt, args);
- va_end(args);
- return gtk_label_new(buf);
-}
-
-static GtkWidget *print_dialog(GtkPrintOperation *operation, gpointer user_data)
-{
- GtkWidget *vbox, *radio1, *radio2, *radio3, *radio4, *radio5,
- *frame, *frame1, *frame2,
- *box, *box1, *box2, *box3, *box4,
- *button, *colorButton, *label1, *label2, *label3,
- *scale_prof_hscale, *scale_tanks_hscale, *scale_notes_hscale, *scrolled_window;
- int dives;
- gtk_print_operation_set_custom_tab_label(operation, _("Print type"));
-
- scrolled_window = gtk_scrolled_window_new(0, 0);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- vbox = gtk_vbox_new(FALSE, 5);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), vbox);
-
- frame = gtk_frame_new(_("Print type"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
-
- box = gtk_hbox_new(FALSE, 2);
- gtk_container_add(GTK_CONTAINER(frame), box);
-
- radio1 = gtk_radio_button_new_with_label (NULL, _("6 dives per page"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio1),
- print_options.type == PRETTY);
- radio2 = gtk_radio_button_new_with_label_from_widget (
- GTK_RADIO_BUTTON (radio1), _("2 dives per page"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2),
- print_options.type == TWOPERPAGE);
- radio3 = gtk_radio_button_new_with_label_from_widget (
- GTK_RADIO_BUTTON (radio1), _("Table print"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio3),
- print_options.type == TABLE);
- gtk_box_pack_start (GTK_BOX (box), radio1, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (box), radio2, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (box), radio3, TRUE, TRUE, 0);
-
- g_signal_connect(radio1, "toggled", G_CALLBACK(set_pretty), NULL);
- g_signal_connect(radio2, "toggled", G_CALLBACK(set_twoperpage), NULL);
- g_signal_connect(radio3, "toggled", G_CALLBACK(set_table), NULL);
-
- dives = nr_selected_dives();
- print_options.print_selected = dives >= 1;
- if (print_options.print_selected) {
- frame = gtk_frame_new(_("Print selection"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
- box = gtk_hbox_new(FALSE, 1);
- gtk_container_add(GTK_CONTAINER(frame), box);
- button = gtk_check_button_new_with_label(_("Print only selected dives"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
- print_options.print_selected);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 2);
- g_signal_connect(G_OBJECT(button), "toggled",
- G_CALLBACK(print_selection_toggle), NULL);
- }
- frame = gtk_frame_new(_("Layout Options"));
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
- box = gtk_vbox_new(FALSE, 5);
- gtk_container_add(GTK_CONTAINER(frame), box);
- colorButton = gtk_check_button_new_with_label(_("Print in color"));
- g_signal_connect(G_OBJECT(colorButton), "toggled",
- G_CALLBACK(color_selection_toggle), NULL);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(colorButton),print_options.color_selected);
- gtk_box_pack_start(GTK_BOX(box), colorButton, FALSE, FALSE, 2);
-
- frame1 = gtk_frame_new(_("Ordering"));
- gtk_box_pack_start(GTK_BOX(box), frame1, FALSE, FALSE, 5);
- box1 = gtk_vbox_new (TRUE, 1);
- gtk_container_add(GTK_CONTAINER(frame1), box1);
-
- radio4 = gtk_radio_button_new_with_label (NULL, _("Profile on top"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio4), print_options.notes_up);
-
- radio5 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio4), _("Notes on top"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio5), print_options.notes_up);
-
- g_signal_connect(G_OBJECT(radio4), "toggled", G_CALLBACK(set_profile_up), NULL);
- g_signal_connect(G_OBJECT(radio5), "toggled", G_CALLBACK(set_notes_up), NULL);
-
- gtk_box_pack_start(GTK_BOX(box1), radio4, TRUE, FALSE, 2);
- gtk_box_pack_start(GTK_BOX(box1), radio5, TRUE, FALSE, 2);
-
- frame2 = gtk_frame_new(_("Sizing heights (%% of layout)"));
- gtk_box_pack_start(GTK_BOX(box), frame2, FALSE, FALSE, 5);
-
- box2 = gtk_hbox_new (TRUE, 1);
- gtk_container_add (GTK_CONTAINER(frame2), box2);
-
- box3 = gtk_vbox_new (FALSE, 5);
- gtk_box_pack_start(GTK_BOX(box2), box3, FALSE, FALSE, 5);
- box4 = gtk_vbox_new (FALSE, 5);
- gtk_box_pack_start(GTK_BOX(box2), box4, TRUE, TRUE, 5);
-
- label1 = create_label(_("Profile height (%d%% - %d%%)"), profile_height_min, profile_height_max);
- label2 = create_label(_("Other data height (%d%% - %d%%)"), tanks_height_min, tanks_height_max);
- label3 = create_label(_("Notes height (%d%% - %d%%)"), notes_height_min, notes_height_max);
- gtk_box_pack_start (GTK_BOX(box3), label1, TRUE, TRUE, 10);
- gtk_box_pack_start (GTK_BOX(box3), label2, TRUE, TRUE, 10);
- gtk_box_pack_start (GTK_BOX(box3), label3, TRUE, TRUE, 10);
-
- scale_prof_hscale = gtk_hscale_new_with_range (profile_height_min, profile_height_max, 1);
- gtk_range_set_value (GTK_RANGE(scale_prof_hscale), print_options.profile_height);
- gtk_range_set_increments (GTK_RANGE(scale_prof_hscale),1,5);
- gtk_scale_set_value_pos (GTK_SCALE(scale_prof_hscale), GTK_POS_LEFT);
-
- scale_tanks_hscale = gtk_hscale_new_with_range (tanks_height_min, tanks_height_max, 1);
- gtk_range_set_value (GTK_RANGE(scale_tanks_hscale), print_options.tanks_height);
- gtk_range_set_increments (GTK_RANGE(scale_tanks_hscale),1,1);
- gtk_scale_set_value_pos (GTK_SCALE(scale_tanks_hscale), GTK_POS_LEFT);
-
- /* this third scale just shows how much is left for the notes;
- * it can't be directly changed by the user */
- scale_notes_hscale = gtk_hscale_new_with_range (notes_height_min, notes_height_max, 1);
- gtk_range_set_value (GTK_RANGE(scale_notes_hscale), print_options.notes_height);
- gtk_range_set_increments (GTK_RANGE(scale_notes_hscale),1,1);
- gtk_scale_set_value_pos (GTK_SCALE(scale_notes_hscale), GTK_POS_LEFT);
- gtk_widget_set_sensitive(GTK_WIDGET(scale_notes_hscale), FALSE);
-
- g_signal_connect(G_OBJECT(scale_prof_hscale),"value-changed",G_CALLBACK(prof_hscale), scale_notes_hscale);
- g_signal_connect(G_OBJECT(scale_tanks_hscale),"value-changed",G_CALLBACK(tanks_hscale), scale_notes_hscale);
-
- gtk_box_pack_start (GTK_BOX(box4), scale_prof_hscale, TRUE, TRUE, 5);
- gtk_box_pack_start (GTK_BOX(box4), scale_tanks_hscale, TRUE, TRUE, 5);
- gtk_box_pack_start (GTK_BOX(box4), scale_notes_hscale, TRUE, TRUE, 5);
-
- gtk_widget_show_all(vbox);
- return scrolled_window;
-}
-
-static gboolean paginate(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
-{
- draw_table(operation, context, last_page_paginated++, NULL);
- if (last_dive_paginated >= dive_table.nr) {
- return TRUE;
- } else {
- gtk_print_operation_set_n_pages(operation, last_page_paginated + 1);
- return FALSE;
- }
-}
-static void end_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
-{
- if (first_dive) {
- free(first_dive);
- first_dive = 0;
- }
-}
-
-static void print_dialog_apply(GtkPrintOperation *operation, GtkWidget *widget, gpointer user_data)
-{
- Print_params *print_params = g_slice_new(Print_params);
-
- if (print_options.type == PRETTY) {
- print_params->dives = 6;
- print_params->h_scale = 3;
- print_params->w_scale = 2;
- print_params->rotation = 0;
- g_signal_connect(operation, "draw_page", G_CALLBACK(draw_page), print_params);
- } else {
- if (print_options.type == TWOPERPAGE) {
- print_params->dives = 2;
- print_params->h_scale = 1.6;
- print_params->w_scale = 1.8;
- print_params->rotation = 1;
- g_signal_connect(operation, "draw_page", G_CALLBACK(draw_page), print_params);
- } else {
- g_signal_connect(operation, "draw_page", G_CALLBACK(draw_table), print_params);
- g_signal_connect(operation, "paginate", G_CALLBACK(paginate), NULL);
- g_signal_connect(operation, "end_print", G_CALLBACK(end_print), NULL);
- last_page_paginated = 0;
- last_dive_paginated = -1;
- }
- }
-}
-
-static GtkPrintSettings *settings = NULL;
-
-void do_print(void)
-{
- GtkPrintOperation *print;
- GtkPrintOperationResult res;
-
- repaint_dive();
- print = gtk_print_operation_new();
- gtk_print_operation_set_unit(print, GTK_UNIT_INCH);
- if (settings != NULL)
- gtk_print_operation_set_print_settings(print, settings);
- g_signal_connect(print, "create-custom-widget", G_CALLBACK(print_dialog), NULL);
- g_signal_connect(print, "custom-widget-apply", G_CALLBACK(print_dialog_apply), NULL);
- g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
- res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
- GTK_WINDOW(main_window), NULL);
- if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
- if (settings != NULL)
- g_object_unref(settings);
- settings = g_object_ref(gtk_print_operation_get_print_settings(print));
- }
- g_object_unref(print);
-}
diff --git a/subsurfacestartup.c b/subsurfacestartup.c
index a65c5c800..dd0f80899 100644
--- a/subsurfacestartup.c
+++ b/subsurfacestartup.c
@@ -26,9 +26,6 @@ struct preferences default_prefs = {
.font_size = 14.0,
.show_invalid = FALSE,
.show_time = FALSE,
-#ifdef USE_GTK_UI
- .map_provider = OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID,
-#endif
};
struct units *get_units()
diff --git a/uemis-downloader.c b/uemis-downloader.c
index 554da290c..9f1dfb354 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -25,9 +25,6 @@
#include "dive.h"
#include "divelist.h"
#include "display.h"
-#if USE_GTK_UI
-#include "display-gtk.h"
-#endif
#define ERR_FS_ALMOST_FULL QT_TR_NOOP("Uemis Zurich: File System is almost full\nDisconnect/reconnect the dive computer\nand click \'Retry\'")
#define ERR_FS_FULL QT_TR_NOOP("Uemis Zurich: File System is full\nDisconnect/reconnect the dive computer\nand try again")
#define ERR_FS_SHORT_WRITE QT_TR_NOOP("Short write to req.txt file\nIs the Uemis Zurich plugged in correctly?")
@@ -52,35 +49,8 @@ static int number_of_files;
static char *mbuf = NULL;
static int mbuf_size = 0;
-#if USE_GTK_UI
-struct argument_block {
- const char *mountpath;
- progressbar_t *progress;
- bool force_download;
-};
-#endif
-
static int nr_divespots = 0;
-#if USE_GTK_UI
-static int import_thread_done = 0, import_thread_cancelled;
-static const char *progress_bar_text = "";
-static double progress_bar_fraction = 0.0;
-
-static GError *error(const char *fmt, ...)
-{
- va_list args;
- GError *error;
-
- va_start(args, fmt);
- error = g_error_new_valist(
- g_quark_from_string("subsurface"),
- DIVE_ERROR_PARSE, fmt, args);
- va_end(args);
- return error;
-}
-#endif
-
/* helper function to parse the Uemis data structures */
static void uemis_ts(char *buffer, void *_when)
{
@@ -905,63 +875,3 @@ bail:
return result;
}
-#if USE_GTK_UI
-static void *pthread_wrapper(void *_data)
-{
- struct argument_block *args = _data;
- const char *err_string = do_uemis_download(args);
- import_thread_done = 1;
- return (void *)err_string;
-}
-
-/* this simply ends the dialog without a response and asks not to be fired again
- * as we set this function up in every loop while uemis_download is waiting for
- * the download to finish */
-static bool timeout_func(gpointer _data)
-{
- GtkDialog *dialog = _data;
- if (!import_thread_cancelled)
- gtk_dialog_response(dialog, GTK_RESPONSE_NONE);
- return FALSE;
-}
-
-GError *uemis_download(const char *mountpath, progressbar_t *progress,
- GtkDialog *dialog, bool force_download)
-{
- pthread_t pthread;
- void *retval;
- struct argument_block args = {mountpath, progress, force_download};
-
- /* I'm sure there is some better interface for waiting on a thread in a UI main loop */
- import_thread_done = 0;
- progress_bar_text = "";
- progress_bar_fraction = 0.0;
- pthread_create(&pthread, NULL, pthread_wrapper, &args);
- /* loop here until the import is done or was cancelled by the user;
- * in order to get control back from gtk we register a timeout function
- * that ends the dialog with no response every 100ms; we then update the
- * progressbar and setup the timeout again - unless of course the user
- * pressed cancel, in which case we just wait for the download thread
- * to react to that and exit */
- while (!import_thread_done) {
- if (!import_thread_cancelled) {
- int result;
- g_timeout_add(100, timeout_func, dialog);
- update_progressbar(args.progress, progress_bar_fraction);
- update_progressbar_text(args.progress, progress_bar_text);
- result = gtk_dialog_run(dialog);
- if (result == GTK_RESPONSE_CANCEL)
- import_thread_cancelled = TRUE;
- } else {
- update_progressbar(args.progress, progress_bar_fraction);
- update_progressbar_text(args.progress, tr("Cancelled, exiting cleanly..."));
- usleep(100000);
- }
- }
- if (pthread_join(pthread, &retval) < 0)
- return error("Pthread return with error");
- if (retval)
- return error(retval);
- return NULL;
-}
-#endif
diff --git a/webservice.c b/webservice.c
deleted file mode 100644
index e713e1282..000000000
--- a/webservice.c
+++ /dev/null
@@ -1,409 +0,0 @@
-#include <glib/gi18n.h>
-#include <libsoup/soup.h>
-#include <libxml/tree.h>
-#include <libxml/parser.h>
-#include "dive.h"
-#include "divelist.h"
-#include "display-gtk.h"
-#include "file.h"
-
-struct dive_table gps_location_table;
-static gboolean merge_locations_into_dives(void);
-
-enum {
- DD_STATUS_OK,
- DD_STATUS_ERROR_CONNECT,
- DD_STATUS_ERROR_ID,
- DD_STATUS_ERROR_PARSE,
-};
-
-static const gchar *download_dialog_status_text(const gint status)
-{
- switch (status) {
- case DD_STATUS_ERROR_CONNECT:
- return _("Connection Error: ");
- case DD_STATUS_ERROR_ID:
- return _("Invalid user identifier!");
- case DD_STATUS_ERROR_PARSE:
- return _("Cannot parse response!");
- }
- return _("Download Success!");
-}
-
-/* provides a state of the download dialog contents and the downloaded xml */
-struct download_dialog_state {
- GtkWidget *uid;
- GtkWidget *status;
- GtkWidget *apply;
- gchar *xmldata;
- guint xmldata_len;
-};
-
-/* this method uses libsoup as a backend. if there are some portability,
- * compatibility or speed issues, libcurl is a better choice. */
-gboolean webservice_request_user_xml(const gchar *user_id,
- gchar **data,
- guint *len,
- guint *status_code)
-{
- SoupMessage *msg;
- SoupSession *session;
- gboolean ret = FALSE;
- gchar url[256] = {0};
-
- session = soup_session_async_new();
- strcat(url, "http://api.hohndel.org/api/dive/get/?login=");
- strncat(url, user_id, sizeof(url) - strlen(url) - 1);
- msg = soup_message_new("GET", url);
- soup_message_headers_append(msg->request_headers, "Accept", "text/xml");
- soup_session_send_message(session, msg);
- if SOUP_STATUS_IS_SUCCESSFUL(msg->status_code) {
- *len = (guint)msg->response_body->length;
- *data = strdup((gchar *)msg->response_body->data);
- ret = TRUE;
- } else {
- *len = 0;
- *data = NULL;
- }
- *status_code = msg->status_code;
- soup_session_abort(session);
- g_object_unref(G_OBJECT(msg));
- g_object_unref(G_OBJECT(session));
- return ret;
-}
-
-/* requires that there is a <download> or <error> tag under the <root> tag */
-static void download_dialog_traverse_xml(xmlNodePtr node, guint *download_status)
-{
- xmlNodePtr cur_node;
- for (cur_node = node; cur_node; cur_node = cur_node->next) {
- if ((!strcmp((const char *)cur_node->name, (const char *)"download")) &&
- (!strcmp((const char *)xmlNodeGetContent(cur_node), (const char *)"ok"))) {
- *download_status = DD_STATUS_OK;
- return;
- } else if (!strcmp((const char *)cur_node->name, (const char *)"error")) {
- *download_status = DD_STATUS_ERROR_ID;
- return;
- }
- }
-}
-
-static guint download_dialog_parse_response(gchar *xmldata, guint len)
-{
- xmlNodePtr root;
- xmlDocPtr doc = xmlParseMemory(xmldata, len);
- guint status = DD_STATUS_ERROR_PARSE;
-
- if (!doc)
- return DD_STATUS_ERROR_PARSE;
- root = xmlDocGetRootElement(doc);
- if (!root) {
- status = DD_STATUS_ERROR_PARSE;
- goto end;
- }
- if (root->children)
- download_dialog_traverse_xml(root->children, &status);
- end:
- xmlFreeDoc(doc);
- return status;
-}
-
-static void download_dialog_connect_cb(GtkWidget *w, gpointer data)
-{
- struct download_dialog_state *state = (struct download_dialog_state *)data;
- const gchar *uid = gtk_entry_get_text(GTK_ENTRY(state->uid));
- guint len, status_connect, status_xml;
- gchar *xmldata;
- gboolean ret;
- gchar err[256] = {0};
-
- gtk_label_set_text(GTK_LABEL(state->status), _("Connecting..."));
- gtk_widget_set_sensitive(state->apply, FALSE);
- ret = webservice_request_user_xml(uid, &xmldata, &len, &status_connect);
- if (ret) {
- status_xml = download_dialog_parse_response(xmldata, len);
- gtk_label_set_text(GTK_LABEL(state->status), download_dialog_status_text(status_xml));
- if (status_xml != DD_STATUS_OK)
- ret = FALSE;
- } else {
- snprintf(err, sizeof(err), "%s %u!", download_dialog_status_text(DD_STATUS_ERROR_CONNECT), status_connect);
- gtk_label_set_text(GTK_LABEL(state->status), err);
- }
- state->xmldata = xmldata;
- state->xmldata_len = len;
- gtk_widget_set_sensitive(state->apply, ret);
-}
-
-static void download_dialog_release_xml(struct download_dialog_state *state)
-{
- if (state->xmldata)
- free((void *)state->xmldata);
-}
-
-static void clear_table(struct dive_table *table)
-{
- int i;
- for (i = 0; i < table->nr; i++)
- free(table->dives[i]);
- table->nr = 0;
-}
-
-static void download_dialog_response_cb(GtkDialog *d, gint response, gpointer data)
-{
- struct download_dialog_state *state = (struct download_dialog_state *)data;
- switch (response) {
- case GTK_RESPONSE_HELP:
- /* open webservice api page */
- subsurface_launch_for_uri("http://api.hohndel.org/");
- break;
- case GTK_RESPONSE_ACCEPT:
- /* apply download */
- clear_table(&gps_location_table);
- parse_xml_buffer(_("Webservice"), state->xmldata, state->xmldata_len, &gps_location_table, NULL);
- /* now merge the data in the gps_location table into the dive_table */
- if (merge_locations_into_dives()) {
- mark_divelist_changed(TRUE);
-#if USE_GTK_UI
- dive_list_update_dives();
-#endif
- }
- /* store last entered uid in config */
- subsurface_set_conf("webservice_uid", gtk_entry_get_text(GTK_ENTRY(state->uid)));
- default:
- case GTK_RESPONSE_DELETE_EVENT:
- gtk_widget_destroy(GTK_WIDGET(d));
- download_dialog_release_xml(state);
- free(state);
- }
-}
-
-static gboolean is_automatic_fix(struct dive *gpsfix)
-{
- if (gpsfix && gpsfix->location &&
- (!strcmp(gpsfix->location, "automatic fix") ||
- !strcmp(gpsfix->location, "Auto-created dive")))
- return TRUE;
- return FALSE;
-}
-
-#define SAME_GROUP 6 * 3600 // six hours
-
-/* returns TRUE if dive_table was changed */
-static gboolean merge_locations_into_dives(void)
-{
- int i, nr = 0, changed = 0;
- struct dive *gpsfix, *last_named_fix = NULL, *dive;
-
- sort_table(&gps_location_table);
-
- for_each_gps_location(i, gpsfix) {
- if (is_automatic_fix(gpsfix)) {
- dive = find_dive_including(gpsfix->when);
- if (dive && !dive_has_gps_location(dive)) {
-#if DEBUG_WEBSERVICE
- struct tm tm;
- utc_mkdate(gpsfix->when, &tm);
- printf("found dive named %s @ %04d-%02d-%02d %02d:%02d:%02d\n",
- gpsfix->location,
- tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
-#endif
- changed++;
- copy_gps_location(gpsfix, dive);
- }
- } else {
- if (last_named_fix && dive_within_time_range(last_named_fix, gpsfix->when, SAME_GROUP)) {
- nr++;
- } else {
- nr = 1;
- last_named_fix = gpsfix;
- }
- dive = find_dive_n_near(gpsfix->when, nr, SAME_GROUP);
- if (dive) {
- if (!dive_has_gps_location(dive)) {
- copy_gps_location(gpsfix, dive);
- changed++;
- }
- if (!dive->location) {
- dive->location = strdup(gpsfix->location);
- changed++;
- }
- } else {
- struct tm tm;
- utc_mkdate(gpsfix->when, &tm);
-#if DEBUG_WEBSERVICE
- printf("didn't find dive matching gps fix named %s @ %04d-%02d-%02d %02d:%02d:%02d\n",
- gpsfix->location,
- tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
-#endif
- }
- }
- }
- return changed > 0;
-}
-
-void webservice_download_dialog(void)
-{
- const guint pad = 6;
- /* user entered value should be stored in the config */
- const gchar *current_uid = subsurface_get_conf("webservice_uid");
- GtkWidget *dialog, *vbox, *status, *info, *uid;
- GtkWidget *frame_uid, *frame_status, *download, *image, *apply;
- struct download_dialog_state *state = calloc(1, sizeof(struct download_dialog_state));
- gboolean has_previous_uid = TRUE;
-
- if (!current_uid) {
- current_uid = "";
- has_previous_uid = FALSE;
- }
-
- dialog = gtk_dialog_new_with_buttons(_("Download From Web Service"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_APPLY,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
- GTK_STOCK_HELP,
- GTK_RESPONSE_HELP,
- NULL);
-
- apply = gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
- gtk_widget_set_sensitive(apply, FALSE);
-
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- info = gtk_label_new(_("Enter a user identifier and press 'Download'."
- " Once the download is complete you can press 'Apply'"
- " if you wish to apply the changes."));
- gtk_label_set_line_wrap(GTK_LABEL(info), TRUE);
- gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, TRUE, 0);
- gtk_misc_set_padding(GTK_MISC(info), pad, pad);
-
- frame_uid = gtk_frame_new(_("User Identifier"));
- gtk_box_pack_start(GTK_BOX(vbox), frame_uid, FALSE, TRUE, pad);
- uid = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(frame_uid), uid);
- gtk_entry_set_max_length(GTK_ENTRY(uid), 30);
- gtk_entry_set_text(GTK_ENTRY(uid), current_uid);
-
- download = gtk_button_new_with_label(_(" Download"));
- image = gtk_image_new_from_stock(GTK_STOCK_CONNECT, GTK_ICON_SIZE_MENU);
- gtk_button_set_image(GTK_BUTTON(download), image);
- gtk_box_pack_start(GTK_BOX(vbox), download, FALSE, TRUE, pad);
- g_signal_connect(download, "clicked", G_CALLBACK(download_dialog_connect_cb), (gpointer)state);
-
- frame_status = gtk_frame_new(_("Status"));
- status = gtk_label_new(_("Idle"));
- gtk_box_pack_start(GTK_BOX(vbox), frame_status, FALSE, TRUE, pad);
- gtk_container_add(GTK_CONTAINER(frame_status), status);
- gtk_misc_set_padding(GTK_MISC(status), pad, pad);
-
- state->uid = uid;
- state->status = status;
- state->apply = apply;
-
- g_signal_connect(dialog, "response", G_CALLBACK(download_dialog_response_cb), (gpointer)state);
- gtk_widget_show_all(dialog);
- if (has_previous_uid)
- free((void *)current_uid);
-}
-
-static gboolean divelogde_dialog(const char **user, const char **pass)
-{
- GtkWidget *dialog, *vbox, *info, *frame_user, *frame_pass, *uid, *pwd;
- gboolean ret = FALSE;
-
- *user = subsurface_get_conf("divelogde_user");
- *pass = subsurface_get_conf("divelogde_pass");
- dialog = gtk_dialog_new_with_buttons(_("Upload to divelogs.de"),
- GTK_WINDOW(main_window),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_APPLY,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
- NULL);
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- info = gtk_label_new(_("Please enter your userid and password for divelogs.de. "
- "The selected dives will be added to your account"));
- gtk_label_set_line_wrap(GTK_LABEL(info), TRUE);
- gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, TRUE, 0);
- gtk_misc_set_padding(GTK_MISC(info), 6, 6);
-
- frame_user = gtk_frame_new(_("User Identifier"));
- gtk_box_pack_start(GTK_BOX(vbox), frame_user, FALSE, TRUE, 6);
- uid = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(frame_user), uid);
- gtk_entry_set_max_length(GTK_ENTRY(uid), 40);
- gtk_entry_set_text(GTK_ENTRY(uid), *user ?: "");
- gtk_entry_set_activates_default(GTK_ENTRY(uid), TRUE);
-
- frame_pass = gtk_frame_new(_("Password"));
- gtk_box_pack_start(GTK_BOX(vbox), frame_pass, FALSE, TRUE, 6);
- pwd = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(frame_pass), pwd);
- gtk_entry_set_max_length(GTK_ENTRY(pwd), 40);
- gtk_entry_set_text(GTK_ENTRY(pwd), *pass ?: "");
- gtk_entry_set_visibility(GTK_ENTRY(pwd), FALSE);
- gtk_entry_set_activates_default(GTK_ENTRY(pwd), TRUE);
- gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
-
- gtk_widget_show_all(dialog);
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- free((void*)*user);
- free((void*)*pass);
- *user = strdup(gtk_entry_get_text(GTK_ENTRY(uid)));
- *pass = strdup(gtk_entry_get_text(GTK_ENTRY(pwd)));
- subsurface_set_conf("divelogde_user", *user);
- subsurface_set_conf("divelogde_pass", *pass);
- ret = TRUE;
- }
- gtk_widget_destroy(dialog);
- return ret;
-}
-
-int divelogde_upload(char *fn, char **error)
-{
- SoupMessage *msg;
- SoupMultipart *multipart;
- SoupSession *session;
- SoupBuffer *sbuf;
- gboolean ret = FALSE;
-#ifdef __MINGW32__
- /* for odd reasons I can't seem to get https connections to work
- * with mingw32 when cross-building the Windows binaries... so fall
- * back to http for now */
- char url[256] = "http://divelogs.de/DivelogsDirectImport.php";
-#else
- char url[256] = "https://divelogs.de/DivelogsDirectImport.php";
-#endif
- const char *pass = NULL;
- const char *user = NULL;
- struct memblock mem;
-
- if (readfile(fn, &mem) < 0)
- return ret;
- if (!divelogde_dialog(&user, &pass))
- return TRUE;
- sbuf = soup_buffer_new(SOUP_MEMORY_STATIC, mem.buffer, mem.size);
- session = soup_session_async_new();
- multipart = soup_multipart_new(SOUP_FORM_MIME_TYPE_MULTIPART);
- soup_multipart_append_form_string(multipart, "user", user);
- soup_multipart_append_form_string(multipart, "pass", pass);
-
- soup_multipart_append_form_file(multipart, "userfile", fn, NULL, sbuf);
- msg = soup_form_request_new_from_multipart(url, multipart);
- soup_message_headers_append(msg->request_headers, "Accept", "text/xml");
- soup_session_send_message(session, msg);
- if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) {
- *error = strdup(msg->response_body->data);
- ret = TRUE;
- } else {
- *error = strdup(msg->reason_phrase);
- }
- soup_session_abort(session);
- g_object_unref(G_OBJECT(msg));
- g_object_unref(G_OBJECT(session));
- return ret;
-}
diff --git a/windows.c b/windows.c
index fb2883916..731ef2448 100644
--- a/windows.c
+++ b/windows.c
@@ -2,209 +2,11 @@
/* implements Windows specific functions */
#include "dive.h"
#include "display.h"
-#if USE_GTK_UI
-#include "display-gtk.h"
-#endif
#include <windows.h>
#include <shlobj.h>
const char system_divelist_default_font[] = "Sans 8";
-static HKEY hkey;
-
-void subsurface_open_conf(void)
-{
- LONG success;
-
- success = RegCreateKeyEx(HKEY_CURRENT_USER, (LPCTSTR)TEXT("Software\\subsurface"),
- 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
- NULL, &hkey, NULL);
- if (success != ERROR_SUCCESS)
- printf("CreateKey Software\\subsurface failed %ld\n", success);
-}
-
-void subsurface_unset_conf(const char *name)
-{
- RegDeleteValue(hkey, (LPCTSTR)name);
-}
-
-void subsurface_set_conf(const char *name, const char *value)
-{
- /* since we are using the pointer 'value' as both an actual
- * pointer to the string setting and as a way to pass the
- * numbers 0 and 1 to this function for booleans, one of the
- * calls to RegSetValueEx needs to pass &value (when we want
- * to pass the boolean value), the other one passes value (the
- * address of the string. */
- int wlen;
- wchar_t *wname, *wstring;
-
- wname = (wchar_t *)g_utf8_to_utf16(name, -1, NULL, NULL, NULL);
- if (!wname)
- return;
-
- wlen = g_utf8_strlen((char *)value, -1);
- wstring = (wchar_t *)g_utf8_to_utf16((char *)value, -1, NULL, NULL, NULL);
- if (!wstring || !wlen) {
- free(wname);
- return;
- }
- RegSetValueExW(hkey, (LPCWSTR)wname, 0, REG_SZ, (const BYTE *)wstring,
- wlen * sizeof(wchar_t));
- free(wstring);
- free(wname);
-}
-
-void subsurface_set_conf_int(const char *name, int value)
-{
- RegSetValueEx(hkey, (LPCTSTR)name, 0, REG_DWORD, (const BYTE *)&value, 4);
-}
-
-void subsurface_set_conf_bool(const char *name, bool value)
-{
- subsurface_set_conf_int(name, value);
-}
-
-const char *subsurface_get_conf(const char *name)
-{
- const int csize = 64;
- int blen = 0;
- LONG ret = ERROR_MORE_DATA;
- wchar_t *wstring = NULL, *wname;
- char *utf8_string;
-
- wname = (wchar_t *)g_utf8_to_utf16(name, -1, NULL, NULL, NULL);
- if (!wname)
- return NULL;
- blen = 0;
- /* lest try to load the string in chunks of 'csize' bytes until it fits */
- while (ret == ERROR_MORE_DATA) {
- blen += csize;
- wstring = (wchar_t *)realloc(wstring, blen * sizeof(wchar_t));
- ret = RegQueryValueExW(hkey, (LPCWSTR)wname, NULL, NULL,
- (LPBYTE)wstring, (LPDWORD)&blen);
- }
- /* that's what happens the first time we start - just return NULL */
- if (ret != ERROR_SUCCESS) {
- free(wname);
- free(wstring);
- return NULL;
- }
- /* convert the returned string into utf-8 */
- utf8_string = g_utf16_to_utf8(wstring, -1, NULL, NULL, NULL);
- free(wstring);
- free(wname);
- if (!utf8_string)
- return NULL;
- if (!g_utf8_validate(utf8_string, -1, NULL)) {
- free(utf8_string);
- return NULL;
- }
- return utf8_string;
-}
-
-int subsurface_get_conf_int(const char *name)
-{
- DWORD value = -1, len = 4;
- LONG ret = RegQueryValueEx(hkey, (LPCTSTR)TEXT(name), NULL, NULL,
- (LPBYTE)&value, (LPDWORD)&len);
- if (ret != ERROR_SUCCESS)
- return -1;
- return value;
-}
-
-int subsurface_get_conf_bool(const char *name)
-{
- int ret = subsurface_get_conf_int(name);
- if (ret == -1)
- return ret;
- return ret != 0;
-}
-
-void subsurface_flush_conf(void)
-{
- /* this is a no-op */
-}
-
-void subsurface_close_conf(void)
-{
- RegCloseKey(hkey);
-}
-
-#if USE_GTK_UI
-int subsurface_fill_device_list(GtkListStore *store)
-{
- const int bufdef = 512;
- const char *dlabels[] = {"UEMISSDA", NULL};
- const char *devdef = "COM1";
- GtkTreeIter iter;
- int index = -1, nentries = 0, ret, i;
- char bufname[bufdef], bufval[bufdef], *p;
- DWORD nvalues, bufval_len, bufname_len;
- HKEY key;
-
- /* add serial ports */
- ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM",
- 0, KEY_READ, &key);
- if (ret == ERROR_SUCCESS) {
- ret = RegQueryInfoKeyA(key, NULL, NULL, NULL, NULL, NULL, NULL, &nvalues,
- NULL, NULL, NULL, NULL);
- if (ret == ERROR_SUCCESS)
- for (i = 0; i < nvalues; i++) {
- memset(bufval, 0, bufdef);
- memset(bufname, 0, bufdef);
- bufname_len = bufdef;
- bufval_len = bufdef;
- ret = RegEnumValueA(key, i, bufname, &bufname_len, NULL, NULL, bufval,
- &bufval_len);
- if (ret == ERROR_SUCCESS) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, 0, bufval, -1);
- if (is_default_dive_computer_device(bufval))
- index = nentries;
- nentries++;
- }
- }
- }
- /* add drive letters that match labels */
- memset(bufname, 0, bufdef);
- bufname_len = bufdef;
- if (GetLogicalDriveStringsA(bufname_len, bufname)) {
- p = bufname;
- while (*p) {
- memset(bufval, 0, bufdef);
- if (GetVolumeInformationA(p, bufval, bufdef, NULL, NULL, NULL, NULL, 0)) {
- for (i = 0; dlabels[i] != NULL; i++)
- if (!strcmp(bufval, dlabels[i])) {
- char name[80];
- snprintf(name, sizeof(name), "%s (%s)", p, dlabels[i]);
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, 0, name, -1);
- if (is_default_dive_computer_device(p))
- index = nentries;
- nentries++;
- }
- }
- p = &p[strlen(p) + 1];
- }
- }
- /* if we can't find anything, use the default */
- if (!nentries) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- 0, devdef, -1);
- if (is_default_dive_computer_device(devdef))
- index = 0;
- }
- return index;
-}
-#endif /* USE_GTK_UI */
-
-const char *subsurface_icon_name()
-{
- return "subsurface.ico";
-}
-
const char *system_default_filename(void)
{
char datapath[MAX_PATH];
@@ -223,27 +25,6 @@ const char *system_default_filename(void)
return buffer;
}
-const char *subsurface_gettext_domainpath(char *argv0)
-{
- /* first hackishly make sure that the LANGUAGE information is correctly set up
- * in the environment */
- char buffer[80];
- gchar *locale = g_win32_getlocale();
- snprintf(buffer, sizeof(buffer), "LANGUAGE=%s.UTF-8", locale);
- putenv(buffer);
- g_free(locale);
- /* always use translation directory relative to install location, regardless of argv0 */
- return "./share/locale";
-}
-
-#if USE_GTK_UI
-void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
- GtkWidget *vbox, GtkUIManager *ui_manager)
-{
- gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
-}
-#endif /* USE_GTK_UI */
-
/* barely documented API */
extern int __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
@@ -305,20 +86,6 @@ void subsurface_command_line_exit(gint *argc, gchar ***argv)
g_free(*argv);
}
-bool subsurface_launch_for_uri(const char* uri)
-{
- gboolean ret = FALSE;
- wchar_t *wuri = (wchar_t *)g_utf8_to_utf16(uri, -1, NULL, NULL, NULL);
- if (wuri) {
- if ((INT_PTR)ShellExecuteW(NULL, L"open", wuri, NULL, NULL, SW_SHOWNORMAL) > 32)
- ret = TRUE;
- free(wuri);
- }
- if (!ret)
- g_message("ShellExecute failed for: %s", uri);
- return ret;
-}
-
/* check if we are running a newer OS version */
bool subsurface_os_feature_available(os_feature_t f)
{