Fix:Core: Bug fixed when <speech active=...> hasn't been set
authorsingesang <singesang@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 22 Jan 2009 14:40:10 +0000 (14:40 +0000)
committersingesang <singesang@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 22 Jan 2009 14:40:10 +0000 (14:40 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1962 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit.c
navit/osd/core/osd_core.c

index 7a8f79e..21b22b5 100644 (file)
@@ -997,19 +997,33 @@ navit_say(struct navit *this_, char *text)
        speech_say(this_->speech, text);
 }
 
+/**
+ * @brief Toggles the navigation announcer for navit
+ * @param this_ The navit object
+ */
 void
 navit_announcer_toggle(struct navit *this_)
 {
     struct attr attr, speechattr;
+
+    // search for the speech attribute
     if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
         return;
-    if(!speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL))
-        return;
-    
-    attr.u.num = !attr.u.num;
-    
+    // find out if the corresponding attribute attr_active has been set
+    if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
+        // flip it then...
+        attr.u.num = !attr.u.num;
+    } else {
+        // otherwise disable it because voice is enabled by default
+        attr.type = attr_active;
+        attr.u.num = 0;
+    }
+
+    // apply the new state
     if(!speech_set_attr(speechattr.u.speech, &attr))
         return;
+
+    // announce that the speech attribute has changed
     callback_list_call_attr_0(this_->attr_cbl, attr_speech);
 }
 
index ce9fed8..3f2c939 100644 (file)
@@ -1525,8 +1525,8 @@ osd_nav_toggle_announcer_draw(struct nav_toggle_announcer *this, struct navit *n
             if (!speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL))
                 attr.u.num = 1;
         this->active = attr.u.num;
-    }
-    this->active = !this->active;
+    } else
+        this->active = !this->active;
 
     if(this->active != this->last_state)
     {