combjs

view 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 source
1 #include <stdio.h>
2 #include <QApplication>
3 #include <QMessageBox>
4 #include "combjs.h"
5 #include "gui.h"
7 MainWindow *main_win;
9 int main(int argc, char **argv)
10 {
11 QApplication app(argc, argv);
13 main_win = new MainWindow;
14 main_win->show();
16 return app.exec();
17 }
19 int enum_joysticks(std::vector<Joystick> *jsvec)
20 {
21 jsvec->clear();
23 FILE *pipe = popen("combjs -l", "r");
24 if(!pipe) {
25 QMessageBox::critical(main_win, "Critical error",
26 "Failed to execute combjs, make sure it's installed in the path.");
27 exit(1);
28 }
30 char line[512];
31 while(fgets(line, sizeof line, pipe)) {
32 Joystick js;
33 char *ptr, *end;
35 if(!(ptr = strchr(line, ':'))) {
36 goto inval;
37 }
38 *ptr++ = 0;
40 js.dev = line;
42 if(!(ptr = strchr(ptr, '"')) || !(end = strchr(ptr + 1, '"'))) {
43 goto inval;
44 }
45 *end = 0;
47 js.name = ptr + 1;
48 ptr = end + 1;
50 if(sscanf(ptr, ", axes: %d, buttons: %d", &js.num_axes, &js.num_bn) != 2) {
51 goto inval;
52 }
54 js.isvirt = false;
55 jsvec->push_back(js);
56 }
57 pclose(pipe);
59 return jsvec->size();
61 inval:
62 QMessageBox::critical(main_win, "Invalid combjs output",
63 "The output from combjs is in an unexpected format, version missmatch?");
64 exit(1);
65 return -1; /* unreachable (duh) */
66 }