8#include "QHyodaX11Emacs.h"
9#include "QHyodaX11Xterm.h"
23QHyodaX11Emacs::QHyodaX11Emacs(QWidget *parent,
27 qDebug() <<
"[NEW] QHyodaX11Emacs";
34QHyodaX11Emacs::~QHyodaX11Emacs(
void){
35 qDebug() <<
"~QHyodaX11Emacs";
66void QHyodaX11Emacs::clientIsEmbedded(){
67 qDebug()<<
"[QHyodaX11Emacs::clientIsEmbedded]";
75void QHyodaX11Emacs::clientClosed(){
76 qDebug() <<
"[QHyodaX11Emacs::clientClosed] Container clientClosed!";
92void QHyodaX11Emacs::launchEmacsInWindow(QWidget *widget, QString fileNameToOpen){
94 launchServerInWindow(widget, fileNameToOpen);
96 launchClient(fileNameToOpen);
103void QHyodaX11Emacs::launchServerInWindow(QWidget *widget, QString fileName){
104 qDebug() <<
"[QHyodaX11Emacs::launchServerInWindow]";
108 splitter->setStretchFactor(0, 3);
109 splitter->addWidget(
this);
112 X11Process.append(
new QProcess(widget));
113 X11Process.last()->setProcessChannelMode(QProcess::MergedChannels);
114 connect(X11Process.last(), SIGNAL(finished(
int, QProcess::ExitStatus)),
this, SLOT(serverFinished(
int, QProcess::ExitStatus)));
115 connect(X11Process.last(), SIGNAL(readyReadStandardOutput()),
this, SLOT(serverReadyReadStandardOutput()));
117 QString emacs_path(
"emacs");
118 QString setqEmacsName(
"(setq server-name \"");
119 setqEmacsName.append(title);
120 setqEmacsName.append(
"\")");
122 QStringList daemonArgs=QStringList()
128 <<
"--eval" << setqEmacsName
129 <<
"--eval" <<
"(setq server-raise-frame nil)"
130 <<
"--eval" <<
"(server-force-delete)"
131 <<
"--eval" <<
"(server-start)"
132 <<
"--eval" <<
"(hl-line-mode)"
136 <<
"--parent-id" << QString::number(this->winId());
137 if (fileName!=NULL) daemonArgs << fileName;
138 qDebug()<<
"daemonArgs:"<<daemonArgs;
139 X11Process.last()->start(emacs_path, daemonArgs);
140 if (!X11Process.last()->waitForStarted()) qFatal(
"emacs NOT started!");
141 qDebug()<<
"serverUp!";
148void QHyodaX11Emacs::launchXtermInWindow(QWidget *widget){
151 splitter->addWidget(
this);
153 X11Process.append(
new QProcess(widget));
154 X11Process.last()->setProcessChannelMode(QProcess::MergedChannels);
155 connect(X11Process.last(), SIGNAL(finished(
int, QProcess::ExitStatus)),
this, SLOT(xtermFinished(
int, QProcess::ExitStatus)));
156 connect(X11Process.last(), SIGNAL(readyReadStandardOutput()),
this, SLOT(xtermReadyReadStandardOutput()));
157 QString executable(
"/usr/bin/xterm");
158 QStringList arguments=QStringList() <<
"-fg" <<
"cyan"
161 <<
"-sb" <<
"-sl" <<
"8192"
169 <<
"-into" << QString::number(this->winId());
170 X11Process.last()->start(executable, arguments);
171 if (!X11Process.last()->waitForStarted()) qFatal(
"QHyodaX11Emacs::refresh NOT started!");
172 splitter->setStretchFactor(1,1);
179void QHyodaX11Emacs::launchClient(QString fileName){
180 qDebug()<<
"launchClient"<<fileName;
181 X11Process.append(
new QProcess(
this));
182 X11Process.last()->setProcessChannelMode(QProcess::MergedChannels);
183 connect(X11Process.last(), SIGNAL(finished(
int, QProcess::ExitStatus)),
this, SLOT(clientFinished(
int, QProcess::ExitStatus)));
184 connect(X11Process.last(), SIGNAL(readyReadStandardOutput()),
this, SLOT(clientReadyReadStandardOutput()));
185 QString emacsclient(
"emacsclient");
186 QStringList clientArgs=QStringList() <<
"-n" <<
"-s" << title;
188 if (fileName!=NULL) clientArgs << fileName;
189 qDebug()<<
"clientArgs:"<<clientArgs;
190 X11Process.last()->start(emacsclient, clientArgs);
191 if (!X11Process.last()->waitForStarted()) qFatal(
"QProcessEmacs NOT started!");
198void QHyodaX11Emacs::serverFinished(
int exitCode, QProcess::ExitStatus exitStatus){
199 qDebug() <<
"[QHyodaX11Emacs::serverFinished] emacs finished with exitCode="<<exitCode<<
", and exitStatus="<<exitStatus;
202void QHyodaX11Emacs::serverReadyReadStandardOutput(
void){
203 const QString output=QString(X11Process.at(0)->readAllStandardOutput());
205 if (output.contains(
"Starting Emacs daemon")){
207 qDebug()<<
"emacs has started!";
213void QHyodaX11Emacs::clientFinished(
int exitCode, QProcess::ExitStatus exitStatus){
214 qDebug() <<
"[QHyodaX11Emacs::clientFinished] with exitCode="<<exitCode<<
", and exitStatus="<<exitStatus;
215 if (splitter->count()==0)
return;
216 splitter->setStretchFactor(1,1);
218void QHyodaX11Emacs::clientReadyReadStandardOutput(
void){
219 qDebug()<<X11Process.last()->readAllStandardOutput();
223void QHyodaX11Emacs::xtermFinished(
int exitCode, QProcess::ExitStatus exitStatus){
224 qDebug() <<
"[QHyodaX11Emacs::xtermFinished] finished with exitCode="<<exitCode<<
", and exitStatus="<<exitStatus;
227void QHyodaX11Emacs::xtermReadyReadStandardOutput(
void){
228 qDebug()<<X11Process.at(1)->readAllStandardOutput();