noinst_LTLIBRARIES = libnavit.la
libnavit_la_SOURCES = atom.c attr.c cache.c callback.c command.c compass.c coord.c country.c cursor.c data_window.c debug.c \
event.c event_glib.h 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 \
+ mapset.c maptype.c menu.c messages.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
profile.c projection.c route.c search.c speech.c transform.c track.c \
util.c vehicle.c xmlconfig.c atom.h attr.h attr_def.h cache.h callback.h color.h command.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 event.h \
file.h graphics.h gtkext.h gui.h item.h item_def.h keys.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 \
+ map_data.h mapset.h maptype.h menu.h messages.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 \
transform.h track.h util.h vehicle.h window.h xmlconfig.h zipfile.h \
navit_nls.h
ATTR(autozoom_min)
ATTR(maxspeed)
ATTR(cdf_histsize)
+ATTR(message_maxage)
+ATTR(message_maxnum)
ATTR2(0x00028000,type_boolean_begin)
/* boolean */
ATTR(overwrite)
--- /dev/null
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+#include <time.h>
+#include "messages.h"
+#include "callback.h"
+#include "event.h"
+#include "attr.h"
+
+struct messagelist {
+ struct message *messages; /**< All the messages that can currently be shown */
+ int last_mid; /**< Last Message ID */
+ int maxage; /**< Maximum age of messages */
+ int maxnum; /**< Maximum number of messages */
+ struct callback *msg_cleanup_cb; /**< Callback to clean up the messages */
+ struct event_idle *msg_cleanup_ev; /**< Idle event to clean up the messages */
+};
+
+int
+message_new(struct messagelist *this_, char *message)
+{
+ struct message *msg;
+
+ msg = g_new0(struct message, 1);
+ msg->text = g_strdup(message);
+ msg->id = ++(this_->last_mid);
+ msg->time = time(NULL);
+
+ msg->next = this_->messages;
+ this_->messages = msg;
+
+ return msg->id;
+}
+
+int
+message_delete(struct messagelist *this_, int mid)
+{
+ struct message *msg,*last;;
+
+ msg = this_->messages;
+ last = NULL;
+
+ while (msg) {
+ if (msg->id == mid) {
+ break;
+ }
+
+ last = msg;
+ msg = msg->next;
+ }
+
+ if (msg) {
+ if (last) {
+ last->next = msg->next;
+ } else {
+ this_->messages = msg->next;
+ }
+
+ g_free(msg->text);
+ g_free(msg);
+
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+static void
+message_cleanup(struct messagelist *this_)
+{
+ struct message *msg,*next,*prev=NULL;
+ int i;
+ time_t now;
+
+ msg = this_->messages;
+
+ now = time(NULL);
+
+ i = 0;
+ while (msg && (i < this_->maxnum)) {
+ if ((now - msg->time) > this_->maxage) {
+ break;
+ }
+
+ i++;
+ prev = msg;
+ msg = msg->next;
+ }
+
+ if (prev) {
+ prev->next = NULL;
+ } else {
+ this_->messages = NULL;
+ }
+
+ while (msg) {
+ next = msg->next;
+
+ g_free(msg->text);
+ g_free(msg);
+
+ msg = next;
+ }
+}
+
+struct messagelist
+*messagelist_new(struct attr **attrs)
+{
+ struct messagelist *this = g_new0(struct messagelist, 1);
+ struct attr num_attr,age_attr;
+
+ if (attr_generic_get_attr(attrs, NULL, attr_message_maxage, &age_attr, NULL)) {
+ this->maxage = age_attr.u.num;
+ } else {
+ this->maxage = 10;
+ }
+
+ if (attr_generic_get_attr(attrs, NULL, attr_message_maxnum, &num_attr, NULL)) {
+ this->maxnum = num_attr.u.num;
+ } else {
+ this->maxnum = 3;
+ }
+
+ return this;
+}
+
+void
+messagelist_init(struct messagelist *this_)
+{
+ this_->msg_cleanup_cb = callback_new_1(callback_cast(message_cleanup), this_);
+ this_->msg_cleanup_ev = event_add_idle(150, this_->msg_cleanup_cb);
+}
+
+struct message
+*message_get(struct messagelist *this_)
+{
+ return this_->messages;
+}
--- /dev/null
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef NAVIT_MESSAGES_H
+#define NAVIT_MESSAGES_H
+
+struct messagelist;
+
+struct message {
+ struct message *next;
+ int id;
+ time_t time;
+ char *text;
+};
+
+/* Prototypes */
+struct attr;
+
+int message_new(struct messagelist *this_, char *message);
+int message_delete(struct messagelist *this_, int mid);
+struct messagelist *messagelist_new(struct attr **attrs);
+void messagelist_init(struct messagelist *this_);
+struct message *message_get(struct messagelist *this_);
+
+#endif
#include "command.h"
#include "navit_nls.h"
#include "util.h"
+#include "messages.h"
/**
* @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
int w,h;
int drag_bitmap;
int use_mousewheel;
+ struct messagelist *messages;
struct callback *resize_callback,*button_callback,*motion_callback;
};
}
this_->displaylist=graphics_displaylist_new();
command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
+
+ this_->messages = messagelist_new(attrs);
+
return this_;
}
return 1;
}
+void
+navit_add_message(struct navit *this_, char *message)
+{
+ message_new(this_->messages, message);
+}
+
+struct message
+*navit_get_messages(struct navit *this_)
+{
+ return message_get(this_->messages);
+}
+
static int
navit_set_graphics(struct navit *this_, struct graphics *gra)
{
while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
speech_say(this_->speech, attr.u.str);
+ navit_add_message(this_, attr.u.str);
navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
}
map_rect_destroy(mr);
#endif
callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
this_->ready|=1;
+
+ messagelist_init(this_->messages);
+
if (this_->ready == 3)
navit_draw(this_);
}