13 #include "transform.h"
16 #include "navigation.h"
20 #define _(STRING) gettext(STRING)
22 struct statusbar_priv {
29 struct callback *vehicle_cb;
36 statusbar_destroy(struct statusbar_priv *this)
42 statusbar_gps_update(struct statusbar_priv *this, int sats, int qual, double lng, double lat, double height, double direction, double speed)
46 char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
58 dir_idx=(direction+22.5)/45;
60 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);
61 gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
66 statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct vehicle *v)
68 struct navigation *nav=NULL;
70 struct map_rect *mr=NULL;
71 struct item *item=NULL;
75 struct tm *eta_tm=NULL;
77 double lng, lat, direction=0, height=0, speed=0;
81 char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
86 nav=navit_get_navigation(navit);
88 map=navigation_get_map(nav);
90 mr=map_rect_new(map, NULL);
92 item=map_rect_get_item(mr);
94 if (item_attr_get(item, attr_destination_length, &attr))
96 if (item_attr_get(item, attr_destination_time, &attr)) {
97 eta=time(NULL)+attr.u.num/10;
98 eta_tm=localtime(&eta);
102 map_rect_destroy(mr);
103 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);
104 if (strcmp(buffer, this->route_text)) {
105 strcpy(this->route_text, buffer);
106 gtk_label_set_text(GTK_LABEL(this->route), this->route_text);
108 if (!vehicle_get_attr(v, attr_position_coord_geo, &attr))
110 lng=attr.u.coord_geo->lng;
111 lat=attr.u.coord_geo->lat;
120 if (vehicle_get_attr(v, attr_position_direction, &attr))
121 direction=*(attr.u.numd);
122 direction=fmod(direction,360);
125 dir_idx=(direction+22.5)/45;
127 if (vehicle_get_attr(v, attr_position_height, &attr))
128 height=*(attr.u.numd);
129 if (vehicle_get_attr(v, attr_position_speed, &attr))
130 speed=*(attr.u.numd);
131 if (vehicle_get_attr(v, attr_position_sats_used, &attr))
133 if (vehicle_get_attr(v, attr_position_qual, &attr))
135 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);
136 gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
139 struct statusbar_priv *
140 gui_gtk_statusbar_new(struct gui_priv *gui)
142 struct statusbar_priv *this=g_new0(struct statusbar_priv, 1);
145 this->hbox=gtk_hbox_new(FALSE, 1);
146 this->gps=gtk_label_new( "GPS 00/0 0000.0000N 00000.0000E 0000m 000°NO 000km/h" );
147 gtk_label_set_justify(GTK_LABEL(this->gps), GTK_JUSTIFY_LEFT);
148 this->route=gtk_label_new( _( "Route 0000km 0+00:00 ETA" ) );
149 gtk_label_set_justify(GTK_LABEL(this->route), GTK_JUSTIFY_LEFT);
150 gtk_box_pack_start(GTK_BOX(this->hbox), this->gps, TRUE, TRUE, 2);
151 gtk_box_pack_start(GTK_BOX(this->hbox), gtk_vseparator_new(), TRUE, TRUE, 2);
152 gtk_box_pack_start(GTK_BOX(this->hbox), this->route, TRUE, TRUE, 2);
153 GTK_WIDGET_UNSET_FLAGS (this->hbox, GTK_CAN_FOCUS);
155 gtk_box_pack_end(GTK_BOX(gui->vbox), this->hbox, FALSE, FALSE, 0);
156 gtk_widget_show_all(this->hbox);
157 /* add a callback for position updates */
158 this->vehicle_cb=callback_new_attr_1(callback_cast(statusbar_route_update), attr_position_coord_geo, this);
159 navit_add_callback(gui->nav, this->vehicle_cb);