Diff of /trunk/src/misc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 212 by harbaum, Wed Nov 25 13:52:17 2009 UTC revision 216 by harbaum, Thu Nov 26 14:32:41 2009 UTC
# Line 28  Line 28 
28    
29  #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)  #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)
30  #include <hildon/hildon-entry.h>  #include <hildon/hildon-entry.h>
31    #include <hildon/hildon-touch-selector.h>
32    #include <hildon/hildon-picker-button.h>
33    #include <hildon/hildon-picker-dialog.h>
34  #endif  #endif
35    
36  char strlastchr(char *str) {  char strlastchr(char *str) {
# Line 628  static GtkWidget *popup_menu_create(appd Line 631  static GtkWidget *popup_menu_create(appd
631                      GtkWidget *lat_entry, GtkWidget *lon_entry) {                      GtkWidget *lat_entry, GtkWidget *lon_entry) {
632    GtkWidget *menu = gtk_menu_new();    GtkWidget *menu = gtk_menu_new();
633    
634    menu_add(menu, appdata, NULL, _("Current position (GPS)"),    menu_add(menu, appdata, icon_get_widget(ICON_POS, 18),
635             cb_gps, lon_entry, lat_entry);             _("Current position (GPS)"), cb_gps, lon_entry, lat_entry);
636    menu_add(menu, appdata, NULL, _("Geomath projection"),    menu_add(menu, appdata, icon_get_widget(ICON_POS, 19),
637             cb_geomath, lon_entry, lat_entry);             _("Geomath projection"), cb_geomath, lon_entry, lat_entry);
638  #ifdef ENABLE_OSM_GPS_MAP  #ifdef ENABLE_OSM_GPS_MAP
639    menu_add(menu, appdata, NULL, _("Map position"),    menu_add(menu, appdata, icon_get_widget(ICON_POS, 20),
640             cb_map, lon_entry, lat_entry);             _("Map position"), cb_map, lon_entry, lat_entry);
641  #endif  #endif
642    
643      printf("popup cache present: %s\n", appdata->cur_cache?"Yes":"No");
644    
645    if(appdata->cur_cache) {    if(appdata->cur_cache) {
646      cache_t *cache = appdata->cur_cache;      cache_t *cache = appdata->cur_cache;
647    
648      if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) {      if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) {
649        menu_add(menu, appdata, icon_get_widget(ICON_CACHE_TYPE, cache->type),        menu_add(menu, appdata, icon_get_widget(ICON_POS, cache->type + 6),
650                 cache->id, cb_cache, lon_entry, lat_entry);                 cache->id, cb_cache, lon_entry, lat_entry);
651      }      }
652    
# Line 650  static GtkWidget *popup_menu_create(appd Line 655  static GtkWidget *popup_menu_create(appd
655      while(wpt) {      while(wpt) {
656        GtkWidget *icon = NULL;        GtkWidget *icon = NULL;
657        if(wpt->sym != WPT_SYM_UNKNOWN)        if(wpt->sym != WPT_SYM_UNKNOWN)
658          icon = icon_get_widget(ICON_WPT, wpt->sym);          icon = icon_get_widget(ICON_POS, wpt->sym);
659    
660        menu_add(menu, appdata, icon, wpt->id, cb_cache,        menu_add(menu, appdata, icon, wpt->id, cb_cache,
661                 lon_entry, lat_entry);                 lon_entry, lat_entry);
# Line 692  GtkWidget *coo_popup(appdata_t *appdata, Line 697  GtkWidget *coo_popup(appdata_t *appdata,
697            (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));            (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
698  #endif  #endif
699    
700    gtk_button_set_image(GTK_BUTTON(button),    gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 17));
        gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON));  
701    
702    gtk_widget_set_tooltip_text(button, _("Preset coordinates"));    gtk_widget_set_tooltip_text(button, _("Preset coordinates"));
703    
# Line 716  GtkWidget *entry_new(void) { Line 720  GtkWidget *entry_new(void) {
720    return hildon_entry_new(HILDON_SIZE_AUTO);    return hildon_entry_new(HILDON_SIZE_AUTO);
721  #endif  #endif
722  }  }
723    
724    gboolean pos_differ(pos_t *pos1, pos_t *pos2) {
725      int lat1 = (60000 * pos1->lat)+0.5, lon1 = (60000 * pos1->lon)+0.5;
726      int lat2 = (60000 * pos2->lat)+0.5, lon2 = (60000 * pos2->lon)+0.5;
727    
728      return((lat1 != lat2) || (lon1 != lon2));
729    }
730    
731    #ifdef FREMANTLE
732    void selection_changed (HildonTouchSelector * selector,
733                       gpointer *user_data) {
734      gchar *current_selection = NULL;
735    
736      current_selection = hildon_touch_selector_get_current_text (selector);
737      g_debug ("Current selection : %s", current_selection);
738    }
739    
740    static GtkWidget *create_customized_selector() {
741      GtkWidget *selector = NULL;
742      GSList *icon_list = NULL;
743      GtkListStore *store_icons = NULL;
744      GSList *item = NULL;
745      GtkCellRenderer *renderer = NULL;
746      HildonTouchSelectorColumn *column = NULL;
747    
748      selector = hildon_touch_selector_new ();
749    
750      icon_list = gtk_stock_list_ids ();
751    
752      store_icons = gtk_list_store_new (1, G_TYPE_STRING);
753      for (item = icon_list; item; item = g_slist_next (item)) {
754        GtkTreeIter iter;
755        gchar *label = item->data;
756    
757        gtk_list_store_append (store_icons, &iter);
758        gtk_list_store_set (store_icons, &iter, 0, label, -1);
759        g_free (label);
760      }
761      g_slist_free (icon_list);
762    
763      renderer = gtk_cell_renderer_pixbuf_new ();
764      gtk_cell_renderer_set_fixed_size (renderer, -1, 100);
765    
766      column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
767                                                    GTK_TREE_MODEL (store_icons),
768                                                    renderer, "stock-id", 0, NULL);
769    
770      g_object_set (G_OBJECT (column), "text-column", 0, NULL);
771    
772      hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
773                                                       HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE);
774    
775    
776      g_signal_connect (G_OBJECT (selector), "changed",
777                        G_CALLBACK (selection_changed), NULL);
778    
779      return selector;
780    }
781    
782    static gint on_picker_request(GtkWidget *button, GdkEventButton *event,
783                                  gpointer data) {
784    
785      if(event->type == GDK_BUTTON_PRESS) {
786        GtkWidget *dialog = hildon_picker_dialog_new(NULL);
787        GtkWidget *selector = create_customized_selector();
788        hildon_picker_dialog_set_selector(HILDON_PICKER_DIALOG(dialog),
789                          HILDON_TOUCH_SELECTOR(selector));
790    
791        hildon_touch_selector_set_active(HILDON_TOUCH_SELECTOR (selector), 1, -1);
792    
793        gtk_widget_show_all(dialog);
794        gtk_dialog_run(GTK_DIALOG(dialog));
795        gtk_widget_destroy(dialog);
796    
797        return TRUE;
798      }
799      return FALSE;
800    }
801    
802    GtkWidget *picker_button_new(void) {
803      GtkWidget *button;
804    
805    #if 1
806      button = gtk_button_new();
807      hildon_gtk_widget_set_theme_size(button,
808              (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
809    
810      gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 17));
811    
812      gtk_signal_connect(GTK_OBJECT(button), "button-press-event",
813                         (GtkSignalFunc)on_picker_request, NULL);
814    
815    #else
816      button = hildon_picker_button_new(HILDON_SIZE_AUTO,
817                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL);
818    
819      hildon_button_set_title(HILDON_BUTTON(button), "Test");
820      hildon_picker_button_set_selector(HILDON_PICKER_BUTTON(button),
821                        HILDON_TOUCH_SELECTOR(create_customized_selector()));
822    #endif
823    
824      return button;
825    }
826    #endif

Legend:
Removed from v.212  
changed lines
  Added in v.216