r3301 - in trunk/src/target/OM-2007.2/applications/openmoko-worldclock2: . data src

chris at sita.openmoko.org chris at sita.openmoko.org
Mon Oct 29 18:54:20 CET 2007


Author: chris
Date: 2007-10-29 18:54:18 +0100 (Mon, 29 Oct 2007)
New Revision: 3301

Added:
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/data/
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/data/Makefile.am
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.c
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.h
Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/ChangeLog
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/Makefile.am
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/configure.ac
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/Makefile.am
   trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-main.c
Log:
        * Makefile.am:
        * configure.ac:
        * data/Makefile.am:
        * src/Makefile.am:
        * src/worldclock-data.c:
        * src/worldclock-data.h:
        * src/worldclock-main.c: (increment_time_timeout),
        (date_time_changed_cb), (settings_clicked_cb), (add_marks), (main):
        Add markers for time-zones on the map and add rudimentary system-clock 
        setting functionality


Modified: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/ChangeLog	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/ChangeLog	2007-10-29 17:54:18 UTC (rev 3301)
@@ -1,3 +1,16 @@
+2007-10-29  Chris Lord  <chris at openedhand.com>
+
+	* Makefile.am:
+	* configure.ac:
+	* data/Makefile.am:
+	* src/Makefile.am:
+	* src/worldclock-data.c:
+	* src/worldclock-data.h:
+	* src/worldclock-main.c: (increment_time_timeout),
+	(date_time_changed_cb), (settings_clicked_cb), (add_marks), (main):
+	Add markers for time-zones on the map and add rudimentary system-clock
+	setting functionality
+
 2007-10-22  Chris Lord  <chris at openedhand.com>
 
 	* AUTHORS:

Modified: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/Makefile.am	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/Makefile.am	2007-10-29 17:54:18 UTC (rev 3301)
@@ -1 +1 @@
-SUBDIRS=src
+SUBDIRS=data src

Modified: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/configure.ac
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/configure.ac	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/configure.ac	2007-10-29 17:54:18 UTC (rev 3301)
@@ -13,9 +13,11 @@
 PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6.0)
 PKG_CHECK_MODULES(MOKOUI, libmokoui2 >= 0.3)
 PKG_CHECK_MODULES(JANA, libjana libjana-ecal libjana-gtk)
+PKG_CHECK_MODULES(NOTIFY, libnotify >= 0.4)
 
 AC_OUTPUT([
 Makefile
+data/Makefile
 src/Makefile
 ])
 

Added: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/data/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/data/Makefile.am	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/data/Makefile.am	2007-10-29 17:54:18 UTC (rev 3301)
@@ -0,0 +1,7 @@
+resdir = $(pkgdatadir)
+res_DATA = 
+
+MAINTAINERCLEANFILES = Makefile.in
+
+EXTRA_DIST = $(res_DATA)
+

Modified: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/Makefile.am	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/Makefile.am	2007-10-29 17:54:18 UTC (rev 3301)
@@ -1,8 +1,11 @@
 
-AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" $(GTK_CFLAGS) $(JANA_CFLAGS) $(MOKOUI_CFLAGS) -Wall
-AM_LDFLAGS = $(GTK_LIBS) $(JANA_LIBS) $(MOKOUI_LIBS)
+AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" $(GTK_CFLAGS) $(JANA_CFLAGS) $(MOKOUI_CFLAGS) $(NOTIFY_CFLAGS) -Wall
+AM_LDFLAGS = $(GTK_LIBS) $(JANA_LIBS) $(MOKOUI_LIBS) $(NOTIFY_LIBS)
 
 bin_PROGRAMS=openmoko-worldclock
 
-openmoko_worldclock_SOURCES = worldclock-main.c
+openmoko_worldclock_SOURCES = \
+	worldclock-main.c \
+	worldclock-data.c \
+	worldclock-data.h
 

Added: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.c	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.c	2007-10-29 17:54:18 UTC (rev 3301)
@@ -0,0 +1,63 @@
+/*
+ *  openmoko-worldclock -- OpenMoko Clock Application
+ *
+ *  Authored by Chris Lord <chris at openedhand.com>
+ *
+ *  Copyright (C) 2007 OpenMoko Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#include "worldclock-data.h"
+
+/* Note, these are the same timezones as the 'main' zones in openmoko-dates2 */
+ const WorldClockZoneData world_clock_tzdata[39] = {
+	{ "Amsterdam", "Europe/Amsterdam", 52.367, 4.9, "The Netherlands" },
+	{ "Auckland", "Pacific/Auckland", -36.85, 174.783, "New Zealand" },
+	{ "Berlin", "Europe/Berlin", 52.52, 13.41, "Germany" },
+	{ "Buenos Aires", "America/Argentina/Buenos_Aires", -34.667, -58.4, "Argentina" },
+	{ "Cairo", "Africa/Cairo", 30.05, 31.3667, "Egypt" },
+	{ "Calcutta", "Asia/Calcutta", 22.5656, 88.34667, "India" },
+	{ "Chicago", "America/Chicago", 41.9, -87.65, "The United States" },
+	{ "Denver", "America/Denver", 39.75, -104.9833, "The United States" },
+	{ "Dublin", "Europe/Dublin", 53.34277, -6.2661, "Ireland" },
+	{ "Hong Kong", "Asia/Hong_Kong", 22.2833, 114.1333, "Hong Kong" },
+	{ "Honolulu", "Pacific/Honolulu", 21.30889, -157.8261, "The United States" },
+	{ "Istanbul", "Europe/Istanbul", 41, 29, "Turkey" },
+	{ "Jakarta", "Asia/Jakarta", -6.1833, 106.8333, "Indonesia" },
+	{ "Karachi", "Asia/Karachi", 24.85, 67.01667, "Pakistan" },
+	{ "Kinshasa", "Africa/Kinshasa", -4.2667, 15.2833, "The Democratic Republic of the Congo" },
+	{ "Lagos", "Africa/Lagos", 6.5833, 3.3331, "Nigeria" },
+	{ "Lima", "America/Lima", 12.0433, 0.02833, "Peru" },
+	{ "London", "Europe/London", 51.50694, -0.1275, "The United Kingdom" },
+	{ "Los Angeles", "America/Los_Angeles", 34.05, -118.25, "The United States" },
+	{ "Madrid", "Europe/Madrid", 40.3833, -3.71667, "Spain" },
+	{ "Manila", "Asia/Manila", 14.5833, 121, "The Philippines" },
+	{ "Mexico City", "America/Mexico_City", 19.6931, -99.218611111, "Mexico" },
+	{ "Montreal", "America/Montreal", 45.50889, -73.55417, "Canada" },
+	{ "Moscow", "Europe/Moscow", 55.75222, 37.61556, "Russia" },
+	{ "New York", "America/New_York", 43.14, -77.63944, "The United States" },
+	{ "Paris", "Europe/Paris", 48.8667, 2.3331, "France" },
+	{ "Rome", "Europe/Rome", 41.9, 12.4833, "Italy" },
+	{ "Sao Paulo", "America/Sao_Paulo", -23.54333, -46.63306, "Brazil" },
+	{ "Seoul", "Asia/Seoul", 37.521, 126.986, "South Korea" },
+	{ "Shanghai", "Asia/Shanghai", 31.1667, 121.4667, "The People's Republic of China" },
+	{ "Singapore", "Asia/Singapore", 1.2833, 103.85, "Singapore" },
+	{ "Stockholm", "Europe/Stockholm", 59.35, 18.0667, "Sweden" },
+	{ "Sydney", "Australia/Sydney", -33.86833, 151.20861, "Australia" },
+	{ "Taipei", "Asia/Taipei", 25.0333, 121.6333, "The Republic of China" },
+	{ "Tehran", "Asia/Tehran", 35.696189, 51.42296, "Iran" },
+	{ "Tijuana", "America/Tijuana", 32.525, -117.0333, "Mexico" },
+	{ "Tokyo", "Asia/Tokyo", 35.6833, 139.7667, "Japan" },
+	{ "Toronto", "America/Toronto", 43.65, -79.38333, "Canada" },
+	{ "Vancouver", "America/Vancouver", 49.26667, -123.1167, "Canada" },
+ };

Added: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.h	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-data.h	2007-10-29 17:54:18 UTC (rev 3301)
@@ -0,0 +1,35 @@
+/*
+ *  openmoko-worldclock -- OpenMoko Clock Application
+ *
+ *  Authored by Chris Lord <chris at openedhand.com>
+ *
+ *  Copyright (C) 2007 OpenMoko Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#ifndef WORLDCLOCK_DATA_H
+#define WORLDCLOCK_DATA_H
+
+#include <glib.h>
+
+typedef struct {
+	gchar *name;
+	gchar *tzname;
+	gdouble lat;
+	gdouble lon;
+	gchar *country;
+} WorldClockZoneData;
+
+extern const WorldClockZoneData world_clock_tzdata[39];
+
+#endif /* WORLDCLOCK_DATA_H */

Modified: trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-main.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-main.c	2007-10-29 11:13:38 UTC (rev 3300)
+++ trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-main.c	2007-10-29 17:54:18 UTC (rev 3301)
@@ -1,3 +1,21 @@
+/*
+ *  openmoko-worldclock -- OpenMoko Clock Application
+ *
+ *  Authored by Chris Lord <chris at openedhand.com>
+ *
+ *  Copyright (C) 2007 OpenMoko Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
 
 #include <gtk/gtk.h>
 #include <libjana/jana.h>
@@ -4,6 +22,9 @@
 #include <libjana-ecal/jana-ecal.h>
 #include <libjana-gtk/jana-gtk.h>
 #include <libmokoui2/moko-finger-scroll.h>
+#include <time.h>
+#include <sys/time.h>
+#include "worldclock-data.h"
 
 static gchar *location;
 
@@ -14,6 +35,7 @@
 	GtkWidget *load_bar;
 	
 	guint render_idle;
+	guint time_idle;
 	
 	gchar *location;
 	gdouble zoom_level;
@@ -57,7 +79,97 @@
 	zoom_map (data);
 }
 
+static gboolean ignore_next = FALSE;
+
 static gboolean
+increment_time_timeout (JanaGtkDateTime *dt)
+{
+	JanaTime *time;
+
+	ignore_next = TRUE;
+
+	time = jana_gtk_date_time_get_time (dt);
+	jana_time_set_seconds (time, jana_time_get_seconds (time) + 1);
+	jana_gtk_date_time_set_time (dt, time);
+	g_object_unref (time);
+	
+	return TRUE;
+}
+
+static void
+date_time_changed_cb (JanaGtkDateTime *dt, WorldClockData *data)
+{
+	if (ignore_next) {
+		ignore_next = FALSE;
+		return;
+	}
+	if (data->time_idle) {
+		g_source_remove (data->time_idle);
+		data->time_idle = 0;
+	}
+}
+
+static void
+settings_clicked_cb (GtkToolButton *button, WorldClockData *data)
+{
+	GtkWidget *time_dialog, *datetime;
+	gchar *location;
+	JanaTime *time;
+	
+	time_dialog = gtk_dialog_new_with_buttons ("Set time",
+		GTK_WINDOW (data->window),
+		GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_MODAL,
+		GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
+	
+	location = jana_ecal_utils_guess_location ();
+	time = jana_ecal_utils_time_now (location);
+	g_free (location);
+	datetime = jana_gtk_date_time_new (time);
+	jana_gtk_date_time_set_editable (JANA_GTK_DATE_TIME (datetime), TRUE);
+	g_object_unref (time);
+	
+	g_signal_connect (datetime, "changed",
+		G_CALLBACK (date_time_changed_cb), data);
+
+#if GLIB_CHECK_VERSION(2,14,0)
+	data->time_idle = g_timeout_add_seconds (1, (GSourceFunc)
+		increment_time_timeout, datetime);
+#else
+	data->time_idle = g_timeout_add (1000, (GSourceFunc)
+		increment_time_timeout, datetime);
+#endif
+	
+	gtk_container_add (GTK_CONTAINER (
+		GTK_DIALOG (time_dialog)->vbox), datetime);
+	gtk_widget_show (datetime);
+	
+	gtk_dialog_run (GTK_DIALOG (time_dialog));
+	
+	/* Set system time */
+	if (data->time_idle) {
+		/* Time hasn't changed, don't set */
+		g_source_remove (data->time_idle);
+	} else {
+		struct timeval time_tv;
+		struct tm time_tm;
+		
+		time = jana_gtk_date_time_get_time (
+			JANA_GTK_DATE_TIME (datetime));
+
+		/* TODO: Maybe this should convert to UTC before setting? */
+		time_tm = jana_utils_time_to_tm (time);
+		time_tv.tv_sec = timegm (&time_tm);
+		time_tv.tv_usec = 0;
+		
+		settimeofday (&time_tv, NULL);
+		
+		g_object_unref (time);
+	}
+	
+	gtk_widget_destroy (time_dialog);
+}
+
+static gboolean
 set_time (GtkWidget *map)
 {
 	JanaTime *time;
@@ -92,6 +204,48 @@
 	gtk_widget_hide (data->load_window);
 }
 
+static void
+add_marks (WorldClockData *data)
+{
+	gint i, width, height;
+	
+	gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
+	
+	for (i = 0; i < G_N_ELEMENTS (world_clock_tzdata); i++) {
+		JanaGtkWorldMapMarker *mark;
+		gchar *path, *image_name;
+		GdkPixbuf *pixbuf;
+		
+		GError *error = NULL;
+
+		image_name = g_strdelimit (g_utf8_strdown (
+			world_clock_tzdata[i].country, -1), " '", '_');
+		path = g_strconcat (PKGDATADIR G_DIR_SEPARATOR_S,
+			image_name, ".svg", NULL);
+		g_free (image_name);
+
+		if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
+			pixbuf = NULL;
+		} else if (!(pixbuf = gdk_pixbuf_new_from_file_at_size (path,
+			     width, -1, &error))) {
+			g_warning ("Error loading '%s': %s",
+				path, error->message);
+			g_error_free (error);
+		}
+		if (pixbuf)
+			mark = jana_gtk_world_map_marker_pixbuf_new (pixbuf);
+		else
+			mark = jana_gtk_world_map_marker_new ();
+
+		g_object_set_data (G_OBJECT (mark), "zone",
+			(gpointer)(&world_clock_tzdata[i]));
+		jana_gtk_world_map_add_marker (JANA_GTK_WORLD_MAP (data->map),
+			mark, world_clock_tzdata[i].lat,
+			world_clock_tzdata[i].lon);
+		g_free (path);
+	}
+}
+
 int
 main (int argc, char **argv)
 {
@@ -110,6 +264,14 @@
 	/* Create toolbar */
 	toolbar = gtk_toolbar_new ();
 
+	/* Settings button */
+	button = worldclock_utils_toolbutton_new (GTK_STOCK_PREFERENCES);
+	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 0);
+	gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
+		gtk_separator_tool_item_new (), 0);
+	g_signal_connect (button, "clicked",
+		G_CALLBACK (settings_clicked_cb), &data);
+	
 	/* Zoom in button */
 	button = worldclock_utils_toolbutton_new (GTK_STOCK_ZOOM_IN);
 	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 0);
@@ -128,6 +290,7 @@
 
 	/* Create scrolling map */
 	data.map = jana_gtk_world_map_new ();
+	add_marks (&data);
 	scroll = moko_finger_scroll_new ();
 	moko_finger_scroll_add_with_viewport (MOKO_FINGER_SCROLL (scroll),
 		data.map);
@@ -173,8 +336,8 @@
 		"gtk-xft-dpi", 285 * 1024,
 		"gtk-font-name", "Sans 6",
 		NULL);
+#endif
 	gtk_window_set_default_size (GTK_WINDOW (data.window), 480, 600);
-#endif
 
 	location = jana_ecal_utils_guess_location ();
 	id = g_timeout_add (1000 * 60 * 10, (GSourceFunc)set_time, data.map);





More information about the commitlog mailing list