From 2872d9ef363dc84abcc1a5a73ad7778ab70ee4ab Mon Sep 17 00:00:00 2001 From: Michael Hasling Date: Sun, 17 Mar 2024 15:25:40 +0000 Subject: [PATCH] Convert ChartFox interfacing to v2 API. --- .gitignore | 16 +- CMakeLists.txt | 6 +- config.h.in | 2 +- src/CMakeLists.txt | 5 +- src/avitab/apps/AppLauncher.cpp | 2 +- src/avitab/apps/ProvidersApp.cpp | 179 +++++++++--- src/avitab/apps/ProvidersApp.h | 26 +- src/charts/Chart.h | 3 +- src/charts/ChartService.cpp | 35 ++- src/charts/ChartService.h | 12 +- src/charts/RESTClient.h | 1 + src/charts/libchartfox/CMakeLists.txt | 2 + src/charts/libchartfox/ChartFoxAPI.cpp | 182 +++++++++--- src/charts/libchartfox/ChartFoxAPI.h | 46 ++- src/charts/libchartfox/ChartFoxAuthServer.cpp | 276 ++++++++++++++++++ src/charts/libchartfox/ChartFoxAuthServer.h | 59 ++++ src/charts/libchartfox/ChartFoxChart.cpp | 121 +++----- src/charts/libchartfox/ChartFoxChart.h | 35 ++- .../libchartfox/ChartFoxOAuth2Client.cpp | 249 ++++++++++++++++ src/charts/libchartfox/ChartFoxOAuth2Client.h | 84 ++++++ src/charts/liblocalfile/LocalFileChart.h | 19 +- src/charts/libnavigraph/NavigraphChart.h | 18 +- src/gui_toolkit/widgets/Widget.cpp | 5 + src/gui_toolkit/widgets/Widget.h | 1 + 24 files changed, 1130 insertions(+), 254 deletions(-) create mode 100644 src/charts/libchartfox/ChartFoxAuthServer.cpp create mode 100644 src/charts/libchartfox/ChartFoxAuthServer.h create mode 100644 src/charts/libchartfox/ChartFoxOAuth2Client.cpp create mode 100644 src/charts/libchartfox/ChartFoxOAuth2Client.h diff --git a/.gitignore b/.gitignore index 8bddc2f8..7c28b745 100644 --- a/.gitignore +++ b/.gitignore @@ -34,9 +34,18 @@ *.app # Project specific ignores -build -build-third -cmake-build-debug +/build/ +/build-third/ +/cmake-build-debug/ +/build-*/ +/scratch/ + +# Ignore hidden files, apart from some project specifics +/.* +!/.gitattributes +!/.gitignore +!/.gitmodules +!/.clang-format # Jetbrains IDE .idea/ @@ -46,6 +55,7 @@ cmake-build-debug # VSCode IDE .vscode/ +*.code-workspace # clangd index and compilation database .cache diff --git a/CMakeLists.txt b/CMakeLists.txt index 72138837..d7217b91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.20) project(AviTab VERSION 0.6.3 DESCRIPTION "AviTab X-Plane plugin") if (NOT "$ENV{NAVIGRAPH_SECRET}" STREQUAL "") set(NAVIGRAPH_SECRET "$ENV{NAVIGRAPH_SECRET}" CACHE INTERNAL "Copied from environment variable") endif() -if (NOT "$ENV{CHARTFOX_SECRET}" STREQUAL "") - set(CHARTFOX_SECRET "$ENV{CHARTFOX_SECRET}" CACHE INTERNAL "Copied from environment variable") +if (NOT "$ENV{CHARTFOX_CLIENTID}" STREQUAL "") + set(CHARTFOX_CLIENTID "$ENV{CHARTFOX_CLIENTID}" CACHE INTERNAL "Copied from environment variable") endif() configure_file( diff --git a/config.h.in b/config.h.in index a23ece67..6c061e9e 100644 --- a/config.h.in +++ b/config.h.in @@ -21,4 +21,4 @@ #define AVITAB_VERSION_PATCH @AviTab_VERSION_PATCH@ #define AVITAB_VERSION_STR "@AviTab_VERSION_MAJOR@.@AviTab_VERSION_MINOR@.@AviTab_VERSION_PATCH@" #define NAVIGRAPH_CLIENT_SECRET "@NAVIGRAPH_SECRET@" -#define CHARTFOX_CLIENT_SECRET "@CHARTFOX_SECRET@" +#define CHARTFOX_CLIENT_ID "@CHARTFOX_CLIENTID@" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 20fb1e11..767d9ca1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -158,8 +158,9 @@ if(WIN32 AND DEFINED ENV{MSFS_SDK}) ) add_library(SimConnect STATIC IMPORTED) - set_property(TARGET SimConnect PROPERTY IMPORTED_LOCATION "$ENV{MSFS_SDK}/SimConnect SDK/lib/SimConnect.dll") - set_property(TARGET SimConnect PROPERTY IMPORTED_IMPLIB "$ENV{MSFS_SDK}/SimConnect SDK/lib/SimConnect.lib") + cmake_path(SET MSFS_SDK $ENV{MSFS_SDK}) + set_property(TARGET SimConnect PROPERTY IMPORTED_LOCATION "${MSFS_SDK}/SimConnect SDK/lib/SimConnect.dll") + set_property(TARGET SimConnect PROPERTY IMPORTED_IMPLIB "${MSFS_SDK}/SimConnect SDK/lib/SimConnect.lib") target_link_libraries(AviTab-msfs -static diff --git a/src/avitab/apps/AppLauncher.cpp b/src/avitab/apps/AppLauncher.cpp index 1fc8a463..76595703 100644 --- a/src/avitab/apps/AppLauncher.cpp +++ b/src/avitab/apps/AppLauncher.cpp @@ -43,7 +43,7 @@ AppLauncher::AppLauncher(FuncsPtr appFuncs): addEntry("Aircraft", root + "if_ilustracoes_04-11_1519786.png", AppId::PLANE_MANUAL); addEntry("Notes", root + "if_txt2_3783.png", AppId::NOTES); - if (api().getChartService()->getNavigraph()->isSupported() || api().getChartService()->getChartfox()->isSupported()) { + if (api().getChartService()->getNavigraph()->isSupported() || api().getChartService()->getChartFox()->isSupported()) { addEntry("Providers", root + "if_Airport_22906.png", AppId::NAVIGRAPH); } diff --git a/src/avitab/apps/ProvidersApp.cpp b/src/avitab/apps/ProvidersApp.cpp index 158f8d42..8e3778e9 100644 --- a/src/avitab/apps/ProvidersApp.cpp +++ b/src/avitab/apps/ProvidersApp.cpp @@ -39,11 +39,17 @@ ProvidersApp::ProvidersApp(FuncsPtr appFuncs): } } - if (api().getChartService()->getChartfox()->isSupported()) { + if (api().getChartService()->getChartFox() != nullptr) { chartFoxPage = tabs->addTab(tabs, "ChartFox"); windowChartFox = std::make_shared(chartFoxPage, "ChartFox"); windowChartFox->setOnClose([this] () { exit(); }); resetChartFoxLayout(); + + auto chartFox = api().getChartService()->getChartFox(); + if (chartFox->isAuthenticated()) { + // modify the tab to display as if just logged in + onChartFoxLoginSuccessful(); + } } } @@ -60,10 +66,10 @@ void ProvidersApp::resetNavigraphLayout() { labelNavigraph->setLongMode(true); labelNavigraph->alignInTopLeft(); - button.reset(); - button = std::make_shared