Changeset 3301


Ignore:
Timestamp:
10/29/07 18:54:18 (6 years ago)
Author:
chris
Message:
  • 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
Location:
trunk/src/target/OM-2007.2/applications/openmoko-worldclock2
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/ChangeLog

    r3241 r3301  
     12007-10-29  Chris Lord  <chris@openedhand.com> 
     2 
     3        * Makefile.am: 
     4        * configure.ac: 
     5        * data/Makefile.am: 
     6        * src/Makefile.am: 
     7        * src/worldclock-data.c: 
     8        * src/worldclock-data.h: 
     9        * src/worldclock-main.c: (increment_time_timeout), 
     10        (date_time_changed_cb), (settings_clicked_cb), (add_marks), (main): 
     11        Add markers for time-zones on the map and add rudimentary system-clock 
     12        setting functionality 
     13 
    1142007-10-22  Chris Lord  <chris@openedhand.com> 
    215 
  • trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/Makefile.am

    r3241 r3301  
    1 SUBDIRS=src 
     1SUBDIRS=data src 
  • trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/configure.ac

    r3241 r3301  
    1414PKG_CHECK_MODULES(MOKOUI, libmokoui2 >= 0.3) 
    1515PKG_CHECK_MODULES(JANA, libjana libjana-ecal libjana-gtk) 
     16PKG_CHECK_MODULES(NOTIFY, libnotify >= 0.4) 
    1617 
    1718AC_OUTPUT([ 
    1819Makefile 
     20data/Makefile 
    1921src/Makefile 
    2022]) 
  • trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/Makefile.am

    r3241 r3301  
    11 
    2 AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" $(GTK_CFLAGS) $(JANA_CFLAGS) $(MOKOUI_CFLAGS) -Wall 
    3 AM_LDFLAGS = $(GTK_LIBS) $(JANA_LIBS) $(MOKOUI_LIBS) 
     2AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" $(GTK_CFLAGS) $(JANA_CFLAGS) $(MOKOUI_CFLAGS) $(NOTIFY_CFLAGS) -Wall 
     3AM_LDFLAGS = $(GTK_LIBS) $(JANA_LIBS) $(MOKOUI_LIBS) $(NOTIFY_LIBS) 
    44 
    55bin_PROGRAMS=openmoko-worldclock 
    66 
    7 openmoko_worldclock_SOURCES = worldclock-main.c 
     7openmoko_worldclock_SOURCES = \ 
     8        worldclock-main.c \ 
     9        worldclock-data.c \ 
     10        worldclock-data.h 
    811 
  • trunk/src/target/OM-2007.2/applications/openmoko-worldclock2/src/worldclock-main.c

    r3241 r3301  
     1/* 
     2 *  openmoko-worldclock -- OpenMoko Clock Application 
     3 * 
     4 *  Authored by Chris Lord <chris@openedhand.com> 
     5 * 
     6 *  Copyright (C) 2007 OpenMoko Inc. 
     7 * 
     8 *  This program is free software; you can redistribute it and/or modify 
     9 *  it under the terms of the GNU Lesser Public License as published by 
     10 *  the Free Software Foundation; version 2 of the license. 
     11 * 
     12 *  This program is distributed in the hope that it will be useful, 
     13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     15 *  GNU Lesser Public License for more details. 
     16 * 
     17 *  Current Version: $Rev$ ($Date$) [$Author$] 
     18 */ 
    119 
    220#include <gtk/gtk.h> 
     
    523#include <libjana-gtk/jana-gtk.h> 
    624#include <libmokoui2/moko-finger-scroll.h> 
     25#include <time.h> 
     26#include <sys/time.h> 
     27#include "worldclock-data.h" 
    728 
    829static gchar *location; 
     
    1536         
    1637        guint render_idle; 
     38        guint time_idle; 
    1739         
    1840        gchar *location; 
     
    5880} 
    5981 
     82static gboolean ignore_next = FALSE; 
     83 
     84static gboolean 
     85increment_time_timeout (JanaGtkDateTime *dt) 
     86{ 
     87        JanaTime *time; 
     88 
     89        ignore_next = TRUE; 
     90 
     91        time = jana_gtk_date_time_get_time (dt); 
     92        jana_time_set_seconds (time, jana_time_get_seconds (time) + 1); 
     93        jana_gtk_date_time_set_time (dt, time); 
     94        g_object_unref (time); 
     95         
     96        return TRUE; 
     97} 
     98 
     99static void 
     100date_time_changed_cb (JanaGtkDateTime *dt, WorldClockData *data) 
     101{ 
     102        if (ignore_next) { 
     103                ignore_next = FALSE; 
     104                return; 
     105        } 
     106        if (data->time_idle) { 
     107                g_source_remove (data->time_idle); 
     108                data->time_idle = 0; 
     109        } 
     110} 
     111 
     112static void 
     113settings_clicked_cb (GtkToolButton *button, WorldClockData *data) 
     114{ 
     115        GtkWidget *time_dialog, *datetime; 
     116        gchar *location; 
     117        JanaTime *time; 
     118         
     119        time_dialog = gtk_dialog_new_with_buttons ("Set time", 
     120                GTK_WINDOW (data->window), 
     121                GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_MODAL, 
     122                GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); 
     123         
     124        location = jana_ecal_utils_guess_location (); 
     125        time = jana_ecal_utils_time_now (location); 
     126        g_free (location); 
     127        datetime = jana_gtk_date_time_new (time); 
     128        jana_gtk_date_time_set_editable (JANA_GTK_DATE_TIME (datetime), TRUE); 
     129        g_object_unref (time); 
     130         
     131        g_signal_connect (datetime, "changed", 
     132                G_CALLBACK (date_time_changed_cb), data); 
     133 
     134#if GLIB_CHECK_VERSION(2,14,0) 
     135        data->time_idle = g_timeout_add_seconds (1, (GSourceFunc) 
     136                increment_time_timeout, datetime); 
     137#else 
     138        data->time_idle = g_timeout_add (1000, (GSourceFunc) 
     139                increment_time_timeout, datetime); 
     140#endif 
     141         
     142        gtk_container_add (GTK_CONTAINER ( 
     143                GTK_DIALOG (time_dialog)->vbox), datetime); 
     144        gtk_widget_show (datetime); 
     145         
     146        gtk_dialog_run (GTK_DIALOG (time_dialog)); 
     147         
     148        /* Set system time */ 
     149        if (data->time_idle) { 
     150                /* Time hasn't changed, don't set */ 
     151                g_source_remove (data->time_idle); 
     152        } else { 
     153                struct timeval time_tv; 
     154                struct tm time_tm; 
     155                 
     156                time = jana_gtk_date_time_get_time ( 
     157                        JANA_GTK_DATE_TIME (datetime)); 
     158 
     159                /* TODO: Maybe this should convert to UTC before setting? */ 
     160                time_tm = jana_utils_time_to_tm (time); 
     161                time_tv.tv_sec = timegm (&time_tm); 
     162                time_tv.tv_usec = 0; 
     163                 
     164                settimeofday (&time_tv, NULL); 
     165                 
     166                g_object_unref (time); 
     167        } 
     168         
     169        gtk_widget_destroy (time_dialog); 
     170} 
     171 
    60172static gboolean 
    61173set_time (GtkWidget *map) 
     
    91203        g_source_remove (data->render_idle); 
    92204        gtk_widget_hide (data->load_window); 
     205} 
     206 
     207static void 
     208add_marks (WorldClockData *data) 
     209{ 
     210        gint i, width, height; 
     211         
     212        gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height); 
     213         
     214        for (i = 0; i < G_N_ELEMENTS (world_clock_tzdata); i++) { 
     215                JanaGtkWorldMapMarker *mark; 
     216                gchar *path, *image_name; 
     217                GdkPixbuf *pixbuf; 
     218                 
     219                GError *error = NULL; 
     220 
     221                image_name = g_strdelimit (g_utf8_strdown ( 
     222                        world_clock_tzdata[i].country, -1), " '", '_'); 
     223                path = g_strconcat (PKGDATADIR G_DIR_SEPARATOR_S, 
     224                        image_name, ".svg", NULL); 
     225                g_free (image_name); 
     226 
     227                if (!g_file_test (path, G_FILE_TEST_EXISTS)) { 
     228                        pixbuf = NULL; 
     229                } else if (!(pixbuf = gdk_pixbuf_new_from_file_at_size (path, 
     230                             width, -1, &error))) { 
     231                        g_warning ("Error loading '%s': %s", 
     232                                path, error->message); 
     233                        g_error_free (error); 
     234                } 
     235                if (pixbuf) 
     236                        mark = jana_gtk_world_map_marker_pixbuf_new (pixbuf); 
     237                else 
     238                        mark = jana_gtk_world_map_marker_new (); 
     239 
     240                g_object_set_data (G_OBJECT (mark), "zone", 
     241                        (gpointer)(&world_clock_tzdata[i])); 
     242                jana_gtk_world_map_add_marker (JANA_GTK_WORLD_MAP (data->map), 
     243                        mark, world_clock_tzdata[i].lat, 
     244                        world_clock_tzdata[i].lon); 
     245                g_free (path); 
     246        } 
    93247} 
    94248 
     
    111265        toolbar = gtk_toolbar_new (); 
    112266 
     267        /* Settings button */ 
     268        button = worldclock_utils_toolbutton_new (GTK_STOCK_PREFERENCES); 
     269        gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 0); 
     270        gtk_toolbar_insert (GTK_TOOLBAR (toolbar), 
     271                gtk_separator_tool_item_new (), 0); 
     272        g_signal_connect (button, "clicked", 
     273                G_CALLBACK (settings_clicked_cb), &data); 
     274         
    113275        /* Zoom in button */ 
    114276        button = worldclock_utils_toolbutton_new (GTK_STOCK_ZOOM_IN); 
     
    129291        /* Create scrolling map */ 
    130292        data.map = jana_gtk_world_map_new (); 
     293        add_marks (&data); 
    131294        scroll = moko_finger_scroll_new (); 
    132295        moko_finger_scroll_add_with_viewport (MOKO_FINGER_SCROLL (scroll), 
     
    174337                "gtk-font-name", "Sans 6", 
    175338                NULL); 
     339#endif 
    176340        gtk_window_set_default_size (GTK_WINDOW (data.window), 480, 600); 
    177 #endif 
    178341 
    179342        location = jana_ecal_utils_guess_location (); 
Note: See TracChangeset for help on using the changeset viewer.