Commit 0c1332e6 authored by Volker Krause's avatar Volker Krause

Feed home country from Settings into TimelineModel

parent 5a2c23fc
......@@ -103,20 +103,23 @@ int main(int argc, char **argv)
parser.addPositionalArgument(QStringLiteral("pass"), QStringLiteral("PkPass file to import."));
parser.process(app);
Settings settings;
ApplicationController appController;
PkPassManager passMgr;
ReservationManager resMgr;
resMgr.setPkPassManager(&passMgr);
TimelineModel timelineModel;
timelineModel.setHomeCountryIsoCode(settings.homeCountryIsoCode());
timelineModel.setReservationManager(&resMgr);
ApplicationController appController;
Settings settings;
QObject::connect(&settings, &Settings::homeCountryIsoCodeChanged, &timelineModel, &TimelineModel::setHomeCountryIsoCode);
WeatherForecastManager weatherForecastMgr;
weatherForecastMgr.setAllowNetworkAccess(settings.weatherForecastEnabled());
QObject::connect(&settings, &Settings::weatherForecastEnabledChanged, &weatherForecastMgr, &WeatherForecastManager::setAllowNetworkAccess);
timelineModel.setWeatherForecastManager(&weatherForecastMgr);
qmlRegisterUncreatableType<KPkPass::Barcode>("org.kde.pkpass", 1, 0, "Barcode", {});
qmlRegisterUncreatableType<KPkPass::Field>("org.kde.pkpass", 1, 0, "Field", {});
......
......@@ -25,6 +25,8 @@ Settings::Settings(QObject *parent)
QSettings s;
s.beginGroup(QLatin1String("Settings"));
m_weatherEnabled = s.value(QLatin1String("WeatherForecastEnabled"), false).toBool();
// TODO configurable home country
m_homeCountry = s.value(QLatin1String("HomeCountry"), QStringLiteral("DE")).toString();
}
Settings::~Settings() = default;
......@@ -47,3 +49,8 @@ void Settings::setWeatherForecastEnabled(bool enabled)
emit weatherForecastEnabledChanged(enabled);
}
QString Settings::homeCountryIsoCode() const
{
return m_homeCountry;
}
......@@ -32,10 +32,14 @@ public:
bool weatherForecastEnabled() const;
void setWeatherForecastEnabled(bool enabled);
QString homeCountryIsoCode() const;
signals:
void weatherForecastEnabledChanged(bool enabled);
void homeCountryIsoCodeChanged(const QString &isoCode);
private:
QString m_homeCountry;
bool m_weatherEnabled = false;
};
......
......@@ -146,6 +146,12 @@ void TimelineModel::setWeatherForecastManager(WeatherForecastManager* mgr)
connect(m_weatherMgr, &WeatherForecastManager::forecastUpdated, this, &TimelineModel::updateWeatherElements);
}
void TimelineModel::setHomeCountryIsoCode(const QString &isoCode)
{
m_homeCountry = isoCode;
updateInformationElements();
}
int TimelineModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid() || !m_resMgr) {
......@@ -304,7 +310,7 @@ void TimelineModel::updateInformationElements()
// differences is introduced by the transition
CountryInformation homeCountry;
homeCountry.setIsoCode(QLatin1String("DE")); // TODO configurable home country
homeCountry.setIsoCode(m_homeCountry);
auto previousCountry = homeCountry;
for (auto it = m_elements.begin(); it != m_elements.end(); ++it) {
......
......@@ -74,6 +74,7 @@ public:
void setReservationManager(ReservationManager *mgr);
void setWeatherForecastManager(WeatherForecastManager *mgr);
void setHomeCountryIsoCode(const QString &isoCode);
QVariant data(const QModelIndex& index, int role) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
......@@ -109,6 +110,7 @@ private:
ReservationManager *m_resMgr = nullptr;
WeatherForecastManager *m_weatherMgr = nullptr;
std::vector<Element> m_elements;
QString m_homeCountry;
};
#endif // TIMELINEMODEL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment