Commit 97ffb4e7 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

Some refactoring

  - Add reportSessionCrash to Session, for reporting crashes to user
  - Use reportSessionCrash in PythonSession and improve login of PythonSession::logout()
parent 476c6fd6
......@@ -116,7 +116,8 @@ void PythonSession::logout()
if (!m_process)
return;
sendCommand(QLatin1String("exit"));
if (m_process->exitStatus() != QProcess::CrashExit && m_process->error() != QProcess::WriteError)
sendCommand(QLatin1String("exit"));
if(m_process->state() == QProcess::Running && !m_process->waitForFinished(1000))
{
disconnect(m_process, &QProcess::errorOccurred, this, &PythonSession::reportServerProcessError);
......@@ -275,8 +276,5 @@ void PythonSession::reportServerProcessError(QProcess::ProcessError serverError)
emit error(i18n("Communication with Cantor python server failed for unknown reasons."));
break;
}
// Server crash, and now m_process is invalid, so remove m_process object
m_process->deleteLater();
m_process = nullptr;
Session::logout();
reportSessionCrash();
}
......@@ -26,6 +26,8 @@ using namespace Cantor;
#include <QTimer>
#include <QQueue>
#include <KMessageBox>
#include <KLocalizedString>
class Cantor::SessionPrivate
{
......@@ -181,10 +183,9 @@ QSyntaxHighlighter* Session::syntaxHighlighter(QObject* parent)
DefaultVariableModel* Session::variableModel() const
{
//Return deafult session model per default
//By default, variableModel is nullptr, so Backends not offering variable management don't
//have to reimplement this. This method should only be called on backends with
//VariableManagement Capability flag
//By default, there is variableModel in session, used by syntax higlighter for variable analyzing
//The model store only variable names by default.
//In backends with VariableManagement Capability flag, this model also used for Cantor variable doc panel
return d->variableModel;
}
......@@ -231,3 +232,16 @@ QStringList Session::locateAllCantorFiles(const QString& partialPath, QStandardP
return files;
}
void Cantor::Session::reportSessionCrash(const QString& additionalInfo)
{
// Reporting about crashing backend in session without backend has not sense
if (d->backend == nullptr)
return;
if (additionalInfo.isEmpty())
KMessageBox::error(nullptr, i18n("%1 process has died unexpectedly. All calculation results are lost.", d->backend->name()), i18n("Error - Cantor"));
else
KMessageBox::error(nullptr, i18n("%1 process has died unexpectedly with message \"%2\". All calculation results are lost.", d->backend->name()), i18n("Error - Cantor"));
logout();
}
......@@ -251,6 +251,15 @@ class CANTOR_EXPORT Session : public QObject
QString locateCantorFile(const QString& partialPath, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile);
QStringList locateAllCantorFiles(const QString& partialPath, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile);
/**
* Sometimes backend process/server could crash, stop responding, in other words, session can't
* continue to work without restart.
* This method will notify about session crashing with automatically logout
* and another actions, which needed to do in situations like that
*/
void reportSessionCrash(const QString& additionalInfo = QString());
Q_SIGNALS:
void statusChanged(Cantor::Session::Status newStatus);
void loginStarted();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment