summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c153
1 files changed, 23 insertions, 130 deletions
diff --git a/main.c b/main.c
index a57e12981..510dbfa68 100644
--- a/main.c
+++ b/main.c
@@ -10,7 +10,10 @@
#include "dive.h"
#include "divelist.h"
+#ifdef USE_GTK_UI
#include <osm-gps-map.h>
+#endif
+
#ifdef DEBUGFILE
char *debugfilename;
FILE *debugfile;
@@ -36,7 +39,9 @@ struct preferences default_prefs = {
.calc_ceiling_3m_incr = FALSE,
.gflow = 0.30,
.gfhigh = 0.75,
+#ifdef USE_GTK_UI
.map_provider = OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID,
+#endif
};
/* random helper functions, used here or elsewhere */
@@ -77,137 +82,10 @@ const char *monthname(int mon)
}
/*
- * When adding dives to the dive table, we try to renumber
- * the new dives based on any old dives in the dive table.
- *
- * But we only do it if:
- *
- * - there are no dives in the dive table
- *
- * OR
- *
- * - the last dive in the old dive table was numbered
- *
- * - all the new dives are strictly at the end (so the
- * "last dive" is at the same location in the dive table
- * after re-sorting the dives.
- *
- * - none of the new dives have any numbers
- *
- * This catches the common case of importing new dives from
- * a dive computer, and gives them proper numbers based on
- * your old dive list. But it tries to be very conservative
- * and not give numbers if there is *any* question about
- * what the numbers should be - in which case you need to do
- * a manual re-numbering.
- */
-static void try_to_renumber(struct dive *last, int preexisting)
-{
- int i, nr;
-
- /*
- * If the new dives aren't all strictly at the end,
- * we're going to expect the user to do a manual
- * renumbering.
- */
- if (preexisting && get_dive(preexisting-1) != last)
- return;
-
- /*
- * If any of the new dives already had a number,
- * we'll have to do a manual renumbering.
- */
- for (i = preexisting; i < dive_table.nr; i++) {
- struct dive *dive = get_dive(i);
- if (dive->number)
- return;
- }
-
- /*
- * Ok, renumber..
- */
- if (last)
- nr = last->number;
- else
- nr = 0;
- for (i = preexisting; i < dive_table.nr; i++) {
- struct dive *dive = get_dive(i);
- dive->number = ++nr;
- }
-}
-
-/*
* track whether we switched to importing dives
*/
static gboolean imported = FALSE;
-/*
- * This doesn't really report anything at all. We just sort the
- * dives, the GUI does the reporting
- */
-void report_dives(gboolean is_imported, gboolean prefer_imported)
-{
- int i;
- int preexisting = dive_table.preexisting;
- struct dive *last;
-
- /* check if we need a nickname for the divecomputer for newly downloaded dives;
- * since we know they all came from the same divecomputer we just check for the
- * first one */
- if (preexisting < dive_table.nr && dive_table.dives[preexisting]->downloaded)
- set_dc_nickname(dive_table.dives[preexisting]);
- else
- /* they aren't downloaded, so record / check all new ones */
- for (i = preexisting; i < dive_table.nr; i++)
- set_dc_nickname(dive_table.dives[i]);
-
- /* This does the right thing for -1: NULL */
- last = get_dive(preexisting-1);
-
- sort_table(&dive_table);
-
- for (i = 1; i < dive_table.nr; i++) {
- struct dive **pp = &dive_table.dives[i-1];
- struct dive *prev = pp[0];
- struct dive *dive = pp[1];
- struct dive *merged;
-
- /* only try to merge overlapping dives - or if one of the dives has
- * zero duration (that might be a gps marker from the webservice) */
- if (prev->duration.seconds && dive->duration.seconds &&
- prev->when + prev->duration.seconds < dive->when)
- continue;
-
- merged = try_to_merge(prev, dive, prefer_imported);
- if (!merged)
- continue;
-
- /* careful - we might free the dive that last points to. Oops... */
- if (last == prev || last == dive)
- last = merged;
-
- /* Redo the new 'i'th dive */
- i--;
- add_single_dive(i, merged);
- delete_single_dive(i+1);
- delete_single_dive(i+1);
- }
- /* make sure no dives are still marked as downloaded */
- for (i = 1; i < dive_table.nr; i++)
- dive_table.dives[i]->downloaded = FALSE;
-
- if (is_imported) {
- /* If there are dives in the table, are they numbered */
- if (!last || last->number)
- try_to_renumber(last, preexisting);
-
- /* did we add dives to the dive table? */
- if (preexisting != dive_table.nr)
- mark_divelist_changed(TRUE);
- }
- dive_list_update_dives();
-}
-
static void parse_argument(const char *arg)
{
const char *p = arg+1;
@@ -222,7 +100,11 @@ static void parse_argument(const char *arg)
if (strcmp(arg,"--import") == 0) {
/* mark the dives so far as the base,
* everything after is imported */
+#if USE_GTK_UI
report_dives(FALSE, FALSE);
+#else
+ process_dives(FALSE, FALSE);
+#endif
imported = TRUE;
return;
}
@@ -242,6 +124,7 @@ static void parse_argument(const char *arg)
void update_dive(struct dive *new_dive)
{
+#if USE_GTK_UI
static struct dive *buffered_dive;
struct dive *old_dive = buffered_dive;
@@ -252,6 +135,7 @@ void update_dive(struct dive *new_dive)
show_dive_equipment(new_dive, W_IDX_PRIMARY);
show_dive_stats(new_dive);
buffered_dive = new_dive;
+#endif
}
void renumber_dives(int nr)
@@ -261,7 +145,9 @@ void renumber_dives(int nr)
for (i = 0; i < dive_table.nr; i++) {
struct dive *dive = dive_table.dives[i];
dive->number = nr + i;
+#if USE_GTK_UI
flush_divelist(dive);
+#endif
}
mark_divelist_changed(TRUE);
}
@@ -331,7 +217,7 @@ int main(int argc, char **argv)
subsurface_command_line_init(&argc, &argv);
parse_xml_init();
- init_ui(&argc, &argv);
+ init_ui(&argc, &argv); /* the gtk stuff is needed for parsing below */
for (i = 1; i < argc; i++) {
const char *a = argv[i];
@@ -352,7 +238,9 @@ int main(int argc, char **argv)
}
if (error != NULL)
{
+#if USE_GTK_UI
report_error(error);
+#endif
g_error_free(error);
error = NULL;
}
@@ -365,15 +253,20 @@ int main(int argc, char **argv)
sure we remember this as the filename in use */
set_filename(filename, FALSE);
}
+#if USE_GTK_UI
report_dives(imported, FALSE);
if (dive_table.nr == 0)
show_dive_info(NULL);
- run_ui();
- exit_ui();
+#else
+ process_dives(imported, FALSE);
+#endif
parse_xml_exit();
subsurface_command_line_exit(&argc, &argv);
+ init_qt_ui(&argc, &argv); /* qt bit delayed until dives are parsed */
+ run_ui();
+ exit_ui();
#ifdef DEBUGFILE
if (debugfile)
fclose(debugfile);