]> git.street.me.uk Git - andy/viking.git/blobdiff - src/acquire.c
Fix intermittent problem of map redraw.
[andy/viking.git] / src / acquire.c
index a9484645dda57f3ae5ce069da201a283f573842e..1c47a151333d16bcc10a8685e28d58f643a6f30f 100644 (file)
@@ -44,9 +44,9 @@ static void progress_func ( BabelProgressCode c, gpointer data, acq_dialog_widge
 {
   gdk_threads_enter ();
   if (!w->ok) {
 {
   gdk_threads_enter ();
   if (!w->ok) {
-    g_free ( w );
     if ( w->interface->cleanup_func )
     if ( w->interface->cleanup_func )
-      w->interface->cleanup_func( w->specific_data );
+      w->interface->cleanup_func( w->user_data );
+    g_free ( w );
     gdk_threads_leave();
     g_thread_exit ( NULL );
   }
     gdk_threads_leave();
     g_thread_exit ( NULL );
   }
@@ -100,22 +100,22 @@ static void get_from_anything ( w_and_interface_t *wi )
       g_object_unref ( G_OBJECT ( vtl ) );
     gdk_threads_leave();
   } 
       g_object_unref ( G_OBJECT ( vtl ) );
     gdk_threads_leave();
   } 
-
-  gdk_threads_enter();
-  if (w->ok) {
-    gtk_label_set_text ( GTK_LABEL(w->status), "Done." );
-    if ( creating_new_layer )
-    vik_aggregate_layer_add_layer( vik_layers_panel_get_top_layer(w->vlp), VIK_LAYER(vtl));
-    gtk_dialog_set_response_sensitive ( GTK_DIALOG(w->dialog), GTK_RESPONSE_ACCEPT, TRUE );
-    gtk_dialog_set_response_sensitive ( GTK_DIALOG(w->dialog), GTK_RESPONSE_REJECT, FALSE );
-  } else {
-    /* canceled */
-    if ( creating_new_layer )
-      g_object_unref(vtl);
+  else {
+    gdk_threads_enter();
+    if (w->ok) {
+      gtk_label_set_text ( GTK_LABEL(w->status), "Done." );
+      if ( creating_new_layer )
+       vik_aggregate_layer_add_layer( vik_layers_panel_get_top_layer(w->vlp), VIK_LAYER(vtl));
+      gtk_dialog_set_response_sensitive ( GTK_DIALOG(w->dialog), GTK_RESPONSE_ACCEPT, TRUE );
+      gtk_dialog_set_response_sensitive ( GTK_DIALOG(w->dialog), GTK_RESPONSE_REJECT, FALSE );
+    } else {
+      /* canceled */
+      if ( creating_new_layer )
+       g_object_unref(vtl);
+    }
   }
   }
-
   if ( interface->cleanup_func )
   if ( interface->cleanup_func )
-    interface->cleanup_func ( w->specific_data );
+    interface->cleanup_func ( w->user_data );
 
   if ( w->ok ) {
     w->ok = FALSE;
 
   if ( w->ok ) {
     w->ok = FALSE;
@@ -134,24 +134,38 @@ void a_acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSo
   GtkWidget *status;
   gchar *cmd, *extra;
   acq_dialog_widgets_t *w;
   GtkWidget *status;
   gchar *cmd, *extra;
   acq_dialog_widgets_t *w;
+  gpointer user_data;
 
   w_and_interface_t *wi;
 
 
   w_and_interface_t *wi;
 
-  if ( interface->add_widgets_func ) {
-    gpointer first_dialog_data;
-    dialog = gtk_dialog_new_with_buttons ( "", NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL );
-    first_dialog_data = interface->add_widgets_func(dialog, vvp);
+  g_assert(interface->init_func);
+  user_data = interface->init_func();
+  
+  if ( interface->check_existence_func ) {
+    gchar *error_str = interface->check_existence_func();
+    if ( error_str ) {
+      a_dialog_error_msg ( GTK_WINDOW(vw), error_str );
+      g_free ( error_str );
+      return;
+    }
+  }    
+
+  if ( interface->add_setup_widgets_func ) {
+    dialog = gtk_dialog_new_with_buttons ( "", GTK_WINDOW(vw), 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL );
+
+    interface->add_setup_widgets_func(dialog, vvp, user_data);
+    gtk_window_set_title ( GTK_WINDOW(dialog), interface->window_title );
+
     if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
     if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
-      interface->first_cleanup_func(first_dialog_data);
+      interface->cleanup_func(user_data);
       gtk_widget_destroy(dialog);
       return;
     }
       gtk_widget_destroy(dialog);
       return;
     }
-    interface->get_cmd_string_func ( first_dialog_data, &cmd, &extra );
-    interface->first_cleanup_func(first_dialog_data);
+    interface->get_cmd_string_func ( user_data, &cmd, &extra );
     gtk_widget_destroy(dialog);
     dialog = NULL;
   } else
     gtk_widget_destroy(dialog);
     dialog = NULL;
   } else
-    interface->get_cmd_string_func ( NULL, &cmd, &extra );
+    interface->get_cmd_string_func ( user_data, &cmd, &extra );
 
   if ( ! cmd )
     return;
 
   if ( ! cmd )
     return;
@@ -163,13 +177,13 @@ void a_acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSo
   wi->cmd = cmd;
   wi->extra = extra;
 
   wi->cmd = cmd;
   wi->extra = extra;
 
-  dialog = gtk_dialog_new_with_buttons ( "", NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL );
+  dialog = gtk_dialog_new_with_buttons ( "", GTK_WINDOW(vw), 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL );
   gtk_dialog_set_response_sensitive ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE );
   gtk_dialog_set_response_sensitive ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE );
+  gtk_window_set_title ( GTK_WINDOW(dialog), interface->window_title );
 
 
   w->dialog = dialog;
   w->ok = TRUE;
 
 
   w->dialog = dialog;
   w->ok = TRUE;
-
   status = gtk_label_new ("Status: detecting gpsbabel");
   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), status, FALSE, FALSE, 5 );
   gtk_widget_show_all(status);
   status = gtk_label_new ("Status: detecting gpsbabel");
   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), status, FALSE, FALSE, 5 );
   gtk_widget_show_all(status);
@@ -178,10 +192,11 @@ void a_acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSo
   w->vw = vw;
   w->vlp = vlp;
   w->vvp = vvp;
   w->vw = vw;
   w->vlp = vlp;
   w->vvp = vvp;
-  if ( interface->add_progress_widgets_func )
-    w->specific_data = interface->add_progress_widgets_func ( dialog );
-  else
-    w->specific_data = NULL;
+  if ( interface->add_progress_widgets_func ) {
+    interface->add_progress_widgets_func ( dialog, user_data );
+  }
+  w->user_data = user_data;
+
 
   g_thread_create((GThreadFunc)get_from_anything, wi, FALSE, NULL );
 
 
   g_thread_create((GThreadFunc)get_from_anything, wi, FALSE, NULL );