3 #include <hildon/hildon.h>
4 #include <hildon/hildon-file-chooser-dialog.h>
5 #include <location/location-gpsd-control.h>
6 #include <location/location-gps-device.h>
7 #include <location/location-misc.h>
8 #include <location/location-distance-utils.h>
11 HildonProgram *program;
14 GtkWidget * main_vbox;
15 GtkWidget *status_label;
16 GtkButton *start_button;
19 static GtkWidget *window = NULL;
21 static gchar * interface_file_chooser (AppData * appdata, GtkFileChooserAction action)
24 gchar *filename = NULL;
26 dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (appdata->window), action);
27 gtk_widget_show_all (GTK_WIDGET (dialog));
29 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
30 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
33 gtk_widget_destroy(dialog);
37 static void cb_example_file_save (GtkWidget * w, AppData * data)
39 gchar *filename = NULL;
40 filename = interface_file_chooser (data, GTK_FILE_CHOOSER_ACTION_SAVE);
42 if (filename == NULL) {
46 FILE * f = fopen (filename, "w");
47 fprintf (f, "This file was generated by Hildon File Chooser example.");
51 g_print ("File saved as %s\n", filename);
55 on_gps_device_changed (LocationGPSDevice *device, gpointer data)
57 GtkLabel *info = (GtkLabel*)data;
62 msg = g_string_sized_new (512);
64 if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
65 g_print ("time = %f\n", device->fix->time);
66 g_string_append_printf(msg, "time = %f\n", device->fix->time);
69 if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
70 g_print ("lat = %f, long = %f\n",
71 device->fix->latitude,
72 device->fix->longitude);
73 g_string_append_printf (msg, "lat = %f, long = %f\n",
74 device->fix->latitude,
75 device->fix->longitude);
78 if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
79 g_print ("alt = %f\n", device->fix->altitude);
80 g_string_append_printf (msg, "alt = %f\n", device->fix->altitude);
83 if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
84 g_print ("speed = %f\n", device->fix->speed);
85 g_string_append_printf (msg, "speed = %f, ", device->fix->speed);
88 if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
89 g_print ("track = %f\n", device->fix->track);
90 g_string_append_printf (msg, "track = %f, ", device->fix->track);
93 if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) {
94 g_print ("climb = %f\n", device->fix->climb);
95 g_string_append_printf (msg, "climb = %f\n", device->fix->climb);
98 g_print ("Accuracy values:\n");
99 g_print ("\tept = %e, eph = %e, epv = %e, epd = %e, "
100 "eps = %e, epc = %e\n",
109 g_print ("Satellites in view: %d\n", device->satellites_in_view);
110 g_print ("Satellites in use: %d\n", device->satellites_in_use);
111 g_string_append_printf (msg, "Satellites = % 2d/% 2d\n", device->satellites_in_use, device->satellites_in_view);
112 g_print ("GPS status: %d\n", device->status);
113 g_string_append_printf (msg, "GPS status: %d\n", device->status);
115 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), device->status == LOCATION_GPS_DEVICE_STATUS_NO_FIX);
118 if (device->cell_info) {
119 if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET)
120 g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc);
122 if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET)
123 g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
126 gtk_label_set_text(info, msg->str);
127 //gtk_widget_show(GTK_WIDGET(info));
128 g_string_free(msg, TRUE);
132 on_gps_error (LocationGPSDevice *device, gpointer data)
134 g_error ("GPS error");
138 on_gps_stop (LocationGPSDevice *device, gpointer data)
140 g_warning ("GPS stopped");
144 on_gps_start (LocationGPSDevice *device, gpointer data)
146 g_warning ("GPS started");
149 int main (int argc, char **argv)
151 GtkWidget *picker_button = NULL;
152 AppData * data = g_new0 (AppData, 1);
154 hildon_gtk_init (&argc, &argv);
155 LocationGPSDControl *control;
156 LocationGPSDevice *device;
158 data->program = hildon_program_get_instance ();
159 g_set_application_name("GPS tracker");
161 window = hildon_stackable_window_new ();
162 hildon_program_add_window (data->program, HILDON_WINDOW (window));
164 data->main_vbox = (void*)gtk_vbox_new(FALSE, 0);
166 /* Create a picker button */
167 picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
168 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
170 /* Set a title to the button*/
171 hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
173 data->start_button = GTK_BUTTON (hildon_gtk_button_new (HILDON_SIZE_THUMB_HEIGHT));
174 gtk_button_set_label (data->start_button, "Start");
175 gtk_box_pack_start(GTK_BOX(data->main_vbox), GTK_WIDGET(data->start_button), FALSE, FALSE, 8);
176 gtk_box_pack_start(GTK_BOX(data->main_vbox), GTK_WIDGET(picker_button), FALSE, FALSE, 0);
177 data->status_label = gtk_label_new("Hier kommt der Status hin\nUnd hier ist die 2. Zeile");
178 gtk_box_pack_start_defaults(GTK_BOX(data->main_vbox), data->status_label);
179 /* Add vbox to main window */
180 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(data->main_vbox));
182 g_signal_connect (G_OBJECT (window), "destroy",
183 G_CALLBACK (gtk_main_quit), NULL);
185 control = location_gpsd_control_get_default ();
186 hildon_banner_show_information(GTK_WIDGET(window), NULL, "Hi there!");
187 location_gpsd_control_start (control);
190 * Note that in real life one may want to use some other method and interval
191 * than LOCATION_METHOD_USER_SELECTED and LOCATION_INTERVAL_DEFAULT,
192 * respectively. For more information on possible values for these parameters
193 * please see liblocation online documentation.
195 g_object_set (G_OBJECT (control),
196 "preferred-method", LOCATION_METHOD_USER_SELECTED,
197 "preferred-interval", LOCATION_INTERVAL_DEFAULT,
200 device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL);
202 g_signal_connect (control, "error", G_CALLBACK (on_gps_error), NULL);
203 g_signal_connect (control, "gpsd-running", G_CALLBACK (on_gps_start), NULL);
204 g_signal_connect (control, "gpsd-stopped", G_CALLBACK (on_gps_stop), NULL);
205 g_signal_connect (device, "changed", G_CALLBACK (on_gps_device_changed), data->status_label);
207 gtk_widget_show_all (GTK_WIDGET (window));
209 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), 1);
212 location_gpsd_control_stop (control);
214 g_object_unref (device);
215 g_object_unref (control);