summaryrefslogtreecommitdiff
path: root/navit
diff options
context:
space:
mode:
authorbustersnyvel <bustersnyvel@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-07-26 22:36:19 +0000
committerbustersnyvel <bustersnyvel@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-07-26 22:36:19 +0000
commit956fc7380aac2e92aa46401b252abcfec2be660e (patch)
tree8e5ad7edb3a139ee11137e59201327693168a8ee /navit
parent2f773b5fb3e5667e045d5b038f57ee5a412eac0b (diff)
downloadnavit-svn-956fc7380aac2e92aa46401b252abcfec2be660e.tar.gz
add:core:Selecting the vehicle profile now works, but setting it on the vehicle doesn't, ticket #396
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2406 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r--navit/gui/internal/gui_internal.c105
-rw-r--r--navit/navit.c6
-rw-r--r--navit/navit.h11
-rw-r--r--navit/vehicleprofile.c15
-rw-r--r--navit/vehicleprofile.h6
5 files changed, 142 insertions, 1 deletions
diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c
index 33f20242..68c01302 100644
--- a/navit/gui/internal/gui_internal.c
+++ b/navit/gui/internal/gui_internal.c
@@ -37,6 +37,7 @@
#include "item.h"
#include "file.h"
#include "navit.h"
+#include "navit_nls.h"
#include "debug.h"
#include "gui.h"
#include "coord.h"
@@ -49,6 +50,7 @@
#include "layout.h"
#include "callback.h"
#include "vehicle.h"
+#include "vehicleprofile.h"
#include "window.h"
#include "main.h"
#include "keys.h"
@@ -3119,6 +3121,98 @@ gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *
gui_internal_menu_render(this);
}
+/**
+ * A container to hold the selected vehicle and the desired profile in
+ * one data item.
+ */
+struct vehicle_and_profilename {
+ struct vehicle *vehicle;
+ char *profilename;
+};
+
+/**
+ * Reacts to a button press that changes a vehicle's active profile.
+ *
+ * @see gui_internal_add_vehicle_profile
+ */
+static void
+gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
+ widget *wm, void *data)
+{
+ struct vehicle_and_profilename *vapn = data;
+ struct vehicle *v = vapn->vehicle;
+ char *profilename = vapn->profilename;
+ struct attr vehicle_name_attr;
+ char *vehicle_name = NULL;
+
+ // Get the vehicle name
+ vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
+ vehicle_name = vehicle_name_attr.u.str;
+
+ dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
+ profilename);
+
+ // Change the profile name
+ struct attr profilename = {attr_profilename, {profilename}};
+ vehicle_set_attr(v, &profilename, NULL);
+}
+
+/**
+ * Adds the vehicle profile to the GUI, allowing the user to pick a
+ * profile for the currently selected vehicle.
+ */
+static void
+gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
+ *parent, struct vehicle *v, struct vehicleprofile *profile)
+{
+ // Just here to show up in the translation file, nice and close to
+ // where the translations are actually used.
+ struct attr profile_attr;
+ struct attr *attr = NULL;
+ char *name = NULL;
+ char *active_profile = NULL;
+ char *label = NULL;
+ int active;
+ struct vehicle_and_profilename *context = NULL;
+
+ static char *__profile_translations[] = {
+ _n("car"), _n("bike"), _n("pedestrian")
+ };
+
+ // Figure out the profile name
+ attr = attr_search(profile->attrs, NULL, attr_name);
+ name = attr->u.str;
+
+ // Determine whether the profile is the active one
+ vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
+ active_profile = profile_attr.u.str;
+ active = strcmp(name, active_profile) == 0;
+
+ dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
+ active_profile, active);
+
+ // Build a translatable label.
+ if(active) {
+ label = g_strdup_printf(_("Current profile: %s"), _(name));
+ } else {
+ label = g_strdup_printf(_("Change profile to: %s"), _(name));
+ }
+
+ // Create the context object (the vehicle and the desired profile)
+ context = g_new0(struct vehicle_and_profilename, 1);
+ context->vehicle = v;
+ context->profilename = name;
+
+ // Add the button
+ gui_internal_widget_append(parent,
+ gui_internal_button_new_with_callback(
+ this, label,
+ image_new_xs(this, active ? "gui_active" : "gui_inactive"),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_set_active_profile, context));
+
+ free(label);
+}
static void
gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
@@ -3126,6 +3220,8 @@ gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void
struct widget *w,*wb;
struct attr attr,active_vehicle;
struct vehicle *v=wm->data;
+ struct vehicleprofile *profile = NULL;
+
wb=gui_internal_menu(this, wm->text);
w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
gui_internal_widget_append(wb, w);
@@ -3149,6 +3245,15 @@ gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void
image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
gui_internal_cmd_show_nmea_data, wm->data));
}
+
+ // Add all the possible vehicle profiles to the menu
+ GList *profiles = navit_get_vehicleprofiles(this->nav);
+ while(profiles) {
+ profile = (struct vehicleprofile *)profiles->data;
+ gui_internal_add_vehicle_profile(this, w, v, profile);
+ profiles = g_list_next(profiles);
+ }
+
callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
gui_internal_menu_render(this);
}
diff --git a/navit/navit.c b/navit/navit.c
index 61c48783..cab07545 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -716,6 +716,12 @@ navit_get_vehicleprofile(struct navit *this_)
return this_->vehicleprofile;
}
+GList *
+navit_get_vehicleprofiles(struct navit *this_)
+{
+ return this_->vehicleprofiles;
+}
+
static void
navit_projection_set(struct navit *this_, enum projection pro)
{
diff --git a/navit/navit.h b/navit/navit.h
index 2068055e..c0ef1372 100644
--- a/navit/navit.h
+++ b/navit/navit.h
@@ -42,6 +42,13 @@ struct route;
struct tracking;
struct transformation;
struct vehicleprofile;
+
+// defined in glib.h.
+#ifndef __G_LIST_H__
+struct _GList;
+typedef struct _GList GList;
+#endif
+
void navit_add_mapset(struct navit *this_, struct mapset *ms);
struct mapset *navit_get_mapset(struct navit *this_);
struct tracking *navit_get_tracking(struct navit *this_);
@@ -61,6 +68,10 @@ void navit_add_message(struct navit *this_, char *message);
struct message *navit_get_messages(struct navit *this_);
struct graphics *navit_get_graphics(struct navit *this_);
struct vehicleprofile *navit_get_vehicleprofile(struct navit *this_);
+
+//! Returns a list of 'struct vehicleprofile *'
+GList *navit_get_vehicleprofiles(struct navit *this_);
+
void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async);
int navit_check_route(struct navit *this_);
void navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *description);
diff --git a/navit/vehicleprofile.c b/navit/vehicleprofile.c
index f6875ae9..9b2ae2a8 100644
--- a/navit/vehicleprofile.c
+++ b/navit/vehicleprofile.c
@@ -19,6 +19,7 @@
#include <glib.h>
#include <string.h>
+#include <stdlib.h>
#include "debug.h"
#include "item.h"
#include "roadprofile.h"
@@ -44,6 +45,14 @@ vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
case attr_route_mode:
this_->mode=attr->u.num;
break;
+ case attr_name:
+ if(this_->name) free(this_->name);
+
+ // Only copy the first 1024 characters. Should be enough for
+ // normal use, but still prevent ludicrous memory allocations
+ // in case of a bug somewhere.
+ this_->name = strndup(attr->u.str, 2);
+ break;
default:
break;
}
@@ -112,3 +121,9 @@ vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type
{
return g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)type);
}
+
+char *
+vehicleprofile_get_name(struct vehicleprofile *this_)
+{
+ return this_->name;
+}
diff --git a/navit/vehicleprofile.h b/navit/vehicleprofile.h
index c4249866..47ce832f 100644
--- a/navit/vehicleprofile.h
+++ b/navit/vehicleprofile.h
@@ -25,7 +25,8 @@ struct vehicleprofile {
int maxspeed_handling; /**< 0 = Always, 1 = Only if lower, 2 = Never */
int static_speed; /**< Maximum speed of vehicle to consider it stationary */
int static_distance; /**< Maximum distance of previous position of vehicle to consider it stationary */
- struct attr **attrs;
+ char *name; // the vehicle profile name
+ struct attr **attrs;
GHashTable *roadprofile_hash;
};
@@ -35,3 +36,6 @@ int vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr);
int vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr);
int vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr);
struct roadprofile * vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type);
+
+//! Returns the vehicle profile's name.
+char * vehicleprofile_get_name(struct vehicleprofile *this_);