waybar/src/factory.cpp

27 lines
928 B
C++
Raw Normal View History

2018-08-09 12:05:48 +02:00
#include "factory.hpp"
waybar::Factory::Factory(Bar &bar, Json::Value config)
: _bar(bar), _config(config)
{}
waybar::IModule &waybar::Factory::makeModule(std::string name)
{
if (name == "battery")
2018-08-09 13:30:11 +02:00
return *new waybar::modules::Battery(_config[name]);
2018-08-09 12:05:48 +02:00
if (name == "workspaces")
return *new waybar::modules::Workspaces(_bar);
if (name == "memory")
2018-08-09 13:30:11 +02:00
return *new waybar::modules::Memory(_config[name]);
2018-08-09 12:05:48 +02:00
if (name == "cpu")
2018-08-09 13:30:11 +02:00
return *new waybar::modules::Cpu(_config[name]);
2018-08-09 12:05:48 +02:00
if (name == "clock")
2018-08-09 13:30:11 +02:00
return *new waybar::modules::Clock(_config[name]);
2018-08-09 16:38:24 +02:00
if (name == "network")
return *new waybar::modules::Network(_config[name]);
2018-08-09 23:55:38 +02:00
if (name == "pulseaudio")
return *new waybar::modules::Pulseaudio(_config[name]);
if (!name.compare(0, 7, "custom/") && name.size() > 7)
return *new waybar::modules::Custom(name.substr(7), _config[name]);
2018-08-09 12:05:48 +02:00
throw std::runtime_error("Unknown module: " + name);
}