Initial commit, partially working
authorMichele Tameni <michele@amdplanet.it>
Sun, 8 Nov 2009 20:39:06 +0000 (21:39 +0100)
committerMichele Tameni <michele@amdplanet.it>
Sun, 8 Nov 2009 20:39:06 +0000 (21:39 +0100)
src/app_data.c [new file with mode: 0644]
src/app_data.h [new file with mode: 0644]
src/interface.c [new file with mode: 0644]
src/interface.h [new file with mode: 0644]
src/loc_data.c [new file with mode: 0644]
src/loc_data.h [new file with mode: 0644]
src/main.c [new file with mode: 0644]

diff --git a/src/app_data.c b/src/app_data.c
new file mode 100644 (file)
index 0000000..6c4cadc
--- /dev/null
@@ -0,0 +1,42 @@
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "app_data.h"
+
+/* Global AppData only access with get_app_data() */
+AppData *_app_data = NULL;
+
+AppData*
+app_data_get()
+{
+    return _app_data;
+}
+
+void
+app_data_init()
+{
+    g_return_if_fail(_app_data == NULL);
+    
+    _app_data = g_new(AppData, 1);
+    _app_data->fullscreen = FALSE;
+    _app_data->main_ui = NULL;
+    _app_data->program = hildon_program_get_instance();
+    _app_data->control = location_gpsd_control_get_default();
+    _app_data->device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
+
+    g_object_set(G_OBJECT(_app_data->control),
+                 "preferred-method", LOCATION_METHOD_GNSS | LOCATION_METHOD_AGNSS,
+                 "preferred-interval", LOCATION_INTERVAL_DEFAULT,
+                 NULL);
+
+}
+
+void app_data_free()
+{
+       AppData *app_data = app_data_get();
+       if (app_data->main_ui->window != NULL) {
+               gtk_widget_destroy(GTK_WIDGET(app_data->main_ui->window));
+       }
+        
+       g_free(app_data);
+}
diff --git a/src/app_data.h b/src/app_data.h
new file mode 100644 (file)
index 0000000..e3d7757
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef APP_DATA_H_
+#define APP_DATA_H_
+
+#include <hildon/hildon-program.h>
+#include "interface.h"
+#include <location/location-gps-device.h>
+#include <location/location-gpsd-control.h>
+
+typedef struct
+{
+    HildonProgram *program;
+    gboolean      fullscreen;
+    gboolean       portrait;
+    UserInterface  *main_ui;
+    LocationGPSDControl *control;
+    LocationGPSDevice *device;
+} AppData;
+
+void app_data_init(void);
+AppData* app_data_get(void);
+void app_data_free(void);
+
+#endif /*APP_DATA_H_*/
diff --git a/src/interface.c b/src/interface.c
new file mode 100644 (file)
index 0000000..c1b4818
--- /dev/null
@@ -0,0 +1,105 @@
+#include "interface.h"
+#include <hildon/hildon.h>
+
+UserInterface*
+create_ui()
+{
+    UserInterface *ui = g_new0(UserInterface, 1);
+
+    GtkWidget *main_win;
+
+    GtkWidget *vbox;
+    GtkWidget *first_hbox;
+    GtkWidget *second_hbox;
+    GtkWidget *third_hbox;
+
+    GtkWidget *pannable_area; 
+        
+    GtkWidget *lat_label;
+    GtkWidget *lon_label;
+    GtkWidget *altitude_label;
+    GtkWidget *speed_label;
+    GtkWidget *fix_status_label;
+
+    GtkLabel *lat_val_label;
+    GtkLabel *lon_val_label;
+    GtkLabel *alt_val_label;
+    GtkLabel *speed_val_label;
+    GtkLabel *fix_status_val_label;
+
+    
+    
+    main_win = hildon_stackable_window_new ();
+    gtk_window_set_title ( GTK_WINDOW (main_win), "WAI");
+        
+    pannable_area = hildon_pannable_area_new ();
+    vbox = gtk_vbox_new (FALSE, 0);
+
+    first_hbox = gtk_hbox_new (FALSE, 0);
+    second_hbox = gtk_hbox_new (FALSE, 0);
+    third_hbox = gtk_hbox_new (FALSE, 0);
+    
+    
+    lat_label = gtk_label_new("Lat:");
+    lon_label = gtk_label_new("Lon:");
+
+    lat_val_label = GTK_LABEL(gtk_label_new("-"));
+    lon_val_label = GTK_LABEL(gtk_label_new("-"));
+
+    altitude_label = gtk_label_new("Altitude:");
+    speed_label = gtk_label_new("Speed:");
+    fix_status_label = gtk_label_new("Fix Status:");
+    
+    alt_val_label = GTK_LABEL(gtk_label_new("-"));
+    speed_val_label = GTK_LABEL(gtk_label_new("-"));
+    fix_status_val_label = GTK_LABEL(gtk_label_new("-"));
+        
+    gtk_container_add (GTK_CONTAINER (first_hbox),
+                       lat_label);
+    gtk_container_add (GTK_CONTAINER (first_hbox),
+                       GTK_WIDGET (lat_val_label ));
+    gtk_container_add (GTK_CONTAINER (first_hbox),
+                       lon_label);
+    gtk_container_add (GTK_CONTAINER (first_hbox),
+                       GTK_WIDGET (lon_val_label));
+
+    gtk_container_add (GTK_CONTAINER (vbox),
+                       first_hbox);
+
+    gtk_container_add (GTK_CONTAINER (second_hbox),
+                       altitude_label);
+    gtk_container_add (GTK_CONTAINER (second_hbox),
+                       GTK_WIDGET (alt_val_label ));
+    gtk_container_add (GTK_CONTAINER (second_hbox),
+                       speed_label);
+    gtk_container_add (GTK_CONTAINER (second_hbox),
+                       GTK_WIDGET (speed_val_label ));
+    
+
+    gtk_container_add (GTK_CONTAINER (vbox),
+                       second_hbox);
+
+    gtk_container_add (GTK_CONTAINER (third_hbox),
+                       fix_status_label);
+    gtk_container_add (GTK_CONTAINER (third_hbox),
+                       GTK_WIDGET (fix_status_val_label ));
+        
+    gtk_container_add (GTK_CONTAINER (vbox),
+                       third_hbox);
+
+    hildon_pannable_area_add_with_viewport (
+        HILDON_PANNABLE_AREA (pannable_area), vbox);
+    gtk_container_add (GTK_CONTAINER (main_win),
+                       pannable_area);
+    
+    ui->window = main_win;
+    ui->latitude_value_label = lat_val_label;
+    ui->longitude_value_label = lon_val_label;
+    ui->altitude_value_label = alt_val_label;
+    ui->speed_value_label = speed_val_label;
+//    ui->fix_status_label = fix_status_val_label;
+    
+    gtk_widget_show_all (main_win);
+
+    return ui;
+}
diff --git a/src/interface.h b/src/interface.h
new file mode 100644 (file)
index 0000000..c4374de
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef INTERFACE_H
+#define INTERFACE_H
+
+#include <hildon/hildon.h>
+
+typedef struct
+{
+    GtkWidget *window;
+    GtkLabel *latitude_value_label;
+    GtkLabel *longitude_value_label;
+    GtkLabel *altitude_value_label;
+    GtkLabel *speed_value_label;
+    GtkLabel *fix_status_label;
+    
+} UserInterface;
+
+UserInterface* create_ui(void);
+
+#endif /* INTERFACE_H */
diff --git a/src/loc_data.c b/src/loc_data.c
new file mode 100644 (file)
index 0000000..3fe4cac
--- /dev/null
@@ -0,0 +1,73 @@
+#include "app_data.h"
+#include "loc_data.h"
+
+void on_error(LocationGPSDControl *control, LocationGPSDControlError error, gpointer data)
+{ 
+       g_debug("location error: %d... quitting", error);
+}
+
+void on_changed(LocationGPSDevice *device, gpointer data)
+
+{    
+    if (!device)
+        return;
+    
+    if (device->fix) {
+        if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
+            AppData *app_data = (AppData *) data;
+            
+            gchar *tmp_str = (gchar *) g_malloc (25);
+            
+            g_sprintf(tmp_str,"%f", device->fix->latitude);
+            gtk_label_set_text( GTK_LABEL(app_data->main_ui->latitude_value_label), tmp_str );
+
+            g_sprintf(tmp_str,"%f", device->fix->longitude);
+            gtk_label_set_text( GTK_LABEL(app_data->main_ui->longitude_value_label), tmp_str );
+
+            if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
+                g_sprintf(tmp_str,"%f", device->fix->altitude);
+                gtk_label_set_text( GTK_LABEL(app_data->main_ui->altitude_value_label), tmp_str );
+            }
+
+            if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
+                g_sprintf(tmp_str,"%f", device->fix->speed);
+                gtk_label_set_text( GTK_LABEL(app_data->main_ui->speed_value_label), tmp_str );
+            }
+            
+            switch(device->fix->mode) {
+            case LOCATION_GPS_DEVICE_MODE_NOT_SEEN:
+                g_sprintf(tmp_str,"%s", "No sat in view");
+                break;
+            case LOCATION_GPS_DEVICE_MODE_NO_FIX:
+                g_sprintf(tmp_str,"%s", "Not fixed yed");
+                break;
+            case LOCATION_GPS_DEVICE_MODE_2D:
+                g_sprintf(tmp_str,"%s", "2D Fix");
+                break;
+            case LOCATION_GPS_DEVICE_MODE_3D:
+                g_sprintf(tmp_str,"%s", "3D FIX");
+                break;
+            default:
+                g_sprintf(tmp_str,"%s", "Bho");
+            }
+            
+
+            gtk_label_set_text( GTK_LABEL(app_data->main_ui->fix_status_label), tmp_str );
+            
+            g_debug("lat = %f, long = %f", device->fix->latitude, device->fix->longitude);
+
+            g_free(tmp_str);
+        }
+    }
+} 
+
+void on_stop(LocationGPSDControl *control, gpointer data)
+{
+       g_debug("quitting");
+} 
+
+gboolean start_location(gpointer data)
+{
+       location_gpsd_control_start((LocationGPSDControl *) data);
+       return FALSE;
+}
diff --git a/src/loc_data.h b/src/loc_data.h
new file mode 100644 (file)
index 0000000..03a24ed
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef LOC_DATA_H_
+#define LOC_DATA_H_
+#include <location/location-gps-device.h>
+#include <location/location-gpsd-control.h>
+
+void on_error(LocationGPSDControl *control, LocationGPSDControlError error, gpointer data);
+
+void on_changed(LocationGPSDevice *device, gpointer data);
+
+void on_stop(LocationGPSDControl *control, gpointer data);
+
+gboolean start_location(gpointer data);
+
+#endif /*LOC_DATA_H_*/
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..d5d635c
--- /dev/null
@@ -0,0 +1,43 @@
+#include <hildon/hildon.h>
+#include "app_data.h"
+#include "loc_data.h"
+
+void
+exit_wai(GtkWidget *widget,
+         gpointer   data)
+{
+    gtk_main_quit();
+    AppData *app_data = app_data_get();
+    /* Free AppData */
+    app_data_free();
+}
+
+int
+main(int argc, char *argv[])
+{
+    HildonProgram *program;
+    AppData *app_data;
+
+    hildon_gtk_init (&argc, &argv);
+
+    program = hildon_program_get_instance ();
+
+    app_data_init();
+    app_data = app_data_get();
+
+    app_data->main_ui = create_ui();
+
+    // FIXME move out
+    g_signal_connect(app_data->control, "error-verbose", G_CALLBACK(on_error), NULL);
+    g_signal_connect(app_data->device, "changed", G_CALLBACK(on_changed), app_data);
+    g_signal_connect(app_data->control, "gpsd-stopped", G_CALLBACK(on_stop), NULL);
+    
+    g_idle_add(start_location, app_data->control);
+
+    g_signal_connect (app_data->main_ui->window, "destroy", G_CALLBACK (exit_wai), NULL);
+    
+    
+    gtk_main();
+    
+    return 0;
+}