aboutsummaryrefslogtreecommitdiff
path: root/src/Keys.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-12-20 17:37:57 (GMT)
committerfluxgen <fluxgen>2003-12-20 17:37:57 (GMT)
commit29c778459955d5aaa17e619f8acf09dc3ec1d9b2 (patch)
treecee66d71d15d855b71f2987f6de255ac3e7a92db /src/Keys.cc
parent7e167d9b83e81a634a4bdc09ba78be5d83bbbc37 (diff)
downloadfluxbox-29c778459955d5aaa17e619f8acf09dc3ec1d9b2.zip
fluxbox-29c778459955d5aaa17e619f8acf09dc3ec1d9b2.tar.bz2
addBinding function and some cleaning
Diffstat (limited to 'src/Keys.cc')
-rw-r--r--src/Keys.cc172
1 files changed, 100 insertions, 72 deletions
diff --git a/src/Keys.cc b/src/Keys.cc
index d5bf786..8ca47c3 100644
--- a/src/Keys.cc
+++ b/src/Keys.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22//$Id: Keys.cc,v 1.39 2003/12/04 21:31:02 fluxgen Exp $ 22//$Id: Keys.cc,v 1.40 2003/12/20 17:37:57 fluxgen Exp $
23 23
24 24
25#include "Keys.hh" 25#include "Keys.hh"
@@ -118,97 +118,125 @@ bool Keys::load(const char *filename) {
118 if (!infile) 118 if (!infile)
119 return false; // faild to open file 119 return false; // faild to open file
120 120
121 int line=0;//current line, so we can tell the user where the fault is 121 m_current_line = 0;//current line, so we can tell the user where the fault is
122 122
123 while (!infile.eof()) { 123 while (!infile.eof()) {
124 string linebuffer; 124 string linebuffer;
125 125
126 getline(infile, linebuffer); 126 getline(infile, linebuffer);
127 127
128 line++; 128 m_current_line++;
129 vector<string> val;
130 //Parse arguments
131 FbTk::StringUtil::stringtok(val, linebuffer.c_str());
132 129
133 //must have at least 1 argument 130 addBinding(linebuffer);
134 if (val.size() <= 0) 131 } // end while eof
135 continue; 132
133 m_current_line = 0;
134 m_filename = filename;
135 return true;
136}
137
138bool Keys::save(const char *filename) const {
139 //!!
140 //!! TODO: fix keybinding saving
141 //!! (we probably need to save key actions
142 //!! as strings instead of creating new Commands)
143
144 // open file for writing
145 // ofstream outfile(filename);
146 // if (!outfile)
147 return false;
148 // return true;
149}
150
151bool Keys::addBinding(const std::string &linebuffer) {
152
153 vector<string> val;
154 // Parse arguments
155 FbTk::StringUtil::stringtok(val, linebuffer.c_str());
156
157 // must have at least 1 argument
158 if (val.size() <= 0)
159 return true; // empty lines are valid.
136 160
137 if (val[0][0] == '#') //the line is commented 161 if (val[0][0] == '#') //the line is commented
138 continue; 162 return true; // still a valid line.
139 163
140 unsigned int key=0, mod=0; 164 unsigned int key = 0, mod = 0;
141 char keyarg=0; 165 char keyarg = 0;
142 t_key *current_key=0, *last_key=0; 166 t_key *current_key=0, *last_key=0;
143 167
144 for (unsigned int argc=0; argc<val.size(); argc++) { 168 // for each argument
145 169 for (unsigned int argc=0; argc<val.size(); argc++) {
146 if (val[argc][0] != ':') { // parse key(s) 170
147 keyarg++; 171 if (val[argc][0] != ':') { // parse key(s)
148 if (keyarg==1) //first arg is modifier 172 keyarg++;
149 mod = FbTk::KeyUtil::getModifier(val[argc].c_str()); 173 if (keyarg==1) //first arg is modifier
150 else if (keyarg>1) { 174 mod = FbTk::KeyUtil::getModifier(val[argc].c_str());
151 175 else if (keyarg > 1) {
152 //keyarg=0; 176
153 int tmpmod = FbTk::KeyUtil::getModifier(val[argc].c_str()); 177 int tmpmod = FbTk::KeyUtil::getModifier(val[argc].c_str());
154 if(tmpmod) 178 if(tmpmod)
155 mod|=tmpmod; //If it's a modifier 179 mod |= tmpmod; //If it's a modifier
156 else { 180 else {
157 key = FbTk::KeyUtil::getKey(val[argc].c_str()); // else get the key 181 key = FbTk::KeyUtil::getKey(val[argc].c_str()); // else get the key
158 if (key == 0) { 182 if (key == 0) {
159 cerr<<"["<<filename<<"]: Invalid key/modifier on line("<< 183 cerr<<"Keys: Invalid key/modifier on line("<<
160 line<<"): "<<linebuffer<<endl; 184 m_current_line<<"): "<<linebuffer<<endl;
161 break; // get next line 185 return false;
162 } 186 }
163 if (!current_key) { 187 if (!current_key) {
164 current_key = new t_key(key, mod); 188 current_key = new t_key(key, mod);
165 last_key = current_key; 189 last_key = current_key;
166 } else { 190 } else {
167 t_key *temp_key = new t_key(key, mod); 191 t_key *temp_key = new t_key(key, mod);
168 last_key->keylist.push_back(temp_key); 192 last_key->keylist.push_back(temp_key);
169 last_key = temp_key; 193 last_key = temp_key;
170 }
171 } 194 }
172 }
173
174 } else { // parse command line
175 if (last_key == 0) {
176 cerr<<"File: "<<filename<<". Error on line: "<<line<<endl;
177 cerr<<"> "<<linebuffer<<endl;
178 break;
179 } 195 }
196 }
180 197
181 const char *str = 198 } else { // parse command line
182 FbTk::StringUtil::strcasestr(linebuffer.c_str(), 199 if (last_key == 0) {
183 val[argc].c_str() + 1); // +1 to skip ':' 200 cerr<<"Keys: Error on line: "<<m_current_line<<endl;
184 if (str == 0) { 201 cerr<<"> "<<linebuffer<<endl;
185 cerr<<"File: "<<filename<<". Error on line: "<<line<<endl; 202 return false;
186 cerr<<"> "<<linebuffer<<endl; 203 }
187 } else { 204 bool ret_val = true;
205 const char *str =
206 FbTk::StringUtil::strcasestr(linebuffer.c_str(),
207 val[argc].c_str() + 1); // +1 to skip ':'
208 if (str == 0) {
209 cerr<<"Keys: Error on line: "<<m_current_line<<endl;
210 cerr<<"> "<<linebuffer<<endl;
211 ret_val = false;
212 } else {
188 213
189 last_key->m_command = CommandParser::instance().parseLine(str); 214 last_key->m_command = CommandParser::instance().parseLine(str);
190 215
191 if (*last_key->m_command == 0) { 216 if (*last_key->m_command == 0) {
192 cerr<<"File: "<<filename<<". Error on line: "<<line<<endl; 217 cerr<<"Keys: Error on line: "<<m_current_line<<endl;
193 cerr<<"> "<<linebuffer<<endl; 218 cerr<<"> "<<linebuffer<<endl;
194 } else { 219 } else {
195 // Add the keychain to list 220 // Add the keychain to list
196 if (!mergeTree(current_key)) 221 if (!mergeTree(current_key)) {
197 cerr<<"Keys: Failed to merge keytree!"<<endl; 222 cerr<<"Keys: Failed to merge keytree!"<<endl;
223 ret_val = false;
198 } 224 }
199 } 225 }
200 delete current_key; 226 }
201 current_key = 0; 227 delete current_key;
202 last_key = 0; 228 current_key = 0;
229 last_key = 0;
203 230
204 break; // dont process this linebuffer more 231 return ret_val;
205 } // end if
206 } // end for
207 } // end while eof
208 232
209 return true; 233 } // end if
234 } // end for
235
236 return false;
210} 237}
211 238
239
212/** 240/**
213 @return the KeyAction of the XKeyEvent 241 @return the KeyAction of the XKeyEvent
214*/ 242*/