Move ScriptingDock contructor to cxx file
[frida/frida.git] / src / gui / widgets / ScriptingDock.cxx
1 #include "ScriptingDock.hxx"
2
3 namespace {
4 SCM handler (void*, SCM tag, SCM throw_args) {
5 scm_handle_by_message_noexit ((void*)"foo", tag, throw_args);
6 return SCM_BOOL_F;
7 }
8 }
9
10 ScriptingDock::ScriptingDock(const QString& title, QWidget * parent)
11 : QDockWidget(title, parent)
12 , logger(log4cxx::Logger::getLogger("ScriptingDock")) {
13 QTabWidget * tab = new QTabWidget;
14 QWidget * widget = new QWidget;
15 widget->setLayout(layout = new QGridLayout);
16 layout->addWidget(browser = new QTextBrowser, 0, 0, 1, 0);
17 layout->addWidget(line = new QLineEdit, 1, 0);
18 layout->addWidget(button = new QPushButton(tr("Evaluate")), 1, 1);
19 tab->addTab(widget, "GUILE");
20 ((QDockWidget*)this)->setWidget(tab);
21 connect(button, SIGNAL(released()), this, SLOT(doEvaluate()));
22 connect(line, SIGNAL(returnPressed()), this, SLOT(doEvaluate()));
23 scm_init_guile();
24 guile_output_port = scm_open_output_string();
25 guile_error_port = scm_open_output_string();
26 scm_set_current_output_port(guile_output_port);
27 scm_set_current_error_port(guile_error_port);
28 }
29
30
31 void ScriptingDock::doEvaluate() {
32 QString text = line->text();
33 line->clear();
34 LOG4CXX_INFO(logger, "Evaluating String \"" << text.toStdString() << "\"");
35 browser->append(QString("> ") + text);
36
37 SCM result_obj = scm_internal_catch(SCM_BOOL_T,
38 (SCM (*)(void *))scm_c_eval_string,
39 (void*)text.toStdString().c_str(),
40 handler, NULL);
41 SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
42
43 SCM output = scm_get_output_string(guile_output_port);
44 QString output_q = scm_to_locale_string(output);
45 if (output_q.endsWith("\n")) output_q.chop(1);
46 if (output_q != "") browser->append(output_q);
47
48 output = scm_get_output_string(guile_error_port);
49 output_q = scm_to_locale_string(output);
50 if (output_q.endsWith("\n")) output_q.chop(1);
51 if (output_q != "") browser->append(output_q);
52
53 scm_truncate_file(guile_output_port, scm_from_uint16(0));
54 scm_truncate_file(guile_error_port, scm_from_uint16(0));
55
56 browser->append(scm_to_locale_string(result_str));
57 }