summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-01 17:29:38 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-01 17:29:38 -0800
commita58d470bad755c138a84b5516fa27bf74924e24c (patch)
tree6b902760a42bba3707dff08191c5d3f442074d29
parent030d0c1294bf6c90c3a58e6678dc56760d197bcb (diff)
downloadsubsurface-a58d470bad755c138a84b5516fa27bf74924e24c.tar.gz
Remove autogroup from the preferences and store per file instead
Having two spots to toggle autogroup had always been a clear sign of insanity. The inconsistent ludicrous semantic of when we remembered the state of autogroup was even worse. This finally gets rid of that disaster and drops the autogroup setting from the preferences and makes it instead a per file property. When you save a file, it saves the state of the autogroup toggle. This seems much more useful - you may have files where you want to create trips by default. And others, where you don't. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h1
-rw-r--r--gtk-gui.c24
-rw-r--r--parse-xml.c33
-rw-r--r--save-xml.c2
4 files changed, 46 insertions, 14 deletions
diff --git a/dive.h b/dive.h
index 9914e7d1d..d1e947458 100644
--- a/dive.h
+++ b/dive.h
@@ -536,6 +536,7 @@ extern void remember_dc(const char *model, uint32_t deviceid, const char *nickna
extern gboolean dc_was_saved(struct divecomputer *dc);
extern void mark_dc_saved(struct divecomputer *dc);
extern void clear_dc_saved_status(void);
+extern void set_autogroup(gboolean value);
#define DIVE_ERROR_PARSE 1
diff --git a/gtk-gui.c b/gtk-gui.c
index 95de4e1cb..a2f5e00f1 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -57,6 +57,8 @@ static const char *default_dive_computer_device;
static gboolean force_download;
static gboolean prefer_downloaded;
+GtkActionGroup *action_group;
+
struct units *get_output_units()
{
return &prefs.output_units;
@@ -506,7 +508,6 @@ OPTIONCALLBACK(temperature_toggle, prefs.visible_cols.temperature)
OPTIONCALLBACK(totalweight_toggle, prefs.visible_cols.totalweight)
OPTIONCALLBACK(suit_toggle, prefs.visible_cols.suit)
OPTIONCALLBACK(cylinder_toggle, prefs.visible_cols.cylinder)
-OPTIONCALLBACK(autogroup_toggle, autogroup)
OPTIONCALLBACK(po2_toggle, prefs.pp_graphs.po2)
OPTIONCALLBACK(pn2_toggle, prefs.pp_graphs.pn2)
OPTIONCALLBACK(phe_toggle, prefs.pp_graphs.phe)
@@ -674,11 +675,6 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
box = gtk_hbox_new(FALSE, 6);
gtk_container_add(GTK_CONTAINER(frame), box);
- button = gtk_check_button_new_with_label(_("Automatically group dives in trips"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), autogroup);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
- g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(autogroup_toggle), NULL);
-
frame = gtk_frame_new(_("Default XML Data File"));
gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 5);
box = gtk_hbox_new(FALSE, 6);
@@ -814,7 +810,6 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
subsurface_set_conf("MAXCNS", PREF_BOOL, BOOL_TO_PTR(prefs.visible_cols.maxcns));
subsurface_set_conf("divelist_font", PREF_STRING, divelist_font);
- subsurface_set_conf("autogroup", PREF_BOOL, BOOL_TO_PTR(autogroup));
subsurface_set_conf("po2graph", PREF_BOOL, BOOL_TO_PTR(prefs.pp_graphs.po2));
subsurface_set_conf("pn2graph", PREF_BOOL, BOOL_TO_PTR(prefs.pp_graphs.pn2));
@@ -916,6 +911,17 @@ static void autogroup_cb(GtkWidget *w, gpointer data)
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;
@@ -1119,7 +1125,7 @@ static const gchar* ui_string = " \
static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
{
- GtkActionGroup *action_group = gtk_action_group_new("Menu");
+ 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;
@@ -1232,7 +1238,7 @@ void init_ui(int *argcp, char ***argvp)
}
prefs.profile_red_ceiling = PTR_TO_BOOL(subsurface_get_conf("redceiling", PREF_BOOL));
divelist_font = subsurface_get_conf("divelist_font", PREF_STRING);
- autogroup = PTR_TO_BOOL(subsurface_get_conf("autogroup", PREF_BOOL));
+
default_filename = subsurface_get_conf("default_filename", PREF_STRING);
default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING);
diff --git a/parse-xml.c b/parse-xml.c
index a256990b3..e7cb1a182 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -595,16 +595,29 @@ static void eventtime(char *buffer, void *_duration)
duration->seconds += cur_sample->time.seconds;
}
+static void try_to_match_autogroup(const char *name, char *buf)
+{
+ int len = strlen(name);
+ int autogroupvalue;
+
+ start_match("autogroup", name, buf);
+ if (MATCH(".autogroup.state", get_index, &autogroupvalue)) {
+ set_autogroup(autogroupvalue);
+ return;
+ }
+ nonmatch("autogroup", name, buf);
+}
+
static void try_to_fill_dc_settings(const char *name, char *buf)
{
int len = strlen(name);
start_match("divecomputerid", name, buf);
- if (MATCH(".model", utf8_string, &cur_settings.dc.model))
+ if (MATCH("divecomputerid.model", utf8_string, &cur_settings.dc.model))
return;
- if (MATCH(".deviceid", hex_value, &cur_settings.dc.deviceid))
+ if (MATCH("divecomputerid.deviceid", hex_value, &cur_settings.dc.deviceid))
return;
- if (MATCH(".nickname", utf8_string, &cur_settings.dc.nickname))
+ if (MATCH("divecomputerid.nickname", utf8_string, &cur_settings.dc.nickname))
return;
nonmatch("divecomputerid", name, buf);
@@ -1053,15 +1066,23 @@ static void reset_dc_settings(void)
cur_settings.dc.deviceid = 0;
}
-static void dc_settings_start(void)
+static void settings_start(void)
{
in_settings = TRUE;
+}
+
+static void settings_end(void)
+{
+ in_settings = FALSE;
+}
+
+static void dc_settings_start(void)
+{
reset_dc_settings();
}
static void dc_settings_end(void)
{
- in_settings = FALSE;
if (cur_settings.dc.model)
remember_dc(cur_settings.dc.model, cur_settings.dc.deviceid, cur_settings.dc.nickname, TRUE);
reset_dc_settings();
@@ -1218,6 +1239,7 @@ static void entry(const char *name, char *buf)
{
if (in_settings) {
try_to_fill_dc_settings(name, buf);
+ try_to_match_autogroup(name, buf);
return;
}
if (cur_event.active) {
@@ -1341,6 +1363,7 @@ static struct nesting {
void (*start)(void), (*end)(void);
} nesting[] = {
{ "divecomputerid", dc_settings_start, dc_settings_end },
+ { "settings", settings_start, settings_end },
{ "dive", dive_start, dive_end },
{ "Dive", dive_start, dive_end },
{ "trip", trip_start, trip_end },
diff --git a/save-xml.c b/save-xml.c
index 0626d0adc..59eb02e23 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -532,6 +532,8 @@ void save_dives(const char *filename)
dc = dc->next;
}
}
+ if (autogroup)
+ fprintf(f, "<autogroup state='1' />\n");
fprintf(f, "</settings>\n<dives>\n");
for (trip = dive_trip_list; trip != NULL; trip = trip->next)