X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/576cbd17b70ade8af82d819e647954e2e6731cc2..c9ee385c638ffa5266b9cc703620939ac03a7c07:/src/vikwindow.c diff --git a/src/vikwindow.c b/src/vikwindow.c index 563227ab..84f213c4 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -27,25 +27,29 @@ #include "background.h" #include "acquire.h" #include "datasources.h" -#include "googlesearch.h" +#include "vikgoto.h" #include "dems.h" +#include "mapcache.h" #include "print.h" #include "preferences.h" +#include "icons/icons.h" +#include "vikexttools.h" +#ifdef HAVE_STDLIB_H #include +#endif +#ifdef HAVE_MATH_H #include +#endif +#ifdef HAVE_STRING_H #include +#endif #include +#include +#include #include #include -#ifdef WINDOWS -/* TODO IMPORTANT: mkdir for windows header? is it called 'mkdir' */ -#define make_dir(dir) mkdir(dir) -#else -#include -#include -#define make_dir(dir) mkdir(dir,0777) -#endif +#include #define VIKING_WINDOW_WIDTH 1000 #define VIKING_WINDOW_HEIGHT 800 @@ -108,8 +112,9 @@ static toolbox_tools_t* toolbox_create(VikWindow *vw); static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type ); static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name); static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name); +static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name); static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event); -static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event); +static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event); static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event); @@ -179,10 +184,6 @@ static guint window_signals[VW_LAST_SIGNAL] = { 0 }; static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Pan"), N_("Zoom"), N_("Ruler") }; -GdkCursor *vw_cursor_pan = NULL; -GdkCursor *vw_cursor_zoom = NULL; -GdkCursor *vw_cursor_ruler = NULL; - GType vik_window_get_type (void) { static GType vw_type = 0; @@ -296,12 +297,13 @@ static void window_init ( VikWindow *vw ) gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS); + vik_ext_tools_add_menu_items ( vw, vw->uim ); g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(window_configure_event), vw); - gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK ); + gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK ); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_release_event", G_CALLBACK(draw_release), vw); @@ -313,8 +315,8 @@ static void window_init ( VikWindow *vw ) gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT); hpaned = gtk_hpaned_new (); - gtk_paned_add1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp) ); - gtk_paned_add2 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vvp) ); + gtk_paned_pack1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp), FALSE, FALSE ); + gtk_paned_pack2 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vvp), TRUE, TRUE ); /* This packs the button into the window (a gtk container). */ gtk_box_pack_start (GTK_BOX(main_vbox), hpaned, TRUE, TRUE, 0); @@ -404,18 +406,22 @@ static void draw_status ( VikWindow *vw ) void vik_window_set_redraw_trigger(VikLayer *vl) { VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl)); - vw->trigger = vl; + if (NULL != vw) + vw->trigger = vl; } static void window_configure_event ( VikWindow *vw ) { - static first = 1; + static int first = 1; draw_redraw ( vw ); if (first) { // This is a hack to set the cursor corresponding to the first tool // FIXME find the correct way to initialize both tool and its cursor + const GdkCursor *cursor = NULL; first = 0; - gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_pan ); + cursor = toolbox_get_cursor(vw->vt, "Pan"); + /* We set cursor, even if it is NULL: it resets to default */ + gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor ); } } @@ -493,16 +499,26 @@ static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event) static VikCoord coord; static struct UTM utm; static struct LatLon ll; - static char pointer_buf[36]; + #define BUFFER_SIZE 50 + static char pointer_buf[BUFFER_SIZE]; + gchar *lat = NULL, *lon = NULL; gint16 alt; gdouble zoom; VikDemInterpol interpol_method; + /* This is a hack, but work far the best, at least for single pointer systems. + * See http://bugzilla.gnome.org/show_bug.cgi?id=587714 for more. */ + gint x, y; + gdk_window_get_pointer (event->window, &x, &y, NULL); + event->x = x; + event->y = y; + toolbox_move(vw->vt, event); vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord ); vik_coord_to_utm ( &coord, &utm ); a_coords_utm_to_latlon ( &utm, &ll ); + a_coords_latlon_to_string ( &ll, &lat, &lon ); /* Change interpolate method according to scale */ zoom = vik_viewport_get_zoom(vw->viking_vvp); if (zoom > 2.0) @@ -512,12 +528,22 @@ static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event) else interpol_method = VIK_DEM_INTERPOL_BEST; if ((alt = a_dems_get_elev_by_coord(&coord, interpol_method)) != VIK_DEM_INVALID_ELEVATION) - g_snprintf ( pointer_buf, 36, _("Cursor: %f %f %dm"), ll.lat, ll.lon, alt ); + g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dm"), lat, lon, alt ); else - g_snprintf ( pointer_buf, 36, _("Cursor: %f %f"), ll.lat, ll.lon ); + g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s"), lat, lon ); + g_free (lat); + lat = NULL; + g_free (lon); + lon = NULL; vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf ); vik_window_pan_move ( vw, event ); + + /* This is recommended by the GTK+ documentation, but does not work properly. + * Use deprecated way until GTK+ gets a solution for correct motion hint handling: + * http://bugzilla.gnome.org/show_bug.cgi?id=587714 + */ + /* gdk_event_request_motions ( event ); */ } static void vik_window_pan_release ( VikWindow *vw, GdkEventButton *event ) @@ -545,42 +571,33 @@ static void draw_release ( VikWindow *vw, GdkEventButton *event ) static void draw_scroll (VikWindow *vw, GdkEventScroll *event) { - if ( event->state == GDK_CONTROL_MASK ) { + guint modifiers = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK); + if ( modifiers == GDK_CONTROL_MASK ) { /* control == pan up & down */ if ( event->direction == GDK_SCROLL_UP ) vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)/3 ); else vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)*2/3 ); - } else if ( event->state == GDK_SHIFT_MASK ) { - /* control-shift == pan left & right */ + } else if ( modifiers == GDK_SHIFT_MASK ) { + /* shift == pan left & right */ if ( event->direction == GDK_SCROLL_UP ) vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/3, vik_viewport_get_height(vw->viking_vvp)/2 ); else vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)*2/3, vik_viewport_get_height(vw->viking_vvp)/2 ); - } else if ( event->state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ) { - if ( event->direction == GDK_SCROLL_UP ) { - /* make sure mouse is still over the same point on the map when we zoom */ - VikCoord coord; - gint x, y; - gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2; - gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2; - vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord ); + } else if ( modifiers == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ) { + /* control+shift == make sure mouse is still over the same point on the map when we zoom */ + VikCoord coord; + gint x, y; + gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2; + gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2; + vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord ); + if ( event->direction == GDK_SCROLL_UP ) vik_viewport_zoom_in (vw->viking_vvp); - vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y ); - vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x), - center_y + (y - event->y) ); - } - else { - VikCoord coord; - gint x, y; - gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2; - gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2; - vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord ); + else vik_viewport_zoom_out(vw->viking_vvp); - vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y ); - vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x), - center_y + (y - event->y) ); - } + vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y ); + vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x), + center_y + (y - event->y) ); } else { if ( event->direction == GDK_SCROLL_UP ) vik_viewport_zoom_in (vw->viking_vvp); @@ -787,14 +804,16 @@ static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, VikCoord coord; gchar *temp; if ( event->button == 1 ) { + gchar *lat=NULL, *lon=NULL; vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord ); vik_coord_to_latlon ( &coord, &ll ); + a_coords_latlon_to_string ( &ll, &lat, &lon ); if ( s->has_oldcoord ) { - temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) ); + temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) ); s->has_oldcoord = FALSE; } else { - temp = g_strdup_printf ( "%f %f", ll.lat, ll.lon ); + temp = g_strdup_printf ( "%s %s", lat, lon ); s->has_oldcoord = TRUE; } @@ -810,7 +829,7 @@ static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, return VIK_LAYER_TOOL_ACK; } -static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s) +static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, ruler_tool_state_t *s) { VikViewport *vvp = s->vvp; VikWindow *vw = s->vw; @@ -822,6 +841,7 @@ static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventButton *event, r if ( s->has_oldcoord ) { int oldx, oldy, w1, h1, w2, h2; static GdkPixmap *buf = NULL; + gchar *lat=NULL, *lon=NULL; w1 = vik_viewport_get_width(vvp); h1 = vik_viewport_get_height(vvp); if (!buf) { @@ -848,8 +868,8 @@ static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventButton *event, r g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL); draw_buf_done = FALSE; } - - temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) ); + a_coords_latlon_to_string(&ll, &lat, &lon); + temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) ); vik_statusbar_set_message ( vw->viking_vs, 3, temp ); g_free ( temp ); } @@ -873,8 +893,11 @@ static VikToolInterface ruler_tool = (VikToolActivationFunc) NULL, (VikToolActivationFunc) ruler_deactivate, (VikToolMouseFunc) ruler_click, - (VikToolMouseFunc) ruler_move, - (VikToolMouseFunc) ruler_release }; + (VikToolMouseMoveFunc) ruler_move, + (VikToolMouseFunc) ruler_release, + NULL, + GDK_CURSOR_IS_PIXMAP, + &cursor_ruler_pixbuf }; /*** end ruler code ********************************************************/ @@ -899,7 +922,7 @@ static VikLayerToolFuncStatus zoomtool_click (VikLayer *vl, GdkEventButton *even return VIK_LAYER_TOOL_ACK; } -static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventButton *event, VikViewport *vvp) +static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventMotion *event, VikViewport *vvp) { return VIK_LAYER_TOOL_ACK; } @@ -916,8 +939,11 @@ static VikToolInterface zoom_tool = (VikToolActivationFunc) NULL, (VikToolActivationFunc) NULL, (VikToolMouseFunc) zoomtool_click, - (VikToolMouseFunc) zoomtool_move, - (VikToolMouseFunc) zoomtool_release }; + (VikToolMouseMoveFunc) zoomtool_move, + (VikToolMouseFunc) zoomtool_release, + NULL, + GDK_CURSOR_IS_PIXMAP, + &cursor_zoom_pixbuf }; /*** end zoom code ********************************************************/ /******************************************************************************** @@ -937,7 +963,7 @@ static VikLayerToolFuncStatus pantool_click (VikLayer *vl, GdkEventButton *event return VIK_LAYER_TOOL_ACK; } -static VikLayerToolFuncStatus pantool_move (VikLayer *vl, GdkEventButton *event, VikWindow *vw) +static VikLayerToolFuncStatus pantool_move (VikLayer *vl, GdkEventMotion *event, VikWindow *vw) { vik_window_pan_move ( vw, event ); return VIK_LAYER_TOOL_ACK; @@ -957,8 +983,10 @@ static VikToolInterface pan_tool = (VikToolActivationFunc) NULL, (VikToolActivationFunc) NULL, (VikToolMouseFunc) pantool_click, - (VikToolMouseFunc) pantool_move, - (VikToolMouseFunc) pantool_release }; + (VikToolMouseMoveFunc) pantool_move, + (VikToolMouseFunc) pantool_release, + NULL, + GDK_FLEUR }; /*** end pan code ********************************************************/ static void draw_pan_cb ( GtkAction *a, VikWindow *vw ) @@ -1102,6 +1130,17 @@ static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw ) a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to delete.") ); } +static void view_side_panel_cb ( GtkAction *a, VikWindow *vw ) +{ + GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ViewSidePanel" ); + g_assert(check_box); + gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box)); + if ( state ) + gtk_widget_show(GTK_WIDGET(vw->viking_vlp)); + else + gtk_widget_hide(GTK_WIDGET(vw->viking_vlp)); +} + /*************************************** ** tool management routines ** @@ -1172,6 +1211,24 @@ static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name) vt->active_tool = tool; } +static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name) +{ + int tool = toolbox_get_tool(vt, tool_name); + toolbox_tool_t *t = &vt->tools[tool]; + if (t->ti.cursor == NULL) { + if (t->ti.cursor_type == GDK_CURSOR_IS_PIXMAP && t->ti.cursor_data != NULL) { + GError *cursor_load_err = NULL; + GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, &cursor_load_err); + /* TODO: settable offeset */ + t->ti.cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 ); + g_object_unref ( G_OBJECT(cursor_pixbuf) ); + } else { + t->ti.cursor = gdk_cursor_new ( t->ti.cursor_type ); + } + } + return t->ti.cursor; +} + static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event) { VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp ); @@ -1182,7 +1239,7 @@ static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event) } } -static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event) +static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event) { VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp ); if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) { @@ -1214,20 +1271,22 @@ static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw ) { /* White Magic, my friends ... White Magic... */ int layer_id, tool_id; + const GdkCursor *cursor = NULL; toolbox_activate(vw->vt, gtk_action_get_name(a)); + cursor = toolbox_get_cursor(vw->vt, gtk_action_get_name(a)); + /* We set cursor, even if it is NULL: it resets to default */ + gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor ); + if (!strcmp(gtk_action_get_name(a), "Pan")) { vw->current_tool = TOOL_PAN; - gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_pan ); } else if (!strcmp(gtk_action_get_name(a), "Zoom")) { vw->current_tool = TOOL_ZOOM; - gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_zoom ); } else if (!strcmp(gtk_action_get_name(a), "Ruler")) { vw->current_tool = TOOL_RULER; - gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_ruler ); } else { /* TODO: only enable tools from active layer */ @@ -1237,7 +1296,6 @@ static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw ) vw->current_tool = TOOL_LAYER; vw->tool_layer_id = layer_id; vw->tool_tool_id = tool_id; - gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vik_layer_get_tool_cursor ( layer_id, tool_id ) ); } } } @@ -1271,17 +1329,93 @@ GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode m GtkWidget *mode_button; gchar *buttonname; switch ( mode ) { - case VIK_VIEWPORT_DRAWMODE_UTM: buttonname = "/ui/MainMenu/View/ModeUTM"; break; +#ifdef VIK_CONFIG_EXPEDIA case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break; - case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break; +#endif case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break; - default: buttonname = "/ui/MainMenu/View/ModeKH"; + default: buttonname = "/ui/MainMenu/View/ModeUTM"; } mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname ); g_assert ( mode_button ); return mode_button; } +static void on_activate_recent_item (GtkRecentChooser *chooser, + VikWindow *self) +{ + gchar *filename; + + filename = gtk_recent_chooser_get_current_uri (chooser); + if (filename != NULL) + { + GFile *file = g_file_new_for_uri ( filename ); + gchar *path = g_file_get_path ( file ); + g_object_unref ( file ); + if ( self->filename ) + { + gchar *filenames[] = { path, NULL }; + g_signal_emit ( G_OBJECT(self), window_signals[VW_OPENWINDOW_SIGNAL], 0, filenames ); + } + else + vik_window_open_file ( self, filename, TRUE ); + g_free ( path ); + } + + g_free (filename); +} + +static void setup_recent_files (VikWindow *self) +{ + GtkRecentManager *manager; + GtkRecentFilter *filter; + GtkWidget *menu, *menu_item; + + filter = gtk_recent_filter_new (); + /* gtk_recent_filter_add_application (filter, g_get_application_name()); */ + gtk_recent_filter_add_group(filter, "viking"); + + manager = gtk_recent_manager_get_default (); + menu = gtk_recent_chooser_menu_new_for_manager (manager); + gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu), GTK_RECENT_SORT_MRU); + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter); + + menu_item = gtk_ui_manager_get_widget (self->uim, "/ui/MainMenu/File/OpenRecentFile"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu); + + g_signal_connect (G_OBJECT (menu), "item-activated", + G_CALLBACK (on_activate_recent_item), (gpointer) self); +} + +static void update_recently_used_document(const gchar *filename) +{ + /* Update Recently Used Document framework */ + GtkRecentManager *manager = gtk_recent_manager_get_default(); + GtkRecentData *recent_data = g_slice_new (GtkRecentData); + gchar *groups[] = {"viking", NULL}; + GFile *file = g_file_new_for_commandline_arg(filename); + gchar *uri = g_file_get_uri(file); + gchar *basename = g_path_get_basename(filename); + g_object_unref(file); + file = NULL; + + recent_data->display_name = basename; + recent_data->description = NULL; + recent_data->mime_type = "text/x-gps-data"; + recent_data->app_name = (gchar *) g_get_application_name (); + recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%f", NULL); + recent_data->groups = groups; + recent_data->is_private = FALSE; + if (!gtk_recent_manager_add_full (manager, uri, recent_data)) + { + g_warning (_("Unable to add '%s' to the list of recently used documents"), uri); + } + + g_free (uri); + g_free (basename); + g_free (recent_data->app_exec); + g_slice_free (GtkRecentData, recent_data); +} + void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename ) { switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) ) @@ -1292,6 +1426,7 @@ void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean chang case 1: { GtkWidget *mode_button; + /* Update UI */ if ( change_filename ) window_set_filename ( vw, filename ); mode_button = vik_window_get_drawmode_button ( vw, vik_viewport_get_drawmode ( vw->viking_vvp ) ); @@ -1309,11 +1444,15 @@ void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean chang g_assert ( mode_button ); gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_centermark(vw->viking_vvp) ); } - default: draw_update ( vw ); + default: + update_recently_used_document(filename); + draw_update ( vw ); } } static void load_file ( GtkAction *a, VikWindow *vw ) { + GSList *files = NULL; + GSList *cur_file = NULL; gboolean newwindow; if (!strcmp(gtk_action_get_name(a), "Open")) { newwindow = TRUE; @@ -1328,12 +1467,17 @@ static void load_file ( GtkAction *a, VikWindow *vw ) if ( ! vw->open_dia ) { - vw->open_dia = gtk_file_selection_new ( _("Please select a GPS data file to open. ") ); - gtk_file_selection_set_select_multiple ( GTK_FILE_SELECTION(vw->open_dia), TRUE ); + vw->open_dia = gtk_file_chooser_dialog_new (_("Please select a GPS data file to open. "), + GTK_WINDOW(vw), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + 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 ); } - if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_OK ) + if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_ACCEPT ) { gtk_widget_hide ( vw->open_dia ); #ifdef VIKING_PROMPT_IF_MODIFIED @@ -1341,14 +1485,19 @@ static void load_file ( GtkAction *a, VikWindow *vw ) #else if ( vw->filename && newwindow ) #endif - g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) ) ); + g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) ) ); else { - gchar **files = gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) ); - gboolean change_fn = newwindow && (!files[1]); /* only change fn if one file */ - while ( *files ) { - vik_window_open_file ( vw, *files, change_fn ); - files++; + files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) ); + gboolean change_fn = newwindow && (g_slist_length(files)==1); /* only change fn if one file */ + + cur_file = files; + while ( cur_file ) { + gchar *file_name = cur_file->data; + vik_window_open_file ( vw, file_name, change_fn ); + g_free (file_name); + cur_file = g_slist_next (cur_file); } + g_slist_free (files); } } else @@ -1361,15 +1510,20 @@ static gboolean save_file_as ( GtkAction *a, VikWindow *vw ) const gchar *fn; if ( ! vw->save_dia ) { - vw->save_dia = gtk_file_selection_new ( _("Save as Viking File.") ); + vw->save_dia = gtk_file_chooser_dialog_new (_("Save as Viking File."), + GTK_WINDOW(vw), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); gtk_window_set_transient_for ( GTK_WINDOW(vw->save_dia), GTK_WINDOW(vw) ); gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE ); } - while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_OK ) + while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_ACCEPT ) { - fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_dia) ); - if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(vw->save_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) ) + fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_dia) ); + if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == FALSE || a_dialog_overwrite ( GTK_WINDOW(vw->save_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) ) { window_set_filename ( vw, fn ); rv = window_save ( vw ); @@ -1384,7 +1538,10 @@ static gboolean save_file_as ( GtkAction *a, VikWindow *vw ) static gboolean window_save ( VikWindow *vw ) { if ( a_file_save ( vik_layers_panel_get_top_layer ( vw->viking_vlp ), vw->viking_vvp, vw->filename ) ) + { + update_recently_used_document ( vw->filename ); return TRUE; + } else { a_dialog_error_msg ( GTK_WINDOW(vw), _("The filename you requested could not be opened for writing.") ); @@ -1422,7 +1579,12 @@ static void acquire_from_gc ( GtkAction *a, VikWindow *vw ) static void goto_address( GtkAction *a, VikWindow *vw) { - a_google_search(vw, vw->viking_vlp, vw->viking_vvp); + a_vik_goto(vw, vw->viking_vlp, vw->viking_vvp); +} + +static void mapcache_flush_cb ( GtkAction *a, VikWindow *vw ) +{ + a_mapcache_flush(); } static void preferences_cb ( GtkAction *a, VikWindow *vw ) @@ -1522,7 +1684,7 @@ static void save_image_dir ( VikWindow *vw, const gchar *fn, guint w, guint h, g g_assert ( vik_viewport_get_coord_mode ( vw->viking_vvp ) == VIK_COORD_UTM ); - make_dir(fn); + g_mkdir(fn,0777); utm_orig = *((const struct UTM *)vik_viewport_get_center ( vw->viking_vvp )); @@ -1724,15 +1886,20 @@ static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw ) { const gchar *fn; if (!vw->save_img_dia) { - vw->save_img_dia = gtk_file_selection_new ( _("Save Image") ); + vw->save_img_dia = gtk_file_chooser_dialog_new (_("Save Image"), + GTK_WINDOW(vw), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dia), GTK_WINDOW(vw) ); gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dia), TRUE ); } - while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_OK ) + while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_ACCEPT ) { - fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_img_dia) ); - if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(vw->save_img_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) ) + fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dia) ); + if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == FALSE || a_dialog_overwrite ( GTK_WINDOW(vw->save_img_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) ) { draw_to_image_file ( vw, fn, TRUE ); break; @@ -1743,21 +1910,27 @@ static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw ) static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw ) { - const gchar *fn; + gchar *fn = NULL; + if (!vw->save_img_dir_dia) { - vw->save_img_dir_dia = gtk_file_selection_new ( _("Choose a name for a new directory to hold images")); + vw->save_img_dir_dia = gtk_file_chooser_dialog_new (_("Choose a directory to hold images"), + GTK_WINDOW(vw), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dir_dia), GTK_WINDOW(vw) ); gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dir_dia), TRUE ); } - - while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_OK ) + + while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_ACCEPT ) { - fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_img_dir_dia) ); - if ( access ( fn, F_OK ) == 0 ) - a_dialog_info_msg_extra ( GTK_WINDOW(vw->save_img_dir_dia), _("The file %s exists. Please choose a name for a new directory to hold images in that does not exist."), a_file_basename(fn) ); - else + fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dir_dia) ); + if ( fn ) { draw_to_image_file ( vw, fn, FALSE ); + g_free(fn); + fn = NULL; break; } } @@ -1781,12 +1954,6 @@ static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWin else if (!strcmp(gtk_action_get_name(a), "ModeExpedia")) { drawmode = VIK_VIEWPORT_DRAWMODE_EXPEDIA; } - else if (!strcmp(gtk_action_get_name(a), "ModeGoogle")) { - drawmode = VIK_VIEWPORT_DRAWMODE_GOOGLE; - } - else if (!strcmp(gtk_action_get_name(a), "ModeKH")) { - drawmode = VIK_VIEWPORT_DRAWMODE_KH; - } else if (!strcmp(gtk_action_get_name(a), "ModeMercator")) { drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR; } @@ -1860,10 +2027,12 @@ static GtkActionEntry entries[] = { { "SetPan", NULL, N_("_Pan"), 0, 0, 0 }, { "Layers", NULL, N_("_Layers"), 0, 0, 0 }, { "Tools", NULL, N_("_Tools"), 0, 0, 0 }, + { "Exttools", NULL, N_("_Webtools"), 0, 0, 0 }, { "Help", NULL, N_("_Help"), 0, 0, 0 }, { "New", GTK_STOCK_NEW, N_("_New"), "N", N_("New file"), (GCallback)newwindow_cb }, { "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_("A_ppend File"), NULL, N_("Append data from a different file"), (GCallback)load_file }, { "Acquire", NULL, N_("A_cquire"), 0, 0, 0 }, { "AcquireGPS", NULL, N_("From _GPS"), NULL, N_("Transfer data from a GPS device"), (GCallback)acquire_from_gps }, @@ -1883,13 +2052,13 @@ static GtkActionEntry entries[] = { { "Exit", GTK_STOCK_QUIT, N_("E_xit"), "W", N_("Exit the program"), (GCallback)window_close }, { "SaveExit", GTK_STOCK_QUIT, N_("Save and Exit"), NULL, N_("Save and Exit the program"), (GCallback)save_file_and_exit }, - { "GoogleMapsSearch", GTK_STOCK_GO_FORWARD, N_("Go To Google Maps location"), NULL, N_("Go to address/place using Google Maps search"), (GCallback)goto_address }, - { "GotoLL", GTK_STOCK_QUIT, N_("_Go to Lat\\/Lon..."), NULL, N_("Go to arbitrary lat\\/lon coordinate"), (GCallback)draw_goto_cb }, - { "GotoUTM", GTK_STOCK_QUIT, N_("Go to UTM..."), NULL, N_("Go to arbitrary UTM coordinate"), (GCallback)draw_goto_cb }, + { "GotoSearch", GTK_STOCK_JUMP_TO, N_("Go To location"), NULL, N_("Go to address/place using text search"), (GCallback)goto_address }, + { "GotoLL", GTK_STOCK_JUMP_TO, N_("_Go to Lat\\/Lon..."), NULL, N_("Go to arbitrary lat\\/lon coordinate"), (GCallback)draw_goto_cb }, + { "GotoUTM", GTK_STOCK_JUMP_TO, N_("Go to UTM..."), NULL, N_("Go to arbitrary UTM coordinate"), (GCallback)draw_goto_cb }, { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Background Color..."), NULL, NULL, (GCallback)set_bg_color }, { "ZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "plus", NULL, (GCallback)draw_zoom_cb }, { "ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "minus", NULL, (GCallback)draw_zoom_cb }, - { "ZoomTo", GTK_STOCK_ZOOM_FIT, N_("Zoom _To"), "Z", NULL, (GCallback)zoom_to_cb }, + { "ZoomTo", GTK_STOCK_ZOOM_FIT, N_("Zoom _To"), "Z", NULL, (GCallback)zoom_to_cb }, { "Zoom0.25", NULL, N_("0.25"), NULL, NULL, (GCallback)draw_zoom_cb }, { "Zoom0.5", NULL, N_("0.5"), NULL, NULL, (GCallback)draw_zoom_cb }, { "Zoom1", NULL, N_("1"), NULL, NULL, (GCallback)draw_zoom_cb }, @@ -1911,7 +2080,8 @@ static GtkActionEntry entries[] = { { "Paste", GTK_STOCK_PASTE, N_("_Paste"), NULL, NULL, (GCallback)menu_paste_layer_cb }, { "Delete", GTK_STOCK_DELETE, N_("_Delete"), NULL, NULL, (GCallback)menu_delete_layer_cb }, { "DeleteAll", NULL, N_("Delete All"), NULL, NULL, (GCallback)clear_cb }, - { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences..."), NULL, NULL, (GCallback)preferences_cb }, + { "MapCacheFlush",NULL, N_("Flush Map cache"), NULL, NULL, (GCallback)mapcache_flush_cb }, + { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences..."), NULL, NULL, (GCallback)preferences_cb }, { "Properties",GTK_STOCK_PROPERTIES, N_("_Properties"), NULL, NULL, (GCallback)menu_properties_cb }, { "About", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, (GCallback)help_about_cb }, @@ -1921,9 +2091,7 @@ static GtkActionEntry entries[] = { static GtkRadioActionEntry mode_entries[] = { { "ModeUTM", NULL, N_("_UTM Mode"), "u", NULL, 0 }, { "ModeExpedia", NULL, N_("_Expedia Mode"), "e", NULL, 1 }, - { "ModeGoogle", NULL, N_("_Old Google Mode"), "o", NULL, 2 }, - { "ModeKH", NULL, N_("Old _KH Mode"), "k", NULL, 3 }, - { "ModeMercator", NULL, N_("_Google Mode"), "g", NULL, 4 } + { "ModeMercator", NULL, N_("_Mercator Mode"), "g", NULL, 4 } }; static GtkRadioActionEntry tool_entries[] = { @@ -1933,9 +2101,10 @@ static GtkRadioActionEntry tool_entries[] = { }; static GtkToggleActionEntry toggle_entries[] = { - { "ShowScale", NULL, N_("Show Scale"), NULL, NULL, (GCallback)set_draw_scale, TRUE }, - { "ShowCenterMark", NULL, N_("Show Center Mark"), NULL, NULL, (GCallback)set_draw_centermark, TRUE }, - { "FullScreen", NULL, N_("Full Screen"), "F11", NULL, (GCallback)full_screen_cb, FALSE }, + { "ShowScale", NULL, N_("Show Scale"), NULL, N_("Show Scale"), (GCallback)set_draw_scale, TRUE }, + { "ShowCenterMark", NULL, N_("Show Center Mark"), NULL, N_("Show Center Mark"), (GCallback)set_draw_centermark, TRUE }, + { "FullScreen", GTK_STOCK_FULLSCREEN, N_("Full Screen"), "F11", N_("Activate full screen mode"), (GCallback)full_screen_cb, FALSE }, + { "ViewSidePanel", GTK_STOCK_INDEX, N_("Show Side Panel"), "F9", N_("Show Side Panel"), (GCallback)view_side_panel_cb, TRUE }, }; #include "menu.xml.h" @@ -2051,29 +2220,31 @@ static void window_create_ui( VikWindow *window ) accel_group = gtk_ui_manager_get_accel_group (uim); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); gtk_ui_manager_ensure_update (uim); + + setup_recent_files(window); } -#include "icons/icons.h" static struct { const GdkPixdata *data; gchar *stock_id; } stock_icons[] = { - { &addtr_18, "Create Track" }, - { &begintr_18, "Begin Track" }, - { &edtr_18, "Edit Trackpoint" }, - { &addwp_18, "Create Waypoint" }, - { &edwp_18, "Edit Waypoint" }, - { &iscissors_18, "Magic Scissors" }, - { &mover_22, "vik-icon-pan" }, - { &zoom_18, "vik-icon-zoom" }, - { &ruler_18, "vik-icon-ruler" }, - { &geozoom_18, "Georef Zoom Tool" }, - { &geomove_18, "Georef Move Map" }, - { &mapdl_18, "Maps Download" }, - { &demdl_18, "DEM Download/Import" }, - { &showpic_18, "Show Picture" }, + { &begintr_18_pixbuf, "Begin Track" }, + { &iscissors_18_pixbuf, "Magic Scissors" }, + { &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" }, + { &zoom_18_pixbuf, "vik-icon-zoom" }, + { &ruler_18_pixbuf, "vik-icon-ruler" }, + { &geozoom_18_pixbuf, "Georef Zoom Tool" }, + { &geomove_18_pixbuf, "Georef Move Map" }, + { &mapdl_18_pixbuf, "Maps Download" }, + { &showpic_18_pixbuf, "Show Picture" }, }; static gint n_stock_icons = G_N_ELEMENTS (stock_icons); @@ -2092,27 +2263,3 @@ register_vik_icons (GtkIconFactory *icon_factory) } } -void vik_window_cursors_init() -{ - GdkPixbuf *cursor_pixbuf; - GError *cursor_load_err; - - vw_cursor_pan = gdk_cursor_new(GDK_FLEUR); - - cursor_pixbuf = gdk_pixbuf_from_pixdata (&cursor_zoom, FALSE, &cursor_load_err); - vw_cursor_zoom = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 6, 6 ); - - g_object_unref ( G_OBJECT(cursor_pixbuf) ); - - cursor_pixbuf = gdk_pixbuf_from_pixdata (&cursor_ruler, FALSE, &cursor_load_err); - vw_cursor_ruler = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 6, 6 ); - - g_object_unref ( G_OBJECT(cursor_pixbuf) ); -} - -void vik_window_cursors_uninit() -{ - gdk_cursor_unref ( vw_cursor_pan ); - gdk_cursor_unref ( vw_cursor_zoom ); - gdk_cursor_unref ( vw_cursor_ruler ); -}