Moved coordinate transformation proto to a subdirectory
[ptas] / lib-timeout-home-widget.c
1 /*
2  * This file is part of hildon-timeout-home-widget-example
3  *
4  * Copyright (C) 2009 Nokia Corporation. All rights reserved.
5  *
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
8  * directory.
9  *
10  */
11
12 #include <gtk/gtk.h>
13 #include <hildon/hildon.h>
14
15 #include "lib-timeout-home-widget.h"
16
17 #include "location-provider.h"
18
19 HD_DEFINE_PLUGIN_MODULE (TimeOutPlugin, time_out_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
20
21 GtkTextBuffer *debugBuffer = NULL;
22
23 static void printDebug(const char *msg)
24 {
25     if (debugBuffer != NULL) {
26         gtk_text_buffer_insert_at_cursor(debugBuffer, msg, -1);
27         gtk_text_buffer_insert_at_cursor(debugBuffer, "\n", -1);
28     }
29 }
30
31 char debugStr[1024];
32 #define debug(...) sprintf(debugStr, __VA_ARGS__); printDebug(debugStr)
33
34 static void location_listener(double latitude, double longitude)
35 {
36     debug("got location: %f, %f", latitude, longitude);
37 }
38
39 int locationTrackingOn = 0;
40 void search_button_clicked(GtkButton *button, gpointer user_data)
41 {
42     if (!locationTrackingOn) {
43         // Setup location tracking
44         setup_location_provider();
45         set_location_listener(location_listener);
46         start_location_provider();
47
48         locationTrackingOn = 1;
49         debug("Location tracking started");
50     } else {
51         stop_location_provider();
52         cleanup_location_provider();
53
54         locationTrackingOn = 0;
55         debug("Location tracking stopped");
56     }
57 }
58
59 static GtkWidget *build_ui(void)
60 {
61     GtkVBox *contents = GTK_VBOX(gtk_vbox_new(0, FALSE));
62     GtkLabel *label = GTK_LABEL(gtk_label_new("Get me home"));
63 //     HildonPickerButton *action;
64 //     action = HILDON_PICKER_BUTTON (hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT,
65 //                                         HILDON_BUTTON_ARRANGEMENT_VERTICAL));
66 //     HildonTouchSelector *action_selector;
67 //     action_selector = HILDON_TOUCH_SELECTOR (hildon_touch_selector_new_text ());
68 //     hildon_button_set_title (HILDON_BUTTON (action), "Action");
69 //     hildon_touch_selector_append_text (action_selector, "Blank Screen");
70 //     hildon_touch_selector_append_text (action_selector, "Suspend");
71 //     hildon_touch_selector_append_text (action_selector, "Turn Off");
72 //     hildon_picker_button_set_selector (action, action_selector);
73 //     hildon_picker_button_set_active (action, 0);
74
75     GtkWidget* getmehomeButton = hildon_gtk_button_new(HILDON_SIZE_AUTO);
76     gtk_button_set_label(GTK_BUTTON(getmehomeButton), "Search");
77
78     g_signal_connect(getmehomeButton, "clicked", G_CALLBACK(search_button_clicked), NULL);
79
80 //     HildonTimeButton *time;
81 //     time = HILDON_TIME_BUTTON (hildon_time_button_new (HILDON_SIZE_FINGER_HEIGHT,
82 //                                         HILDON_BUTTON_ARRANGEMENT_VERTICAL));
83 //     hildon_time_button_set_time (time, 22, 00);
84
85     GtkHBox *buttons = GTK_HBOX(gtk_hbox_new(0, TRUE));
86     gtk_container_add(GTK_CONTAINER(buttons), GTK_WIDGET(getmehomeButton));
87 //     gtk_container_add (GTK_CONTAINER (buttons), GTK_WIDGET (action));
88 //     gtk_container_add (GTK_CONTAINER (buttons), GTK_WIDGET (time));
89
90     GtkWidget *debugView = hildon_text_view_new();  // gtk_text_view_new();
91     gtk_widget_set_size_request(GTK_WIDGET(debugView), 400, 200);
92     debugBuffer = hildon_text_view_get_buffer(HILDON_TEXT_VIEW(debugView)); // gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
93     GtkWidget* debugScroller = gtk_scrolled_window_new(NULL, NULL);
94     gtk_container_add(GTK_CONTAINER(debugScroller), GTK_WIDGET(debugView));
95
96     gtk_box_pack_start(GTK_BOX(contents), GTK_WIDGET(label), FALSE, FALSE, 0);
97     gtk_box_pack_end(GTK_BOX(contents), GTK_WIDGET(buttons), FALSE, FALSE, 0);
98     gtk_box_pack_end(GTK_BOX(contents), GTK_WIDGET(debugScroller), FALSE, FALSE, 0);
99     gtk_widget_show_all(GTK_WIDGET(contents));
100
101     return GTK_WIDGET(contents);
102 }
103
104 static void
105 time_out_plugin_init (TimeOutPlugin *desktop_plugin)
106 {
107     GtkWidget *contents = build_ui ();
108     gtk_container_add (GTK_CONTAINER (desktop_plugin), contents);
109 }
110
111 static void
112 time_out_plugin_class_init (TimeOutPluginClass *class) {}
113
114 static void
115 time_out_plugin_class_finalize (TimeOutPluginClass *class) {}