rendered paste bodyIndex: backends/maxima/maximasession.cpp
===================================================================
--- backends/maxima/maximasession.cpp (Revision 1074266)
+++ backends/maxima/maximasession.cpp (Arbeitskopie)
@@ -27,9 +27,11 @@
#include <QTimer>
#include <QTcpSocket>
#include <QTcpServer>
+#include <QEventLoop>
#include <kdebug.h>
#include <kprocess.h>
#include <kmessagebox.h>
+#include <kapplication.h>
#include <klocale.h>
#include <signal.h>
#include "settings.h"
@@ -61,6 +63,8 @@
m_helperMaxima=0;
m_justRestarted=false;
m_useLegacy=false;
+
+ connect(kapp, SIGNAL(aboutToQuit()), this, SLOT(cleanupOnQuit()));
}
MaximaSession::~MaximaSession()
@@ -142,26 +146,60 @@
void MaximaSession::logout()
{
kDebug()<<"logout";
+
+ if(!m_process||!m_maxima)
+ return;
+
disconnect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(restartMaxima()));
if(m_expressionQueue.isEmpty())
- evaluateExpression("quit();", Cantor::Expression::DeleteOnFinish);
+ {
+ kDebug()<<"writing quit";
+ m_maxima->write("quit();\n");
+ m_maxima->flush();
+ //evaluateExpression("quit();", Cantor::Expression::DeleteOnFinish);
+ }
else
{
m_expressionQueue.clear();
}
+
//Give maxima time to clean up
- if(!m_process->waitForFinished(3000))
+ kDebug()<<"waiting for maxima to finish";
+
+ if(m_process->state()!=QProcess::NotRunning)
{
- m_process->kill();
+ if(!m_maxima->waitForDisconnected(3000))
+ {
+ m_process->kill();
+ m_maxima->waitForDisconnected(3000);
+ }
+
+ kDebug()<<"exec done";
}
- m_process->deleteLater();
+ kDebug()<<"closing socket";
+ m_maxima->close();
+
+ kDebug()<<"done...";
+
+ delete m_process;
+ m_process=0;
+ delete m_helperProcess;
+ m_helperProcess=0;
+ delete m_helperMaxima;
+ m_helperMaxima=0;
+ delete m_maxima;
+ m_maxima=0;
+
+ kDebug()<<"destroyed maxima";
+
m_expressionQueue.clear();
}
void MaximaSession::newConnection()
{
+ kDebug()<<"new connection";
QTcpSocket* const socket=m_server->nextPendingConnection();
if(m_maxima==0)
{
@@ -514,6 +552,7 @@
void MaximaSession::startHelperProcess()
{
+ kDebug()<<"starting helper";
m_helperMaxima=0;
m_isHelperReady=false;
if(!m_server)
@@ -570,6 +609,29 @@
return new MaximaHighlighter(parent);
}
+void MaximaSession::cleanupOnQuit()
+{
+ kDebug()<<"cleanup";
+ if(m_maxima)
+ {
+ kDebug()<<"writing quit";
+ m_maxima->write("quit();\n");
+ m_maxima->flush();
+ m_maxima->waitForDisconnected(3000);
+ m_process->kill();
+ m_maxima->waitForDisconnected(3000);
+ }
+ delete m_process;
+ m_process=0;
+ delete m_helperProcess;
+ m_helperProcess=0;
+ delete m_helperMaxima;
+ m_helperMaxima=0;
+ delete m_maxima;
+ m_maxima=0;
+}
+
+
#include "maximasession.moc"
Index: backends/maxima/maximasession.h
===================================================================
--- backends/maxima/maximasession.h (Revision 1074266)
+++ backends/maxima/maximasession.h (Arbeitskopie)
@@ -86,6 +86,9 @@
void killLabels();
void reportProcessError(QProcess::ProcessError error);
+
+ void cleanupOnQuit();
+
private:
QTcpServer* m_server;
QTcpSocket* m_maxima;