b334d712a1f20f552b6dab689fa57bc26e457c08
[frida/frida.git] / src / gui / widgets / ScriptingDock.cxx
1 #include "ScriptingDock.hxx"
2 #include "bindings/Interpreter.hxx"
3
4 #include <sstream>
5
6 ScriptingDock::ScriptingDock(Interpreter* interpreter, const QString& title, QWidget * parent)
7 : QDockWidget(title, parent)
8 , logger(log4cxx::Logger::getLogger("ScriptingDock"))
9 , interpreter(interpreter) {
10 QTabWidget * tab = new QTabWidget;
11 QWidget * widget = new QWidget;
12 widget->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 tab->addTab(widget, "GUILE");
17 ((QDockWidget*)this)->setWidget(tab);
18 connect(button, SIGNAL(released()), this, SLOT(doEvaluate()));
19 connect(line, SIGNAL(returnPressed()), this, SLOT(doEvaluate()));
20 }
21
22
23 void ScriptingDock::doEvaluate() {
24 std::stringstream stdout, stderr;
25 std::string result;
26 QString output;
27 QString text = line->text();
28
29 line->clear();
30 LOG4CXX_INFO(logger, "Evaluating String \"" << text.toStdString() << "\"");
31 browser->append(QString("> ") + text);
32
33 interpreter->evaluate(text.toStdString(), stdout, stderr, result);
34
35 output = stdout.str().c_str();
36 if (output.endsWith("\n")) output.chop(1);
37 if (output != "") browser->append(output);
38
39 output = stderr.str().c_str();
40 if (output.endsWith("\n")) output.chop(1);
41 if (output != "") browser->append(output);
42
43 browser->append(result.c_str());
44 }