]> git.street.me.uk Git - andy/viking.git/blame - src/acquire.c
Prevent the program grinding to a halt if trying to deal with thousands of tiles
[andy/viking.git] / src / acquire.c
CommitLineData
1d1bc3c1
EB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
b2aa700f 5 * Copyright (C) 2013, Rob Norris <rw_norris@hotmail.com>
1d1bc3c1
EB
6 *
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.
11 *
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.
16 *
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
20 *
21 */
4c77d5e0
GB
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
8c060406 26#include <stdio.h>
1d1bc3c1
EB
27#include <string.h>
28#include <glib/gprintf.h>
4c77d5e0 29#include <glib/gi18n.h>
1d1bc3c1
EB
30
31#include "viking.h"
32#include "babel.h"
33#include "gpx.h"
7b3479e3 34#include "acquire.h"
1d1bc3c1 35
28c82d8b
EB
36/************************ FILTER LIST *******************/
37// extern VikDataSourceInterface vik_datasource_gps_interface;
28c82d8b
EB
38
39/*** Input is TRWLayer ***/
40extern VikDataSourceInterface vik_datasource_bfilter_simplify_interface;
41extern VikDataSourceInterface vik_datasource_bfilter_dup_interface;
42
43/*** Input is a track and a TRWLayer ***/
44extern VikDataSourceInterface vik_datasource_bfilter_polygon_interface;
45extern VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface;
46
47/*** Input is a track ***/
48
49const VikDataSourceInterface *filters[] = {
50 &vik_datasource_bfilter_simplify_interface,
51 &vik_datasource_bfilter_dup_interface,
52 &vik_datasource_bfilter_polygon_interface,
53 &vik_datasource_bfilter_exclude_polygon_interface,
54};
55
56const guint N_FILTERS = sizeof(filters) / sizeof(filters[0]);
57
58VikTrack *filter_track = NULL;
28c82d8b
EB
59
60/********************************************************/
61
7b3479e3 62/* passed along to worker thread */
1d1bc3c1 63typedef struct {
7b3479e3 64 acq_dialog_widgets_t *w;
7b3479e3
EB
65 gchar *cmd;
66 gchar *extra;
b2aa700f
RN
67 gboolean creating_new_layer;
68 VikTrwLayer *vtl;
ed691ed1 69 gpointer options;
7b3479e3 70} w_and_interface_t;
1d1bc3c1 71
1d1bc3c1 72
7b3479e3 73/*********************************************************
cf697cc2 74 * Definitions and routines for acquiring data from Data Sources in general
7b3479e3 75 *********************************************************/
1d1bc3c1 76
cf697cc2
EB
77static void progress_func ( BabelProgressCode c, gpointer data, acq_dialog_widgets_t *w )
78{
b2aa700f
RN
79 if ( w->source_interface->is_thread ) {
80 gdk_threads_enter ();
81 if ( !w->running ) {
82 if ( w->source_interface->cleanup_func )
83 w->source_interface->cleanup_func ( w->user_data );
84 gdk_threads_leave ();
85 g_thread_exit ( NULL );
86 }
87 gdk_threads_leave ();
cf697cc2 88 }
cf697cc2 89
62ddf770 90 if ( w->source_interface->progress_func )
5564dd66 91 w->source_interface->progress_func ( c, data, w );
cf697cc2
EB
92}
93
b2aa700f
RN
94/**
95 * Some common things to do on completion of a datasource process
96 * . Update layer
97 * . Update dialog info
98 * . Update main dsisplay
99 */
100static void on_complete_process (w_and_interface_t *wi)
101{
102 if (wi->w->running) {
103 gtk_label_set_text ( GTK_LABEL(wi->w->status), _("Done.") );
104 if ( wi->creating_new_layer ) {
105 /* Only create the layer if it actually contains anything useful */
106 // TODO: create function for this operation to hide detail:
bec82ff5 107 if ( ! vik_trw_layer_is_empty ( wi->vtl ) ) {
b2aa700f
RN
108 vik_layer_post_read ( VIK_LAYER(wi->vtl), wi->w->vvp, TRUE );
109 vik_aggregate_layer_add_layer( vik_layers_panel_get_top_layer(wi->w->vlp), VIK_LAYER(wi->vtl));
110 }
111 else
112 gtk_label_set_text ( GTK_LABEL(wi->w->status), _("No data.") );
113 }
114 /* View this data if available and is desired */
115 if ( wi->vtl && wi->w->source_interface->autoview ) {
116 vik_trw_layer_auto_set_view ( wi->vtl, vik_layers_panel_get_viewport(wi->w->vlp) );
117 }
118 if ( wi->w->source_interface->keep_dialog_open ) {
119 gtk_dialog_set_response_sensitive ( GTK_DIALOG(wi->w->dialog), GTK_RESPONSE_ACCEPT, TRUE );
120 gtk_dialog_set_response_sensitive ( GTK_DIALOG(wi->w->dialog), GTK_RESPONSE_REJECT, FALSE );
121 } else {
122 gtk_dialog_response ( GTK_DIALOG(wi->w->dialog), GTK_RESPONSE_ACCEPT );
123 }
124 // Main display update
125 if ( wi->vtl )
126 vik_layers_panel_emit_update ( wi->w->vlp );
127 } else {
128 /* cancelled */
129 if ( wi->creating_new_layer )
130 g_object_unref(wi->vtl);
131 }
132}
28c82d8b 133
1d1bc3c1 134/* this routine is the worker thread. there is only one simultaneous download allowed */
7b3479e3 135static void get_from_anything ( w_and_interface_t *wi )
1d1bc3c1 136{
7b3479e3
EB
137 gchar *cmd = wi->cmd;
138 gchar *extra = wi->extra;
0d337f27 139 gboolean result = TRUE;
805d282e 140
62ddf770 141 VikDataSourceInterface *source_interface = wi->w->source_interface;
1d1bc3c1 142
eb3f9398 143 if ( source_interface->process_func )
ed691ed1 144 result = source_interface->process_func ( wi->vtl, cmd, extra, (BabelStatusFunc) progress_func, wi->w, wi->options );
7b3479e3
EB
145
146 g_free ( cmd );
147 g_free ( extra );
ed691ed1 148 g_free ( wi->options );
7b3479e3 149
9a91dd66 150 if (wi->w->running && !result) {
1d1bc3c1 151 gdk_threads_enter();
b2aa700f
RN
152 gtk_label_set_text ( GTK_LABEL(wi->w->status), _("Error: acquisition failed.") );
153 if ( wi->creating_new_layer )
154 g_object_unref ( G_OBJECT ( wi->vtl ) );
1d1bc3c1
EB
155 gdk_threads_leave();
156 }
5f304fd7 157 else {
65f0ccab 158 gdk_threads_enter();
b2aa700f
RN
159 on_complete_process ( wi );
160 gdk_threads_leave();
1d1bc3c1 161 }
b2aa700f 162
62ddf770 163 if ( source_interface->cleanup_func )
b2aa700f 164 source_interface->cleanup_func ( wi->w->user_data );
7b3479e3 165
b2aa700f
RN
166 if ( wi->w->running ) {
167 wi->w->running = FALSE;
7b3479e3 168 }
9a91dd66
RN
169 else {
170 g_free ( wi->w );
171 g_free ( wi );
172 wi = NULL;
173 }
7b3479e3 174
1d1bc3c1
EB
175 g_thread_exit ( NULL );
176}
177
7b3479e3 178
28c82d8b
EB
179static gchar *write_tmp_trwlayer ( VikTrwLayer *vtl )
180{
181 int fd_src;
182 gchar *name_src;
183 FILE *f;
184 g_assert ((fd_src = g_file_open_tmp("tmp-viking.XXXXXX", &name_src, NULL)) >= 0);
e45b3da1 185 g_debug ("%s: temporary file: %s", __FUNCTION__, name_src);
28c82d8b 186 f = fdopen(fd_src, "w");
208d2084 187 a_gpx_write_file(vtl, f, NULL);
28c82d8b 188 fclose(f);
8c060406 189 f = NULL;
28c82d8b
EB
190 return name_src;
191}
192
193/* TODO: write with name of old track */
194static gchar *write_tmp_track ( VikTrack *track )
195{
196 int fd_src;
197 gchar *name_src;
198 FILE *f;
199 g_assert ((fd_src = g_file_open_tmp("tmp-viking.XXXXXX", &name_src, NULL)) >= 0);
e45b3da1 200 g_debug ("%s: temporary file: %s", __FUNCTION__, name_src);
28c82d8b 201 f = fdopen(fd_src, "w");
208d2084 202 a_gpx_write_track_file(track, f, NULL); /* Thank you Guilhem! Just when I needed this function... -- Evan */
28c82d8b 203 fclose(f);
8c060406 204 f = NULL;
28c82d8b
EB
205 return name_src;
206}
207
208/* TODO: cleanup, getr rid of redundancy */
209
210/* depending on type of filter, often only vtl or track will be given.
211 * the other can be NULL.
212 */
62ddf770 213static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSourceInterface *source_interface,
28c82d8b 214 VikTrwLayer *vtl, VikTrack *track )
1d1bc3c1 215{
28c82d8b 216 /* for manual dialogs */
1d1bc3c1 217 GtkWidget *dialog = NULL;
7b3479e3 218 GtkWidget *status;
0944940f
RN
219 gchar *cmd = NULL;
220 gchar *extra = NULL;
c9a36bd6
RN
221 gchar *cmd_off = NULL;
222 gchar *extra_off = NULL;
7b3479e3 223 acq_dialog_widgets_t *w;
65f0ccab 224 gpointer user_data;
ed691ed1 225 gpointer options = NULL;
7b3479e3 226
28c82d8b
EB
227 /* for UI builder */
228 gpointer pass_along_data;
7ee4103e 229 VikLayerParamData *paramdatas = NULL;
28c82d8b 230
7b3479e3
EB
231 w_and_interface_t *wi;
232
28c82d8b 233 /*** INIT AND CHECK EXISTENCE ***/
62ddf770
MA
234 if ( source_interface->init_func )
235 user_data = source_interface->init_func();
28c82d8b
EB
236 else
237 user_data = NULL;
238 pass_along_data = user_data;
239
62ddf770
MA
240 if ( source_interface->check_existence_func ) {
241 gchar *error_str = source_interface->check_existence_func();
92255687
EB
242 if ( error_str ) {
243 a_dialog_error_msg ( GTK_WINDOW(vw), error_str );
244 g_free ( error_str );
245 return;
246 }
247 }
248
28c82d8b
EB
249 /* BUILD UI & GET OPTIONS IF NECESSARY. */
250
251 /* POSSIBILITY 0: NO OPTIONS. DO NOTHING HERE. */
252 /* POSSIBILITY 1: ADD_SETUP_WIDGETS_FUNC */
62ddf770 253 if ( source_interface->add_setup_widgets_func ) {
f4b1d29b 254 dialog = gtk_dialog_new_with_buttons ( "", GTK_WINDOW(vw), 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL );
92255687 255
5f7a8ef6
RN
256 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
257 GtkWidget *response_w = NULL;
258#if GTK_CHECK_VERSION (2, 20, 0)
259 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
260#endif
261
62ddf770
MA
262 source_interface->add_setup_widgets_func(dialog, vvp, user_data);
263 gtk_window_set_title ( GTK_WINDOW(dialog), _(source_interface->window_title) );
a8d46e0b 264
5f7a8ef6
RN
265 if ( response_w )
266 gtk_widget_grab_focus ( response_w );
267
7b3479e3 268 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
62ddf770 269 source_interface->cleanup_func(user_data);
7b3479e3
EB
270 gtk_widget_destroy(dialog);
271 return;
272 }
28c82d8b
EB
273 }
274 /* POSSIBILITY 2: UI BUILDER */
62ddf770 275 else if ( source_interface->params ) {
13fde155 276 paramdatas = a_uibuilder_run_dialog ( source_interface->window_title, GTK_WINDOW(vw),
62ddf770
MA
277 source_interface->params, source_interface->params_count,
278 source_interface->params_groups, source_interface->params_groups_count,
279 source_interface->params_defaults );
28c82d8b
EB
280 if ( paramdatas )
281 pass_along_data = paramdatas;
282 else
283 return; /* TODO: do we have to free anything here? */
284 }
285
286 /* CREATE INPUT DATA & GET COMMAND STRING */
287
62ddf770 288 if ( source_interface->inputtype == VIK_DATASOURCE_INPUTTYPE_TRWLAYER ) {
28c82d8b
EB
289 gchar *name_src = write_tmp_trwlayer ( vtl );
290
62ddf770 291 ((VikDataSourceGetCmdStringFuncWithInput) source_interface->get_cmd_string_func)
28c82d8b
EB
292 ( pass_along_data, &cmd, &extra, name_src );
293
294 g_free ( name_src );
295 /* TODO: delete the tmp file? or delete it only after we're done with it? */
62ddf770 296 } else if ( source_interface->inputtype == VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK ) {
28c82d8b
EB
297 gchar *name_src = write_tmp_trwlayer ( vtl );
298 gchar *name_src_track = write_tmp_track ( track );
299
62ddf770 300 ((VikDataSourceGetCmdStringFuncWithInputInput) source_interface->get_cmd_string_func)
28c82d8b
EB
301 ( pass_along_data, &cmd, &extra, name_src, name_src_track );
302
303 g_free ( name_src );
304 g_free ( name_src_track );
62ddf770 305 } else if ( source_interface->inputtype == VIK_DATASOURCE_INPUTTYPE_TRACK ) {
28c82d8b
EB
306 gchar *name_src_track = write_tmp_track ( track );
307
62ddf770 308 ((VikDataSourceGetCmdStringFuncWithInput) source_interface->get_cmd_string_func)
28c82d8b
EB
309 ( pass_along_data, &cmd, &extra, name_src_track );
310
311 g_free ( name_src_track );
0944940f 312 } else if ( source_interface->get_cmd_string_func )
ed691ed1 313 source_interface->get_cmd_string_func ( pass_along_data, &cmd, &extra, &options );
28c82d8b 314
2b756ea0
RN
315 /* Get data for Off command */
316 if ( source_interface->off_func ) {
317 source_interface->off_func ( pass_along_data, &cmd_off, &extra_off );
318 }
319
28c82d8b 320 /* cleanup for option dialogs */
62ddf770 321 if ( source_interface->add_setup_widgets_func ) {
7b3479e3
EB
322 gtk_widget_destroy(dialog);
323 dialog = NULL;
62ddf770
MA
324 } else if ( source_interface->params ) {
325 a_uibuilder_free_paramdatas ( paramdatas, source_interface->params, source_interface->params_count );
28c82d8b
EB
326 }
327
7b3479e3
EB
328 w = g_malloc(sizeof(*w));
329 wi = g_malloc(sizeof(*wi));
330 wi->w = w;
62ddf770 331 wi->w->source_interface = source_interface;
7b3479e3 332 wi->cmd = cmd;
28c82d8b 333 wi->extra = extra; /* usually input data type (?) */
ed691ed1 334 wi->options = options;
b2aa700f
RN
335 wi->vtl = vtl;
336 wi->creating_new_layer = (!vtl);
1d1bc3c1 337
f4b1d29b 338 dialog = gtk_dialog_new_with_buttons ( "", GTK_WINDOW(vw), 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL );
1d1bc3c1 339 gtk_dialog_set_response_sensitive ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE );
62ddf770 340 gtk_window_set_title ( GTK_WINDOW(dialog), _(source_interface->window_title) );
1d1bc3c1 341
1d1bc3c1 342 w->dialog = dialog;
b2aa700f
RN
343 w->running = TRUE;
344 status = gtk_label_new (_("Working..."));
7b3479e3 345 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), status, FALSE, FALSE, 5 );
5f7a8ef6 346 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
b2aa700f
RN
347 // May not want to see the dialog at all
348 if ( source_interface->is_thread || source_interface->keep_dialog_open )
349 gtk_widget_show_all(dialog);
1d1bc3c1 350 w->status = status;
7b3479e3 351
1d1bc3c1
EB
352 w->vw = vw;
353 w->vlp = vlp;
354 w->vvp = vvp;
62ddf770
MA
355 if ( source_interface->add_progress_widgets_func ) {
356 source_interface->add_progress_widgets_func ( dialog, user_data );
65f0ccab
AF
357 }
358 w->user_data = user_data;
7b3479e3 359
b2aa700f
RN
360 if (source_interface->mode == VIK_DATASOURCE_ADDTOLAYER) {
361 VikLayer *current_selected = vik_layers_panel_get_selected ( w->vlp );
362 if ( IS_VIK_TRW_LAYER(current_selected) ) {
363 wi->vtl = VIK_TRW_LAYER(current_selected);
364 wi->creating_new_layer = FALSE;
365 }
366 }
3cc57413
RN
367 else if ( source_interface->mode == VIK_DATASOURCE_MANUAL_LAYER_MANAGEMENT ) {
368 // Don't create in acquire - as datasource will perform the necessary actions
369 wi->creating_new_layer = FALSE;
6ef14d6b
RN
370 VikLayer *current_selected = vik_layers_panel_get_selected ( w->vlp );
371 if ( IS_VIK_TRW_LAYER(current_selected) )
372 wi->vtl = VIK_TRW_LAYER(current_selected);
3cc57413 373 }
b2aa700f
RN
374 if ( wi->creating_new_layer ) {
375 wi->vtl = VIK_TRW_LAYER ( vik_layer_create ( VIK_LAYER_TRW, w->vvp, NULL, FALSE ) );
376 vik_layer_rename ( VIK_LAYER ( wi->vtl ), _(source_interface->layer_title) );
377 }
a8d46e0b 378
b2aa700f
RN
379 if ( source_interface->is_thread ) {
380 if ( cmd ) {
381 g_thread_create((GThreadFunc)get_from_anything, wi, FALSE, NULL );
382 gtk_dialog_run ( GTK_DIALOG(dialog) );
383 if (w->running) {
9a91dd66
RN
384 // Cancel and mark for thread to finish
385 w->running = FALSE;
386 // NB Thread will free memory
b2aa700f
RN
387 } else {
388 if ( cmd_off ) {
389 /* Turn off */
ed691ed1 390 a_babel_convert_from (NULL, cmd_off, extra_off, NULL, NULL, NULL);
b2aa700f
RN
391 g_free ( cmd_off );
392 }
393 if ( extra_off )
394 g_free ( extra_off );
9a91dd66
RN
395
396 // Thread finished by normal completion - free memory
397 g_free ( w );
398 g_free ( wi );
b2aa700f
RN
399 }
400 }
401 else {
402 // This shouldn't happen...
403 gtk_label_set_text ( GTK_LABEL(w->status), _("Unable to create command\nAcquire method failed.") );
404 gtk_dialog_run (GTK_DIALOG (dialog));
b2aa700f
RN
405 }
406 }
7b3479e3 407 else {
b2aa700f
RN
408 // bypass thread method malarkly - you'll just have to wait...
409 if ( source_interface->process_func ) {
ed691ed1 410 gboolean result = source_interface->process_func ( wi->vtl, cmd, extra, (BabelStatusFunc) progress_func, w, options );
b2aa700f
RN
411 if ( !result )
412 a_dialog_msg ( GTK_WINDOW(vw), GTK_MESSAGE_ERROR, _("Error: acquisition failed."), NULL );
2b756ea0 413 }
b2aa700f
RN
414 g_free ( cmd );
415 g_free ( extra );
ed691ed1 416 g_free ( options );
b2aa700f
RN
417
418 on_complete_process ( wi );
419 // Actually show it if necessary
420 if ( wi->w->source_interface->keep_dialog_open )
421 gtk_dialog_run ( GTK_DIALOG(dialog) );
9a91dd66
RN
422
423 g_free ( w );
424 g_free ( wi );
7b3479e3 425 }
b2aa700f 426
1d1bc3c1
EB
427 gtk_widget_destroy ( dialog );
428}
7b3479e3 429
fba47910
GB
430/**
431 * a_acquire:
432 *
433 * Process the given VikDataSourceInterface for sources with no input data.
434 */
62ddf770
MA
435void a_acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSourceInterface *source_interface ) {
436 acquire ( vw, vlp, vvp, source_interface, NULL, NULL );
28c82d8b
EB
437}
438
439static void acquire_trwlayer_callback ( GObject *menuitem, gpointer *pass_along )
440{
441 VikDataSourceInterface *iface = g_object_get_data ( menuitem, "vik_acq_iface" );
442 VikWindow *vw = pass_along[0];
443 VikLayersPanel *vlp = pass_along[1];
444 VikViewport *vvp = pass_along[2];
445 VikTrwLayer *vtl = pass_along[3];
446 VikTrack *tr = pass_along[4];
447
448 acquire ( vw, vlp, vvp, iface, vtl, tr );
449}
450
451static GtkWidget *acquire_build_menu ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp,
452 VikTrwLayer *vtl, VikTrack *track, /* both passed to acquire, although for many filters only one ness */
453 const gchar *menu_title, vik_datasource_inputtype_t inputtype )
454{
0d337f27 455 static gpointer pass_along[5];
7ee4103e
GB
456 GtkWidget *menu_item=NULL, *menu=NULL;
457 GtkWidget *item=NULL;
28c82d8b
EB
458 int i;
459
28c82d8b
EB
460 pass_along[0] = vw;
461 pass_along[1] = vlp;
462 pass_along[2] = vvp;
463 pass_along[3] = vtl;
464 pass_along[4] = track;
465
466 for ( i = 0; i < N_FILTERS; i++ ) {
467 if ( filters[i]->inputtype == inputtype ) {
468 if ( ! menu_item ) { /* do this just once, but return NULL if no filters */
469 menu = gtk_menu_new();
c6fb43ba 470 menu_item = gtk_menu_item_new_with_mnemonic ( menu_title );
28c82d8b
EB
471 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu );
472 }
473
474 item = gtk_menu_item_new_with_label ( filters[i]->window_title );
475 g_object_set_data ( G_OBJECT(item), "vik_acq_iface", (gpointer) filters[i] );
476 g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(acquire_trwlayer_callback), pass_along );
477 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
478 gtk_widget_show ( item );
479 }
480 }
481
482 return menu_item;
483}
484
fba47910
GB
485/**
486 * a_acquire_trwlayer_menu:
487 *
488 * Create a sub menu intended for rightclicking on a TRWLayer's menu called "Filter".
489 *
490 * Returns: %NULL if no filters.
491 */
28c82d8b
EB
492GtkWidget *a_acquire_trwlayer_menu (VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikTrwLayer *vtl)
493{
0d6911da 494 return acquire_build_menu ( vw, vlp, vvp, vtl, NULL, _("_Filter"), VIK_DATASOURCE_INPUTTYPE_TRWLAYER );
28c82d8b
EB
495}
496
fba47910
GB
497/**
498 * a_acquire_trwlayer_track_menu:
499 *
500 * Create a sub menu intended for rightclicking on a TRWLayer's menu called "Filter with Track "TRACKNAME"...".
501 *
502 * Returns: %NULL if no filters or no filter track has been set.
503 */
28c82d8b
EB
504GtkWidget *a_acquire_trwlayer_track_menu (VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikTrwLayer *vtl)
505{
506 if ( filter_track == NULL )
507 return NULL;
508 else {
0d6911da 509 gchar *menu_title = g_strdup_printf ( _("Filter with %s"), filter_track->name );
28c82d8b
EB
510 GtkWidget *rv = acquire_build_menu ( vw, vlp, vvp, vtl, filter_track,
511 menu_title, VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK );
512 g_free ( menu_title );
513 return rv;
514 }
515}
516
fba47910
GB
517/**
518 * a_acquire_track_menu:
519 *
520 * Create a sub menu intended for rightclicking on a track's menu called "Filter".
521 *
522 * Returns: %NULL if no applicable filters
523 */
28c82d8b
EB
524GtkWidget *a_acquire_track_menu (VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikTrack *tr)
525{
0d6911da 526 return acquire_build_menu ( vw, vlp, vvp, NULL, tr, _("Filter"), VIK_DATASOURCE_INPUTTYPE_TRACK );
28c82d8b
EB
527}
528
fba47910
GB
529/**
530 * a_acquire_set_filter_track:
531 *
532 * Sets application-wide track to use with filter. references the track.
533 */
ce4bd1cf 534void a_acquire_set_filter_track ( VikTrack *tr )
28c82d8b
EB
535{
536 if ( filter_track )
537 vik_track_free ( filter_track );
28c82d8b
EB
538
539 filter_track = tr;
540 vik_track_ref ( tr );
28c82d8b 541}