Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
QHyodaX11Emacs.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7#include "QHyodaGdb.h"
8#include "QHyodaX11Emacs.h"
9#include "QHyodaX11Xterm.h"
10
11//#include "ui_hyoda.h"
12
13//#include <QtWidgets>
14//#include <QProcess>
15//#include <QX11EmbedContainer>
16//#include <QX11Info>
17
18//#include <unistd.h>
19
20/******************************************************************************
21 * QHyodaX11Emacs
22 *****************************************************************************/
23QHyodaX11Emacs::QHyodaX11Emacs(QWidget *parent,
24 QString title): QHyodaX11(parent, title),
25 serverUp(false)
26{
27 qDebug() << "[NEW] QHyodaX11Emacs";
28}
29
30
31/***********************************************
32 * ~QHyodaX11Emacs
33 ***********************************************/
34QHyodaX11Emacs::~QHyodaX11Emacs(void){
35 qDebug() << "~QHyodaX11Emacs";
36/*
37 if (xterm!=NULL){
38 qDebug() << "~QHyodaX11Emacs closing xterm";
39 xterm->close();
40 xterm->closeWriteChannel();
41 if (xterm->waitForFinished()) qFatal("xterm NOT closed!");
42 delete xterm;
43 }
44
45 if (emacs!=NULL){
46 qDebug() << "~QHyodaX11Emacs closing emacs";
47 emacs->close();
48 emacs->closeWriteChannel();
49 if (emacs->waitForFinished()) qFatal("QProcessEmacs NOT closed!");
50 delete emacs;
51 }
52
53 if (emacsClientProcess==NULL) return;
54 qDebug() << "~QHyodaX11Emacs closing emacsClientProcess";
55 emacsClientProcess->close();
56 emacsClientProcess->closeWriteChannel();
57 if (emacsClientProcess->waitForFinished()) qFatal("QProcessEmacs NOT closed!");
58 delete emacsClientProcess;*/
59}
60
61
62
63/**********************************************************
64 * embedIsEmbedded
65 **********************************************************/
66void QHyodaX11Emacs::clientIsEmbedded(){
67 qDebug()<<"[QHyodaX11Emacs::clientIsEmbedded]";
68 //#warning Work around for emacs to show correctly
69 //usleep(1500ul*1000ul);
70}
71
72/**********************************************************
73 * embedClosed
74 **********************************************************/
75void QHyodaX11Emacs::clientClosed(){
76 qDebug() << "[QHyodaX11Emacs::clientClosed] Container clientClosed!";
77//#warning Should remove tab
78}
79
80/**********************************************************
81 * emacsError
82 **********************************************************/
83/*void QHyodaX11Emacs::error(QX11EmbedContainer::Error error){
84 qDebug() << "[QHyodaX11Emacs::error] Container error:"<<error;
85 }*/
86
87
88
89/***********************************************
90 * launchEmacsInWindow
91 ***********************************************/
92void QHyodaX11Emacs::launchEmacsInWindow(QWidget *widget, QString fileNameToOpen){
93 if (!serverUp)
94 launchServerInWindow(widget, fileNameToOpen);
95 else
96 launchClient(fileNameToOpen);
97}
98
99
100/**********************************************************
101 * launchServerInWindow
102 **********************************************************/
103void QHyodaX11Emacs::launchServerInWindow(QWidget *widget, QString fileName){
104 qDebug() << "[QHyodaX11Emacs::launchServerInWindow]";
105 // Now create our container
106 //X11Container.append(new QHyodaX11Embed(widget, this));
107 // Set initial stretch factor
108 splitter->setStretchFactor(0, 3);
109 splitter->addWidget(this);
110
111// Now launching server
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()));
116
117 QString emacs_path("emacs");
118 QString setqEmacsName("(setq server-name \"");
119 setqEmacsName.append(title);
120 setqEmacsName.append("\")");
121
122 QStringList daemonArgs=QStringList()
123 //<< "-Q"
124 //<< "--maximized"
125 //<< "--geometry"<< "20x60"
126 //<< "--geometry"<< geoString
127 //<< "--internal-border" << 0
128 << "--eval" << setqEmacsName
129 << "--eval" << "(setq server-raise-frame nil)"
130 << "--eval" << "(server-force-delete)"
131 << "--eval" << "(server-start)"
132 << "--eval" << "(hl-line-mode)"
133 //<< "--fullwidth"
134 //<< "--fullheight"
135 //<< "--fullscreen"
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!";
142 serverUp=true;
143}
144
145/**********************************************************
146 * launchXtermInWindow
147 **********************************************************/
148void QHyodaX11Emacs::launchXtermInWindow(QWidget *widget){
149 // Now add an xterm south
150 //X11Container.append(new QHyodaX11Embed(widget,this));
151 splitter->addWidget(this);
152
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"
159 << "-bg" << "black"
160 << "-vb" // Visual bell is preferred over an audible one
161 << "-sb" << "-sl" << "8192"
162 << "-bc" // Turn on text cursor blinking
163 << "+l" // Turn logging off
164 << "+lc" // Turn off support of automatic selection of locale encodings
165 << "-s" // This option indicates that xterm may scroll asynchronously
166 << "+aw" // This option indicates that auto-wraparound should not be allowed
167 //<< "+tb" // This option indicates that xterm should not set up a toolbar
168 << "-ut" // This option indicates that xterm should not write a record into the the system utmp log file
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);
173}
174
175
176/**********************************************************
177 * launchClient
178 **********************************************************/
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;//emacsName;
187 // Dans le cas du tab pour visualiser les 'src', on ne passe pas d'argument fileName
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!");
192}
193
194
195
196
197// Process slots
198void QHyodaX11Emacs::serverFinished(int exitCode, QProcess::ExitStatus exitStatus){
199 qDebug() << "[QHyodaX11Emacs::serverFinished] emacs finished with exitCode="<<exitCode<<", and exitStatus="<<exitStatus;
200 //X11Container.at(0)->hide();
201}
202void QHyodaX11Emacs::serverReadyReadStandardOutput(void){
203 const QString output=QString(X11Process.at(0)->readAllStandardOutput());
204 qDebug()<<output;
205 if (output.contains("Starting Emacs daemon")){
206 serverUp=true;
207 qDebug()<<"emacs has started!";
208 //launchClient(fileName);
209 }
210}
211
212
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);
217}
218void QHyodaX11Emacs::clientReadyReadStandardOutput(void){
219 qDebug()<<X11Process.last()->readAllStandardOutput();
220}
221
222
223void QHyodaX11Emacs::xtermFinished(int exitCode, QProcess::ExitStatus exitStatus){
224 qDebug() << "[QHyodaX11Emacs::xtermFinished] finished with exitCode="<<exitCode<<", and exitStatus="<<exitStatus;
225 //xtermContainer->hide();
226}
227void QHyodaX11Emacs::xtermReadyReadStandardOutput(void){
228 qDebug()<<X11Process.at(1)->readAllStandardOutput();
229}
230
231