Cleanup
[speedometer] / main.c
1 /****
2         Speedometer, shows your current speed using GPS
3         Copyright (C) 2008 Wellu Mäkinen <wellu@wellu.org>
4
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.
9
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.
14
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/>.
17  ****/
18
19 #include <hildon/hildon-program.h>
20 #include <hildon/hildon-window.h>
21 #include <stdlib.h>
22 #include <gtk/gtk.h>
23 #include <libosso.h>
24
25 #include "callbacks.h"
26 #include "appdata.h"
27 #include "ui.h"
28 #include "util.h"
29
30 #define PROGNAME "org.wellu.speedometer"
31
32 static AppData *appdata;
33 static osso_context_t* osso_ctx;
34
35 /* Requests delay from screen blanking
36  * Should be called at least once in every 60 seconds
37  * we're not bothered about errors here as dbus calls
38  * either succeed or not. Worst case would be dimmed
39  * screen anyway.
40  */
41 static gboolean delay_display_blanking(gpointer data) {
42         g_print("Requesting not to blank the screen in the next 60 secs.\n");
43         osso_display_blanking_pause(data);
44         return TRUE;
45 }
46
47 void init_app() {
48         appdata = g_new0(AppData, 1);
49         appdata->program = HILDON_PROGRAM(hildon_program_get_instance());
50         appdata->window = HILDON_WINDOW(hildon_window_new());
51         hildon_program_add_window(appdata->program, appdata->window);
52
53         osso_ctx = osso_initialize(PROGNAME, "1.0", FALSE, NULL);
54
55         delay_display_blanking(osso_ctx);
56         g_timeout_add(55000, (GSourceFunc) delay_display_blanking, osso_ctx);
57 }
58
59 void deinit_app() {
60         osso_deinitialize(osso_ctx);
61         stop_gps(appdata);
62 }
63
64 int main(int argc, char** argv) {
65         gtk_init(&argc, &argv);
66
67         init_app();
68
69         // loads images from the disk to the image array
70         load_graphics(appdata);
71
72         // set display to 000
73         set_digits_to_zero(appdata);
74
75         // inits the ui placement
76         create_ui(appdata);
77
78         g_thread_init(NULL);
79
80         show_cardware_dialog();
81
82         start_gps(appdata);
83
84         gtk_main();
85
86         // here we cleanup things
87         deinit_app();
88
89         return EXIT_SUCCESS;
90 }
91