Cleanup of bar::load

This commit is contained in:
Michael Carlberg 2016-06-23 23:36:45 +02:00
parent ee1c980be1
commit 825b47b7d4
2 changed files with 28 additions and 38 deletions

View File

@ -2,10 +2,10 @@
#define APP_NAME "@PROJECT_NAME@" #define APP_NAME "@PROJECT_NAME@"
#cmakedefine ENABLE_ALSA #cmakedefine ENABLE_ALSA true
#cmakedefine ENABLE_MPD #cmakedefine ENABLE_MPD true
#cmakedefine ENABLE_NETWORK #cmakedefine ENABLE_NETWORK true
#cmakedefine ENABLE_I3 #cmakedefine ENABLE_I3 true
#define BUILDER_SPACE_TOKEN "%__" #define BUILDER_SPACE_TOKEN "%__"
#define ALSA_SOUNDCARD "@SETTING_ALSA_SOUNDCARD@" #define ALSA_SOUNDCARD "@SETTING_ALSA_SOUNDCARD@"

View File

@ -1,4 +1,5 @@
#include "bar.hpp" #include "bar.hpp"
#include "config.hpp"
#include "registry.hpp" #include "registry.hpp"
#include "services/builder.hpp" #include "services/builder.hpp"
#include "utils/config.hpp" #include "utils/config.hpp"
@ -139,40 +140,29 @@ void Bar::load()
std::unique_ptr<modules::ModuleInterface> module; std::unique_ptr<modules::ModuleInterface> module;
auto type = config::get<std::string>("module/"+ mod, "type"); auto type = config::get<std::string>("module/"+ mod, "type");
if (type == "internal/counter") module = std::make_unique<modules::CounterModule>(mod); if (!ENABLE_ALSA && type == "internal/volume")
else if (type == "internal/backlight") module = std::make_unique<modules::BacklightModule>(mod); throw CompiledWithoutModuleSupport(type);
else if (type == "internal/battery") module = std::make_unique<modules::BatteryModule>(mod); if (!ENABLE_I3 && type == "internal/i3")
else if (type == "internal/bspwm") module = std::make_unique<modules::BspwmModule>(mod, this->opts->monitor->name); throw CompiledWithoutModuleSupport(type);
else if (type == "internal/cpu") module = std::make_unique<modules::CpuModule>(mod); if (!ENABLE_MPD && type == "internal/mpd")
else if (type == "internal/date") module = std::make_unique<modules::DateModule>(mod); throw CompiledWithoutModuleSupport(type);
else if (type == "internal/memory") module = std::make_unique<modules::MemoryModule>(mod); if (!ENABLE_NETWORK && type == "internal/network")
else if (type == "internal/network") throw CompiledWithoutModuleSupport(type);
#ifdef ENABLE_NETWORK
module = std::make_unique<modules::NetworkModule>(mod); if (type == "internal/counter") module = std::make_unique<modules::CounterModule>(mod);
#else else if (type == "internal/backlight") module = std::make_unique<modules::BacklightModule>(mod);
throw CompiledWithoutModuleSupport("network"); else if (type == "internal/battery") module = std::make_unique<modules::BatteryModule>(mod);
#endif else if (type == "internal/bspwm") module = std::make_unique<modules::BspwmModule>(mod, this->opts->monitor->name);
else if (type == "internal/i3") else if (type == "internal/cpu") module = std::make_unique<modules::CpuModule>(mod);
#ifdef ENABLE_I3 else if (type == "internal/date") module = std::make_unique<modules::DateModule>(mod);
module = std::make_unique<modules::i3Module>(mod, this->opts->monitor->name); else if (type == "internal/memory") module = std::make_unique<modules::MemoryModule>(mod);
#else else if (type == "internal/i3") module = std::make_unique<modules::i3Module>(mod, this->opts->monitor->name);
throw CompiledWithoutModuleSupport("i3"); else if (type == "internal/mpd") module = std::make_unique<modules::MpdModule>(mod);
#endif else if (type == "internal/volume") module = std::make_unique<modules::VolumeModule>(mod);
else if (type == "internal/mpd") else if (type == "internal/network") module = std::make_unique<modules::NetworkModule>(mod);
#ifdef ENABLE_MPD else if (type == "custom/text") module = std::make_unique<modules::TextModule>(mod);
module = std::make_unique<modules::MpdModule>(mod); else if (type == "custom/script") module = std::make_unique<modules::ScriptModule>(mod);
#else else if (type == "custom/menu") module = std::make_unique<modules::MenuModule>(mod);
throw CompiledWithoutModuleSupport("mpd");
#endif
else if (type == "internal/volume")
#ifdef ENABLE_ALSA
module = std::make_unique<modules::VolumeModule>(mod);
#else
throw CompiledWithoutModuleSupport("volume");
#endif
else if (type == "custom/text") module = std::make_unique<modules::TextModule>(mod);
else if (type == "custom/script") module = std::make_unique<modules::ScriptModule>(mod);
else if (type == "custom/menu") module = std::make_unique<modules::MenuModule>(mod);
else throw ConfigurationError("Unknown module: "+ mod); else throw ConfigurationError("Unknown module: "+ mod);
vec.emplace_back(module->name()); vec.emplace_back(module->name());