From: Linus Torvalds Date: Tue, 28 Aug 2012 20:16:57 +0000 (-0700) Subject: Merge git://git.tdb.fi/ext/subsurface X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e4955f9be116cd413e8ee3986d737e9e1b95e348;hp=-c;p=ext%2Fsubsurface.git Merge git://git.tdb.fi/ext/subsurface Pull a few buglet fixes from Mikko Rasa. Some trivial conflicts due to changes in the dive selection logic, and using the new "for_each_dive()" helper. * git://git.tdb.fi/ext/subsurface: Check if multi-dive editing is actually needed Fix an off-by-one error in buffer allocation --- e4955f9be116cd413e8ee3986d737e9e1b95e348 diff --combined gtk-gui.c index bc8e6e0,ac80a47..2a4d77a --- a/gtk-gui.c +++ b/gtk-gui.c @@@ -98,7 -98,7 +98,7 @@@ void report_error(GError* error { return; } - + if (error_info_bar == NULL) { error_count = 1; @@@ -108,11 -108,11 +108,11 @@@ g_signal_connect(error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL); gtk_info_bar_set_message_type(GTK_INFO_BAR(error_info_bar), GTK_MESSAGE_ERROR); - + error_label = gtk_label_new(error->message); GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(error_info_bar)); gtk_container_add(GTK_CONTAINER(container), error_label); - + gtk_box_pack_start(GTK_BOX(main_vbox), error_info_bar, FALSE, FALSE, 0); gtk_widget_show_all(main_vbox); } @@@ -151,7 -151,7 +151,7 @@@ static void file_open(GtkWidget *w, gpo GSList *filenames, *fn_glist; char *filename; filenames = fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); - + GError *error = NULL; while(filenames != NULL) { filename = filenames->data; @@@ -162,7 -162,7 +162,7 @@@ g_error_free(error); error = NULL; } - + g_free(filename); filenames = g_slist_next(filenames); } @@@ -172,43 -172,10 +172,43 @@@ gtk_widget_destroy(dialog); } +/* return the path and the file component contained in the full path */ +static char *path_and_file(char *pathin, char **fileout) { + char *slash = pathin, *next; + char *result; + size_t len, n; + + if (! pathin) { + *fileout = strdup(""); + return strdup(""); + } + while ((next = strpbrk(slash + 1, "\\/"))) + slash = next; + if (pathin != slash) + slash++; + *fileout = strdup(slash); + + /* strndup(pathin, slash - pathin) */ + n = slash - pathin; + len = strlen(pathin); + if (n < len) + len = n; + + result = (char *)malloc(len + 1); + if (!result) + return 0; + + result[len] = '\0'; + return (char *)memcpy(result, pathin, len); +} + static void file_save_as(GtkWidget *w, gpointer data) { GtkWidget *dialog; char *filename = NULL; + char *current_file; + char *current_dir; + dialog = gtk_file_chooser_dialog_new("Save File As", GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_SAVE, @@@ -217,13 -184,7 +217,13 @@@ NULL); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), existing_filename); + current_dir = path_and_file(existing_filename, ¤t_file); + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), current_dir); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), current_file); + + free(current_dir); + free(current_file); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); } @@@ -262,7 -223,7 +262,7 @@@ static gboolean ask_save_changes( 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))); + char *label_text = (char*) malloc(sizeof(char) * (93 + 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); @@@ -428,7 -389,6 +428,7 @@@ OPTIONCALLBACK(temperature_toggle, visi OPTIONCALLBACK(totalweight_toggle, visible_cols.totalweight) OPTIONCALLBACK(suit_toggle, visible_cols.suit) OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder) +OPTIONCALLBACK(autogroup_toggle, autogroup) static void event_toggle(GtkWidget *w, gpointer _data) { @@@ -524,22 -484,8 +524,22 @@@ static void preferences_dialog(GtkWidge gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(suit_toggle), NULL); + frame = gtk_frame_new("Divelist Font"); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5); + font = gtk_font_button_new_with_font(divelist_font); - gtk_box_pack_start(GTK_BOX(vbox), font, FALSE, FALSE, 5); + gtk_container_add(GTK_CONTAINER(frame),font); + + frame = gtk_frame_new("Misc. Options"); + 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("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); gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); @@@ -568,7 -514,6 +568,7 @@@ subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac)); subsurface_set_conf("OTU", PREF_BOOL, BOOL_TO_PTR(visible_cols.otu)); subsurface_set_conf("divelist_font", PREF_STRING, divelist_font); + subsurface_set_conf("autogroup", PREF_BOOL, BOOL_TO_PTR(autogroup)); /* Flush the changes out to the system */ subsurface_flush_conf(); @@@ -849,8 -794,6 +849,8 @@@ void init_ui(int *argcp, char ***argvp divelist_font = subsurface_get_conf("divelist_font", PREF_STRING); + autogroup = PTR_TO_BOOL(subsurface_get_conf("autogroup", PREF_BOOL)); + default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING); default_dive_computer_product = subsurface_get_conf("dive_computer_product", PREF_STRING); default_dive_computer_device = subsurface_get_conf("dive_computer_device", PREF_STRING); diff --combined info.c index cccc649,66e4f0a..d9379ac --- a/info.c +++ b/info.c @@@ -1,7 -1,7 +1,7 @@@ /* info.c */ -/* creates the UI for the info frame - +/* creates the UI for the info frame - * controlled through the following interfaces: - * + * * void show_dive_info(struct dive *dive) * * called from gtk-ui: @@@ -166,7 -166,7 +166,7 @@@ static int delete_dive_info(struct div static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data) { - edit_multi_dive_info(-1); + edit_multi_dive_info(NULL); } static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data) @@@ -482,7 -482,7 +482,7 @@@ void update_equipment_data(struct dive if ( ! cylinders_equal(remember_cyl, master->cylinder) && (no_cylinders(dive->cylinder) || cylinders_equal(dive->cylinder, remember_cyl))) - memcpy(dive->cylinder, master->cylinder, CYL_BYTES); + copy_cylinders(master->cylinder, dive->cylinder); if (! weightsystems_equal(remember_ws, master->weightsystem) && (no_weightsystems(dive->weightsystem) || weightsystems_equal(dive->weightsystem, remember_ws))) @@@ -490,12 -490,13 +490,13 @@@ } /* A negative index means "all selected" */ -int edit_multi_dive_info(int index) +int edit_multi_dive_info(struct dive *single_dive) { int success; GtkWidget *dialog, *vbox; struct dive_info info; struct dive *master; + gboolean multi; dialog = gtk_dialog_new_with_buttons("Dive Info", GTK_WINDOW(main_window), @@@ -505,21 -506,37 +506,36 @@@ NULL); vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - master = get_dive(index); + master = single_dive; if (!master) master = current_dive; - dive_info_widget(vbox, master, &info, !single_dive); + + /* See if we should use multi dive mode */ + multi = FALSE; - if (index < 0) - { ++ if (!single_dive) { + int i; + struct dive *dive; + - for (i = 0; (dive = get_dive(i)) != NULL; i++) { ++ for_each_dive(i, dive) { + if (dive != master && dive->selected) { + multi = TRUE; + break; + } + } + } + + dive_info_widget(vbox, master, &info, multi); show_dive_equipment(master, W_IDX_SECONDARY); save_equipment_data(master); gtk_widget_show_all(dialog); success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT; if (success) { /* Update the non-current selected dives first */ - if (index < 0) { + if (!single_dive) { int i; struct dive *dive; - for (i = 0; (dive = get_dive(i)) != NULL; i++) { + for_each_dive(i, dive) { if (dive == master || !dive->selected) continue; /* copy all "info" fields */ @@@ -544,9 -561,12 +560,9 @@@ int edit_dive_info(struct dive *dive) { - int idx; - if (!dive) return 0; - idx = dive->number; - return edit_multi_dive_info(idx); + return edit_multi_dive_info(dive); } static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)