From 915532bf8fbda9ba2a36e04fcd6acc67c6c68fa5 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Tue, 1 Oct 2024 14:54:37 +1300 Subject: Restructure --- config.cpp | 132 ------------------------------------------------------------- 1 file changed, 132 deletions(-) delete mode 100644 config.cpp (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp deleted file mode 100644 index 3af2491..0000000 --- a/config.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "config.h" -#include "commands.h" -#include "error.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//Just for testing -#include - -using std::string; - -// For testing -using std::cout, std::endl; - -const void Config::gapsCmd(const CommandArg* argv) -{ - gaps = argv[0].num; -} - -const void Config::outerGapsCmd(const CommandArg* argv) -{ - outerGaps = argv[0].num; -} - -const void Config::logFileCmd(const CommandArg* argv) -{ - logFile = argv[0].str; -} - -const void Config::addWorkspaceCmd(const CommandArg* argv) -{ - int* prefs = new int[argv[1].numArr.size]; - for(int i = 0; i < argv[1].numArr.size; i++) - { - prefs[i] = argv[1].numArr.arr[i] - 1; - } - workspaces.push_back({argv[0].str, prefs, argv[1].numArr.size}); - numWS++; -} - -const void Config::swapSuperAltCmd(const CommandArg* argv) -{ - swapSuperAlt ^= true; -} - -Config::Config(CommandsModule& commandsModule) - : commandsModule(commandsModule) -{ - //Register commands for config - commandsModule.addCommand("gaps", &Config::gapsCmd, 1, {NUM}, this); - commandsModule.addCommand("outergaps", &Config::outerGapsCmd, 1, {NUM}, this); - commandsModule.addCommand("logfile", &Config::logFileCmd, 1, {STR_REST}, this); - commandsModule.addCommand("addworkspace", &Config::addWorkspaceCmd, 2, {STR, NUM_ARR_REST}, this); - commandsModule.addCommand("swapmods", &Config::swapSuperAltCmd, 0, {}, this); -} - -std::vector Config::reloadFile() -{ - if(!loaded) - return {{CFG_ERR_NON_FATAL, "Not loaded config yet"}}; - return loadFromFile(file); -} - -std::vector Config::loadFromFile(std::string path) -{ - std::vector errs; - - file = path; - - std::ifstream config(path); - if(!config.good()) - { - config = std::ifstream("/etc/YATwm/config"); - errs.push_back({CFG_ERR_FATAL, "Using default config: /etc/YATwm/config"}); - } - - //Set defaults - gaps = 10; - outerGaps = 10; - logFile = "/tmp/yatlog.txt"; - numWS = 0; - swapSuperAlt = false; - workspaces = std::vector(); - - //Probably need something for workspaces and binds too... - - string cmd; - int line = 0; - while(getline(config, cmd)) - { - line++; - if(cmd.size() == 0) - continue; - if(cmd.at(0) == '#') - continue; - try - { - commandsModule.runCommand(cmd); - } - catch (Err e) - { - errs.push_back({e.code, "Error in config (line " + std::to_string(line) + "): " + std::to_string(e.code) + "\n\tMessage: " + e.message}); - - } - } - loaded = true; - return errs; -} - -Config::~Config() -{ - free(); -} -void Config::free() -{ - if(!loaded) - return; - for(Workspace w : workspaces) - { - delete [] w.screenPreferences; - } -} -- cgit v1.2.3