1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
5 * Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
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 General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "file_magic.h"
28 #ifdef VIK_CONFIG_GEOTAG
29 #include "geotag_exif.h"
36 * Returns: Whether the file is a JPG
38 gboolean a_jpg_magic_check ( const gchar *filename )
40 return file_magic_check ( filename, "image/jpeg", ".jpg" );
44 * Load a single JPG into a Trackwaypoint Layer as a waypoint
46 * @top: The Aggregate layer that a new TRW layer may be created in
47 * @filename: The JPG filename
50 * Returns: Whether the loading was a success or not
52 * If the JPG has geotag information then the waypoint will be created with the appropriate position.
53 * Otherwise the waypoint will be positioned at the current screen center.
54 * If a TRW layer is already selected the waypoint will be created in that layer.
56 gboolean a_jpg_load_file ( VikAggregateLayer *top, const gchar *filename, VikViewport *vvp )
58 gboolean auto_zoom = TRUE;
59 VikWindow *vw = (VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(top)));
60 VikLayersPanel *vlp = vik_window_layers_panel ( vw );
61 // Auto load into TrackWaypoint layer if one is selected
62 VikLayer *vtl = vik_layers_panel_get_selected ( vlp );
64 gboolean create_layer = FALSE;
65 if ( vtl == NULL || vtl->type != VIK_LAYER_TRW ) {
66 // Create layer if necessary
67 vtl = vik_layer_create ( VIK_LAYER_TRW, vvp, FALSE );
68 vik_layer_rename ( vtl, a_file_basename ( filename ) );
73 VikWaypoint *wp = NULL;
74 #ifdef VIK_CONFIG_GEOTAG
75 wp = a_geotag_create_waypoint_from_file ( filename, vik_viewport_get_coord_mode (vvp), &name );
78 // Create name if geotag method didn't return one
80 name = g_strdup ( a_file_basename ( filename ) );
81 vik_trw_layer_filein_add_waypoint ( VIK_TRW_LAYER(vtl), name, wp );
85 wp = vik_waypoint_new ();
87 vik_trw_layer_filein_add_waypoint ( VIK_TRW_LAYER(vtl), (gchar*) a_file_basename(filename), wp );
88 vik_waypoint_set_image ( wp, filename );
89 // Simply set position to the current center
90 wp->coord = *( vik_viewport_get_center ( vvp ) );
95 vik_layer_post_read ( vtl, vvp, TRUE );
97 vik_aggregate_layer_add_layer ( top, vtl, FALSE );
99 vik_trw_layer_auto_set_view ( VIK_TRW_LAYER(vtl), vvp );
101 // ATM This routine can't fail