git-svn-id: file:///svnroot/speedometer/trunk@38 df364472-da61-43ef-8a67-511c89aa921b
authorwellu <wellu@wellu.org>
Fri, 26 Sep 2008 13:44:23 +0000 (13:44 +0000)
committerwellu <wellu@wellu.org>
Fri, 26 Sep 2008 13:44:23 +0000 (13:44 +0000)
Makefile
README
appdata.h
callbacks.c
main.c
ui.c
ui.h
util.c
util.h

index 9c1b324..5d7214d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 PKGS     = gtk+-2.0 liblocation gconf-2.0
 CC       = gcc
 LINK     = gcc
-CFLAGS   = -g
+CFLAGS   = -g -Wall -pedantic -std=gnu99
 INCPATH  = `pkg-config --cflags $(PKGS)`
 LIBS     = `pkg-config --libs $(PKGS)`
 
diff --git a/README b/README
index d25d582..9fbcbec 100644 (file)
--- a/README
+++ b/README
@@ -20,3 +20,7 @@ PO Box
 33580 Tampere
 
 FINLAND
+
+
+
+
index c8befbf..45184d5 100644 (file)
--- a/appdata.h
+++ b/appdata.h
@@ -26,8 +26,11 @@ typedef struct _AppData {
     HildonProgram *program;
     HildonWindow *window;
 
-       GtkWidget* image_array[10]; // original images from the disk
-       GtkWidget* digit_array[3]; // actual images that are shown as speed
+       GtkWidget* graphix[10];         // contains all the graphics
+       GtkWidget* big_digits[3];       // big digits that are shown as speed
+       GtkWidget* small_digits[2];     // small digits that are shown on the screen
+       guint unit;                                     // unit used in conversion
+
 } AppData;
 
 #endif /* APPDATA_H_ */
index 479cca7..0a245fe 100644 (file)
 ****/
 
 #include <math.h>
+#include <hildon/hildon-banner.h>
 
 #include "callbacks.h"
 #include "appdata.h"
 #include "util.h"
 
-// this is just here for debugging
-static void print_location(LocationGPSDevice* device) {
-       g_print("Latitude: %.2f\n"
-                       "Longitude: %.2f\n"
-                       "Altitude: %.2f\n"
-                       "Speed: %.2d\n",
-                       device->fix->latitude,
-                       device->fix->longitude,
-                       device->fix->altitude,
-                       device->fix->speed);
-}
-
 void location_changed(LocationGPSDevice* device, gpointer data) {
-       //print_location(device);
        g_assert(data);
        g_assert(device);
 
@@ -101,9 +89,6 @@ gboolean top_event_box_button_press(GtkWidget* widget, GdkEventButton* event, gp
                stop_gps(appdata);
                g_signal_emit_by_name(appdata->window, "delete_event");
        }
-       else {
-               randomize(appdata);
-       }
        return TRUE;
 }
 
@@ -111,9 +96,6 @@ gboolean top_event_box_button_press(GtkWidget* widget, GdkEventButton* event, gp
 gboolean bottom_event_box_button_press(GtkWidget* widget, GdkEventButton* event, gpointer data) {
        gdouble x = event->x;
        g_print("Bottom event box pressed at: %f\n", x);
-       AppData* appdata = (AppData*) data;
-
-       randomize(data);
        return TRUE;
 }
 
diff --git a/main.c b/main.c
index 44875cd..782db74 100644 (file)
--- a/main.c
+++ b/main.c
@@ -37,7 +37,7 @@ int main(int argc, char** argv) {
        hildon_program_add_window(appdata->program, appdata->window);
 
        // loads images from the disk to the image array
-       load_images(appdata);
+       load_graphix(appdata);
 
        // set display to 000
        load_initial_pixbufs(appdata);
diff --git a/ui.c b/ui.c
index 0fa47fc..ca760f8 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -17,6 +17,7 @@
  ****/
 
 #include <gtk/gtk.h>
+#include <glib/gprintf.h>
 
 #include "ui.h"
 #include "callbacks.h"
@@ -32,14 +33,14 @@ static void set_widget_bg_black(GtkWidget* widget) {
        gtk_widget_modify_bg(GTK_WIDGET(widget), GTK_STATE_NORMAL, &black);
 }
 
-void load_images(AppData *appdata) {
+void load_graphix(AppData *appdata) {
        g_assert(appdata);
        g_print("Loading images\n");
        guint i = 0;
        while(i < 10) {
                char* path = g_malloc(30);
                g_sprintf(path, IMAGE_PATH, i);
-               appdata->image_array[i] = gtk_image_new_from_file(path);
+               appdata->graphix[i] = gtk_image_new_from_file(path);
                g_print(path);
                g_print("\n");
                g_free(path);
@@ -50,11 +51,11 @@ void load_images(AppData *appdata) {
 void load_initial_pixbufs(AppData* appdata) {
        g_assert(appdata);
 
-       GdkPixbuf* zero = gtk_image_get_pixbuf(GTK_IMAGE(appdata->image_array[0]));
+       GdkPixbuf* zero = gtk_image_get_pixbuf(GTK_IMAGE(appdata->graphix[0]));
 
-       appdata->digit_array[0] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
-       appdata->digit_array[1] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
-       appdata->digit_array[2] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
+       appdata->big_digits[0] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
+       appdata->big_digits[1] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
+       appdata->big_digits[2] = GTK_WIDGET(gtk_image_new_from_pixbuf(zero));
 }
 
 void set_nth_digit(AppData* appdata, guint n, guint value) {
@@ -62,35 +63,23 @@ void set_nth_digit(AppData* appdata, guint n, guint value) {
        g_assert(value < 10);
        g_assert(n < 3);
 
-       GtkWidget* image = appdata->digit_array[n];
-       GdkPixbuf* buf = gtk_image_get_pixbuf(GTK_IMAGE(appdata->image_array[value]));
+       GtkWidget* image = appdata->big_digits[n];
+       GdkPixbuf* buf = gtk_image_get_pixbuf(GTK_IMAGE(appdata->graphix[value]));
        gtk_image_set_from_pixbuf(GTK_IMAGE(image), buf);
 }
 
 void repaint_all_digits(AppData* appdata) {
        g_assert(appdata);
-       gtk_widget_queue_draw(GTK_WIDGET(appdata->digit_array[0]));
-       gtk_widget_queue_draw(GTK_WIDGET(appdata->digit_array[1]));
-       gtk_widget_queue_draw(GTK_WIDGET(appdata->digit_array[2]));
+       gtk_widget_queue_draw(GTK_WIDGET(appdata->big_digits[0]));
+       gtk_widget_queue_draw(GTK_WIDGET(appdata->big_digits[1]));
+       gtk_widget_queue_draw(GTK_WIDGET(appdata->big_digits[2]));
 }
 
-// used only in testing...
-void randomize(AppData* appdata) {
+void create_ui(AppData* appdata) {
        g_assert(appdata);
-       gint32 n = g_random_int_range(0, 3);
-       GtkWidget* image = appdata->digit_array[n];
-
-       gint32 m = g_random_int_range(0, 10);
-       GdkPixbuf* buf = gtk_image_get_pixbuf(GTK_IMAGE(appdata->image_array[m]));
 
-       g_print("Setting number %d to %d.. ", n+1, m);
+       appdata->unit = 1; // by default use km/h display
 
-       gtk_image_set_from_pixbuf(GTK_IMAGE(image), buf);
-       gtk_widget_queue_draw(appdata->digit_array[n]);
-}
-
-void create_ui(AppData* appdata) {
-       g_assert(appdata);
        GtkWidget *hbox;
        GtkWidget *vbox;
 
@@ -121,9 +110,9 @@ void create_ui(AppData* appdata) {
                appdata->window);
 
        // add three digits to the hbox
-       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->digit_array[0]), FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->digit_array[1]), FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->digit_array[2]), FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->big_digits[0]), FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->big_digits[1]), FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(appdata->big_digits[2]), FALSE, FALSE, 0);
 
        gtk_box_pack_start_defaults(GTK_BOX(vbox), top_e); // add event box on top
        gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); // numbers to the middle
diff --git a/ui.h b/ui.h
index 79828ee..9d9fbcb 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -21,7 +21,7 @@
 
 #include "appdata.h"
 
-void load_images(AppData *appdata);
+void load_graphix(AppData *appdata);
 
 void load_initial_pixbufs(AppData* appdata);
 
@@ -30,8 +30,6 @@ void set_nth_digit(AppData* appdata, guint n, guint value);
 // queues repaint of all digits on the screen
 void repaint_all_digits(AppData* appdata);
 
-void randomize(AppData* appdata);
-
 void create_ui(AppData* appdata);
 
 void connect_signals(AppData* appdata);
diff --git a/util.c b/util.c
index a20f0b1..671f9cc 100644 (file)
--- a/util.c
+++ b/util.c
 
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
-****/
+ ****/
 
 #include <math.h>
 #include <location/location-gps-device.h>
 #include <location/location-gpsd-control.h>
 #include <gconf/gconf-client.h>
+#include <glib/gprintf.h>
 
 #include "util.h"
 #include "appdata.h"
 #include "callbacks.h"
 #include "ui.h"
 
-
-gdouble unit_array[] = {3.6};
+/* This is used when converting to other units
+ * number represents a multiplier which is used
+ * when converting the base unit to other units.
+ * Base unit is m/s thus the first multiplier is
+ * one. Units are in following order:
+ *
+ * m/s, km/h, mph
+ */
+gdouble conversion[] = { 1, 3.6, 2.237 };
 
 #define GCONF_KEY "/apps/Maemo/speedometer/disclaimer"
 
@@ -64,6 +72,11 @@ void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
        g_assert(appdata);
        g_assert(!isnan(speed));
 
+       /* speed is in m/s so let's convert
+        * it to the unit that we are using
+        */
+       speed *= conversion[appdata->unit];
+
        // convert float to a 6 digits (including dot) wide string with leading zeros
        gchar* charspeed = g_malloc(10); // alloc
        g_sprintf(charspeed, "%0*.2f", 6, speed);
@@ -83,7 +96,7 @@ void interpret_speed_from_gps(AppData* appdata, gdouble speed) {
 }
 
 
-static show_dialog() {
+static void show_dialog() {
        GtkWidget *dialog = gtk_message_dialog_new(
                        NULL,
                        GTK_DIALOG_MODAL,
@@ -93,7 +106,7 @@ static show_dialog() {
                        "which means (among other things) that you don't have to pay "
                        "a dime for it. "
                        "If you think, however, that this software is worth it, you "
-                       "can always drop me a postcard. (or a speeding ticket :)\n\n"
+                       "can always drop me a postcard.\n\n"
                        "Wellu Mäkinen\n"
                        "PO BOX\n"
                        "33580 Tampere\n"
@@ -117,3 +130,6 @@ void show_cardware_dialog() {
        g_object_unref(client);
 }
 
+void load_settings() {
+
+}
diff --git a/util.h b/util.h
index 95d7f13..2e24e92 100644 (file)
--- a/util.h
+++ b/util.h
@@ -33,4 +33,7 @@ void interpret_speed_from_gps(AppData* appdata, gdouble speed);
 // shows instructions how to send me a postcard
 void show_cardware_dialog();
 
+// loads settings from GConf
+void load_settings();
+
 #endif /* UTIL_H_ */