]> git.tdb.fi Git - ext/subsurface.git/blobdiff - gtk-gui.c
Remember the default dive computer setting
[ext/subsurface.git] / gtk-gui.c
index 402e91a6e5f2f1f29c15e9ea07129f1e9a2df019..ca033835d31630a9144fdbb3505a2a612f9ca267 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -31,6 +31,23 @@ static GtkWidget *dive_profile;
 
 visible_cols_t visible_cols = {TRUE, FALSE};
 
+static const char *default_dive_computer;
+
+static int is_default_dive_computer(const char *name)
+{
+       return default_dive_computer && !strcmp(name, default_dive_computer);
+}
+
+static void set_default_dive_computer(const char *name)
+{
+       if (!name || !*name)
+               return;
+       if (is_default_dive_computer(name))
+               return;
+       default_dive_computer = name;
+       subsurface_set_conf("dive_computer", PREF_STRING, name);
+}
+
 void repaint_dive(void)
 {
        update_dive(current_dive);
@@ -296,6 +313,8 @@ UNITCALLBACK(set_liter, volume, LITER)
 UNITCALLBACK(set_cuft, volume, CUFT)
 UNITCALLBACK(set_celsius, temperature, CELSIUS)
 UNITCALLBACK(set_fahrenheit, temperature, FAHRENHEIT)
+UNITCALLBACK(set_kg, weight, KG)
+UNITCALLBACK(set_lbs, weight, LBS)
 
 #define OPTIONCALLBACK(name, option) \
 static void name(GtkWidget *w, gpointer data) \
@@ -357,6 +376,11 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
                "Fahrenheit",  set_fahrenheit, (output_units.temperature == FAHRENHEIT),
                NULL);
 
+       create_radio(box, "Weight:",
+               "kg", set_kg, (output_units.weight == KG),
+               "lbs",  set_lbs, (output_units.weight == LBS),
+               NULL);
+
        frame = gtk_frame_new("Columns");
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
 
@@ -409,13 +433,16 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
                subsurface_set_conf("psi", PREF_BOOL, BOOL_TO_PTR(output_units.pressure == PSI));
                subsurface_set_conf("cuft", PREF_BOOL, BOOL_TO_PTR(output_units.volume == CUFT));
                subsurface_set_conf("fahrenheit", PREF_BOOL, BOOL_TO_PTR(output_units.temperature == FAHRENHEIT));
+               subsurface_set_conf("lbs", PREF_BOOL, BOOL_TO_PTR(output_units.weight == LBS));
                subsurface_set_conf("TEMPERATURE", PREF_BOOL, BOOL_TO_PTR(visible_cols.temperature));
                subsurface_set_conf("CYLINDER", PREF_BOOL, BOOL_TO_PTR(visible_cols.cylinder));
                subsurface_set_conf("NITROX", PREF_BOOL, BOOL_TO_PTR(visible_cols.nitrox));
                subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac));
                subsurface_set_conf("OTU", PREF_BOOL, BOOL_TO_PTR(visible_cols.otu));
                subsurface_set_conf("divelist_font", PREF_STRING, divelist_font);
-               subsurface_close_conf();
+
+               /* Flush the changes out to the system */
+               subsurface_flush_conf();
        }
        gtk_widget_destroy(dialog);
 }
@@ -670,6 +697,8 @@ void init_ui(int *argcp, char ***argvp)
                output_units.volume = CUFT;
        if (subsurface_get_conf("fahrenheit", PREF_BOOL))
                output_units.temperature = FAHRENHEIT;
+       if (subsurface_get_conf("lbs", PREF_BOOL))
+               output_units.weight = LBS;
        /* an unset key is FALSE - all these are hidden by default */
        visible_cols.cylinder = PTR_TO_BOOL(subsurface_get_conf("CYLINDER", PREF_BOOL));
        visible_cols.temperature = PTR_TO_BOOL(subsurface_get_conf("TEMPERATURE", PREF_BOOL));
@@ -679,6 +708,8 @@ void init_ui(int *argcp, char ***argvp)
 
        divelist_font = subsurface_get_conf("divelist_font", PREF_STRING);
 
+       default_dive_computer = subsurface_get_conf("dive_computer", PREF_STRING);
+
        error_info_bar = NULL;
        win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        g_set_application_name ("subsurface");
@@ -759,6 +790,11 @@ void run_ui(void)
        gtk_main();
 }
 
+void exit_ui(void)
+{
+       subsurface_close_conf();
+}
+
 typedef struct {
        cairo_rectangle_int_t rect;
        const char *text;
@@ -857,19 +893,22 @@ int process_ui_events(void)
        return ret;
 }
 
-
-static void fill_computer_list(GtkListStore *store)
+static int fill_computer_list(GtkListStore *store)
 {
+       int index = -1, i;
        GtkTreeIter iter;
        struct device_list *list = device_list;
 
-       for (list = device_list ; list->name ; list++) {
+       for (list = device_list, i = 0 ; list->name ; list++, i++) {
                gtk_list_store_append(store, &iter);
                gtk_list_store_set(store, &iter,
                        0, list->name,
                        1, list->type,
                        -1);
+               if (is_default_dive_computer(list->name))
+                       index = i;
        }
+       return index;
 }
 
 static GtkComboBox *dive_computer_selector(GtkWidget *vbox)
@@ -877,12 +916,13 @@ static GtkComboBox *dive_computer_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(2, G_TYPE_STRING, G_TYPE_INT);
-       fill_computer_list(model);
+       default_index = fill_computer_list(model);
 
        frame = gtk_frame_new("Dive computer");
        gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
@@ -894,6 +934,8 @@ static GtkComboBox *dive_computer_selector(GtkWidget *vbox)
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "text", 0, NULL);
 
+       gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), default_index);
+
        return GTK_COMBO_BOX(combo_box);
 }
 
@@ -1023,6 +1065,7 @@ void import_dialog(GtkWidget *w, gpointer data)
                        devicedata.type = type;
                        devicedata.name = comp;
                        devicedata.devname = gtk_entry_get_text(device);
+                       set_default_dive_computer(devicedata.name);
                        do_import(&devicedata);
                } else {
                        g_slist_foreach(list,do_import_file,NULL);