Split up preference data structure definition into 'pref.h'

.. and rename the badly named 'output_units/input_units' variables.

We used to have this confusing thing where we had two different units
(input vs output) that *look* like they are mirror images, but in fact
"output_units" was the user units, and "input_units" are the XML parsing
units.

So this renames them to be clearer.  "output_units" is now just "units"
(it's the units a user would ever see), and "input_units" is now
"xml_parsing_units" and set by the XML file parsers to reflect the units
of the parsed file.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2013-01-10 17:26:10 -08:00 committed by Dirk Hohndel
parent 4c13f1f6b4
commit 868a2cc090
15 changed files with 143 additions and 115 deletions

View file

@ -15,49 +15,6 @@ typedef struct {
GtkWidget *bar; GtkWidget *bar;
} progressbar_t; } progressbar_t;
typedef struct {
gboolean cylinder;
gboolean temperature;
gboolean totalweight;
gboolean suit;
gboolean nitrox;
gboolean sac;
gboolean otu;
gboolean maxcns;
} visible_cols_t;
typedef struct {
gboolean po2;
gboolean pn2;
gboolean phe;
double po2_threshold;
double pn2_threshold;
double phe_threshold;
} partial_pressure_graphs_t;
struct preferences {
struct units output_units;
visible_cols_t visible_cols;
partial_pressure_graphs_t pp_graphs;
gboolean profile_red_ceiling;
gboolean profile_calc_ceiling;
gboolean calc_ceiling_3m_incr;
double gflow;
double gfhigh;
};
extern struct preferences prefs;
#define PP_GRAPHS_ENABLED (prefs.pp_graphs.po2 || prefs.pp_graphs.pn2 || prefs.pp_graphs.phe)
typedef enum {
PREF_BOOL,
PREF_STRING
} pref_type_t;
#define BOOL_TO_PTR(_cond) ((_cond) ? (void *)1 : NULL)
#define PTR_TO_BOOL(_ptr) ((_ptr) != NULL)
#if defined __APPLE__ #if defined __APPLE__
#define CTRLCHAR "<Meta>" #define CTRLCHAR "<Meta>"
#define SHIFTCHAR "<Shift>" #define SHIFTCHAR "<Shift>"
@ -68,12 +25,6 @@ typedef enum {
#define PREFERENCE_ACCEL NULL #define PREFERENCE_ACCEL NULL
#endif #endif
extern void subsurface_open_conf(void);
extern void subsurface_set_conf(char *name, pref_type_t type, const void *value);
extern const void *subsurface_get_conf(char *name, pref_type_t type);
extern void subsurface_flush_conf(void);
extern void subsurface_close_conf(void);
extern int subsurface_fill_device_list(GtkListStore *store); extern int subsurface_fill_device_list(GtkListStore *store);
extern const char *subsurface_icon_name(void); extern const char *subsurface_icon_name(void);
extern void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar, extern void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,

22
dive.c
View file

@ -34,9 +34,9 @@ int get_pressure_units(unsigned int mb, const char **units)
{ {
int pressure; int pressure;
const char* unit; const char* unit;
struct units *output_units_p = get_output_units(); struct units *units_p = get_units();
switch (output_units_p->pressure) { switch (units_p->pressure) {
case PASCAL: case PASCAL:
pressure = mb * 100; pressure = mb * 100;
unit = _("pascal"); unit = _("pascal");
@ -59,9 +59,9 @@ double get_temp_units(unsigned int mk, const char **units)
{ {
double deg; double deg;
const char *unit; const char *unit;
struct units *output_units_p = get_output_units(); struct units *units_p = get_units();
if (output_units_p->temperature == FAHRENHEIT) { if (units_p->temperature == FAHRENHEIT) {
deg = mkelvin_to_F(mk); deg = mkelvin_to_F(mk);
unit = UTF8_DEGREE "F"; unit = UTF8_DEGREE "F";
} else { } else {
@ -78,9 +78,9 @@ double get_volume_units(unsigned int ml, int *frac, const char **units)
int decimals; int decimals;
double vol; double vol;
const char *unit; const char *unit;
struct units *output_units_p = get_output_units(); struct units *units_p = get_units();
switch (output_units_p->volume) { switch (units_p->volume) {
case LITER: case LITER:
vol = ml / 1000.0; vol = ml / 1000.0;
unit = _("l"); unit = _("l");
@ -104,9 +104,9 @@ double get_depth_units(unsigned int mm, int *frac, const char **units)
int decimals; int decimals;
double d; double d;
const char *unit; const char *unit;
struct units *output_units_p = get_output_units(); struct units *units_p = get_units();
switch (output_units_p->length) { switch (units_p->length) {
case METERS: case METERS:
d = mm / 1000.0; d = mm / 1000.0;
unit = _("m"); unit = _("m");
@ -130,9 +130,9 @@ double get_weight_units(unsigned int grams, int *frac, const char **units)
int decimals; int decimals;
double value; double value;
const char* unit; const char* unit;
struct units *output_units_p = get_output_units(); struct units *units_p = get_units();
if (output_units_p->weight == LBS) { if (units_p->weight == LBS) {
value = grams_to_lbs(grams); value = grams_to_lbs(grams);
unit = _("lbs"); unit = _("lbs");
decimals = 0; decimals = 0;
@ -352,7 +352,7 @@ static void sanitize_cylinder_type(cylinder_type_t *type)
if (!type->size.mliter) if (!type->size.mliter)
return; return;
if (input_units.volume == CUFT) { if (xml_parsing_units.volume == CUFT) {
/* confusing - we don't really start from ml but millicuft !*/ /* confusing - we don't really start from ml but millicuft !*/
volume_of_air = cuft_to_l(type->size.mliter); volume_of_air = cuft_to_l(type->size.mliter);
atm = to_ATM(type->workingpressure); /* working pressure in atm */ atm = to_ATM(type->workingpressure); /* working pressure in atm */

7
dive.h
View file

@ -426,9 +426,9 @@ struct units {
.weight = LBS \ .weight = LBS \
} }
extern const struct units SI_units, IMPERIAL_units; extern const struct units SI_units, IMPERIAL_units;
extern struct units input_units; extern struct units xml_parsing_units;
extern struct units *get_output_units(void); extern struct units *get_units(void);
extern int verbose; extern int verbose;
struct dive_table { struct dive_table {
@ -613,4 +613,7 @@ void free_dps(struct divedatapoint *dp);
extern char *debugfilename; extern char *debugfilename;
extern FILE *debugfile; extern FILE *debugfile;
#endif #endif
#include "pref.h"
#endif /* DIVE_H */ #endif /* DIVE_H */

View file

@ -405,7 +405,7 @@ static void depth_data_func(GtkTreeViewColumn *col,
if (idx < 0) { if (idx < 0) {
*buffer = '\0'; *buffer = '\0';
} else { } else {
switch (prefs.output_units.length) { switch (prefs.units.length) {
case METERS: case METERS:
/* To tenths of meters */ /* To tenths of meters */
depth = (depth + 49) / 100; depth = (depth + 49) / 100;
@ -464,7 +464,7 @@ static void temperature_data_func(GtkTreeViewColumn *col,
*buffer = 0; *buffer = 0;
if (idx >= 0 && value) { if (idx >= 0 && value) {
double deg; double deg;
switch (prefs.output_units.temperature) { switch (prefs.units.temperature) {
case CELSIUS: case CELSIUS:
deg = mkelvin_to_C(value); deg = mkelvin_to_C(value);
break; break;
@ -661,7 +661,7 @@ static void sac_data_func(GtkTreeViewColumn *col,
} }
sac = value / 1000.0; sac = value / 1000.0;
switch (prefs.output_units.volume) { switch (prefs.units.volume) {
case LITER: case LITER:
fmt = "%4.1f"; fmt = "%4.1f";
break; break;

View file

@ -75,7 +75,7 @@ static int convert_pressure(int mbar, double *p)
int decimals = 1; int decimals = 1;
double pressure; double pressure;
if (prefs.output_units.pressure == PSI) { if (prefs.units.pressure == PSI) {
pressure = mbar_to_PSI(mbar); pressure = mbar_to_PSI(mbar);
decimals = 0; decimals = 0;
} else { } else {
@ -92,12 +92,12 @@ static void convert_volume_pressure(int ml, int mbar, double *v, double *p)
volume = ml / 1000.0; volume = ml / 1000.0;
if (mbar) { if (mbar) {
if (prefs.output_units.volume == CUFT) { if (prefs.units.volume == CUFT) {
volume = ml_to_cuft(ml); volume = ml_to_cuft(ml);
volume *= bar_to_atm(mbar / 1000.0); volume *= bar_to_atm(mbar / 1000.0);
} }
if (prefs.output_units.pressure == PSI) if (prefs.units.pressure == PSI)
pressure = mbar_to_PSI(mbar); pressure = mbar_to_PSI(mbar);
else else
pressure = mbar / 1000.0; pressure = mbar / 1000.0;
@ -111,7 +111,7 @@ static int convert_weight(int grams, double *m)
int decimals = 1; /* not sure - do people do less than whole lbs/kg ? */ int decimals = 1; /* not sure - do people do less than whole lbs/kg ? */
double weight; double weight;
if (prefs.output_units.weight == LBS) if (prefs.units.weight == LBS)
weight = grams_to_lbs(grams); weight = grams_to_lbs(grams);
else else
weight = grams / 1000.0; weight = grams / 1000.0;
@ -631,14 +631,14 @@ static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl
{ {
int mbar, ml; int mbar, ml;
if (prefs.output_units.pressure == PSI) { if (prefs.units.pressure == PSI) {
pressure = psi_to_bar(pressure); pressure = psi_to_bar(pressure);
start = psi_to_bar(start); start = psi_to_bar(start);
end = psi_to_bar(end); end = psi_to_bar(end);
} }
mbar = pressure * 1000 + 0.5; mbar = pressure * 1000 + 0.5;
if (mbar && prefs.output_units.volume == CUFT) { if (mbar && prefs.units.volume == CUFT) {
volume = cuft_to_l(volume); volume = cuft_to_l(volume);
volume /= bar_to_atm(pressure); volume /= bar_to_atm(pressure);
} }
@ -714,7 +714,7 @@ static void record_weightsystem_changes(weightsystem_t *ws, struct ws_widget *we
desc = gtk_combo_box_get_active_text(box); desc = gtk_combo_box_get_active_text(box);
value = gtk_spin_button_get_value(weightsystem_widget->weight); value = gtk_spin_button_get_value(weightsystem_widget->weight);
if (prefs.output_units.weight == LBS) if (prefs.units.weight == LBS)
grams = lbs_to_grams(value); grams = lbs_to_grams(value);
else else
grams = value * 1000; grams = value * 1000;
@ -1041,7 +1041,7 @@ static void ws_widget(GtkWidget *vbox, struct ws_widget *ws_widget, GtkListStore
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
if ( prefs.output_units.weight == KG) if ( prefs.units.weight == KG)
widget = create_spinbutton(hbox, _("kg"), 0, 50, 0.5); widget = create_spinbutton(hbox, _("kg"), 0, 50, 0.5);
else else
widget = create_spinbutton(hbox, _("lbs"), 0, 110, 1); widget = create_spinbutton(hbox, _("lbs"), 0, 110, 1);

View file

@ -53,9 +53,9 @@ static gboolean prefer_downloaded;
GtkActionGroup *action_group; GtkActionGroup *action_group;
struct units *get_output_units() struct units *get_units()
{ {
return &prefs.output_units; return &prefs.units;
} }
static int is_default_dive_computer(const char *vendor, const char *product) static int is_default_dive_computer(const char *vendor, const char *product)
@ -475,7 +475,7 @@ static void update_screen()
static void name(GtkWidget *w, gpointer data) \ static void name(GtkWidget *w, gpointer data) \
{ \ { \
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) \ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) \
prefs.output_units.type = value; \ prefs.units.type = value; \
update_screen(); \ update_screen(); \
} }
@ -631,28 +631,28 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
gtk_container_add(GTK_CONTAINER(frame), box); gtk_container_add(GTK_CONTAINER(frame), box);
create_radio(box, _("Depth:"), create_radio(box, _("Depth:"),
_("Meter"), set_meter, (prefs.output_units.length == METERS), _("Meter"), set_meter, (prefs.units.length == METERS),
_("Feet"), set_feet, (prefs.output_units.length == FEET), _("Feet"), set_feet, (prefs.units.length == FEET),
NULL); NULL);
create_radio(box, _("Pressure:"), create_radio(box, _("Pressure:"),
_("Bar"), set_bar, (prefs.output_units.pressure == BAR), _("Bar"), set_bar, (prefs.units.pressure == BAR),
_("PSI"), set_psi, (prefs.output_units.pressure == PSI), _("PSI"), set_psi, (prefs.units.pressure == PSI),
NULL); NULL);
create_radio(box, _("Volume:"), create_radio(box, _("Volume:"),
_("Liter"), set_liter, (prefs.output_units.volume == LITER), _("Liter"), set_liter, (prefs.units.volume == LITER),
_("CuFt"), set_cuft, (prefs.output_units.volume == CUFT), _("CuFt"), set_cuft, (prefs.units.volume == CUFT),
NULL); NULL);
create_radio(box, _("Temperature:"), create_radio(box, _("Temperature:"),
_("Celsius"), set_celsius, (prefs.output_units.temperature == CELSIUS), _("Celsius"), set_celsius, (prefs.units.temperature == CELSIUS),
_("Fahrenheit"), set_fahrenheit, (prefs.output_units.temperature == FAHRENHEIT), _("Fahrenheit"), set_fahrenheit, (prefs.units.temperature == FAHRENHEIT),
NULL); NULL);
create_radio(box, _("Weight:"), create_radio(box, _("Weight:"),
_("kg"), set_kg, (prefs.output_units.weight == KG), _("kg"), set_kg, (prefs.units.weight == KG),
_("lbs"), set_lbs, (prefs.output_units.weight == LBS), _("lbs"), set_lbs, (prefs.units.weight == LBS),
NULL); NULL);
frame = gtk_frame_new(_("Show Columns")); frame = gtk_frame_new(_("Show Columns"));
@ -865,11 +865,11 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
update_screen(); update_screen();
subsurface_set_conf("feet", PREF_BOOL, BOOL_TO_PTR(prefs.output_units.length == FEET)); subsurface_set_conf("feet", PREF_BOOL, BOOL_TO_PTR(prefs.units.length == FEET));
subsurface_set_conf("psi", PREF_BOOL, BOOL_TO_PTR(prefs.output_units.pressure == PSI)); subsurface_set_conf("psi", PREF_BOOL, BOOL_TO_PTR(prefs.units.pressure == PSI));
subsurface_set_conf("cuft", PREF_BOOL, BOOL_TO_PTR(prefs.output_units.volume == CUFT)); subsurface_set_conf("cuft", PREF_BOOL, BOOL_TO_PTR(prefs.units.volume == CUFT));
subsurface_set_conf("fahrenheit", PREF_BOOL, BOOL_TO_PTR(prefs.output_units.temperature == FAHRENHEIT)); subsurface_set_conf("fahrenheit", PREF_BOOL, BOOL_TO_PTR(prefs.units.temperature == FAHRENHEIT));
subsurface_set_conf("lbs", PREF_BOOL, BOOL_TO_PTR(prefs.output_units.weight == LBS)); subsurface_set_conf("lbs", PREF_BOOL, BOOL_TO_PTR(prefs.units.weight == LBS));
subsurface_set_conf("TEMPERATURE", PREF_BOOL, BOOL_TO_PTR(prefs.visible_cols.temperature)); subsurface_set_conf("TEMPERATURE", PREF_BOOL, BOOL_TO_PTR(prefs.visible_cols.temperature));
subsurface_set_conf("TOTALWEIGHT", PREF_BOOL, BOOL_TO_PTR(prefs.visible_cols.totalweight)); subsurface_set_conf("TOTALWEIGHT", PREF_BOOL, BOOL_TO_PTR(prefs.visible_cols.totalweight));
@ -1282,15 +1282,15 @@ void init_ui(int *argcp, char ***argvp)
subsurface_open_conf(); subsurface_open_conf();
if (subsurface_get_conf("feet", PREF_BOOL)) if (subsurface_get_conf("feet", PREF_BOOL))
prefs.output_units.length = FEET; prefs.units.length = FEET;
if (subsurface_get_conf("psi", PREF_BOOL)) if (subsurface_get_conf("psi", PREF_BOOL))
prefs.output_units.pressure = PSI; prefs.units.pressure = PSI;
if (subsurface_get_conf("cuft", PREF_BOOL)) if (subsurface_get_conf("cuft", PREF_BOOL))
prefs.output_units.volume = CUFT; prefs.units.volume = CUFT;
if (subsurface_get_conf("fahrenheit", PREF_BOOL)) if (subsurface_get_conf("fahrenheit", PREF_BOOL))
prefs.output_units.temperature = FAHRENHEIT; prefs.units.temperature = FAHRENHEIT;
if (subsurface_get_conf("lbs", PREF_BOOL)) if (subsurface_get_conf("lbs", PREF_BOOL))
prefs.output_units.weight = LBS; prefs.units.weight = LBS;
/* an unset key is FALSE - all these are hidden by default */ /* an unset key is FALSE - all these are hidden by default */
prefs.visible_cols.cylinder = PTR_TO_BOOL(subsurface_get_conf("CYLINDER", PREF_BOOL)); prefs.visible_cols.cylinder = PTR_TO_BOOL(subsurface_get_conf("CYLINDER", PREF_BOOL));
prefs.visible_cols.temperature = PTR_TO_BOOL(subsurface_get_conf("TEMPERATURE", PREF_BOOL)); prefs.visible_cols.temperature = PTR_TO_BOOL(subsurface_get_conf("TEMPERATURE", PREF_BOOL));

8
info.c
View file

@ -450,7 +450,7 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc
new_text = (char *)gtk_entry_get_text(info->airtemp); new_text = (char *)gtk_entry_get_text(info->airtemp);
if(sscanf(new_text, "%lf", &newtemp) == 1) { if(sscanf(new_text, "%lf", &newtemp) == 1) {
unsigned long mkelvin; unsigned long mkelvin;
switch (prefs.output_units.temperature) { switch (prefs.units.temperature) {
case CELSIUS: case CELSIUS:
mkelvin = C_to_mkelvin(newtemp); mkelvin = C_to_mkelvin(newtemp);
break; break;
@ -895,8 +895,8 @@ static timestamp_t dive_time_widget(struct dive *dive)
gtk_box_pack_end(GTK_BOX(box), duration, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(box), duration, FALSE, FALSE, 0);
/* Depth box */ /* Depth box */
box = frame_box(hbox, _("Depth (%s):"), prefs.output_units.length == FEET ? _("ft") : _("m")); box = frame_box(hbox, _("Depth (%s):"), prefs.units.length == FEET ? _("ft") : _("m"));
if (prefs.output_units.length == FEET) { if (prefs.units.length == FEET) {
depthinterval = 1.0; depthinterval = 1.0;
} else { } else {
depthinterval = 0.1; depthinterval = 0.1;
@ -922,7 +922,7 @@ static timestamp_t dive_time_widget(struct dive *dive)
tm.tm_min = gtk_spin_button_get_value(GTK_SPIN_BUTTON(m)); tm.tm_min = gtk_spin_button_get_value(GTK_SPIN_BUTTON(m));
val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(depth)); val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(depth));
if (prefs.output_units.length == FEET) { if (prefs.units.length == FEET) {
dive->maxdepth.mm = feet_to_mm(val); dive->maxdepth.mm = feet_to_mm(val);
} else { } else {
dive->maxdepth.mm = val * 1000 + 0.5; dive->maxdepth.mm = val * 1000 + 0.5;

View file

@ -23,6 +23,11 @@ void subsurface_open_conf(void)
gconf = gconf_client_get_default(); gconf = gconf_client_get_default();
} }
void subsurface_unset_conf(char *name)
{
gconf_client_unset(gconf, gconf_name(name), NULL);
}
void subsurface_set_conf(char *name, pref_type_t type, const void *value) void subsurface_set_conf(char *name, pref_type_t type, const void *value)
{ {
switch (type) { switch (type) {

View file

@ -26,6 +26,11 @@ void subsurface_open_conf(void)
/* nothing at this time */ /* nothing at this time */
} }
void subsurface_unset_conf(char *name)
{
CFPreferencesSetAppValue(CFSTR_VAR(name), NULL, SUBSURFACE_PREFERENCES);
}
void subsurface_set_conf(char *name, pref_type_t type, const void *value) void subsurface_set_conf(char *name, pref_type_t type, const void *value)
{ {
switch (type) { switch (type) {

4
main.c
View file

@ -15,7 +15,7 @@ char *debugfilename;
FILE *debugfile; FILE *debugfile;
#endif #endif
struct units output_units; struct units units;
/* random helper functions, used here or elsewhere */ /* random helper functions, used here or elsewhere */
static int sortfn(const void *_a, const void *_b) static int sortfn(const void *_a, const void *_b)
@ -253,7 +253,7 @@ int main(int argc, char **argv)
bindtextdomain("subsurface", path); bindtextdomain("subsurface", path);
bind_textdomain_codeset("subsurface", "utf-8"); bind_textdomain_codeset("subsurface", "utf-8");
textdomain("subsurface"); textdomain("subsurface");
output_units = SI_units; units = SI_units;
#if DEBUGFILE > 1 #if DEBUGFILE > 1
debugfile = stderr; debugfile = stderr;

View file

@ -128,7 +128,7 @@ static int match(const char *pattern, int plen,
} }
struct units input_units; struct units xml_parsing_units;
const struct units SI_units = SI_UNITS; const struct units SI_units = SI_UNITS;
const struct units IMPERIAL_units = IMPERIAL_UNITS; const struct units IMPERIAL_units = IMPERIAL_UNITS;
@ -267,7 +267,7 @@ static void pressure(char *buffer, void *_press)
/* Just ignore zero values */ /* Just ignore zero values */
if (!val.fp) if (!val.fp)
break; break;
switch (input_units.pressure) { switch (xml_parsing_units.pressure) {
case PASCAL: case PASCAL:
mbar = val.fp / 100; mbar = val.fp / 100;
break; break;
@ -311,7 +311,7 @@ static void depth(char *buffer, void *_depth)
switch (integer_or_float(buffer, &val)) { switch (integer_or_float(buffer, &val)) {
case FLOAT: case FLOAT:
switch (input_units.length) { switch (xml_parsing_units.length) {
case METERS: case METERS:
depth->mm = val.fp * 1000 + 0.5; depth->mm = val.fp * 1000 + 0.5;
break; break;
@ -332,7 +332,7 @@ static void weight(char *buffer, void *_weight)
switch (integer_or_float(buffer, &val)) { switch (integer_or_float(buffer, &val)) {
case FLOAT: case FLOAT:
switch (input_units.weight) { switch (xml_parsing_units.weight) {
case KG: case KG:
weight->grams = val.fp * 1000 + 0.5; weight->grams = val.fp * 1000 + 0.5;
break; break;
@ -357,7 +357,7 @@ static void temperature(char *buffer, void *_temperature)
if (!val.fp) if (!val.fp)
break; break;
/* Celsius */ /* Celsius */
switch (input_units.temperature) { switch (xml_parsing_units.temperature) {
case KELVIN: case KELVIN:
temperature->mkelvin = val.fp * 1000; temperature->mkelvin = val.fp * 1000;
break; break;
@ -1364,15 +1364,15 @@ static void DivingLog_importer(void)
* *
* Crazy f*%^ morons. * Crazy f*%^ morons.
*/ */
input_units = SI_units; xml_parsing_units = SI_units;
} }
static void uddf_importer(void) static void uddf_importer(void)
{ {
import_source = UDDF; import_source = UDDF;
input_units = SI_units; xml_parsing_units = SI_units;
input_units.pressure = PASCAL; xml_parsing_units.pressure = PASCAL;
input_units.temperature = KELVIN; xml_parsing_units.temperature = KELVIN;
} }
/* /*
@ -1437,7 +1437,7 @@ static void reset_all(void)
* data within one file, we might have to reset it per * data within one file, we might have to reset it per
* dive for that format. * dive for that format.
*/ */
input_units = SI_units; xml_parsing_units = SI_units;
import_source = UNKNOWN; import_source = UNKNOWN;
} }

View file

@ -667,7 +667,7 @@ static int validate_depth(const char *text, int *mm_p)
while (isspace(*text)) while (isspace(*text))
text++; text++;
imperial = get_output_units()->length == FEET; imperial = get_units()->length == FEET;
if (*text == 'm') { if (*text == 'm') {
imperial = 0; imperial = 0;
text++; text++;

54
pref.h Normal file
View file

@ -0,0 +1,54 @@
#ifndef PREF_H
#define PREF_H
typedef struct {
gboolean cylinder;
gboolean temperature;
gboolean totalweight;
gboolean suit;
gboolean nitrox;
gboolean sac;
gboolean otu;
gboolean maxcns;
} visible_cols_t;
typedef struct {
gboolean po2;
gboolean pn2;
gboolean phe;
double po2_threshold;
double pn2_threshold;
double phe_threshold;
} partial_pressure_graphs_t;
struct preferences {
struct units units;
visible_cols_t visible_cols;
partial_pressure_graphs_t pp_graphs;
gboolean profile_red_ceiling;
gboolean profile_calc_ceiling;
gboolean calc_ceiling_3m_incr;
double gflow;
double gfhigh;
};
extern struct preferences prefs, default_prefs;
#define PP_GRAPHS_ENABLED (prefs.pp_graphs.po2 || prefs.pp_graphs.pn2 || prefs.pp_graphs.phe)
typedef enum {
PREF_BOOL,
PREF_STRING
} pref_type_t;
#define BOOL_TO_PTR(_cond) ((_cond) ? (void *)1 : NULL)
#define PTR_TO_BOOL(_ptr) ((_ptr) != NULL)
extern void subsurface_open_conf(void);
extern void subsurface_set_conf(char *name, pref_type_t type, const void *value);
extern void subsurface_unset_conf(char *name);
extern const void *subsurface_get_conf(char *name, pref_type_t type);
extern void subsurface_flush_conf(void);
extern void subsurface_close_conf(void);
#endif /* PREF_H */

View file

@ -533,7 +533,7 @@ static void plot_depth_scale(struct graphics_context *gc, struct plot_info *pi)
maxdepth = get_maxdepth(pi); maxdepth = get_maxdepth(pi);
gc->topy = 0; gc->bottomy = maxdepth; gc->topy = 0; gc->bottomy = maxdepth;
switch (prefs.output_units.length) { switch (prefs.units.length) {
case METERS: marker = 10000; break; case METERS: marker = 10000; break;
case FEET: marker = 9144; break; /* 30 ft */ case FEET: marker = 9144; break; /* 30 ft */
} }
@ -721,7 +721,7 @@ static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi
/* Depth markers: every 30 ft or 10 m*/ /* Depth markers: every 30 ft or 10 m*/
gc->leftx = 0; gc->rightx = 1.0; gc->leftx = 0; gc->rightx = 1.0;
gc->topy = 0; gc->bottomy = maxdepth; gc->topy = 0; gc->bottomy = maxdepth;
switch (prefs.output_units.length) { switch (prefs.units.length) {
case METERS: marker = 10000; break; case METERS: marker = 10000; break;
case FEET: marker = 9144; break; /* 30 ft */ case FEET: marker = 9144; break; /* 30 ft */
} }

View file

@ -32,6 +32,16 @@ void subsurface_open_conf(void)
printf("CreateKey Software\\subsurface failed %ld\n", success); printf("CreateKey Software\\subsurface failed %ld\n", success);
} }
void subsurface_unset_conf(char *name)
{
wchar_t *wname;
wname = (wchar_t *)g_utf8_to_utf16(name, -1, NULL, NULL, NULL);
if (!wname)
return;
RegDeleteKey(hkey, (LPCWSTR)wname);
}
void subsurface_set_conf(char *name, pref_type_t type, const void *value) void subsurface_set_conf(char *name, pref_type_t type, const void *value)
{ {
/* since we are using the pointer 'value' as both an actual /* since we are using the pointer 'value' as both an actual