2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
31 #include "transform.h"
34 #include "navigation.h"
36 #include "navit_nls.h"
38 struct statusbar_priv {
45 struct callback *vehicle_cb;
52 statusbar_destroy(struct statusbar_priv *this)
58 statusbar_gps_update(struct statusbar_priv *this, int sats, int qual, double lng, double lat, double height, double direction, double speed)
62 char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
74 dir_idx=(direction+22.5)/45;
76 sprintf(this->gps_text, "GPS %2d/%1d %02.0f%07.4f%c %03.0f%07.4f%c %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, floor(lat), fmod(lat*60,60), lat_c, floor(lng), fmod(lng*60,60), lng_c, height, direction, dir, speed);
77 gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
82 statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct vehicle *v)
84 struct navigation *nav=NULL;
86 struct map_rect *mr=NULL;
87 struct item *item=NULL;
91 struct tm *eta_tm=NULL;
93 double lng, lat, direction=0, height=0, speed=0;
97 char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
102 nav=navit_get_navigation(navit);
104 map=navigation_get_map(nav);
106 mr=map_rect_new(map, NULL);
108 item=map_rect_get_item(mr);
110 if (item_attr_get(item, attr_destination_length, &attr))
111 route_len=attr.u.num;
112 if (item_attr_get(item, attr_destination_time, &attr)) {
113 eta=time(NULL)+attr.u.num/10;
114 eta_tm=localtime(&eta);
118 map_rect_destroy(mr);
119 sprintf(buffer,_("Route %4.0fkm %02d:%02d ETA" ),route_len/1000, eta_tm ? eta_tm->tm_hour : 0 , eta_tm ? eta_tm->tm_min : 0);
120 if (strcmp(buffer, this->route_text)) {
121 strcpy(this->route_text, buffer);
122 gtk_label_set_text(GTK_LABEL(this->route), this->route_text);
124 if (!vehicle_get_attr(v, attr_position_coord_geo, &attr, NULL))
126 lng=attr.u.coord_geo->lng;
127 lat=attr.u.coord_geo->lat;
136 if (vehicle_get_attr(v, attr_position_direction, &attr, NULL))
137 direction=*(attr.u.numd);
138 direction=fmod(direction,360);
141 dir_idx=(direction+22.5)/45;
143 if (vehicle_get_attr(v, attr_position_height, &attr, NULL))
144 height=*(attr.u.numd);
145 if (vehicle_get_attr(v, attr_position_speed, &attr, NULL))
146 speed=*(attr.u.numd);
147 if (vehicle_get_attr(v, attr_position_sats_used, &attr, NULL))
149 if (vehicle_get_attr(v, attr_position_qual, &attr, NULL))
151 sprintf(this->gps_text,"GPS %2d/%1d %02.0f%07.4f%c %03.0f%07.4f%c %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, floor(lat), fmod(lat*60,60), lat_c, floor(lng), fmod(lng*60,60), lng_c, height, direction, dir, speed);
152 gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
155 struct statusbar_priv *
156 gui_gtk_statusbar_new(struct gui_priv *gui)
158 struct statusbar_priv *this=g_new0(struct statusbar_priv, 1);
161 this->hbox=gtk_hbox_new(FALSE, 1);
162 this->gps=gtk_label_new( "GPS 00/0 0000.0000N 00000.0000E 0000m 000°NO 000km/h" );
163 gtk_label_set_justify(GTK_LABEL(this->gps), GTK_JUSTIFY_LEFT);
164 this->route=gtk_label_new( _( "Route 0000km 0+00:00 ETA" ) );
165 gtk_label_set_justify(GTK_LABEL(this->route), GTK_JUSTIFY_LEFT);
166 gtk_box_pack_start(GTK_BOX(this->hbox), this->gps, TRUE, TRUE, 2);
167 gtk_box_pack_start(GTK_BOX(this->hbox), gtk_vseparator_new(), TRUE, TRUE, 2);
168 gtk_box_pack_start(GTK_BOX(this->hbox), this->route, TRUE, TRUE, 2);
169 GTK_WIDGET_UNSET_FLAGS (this->hbox, GTK_CAN_FOCUS);
171 gtk_box_pack_end(GTK_BOX(gui->vbox), this->hbox, FALSE, FALSE, 0);
172 gtk_widget_show_all(this->hbox);
173 /* add a callback for position updates */
174 this->vehicle_cb=callback_new_attr_1(callback_cast(statusbar_route_update), attr_position_coord_geo, this);
175 navit_add_callback(gui->nav, this->vehicle_cb);