Skip to content

Commit

Permalink
Remove power off logo when generation is disabled
Browse files Browse the repository at this point in the history
Refs: #102
  • Loading branch information
orontee committed Nov 23, 2024
1 parent 89f6aba commit c0c4bde
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 11 additions & 10 deletions src/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 29 additions & 2 deletions src/logo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,37 @@ 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);
if (must_generate) {
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";

Expand All @@ -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
6 changes: 6 additions & 0 deletions src/logo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <inkview.h>
#include <memory>
#include <string>

#include "config.h"
#include "dailyforecastbox.h"
Expand Down Expand Up @@ -37,12 +38,17 @@ struct LogoGenerator {

void generate_maybe() const;

static std::string get_logo_path();

static bool logo_exists();

private:
std::shared_ptr<Config> config;
std::shared_ptr<Model> model;
std::shared_ptr<Icons> icons;
std::shared_ptr<Fonts> fonts;

void generate() const;
void remove() const;
};
} // namespace taranis

0 comments on commit c0c4bde

Please sign in to comment.