Changed api for navigation_list
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 4 Oct 2007 17:51:16 +0000 (17:51 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 4 Oct 2007 17:51:16 +0000 (17:51 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@445 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/attr_def.h
navit/src/gui/sdl/gui_sdl_window.cpp
navit/src/navigation.c
navit/src/navigation.h
navit/src/navit.c

index ae89fad..32be1a3 100644 (file)
@@ -47,4 +47,9 @@ ATTR(open_hours)
 ATTR(icon)
 ATTR(info_html)
 ATTR(price_html)
+/* navigation */
+ATTR(navigation_short)
+ATTR(navigation_long)
+ATTR(navigation_long_exact)
+ATTR(navigation_speech)
 ATTR2(type_string_end,0x0003ffff)
index 1352398..fcc37eb 100644 (file)
@@ -102,7 +102,9 @@ sdl_update_roadbook(struct navigation *nav)
        // First, update the 'Navigation Tip' on the main window
 
        try {
-               WindowManager::getSingleton().getWindow("Navit/Routing/Tips")->setText(navigation_list_get(list, navigation_mode_speech));
+               struct attr attr;
+               item_attr_get(navigation_list_get_item(list), attr_navigation_speech, &attr);
+               WindowManager::getSingleton().getWindow("Navit/Routing/Tips")->setText(attr.u.str);
        }
        catch (CEGUI::Exception& e)
        {
@@ -122,15 +124,16 @@ sdl_update_roadbook(struct navigation *nav)
                MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("Roadbook"));
                mcl->resetList();
 
-               char *str;      
+               item *item;
+               struct attr attr;
 
                list=navigation_list_new(nav);  
-               while ((str=navigation_list_get(list, navigation_mode_short))) {
+               while ((item=navigation_list_get_item(list))) {
                                
 //                     printf("SDL : %s\n", str);
                        mcl->addRow();
-
-                       ListboxTextItem* itemListbox = new ListboxTextItem(str);
+                       item_attr_get(item, attr_navigation_short, &attr);
+                       ListboxTextItem* itemListbox = new ListboxTextItem(attr.u.str);
                        itemListbox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
                        mcl->setItem(itemListbox, 0, mcl->getRowCount()-1);
                }
@@ -191,7 +194,7 @@ static int gui_run_main_loop(struct gui_priv *this_)
        navig=navit_get_navigation(sdl_gui_navit);
 
        navigation_register_callback(navig,
-               navigation_mode_long,
+               attr_navigation_long,
                callback_new_0((void (*)())sdl_update_roadbook)
        );
 
index 5348165..b4b91c6 100644 (file)
@@ -46,8 +46,13 @@ struct navigation_command {
 struct navigation_list {
        struct navigation *nav;
        struct navigation_command *cmd;
+       struct navigation_command *cmd_next;
        struct navigation_itm *itm;
+       struct navigation_itm *itm_next;
+       struct item item;
+#if 0
        char *str;
+#endif
 };
 
 struct street_data {
@@ -169,9 +174,9 @@ round_distance(int dist)
 }
 
 static char *
-get_distance(int dist, enum navigation_mode mode, int is_length)
+get_distance(int dist, enum attr_type type, int is_length)
 {
-       if (mode == navigation_mode_long) {
+       if (type == attr_navigation_long) {
                if (is_length)
                        return g_strdup_printf(_("%d m"), dist);
                else
@@ -419,7 +424,7 @@ make_maneuvers(struct navigation *this_)
 }
 
 static char *
-show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum navigation_mode mode)
+show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
 {
        char *dir=_("right"),*strength="";
        int distance=itm->dest_length-cmd->itm->dest_length;
@@ -442,9 +447,9 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
                dbg(1,"delta=%d\n", delta);
                strength=_("unknown ");
        }
-       if (mode != navigation_mode_long_exact) 
+       if (type != attr_navigation_long_exact) 
                distance=round_distance(distance);
-       if (mode == navigation_mode_speech) {
+       if (type == attr_navigation_speech) {
                if (nav->turn_around) 
                        return g_strdup(_("When possible, please turn around"));
                level=navigation_get_announce_level(nav, itm->item.type, distance);
@@ -452,7 +457,7 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
        }
        switch(level) {
        case 3:
-               d=get_distance(distance, mode, 1);
+               d=get_distance(distance, type, 1);
                ret=g_strdup_printf(_("Follow the road for the next %s"), d);
                g_free(d);
                return ret;
@@ -460,7 +465,7 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
                d=g_strdup(_("soon"));
                break;
        case 1:
-               d=get_distance(distance, mode, 0);
+               d=get_distance(distance, type, 0);
                break;
        case 0:
                d=g_strdup(_("now"));
@@ -493,34 +498,63 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
        return ret;
 }
 
+static int
+navigation_list_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
+{
+       struct navigation_list *this_=priv_data;
+       switch(attr_type) {
+       case attr_navigation_short:
+       case attr_navigation_long:
+       case attr_navigation_long_exact:
+       case attr_navigation_speech:
+               attr->u.str=show_maneuver(this_->nav, this_->itm, this_->cmd, attr_type);
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+struct item_methods navigation_list_item_methods = {
+       NULL,
+       NULL,
+       NULL,
+       navigation_list_item_attr_get,
+};
+
+
+
 struct navigation_list *
 navigation_list_new(struct navigation *this_)
 {
        struct navigation_list *ret=g_new0(struct navigation_list, 1);
        ret->nav=this_;
-       ret->cmd=this_->cmd_first;
-       ret->itm=this_->first;
+       ret->cmd_next=this_->cmd_first;
+       ret->itm_next=this_->first;
+       ret->item.meth=&navigation_list_item_methods;
+       ret->item.priv_data=ret;
        return ret;
 }
 
-char *
-navigation_list_get(struct navigation_list *this_, enum navigation_mode mode)
+struct item *
+navigation_list_get_item(struct navigation_list *this_)
 {
-       if (!this_->cmd)
+       if (!this_->cmd_next)
                return NULL;
-       g_free(this_->str);
+       this_->cmd=this_->cmd_next;
+       this_->itm=this_->itm_next;
+#if 0
        this_->str=show_maneuver(this_->nav, this_->itm, this_->cmd, mode);
-       this_->itm=this_->cmd->itm;
-       this_->cmd=this_->cmd->next;
+#endif
+       this_->itm_next=this_->cmd->itm;
+       this_->cmd_next=this_->cmd->next;
 
-       return this_->str;
+       return &this_->item;
 }
 
 
 void
 navigation_list_destroy(struct navigation_list *this_)
 {
-       g_free(this_->str);
        g_free(this_);
 }
 
@@ -642,9 +676,9 @@ navigation_destroy(struct navigation *this_)
 }
 
 int
-navigation_register_callback(struct navigation *this_, enum navigation_mode mode, struct callback *cb)
+navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
 {
-       if (mode == navigation_mode_speech)
+       if (type == attr_navigation_speech)
                callback_list_add(this_->callback_speech, cb);
        else
                callback_list_add(this_->callback, cb);
@@ -652,9 +686,9 @@ navigation_register_callback(struct navigation *this_, enum navigation_mode mode
 }
 
 void
-navigation_unregister_callback(struct navigation *this_, enum navigation_mode mode, struct callback *cb)
+navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
 {
-       if (mode == navigation_mode_speech)
+       if (type == attr_navigation_speech)
                callback_list_remove_destroy(this_->callback_speech, cb);
        else
                callback_list_remove_destroy(this_->callback, cb);
index a799094..a6df887 100644 (file)
@@ -1,17 +1,11 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-enum navigation_mode {
-       navigation_mode_long,
-       navigation_mode_long_exact,
-       navigation_mode_short,
-       navigation_mode_speech,
-};
-
 /* prototypes */
+enum attr_type;
 enum item_type;
-enum navigation_mode;
 struct callback;
+struct item;
 struct mapset;
 struct navigation;
 struct navigation_list;
@@ -20,12 +14,12 @@ struct navigation *navigation_new(struct mapset *ms);
 void navigation_set_mapset(struct navigation *this_, struct mapset *ms);
 int navigation_set_announce(struct navigation *this_, enum item_type type, int *level);
 struct navigation_list *navigation_list_new(struct navigation *this_);
-char *navigation_list_get(struct navigation_list *this_, enum navigation_mode mode);
+struct item *navigation_list_get_item(struct navigation_list *this_);
 void navigation_list_destroy(struct navigation_list *this_);
 void navigation_update(struct navigation *this_, struct route *route);
 void navigation_destroy(struct navigation *this_);
-int navigation_register_callback(struct navigation *this_, enum navigation_mode mode, struct callback *cb);
-void navigation_unregister_callback(struct navigation *this_, enum navigation_mode mode, struct callback *cb);
+int navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb);
+void navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb);
 /* end of prototypes */
 #ifdef __cplusplus
 }
index 42c94eb..c19a937 100644 (file)
@@ -557,11 +557,13 @@ navit_speak(struct navit *this_)
 {
        struct navigation *nav=this_->navigation;
        struct navigation_list *list;
-       char *text;
+       struct item *item;
+       struct attr attr;
 
        list=navigation_list_new(nav);  
-       text=navigation_list_get(list, navigation_mode_speech);
-       speech_say(this_->speech, text);
+       item=navigation_list_get_item(list);
+       if (item_attr_get(item, attr_navigation_speech, &attr)) 
+               speech_say(this_->speech, attr.u.str);
        navigation_list_destroy(list);
 }
 
@@ -570,16 +572,19 @@ navit_window_roadbook_update(struct navit *this_)
 {
        struct navigation *nav=this_->navigation;
        struct navigation_list *list;
-       char *str;
+       struct item *item;
+       struct attr attr;
        struct param_list param[1];
 
        dbg(1,"enter\n");       
        datawindow_mode(this_->roadbook_window, 1);
        list=navigation_list_new(nav);
-       while ((str=navigation_list_get(list, navigation_mode_long_exact))) {
-               dbg(2, "Command='%s'\n", str);
+       while ((item=navigation_list_get_item(list))) {
+               attr.u.str=NULL;
+               item_attr_get(item, attr_navigation_long, &attr);
+               dbg(2, "Command='%s'\n", attr.u.str);
                param[0].name="Command";
-               param[0].value=str;
+               param[0].value=attr.u.str;
                datawindow_add(this_->roadbook_window, param, 1);
        }
        navigation_list_destroy(list);
@@ -590,7 +595,7 @@ void
 navit_window_roadbook_destroy(struct navit *this_)
 {
        dbg(0, "enter\n");
-       navigation_unregister_callback(this_->navigation, navigation_mode_long, this_->roadbook_callback);
+       navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
        this_->roadbook_window=NULL;
        this_->roadbook_callback=NULL;
 }
@@ -598,7 +603,7 @@ void
 navit_window_roadbook_new(struct navit *this_)
 {
        this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
-       navigation_register_callback(this_->navigation, navigation_mode_long, this_->roadbook_callback);
+       navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
        this_->roadbook_window=gui_datawindow_new(this_->gui, "Roadbook", NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
        navit_window_roadbook_update(this_);
 }
@@ -832,7 +837,7 @@ navit_init(struct navit *this_)
        }
        if (this_->navigation && this_->speech) {
                this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
-               navigation_register_callback(this_->navigation, navigation_mode_speech, this_->nav_speech_cb);
+               navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
 #if 0
 #endif
        }