Chris made a pretty map widget thing and threw down the gauntlet
“I’m expecting a libjana-gtk/gypsy mash-up from a certain Mr. Burton (no pressure)“
Given that Gypsy is my baby, I felt obligated to beat Ross to it 🙂 And so I present
And a massive 87 line program to how how fun and easy it can be to find out your location and then draw it on a map.
#include <gtk/gtk.h>
#include <libjana-gtk/jana-gtk-world-map.h>
#include <gypsy/gypsy-control.h>
#include <gypsy/gypsy-device.h>
#include <gypsy/gypsy-position.h>GypsyControl *control;
GypsyDevice *device;static void
destroyed_cb (GtkWidget *window, gpointer data)
{
gypsy_device_stop (device);
g_object_unref (control);Â Â Â gtk_main_quit ();
}static void
position_changed (GypsyPosition *position, GypsyPositionFields fields_set, int timestamp, double latitude, double longitude, double altitude, JanaGtkWorldMap *map)
{
if ((fields_set & GYPSY_POSITION_FIELDS_LATITUDE) &&
(fields_set & GYPSY_POSITION_FIELDS_LONGITUDE)) {
jana_gtk_world_map_add_mark (map, latitude, longitude);
}
}int
main (int argc, char **argv)
{
GtkWidget *window, *map;
GypsyPosition *position;
GError *error = NULL;
char *path;Â Â Â gtk_init (&argc, &argv);
   if (argc < 2) {
g_print ("Usage: %s <device\n", argv[0]);
return 1;
}Â Â Â control = gypsy_control_get_default ();
path = gypsy_control_create (control, argv[1], &error);
if (path == NULL) {
g_warning ("Error creating client for %s: %s", argv[1], error->message);
g_error_free (error);
return 1;
}Â Â Â window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy", G_CALLBACK (destroyed_cb), NULL);Â Â Â map = jana_gtk_world_map_new ();
   gtk_container_add (GTK_CONTAINER (window), map);
gtk_widget_show_all (window);Â Â Â device = gypsy_device_new (path);
position = gypsy_position_new (path);
g_signal_connect (position, "position-changed", G_CALLBACK (position_changed), map);Â Â Â gypsy_device_start (device, &error);
if (error != NULL) {
g_warning ("Error starting %s: %s", argv[1], error->message);
g_error_free (error);
return 1;
}Â Â Â gtk_main ();
return 0;
}
As you can see, its really not a lot of code. I also added 10 lines to libjana-gtk to draw the marker. Total time taken, about 40minutes, including testing, debugging and discussing a few bugs with Chris. So lets see what sloccount says about it:
Total Physical Source Lines of Code (SLOC) = 80
Development Effort Estimate, Person-Years (Person-Months) = 0.01 (0.17)
Schedule Estimate, Years (Months) = 0.11 (1.27)
Estimated Average Number of Developers (Effort/Schedule) = 0.13
Total Estimated Cost to Develop = $ 1,905
Hmm, we should have scheduled 1.27 months for it and I should have earned 2grand? (not including the code I added to libjana-gtk which would have increased the line count to 90)
Oh, whoops, almost forgot this:
Please credit this data as “generated by pulling numbers out of David A. Wheeler’s ass”
sloccount – for when you need to over estimate EVERYTHING.
Your whitespace sucks and you smell funny.
Playing well with the rest of the community as usual, eh? 🙄
Damn you Holmes, DAMN YOU.
Of course it overestimates the cost of your code. However, it always underestimates the cost for the code I write.