X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=gtk-gui.c;h=77e46c952da358e983caeb8c8102b81d91e507b5;hb=f3134cbb8995267e6a18b9564f3022e7fe7314a9;hp=77cf4a9ec49edf7bd904cc9cffb9cce9ee461a8e;hpb=682135838ff313594c7f67fabd9be8f88a33883b;p=ext%2Fsubsurface.git diff --git a/gtk-gui.c b/gtk-gui.c index 77cf4a9..77e46c9 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -31,13 +31,10 @@ struct units output_units; #define GCONF_NAME(x) "/apps/subsurface/" #x -void on_destroy(GtkWidget* w, gpointer data) -{ - gtk_main_quit(); -} - static GtkWidget *dive_profile; +visible_cols_t visible_cols = {TRUE, FALSE}; + void repaint_dive(void) { update_dive(current_dive); @@ -146,23 +143,64 @@ static void file_save(GtkWidget *w, gpointer data) filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); save_dives(filename); g_free(filename); + mark_divelist_changed(FALSE); + } + gtk_widget_destroy(dialog); +} + +static void ask_save_changes() +{ + GtkWidget *dialog, *label, *content; + dialog = gtk_dialog_new_with_buttons("Save Changes?", + GTK_WINDOW(main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + NULL); + content = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + label = gtk_label_new ("You have unsaved changes\nWould you like to save those before exiting the program?"); + gtk_container_add (GTK_CONTAINER (content), label); + gtk_widget_show_all (dialog); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + file_save(NULL,NULL); } gtk_widget_destroy(dialog); } +static gboolean on_delete(GtkWidget* w, gpointer data) +{ + /* Make sure to flush any modified dive data */ + update_dive(NULL); + + if (unsaved_changes()) + ask_save_changes(); + + return FALSE; /* go ahead, kill the program, we're good now */ +} + +static void on_destroy(GtkWidget* w, gpointer data) +{ + gtk_main_quit(); +} + static void quit(GtkWidget *w, gpointer data) { + /* Make sure to flush any modified dive data */ + update_dive(NULL); + + if (unsaved_changes()) + ask_save_changes(); gtk_main_quit(); } -static void create_radio(GtkWidget *dialog, const char *name, ...) +static void create_radio(GtkWidget *vbox, const char *name, ...) { va_list args; GtkRadioButton *group = NULL; GtkWidget *box, *label; box = gtk_hbox_new(TRUE, 10); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box); + gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0); label = gtk_label_new(name); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); @@ -207,10 +245,19 @@ UNITCALLBACK(set_cuft, volume, CUFT) UNITCALLBACK(set_celsius, temperature, CELSIUS) UNITCALLBACK(set_fahrenheit, temperature, FAHRENHEIT) +#define OPTIONCALLBACK(name, option) \ +static void name(GtkWidget *w, gpointer data) \ +{ \ + option = GTK_TOGGLE_BUTTON(w)->active; \ +} + +OPTIONCALLBACK(otu_toggle, visible_cols.otu) +OPTIONCALLBACK(sac_toggle, visible_cols.sac) + static void preferences_dialog(GtkWidget *w, gpointer data) { int result; - GtkWidget *dialog, *font, *frame, *box; + GtkWidget *dialog, *font, *frame, *box, *button; menu_units = output_units; @@ -247,6 +294,22 @@ static void preferences_dialog(GtkWidget *w, gpointer data) "Fahrenheit", set_fahrenheit, (output_units.temperature == FAHRENHEIT), NULL); + frame = gtk_frame_new("Columns"); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5); + + box = gtk_hbox_new(FALSE, 6); + gtk_container_add(GTK_CONTAINER(frame), box); + + button = gtk_check_button_new_with_label("Show SAC"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.sac); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(sac_toggle), NULL); + + button = gtk_check_button_new_with_label("Show OTU"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.otu); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(otu_toggle), NULL); + font = gtk_font_button_new_with_font(divelist_font); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), font, FALSE, FALSE, 5); @@ -262,10 +325,13 @@ static void preferences_dialog(GtkWidget *w, gpointer data) output_units = menu_units; update_dive_list_units(); repaint_dive(); + update_dive_list_col_visibility(); gconf_client_set_bool(gconf, GCONF_NAME(feet), output_units.length == FEET, NULL); gconf_client_set_bool(gconf, GCONF_NAME(psi), output_units.pressure == PSI, NULL); gconf_client_set_bool(gconf, GCONF_NAME(cuft), output_units.volume == CUFT, NULL); gconf_client_set_bool(gconf, GCONF_NAME(fahrenheit), output_units.temperature == FAHRENHEIT, NULL); + gconf_client_set_bool(gconf, GCONF_NAME(SAC), ! visible_cols.sac, NULL); /* inverted to get the correct default */ + gconf_client_set_bool(gconf, GCONF_NAME(OTU), visible_cols.otu, NULL); gconf_client_set_string(gconf, GCONF_NAME(divelist_font), divelist_font, NULL); } gtk_widget_destroy(dialog); @@ -379,7 +445,11 @@ void init_ui(int argc, char **argv) output_units.volume = CUFT; if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL)) output_units.temperature = FAHRENHEIT; - + /* an unset key is FALSE - so in order to get the default behavior right we + invert the meaning of the SAC key */ + visible_cols.otu = gconf_client_get_bool(gconf, GCONF_NAME(OTU), NULL); + visible_cols.sac = ! gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL); + divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL); if (!divelist_font) divelist_font = DIVELIST_DEFAULT_FONT; @@ -387,6 +457,7 @@ void init_ui(int argc, char **argv) error_info_bar = NULL; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_icon_from_file(GTK_WINDOW(win), "icon.svg", NULL); + g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK (on_delete), NULL); g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL); main_window = win; @@ -614,3 +685,11 @@ void update_progressbar(progressbar_t *progress, double value) { gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value); } + + +void set_filename(const char *filename) +{ + if (filename) + existing_filename = strdup(filename); + return; +}