summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-27 11:58:13 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-27 11:58:13 -0800
commit1cbffeaaf5a92792beac0e4848082910c82e9498 (patch)
tree1c2a574c8ec7e363524c266a7b7c7eb05aa4f2f4 /info.c
parent3f261f56f3401695d0577598624dddc09243b371 (diff)
downloadsubsurface-1cbffeaaf5a92792beac0e4848082910c82e9498.tar.gz
Allow manual entry of GPS coordinates
This implementation gives the user the ability to add GPS coordinates to the dive location. It works as expected in multi-dive edit scenarios. It has two major flaws: - it only support WGS84 style coordinates - it should instead be intelligent enough to parse the common formats, at least using NSEW instead of sign and understanding minutes and seconds instead of decimal degrees - but in reality, it really needs to support a map picker Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'info.c')
-rw-r--r--info.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/info.c b/info.c
index 7b5298a32..49caf748b 100644
--- a/info.c
+++ b/info.c
@@ -394,15 +394,43 @@ static int get_rating(const char *string)
return rating_val;
}
+static gboolean gps_changed(struct dive *dive, struct dive *master, const char *gps_text)
+{
+ double latitude, longitude;
+ int latudeg, longudeg;
+
+ /* if we have a master and the dive's gps address is different from it,
+ * don't change the dive */
+ if (master && (master->latitude.udeg != dive->latitude.udeg ||
+ master->longitude.udeg != dive->longitude.udeg))
+ return FALSE;
+ if (sscanf(gps_text, "%lf,%lf", &latitude, &longitude) != 2)
+ return FALSE;
+ latudeg = 1000000 * latitude + 0.5;
+ longudeg = 1000000 * longitude + 0.5;
+
+ /* if master gps didn't change, don't change dive */
+ if (master && master->latitude.udeg == latudeg && master->longitude.udeg == longudeg)
+ return FALSE;
+ /* if dive gps didn't change, nothing changed */
+ if (dive->latitude.udeg == latudeg && dive->longitude.udeg == longudeg)
+ return FALSE;
+ /* ok, update the dive and mark things changed */
+ dive->latitude.udeg = latudeg;
+ dive->longitude.udeg = longudeg;
+ return TRUE;
+}
+
struct dive_info {
GtkComboBoxEntry *location, *divemaster, *buddy, *rating, *suit, *viz;
- GtkEntry *airtemp;
+ GtkEntry *airtemp, *gps;
GtkTextView *notes;
};
static void save_dive_info_changes(struct dive *dive, struct dive *master, struct dive_info *info)
{
char *old_text, *new_text;
+ const char *gps_text;
char *rating_string;
double newtemp;
int changed = 0;
@@ -413,6 +441,10 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc
changed = 1;
}
+ gps_text = gtk_entry_get_text(info->gps);
+ if (gps_changed(dive, master, gps_text))
+ changed = 1;
+
new_text = get_combo_box_entry_text(info->divemaster, &dive->divemaster, master->divemaster);
if (new_text) {
add_people(new_text);
@@ -503,6 +535,7 @@ static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info
GtkWidget *hbox, *label, *frame, *equipment;
char buffer[128];
char airtemp[6];
+ char gps_text[25] = "";
const char *unit;
double value;
@@ -515,6 +548,11 @@ static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info
info->location = text_entry(box, _("Location"), location_list, dive->location);
+ if (dive_has_location(dive))
+ snprintf(gps_text, sizeof(gps_text), "%3.5lf,%3.5lf", dive->latitude.udeg / 1000000.0,
+ dive->longitude.udeg / 1000000.0);
+ info->gps = single_text_entry(box, _("GPS"), gps_text);
+
hbox = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);