combjs
diff gui/combjs-gui.cc @ 1:dd02002227a2
- added a few commandline arguments to combjs
- trying to make a gui frontend
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 14 Jul 2011 15:40:20 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gui/combjs-gui.cc Thu Jul 14 15:40:20 2011 +0300 1.3 @@ -0,0 +1,66 @@ 1.4 +#include <stdio.h> 1.5 +#include <QApplication> 1.6 +#include <QMessageBox> 1.7 +#include "combjs.h" 1.8 +#include "gui.h" 1.9 + 1.10 +MainWindow *main_win; 1.11 + 1.12 +int main(int argc, char **argv) 1.13 +{ 1.14 + QApplication app(argc, argv); 1.15 + 1.16 + main_win = new MainWindow; 1.17 + main_win->show(); 1.18 + 1.19 + return app.exec(); 1.20 +} 1.21 + 1.22 +int enum_joysticks(std::vector<Joystick> *jsvec) 1.23 +{ 1.24 + jsvec->clear(); 1.25 + 1.26 + FILE *pipe = popen("combjs -l", "r"); 1.27 + if(!pipe) { 1.28 + QMessageBox::critical(main_win, "Critical error", 1.29 + "Failed to execute combjs, make sure it's installed in the path."); 1.30 + exit(1); 1.31 + } 1.32 + 1.33 + char line[512]; 1.34 + while(fgets(line, sizeof line, pipe)) { 1.35 + Joystick js; 1.36 + char *ptr, *end; 1.37 + 1.38 + if(!(ptr = strchr(line, ':'))) { 1.39 + goto inval; 1.40 + } 1.41 + *ptr++ = 0; 1.42 + 1.43 + js.dev = line; 1.44 + 1.45 + if(!(ptr = strchr(ptr, '"')) || !(end = strchr(ptr + 1, '"'))) { 1.46 + goto inval; 1.47 + } 1.48 + *end = 0; 1.49 + 1.50 + js.name = ptr + 1; 1.51 + ptr = end + 1; 1.52 + 1.53 + if(sscanf(ptr, ", axes: %d, buttons: %d", &js.num_axes, &js.num_bn) != 2) { 1.54 + goto inval; 1.55 + } 1.56 + 1.57 + js.isvirt = false; 1.58 + jsvec->push_back(js); 1.59 + } 1.60 + pclose(pipe); 1.61 + 1.62 + return jsvec->size(); 1.63 + 1.64 +inval: 1.65 + QMessageBox::critical(main_win, "Invalid combjs output", 1.66 + "The output from combjs is in an unexpected format, version missmatch?"); 1.67 + exit(1); 1.68 + return -1; /* unreachable (duh) */ 1.69 +}