From b73f29fea3ae88a06d8f773a6d48510520c127f0 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 9 Sep 2012 09:06:44 -0700 Subject: First cut of adding a default file name The default file name is OS specific and tries to follow the customs on each of the OSs. It can be configured through the preferences dialog. On MacOS we get a strange warning which appears to be a well documented Gtk bug on MacOS. Signed-off-by: Dirk Hohndel --- main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 2489473b9..a2c24ec99 100644 --- a/main.c +++ b/main.c @@ -211,6 +211,7 @@ void renumber_dives(int nr) int main(int argc, char **argv) { int i; + gboolean no_filenames = TRUE; output_units = SI_units; @@ -225,6 +226,7 @@ int main(int argc, char **argv) parse_argument(a); continue; } + no_filenames = FALSE; GError *error = NULL; parse_file(a, &error); @@ -235,7 +237,14 @@ int main(int argc, char **argv) error = NULL; } } - + if (no_filenames) { + GError *error = NULL; + const char *filename = subsurface_default_filename(); + parse_file(filename, &error); + /* don't report errors - this file may not exist, but make + sure we remember this as the filename in use */ + set_filename(filename); + } report_dives(imported); run_ui(); -- cgit v1.2.3-70-g09d2 From 78c5aa9f071ab56e56bf760e3e7fc7f0f0d1b1ff Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 10 Sep 2012 12:27:00 -0700 Subject: Change behavior for the existing filename Previously we always picked the last file that was openend as the file name to save to. That seems counterintuitive when importing files or when opening multiple files. Especially if Subsurface was executed without a file on the command line and we are using the default file. Now we only remember a file name if it was the first one to ever be openend or if it was used in save-as. Signed-off-by: Dirk Hohndel --- dive.h | 2 +- gtk-gui.c | 10 +++++----- main.c | 2 +- parse-xml.c | 5 ++--- 4 files changed, 9 insertions(+), 10 deletions(-) (limited to 'main.c') diff --git a/dive.h b/dive.h index 746b94093..af141bbde 100644 --- a/dive.h +++ b/dive.h @@ -379,7 +379,7 @@ static inline struct dive *get_dive(unsigned int nr) extern void parse_xml_init(void); extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error); -extern void set_filename(const char *filename); +extern void set_filename(const char *filename, gboolean force); extern void parse_file(const char *filename, GError **error); diff --git a/gtk-gui.c b/gtk-gui.c index 1d5fc4cc9..6666f5560 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -233,7 +233,7 @@ static void file_save_as(GtkWidget *w, gpointer data) if (filename){ save_dives(filename); - set_filename(filename); + set_filename(filename, TRUE); g_free(filename); mark_divelist_changed(FALSE); } @@ -1419,11 +1419,11 @@ void update_progressbar_text(progressbar_t *progress, const char *text) gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), text); } -void set_filename(const char *filename) +void set_filename(const char *filename, gboolean force) { - if (existing_filename) - free(existing_filename); - existing_filename = NULL; + if (!force && existing_filename) + return; + free(existing_filename); if (filename) existing_filename = strdup(filename); } diff --git a/main.c b/main.c index a2c24ec99..01306b1bf 100644 --- a/main.c +++ b/main.c @@ -243,7 +243,7 @@ int main(int argc, char **argv) parse_file(filename, &error); /* don't report errors - this file may not exist, but make sure we remember this as the filename in use */ - set_filename(filename); + set_filename(filename, FALSE); } report_dives(imported); diff --git a/parse-xml.c b/parse-xml.c index 1c4db7d9d..a4ae81b25 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -1475,9 +1475,8 @@ void parse_xml_buffer(const char *url, const char *buffer, int size, GError **er } return; } - /* we assume that the last (or only) filename passed as argument is a - * great filename to use as default when saving the dives */ - set_filename(url); + /* remember, if necessary, that this is the filename to store to */ + set_filename(url, FALSE); reset_all(); dive_start(); #ifdef XSLT -- cgit v1.2.3-70-g09d2 From b4d55c8b598b648acda0f8107868b8753283c72e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 10 Sep 2012 14:44:48 -0700 Subject: Change the definition of "dive table changed" We only ask to save changes if the dive table was changed. Yet we didn't consider the dive table changed if it was initially empty. So starting with an empty file and making changes we were quitting without saving. Signed-off-by: Dirk Hohndel --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 01306b1bf..46e22041d 100644 --- a/main.c +++ b/main.c @@ -140,8 +140,8 @@ void report_dives(gboolean is_imported) if (last && last->number) try_to_renumber(last, preexisting); - /* did we have dives in the table and added more? */ - if (last && preexisting != dive_table.nr) + /* did we add dives to the dive table? */ + if (preexisting != dive_table.nr) mark_divelist_changed(TRUE); } dive_table.preexisting = dive_table.nr; -- cgit v1.2.3-70-g09d2 From 0d637c2fa915d13af8e00d5f236d3f111101c6e3 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 15 Sep 2012 18:05:43 -0700 Subject: Show the datafile name even with no dives That's especially useful if starting without a filename and without an existing default file - this way it's clear that Subsurface still considers itself synced with the default file. Signed-off-by: Dirk Hohndel --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 46e22041d..d66972cdc 100644 --- a/main.c +++ b/main.c @@ -246,7 +246,7 @@ int main(int argc, char **argv) set_filename(filename, FALSE); } report_dives(imported); - + show_dive_info(NULL); run_ui(); exit_ui(); return 0; -- cgit v1.2.3-70-g09d2 From fa2f1b6eb06e65e6426cc3a488c6cb5c960e7d49 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 15 Sep 2012 20:47:53 -0700 Subject: Fix potential crash when importing dives If the last of the preexisting dives gets merged with a new dive we end up dereferencing a freed pointer. Signed-off-by: Dirk Hohndel --- main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index d66972cdc..3d9b43b41 100644 --- a/main.c +++ b/main.c @@ -125,6 +125,9 @@ void report_dives(gboolean is_imported) if (!merged) continue; + /* careful - we might free the dive that last points to. Oops... */ + if (last == prev || last == dive) + last = merged; free(prev); free(dive); *pp = merged; -- cgit v1.2.3-70-g09d2 From d7465129bb7fc912ec89671051192983b80711c4 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 16 Sep 2012 06:04:37 -0400 Subject: Make sure dive info is displayed correctly at start Commit cdae2869d1dd ("Show the datafile name even with no dives") was a little too aggressive in making sure that we show the correct window title - we only should call show_dive_info(NULL) if there is indeed no dive in the dive table - otherwise we display empty dive info at program start. Signed-off-by: Dirk Hohndel --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 3d9b43b41..2bdccd277 100644 --- a/main.c +++ b/main.c @@ -249,7 +249,8 @@ int main(int argc, char **argv) set_filename(filename, FALSE); } report_dives(imported); - show_dive_info(NULL); + if (dive_table.nr == 0) + show_dive_info(NULL); run_ui(); exit_ui(); return 0; -- cgit v1.2.3-70-g09d2