Changeset View
Changeset View
Standalone View
Standalone View
runners/characters/charrunner.cpp
Show All 13 Lines | |||||
14 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. | ||
15 | * | 15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "charrunner.h" | 20 | #include "charrunner.h" | ||
21 | 21 | | |||
22 | #include <KIcon> | 22 | // KF | ||
23 | #include <KRunner/QueryMatch> | ||||
24 | #include <KLocalizedString> | ||||
25 | | ||||
26 | | ||||
27 | //Names of config-entries | ||||
28 | static const char CONFIG_TRIGGERWORD[] = "triggerWord"; | ||||
29 | static const char CONFIG_ALIASES[] = "aliases"; | ||||
30 | static const char CONFIG_CODES[] = "codes"; | ||||
23 | 31 | | |||
24 | #include <Plasma/QueryMatch> | | |||
25 | 32 | | |||
26 | CharacterRunner::CharacterRunner( QObject* parent, const QVariantList &args ) | 33 | CharacterRunner::CharacterRunner( QObject* parent, const QVariantList &args ) | ||
27 | : Plasma::AbstractRunner(parent, args) | 34 | : Plasma::AbstractRunner(parent, args) | ||
28 | { | 35 | { | ||
29 | Q_UNUSED(args) | 36 | Q_UNUSED(args) | ||
30 | setObjectName(QLatin1String( "CharacterRunner" )); | 37 | setObjectName(QLatin1String( "CharacterRunner" )); | ||
31 | setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File | | 38 | setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File | | ||
32 | Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::Executable | | 39 | Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::Executable | | ||
Show All 14 Lines | 49 | { | |||
47 | m_codes = grp.readEntry(CONFIG_CODES, QStringList()); | 54 | m_codes = grp.readEntry(CONFIG_CODES, QStringList()); | ||
48 | addSyntax(Plasma::RunnerSyntax(m_triggerWord + QLatin1String( ":q:" ), | 55 | addSyntax(Plasma::RunnerSyntax(m_triggerWord + QLatin1String( ":q:" ), | ||
49 | i18n("Creates Characters from :q: if it is a hexadecimal code or defined alias."))); | 56 | i18n("Creates Characters from :q: if it is a hexadecimal code or defined alias."))); | ||
50 | } | 57 | } | ||
51 | 58 | | |||
52 | void CharacterRunner::match(Plasma::RunnerContext &context) | 59 | void CharacterRunner::match(Plasma::RunnerContext &context) | ||
53 | { | 60 | { | ||
54 | QString term = context.query(); | 61 | QString term = context.query(); | ||
55 | QString specChar; | | |||
56 | 62 | | |||
57 | term = term.replace(QLatin1Char( ' ' ), QLatin1String( "" )); //remove blanks | 63 | term = term.replace(QLatin1Char( ' ' ), QLatin1String( "" )); //remove blanks | ||
58 | if (term.length() < 2) //ignore too short queries | 64 | if (term.length() < 2) //ignore too short queries | ||
59 | { | 65 | { | ||
60 | return; | 66 | return; | ||
61 | } | 67 | } | ||
62 | if (!term.startsWith(m_triggerWord)) //ignore queries without the triggerword | 68 | if (!term.startsWith(m_triggerWord)) //ignore queries without the triggerword | ||
63 | { | 69 | { | ||
Show All 9 Lines | |||||
73 | bool ok; //checkvariable | 79 | bool ok; //checkvariable | ||
74 | int hex = term.toInt(&ok, 16); //convert query into int | 80 | int hex = term.toInt(&ok, 16); //convert query into int | ||
75 | if (!ok) //check if conversion was successful | 81 | if (!ok) //check if conversion was successful | ||
76 | { | 82 | { | ||
77 | return; | 83 | return; | ||
78 | } | 84 | } | ||
79 | 85 | | |||
80 | //make special caracter out of the hex.-code | 86 | //make special caracter out of the hex.-code | ||
81 | specChar=QString(); | 87 | const QString specChar = QChar(hex); | ||
82 | specChar.toUtf8(); | | |||
83 | specChar[0]=hex; | | |||
84 | 88 | | |||
85 | //create match | 89 | //create match | ||
86 | Plasma::QueryMatch match(this); | 90 | Plasma::QueryMatch match(this); | ||
87 | match.setType(Plasma::QueryMatch::InformationalMatch); | 91 | match.setType(Plasma::QueryMatch::InformationalMatch); | ||
88 | match.setIcon(KIcon(QLatin1String( "accessories-character-map" ))); | 92 | match.setIconName(QStringLiteral("accessories-character-map")); | ||
89 | match.setText(specChar); | 93 | match.setText(specChar); | ||
90 | match.setData(specChar); | 94 | match.setData(specChar); | ||
91 | match.setId(QString()); | 95 | match.setId(QString()); | ||
92 | context.addMatch(term, match); | 96 | context.addMatch(match); | ||
93 | } | 97 | } | ||
94 | 98 | | |||
99 | K_EXPORT_PLASMA_RUNNER(CharacterRunner, CharacterRunner) | ||||
100 | | ||||
101 | #include "charrunner.moc" |