summaryrefslogtreecommitdiff
path: root/navit/layout.c
diff options
context:
space:
mode:
authorlains <lains@caramail.com>2018-11-18 22:59:14 +0100
committerPierre GRANDIN <pgrandin@users.noreply.github.com>2018-11-18 13:59:14 -0800
commite70a28963ff9754d3257361fad93aebf59edee08 (patch)
tree07a97ee212611ff4d1156baf87b8744f5d2b9ba4 /navit/layout.c
parentb0773218ab67e00e1aa7303829f342dce87c46c0 (diff)
downloadnavit-e70a28963ff9754d3257361fad93aebf59edee08.tar.gz
Refactoring:Xmlconfig:Moving layout definition in their own .xml file (makes main navit.xml file lighter) (#559)
Layouts contain quite heavy xml code, and there are many layouts available for navit. They are all inserted inside the main navit.xml, which makes it hard to edit because of its size, even if changes or customizations by users are very rarely on the layout code. I have thus moved the layout code away from navit.xml, each layout having its own xml definition file, called navit_layout_*.xml These files are inserted inside the main navit.xml file by using the already existing xi:include mechanism, this also allow for backwards compatibility (old monolithic navit.xml files are still valid and can be used). The other advantage for this is that f the user wants to have his/her own customized navit.xml, he/she can still include the shipped layout files, making their xml lighter. This also allow to enable/disable specific layouts easily by including or not each layout file. It is also easier to perform side-by-side comparison between two layout files.
Diffstat (limited to 'navit/layout.c')
-rw-r--r--navit/layout.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/navit/layout.c b/navit/layout.c
index 25f60bc4b..f2f3d1a75 100644
--- a/navit/layout.c
+++ b/navit/layout.c
@@ -25,15 +25,31 @@
#include "layout.h"
#include "coord.h"
#include "debug.h"
+#include "navit.h"
-
-struct layout * layout_new(struct attr *parent, struct attr **attrs) {
+/**
+ * @brief Create a new layout object and attach it to a navit parent
+ *
+ * @param parent The parent for this layout (a navit attr)
+ * @param attrs An array of attributes that for this layout
+ * @return The newly created layout object
+ */
+struct layout *
+layout_new(struct attr *parent, struct attr **attrs) {
struct layout *l;
+ struct navit *navit;
struct color def_color = {COLOR_BACKGROUND_};
struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_attr;
if (! (name_attr=attr_search(attrs, NULL, attr_name)))
return NULL;
+ navit = parent->u.navit;
+ if (navit_get_layout_by_name(navit, name_attr->u.str)) {
+ dbg(lvl_warning, "Another layout with name '%s' has already been parsed. Discarding subsequent duplicate.",
+ name_attr->u.str);
+ return NULL;
+ }
+
l = g_new0(struct layout, 1);
l->func=&layout_func;
navit_object_ref((struct navit_object *)l);
@@ -55,7 +71,7 @@ struct layout * layout_new(struct attr *parent, struct attr **attrs) {
l->order_delta=order_delta_attr->u.num;
if ((active_attr=attr_search(attrs, NULL, attr_active)))
l->active = active_attr->u.num;
- l->navit=parent->u.navit;
+ l->navit=navit;
return l;
}