X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=getmehome%2Flib-timeout-home-widget.c;h=37aab6aca1c972ea861f3714195ac8c86410943f;hb=376f9ef2f5a009174dc76c1d43e444a1a247e9b6;hp=a54898189291540d4f8c24a3f38036644b37e9fa;hpb=ac37216affc2751951f4d0e44014a61196b02fe5;p=ptas diff --git a/getmehome/lib-timeout-home-widget.c b/getmehome/lib-timeout-home-widget.c index a548981..37aab6a 100644 --- a/getmehome/lib-timeout-home-widget.c +++ b/getmehome/lib-timeout-home-widget.c @@ -11,10 +11,13 @@ #include #include +#include +#include #include "lib-timeout-home-widget.h" #include "location-provider.h" +#include "coordinate-system.h" HD_DEFINE_PLUGIN_MODULE (TimeOutPlugin, time_out_plugin, HD_TYPE_HOME_PLUGIN_ITEM) @@ -31,14 +34,68 @@ static void printDebug(const char *msg) char debugStr[1024]; #define debug(...) sprintf(debugStr, __VA_ARGS__); printDebug(debugStr) + + +void start_location_tracking(); +void stop_location_tracking(); + + +#define IDLE 0 +#define SEARCHING_LOCATION 1 +#define LOCATION_RECEIVED 2 + +static int widget_state = IDLE; + +void get_me_home(KKJ x, KKJ y) +{ + time_t t; + struct tm *tmp; + + char hour[4]; + char minute[4]; + + // Get the current time + t = time(NULL); + tmp = localtime(&t); + if (tmp == NULL) { + return; + } + + // Format needed parts from the current time + strftime(hour, sizeof(hour), "%H", tmp); + strftime(minute, sizeof(minute), "%M", tmp); + + debug("Hour %s minute %s", hour, minute); + + // Format the URL + + + // Open the browser + char command[1024]; + sprintf(command, "browser_dbuscmd.sh load_url http://www.reittiopas.fi"); + system(command); +} + static void location_listener(double latitude, double longitude) { - debug("got location: %f, %f", latitude, longitude); + KKJ x, y; + +// debug("got location: %f, %f", latitude, longitude); + + if (widget_state == SEARCHING_LOCATION) { + widget_state = LOCATION_RECEIVED; + + WGS84lola_to_KKJxy(longitude, latitude, &x, &y); + + get_me_home(x, y); + + stop_location_tracking(); + widget_state = IDLE; + } } int locationTrackingOn = 0; -void search_button_clicked(GtkButton *button, gpointer user_data) -{ +void start_location_tracking() { if (!locationTrackingOn) { // Setup location tracking setup_location_provider(); @@ -47,12 +104,24 @@ void search_button_clicked(GtkButton *button, gpointer user_data) locationTrackingOn = 1; debug("Location tracking started"); - } else { - stop_location_provider(); - cleanup_location_provider(); + } +} - locationTrackingOn = 0; - debug("Location tracking stopped"); +void stop_location_tracking() { + if (locationTrackingOn) { + stop_location_provider(); + cleanup_location_provider(); + + locationTrackingOn = 0; + debug("Location tracking stopped"); + } +} + +void search_button_clicked(GtkButton *button, gpointer user_data) +{ + if (widget_state == IDLE) { + widget_state = SEARCHING_LOCATION; + start_location_tracking(); } } @@ -73,7 +142,7 @@ static GtkWidget *build_ui(void) // hildon_picker_button_set_active (action, 0); GtkWidget* getmehomeButton = hildon_gtk_button_new(HILDON_SIZE_AUTO); - gtk_button_set_label(GTK_BUTTON(getmehomeButton), "Search"); + gtk_button_set_label(GTK_BUTTON(getmehomeButton), "Get Me Home"); g_signal_connect(getmehomeButton, "clicked", G_CALLBACK(search_button_clicked), NULL); @@ -99,6 +168,14 @@ static GtkWidget *build_ui(void) gtk_widget_show_all(GTK_WIDGET(contents)); return GTK_WIDGET(contents); + + /*GtkWidget* getmehomeButton = hildon_gtk_button_new(HILDON_SIZE_AUTO); + gtk_button_set_label(GTK_BUTTON(getmehomeButton), "Get Me Home"); + g_signal_connect(getmehomeButton, "clicked", G_CALLBACK(search_button_clicked), NULL); + + gtk_widget_show_all(GTK_WIDGET(getmehomeButton)); + + return GTK_WIDGET(getmehomeButton);*/ } static void