7#include "observatoryweathermodel.h"
9#include <KLocalizedString>
14void ObservatoryWeatherModel::initModel(Weather *weather)
16 weatherInterface = weather;
19 weatherChanged(status());
21 connect(weatherInterface, &Weather::ready,
this, [&]()
24 emit updateWeatherStatus();
26 connect(weatherInterface, &Weather::newStatus,
this, &ObservatoryWeatherModel::weatherChanged);
27 connect(weatherInterface, &Weather::newWeatherData,
this, &ObservatoryWeatherModel::updateWeatherData);
28 connect(weatherInterface, &Weather::newWeatherData,
this, &ObservatoryWeatherModel::newWeatherData);
29 connect(weatherInterface, &Weather::disconnected,
this, [&]()
36 warningActionsActive = Options::warningActionsActive();
37 warningActions.parkDome = Options::weatherWarningCloseDome();
38 warningActions.closeShutter = Options::weatherWarningCloseShutter();
39 warningActions.delay = Options::weatherWarningDelay();
40 alertActionsActive = Options::alertActionsActive();
41 alertActions.parkDome = Options::weatherAlertCloseDome();
42 alertActions.closeShutter = Options::weatherAlertCloseShutter();
43 alertActions.delay = Options::weatherAlertDelay();
44 m_autoScaleValues = Options::weatherAutoScaleValues();
47 warningActions.stopScheduler =
false;
48 alertActions.stopScheduler =
false;
50 warningTimer.
setInterval(
static_cast<int>(warningActions.delay * 1000));
52 alertTimer.
setInterval(
static_cast<int>(alertActions.delay * 1000));
57 execute(warningActions);
61 execute(alertActions);
64 if (weatherInterface->status() != ISD::Weather::WEATHER_IDLE)
70ISD::Weather::Status ObservatoryWeatherModel::status()
72 if (weatherInterface ==
nullptr)
73 return ISD::Weather::WEATHER_IDLE;
75 return weatherInterface->status();
78bool ObservatoryWeatherModel::refresh()
80 return weatherInterface->refresh();
83void ObservatoryWeatherModel::setWarningActionsActive(
bool active)
85 warningActionsActive = active;
86 Options::setWarningActionsActive(active);
89 if (!active && warningTimer.
isActive())
92 else if (weatherInterface->status() == ISD::Weather::WEATHER_WARNING)
96void ObservatoryWeatherModel::startWarningTimer()
98 if (warningActionsActive && (warningActions.parkDome || warningActions.closeShutter || warningActions.stopScheduler))
101 warningTimer.
start();
107void ObservatoryWeatherModel::setAlertActionsActive(
bool active)
109 alertActionsActive = active;
110 Options::setAlertActionsActive(active);
113 if (!active && alertTimer.
isActive())
116 else if (weatherInterface->status() == ISD::Weather::WEATHER_ALERT)
120void ObservatoryWeatherModel::setAutoScaleValues(
bool value)
122 m_autoScaleValues = value;
123 Options::setWeatherAutoScaleValues(value);
126void ObservatoryWeatherModel::startAlertTimer()
128 if (alertActionsActive && (alertActions.parkDome || alertActions.closeShutter || alertActions.stopScheduler))
137void ObservatoryWeatherModel::setWarningActions(WeatherActions actions)
139 warningActions = actions;
140 Options::setWeatherWarningCloseDome(actions.parkDome);
141 Options::setWeatherWarningCloseShutter(actions.closeShutter);
142 Options::setWeatherWarningDelay(actions.delay);
144 warningTimer.
setInterval(
static_cast<int>(actions.delay * 1000));
146 if (weatherInterface->status() == ISD::Weather::WEATHER_WARNING)
151QString ObservatoryWeatherModel::getWarningActionsStatus()
156 return i18np(
"%1 second remaining",
"%1 seconds remaining", remaining);
159 return i18n(
"Status: inactive");
162void ObservatoryWeatherModel::setAlertActions(WeatherActions actions)
164 alertActions = actions;
165 Options::setWeatherAlertCloseDome(actions.parkDome);
166 Options::setWeatherAlertCloseShutter(actions.closeShutter);
167 Options::setWeatherAlertDelay(actions.delay);
169 alertTimer.
setInterval(
static_cast<int>(actions.delay * 1000));
171 if (weatherInterface->status() == ISD::Weather::WEATHER_ALERT)
175QString ObservatoryWeatherModel::getAlertActionsStatus()
180 return i18np(
"%1 second remaining",
"%1 seconds remaining", remaining);
183 return i18n(
"Status: inactive");
186void ObservatoryWeatherModel::updateWeatherStatus()
188 weatherChanged(status());
193void ObservatoryWeatherModel::weatherChanged(ISD::Weather::Status status)
197 case ISD::Weather::WEATHER_OK:
201 case ISD::Weather::WEATHER_WARNING:
205 case ISD::Weather::WEATHER_ALERT:
212 emit newStatus(status);
215void ObservatoryWeatherModel::updateWeatherData(
const std::vector<ISD::Weather::WeatherData> &data)
218 for (
auto &oneEntry : data)
221 unsigned long pos = findWeatherData(oneEntry.name);
222 if (pos < m_WeatherData.size())
223 m_WeatherData[pos].value = oneEntry.value;
225 else if (oneEntry.name.startsWith(
"WEATHER_"))
226 m_WeatherData.push_back({
QString(oneEntry.name),
QString(oneEntry.label), oneEntry.value});
232unsigned long ObservatoryWeatherModel::findWeatherData(
const QString name)
235 for (i = 0; i < m_WeatherData.size(); i++)
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
QString name(GameStandardAction id)
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
void setInterval(int msec)
bool isActive() const const
void setSingleShot(bool singleShot)