X-Git-Url: http://pileus.org/git/?p=aweather;a=blobdiff_plain;f=src%2Fplugins%2Fgps-plugin.c;h=d162cfd15cec14a2e0ce76675bef48f6c6dea0c0;hp=419dc1430a13d2970e4b93878c8c4857455acefe;hb=274a83a00dae79b7d1927210e51214422e77d0d5;hpb=0f3562e40af590f16de2b2b3f014cd5ce48af351 diff --git a/src/plugins/gps-plugin.c b/src/plugins/gps-plugin.c index 419dc14..d162cfd 100644 --- a/src/plugins/gps-plugin.c +++ b/src/plugins/gps-plugin.c @@ -40,6 +40,8 @@ #include "level2.h" #include "../aweather-location.h" +#include "compat.h" + /* interval to update map with new gps data in seconds. */ #define GPS_UPDATE_INTERVAL (2) @@ -695,7 +697,7 @@ static void gps_init_control_frame(GritsPluginGps *gps, GtkWidget *gbox) gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_frame_set_shadow_type(GTK_FRAME(gps_control_frame), GTK_SHADOW_NONE); - GtkWidget *cbox = gtk_vbox_new(FALSE, 2); + GtkWidget *cbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); gtk_container_add(GTK_CONTAINER(gps_control_frame), cbox); gtk_box_pack_start(GTK_BOX(gbox), gps_control_frame, FALSE, FALSE, 0); @@ -782,7 +784,7 @@ static void gps_init_track_log_frame(GritsPluginGps *gps, GtkWidget *gbox) GtkWidget *label = gtk_frame_get_label_widget(GTK_FRAME(gps_log_frame)); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_frame_set_shadow_type(GTK_FRAME(gps_log_frame), GTK_SHADOW_NONE); - GtkWidget *lbox = gtk_vbox_new(FALSE, 2); + GtkWidget *lbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); gtk_container_add(GTK_CONTAINER(gps_log_frame), lbox); gtk_box_pack_start(GTK_BOX(gbox), gps_log_frame, FALSE, FALSE, 0); @@ -796,7 +798,7 @@ static void gps_init_track_log_frame(GritsPluginGps *gps, GtkWidget *gbox) FALSE, FALSE, 0); /* Set up filename entry box */ - GtkWidget *fbox = gtk_hbox_new(FALSE, 2); + GtkWidget *fbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); GtkWidget *filename_label = gtk_label_new("Filename:"); gtk_box_pack_start(GTK_BOX(fbox), filename_label, FALSE, FALSE, 0); gps->ui.gps_log_filename_entry = gtk_entry_new(); @@ -805,11 +807,11 @@ static void gps_init_track_log_frame(GritsPluginGps *gps, GtkWidget *gbox) gtk_box_pack_start(GTK_BOX(lbox), fbox, FALSE, FALSE, 0); /* set up gps log interval slider */ - GtkWidget *ubox = gtk_hbox_new(FALSE, 4); + GtkWidget *ubox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); GtkWidget *interval_label = gtk_label_new("Update Interval:"); gtk_box_pack_start(GTK_BOX(ubox), interval_label, FALSE, FALSE, 0); gps->ui.gps_log_interval_slider = - gtk_hscale_new_with_range(1.0, 600.0, 30.0); + gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, 1.0, 600.0, 30.0); gtk_range_set_value(GTK_RANGE(gps->ui.gps_log_interval_slider), GPS_LOG_DEFAULT_UPDATE_INTERVAL); g_signal_connect(G_OBJECT(gps->ui.gps_log_interval_slider), @@ -819,9 +821,11 @@ static void gps_init_track_log_frame(GritsPluginGps *gps, GtkWidget *gbox) gtk_range_set_increments( GTK_RANGE(gps->ui.gps_log_interval_slider), 10.0 /* step */, 30.0 /* page up/down */); +#if ! GTK_CHECK_VERSION(3,0,0) gtk_range_set_update_policy( GTK_RANGE(gps->ui.gps_log_interval_slider), GTK_UPDATE_DELAYED); +#endif gtk_box_pack_start(GTK_BOX(ubox), gps->ui.gps_log_interval_slider, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(lbox), ubox, FALSE, FALSE, 0); @@ -832,7 +836,7 @@ static void gps_init_track_log_frame(GritsPluginGps *gps, GtkWidget *gbox) * GPSD interfaces * *******************/ -static void process_gps(gpointer data, gint source, GdkInputCondition condition) +static gboolean process_gps(GIOChannel *source, GIOCondition condition, gpointer data) { struct gps_data_t *gps_data = (struct gps_data_t *)data; @@ -840,13 +844,17 @@ static void process_gps(gpointer data, gint source, GdkInputCondition condition) /* Process any data from the gps and call the hook function */ if (gps_data != NULL) { + gdouble track = gps_data->fix.track; gint result = gps_read(gps_data); + if (isnan(gps_data->fix.track)) + gps_data->fix.track = track; g_debug("GritsPluginGps: process_gps - gps_read returned %d, " "position %f, %f.", result, gps_data->fix.latitude, gps_data->fix.longitude); } else { g_warning("GritsPluginGps: process_gps - gps_data == NULL."); } + return TRUE; } static gint initialize_gpsd(char *server, gchar *port, struct gps_data_t *gps_data) @@ -854,19 +862,19 @@ static gint initialize_gpsd(char *server, gchar *port, struct gps_data_t *gps_da #if GPSD_API_MAJOR_VERSION < 5 #error "GPSD protocol version 5 or greater required." #endif - gint result; - - if ((result = gps_open(server, port, gps_data)) != 0) { + gint result = gps_open(server, port, gps_data); + if (result > 0) { g_warning("Unable to open gpsd connection to %s:%s: %d, %d, %s", - server, port, result, errno, gps_errstr(errno)); - } else { - (void)gps_stream(gps_data, WATCH_ENABLE|WATCH_JSON, NULL); - g_debug("GritsPluginGps: initialize_gpsd - gpsd fd %u.", - gps_data->gps_fd); - gdk_input_add(gps_data->gps_fd, GDK_INPUT_READ, process_gps, gps_data); + server, port, result, errno, gps_errstr(errno)); + return 0; } - return result; + (void)gps_stream(gps_data, WATCH_ENABLE|WATCH_JSON, NULL); + g_debug("GritsPluginGps: initialize_gpsd - gpsd fd %u.", gps_data->gps_fd); + GIOChannel *channel = g_io_channel_unix_new(gps_data->gps_fd); + gint input_tag = g_io_add_watch(channel, G_IO_IN, process_gps, gps_data); + g_io_channel_unref(channel); + return input_tag; } @@ -880,10 +888,10 @@ GritsPluginGps *grits_plugin_gps_new(GritsViewer *viewer, GritsPrefs *prefs) /* TODO: move to constructor if possible */ g_debug("GritsPluginGps: new"); GritsPluginGps *gps = g_object_new(GRITS_TYPE_PLUGIN_GPS, NULL); - gps->viewer = viewer; - gps->prefs = prefs; + gps->viewer = g_object_ref(viewer); + gps->prefs = g_object_ref(prefs); - initialize_gpsd("localhost", DEFAULT_GPSD_PORT, &gps->gps_data); + gps->input_tag = initialize_gpsd("localhost", DEFAULT_GPSD_PORT, &gps->gps_data); gps->follow_gps = FALSE; gps_track_init(&gps->track); @@ -917,7 +925,7 @@ static void grits_plugin_gps_init(GritsPluginGps *gps) { g_debug("GritsPluginGps: gps_init"); - gps->config = gtk_hbox_new(FALSE, 15); + gps->config = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 15); } static void grits_plugin_gps_dispose(GObject *gobject) @@ -926,17 +934,28 @@ static void grits_plugin_gps_dispose(GObject *gobject) g_debug("GritsPluginGps: dispose"); + if (gps->gps_update_timeout_id) { + g_source_remove(gps->gps_update_timeout_id); + gps->gps_update_timeout_id = 0; + } + if (gps->ui.gps_log_timeout_id) { + g_source_remove(gps->ui.gps_log_timeout_id); + gps->ui.gps_log_timeout_id = 0; + } + if (gps->input_tag) { + g_source_remove(gps->input_tag); + gps->input_tag = 0; + } if (gps->viewer) { - if (gps->marker) { - grits_viewer_remove(gps->viewer, - GRITS_OBJECT(gps->marker)); - } - g_object_unref(gps->viewer); + GritsViewer *viewer = gps->viewer; gps->viewer = NULL; + if (gps->marker) + grits_viewer_remove(viewer, + GRITS_OBJECT(gps->marker)); + g_object_unref(gps->prefs); + g_object_unref(viewer); } - gps_track_free(&gps->track); - /* Drop references */ G_OBJECT_CLASS(grits_plugin_gps_parent_class)->dispose(gobject); } @@ -948,7 +967,7 @@ static void grits_plugin_gps_finalize(GObject *gobject) g_debug("GritsPluginGps: finalize"); /* Free data */ - gtk_widget_destroy(gps->config); + gps_track_free(&gps->track); G_OBJECT_CLASS(grits_plugin_gps_parent_class)->finalize(gobject); }