2 Speedometer, shows your current speed using GPS
3 Copyright (C) 2008 Wellu Mäkinen <wellu@wellu.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <location/location-gps-device.h>
20 #include <location/location-gpsd-control.h>
21 #include <gconf/gconf-client.h>
25 #include "callbacks.h"
28 #define GCONF_KEY "/apps/Maemo/speedometer/disclaimer"
30 static LocationGPSDevice *device = NULL;
31 static LocationGPSDControl *control = NULL;
33 void start_gps(AppData* appdata) {
37 device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
38 g_signal_connect(device, "changed", G_CALLBACK(location_changed), appdata);
40 control = location_gpsd_control_get_default();
41 location_gpsd_control_request_status(control);
42 if(control->can_control) {
43 location_gpsd_control_start(control);
48 void stop_gps(AppData* appdata) {
51 control = location_gpsd_control_get_default();
52 location_gpsd_control_request_status(control);
53 if(control->can_control) {
54 location_gpsd_control_stop(control);
59 void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
61 g_assert(!isnan(speed));
63 // convert float to a 6 digits (including dot) wide string with leading zeros
64 gchar* charspeed = g_malloc(10); // alloc
65 g_sprintf(charspeed, "%0*.2f", 6, speed);
67 g_print("Speed is %s km/h\n", charspeed);
72 set_nth_digit(appdata, i, g_ascii_digit_value(charspeed[i]));
74 repaint_all_digits(appdata);
80 static show_dialog() {
81 GtkWidget *dialog = gtk_message_dialog_new(
86 "This program is licensed under GNU General Public License, "
87 "which means (among other things) that you don't have to pay "
89 "If you think, however, that this software is worth it, you "
90 "can always drop me a postcard.\n\n"
95 gtk_dialog_run(GTK_DIALOG(dialog));
96 gtk_widget_destroy(dialog);
99 void show_cardware_dialog() {
100 GConfClient* client = gconf_client_get_default();
101 g_assert(GCONF_IS_CLIENT(client));
103 GConfValue* gcvalue = NULL;
104 gcvalue = gconf_client_get_without_default(client, GCONF_KEY, NULL);
106 if(gcvalue == NULL) {
107 g_print("GConf key not found so show dialog.");
109 gconf_client_set_bool(client, GCONF_KEY, TRUE, NULL);
111 g_object_unref(client);