diff --git a/NEWS.md b/NEWS.md index 8241da5..f137539 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Changed +- Remove power off logo when generation is disabled + [#102](https://github.com/orontee/taranis/issues/102) + - Power off logo adapt to screen mode [#101](https://github.com/orontee/taranis/issues/101) diff --git a/src/app.cc b/src/app.cc index 6158be4..f308dca 100644 --- a/src/app.cc +++ b/src/app.cc @@ -185,17 +185,18 @@ void App::load_config() { // by the backend thus unit system or language change implies that // data are obsolete - const bool generate_shutdown_logo = - this->config->read_bool("generate_shutdown_logo", false); - if (generate_shutdown_logo) { - if (this->ui) { - this->ui->generate_logo_maybe(); + if (this->ui) { + this->ui->generate_logo_maybe(); - // A logo generation must be requested after the config changed - // since no model update (which triggers a logo generation) may - // happen before user open the device configuration panel for - // logos (See issue #28) - } + // A logo generation must be requested after the config changed + // since no model update (which triggers a logo generation) may + // happen before user open the device configuration panel for + // logos (See issue #28) + + // Also don't bother for the value of the configuration key + // generate_shutdown_logo since if it changed to false, one must + // remove the logo (handled by generate_logo_maybe(), yeah not + // that intuitive...) } const auto event_handler = GetEventHandler(); diff --git a/src/logo.cc b/src/logo.cc index 01cef98..10de4cd 100644 --- a/src/logo.cc +++ b/src/logo.cc @@ -35,6 +35,13 @@ void Logo::do_paint() { } } +std::string LogoGenerator::get_logo_path() { + const auto filename = + std::string{USEROFFLOGOPATH} + "/taranis_weather_forecast.bmp"; + + return filename; +} + void LogoGenerator::generate_maybe() const { const auto must_generate = this->config->read_bool("generate_shutdown_logo", false); @@ -42,9 +49,23 @@ void LogoGenerator::generate_maybe() const { this->generate(); } else { BOOST_LOG_TRIVIAL(debug) << "Skipping logo generation"; + if (LogoGenerator::logo_exists()) { + this->remove(); + } } } +bool LogoGenerator::logo_exists() { + const auto filename = LogoGenerator::get_logo_path(); + struct stat buffer; + if (iv_stat(filename.c_str(), &buffer) == 0) { + BOOST_LOG_TRIVIAL(debug) << "Logo exists"; + return true; + } + BOOST_LOG_TRIVIAL(debug) << "Logo doesn't exists"; + return false; +} + void LogoGenerator::generate() const { BOOST_LOG_TRIVIAL(debug) << "Generating new logo"; @@ -71,10 +92,16 @@ void LogoGenerator::generate() const { const auto bitmap = BitmapFromCanvas(0, 0, ScreenWidth(), ScreenHeight(), 0, &canvas); - const auto filename = - std::string{USEROFFLOGOPATH} + "/taranis_weather_forecast.bmp"; + const auto filename = LogoGenerator::get_logo_path(); SaveBitmap(filename.data(), bitmap); SetCanvas(original_canvas); } + +void LogoGenerator::remove() const { + BOOST_LOG_TRIVIAL(debug) << "Removing logo"; + + const auto filename = LogoGenerator::get_logo_path(); + iv_unlink(filename.c_str()); +} } // namespace taranis diff --git a/src/logo.h b/src/logo.h index d71287a..1deea5c 100644 --- a/src/logo.h +++ b/src/logo.h @@ -2,6 +2,7 @@ #include #include +#include #include "config.h" #include "dailyforecastbox.h" @@ -37,6 +38,10 @@ struct LogoGenerator { void generate_maybe() const; + static std::string get_logo_path(); + + static bool logo_exists(); + private: std::shared_ptr config; std::shared_ptr model; @@ -44,5 +49,6 @@ struct LogoGenerator { std::shared_ptr fonts; void generate() const; + void remove() const; }; } // namespace taranis