Skip to content

Commit

Permalink
initial SkySight integration by jfwells
Browse files Browse the repository at this point in the history
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
  • Loading branch information
fb committed Apr 29, 2020
1 parent 17a9ce3 commit 28b3f22
Show file tree
Hide file tree
Showing 35 changed files with 3,520 additions and 3 deletions.
9 changes: 8 additions & 1 deletion build/main.mk
Expand Up @@ -153,6 +153,7 @@ endif
ifeq ($(HAVE_HTTP),y)
DIALOG_SOURCES += \
$(SRC)/Dialogs/Weather/PCMetDialog.cpp \
$(SRC)/Dialogs/Weather/SkysightDialog.cpp \
$(SRC)/Dialogs/Weather/NOAAList.cpp \
$(SRC)/Dialogs/Weather/NOAADetails.cpp
endif
Expand Down Expand Up @@ -778,7 +779,13 @@ XCSOAR_SOURCES += \
$(SRC)/Weather/NOAAFormatter.cpp \
$(SRC)/Weather/NOAADownloader.cpp \
$(SRC)/Weather/NOAAStore.cpp \
$(SRC)/Weather/NOAAUpdater.cpp
$(SRC)/Weather/NOAAUpdater.cpp \
$(SRC)/Weather/Skysight/Skysight.cpp \
$(SRC)/Weather/Skysight/CDFDecoder.cpp \
$(SRC)/Weather/Skysight/APIQueue.cpp \
$(SRC)/Weather/Skysight/SkysightAPI.cpp \
$(SRC)/Weather/Skysight/Request.cpp \
$(SRC)/Weather/Skysight/SkysightRegions.cpp

XCSOAR_SOURCES += \
$(SRC)/Tracking/LiveTrack24.cpp
Expand Down
18 changes: 18 additions & 0 deletions src/DataGlobals.cpp
Expand Up @@ -23,6 +23,7 @@ Copyright_License {

#include "DataGlobals.hpp"
#include "Weather/Rasp/RaspStore.hpp"
#include "Weather/Skysight/Skysight.hpp"
#include "UIGlobals.hpp"
#include "MapWindow/GlueMapWindow.hpp"
#include "Interface.hpp"
Expand All @@ -36,6 +37,15 @@ DataGlobals::GetRasp()
: nullptr;
}

std::shared_ptr<Skysight>
DataGlobals::GetSkysight()
{
auto *map = UIGlobals::GetMap();
return map != nullptr
? map->GetSkysight()
: nullptr;
}

void
DataGlobals::SetRasp(std::shared_ptr<RaspStore> rasp)
{
Expand All @@ -47,3 +57,11 @@ DataGlobals::SetRasp(std::shared_ptr<RaspStore> rasp)
if (map != nullptr)
map->SetRasp(std::move(rasp));
}

void
DataGlobals::SetSkysight(std::shared_ptr<Skysight> skysight)
{
auto *map = UIGlobals::GetMap();
if (map != nullptr)
map->SetSkysight(std::move(skysight));
}
3 changes: 3 additions & 0 deletions src/DataGlobals.hpp
Expand Up @@ -27,6 +27,7 @@ Copyright_License {
#include <memory>

class RaspStore;
class Skysight;

/**
* This namespace provides helper functions to access generic global
Expand All @@ -41,7 +42,9 @@ class RaspStore;
*/
namespace DataGlobals {
std::shared_ptr<RaspStore> GetRasp();
std::shared_ptr<Skysight> GetSkysight();
void SetRasp(std::shared_ptr<RaspStore> rasp);
void SetSkysight(std::shared_ptr<Skysight> skysight);
};

#endif
49 changes: 47 additions & 2 deletions src/Dialogs/Settings/Panels/WeatherConfigPanel.cpp
Expand Up @@ -29,6 +29,10 @@ Copyright_License {
#include "Interface.hpp"
#include "UIGlobals.hpp"
#include "Util/NumberParser.hpp"
#include "Form/DataField/Enum.hpp"
#include "Form/DataField/Listener.hpp"
#include "DataGlobals.hpp"
#include "Weather/Skysight/Skysight.hpp"

enum ControlIndex {
#ifdef HAVE_PCMET
Expand All @@ -37,10 +41,15 @@ enum ControlIndex {
PCMET_FTP_USER,
PCMET_FTP_PASSWORD,
#endif
#ifdef HAVE_SKYSIGHT
SKYSIGHT_EMAIL,
SKYSIGHT_PASSWORD,
SKYSIGHT_REGION
#endif
};

class WeatherConfigPanel final
: public RowFormWidget {
: public RowFormWidget, DataFieldListener {
public:
WeatherConfigPanel()
:RowFormWidget(UIGlobals::GetDialogLook()) {}
Expand All @@ -49,13 +58,29 @@ class WeatherConfigPanel final
/* methods from Widget */
virtual void Prepare(ContainerWindow &parent, const PixelRect &rc) override;
virtual bool Save(bool &changed) override;

private:
/* methods from DataFieldListener */
virtual void OnModified(DataField &df) override {};
};

static void FillRegionControl(WndProperty &wp, const TCHAR *setting)
{
DataFieldEnum *df = (DataFieldEnum *)wp.GetDataField();
auto skysight = DataGlobals::GetSkysight();

for(auto &i : skysight->GetRegions())
df->addEnumText(i.first.c_str(), i.second.c_str());

// if old region doesn't exist any more this will fall back to first element
df->Set(setting);
wp.RefreshDisplay();
}
void
WeatherConfigPanel::Prepare(ContainerWindow &parent, const PixelRect &rc)
{
const auto &settings = CommonInterface::GetComputerSettings().weather;

WndProperty *wp;
RowFormWidget::Prepare(parent, rc);

AddText(_T("pc_met Username"), _T(""),
Expand All @@ -67,6 +92,14 @@ WeatherConfigPanel::Prepare(ContainerWindow &parent, const PixelRect &rc)
settings.pcmet.ftp_credentials.username);
AddPassword(_T("pc_met FTP Password"), _T(""),
settings.pcmet.ftp_credentials.password);

AddText(_T("Skysight Email"), _T("The e-mail you use to log in to the skysight.io site."),
settings.skysight.email);
AddPassword(_T("Skysight Password"), _T("Your Skysight password."),
settings.skysight.password);
wp = AddEnum(_T("Skysight Region"), _T("The Skysight region to load data for."), this);
FillRegionControl(*wp, settings.skysight.region);

}

bool
Expand All @@ -90,6 +123,18 @@ WeatherConfigPanel::Save(bool &_changed)
settings.pcmet.ftp_credentials.password);
#endif

#ifdef HAVE_SKYSIGHT
changed |= SaveValue(SKYSIGHT_EMAIL, ProfileKeys::SkysightEmail,
settings.skysight.email);

changed |= SaveValue(SKYSIGHT_PASSWORD, ProfileKeys::SkysightPassword,
settings.skysight.password);

changed |= SaveValue(SKYSIGHT_REGION, ProfileKeys::SkysightRegion,
settings.skysight.region);
DataGlobals::GetSkysight()->Init();
#endif

_changed |= changed;

return true;
Expand Down

0 comments on commit 28b3f22

Please sign in to comment.