aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-08-01 15:33:40 (GMT)
committerPaul Tagliamonte <paultag@fluxbox.org>2012-04-07 02:12:17 (GMT)
commit05d222c463f4b7e84973eec9a211f4ac1bd35d0f (patch)
treeb1dcb535742a5c2705f5bb5fa261702bf3c742d6 /src
parent6b8cac1f4cadd81f2d3ed313e2bc05af51c84643 (diff)
downloadfluxbox_paul-05d222c463f4b7e84973eec9a211f4ac1bd35d0f.zip
fluxbox_paul-05d222c463f4b7e84973eec9a211f4ac1bd35d0f.tar.bz2
Refactoring: move details if init file loading into LResourceManager
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/LResource.cc34
-rw-r--r--src/FbTk/LResource.hh2
-rw-r--r--src/fluxbox.cc22
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 @@
24 24
25#include "LResource.hh" 25#include "LResource.hh"
26 26
27#include "I18n.hh"
27#include "LuaUtil.hh" 28#include "LuaUtil.hh"
28#include "Resource.hh" 29#include "Resource.hh"
29 30
@@ -105,10 +106,43 @@ LResourceManager::LResourceManager(const std::string &root, Lua &l)
105 setLua(l); 106 setLua(l);
106} 107}
107 108
109void LResourceManager::load(const std::string &filename, const std::string &fallback) {
110 _FB_USES_NLS;
111 m_l->checkstack(1);
112 lua::stack_sentry s(*m_l);
113
114 m_filename = filename;
115
116 try {
117 m_l->loadfile(filename.c_str());
118 m_l->call(0, 0);
119 }
120 catch(lua::exception &e) {
121 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database",
122 "Failed trying to read rc file") << ":" << filename << std::endl;
123 std::cerr << "Fluxbox: " << e.what() << std::endl;
124 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFileTrying, "Retrying with",
125 "Retrying rc file loading with (the following file)")
126 << ": " << fallback << std::endl;
127 try {
128 m_l->loadfile(fallback.c_str());
129 m_l->call(0, 0);
130 }
131 catch(lua::exception &e) {
132 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "")
133 << ": " << fallback << std::endl;
134 std::cerr << "Fluxbox: " << e.what() << std::endl;
135 }
136 }
137}
138
108bool LResourceManager::save(const char *filename, const char *) { 139bool LResourceManager::save(const char *filename, const char *) {
109 m_l->checkstack(3); 140 m_l->checkstack(3);
110 lua::stack_sentry s(*m_l); 141 lua::stack_sentry s(*m_l);
111 142
143 if(filename == NULL)
144 filename = m_filename.c_str();
145
112 m_l->getfield(lua::REGISTRYINDEX, dump_resources); 146 m_l->getfield(lua::REGISTRYINDEX, dump_resources);
113 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); 147 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str());
114 m_l->pushstring(filename); 148 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:
38 static void convert(ResourceManager &old, const std::string &new_file); 38 static void convert(ResourceManager &old, const std::string &new_file);
39 39
40 LResourceManager(const std::string &root, Lua &l); 40 LResourceManager(const std::string &root, Lua &l);
41 void load(const std::string &filename, const std::string &fallback);
41 virtual bool save(const char *filename, const char *); 42 virtual bool save(const char *filename, const char *);
42 virtual void addResource(Resource_base &r); 43 virtual void addResource(Resource_base &r);
43 virtual void removeResource(Resource_base &r); 44 virtual void removeResource(Resource_base &r);
@@ -48,6 +49,7 @@ private:
48 void doRemoveResource(Resource_base &r); 49 void doRemoveResource(Resource_base &r);
49 50
50 Lua *m_l; 51 Lua *m_l;
52 std::string m_filename;
51}; 53};
52 54
53} // end namespace FbTk 55} // 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 {
1149 1149
1150/// loads resources 1150/// loads resources
1151void Fluxbox::load_rc() { 1151void Fluxbox::load_rc() {
1152 _FB_USES_NLS;
1153 lua::stack_sentry s(*m_l);
1154
1155 string dbfile(getRcFilename());
1156 1152
1157 try { 1153 m_resourcemanager.load(getRcFilename(), DEFAULT_INITFILE);
1158 m_l->loadfile(dbfile.c_str());
1159 m_l->call(0, 0);
1160 }
1161 catch(lua::exception &e) {
1162 cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "Failed trying to read rc file")<<":"<<dbfile<<endl;
1163 cerr<<"Fluxbox: "<<e.what()<<endl;
1164 cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFileTrying, "Retrying with", "Retrying rc file loading with (the following file)")<<": "<<DEFAULT_INITFILE<<endl;
1165 try {
1166 m_l->loadfile(DEFAULT_INITFILE);
1167 m_l->call(0, 0);
1168 }
1169 catch(lua::exception &e) {
1170 cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "")<<": "<<DEFAULT_INITFILE<<endl;
1171 cerr<<"Fluxbox: "<<e.what()<<endl;
1172 }
1173 }
1174 1154
1175 if (m_rc_menufile->empty()) 1155 if (m_rc_menufile->empty())
1176 m_rc_menufile.setDefaultValue(); 1156 m_rc_menufile.setDefaultValue();