-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.cpp
72 lines (59 loc) · 1.92 KB
/
action.cpp
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
#include "action.h"
Action::Action(QObject *parent) : QObject(parent)
{
}
Action::Action(int game, QString key) {
this->game = game;
this->key = key;
if (game == CHESS) {
map.insert("one", 7);
map.insert("two", 6);
map.insert("three", 5);
map.insert("four", 4);
map.insert("five", 3);
map.insert("six", 2);
map.insert("seven", 1);
map.insert("eight", 0);
map.insert("a", 0);
map.insert("b", 1);
map.insert("c", 2);
map.insert("d", 3);
map.insert("e", 4);
map.insert("f", 5);
map.insert("g", 6);
map.insert("h", 7);
}
}
void Action::execute() {
if (game == TETRIS) {
QString string("xdotool key " + key);
QByteArray string8bit = string.toLocal8Bit();
const char* command = string8bit.data();
system (command);
}
else if (game == CHESS) {
QStringList list = key.split(" ");
QStringList move;
move.append(QString::number(map[list[0]]));
move.append(QString::number(map[list[1]]));
move.append(QString::number(map[list[3]]));
move.append(QString::number(map[list[4]]));
QString toSend = move.at(0) + "," + move.at(1) +","+ move.at(2) +","
+ move.at(3);
QByteArray msg = toSend.toUtf8();
sharedMemory.setKey("VoiceChess");
if (!sharedMemory.attach()) {
qDebug() << "Unable to attach mem seg";
qDebug() << QString::fromUtf8(sharedMemory.errorString().toStdString().c_str());
return;
}
QBuffer *buffer = new QBuffer;
buffer->setBuffer(&msg);
int size = buffer->size();
sharedMemory.lock();
char *to = (char*) (sharedMemory.data());
const char *from = buffer->data().data();
memcpy(to, from, qMin(sharedMemory.size(), size));
sharedMemory.unlock();
}
}