X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=gtk-gui.c;h=f28dde4844d5de2ce134844ae2d701d9603a4cf0;hb=76298c64e374b65711734ae42ed455fb18aab702;hp=98c0111eab530ef11de4027f54217f45eed45a27;hpb=e7a70b6ae821e6a178957e2814406ac387b990ea;p=ext%2Fsubsurface.git diff --git a/gtk-gui.c b/gtk-gui.c index 98c0111..f28dde4 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -31,21 +31,43 @@ static GtkWidget *dive_profile; visible_cols_t visible_cols = {TRUE, FALSE}; -static const char *default_dive_computer; +static const char *default_dive_computer_vendor; +static const char *default_dive_computer_product; +static const char *default_dive_computer_device; -static int is_default_dive_computer(const char *name) +static int is_default_dive_computer(const char *vendor, const char *product) { - return default_dive_computer && !strcmp(name, default_dive_computer); + return default_dive_computer_vendor && !strcmp(vendor, default_dive_computer_vendor) && + default_dive_computer_product && !strcmp(product, default_dive_computer_product); } -static void set_default_dive_computer(const char *name) +static int is_default_dive_computer_device(const char *name) +{ + return default_dive_computer_device && !strcmp(name, default_dive_computer_device); +} + +static void set_default_dive_computer(const char *vendor, const char *product) +{ + if (!vendor || !*vendor) + return; + if (!product || !*product) + return; + if (is_default_dive_computer(vendor, product)) + return; + default_dive_computer_vendor = vendor; + default_dive_computer_product = product; + subsurface_set_conf("dive_computer_vendor", PREF_STRING, vendor); + subsurface_set_conf("dive_computer_product", PREF_STRING, product); +} + +static void set_default_dive_computer_device(const char *name) { if (!name || !*name) return; - if (is_default_dive_computer(name)) + if (is_default_dive_computer_device(name)) return; - default_dive_computer = name; - subsurface_set_conf("dive_computer", PREF_STRING, name); + default_dive_computer_device = name; + subsurface_set_conf("dive_computer_device", PREF_STRING, name); } void repaint_dive(void) @@ -151,26 +173,28 @@ static void file_open(GtkWidget *w, gpointer data) static void file_save(GtkWidget *w, gpointer data) { GtkWidget *dialog; - dialog = gtk_file_chooser_dialog_new("Save File", + char *filename; + if (!existing_filename) { + dialog = gtk_file_chooser_dialog_new("Save File", GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); - if (!existing_filename) { - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document"); - } else - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), existing_filename); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *filename; - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document"); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + } + gtk_widget_destroy(dialog); + } else { + filename = existing_filename; + } + if (filename){ save_dives(filename); - g_free(filename); mark_divelist_changed(FALSE); } - gtk_widget_destroy(dialog); } static void ask_save_changes() @@ -182,7 +206,18 @@ static void ask_save_changes() GTK_STOCK_NO, GTK_RESPONSE_NO, 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?"); + + if (!existing_filename){ + label = gtk_label_new ( + "You have unsaved changes\nWould you like to save those before exiting the program?"); + } else { + char *label_text = (char*) malloc(sizeof(char) * (92 + strlen(existing_filename))); + sprintf(label_text, + "You have unsaved changes to file: %s \nWould you like to save those before exiting the program?", + existing_filename); + label = gtk_label_new (label_text); + g_free(label_text); + } gtk_container_add (GTK_CONTAINER (content), label); gtk_widget_show_all (dialog); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); @@ -326,6 +361,8 @@ OPTIONCALLBACK(otu_toggle, visible_cols.otu) OPTIONCALLBACK(sac_toggle, visible_cols.sac) OPTIONCALLBACK(nitrox_toggle, visible_cols.nitrox) OPTIONCALLBACK(temperature_toggle, visible_cols.temperature) +OPTIONCALLBACK(totalweight_toggle, visible_cols.totalweight) +OPTIONCALLBACK(suit_toggle, visible_cols.suit) OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder) static void event_toggle(GtkWidget *w, gpointer _data) @@ -381,37 +418,47 @@ static void preferences_dialog(GtkWidget *w, gpointer data) "lbs", set_lbs, (output_units.weight == LBS), NULL); - frame = gtk_frame_new("Columns"); + frame = gtk_frame_new("Show 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 Temp"); + button = gtk_check_button_new_with_label("Temp"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.temperature); gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(temperature_toggle), NULL); - button = gtk_check_button_new_with_label("Show Cyl"); + button = gtk_check_button_new_with_label("Cyl"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.cylinder); gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(cylinder_toggle), NULL); - button = gtk_check_button_new_with_label("Show O" UTF8_SUBSCRIPT_2 "%"); + button = gtk_check_button_new_with_label("O" UTF8_SUBSCRIPT_2 "%"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.nitrox); gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(nitrox_toggle), NULL); - button = gtk_check_button_new_with_label("Show SAC"); + button = gtk_check_button_new_with_label("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"); + button = gtk_check_button_new_with_label("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); + button = gtk_check_button_new_with_label("Weight"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.totalweight); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(totalweight_toggle), NULL); + + button = gtk_check_button_new_with_label("Suit"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.suit); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(suit_toggle), NULL); + font = gtk_font_button_new_with_font(divelist_font); gtk_box_pack_start(GTK_BOX(vbox), font, FALSE, FALSE, 5); @@ -435,6 +482,8 @@ static void preferences_dialog(GtkWidget *w, gpointer data) subsurface_set_conf("fahrenheit", PREF_BOOL, BOOL_TO_PTR(output_units.temperature == FAHRENHEIT)); subsurface_set_conf("lbs", PREF_BOOL, BOOL_TO_PTR(output_units.weight == LBS)); subsurface_set_conf("TEMPERATURE", PREF_BOOL, BOOL_TO_PTR(visible_cols.temperature)); + subsurface_set_conf("TOTALWEIGHT", PREF_BOOL, BOOL_TO_PTR(visible_cols.totalweight)); + subsurface_set_conf("SUIT", PREF_BOOL, BOOL_TO_PTR(visible_cols.suit)); subsurface_set_conf("CYLINDER", PREF_BOOL, BOOL_TO_PTR(visible_cols.cylinder)); subsurface_set_conf("NITROX", PREF_BOOL, BOOL_TO_PTR(visible_cols.nitrox)); subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac)); @@ -604,6 +653,7 @@ static GtkActionEntry menu_items[] = { { "SaveFile", GTK_STOCK_SAVE, NULL, CTRLCHAR "S", NULL, G_CALLBACK(file_save) }, { "Print", GTK_STOCK_PRINT, NULL, CTRLCHAR "P", NULL, G_CALLBACK(do_print) }, { "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) }, + { "AddDive", NULL, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) }, { "Preferences", NULL, "Preferences", PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) }, { "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) }, { "SelectEvents", NULL, "SelectEvents", NULL, NULL, G_CALLBACK(selectevents_dialog) }, @@ -630,6 +680,7 @@ static const gchar* ui_string = " \ \