From d75a3755389f1bc903de4eb21fa213457cccdee0 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 24 May 2016 06:30:06 +0200 Subject: [PATCH] fix(core): Be more clean why the module is invalid --- include/bar.hpp | 7 +++++++ include/config.hpp.cmake | 2 ++ src/bar.cpp | 20 ++++++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 7160acf4..72b667c6 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -4,11 +4,18 @@ #include #include +#include "config.hpp" #include "exception.hpp" #include "utils/xlib.hpp" DefineBaseException(ConfigurationError); +struct CompiledWithoutModuleSupport : public ConfigurationError +{ + CompiledWithoutModuleSupport(std::string module_name) + : ConfigurationError(std::string(APP_NAME) + " was not compiled with support for module \""+ module_name +"\"") {} +}; + struct Font { std::string id; diff --git a/include/config.hpp.cmake b/include/config.hpp.cmake index 7e47425a..ac491de6 100644 --- a/include/config.hpp.cmake +++ b/include/config.hpp.cmake @@ -1,6 +1,8 @@ #ifndef _CONFIG_HPP_ #define _CONFIG_HPP_ +#define APP_NAME "@PROJECT_NAME@" + #cmakedefine ENABLE_ALSA #cmakedefine ENABLE_MPD #cmakedefine ENABLE_NETWORK diff --git a/src/bar.cpp b/src/bar.cpp index b2924210..8e8b448c 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -157,17 +157,29 @@ void Bar::load() else if (type == "internal/cpu") module = std::make_unique(mod); else if (type == "internal/date") module = std::make_unique(mod); else if (type == "internal/memory") module = std::make_unique(mod); + else if (type == "internal/network") #ifdef ENABLE_NETWORK - else if (type == "internal/network") module = std::make_unique(mod); + module = std::make_unique(mod); +#else + throw CompiledWithoutModuleSupport("network"); #endif + else if (type == "internal/i3") #ifdef ENABLE_I3 - else if (type == "internal/i3") module = std::make_unique(mod, this->opts->monitor->name); + module = std::make_unique(mod, this->opts->monitor->name); +#else + throw CompiledWithoutModuleSupport("i3"); #endif + else if (type == "internal/mpd") #ifdef ENABLE_MPD - else if (type == "internal/mpd") module = std::make_unique(mod); + module = std::make_unique(mod); +#else + throw CompiledWithoutModuleSupport("mpd"); #endif + else if (type == "internal/volume") #ifdef ENABLE_ALSA - else if (type == "internal/volume") module = std::make_unique(mod); + module = std::make_unique(mod); +#else + throw CompiledWithoutModuleSupport("volume"); #endif #if 0 else if (type == "internal/rtorrent") module = std::make_unique(mod);