Skip to content

Commit

Permalink
Fix: Configuration dialog fixes. Provider data units fix. Bump to ver…
Browse files Browse the repository at this point in the history
…sion 1.31.1
  • Loading branch information
FelixdelasPozas committed Jan 4, 2025
1 parent 55855cb commit 020744c
Show file tree
Hide file tree
Showing 22 changed files with 1,779 additions and 1,401 deletions.
2 changes: 1 addition & 1 deletion AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <QDateTime>
#include <QApplication>

const QString AboutDialog::VERSION{"1.31.0"};
const QString AboutDialog::VERSION{"1.31.1"};
const QString COPYRIGHT{"Copyright (c) 2016-%1 Félix de las Pozas Álvarez"};

//-----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(TrayWeather)
# Version Number
set (TRAYWEATHER_VERSION_MAJOR 1)
set (TRAYWEATHER_VERSION_MINOR 31)
set (TRAYWEATHER_VERSION_PATCH 0)
set (TRAYWEATHER_VERSION_PATCH 1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
49 changes: 41 additions & 8 deletions ConfigurationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ void ConfigurationDialog::replyFinished(QNetworkReply* reply)

m_ipapiLabel->setStyleSheet("QLabel { color : green; }");
m_ipapiLabel->setText(tr("Success"));

m_latitudeSpin->setValue(values.at(7).toDouble());
m_longitudeSpin->setValue(values.at(8).toDouble());

reply->deleteLater();

return;
Expand Down Expand Up @@ -395,10 +399,39 @@ void ConfigurationDialog::requestDNSIPGeolocation()
}

//--------------------------------------------------------------------
void ConfigurationDialog::requestAPIKeyTest() const
void ConfigurationDialog::requestAPIKeyTest()
{
if(m_provider)
const double latitude = m_latitudeSpin->value();
const double longitude = m_longitudeSpin->value();

if(m_apikey->text().isEmpty())
{
QMessageBox msgbox(this);
msgbox.setWindowTitle(tr("API Key Error"));
msgbox.setWindowIcon(QIcon(":/TrayWeather/application.svg"));
msgbox.setText(tr("API key missing!"));
msgbox.exec();
return;
}

if((latitude > 90.0) || (latitude < -90.0) || (longitude > 180.0) || (longitude < -180.0))
{
QMessageBox msgbox(this);
msgbox.setWindowTitle(tr("Location Error"));
msgbox.setWindowIcon(QIcon(":/TrayWeather/application.svg"));
msgbox.setText(tr("You must set a valid location before testing the API key."));
msgbox.exec();
return;
}

m_config.latitude = latitude;
m_config.longitude = longitude;

if(m_provider && m_provider->capabilities().requiresKey)
{
m_provider->setApiKey(m_apikey->text());
m_provider->testApiKey(m_netManager);
}

m_apiTest->setEnabled(false);
m_testLabel->setStyleSheet("QLabel { color : blue; }");
Expand Down Expand Up @@ -437,10 +470,10 @@ void ConfigurationDialog::connectSignals()
this, SLOT(onDNSRequestStateChanged(int)));

connect(m_useGeolocation, SIGNAL(toggled(bool)),
this, SLOT(onRadioChanged()));
this, SLOT(onLocationRadioChanged()));

connect(m_useManual, SIGNAL(toggled(bool)),
this, SLOT(onRadioChanged()));
this, SLOT(onLocationRadioChanged()));

connect(m_longitudeSpin, SIGNAL(editingFinished()),
this, SLOT(onCoordinatesChanged()));
Expand Down Expand Up @@ -553,7 +586,7 @@ void ConfigurationDialog::disconnectProviderSignals()
}

//--------------------------------------------------------------------
void ConfigurationDialog::onRadioChanged()
void ConfigurationDialog::onLocationRadioChanged()
{
auto manualEnabled = m_useManual->isChecked();

Expand Down Expand Up @@ -905,7 +938,7 @@ void ConfigurationDialog::setConfiguration(const Configuration &configuration)
}

// this requests geolocation if checked.
onRadioChanged();
onLocationRadioChanged();
onCoordinatesChanged();

if(configuration.isValid())
Expand Down Expand Up @@ -969,10 +1002,10 @@ void ConfigurationDialog::disconnectSignals()
this, SLOT(onDNSRequestStateChanged(int)));

disconnect(m_useGeolocation, SIGNAL(toggled(bool)),
this, SLOT(onRadioChanged()));
this, SLOT(onLocationRadioChanged()));

disconnect(m_useManual, SIGNAL(toggled(bool)),
this, SLOT(onRadioChanged()));
this, SLOT(onLocationRadioChanged()));

disconnect(m_longitudeSpin, SIGNAL(editingFinished()),
this, SLOT(onCoordinatesChanged()));
Expand Down
4 changes: 2 additions & 2 deletions ConfigurationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ConfigurationDialog
/** \brief Request test of API key validity.
*
*/
void requestAPIKeyTest() const;
void requestAPIKeyTest();

/** \brief Disables/Enables geolocation from DNS IP instead of geolocation detected ip.
* \param[in] state DNS Checkbox state.
Expand All @@ -125,7 +125,7 @@ class ConfigurationDialog
/** \brief Helper method that enables/disables part of the UI depending on the state of the UI radio buttons.
*
*/
void onRadioChanged();
void onLocationRadioChanged();

/** \brief Helper method that updates the coordinates labels when one changes.
*
Expand Down
4 changes: 4 additions & 0 deletions Provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ void OpenMeteoProvider::processWeatherData(const QByteArray &contents)
m_current.country = "Unknown";

fillWMOCodeInForecast(m_current);
changeWeatherUnits(m_config, m_current);

emit weatherDataReady();
}
Expand Down Expand Up @@ -773,7 +774,10 @@ void OpenMeteoProvider::processWeatherData(const QByteArray &contents)
fillWMOCodeInForecast(data);

if(!hasEntry(data.dt))
{
changeWeatherUnits(m_config, data);
m_forecast << data;
}
}

if(!m_forecast.isEmpty())
Expand Down
77 changes: 75 additions & 2 deletions Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ void load(Configuration &configuration)
configuration.showAlerts = settings.value(SHOW_ALERTS, true).toBool();
configuration.swapTrayIcons = settings.value(TRAY_SWAP_ICONS, false).toBool();
configuration.trayIconSize = settings.value(TRAY_ICON_SIZE, 100).toInt();
configuration.tempRepr = static_cast<Representation>(settings.value(GRAPH_TEMP_REPR, 2).toInt());
configuration.rainRepr = static_cast<Representation>(settings.value(GRAPH_RAIN_REPR, 3).toInt());
configuration.tempRepr = static_cast<Representation>(settings.value(GRAPH_TEMP_REPR, 1).toInt());
configuration.rainRepr = static_cast<Representation>(settings.value(GRAPH_RAIN_REPR, 2).toInt());
configuration.snowRepr = static_cast<Representation>(settings.value(GRAPH_SNOW_REPR, 0).toInt());
configuration.tempReprColor = QColor(settings.value(GRAPH_TEMP_COLOR, "#FF0000FF").toString());
configuration.rainReprColor = QColor(settings.value(GRAPH_RAIN_COLOR, "#FF00FF00").toString());
Expand Down Expand Up @@ -1344,6 +1344,79 @@ void fillWMOCodeInForecast(ForecastData &forecast)
}
}

//--------------------------------------------------------------------
void changeWeatherUnits(const Configuration &config, ForecastData &forecast)
{
switch (config.units)
{
default:
case Units::METRIC:
return;
break;
case Units::IMPERIAL:
forecast.rain = convertMmToInches(forecast.rain);
forecast.snow = convertMmToInches(forecast.snow);
forecast.pressure = converthPaToinHg(forecast.pressure);
forecast.temp = convertCelsiusToFahrenheit(forecast.temp);
forecast.temp_max = convertCelsiusToFahrenheit(forecast.temp_max);
forecast.temp_min = convertCelsiusToFahrenheit(forecast.temp_min);
forecast.wind_speed = convertMetersSecondToMilesHour(forecast.wind_speed);
break;
case Units::CUSTOM:
{
switch (config.precUnits)
{
case PrecipitationUnits::INCH:
forecast.rain = convertMmToInches(forecast.rain);
forecast.snow = convertMmToInches(forecast.snow);
break;
default:
case PrecipitationUnits::MM:
break;
}
switch (config.windUnits)
{
case WindUnits::FEETSEC:
forecast.wind_speed = convertMetersSecondToFeetSecond(forecast.wind_speed);
break;
case WindUnits::KMHR:
forecast.wind_speed = convertMetersSecondToKilometersHour(forecast.wind_speed);
break;
case WindUnits::MILHR:
forecast.wind_speed = convertMetersSecondToMilesHour(forecast.wind_speed);
break;
case WindUnits::KNOTS:
forecast.wind_speed = convertMetersSecondToKnots(forecast.wind_speed);
break;
default:
case WindUnits::METSEC:
break;
}
switch (config.tempUnits)
{
case TemperatureUnits::FAHRENHEIT:
forecast.temp = convertCelsiusToFahrenheit(forecast.temp);
forecast.temp_min = convertCelsiusToFahrenheit(forecast.temp_min);
forecast.temp_max = convertCelsiusToFahrenheit(forecast.temp_max);
break;
default:
case TemperatureUnits::CELSIUS:
break;
}
switch(config.pressureUnits)
{
case PressureUnits::INHG:
forecast.pressure = converthPaToinHg(forecast.pressure);
break;
default:
case PressureUnits::HPA:
break;
}
break;
}
}
}

//--------------------------------------------------------------------
QNetworkReply *NetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
Expand Down
7 changes: 7 additions & 0 deletions Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,13 @@ QSettings applicationSettings();
*/
void fillWMOCodeInForecast(ForecastData &forecast);

/** \brief Changes the weather units of the forecast data according to the given configuration.
* \param[in] config Configuration struct reference.
* \param[in] forecast ForecastData object reference.
*
*/
void changeWeatherUnits(const Configuration &config, ForecastData &forecast);

/** \class CustomComboBox
* \brief ComboBox that uses rich text for selected item.
*
Expand Down
7 changes: 4 additions & 3 deletions WeatherDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,9 +1238,9 @@ void WeatherDialog::showEvent(QShowEvent *e)
const auto wSize = size();
if(wSize.width() < 717 || wSize.height() < 515) setFixedSize(717, 515);

if(m_config->mapsEnabled)
if (m_config->mapsEnabled && m_provider && m_provider->capabilities().hasMaps)
{
if(!mapsEnabled())
if (!mapsEnabled())
{
onMapsButtonPressed();
}
Expand All @@ -1251,7 +1251,8 @@ void WeatherDialog::showEvent(QShowEvent *e)
}
else
{
if(mapsEnabled()) onMapsButtonPressed();
if (mapsEnabled())
onMapsButtonPressed();
}
}

Expand Down
Loading

0 comments on commit 020744c

Please sign in to comment.