From 4e1a5c3eebf50657629e2b4eba13649c2b599598 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 3 Feb 2010 02:45:19 +0000 Subject: Added abandoned KDE3 version of katapult git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/katapult@1084407 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- katapult/plugins/catalogs/spellcatalog/Makefile.am | 19 +++ .../catalogs/spellcatalog/actioncopyspelling.cpp | 80 +++++++++++++ .../catalogs/spellcatalog/actioncopyspelling.h | 51 ++++++++ .../cr128-action-katapultspellcheck.png | Bin 0 -> 8211 bytes .../crsc-action-katapultspellcheck.svgz | Bin 0 -> 1396 bytes .../spellcatalog/katapult_spellcatalog.desktop | 43 +++++++ katapult/plugins/catalogs/spellcatalog/settings.ui | 65 ++++++++++ .../plugins/catalogs/spellcatalog/spellcatalog.cpp | 122 +++++++++++++++++++ .../plugins/catalogs/spellcatalog/spellcatalog.h | 73 +++++++++++ .../plugins/catalogs/spellcatalog/spelling.cpp | 133 +++++++++++++++++++++ katapult/plugins/catalogs/spellcatalog/spelling.h | 74 ++++++++++++ 11 files changed, 660 insertions(+) create mode 100644 katapult/plugins/catalogs/spellcatalog/Makefile.am create mode 100644 katapult/plugins/catalogs/spellcatalog/actioncopyspelling.cpp create mode 100644 katapult/plugins/catalogs/spellcatalog/actioncopyspelling.h create mode 100644 katapult/plugins/catalogs/spellcatalog/cr128-action-katapultspellcheck.png create mode 100644 katapult/plugins/catalogs/spellcatalog/crsc-action-katapultspellcheck.svgz create mode 100644 katapult/plugins/catalogs/spellcatalog/katapult_spellcatalog.desktop create mode 100644 katapult/plugins/catalogs/spellcatalog/settings.ui create mode 100644 katapult/plugins/catalogs/spellcatalog/spellcatalog.cpp create mode 100644 katapult/plugins/catalogs/spellcatalog/spellcatalog.h create mode 100644 katapult/plugins/catalogs/spellcatalog/spelling.cpp create mode 100644 katapult/plugins/catalogs/spellcatalog/spelling.h (limited to 'katapult/plugins/catalogs/spellcatalog') diff --git a/katapult/plugins/catalogs/spellcatalog/Makefile.am b/katapult/plugins/catalogs/spellcatalog/Makefile.am new file mode 100644 index 0000000..eb07f58 --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/Makefile.am @@ -0,0 +1,19 @@ +# Copyright (C) 2006 Jonathan Riddell + +# set the include path for X, qt and KDE +INCLUDES = -I$(top_srcdir)/katapult/common $(all_includes) + +# header files +noinst_HEADERS = actioncopyspelling.h spellcatalog.h spelling.h + +# use automoc +METASOURCES = AUTO + +KDE_ICON = AUTO + +# our plugin +kde_module_LTLIBRARIES = katapult_spellcatalog.la +katapult_spellcatalog_la_SOURCES = settings.ui spellcatalog.cpp spelling.cpp actioncopyspelling.cpp +katapult_spellcatalog_la_LDFLAGS = -module $(KDE_RPATH) $(KDE_PLUGIN) $(all_libraries) +katapult_spellcatalog_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KIO) $(top_builddir)/katapult/common/libkatapult.la +kde_services_DATA = katapult_spellcatalog.desktop diff --git a/katapult/plugins/catalogs/spellcatalog/actioncopyspelling.cpp b/katapult/plugins/catalogs/spellcatalog/actioncopyspelling.cpp new file mode 100644 index 0000000..87857d3 --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/actioncopyspelling.cpp @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (C) 2006 Jonathan Riddell * + * jriddell@ubuntu.com * + * * + * Copyright (C) 2005 by Joe Ferris * + * jferris@optimistictech.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include +#include + +#include + +#include "spellcatalog.h" +#include "spelling.h" +#include "katapultitem.h" +#include "actioncopyspelling.h" + +ActionCopySpelling::ActionCopySpelling() + : KatapultAction(), _spelling(0) +{ +} + +ActionCopySpelling::~ActionCopySpelling() +{ +} + +QString ActionCopySpelling::text() const +{ + if (_spelling->parseError()) { + return i18n("Parse Error"); + } else { + return _spelling->result(); + } +} + +QPixmap ActionCopySpelling::icon(int size) const +{ + return KGlobal::iconLoader()->loadIcon("katapultspellcheck", KIcon::NoGroup, size); +} + +bool ActionCopySpelling::accepts(const KatapultItem* item) const +{ + bool accept = strcmp(item->className(), "Spelling") == 0; + if (accept) { + _spelling = (const Spelling*)item; + } + return accept; +} + +void ActionCopySpelling::execute(const KatapultItem* item) const +{ + if (strcmp(item->className(), "Spelling") == 0) { + _spelling = (const Spelling*)item; + + _spelling->evaluate(); + + // Copy calculation and result into clipboard (unless there's a parse error). + if (!_spelling->parseError()) { + _spelling->copyToClipboard(); + } + } +} diff --git a/katapult/plugins/catalogs/spellcatalog/actioncopyspelling.h b/katapult/plugins/catalogs/spellcatalog/actioncopyspelling.h new file mode 100644 index 0000000..e15c3d9 --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/actioncopyspelling.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2006 Jonathan Riddell * + * jriddell@ubuntu.com * + * * + * Copyright (C) 2005 by Joe Ferris * + * jferris@optimistictech.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef ACTIONCOPYSPELLING_H +#define ACTIONCOPYSPELLING_H + +#include "katapultaction.h" + +class KatapultItem; +class Spelling; + +/** +@author Tobi Vollebregt +*/ +class ActionCopySpelling : public KatapultAction +{ + public: + ActionCopySpelling(); + ~ActionCopySpelling(); + + virtual void execute(const KatapultItem*) const; + virtual bool accepts(const KatapultItem*) const; + virtual QString text() const; + virtual QPixmap icon(int) const; + + private: + //_expr needs to be mutable because accepts() is const. + mutable const Spelling* _spelling; + +}; + +#endif diff --git a/katapult/plugins/catalogs/spellcatalog/cr128-action-katapultspellcheck.png b/katapult/plugins/catalogs/spellcatalog/cr128-action-katapultspellcheck.png new file mode 100644 index 0000000..f11344d Binary files /dev/null and b/katapult/plugins/catalogs/spellcatalog/cr128-action-katapultspellcheck.png differ diff --git a/katapult/plugins/catalogs/spellcatalog/crsc-action-katapultspellcheck.svgz b/katapult/plugins/catalogs/spellcatalog/crsc-action-katapultspellcheck.svgz new file mode 100644 index 0000000..2105fa5 Binary files /dev/null and b/katapult/plugins/catalogs/spellcatalog/crsc-action-katapultspellcheck.svgz differ diff --git a/katapult/plugins/catalogs/spellcatalog/katapult_spellcatalog.desktop b/katapult/plugins/catalogs/spellcatalog/katapult_spellcatalog.desktop new file mode 100644 index 0000000..035ee06 --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/katapult_spellcatalog.desktop @@ -0,0 +1,43 @@ +# Copyright (C) 2006 Jonathan Riddell +[Desktop Entry] +Name=Spell Catalog +Name[ar]=مستعرض التدقيق الأملائي ( Spell Catalog ) +Name[bg]=Каталог за проверка на правописа +Name[da]=Katalogisér stavning +Name[de]=Rechtschreibung-Katalog +Name[el]=Κατάλογος ορθογραφίας +Name[es]=Catalogador de ortografía +Name[et]=Õigekirjakataloog +Name[fr]=Catalogue orthographique +Name[ga]=Catalóg Litrithe +Name[gl]=Catálogo de Ortografia +Name[it]=Catalogo controllo ortografico +Name[ja]=スペルカタログ +Name[nb]=Stavekatalog +Name[nl]=Spelcatalogus +Name[pt]=Catálogo de Ortografia +Name[pt_BR]=Catálogo de Ortografia +Name[sv]=Stavningskatalog +Name[uk]=Каталог правопису +Comment=Check the spelling of a word +Comment[ar]=دقًق املائيا في الكلمة +Comment[bg]=Проверка правописа на дума +Comment[da]=Tjek stavning af et ord +Comment[de]=Die Schreibweise eines Wortes überprüfen +Comment[el]=Ορθογραφικός έλεγχος μιας λέξης +Comment[es]=Comprueba la ortografía de una palabra +Comment[et]=Sõna õigekirja kontroll +Comment[fr]=Vérifier l'orthographe d'un mot +Comment[gl]=Verifica a ortografia dunha palabra +Comment[it]=Controllo ortografico di una parola +Comment[ja]=単語のスペルをチェック +Comment[nb]=Sjekk skrivemåten for et ord +Comment[nl]=Controleert de spelling van een woord +Comment[pt]=Verificar a ortografia de uma palavra +Comment[pt_BR]=Verificar a ortografia de uma palavra +Comment[sv]=Kontrollera stavningen av ett ord +Comment[uk]=Перевірити правопис слова +ServiceTypes=Katapult/Catalog +Type=Service +X-KDE-Library=katapult_spellcatalog +X-Katapult-ID=Spell Catalog diff --git a/katapult/plugins/catalogs/spellcatalog/settings.ui b/katapult/plugins/catalogs/spellcatalog/settings.ui new file mode 100644 index 0000000..402b416 --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/settings.ui @@ -0,0 +1,65 @@ + +SpellCatalogSettings + + + SpellCatalogSettings + + + + 0 + 0 + 356 + 265 + + + + Settings + + + + unnamed + + + + triggerWordLE + + + + + triggerWordLabel + + + Trigger Word: + + + + + introLabel + + + Use with: "spell myword" + + + + + spacer2 + + + Vertical + + + Expanding + + + + 20 + 150 + + + + + + + + + diff --git a/katapult/plugins/catalogs/spellcatalog/spellcatalog.cpp b/katapult/plugins/catalogs/spellcatalog/spellcatalog.cpp new file mode 100644 index 0000000..5cbdbed --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/spellcatalog.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (C) 2006 Jonathan Riddell * + * jriddell@ubuntu.com * + * * + * Copyright (C) 2005 Tobi Vollebregt * + * tobivollebregt@gmail.com * + * * + * Copyright (C) 2005 by Joe Ferris * + * jferris@optimistictech.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include +#include + +#include +#include + +#include "settings.h" +#include "spellcatalog.h" +#include "actionregistry.h" +#include "actioncopyspelling.h" +#include "status.h" + +K_EXPORT_COMPONENT_FACTORY( katapult_spellcatalog, + KGenericFactory( "katapult_spellcatalog" ) ) + +SpellCatalog::SpellCatalog(QObject*, const char*, const QStringList&): _result(this, QString::null) +{ + ActionRegistry::self()->registerAction(new ActionCopySpelling()); +} + +SpellCatalog::~SpellCatalog() +{ +} + +void SpellCatalog::queryChanged() +{ + int newStatus = 0; + QString cmd = query(); + int origLength = cmd.length(); + + if (cmd.isEmpty()) { + reset(); + setBestMatch(Match()); + } else { + if (accepts(cmd)) { + _result.setText(cmd); + + setBestMatch(Match(&_result, _result.parseError() ? 10 : 100, origLength)); + //set status. + //add S_Multiple to make sure katapult doesn't auto-exec and close the window + //add S_Active to make sure katapult doesn't start the hideTimer or clearTimer + newStatus = S_HasResults | S_Multiple | S_Active; + } else { + newStatus = 0; + } + } + setStatus(newStatus); +} + +bool SpellCatalog::accepts(const QString& str) const +{ + //accept if we begin with the triggerWord + int length = _triggerWord.length(); + return str.left(length + 1) == _triggerWord + " "; +} + +void SpellCatalog::readSettings(KConfigBase* config) +{ + _triggerWord = config->readEntry("TriggerWord", i18n("Should be short, easy and quick to type", "spell")); +} + +void SpellCatalog::writeSettings(KConfigBase* config) +{ + config->writeEntry("TriggerWord", _triggerWord); +} + +QWidget * SpellCatalog::configure() +{ + SpellCatalogSettings* settings = new SpellCatalogSettings(); + + settings->triggerWordLE->setText(_triggerWord); + connect(settings->triggerWordLE, SIGNAL(textChanged(const QString&)), this, SLOT(triggerWordChanged(const QString&))); + + settings->introLabel->setText(i18n("Use with \"%1 myword\"").arg(_triggerWord)); + + return settings; +} + +void SpellCatalog::triggerWordChanged(const QString& triggerWord) +{ + _triggerWord = QString(triggerWord); +} + +int SpellCatalog::triggerWordLength() +{ + return _triggerWord.length(); +} + +void SpellCatalog::reset() +{ + _result.setText(QString::null); +} + +#include "spellcatalog.moc" diff --git a/katapult/plugins/catalogs/spellcatalog/spellcatalog.h b/katapult/plugins/catalogs/spellcatalog/spellcatalog.h new file mode 100644 index 0000000..86181dc --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/spellcatalog.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2006 Jonathan Riddell * + * jriddell@ubuntu.com * + * * + * Copyright (C) 2005 Tobi Vollebregt * + * tobivollebregt@gmail.com * + * * + * Copyright (C) 2005 by Joe Ferris * + * jferris@optimistictech.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef SPELLCATALOG_H +#define SPELLCATALOG_H + +#include + +#include + +#include "spelling.h" +#include "katapultcatalog.h" + +class QWidget; + +/** +@author Jonathan Riddell + */ +class SpellCatalog : public KatapultCatalog +{ + Q_OBJECT + + public: + + SpellCatalog(QObject*, const char*, const QStringList&); + virtual ~SpellCatalog(); + + virtual void readSettings(KConfigBase*); + virtual void writeSettings(KConfigBase*); + virtual QWidget* configure(); + int triggerWordLength(); + + protected: + + virtual void queryChanged(); + + private: + bool accepts(const QString&) const; + + QString _triggerWord; + + Spelling _result; // The one result (there's always one). + + void reset(); + + protected slots: + void triggerWordChanged(const QString& triggerWord); + +}; + +#endif diff --git a/katapult/plugins/catalogs/spellcatalog/spelling.cpp b/katapult/plugins/catalogs/spellcatalog/spelling.cpp new file mode 100644 index 0000000..fe08355 --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/spelling.cpp @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (C) 2006 Jonathan Riddell * + * jriddell@ubuntu.com * + * * + * Copyright (C) 2005 by Joe Ferris * + * jferris@optimistictech.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include +#include + +#include + +#include "spellcatalog.h" +#include "spelling.h" + + +Spelling::Spelling(SpellCatalog* catalog, const QString& text): KatapultItem(), _catalog(catalog), _text(text) +{ + spellChecker = new KSpell( 0, "caption", this, SLOT(spellCheckerReady()) ); + + connect( spellChecker, SIGNAL(misspelling(const QString&, const QStringList&, unsigned int)), + this, SLOT(spellCheckerMisspelling(const QString&, const QStringList&, unsigned int)) ); + + connect( spellChecker, SIGNAL(corrected(const QString&, const QString&, unsigned int)), + this, SLOT(spellCheckerCorrected(const QString&, const QString&, unsigned int)) ); + + evaluate(); +} + +Spelling::~Spelling() { + delete spellChecker; +} + +void Spelling::spellCheckerReady() { +} + +void Spelling::spellCheckerCorrected(const QString& /*originalword*/, const QString& /*newword*/, unsigned int /*pos*/) { + corrected = true; +} + +void Spelling::spellCheckerMisspelling(const QString& /*originalword*/, const QStringList& suggestions, unsigned int /*pos*/) { + misspelt = true; + suggestedWords = suggestions.join(","); +} + +QPixmap Spelling::icon(int size) const +{ + const char* icon = "checkmark"; + if (_parseError || misspelt) { + icon = "no"; + } + return KGlobal::iconLoader()->loadIcon(icon, KIcon::NoGroup, size); +} + +QString Spelling::text() const +{ + return _text; +} + +void Spelling::setText(const QString& text) +{ + _text = text; + evaluate(); +} + +QString Spelling::result() const +{ + return _result; +} + +bool Spelling::parseError() const +{ + return _parseError; +} + +SpellCatalog* Spelling::catalog() const +{ + return _catalog; +} + +void Spelling::evaluate() const +{ + int length = catalog()->triggerWordLength(); + + QString text = _text.mid(length + 1); // + 1 for space + + misspelt = false; + corrected = false; + + _parseError = false; + if (!_text.isEmpty()) { + _result = "my result"; + spellChecker->checkWord(text); + + while (corrected == false) { + kapp->processEvents(); + } + + if (misspelt) { + _result = suggestedWords; + } else { + _result = "Correct"; + } + } else { + _parseError = true; + } +} + +void Spelling::copyToClipboard() const { + QClipboard* clipBoard = QApplication::clipboard(); + clipBoard->setText(suggestedWords, QClipboard::Clipboard); + clipBoard->setText(suggestedWords, QClipboard::Selection); +} + +#include "spelling.moc" diff --git a/katapult/plugins/catalogs/spellcatalog/spelling.h b/katapult/plugins/catalogs/spellcatalog/spelling.h new file mode 100644 index 0000000..ea4b846 --- /dev/null +++ b/katapult/plugins/catalogs/spellcatalog/spelling.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2006 Jonathan Riddell * + * jriddell@ubuntu.com * + * * + * Copyright (C) 2005 by Joe Ferris * + * jferris@optimistictech.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef SPELLING_H +#define SPELLING_H + +#include + +#include + +class SpellCatalog; + +/** +@author Tobi Vollebregt +*/ +class Spelling : public KatapultItem +{ + Q_OBJECT + public: + Spelling(SpellCatalog*, const QString&); + ~Spelling(); + + virtual QPixmap icon(int) const; + virtual QString text() const; + + void setText(const QString&); + QString result() const; + bool parseError() const; + + //evaluate() must be const, or ActionEvaluateSpelling::execute() can't call it. + //It makes sense because evaluate() does _not_ change the expression, + //it just calculates the result and remembers that. + void evaluate() const; + + SpellCatalog* catalog() const; + + void copyToClipboard() const; + + private: + SpellCatalog* const _catalog; + QString _text; + mutable QString _result; + mutable bool _parseError; + KSpell* spellChecker; + mutable bool misspelt; + mutable bool corrected; + QString suggestedWords; + + protected slots: + void spellCheckerReady(); + void spellCheckerCorrected(const QString& originalword, const QString& newword, unsigned int pos); + void spellCheckerMisspelling(const QString& originalword, const QStringList& suggestions, unsigned int pos); +}; + +#endif -- cgit v1.2.1