aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Resource.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Resource.cc')
-rw-r--r--src/FbTk/Resource.cc39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/FbTk/Resource.cc b/src/FbTk/Resource.cc
index 37555b3..8f63322 100644
--- a/src/FbTk/Resource.cc
+++ b/src/FbTk/Resource.cc
@@ -38,6 +38,33 @@ using std::string;
38namespace FbTk { 38namespace FbTk {
39 39
40 40
41void ResourceManager_base::load(const std::string &filename, const std::string &fallback) {
42 _FB_USES_NLS;
43
44 m_filename = filename;
45
46 try {
47 doLoad(filename);
48 }
49 catch(std::runtime_error &e) {
50 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database",
51 "Failed trying to read rc file") << ":" << filename << std::endl;
52 std::cerr << "Fluxbox: " << e.what() << std::endl;
53 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFileTrying, "Retrying with",
54 "Retrying rc file loading with (the following file)")
55 << ": " << fallback << std::endl;
56 try {
57 doLoad(fallback);
58 }
59 catch(std::runtime_error &e) {
60 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "")
61 << ": " << fallback << std::endl;
62 std::cerr << "Fluxbox: " << e.what() << std::endl;
63 throw;
64 }
65 }
66}
67
41void ResourceManager_base::addResource(Resource_base &r) { 68void ResourceManager_base::addResource(Resource_base &r) {
42 m_resourcelist.push_back(&r); 69 m_resourcelist.push_back(&r);
43 m_resourcelist.unique(); 70 m_resourcelist.unique();
@@ -87,7 +114,6 @@ ResourceManager::ResourceManager(const std::string &root, const std::string &alt
87 ResourceManager_base(root), 114 ResourceManager_base(root),
88 m_db_lock(0), 115 m_db_lock(0),
89 m_database(0), 116 m_database(0),
90 m_filename(filename ? filename : ""),
91 m_alt_root(alt_root) 117 m_alt_root(alt_root)
92{ 118{
93 static bool xrm_initialized = false; 119 static bool xrm_initialized = false;
@@ -96,6 +122,7 @@ ResourceManager::ResourceManager(const std::string &root, const std::string &alt
96 xrm_initialized = true; 122 xrm_initialized = true;
97 } 123 }
98 124
125 m_filename = filename ? filename : "";
99 if (lock_db) 126 if (lock_db)
100 lock(); 127 lock();
101} 128}
@@ -108,11 +135,9 @@ ResourceManager::~ResourceManager() {
108 135
109/** 136/**
110 reloads all resources from resourcefile 137 reloads all resources from resourcefile
111 @return true on success else false 138 throws an exception in case of failure
112*/ 139*/
113bool ResourceManager::load(const char *filename) { 140void ResourceManager::doLoad(const std::string &filename) {
114 m_filename = StringUtil::expandFilename(filename).c_str();
115
116 // force reload (lock will ensure it exists) 141 // force reload (lock will ensure it exists)
117 if (m_database) { 142 if (m_database) {
118 delete m_database; 143 delete m_database;
@@ -122,7 +147,7 @@ bool ResourceManager::load(const char *filename) {
122 lock(); 147 lock();
123 if (!m_database) { 148 if (!m_database) {
124 unlock(); 149 unlock();
125 return false; 150 throw std::runtime_error("");
126 } 151 }
127 152
128 XrmValue value; 153 XrmValue value;
@@ -146,8 +171,6 @@ bool ResourceManager::load(const char *filename) {
146 } 171 }
147 172
148 unlock(); 173 unlock();
149
150 return true;
151} 174}
152 175
153/** 176/**