Add:Core:Improving message interface
authortinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 15 Mar 2009 17:01:08 +0000 (17:01 +0000)
committertinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 15 Mar 2009 17:01:08 +0000 (17:01 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2126 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/attr_def.h
navit/navit/messages.c
navit/navit/navit.c

index 2a3fb02..723f946 100644 (file)
@@ -198,6 +198,7 @@ ATTR(osm_tag)
 ATTR(municipality_name)
 ATTR(county_name)
 ATTR(state_name)
+ATTR(message)
 ATTR2(0x0003ffff,type_string_end)
 ATTR2(0x00040000,type_special_begin)
 ATTR(order)
index f6ba47a..5904795 100644 (file)
@@ -95,7 +95,7 @@ message_cleanup(struct messagelist *this_)
 
        i = 0;
        while (msg && (i < this_->maxnum)) {
-               if ((now - msg->time) > this_->maxage) {
+               if ((this_->maxage > 0) && (now - msg->time) > this_->maxage) {
                        break;
                }
 
index bca3447..cbd7c32 100644 (file)
@@ -1623,6 +1623,9 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
                if (attr_updated && !init) 
                        navit_draw(this_);
                break;
+       case attr_message:
+               navit_add_message(this_, attr->u.str);
+               break;
        default:
                return 0;
        }
@@ -1643,7 +1646,37 @@ navit_set_attr(struct navit *this_, struct attr *attr)
 int
 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
 {
+       struct message *msg;
+       int len,offset;
+
        switch (type) {
+       case attr_message:
+               msg = navit_get_messages(this_);
+               
+               if (!msg) {
+                       return 0;
+               }
+
+               len = 0;
+               while (msg) {
+                       len += strlen(msg->text) + 1;
+                       msg = msg->next;
+               }
+               attr->u.str = g_malloc(len + 1);
+               
+               msg = navit_get_messages(this_);
+               offset = 0;
+               while (msg) {
+                       g_stpcpy((attr->u.str + offset), msg->text);
+                       offset += strlen(msg->text);
+                       attr->u.str[offset] = '\n';
+                       offset++;
+
+                       msg = msg->next;
+               }
+
+               attr->u.str[len] = '\0';
+               break;
        case attr_bookmark_map:
                attr->u.map=this_->bookmark;
                break;