@ -4,6 +4,7 @@
# include "selfdrive/ui/qt/request_repeater.h"
# include "selfdrive/ui/qt/widgets/controls.h"
# include "selfdrive/ui/qt/util.h"
# include "selfdrive/common/util.h"
static QString shorten ( const QString & str , int max_len ) {
@ -47,8 +48,21 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
main_layout - > addLayout ( home_work_layout ) ;
main_layout - > addSpacing ( 50 ) ;
main_layout - > addWidget ( horizontal_line ( ) ) ;
main_layout - > addSpacing ( 50 ) ;
// Recents
QLabel * recent = new QLabel ( " Recent " ) ;
recent - > setStyleSheet ( R " (font-size: 55px;) " ) ;
main_layout - > addWidget ( recent ) ;
main_layout - > addSpacing ( 20 ) ;
recent_layout = new QVBoxLayout ;
main_layout - > addLayout ( recent_layout ) ;
// Settings
main_layout - > addSpacing ( 50 ) ;
main_layout - > addWidget ( horizontal_line ( ) ) ;
main_layout - > addWidget ( new ParamControl ( " NavSettingTime24h " ,
" Show ETA in 24h format " ,
" Use 24h format instead of am/pm " ,
@ -60,10 +74,27 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
std : : string dongle_id = Params ( ) . get ( " DongleId " ) ;
if ( util : : is_valid_dongle_id ( dongle_id ) ) {
// Fetch favorite and recent locations
{
std : : string url = " https://api.commadotai.com/v1/navigation/ " + dongle_id + " /locations " ;
RequestRepeater * repeater = new RequestRepeater ( this , QString : : fromStdString ( url ) , " ApiCache_NavDestinations " , 30 ) ;
QObject : : connect ( repeater , & RequestRepeater : : receivedResponse , this , & MapPanel : : parseResponse ) ;
}
// Destination set while offline
{
std : : string url = " https://api.commadotai.com/v1/navigation/ " + dongle_id + " /next " ;
RequestRepeater * repeater = new RequestRepeater ( this , QString : : fromStdString ( url ) , " " , 10 ) ;
QObject : : connect ( repeater , & RequestRepeater : : receivedResponse , [ ] ( QString resp ) {
auto params = Params ( ) ;
if ( resp ! = " null " & & params . get ( " NavDestination " ) . empty ( ) ) {
params . put ( " NavDestination " , resp . toStdString ( ) ) ;
}
} ) ;
}
}
}
void MapPanel : : clear ( ) {
@ -76,6 +107,8 @@ void MapPanel::clear() {
work_address - > setStyleSheet ( R " (font-size: 50px; color: grey;) " ) ;
work_address - > setText ( " No work \n location set " ) ;
work_button - > disconnect ( ) ;
clearLayout ( recent_layout ) ;
}
@ -88,6 +121,7 @@ void MapPanel::parseResponse(const QString &response) {
clear ( ) ;
bool has_recents = false ;
for ( auto location : doc . array ( ) ) {
auto obj = location . toObject ( ) ;
@ -96,8 +130,7 @@ void MapPanel::parseResponse(const QString &response) {
auto name = obj [ " place_name " ] . toString ( ) ;
auto details = shorten ( obj [ " place_details " ] . toString ( ) , 30 ) ;
if ( type = = " favorite " ) {
if ( label = = " home " ) {
if ( type = = " favorite " & & label = = " home " ) {
home_address - > setText ( name ) ;
home_address - > setStyleSheet ( R " (font-size: 50px; color: white;) " ) ;
home_button - > setIcon ( QPixmap ( " ../assets/navigation/home.png " ) ) ;
@ -105,7 +138,7 @@ void MapPanel::parseResponse(const QString &response) {
navigateTo ( obj ) ;
emit closeSettings ( ) ;
} ) ;
} else if ( label = = " work " ) {
} else if ( type = = " favorite " & & label = = " work " ) {
work_address - > setText ( name ) ;
work_address - > setStyleSheet ( R " (font-size: 50px; color: white;) " ) ;
work_button - > setIcon ( QPixmap ( " ../assets/navigation/work.png " ) ) ;
@ -113,8 +146,48 @@ void MapPanel::parseResponse(const QString &response) {
navigateTo ( obj ) ;
emit closeSettings ( ) ;
} ) ;
} else {
ClickableWidget * widget = new ClickableWidget ;
QHBoxLayout * layout = new QHBoxLayout ( widget ) ;
layout - > setContentsMargins ( 40 , 10 , 40 , 10 ) ;
QLabel * recent_label = new QLabel ( name + " " + details ) ;
recent_label - > setStyleSheet ( R " (font-size: 50px; color: #9c9c9c) " ) ;
layout - > addWidget ( recent_label ) ;
layout - > addStretch ( ) ;
QLabel * arrow = new QLabel ( " → " ) ;
arrow - > setStyleSheet ( R " (font-size: 60px;) " ) ;
layout - > addWidget ( arrow ) ;
widget - > setStyleSheet ( R " (
. ClickableWidget {
border - radius : 10 px ;
border - width : 1 px ;
border - style : solid ;
border - color : gray ;
}
QWidget {
background - color : # 393939 ;
}
) " );
QObject : : connect ( widget , & ClickableWidget : : clicked , [ = ] ( ) {
navigateTo ( obj ) ;
emit closeSettings ( ) ;
} ) ;
recent_layout - > addWidget ( widget ) ;
recent_layout - > addSpacing ( 10 ) ;
has_recents = true ;
}
}
if ( ! has_recents ) {
QLabel * no_recents = new QLabel ( " no recent destinations " ) ;
no_recents - > setStyleSheet ( R " (font-size: 50px; color: #9c9c9c) " ) ;
recent_layout - > addWidget ( no_recents ) ;
}
}