#include <hildon/hildon-window.h>
#include <stdlib.h>
#include <gtk/gtk.h>
-#include <location/location-gps-device.h>
-#include <location/location-gpsd-control.h>
+#include <libosso.h>
#include "callbacks.h"
+#include "appdata.h"
+#include "ui.h"
+#include "util.h"
+
+#define PROGNAME "org.wellu.speedometer"
+
+static AppData *appdata;
+static osso_context_t* osso_ctx;
+
+/* Requests delay from screen blanking
+ * Should be called at least once in every 60 seconds
+ * we're not bothered about errors here as dbus calls
+ * either succeed or not. Worst case would be dimmed
+ * screen anyway.
+ */
+static gboolean delay_display_blanking(gpointer data) {
+ g_print("Requesting not to blank the screen in the next 60 secs.\n");
+ osso_display_blanking_pause(data);
+ return TRUE;
+}
-int main(int argc, char** argv) {
-
-
- HildonProgram *program;
- HildonWindow *window;
-
- gtk_init(&argc, &argv);
-
- GtkImage* table[10]; // stores the images
-
- GtkWidget *box;
-
- program = HILDON_PROGRAM(hildon_program_get_instance());
- g_set_application_name("Speedometer");
-
- window = HILDON_WINDOW(hildon_window_new());
- hildon_program_add_window(program, window);
-
-
- int i = 0;
- while(i < 10) {
- char* path = malloc(30);
- g_sprintf(path, "data/%d.png", i);
- table[i] = gtk_image_new_from_file(path);
- g_print(path);
- g_print("\n");
- free(path);
- i++;
- }
+void init_app() {
+ appdata = g_new0(AppData, 1);
+ appdata->program = HILDON_PROGRAM(hildon_program_get_instance());
+ appdata->window = HILDON_WINDOW(hildon_window_new());
+ hildon_program_add_window(appdata->program, appdata->window);
- box = gtk_hbox_new(TRUE, 0);
+ osso_ctx = osso_initialize(PROGNAME, "1.0", FALSE, NULL);
- gtk_box_pack_start(box, table[6], FALSE, FALSE, 0);
- gtk_box_pack_start(box, table[5], FALSE, FALSE, 0);
- gtk_box_pack_start(box, table[8], FALSE, FALSE, 0);
+ delay_display_blanking(osso_ctx);
+ g_timeout_add(55000, (GSourceFunc) delay_display_blanking, osso_ctx);
+}
- gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(box));
+void deinit_app() {
+ osso_deinitialize(osso_ctx);
+ stop_gps(appdata);
+}
- // set the background color to black
- GdkColor black;
- black.red = 0x0000;
- black.blue = 0x0000;
- black.green = 0x0000;
- gtk_widget_modify_bg(window, GTK_STATE_NORMAL, &black);
+int main(int argc, char** argv) {
+ gtk_init(&argc, &argv);
- // set the window fullscreen
- gtk_window_fullscreen(GTK_WINDOW(window));
+ init_app();
- gtk_widget_show_all(GTK_WIDGET(window));
+ // loads images from the disk to the image array
+ load_graphics(appdata);
+ // set display to 000
+ set_digits_to_zero(appdata);
+ // inits the ui placement
+ create_ui(appdata);
g_thread_init(NULL);
+ show_cardware_dialog();
-#ifdef __arm__
- // gps device
- LocationGPSDevice *device;
- device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
-
- // connect some signal handlers
- g_signal_connect (device, "changed", G_CALLBACK (location_changed), NULL);
+ start_gps(appdata);
- g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(key_press_cb), window);
-
- LocationGPSDControl *control;
-
- control = location_gpsd_control_get_default();
- location_gpsd_control_start(control);
-#endif // __arm__
-
- /* Connect signal to X in the upper corner */
- g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL);
-
- /* Start the main event loop. */
gtk_main();
+ // here we cleanup things
+ deinit_app();
+
return EXIT_SUCCESS;
}