load_rc() now uses the obResource class to load its configuration
This commit is contained in:
parent
3da13c1682
commit
17ef263859
4 changed files with 51 additions and 60 deletions
|
@ -42,6 +42,12 @@ obResource::obResource(const std::string &file) {
|
|||
m_autosave = true;
|
||||
}
|
||||
|
||||
obResource::obResource() {
|
||||
m_modified = false;
|
||||
m_database = NULL;
|
||||
m_autosave = true;
|
||||
}
|
||||
|
||||
obResource::~obResource() {
|
||||
if (m_database != NULL)
|
||||
XrmDestroyDatabase(m_database);
|
||||
|
@ -49,7 +55,6 @@ obResource::~obResource() {
|
|||
|
||||
void obResource::setFile(const std::string &file) {
|
||||
m_file = file;
|
||||
assert(m_file.c_str() != NULL);
|
||||
}
|
||||
|
||||
void obResource::setAutoSave(bool autosave) {
|
||||
|
@ -57,12 +62,14 @@ void obResource::setAutoSave(bool autosave) {
|
|||
}
|
||||
|
||||
void obResource::save() {
|
||||
assert(m_file.c_str() != NULL);
|
||||
assert(m_database != NULL);
|
||||
XrmPutFileDatabase(m_database, m_file.c_str());
|
||||
m_modified = false;
|
||||
}
|
||||
|
||||
bool obResource::load() {
|
||||
assert(m_file.c_str() != NULL);
|
||||
if (m_database != NULL)
|
||||
XrmDestroyDatabase(m_database);
|
||||
m_modified = false;
|
||||
|
@ -72,6 +79,7 @@ bool obResource::load() {
|
|||
}
|
||||
|
||||
void obResource::setValue(const std::string &rname, bool value) {
|
||||
assert(rname.c_str() != NULL);
|
||||
assert(m_database != NULL);
|
||||
|
||||
const char *val = (value ? "True" : "False");
|
||||
|
@ -84,6 +92,7 @@ void obResource::setValue(const std::string &rname, bool value) {
|
|||
}
|
||||
|
||||
void obResource::setValue(const std::string &rname, long value) {
|
||||
assert(rname.c_str() != NULL);
|
||||
assert(m_database != NULL);
|
||||
|
||||
char val[11];
|
||||
|
@ -97,6 +106,7 @@ void obResource::setValue(const std::string &rname, long value) {
|
|||
}
|
||||
|
||||
void obResource::setValue(const std::string &rname, const char *value) {
|
||||
assert(rname.c_str() != NULL);
|
||||
assert(m_database != NULL);
|
||||
|
||||
std::string rc_string = rname + ": " + value;
|
||||
|
@ -108,6 +118,7 @@ void obResource::setValue(const std::string &rname, const char *value) {
|
|||
}
|
||||
|
||||
void obResource::setValue(const std::string &rname, const std::string &value) {
|
||||
assert(rname.c_str() != NULL);
|
||||
assert(m_database != NULL);
|
||||
|
||||
std::string rc_string = rname + ": " + value;
|
||||
|
|
|
@ -30,9 +30,10 @@
|
|||
class obResource {
|
||||
public:
|
||||
obResource(const std::string &file);
|
||||
obResource();
|
||||
virtual ~obResource();
|
||||
|
||||
// an empty string is an invalid value for the file and will cause an assert
|
||||
// an empty string will cause an assert if load() or save() is called
|
||||
inline const std::string &file() const {
|
||||
return static_cast<const std::string &>(m_file);
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@
|
|||
#include "Workspace.h"
|
||||
#include "Workspacemenu.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
# include <stdio.h>
|
||||
#endif // HAVE_STDIO_H
|
||||
|
@ -171,6 +173,7 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
|
|||
} else {
|
||||
rc_file = bstrdup(rc);
|
||||
}
|
||||
config.setFile(rc_file);
|
||||
|
||||
no_focus = False;
|
||||
|
||||
|
@ -1200,89 +1203,64 @@ void Openbox::save_rc(void) {
|
|||
|
||||
|
||||
void Openbox::load_rc(void) {
|
||||
XrmDatabase database = (XrmDatabase) 0;
|
||||
|
||||
database = XrmGetFileDatabase(rc_file);
|
||||
|
||||
XrmValue value;
|
||||
char *value_type;
|
||||
config.load();
|
||||
|
||||
std::string s;
|
||||
long l;
|
||||
bool b;
|
||||
|
||||
if (resource.menu_file)
|
||||
delete [] resource.menu_file;
|
||||
|
||||
if (XrmGetResource(database, "session.menuFile", "Session.MenuFile",
|
||||
&value_type, &value))
|
||||
resource.menu_file = bstrdup(value.addr);
|
||||
if (config.getValue("session.menuFile", "Session.MenuFile", s))
|
||||
resource.menu_file = bstrdup(s.c_str());
|
||||
else
|
||||
resource.menu_file = bstrdup(DEFAULTMENU);
|
||||
|
||||
if (XrmGetResource(database, "session.colorsPerChannel",
|
||||
"Session.ColorsPerChannel", &value_type, &value)) {
|
||||
if (sscanf(value.addr, "%d", &resource.colors_per_channel) != 1) {
|
||||
resource.colors_per_channel = 4;
|
||||
} else {
|
||||
if (resource.colors_per_channel < 2) resource.colors_per_channel = 2;
|
||||
if (resource.colors_per_channel > 6) resource.colors_per_channel = 6;
|
||||
}
|
||||
} else {
|
||||
if (config.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
|
||||
l))
|
||||
resource.colors_per_channel = (l < 2 ? 2 : (l > 6 ? 6 : l)); // >= 2, <= 6
|
||||
else
|
||||
resource.colors_per_channel = 4;
|
||||
}
|
||||
|
||||
if (resource.style_file)
|
||||
delete [] resource.style_file;
|
||||
|
||||
if (XrmGetResource(database, "session.styleFile", "Session.StyleFile",
|
||||
&value_type, &value))
|
||||
resource.style_file = bstrdup(value.addr);
|
||||
if (config.getValue("session.styleFile", "Session.StyleFile", s))
|
||||
resource.style_file = bstrdup(s.c_str());
|
||||
else
|
||||
resource.style_file = bstrdup(DEFAULTSTYLE);
|
||||
|
||||
if (XrmGetResource(database, "session.titlebarLayout",
|
||||
"Session.TitlebarLayout", &value_type, &value)) {
|
||||
resource.titlebar_layout = bstrdup(value.addr == NULL ? "ILMC" :
|
||||
value.addr);
|
||||
} else {
|
||||
if (resource.titlebar_layout)
|
||||
delete [] resource.titlebar_layout;
|
||||
if (config.getValue("session.titlebarLayout", "Session.TitlebarLayout", s))
|
||||
resource.titlebar_layout = bstrdup(s.c_str());
|
||||
else
|
||||
resource.titlebar_layout = bstrdup("ILMC");
|
||||
}
|
||||
|
||||
if (XrmGetResource(database, "session.doubleClickInterval",
|
||||
"Session.DoubleClickInterval", &value_type, &value)) {
|
||||
if (sscanf(value.addr, "%lu", &resource.double_click_interval) != 1)
|
||||
resource.double_click_interval = 250;
|
||||
} else {
|
||||
if (config.getValue("session.doubleClickInterval",
|
||||
"Session.DoubleClickInterval", l))
|
||||
resource.double_click_interval = l;
|
||||
else
|
||||
resource.double_click_interval = 250;
|
||||
}
|
||||
|
||||
if (XrmGetResource(database, "session.autoRaiseDelay",
|
||||
"Session.AutoRaiseDelay", &value_type, &value)) {
|
||||
if (sscanf(value.addr, "%ld", &resource.auto_raise_delay.tv_usec) != 1)
|
||||
resource.auto_raise_delay.tv_usec = 400;
|
||||
} else {
|
||||
if (!config.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l))
|
||||
resource.auto_raise_delay.tv_usec = l;
|
||||
else
|
||||
resource.auto_raise_delay.tv_usec = 400;
|
||||
}
|
||||
|
||||
resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec / 1000;
|
||||
resource.auto_raise_delay.tv_usec -=
|
||||
(resource.auto_raise_delay.tv_sec * 1000);
|
||||
resource.auto_raise_delay.tv_usec *= 1000;
|
||||
|
||||
if (XrmGetResource(database, "session.cacheLife", "Session.CacheLife",
|
||||
&value_type, &value)) {
|
||||
if (sscanf(value.addr, "%lu", &resource.cache_life) != 1)
|
||||
resource.cache_life = 5l;
|
||||
} else {
|
||||
resource.cache_life = 5l;
|
||||
}
|
||||
|
||||
if (config.getValue("session.cacheLife", "Session.CacheLife", l))
|
||||
resource.cache_life = l;
|
||||
else
|
||||
resource.cache_life = 51;
|
||||
resource.cache_life *= 60000;
|
||||
|
||||
if (XrmGetResource(database, "session.cacheMax", "Session.CacheMax",
|
||||
&value_type, &value)) {
|
||||
if (sscanf(value.addr, "%lu", &resource.cache_max) != 1)
|
||||
resource.cache_max = 200;
|
||||
} else {
|
||||
if (config.getValue("session.cacheMax", "Session.CacheMax", l))
|
||||
resource.cache_max = l;
|
||||
else
|
||||
resource.cache_max = 200;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
# endif // HAVE_SYS_TIME_H
|
||||
#endif // TIME_WITH_SYS_TIME
|
||||
|
||||
|
||||
#include "Resource.h"
|
||||
#include "LinkedList.h"
|
||||
#include "BaseDisplay.h"
|
||||
#include "Timer.h"
|
||||
|
@ -115,6 +115,7 @@ private:
|
|||
Window masked;
|
||||
char *rc_file, **argv;
|
||||
int argc;
|
||||
obResource config;
|
||||
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in a new issue