Changeset View
Changeset View
Standalone View
Standalone View
runners/converter/converterrunner.h
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2007,2008 Petri Damstén <damu@iki.fi> | 2 | * Copyright (C) 2007,2008 Petri Damstén <damu@iki.fi> | ||
3 | * Copyright (C) 2020 Alexander Lohnau <alexander.lohnau@gmx.de> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License as | 6 | * modify it under the terms of the GNU General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of | 7 | * published by the Free Software Foundation; either version 2 of | ||
7 | * the License, or (at your option) any later version. | 8 | * the License, or (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. | ||
13 | * | 14 | * | ||
14 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 17 | */ | ||
17 | 18 | | |||
18 | #ifndef CONVERTERRUNNER_H | 19 | #ifndef CONVERTERRUNNER_H | ||
19 | #define CONVERTERRUNNER_H | 20 | #define CONVERTERRUNNER_H | ||
20 | 21 | | |||
21 | #include <krunner/abstractrunner.h> | 22 | #include <KRunner/AbstractRunner> | ||
23 | #include <QRegularExpression> | ||||
24 | #include <QLocale> | ||||
25 | #include <QAction> | ||||
26 | #include <KUnitConversion/Converter> | ||||
27 | #include <KUnitConversion/UnitCategory> | ||||
28 | | ||||
22 | 29 | | |||
23 | /** | 30 | /** | ||
24 | * This class converts values to different units. | 31 | * This class converts values to different units. | ||
25 | */ | 32 | */ | ||
26 | class ConverterRunner : public Plasma::AbstractRunner | 33 | class ConverterRunner: public Plasma::AbstractRunner | ||
27 | { | 34 | { | ||
28 | Q_OBJECT | 35 | Q_OBJECT | ||
29 | 36 | | |||
30 | public: | 37 | public: | ||
31 | ConverterRunner(QObject* parent, const QVariantList &args); | 38 | ConverterRunner(QObject *parent, const QVariantList &args); | ||
39 | void init() override; | ||||
40 | void insertCompatibleUnits(); | ||||
32 | ~ConverterRunner() override; | 41 | ~ConverterRunner() override; | ||
33 | 42 | | |||
34 | void match(Plasma::RunnerContext &context) override; | 43 | void match(Plasma::RunnerContext &context) override; | ||
44 | QList<QAction *> actionsForMatch(const Plasma::QueryMatch &match) override; | ||||
35 | void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override; | 45 | void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override; | ||
36 | 46 | | |||
37 | private: | 47 | private: | ||
38 | QStringList m_separators; | 48 | KUnitConversion::Converter converter; | ||
49 | const QLocale locale; | ||||
50 | QRegularExpression valueRegex; | ||||
51 | QRegularExpression unitSeperatorRegex; | ||||
52 | /** To convert currency symbols back to ISO string and handle case sensitive units */ | ||||
53 | QMap<QString, QString> compatibleUnits; | ||||
54 | | ||||
55 | QList<QAction *> actionList; | ||||
56 | QLatin1String copyActionId = QLatin1String("copy"); | ||||
57 | QLatin1String copyUnitActionId = QLatin1String("copy-unit"); | ||||
58 | | ||||
59 | QPair<bool, double> stringToDouble(const QStringRef &value); | ||||
60 | QPair<bool, double> getValidatedNumberValue(const QString &value); | ||||
61 | QList<KUnitConversion::Unit> createResultUnits(QString &outputUnitString, | ||||
62 | const KUnitConversion::UnitCategory &category); | ||||
39 | }; | 63 | }; | ||
40 | 64 | | |||
41 | #endif | 65 | #endif |