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