Esempio n. 1
0
gchar * a_vik_goto_get_search_string_for_this_place(VikWindow *vw)
{
  if (!last_coord)
    return NULL;

  VikViewport *vvp = vik_window_viewport(vw);
  const VikCoord *cur_center = vik_viewport_get_center(vvp);
  if (vik_coord_equals(cur_center, last_coord)) {
    return(last_successful_goto_str);
  }
  else
    return NULL;
}
Esempio n. 2
0
/**
 * Search all TrackWaypoint layers in this aggregate layer for an item on the user specified date
 */
static void aggregate_layer_search_date ( menu_array_values values )
{
  VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( values[MA_VAL] );
  VikCoord position;
  gchar *date_str = a_dialog_get_date ( VIK_GTK_WINDOW_FROM_LAYER(val), _("Search by Date") );

  if ( !date_str )
    return;

  VikViewport *vvp = vik_window_viewport ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(val)) );

  GList *gl = NULL;
  gl = vik_aggregate_layer_get_all_layers_of_type ( val, gl, VIK_LAYER_TRW, TRUE );
  gboolean found = FALSE;
  // Search tracks first
  while ( gl && !found ) {
    // Make it auto select the item if found
    found = vik_trw_layer_find_date ( VIK_TRW_LAYER(gl->data), date_str, &position, vvp, TRUE, TRUE );
    gl = g_list_next ( gl );
  }
  g_list_free ( gl );
  if ( !found ) {
    // Reset and try on Waypoints
    gl = NULL;
    gl = vik_aggregate_layer_get_all_layers_of_type ( val, gl, VIK_LAYER_TRW, TRUE );
    while ( gl && !found ) {
      // Make it auto select the item if found
      found = vik_trw_layer_find_date ( VIK_TRW_LAYER(gl->data), date_str, &position, vvp, FALSE, TRUE );
      gl = g_list_next ( gl );
    }
    g_list_free ( gl );
  }

  if ( !found )
    a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_LAYER(val), _("No items found with the requested date.") );
  g_free ( date_str );
}
Esempio n. 3
0
static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadMapOptions *options_unused )
{
    //datasource_osm_my_traces_t *data = (datasource_osm_my_traces_t *)adw->user_data;

    gboolean result;

    gchar *user_pass = osm_get_login();

    DownloadMapOptions options = { FALSE, FALSE, NULL, 2, NULL, user_pass }; // Allow a couple of redirects

    xml_data *xd = g_malloc ( sizeof (xml_data) );
    //xd->xpath = g_string_new ( "" );
    xd->c_cdata = g_string_new ( "" );
    xd->current_tag = tt_unknown;
    xd->current_gpx_meta_data = new_gpx_meta_data_t();
    xd->list_of_gpx_meta_data = NULL;

    gchar *tmpname = a_download_uri_to_tmp_file ( DS_OSM_TRACES_GPX_FILES, &options );
    result = read_gpx_files_metadata_xml ( tmpname, xd );
    // Test already downloaded metadata file: eg:
    //result = read_gpx_files_metadata_xml ( "/tmp/viking-download.GI47PW", xd );

    if ( tmpname ) {
        g_remove ( tmpname );
        g_free ( tmpname );
    }

    if ( ! result )
        return FALSE;

    if ( g_list_length ( xd->list_of_gpx_meta_data ) == 0 ) {
        if (!vik_datasource_osm_my_traces_interface.is_thread)
            none_found ( GTK_WINDOW(adw->vw) );
        return FALSE;
    }

    xd->list_of_gpx_meta_data = g_list_reverse ( xd->list_of_gpx_meta_data );

    set_in_current_view_property ( vtl, adw->user_data, xd->list_of_gpx_meta_data );

    if (vik_datasource_osm_my_traces_interface.is_thread) gdk_threads_enter();
    GList *selected = select_from_list ( GTK_WINDOW(adw->vw), xd->list_of_gpx_meta_data, "Select GPS Traces", "Select the GPS traces you want to add." );
    if (vik_datasource_osm_my_traces_interface.is_thread) gdk_threads_leave();

    // If passed in on an existing layer - we will create everything into that.
    //  thus with many differing gpx's - this will combine all waypoints into this single layer!
    // Hence the preference is to create multiple layers
    //  and so this creation of the layers must be managed here

    gboolean create_new_layer = ( !vtl );

    // Only update the screen on the last layer acquired
    VikTrwLayer *vtl_last = vtl;
    gboolean got_something = FALSE;

    GList *selected_iterator = selected;
    while ( selected_iterator ) {

        VikTrwLayer *vtlX = vtl;

        if ( create_new_layer ) {
            // Have data but no layer - so create one
            vtlX = VIK_TRW_LAYER ( vik_layer_create ( VIK_LAYER_TRW, vik_window_viewport(adw->vw), NULL, FALSE ) );
            if ( ((gpx_meta_data_t*)selected_iterator->data)->name )
                vik_layer_rename ( VIK_LAYER ( vtlX ), ((gpx_meta_data_t*)selected_iterator->data)->name );
            else
                vik_layer_rename ( VIK_LAYER ( vtlX ), _("My OSM Traces") );
            vik_aggregate_layer_add_layer ( vik_layers_panel_get_top_layer (adw->vlp), VIK_LAYER(vtlX) );
        }

        result = FALSE;
        gint gpx_id = ((gpx_meta_data_t*)selected_iterator->data)->id;
        if ( gpx_id ) {
            gchar *url = g_strdup_printf ( DS_OSM_TRACES_GPX_URL_FMT, gpx_id );

            result = a_babel_convert_from_url ( vtlX, url, "gpx", status_cb, adw, &options );
            // TODO investigate using a progress bar:
            // http://developer.gnome.org/gtk/2.24/GtkProgressBar.html

            got_something = got_something || result;
            // TODO feedback to UI to inform which traces failed
            if ( !result )
                g_warning ( _("Unable to get trace: %s"), url );
        }

        if ( result ) {
            // Move to area of the track
            vik_trw_layer_auto_set_view ( vtlX, vik_window_viewport(adw->vw) );
            vik_layer_post_read ( VIK_LAYER(vtlX), vik_window_viewport(adw->vw), TRUE );
            vtl_last = vtlX;
        }
        else if ( create_new_layer ) {
            // Layer not needed as no data has been acquired
            g_object_unref ( vtlX );
        }

        selected_iterator = g_list_next ( selected_iterator );
    }

    // Free memory
    if ( xd->current_gpx_meta_data )
        free_gpx_meta_data ( xd->current_gpx_meta_data, NULL );
    g_free ( xd->current_gpx_meta_data );
    free_gpx_meta_data_list ( xd->list_of_gpx_meta_data );
    free_gpx_meta_data_list ( selected );
    g_free ( xd );
    g_free ( user_pass );

    // Would prefer to keep the update in acquire.c,
    //  however since we may create the layer - need to do the update here
    if ( got_something )
        vik_layer_emit_update ( VIK_LAYER(vtl_last) );

    // ATM The user is only informed if all getting *all* of the traces failed
    if ( selected )
        result = got_something;
    else
        // Process was cancelled but need to return that it proceeded as expected
        result = TRUE;

    return result;
}
Esempio n. 4
0
static gboolean trw_layer_waypoint_menu_popup ( GtkWidget *tree_view,
                                                GdkEventButton *event,
                                                gpointer data )
{
	static GtkTreeIter iter;

	// Use selected item to get a single iterator ref
	// This relies on an row being selected as part of the right click
	GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(tree_view) );
	if ( gtk_tree_selection_count_selected_rows (selection) != 1 )
		return FALSE;

	GtkTreePath *path;
	GtkTreeModel *model = gtk_tree_view_get_model ( GTK_TREE_VIEW(tree_view) );

	// All this just to get the iter
	if ( gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW(tree_view),
	                                     (gint) event->x,
	                                     (gint) event->y,
	                                     &path, NULL, NULL, NULL)) {
		gtk_tree_model_get_iter_from_string ( model, &iter, gtk_tree_path_to_string (path) );
		gtk_tree_path_free ( path );
	}
	else
		return FALSE;

	VikWaypoint *wpt;
	gtk_tree_model_get ( model, &iter, WPT_COL_NUM, &wpt, -1 );
	if ( !wpt ) return FALSE;

	VikTrwLayer *vtl;
	gtk_tree_model_get ( model, &iter, TRW_COL_NUM, &vtl, -1 );
	if ( !IS_VIK_TRW_LAYER(vtl) ) return FALSE;

	wpu_udata udataU;
	udataU.wp   = wpt;
	udataU.uuid = NULL;

	gpointer *wptf;
	wptf = g_hash_table_find ( vik_trw_layer_get_waypoints(vtl), (GHRFunc) trw_layer_waypoint_find_uuid, &udataU );

	if ( wptf && udataU.uuid ) {
		VikViewport *vvp = vik_window_viewport((VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(vtl)));

		GtkWidget *menu = gtk_menu_new();

		// Originally started to reuse the trw_layer menu items
		//  however these offer too many ways to edit the waypoint data
		//  so without an easy way to distinguish read only operations,
		//  create a very minimal new set of operations
		add_menu_items ( GTK_MENU(menu),
		                 vtl,
		                 wpt,
		                 udataU.uuid,
		                 vvp,
		                 tree_view,
		                 data );

		gtk_menu_popup ( GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, gtk_get_current_event_time() );
		return TRUE;
	}
	return FALSE;
}