-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStdinConnection.cpp
47 lines (35 loc) · 960 Bytes
/
StdinConnection.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
#include <QtCore/QSocketNotifier>
#include "StdinConnection.h"
StdinConnection::StdinConnection(QObject *parent)
: QObject(parent)
, m_stdin(stdin, QIODevice::ReadOnly)
{
QSocketNotifier *n1 = new QSocketNotifier(0, QSocketNotifier::Read, this);
connect(n1, SIGNAL(activated(int)), this, SLOT(read()));
QSocketNotifier *n2 = new QSocketNotifier(0, QSocketNotifier::Exception, this);
connect(n2, SIGNAL(activated(int)), this, SIGNAL(close()));
QTextStream m_stdout(stdout, QIODevice::WriteOnly);
m_stdout << "OK\n";
m_stdout.flush();
}
StdinConnection::~StdinConnection()
{
}
void StdinConnection::read()
{
if (m_stdin.atEnd()) {
emit close();
return;
}
QString cmd;
m_stdin >> cmd;
if (cmd.isEmpty() || cmd == "QUIT") {
emit close();
return;
}
if (cmd == "TOGGLE") {
emit toggleVisible();
return;
}
}
#include "StdinConnection.moc"