|
|
@ -1,5 +1,6 @@ |
|
|
|
#include "map_settings.h" |
|
|
|
#include "map_settings.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QApplication> |
|
|
|
#include <QDebug> |
|
|
|
#include <QDebug> |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
@ -84,38 +85,8 @@ MapSettings::MapSettings(bool closeable, QWidget *parent) |
|
|
|
|
|
|
|
|
|
|
|
setStyleSheet("MapSettings { background-color: #333333; }"); |
|
|
|
setStyleSheet("MapSettings { background-color: #333333; }"); |
|
|
|
|
|
|
|
|
|
|
|
if (auto dongle_id = getDongleId()) { |
|
|
|
QObject::connect(NavigationRequest::instance(), &NavigationRequest::locationsUpdated, this, &MapSettings::parseResponse); |
|
|
|
// Fetch favorite and recent locations
|
|
|
|
QObject::connect(NavigationRequest::instance(), &NavigationRequest::nextDestinationUpdated, this, &MapSettings::updateCurrentRoute); |
|
|
|
{ |
|
|
|
|
|
|
|
QString url = CommaApi::BASE_URL + "/v1/navigation/" + *dongle_id + "/locations"; |
|
|
|
|
|
|
|
RequestRepeater* repeater = new RequestRepeater(this, url, "ApiCache_NavDestinations", 30, true); |
|
|
|
|
|
|
|
QObject::connect(repeater, &RequestRepeater::requestDone, this, &MapSettings::parseResponse); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Destination set while offline
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString url = CommaApi::BASE_URL + "/v1/navigation/" + *dongle_id + "/next"; |
|
|
|
|
|
|
|
RequestRepeater* repeater = new RequestRepeater(this, url, "", 10, true); |
|
|
|
|
|
|
|
HttpRequest* deleter = new HttpRequest(this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QObject::connect(repeater, &RequestRepeater::requestDone, [=](const QString &resp, bool success) { |
|
|
|
|
|
|
|
if (success && resp != "null") { |
|
|
|
|
|
|
|
if (params.get("NavDestination").empty()) { |
|
|
|
|
|
|
|
qWarning() << "Setting NavDestination from /next" << resp; |
|
|
|
|
|
|
|
params.put("NavDestination", resp.toStdString()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qWarning() << "Got location from /next, but NavDestination already set"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send DELETE to clear destination server side
|
|
|
|
|
|
|
|
deleter->sendRequest(url, HttpRequest::Method::DELETE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update UI (athena can set destination at any time)
|
|
|
|
|
|
|
|
updateCurrentRoute(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MapSettings::mousePressEvent(QMouseEvent *ev) { |
|
|
|
void MapSettings::mousePressEvent(QMouseEvent *ev) { |
|
|
@ -347,3 +318,43 @@ void DestinationWidget::unset(const QString &label, bool current) { |
|
|
|
|
|
|
|
|
|
|
|
setStyleSheet(styleSheet()); |
|
|
|
setStyleSheet(styleSheet()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// singleton NavigationRequest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NavigationRequest *NavigationRequest::instance() { |
|
|
|
|
|
|
|
static NavigationRequest *request = new NavigationRequest(qApp); |
|
|
|
|
|
|
|
return request; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NavigationRequest::NavigationRequest(QObject *parent) : QObject(parent) { |
|
|
|
|
|
|
|
if (auto dongle_id = getDongleId()) { |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Fetch favorite and recent locations
|
|
|
|
|
|
|
|
QString url = CommaApi::BASE_URL + "/v1/navigation/" + *dongle_id + "/locations"; |
|
|
|
|
|
|
|
RequestRepeater *repeater = new RequestRepeater(this, url, "ApiCache_NavDestinations", 30, true); |
|
|
|
|
|
|
|
QObject::connect(repeater, &RequestRepeater::requestDone, this, &NavigationRequest::locationsUpdated); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Destination set while offline
|
|
|
|
|
|
|
|
QString url = CommaApi::BASE_URL + "/v1/navigation/" + *dongle_id + "/next"; |
|
|
|
|
|
|
|
HttpRequest *deleter = new HttpRequest(this); |
|
|
|
|
|
|
|
RequestRepeater *repeater = new RequestRepeater(this, url, "", 10, true); |
|
|
|
|
|
|
|
QObject::connect(repeater, &RequestRepeater::requestDone, [=](const QString &resp, bool success) { |
|
|
|
|
|
|
|
if (success && resp != "null") { |
|
|
|
|
|
|
|
if (params.get("NavDestination").empty()) { |
|
|
|
|
|
|
|
qWarning() << "Setting NavDestination from /next" << resp; |
|
|
|
|
|
|
|
params.put("NavDestination", resp.toStdString()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qWarning() << "Got location from /next, but NavDestination already set"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Send DELETE to clear destination server side
|
|
|
|
|
|
|
|
deleter->sendRequest(url, HttpRequest::Method::DELETE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update UI (athena can set destination at any time)
|
|
|
|
|
|
|
|
emit nextDestinationUpdated(resp, success); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|