694b00fe2451b7c06ac642a47b813a08d4a81bbc
[profile/ivi/navit.git] / navit / navit / navit.c
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2009 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 #define _USE_MATH_DEFINES 1
21 #include "config.h"
22 #ifdef HAVE_UNISTD_H
23 #include <unistd.h>
24 #endif
25 #include <stdio.h>
26 #include <errno.h>
27 #include <stdlib.h>
28 #include <signal.h>
29 #include <string.h>
30 #include <fcntl.h>
31 #include <glib.h>
32 #include <math.h>
33 #include <time.h>
34 #include "debug.h"
35 #include "navit.h"
36 #include "callback.h"
37 #include "gui.h"
38 #include "item.h"
39 #include "projection.h"
40 #include "map.h"
41 #include "mapset.h"
42 #include "main.h"
43 #include "coord.h"
44 #include "point.h"
45 #include "transform.h"
46 #include "param.h"
47 #include "menu.h"
48 #include "graphics.h"
49 #include "popup.h"
50 #include "data_window.h"
51 #include "route.h"
52 #include "navigation.h"
53 #include "speech.h"
54 #include "track.h"
55 #include "vehicle.h"
56 #include "layout.h"
57 #include "log.h"
58 #include "attr.h"
59 #include "event.h"
60 #include "file.h"
61 #include "profile.h"
62 #include "command.h"
63 #include "navit_nls.h"
64 #include "map.h"
65 #include "util.h"
66 #include "messages.h"
67 #include "vehicleprofile.h"
68 #include "sunriset.h"
69 #include "bookmarks.h"
70 #include "xmlconfig.h"
71 #ifdef HAVE_API_WIN32_BASE
72 #include <windows.h>
73 #include "util.h"
74 #endif
75 #ifdef HAVE_API_WIN32_CE
76 #include "libc.h"
77 #endif
78
79 /* define string for bookmark handling */
80 #define TEXTFILE_COMMENT_NAVI_STOPPED "# navigation stopped\n"
81
82 /**
83  * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object
84  * @{
85  */
86
87 //! The navit_vehicule
88 struct navit_vehicle {
89         int follow;
90         /*! Limit of the follow counter. See navit_add_vehicle */
91         int follow_curr;
92         /*! Deprecated : follow counter itself. When it reaches 'update' counts, map is recentered*/
93         struct coord coord;
94         int dir;
95         int speed;
96         struct coord last; /*< Position of the last update of this vehicle */
97         struct vehicle *vehicle;
98         struct attr callback;
99         int animate_cursor;
100 };
101
102 struct navit {
103         struct object_func *func;
104         int refcount;
105         struct attr **attrs;
106         struct attr self;
107         GList *mapsets;
108         GList *layouts;
109         struct gui *gui;
110         struct layout *layout_current;
111         struct graphics *gra;
112         struct action *action;
113         struct transformation *trans, *trans_cursor;
114         struct compass *compass;
115         struct route *route;
116         struct navigation *navigation;
117         struct speech *speech;
118         struct tracking *tracking;
119         int ready;
120         struct window *win;
121         struct displaylist *displaylist;
122         int tracking_flag;
123         int orientation;
124         int recentdest_count;
125         int osd_configuration;
126         GList *vehicles;
127         GList *windows_items;
128         struct navit_vehicle *vehicle;
129         struct callback_list *attr_cbl;
130         struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb, *progress_cb;
131         struct datawindow *roadbook_window;
132         struct map *former_destination;
133         struct point pressed, last, current;
134         int button_pressed,moved,popped,zoomed;
135         int center_timeout;
136         int autozoom_secs;
137         int autozoom_min;
138         int autozoom_active;
139         struct event_timeout *button_timeout, *motion_timeout;
140         struct callback *motion_timeout_callback;
141         int ignore_button;
142         int ignore_graphics_events;
143         struct log *textfile_debug_log;
144         struct pcoord destination;
145         int destination_valid;
146         int blocked;
147         int w,h;
148         int drag_bitmap;
149         int use_mousewheel;
150         struct messagelist *messages;
151         struct callback *resize_callback,*button_callback,*motion_callback,*predraw_callback;
152         struct vehicleprofile *vehicleprofile;
153         GList *vehicleprofiles;
154         int pitch;
155         int follow_cursor;
156         int prevTs;
157         int graphics_flags;
158         int zoom_min, zoom_max;
159         int radius;
160         struct bookmarks *bookmarks;
161         int flags;
162                  /* 1=No graphics ok */
163                  /* 2=No gui ok */
164         int border;
165         int imperial;
166         int waypoints_flag;
167         struct attr **attr_list;
168 };
169
170 struct gui *main_loop_gui;
171
172 struct attr_iter {
173         void *iter;
174         union {
175                 GList *list;
176                 struct mapset_handle *mapset_handle;
177         } u;
178 };
179
180 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
181 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
182 static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
183 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
184 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir);
185 static void navit_set_cursors(struct navit *this_);
186 static void navit_cmd_zoom_to_route(struct navit *this);
187 static void navit_cmd_set_center_cursor(struct navit *this_);
188 static void navit_cmd_announcer_toggle(struct navit *this_);
189 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
190 struct object_func navit_func;
191
192 struct navit *global_navit;
193
194 void
195 navit_add_mapset(struct navit *this_, struct mapset *ms)
196 {
197         this_->mapsets = g_list_append(this_->mapsets, ms);
198 }
199
200 struct mapset *
201 navit_get_mapset(struct navit *this_)
202 {
203         if(this_->mapsets){
204                 return this_->mapsets->data;
205         } else {
206                 dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
207         }
208         return NULL;
209 }
210
211 struct tracking *
212 navit_get_tracking(struct navit *this_)
213 {
214         return this_->tracking;
215 }
216
217 /**
218  * @brief       Get the user data directory.
219  * @param[in]    create - create the directory if it does not exist
220  *
221  * @return      char * to the data directory string.
222  *
223  * returns the directory used to store user data files (center.txt,
224  * destination.txt, bookmark.txt, ...)
225  *
226  */
227 char*
228 navit_get_user_data_directory(int create) {
229         char *dir;
230         dir = getenv("NAVIT_USER_DATADIR");
231         if (create && !file_exists(dir)) {
232                 dbg(0,"creating dir %s\n", dir);
233                 if (file_mkdir(dir,0)) {
234                         dbg(0,"failed creating dir %s\n", dir);
235                         return NULL;
236                 }
237         }
238         return dir;
239 } /* end: navit_get_user_data_directory(gboolean create) */
240
241
242 void
243 navit_draw_async(struct navit *this_, int async)
244 {
245
246         if (this_->blocked) {
247                 this_->blocked |= 2;
248                 return;
249         }
250         transform_setup_source_rect(this_->trans);
251         graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
252 }
253
254 void
255 navit_draw(struct navit *this_)
256 {
257         if (this_->ready == 3)
258                 navit_draw_async(this_, 0);
259 }
260
261 int
262 navit_get_ready(struct navit *this_)
263 {
264         return this_->ready;
265 }
266
267
268
269 void
270 navit_draw_displaylist(struct navit *this_)
271 {
272         if (this_->ready == 3)
273                 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
274 }
275
276 static void
277 navit_map_progress(struct navit *this_)
278 {
279         struct map *map;
280         struct mapset *ms;
281         struct mapset_handle *msh;
282         struct attr attr;
283         struct point p;
284         if (this_->ready != 3)
285                 return;
286         p.x=10;
287         p.y=32;
288
289         ms=this_->mapsets->data;
290         msh=mapset_open(ms);
291         while (msh && (map=mapset_next(msh, 0))) {
292                 if (map_get_attr(map, attr_progress, &attr, NULL)) {
293                         char *str=g_strdup_printf("%s           ",attr.u.str);
294                         graphics_draw_mode(this_->gra, draw_mode_begin);
295                         graphics_draw_text_std(this_->gra, 16, str, &p);
296                         g_free(str);
297                         p.y+=32;
298                         graphics_draw_mode(this_->gra, draw_mode_end);
299                 }
300         }
301         mapset_close(msh);
302 }
303
304 static void
305 navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
306 {
307         int updated;
308         if (attr->type != attr_route_status)
309                 return;
310         updated=attr->u.num;
311         if (this_->ready != 3)
312                 return;
313         if (updated != route_status_path_done_new)
314                 return;
315         if (this_->vehicle) {
316                 if (this_->vehicle->follow_curr == 1)
317                         return;
318                 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
319                         this_->vehicle->follow_curr=this_->vehicle->follow;
320         }
321         navit_draw(this_);
322 }
323
324 void
325 navit_handle_resize(struct navit *this_, int w, int h)
326 {
327         struct map_selection sel;
328         int callback=(this_->ready == 1);
329         this_->ready |= 2;
330         memset(&sel, 0, sizeof(sel));
331         this_->w=w;
332         this_->h=h;
333         sel.u.p_rect.rl.x=w;
334         sel.u.p_rect.rl.y=h;
335         transform_set_screen_selection(this_->trans, &sel);
336         graphics_init(this_->gra);
337         graphics_set_rect(this_->gra, &sel.u.p_rect);
338         if (callback) 
339                 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
340         if (this_->ready == 3)
341                 navit_draw_async(this_, 1);
342 }
343
344 static void
345 navit_resize(void *data, int w, int h)
346 {
347         struct navit *this=data;
348         if (!this->ignore_graphics_events)
349                 navit_handle_resize(this, w, h);
350 }
351
352 int
353 navit_get_width(struct navit *this_)
354 {
355         return this_->w;
356 }
357
358
359 int
360 navit_get_height(struct navit *this_)
361 {
362         return this_->h;
363 }
364
365 static void
366 navit_popup(void *data)
367 {
368         struct navit *this_=data;
369         popup(this_, 1, &this_->pressed);
370         this_->button_timeout=NULL;
371         this_->popped=1;
372 }
373
374
375 int
376 navit_ignore_button(struct navit *this_)
377 {
378         if (this_->ignore_button)
379                 return 1;
380         this_->ignore_button=1;
381         return 0;
382 }
383
384 void
385 navit_ignore_graphics_events(struct navit *this_, int ignore)
386 {
387         this_->ignore_graphics_events=ignore;
388 }
389
390 static void
391 update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
392 {
393         struct coord co,cn;
394         struct coord c,*cp;
395         int yaw;
396         double angleo,anglen;
397
398         if (!transform_reverse(tr, old, &co))
399                 return;
400         if (rot) {
401                 angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
402                 anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
403                 yaw=transform_get_yaw(tr)+angleo-anglen;
404                 transform_set_yaw(tr, yaw % 360);
405         }
406         if (!transform_reverse(tr, new, &cn))
407                 return;
408         cp=transform_get_center(tr);
409         c.x=cp->x+co.x-cn.x;
410         c.y=cp->y+co.y-cn.y;
411         dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
412         transform_set_center(tr, &c);
413 }
414
415 void
416 navit_set_timeout(struct navit *this_)
417 {
418         struct attr follow;
419         follow.type=attr_follow;
420         follow.u.num=this_->center_timeout;
421         navit_set_attr(this_, &follow);
422 }
423
424 int
425 navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
426 {
427         int border=16;
428
429         dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button);
430         callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
431         if (this_->ignore_button) {
432                 this_->ignore_button=0;
433                 return 0;
434         }
435         if (pressed) {
436                 this_->pressed=*p;
437                 this_->last=*p;
438                 this_->zoomed=0;
439                 if (button == 1) {
440                         this_->button_pressed=1;
441                         this_->moved=0;
442                         this_->popped=0;
443                         if (popup_callback)
444                                 this_->button_timeout=event_add_timeout(500, 0, popup_callback);
445                 }
446                 if (button == 2)
447                         navit_set_center_screen(this_, p, 1);
448                 if (button == 3)
449                         popup(this_, button, p);
450                 if (button == 4 && this_->use_mousewheel) {
451                         this_->zoomed = 1;
452                         navit_zoom_in(this_, 2, p);
453                 }
454                 if (button == 5 && this_->use_mousewheel) {
455                         this_->zoomed = 1;
456                         navit_zoom_out(this_, 2, p);
457                 }
458         } else {
459
460                 this_->button_pressed=0;
461                 if (this_->button_timeout) {
462                         event_remove_timeout(this_->button_timeout);
463                         this_->button_timeout=NULL;
464                         if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
465                                 navit_set_center_screen(this_, p, !this_->zoomed);
466                         }
467                 }
468                 if (this_->motion_timeout) {
469                         event_remove_timeout(this_->motion_timeout);
470                         this_->motion_timeout=NULL;
471                 }
472                 if (this_->moved) {
473                         struct point pr;
474                         pr.x=this_->w/2;
475                         pr.y=this_->h;
476 #if 0
477                         update_transformation(this_->trans, &this_->pressed, p, &pr);
478 #else
479                         update_transformation(this_->trans, &this_->pressed, p, NULL);
480 #endif
481                         graphics_draw_drag(this_->gra, NULL);
482                         transform_copy(this_->trans, this_->trans_cursor);
483                         graphics_overlay_disable(this_->gra, 0);
484                         if (!this_->zoomed) 
485                                 navit_set_timeout(this_);
486                         navit_draw(this_);
487                 } else
488                         return 1;
489         }
490         return 0;
491 }
492
493 static void
494 navit_button(void *data, int pressed, int button, struct point *p)
495 {
496         struct navit *this=data;
497         dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events);
498         if (!this->ignore_graphics_events) {
499                 if (! this->popup_callback)
500                         this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
501                 navit_handle_button(this, pressed, button, p, this->popup_callback);
502         }
503 }
504
505
506 static void
507 navit_motion_timeout(struct navit *this_)
508 {
509         int dx, dy;
510
511         if (this_->drag_bitmap) {
512                 struct point point;
513                 point.x=(this_->current.x-this_->pressed.x);
514                 point.y=(this_->current.y-this_->pressed.y);
515                 if (graphics_draw_drag(this_->gra, &point)) {
516                         graphics_overlay_disable(this_->gra, 1);
517                         graphics_draw_mode(this_->gra, draw_mode_end);
518                         this_->moved=1;
519                         this_->motion_timeout=NULL;
520                         return;
521                 }
522         } 
523         dx=(this_->current.x-this_->last.x);
524         dy=(this_->current.y-this_->last.y);
525         if (dx || dy) {
526                 struct transformation *tr;
527                 struct point pr;
528                 this_->last=this_->current;
529                 graphics_overlay_disable(this_->gra, 1);
530                 tr=transform_dup(this_->trans);
531                 pr.x=this_->w/2;
532                 pr.y=this_->h;
533 #if 0
534                 update_transformation(tr, &this_->pressed, &this_->current, &pr);
535 #else
536                 update_transformation(tr, &this_->pressed, &this_->current, NULL);
537 #endif
538 #if 0
539                 graphics_displaylist_move(this_->displaylist, dx, dy);
540 #endif
541                 graphics_draw_cancel(this_->gra, this_->displaylist);
542                 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
543                 transform_destroy(tr);
544                 this_->moved=1;
545         }
546         this_->motion_timeout=NULL;
547         return;
548 }
549
550 void
551 navit_handle_motion(struct navit *this_, struct point *p)
552 {
553         int dx, dy;
554
555         if (this_->button_pressed && !this_->popped) {
556                 dx=(p->x-this_->pressed.x);
557                 dy=(p->y-this_->pressed.y);
558                 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
559                         this_->moved=1;
560                         if (this_->button_timeout) {
561                                 event_remove_timeout(this_->button_timeout);
562                                 this_->button_timeout=NULL;
563                         }
564                         this_->current=*p;
565                         if (! this_->motion_timeout_callback)
566                                 this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
567                         if (! this_->motion_timeout)
568                                 this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
569                 }
570         }
571 }
572
573 static void
574 navit_motion(void *data, struct point *p)
575 {
576         struct navit *this=data;
577         if (!this->ignore_graphics_events) 
578                 navit_handle_motion(this, p);
579 }
580
581 static void
582 navit_predraw(struct navit *this_)
583 {
584         GList *l;
585         struct navit_vehicle *nv;
586         transform_copy(this_->trans, this_->trans_cursor);
587         l=this_->vehicles;
588         while (l) {
589                 nv=l->data;
590                 navit_vehicle_draw(this_, nv, NULL);
591                 l=g_list_next(l);
592         }
593 }
594
595 static void
596 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
597 {
598         struct coord c1, c2, *center;
599         if (scale < this_->zoom_min)
600                 scale=this_->zoom_min;
601         if (scale > this_->zoom_max)
602                 scale=this_->zoom_max;
603         if (p)
604                 transform_reverse(this_->trans, p, &c1);
605         transform_set_scale(this_->trans, scale);
606         if (p) {
607                 transform_reverse(this_->trans, p, &c2);
608                 center = transform_center(this_->trans);
609                 center->x += c1.x - c2.x;
610                 center->y += c1.y - c2.y;
611         }
612         if (draw)
613                 navit_draw(this_);
614 }
615
616 /**
617  * @brief Automatically adjusts zoom level
618  *
619  * This function automatically adjusts the current
620  * zoom level according to the current speed.
621  *
622  * @param this_ The navit struct
623  * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
624  * @param speed The vehicles speed in meters per second
625  * @param dir The direction into which the vehicle moves
626  */
627 static void
628 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
629 {
630         struct point pc;
631         int distance,w,h;
632         double new_scale;
633         long scale;
634
635         if (! this_->autozoom_active) {
636                 return;
637         }
638
639         distance = speed * this_->autozoom_secs;
640
641         transform_get_size(this_->trans, &w, &h);
642         transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
643         scale = transform_get_scale(this_->trans);
644
645         /* We make sure that the point we want to see is within a certain range
646          * around the vehicle. The radius of this circle is the size of the
647          * screen. This doesn't necessarily mean the point is visible because of
648          * perspective etc. Quite rough, but should be enough. */
649         
650         if (w > h) {
651                 new_scale = (double)distance / h * 16; 
652         } else {
653                 new_scale = (double)distance / w * 16; 
654         }
655
656         if (abs(new_scale - scale) < 2) { 
657                 return; // Smoothing
658         }
659         
660         if (new_scale >= this_->autozoom_min) {
661                 navit_scale(this_, (long)new_scale, &pc, 0);
662         } else {
663                 if (scale != this_->autozoom_min) {
664                         navit_scale(this_, this_->autozoom_min, &pc, 0);
665                 }
666         }
667 }
668
669 /**
670  * Change the current zoom level, zooming closer to the ground
671  *
672  * @param navit The navit instance
673  * @param factor The zoom factor, usually 2
674  * @param p The invariant point (if set to NULL, default to center)
675  * @returns nothing
676  */
677 void
678 navit_zoom_in(struct navit *this_, int factor, struct point *p)
679 {
680         long scale=transform_get_scale(this_->trans)/factor;
681         if (scale < 1)
682                 scale=1;
683         navit_scale(this_, scale, p, 1);
684 }
685
686 /**
687  * Change the current zoom level
688  *
689  * @param navit The navit instance
690  * @param factor The zoom factor, usually 2
691  * @param p The invariant point (if set to NULL, default to center)
692  * @returns nothing
693  */
694 void
695 navit_zoom_out(struct navit *this_, int factor, struct point *p)
696 {
697         long scale=transform_get_scale(this_->trans)*factor;
698         navit_scale(this_, scale, p, 1);
699 }
700
701 void
702 navit_zoom_in_cursor(struct navit *this_, int factor)
703 {
704         struct point p;
705         if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
706                 navit_zoom_in(this_, factor, &p);
707                 this_->vehicle->follow_curr=this_->vehicle->follow;
708         } else
709                 navit_zoom_in(this_, factor, NULL);
710 }
711
712 void
713 navit_zoom_out_cursor(struct navit *this_, int factor)
714 {
715         struct point p;
716         if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
717                 navit_zoom_out(this_, 2, &p);
718                 this_->vehicle->follow_curr=this_->vehicle->follow;
719         } else
720                 navit_zoom_out(this_, 2, NULL);
721 }
722
723 static int
724 navit_cmd_zoom_in(struct navit *this_)
725 {
726         navit_zoom_in_cursor(this_, 2);
727         return 0;
728 }
729
730 static int
731 navit_cmd_zoom_out(struct navit *this_)
732 {
733         navit_zoom_out_cursor(this_, 2);
734         return 0;
735 }
736
737
738 static void
739 navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
740 {
741         if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) 
742                 navit_say(this, in[0]->u.str);
743 }
744
745 static GHashTable *cmd_int_var_hash = NULL;
746 static GHashTable *cmd_attr_var_hash = NULL;
747
748 /**
749  * Store key value pair for the  command system (for int typed values)
750  *
751  * @param navit The navit instance
752  * @param function unused (needed to match command function signiture)
753  * @param in input attributes in[0] is the key string, in[1] is the integer value to store
754  * @param out output attributes, unused 
755  * @param valid unused 
756  * @returns nothing
757  */
758 static void
759 navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
760 {
761         char*key;
762         struct attr*val;
763         if(!cmd_int_var_hash) {
764                 cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
765         }
766
767         if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
768              (in && in[1] && ATTR_IS_NUMERIC(in[1]->type))) {
769                 val = g_new(struct attr,1);
770                 attr_dup_content(in[1],val);
771                 key = g_strdup(in[0]->u.str);
772                 g_hash_table_insert(cmd_int_var_hash, key, val);
773         }
774 }
775
776
777 /**
778  * Store key value pair for the  command system (for attr typed values, can be used as opaque handles)
779  *
780  * @param navit The navit instance
781  * @param function unused (needed to match command function signiture)
782  * @param in input attributes in[0] is the key string, in[1] is the attr* value to store
783  * @param out output attributes, unused 
784  * @param valid unused 
785  * @returns nothing
786  */
787 //TODO free stored attributes on navit_destroy
788 static void
789 navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
790 {
791         char*key;
792         struct attr*val;
793         if(!cmd_attr_var_hash) {
794                 cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
795         }
796
797         if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
798              (in && in[1] )) {
799                 val = attr_dup(in[1]);
800                 //val = in[1];
801                 key = g_strdup(in[0]->u.str);
802                 g_hash_table_insert(cmd_attr_var_hash, key, val);
803         } else {
804                 dbg(1, "Wrong parameters for set_attr_var() command function\n");
805         }
806 }
807
808
809
810 /**
811  * command to toggle the active state of a named layer of the current layout
812  *
813  * @param navit The navit instance
814  * @param function unused (needed to match command function signiture)
815  * @param in input attribute in[0] is the name of the layer
816  * @param out output unused
817  * @param valid unused 
818  * @returns nothing
819  */
820 static void
821 navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
822 {
823         if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
824                 if(this->layout_current && this->layout_current->layers) {
825                         GList* layers = this->layout_current->layers;
826                         while (layers) {
827                                 struct layer*l=layers->data;
828                                 if(l && !strcmp(l->name,in[0]->u.str) ) {
829                                         l->active ^= 1;
830                                         navit_draw(this);
831                                         return;
832                                 }
833                                 layers=g_list_next(layers);
834                         }
835                 }
836         }
837 }
838
839 /**
840  * adds an item with the current coordinate of the vehicle to a named map
841  *
842  * @param navit The navit instance
843  * @param function unused (needed to match command function signiture)
844  * @param in input attribute in[0] is the name of the map 
845  * @param out output attribute, 0 on error or the id of the created item on success
846  * @param valid unused 
847  * @returns nothing
848  */
849 static void
850 navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
851 {
852         struct attr **list = g_new0(struct attr *,2);
853         struct attr*val = g_new0(struct attr,1);
854         struct mapset* ms;
855         struct map_selection sel;
856         const int selection_range = 10;
857         enum item_type item_type;
858         struct item *it;
859         struct map* curr_map = NULL;
860         struct coord curr_coord;
861         struct map_rect *mr;
862         
863         //return invalid item on error
864         val->type   = attr_none;
865         val->u.item  = NULL;    
866         list[0]     = val;
867         list[1]     = NULL;
868         *out = list;
869         if (
870                 in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
871                       in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str    //item type
872         ) {
873
874                 if(!(ms=navit_get_mapset(this))) {
875                         dbg(1, "Command function map_add_curr_pos(): there is no active mapset\n");
876                         return;
877                 }
878
879                 if((item_type = item_from_name(in[1]->u.str))==type_none) {
880                         dbg(1, "Command function map_add_curr_pos(): unknown item type\n");
881                         return;
882                 }
883
884                 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
885
886                 //no map with the given name found
887                 if( ! curr_map) {
888                         dbg(1, "Command function map_add_curr_pos(): map not found\n");
889                         return;
890                 }
891         
892                 if(this->vehicle && this->vehicle->vehicle ) {
893                         struct attr pos_attr;
894                         if(vehicle_get_attr(this->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) {
895                                 transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord);
896                         } else {
897                                 dbg(1, "Command function map_add_curr_pos(): vehicle position is not accessible\n");
898                                 return;
899                         }
900                 } else {
901                         dbg(1, "Command function map_add_curr_pos(): no vehicle\n");
902                         return;
903                 }
904
905                 sel.next=NULL;
906                 sel.order=18;
907                 sel.range.min=type_none;
908                 sel.range.max=type_tec_common;
909                 sel.u.c_rect.lu.x=curr_coord.x-selection_range;
910                 sel.u.c_rect.lu.y=curr_coord.y+selection_range;
911                 sel.u.c_rect.rl.x=curr_coord.x+selection_range;
912                 sel.u.c_rect.rl.y=curr_coord.y-selection_range;
913  
914                 mr = map_rect_new(curr_map, &sel);
915                 if(mr) {
916                         it = map_rect_create_item( mr, item_type);
917                         if (it) {
918                                 val->type = attr_type_item_begin;
919                                 item_coord_set(it,&curr_coord, 1, change_mode_modify);
920                         }
921                         val->u.item  = it;
922                 }
923                 map_rect_destroy(mr);
924         }
925 }
926
927 /**
928  * sets an attribute (name value pair) of a map item specified by map name and item id
929  *
930  * @param navit The navit instance
931  * @param function unused (needed to match command function signiture)
932  * @param in input attribute in[0] - name of the map  ; in[1] - item  ; in[2] - attr name ; in[3] - attr value
933  * @param out output attribute, 0 on error, 1 on success
934  * @param valid unused 
935  * @returns nothing
936  */
937 static void
938 navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
939 {
940         if (
941                 in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str  &&//map name
942                       in[1] && ATTR_IS_ITEM(in[1]->type)   &&                  //item
943                       in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str
944                       in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str    //attr_value str
945         ) {
946                 struct attr attr_to_set;
947                 struct map* curr_map = NULL;
948                 struct mapset *ms;
949                 struct map_selection sel;
950                 const int selection_range = 500;
951                 struct coord curr_coord;
952                 struct item *it;
953                 
954                 if(ATTR_IS_STRING(attr_from_name(in[2]->u.str))) {
955                         attr_to_set.u.str = in[3]->u.str;
956                         attr_to_set.type = attr_from_name(in[2]->u.str);
957                 }
958                 else if(ATTR_IS_INT(attr_from_name(in[2]->u.str))) {
959                         attr_to_set.u.num = atoi(in[3]->u.str);
960                         attr_to_set.type = attr_from_name(in[2]->u.str);
961                 }
962                 else if(ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str))) {
963                         double* val = g_new0(double,1);
964                         *val = atof(in[3]->u.str);
965                         attr_to_set.u.numd = val;
966                         attr_to_set.type = attr_from_name(in[2]->u.str);
967                 }
968
969                 ms = navit_get_mapset(this);
970
971                 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
972
973                 if( ! curr_map) {
974                         return;
975                 }
976                 sel.next=NULL;
977                 sel.order=18;
978                 sel.range.min=type_none;
979                 sel.range.max=type_tec_common;
980                 sel.u.c_rect.lu.x=curr_coord.x-selection_range;
981                 sel.u.c_rect.lu.y=curr_coord.y+selection_range;
982                 sel.u.c_rect.rl.x=curr_coord.x+selection_range;
983                 sel.u.c_rect.rl.y=curr_coord.y-selection_range;
984  
985                 it = in[1]->u.item;
986                 if(it) {
987                         item_attr_set(it, &attr_to_set, change_mode_modify);
988                 }
989         } else {
990                 dbg(4,"Error in command function item_set_attr()\n");
991                 dbg(4,"Command function item_set_attr(): map cond:       %d\n",(in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)?1:0);
992                 dbg(4,"Command function item_set_attr(): item cond:      %d\n",(in[1] && ATTR_IS_ITEM(in[1]->type))?1:0);
993                 dbg(4,"Command function item_set_attr(): attr type cond: %d\n",(in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str)?1:0);
994                 dbg(4,"Command function item_set_attr(): attr val cond:  %d\n",(in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str)?1:0);
995         }
996 }
997
998 /**
999  * Get attr variable given a key string for the command system (for opaque usage)
1000  *
1001  * @param navit The navit instance
1002  * @param function unused (needed to match command function signiture)
1003  * @param in input attribute in[0] is the key string
1004  * @param out output attribute, the attr for the given key string if exists or NULL  
1005  * @param valid unused 
1006  * @returns nothing
1007  */
1008 static void
1009 navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1010 {
1011         struct attr **list = g_new0(struct attr *,2);
1012         if(!cmd_attr_var_hash) {
1013                 struct attr*val = g_new0(struct attr,1);
1014                 cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
1015                 val->type   = attr_type_item_begin;
1016                 val->u.item = NULL;
1017                 list[0]     = val;
1018         }
1019         if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
1020                 struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str);
1021                 if(ret) {
1022                         list[0] = attr_dup(ret);
1023                 }
1024                 else {
1025                         struct attr*val = g_new0(struct attr,1);
1026                         val->type   = attr_type_int_begin;
1027                         val->u.item = NULL;
1028                         list[0]   = val;
1029                 }
1030         }
1031         list[1] = NULL;
1032         *out = list;
1033 }
1034
1035
1036 /**
1037  * Get value given a key string for the command system
1038  *
1039  * @param navit The navit instance
1040  * @param function unused (needed to match command function signiture)
1041  * @param in input attribute in[0] is the key string
1042  * @param out output attribute, the value for the given key string if exists or 0  
1043  * @param valid unused 
1044  * @returns nothing
1045  */
1046 static void
1047 navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1048 {
1049         struct attr **list = g_new0(struct attr *,2);
1050         if(!cmd_int_var_hash) {
1051                 struct attr*val = g_new0(struct attr,1);
1052                 cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
1053                 val->type   = attr_type_int_begin;
1054                 val->u.num  = 0;
1055                 list[0]     = val;
1056         }
1057         if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
1058                 struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str);
1059                 if(ret) {
1060                         list[0] = attr_dup(ret);
1061                 }
1062                 else {
1063                         struct attr*val = g_new0(struct attr,1);
1064                         val->type   = attr_type_int_begin;
1065                         val->u.num  = 0;
1066                         list[0]   = val;
1067                 }
1068         }
1069         list[1] = NULL;
1070         *out = list;
1071 }
1072
1073 GList *cmd_int_var_stack = NULL;
1074
1075 /**
1076  * Push an integer to the stack for the command system
1077  *
1078  * @param navit The navit instance
1079  * @param function unused (needed to match command function signiture)
1080  * @param in input attribute in[0] is the integer attibute to push
1081  * @param out output attributes, unused 
1082  * @param valid unused 
1083  * @returns nothing
1084  */
1085 static void
1086 navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1087 {
1088         if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type)) {
1089                 struct attr*val = g_new(struct attr,1);
1090                 attr_dup_content(in[0],val);
1091                 cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val);
1092         }
1093 }
1094
1095 /**
1096  * Pop an integer from the command system's integer stack
1097  *
1098  * @param navit The navit instance
1099  * @param function unused (needed to match command function signiture)
1100  * @param in input attributes unused
1101  * @param out output attribute, the value popped if stack isn't empty or 0
1102  * @param valid unused 
1103  * @returns nothing
1104  */
1105 static void
1106 navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1107 {
1108         struct attr **list = g_new0(struct attr *,2);
1109         if(!cmd_int_var_stack) {
1110                 struct attr*val = g_new0(struct attr,1);
1111                 val->type = attr_type_int_begin;
1112                 val->u.num  = 0;
1113                 list[0]   = val;
1114         }
1115         else {
1116                 list[0] = cmd_int_var_stack->data;
1117                 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
1118         }
1119         list[1] = NULL;
1120         *out = list;
1121 }
1122
1123 /**
1124  * Get current size of command system's integer stack
1125  *
1126  * @param navit The navit instance
1127  * @param function unused (needed to match command function signiture)
1128  * @param in input attributes unused
1129  * @param out output attribute, the size of stack
1130  * @param valid unused 
1131  * @returns nothing
1132  */
1133 static void
1134 navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1135 {
1136         struct attr **list;
1137         struct attr *attr  = g_new0(struct attr  ,1);
1138         attr->type  = attr_type_int_begin;
1139         if(!cmd_int_var_stack) {
1140                 attr->u.num = 0; 
1141         }
1142         else {
1143                 attr->u.num = g_list_length(cmd_int_var_stack); 
1144         }
1145         list = g_new0(struct attr *,2);
1146         list[0] = attr;
1147         list[1] = NULL;
1148         *out = list;
1149         cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
1150 }
1151
1152 static struct attr **
1153 navit_get_coord(struct navit *this, struct attr **in, struct pcoord *pc)
1154 {
1155         if (!in)
1156                 return NULL;
1157         if (!in[0])
1158                 return NULL;
1159         pc->pro = transform_get_projection(this->trans);
1160         if (ATTR_IS_STRING(in[0]->type)) {
1161                 struct coord c;
1162                 coord_parse(in[0]->u.str, pc->pro, &c);
1163                 pc->x=c.x;
1164                 pc->y=c.y;
1165                 in++;   
1166         } else if (ATTR_IS_COORD(in[0]->type)) {
1167                 pc->x=in[0]->u.coord->x;
1168                 pc->y=in[0]->u.coord->y;
1169                 in++;
1170         } else if (ATTR_IS_PCOORD(in[0]->type)) {
1171                 *pc=*in[0]->u.pcoord;
1172                 in++;
1173         } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
1174                 pc->pro=in[0]->u.num;
1175                 pc->x=in[1]->u.num;
1176                 pc->y=in[2]->u.num;
1177                 in+=3;
1178         } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
1179                 pc->x=in[0]->u.num;
1180                 pc->y=in[1]->u.num;
1181                 in+=2;
1182         } else
1183                 return NULL;
1184         return in;
1185 }
1186
1187 static void
1188 navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1189 {
1190         struct pcoord pc;
1191         char *description=NULL;
1192         in=navit_get_coord(this, in, &pc);
1193         if (!in)
1194                 return;
1195         if (in[0] && ATTR_IS_STRING(in[0]->type))
1196                 description=in[0]->u.str;
1197         navit_set_destination(this, &pc, description, 1);
1198 }
1199
1200
1201 static void
1202 navit_cmd_route_remove_next_waypoint(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1203 {
1204         navit_remove_waypoint(this);
1205 }
1206
1207
1208 static void
1209 navit_cmd_route_remove_last_waypoint(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1210 {
1211         navit_remove_nth_waypoint(this, navit_get_destination_count(this)-1);
1212 }
1213
1214
1215 static void
1216 navit_cmd_set_center(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1217 {
1218         struct pcoord pc;
1219         in=navit_get_coord(this, in, &pc);
1220         if (!in)
1221                 return;
1222         navit_set_center(this, &pc, 0);
1223 }
1224
1225
1226 static void
1227 navit_cmd_set_position(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1228 {
1229         struct pcoord pc;
1230         in=navit_get_coord(this, in, &pc);
1231         if (!in)
1232                 return;
1233         navit_set_position(this, &pc);
1234 }
1235
1236
1237 static void
1238 navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1239 {
1240         struct attr attr;
1241         attr.type=attr_type_string_begin;
1242         attr.u.str="Fix me";
1243         if (out) {
1244                 *out=attr_generic_add_attr(*out, &attr);
1245         }
1246 }
1247
1248 /**
1249  * Join several string attributes into one
1250  *
1251  * @param navit The navit instance
1252  * @param function unused (needed to match command function signiture)
1253  * @param in input attributes in[0] - separator, in[1..] - attributes to join
1254  * @param out output attribute joined attribute as string
1255  * @param valid unused 
1256  * @returns nothing
1257  */
1258 static void
1259 navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1260 {
1261         struct attr attr;
1262         gchar *ret, *sep;
1263         int i;
1264         attr.type=attr_type_string_begin;
1265         attr.u.str=NULL;
1266         if(in[0] && in[1]) {
1267                 sep=attr_to_text(in[0],NULL,1);
1268                 ret=attr_to_text(in[1],NULL,1);
1269                 for(i=2;in[i];i++) {
1270                         gchar *in_i=attr_to_text(in[i],NULL,1);
1271                         gchar *r=g_strjoin(sep,ret,in_i,NULL);
1272                         g_free(in_i);
1273                         g_free(ret);
1274                         ret=r;
1275                 }
1276                 g_free(sep);
1277                 attr.u.str=ret;
1278                 if(out) {
1279                         *out=attr_generic_add_attr(*out, &attr);
1280                 }
1281                 g_free(ret);
1282         }
1283 }
1284
1285 /**
1286  * Call external program
1287  *
1288  * @param navit The navit instance
1289  * @param function unused (needed to match command function signiture)
1290  * @param in input attributes in[0] - name of executable, in[1..] - parameters
1291  * @param out output attribute unused
1292  * @param valid unused 
1293  * @returns nothing
1294  */
1295 static void
1296 navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1297 {
1298         int i,j, nparms, nvalid;
1299         const char ** argv=NULL;
1300         struct spawn_process_info *pi;
1301
1302         nparms=0;
1303         nvalid=0;
1304         if(in) {
1305                 while(in[nparms]) {
1306                         if (in[nparms]->type!=attr_none) 
1307                                 nvalid++;
1308                         nparms++;
1309                 }
1310         }
1311         
1312         if(nvalid>0) {
1313                 argv=g_new(char*,nvalid+1);
1314                 for(i=0,j=0;in[i];i++) {
1315                         if(in[i]->type!=attr_none ) {
1316                                 argv[j++]=attr_to_text(in[i],NULL,1);
1317                         } else {
1318                                 dbg(0,"Parameter #%i is attr_none - skipping\n",i);
1319                         }
1320                 }
1321                 argv[j]=NULL;
1322                 pi=spawn_process(argv);
1323                 
1324                 // spawn_process() testing suite - uncomment following code to test.
1325                 //sleep(3);
1326                 // example of non-blocking wait
1327                 //int st=spawn_process_check_status(pi,0);dbg(0,"status %i\n",st);
1328                 // example of blocking wait
1329                 //st=spawn_process_check_status(pi,1);dbg(0,"status %i\n",st);
1330                 // example of wait after process is finished and status is
1331                 // already tested
1332                 //st=spawn_process_check_status(pi,1);dbg(0,"status %i\n",st);
1333                 // example of wait after process is finished and status is
1334                 // already tested - unblocked
1335                 //st=spawn_process_check_status(pi,0);dbg(0,"status %i\n",st);
1336                 
1337                 // End testing suite
1338                 spawn_process_info_free(pi);
1339                 for(i=0;argv[i];i++)
1340                         g_free(argv[i]);
1341                 g_free(argv);
1342         }
1343 }
1344
1345
1346 static struct command_table commands[] = {
1347         {"zoom_in",command_cast(navit_cmd_zoom_in)},
1348         {"zoom_out",command_cast(navit_cmd_zoom_out)},
1349         {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
1350         {"say",command_cast(navit_cmd_say)},
1351         {"set_center",command_cast(navit_cmd_set_center)},
1352         {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
1353         {"set_destination",command_cast(navit_cmd_set_destination)},
1354         {"route_remove_next_waypoint",command_cast(navit_cmd_route_remove_next_waypoint)},
1355         {"route_remove_last_waypoint",command_cast(navit_cmd_route_remove_last_waypoint)},
1356         {"set_position",command_cast(navit_cmd_set_position)},
1357         {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
1358         {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)},
1359         {"set_int_var",command_cast(navit_cmd_set_int_var)},
1360         {"get_int_var",command_cast(navit_cmd_get_int_var)},
1361         {"push_int",command_cast(navit_cmd_push_int)},
1362         {"pop_int",command_cast(navit_cmd_pop_int)},
1363         {"int_stack_size",command_cast(navit_cmd_int_stack_size)},
1364         {"toggle_layer",command_cast(navit_cmd_toggle_layer)},
1365         {"strjoin",command_cast(navit_cmd_strjoin)},
1366         {"spawn",command_cast(navit_cmd_spawn)},
1367         {"map_add_curr_pos",command_cast(navit_cmd_map_add_curr_pos)},
1368         {"map_item_set_attr",command_cast(navit_cmd_map_item_set_attr)},
1369         {"set_attr_var",command_cast(navit_cmd_set_attr_var)},
1370         {"get_attr_var",command_cast(navit_cmd_get_attr_var)},
1371 };
1372         
1373 void 
1374 navit_command_add_table(struct navit*this_, struct command_table *commands, int count)
1375 {
1376   command_add_table(this_->attr_cbl, commands, count, this_);
1377 }
1378
1379 struct navit *
1380 navit_new(struct attr *parent, struct attr **attrs)
1381 {
1382         struct navit *this_=g_new0(struct navit, 1);
1383         struct pcoord center;
1384         struct coord co;
1385         struct coord_geo g;
1386         enum projection pro=projection_mg;
1387         int zoom = 256;
1388         g.lat=53.13;
1389         g.lng=11.70;
1390
1391         this_->func=&navit_func;
1392         this_->refcount=1;
1393         this_->attrs=attr_list_dup(attrs);
1394         this_->self.type=attr_navit;
1395         this_->self.u.navit=this_;
1396         this_->attr_cbl=callback_list_new();
1397
1398         this_->orientation=-1;
1399         this_->tracking_flag=1;
1400         this_->recentdest_count=10;
1401         this_->osd_configuration=-1;
1402
1403         this_->center_timeout = 10;
1404         this_->use_mousewheel = 1;
1405         this_->autozoom_secs = 10;
1406         this_->autozoom_min = 7;
1407         this_->autozoom_active = 0;
1408         this_->zoom_min = 1;
1409         this_->zoom_max = 2097152;
1410         this_->follow_cursor = 1;
1411         this_->radius = 30;
1412         this_->border = 16;
1413
1414         this_->trans = transform_new();
1415         this_->trans_cursor = transform_new();
1416         transform_set_projection(this_->trans_cursor, pro);
1417         transform_from_geo(pro, &g, &co);
1418         center.x=co.x;
1419         center.y=co.y;
1420         center.pro = pro;
1421         
1422         transform_setup(this_->trans, &center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
1423
1424         this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans);
1425
1426         this_->prevTs=0;
1427
1428         for (;*attrs; attrs++) {
1429                 navit_set_attr_do(this_, *attrs, 1);
1430         }
1431         this_->displaylist=graphics_displaylist_new();
1432         command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
1433
1434         this_->messages = messagelist_new(attrs);
1435
1436         dbg(0,"return %p\n",this_);
1437         
1438         return this_;
1439 }
1440
1441 static int
1442 navit_set_gui(struct navit *this_, struct gui *gui)
1443 {
1444         if (this_->gui)
1445                 return 0;
1446         this_->gui=gui;
1447         if (gui_has_main_loop(this_->gui)) {
1448                 if (! main_loop_gui) {
1449                         main_loop_gui=this_->gui;
1450                 } else {
1451                         dbg(0,"gui with main loop already active, ignoring this instance");
1452                         return 0;
1453                 }
1454         }
1455         return 1;
1456 }
1457
1458 void 
1459 navit_add_message(struct navit *this_, char *message)
1460 {
1461         message_new(this_->messages, message);
1462 }
1463
1464 struct message
1465 *navit_get_messages(struct navit *this_)
1466 {
1467         return message_get(this_->messages);
1468 }
1469
1470 static int
1471 navit_set_graphics(struct navit *this_, struct graphics *gra)
1472 {
1473         if (this_->gra)
1474                 return 0;
1475         this_->gra=gra;
1476         this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
1477         graphics_add_callback(gra, this_->resize_callback);
1478         this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
1479         graphics_add_callback(gra, this_->button_callback);
1480         this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
1481         graphics_add_callback(gra, this_->motion_callback);
1482         this_->predraw_callback=callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_);
1483         graphics_add_callback(gra, this_->predraw_callback);
1484         return 1;
1485 }
1486
1487 struct graphics *
1488 navit_get_graphics(struct navit *this_)
1489 {
1490         return this_->gra;
1491 }
1492
1493 struct vehicleprofile *
1494 navit_get_vehicleprofile(struct navit *this_)
1495 {
1496         return this_->vehicleprofile;
1497 }
1498
1499 GList *
1500 navit_get_vehicleprofiles(struct navit *this_)
1501 {
1502         return this_->vehicleprofiles;
1503 }
1504
1505 static void
1506 navit_projection_set(struct navit *this_, enum projection pro, int draw)
1507 {
1508         struct coord_geo g;
1509         struct coord *c;
1510
1511         c=transform_center(this_->trans);
1512         transform_to_geo(transform_get_projection(this_->trans), c, &g);
1513         transform_set_projection(this_->trans, pro);
1514         transform_from_geo(pro, &g, c);
1515         if (draw)
1516                 navit_draw(this_);
1517 }
1518
1519 static void
1520 navit_mark_navigation_stopped(char *former_destination_file){
1521         FILE *f;
1522         f=fopen(former_destination_file, "a");
1523         if (f) {
1524                 fprintf(f,"%s", TEXTFILE_COMMENT_NAVI_STOPPED);
1525                 fclose(f);
1526         }else{
1527                 dbg(0, "Error setting mark in destination file %s: %s\n", former_destination_file, strerror(errno));
1528         }
1529 }
1530
1531 /**
1532  * Start or add a given set of coordinates for route computing
1533  *
1534  * @param navit The navit instance
1535  * @param c The coordinate to start routing to
1536  * @param description A label which allows the user to later identify this destination in the former destinations selection
1537  * @returns nothing
1538  */
1539 void
1540 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
1541 {
1542         char *destination_file;
1543         destination_file = bookmarks_get_destination_file(TRUE);
1544         if (c) {
1545                 this_->destination=*c;
1546                 this_->destination_valid=1;
1547
1548                 dbg(1, "c=(%i,%i)\n", c->x,c->y);
1549                 bookmarks_append_coord(this_->former_destination, destination_file, c, type_former_destination, description, this_->recentdest_count);
1550         } else {
1551                 this_->destination_valid=0;
1552                 navit_mark_navigation_stopped(destination_file);
1553         }
1554         g_free(destination_file);
1555         callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1556         if (this_->route) {
1557                 struct attr attr;
1558                 navit_get_attr(this_, attr_waypoints_flag, &attr, NULL);
1559                 if (this_->waypoints_flag==0 || route_get_destination_count(this_->route)==0){
1560                         route_set_destination(this_->route, c, async);
1561                 }else{
1562                         route_append_destination(this_->route, c, async);
1563                 }
1564
1565                 if (this_->ready == 3)
1566                         navit_draw(this_);
1567         }
1568 }
1569
1570 /**
1571  * Start the route computing to a given set of coordinates including waypoints
1572  *
1573  * @param navit The navit instance
1574  * @param c The coordinate to start routing to
1575  * @param description A label which allows the user to later identify this destination in the former destinations selection
1576  * @returns nothing
1577  */
1578 void
1579 navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
1580 {
1581         char *destination_file;
1582         if (c && count) {
1583                 this_->destination=c[count-1];
1584                 this_->destination_valid=1;
1585
1586                 destination_file = bookmarks_get_destination_file(TRUE);
1587                 bookmarks_append_coord(this_->former_destination, destination_file, c, type_former_itinerary, description, this_->recentdest_count);
1588                 g_free(destination_file);
1589         } else
1590                 this_->destination_valid=0;
1591         callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1592         if (this_->route) {
1593                 route_set_destinations(this_->route, c, count, async);
1594
1595                 if (this_->ready == 3)
1596                         navit_draw(this_);
1597         }
1598 }
1599
1600 int
1601 navit_get_destinations(struct navit *this_, struct pcoord *pc, int count)
1602 {
1603         if(!this_->route)
1604                 return 0;
1605         return route_get_destinations(this_->route, pc, count);
1606
1607 }
1608
1609 int
1610 navit_get_destination_count(struct navit *this_)
1611 {
1612         if(!this_->route)
1613                 return 0;
1614         return route_get_destination_count(this_->route);
1615 }
1616
1617 char*
1618 navit_get_destination_description(struct navit *this_, int n)
1619 {
1620         if(!this_->route)
1621                 return NULL;
1622         return route_get_destination_description(this_->route, n);
1623 }
1624
1625 void
1626 navit_remove_nth_waypoint(struct navit *this_, int n)
1627 {
1628         if(!this_->route)
1629                 return;
1630         if (route_get_destination_count(this_->route)>1){
1631                 route_remove_nth_waypoint(this_->route, n);
1632         }else{
1633                 navit_set_destination(this_, NULL, NULL, 0);
1634         }
1635 }
1636
1637 void
1638 navit_remove_waypoint(struct navit *this_)
1639 {
1640         if(!this_->route)
1641                 return;
1642         if (route_get_destination_count(this_->route)>1){
1643                 route_remove_waypoint(this_->route);
1644         }else{
1645                 navit_set_destination(this_, NULL, NULL, 0);
1646         }
1647 }
1648
1649 /**
1650  * @brief Checks if a route is calculated
1651  *
1652  * This function checks if a route is calculated.
1653  *
1654  * @param this_ The navit struct whose route should be checked.
1655  * @return True if the route is set, false otherwise.
1656  */
1657 int
1658 navit_check_route(struct navit *this_)
1659 {
1660         if (this_->route) {
1661                 return route_get_path_set(this_->route);
1662         }
1663
1664         return 0;
1665 }
1666
1667 static int
1668 navit_former_destinations_active(struct navit *this_)
1669 {
1670         char *destination_file_name = bookmarks_get_destination_file(FALSE);
1671         FILE *destination_file;
1672         int active=0;
1673         char lastline[100];
1674         destination_file=fopen(destination_file_name,"r");
1675         if (destination_file) {
1676                 while(fgets(lastline, sizeof(lastline), destination_file));
1677                 fclose(destination_file);
1678                 if ((lastline != NULL) && (strcmp(lastline, TEXTFILE_COMMENT_NAVI_STOPPED))){
1679                         active=1;
1680                 }
1681         }
1682         g_free(destination_file_name);
1683         return active;
1684 }
1685
1686 struct map* read_former_destinations_from_file(){
1687         struct attr type, data, flags, *attrs[4];
1688         char *destination_file = bookmarks_get_destination_file(FALSE);
1689         struct map *m;
1690
1691         type.type=attr_type;
1692         type.u.str="textfile";
1693
1694         data.type=attr_data;
1695         data.u.str=destination_file;
1696
1697         flags.type=attr_flags;
1698         flags.u.num=1;
1699
1700         attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL;
1701
1702         m=map_new(NULL, attrs);
1703         g_free(destination_file);
1704         return m;
1705 }
1706
1707 static void
1708 navit_add_former_destinations_from_file(struct navit *this_)
1709 {
1710         struct item *item;
1711         int i,valid=0,count=0;
1712         struct coord c[16];
1713         struct pcoord pc[16];
1714         struct map_rect *mr;
1715
1716         this_->former_destination=read_former_destinations_from_file();
1717         if (!this_->route || !navit_former_destinations_active(this_))
1718                 return; 
1719         mr=map_rect_new(this_->former_destination, NULL);
1720         while ((item=map_rect_get_item(mr))) {
1721                 if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count=item_coord_get(item, c, 16))) 
1722                         valid=1;
1723         }
1724         map_rect_destroy(mr);
1725         if (valid && count > 0) {
1726                 for (i = 0 ; i < count ; i++) {
1727                         pc[i].pro=map_projection(this_->former_destination);
1728                         pc[i].x=c[i].x;
1729                         pc[i].y=c[i].y;
1730                 }
1731                 if (count == 1)
1732                         route_set_destination(this_->route, &pc[0], 1);
1733                 else
1734                         route_set_destinations(this_->route, pc, count, 1);
1735                 this_->destination=pc[count-1];
1736                 this_->destination_valid=1;
1737         }
1738 }
1739
1740
1741 void
1742 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
1743 {
1744         va_list ap;
1745         char *str1,*str2;
1746         va_start(ap, fmt);
1747         if (this_->textfile_debug_log && this_->vehicle) {
1748                 str1=g_strdup_vprintf(fmt, ap);
1749                 str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
1750                 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
1751                 g_free(str2);
1752                 g_free(str1);
1753         }
1754         va_end(ap);
1755 }
1756
1757 void
1758 navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...)
1759 {
1760         va_list ap;
1761         char *str1,*str2;
1762         va_start(ap, fmt);
1763         if (this_->textfile_debug_log && this_->vehicle) {
1764                 str1=g_strdup_vprintf(fmt, ap);
1765                 str2=g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1);
1766                 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
1767                 g_free(str2);
1768                 g_free(str1);
1769         }
1770         va_end(ap);
1771 }
1772
1773 void
1774 navit_say(struct navit *this_, char *text)
1775 {
1776         struct attr attr;
1777         if(this_->speech) {
1778                 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1779                         attr.u.num = 1;
1780                 dbg(1, "this_.speech->active %i\n", attr.u.num);
1781                 if(attr.u.num)
1782                         speech_say(this_->speech, text);
1783         }
1784 }
1785
1786 /**
1787  * @brief Toggles the navigation announcer for navit
1788  * @param this_ The navit object
1789  */
1790 static void
1791 navit_cmd_announcer_toggle(struct navit *this_)
1792 {
1793     struct attr attr, speechattr;
1794
1795     // search for the speech attribute
1796     if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
1797         return;
1798     // find out if the corresponding attribute attr_active has been set
1799     if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
1800         // flip it then...
1801         attr.u.num = !attr.u.num;
1802     } else {
1803         // otherwise disable it because voice is enabled by default
1804         attr.type = attr_active;
1805         attr.u.num = 0;
1806     }
1807
1808     // apply the new state
1809     if(!speech_set_attr(speechattr.u.speech, &attr))
1810         return;
1811
1812     // announce that the speech attribute has changed
1813     callback_list_call_attr_0(this_->attr_cbl, attr_speech);
1814 }
1815
1816 void
1817 navit_speak(struct navit *this_)
1818 {
1819         struct navigation *nav=this_->navigation;
1820         struct map *map=NULL;
1821         struct map_rect *mr=NULL;
1822         struct item *item;
1823         struct attr attr;
1824
1825     if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1826         attr.u.num = 1;
1827     dbg(1, "this_.speech->active %i\n", attr.u.num);
1828     if(!attr.u.num)
1829         return;
1830
1831         if (nav)
1832                 map=navigation_get_map(nav);
1833         if (map)
1834                 mr=map_rect_new(map, NULL);
1835         if (mr) {
1836                 while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
1837                 if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
1838                         speech_say(this_->speech, attr.u.str);
1839                         navit_add_message(this_, attr.u.str);
1840                         navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
1841                 }
1842                 map_rect_destroy(mr);
1843         }
1844 }
1845
1846 static void
1847 navit_window_roadbook_update(struct navit *this_)
1848 {
1849         struct navigation *nav=this_->navigation;
1850         struct map *map=NULL;
1851         struct map_rect *mr=NULL;
1852         struct item *item;
1853         struct attr attr;
1854         struct param_list param[5];
1855         int secs;
1856
1857         dbg(1,"enter\n");
1858         datawindow_mode(this_->roadbook_window, 1);
1859         if (nav)
1860                 map=navigation_get_map(nav);
1861         if (map)
1862                 mr=map_rect_new(map, NULL);
1863         dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
1864         if (mr) {
1865                 dbg(0,"while loop\n");
1866                 while ((item=map_rect_get_item(mr))) {
1867                         dbg(0,"item=%p\n", item);
1868                         attr.u.str=NULL;
1869                         if (item->type != type_nav_position) {
1870                                 item_attr_get(item, attr_navigation_long, &attr);
1871                                 if (attr.u.str == NULL) {
1872                                         continue;
1873                                 }
1874                                 dbg(2, "Command='%s'\n", attr.u.str);
1875                                 param[0].value=g_strdup(attr.u.str);
1876                         } else
1877                                 param[0].value=_("Position");
1878                         param[0].name=_("Command");
1879
1880                         item_attr_get(item, attr_length, &attr);
1881                         dbg(2, "Length=%d\n", attr.u.num);
1882                         param[1].name=_("Length");
1883
1884                         if ( attr.u.num >= 2000 )
1885                         {
1886                                 param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1887                         }
1888                         else
1889                         {
1890                                 param[1].value=g_strdup_printf("%7ld %s",attr.u.num, _("m"));
1891                         }
1892
1893                         item_attr_get(item, attr_time, &attr);
1894                         dbg(2, "Time=%d\n", attr.u.num);
1895                         secs=attr.u.num/10;
1896                         param[2].name=_("Time");
1897                         if ( secs >= 3600 )
1898                         {
1899                                 param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
1900                         }
1901                         else
1902                         {
1903                                 param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1904                         }
1905
1906                         item_attr_get(item, attr_destination_length, &attr);
1907                         dbg(2, "Destlength=%d\n", attr.u.num);
1908                         param[3].name=_("Destination Length");
1909                         if ( attr.u.num >= 2000 )
1910                         {
1911                                 param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1912                         }
1913                         else
1914                         {
1915                                 param[3].value=g_strdup_printf("%ld %s",attr.u.num, _("m"));
1916                         }
1917
1918                         item_attr_get(item, attr_destination_time, &attr);
1919                         dbg(2, "Desttime=%d\n", attr.u.num);
1920                         secs=attr.u.num/10;
1921                         param[4].name=_("Destination Time");
1922                         if ( secs >= 3600 )
1923                         {
1924                                 param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
1925                         }
1926                         else
1927                         {
1928                                 param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1929                         }
1930                         datawindow_add(this_->roadbook_window, param, 5);
1931                 }
1932                 map_rect_destroy(mr);
1933         }
1934         datawindow_mode(this_->roadbook_window, 0);
1935 }
1936
1937 void
1938 navit_window_roadbook_destroy(struct navit *this_)
1939 {
1940         dbg(0, "enter\n");
1941         navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1942         callback_destroy(this_->roadbook_callback);
1943         this_->roadbook_window=NULL;
1944         this_->roadbook_callback=NULL;
1945 }
1946 void
1947 navit_window_roadbook_new(struct navit *this_)
1948 {
1949         if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
1950                 return;
1951         }
1952
1953         this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
1954         navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1955         this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
1956         navit_window_roadbook_update(this_);
1957 }
1958
1959 void
1960 navit_init(struct navit *this_)
1961 {
1962         struct mapset *ms;
1963         struct map *map;
1964         int callback;
1965         char *center_file;
1966
1967         dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
1968
1969         if (!this_->gui && !(this_->flags & 2)) {
1970                 dbg(0,"no gui\n");
1971                 navit_destroy(this_);
1972                 return;
1973         }
1974         if (!this_->gra && !(this_->flags & 1)) {
1975                 dbg(0,"no graphics\n");
1976                 navit_destroy(this_);
1977                 return;
1978         }
1979         dbg(2,"Connecting gui to graphics\n");
1980         if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) {
1981                 struct attr attr_type_gui, attr_type_graphics;
1982                 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
1983                 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
1984                 dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
1985                 dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
1986                 dbg(0," for explanations and solutions\n");
1987
1988                 navit_destroy(this_);
1989                 return;
1990         }
1991         if (this_->speech && this_->navigation) {
1992                 struct attr speech;
1993                 speech.type=attr_speech;
1994                 speech.u.speech=this_->speech;
1995                 navigation_set_attr(this_->navigation, &speech);
1996         }
1997         dbg(2,"Initializing graphics\n");
1998         dbg(2,"Setting Vehicle\n");
1999         navit_set_vehicle(this_, this_->vehicle);
2000         dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
2001         if (this_->mapsets) {
2002                 struct mapset_handle *msh;
2003                 ms=this_->mapsets->data;
2004                 this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
2005                 msh=mapset_open(ms);
2006                 while (msh && (map=mapset_next(msh, 0))) {
2007                         //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
2008                         struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
2009                         map_add_callback(map, pcb);
2010                 }
2011                 mapset_close(msh);
2012                 
2013                 if (this_->route) {
2014                         if ((map=route_get_map(this_->route))) {
2015                                 struct attr map_a;
2016                                 map_a.type=attr_map;
2017                                 map_a.u.map=map;
2018                                 mapset_add_attr(ms, &map_a);
2019                         }
2020                         if ((map=route_get_graph_map(this_->route))) {
2021                                 struct attr map_a,active;
2022                                 map_a.type=attr_map;
2023                                 map_a.u.map=map;
2024                                 active.type=attr_active;
2025                                 active.u.num=0;
2026                                 mapset_add_attr(ms, &map_a);
2027                                 map_set_attr(map, &active);
2028                         }
2029                         route_set_mapset(this_->route, ms);
2030                         route_set_projection(this_->route, transform_get_projection(this_->trans));
2031                 }
2032                 if (this_->tracking) {
2033                         tracking_set_mapset(this_->tracking, ms);
2034                         if (this_->route)
2035                                 tracking_set_route(this_->tracking, this_->route);
2036                 }
2037                 if (this_->navigation) {
2038                         if ((map=navigation_get_map(this_->navigation))) {
2039                                 struct attr map_a,active;
2040                                 map_a.type=attr_map;
2041                                 map_a.u.map=map;
2042                                 active.type=attr_active;
2043                                 active.u.num=0;
2044                                 mapset_add_attr(ms, &map_a);
2045                                 map_set_attr(map, &active);
2046                         }
2047                 }
2048                 if (this_->tracking) {
2049                         if ((map=tracking_get_map(this_->tracking))) {
2050                                 struct attr map_a,active;
2051                                 map_a.type=attr_map;
2052                                 map_a.u.map=map;
2053                                 active.type=attr_active;
2054                                 active.u.num=0;
2055                                 mapset_add_attr(ms, &map_a);
2056                                 map_set_attr(map, &active);
2057                         }
2058                 }
2059                 navit_add_former_destinations_from_file(this_);
2060         }
2061         if (this_->route) {
2062                 struct attr callback;
2063                 this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
2064                 callback.type=attr_callback;
2065                 callback.u.callback=this_->route_cb;
2066                 route_add_attr(this_->route, &callback);
2067         }
2068         if (this_->navigation) {
2069                 if (this_->speech) {
2070                         this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
2071                         navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
2072                 }
2073                 if (this_->route)
2074                         navigation_set_route(this_->navigation, this_->route);
2075         }
2076         dbg(2,"Setting Center\n");
2077         center_file = bookmarks_get_center_file(FALSE);
2078         bookmarks_set_center_from_file(this_->bookmarks, center_file);
2079         g_free(center_file);
2080 #if 0
2081         if (this_->menubar) {
2082                 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
2083                 if (men) {
2084                         navit_add_menu_windows_items(this_, men);
2085                 }
2086         }
2087 #endif
2088         global_navit=this_;
2089 #if 0
2090         navit_window_roadbook_new(this_);
2091         navit_window_items_new(this_);
2092 #endif
2093
2094         messagelist_init(this_->messages);
2095
2096         navit_set_cursors(this_);
2097
2098         callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
2099         callback=(this_->ready == 2);
2100         this_->ready|=1;
2101         dbg(2,"ready=%d\n",this_->ready);
2102         if (this_->ready == 3)
2103                 navit_draw_async(this_, 1);
2104         if (callback)
2105                 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
2106 #if 0
2107         routech_test(this_);
2108 #endif
2109 }
2110
2111 void
2112 navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
2113 {
2114         struct coord c;
2115         int w,h,scale=16;
2116
2117         c.x=(r->rl.x+r->lu.x)/2;
2118         c.y=(r->rl.y+r->lu.y)/2;
2119         transform_set_center(this_->trans, &c);
2120         transform_get_size(this_->trans, &w, &h);
2121         dbg(0,"center 0x%x,0x%x w %d h %d\n",c.x,c.y,w,h);
2122         dbg(0,"%x,%x-%x,%x\n", r->lu.x,r->lu.y,r->rl.x,r->rl.y);
2123         while (scale < 1<<20) {
2124                 struct point p1,p2;
2125                 transform_set_scale(this_->trans, scale);
2126                 transform_setup_source_rect(this_->trans);
2127                 transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
2128                 transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
2129                 dbg(0,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y);
2130                 if (p1.x < 0 || p2.x < 0 || p1.x > w || p2.x > w ||
2131                     p1.y < 0 || p2.y < 0 || p1.y > h || p2.y > h)
2132                         scale*=2;
2133                 else
2134                         break;
2135         
2136         }
2137         dbg(0,"scale=%d (0x%x) of %d (0x%x)\n",scale,scale,1<<20,1<<20);
2138         if (this_->ready == 3)
2139                 navit_draw_async(this_,0);
2140 }
2141
2142 void
2143 navit_zoom_to_route(struct navit *this_, int orientation)
2144 {
2145         struct map *map;
2146         struct map_rect *mr=NULL;
2147         struct item *item;
2148         struct coord c;
2149         struct coord_rect r;
2150         int count=0;
2151         if (! this_->route)
2152                 return;
2153         dbg(1,"enter\n");
2154         map=route_get_map(this_->route);
2155         dbg(1,"map=%p\n",map);
2156         if (map)
2157                 mr=map_rect_new(map, NULL);
2158         dbg(1,"mr=%p\n",mr);
2159         if (mr) {
2160                 while ((item=map_rect_get_item(mr))) {
2161                         dbg(1,"item=%s\n", item_to_name(item->type));
2162                         while (item_coord_get(item, &c, 1)) {
2163                                 dbg(1,"coord\n");
2164                                 if (!count) 
2165                                         r.lu=r.rl=c;
2166                                 else
2167                                         coord_rect_extend(&r, &c);      
2168                                 count++;
2169                         }
2170                 }
2171                 map_rect_destroy(mr);
2172         }
2173         if (! count)
2174                 return;
2175         if (orientation != -1)
2176                 transform_set_yaw(this_->trans, orientation);
2177         navit_zoom_to_rect(this_, &r);
2178 }
2179
2180 static void
2181 navit_cmd_zoom_to_route(struct navit *this)
2182 {
2183         navit_zoom_to_route(this, 0);
2184 }
2185
2186
2187 /**
2188  * Change the current zoom level
2189  *
2190  * @param navit The navit instance
2191  * @param center The point where to center the map, including its projection
2192  * @returns nothing
2193  */
2194 void
2195 navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
2196 {
2197         struct coord *c=transform_center(this_->trans);
2198         struct coord c1,c2;
2199         enum projection pro = transform_get_projection(this_->trans);
2200         if (pro != center->pro) {
2201                 c1.x = center->x;
2202                 c1.y = center->y;
2203                 transform_from_to(&c1, center->pro, &c2, pro);
2204         } else {
2205                 c2.x = center->x;
2206                 c2.y = center->y;
2207         }
2208         *c=c2;
2209         if (set_timeout) 
2210                 navit_set_timeout(this_);
2211         if (this_->ready == 3)
2212                 navit_draw(this_);
2213 }
2214
2215 static void
2216 navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
2217 {
2218         int width, height;
2219         struct point po;
2220         transform_set_center(this_->trans, c);
2221         transform_get_size(this_->trans, &width, &height);
2222         po.x=width/2;
2223         po.y=height/2;
2224         update_transformation(this_->trans, &po, p, NULL);
2225         if (set_timeout)
2226                 navit_set_timeout(this_);
2227 }
2228
2229 /**
2230  * Links all vehicles to a cursor depending on the current profile.
2231  *
2232  * @param this_ A navit instance
2233  * @author Ralph Sennhauser (10/2009)
2234  */
2235 static void
2236 navit_set_cursors(struct navit *this_)
2237 {
2238         struct attr name;
2239         struct navit_vehicle *nv;
2240         struct cursor *c;
2241         GList *v;
2242
2243         v=g_list_first(this_->vehicles); // GList of navit_vehicles
2244         while (v) {
2245                 nv=v->data;
2246                 if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) {
2247                         if (!strcmp(name.u.str,"none"))
2248                                 c=NULL;
2249                         else
2250                                 c=layout_get_cursor(this_->layout_current, name.u.str);
2251                 } else
2252                         c=layout_get_cursor(this_->layout_current, "default");
2253                 vehicle_set_cursor(nv->vehicle, c, 0);
2254                 v=g_list_next(v);
2255         }
2256         return;
2257 }
2258
2259 static int
2260 navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir)
2261 {
2262         int width, height;
2263         struct navit_vehicle *nv=this_->vehicle;
2264
2265         float offset=this_->radius;      // Cursor offset from the center of the screen (percent).
2266 #if 0 /* Better improve track.c to get that issue resolved or make it configurable with being off the default, the jumping back to the center is a bit annoying */
2267         float min_offset = 0.;      // Percent offset at min_offset_speed.
2268         float max_offset = 30.;     // Percent offset at max_offset_speed.
2269         int min_offset_speed = 2;   // Speed in km/h
2270         int max_offset_speed = 50;  // Speed ini km/h
2271         // Calculate cursor offset from the center of the screen, upon speed.
2272         if (nv->speed <= min_offset_speed) {
2273             offset = min_offset;
2274         } else if (nv->speed > max_offset_speed) {
2275             offset = max_offset;
2276         } else {
2277             offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
2278         }
2279 #endif
2280
2281         transform_get_size(this_->trans, &width, &height);
2282         if (this_->orientation == -1 || keep_orientation) {
2283                 p->x=50*width/100;
2284                 p->y=(50 + offset)*height/100;
2285                 if (dir) 
2286                         *dir=keep_orientation?this_->orientation:nv->dir;
2287         } else {
2288                 int mdir;
2289                 if (this_->tracking && this_->tracking_flag) {
2290                         mdir = tracking_get_angle(this_->tracking) - this_->orientation;
2291                 } else {
2292                         mdir=nv->dir-this_->orientation;
2293                 }
2294
2295                 p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
2296                 p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
2297                 if (dir)
2298                         *dir=this_->orientation;
2299         }
2300         return 1;
2301 }
2302
2303 void
2304 navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
2305 {
2306         int dir;
2307         struct point pn;
2308         struct navit_vehicle *nv=this_->vehicle;
2309         navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
2310         transform_set_yaw(this_->trans, dir);
2311         navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
2312         if (autozoom)
2313                 navit_autozoom(this_, &nv->coord, nv->speed, 0);
2314 }
2315
2316 static void
2317 navit_set_center_cursor_draw(struct navit *this_)
2318 {
2319         navit_set_center_cursor(this_,1,0);
2320         if (this_->ready == 3)
2321                 navit_draw_async(this_, 1);
2322 }
2323
2324 static void
2325 navit_cmd_set_center_cursor(struct navit *this_)
2326 {
2327         navit_set_center_cursor_draw(this_);
2328 }
2329
2330 void
2331 navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
2332 {
2333         struct coord c;
2334         struct pcoord pc;
2335         transform_reverse(this_->trans, p, &c);
2336         pc.x = c.x;
2337         pc.y = c.y;
2338         pc.pro = transform_get_projection(this_->trans);
2339         navit_set_center(this_, &pc, set_timeout);
2340 }
2341
2342 static int
2343 navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
2344 {
2345         int dir=0, orient_old=0, attr_updated=0;
2346         struct coord co;
2347         long zoom;
2348         GList *l;
2349         struct navit_vehicle *nv;
2350         struct layout *lay;
2351         struct attr active;
2352         active.type=attr_active;
2353         active.u.num=0;
2354
2355         switch (attr->type) {
2356         case attr_autozoom:
2357                 attr_updated=(this_->autozoom_secs != attr->u.num);
2358                 this_->autozoom_secs = attr->u.num;
2359                 break;
2360         case attr_autozoom_active:
2361                 attr_updated=(this_->autozoom_active != attr->u.num);
2362                 this_->autozoom_active = attr->u.num;
2363                 break;
2364         case attr_center:
2365                 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
2366                 dbg(1,"0x%x,0x%x\n",co.x,co.y);
2367                 transform_set_center(this_->trans, &co);
2368                 break;
2369         case attr_drag_bitmap:
2370                 attr_updated=(this_->drag_bitmap != !!attr->u.num);
2371                 this_->drag_bitmap=!!attr->u.num;
2372                 break;
2373         case attr_flags:
2374                 attr_updated=(this_->flags != attr->u.num);
2375                 this_->flags=attr->u.num;
2376                 break;
2377         case attr_flags_graphics:
2378                 attr_updated=(this_->graphics_flags != attr->u.num);
2379                 this_->graphics_flags=attr->u.num;
2380                 break;
2381         case attr_follow:
2382                 if (!this_->vehicle)
2383                         return 0;
2384                 attr_updated=(this_->vehicle->follow_curr != attr->u.num);
2385                 this_->vehicle->follow_curr = attr->u.num;
2386                 break;
2387         case attr_layout:
2388                 if(this_->layout_current!=attr->u.layout) {
2389                         this_->layout_current=attr->u.layout;
2390                         graphics_font_destroy_all(this_->gra);
2391                         navit_set_cursors(this_);
2392                         if (this_->ready == 3)
2393                                 navit_draw(this_);
2394                         attr_updated=1;
2395                 }
2396                 break;
2397         case attr_layout_name:
2398                 l=this_->layouts;
2399                 while (l) {
2400                         lay=l->data;
2401                         if (!strcmp(lay->name,attr->u.str)) {
2402                                 struct attr attr;
2403                                 attr.type=attr_layout;
2404                                 attr.u.layout=lay;
2405                                 return navit_set_attr_do(this_, &attr, init);
2406                         }
2407                         l=g_list_next(l);
2408                 }               
2409                 return 0;
2410         case attr_map_border:
2411                 if (this_->border != attr->u.num) {
2412                         this_->border=attr->u.num;
2413                         attr_updated=1;
2414                 }
2415                 break;
2416         case attr_orientation:
2417                 orient_old=this_->orientation;
2418                 this_->orientation=attr->u.num;
2419                 if (!init) {
2420                         if (this_->orientation != -1) {
2421                                 dir = this_->orientation;
2422                         } else {
2423                                 if (this_->vehicle) {
2424                                         dir = this_->vehicle->dir;
2425                                 }
2426                         }
2427                         transform_set_yaw(this_->trans, dir);
2428                         if (orient_old != this_->orientation) {
2429 #if 0
2430                                 if (this_->ready == 3)
2431                                         navit_draw(this_);
2432 #endif
2433                                 attr_updated=1;
2434                         }
2435                 }
2436                 break;
2437         case attr_osd_configuration:
2438                 dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
2439                 attr_updated=(this_->osd_configuration != attr->u.num);
2440                 this_->osd_configuration=attr->u.num;
2441                 break;
2442         case attr_pitch:
2443                 attr_updated=(this_->pitch != attr->u.num);
2444                 this_->pitch=attr->u.num;
2445                 transform_set_pitch(this_->trans, this_->pitch);
2446                 if (!init && attr_updated && this_->ready == 3)
2447                         navit_draw(this_);
2448                 break;
2449         case attr_projection:
2450                 if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
2451                         navit_projection_set(this_, attr->u.projection, !init);
2452                         attr_updated=1;
2453                 }
2454                 break;
2455         case attr_radius:
2456                 attr_updated=(this_->radius != attr->u.num);
2457                 this_->radius=attr->u.num;
2458                 break;
2459         case attr_recent_dest:
2460                 attr_updated=(this_->recentdest_count != attr->u.num);
2461                 this_->recentdest_count=attr->u.num;
2462                 break;
2463         case attr_speech:
2464                 if(this_->speech && this_->speech != attr->u.speech) {
2465                         attr_updated=1;
2466                         this_->speech = attr->u.speech;
2467                 }
2468                 break;
2469         case attr_timeout:
2470                 attr_updated=(this_->center_timeout != attr->u.num);
2471                 this_->center_timeout = attr->u.num;
2472                 break;
2473         case attr_tracking:
2474                 attr_updated=(this_->tracking_flag != !!attr->u.num);
2475                 this_->tracking_flag=!!attr->u.num;
2476                 break;
2477         case attr_transformation:
2478                 this_->trans=attr->u.transformation;
2479                 break;
2480         case attr_use_mousewheel:
2481                 attr_updated=(this_->use_mousewheel != !!attr->u.num);
2482                 this_->use_mousewheel=!!attr->u.num;
2483                 break;
2484         case attr_vehicle:
2485                 l=this_->vehicles;
2486                 while(l) {
2487                         nv=l->data;
2488                         if (nv->vehicle == attr->u.vehicle) {
2489                                 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
2490                                         if (this_->vehicle)
2491                                                 vehicle_set_attr(this_->vehicle->vehicle, &active);
2492                                         active.u.num=1;
2493                                         vehicle_set_attr(nv->vehicle, &active);
2494                                         attr_updated=1;
2495                                 }
2496                                 navit_set_vehicle(this_, nv);
2497                         }
2498                         l=g_list_next(l);
2499                 }
2500                 break;
2501         case attr_zoom:
2502                 zoom=transform_get_scale(this_->trans);
2503                 attr_updated=(zoom != attr->u.num);
2504                 transform_set_scale(this_->trans, attr->u.num);
2505                 if (attr_updated && !init) 
2506                         navit_draw(this_);
2507                 break;
2508         case attr_zoom_min:
2509                 attr_updated=(attr->u.num != this_->zoom_min);
2510                 this_->zoom_min=attr->u.num;
2511                 break;
2512         case attr_zoom_max:
2513                 attr_updated=(attr->u.num != this_->zoom_max);
2514                 this_->zoom_max=attr->u.num;
2515                 break;
2516         case attr_message:
2517                 navit_add_message(this_, attr->u.str);
2518                 break;
2519         case attr_follow_cursor:
2520                 attr_updated=(this_->follow_cursor != !!attr->u.num);
2521                 this_->follow_cursor=!!attr->u.num;
2522                 break;
2523         case attr_imperial:
2524                 attr_updated=(this_->imperial != attr->u.num);
2525                 this_->imperial=attr->u.num;
2526                 break;
2527         case attr_waypoints_flag:
2528                 attr_updated=(this_->waypoints_flag != !!attr->u.num);
2529                 this_->waypoints_flag=!!attr->u.num;
2530                 break;
2531         default:
2532                 return 0;
2533         }
2534         if (attr_updated && !init) {
2535                 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
2536                 if (attr->type == attr_osd_configuration)
2537                         graphics_draw_mode(this_->gra, draw_mode_end);
2538         }
2539         return 1;
2540 }
2541
2542 int
2543 navit_set_attr(struct navit *this_, struct attr *attr)
2544 {
2545         return navit_set_attr_do(this_, attr, 0);
2546 }
2547
2548 int
2549 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
2550 {
2551         struct message *msg;
2552         int len,offset;
2553         int ret=1;
2554
2555         switch (type) {
2556         case attr_message:
2557                 msg = navit_get_messages(this_);
2558                 
2559                 if (!msg) {
2560                         return 0;
2561                 }
2562
2563                 len = 0;
2564                 while (msg) {
2565                         len += strlen(msg->text) + 1;
2566                         msg = msg->next;
2567                 }
2568                 attr->u.str = g_malloc(len + 1);
2569                 
2570                 msg = navit_get_messages(this_);
2571                 offset = 0;
2572                 while (msg) {
2573                         g_stpcpy((attr->u.str + offset), msg->text);
2574                         offset += strlen(msg->text);
2575                         attr->u.str[offset] = '\n';
2576                         offset++;
2577
2578                         msg = msg->next;
2579                 }
2580
2581                 attr->u.str[len] = '\0';
2582                 break;
2583         case attr_imperial: 
2584                 attr->u.num=this_->imperial; 
2585                 break; 
2586         case attr_bookmark_map:
2587                 attr->u.map=bookmarks_get_map(this_->bookmarks);
2588                 break;
2589         case attr_bookmarks:
2590                 attr->u.bookmarks=this_->bookmarks;
2591                 break;
2592         case attr_callback_list:
2593                 attr->u.callback_list=this_->attr_cbl;
2594                 break;
2595         case attr_destination:
2596                 if (! this_->destination_valid)
2597                         return 0;
2598                 attr->u.pcoord=&this_->destination;
2599                 break;
2600         case attr_displaylist:
2601                 attr->u.displaylist=this_->displaylist;
2602                 return (attr->u.displaylist != NULL);
2603         case attr_follow:
2604                 if (!this_->vehicle)
2605                         return 0;
2606                 attr->u.num=this_->vehicle->follow_curr;
2607                 break;
2608         case attr_former_destination_map:
2609                 attr->u.map=this_->former_destination;
2610                 break;
2611         case attr_graphics:
2612                 attr->u.graphics=this_->gra;
2613                 ret=(attr->u.graphics != NULL);
2614                 break;
2615         case attr_gui:
2616                 attr->u.gui=this_->gui;
2617                 ret=(attr->u.gui != NULL);
2618                 break;
2619         case attr_layout:
2620                 if (iter) {
2621                         if (iter->u.list) {
2622                                 iter->u.list=g_list_next(iter->u.list);
2623                         } else { 
2624                                 iter->u.list=this_->layouts;
2625                         }
2626                         if (!iter->u.list)
2627                                 return 0;
2628                         attr->u.layout=(struct layout *)iter->u.list->data;
2629                 } else {
2630                         attr->u.layout=this_->layout_current;
2631                 }
2632                 break;
2633         case attr_map:
2634                 if (iter && this_->mapsets) {
2635                         if (!iter->u.mapset_handle) {
2636                                 iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
2637                         }
2638                         attr->u.map=mapset_next(iter->u.mapset_handle, 0);
2639                         if(!attr->u.map) {
2640                                 mapset_close(iter->u.mapset_handle);
2641                                 return 0;
2642                         }
2643                 } else {
2644                         return 0;
2645                 }
2646                 break;
2647         case attr_mapset:
2648                 attr->u.mapset=this_->mapsets->data;
2649                 ret=(attr->u.mapset != NULL);
2650                 break;
2651         case attr_navigation:
2652                 attr->u.navigation=this_->navigation;
2653                 break;
2654         case attr_orientation:
2655                 attr->u.num=this_->orientation;
2656                 break;
2657         case attr_osd:
2658                 ret=attr_generic_get_attr(this_->attr_list, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
2659                 break;
2660         case attr_osd_configuration:
2661                 attr->u.num=this_->osd_configuration;
2662                 break;
2663         case attr_pitch:
2664                 attr->u.num=transform_get_pitch(this_->trans);
2665                 break;
2666         case attr_projection:
2667                 if(this_->trans) {
2668                         attr->u.num=transform_get_projection(this_->trans);
2669                 } else {
2670                         return 0;
2671                 }
2672                 break;
2673         case attr_route:
2674                 attr->u.route=this_->route;
2675                 break;
2676         case attr_speech:
2677                 attr->u.speech=this_->speech;
2678                 break;
2679         case attr_tracking:
2680                 attr->u.num=this_->tracking_flag;
2681                 break;
2682         case attr_trackingo:
2683                 attr->u.tracking=this_->tracking;
2684                 break;
2685         case attr_transformation:
2686                 attr->u.transformation=this_->trans;
2687                 break;
2688         case attr_vehicle:
2689                 if(iter) {
2690                         if(iter->u.list) {
2691                                 iter->u.list=g_list_next(iter->u.list);
2692                         } else { 
2693                                 iter->u.list=this_->vehicles;
2694                         }
2695                         if(!iter->u.list)
2696                                 return 0;
2697                         attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
2698                 } else {
2699                         if(this_->vehicle) {
2700                                 attr->u.vehicle=this_->vehicle->vehicle;
2701                         } else {
2702                                 return 0;
2703                         }
2704                 }
2705                 break;
2706         case attr_vehicleprofile:
2707                 attr->u.vehicleprofile=this_->vehicleprofile;
2708                 break;
2709         case attr_zoom:
2710                 attr->u.num=transform_get_scale(this_->trans);
2711                 break;
2712         case attr_autozoom_active:
2713                 attr->u.num=this_->autozoom_active;
2714                 break;
2715         case attr_follow_cursor:
2716                 attr->u.num=this_->follow_cursor;
2717                 break;
2718         case attr_waypoints_flag:
2719                 attr->u.num=this_->waypoints_flag;
2720                 break;
2721         default:
2722                 return 0;
2723         }
2724         attr->type=type;
2725         return ret;
2726 }
2727
2728 static int
2729 navit_add_log(struct navit *this_, struct log *log)
2730 {
2731         struct attr type_attr;
2732         if (!log_get_attr(log, attr_type, &type_attr, NULL))
2733                 return 0;
2734         if (!strcmp(type_attr.u.str, "textfile_debug")) {
2735                 char *header = "type=track_tracked\n";
2736                 if (this_->textfile_debug_log)
2737                         return 0;
2738                 log_set_header(log, header, strlen(header));
2739                 this_->textfile_debug_log=log;
2740                 return 1;
2741         }
2742         return 0;
2743 }
2744
2745 static int
2746 navit_add_layout(struct navit *this_, struct layout *layout)
2747 {
2748         struct attr active;
2749         this_->layouts = g_list_append(this_->layouts, layout);
2750         layout_get_attr(layout, attr_active, &active, NULL);
2751         if(active.u.num || !this_->layout_current) { 
2752                 this_->layout_current=layout;
2753                 return 1;
2754         }
2755         return 0;
2756 }
2757
2758 int
2759 navit_add_attr(struct navit *this_, struct attr *attr)
2760 {
2761         int ret=1;
2762         switch (attr->type) {
2763         case attr_callback:
2764                 navit_add_callback(this_, attr->u.callback);
2765                 break;
2766         case attr_log:
2767                 ret=navit_add_log(this_, attr->u.log);
2768                 break;
2769         case attr_gui:
2770                 ret=navit_set_gui(this_, attr->u.gui);
2771                 break;
2772         case attr_graphics:
2773                 ret=navit_set_graphics(this_, attr->u.graphics);
2774                 break;
2775         case attr_layout:
2776                 ret=navit_add_layout(this_, attr->u.layout);
2777                 break;
2778         case attr_route:
2779                 this_->route=attr->u.route;
2780                 break;
2781         case attr_mapset:
2782                 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
2783                 break;
2784         case attr_navigation:
2785                 this_->navigation=attr->u.navigation;
2786                 break;
2787         case attr_osd:
2788                 this_->attr_list=attr_generic_add_attr(this_->attr_list, attr);
2789                 break;
2790         case attr_recent_dest:
2791                 this_->recentdest_count = attr->u.num;
2792                 break;
2793         case attr_speech:
2794                 this_->speech=attr->u.speech;
2795                 break;
2796         case attr_trackingo:
2797                 this_->tracking=attr->u.tracking;
2798                 break;
2799         case attr_vehicle:
2800                 ret=navit_add_vehicle(this_, attr->u.vehicle);
2801                 break;
2802         case attr_vehicleprofile:
2803                 this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
2804                 break;
2805         case attr_autozoom_min:
2806                 this_->autozoom_min = attr->u.num;
2807                 break;
2808         default:
2809                 return 0;
2810         }
2811         if (ret)
2812                 this_->attrs=attr_generic_add_attr(this_->attrs, attr);
2813         callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
2814         return ret;
2815 }
2816
2817 int
2818 navit_remove_attr(struct navit *this_, struct attr *attr)
2819 {
2820         int ret=1;
2821         switch (attr->type) {
2822         case attr_callback:
2823                 navit_remove_callback(this_, attr->u.callback);
2824                 break;
2825         case attr_vehicle:
2826                 this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
2827                 return 1;
2828         default:
2829                 return 0;
2830         }
2831         return ret;
2832 }
2833
2834 struct attr_iter *
2835 navit_attr_iter_new(void)
2836 {
2837         return g_new0(struct attr_iter, 1);
2838 }
2839
2840 void
2841 navit_attr_iter_destroy(struct attr_iter *iter)
2842 {
2843         g_free(iter);
2844 }
2845
2846 void
2847 navit_add_callback(struct navit *this_, struct callback *cb)
2848 {
2849         callback_list_add(this_->attr_cbl, cb);
2850 }
2851
2852 void
2853 navit_remove_callback(struct navit *this_, struct callback *cb)
2854 {
2855         callback_list_remove(this_->attr_cbl, cb);
2856 }
2857
2858 /**
2859  * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
2860  *
2861  * @param navit The navit instance
2862  * @returns nothing
2863  */
2864
2865 static void
2866 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
2867 {
2868         struct point cursor_pnt;
2869         enum projection pro;
2870
2871         if (this_->blocked)
2872                 return;
2873         if (pnt)
2874                 cursor_pnt=*pnt;
2875         else {
2876                 pro=transform_get_projection(this_->trans_cursor);
2877                 if (!pro)
2878                         return;
2879                 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2880         }
2881         vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans_cursor), nv->speed);
2882 #if 0   
2883         if (pnt)
2884                 pnt2=*pnt;
2885         else {
2886                 pro=transform_get_projection(this_->trans);
2887                 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
2888         }
2889 #if 1
2890         cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
2891 #else
2892         cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
2893 #endif
2894 #endif
2895 }
2896
2897 static void
2898 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
2899 {
2900         struct attr attr_valid, attr_dir, attr_speed, attr_pos;
2901         struct pcoord cursor_pc;
2902         struct point cursor_pnt, *pnt=&cursor_pnt;
2903         struct tracking *tracking=NULL;
2904         struct pcoord pc[16];
2905         enum projection pro=transform_get_projection(this_->trans_cursor);
2906         int count;
2907         int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
2908         void *attr_object;
2909         char *destination_file;
2910         char *description;
2911
2912         profile(0,NULL);
2913         if (this_->ready == 3)
2914                 navit_layout_switch(this_);
2915         if (this_->vehicle == nv && this_->tracking_flag)
2916                 tracking=this_->tracking;
2917         if (tracking) {
2918                 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
2919                 attr_object=tracking;
2920                 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
2921         } else {
2922                 attr_object=nv->vehicle;
2923                 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
2924         }
2925         if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
2926                 if (!attr_valid.u.num != attr_position_valid_invalid)
2927                         return;
2928         if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
2929             ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
2930             ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
2931                 profile(0,"return 2\n");
2932                 return;
2933         }
2934         nv->dir=*attr_dir.u.numd;
2935         nv->speed=*attr_speed.u.numd;
2936         transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
2937         if (nv != this_->vehicle) {
2938                 if (this_->ready == 3)
2939                         navit_vehicle_draw(this_, nv, NULL);
2940                 profile(0,"return 3\n");
2941                 return;
2942         }
2943         cursor_pc.x = nv->coord.x;
2944         cursor_pc.y = nv->coord.y;
2945         cursor_pc.pro = pro;
2946         if (this_->route) {
2947                 if (tracking)
2948                         route_set_position_from_tracking(this_->route, tracking, pro);
2949                 else
2950                         route_set_position(this_->route, &cursor_pc);
2951         }
2952         callback_list_call_attr_0(this_->attr_cbl, attr_position);
2953         navit_textfile_debug_log(this_, "type=trackpoint_tracked");
2954         if (this_->ready == 3) {
2955                 if (this_->gui && nv->speed > 2)
2956                         navit_disable_suspend();
2957
2958                 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2959                 if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow && 
2960                         (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border)))
2961                         navit_set_center_cursor_draw(this_);
2962                 else
2963                         navit_vehicle_draw(this_, nv, pnt);
2964
2965                 if (nv->follow_curr > 1)
2966                         nv->follow_curr--;
2967                 else
2968                         nv->follow_curr=nv->follow;
2969         }
2970         callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
2971
2972         /* Finally, if we reached our destination, stop navigation. */
2973         if (this_->route) {
2974                 switch(route_destination_reached(this_->route)) {
2975                 case 1:
2976                         description=route_get_destination_description(this_->route, 0);
2977                         route_remove_waypoint(this_->route);
2978                         count=route_get_destinations(this_->route, pc, 16);
2979                         destination_file = bookmarks_get_destination_file(TRUE);
2980                         bookmarks_append_coord(this_->former_destination, destination_file, pc, type_former_itinerary_part, description, this_->recentdest_count);
2981                         g_free(description);
2982                         break;  
2983                 case 2:
2984                         description=route_get_destination_description(this_->route, 0);
2985                         count=route_get_destinations(this_->route, pc, 1);
2986                         destination_file = bookmarks_get_destination_file(TRUE);
2987                         bookmarks_append_coord(this_->former_destination, destination_file, pc, type_former_itinerary_part, description, this_->recentdest_count);
2988                         g_free(description);
2989                         navit_set_destination(this_, NULL, NULL, 0);
2990                         break;
2991                 }
2992         }
2993         profile(0,"return 5\n");
2994 }
2995
2996 /**
2997  * Set the position of the vehicle
2998  *
2999  * @param navit The navit instance
3000  * @param c The coordinate to set as position
3001  * @returns nothing
3002  */
3003
3004 void
3005 navit_set_position(struct navit *this_, struct pcoord *c)
3006 {
3007         if (this_->route) {
3008                 route_set_position(this_->route, c);
3009                 callback_list_call_attr_0(this_->attr_cbl, attr_position);
3010         }
3011         if (this_->ready == 3)
3012                 navit_draw(this_);
3013 }
3014
3015 static int
3016 navit_set_vehicleprofile(struct navit *this_, char *name)
3017 {
3018         struct attr attr;
3019         GList *l;
3020         l=this_->vehicleprofiles;
3021         while (l) {
3022                 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
3023                         if (!strcmp(attr.u.str, name)) {
3024                                 this_->vehicleprofile=l->data;
3025                                 if (this_->route)
3026                                         route_set_profile(this_->route, this_->vehicleprofile);
3027                                 return 1;
3028                         }
3029                 }
3030                 l=g_list_next(l);
3031         }
3032         return 0;
3033 }
3034
3035 static void
3036 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
3037 {
3038         struct attr attr;
3039         this_->vehicle=nv;
3040         if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
3041                 if (navit_set_vehicleprofile(this_, attr.u.str))
3042                         return;
3043         }
3044         if (!navit_set_vehicleprofile(this_,"car")) {
3045                 /* We do not have a fallback "car" profile
3046                 * so lets set any profile */
3047                 GList *l;
3048                 l=this_->vehicleprofiles;
3049                 if (l) {
3050                     this_->vehicleprofile=l->data;
3051                     if (this_->route)
3052                         route_set_profile(this_->route, this_->vehicleprofile);
3053                 }
3054         }
3055 }
3056
3057 /**
3058  * Register a new vehicle
3059  *
3060  * @param navit The navit instance
3061  * @param v The vehicle instance
3062  * @returns 1 for success
3063  */
3064 static int
3065 navit_add_vehicle(struct navit *this_, struct vehicle *v)
3066 {
3067         struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
3068         struct attr follow, active, animate;
3069         nv->vehicle=v;
3070         nv->follow=0;
3071         nv->last.x = 0;
3072         nv->last.y = 0;
3073         nv->animate_cursor=0;
3074         if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
3075                 nv->follow=follow.u.num;
3076         nv->follow_curr=nv->follow;
3077         this_->vehicles=g_list_append(this_->vehicles, nv);
3078         if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
3079                 navit_set_vehicle(this_, nv);
3080         if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
3081                 nv->animate_cursor=animate.u.num;
3082         nv->callback.type=attr_callback;
3083         nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
3084         vehicle_add_attr(nv->vehicle, &nv->callback);
3085         vehicle_set_attr(nv->vehicle, &this_->self);
3086         return 1;
3087 }
3088
3089
3090
3091
3092 struct gui *
3093 navit_get_gui(struct navit *this_)
3094 {
3095         return this_->gui;
3096 }
3097
3098 struct transformation *
3099 navit_get_trans(struct navit *this_)
3100 {
3101         return this_->trans;
3102 }
3103
3104 struct route *
3105 navit_get_route(struct navit *this_)
3106 {
3107         return this_->route;
3108 }
3109
3110 struct navigation *
3111 navit_get_navigation(struct navit *this_)
3112 {
3113         return this_->navigation;
3114 }
3115
3116 struct displaylist *
3117 navit_get_displaylist(struct navit *this_)
3118 {
3119         return this_->displaylist;
3120 }
3121
3122 void
3123 navit_layout_switch(struct navit *n) 
3124 {
3125
3126     int currTs=0;
3127     struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
3128     double trise,tset,trise_actual;
3129     struct layout *l;
3130     int year, month, day;
3131     
3132     if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
3133         return; //No layout - nothing to switch
3134     }
3135     if (!n->vehicle)
3136         return;
3137     l=layout_attr.u.layout;
3138     
3139     if (l->dayname || l->nightname) {
3140         //Ok, we know that we have profile to switch
3141         
3142         //Check that we aren't calculating too fast
3143         if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
3144                 currTs=iso8601_to_secs(iso8601_attr.u.str);
3145                 dbg(1,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60);
3146         }
3147         if (currTs-(n->prevTs)<60) {
3148             //We've have to wait a little
3149             return;
3150         }
3151         if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
3152                 return;
3153         if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
3154                 return; //No valid fix yet
3155         }
3156         if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
3157                 //No position - no sun
3158                 return;
3159         }
3160         
3161         //We calculate sunrise anyway, cause it is needed both for day and for night
3162         if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
3163                 //near the pole sun never rises/sets, so we should never switch profiles
3164                 dbg(1,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise));
3165                 n->prevTs=currTs;
3166                 return;
3167             }
3168         
3169         trise_actual=trise;
3170         dbg(1,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
3171         if (l->dayname) {
3172         
3173             if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) || 
3174                     (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
3175                 //The sun is rising now!
3176                 if (strcmp(l->name,l->dayname)) {
3177                     navit_set_layout_by_name(n,l->dayname);
3178                 }
3179             }
3180         }
3181         if (l->nightname) {
3182             if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
3183                 //near the pole sun never rises/sets, so we should never switch profiles
3184                 dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset));
3185                 n->prevTs=currTs;
3186                 return;
3187             }
3188             dbg(1,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
3189             if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
3190                 || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) || 
3191                         ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
3192                 //Time to sleep
3193                 if (strcmp(l->name,l->nightname)) {
3194                     navit_set_layout_by_name(n,l->nightname);
3195                 }
3196             }   
3197         }
3198         
3199         n->prevTs=currTs;
3200     }
3201 }
3202
3203 int 
3204 navit_set_vehicle_by_name(struct navit *n,const char *name) 
3205 {
3206     struct vehicle *v;
3207     struct attr_iter *iter;
3208     struct attr vehicle_attr, name_attr;
3209
3210         iter=navit_attr_iter_new();
3211
3212     while (navit_get_attr(n,attr_vehicle,&vehicle_attr,iter)) {
3213                 v=vehicle_attr.u.vehicle;
3214                 vehicle_get_attr(v,attr_name,&name_attr,NULL);
3215                 if (name_attr.type==attr_name) {
3216                         if (!strcmp(name,name_attr.u.str)) {
3217                                 navit_set_attr(n,&vehicle_attr);                                
3218                                 navit_attr_iter_destroy(iter);
3219                                 return 1;
3220                         }
3221                 }
3222         }
3223     navit_attr_iter_destroy(iter);
3224     return 0;
3225 }
3226
3227 int 
3228 navit_set_layout_by_name(struct navit *n,const char *name) 
3229 {
3230     struct layout *l;
3231     struct attr_iter iter;
3232     struct attr layout_attr;
3233
3234     iter.u.list=0x00;
3235
3236     if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
3237         return 0; //No layouts - nothing to do
3238     }
3239     if (iter.u.list==NULL) {
3240         return 0;
3241     }
3242     
3243     iter.u.list=g_list_first(iter.u.list);
3244     
3245     while(iter.u.list) {
3246         l=(struct layout*)iter.u.list->data;
3247         if (!strcmp(name,l->name)) {
3248             layout_attr.u.layout=l;
3249             layout_attr.type=attr_layout;
3250             navit_set_attr(n,&layout_attr);
3251             iter.u.list=g_list_first(iter.u.list);
3252             return 1;
3253         }
3254         iter.u.list=g_list_next(iter.u.list);
3255     }
3256
3257     iter.u.list=g_list_first(iter.u.list);
3258     return 0;
3259 }
3260
3261 void
3262 navit_disable_suspend() {
3263         gui_disable_suspend(global_navit->gui);
3264         callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend);
3265 }
3266
3267 int
3268 navit_block(struct navit *this_, int block)
3269 {
3270         if (block > 0) {
3271                 this_->blocked |= 1;
3272                 if (graphics_draw_cancel(this_->gra, this_->displaylist))
3273                         this_->blocked |= 2;
3274                 return 0;
3275         }
3276         if ((this_->blocked & 2) || block < 0) {
3277                 this_->blocked=0;
3278                 navit_draw(this_);
3279                 return 1;
3280         }
3281         this_->blocked=0;
3282         return 0;
3283 }
3284
3285 void
3286 navit_destroy(struct navit *this_)
3287 {
3288         dbg(0,"enter %p\n",this_);
3289         graphics_draw_cancel(this_->gra, this_->displaylist);
3290         callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
3291         attr_list_free(this_->attrs);
3292         if (this_->bookmarks) {
3293                 char *center_file = bookmarks_get_center_file(TRUE);
3294                 bookmarks_write_center_to_file(this_->bookmarks, center_file);
3295                 g_free(center_file);
3296                 bookmarks_destroy(this_->bookmarks);
3297         }
3298
3299         callback_destroy(this_->nav_speech_cb);
3300         callback_destroy(this_->roadbook_callback);
3301         callback_destroy(this_->popup_callback);
3302         callback_destroy(this_->motion_timeout_callback);
3303         callback_destroy(this_->progress_cb);
3304
3305         if(this_->gra) {
3306           graphics_remove_callback(this_->gra, this_->resize_callback);
3307           graphics_remove_callback(this_->gra, this_->button_callback);
3308           graphics_remove_callback(this_->gra, this_->motion_callback);
3309           graphics_remove_callback(this_->gra, this_->predraw_callback);
3310         }
3311
3312         callback_destroy(this_->resize_callback);
3313         callback_destroy(this_->motion_callback);
3314         callback_destroy(this_->predraw_callback);
3315
3316         callback_destroy(this_->route_cb);
3317         if (this_->route)
3318                 route_destroy(this_->route);
3319
3320         map_destroy(this_->former_destination);
3321
3322         graphics_displaylist_destroy(this_->displaylist);
3323
3324         graphics_free(this_->gra);
3325
3326         g_free(this_);
3327 }
3328
3329 struct navit *
3330 navit_ref(struct navit *this_)
3331 {
3332         this_->refcount++;
3333         dbg(0,"refcount %d\n",this_->refcount);
3334         return this_;
3335 }
3336
3337 void
3338 navit_unref(struct navit *this_)
3339 {
3340         this_->refcount--;
3341         dbg(0,"refcount %d\n",this_->refcount);
3342         if (this_->refcount <= 0)
3343                 navit_destroy(this_);
3344 }
3345
3346 struct object_func navit_func = {
3347         attr_navit,
3348         (object_func_new)navit_new,
3349         (object_func_get_attr)navit_get_attr,
3350         (object_func_iter_new)navit_attr_iter_new,
3351         (object_func_iter_destroy)navit_attr_iter_destroy,
3352         (object_func_set_attr)navit_set_attr,
3353         (object_func_add_attr)navit_add_attr,
3354         (object_func_remove_attr)navit_remove_attr,
3355         (object_func_init)navit_init,
3356         (object_func_destroy)navit_destroy,
3357         (object_func_dup)NULL,
3358         (object_func_ref)navit_ref,
3359         (object_func_unref)navit_unref,
3360 };
3361
3362 /** @} */