From 05d222c463f4b7e84973eec9a211f4ac1bd35d0f Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 1 Aug 2011 17:33:40 +0200 Subject: Refactoring: move details if init file loading into LResourceManager --- src/FbTk/LResource.cc | 34 ++++++++++++++++++++++++++++++++++ src/FbTk/LResource.hh | 2 ++ src/fluxbox.cc | 22 +--------------------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc index 0909520..31362bd 100644 --- a/src/FbTk/LResource.cc +++ b/src/FbTk/LResource.cc @@ -24,6 +24,7 @@ #include "LResource.hh" +#include "I18n.hh" #include "LuaUtil.hh" #include "Resource.hh" @@ -105,10 +106,43 @@ LResourceManager::LResourceManager(const std::string &root, Lua &l) setLua(l); } +void LResourceManager::load(const std::string &filename, const std::string &fallback) { + _FB_USES_NLS; + m_l->checkstack(1); + lua::stack_sentry s(*m_l); + + m_filename = filename; + + try { + m_l->loadfile(filename.c_str()); + m_l->call(0, 0); + } + catch(lua::exception &e) { + std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", + "Failed trying to read rc file") << ":" << filename << std::endl; + std::cerr << "Fluxbox: " << e.what() << std::endl; + std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFileTrying, "Retrying with", + "Retrying rc file loading with (the following file)") + << ": " << fallback << std::endl; + try { + m_l->loadfile(fallback.c_str()); + m_l->call(0, 0); + } + catch(lua::exception &e) { + std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "") + << ": " << fallback << std::endl; + std::cerr << "Fluxbox: " << e.what() << std::endl; + } + } +} + bool LResourceManager::save(const char *filename, const char *) { m_l->checkstack(3); lua::stack_sentry s(*m_l); + if(filename == NULL) + filename = m_filename.c_str(); + m_l->getfield(lua::REGISTRYINDEX, dump_resources); m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); m_l->pushstring(filename); diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh index bb7f224..f0f8050 100644 --- a/src/FbTk/LResource.hh +++ b/src/FbTk/LResource.hh @@ -38,6 +38,7 @@ public: static void convert(ResourceManager &old, const std::string &new_file); LResourceManager(const std::string &root, Lua &l); + void load(const std::string &filename, const std::string &fallback); virtual bool save(const char *filename, const char *); virtual void addResource(Resource_base &r); virtual void removeResource(Resource_base &r); @@ -48,6 +49,7 @@ private: void doRemoveResource(Resource_base &r); Lua *m_l; + std::string m_filename; }; } // end namespace FbTk diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 224c7f0..a26fd66 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -1149,28 +1149,8 @@ string Fluxbox::getDefaultDataFilename(const char *name) const { /// loads resources void Fluxbox::load_rc() { - _FB_USES_NLS; - lua::stack_sentry s(*m_l); - - string dbfile(getRcFilename()); - try { - m_l->loadfile(dbfile.c_str()); - m_l->call(0, 0); - } - catch(lua::exception &e) { - cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "Failed trying to read rc file")<<":"<loadfile(DEFAULT_INITFILE); - m_l->call(0, 0); - } - catch(lua::exception &e) { - cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "")<<": "<empty()) m_rc_menufile.setDefaultValue(); -- cgit v0.11.2