mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Remember the default dive computer setting
Always having to re-select the same dive computer got really annoying when I had trouble importing the dives. Let's not force the user to do that, since we could just remember the last dive computer used, and default to that one. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
725e4582d9
commit
c8f3dc3594
1 changed files with 30 additions and 4 deletions
34
gtk-gui.c
34
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);
|
||||
|
@ -691,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");
|
||||
|
@ -874,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)
|
||||
|
@ -894,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);
|
||||
|
@ -911,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);
|
||||
}
|
||||
|
||||
|
@ -1040,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);
|
||||
|
|
Loading…
Add table
Reference in a new issue