diff --git a/selfdrive/ui/qt/api.cc b/selfdrive/ui/qt/api.cc index 1c997874e3..7c998d57a9 100644 --- a/selfdrive/ui/qt/api.cc +++ b/selfdrive/ui/qt/api.cc @@ -72,7 +72,7 @@ QString CommaApi::create_jwt(QVector> payloads, int e } -HttpRequest::HttpRequest(QObject *parent, QString requestURL, const QString &cache_key, bool create_jwt_) : cache_key(cache_key), create_jwt(create_jwt_), QObject(parent) { +HttpRequest::HttpRequest(QObject *parent, const QString &requestURL, const QString &cache_key, bool create_jwt_) : cache_key(cache_key), create_jwt(create_jwt_), QObject(parent) { networkAccessManager = new QNetworkAccessManager(this); reply = NULL; @@ -90,7 +90,7 @@ HttpRequest::HttpRequest(QObject *parent, QString requestURL, const QString &cac } } -void HttpRequest::sendRequest(QString requestURL){ +void HttpRequest::sendRequest(const QString &requestURL){ QString token; if(create_jwt) { token = CommaApi::create_jwt(); diff --git a/selfdrive/ui/qt/api.hpp b/selfdrive/ui/qt/api.hpp index 347e12f784..0ec8f8b4b4 100644 --- a/selfdrive/ui/qt/api.hpp +++ b/selfdrive/ui/qt/api.hpp @@ -33,9 +33,9 @@ class HttpRequest : public QObject { Q_OBJECT public: - explicit HttpRequest(QObject* parent, QString requestURL, const QString &cache_key = "", bool create_jwt_ = true); + explicit HttpRequest(QObject* parent, const QString &requestURL, const QString &cache_key = "", bool create_jwt_ = true); QNetworkReply *reply; - void sendRequest(QString requestURL); + void sendRequest(const QString &requestURL); private: QNetworkAccessManager *networkAccessManager; @@ -48,7 +48,7 @@ private slots: void requestFinished(); signals: - void receivedResponse(QString response); - void failedResponse(QString errorString); - void timeoutResponse(QString errorString); + void receivedResponse(const QString &response); + void failedResponse(const QString &errorString); + void timeoutResponse(const QString &errorString); }; diff --git a/selfdrive/ui/qt/request_repeater.cc b/selfdrive/ui/qt/request_repeater.cc index a0d4569954..651efd18bb 100644 --- a/selfdrive/ui/qt/request_repeater.cc +++ b/selfdrive/ui/qt/request_repeater.cc @@ -1,6 +1,6 @@ #include "request_repeater.hpp" -RequestRepeater::RequestRepeater(QObject *parent, QString requestURL, const QString &cacheKey, +RequestRepeater::RequestRepeater(QObject *parent, const QString &requestURL, const QString &cacheKey, int period) : HttpRequest(parent, requestURL, cacheKey) { timer = new QTimer(this); timer->setTimerType(Qt::VeryCoarseTimer); diff --git a/selfdrive/ui/qt/request_repeater.hpp b/selfdrive/ui/qt/request_repeater.hpp index c0a0a787ec..ab4489c3dc 100644 --- a/selfdrive/ui/qt/request_repeater.hpp +++ b/selfdrive/ui/qt/request_repeater.hpp @@ -3,7 +3,7 @@ class RequestRepeater : public HttpRequest { public: - RequestRepeater(QObject *parent, QString requestURL, const QString &cacheKey = "", int period = 0); + RequestRepeater(QObject *parent, const QString &requestURL, const QString &cacheKey = "", int period = 0); private: QTimer *timer; diff --git a/selfdrive/ui/qt/widgets/drive_stats.cc b/selfdrive/ui/qt/widgets/drive_stats.cc index 5db55d7b8f..6f810765a5 100644 --- a/selfdrive/ui/qt/widgets/drive_stats.cc +++ b/selfdrive/ui/qt/widgets/drive_stats.cc @@ -22,9 +22,8 @@ static QLayout* build_stat_layout(QLabel** metric, const QString& name) { return layout; } -void DriveStats::parseResponse(QString response) { - response = response.trimmed(); - QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); +void DriveStats::parseResponse(const QString& response) { + QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8()); if (doc.isNull()) { qDebug() << "JSON Parse failed on getting past drives statistics"; return; @@ -66,5 +65,5 @@ DriveStats::DriveStats(QWidget* parent) : QWidget(parent) { QString dongleId = QString::fromStdString(Params().get("DongleId")); QString url = "https://api.commadotai.com/v1.1/devices/" + dongleId + "/stats"; RequestRepeater *repeater = new RequestRepeater(this, url, "ApiCache_DriveStats", 13); - QObject::connect(repeater, SIGNAL(receivedResponse(QString)), this, SLOT(parseResponse(QString))); + QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &DriveStats::parseResponse); } diff --git a/selfdrive/ui/qt/widgets/drive_stats.hpp b/selfdrive/ui/qt/widgets/drive_stats.hpp index 64b93cfe73..d90e296b41 100644 --- a/selfdrive/ui/qt/widgets/drive_stats.hpp +++ b/selfdrive/ui/qt/widgets/drive_stats.hpp @@ -14,5 +14,5 @@ private: } all_, week_; private slots: - void parseResponse(QString response); + void parseResponse(const QString &response); }; diff --git a/selfdrive/ui/qt/widgets/setup.cc b/selfdrive/ui/qt/widgets/setup.cc index a0480ed1a7..b5702c4c81 100644 --- a/selfdrive/ui/qt/widgets/setup.cc +++ b/selfdrive/ui/qt/widgets/setup.cc @@ -105,10 +105,10 @@ PrimeUserWidget::PrimeUserWidget(QWidget* parent) : QWidget(parent) { QString url = "https://api.commadotai.com/v1/devices/" + dongleId + "/owner"; RequestRepeater *repeater = new RequestRepeater(this, url, "ApiCache_Owner", 6); - QObject::connect(repeater, SIGNAL(receivedResponse(QString)), this, SLOT(replyFinished(QString))); + QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &PrimeUserWidget::replyFinished); } -void PrimeUserWidget::replyFinished(QString response) { +void PrimeUserWidget::replyFinished(const QString &response) { QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); if (doc.isNull()) { qDebug() << "JSON Parse failed on getting username and points"; @@ -238,12 +238,12 @@ SetupWidget::SetupWidget(QWidget* parent) : QFrame(parent) { QString url = "https://api.commadotai.com/v1.1/devices/" + dongleId + "/"; RequestRepeater* repeater = new RequestRepeater(this, url, "ApiCache_Device", 5); - QObject::connect(repeater, SIGNAL(receivedResponse(QString)), this, SLOT(replyFinished(QString))); - QObject::connect(repeater, SIGNAL(failedResponse(QString)), this, SLOT(parseError(QString))); + QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &SetupWidget::replyFinished); + QObject::connect(repeater, &RequestRepeater::failedResponse, this, &SetupWidget::parseError); hide(); // Only show when first request comes back } -void SetupWidget::parseError(QString response) { +void SetupWidget::parseError(const QString &response) { show(); showQr = false; mainLayout->setCurrentIndex(0); @@ -254,7 +254,7 @@ void SetupWidget::showQrCode(){ mainLayout->setCurrentIndex(1); } -void SetupWidget::replyFinished(QString response) { +void SetupWidget::replyFinished(const QString &response) { show(); QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); if (doc.isNull()) { diff --git a/selfdrive/ui/qt/widgets/setup.hpp b/selfdrive/ui/qt/widgets/setup.hpp index 0479db8f95..2c5f51bcc9 100644 --- a/selfdrive/ui/qt/widgets/setup.hpp +++ b/selfdrive/ui/qt/widgets/setup.hpp @@ -33,7 +33,7 @@ private: CommaApi* api; private slots: - void replyFinished(QString response); + void replyFinished(const QString &response); }; class PrimeAdWidget : public QWidget { @@ -56,7 +56,7 @@ private: bool showQr = false; private slots: - void parseError(QString response); - void replyFinished(QString response); + void parseError(const QString &response); + void replyFinished(const QString &response); void showQrCode(); };