From: Marius Nita Date: Wed, 6 Nov 2002 14:02:50 +0000 (+0000) Subject: moved em to otk X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=29d640fdc2d7d3f2b1a8608daae1799ee947167e;p=chaz%2Fopenbox moved em to otk --- diff --git a/src/configuration.cc b/src/configuration.cc deleted file mode 100644 index 4d0af097..00000000 --- a/src/configuration.cc +++ /dev/null @@ -1,237 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif // HAVE_CONFIG_H - -extern "C" { -#ifdef HAVE_STDLIB_H -# include -#endif // HAVE_STDLIB_H -} - -#include "configuration.hh" -#include "util.hh" - -#include - -using std::string; - -namespace ob { - -bool Configuration::_initialized = False; - -Configuration::Configuration(const string &file, bool autosave) { - setFile(file); - _modified = False; - _database = NULL; - _autosave = autosave; - if (! _initialized) { - XrmInitialize(); - _initialized = True; - } -} - -Configuration::Configuration(bool autosave) { - _modified = False; - _database = NULL; - _autosave = autosave; - if (! _initialized) { - XrmInitialize(); - _initialized = True; - } -} - -Configuration::~Configuration() { - if (_database != NULL) - XrmDestroyDatabase(_database); -} - -void Configuration::setFile(const string &file) { - _file = file; -} - -void Configuration::setAutoSave(bool autosave) { - _autosave = autosave; -} - -void Configuration::save() { - assert(_database != NULL); - XrmPutFileDatabase(_database, _file.c_str()); - _modified = False; -} - -bool Configuration::load() { - if (_database != NULL) - XrmDestroyDatabase(_database); - _modified = False; - if (NULL == (_database = XrmGetFileDatabase(_file.c_str()))) - return False; - return True; -} - -bool Configuration::merge(const string &file, bool overwrite) { - if (XrmCombineFileDatabase(file.c_str(), &_database, overwrite) == 0) - return False; - _modified = True; - if (_autosave) - save(); - return True; -} - -void Configuration::create() { - if (_database != NULL) - XrmDestroyDatabase(_database); - _modified = False; - assert(NULL != (_database = XrmGetStringDatabase(""))); -} - -void Configuration::setValue(const string &rname, bool value) { - assert(_database != NULL); - - const char *val = (value ? "True" : "False"); - string rc_string = rname + ": " + val; - XrmPutLineResource(&_database, rc_string.c_str()); - - _modified = True; - if (_autosave) - save(); -} - -void Configuration::setValue(const string &rname, unsigned long value) { - assert(_database != NULL); - - string rc_string = rname + ": " + itostring(value); - XrmPutLineResource(&_database, rc_string.c_str()); - - _modified = True; - if (_autosave) - save(); -} - -void Configuration::setValue(const string &rname, long value) { - assert(_database != NULL); - - string rc_string = rname + ": " + itostring(value); - XrmPutLineResource(&_database, rc_string.c_str()); - - _modified = True; - if (_autosave) - save(); -} - -void Configuration::setValue(const string &rname, const char *value) { - assert(_database != NULL); - assert(value != NULL); - - string rc_string = rname + ": " + value; - XrmPutLineResource(&_database, rc_string.c_str()); - - _modified = True; - if (_autosave) - save(); -} - -void Configuration::setValue(const string &rname, const string &value) { - assert(_database != NULL); - - string rc_string = rname + ": " + value; - XrmPutLineResource(&_database, rc_string.c_str()); - - _modified = True; - if (_autosave) - save(); -} - -bool Configuration::getValue(const string &rname, bool &value) const { - assert(_database != NULL); - - string rclass = createClassName(rname); - - char *rettype; - XrmValue retvalue; - if (0 == XrmGetResource(_database, rname.c_str(), rclass.c_str(), - &rettype, &retvalue) || retvalue.addr == NULL) - return False; - string val = retvalue.addr; - if (val == "True" || val == "True") - value = True; - else - value = False; - return True; -} - -bool Configuration::getValue(const string &rname, long &value) const { - assert(_database != NULL); - - string rclass = createClassName(rname); - - char *rettype; - XrmValue retvalue; - if (0 == XrmGetResource(_database, rname.c_str(), rclass.c_str(), - &rettype, &retvalue) || retvalue.addr == NULL) - return False; - char *end; - value = strtol(retvalue.addr, &end, 10); - if (end == retvalue.addr) - return False; - return True; -} - -bool Configuration::getValue(const string &rname, unsigned long &value) const { - assert(_database != NULL); - - string rclass = createClassName(rname); - - char *rettype; - XrmValue retvalue; - if (0 == XrmGetResource(_database, rname.c_str(), rclass.c_str(), - &rettype, &retvalue) || retvalue.addr == NULL) - return False; - char *end; - value = strtoul(retvalue.addr, &end, 10); - if (end == retvalue.addr) - return False; - return True; -} - -bool Configuration::getValue(const string &rname, - string &value) const { - assert(_database != NULL); - - string rclass = createClassName(rname); - - char *rettype; - XrmValue retvalue; - if (0 == XrmGetResource(_database, rname.c_str(), rclass.c_str(), - &rettype, &retvalue) || retvalue.addr == NULL) - return False; - value = retvalue.addr; - return True; -} - - -string Configuration::createClassName(const string &rname) const { - string rclass(rname); - - string::iterator it = rclass.begin(), end = rclass.end(); - while (True) { - *it = toUpper(*it); - ++it; - if (it == end) break; - it = std::find(it, rclass.end(), '.'); - if (it == end) break; - ++it; - if (it == end) break; - } - return rclass; -} - - -char Configuration::toUpper(char c) const { - if (c >= 'a' && c <= 'z') - return c - 'a' + 'A'; - return c; -} - -} diff --git a/src/configuration.hh b/src/configuration.hh deleted file mode 100644 index 8a14604a..00000000 --- a/src/configuration.hh +++ /dev/null @@ -1,89 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __Configuration_hh -#define __Configuration_hh - -/*! @file configuration.hh - @brief Loads, saves, and provides configuration options for the window - manager -*/ - -extern "C" { -#include -#include -} - -#include - -namespace ob { - -/* - * The Configuration class is a generic wrapper for configuration settings. - * - * This class is used for the global rc/config file, and for styles. - * - * This implementation of the Configuration class wraps an X resource database - * file. - */ -class Configuration { -public: - explicit Configuration(const std::string &file, bool autosave = True); - Configuration(bool autosave = True); - virtual ~Configuration(); - - inline const std::string &file() const { - return static_cast(_file); - } - void setFile(const std::string &file); - - // defaults to true! - inline bool autoSave() const { - return _autosave; - } - void setAutoSave(bool); - - inline bool isModified() const { - return _modified; - } - - void save(); - bool load(); - bool merge(const std::string &file, bool overwrite = False); - void create(); - - void setValue(const std::string &rname, bool value); - inline void setValue(const std::string &rname, int value) { - setValue(rname, (long) value); - } - inline void setValue(const std::string &rname, unsigned int value) { - setValue(rname, (unsigned long) value); - } - void setValue(const std::string &rname, long value); - void setValue(const std::string &rname, unsigned long value); - void setValue(const std::string &rname, const std::string &value); - void setValue(const std::string &rname, const char *value); - - bool getValue(const std::string &rname, bool &value) const; - inline bool getValue(const std::string &rname, int &value) const { - return getValue(rname, (long) value); - } - inline bool getValue(const std::string &rname, unsigned int &value) const { - return getValue(rname, (unsigned long) value); - } - bool getValue(const std::string &rname, long &value) const; - bool getValue(const std::string &rname, unsigned long &value) const; - bool getValue(const std::string &rname, std::string &value) const; - -private: - std::string createClassName(const std::string &rname) const; - char toUpper(char) const; - - static bool _initialized; - std::string _file; - bool _modified; - bool _autosave; - XrmDatabase _database; -}; - -} - -#endif // __Configuration_hh diff --git a/src/util.cc b/src/util.cc deleted file mode 100644 index 77913952..00000000 --- a/src/util.cc +++ /dev/null @@ -1,114 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif // HAVE_CONFIG_H - -extern "C" { -#include - -#ifdef HAVE_STRING_H -#include -#endif - -#ifdef HAVE_STDLIB_H -#include -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif // HAVE_UNISTD_H - -#if defined(HAVE_PROCESS_H) && defined(__EMX__) -# include -#endif // HAVE_PROCESS_H __EMX__ - -#include -} - -#include - -#include "util.hh" - -using std::string; - -namespace ob { - -string expandTilde(const string& s) { - if (s[0] != '~') return s; - - const char* const home = getenv("HOME"); - if (home == NULL) return s; - - return string(home + s.substr(s.find('/'))); -} - - -void bexec(const string& command, const string& displaystring) { -#ifndef __EMX__ - if (! fork()) { - setsid(); - int ret = putenv(const_cast(displaystring.c_str())); - assert(ret != -1); - ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL); - exit(ret); - } -#else // __EMX__ - spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", command.c_str(), NULL); -#endif // !__EMX__ -} - - -string textPropertyToString(Display *display, XTextProperty& text_prop) { - string ret; - - if (text_prop.value && text_prop.nitems > 0) { - if (text_prop.encoding == XA_STRING) { - ret = (char *) text_prop.value; - } else { - text_prop.nitems = strlen((char *) text_prop.value); - - char **list; - int num; - if (XmbTextPropertyToTextList(display, &text_prop, - &list, &num) == Success && - num > 0 && *list) { - ret = *list; - XFreeStringList(list); - } - } - } - - return ret; -} - - -string itostring(unsigned long i) { - if (i == 0) - return string("0"); - - string tmp; - for (; i > 0; i /= 10) - tmp.insert(tmp.begin(), "0123456789"[i%10]); - return tmp; -} - - -string itostring(long i) { - std::string tmp = itostring( (unsigned long) std::abs(i)); - if (i < 0) - tmp.insert(tmp.begin(), '-'); - return tmp; -} - -} - -#ifndef HAVE_BASENAME -string basename (const string& path) { - string::size_type slash = path.rfind('/'); - if (slash == string::npos) - return path; - return path.substr(slash+1); -} -#endif // HAVE_BASENAME - diff --git a/src/util.hh b/src/util.hh deleted file mode 100644 index 303d2ffd..00000000 --- a/src/util.hh +++ /dev/null @@ -1,49 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef _BLACKBOX_UTIL_HH -#define _BLACKBOX_UTIL_HH - -extern "C" { -#include -#include - -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else // !TIME_WITH_SYS_TIME -# ifdef HAVE_SYS_TIME_H -# include -# else // !HAVE_SYS_TIME_H -# include -# endif // HAVE_SYS_TIME_H -#endif // TIME_WITH_SYS_TIME -} - - -#include -#include - -namespace ob { - -/* XXX: this needs autoconf help */ -const unsigned int BSENTINEL = 65535; - -std::string expandTilde(const std::string& s); - -void bexec(const std::string& command, const std::string& displaystring); - -std::string textPropertyToString(Display *display, XTextProperty& text_prop); - -std::string itostring(unsigned long i); -std::string itostring(long i); -inline std::string itostring(unsigned int i) - { return itostring((unsigned long) i); } -inline std::string itostring(int i) - { return itostring((long) i); } - -} - -#ifndef HAVE_BASENAME -std::string basename(const std::string& path); -#endif - -#endif