Core:Fix:Cleanup and reorganisation of gui_gtk centric code.
authorhorwitz <horwitz@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 17 Mar 2008 23:46:41 +0000 (23:46 +0000)
committerhorwitz <horwitz@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 17 Mar 2008 23:46:41 +0000 (23:46 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@946 ffa7fe5e-494d-0410-b361-a75ebd5db220

19 files changed:
navit/src/Makefile.am
navit/src/attr.h
navit/src/attr_def.h
navit/src/cursor.c
navit/src/gui.c
navit/src/gui.h
navit/src/gui/gtk/gui_gtk.h
navit/src/gui/gtk/gui_gtk_action.c
navit/src/gui/gtk/gui_gtk_statusbar.c
navit/src/gui/gtk/gui_gtk_window.c
navit/src/gui/sdl/gui_sdl.h
navit/src/gui/sdl/gui_sdl_window.cpp
navit/src/navit.c
navit/src/navit.h
navit/src/navit.xml
navit/src/osd/core/osd_core.c
navit/src/projection.h
navit/src/vehicle.c
navit/src/vehicle.h

index 70770d6..43148dc 100644 (file)
@@ -16,12 +16,12 @@ EXTRA_DIST = navit.xml
 navit_SOURCES = attr.c callback.c compass.c coord.c country.c cursor.c data_window.c debug.c \
        file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
        mapset.c maptype.c menu.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
-       profile.c route.c search.c speech.c transform.c track.c \
+       profile.c projection.c route.c search.c speech.c transform.c track.c \
        util.c vehicle.c xmlconfig.c attr.h attr_def.h callback.h color.h compass.h coord.h country.h \
        cursor.h data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h \
        file.h graphics.h gtkext.h gui.h item.h item_def.h log.h layer.h layout.h main.h map-share.h map.h\
        map_data.h mapset.h maptype.h menu.h navigation.h navit.h osd.h \
-       param.h phrase.h plugin.h point.h plugin_def.h projection.h popup.h route.h profile.h search.h speech.h statusbar.h \
+       param.h phrase.h plugin.h point.h plugin_def.h projection.h popup.h route.h profile.h search.h speech.h \
        transform.h track.h util.h vehicle.h xmlconfig.h
 
 osm2navit_SOURCES = osm2navit.c item.c debug.c zipfile.h
index 55f1bbf..58147b2 100644 (file)
@@ -7,6 +7,8 @@ extern "C" {
 #ifndef ATTR_H
 #define ATTR_H
 
+#include "projection.h"
+
 enum item_type;
 
 enum attr_type {
@@ -31,11 +33,15 @@ struct attr {
                int num;
                struct item *item;
                enum item_type item_type;
+               enum projection projection;
                double * numd;
                struct color *color;
                struct coord_geo *coord_geo;
                struct navit *navit;
                struct callback *callback;
+               struct vehicle *vehicle;
+               struct layout *layout;
+               struct map *map;
                struct log *log;
                struct route *route;
                struct navigation *navigation;
index 79cd760..d905aef 100644 (file)
@@ -37,6 +37,7 @@ ATTR(interval)
 ATTR(position_qual)
 ATTR(zoom)
 ATTR(retry_interval)
+ATTR(projection)
 ATTR2(0x00028000,type_boolean_begin)
 /* boolean */
 ATTR(overwrite)
@@ -114,6 +115,8 @@ ATTR(log)
 ATTR(callback)
 ATTR(route)
 ATTR(navigation)
+ATTR(vehicle)
+ATTR(map)
 ATTR2(0x0008ffff,type_object_end)
 ATTR2(0x00090000,type_coord_begin)
 ATTR2(0x0009ffff,type_coord_end)
index ff2d4b5..485754e 100644 (file)
@@ -11,8 +11,6 @@
 #include "projection.h"
 #include "point.h"
 #include "graphics.h"
-#include "statusbar.h"
-#include "menu.h"
 #include "vehicle.h"
 #include "navit.h"
 #include "callback.h"
index afc1e24..5c4c80c 100644 (file)
@@ -1,7 +1,6 @@
 #include <glib.h>
 #include "debug.h"
 #include "gui.h"
-#include "statusbar.h"
 #include "menu.h"
 #include "data_window.h"
 #include "plugin.h"
@@ -21,21 +20,6 @@ gui_new(struct navit *nav, const char *type, struct attr **attrs)
        return this_;
 }
 
-struct statusbar *
-gui_statusbar_new(struct gui *gui)
-{
-       struct statusbar *this_;
-       if (! gui->meth.statusbar_new)
-               return NULL;
-       this_=g_new0(struct statusbar, 1);
-       this_->priv=gui->meth.statusbar_new(gui->priv, &this_->meth);
-       if (! this_->priv) {
-               g_free(this_);
-               return NULL;
-       }
-       return this_;
-}
-
 struct menu *
 gui_menubar_new(struct gui *gui)
 {
@@ -51,22 +35,6 @@ gui_menubar_new(struct gui *gui)
        return this_;
 }
 
-
-struct menu *
-gui_toolbar_new(struct gui *gui)
-{
-       struct menu *this_;
-       if (! gui->meth.toolbar_new)
-               return NULL;
-       this_=g_new0(struct menu, 1);
-       this_->priv=gui->meth.toolbar_new(gui->priv, &this_->meth);
-       if (! this_->priv) {
-               g_free(this_);
-               return NULL;
-       }
-       return this_;
-}
-
 struct menu *
 gui_popup_new(struct gui *gui)
 {
index 33167a5..c204b05 100644 (file)
@@ -4,7 +4,6 @@
 struct navit;
 struct gui_priv;
 struct menu_methods;
-struct statusbar_methods;
 struct datawindow_methods;
 struct callback;
 struct graphics;
@@ -13,8 +12,6 @@ struct pcoord;
 
 struct gui_methods {
        struct menu_priv *(*menubar_new)(struct gui_priv *priv, struct menu_methods *meth);
-       struct menu_priv *(*toolbar_new)(struct gui_priv *priv, struct menu_methods *meth);
-       struct statusbar_priv *(*statusbar_new)(struct gui_priv *priv, struct statusbar_methods *meth);
        struct menu_priv *(*popup_new)(struct gui_priv *priv, struct menu_methods *meth);
        int (*set_graphics)(struct gui_priv *priv, struct graphics *gra);
        int (*run_main_loop)(struct gui_priv *priv);
@@ -37,11 +34,8 @@ struct graphics;
 struct gui;
 struct menu;
 struct navit;
-struct statusbar;
 struct gui *gui_new(struct navit *nav, const char *type, struct attr **attrs);
-struct statusbar *gui_statusbar_new(struct gui *gui);
 struct menu *gui_menubar_new(struct gui *gui);
-struct menu *gui_toolbar_new(struct gui *gui);
 struct menu *gui_popup_new(struct gui *gui);
 struct datawindow *gui_datawindow_new(struct gui *gui, char *name, struct callback *click, struct callback *close);
 int gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description);
index 7bf8dae..ddf8e7f 100644 (file)
@@ -1,10 +1,10 @@
 #include "coord.h"
 
-struct statusbar_methods;
 struct menu_methods;
 struct datawindow_methods;
 struct navit;
 struct callback;
+struct statusbar_priv;
 
 struct gui_priv {
        struct navit *nav;
@@ -17,13 +17,20 @@ struct gui_priv {
        GtkActionGroup *base_group;
        GtkActionGroup *debug_group;
        GtkActionGroup *dyn_group;
-       GtkUIManager *menu_manager;
-        void *statusbar;
+       GtkUIManager *ui_manager;
+       GSList *layout_group;
+       GSList *projection_group;
+       GSList *vehicle_group;
+       GtkUIManager *menu_manager; // old
+        struct statusbar_priv *statusbar;
+       int menubar_enable;
+       int toolbar_enable;
+       int statusbar_enable;
        int dyn_counter;
 };
 
+void gui_gtk_ui_init(struct gui_priv *this);
 struct menu_priv *gui_gtk_menubar_new(struct gui_priv *gui, struct menu_methods *meth);
-struct menu_priv *gui_gtk_toolbar_new(struct gui_priv *gui, struct menu_methods *meth);
-struct statusbar_priv *gui_gtk_statusbar_new(struct gui_priv *gui, struct statusbar_methods *meth);
+struct statusbar_priv *gui_gtk_statusbar_new(struct gui_priv *gui);
 struct menu_priv *gui_gtk_popup_new(struct gui_priv *gui, struct menu_methods *meth);
 struct datawindow_priv *gui_gtk_datawindow_new(struct gui_priv *gui, char *name, struct callback *click, struct callback *close, struct datawindow_methods *meth);
index 183d011..3feb08c 100644 (file)
@@ -138,64 +138,22 @@ destination_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
        destination_address(gui->nav);
 }
 
-
 static void
 quit_action (GtkWidget *w, struct gui_priv *gui, void *dummy)
 {
        navit_destroy(gui->nav);
 }
 
-static void
-visible_blocks_action(GtkWidget *w, struct container *co)
-{
-#if 0
-       co->data_window[data_window_type_block]=data_window("Visible Blocks",co->win,NULL);
-       graphics_redraw(co);
-#endif
-}
-
-static void
-visible_towns_action(GtkWidget *w, struct container *co)
-{
-#if 0
-       co->data_window[data_window_type_town]=data_window("Visible Towns",co->win,NULL);
-       graphics_redraw(co);
-#endif
-}
-
-static void
-visible_polys_action(GtkWidget *w, struct container *co)
-{
-#if 0
-       co->data_window[data_window_type_street]=data_window("Visible Polys",co->win,NULL);
-       graphics_redraw(co);
-#endif
-}
-
-static void
-visible_streets_action(GtkWidget *w, struct container *co)
-{
-#if 0
-       co->data_window[data_window_type_street]=data_window("Visible Streets",co->win,NULL);
-       graphics_redraw(co);
-#endif
-}
-
-static void
-visible_points_action(GtkWidget *w, struct container *co)
-{
-#if 0
-       co->data_window[data_window_type_point]=data_window("Visible Points",co->win,NULL);
-       graphics_redraw(co);
-#endif
-}
-
 static GtkActionEntry entries[] =
 {
-       { "DisplayMenuAction", NULL, gettext_noop("Display") },
+       { "DisplayMenuAction", NULL, _n("Display") },
        { "RouteMenuAction", NULL, _n("Route") },
-       { "Map", NULL, _n("Map") },
+       { "FormerDestinationMenuAction", NULL, _n("Former Destinations") },
+       { "BookmarkMenuAction", NULL, _n("Bookmarks") },
+       { "MapMenuAction", NULL, _n("Map") },
        { "LayoutMenuAction", NULL, _n("Layout") },
+       { "ProjectionMenuAction", NULL, _n("Projection") },
+       { "VehicleMenuAction", NULL, _n("Vehicle") },
        { "ZoomOutAction", GTK_STOCK_ZOOM_OUT, _n("ZoomOut"), NULL, NULL, G_CALLBACK(zoom_out_action) },
        { "ZoomInAction", GTK_STOCK_ZOOM_IN, _n("ZoomIn"), NULL, NULL, G_CALLBACK(zoom_in_action) },
        { "RefreshAction", GTK_STOCK_REFRESH, _n("Refresh"), NULL, NULL, G_CALLBACK(refresh_action) },
@@ -230,11 +188,6 @@ static guint n_toggleentries = G_N_ELEMENTS (toggleentries);
 static GtkActionEntry debug_entries[] =
 {
        { "DataMenuAction", NULL, _n("Data") },
-       { "VisibleBlocksAction", NULL, _n("VisibleBlocks"), NULL, NULL, G_CALLBACK(visible_blocks_action) },
-       { "VisibleTownsAction", NULL, _n("VisibleTowns"), NULL, NULL, G_CALLBACK(visible_towns_action) },
-       { "VisiblePolysAction", NULL, _n("VisiblePolys"), NULL, NULL, G_CALLBACK(visible_polys_action) },
-       { "VisibleStreetsAction", NULL, _n("VisibleStreets"), NULL, NULL, G_CALLBACK(visible_streets_action) },
-       { "VisiblePointsAction", NULL, _n("VisiblePoints"), NULL, NULL, G_CALLBACK(visible_points_action) },
 };
 
 static guint n_debug_entries = G_N_ELEMENTS (debug_entries);
@@ -378,19 +331,32 @@ static char layout[] =
                                <placeholder name=\"RouteMenuAdditions\" />\
                        </menu>\
                        <menu name=\"Data\" action=\"DataMenuAction\">\
-                               <menuitem name=\"Visible Blocks\" action=\"VisibleBlocksAction\" />\
-                               <menuitem name=\"Visible Towns\" action=\"VisibleTownsAction\" />\
-                               <menuitem name=\"Visible Polys\" action=\"VisiblePolysAction\" />\
-                               <menuitem name=\"Visible Streets\" action=\"VisibleStreetsAction\" />\
-                               <menuitem name=\"Visible Points\" action=\"VisiblePointsAction\" />\
                                <placeholder name=\"DataMenuAdditions\" />\
                        </menu>\
                        <menu name=\"Route\" action=\"RouteMenuAction\">\
                                <menuitem name=\"Refresh\" action=\"RefreshAction\" />\
                                <menuitem name=\"Destination\" action=\"DestinationAction\" />\
                                <menuitem name=\"Clear\" action=\"RouteClearAction\" />\
+                               <menu name=\"FormerDestinations\" action=\"FormerDestinationMenuAction\">\
+                                       <placeholder name=\"FormerDestinationMenuAdditions\" />\
+                               </menu>\
+                               <menu name=\"Bookmarks\" action=\"BookmarkMenuAction\">\
+                                       <placeholder name=\"BookmarkMenuAdditions\" />\
+                               </menu>\
                                <placeholder name=\"RouteMenuAdditions\" />\
                        </menu>\
+                       <menu name=\"Map\" action=\"MapMenuAction\">\
+                               <menu name=\"Layout\" action=\"LayoutMenuAction\">\
+                                       <placeholder name=\"LayoutMenuAdditions\" />\
+                               </menu>\
+                               <menu name=\"Projection\" action=\"ProjectionMenuAction\">\
+                                       <placeholder name=\"ProjectionMenuAdditions\" />\
+                               </menu>\
+                               <menu name=\"Vehicle\" action=\"VehicleMenuAction\">\
+                                       <placeholder name=\"VehicleMenuAdditions\" />\
+                               </menu>\
+                               <placeholder name=\"MapMenuAdditions\" />\
+                       </menu>\
                </menubar>\
                <toolbar name=\"ToolBar\" action=\"BaseToolbar\" action=\"BaseToolbarAction\">\
                        <placeholder name=\"ToolItems\">\
@@ -442,8 +408,8 @@ add_menu(struct menu_priv *menu, struct menu_methods *meth, char *name, enum men
                if (cb)
                        ret->handler_id=g_signal_connect(ret->action, "activate", G_CALLBACK(activate), ret);
                gtk_action_group_add_action(menu->gui->dyn_group, ret->action);
-               ret->merge_id=gtk_ui_manager_new_merge_id(menu->gui->menu_manager);
-               gtk_ui_manager_add_ui( menu->gui->menu_manager, ret->merge_id, menu->path, dynname, dynname, type == menu_type_submenu ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE);
+               ret->merge_id=gtk_ui_manager_new_merge_id(menu->gui->ui_manager);
+               gtk_ui_manager_add_ui( menu->gui->ui_manager, ret->merge_id, menu->path, dynname, dynname, type == menu_type_submenu ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE);
        }
        ret->gui=menu->gui;
        ret->path=g_strdup_printf("%s/%s", menu->path, dynname);
@@ -469,7 +435,7 @@ remove_menu(struct menu_priv *item, int recursive)
                }
        }
        if (item->action) {
-               gtk_ui_manager_remove_ui(item->gui->menu_manager, item->merge_id);
+               gtk_ui_manager_remove_ui(item->gui->ui_manager, item->merge_id);
                gtk_action_group_remove_action(item->gui->dyn_group, item->action);
 #if 0
                if (item->callback)
@@ -494,9 +460,15 @@ get_toggle(struct menu_priv *menu)
 }
 
 static struct menu_methods menu_methods = {
+#if 1
        add_menu,
        set_toggle,
        get_toggle,
+#else
+       NULL,
+       NULL,
+       NULL
+#endif
 };
 
 
@@ -511,66 +483,64 @@ static void
 popup_activate(struct menu_priv *menu)
 {
 #ifdef _WIN32
-       menu->widget=gtk_ui_manager_get_widget(menu->gui->menu_manager, menu->path );
+       menu->widget=gtk_ui_manager_get_widget(menu->gui->ui_manager, menu->path );
 #endif
        gtk_menu_popup(GTK_MENU(menu->widget), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
        menu->handler_id=g_signal_connect(menu->widget, "selection-done", G_CALLBACK(popup_deactivate), menu);
 }
 
+void
+gui_gtk_ui_init(struct gui_priv *this)
+{
+       GError *error = NULL;
+       struct attr attr;
+       GtkToggleAction *toggle_action;
+
+       this->base_group = gtk_action_group_new ("BaseActions");
+       this->debug_group = gtk_action_group_new ("DebugActions");
+       this->dyn_group = gtk_action_group_new ("DynamicActions");
+       register_my_stock_icons();
+       this->ui_manager = gtk_ui_manager_new ();
+       gtk_action_group_set_translation_domain(this->base_group,"navit");
+       gtk_action_group_set_translation_domain(this->debug_group,"navit");
+       gtk_action_group_set_translation_domain(this->dyn_group,"navit");
+       gtk_action_group_add_actions (this->base_group, entries, n_entries, this);
+       gtk_action_group_add_toggle_actions (this->base_group, toggleentries, n_toggleentries, this);
+       gtk_ui_manager_insert_action_group (this->ui_manager, this->base_group, 0);
+       gtk_action_group_add_actions (this->debug_group, debug_entries, n_debug_entries, this);
+       gtk_ui_manager_insert_action_group (this->ui_manager, this->debug_group, 0);
+       gtk_ui_manager_add_ui_from_string (this->ui_manager, layout, strlen(layout), &error);
+       gtk_ui_manager_insert_action_group (this->ui_manager, this->dyn_group, 0);
+       if (error) {
+               g_message ("building menus failed: %s", error->message);
+               g_error_free (error);
+       }
+       if (navit_get_attr(this->nav, attr_cursor, &attr, NULL)) {
+               toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "CursorAction"));
+               gtk_toggle_action_set_active(toggle_action, attr.u.num);
+       }
+       if (navit_get_attr(this->nav, attr_orientation, &attr, NULL)) {
+               toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "OrientationAction"));
+               gtk_toggle_action_set_active(toggle_action, attr.u.num);
+       }
+       if (navit_get_attr(this->nav, attr_tracking, &attr, NULL)) {
+               toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
+               gtk_toggle_action_set_active(toggle_action, attr.u.num);
+       }
+}
+
 static struct menu_priv *
 gui_gtk_ui_new (struct gui_priv *this, struct menu_methods *meth, char *path, int popup, GtkWidget **widget_ret)
 {
        struct menu_priv *ret;
-       GError *error;
        GtkWidget *widget;
-       struct attr attr;
-       GtkToggleAction *toggle_action;
 
        *meth=menu_methods;
        ret=g_new0(struct menu_priv, 1);
        ret->path=g_strdup(path);
        ret->gui=this;
-       if (! this->menu_manager) {
-               this->base_group = gtk_action_group_new ("BaseActions");
-               this->debug_group = gtk_action_group_new ("DebugActions");
-               this->dyn_group = gtk_action_group_new ("DynamicActions");
-               register_my_stock_icons();
-               this->menu_manager = gtk_ui_manager_new ();
-               gtk_action_group_set_translation_domain(this->base_group,"navit");
-               gtk_action_group_set_translation_domain(this->debug_group,"navit");
-               gtk_action_group_set_translation_domain(this->dyn_group,"navit");
-               gtk_action_group_add_actions (this->base_group, entries, n_entries, this);
-               gtk_action_group_add_toggle_actions (this->base_group, toggleentries, n_toggleentries, this);
-               gtk_ui_manager_insert_action_group (this->menu_manager, this->base_group, 0);
-               gtk_action_group_add_actions (this->debug_group, debug_entries, n_debug_entries, this);
-               gtk_ui_manager_insert_action_group (this->menu_manager, this->debug_group, 0);
-               gtk_ui_manager_add_ui_from_string (this->menu_manager, layout, strlen(layout), &error);
-               gtk_ui_manager_insert_action_group (this->menu_manager, this->dyn_group, 0);
-               error=NULL;
-               if (error) {
-                       g_message ("building menus failed: %s", error->message);
-                       g_error_free (error);
-               }
-               if (navit_get_attr(this->nav, attr_cursor, &attr)) {
-                       toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "CursorAction"));
-                       gtk_toggle_action_set_active(toggle_action, attr.u.num);
-               } else {
-                       dbg(0, "Unable to locate CursorAction\n");
-               }
-               if (navit_get_attr(this->nav, attr_orientation, &attr)) {
-                       toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "OrientationAction"));
-                       gtk_toggle_action_set_active(toggle_action, attr.u.num);
-               } else {
-                       dbg(0, "Unable to locate OrientationAction\n");
-               }
-               if (navit_get_attr(this->nav, attr_tracking, &attr)) {
-                       toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
-                       gtk_toggle_action_set_active(toggle_action, attr.u.num);
-               } else {
-                       dbg(0, "Unable to locate TrackingAction\n");
-               }
-       }
-       widget=gtk_ui_manager_get_widget(this->menu_manager, path);
+
+       widget=gtk_ui_manager_get_widget(this->ui_manager, path);
        GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
        if (widget_ret)
                *widget_ret=widget;
@@ -584,17 +554,13 @@ gui_gtk_ui_new (struct gui_priv *this, struct menu_methods *meth, char *path, in
        return ret;
 }
 
-struct menu_priv *
-gui_gtk_toolbar_new(struct gui_priv *this, struct menu_methods *meth)
-{
-       return gui_gtk_ui_new(this, meth, "/ui/ToolBar", 0, NULL);
-}
-
+#if 0
 struct menu_priv *
 gui_gtk_menubar_new(struct gui_priv *this, struct menu_methods *meth)
 {
        return gui_gtk_ui_new(this, meth, "/ui/MenuBar", 0, &this->menubar);
 }
+#endif
 
 struct menu_priv *
 gui_gtk_popup_new(struct gui_priv *this, struct menu_methods *meth)
index 2c843fe..f029e08 100644 (file)
@@ -16,8 +16,6 @@
 #include "navigation.h"
 #include "gui_gtk.h"
 
-#include "statusbar.h"
-
 
 #define _(STRING) gettext(STRING)
 
@@ -107,7 +105,7 @@ statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct
                strcpy(this->route_text, buffer);
                gtk_label_set_text(GTK_LABEL(this->route), this->route_text);
        }
-       if (!vehicle_position_attr_get(v, attr_position_coord_geo, &attr))
+       if (!vehicle_get_attr(v, attr_position_coord_geo, &attr))
                return;
        lng=attr.u.coord_geo->lng;
        lat=attr.u.coord_geo->lat;
@@ -119,37 +117,31 @@ statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct
                lat=-lat;
                lat_c='S';
        }
-       if (vehicle_position_attr_get(v, attr_position_direction, &attr))
+       if (vehicle_get_attr(v, attr_position_direction, &attr))
                direction=*(attr.u.numd);
        direction=fmod(direction,360);
        if (direction < 0)
                direction+=360;
        dir_idx=(direction+22.5)/45;
        dir=dirs[dir_idx];
-       if (vehicle_position_attr_get(v, attr_position_height, &attr))
+       if (vehicle_get_attr(v, attr_position_height, &attr))
                height=*(attr.u.numd);
-       if (vehicle_position_attr_get(v, attr_position_speed, &attr))
+       if (vehicle_get_attr(v, attr_position_speed, &attr))
                speed=*(attr.u.numd);
-       if (vehicle_position_attr_get(v, attr_position_sats_used, &attr))
+       if (vehicle_get_attr(v, attr_position_sats_used, &attr))
                sats=attr.u.num;
-       if (vehicle_position_attr_get(v, attr_position_qual, &attr))
+       if (vehicle_get_attr(v, attr_position_qual, &attr))
                qual=attr.u.num;
        sprintf(this->gps_text,"GPS %2d/%1d %02.0f%07.4f%c %03.0f%07.4f%c %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, floor(lat), fmod(lat*60,60), lat_c, floor(lng), fmod(lng*60,60), lng_c, height, direction, dir, speed);
        gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
 }
 
-static struct statusbar_methods methods = {
-       statusbar_destroy,
-};
-
 struct statusbar_priv *
-gui_gtk_statusbar_new(struct gui_priv *gui, struct statusbar_methods *meth)
+gui_gtk_statusbar_new(struct gui_priv *gui)
 {
        struct statusbar_priv *this=g_new0(struct statusbar_priv, 1);
 
        this->gui=gui;
-       *meth=methods;
-
        this->hbox=gtk_hbox_new(FALSE, 1);
        this->gps=gtk_label_new( "GPS 00/0 0000.0000N 00000.0000E 0000m 000°NO 000km/h" );
        gtk_label_set_justify(GTK_LABEL(this->gps),  GTK_JUSTIFY_LEFT);
index 815d2bf..79ef206 100644 (file)
 #include "gui_gtk.h"
 #include "transform.h"
 #include "config.h"
+#include "callback.h"
+#include "layout.h"
+#include "vehicle.h"
+#include "map.h"
 
 #ifdef USE_HILDON
 #include "hildon-widgets/hildon-defines.h"
@@ -165,9 +169,11 @@ gui_gtk_add_bookmark(struct gui_priv *gui, struct pcoord *c, char *description)
 }
 
 struct gui_methods gui_gtk_methods = {
+#if 0
        gui_gtk_menubar_new,
-       gui_gtk_toolbar_new,
-       gui_gtk_statusbar_new,
+#else
+       NULL,
+#endif
        gui_gtk_popup_new,
        gui_gtk_set_graphics,
        NULL,
@@ -178,11 +184,253 @@ struct gui_methods gui_gtk_methods = {
 static gboolean
 gui_gtk_delete(GtkWidget *widget, GdkEvent *event, struct navit *nav)
 {
+       /* FIXME remove attr_navit callback */
        navit_destroy(nav);
 
        return TRUE;
 }
 
+static void
+gui_gtk_toggle_init(struct gui_priv *this)
+{
+       struct attr attr;
+       GtkToggleAction *toggle_action;
+
+       if (navit_get_attr(this->nav, attr_cursor, &attr, NULL)) {
+               toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "CursorAction"));
+               gtk_toggle_action_set_active(toggle_action, attr.u.num);
+       } else {
+               dbg(0, "Unable to locate CursorAction\n");
+       }
+       if (navit_get_attr(this->nav, attr_orientation, &attr, NULL)) {
+               toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "OrientationAction"));
+               gtk_toggle_action_set_active(toggle_action, attr.u.num);
+       } else {
+               dbg(0, "Unable to locate OrientationAction\n");
+       }
+       if (navit_get_attr(this->nav, attr_tracking, &attr, NULL)) {
+               toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
+               gtk_toggle_action_set_active(toggle_action, attr.u.num);
+       } else {
+               dbg(0, "Unable to locate TrackingAction\n");
+       }
+}
+
+struct action_cb_data {
+       struct gui_priv *gui;
+       struct attr attr;
+};
+
+static void
+gui_gtk_action_activate(GtkToggleAction *action, struct action_cb_data *data)
+{
+}
+static void
+gui_gtk_add_menu(struct gui_priv *this, char *name, char *label, char *path, struct action_cb_data *data)
+{
+       GtkAction *action;
+       guint merge_id;
+
+       action=gtk_action_new(name, label, NULL, NULL);
+       g_signal_connect(action, "activate", G_CALLBACK(gui_gtk_action_activate), data);
+       gtk_action_group_add_action(this->dyn_group, action);
+       merge_id=gtk_ui_manager_new_merge_id(this->ui_manager);
+       gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+}
+
+static void
+gui_gtk_action_toggled(GtkToggleAction *action, struct action_cb_data *data)
+{
+       map_set_active(data->attr.u.map, gtk_toggle_action_get_active(action));
+       navit_draw(data->gui->nav);
+}
+
+static void
+gui_gtk_add_toggle_menu(struct gui_priv *this, char *name, char *label, char *path, struct action_cb_data *data, gboolean active)
+{
+       GtkToggleAction *toggle_action;
+       guint merge_id;
+
+       toggle_action=gtk_toggle_action_new(name, label, NULL, NULL);
+       gtk_toggle_action_set_active(toggle_action, active);
+       g_signal_connect(GTK_ACTION(toggle_action), "toggled", G_CALLBACK(gui_gtk_action_toggled), data);
+       gtk_action_group_add_action(this->dyn_group, GTK_ACTION(toggle_action));
+       merge_id=gtk_ui_manager_new_merge_id(this->ui_manager);
+       gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+}
+
+static void
+gui_gtk_action_changed(GtkRadioAction *action, GtkRadioAction *current, struct action_cb_data *data)
+{
+       if (action == current) {
+               navit_set_attr(data->gui->nav, &data->attr);
+       }
+}
+
+static void
+gui_gtk_add_radio_menu(struct gui_priv *this, char *name, char *label, char *path, struct action_cb_data *data, GSList **g)
+{
+       GtkRadioAction *radio_action;
+       guint merge_id;
+
+       radio_action=gtk_radio_action_new(name, label, NULL, NULL, 0);
+       gtk_radio_action_set_group(radio_action, *g);
+       *g=gtk_radio_action_get_group(radio_action);
+       g_signal_connect(GTK_ACTION(radio_action), "changed", G_CALLBACK(gui_gtk_action_changed), data);
+       gtk_action_group_add_action(this->dyn_group, GTK_ACTION(radio_action));
+       merge_id=gtk_ui_manager_new_merge_id(this->ui_manager);
+       gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+}
+
+static void
+gui_gtk_layouts_init(struct gui_priv *this)
+{
+       struct attr_iter *iter;
+       struct attr attr;
+       struct action_cb_data *data;
+       int count=0;
+       char *name;
+
+       iter=navit_attr_iter_new();
+       while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
+               name=g_strdup_printf("Layout %d", count++);
+               data=g_new(struct action_cb_data, 1);
+               data->gui=this;
+               data->attr.type=attr_layout;
+               data->attr.u.layout=attr.u.layout;
+               gui_gtk_add_radio_menu(this, name, attr.u.layout->name, "/ui/MenuBar/Map/Layout/LayoutMenuAdditions", data, &this->layout_group);
+               g_free(name);
+       }
+       navit_attr_iter_destroy(iter);
+}
+
+static void
+gui_gtk_projections_init(struct gui_priv *this)
+{
+       struct action_cb_data *data;
+
+       data=g_new(struct action_cb_data, 1);
+       data->gui=this;
+       data->attr.type=attr_projection;
+       data->attr.u.projection=projection_mg;
+       gui_gtk_add_radio_menu(this, "Projection mg", "Map & Guide", "/ui/MenuBar/Map/Projection/ProjectionMenuAdditions", data, &this->projection_group);
+
+       data=g_new(struct action_cb_data, 1);
+       data->gui=this;
+       data->attr.type=attr_projection;
+       data->attr.u.projection=projection_garmin;
+       gui_gtk_add_radio_menu(this, "Projection garmin", "Garmin", "/ui/MenuBar/Map/Projection/ProjectionMenuAdditions", data, &this->projection_group);
+}
+
+static void
+gui_gtk_vehicles_init(struct gui_priv *this)
+{
+       struct attr_iter *iter;
+       struct attr attr,vattr;
+       struct action_cb_data *data;
+       int count=0;
+       char *name;
+
+       iter=navit_attr_iter_new();
+       while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
+               vehicle_get_attr(attr.u.vehicle, attr_name, &vattr);
+               name=g_strdup_printf("Vehicle %d", count++);
+               data=g_new(struct action_cb_data, 1);
+               data->gui=this;
+               data->attr.type=attr_vehicle;
+               data->attr.u.vehicle=attr.u.vehicle;
+               gui_gtk_add_radio_menu(this, name, vattr.u.str, "/ui/MenuBar/Map/Vehicle/VehicleMenuAdditions", data, &this->vehicle_group);
+               g_free(name);
+       }
+       navit_attr_iter_destroy(iter);
+}
+
+static void
+gui_gtk_maps_init(struct gui_priv *this)
+{
+       struct attr_iter *iter;
+       struct attr attr;
+       struct action_cb_data *data;
+       int count=0;
+       char *name, *label;
+
+       iter=navit_attr_iter_new();
+       while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
+               name=g_strdup_printf("Map %d", count++);
+               label=g_strdup_printf("%s:%s", map_get_type(attr.u.map), map_get_filename(attr.u.map));
+               data=g_new(struct action_cb_data, 1);
+               data->gui=this;
+               data->attr.type=attr_map;
+               data->attr.u.map=attr.u.map;
+               gui_gtk_add_toggle_menu(this, name, label, "/ui/MenuBar/Map/MapMenuAdditions", data, map_get_active(attr.u.map));
+               g_free(name);
+               g_free(label);
+       }
+       navit_attr_iter_destroy(iter);
+
+}
+
+static void
+gui_gtk_destinations_init(struct gui_priv *this)
+{
+       struct action_cb_data *data;
+
+       data=g_new(struct action_cb_data, 1);
+       data->gui=this;
+       data->attr.type=attr_destination;
+       data->attr.u.pcoord=g_new(struct pcoord, 1);
+       data->attr.u.pcoord->pro=projection_mg;
+       data->attr.u.pcoord->x=0x13a3e2;
+       data->attr.u.pcoord->y=0x5d6d6a;
+       gui_gtk_add_menu(this, "Destination 1", "Muenchen","/ui/MenuBar/Route/FormerDestinations/FormerDestinationMenuAdditions",data); 
+}
+
+static void
+gui_gtk_bookmarks_init(struct gui_priv *this)
+{
+       struct action_cb_data *data;
+
+       data=g_new(struct action_cb_data, 1);
+       data->gui=this;
+       data->attr.type=attr_destination;
+       data->attr.u.pcoord=g_new(struct pcoord, 1);
+       data->attr.u.pcoord->pro=projection_mg;
+       data->attr.u.pcoord->x=0x13a3e2;
+       data->attr.u.pcoord->y=0x5d6d6a;
+       gui_gtk_add_menu(this, "Bookmark 1", "Muenchen","/ui/MenuBar/Route/Bookmarks/BookmarkMenuAdditions",data); 
+}
+
+static void
+gui_gtk_init(struct gui_priv *this, struct navit *nav)
+{
+       GtkWidget *widget;
+
+       gui_gtk_ui_init(this);
+
+       gui_gtk_toggle_init(this);
+       if (this->menubar_enable) {
+               widget=gtk_ui_manager_get_widget(this->ui_manager, "/ui/MenuBar");
+               GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
+               gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
+               gtk_widget_show (widget);
+       }
+       if (this->toolbar_enable) {
+               widget=gtk_ui_manager_get_widget(this->ui_manager, "/ui/ToolBar");
+               GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
+               gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
+               gtk_widget_show (widget);
+       }
+       if (this->statusbar_enable) {
+               this->statusbar=gui_gtk_statusbar_new(this);
+       }
+       gui_gtk_layouts_init(this);
+       gui_gtk_projections_init(this);
+       gui_gtk_vehicles_init(this);
+       gui_gtk_maps_init(this);
+       gui_gtk_destinations_init(this);
+       gui_gtk_bookmarks_init(this);
+}
+
 static struct gui_priv *
 gui_gtk_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs) 
 {
@@ -190,28 +438,36 @@ gui_gtk_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
        int w=792, h=547;
        char *cp = getenv("NAVIT_XID");
        unsigned xid = 0;
-       struct attr *menubar, *toolbar, *statusbar;
+       struct attr *attr;
 
        if (cp) {
                xid = strtol(cp, NULL, 0);
        }
 
-       menubar = attr_search(attrs, NULL, attr_menubar);
-       if (menubar && menubar->u.num == 0) {
-               gui_gtk_methods.menubar_new = NULL;
+       this=g_new0(struct gui_priv, 1);
+       this->nav=nav;
+
+       attr = attr_search(attrs, NULL, attr_menubar);
+       if (attr) {
+               this->menubar_enable=attr->u.num;
+       } else {
+               this->menubar_enable=1;
        }
-       toolbar = attr_search(attrs, NULL, attr_toolbar);
-       if (toolbar && toolbar->u.num == 0) {
-               gui_gtk_methods.toolbar_new = NULL;
+       attr=attr_search(attrs, NULL, attr_toolbar);
+       if (attr) {
+               this->toolbar_enable=attr->u.num;
+       } else {
+               this->toolbar_enable=1;
        }
-       statusbar = attr_search(attrs, NULL, attr_statusbar);
-       if (statusbar && statusbar->u.num == 0) {
-               gui_gtk_methods.statusbar_new = NULL;
+       attr=attr_search(attrs, NULL, attr_statusbar);
+       if (attr) {
+               this->statusbar_enable=attr->u.num;
+       } else {
+               this->statusbar_enable=1;
        }
+
        *meth=gui_gtk_methods;
 
-       this=g_new0(struct gui_priv, 1);
-       this->nav=nav;
        if (!xid) 
                this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        else
@@ -225,6 +481,8 @@ gui_gtk_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
        gtk_container_add(GTK_CONTAINER(this->win), this->vbox);
        gtk_widget_show_all(this->win);
 
+
+       navit_add_callback(nav, callback_new_attr_1(callback_cast(gui_gtk_init), attr_navit, this));
        return this;
 }
 
index 50e3714..877d69e 100644 (file)
@@ -4,7 +4,6 @@
 #define YRES 600
 
 
-struct statusbar_methods;
 struct menu_methods;
 struct navit;
 
@@ -15,14 +14,6 @@ bool BookmarkGo(const char * name);
 bool FormerDestGo(const char * name);
 
 struct gui_priv {
-/*
-        GtkWidget *win;
-        GtkWidget *vbox;
-       GtkActionGroup *base_group;
-       GtkActionGroup *debug_group;
-       GtkActionGroup *dyn_group;
-       GtkUIManager *menu_manager;
-        void *statusbar;*/
        struct navit *nav;
        int dyn_counter;
 };
index 36416a5..7517102 100644 (file)
@@ -409,17 +409,6 @@ bool FormerDestGo(const char * name)
        }
 
 }
-static struct menu_priv *
-gui_sdl_toolbar_new(struct gui_priv *this_, struct menu_methods *meth)
-{
-       return NULL; //gui_gtk_ui_new(this_, meth, "/ui/ToolBar", nav, 0);
-}
-
-static struct statusbar_priv *
-gui_sdl_statusbar_new(struct gui_priv *gui, struct statusbar_methods *meth)
-{
-       return NULL; //gui_gtk_ui_new(this_, meth, "/ui/ToolBar", nav, 0);
-}
 
 static struct menu_priv *
 gui_sdl_menubar_new(struct gui_priv *this_, struct menu_methods *meth)
@@ -436,8 +425,6 @@ gui_sdl_popup_new(struct gui_priv *this_, struct menu_methods *meth)
 
 struct gui_methods gui_sdl_methods = {
        gui_sdl_menubar_new,
-       gui_sdl_toolbar_new,
-       gui_sdl_statusbar_new,
        gui_sdl_popup_new,
        gui_sdl_set_graphics,
        gui_run_main_loop,
@@ -750,21 +737,21 @@ static void vehicle_callback_handler( struct navit *nav, struct vehicle *v){
        struct attr attr;
        int sats=0, sats_used=0;
 
-       if (vehicle_position_attr_get(v, attr_position_speed, &attr))
+       if (vehicle_get_attr(v, attr_position_speed, &attr))
                sprintf (buffer, "%02.02f km/h", *attr.u.numd);
        else
                strcpy (buffer, "N/A");
        CEGUI::WindowManager::getSingleton().getWindow("OSD/SpeedoMeter")->setText(buffer);
 
-       if (vehicle_position_attr_get(v, attr_position_height, &attr))
+       if (vehicle_get_attr(v, attr_position_height, &attr))
                sprintf (buffer, "%.f m", *attr.u.numd);
        else
                strcpy (buffer, "N/A");
        CEGUI::WindowManager::getSingleton().getWindow("OSD/Altimeter")->setText(buffer);
 
-       if (vehicle_position_attr_get(v, attr_position_sats, &attr))
+       if (vehicle_get_attr(v, attr_position_sats, &attr))
                sats=attr.u.num;
-       if (vehicle_position_attr_get(v, attr_position_sats_used, &attr))
+       if (vehicle_get_attr(v, attr_position_sats_used, &attr))
                sats_used=attr.u.num;
 //     printf(" sats : %i, used %i: \n",sats,sats_used);
        // Sat image hardcoded for now. may break the TaharezSkin
index 7da01b7..ba5a68c 100644 (file)
@@ -33,6 +33,7 @@
 #include "color.h"
 #include "layout.h"
 #include "log.h"
+#include "attr.h"
 
 #define _(STRING)    gettext(STRING)
 /**
@@ -41,7 +42,9 @@
  */
 
 struct navit_vehicle {
+#if 0
        char *name;
+#endif
        int update;
        int update_curr;
        int follow;
@@ -71,8 +74,6 @@ struct navit {
        struct transformation *trans;
        struct compass *compass;
        struct menu *menu;
-       struct menu *toolbar;
-       struct statusbar *statusbar;
        struct menu *menubar;
        struct route *route;
        struct navigation *navigation;
@@ -105,6 +106,13 @@ struct navit {
 
 struct gui *main_loop_gui;
 
+struct attr_iter {
+       union {
+               GList *list;
+               struct mapset_handle *mapset_handle;
+       } u;
+};
+
 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
 
@@ -400,8 +408,6 @@ navit_set_gui(struct navit *this_, struct gui *gui, char *type)
                }
        }
        this_->menubar=gui_menubar_new(this_->gui);
-       this_->toolbar=gui_toolbar_new(this_->gui);
-       this_->statusbar=gui_statusbar_new(this_->gui);
 }
 
 void
@@ -421,15 +427,6 @@ navit_get_graphics(struct navit *this_)
 }
 
 static void
-navit_map_toggle(struct menu *menu, struct navit *this_, struct map *map)
-{
-       if ((menu_get_toggle(menu) != 0) != (map_get_active(map) != 0)) {
-               map_set_active(map, (menu_get_toggle(menu) != 0));
-               navit_draw(this_);
-       }
-}
-
-static void
 navit_projection_set(struct navit *this_, enum projection pro)
 {
        struct coord_geo g;
@@ -467,18 +464,6 @@ navit_add_menu_destinations(struct navit *this_, char *name, struct menu *rmen,
        }
 }
 
-static const char *
-navit_proj2str(enum projection pro)
-{
-       switch (pro) {
-               case projection_mg:
-                       return "mg";
-               case projection_garmin:
-                       return "garmin";
-               default:
-                       return "";
-       }
-}
 static void
 navit_append_coord(struct navit *this_, char *file, struct pcoord *c, char *type, char *description, struct menu *rmen, GHashTable *h, void (*cb_func)(void))
 {
@@ -492,7 +477,7 @@ navit_append_coord(struct navit *this_, char *file, struct pcoord *c, char *type
        if (f) {
                offset=ftell(f);
                if (c) {
-                       prostr = navit_proj2str(c->pro);
+                       prostr = projection_to_name(c->pro);
                        fprintf(f,"%s%s0x%x 0x%x type=%s label=\"%s\"\n",
                                 prostr, *prostr ? ":" : "", c->x, c->y, type, description);
                } else
@@ -618,64 +603,6 @@ navit_add_bookmark(struct navit *this_, struct pcoord *c, char *description)
 
 struct navit *global_navit;
 
-void
-navit_add_menu_layouts(struct navit *this_, struct menu *men)
-{
-       GList *layouts;
-       struct layout *l;
-       struct callback *cb;
-
-       layouts = this_->layouts;
-       while (layouts) {
-               l=layouts->data;
-               cb=callback_new_2(callback_cast(navit_set_attr), this_, attr_new_from_text("layout",l->name));
-               menu_add(men, l->name, menu_type_menu, cb);
-               layouts=g_list_next(layouts);
-       }
-}
-
-void
-navit_add_menu_layout(struct navit *this_, struct menu *men)
-{
-       navit_add_menu_layouts(this_, menu_add(men, _("Layout"), menu_type_submenu, NULL));
-}
-
-void
-navit_add_menu_projections(struct navit *this_, struct menu *men)
-{
-       struct callback *cb;
-       cb=callback_new_2(callback_cast(navit_projection_set), this_, (void *)projection_mg);
-       menu_add(men, "M&G", menu_type_menu, cb);
-       cb=callback_new_2(callback_cast(navit_projection_set), this_, (void *)projection_garmin);
-       menu_add(men, "Garmin", menu_type_menu, cb);
-}
-
-void
-navit_add_menu_projection(struct navit *this_, struct menu *men)
-{
-       navit_add_menu_projections(this_, menu_add(men, _("Projection"), menu_type_submenu, NULL));
-}
-
-void
-navit_add_menu_maps(struct navit *this_, struct mapset *ms, struct menu *men)
-{
-       struct mapset_handle *handle;
-       struct map *map;
-       struct menu *mmen;
-       struct callback *cb;
-
-       handle=mapset_open(ms);
-       while ((map=mapset_next(handle,0))) {
-               char *s=g_strdup_printf("%s:%s", map_get_type(map), map_get_filename(map));
-               cb=callback_new_3(callback_cast(navit_map_toggle), NULL, this_, map);
-               mmen=menu_add(men, s, menu_type_toggle, cb);
-               callback_set_arg(cb, 0, mmen);
-               menu_set_toggle(mmen, map_get_active(map));
-               g_free(s);
-       }
-       mapset_close(handle);
-}
-
 static void
 navit_add_menu_destinations_from_file(struct navit *this_, char *file, struct menu *rmen, GHashTable *h, struct route *route, void (*cb_func)(void))
 {
@@ -707,7 +634,7 @@ navit_add_menu_destinations_from_file(struct navit *this_, char *file, struct me
        }
 }
 
-void
+static void
 navit_add_menu_former_destinations(struct navit *this_, struct menu *men, struct route *route)
 {
        if (men)
@@ -717,7 +644,7 @@ navit_add_menu_former_destinations(struct navit *this_, struct menu *men, struct
        navit_add_menu_destinations_from_file(this_, "destination.txt", this_->destinations, NULL, route, callback_cast(navit_set_destination_from_destination));
 }
 
-void
+static void
 navit_add_menu_bookmarks(struct navit *this_, struct menu *men)
 {
        if (men)
@@ -728,42 +655,6 @@ navit_add_menu_bookmarks(struct navit *this_, struct menu *men)
 }
 
 static void
-navit_vehicle_toggle(struct navit *this_, struct navit_vehicle *nv)
-{
-       if (menu_get_toggle(nv->menu)) {
-               if (this_->vehicle && this_->vehicle != nv)
-                       menu_set_toggle(this_->vehicle->menu, 0);
-               this_->vehicle=nv;
-       } else {
-               if (this_->vehicle == nv)
-                       this_->vehicle=NULL;
-       }
-}
-
-void
-navit_add_menu_vehicles(struct navit *this_, struct menu *men)
-{
-       struct navit_vehicle *nv;
-       struct callback *cb;
-       GList *l;
-       l=this_->vehicles;
-       while (l) {
-               nv=l->data;
-               cb=callback_new_2(callback_cast(navit_vehicle_toggle), this_, nv);
-               nv->menu=menu_add(men, nv->name, menu_type_toggle, cb);
-               menu_set_toggle(nv->menu, this_->vehicle == nv);
-               l=g_list_next(l);
-       }
-}
-
-void
-navit_add_menu_vehicle(struct navit *this_, struct menu *men)
-{
-       men=menu_add(men, _("Vehicle"), menu_type_submenu, NULL);
-       navit_add_menu_vehicles(this_, men);
-}
-
-static void
 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
 {
        va_list ap;
@@ -1059,7 +950,7 @@ navit_add_window_items(struct navit *this_, struct navit_window_items *nwi)
        this_->windows_items=g_list_append(this_->windows_items, nwi);
 }
 
-void
+static void
 navit_add_menu_windows_items(struct navit *this_, struct menu *men)
 {
        struct navit_window_items *nwi;
@@ -1133,21 +1024,7 @@ navit_init(struct navit *this_)
                        }
                        navigation_set_mapset(this_->navigation, ms);
                }
-               if (this_->menubar) {
-                       men=menu_add(this_->menubar, _("Map"), menu_type_submenu, NULL);
-                       if (men) {
-                               navit_add_menu_layout(this_, men);
-                               navit_add_menu_projection(this_, men);
-                               navit_add_menu_vehicle(this_, men);
-                               navit_add_menu_maps(this_, ms, men);
-                       }
-                       men=menu_add(this_->menubar, _("Route"), menu_type_submenu, NULL);
-                       if (men) {
-                               navit_add_menu_former_destinations(this_, men, this_->route);
-                               navit_add_menu_bookmarks(this_, men);
-                       }
-               } else
-                       navit_add_menu_former_destinations(this_, NULL, this_->route);
+               navit_add_menu_former_destinations(this_, NULL, this_->route);
        }
        if (this_->navigation && this_->speech) {
                this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
@@ -1221,8 +1098,6 @@ navit_set_center_screen(struct navit *this_, struct point *p)
 int
 navit_set_attr(struct navit *this_, struct attr *attr)
 {
-       GList *layouts;
-       struct layout *l;
        int dir=0, orient_old=0, attr_updated=0;
 
        switch (attr->type) {
@@ -1232,9 +1107,10 @@ navit_set_attr(struct navit *this_, struct attr *attr)
                        attr_updated=1;
                }
                break;
-       case attr_tracking:
-               if (this_->tracking_flag != !!attr->u.num) {
-                       this_->tracking_flag=!!attr->u.num;
+       case attr_layout:
+               if(this_->layout_current!=attr->u.layout) {
+                       this_->layout_current=attr->u.layout;
+                       navit_draw(this_);
                        attr_updated=1;
                }
                break;
@@ -1254,16 +1130,29 @@ navit_set_attr(struct navit *this_, struct attr *attr)
                        attr_updated=1;
                }
                break;
-       case attr_layout:
-               layouts = this_->layouts;
-               while (layouts) {
-                       l=layouts->data;
-                       if(!strcmp(attr->u.str,l->name) && this_->layout_current!=l) {
-                               this_->layout_current=l;
-                               navit_draw(this_);
-                               attr_updated=1;
+       case attr_projection:
+               if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
+                       navit_projection_set(this_, attr->u.projection);
+                       attr_updated=1;
+               }
+               break;
+       case attr_tracking:
+               if (this_->tracking_flag != !!attr->u.num) {
+                       this_->tracking_flag=!!attr->u.num;
+                       attr_updated=1;
+               }
+               break;
+       case attr_vehicle:
+               if (this_->vehicle && this_->vehicle->vehicle != attr->u.vehicle) {
+                       GList *l;
+                       l=this_->vehicles;
+                       while(l) {
+                               if (((struct navit_vehicle *)l->data)->vehicle == attr->u.vehicle) {
+                                       this_->vehicle=(struct navit_vehicle *)l;
+                                       attr_updated=1;
+                               }
+                               l=g_list_next(l);
                        }
-                       layouts=g_list_next(layouts);
                }
                break;
        default:
@@ -1276,25 +1165,75 @@ navit_set_attr(struct navit *this_, struct attr *attr)
 }
 
 int
-navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr)
+navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
 {
        switch (type) {
        case attr_cursor:
                attr->u.num=this_->cursor_flag;
                break;
-       case attr_tracking:
-               attr->u.num=this_->tracking_flag;
+       case attr_destination:
+               if (! this_->destination_valid)
+                       return 0;
+               attr->u.pcoord=&this_->destination;
+               break;
+       case attr_layout:
+               if (iter) {
+                       if (iter->u.list) {
+                               iter->u.list=g_list_next(iter->u.list);
+                       } else { 
+                               iter->u.list=this_->layouts;
+                       }
+                       if (!iter->u.list)
+                               return 0;
+                       attr->u.layout=(struct layout *)iter->u.list->data;
+               } else {
+                       attr->u.layout=this_->layout_current;
+               }
+               break;
+       case attr_map:
+               if (iter && this_->mapsets) {
+                       if (!iter->u.mapset_handle) {
+                               iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
+                       }
+                       attr->u.map=mapset_next(iter->u.mapset_handle, 0);
+                       if(!attr->u.map) {
+                               mapset_close(iter->u.mapset_handle);
+                               return 0;
+                       }
+               } else {
+                       return 0;
+               }
                break;
        case attr_orientation:
                attr->u.num=this_->orient_north_flag;
                break;
-       case attr_layout:
-               attr->u.str=g_strdup(this_->layout_current->name);
-               break;
-       case attr_destination:
-               if (! this_->destination_valid)
+       case attr_projection:
+               if(this_->trans) {
+                       attr->u.num=transform_get_projection(this_->trans);
+               } else {
                        return 0;
-               attr->u.pcoord=&this_->destination;
+               }
+               break;
+       case attr_tracking:
+               attr->u.num=this_->tracking_flag;
+               break;
+       case attr_vehicle:
+               if(iter) {
+                       if(iter->u.list) {
+                               iter->u.list=g_list_next(iter->u.list);
+                       } else { 
+                               iter->u.list=this_->vehicles;
+                       }
+                       if(!iter->u.list)
+                               return 0;
+                       attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
+               } else {
+                       if(this_->vehicle) {
+                               attr->u.vehicle=this_->vehicle->vehicle;
+                       } else {
+                               return 0;
+                       }
+               }
                break;
        default:
                return 0;
@@ -1331,6 +1270,18 @@ navit_add_attr(struct navit *this_, struct attr *attr, struct attr **attrs)
        return 1;
 }
 
+struct attr_iter *
+navit_attr_iter_new()
+{
+       return g_new0(struct attr_iter, 1);
+}
+
+void
+navit_attr_iter_destroy(struct attr_iter *iter)
+{
+       g_free(iter);
+}
+
 void
 navit_add_callback(struct navit *this_, struct callback *cb)
 {
@@ -1381,9 +1332,9 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
        if (! this_->ready)
                return;
 
-       if (! vehicle_position_attr_get(nv->vehicle, attr_position_direction, &attr_dir) ||
-           ! vehicle_position_attr_get(nv->vehicle, attr_position_speed, &attr_speed) ||
-           ! vehicle_position_attr_get(nv->vehicle, attr_position_coord_geo, &attr_pos))
+       if (! vehicle_get_attr(nv->vehicle, attr_position_direction, &attr_dir) ||
+           ! vehicle_get_attr(nv->vehicle, attr_position_speed, &attr_speed) ||
+           ! vehicle_get_attr(nv->vehicle, attr_position_coord_geo, &attr_pos))
                return;
        nv->dir=*attr_dir.u.numd;
        nv->speed=*attr_speed.u.numd;
@@ -1481,14 +1432,11 @@ struct navit_vehicle *
 navit_add_vehicle(struct navit *this_, struct vehicle *v, struct attr **attrs)
 {
        struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
-       struct attr *name,*update,*follow,*color,*active, *color2, *animate;
+       struct attr *update,*follow,*color,*active, *color2, *animate;
        nv->vehicle=v;
        nv->update=1;
        nv->follow=0;
        nv->animate_cursor=0;
-       nv->name="Noname";
-       if ((name=attr_search(attrs, NULL, attr_name)))
-               nv->name=g_strdup(name->u.str);
        if ((update=attr_search(attrs, NULL, attr_update)))
                nv->update=nv->update=update->u.num;
        if ((follow=attr_search(attrs, NULL, attr_follow)))
index a18add1..aa8286f 100644 (file)
@@ -9,6 +9,8 @@ extern struct gui *main_loop_gui;
 enum item_type;
 enum attr_type;
 struct attr;
+struct attr_iter;
+struct attr_iter;
 struct callback;
 struct coord;
 struct displaylist;
@@ -42,28 +44,20 @@ void navit_set_graphics(struct navit *this_, struct graphics *gra, char *type);
 struct graphics *navit_get_graphics(struct navit *this_);
 void navit_set_destination(struct navit *this_, struct pcoord *c, char *description);
 void navit_add_bookmark(struct navit *this_, struct pcoord *c, char *description);
-void navit_add_menu_layouts(struct navit *this_, struct menu *men);
-void navit_add_menu_layout(struct navit *this_, struct menu *men);
-void navit_add_menu_projections(struct navit *this_, struct menu *men);
-void navit_add_menu_projection(struct navit *this_, struct menu *men);
-void navit_add_menu_maps(struct navit *this_, struct mapset *ms, struct menu *men);
-void navit_add_menu_former_destinations(struct navit *this_, struct menu *men, struct route *route);
-void navit_add_menu_bookmarks(struct navit *this_, struct menu *men);
-void navit_add_menu_vehicles(struct navit *this_, struct menu *men);
-void navit_add_menu_vehicle(struct navit *this_, struct menu *men);
 void navit_speak(struct navit *this_);
 void navit_window_roadbook_destroy(struct navit *this_);
 void navit_window_roadbook_new(struct navit *this_);
 struct navit_window_items *navit_window_items_new(const char *name, int distance);
 void navit_window_items_add_item(struct navit_window_items *nwi, enum item_type type);
 void navit_add_window_items(struct navit *this_, struct navit_window_items *nwi);
-void navit_add_menu_windows_items(struct navit *this_, struct menu *men);
 void navit_init(struct navit *this_);
 void navit_set_center(struct navit *this_, struct pcoord *center);
 void navit_set_center_screen(struct navit *this_, struct point *p);
 int navit_set_attr(struct navit *this_, struct attr *attr);
-int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr);
+int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
 int navit_add_attr(struct navit *this_, struct attr *attr, struct attr **attrs);
+struct attr_iter *navit_attr_iter_new(void);
+void navit_attr_iter_destroy(struct attr_iter *iter);
 void navit_add_callback(struct navit *this_, struct callback *cb);
 void navit_remove_callback(struct navit *this_, struct callback *cb);
 void navit_set_position(struct navit *this_, struct pcoord *c);
index 41ca143..5bef8d6 100644 (file)
@@ -30,7 +30,7 @@ Change to your home coordinates.
        <vehicle name="Meins" enabled="yes" source="gpsd://localhost" color="#0000ff" follow="1" refresh="1"/>
        -->
        
-       <vehicle name="Deins" enabled="no" source="gpsd://somehost" color="#0000aa"/> 
+       <vehicle name="Demo" enabled="yes" source="demo://" color="#0000aa"/> 
        <tracking>
        </tracking>
        <route>
index 409664c..72c260f 100644 (file)
@@ -100,11 +100,11 @@ osd_compass_draw(struct compass *this, struct navit *nav, struct vehicle *v)
        p.x=30;
        p.y=30;
        graphics_draw_circle(this->gr, this->white, &p, 50);
-       if (v && vehicle_position_attr_get(v, attr_position_direction, &attr_dir)) {
+       if (v && vehicle_get_attr(v, attr_position_direction, &attr_dir)) {
                vdir=*attr_dir.u.numd;
                handle(this->gr, this->white, &p, 20, -vdir);
        }
-       if (navit_get_attr(nav, attr_destination, &destination_attr) && v && vehicle_position_attr_get(v, attr_position_coord_geo, &position_attr)) {
+       if (navit_get_attr(nav, attr_destination, &destination_attr, NULL) && v && vehicle_get_attr(v, attr_position_coord_geo, &position_attr)) {
                pro=destination_attr.u.pcoord->pro;
                transform_from_geo(pro, position_attr.u.coord_geo, &c1);
                c2.x=destination_attr.u.pcoord->x;
index 361de78..12f46ba 100644 (file)
@@ -5,5 +5,8 @@ enum projection {
        projection_none, projection_mg, projection_garmin
 };
 
+enum projection projection_from_name(const char *name);
+char * projection_to_name(enum projection proj);
+
 #endif
 
index a4baf21..37e07e0 100644 (file)
@@ -11,6 +11,7 @@
 #include "vehicle.h"
 
 struct vehicle {
+       char *name;
        struct vehicle_priv *priv;
        struct vehicle_methods meth;
        struct callback_list *cbl;
@@ -94,6 +95,7 @@ vehicle_new(struct attr **attrs)
                                                 cbl,
                                                 struct attr ** attrs);
        char *type, *colon;
+       struct attr *name;
 
        dbg(1, "enter\n");
        source = attr_search(attrs, NULL, attr_source);
@@ -124,17 +126,30 @@ vehicle_new(struct attr **attrs)
        }
        dbg(1, "leave\n");
 
+       if ((name=attr_search(attrs, NULL, attr_name))) {
+               this_->name=g_strdup(name->u.str);
+       } else {
+               this_->name=g_strdup("Noname");
+       }
        return this_;
 }
 
 int
-vehicle_position_attr_get(struct vehicle *this_, enum attr_type type,
-                         struct attr *attr)
+vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr)
 {
-       if (this_->meth.position_attr_get)
-               return this_->meth.position_attr_get(this_->priv, type,
-                                                    attr);
-       return 0;
+       switch (type) {
+       case attr_name:
+               attr->u.str=this_->name;
+               break;
+       default:
+               if (this_->meth.position_attr_get) {
+                       return this_->meth.position_attr_get(this_->priv, type, attr);
+               } else {
+                       return 0;
+               }
+       }
+       attr->type=type;
+       return 1;
 }
 
 int
@@ -179,5 +194,6 @@ void
 vehicle_destroy(struct vehicle *this_)
 {
        callback_list_destroy(this_->cbl);
+       if(this_->name) g_free(this_->name);
        g_free(this_);
 }
index c67567d..e2ad052 100644 (file)
@@ -18,7 +18,7 @@ struct vehicle_methods {
 
 /* prototypes */
 struct vehicle *vehicle_new(struct attr **attrs);
-int vehicle_position_attr_get(struct vehicle *this_, enum attr_type type, struct attr *attr);
+int vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr);
 int vehicle_set_attr(struct vehicle *this_, struct attr *attr, struct attr **attrs);
 int vehicle_add_attr(struct vehicle *this_, struct attr *attr, struct attr **attrs);
 int vehicle_remove_attr(struct vehicle *this_, struct attr *attr);