Add log widget to lower dock
[frida/frida.git] / src / gui / widgets / ScriptingDock.cxx
1 #include "ScriptingDock.hxx"
2 #include "FridaDock.hxx"
3
4 #include "bindings/Interpreter.hxx"
5
6 #include <sstream>
7
8 ScriptingDock::ScriptingDock(Interpreter* interpreter, FridaDock* parent)
9 : QWidget(parent)
10 , logger(log4cxx::Logger::getLogger("ScriptingDock"))
11 , interpreter(interpreter) {
12 setLayout(layout = new QGridLayout);
13 layout->addWidget(browser = new QTextBrowser, 0, 0, 1, 0);
14 layout->addWidget(line = new QLineEdit, 1, 0);
15 layout->addWidget(button = new QPushButton(tr("Evaluate")), 1, 1);
16 connect(button, SIGNAL(released()), this, SLOT(doEvaluate()));
17 connect(line, SIGNAL(returnPressed()), this, SLOT(doEvaluate()));
18 }
19
20
21 void ScriptingDock::doEvaluate() {
22 std::stringstream stdout, stderr;
23 std::string result;
24 QString output;
25 QString text = line->text();
26
27 line->clear();
28 LOG4CXX_INFO(logger, "Evaluating String \"" << text.toStdString() << "\"");
29 browser->append(QString("> ") + text);
30
31 interpreter->evaluate(text.toStdString(), stdout, stderr, result);
32
33 output = stdout.str().c_str();
34 if (output.endsWith("\n")) output.chop(1);
35 if (output != "") browser->append(output);
36
37 output = stderr.str().c_str();
38 if (output.endsWith("\n")) output.chop(1);
39 if (output != "") browser->append(output);
40
41 browser->append(result.c_str());
42 }