Commit 22b382b0 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Calc runner: Initialize Qalculate when needed

It takes a lot of time to initialize hence init when needed.

As a drive by, remove some unused signals from QalculateEngine
parent ee0bb8c1
Pipeline #136565 passed with stage
in 6 minutes and 55 seconds
......@@ -14,6 +14,7 @@
#include <QDebug>
#include <QIcon>
#include <QMutex>
#include <QRegularExpression>
#include <KLocalizedString>
......@@ -21,11 +22,11 @@
K_PLUGIN_CLASS_WITH_JSON(CalculatorRunner, "plasma-runner-calculator.json")
static QMutex s_initMutex;
CalculatorRunner::CalculatorRunner(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
: Plasma::AbstractRunner(parent, metaData, args)
{
m_engine = new QalculateEngine;
setObjectName(QStringLiteral("Calculator"));
QString description = i18n(
......@@ -41,7 +42,6 @@ CalculatorRunner::CalculatorRunner(QObject *parent, const KPluginMetaData &metaD
CalculatorRunner::~CalculatorRunner()
{
delete m_engine;
}
void CalculatorRunner::userFriendlySubstitutions(QString &cmd)
......@@ -137,8 +137,14 @@ void CalculatorRunner::match(Plasma::RunnerContext &context)
QString CalculatorRunner::calculate(const QString &term, bool *isApproximate)
{
QString result;
{
QMutexLocker lock(&s_initMutex);
if (!m_engine) {
m_engine = std::make_unique<QalculateEngine>();
}
}
QString result;
try {
result = m_engine->evaluate(term, isApproximate);
} catch (std::exception &e) {
......
......@@ -37,6 +37,6 @@ private:
void userFriendlyMultiplication(QString &cmd);
void userFriendlySubstitutions(QString &cmd);
QalculateEngine *m_engine;
std::unique_ptr<QalculateEngine> m_engine;
QList<QAction *> m_actions;
};
......@@ -32,10 +32,6 @@ public Q_SLOTS:
protected Q_SLOTS:
void updateResult(KJob *);
Q_SIGNALS:
void resultReady(const QString &);
void formattedResultReady(const QString &);
private:
QString m_lastResult;
static QAtomicInt s_counter;
......
Supports Markdown
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