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>
This commit is contained in:
Dirk Hohndel 2013-01-01 17:29:38 -08:00
parent 030d0c1294
commit a58d470bad
4 changed files with 46 additions and 14 deletions

1
dive.h
View file

@ -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 gboolean dc_was_saved(struct divecomputer *dc);
extern void mark_dc_saved(struct divecomputer *dc); extern void mark_dc_saved(struct divecomputer *dc);
extern void clear_dc_saved_status(void); extern void clear_dc_saved_status(void);
extern void set_autogroup(gboolean value);
#define DIVE_ERROR_PARSE 1 #define DIVE_ERROR_PARSE 1

View file

@ -57,6 +57,8 @@ static const char *default_dive_computer_device;
static gboolean force_download; static gboolean force_download;
static gboolean prefer_downloaded; static gboolean prefer_downloaded;
GtkActionGroup *action_group;
struct units *get_output_units() struct units *get_output_units()
{ {
return &prefs.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(totalweight_toggle, prefs.visible_cols.totalweight)
OPTIONCALLBACK(suit_toggle, prefs.visible_cols.suit) OPTIONCALLBACK(suit_toggle, prefs.visible_cols.suit)
OPTIONCALLBACK(cylinder_toggle, prefs.visible_cols.cylinder) OPTIONCALLBACK(cylinder_toggle, prefs.visible_cols.cylinder)
OPTIONCALLBACK(autogroup_toggle, autogroup)
OPTIONCALLBACK(po2_toggle, prefs.pp_graphs.po2) OPTIONCALLBACK(po2_toggle, prefs.pp_graphs.po2)
OPTIONCALLBACK(pn2_toggle, prefs.pp_graphs.pn2) OPTIONCALLBACK(pn2_toggle, prefs.pp_graphs.pn2)
OPTIONCALLBACK(phe_toggle, prefs.pp_graphs.phe) 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); box = gtk_hbox_new(FALSE, 6);
gtk_container_add(GTK_CONTAINER(frame), box); 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")); frame = gtk_frame_new(_("Default XML Data File"));
gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 5);
box = gtk_hbox_new(FALSE, 6); 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("MAXCNS", PREF_BOOL, BOOL_TO_PTR(prefs.visible_cols.maxcns));
subsurface_set_conf("divelist_font", PREF_STRING, divelist_font); 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("po2graph", PREF_BOOL, BOOL_TO_PTR(prefs.pp_graphs.po2));
subsurface_set_conf("pn2graph", PREF_BOOL, BOOL_TO_PTR(prefs.pp_graphs.pn2)); 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(); 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) static void renumber_dialog(GtkWidget *w, gpointer data)
{ {
int result; int result;
@ -1119,7 +1125,7 @@ static const gchar* ui_string = " \
static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager) 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_set_translation_domain(action_group, "subsurface");
gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0); gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
toggle_items[0].is_active = autogroup; 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)); prefs.profile_red_ceiling = PTR_TO_BOOL(subsurface_get_conf("redceiling", PREF_BOOL));
divelist_font = subsurface_get_conf("divelist_font", PREF_STRING); 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_filename = subsurface_get_conf("default_filename", PREF_STRING);
default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING); default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING);

View file

@ -595,16 +595,29 @@ static void eventtime(char *buffer, void *_duration)
duration->seconds += cur_sample->time.seconds; 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) static void try_to_fill_dc_settings(const char *name, char *buf)
{ {
int len = strlen(name); int len = strlen(name);
start_match("divecomputerid", name, buf); 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; return;
if (MATCH(".deviceid", hex_value, &cur_settings.dc.deviceid)) if (MATCH("divecomputerid.deviceid", hex_value, &cur_settings.dc.deviceid))
return; return;
if (MATCH(".nickname", utf8_string, &cur_settings.dc.nickname)) if (MATCH("divecomputerid.nickname", utf8_string, &cur_settings.dc.nickname))
return; return;
nonmatch("divecomputerid", name, buf); nonmatch("divecomputerid", name, buf);
@ -1053,15 +1066,23 @@ static void reset_dc_settings(void)
cur_settings.dc.deviceid = 0; cur_settings.dc.deviceid = 0;
} }
static void dc_settings_start(void) static void settings_start(void)
{ {
in_settings = TRUE; in_settings = TRUE;
}
static void settings_end(void)
{
in_settings = FALSE;
}
static void dc_settings_start(void)
{
reset_dc_settings(); reset_dc_settings();
} }
static void dc_settings_end(void) static void dc_settings_end(void)
{ {
in_settings = FALSE;
if (cur_settings.dc.model) if (cur_settings.dc.model)
remember_dc(cur_settings.dc.model, cur_settings.dc.deviceid, cur_settings.dc.nickname, TRUE); remember_dc(cur_settings.dc.model, cur_settings.dc.deviceid, cur_settings.dc.nickname, TRUE);
reset_dc_settings(); reset_dc_settings();
@ -1218,6 +1239,7 @@ static void entry(const char *name, char *buf)
{ {
if (in_settings) { if (in_settings) {
try_to_fill_dc_settings(name, buf); try_to_fill_dc_settings(name, buf);
try_to_match_autogroup(name, buf);
return; return;
} }
if (cur_event.active) { if (cur_event.active) {
@ -1341,6 +1363,7 @@ static struct nesting {
void (*start)(void), (*end)(void); void (*start)(void), (*end)(void);
} nesting[] = { } nesting[] = {
{ "divecomputerid", dc_settings_start, dc_settings_end }, { "divecomputerid", dc_settings_start, dc_settings_end },
{ "settings", settings_start, settings_end },
{ "dive", dive_start, dive_end }, { "dive", dive_start, dive_end },
{ "Dive", dive_start, dive_end }, { "Dive", dive_start, dive_end },
{ "trip", trip_start, trip_end }, { "trip", trip_start, trip_end },

View file

@ -532,6 +532,8 @@ void save_dives(const char *filename)
dc = dc->next; dc = dc->next;
} }
} }
if (autogroup)
fprintf(f, "<autogroup state='1' />\n");
fprintf(f, "</settings>\n<dives>\n"); fprintf(f, "</settings>\n<dives>\n");
for (trip = dive_trip_list; trip != NULL; trip = trip->next) for (trip = dive_trip_list; trip != NULL; trip = trip->next)