2 * This file is part of hildon-timeout-home-widget-example
4 * Copyright (C) 2009 Nokia Corporation. All rights reserved.
6 * This maemo code example is licensed under a MIT-style license,
7 * that can be found in the file called "COPYING" in the root
13 #include <hildon/hildon.h>
17 #include "lib-timeout-home-widget.h"
19 #include "location-provider.h"
20 #include "coordinate-system.h"
22 HD_DEFINE_PLUGIN_MODULE (TimeOutPlugin, time_out_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
24 GtkTextBuffer *debugBuffer = NULL;
26 static void printDebug(const char *msg)
28 if (debugBuffer != NULL) {
29 gtk_text_buffer_insert_at_cursor(debugBuffer, msg, -1);
30 gtk_text_buffer_insert_at_cursor(debugBuffer, "\n", -1);
35 #define debug(...) sprintf(debugStr, __VA_ARGS__); printDebug(debugStr)
39 void start_location_tracking();
40 void stop_location_tracking();
43 //KKJ destinationX = 2552414;
44 //KKJ destinationY = 6673664;
46 KKJ destinationX = 2544607;
47 KKJ destinationY = 6683661;
50 #define SEARCHING_LOCATION 1
51 #define LOCATION_RECEIVED 2
53 static int widget_state = IDLE;
55 void get_me_home(KKJ x, KKJ y)
66 // Get the current time
73 // Format needed parts from the current time
74 strftime(hour, sizeof(hour), "%H", tmp);
75 strftime(minute, sizeof(minute), "%M", tmp);
76 strftime(day, sizeof(day), "%d", tmp);
77 strftime(month, sizeof(month), "%m", tmp);
78 strftime(year, sizeof(year), "%Y", tmp);
80 debug("Hour %s minute %s", hour, minute);
84 // http://www.reittiopas.fi/?from=poi*Current+location*2552414*6673664&to=poi*Home*2544607*6683661&hour=12&minute=18&timetype=departure&day=14&month=02&year=2010
85 sprintf(url, "http://www.reittiopas.fi/?from=poi*Current+location*%u*%u&to=poi*Home*%u*%u&hour=%s&minute=%s&timetype=departure&day=%s&month=%s&year=%s", x, y, destinationX, destinationY, hour, minute, day, month, year);
89 sprintf(command, "browser_dbuscmd.sh load_url \"%s\"", url);
93 static void location_listener(double latitude, double longitude)
97 // debug("got location: %f, %f", latitude, longitude);
99 if (widget_state == SEARCHING_LOCATION) {
100 widget_state = LOCATION_RECEIVED;
102 WGS84lola_to_KKJxy(longitude, latitude, &x, &y);
106 stop_location_tracking();
111 int locationTrackingOn = 0;
112 void start_location_tracking() {
113 if (!locationTrackingOn) {
114 // Setup location tracking
115 setup_location_provider();
116 set_location_listener(location_listener);
117 start_location_provider();
119 locationTrackingOn = 1;
120 debug("Location tracking started");
124 void stop_location_tracking() {
125 if (locationTrackingOn) {
126 stop_location_provider();
127 cleanup_location_provider();
129 locationTrackingOn = 0;
130 debug("Location tracking stopped");
134 void search_button_clicked(GtkButton *button, gpointer user_data)
136 if (widget_state == IDLE) {
137 widget_state = SEARCHING_LOCATION;
138 start_location_tracking();
142 static GtkWidget *build_ui(void)
144 GtkVBox *contents = GTK_VBOX(gtk_vbox_new(0, FALSE));
145 GtkLabel *label = GTK_LABEL(gtk_label_new("Get me home"));
146 // HildonPickerButton *action;
147 // action = HILDON_PICKER_BUTTON (hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT,
148 // HILDON_BUTTON_ARRANGEMENT_VERTICAL));
149 // HildonTouchSelector *action_selector;
150 // action_selector = HILDON_TOUCH_SELECTOR (hildon_touch_selector_new_text ());
151 // hildon_button_set_title (HILDON_BUTTON (action), "Action");
152 // hildon_touch_selector_append_text (action_selector, "Blank Screen");
153 // hildon_touch_selector_append_text (action_selector, "Suspend");
154 // hildon_touch_selector_append_text (action_selector, "Turn Off");
155 // hildon_picker_button_set_selector (action, action_selector);
156 // hildon_picker_button_set_active (action, 0);
158 GtkWidget* getmehomeButton = hildon_gtk_button_new(HILDON_SIZE_AUTO);
159 gtk_button_set_label(GTK_BUTTON(getmehomeButton), "Get Me Home");
161 g_signal_connect(getmehomeButton, "clicked", G_CALLBACK(search_button_clicked), NULL);
163 // HildonTimeButton *time;
164 // time = HILDON_TIME_BUTTON (hildon_time_button_new (HILDON_SIZE_FINGER_HEIGHT,
165 // HILDON_BUTTON_ARRANGEMENT_VERTICAL));
166 // hildon_time_button_set_time (time, 22, 00);
168 GtkHBox *buttons = GTK_HBOX(gtk_hbox_new(0, TRUE));
169 gtk_container_add(GTK_CONTAINER(buttons), GTK_WIDGET(getmehomeButton));
170 // gtk_container_add (GTK_CONTAINER (buttons), GTK_WIDGET (action));
171 // gtk_container_add (GTK_CONTAINER (buttons), GTK_WIDGET (time));
173 GtkWidget *debugView = hildon_text_view_new(); // gtk_text_view_new();
174 gtk_widget_set_size_request(GTK_WIDGET(debugView), 400, 200);
175 debugBuffer = hildon_text_view_get_buffer(HILDON_TEXT_VIEW(debugView)); // gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
176 GtkWidget* debugScroller = gtk_scrolled_window_new(NULL, NULL);
177 gtk_container_add(GTK_CONTAINER(debugScroller), GTK_WIDGET(debugView));
179 gtk_box_pack_start(GTK_BOX(contents), GTK_WIDGET(label), FALSE, FALSE, 0);
180 gtk_box_pack_end(GTK_BOX(contents), GTK_WIDGET(buttons), FALSE, FALSE, 0);
181 gtk_box_pack_end(GTK_BOX(contents), GTK_WIDGET(debugScroller), FALSE, FALSE, 0);
182 gtk_widget_show_all(GTK_WIDGET(contents));
184 return GTK_WIDGET(contents);
186 /*GtkWidget* getmehomeButton = hildon_gtk_button_new(HILDON_SIZE_AUTO);
187 gtk_button_set_label(GTK_BUTTON(getmehomeButton), "Get Me Home");
188 g_signal_connect(getmehomeButton, "clicked", G_CALLBACK(search_button_clicked), NULL);
190 gtk_widget_show_all(GTK_WIDGET(getmehomeButton));
192 return GTK_WIDGET(getmehomeButton);*/
196 time_out_plugin_init (TimeOutPlugin *desktop_plugin)
198 GtkWidget *contents = build_ui ();
199 gtk_container_add (GTK_CONTAINER (desktop_plugin), contents);
203 time_out_plugin_class_init (TimeOutPluginClass *class) {}
206 time_out_plugin_class_finalize (TimeOutPluginClass *class) {}