]> git.street.me.uk Git - andy/viking.git/blobdiff - src/datasource_osm_my_traces.c
Fix: use g_list dedicated function instead of own code
[andy/viking.git] / src / datasource_osm_my_traces.c
index 4b5c4e7dce03a071f13d0aff0bb137b3440c33d9..a75af39f55fe83bd8b662939716b771b4492935e 100644 (file)
@@ -49,7 +49,7 @@ typedef struct {
        VikViewport *vvp;
 } datasource_osm_my_traces_t;
 
-static gpointer datasource_osm_my_traces_init( );
+static gpointer datasource_osm_my_traces_init ( acq_vik_t *avt );
 static void datasource_osm_my_traces_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
 static void datasource_osm_my_traces_get_cmd_string ( gpointer user_data, gchar **args, gchar **extra, DownloadMapOptions *options );
 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 );
@@ -80,7 +80,7 @@ VikDataSourceInterface vik_datasource_osm_my_traces_interface = {
   0
 };
 
-static gpointer datasource_osm_my_traces_init ( )
+static gpointer datasource_osm_my_traces_init ( acq_vik_t *avt )
 {
   datasource_osm_my_traces_t *data = g_malloc(sizeof(*data));
   // Reuse GPS functions
@@ -104,18 +104,21 @@ static void datasource_osm_my_traces_add_setup_widgets ( GtkWidget *dialog, VikV
        user_label = gtk_label_new(_("Username:"));
        data->user_entry = gtk_entry_new();
 
-       gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), user_label, FALSE, FALSE, 0 );
-       gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), data->user_entry, FALSE, FALSE, 0 );
+       gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), user_label, FALSE, FALSE, 0 );
+       gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), data->user_entry, FALSE, FALSE, 0 );
        gtk_widget_set_tooltip_markup ( GTK_WIDGET(data->user_entry), _("The email or username used to login to OSM") );
 
        password_label = gtk_label_new ( _("Password:") );
        data->password_entry = gtk_entry_new ();
 
-       gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), password_label, FALSE, FALSE, 0 );
-       gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), data->password_entry, FALSE, FALSE, 0 );
        gtk_widget_set_tooltip_markup ( GTK_WIDGET(data->password_entry), _("The password used to login to OSM") );
 
        osm_login_widgets (data->user_entry, data->password_entry);
+
+       /* Packing all widgets */
+       GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
+       gtk_box_pack_start ( box, password_label, FALSE, FALSE, 0 );
+       gtk_box_pack_start ( box, data->password_entry, FALSE, FALSE, 0 );
        gtk_widget_show_all ( dialog );
 
        /* Keep reference to viewport */
@@ -457,8 +460,8 @@ static GList *select_from_list (GtkWindow *parent, GList *list, const gchar *tit
        gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
        gtk_container_add ( GTK_CONTAINER(scrolledwindow), view );
 
-       gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwindow, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolledwindow, TRUE, TRUE, 0);
 
        // Ensure a reasonable number of items are shown, but let the width be automatically sized
        gtk_widget_set_size_request ( dialog, -1, 400) ;
@@ -491,6 +494,7 @@ static GList *select_from_list (GtkWindow *parent, GList *list, const gchar *tit
                                                }
                                                list_runner = g_list_next ( list_runner );
                                        }
+                                       g_free ( name );
                                }
                        }
                        while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL(store), &iter ) );
@@ -514,7 +518,7 @@ static void none_found ( GtkWindow *gw )
        gtk_window_set_title(GTK_WINDOW(dialog), _("GPS Traces"));
 
        GtkWidget *search_label = gtk_label_new(_("None found!"));
-       gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), search_label, FALSE, FALSE, 5 );
+       gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), search_label, FALSE, FALSE, 5 );
        gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
        gtk_widget_show_all(dialog);
 
@@ -600,6 +604,10 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar
        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 non thread - show program is 'doing something...'
+       if ( !vik_datasource_osm_my_traces_interface.is_thread )
+               vik_window_set_busy_cursor ( adw->vw );
+
        // 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
@@ -623,7 +631,6 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar
                                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;
@@ -639,12 +646,15 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar
                        // TODO feedback to UI to inform which traces failed
                        if ( !result )
                                g_warning ( _("Unable to get trace: %s"), url );
+                       g_free ( url );
                }
 
                if ( result ) {
+                       // Can use the layer
+                       vik_aggregate_layer_add_layer ( vik_layers_panel_get_top_layer (adw->vlp), VIK_LAYER(vtlX), TRUE );
                        // 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 );
+                       vik_trw_layer_auto_set_view ( vtlX, vik_window_viewport(adw->vw) );
                        vtl_last = vtlX;
                }
                else if ( create_new_layer ) {
@@ -676,6 +686,9 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar
                // Process was cancelled but need to return that it proceeded as expected
                result = TRUE;
 
+       if ( !vik_datasource_osm_my_traces_interface.is_thread )
+               vik_window_clear_busy_cursor ( adw->vw );
+
        return result;
 }