From b64ae944b219b31f47f016fd7ab47036db3686ed Mon Sep 17 00:00:00 2001 From: Thomas Thurman Date: Fri, 28 Aug 2009 17:42:23 -0400 Subject: [PATCH] Only show distance if we know where we are --- belltower.c | 65 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/belltower.c b/belltower.c index d4b80e8..d099154 100644 --- a/belltower.c +++ b/belltower.c @@ -20,6 +20,8 @@ GtkWidget *window; +LocationGPSDevice *device; + typedef enum { /** stop scanning the database */ FILTER_STOP, @@ -87,6 +89,7 @@ typedef struct { * we're going to pretend you're in Helsinki * until I get the GPS working */ +gboolean gps_working = FALSE; double current_lat = 60.161790; double current_long = 23.924902; @@ -466,18 +469,29 @@ static FoundTower * found_tower_new (tower *basis) { FoundTower* result = g_new (FoundTower, 1); - gchar *distance = distance_to_tower (basis); result->sortkey = g_strdup (basis->fields[FieldPrimaryKey]); result->primarykey = g_strdup (basis->fields[FieldPrimaryKey]); - result->displayname = g_strdup_printf ("%s, %s (%s, %s) (%s)", - basis->fields[FieldDedication], - basis->fields[FieldPlace], - basis->fields[FieldBells], - basis->fields[FieldPracticeNight], - distance); - g_free (distance); + if (gps_working) + { + gchar *distance = distance_to_tower (basis); + result->displayname = g_strdup_printf ("%s, %s (%s, %s) (%s)", + basis->fields[FieldDedication], + basis->fields[FieldPlace], + basis->fields[FieldBells], + basis->fields[FieldPracticeNight], + distance); + g_free (distance); + } + else + { + result->displayname = g_strdup_printf ("%s, %s (%s, %s)", + basis->fields[FieldDedication], + basis->fields[FieldPlace], + basis->fields[FieldBells], + basis->fields[FieldPracticeNight]); + } return result; } @@ -567,26 +581,11 @@ parse_dove (ParseDoveCallback callback, static void nearby_towers (void) { - char buffer[4096]; - LocationGPSDevice *device; - device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL); - - sprintf(buffer, "%f %f %x", - device->fix->latitude, - device->fix->longitude, - device->fix->fields); - show_message (buffer); - - if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) - { - show_message ("I know where you are!"); - } - else + if (!gps_working) { show_message ("I don't know where you are!"); + return; } - - g_object_unref (device); } static void @@ -815,6 +814,18 @@ recent_towers (void) { } +static void +grab_gps (void) +{ + gps_working = (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET)!=0; + + if (gps_working) + { + current_lat = device->fix->latitude; + current_long = device->fix->longitude; + } +} + int main(int argc, char **argv) { @@ -824,6 +835,10 @@ main(int argc, char **argv) gtk_init (&argc, &argv); g_set_application_name ("Belltower"); + device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL); + grab_gps (); + /* FIXME and call that when the location changes, too */ + window = hildon_stackable_window_new (); gtk_window_set_title (GTK_WINDOW (window), "Belltower"); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); -- 1.7.9.5