src/Resources.cc (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
// holds main resource functions #include "fluxbox.hh" #include "FbTk/StringUtil.hh" #include <stdio.h> #include <string> using namespace std; using namespace FbTk; //----------------------------------------------------------------- //---- accessors for int, bool, and some enums with Resource ------ //----------------------------------------------------------------- template<> void FbTk::Resource<int>:: setFromString(const char* strval) { int val; if (sscanf(strval, "%d", &val)==1) *this = val; } template<> void FbTk::Resource<std::string>:: setFromString(const char *strval) { *this = strval; } template<> void FbTk::Resource<bool>:: setFromString(char const *strval) { *this = (bool)!strcasecmp(strval, "true"); } template<> void FbTk::Resource<Fluxbox::TitlebarList>:: setFromString(char const *strval) { vector<std::string> val; StringUtil::stringtok(val, strval); int size=val.size(); //clear old values m_value.clear(); for (int i=0; i<size; i++) { if (strcasecmp(val[i].c_str(), "Maximize")==0) m_value.push_back(Fluxbox::MAXIMIZE); else if (strcasecmp(val[i].c_str(), "Minimize")==0) m_value.push_back(Fluxbox::MINIMIZE); else if (strcasecmp(val[i].c_str(), "Shade")==0) m_value.push_back(Fluxbox::SHADE); else if (strcasecmp(val[i].c_str(), "Stick")==0) m_value.push_back(Fluxbox::STICK); else if (strcasecmp(val[i].c_str(), "Menu")==0) m_value.push_back(Fluxbox::MENU); else if (strcasecmp(val[i].c_str(), "Close")==0) m_value.push_back(Fluxbox::CLOSE); } } template<> void FbTk::Resource<Fluxbox::TabsAttachArea>:: setFromString(char const *strval) { if (strcasecmp(strval, "Titlebar")==0) m_value= Fluxbox::ATTACH_AREA_TITLEBAR; else m_value= Fluxbox::ATTACH_AREA_WINDOW; } template<> void FbTk::Resource<unsigned int>:: setFromString(const char *strval) { if (sscanf(strval, "%ul", &m_value) != 1) setDefaultValue(); } template<> void FbTk::Resource<long long>:: setFromString(const char *strval) { if (sscanf(strval, "%ul", &m_value) != 1) setDefaultValue(); } //----------------------------------------------------------------- //---- manipulators for int, bool, and some enums with Resource --- //----------------------------------------------------------------- template<> std::string FbTk::Resource<bool>:: getString() { return std::string(**this == true ? "true" : "false"); } template<> std::string FbTk::Resource<int>:: getString() { char strval[256]; sprintf(strval, "%d", **this); return std::string(strval); } template<> std::string FbTk::Resource<std::string>:: getString() { return **this; } template<> std::string FbTk::Resource<Fluxbox::TitlebarList>:: getString() { string retval; int size=m_value.size(); for (int i=0; i<size; i++) { switch (m_value[i]) { case Fluxbox::SHADE: retval.append("Shade"); break; case Fluxbox::MINIMIZE: retval.append("Minimize"); break; case Fluxbox::MAXIMIZE: retval.append("Maximize"); break; case Fluxbox::CLOSE: retval.append("Close"); break; case Fluxbox::STICK: retval.append("Stick"); break; case Fluxbox::MENU: retval.append("Menu"); break; default: break; } retval.append(" "); } return retval; } template<> std::string FbTk::Resource<Fluxbox::TabsAttachArea>:: getString() { if (m_value == Fluxbox::ATTACH_AREA_TITLEBAR) return "Titlebar"; else return "Window"; } template<> string FbTk::Resource<unsigned int>:: getString() { char tmpstr[128]; sprintf(tmpstr, "%ul", m_value); return string(tmpstr); } template<> string FbTk::Resource<long long>:: getString() { char tmpstr[128]; sprintf(tmpstr, "%ul", m_value); return string(tmpstr); } template<> void FbTk::Resource<Fluxbox::Layer>:: setFromString(const char *strval) { int tempnum = 0; if (sscanf(strval, "%d", &tempnum) == 1) m_value = tempnum; else if (strcasecmp(strval, "Menu") == 0) m_value = Fluxbox::instance()->getMenuLayer(); else if (strcasecmp(strval, "AboveDock") == 0) m_value = Fluxbox::instance()->getAboveDockLayer(); else if (strcasecmp(strval, "Dock") == 0) m_value = Fluxbox::instance()->getDockLayer(); else if (strcasecmp(strval, "Top") == 0) m_value = Fluxbox::instance()->getTopLayer(); else if (strcasecmp(strval, "Normal") == 0) m_value = Fluxbox::instance()->getNormalLayer(); else if (strcasecmp(strval, "Bottom") == 0) m_value = Fluxbox::instance()->getBottomLayer(); else if (strcasecmp(strval, "Desktop") == 0) m_value = Fluxbox::instance()->getDesktopLayer(); else setDefaultValue(); } template<> string FbTk::Resource<Fluxbox::Layer>:: getString() { if (m_value.getNum() == Fluxbox::instance()->getMenuLayer()) return string("Menu"); else if (m_value.getNum() == Fluxbox::instance()->getAboveDockLayer()) return string("AboveDock"); else if (m_value.getNum() == Fluxbox::instance()->getDockLayer()) return string("Dock"); else if (m_value.getNum() == Fluxbox::instance()->getTopLayer()) return string("Top"); else if (m_value.getNum() == Fluxbox::instance()->getNormalLayer()) return string("Normal"); else if (m_value.getNum() == Fluxbox::instance()->getBottomLayer()) return string("Bottom"); else if (m_value.getNum() == Fluxbox::instance()->getDesktopLayer()) return string("Desktop"); else { char tmpstr[128]; sprintf(tmpstr, "%d", m_value.getNum()); return string(tmpstr); } } template<> void FbTk::Resource<long>:: setFromString(const char *strval) { if (sscanf(strval, "%ld", &m_value) != 1) setDefaultValue(); } template<> string FbTk::Resource<long>:: getString() { char tmpstr[128]; sprintf(tmpstr, "%ld", m_value); return string(tmpstr); } |