--- trunk/src/main.c 2009/07/06 14:07:36 24 +++ trunk/src/main.c 2009/08/04 14:07:18 44 @@ -202,6 +202,10 @@ GtkTreeIter iter; GtkTreeModel *model = gtk_tree_view_get_model(treeview); + /* check if a cache is already selected and ignore click if yes */ + /* (was probably a double click) */ + if(appdata->cur_cache) return; + if(gtk_tree_model_get_iter(model, &iter, path)) { cache_t *cache; gtk_tree_model_get(model, &iter, CACHELIST_COL_DATA, &cache, -1); @@ -587,7 +591,7 @@ g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view); appdata->cur_gpx = gpx; - char *title = g_strdup_printf("GPXView - %s", gpx->name); + char *title = g_strdup_printf("%s - GPXView", gpx->name); gtk_window_set_title(GTK_WINDOW(window), title); g_free(title); @@ -713,6 +717,10 @@ GtkTreeIter iter; GtkTreeModel *model = gtk_tree_view_get_model(treeview); + /* check if a cache is already selected and ignore click if yes */ + /* (was probably a double click) */ + if(appdata->cur_gpx) return; + if (gtk_tree_model_get_iter(model, &iter, path)) { gpx_t *gpx; gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1); @@ -1433,7 +1441,7 @@ gtk_widget_destroy(dialog); } -void on_window_destroy (GtkWidget *widget, gpointer data); +static void on_window_destroy (GtkWidget *widget, gpointer data); #ifndef USE_MAEMO static void @@ -1509,6 +1517,13 @@ garmin_export(appdata); } +#ifdef ENABLE_OSM_GPS_MAP +static void +cb_menu_map(GtkWidget *window, gpointer data) { + map((appdata_t *)data); +} +#endif + static void cb_menu_geomath(GtkWidget *window, gpointer data) { geomath_dialog((appdata_t *)data); @@ -1525,106 +1540,133 @@ } #ifdef USE_STACKABLE_WINDOW -static GtkWidget *export_menu_create(appdata_t *appdata) { - GtkWidget *button; - HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new()); - - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Export to Maemo Mapper"), - _("Save a Maemo Mapper POI file")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_export_mmpoi), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); +typedef struct { + char *label, *desc; + GtkSignalFunc activate_cb; +} menu_entry_t; - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Export Field Notes"), - _("Save a Garmin Field Notes file")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_export_log), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); +typedef struct { + const char *title; + const menu_entry_t *menu; + int len; +} submenu_t; - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Export Garmin GPX"), - _("Save modified waypoints in GPX file")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_export_garmin), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); +#define COLUMNS 1 - gtk_widget_show_all(GTK_WIDGET(menu)); +void on_submenu_entry_clicked(GtkButton *button, GtkWidget *menu) { - return GTK_WIDGET(menu); + /* force closing of submenu dialog */ + gtk_dialog_response(GTK_DIALOG(menu), GTK_RESPONSE_NONE); + gtk_widget_hide(menu); + + /* let gtk clean up */ + while(gtk_events_pending()) + gtk_main_iteration(); } -/* the export submenu */ -void on_export_clicked(GtkButton *button, appdata_t *appdata) { - if(!appdata->export_menu) - appdata->export_menu = export_menu_create(appdata); +static GtkWidget *app_submenu_create(appdata_t *appdata, + const submenu_t *submenu) { - /* draw a popup menu */ - hildon_app_menu_popup(HILDON_APP_MENU(appdata->export_menu), - GTK_WINDOW(hildon_window_stack_peek( - hildon_window_stack_get_default()))); -} + /* create a oridinary dialog box */ + GtkWidget *dialog = gtk_dialog_new(); + gtk_window_set_title(GTK_WINDOW(dialog), _(submenu->title)); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), + GTK_WINDOW(appdata->window)); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); -static GtkWidget *tools_menu_create(appdata_t *appdata) { - GtkWidget *button; - HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new()); + GtkWidget *table = gtk_table_new(submenu->len/COLUMNS, COLUMNS, TRUE); + int x = 0, y = 0; - /* the following doesn't have an effect */ - // gtk_window_set_title(GTK_WINDOW(menu), "Tools"); + const menu_entry_t *menu_entries = submenu->menu; + while(menu_entries->label) { + GtkWidget *button = NULL; - button = hildon_button_new_with_text( + button = hildon_button_new_with_text( HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Geomath"), - _("Geocoordinate calculation")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_geomath), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); + _(menu_entries->label), _(menu_entries->desc)); + /* try to center both texts */ + hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5); + hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5); - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Geotext"), - _("Text analysis")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_geotext), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); - + g_signal_connect(button, "clicked", + G_CALLBACK(on_submenu_entry_clicked), dialog); + + g_signal_connect(button, "clicked", + menu_entries->activate_cb, appdata); + + gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1); + + x++; + if(x == COLUMNS) { x = 0; y++; } - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Precise Position"), - _("Calculate a precise GPS position")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_precpos), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); + menu_entries++; + } - gtk_widget_show_all(GTK_WIDGET(menu)); + gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table); + + return dialog; +} + +/* popup the dialog shaped submenu */ +static void submenu_popup(GtkWidget *menu) { + gtk_widget_show_all(menu); + gtk_dialog_run(GTK_DIALOG(menu)); + gtk_widget_hide(menu); +} + +static void submenu_cleanup(GtkWidget *menu) { + gtk_widget_destroy(menu); +} + +static const menu_entry_t submenu_export_entries[] = { + { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file", + G_CALLBACK(cb_menu_export_mmpoi) }, + { "Export Field Notes", "Save a Garmin Field Notes file", + G_CALLBACK(cb_menu_export_log) }, + { "Export Garmin GPX", "Save modified waypoints in GPX file", + G_CALLBACK(cb_menu_export_garmin) }, + { NULL, NULL, NULL } +}; + +static const submenu_t submenu_export = { + "Export", submenu_export_entries, + sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1 +}; + +/* the export submenu */ +void on_export_clicked(GtkButton *button, appdata_t *appdata) { + if(!appdata->export_menu) + appdata->export_menu = app_submenu_create(appdata, &submenu_export); - return GTK_WIDGET(menu); + submenu_popup(appdata->export_menu); } +static const menu_entry_t submenu_tools_entries[] = { + { "Geomath", "Geocoordinate calculation", + G_CALLBACK(cb_menu_geomath) }, + { "Geotext", "Text analysis", + G_CALLBACK(cb_menu_geotext) }, + { "Precise Position", "Calculate a precise GPS position", + G_CALLBACK(cb_menu_precpos) }, + { NULL, NULL, NULL } +}; + +static const submenu_t submenu_tools = { + "Tools", submenu_tools_entries, + sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1 +}; + /* the tools submenu */ void on_tools_clicked(GtkButton *button, appdata_t *appdata) { if(!appdata->tools_menu) - appdata->tools_menu = tools_menu_create(appdata); + appdata->tools_menu = app_submenu_create(appdata, &submenu_tools); - /* draw a popup menu */ - hildon_app_menu_popup(HILDON_APP_MENU(appdata->tools_menu), - GTK_WINDOW(hildon_window_stack_peek( - hildon_window_stack_get_default()))); + submenu_popup(appdata->tools_menu); } - HildonAppMenu *menu_create(appdata_t *appdata, int mode) { GtkWidget *button; HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new()); @@ -1650,9 +1692,7 @@ g_signal_connect_after(button, "clicked", G_CALLBACK(cb_menu_adddir), appdata); hildon_app_menu_append(menu, GTK_BUTTON(button)); - } - if(mode == MENU_GPXLIST) { button = gtk_button_new_with_label(_("Export")); g_signal_connect_after(button, "clicked", G_CALLBACK(on_export_clicked), appdata); @@ -1669,6 +1709,15 @@ G_CALLBACK(on_tools_clicked), appdata); hildon_app_menu_append(menu, GTK_BUTTON(button)); +#ifdef ENABLE_OSM_GPS_MAP + if((mode == MENU_GPXLIST) || (mode == MENU_CACHELIST)) { + button = gtk_button_new_with_label(_("Map")); + g_signal_connect_after(button, "clicked", + G_CALLBACK(cb_menu_map), appdata); + hildon_app_menu_append(menu, GTK_BUTTON(button)); + } +#endif + #ifdef HILDON_HELP button = gtk_button_new_with_label(_("Help")); g_signal_connect_after(button, "clicked", @@ -1786,6 +1835,13 @@ submenu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); +#ifdef ENABLE_OSM_GPS_MAP + item = gtk_menu_item_new_with_label( _("Map") ); + gtk_menu_append(GTK_MENU_SHELL(submenu), item); + g_signal_connect(item, "activate", + GTK_SIGNAL_FUNC(cb_menu_map), appdata); +#endif + item = gtk_menu_item_new_with_label( _("Geomath") ); gtk_menu_append(GTK_MENU_SHELL(submenu), item); g_signal_connect(item, "activate", @@ -1845,6 +1901,11 @@ if(appdata->image_path) free(appdata->image_path); if(appdata->search_str) free(appdata->search_str); +#ifdef USE_STACKABLE_WINDOW + if(appdata->export_menu) submenu_cleanup(appdata->export_menu); + if(appdata->tools_menu) submenu_cleanup(appdata->tools_menu); +#endif + gnome_vfs_shutdown(); icons_free(); gps_release(appdata); @@ -1873,7 +1934,7 @@ puts("everything is gone"); } -void on_window_destroy (GtkWidget *widget, gpointer data) { +static void on_window_destroy (GtkWidget *widget, gpointer data) { appdata_t *appdata = (appdata_t*)data; gconf_save_state(appdata); @@ -2216,7 +2277,6 @@ appdata.vbox = gtk_vbox_new(FALSE, 2); gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox); - #ifndef USE_STACKABLE_WINDOW menu_create(&appdata); #else