From f43caf007384c03f73de9fd8313e0c77408c3be7 Mon Sep 17 00:00:00 2001 From: Aki Koskinen Date: Sun, 14 Feb 2010 13:52:22 +0200 Subject: [PATCH] First tryout version for launching the browser from the widget --- getmehome/Makefile.am | 2 +- getmehome/lib-timeout-home-widget.c | 66 +++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/getmehome/Makefile.am b/getmehome/Makefile.am index 8b20f18..42126d2 100644 --- a/getmehome/Makefile.am +++ b/getmehome/Makefile.am @@ -3,7 +3,7 @@ desktoplib_LTLIBRARIES = lib-timeout-home-widget.la desktoplibdir = $(HILDON_DESKTOP_LIB_DIR) -lib_timeout_home_widget_la_SOURCES = lib-timeout-home-widget.c lib-timeout-home-widget.h location-provider.h location-provider.c +lib_timeout_home_widget_la_SOURCES = lib-timeout-home-widget.c lib-timeout-home-widget.h location-provider.c location-provider.h coordinate-system.c coordinate-system.h lib_timeout_home_widget_la_LIBADD = $(EXAMPLE_LIBS) AM_CFLAGS = -Wall $(EXAMPLE_CFLAGS) diff --git a/getmehome/lib-timeout-home-widget.c b/getmehome/lib-timeout-home-widget.c index a548981..5d9fc59 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,65 @@ static void printDebug(const char *msg) char debugStr[1024]; #define debug(...) sprintf(debugStr, __VA_ARGS__); printDebug(debugStr) + +#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); + + widget_state = IDLE; +} + 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); + } } int locationTrackingOn = 0; void search_button_clicked(GtkButton *button, gpointer user_data) { + widget_state = SEARCHING_LOCATION; + if (!locationTrackingOn) { // Setup location tracking setup_location_provider(); @@ -73,7 +127,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 +153,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 -- 1.7.9.5