@@ -434,27 +434,44 @@ FrogPilotLongitudinalPanel::FrogPilotLongitudinalPanel(FrogPilotSettingsWindow *
434434 weatherKeyControl->setVisibleButton (1 , true );
435435 }
436436 }
437- } else {
437+ } else if (id == 1 ) {
438438 weatherKeyControl->setValue (tr (" Testing..." ));
439439
440- QString key = QString::fromStdString (params.get (" WeatherToken" ));
441- QString url = QString (" https://api.openweathermap.org/data/2.5/weather ?lat=42.4293&lon=-83.9850&appid=%1" ).arg (key);
440+ QString key = QString::fromStdString (params.get (" WeatherToken" )). trimmed () ;
441+ QString url30 = QString (" https://api.openweathermap.org/data/3.0/onecall ?lat=42.4293&lon=-83.9850&exclude=current,minutely,hourly,daily,alerts &appid=%1" ).arg (key);
442442
443- QNetworkRequest request (url );
443+ QNetworkRequest request (url30 );
444444 QNetworkReply *reply = networkManager->get (request);
445- connect (reply, &QNetworkReply::finished, [=]() {
446- weatherKeyControl-> setValue ( " " );
445+ QObject:: connect (reply, &QNetworkReply::finished, this , [=]() {
446+ reply-> deleteLater ( );
447447
448- QString message;
449448 if (reply->error () == QNetworkReply::NoError) {
450- message = tr (" Key is valid!" );
451- } else if (reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt () == 401 ) {
452- message = tr (" Invalid key!" );
449+ weatherKeyControl->setValue (" " );
450+ ConfirmationDialog::alert (tr (" Key is valid!" ), this );
451+ return ;
452+ }
453+
454+ int status = reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt ();
455+ if (status == 401 || status == 403 ) {
456+ QString url25 = QString (" https://api.openweathermap.org/data/2.5/weather?lat=42.4293&lon=-83.9850&appid=%1" ).arg (key);
457+
458+ QNetworkRequest request25 (url25);
459+ QNetworkReply *reply25 = networkManager->get (request25);
460+ QObject::connect (reply25, &QNetworkReply::finished, this , [=]() {
461+ reply25->deleteLater ();
462+
463+ weatherKeyControl->setValue (" " );
464+ if (reply25->error () == QNetworkReply::NoError) {
465+ ConfirmationDialog::alert (tr (" Your key is valid for version 2.5, but version 3.0 is highly recommended! Please subscribe to the \" One Call API 3.0\" plan!" ), this );
466+ } else {
467+ int status25 = reply25->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt ();
468+ ConfirmationDialog::alert (tr (" Invalid key! (Error: %1)" ).arg (status25), this );
469+ }
470+ });
453471 } else {
454- message = tr (" An error occurred: %1" ).arg (reply->errorString ());
472+ weatherKeyControl->setValue (" " );
473+ ConfirmationDialog::alert (tr (" An error occurred: %1" ).arg (reply->errorString ()), this );
455474 }
456- ConfirmationDialog::alert (message, this );
457- reply->deleteLater ();
458475 });
459476 }
460477 });
0 commit comments