X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/e5657444f0e97263d19e508251492b17df478944..ab4553c3321e7d41330252da08d42a4c3b558110:/src/vikwindow.c?ds=sidebyside diff --git a/src/vikwindow.c b/src/vikwindow.c index 9e608410..b2228ec1 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -3,6 +3,7 @@ * * Copyright (C) 2003-2005, Evan Battaglia * Copyright (C) 2005-2006, Alex Foobarian + * Copyright (C) 2012, Rob Norris * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -203,6 +204,7 @@ enum { static guint window_signals[VW_LAST_SIGNAL] = { 0 }; +// TODO get rid of this as this is unnecessary duplication... static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Pan"), N_("Zoom"), N_("Ruler"), N_("Select") }; GType vik_window_get_type (void) @@ -261,7 +263,7 @@ void vik_window_selected_layer(VikWindow *vw, VikLayer *vl) for (j = 0; j < tool_count; j++) { action = gtk_action_group_get_action(vw->action_group, - layer_interface->tools[j].name); + layer_interface->tools[j].radioActionEntry.name); g_object_set(action, "sensitive", i == vl->type, NULL); } } @@ -462,7 +464,8 @@ static void draw_status ( VikWindow *vw ) /* xmpp should be a whole number so don't show useless .000 bit */ g_snprintf ( zoom_level, 22, "%d %s", (int)xmpp, unit ); if ( vw->current_tool == TOOL_LAYER ) - vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_TOOL, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].name ); + // Use tooltip rather than the internal name as the tooltip is i8n + vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_TOOL, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].radioActionEntry.tooltip ); else vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_TOOL, _(tool_names[vw->current_tool]) ); @@ -1016,7 +1019,7 @@ static gboolean ruler_key_press (VikLayer *vl, GdkEventKey *event, ruler_tool_st } static VikToolInterface ruler_tool = - { "Ruler", + { { "Ruler", "vik-icon-ruler", N_("_Ruler"), "R", N_("Ruler Tool"), 2 }, (VikToolConstructorFunc) ruler_create, (VikToolDestructorFunc) ruler_destroy, (VikToolActivationFunc) NULL, @@ -1062,7 +1065,7 @@ static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *ev } static VikToolInterface zoom_tool = - { "Zoom", + { { "Zoom", "vik-icon-zoom", N_("_Zoom"), "Z", N_("Zoom Tool"), 1 }, (VikToolConstructorFunc) zoomtool_create, (VikToolDestructorFunc) NULL, (VikToolActivationFunc) NULL, @@ -1106,7 +1109,7 @@ static VikLayerToolFuncStatus pantool_release (VikLayer *vl, GdkEventButton *eve } static VikToolInterface pan_tool = - { "Pan", + { { "Pan", "vik-icon-pan", N_("_Pan"), "P", N_("Pan Tool"), 0 }, (VikToolConstructorFunc) pantool_create, (VikToolDestructorFunc) NULL, (VikToolActivationFunc) NULL, @@ -1222,7 +1225,7 @@ static VikLayerToolFuncStatus selecttool_release (VikLayer *vl, GdkEventButton * } static VikToolInterface select_tool = - { "Select", + { { "Select", "vik-icon-select", N_("_Select"), "S", N_("Select Tool"), 3 }, (VikToolConstructorFunc) selecttool_create, (VikToolDestructorFunc) selecttool_destroy, (VikToolActivationFunc) NULL, @@ -1343,7 +1346,6 @@ static void menu_copy_layer_cb ( GtkAction *a, VikWindow *vw ) static void menu_cut_layer_cb ( GtkAction *a, VikWindow *vw ) { vik_layers_panel_cut_selected ( vw->viking_vlp ); - draw_update ( vw ); vw->modified = TRUE; } @@ -1351,7 +1353,6 @@ static void menu_paste_layer_cb ( GtkAction *a, VikWindow *vw ) { if ( a_clipboard_paste ( vw->viking_vlp ) ) { - draw_update ( vw ); vw->modified = TRUE; } } @@ -1476,7 +1477,7 @@ static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name) { int i; for (i=0; in_tools; i++) { - if (!strcmp(tool_name, vt->tools[i].ti.name)) { + if (!strcmp(tool_name, vt->tools[i].ti.radioActionEntry.name)) { break; } } @@ -1561,7 +1562,7 @@ static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event) void vik_window_enable_layer_tool ( VikWindow *vw, gint layer_id, gint tool_id ) { - gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, vik_layer_get_interface(layer_id)->tools[tool_id].name ) ); + gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, vik_layer_get_interface(layer_id)->tools[tool_id].radioActionEntry.name ) ); } /* this function gets called whenever a toolbar tool is clicked */ @@ -1593,7 +1594,7 @@ static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw ) /* TODO: only enable tools from active layer */ for (layer_id=0; layer_idtools_count; tool_id++ ) { - if (!strcmp(vik_layer_get_interface(layer_id)->tools[tool_id].name, gtk_action_get_name(a))) { + if (!strcmp(vik_layer_get_interface(layer_id)->tools[tool_id].radioActionEntry.name, gtk_action_get_name(a))) { vw->current_tool = TOOL_LAYER; vw->tool_layer_id = layer_id; vw->tool_tool_id = tool_id; @@ -1672,12 +1673,15 @@ static void on_activate_recent_item (GtkRecentChooser *chooser, g_object_unref ( file ); if ( self->filename ) { - gchar *filenames[] = { path, NULL }; + GSList *filenames = NULL; + filenames = g_slist_append ( filenames, path ); g_signal_emit ( G_OBJECT(self), window_signals[VW_OPENWINDOW_SIGNAL], 0, filenames ); + // NB: GSList & contents are freed by main.open_window } - else + else { vik_window_open_file ( self, path, TRUE ); - g_free ( path ); + g_free ( path ); + } } g_free (filename); @@ -1804,6 +1808,42 @@ static void load_file ( GtkAction *a, VikWindow *vw ) GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + GtkFileFilter *filter; + // NB file filters are listed this way for alphabetical ordering +#ifdef VIK_CONFIG_GEOCACHES + filter = gtk_file_filter_new (); + gtk_file_filter_set_name( filter, _("Geocaching") ); + gtk_file_filter_add_pattern ( filter, "*.loc" ); // No MIME type available + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter); +#endif + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name( filter, _("Google Earth") ); + gtk_file_filter_add_mime_type ( filter, "application/vnd.google-earth.kml+xml"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter); + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name( filter, _("GPX") ); + gtk_file_filter_add_pattern ( filter, "*.gpx" ); // No MIME type available + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter); + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name( filter, _("Viking") ); + gtk_file_filter_add_pattern ( filter, "*.vik" ); + gtk_file_filter_add_pattern ( filter, "*.viking" ); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter); + + // NB could have filters for gpspoint (*.gps,*.gpsoint?) + gpsmapper (*.gsm,*.gpsmapper?) + // However assume this are barely used and thus not worthy of inclusion + // as they'll just make the options too many and have no clear file pattern + // one can always use the all option + filter = gtk_file_filter_new (); + gtk_file_filter_set_name( filter, _("All") ); + gtk_file_filter_add_pattern ( filter, "*" ); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter); + // Default to any file - same as before open filters were added + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(vw->open_dia), filter); + gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER(vw->open_dia), TRUE ); gtk_window_set_transient_for ( GTK_WINDOW(vw->open_dia), GTK_WINDOW(vw) ); gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->open_dia), TRUE ); @@ -1901,6 +1941,11 @@ static void acquire_from_gps ( GtkAction *a, VikWindow *vw ) a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface ); } +static void acquire_from_file ( GtkAction *a, VikWindow *vw ) +{ + a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_file_interface ); +} + static void acquire_from_google ( GtkAction *a, VikWindow *vw ) { a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface ); @@ -1920,6 +1965,14 @@ static void acquire_from_gc ( GtkAction *a, VikWindow *vw ) } #endif +#ifdef VIK_CONFIG_GEOTAG +static void acquire_from_geotag ( GtkAction *a, VikWindow *vw ) +{ + vik_datasource_geotag_interface.mode = VIK_DATASOURCE_CREATENEWLAYER; + a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_geotag_interface ); +} +#endif + static void goto_default_location( GtkAction *a, VikWindow *vw) { struct LatLon ll; @@ -2480,14 +2533,18 @@ static GtkActionEntry entries[] = { { "Open", GTK_STOCK_OPEN, N_("_Open..."), "O", N_("Open a file"), (GCallback)load_file }, { "OpenRecentFile", NULL, N_("Open _Recent File"), NULL, NULL, (GCallback)NULL }, { "Append", GTK_STOCK_ADD, N_("Append _File..."), NULL, N_("Append data from a different file"), (GCallback)load_file }, - { "Acquire", NULL, N_("A_cquire"), 0, 0, 0 }, + { "Acquire", GTK_STOCK_GO_DOWN, N_("A_cquire"), NULL, NULL, (GCallback)NULL }, { "AcquireGPS", NULL, N_("From _GPS..."), NULL, N_("Transfer data from a GPS device"), (GCallback)acquire_from_gps }, + { "AcquireGPSBabel", NULL, N_("Import File With GPS_Babel..."), NULL, N_("Import file via GPSBabel converter"), (GCallback)acquire_from_file }, { "AcquireGoogle", NULL, N_("Google _Directions..."), NULL, N_("Get driving directions from Google"), (GCallback)acquire_from_google }, #ifdef VIK_CONFIG_OPENSTREETMAP { "AcquireOSM", NULL, N_("_OSM Traces..."), NULL, N_("Get traces from OpenStreetMap"), (GCallback)acquire_from_osm }, #endif #ifdef VIK_CONFIG_GEOCACHES { "AcquireGC", NULL, N_("Geo_caches..."), NULL, N_("Get Geocaches from geocaching.com"), (GCallback)acquire_from_gc }, +#endif +#ifdef VIK_CONFIG_GEOTAG + { "AcquireGeotag", NULL, N_("From Geotagged _Images..."), NULL, N_("Create waypoints from geotagged images"), (GCallback)acquire_from_geotag }, #endif { "Save", GTK_STOCK_SAVE, N_("_Save"), "S", N_("Save the file"), (GCallback)save_file }, { "SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), NULL, N_("Save the file under different name"), (GCallback)save_file_as }, @@ -2557,13 +2614,6 @@ static GtkRadioActionEntry mode_entries[] = { { "ModeLatLon", NULL, N_("Lat_/Lon Mode"), "l", NULL, 5 }, }; -static GtkRadioActionEntry tool_entries[] = { - { "Pan", "vik-icon-pan", N_("_Pan"), "P", N_("Pan Tool"), 0 }, - { "Zoom", "vik-icon-zoom", N_("_Zoom"), "Z", N_("Zoom Tool"), 1 }, - { "Ruler", "vik-icon-ruler", N_("_Ruler"), "R", N_("Ruler Tool"), 2 }, - { "Select", "vik-icon-select", N_("_Select"), "S", N_("Select Tool"), 3 } -}; - static GtkToggleActionEntry toggle_entries[] = { { "ShowScale", NULL, N_("Show _Scale"), "F5", N_("Show Scale"), (GCallback)set_draw_scale, TRUE }, { "ShowCenterMark", NULL, N_("Show _Center Mark"), "F6", N_("Show Center Mark"), (GCallback)set_draw_centermark, TRUE }, @@ -2613,14 +2663,16 @@ static void window_create_ui( VikWindow *window ) register_vik_icons(icon_factory); + // Copy the tool RadioActionEntries out of the main Window structure into an extending array 'tools' + // so that it can be applied to the UI in one action group add function call below ntools = 0; - for (i=0; ivt->n_tools; i++) { tools = g_renew(GtkRadioActionEntry, tools, ntools+1); radio = &tools[ntools]; ntools++; - *radio = tool_entries[i]; + *radio = window->vt->tools[i].ti.radioActionEntry; radio->value = ntools; - } + } for (i=0; iname; action.stock_id = vik_layer_get_interface(i)->name; - action.label = g_strdup_printf( _("New %s Layer"), vik_layer_get_interface(i)->name); - action.accelerator = NULL; + action.label = g_strdup_printf( _("New _%s Layer"), vik_layer_get_interface(i)->name); + action.accelerator = vik_layer_get_interface(i)->accelerator; action.tooltip = NULL; action.callback = (GCallback)menu_addlayer_cb; gtk_action_group_add_actions(action_group, &action, 1, window); @@ -2646,27 +2698,25 @@ static void window_create_ui( VikWindow *window ) gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE); } + // Further tool copying for to apply to the UI, also apply menu UI setup for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) { tools = g_renew(GtkRadioActionEntry, tools, ntools+1); radio = &tools[ntools]; ntools++; gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools", - _(vik_layer_get_interface(i)->tools[j].name), - vik_layer_get_interface(i)->tools[j].name, + vik_layer_get_interface(i)->tools[j].radioActionEntry.label, + vik_layer_get_interface(i)->tools[j].radioActionEntry.name, GTK_UI_MANAGER_MENUITEM, FALSE); gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems", - _(vik_layer_get_interface(i)->tools[j].name), - vik_layer_get_interface(i)->tools[j].name, + vik_layer_get_interface(i)->tools[j].radioActionEntry.label, + vik_layer_get_interface(i)->tools[j].radioActionEntry.name, GTK_UI_MANAGER_TOOLITEM, FALSE); toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]), i); - radio->name = vik_layer_get_interface(i)->tools[j].name; - radio->stock_id = vik_layer_get_interface(i)->tools[j].name, - radio->label = _(vik_layer_get_interface(i)->tools[j].name); - radio->accelerator = NULL; - radio->tooltip = _(vik_layer_get_interface(i)->tools[j].name); + *radio = vik_layer_get_interface(i)->tools[j].radioActionEntry; + // Overwrite with actual number to use radio->value = ntools; } } @@ -2680,7 +2730,7 @@ static void window_create_ui( VikWindow *window ) for (i=0; itools_count; j++ ) { GtkAction *action = gtk_action_group_get_action(action_group, - vik_layer_get_interface(i)->tools[j].name); + vik_layer_get_interface(i)->tools[j].radioActionEntry.name); g_object_set(action, "sensitive", FALSE, NULL); } } @@ -2694,26 +2744,27 @@ static void window_create_ui( VikWindow *window ) } - +// TODO - add method to add tool icons defined from outside this file +// and remove the reverse dependency on icon definition from this file static struct { const GdkPixdata *data; gchar *stock_id; } stock_icons[] = { - { &begintr_18_pixbuf, "Begin Track" }, - { &route_finder_18_pixbuf, "Route Finder" }, - { &mover_22_pixbuf, "vik-icon-pan" }, - { &demdl_18_pixbuf, "DEM Download/Import" }, - { &showpic_18_pixbuf, "Show Picture" }, - { &addtr_18_pixbuf, "Create Track" }, - { &edtr_18_pixbuf, "Edit Trackpoint" }, - { &addwp_18_pixbuf, "Create Waypoint" }, - { &edwp_18_pixbuf, "Edit Waypoint" }, + { &mover_22_pixbuf, "vik-icon-pan" }, { &zoom_18_pixbuf, "vik-icon-zoom" }, { &ruler_18_pixbuf, "vik-icon-ruler" }, { &select_18_pixbuf, "vik-icon-select" }, - { &geozoom_18_pixbuf, "Georef Zoom Tool" }, - { &geomove_18_pixbuf, "Georef Move Map" }, - { &mapdl_18_pixbuf, "Maps Download" }, + { &begintr_18_pixbuf, "vik-icon-Begin Track" }, + { &route_finder_18_pixbuf, "vik-icon-Route Finder" }, + { &demdl_18_pixbuf, "vik-icon-DEM Download/Import"}, + { &showpic_18_pixbuf, "vik-icon-Show Picture" }, + { &addtr_18_pixbuf, "vik-icon-Create Track" }, + { &edtr_18_pixbuf, "vik-icon-Edit Trackpoint" }, + { &addwp_18_pixbuf, "vik-icon-Create Waypoint" }, + { &edwp_18_pixbuf, "vik-icon-Edit Waypoint" }, + { &geozoom_18_pixbuf, "vik-icon-Georef Zoom Tool" }, + { &geomove_18_pixbuf, "vik-icon-Georef Move Map" }, + { &mapdl_18_pixbuf, "vik-icon-Maps Download" }, }; static gint n_stock_icons = G_N_ELEMENTS (stock_icons); @@ -2747,6 +2798,8 @@ void vik_window_set_selected_trw_layer ( VikWindow *vw, gpointer vtl ) vw->selected_waypoint = NULL; vw->selected_waypoints = NULL; vw->selected_name = NULL; + // Set highlight thickness + vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) ); } gpointer vik_window_get_selected_tracks ( VikWindow *vw ) @@ -2764,6 +2817,8 @@ void vik_window_set_selected_tracks ( VikWindow *vw, gpointer gl, gpointer vtl ) vw->selected_waypoint = NULL; vw->selected_waypoints = NULL; vw->selected_name = NULL; + // Set highlight thickness + vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) ); } gpointer vik_window_get_selected_track ( VikWindow *vw ) @@ -2781,7 +2836,10 @@ void vik_window_set_selected_track ( VikWindow *vw, gpointer *vt, gpointer vtl, vw->selected_tracks = NULL; vw->selected_waypoint = NULL; vw->selected_waypoints = NULL; + // Set highlight thickness + vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) ); } + gpointer vik_window_get_selected_waypoints ( VikWindow *vw ) { return vw->selected_waypoints;