libreoffice-voikko-4.0/0000755000000000000000000000000012245135610013623 5ustar rootrootlibreoffice-voikko-4.0/oxt/0000755000000000000000000000000012245135610014435 5ustar rootrootlibreoffice-voikko-4.0/oxt/SettingsDialog.xdl0000644000000000000000000000432112245135610020066 0ustar rootroot libreoffice-voikko-4.0/oxt/icon.png0000644000000000000000000000371412245135610016100 0ustar rootrootPNG  IHDR7*sBIT|d pHYs4wtEXtSoftwarewww.inkscape.org<IIDAThyu.!$ &Z-MSQSGM3c5A^Q$GIb(.}oaC]d=o?gSDR|}s]e)>)M|%î\J7`JM"ʆJ܊ y"[DMTW%ԗyv;%/eF,Qn'-"+3#v/J2">wڷlANI燳jN8gG7t˜iXI,&&R o$>."˜R!|h'U{,E.Ngrxdvدe~ڲMV8: ."õch\n no8/˾BK7 `;QR1xmv5&x2tts'DtF䔮6dD=mfcX0xi/n% #X{9j@* N9 B)RJQЍ2~= SM~577zj]Sم?_ZdIENDB`libreoffice-voikko-4.0/oxt/SettingsDialog_en_US.properties0000644000000000000000000000107412245135610022566 0ustar rootroot# SettingsDialog strings (English) 0.voikkoasetukset.HelpText= 1.voikkoasetukset.Title=Settings for Voikko 6.voikkoasetukset.hyphenationFrame.HelpText= 7.voikkoasetukset.hyphenationFrame.Label=Hyphenation 8.voikkoasetukset.hyphWordParts.HelpText= 9.voikkoasetukset.hyphWordParts.Label=Apply hyphenation settings to compound word parts 10.voikkoasetukset.hyphUnknownWords.HelpText= 11.voikkoasetukset.hyphUnknownWords.Label=Hyphenate unknown or foreign words 12.voikkoasetukset.vocabularyFrame.Label=Vocabulary 13.voikkoasetukset.topLine.Label=Writing aids based on Voikko libreoffice-voikko-4.0/oxt/icon.svg0000644000000000000000000000750412245135610016114 0ustar rootroot image/svg+xml libreoffice-voikko-4.0/oxt/Linguistic.xcu0000644000000000000000000000153012245135610017267 0ustar rootroot fi-FI voikko.GrammarChecker libreoffice-voikko-4.0/oxt/config.xcu0000644000000000000000000000113312245135610016421 0ustar rootroot standard false true libreoffice-voikko-4.0/oxt/description.xml.template0000644000000000000000000000214012245135610021311 0ustar rootroot Writing aids based on Voikko Voikko-pohjaiset kirjoituksen aputyökalut Voikon kehittäjäyhteisö Voikko development community libreoffice-voikko-4.0/oxt/SettingsDialog_fi_FI.properties0000644000000000000000000000112412245135610022525 0ustar rootroot# SettingsDialog strings (Finnish) 0.voikkoasetukset.HelpText= 1.voikkoasetukset.Title=Voikon asetukset 6.voikkoasetukset.hyphenationFrame.HelpText= 7.voikkoasetukset.hyphenationFrame.Label=Tavutus 8.voikkoasetukset.hyphWordParts.HelpText= 9.voikkoasetukset.hyphWordParts.Label=Noudata tavutusasetuksia my\u00f6s yhdyssanojen osissa 10.voikkoasetukset.hyphUnknownWords.HelpText= 11.voikkoasetukset.hyphUnknownWords.Label=Tavuta tuntemattomat tai vieraskieliset sanat 12.voikkoasetukset.vocabularyFrame.Label=Sanasto 13.voikkoasetukset.topLine.Label=Voikko-pohjaiset kirjoituksen aputy\u00f6kalut libreoffice-voikko-4.0/oxt/META-INF/0000755000000000000000000000000012245135610015575 5ustar rootrootlibreoffice-voikko-4.0/oxt/META-INF/manifest.xml.template0000644000000000000000000000175112245135610021743 0ustar rootroot libreoffice-voikko-4.0/oxt/config.xcs0000644000000000000000000000114312245135610016420 0ustar rootroot libreoffice-voikko-4.0/oxt/SettingsDialog_en_US.default0000644000000000000000000000000012245135610022002 0ustar rootrootlibreoffice-voikko-4.0/oxt/SettingsDialog.xcu0000644000000000000000000000202312245135610020073 0ustar rootroot org.puimula.ooovoikko Voikko Voikko %origin%/SettingsDialog.xdl org.puimula.ooovoikko.SettingsEventHandlerImplementation libreoffice-voikko-4.0/ChangeLog0000644000000000000000000002064012245135610015377 0ustar rootroot2013-10-16 Harri Pitkänen * Re-license under MPL 2.0 and GPLv3+. 2013-10-10 Harri Pitkänen * Support grammar checkers and hyphenators for languages other than Finnish. 2013-10-06 Harri Pitkänen * Configuration option "Check capitalization" was removed in LibreOffice 4.0, no need to support it anymore. 2013-09-17 Harri Pitkänen * Support more languages for LibreOffice. 2013-07-29 Harri Pitkänen * Increase version number to 4.0. * LibreOffice 4.1 or later is now needed for building and running the extension. 2013-06-26 Harri Pitkänen * Avoid querying available spelling languages too often since it's very slow for zhfst spellers. 2013-06-19 Harri Pitkänen * Support more languages for LibreOffice. 2003-05-30 Sjur Moshagen * Support more languages for LibreOffice. 2013-01-06 Harri Pitkänen * Support more languages for LibreOffice. 2012-10-27 Harri Pitkänen * Support more languages for LibreOffice. 2012-02-01 Harri Pitkänen * Add Komi language mappings. 2012-01-20 Harri Pitkänen * Fix build with MSVC 2005. * Update license texts for standalone extension. 2012-01-19 Harri Pitkänen * Add links to extended grammar checker help. 2012-01-02 Harri Pitkänen * Avoid double delete of component objects. 2011-02-17 Tarja Lindfors * New icon. 2011-02-16 Harri Pitkänen * Specify English as the fallback language for settings dialog. 2011-02-05 Harri Pitkänen * Rename source package to libreoffice-voikko. * Add new codes to language mapping table. * Remove -Werror from compiler flags, STLPort (used on 32 bit Linux) headers contain code that triggers warnings with recent GCC. 2011-02-01 Harri Pitkänen * Remove %origin% expansion trick from configuration, it has been unused since version 3.0. * Document that the extension now targets primarily LibreOffice. 2010-12-22 Harri Pitkänen * Add support for spell checking multiple languages. 2010-07-27 David Tardon * Fix broken config.xcu to work with stricter validation in OOo 3.3. 2010-05-31 Harri Pitkänen * Switch to new libvoikko 3.0 API (Trac #11). * Ignoring grammar checker rules works (Trac #12). 2010-05-07 Harri Pitkänen * Add license attribute that allows suppressing the license dialog with unopkg --suppress-license. 2010-04-23 Harri Pitkänen * Remove references to malaga and glib libraries for Windows and OS X. * Increase version number to 3.1.1. 2010-01-05 Harri Pitkänen * Fix error handling for cases where configuration is somehow damaged. Partially fixes SF.net bug #2919454. 2009-10-26 Harri Pitkänen * Reduce scope of a variable to fix cppcheck warning. 2009-10-04 Harri Pitkänen * Re-enable grammar checker on Windows, since it works when libvoikko has been built with MSVC. * Document the fact that MSVC should be used for building libvoikko on Windows. Change the build system so that libvoikko-1.def -> libvoikko-1.lib conversion is no longer done, because MSVC creates libvoikko-1.lib automatically. * Allow copying entire directories when creating standalone extensions. Update the names of files to be copied for libvoikko 2.2. 2009-07-27 Petr Mladek * Change order of linker flags on Linux to enable building with -Wl,--as-needed. 2009-05-15 Harri Pitkänen * Replace the icon with something less irritating and add svg version. 2009-04-11 Harri Pitkänen * Implement listing of available dictionaries in standalone extensions. 2009-04-05 Harri Pitkänen * Print debug info to stderr instead of stdout to avoid buffering. 2009-03-15 Harri Pitkänen * Enable VOIKKO_OPT_ACCEPT_BULLETED_LISTS_IN_GC to silence false positives in bulleted lists. 2009-03-15 Harri Pitkänen * Disable grammar checker on Windows, it does not work. 2009-03-11 Harri Pitkänen * Read dictionary variant from registry on startup. 2009-03-06 Harri Pitkänen * Fall back to default dictionary if specified variant is not available. * Show more ugly warnings when SHOW_UGLY_WARNINGS=1. 2009-02-15 Harri Pitkänen * Allow changing dictionary variant in settings. 2009-02-14 Harri Pitkänen * Turn PropertyManager into a proper singleton. 2009-01-31 Harri Pitkänen * Turn SpellChecker, Hyphenator and GrammarChecker into singletons. 2009-01-04 Harri Pitkänen * Add option for preventing hyphenation of unknown or foreign words. 2008-12-29 Harri Pitkänen * Adapt to grammar checking framework API changes in OOo 3.0.1. 2008-10-12 Harri Pitkänen * Use VOIKKO_OPT_ACCEPT_UNFINISHED_PARAGRAPHS_IN_GC from libvoikko 2.1. * Enable grammar checker by default. * Increase version number to 3.1. 2008-08-23 Harri Pitkänen * Detect UI language and use that to offer grammar error explanations in correct language. 2008-08-16 Harri Pitkänen * Add grammar checker implementation. 2008-08-10 Harri Pitkänen * Adapt to SDK changes on Windows. 2008-08-09 Harri Pitkänen * Adapt to SDK changes on OS X. 2008-07-25 Harri Pitkänen * Adapt to DEV300_m26. 2008-07-21 Harri Pitkänen * Add setting (checkbox) for compound word hyphenation and store the value to the registry. * Use new compound word hyphenation setting when hyphenating. * Add build option SHOW_UGLY_WARNINGS to be used in binary test builds. 2008-07-19 Harri Pitkänen * Add settings dialog. * Add build option for disabling the grammar checker. 2008-07-18 Harri Pitkänen * Add icon and publisher information for new extension manager. 2008-07-10 Harri Pitkänen * Build fixes, thanks to Caolan McNamara from RedHat. 2008-03-30 Harri Pitkänen * Add stub for grammar checker implementation. * Documentation fixes. 2008-03-24 Harri Pitkänen * Respect HyphMinLeading and HyphMinTrailing in Hyphenator::createPossibleHyphens. 2008-03-23 Harri Pitkänen * Update license to GPL v3 or later. * Update extension version and required OOo version for openoffice.org-voikko 3.0 and OOo 3.0. * Use PackageInformationProvider to get the extension installation path. * Use thread unsafe UNO purpose environment. 2008-01-23 Harri Pitkänen * Add Makefile targets 'extension-files', 'oxt' and 'install-unpacked'. 'extension-files' is the new default, 'all' refers to 'oxt'. 2008-01-22 Harri Pitkänen * Use locale encoding with file names. * Add displayname to description.xml for OOo 2.4. 2008-01-19 Harri Pitkänen * Standalone extension support for OS X 10.5. * Update README. 2008-01-18 Harri Pitkänen * Makefile support for OS X 10.5 (Intel). 2007-11-17 Harri Pitkänen * Add magic key "VoikkoGetStatusInformation" for obtaining diagnostics from production builds. * Increase version number to 2.2. 2007-08-19 Harri Pitkänen * Update README * Makefile cleanup 2007-06-19 Harri Pitkänen * Adapt for libvoikko 1.5 * Increase version number to 2.1 * Use private vocabulary files when building as standalone extension * Add support for displaying license text upon extension installation (not enabled by default) 2007-06-14 Harri Pitkänen * Add support for building on Windows with Microsoft Visual C++ 2005 Express Edition * Fix some warnings generated by MSVC 2007-05-12 Harri Pitkänen * Return immediately from Hyphenator::hyphenate and Hyphenator::createPossibleHyphens if initialization has not been done. 2007-05-07 Harri Pitkänen * Do not hyphenate at ' * Increase version number to 2.0.1 2007-04-19 Harri Pitkänen * Initial ChangeLog entry for version 2.0rc1 libreoffice-voikko-4.0/README0000644000000000000000000001060612245135610014506 0ustar rootrootWhat is this? ============= This is libreoffice-voikko, a multi language spellchecker, grammar checker and hyphenator extension for LibreOffice. It uses libvoikko for all linguistic operations. Spell checking is supported for multiple languages. Other features are currently available only for Finnish. License ======= This package is distributed under the terms of Mozilla Public License Version 2.0 (see COPYING). Alternatively, the source code may be used under the terms of the GNU General Public License, version 3 or later. Authors ======= Source code: 2005 - 2013 Harri Pitkänen (hatapitk@iki.fi) Icon: 2011 Tarja Lindfors (tarja@puimula.org) Porting status ============== - Linux: This is the primary development platform, and should always work - FreeBSD: Status unknown - Windows: Should usually work without too much patching. - Mac OS X: Version 10.5 (Intel) was supported, current status unknown. Build requirements ================== - LibreOffice 4.1 or later (Office and SDK). - Libvoikko version 3.7 or later. - On Linux: the C++ compiler from the GCC, version 3.4 or later. Other tools needed for compilation are usually present in default setups of any distribution. - On Windows: Microsoft Visual C++ 2005 or later (the Express Edition is sufficient), GNU make, GNU sed and Info-Zip zip. - On OS X: Xcode tools from the operating system installation CD. Static versions of libvoikko and its dependencies are needed to build a standalone extension. Instructions for compilation ============================ - Install all of the required software listed above. - In a shell, run the SDK setup script which is located in the SDK installation directory. It is called setsdkenv_unix on Linux and OS X, and setsdkenv_windows on Windows. During the first run, this script will ask the location of certain tools. You should answer the questions, although at least on Linux the defaults are usually correct. Answers to these questions will be saved under the home directory of the user (for example to a file libreoffice4.1_sdk/hostname/setsdkenv_unix.sh). * On OS X and Windows you must make sure that neither LibreOffice nor its SDK have spaces in their installation path. On Windows you can use spaces in these paths if you replace the components containing spaces with the "8.3" name during configuration of the SDK as follows: Office = C:\PROGRA~1\LIBREO~1.6 URE = C:\PROGRA~1\LIBREO~1.6\URE - Run "make oxt". This will build the extensions package voikko.oxt under subdirectory build. * There are some settings available that can be used to customize the build. Please see "build settings" in Makefile. You may change any of these settings by running "make VARIABLE=value" instead of "make". Supported Make targets ====================== - extension-files Builds the extension files under build/oxt. - oxt Builds the extensions package voikko.oxt under subdirectory build. - all Same as 'oxt'. - install-unpacked DESTDIR=some_directory Installs the unpacked extension under directory DESTDIR. Default for DESTDIR is /usr/lib/libreoffice-voikko. - dist-gzip Builds the source package. - clean Removes all files generated by other targets. Diagnostic tools ================ Compiling libreoffice-voikko with DEBUG=LOG or DEBUG=FULL will create a build that prints some useful diagnostic output to stdout. To debug possible initialization errors in production builds, try listing spelling suggestions for string "VoikkoGetStatusInformation". This will return a string that contains all successfully initialized languages and failed initializations along with error messages from libvoikko. Bug reports and patches ======================= Patches and bug reports can be sent to the author (hatapitk@iki.fi). The web site for libreoffice-voikko is located at http://voikko.puimula.org Change history ============== Version 2.0 was an almost total rewrite of the previous version 1.2. This version was designed to work well with libvoikko and aimed to use the best current practices for OpenOffice.org extension development. The old code was based on the internals of OpenOffice.org 1.0 and designed to work with a non-free Finnish spellchecking library. In version 2.0 the license was changed from LGPL to GPL to reflect the fact that this extension is useless without libvoikko, which is distributed under the GPL. For changes since 2.0 see ChangeLog. libreoffice-voikko-4.0/src/0000755000000000000000000000000012245135610014412 5ustar rootrootlibreoffice-voikko-4.0/src/PropertyManager.cxx0000644000000000000000000003434012245135610020261 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include #include #include #include #include #include #include #include #include "PropertyManager.hxx" #include "VoikkoHandlePool.hxx" #include "common.hxx" namespace voikko { #ifdef VOIKKO_STANDALONE_EXTENSION static OUString getInstallationPath(uno::Reference & compContext) { try { VOIKKO_DEBUG("getInstallationPath"); uno::Reference provider(deployment::PackageInformationProvider::get(compContext)); OUString locationFileURL = provider->getPackageLocation(A2OU("org.puimula.ooovoikko")); VOIKKO_DEBUG_2("%s", OU2DEBUG(locationFileURL)); OUString locationSystemPath; osl::FileBase::getSystemPathFromFileURL(locationFileURL, locationSystemPath); VOIKKO_DEBUG_2("%s", OU2DEBUG(locationSystemPath)); return locationSystemPath; } catch (uno::Exception e) { // TODO: something more useful here VOIKKO_DEBUG("getInstallationPath(): ERROR"); return OUString(); } } #endif PropertyManager::PropertyManager(uno::Reference cContext): compContext(cContext), linguEventListeners(getVoikkoMutex()), messageLanguage("en_US") { #ifdef VOIKKO_STANDALONE_EXTENSION rtl_TextEncoding encoding = osl_getTextEncodingFromLocale(0); if (encoding == RTL_TEXTENCODING_DONTKNOW) { encoding = RTL_TEXTENCODING_UTF8; } VoikkoHandlePool::getInstance()->setInstallationPath(OUStringToOString(getInstallationPath(cContext), encoding)); #endif VOIKKO_DEBUG("PropertyManager:CTOR"); linguPropSet = 0; hyphMinLeading = 2; hyphMinTrailing = 2; hyphMinWordLength = 5; hyphWordParts = sal_False; hyphUnknownWords = sal_True; try { uno::Any dictVariantA = readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/dictionary"), A2OU("variant")); OUString dictVariant; dictVariantA >>= dictVariant; VoikkoHandlePool::getInstance()->setPreferredGlobalVariant(dictVariant); VOIKKO_DEBUG_2("Initial dictionary variant '%s'", OU2DEBUG(dictVariant)); } catch (beans::UnknownPropertyException e) { VOIKKO_DEBUG("Setting initial dictionary variant to default"); VoikkoHandlePool::getInstance()->setPreferredGlobalVariant(OUString()); } initialize(); } PropertyManager::~PropertyManager() { VOIKKO_DEBUG("PropertyManager:DTOR"); /* This might need locking, but since the property manager is never destroyed * before the office shutdown, there should be no other sources for calls to * libvoikko at this time. */ VoikkoHandlePool::getInstance()->closeAllHandles(); } void SAL_CALL PropertyManager::propertyChange(const beans::PropertyChangeEvent & /*pce*/) throw (uno::RuntimeException) { VOIKKO_DEBUG("PropertyManager::propertyChange"); setProperties(linguPropSet); linguistic2::LinguServiceEvent event; event.nEvent = linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN; sendLinguEvent(event); } void SAL_CALL PropertyManager::disposing(const lang::EventObject &) throw (uno::RuntimeException){ } void PropertyManager::setUiLanguage() { try { uno::Any langA = readFromRegistry( A2OU("org.openoffice.Office.Linguistic/General"), A2OU("UILocale")); OUString lang; langA >>= lang; VOIKKO_DEBUG_2("Specified UI locale = '%s'", OU2DEBUG(lang)); if (lang.match(A2OU("fi"), 0)) { messageLanguage = "fi_FI"; } else if (lang.getLength() == 0) { // Use system default language // FIXME: This does not check LC_MESSAGES. There is // also GetSystemUILanguage but that cannot be used // from extension. rtl_Locale * rtlLocale; osl_getProcessLocale(&rtlLocale); OUString localeLang(rtlLocale->Language); VOIKKO_DEBUG_2("Locale language = '%s'", OU2DEBUG(localeLang)); if (localeLang.match(A2OU("fi"), 0)) { messageLanguage = "fi_FI"; } } } catch (beans::UnknownPropertyException) { VOIKKO_DEBUG("ERROR: PropertyManager::initialize caught UnknownPropertyException"); } } void PropertyManager::initialize() throw (uno::Exception) { VOIKKO_DEBUG("PropertyManager::initialize: starting"); setUiLanguage(); VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_IGNORE_DOT, true); VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_NO_UGLY_HYPHENATION, true); // Set these options globally until OOo bug #97945 is resolved. VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_ACCEPT_TITLES_IN_GC, true); VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_ACCEPT_BULLETED_LISTS_IN_GC, true); VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_ACCEPT_UNFINISHED_PARAGRAPHS_IN_GC, true); uno::Reference servManager = compContext->getServiceManager(); uno::Reference LPIFace = servManager->createInstanceWithContext( A2OU("com.sun.star.linguistic2.LinguProperties"), compContext); linguPropSet = uno::Reference(LPIFace, uno::UNO_QUERY); linguPropSet->addPropertyChangeListener(A2OU("IsSpellWithDigits"), this); linguPropSet->addPropertyChangeListener(A2OU("IsSpellUpperCase"), this); VOIKKO_DEBUG("PropertyManager::initialize: property manager initalized"); // synchronize the local settings from global preferences setProperties(linguPropSet); readVoikkoSettings(); // request that all users of linguistic services run the spellchecker and hyphenator // again with updated settings linguistic2::LinguServiceEvent event; event.nEvent = linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN; sendLinguEvent(event); } sal_Int16 PropertyManager::getHyphMinLeading() { return hyphMinLeading; }; sal_Int16 PropertyManager::getHyphMinTrailing() { return hyphMinTrailing; }; sal_Int16 PropertyManager::getHyphMinWordLength() { return hyphMinWordLength; }; sal_Bool PropertyManager::addLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException) { VOIKKO_DEBUG("PropertyManager::addLinguServiceEventListener"); if (xLstnr.is()) { sal_Int32 listenerCount = linguEventListeners.getLength(); return (linguEventListeners.addInterface(xLstnr) != listenerCount); } else return sal_False; } sal_Bool PropertyManager::removeLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException) { VOIKKO_DEBUG("PropertyManager::removeLinguServiceEventListener"); if (xLstnr.is()) { sal_Int32 listenerCount = linguEventListeners.getLength(); return (linguEventListeners.removeInterface(xLstnr) != listenerCount); } else return sal_False; } void PropertyManager::setHyphWordParts(sal_Bool value) { hyphWordParts = value; syncHyphenatorSettings(); } uno::Any PropertyManager::readFromRegistry(const OUString group, const OUString & key) throw (beans::UnknownPropertyException) { uno::Reference rootView = getRegistryProperties(group, compContext); if (!rootView.is()) { VOIKKO_DEBUG("ERROR: failed to obtain rootView"); throw beans::UnknownPropertyException(); } uno::Reference propSet(rootView, uno::UNO_QUERY); if (!propSet.is()) { VOIKKO_DEBUG("ERROR: failed to obtain propSet"); throw beans::UnknownPropertyException(); } uno::Any value = propSet->getHierarchicalPropertyValue(key); return value; } void PropertyManager::readVoikkoSettings() { try { uno::Any hyphWordParts = readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/hyphenator"), A2OU("hyphWordParts")); hyphWordParts >>= this->hyphWordParts; uno::Any hyphUnknownWords = readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/hyphenator"), A2OU("hyphUnknownWords")); hyphUnknownWords >>= this->hyphUnknownWords; } catch (beans::UnknownPropertyException e) { VOIKKO_DEBUG("ERROR: readVoikkoSettings: UnknownPropertyException"); } syncHyphenatorSettings(); } const char * PropertyManager::getMessageLanguage() { return messageLanguage; } void PropertyManager::reloadVoikkoSettings() { VoikkoHandlePool * pool = VoikkoHandlePool::getInstance(); linguistic2::LinguServiceEvent event; event.nEvent = 0; try { uno::Any hyphWordParts = readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/hyphenator"), A2OU("hyphWordParts")); sal_Bool hyphWordPartsNew = this->hyphWordParts; hyphWordParts >>= hyphWordPartsNew; if (hyphWordPartsNew != this->hyphWordParts) { event.nEvent |= linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN; this->hyphWordParts = hyphWordPartsNew; } uno::Any hyphUnknownWords = readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/hyphenator"), A2OU("hyphUnknownWords")); sal_Bool hyphUnknownWordsNew = this->hyphUnknownWords; hyphUnknownWords >>= hyphUnknownWordsNew; if (hyphUnknownWordsNew != this->hyphUnknownWords) { event.nEvent |= linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN; this->hyphUnknownWords = hyphUnknownWordsNew; } uno::Any dictVariantA = readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/dictionary"), A2OU("variant")); OUString dictVariantNew = pool->getPreferredGlobalVariant(); dictVariantA >>= dictVariantNew; if (dictVariantNew != pool->getPreferredGlobalVariant()) { event.nEvent |= linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN; event.nEvent |= linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN; pool->setPreferredGlobalVariant(dictVariantNew); } } catch (beans::UnknownPropertyException e) { VOIKKO_DEBUG("ERROR: PropertyManager::reloadVoikkoSettings: UnknownPropertyException"); } syncHyphenatorSettings(); sendLinguEvent(event); } void PropertyManager::setProperties(const uno::Reference & properties) { beans::PropertyValue pValue; uno::Sequence pSeq = properties->getPropertySetInfo()->getProperties(); for (sal_Int32 i = 0; i < pSeq.getLength(); i++) { pValue.Name = pSeq[i].Name; pValue.Value = properties->getPropertyValue(pSeq[i].Name); setValue(pValue); } } void PropertyManager::setValues(const uno::Sequence & values) { for (sal_Int32 i = 0; i < values.getLength(); i++) setValue(values[i]); } void PropertyManager::resetValues(const uno::Sequence & values) { beans::PropertyValue globalValue; for (sal_Int32 i = 0; i < values.getLength(); i++) { globalValue.Name = values[i].Name; globalValue.Value = linguPropSet->getPropertyValue(values[i].Name); setValue(globalValue); } } void PropertyManager::setValue(const beans::PropertyValue & value) { sal_Bool bValue = sal_False; // VOIKKO_DEBUG_2("PropertyManager::setValue: name %s", OU2DEBUG(value.Name)); if (value.Name == A2OU("IsSpellWithDigits")) { value.Value >>= bValue; // VOIKKO_DEBUG_2("PropertyManager::setValue: value %i", vbValue); VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_IGNORE_NUMBERS, !bValue); } else if (value.Name == A2OU("IsSpellUpperCase")) { value.Value >>= bValue; // VOIKKO_DEBUG_2("PropertyManager::setValue: value %i", vbValue); VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_IGNORE_UPPERCASE, !bValue); } else if (value.Name == A2OU("HyphMinLeading")) { sal_Int16 iValue; if (value.Value >>= iValue) { hyphMinLeading = iValue; // VOIKKO_DEBUG_2("PropertyManager::setValue: value %i", iValue); syncHyphenatorSettings(); } } else if (value.Name == A2OU("HyphMinTrailing")) { sal_Int16 iValue; if (value.Value >>= iValue) { hyphMinTrailing = iValue; // VOIKKO_DEBUG_2("PropertyManager::setValue: value %i", iValue); syncHyphenatorSettings(); } } else if (value.Name == A2OU("HyphMinWordLength")) { sal_Int16 iValue; if (value.Value >>= iValue) { hyphMinWordLength = iValue; // VOIKKO_DEBUG_2("PropertyManager::setValue: value %i", iValue); syncHyphenatorSettings(); } } } void PropertyManager::syncHyphenatorSettings() { if (hyphWordParts) { VoikkoHandlePool::getInstance()->setGlobalIntegerOption(VOIKKO_MIN_HYPHENATED_WORD_LENGTH, hyphMinWordLength); } else { VoikkoHandlePool::getInstance()->setGlobalIntegerOption(VOIKKO_MIN_HYPHENATED_WORD_LENGTH, 2); } VoikkoHandlePool::getInstance()->setGlobalBooleanOption(VOIKKO_OPT_HYPHENATE_UNKNOWN_WORDS, hyphUnknownWords); } void PropertyManager::sendLinguEvent(const linguistic2::LinguServiceEvent & event) { VOIKKO_DEBUG("PropertyManager::sendLinguEvent"); cppu::OInterfaceIteratorHelper iterator(linguEventListeners); while (iterator.hasMoreElements()) { uno::Reference ref(iterator.next(), uno::UNO_QUERY); if (ref.is()) { VOIKKO_DEBUG("PropertyManager::sendLinguEvent sending event"); ref->processLinguServiceEvent(event); } } } static uno::Reference thePropertyManager = 0; uno::Reference PropertyManager::get(uno::Reference const & context) { if (!thePropertyManager.is()) { VOIKKO_DEBUG("PropertyManager::get first"); thePropertyManager = new PropertyManager(context); } return thePropertyManager; } } libreoffice-voikko-4.0/src/common.hxx0000644000000000000000000000215012245135610016431 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2008 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _COMMON_HXX_ #define _COMMON_HXX_ #include #include #include #include using namespace com::sun::star; namespace voikko { osl::Mutex & getVoikkoMutex(); /** Get property set for given group from registry */ uno::Reference getRegistryProperties(const rtl::OUString & group, uno::Reference compContext); } #endif libreoffice-voikko-4.0/src/hyphenator/0000755000000000000000000000000012245135610016573 5ustar rootrootlibreoffice-voikko-4.0/src/hyphenator/Hyphenator.hxx0000644000000000000000000001024612245135610021450 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2009 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _HYPHENATOR_HXX_ #define _HYPHENATOR_HXX_ #include #include #include #include #include #include #include #include #include "../PropertyManager.hxx" #include "../macros.hxx" using namespace ::com::sun::star; using namespace ::rtl; namespace voikko { class Hyphenator: private cppu::BaseMutex, public cppu::WeakComponentImplHelper5 { public: // ::com::sun::star::lang::XServiceInfo: virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL supportsService(const OUString & serviceName) throw (uno::RuntimeException); virtual uno::Sequence SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException); // ::com::sun::star::linguistic2::XSupportedLocales: virtual uno::Sequence SAL_CALL getLocales() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL hasLocale(const lang::Locale & aLocale) throw (uno::RuntimeException); // ::com::sun::star::linguistic2::XHyphenator: virtual uno::Reference SAL_CALL hyphenate(const OUString & aWord, const lang::Locale & aLocale, sal_Int16 nMaxLeading, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException); virtual uno::Reference SAL_CALL queryAlternativeSpelling(const OUString & aWord, const lang::Locale & aLocale, sal_Int16 nIndex, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException); virtual uno::Reference SAL_CALL createPossibleHyphens(const OUString & aWord, const lang::Locale & aLocale, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException); // ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster: virtual sal_Bool SAL_CALL addLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException); virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException); // ::com::sun::star::lang::XInitialization: virtual void SAL_CALL initialize(const uno::Sequence & aArguments) throw (uno::RuntimeException, uno::Exception); // ::com::sun::star::lang::XServiceDisplayName: virtual OUString SAL_CALL getServiceDisplayName(const lang::Locale & aLocale) throw (uno::RuntimeException); // Static methods static OUString getImplementationName_static(); static uno::Sequence getSupportedServiceNames_static(); static uno::Reference get(uno::Reference const & context); private: explicit Hyphenator(uno::Reference const & context); virtual ~Hyphenator(); virtual void SAL_CALL disposing(); uno::Reference compContext; }; } #endif libreoffice-voikko-4.0/src/hyphenator/PossibleHyphens.cxx0000644000000000000000000000263312245135610022442 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2005 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include "PossibleHyphens.hxx" #include "../macros.hxx" namespace voikko { PossibleHyphens::PossibleHyphens(const OUString & wrd, const OUString & hypWrd, uno::Sequence positions, const lang::Locale & locale) : word(wrd), hyphenatedWord(hypWrd), hyphenationPositions(positions), locale(locale) { } OUString SAL_CALL PossibleHyphens::getWord() throw (uno::RuntimeException) { return word; } lang::Locale SAL_CALL PossibleHyphens::getLocale() throw (uno::RuntimeException) { return locale; } OUString SAL_CALL PossibleHyphens::getPossibleHyphens() throw (uno::RuntimeException) { return hyphenatedWord; } uno::Sequence SAL_CALL PossibleHyphens::getHyphenationPositions() throw (uno::RuntimeException) { return hyphenationPositions; } } libreoffice-voikko-4.0/src/hyphenator/PossibleHyphens.hxx0000644000000000000000000000340012245135610022440 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2005 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _POSSIBLEHYPHENS_HXX_ #define _POSSIBLEHYPHENS_HXX_ #include #include using namespace ::com::sun::star; using namespace ::rtl; namespace voikko { /** Implementation of interface com::sun::star::linguistic2::XPossibleHyphens. See * the interface documentation for more information. */ class PossibleHyphens : public cppu::WeakImplHelper1 { private: const OUString word; const OUString hyphenatedWord; const uno::Sequence hyphenationPositions; const lang::Locale locale; PossibleHyphens & operator=(const PossibleHyphens&); public: PossibleHyphens(const OUString & wrd, const OUString & hypWrd, uno::Sequence positions, const lang::Locale & locale); virtual OUString SAL_CALL getWord() throw (uno::RuntimeException); virtual lang::Locale SAL_CALL getLocale() throw (uno::RuntimeException); virtual OUString SAL_CALL getPossibleHyphens() throw (uno::RuntimeException); virtual uno::Sequence SAL_CALL getHyphenationPositions() throw (uno::RuntimeException); }; } #endif libreoffice-voikko-4.0/src/hyphenator/HyphenatedWord.hxx0000644000000000000000000000346412245135610022260 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2005 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _HYPHENATEDWORD_HXX_ #define _HYPHENATEDWORD_HXX_ #include #include using namespace ::com::sun::star; using namespace ::rtl; namespace voikko { /** Implementation of interface com::sun::star::linguistic2::XHyphenatedWord. See * the interface documentation for more information. */ class HyphenatedWord : public cppu::WeakImplHelper1 { private: const OUString word; const sal_Int16 hyphenPos; const lang::Locale locale; OUString hyphenatedWord; sal_Bool isAlternative; HyphenatedWord & operator=(const HyphenatedWord&); public: HyphenatedWord(const OUString & wrd, sal_Int16 pos, const lang::Locale & locale); virtual OUString SAL_CALL getWord() throw (uno::RuntimeException); virtual lang::Locale SAL_CALL getLocale() throw (uno::RuntimeException); virtual sal_Int16 SAL_CALL getHyphenationPos() throw (uno::RuntimeException); virtual sal_Int16 SAL_CALL getHyphenPos() throw (uno::RuntimeException); virtual OUString SAL_CALL getHyphenatedWord() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL isAlternativeSpelling() throw (uno::RuntimeException); }; } #endif libreoffice-voikko-4.0/src/hyphenator/Hyphenator.cxx0000644000000000000000000002074312245135610021446 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include #include #include "Hyphenator.hxx" #include "HyphenatedWord.hxx" #include "PossibleHyphens.hxx" #include "../VoikkoHandlePool.hxx" #include "../common.hxx" namespace voikko { Hyphenator::Hyphenator(uno::Reference const & context) : cppu::WeakComponentImplHelper5 (m_aMutex), compContext(context) { VOIKKO_DEBUG("Hyphenator:CTOR"); PropertyManager::get(compContext); } OUString SAL_CALL Hyphenator::getImplementationName() throw (uno::RuntimeException) { return getImplementationName_static(); } sal_Bool SAL_CALL Hyphenator::supportsService(const OUString & serviceName) throw (uno::RuntimeException) { uno::Sequence serviceNames = getSupportedServiceNames(); for (sal_Int32 i = 0; i < serviceNames.getLength(); i++) if (serviceNames[i] == serviceName) return sal_True; return sal_False; } uno::Sequence SAL_CALL Hyphenator::getSupportedServiceNames() throw (uno::RuntimeException) { return getSupportedServiceNames_static(); } uno::Sequence SAL_CALL Hyphenator::getLocales() throw (uno::RuntimeException) { return VoikkoHandlePool::getInstance()->getSupportedHyphenationLocales(); } sal_Bool SAL_CALL Hyphenator::hasLocale(const lang::Locale & aLocale) throw (uno::RuntimeException) { return VoikkoHandlePool::getInstance()->supportsHyphenationLocale(aLocale); } uno::Reference SAL_CALL Hyphenator::hyphenate(const OUString & aWord, const lang::Locale & aLocale, sal_Int16 nMaxLeading, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException) { osl::MutexGuard vmg(getVoikkoMutex()); VOIKKO_DEBUG("Hyphenator::hyphenate"); VoikkoHandle * voikkoHandle = VoikkoHandlePool::getInstance()->getHandle(aLocale); if (!voikkoHandle) { return 0; } if (aWord.getLength() > 10000) { return 0; } PropertyManager::get(compContext)->setValues(aProperties); sal_Int16 minLeading = PropertyManager::get(compContext)->getHyphMinLeading(); sal_Int16 minTrailing = PropertyManager::get(compContext)->getHyphMinTrailing(); sal_Int16 wlen = (sal_Int16) aWord.getLength(); // If the word is too short to be hyphenated, return no hyphenation points if (wlen < PropertyManager::get(compContext)->getHyphMinWordLength() || wlen < minLeading + minTrailing) { PropertyManager::get(compContext)->resetValues(aProperties); return 0; } OString oWord = OUStringToOString(aWord, RTL_TEXTENCODING_UTF8); char * hyphenationPoints = voikkoHyphenateCstr(voikkoHandle, oWord.getStr()); if (hyphenationPoints == 0) { PropertyManager::get(compContext)->resetValues(aProperties); return 0; } // find the hyphenation point sal_Int16 hyphenPos = -1; sal_Int16 i = wlen - minTrailing; // The last generally allowed hyphenation point if (i > nMaxLeading) i = nMaxLeading; // The last allowed point on this line for (; i >= minLeading && hyphenPos == -1; i--) { if (aWord[i] == '\'') continue; if (hyphenationPoints[i] == '-' || hyphenationPoints[i] == '=') { hyphenPos = i; break; } } // return the result voikkoFreeCstr(hyphenationPoints); PropertyManager::get(compContext)->resetValues(aProperties); if (hyphenPos != -1) { return new HyphenatedWord(aWord, hyphenPos - 1, aLocale); } else { return 0; } } uno::Reference SAL_CALL Hyphenator::queryAlternativeSpelling(const OUString &, const lang::Locale &, sal_Int16, const uno::Sequence &) throw (uno::RuntimeException, lang::IllegalArgumentException) { VOIKKO_DEBUG("Hyphenator::queryAlternativeSpelling"); // FIXME: Implementing this might be necessary, although everything seems to work // fine without it. return 0; } uno::Reference SAL_CALL Hyphenator::createPossibleHyphens(const OUString & aWord, const lang::Locale & aLocale, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException) { osl::MutexGuard vmg(getVoikkoMutex()); VOIKKO_DEBUG("Hyphenator::createPossibleHyphens"); if (aWord.getLength() > 10000) { return 0; } VoikkoHandle * voikkoHandle = VoikkoHandlePool::getInstance()->getHandle(aLocale); if (!voikkoHandle) { return 0; } sal_Int16 len = (sal_Int16) aWord.getLength(); PropertyManager::get(compContext)->setValues(aProperties); // If the word is too short to be hyphenated, return no hyphenation points sal_Int16 minLeading = PropertyManager::get(compContext)->getHyphMinLeading(); sal_Int16 minTrailing = PropertyManager::get(compContext)->getHyphMinTrailing(); if (len < PropertyManager::get(compContext)->getHyphMinWordLength() || len < minLeading + minTrailing) { PropertyManager::get(compContext)->resetValues(aProperties); return 0; } OString oWord = OUStringToOString(aWord, RTL_TEXTENCODING_UTF8); uno::Reference xRes; char * hyphenationPoints = voikkoHyphenateCstr(voikkoHandle, oWord.getStr()); if (hyphenationPoints == 0) { PropertyManager::get(compContext)->resetValues(aProperties); return 0; } uno::Sequence hyphenSeq(0); OUStringBuffer hyphenatedWordBuffer; OUString hyphenatedWord; sal_Int16 nHyphCount = 0; for (sal_Int16 i = 0; i < len; i++) { hyphenatedWordBuffer.append(aWord[i]); if (i >= minLeading - 1 && i < len - minTrailing && hyphenationPoints[i + 1] == '-') { hyphenSeq.realloc(nHyphCount + 1); hyphenSeq[nHyphCount++] = i; hyphenatedWordBuffer.append(sal_Unicode('=')); } } hyphenatedWord = hyphenatedWordBuffer.makeStringAndClear(); xRes = new PossibleHyphens(aWord, hyphenatedWord, hyphenSeq, aLocale); voikkoFreeCstr(hyphenationPoints); PropertyManager::get(compContext)->resetValues(aProperties); return xRes; } sal_Bool SAL_CALL Hyphenator::addLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException) { osl::MutexGuard vmg(getVoikkoMutex()); VOIKKO_DEBUG("Hyphenator::addLinguServiceEventListener"); return PropertyManager::get(compContext)->addLinguServiceEventListener(xLstnr); } sal_Bool SAL_CALL Hyphenator::removeLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException) { osl::MutexGuard vmg(getVoikkoMutex()); VOIKKO_DEBUG("Hyphenator::removeLinguServiceEventListener"); return PropertyManager::get(compContext)->removeLinguServiceEventListener(xLstnr); } void SAL_CALL Hyphenator::initialize(const uno::Sequence &) throw (uno::RuntimeException, uno::Exception) { } OUString SAL_CALL Hyphenator::getServiceDisplayName(const lang::Locale & aLocale) throw (uno::RuntimeException) { if (aLocale.Language == A2OU("fi")) return A2OU("Tavutus (Voikko)"); else return A2OU("Hyphenator (Voikko)"); } OUString SAL_CALL Hyphenator::getImplementationName_static() { return A2OU("voikko.Hyphenator"); } uno::Sequence SAL_CALL Hyphenator::getSupportedServiceNames_static() { uno::Sequence snames(1); snames.getArray()[0] = A2OU("com.sun.star.linguistic2.Hyphenator"); return snames; } static ::cppu::OWeakObject * theHyphenator = 0; void SAL_CALL Hyphenator::disposing() { VOIKKO_DEBUG("Hyphenator:DISPOSING"); theHyphenator = 0; } uno::Reference SAL_CALL Hyphenator::get(uno::Reference const & context) { VOIKKO_DEBUG("Hyphenator::get"); if (!theHyphenator) { theHyphenator = static_cast< ::cppu::OWeakObject * >(new Hyphenator(context)); } return theHyphenator; } Hyphenator::~Hyphenator() { VOIKKO_DEBUG("Hyphenator:DTOR"); } } libreoffice-voikko-4.0/src/hyphenator/HyphenatedWord.cxx0000644000000000000000000000340012245135610022241 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2005 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include "HyphenatedWord.hxx" #include "../macros.hxx" namespace voikko { HyphenatedWord::HyphenatedWord(const OUString & wrd, sal_Int16 pos, const lang::Locale & locale) : word(wrd), hyphenPos(pos), locale(locale) { if (wrd[pos+1] == '-') { hyphenatedWord = wrd.replaceAt(pos+1, 1, A2OU("")); isAlternative = sal_True; } else { hyphenatedWord = wrd; isAlternative = sal_False; } VOIKKO_DEBUG_2("%s", OU2DEBUG(wrd)); //VOIKKO_DEBUG_2("%s", OU2DEBUG(hyphenatedWord)); VOIKKO_DEBUG_2("%i", pos); } OUString SAL_CALL HyphenatedWord::getWord() throw (uno::RuntimeException) { return word; } OUString SAL_CALL HyphenatedWord::getHyphenatedWord() throw (uno::RuntimeException) { return hyphenatedWord; } lang::Locale SAL_CALL HyphenatedWord::getLocale() throw (uno::RuntimeException) { return locale; } sal_Int16 SAL_CALL HyphenatedWord::getHyphenationPos() throw (uno::RuntimeException) { return hyphenPos; } sal_Int16 SAL_CALL HyphenatedWord::getHyphenPos() throw (uno::RuntimeException) { return hyphenPos; } sal_Bool SAL_CALL HyphenatedWord::isAlternativeSpelling() throw (uno::RuntimeException) { return isAlternative; } } libreoffice-voikko-4.0/src/registry.cxx0000644000000000000000000000565712245135610017023 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2009 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include #include #include #include #include "macros.hxx" #include "spellchecker/SpellChecker.hxx" #include "hyphenator/Hyphenator.hxx" #include "grammar/GrammarChecker.hxx" #include "settings/SettingsEventHandler.hxx" using namespace ::com::sun::star::registry; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::rtl; namespace voikko { extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(sal_Char const ** ppEnvTypeName, uno_Environment **) { VOIKKO_DEBUG("component_getImplementationEnvironment"); *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ":unsafe"; } Reference SAL_CALL regSettingsCreate(const Reference & context) SAL_THROW((Exception)) { return static_cast< ::cppu::OWeakObject * >(new SettingsEventHandler(context)); } static ::cppu::ImplementationEntry const regEntries[] = { { &SpellChecker::get, &SpellChecker::getImplementationName_static, &SpellChecker::getSupportedServiceNames_static, &::cppu::createSingleComponentFactory, 0, 0 }, { &Hyphenator::get, &Hyphenator::getImplementationName_static, &Hyphenator::getSupportedServiceNames_static, &::cppu::createSingleComponentFactory, 0, 0 }, #ifndef DISABLE_GRAMMAR_CHECKER { &GrammarChecker::get, &GrammarChecker::getImplementationName_static, &GrammarChecker::getSupportedServiceNames_static, &::cppu::createSingleComponentFactory, 0, 0 }, #endif { ®SettingsCreate, &SettingsEventHandler::getImplementationName_static, &SettingsEventHandler::getSupportedServiceNames_static, &::cppu::createSingleComponentFactory, 0, 0 }, { 0, 0, 0, 0, 0, 0 } }; extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * serviceManager, void * registryKey) { VOIKKO_DEBUG("component_writeInfo"); return ::cppu::component_writeInfoHelper(serviceManager, registryKey, regEntries); } extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(const char * implName, void * serviceManager, void * registryKey) { VOIKKO_DEBUG("component_getFactory"); return ::cppu::component_getFactoryHelper(implName, serviceManager, registryKey, regEntries); } } libreoffice-voikko-4.0/src/settings/0000755000000000000000000000000012245135610016252 5ustar rootrootlibreoffice-voikko-4.0/src/settings/SettingsEventHandler.cxx0000644000000000000000000003055512245135610023106 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2008 - 2009 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include "SettingsEventHandler.hxx" #include "../common.hxx" #include "../PropertyManager.hxx" #include "../VoikkoHandlePool.hxx" #include #include #include #include #include #include #include #include namespace voikko { SettingsEventHandler::SettingsEventHandler(uno::Reference const & context) : cppu::WeakComponentImplHelper2 (m_aMutex), compContext(context), dictionaryVariantList(1) { VOIKKO_DEBUG("SettingsEventHandler:CTOR"); dictionaryVariantList.getArray()[0] = A2OU("standard: suomen kielen perussanasto"); } OUString SAL_CALL SettingsEventHandler::getImplementationName() throw (uno::RuntimeException) { return getImplementationName_static(); } sal_Bool SAL_CALL SettingsEventHandler::supportsService(const OUString & serviceName) throw (uno::RuntimeException) { uno::Sequence serviceNames = getSupportedServiceNames(); for (sal_Int32 i = 0; i < serviceNames.getLength(); i++) if (serviceNames[i] == serviceName) return sal_True; return sal_False; } uno::Sequence SAL_CALL SettingsEventHandler::getSupportedServiceNames() throw (uno::RuntimeException) { return getSupportedServiceNames_static(); } sal_Bool SAL_CALL SettingsEventHandler::callHandlerMethod(const uno::Reference & xWindow, const uno::Any & EventObject, const OUString & MethodName) throw (lang::WrappedTargetException, uno::RuntimeException) { if (MethodName != A2OU("external_event")) return sal_False; OUString eventS; EventObject >>= eventS; if (eventS == A2OU("ok")) { saveOptionsFromWindowToRegistry(xWindow); PropertyManager::get(compContext)->reloadVoikkoSettings(); return sal_True; } if (eventS == A2OU("back") || eventS == A2OU("initialize")) { initOptionsWindowFromRegistry(xWindow); return sal_True; } return sal_False; } uno::Sequence SAL_CALL SettingsEventHandler::getSupportedMethodNames() throw (uno::RuntimeException) { uno::Sequence methodNames(1); methodNames.getArray()[0] = A2OU("external_event"); return methodNames; } void SettingsEventHandler::initOptionsWindowFromRegistry(const uno::Reference & window) { VOIKKO_DEBUG("initOptionsWindowFromRegistry()"); sal_Bool hyphWordPartsValue = sal_False; sal_Bool hyphUnknownWordsValue = sal_True; uno::Any hyphWordPartsAValue; uno::Any hyphUnknownWordsAValue; try { hyphWordPartsAValue = PropertyManager::get(compContext)->readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/hyphenator"), A2OU("hyphWordParts")); hyphWordPartsAValue >>= hyphWordPartsValue; hyphUnknownWordsAValue = PropertyManager::get(compContext)->readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/hyphenator"), A2OU("hyphUnknownWords")); hyphUnknownWordsAValue >>= hyphUnknownWordsValue; } catch (beans::UnknownPropertyException e) { VOIKKO_DEBUG("ERROR: UnknownPropertyException"); return; } if (hyphWordPartsValue) { VOIKKO_DEBUG("hyphWordParts = true"); } else { VOIKKO_DEBUG("hyphWordParts = false"); } uno::Reference windowContainer = uno::Reference(window, uno::UNO_QUERY); if (!windowContainer.is()) { VOIKKO_DEBUG("ERROR: failed to obtain windowContainer"); return; } uno::Reference hyphWordParts = windowContainer->getControl(A2OU("hyphWordParts")); if (!hyphWordParts.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphWordParts"); return; } uno::Reference hyphWordPartsProps = uno::Reference(hyphWordParts->getModel(), uno::UNO_QUERY); if (!hyphWordPartsProps.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphWordPartsProps"); return; } if (hyphWordPartsValue) hyphWordPartsAValue <<= (sal_Int16) 1; else hyphWordPartsAValue <<= (sal_Int16) 0; hyphWordPartsProps->setPropertyValue(A2OU("State"), hyphWordPartsAValue); uno::Reference hyphUnknownWords = windowContainer->getControl(A2OU("hyphUnknownWords")); if (!hyphUnknownWords.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphUnknownWords"); return; } uno::Reference hyphUnknownWordsProps = uno::Reference(hyphUnknownWords->getModel(), uno::UNO_QUERY); if (!hyphUnknownWordsProps.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphUnknownWordsProps"); return; } if (hyphUnknownWordsValue) hyphUnknownWordsAValue <<= (sal_Int16) 1; else hyphUnknownWordsAValue <<= (sal_Int16) 0; hyphUnknownWordsProps->setPropertyValue(A2OU("State"), hyphUnknownWordsAValue); initVariantDropdown(windowContainer); } void SettingsEventHandler::saveOptionsFromWindowToRegistry(const uno::Reference & window) { VOIKKO_DEBUG("saveOptionsFromWindowToRegistry()"); if (!window.is()) { VOIKKO_DEBUG("ERROR: window is null"); return; } uno::Reference windowContainer = uno::Reference(window, uno::UNO_QUERY); if (!windowContainer.is()) { VOIKKO_DEBUG("ERROR: failed to obtain windowContainer"); return; } uno::Reference hyphWordParts = windowContainer->getControl(A2OU("hyphWordParts")); if (!hyphWordParts.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphWordParts"); return; } uno::Reference hyphWordPartsProps = uno::Reference(hyphWordParts->getModel(), uno::UNO_QUERY); if (!hyphWordPartsProps.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphWordPartsProps"); return; } uno::Any hyphWordPartsAValue = hyphWordPartsProps->getPropertyValue(A2OU("State")); sal_Int16 hyphWordPartsValue = 0; hyphWordPartsAValue >>= hyphWordPartsValue; // 0 = unchecked, 1 = checked uno::Reference hyphUnknownWords = windowContainer->getControl(A2OU("hyphUnknownWords")); if (!hyphUnknownWords.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphUnknownWords"); return; } uno::Reference hyphUnknownWordsProps = uno::Reference(hyphUnknownWords->getModel(), uno::UNO_QUERY); if (!hyphUnknownWordsProps.is()) { VOIKKO_DEBUG("ERROR: failed to obtain hyphUnknownWordsProps"); return; } uno::Any hyphUnknownWordsAValue = hyphUnknownWordsProps->getPropertyValue(A2OU("State")); sal_Int16 hyphUnknownWordsValue = 0; hyphUnknownWordsAValue >>= hyphUnknownWordsValue; // 0 = unchecked, 1 = checked uno::Reference rootView = getRegistryProperties(A2OU("/org.puimula.ooovoikko.Config/hyphenator"), compContext); uno::Reference propSet(rootView, uno::UNO_QUERY); if (!propSet.is()) { VOIKKO_DEBUG("ERROR: failed to obtain propSet"); return; } hyphWordPartsAValue <<= (hyphWordPartsValue == 1 ? sal_True : sal_False); propSet->setHierarchicalPropertyValue(A2OU("hyphWordParts"), hyphWordPartsAValue); hyphUnknownWordsAValue <<= (hyphUnknownWordsValue == 1 ? sal_True : sal_False); propSet->setHierarchicalPropertyValue(A2OU("hyphUnknownWords"), hyphUnknownWordsAValue); uno::Reference updateCommit(rootView, uno::UNO_QUERY); if (!updateCommit.is()) { VOIKKO_DEBUG("ERROR: failed to obtain updateCommit"); return; } updateCommit->commitChanges(); // dictionary variant OUString variantValue = getSelectedVariant(windowContainer); uno::Any variantAValue; variantAValue <<= variantValue; rootView = getRegistryProperties(A2OU("/org.puimula.ooovoikko.Config/dictionary"), compContext); uno::Reference variantPropSet(rootView, uno::UNO_QUERY); if (!variantPropSet.is()) { VOIKKO_DEBUG("ERROR: failed to obtain variantPropSet"); return; } variantPropSet->setHierarchicalPropertyValue(A2OU("variant"), variantAValue); uno::Reference variantUpdateCommit(rootView, uno::UNO_QUERY); if (!variantUpdateCommit.is()) { VOIKKO_DEBUG("ERROR: failed to obtain variantUpdateCommit"); return; } variantUpdateCommit->commitChanges(); } void SettingsEventHandler::initVariantDropdown(const uno::Reference & windowContainer) { uno::Reference variantDropdown = windowContainer->getControl(A2OU("variant")); if (!variantDropdown.is()) { VOIKKO_DEBUG("ERROR: failed to obtain variant dropdown control"); return; } uno::Reference variantProps = uno::Reference(variantDropdown->getModel(), uno::UNO_QUERY); if (!variantDropdown.is()) { VOIKKO_DEBUG("ERROR: failed to obtain variantProps"); return; } // populate dropdown list with available variants initAvailableVariants(); uno::Any stringListAValue; stringListAValue <<= dictionaryVariantList; variantProps->setPropertyValue(A2OU("StringItemList"), stringListAValue); // read selected dictionary variant from registry OUString registryVariantValue(A2OU("standard")); try { uno::Any registryVariantAValue = PropertyManager::get(compContext)->readFromRegistry( A2OU("/org.puimula.ooovoikko.Config/dictionary"), A2OU("variant")); registryVariantAValue >>= registryVariantValue; } catch (beans::UnknownPropertyException e) { VOIKKO_DEBUG("ERROR: UnknownPropertyException dictionary/variant"); return; } registryVariantValue += A2OU(": "); uno::Sequence selectedValues(1); selectedValues[0] = 0; for (sal_Int16 i = 0; i < dictionaryVariantList.getLength(); i++) { if (dictionaryVariantList[i].indexOf(registryVariantValue) == 0) { selectedValues[0] = i; break; } } // set the selected item in the dropdown list uno::Any selectedAValues; selectedAValues <<= selectedValues; variantProps->setPropertyValue(A2OU("SelectedItems"), selectedAValues); } void SettingsEventHandler::initAvailableVariants() { voikko_dict ** dicts = voikko_list_dicts(VoikkoHandlePool::getInstance()->getInstallationPath()); if (!dicts) { VOIKKO_DEBUG("ERROR: Failed to list available dictionaries"); return; } size_t nDicts = 0; for (voikko_dict ** i = dicts; *i; i++) { nDicts++; } dictionaryVariantList = uno::Sequence(nDicts); for (size_t i = 0; i < nDicts; i++) { OUString dictName = A2OU(voikko_dict_variant(dicts[i])); dictName += A2OU(": "); dictName += UTF82OU(voikko_dict_description(dicts[i])); dictionaryVariantList[i] = dictName; } voikko_free_dicts(dicts); } OUString SettingsEventHandler::getSelectedVariant( const uno::Reference & windowContainer) { uno::Reference variantDropdown = windowContainer->getControl(A2OU("variant")); if (!variantDropdown.is()) { VOIKKO_DEBUG("ERROR: failed to obtain variant dropdown control"); return A2OU("standard"); } uno::Reference variantProps = uno::Reference(variantDropdown->getModel(), uno::UNO_QUERY); if (!variantDropdown.is()) { VOIKKO_DEBUG("ERROR: failed to obtain variantProps"); return A2OU("standard"); } // get all values uno::Any stringListAValue = variantProps->getPropertyValue(A2OU("StringItemList")); uno::Sequence stringListValue; stringListAValue >>= stringListValue; // get the selected item index uno::Any selectedAValues = variantProps->getPropertyValue(A2OU("SelectedItems")); uno::Sequence selectedValues(1); selectedAValues >>= selectedValues; // parse the variant id from the string OUString selectedValue = stringListValue[selectedValues[0]]; sal_Int32 variantIdEnd = selectedValue.indexOf(A2OU(":")); if (variantIdEnd != -1) { return selectedValue.copy(0, variantIdEnd); } VOIKKO_DEBUG("ERROR: failed to get the selected variant, returning default"); return A2OU("standard"); } } libreoffice-voikko-4.0/src/settings/SettingsEventHandler.hxx0000644000000000000000000000674512245135610023117 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2008 - 2009 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _SETTINGSEVENTHANDLER_HXX_ #define _SETTINGSEVENTHANDLER_HXX_ #include #include #include #include #include #include #include "../macros.hxx" using namespace ::com::sun::star; using namespace ::rtl; namespace voikko { class SettingsEventHandler: private cppu::BaseMutex, public cppu::WeakComponentImplHelper2 { public: explicit SettingsEventHandler(uno::Reference const & context); virtual ~SettingsEventHandler() {} // ::com::sun::star::lang::XServiceInfo: virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL supportsService(const OUString & serviceName) throw (uno::RuntimeException); virtual uno::Sequence SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException); // ::com::sun::star::awt::XContainerWindowEventHandler: virtual sal_Bool SAL_CALL callHandlerMethod(const uno::Reference & xWindow, const uno::Any & EventObject, const OUString & MethodName) throw (lang::WrappedTargetException, uno::RuntimeException); virtual uno::Sequence SAL_CALL getSupportedMethodNames() throw (uno::RuntimeException); // Static methods static inline OUString getImplementationName_static(); static inline uno::Sequence getSupportedServiceNames_static(); private: /** Initialize options window from registry */ void initOptionsWindowFromRegistry(const uno::Reference & window); /** Save options from options window to registry */ void saveOptionsFromWindowToRegistry(const uno::Reference & window); /** Initialize the dropdown box for dictionary variant */ void initVariantDropdown(const uno::Reference & windowContainer); /** Initialize list of available dictionary variants */ void initAvailableVariants(); /** Get the currently selected dictionary variant from the dropdown box */ OUString getSelectedVariant(const uno::Reference & windowContainer); uno::Reference compContext; uno::Sequence dictionaryVariantList; }; // Static method implementations inline OUString SettingsEventHandler::getImplementationName_static() { return A2OU("org.puimula.ooovoikko.SettingsEventHandlerImplementation"); } inline uno::Sequence SAL_CALL SettingsEventHandler::getSupportedServiceNames_static() { uno::Sequence snames(1); snames.getArray()[0] = A2OU("org.puimula.ooovoikko.SettingsEventHandlerService"); return snames; } } #endif libreoffice-voikko-4.0/src/spellchecker/0000755000000000000000000000000012245135610017056 5ustar rootrootlibreoffice-voikko-4.0/src/spellchecker/SpellAlternatives.hxx0000644000000000000000000000325312245135610023253 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2005 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _SPELLALTERNATIVES_HXX_ #define _SPELLALTERNATIVES_HXX_ #include #include #include using namespace ::com::sun::star; using namespace ::rtl; namespace voikko { class SpellAlternatives : public cppu::WeakImplHelper1 { private: const OUString word; const uno::Sequence alternatives; const lang::Locale locale; SpellAlternatives & operator=(const SpellAlternatives&); public: SpellAlternatives(const OUString & word, uno::Sequence alternatives, const lang::Locale & locale); virtual OUString SAL_CALL getWord() throw (uno::RuntimeException); virtual lang::Locale SAL_CALL getLocale() throw (uno::RuntimeException); virtual sal_Int16 SAL_CALL getFailureType() throw (uno::RuntimeException); virtual sal_Int16 SAL_CALL getAlternativesCount() throw (uno::RuntimeException); virtual uno::Sequence SAL_CALL getAlternatives() throw (uno::RuntimeException); }; } #endif libreoffice-voikko-4.0/src/spellchecker/SpellChecker.hxx0000644000000000000000000001074512245135610022162 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2009 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _SPELLCHECKER_HXX_ #define _SPELLCHECKER_HXX_ //#include "sal/config.h" #include #include #include #include #include #include #include #include #include "../PropertyManager.hxx" #include "../macros.hxx" using namespace ::com::sun::star; using namespace ::rtl; namespace voikko { class SpellChecker: private cppu::BaseMutex, public cppu::WeakComponentImplHelper5 { public: // ::com::sun::star::lang::XServiceInfo: virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL supportsService(const OUString & serviceName) throw (uno::RuntimeException); virtual uno::Sequence SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException); // ::com::sun::star::linguistic2::XSupportedLocales: virtual uno::Sequence SAL_CALL getLocales() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL hasLocale(const lang::Locale & aLocale) throw (uno::RuntimeException); // ::com::sun::star::linguistic2::XSpellChecker: virtual sal_Bool SAL_CALL isValid(const OUString & aWord, const lang::Locale & aLocale, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException); virtual uno::Reference SAL_CALL spell(const OUString & aWord, const lang::Locale & aLocale, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException); // ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster: virtual sal_Bool SAL_CALL addLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException); virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException); // ::com::sun::star::lang::XInitialization: virtual void SAL_CALL initialize(const uno::Sequence & aArguments) throw (uno::RuntimeException, uno::Exception); // ::com::sun::star::lang::XServiceDisplayName: virtual OUString SAL_CALL getServiceDisplayName(const lang::Locale & aLocale) throw (uno::RuntimeException); // Static methods static inline OUString SAL_CALL getImplementationName_static(); static inline uno::Sequence SAL_CALL getSupportedServiceNames_static(); static uno::Reference SAL_CALL get(uno::Reference const & context); private: explicit SpellChecker(uno::Reference const & context); virtual ~SpellChecker(); // SpellChecker(SpellChecker &); // not defined // void operator =(SpellChecker &); // not defined // overload WeakComponentImplHelperBase::disposing() // This function is called upon disposing the component, // if your component needs special work when it becomes // disposed, do it here. virtual void SAL_CALL disposing(); uno::Reference compContext; }; // Static method implementations inline OUString SAL_CALL SpellChecker::getImplementationName_static() { return A2OU("voikko.SpellChecker"); } inline uno::Sequence SAL_CALL SpellChecker::getSupportedServiceNames_static() { uno::Sequence snames(1); snames.getArray()[0] = A2OU("com.sun.star.linguistic2.SpellChecker"); return snames; } } #endif libreoffice-voikko-4.0/src/spellchecker/SpellChecker.cxx0000644000000000000000000001421312245135610022147 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include #include "SpellChecker.hxx" #include "SpellAlternatives.hxx" #include "../VoikkoHandlePool.hxx" #include "../common.hxx" namespace voikko { SpellChecker::SpellChecker(uno::Reference const & context) : cppu::WeakComponentImplHelper5 (m_aMutex), compContext(context) { VOIKKO_DEBUG("SpellChecker:CTOR"); PropertyManager::get(compContext); } OUString SAL_CALL SpellChecker::getImplementationName() throw (uno::RuntimeException) { return getImplementationName_static(); } sal_Bool SAL_CALL SpellChecker::supportsService(const OUString & serviceName) throw (uno::RuntimeException) { uno::Sequence serviceNames = getSupportedServiceNames(); for (sal_Int32 i = 0; i < serviceNames.getLength(); i++) if (serviceNames[i] == serviceName) return sal_True; return sal_False; } uno::Sequence SAL_CALL SpellChecker::getSupportedServiceNames() throw (uno::RuntimeException) { return getSupportedServiceNames_static(); } uno::Sequence SAL_CALL SpellChecker::getLocales() throw (uno::RuntimeException) { return VoikkoHandlePool::getInstance()->getSupportedSpellingLocales(); } sal_Bool SAL_CALL SpellChecker::hasLocale(const lang::Locale & aLocale) throw (uno::RuntimeException) { return VoikkoHandlePool::getInstance()->supportsSpellingLocale(aLocale); } sal_Bool SAL_CALL SpellChecker::isValid(const OUString & aWord, const lang::Locale & aLocale, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException) { osl::MutexGuard vmg(getVoikkoMutex()); VoikkoHandle * voikkoHandle = VoikkoHandlePool::getInstance()->getHandle(aLocale); if (!voikkoHandle) { return sal_False; } OString oWord = OUStringToOString(aWord, RTL_TEXTENCODING_UTF8); const char * c_str = oWord.getStr(); PropertyManager::get(compContext)->setValues(aProperties); // VOIKKO_DEBUG_2("SpellChecker::isValid: c_str: '%s'\n", c_str); int result = voikkoSpellCstr(voikkoHandle, c_str); // VOIKKO_DEBUG_2("SpellChecker::isValid: result = %i\n", result); PropertyManager::get(compContext)->resetValues(aProperties); if (result) return sal_True; else return sal_False; } uno::Reference SAL_CALL SpellChecker::spell( const OUString & aWord, const lang::Locale & aLocale, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException) { // Check if diagnostic message should be returned if (aWord.equals(A2OU("VoikkoGetStatusInformation"))) { uno::Sequence suggSeq(1); suggSeq.getArray()[0] = VoikkoHandlePool::getInstance()->getInitializationStatus(); return new SpellAlternatives(aWord, suggSeq, aLocale); } osl::MutexGuard vmg(getVoikkoMutex()); VoikkoHandle * handle = VoikkoHandlePool::getInstance()->getHandle(aLocale); if (!handle) { return 0; } OString oWord = OUStringToOString(aWord, RTL_TEXTENCODING_UTF8); const char * c_str = oWord.getStr(); PropertyManager::get(compContext)->setValues(aProperties); if (voikkoSpellCstr(handle, c_str)) { PropertyManager::get(compContext)->resetValues(aProperties); return 0; } char ** suggestions = voikkoSuggestCstr(handle, c_str); PropertyManager::get(compContext)->resetValues(aProperties); if (suggestions == 0 || suggestions[0] == 0) { return new SpellAlternatives(aWord, uno::Sequence(0), aLocale); } int scount = 0; while (suggestions[scount] != 0) scount++; uno::Sequence suggSeq(scount); OUString * suggStrings = suggSeq.getArray(); OString ostr; for (int i = 0; i < scount; i++) { ostr = OString(suggestions[i]); suggStrings[i] = OStringToOUString(ostr, RTL_TEXTENCODING_UTF8); } voikkoFreeCstrArray(suggestions); return new SpellAlternatives(aWord, suggSeq, aLocale); } sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException) { osl::MutexGuard vmg(getVoikkoMutex()); VOIKKO_DEBUG("SpellChecker::addLinguServiceEventListener"); return PropertyManager::get(compContext)->addLinguServiceEventListener(xLstnr); } sal_Bool SAL_CALL SpellChecker::removeLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException) { osl::MutexGuard vmg(getVoikkoMutex()); VOIKKO_DEBUG("SpellChecker::removeLinguServiceEventListener"); return PropertyManager::get(compContext)->removeLinguServiceEventListener(xLstnr); } void SAL_CALL SpellChecker::initialize(const uno::Sequence &) throw (uno::RuntimeException, uno::Exception) { } OUString SAL_CALL SpellChecker::getServiceDisplayName(const lang::Locale & aLocale) throw (uno::RuntimeException) { if (aLocale.Language == A2OU("fi")) return A2OU("Oikoluku (Voikko)"); else return A2OU("Spellchecker (Voikko)"); } static ::cppu::OWeakObject * theSpellChecker = 0; void SAL_CALL SpellChecker::disposing() { VOIKKO_DEBUG("SpellChecker:DISPOSING"); theSpellChecker = 0; } uno::Reference SAL_CALL SpellChecker::get(uno::Reference const & context) { VOIKKO_DEBUG("SpellChecker::get"); if (!theSpellChecker) { theSpellChecker = static_cast< ::cppu::OWeakObject * >(new SpellChecker(context)); } return theSpellChecker; } SpellChecker::~SpellChecker() { VOIKKO_DEBUG("SpellChecker:DTOR"); } } libreoffice-voikko-4.0/src/spellchecker/SpellAlternatives.cxx0000644000000000000000000000315512245135610023247 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2005 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include "SpellAlternatives.hxx" #include "../macros.hxx" namespace voikko { SpellAlternatives::SpellAlternatives(const OUString & word, uno::Sequence alternatives, const lang::Locale & locale) : word(word), alternatives(alternatives), locale(locale) { } OUString SAL_CALL SpellAlternatives::getWord() throw (uno::RuntimeException) { return word; } lang::Locale SAL_CALL SpellAlternatives::getLocale() throw (uno::RuntimeException) { return locale; } sal_Int16 SAL_CALL SpellAlternatives::getFailureType() throw (uno::RuntimeException) { // TODO: If Voikko supported specific failure types, we could use them here return linguistic2::SpellFailure::SPELLING_ERROR; } sal_Int16 SAL_CALL SpellAlternatives::getAlternativesCount() throw (uno::RuntimeException) { return static_cast(alternatives.getLength()); // Integer overflow is not possible } uno::Sequence SAL_CALL SpellAlternatives::getAlternatives() throw (uno::RuntimeException) { return alternatives; } } libreoffice-voikko-4.0/src/VoikkoHandlePool.hxx0000644000000000000000000000564612245135610020366 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _VOIKKOHANDLEPOOL_HXX_ #define _VOIKKOHANDLEPOOL_HXX_ #include #include #include #include #include namespace voikko { //using namespace ::rtl; using namespace ::com::sun::star; class VoikkoHandlePool { public: static VoikkoHandlePool * getInstance(); VoikkoHandle * getHandle(const lang::Locale & locale); void closeAllHandles(); void setGlobalBooleanOption(int option, bool value); void setGlobalIntegerOption(int option, int value); /** * Set the preferred dictionary variant (private use tag) that * will be used for all languages. If the specified variant is not * available for given language then standard variant is used * as a fallback. */ void setPreferredGlobalVariant(const rtl::OUString & variant); void setInstallationPath(const rtl::OString & path); const char * getInstallationPath(); rtl::OUString getPreferredGlobalVariant(); uno::Sequence getSupportedSpellingLocales(); uno::Sequence getSupportedHyphenationLocales(); uno::Sequence getSupportedGrammarLocales(); bool supportsSpellingLocale(const lang::Locale & locale); bool supportsHyphenationLocale(const lang::Locale & locale); bool supportsGrammarLocale(const lang::Locale & locale); /** Returns initialization status diagnostics */ rtl::OUString getInitializationStatus(); private: VoikkoHandlePool(); VoikkoHandle * openHandle(const rtl::OString & language); VoikkoHandle * openHandleWithVariant(const rtl::OString & language, const rtl::OString & fullVariant); void addLocale(uno::Sequence & locales, const char * language); std::map handles; std::map initializationErrors; std::map globalBooleanOptions; std::map globalIntegerOptions; std::multimap > bcpToOOoMap; uno::Sequence supportedSpellingLocales; uno::Sequence supportedHyphenationLocales; uno::Sequence supportedGrammarCheckingLocales; rtl::OUString preferredGlobalVariant; rtl::OString installationPath; static VoikkoHandlePool * instance; }; } #endif libreoffice-voikko-4.0/src/VoikkoHandlePool.cxx0000644000000000000000000002662312245135610020357 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2010 - 2012 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include "VoikkoHandlePool.hxx" #include "common.hxx" #include "macros.hxx" namespace voikko { using namespace std; using namespace ::rtl; using namespace ::com::sun::star; struct Bcp47ToOOoMapping { const char * bcpTag; const char * oooLanguage; const char * oooRegion; }; static Bcp47ToOOoMapping const bcpToOOoMapping[] = { {"af", "af", "NA"}, {"af", "af", "ZA"}, {"am", "am", "ET"}, {"ar", "ar", "AE"}, {"ar", "ar", "BH"}, {"ar", "ar", "DJ"}, {"ar", "ar", "DZ"}, {"ar", "ar", "EG"}, {"ar", "ar", "ER"}, {"ar", "ar", "IL"}, {"ar", "ar", "IQ"}, {"ar", "ar", "JO"}, {"ar", "ar", "KM"}, {"ar", "ar", "KW"}, {"ar", "ar", "LB"}, {"ar", "ar", "LY"}, {"ar", "ar", "MA"}, {"ar", "ar", "MR"}, {"ar", "ar", "OM"}, {"ar", "ar", "PS"}, {"ar", "ar", "QA"}, {"ar", "ar", "SA"}, {"ar", "ar", "SD"}, {"ar", "ar", "SO"}, {"ar", "ar", "SY"}, {"ar", "ar", "TD"}, {"ar", "ar", "TN"}, {"ar", "ar", "YE"}, {"bn", "bn", "BD"}, {"bn", "bn", "IN"}, {"ca", "ca", "AD"}, {"ca", "ca", "ES"}, {"cs", "cs", "CZ"}, {"csb", "csb", "PL"}, {"cv", "cv", "RU"}, {"cy", "cy", "GB"}, {"da", "da", "DK"}, {"de", "de", "DE"}, {"de-AT", "de", "AT"}, {"de-BE", "de", "BE"}, {"de-CH", "de", "CH"}, {"de-LU", "de", "LU"}, {"el", "el", "GR"}, {"en-US", "en", "US"}, {"en-US", "en", "ZA"}, {"eo", "eo", ""}, {"es", "es", "ES"}, {"es-MX", "es", "MX"}, {"et", "et", "EE"}, {"eu", "eu", ""}, {"fa", "fa", "IR"}, {"fi", "fi", "FI"}, {"fo", "fo", "FO"}, {"fr", "fr", "FR"}, {"fr-BE", "fr", "BE"}, {"fr-CA", "fr", "CA"}, {"fr-CH", "fr", "CH"}, {"fr-LU", "fr", "LU"}, {"fr-MC", "fr", "MC"}, {"fur", "fur", "IT"}, {"fy", "fy", "NL"}, {"ga", "ga", "IE"}, {"gd", "gd", "GB"}, {"gl", "gl", "ES"}, {"gn", "gug", "PY"}, {"gu", "gu", "IN"}, {"he", "he", "IL"}, {"hi", "hi", "IN"}, {"hr", "hr", "BA"}, {"hr", "hr", "HR"}, {"hu", "hu", "HU"}, {"ia", "ia", ""}, {"id", "id", "ID"}, {"is", "is", "IS"}, {"it", "it", "CH"}, {"it", "it", "IT"}, {"kca", "kca", "RU"}, {"kk", "kk", "KZ"}, {"kl", "kl", "GL"}, {"koi", "koi", "RU"}, {"kpv", "kpv", "RU"}, {"ku", "ku", "TR"}, {"ku", "ku", "SY"}, {"kum", "kum", "RU"}, {"ky", "ky", "CN"}, {"ky", "ky", "KG"}, {"la", "la", "VA"}, {"liv", "liv", "LV"}, {"liv", "liv", "RU"}, {"ln", "ln", "CD"}, {"lt", "lt", "LT"}, {"lv", "lv", "LV"}, {"mdf", "mdf", "RU"}, {"mhr", "mhr", "RU"}, {"mk", "mk", "MK"}, {"ml", "ml", "IN"}, {"mrj", "mrj", "RU"}, {"ms", "ms", ""}, {"ms", "ms", "BN"}, {"ms", "ms", "MY"}, {"myv", "myv", "RU"}, {"nb", "nb", "NO"}, {"ne", "ne", "IN"}, {"ne", "ne", "NP"}, {"nio", "nio", "RU"}, {"nl", "nl", "BE"}, {"nl", "nl", "NL"}, {"nn", "nn", "NO"}, {"nog", "nog", "RU"}, {"nr", "nr", "ZA"}, {"nso", "ns", "ZA"}, {"nso", "nso", "ZA"}, {"ny", "ny", "MW"}, {"oc", "oc", "FR"}, {"olo", "olo", "RU"}, {"or", "or", "IN"}, {"pa", "pa", "IN"}, {"pa", "pa", "PK"}, {"pap-BQ", "pap", "BQ"}, {"pap-CW", "pap", "CW"}, {"pjt", "pjt", "AU"}, {"pl", "pl", "PL"}, {"pt", "pt", "PT"}, {"pt-BR", "pt", "BR"}, {"qu", "qu", "BO"}, {"qu", "qu", "EC"}, {"qu", "qu", "PE"}, {"ro", "ro", "MD"}, {"ro", "ro", "RO"}, {"ru", "ru", "RU"}, {"rw", "rw", "RW"}, {"se", "se", "FI"}, {"se", "se", "NO"}, {"se", "se", "SE"}, {"sid", "sid", "ET"}, {"sjd", "sjd", "RU"}, {"sk", "sk", "SK"}, {"sl", "sl", "SI"}, {"sma", "sma", "NO"}, {"sma", "sma", "SE"}, {"smj", "smj", "NO"}, {"smj", "smj", "SE"}, {"smn", "smn", "FI"}, {"sms", "sms", "FI"}, {"ss", "ss", "ZA"}, {"st", "st", "ZA"}, {"sv", "sv", "FI"}, {"sv", "sv", "SE"}, {"sw", "sw", "KE"}, {"sw", "sw", "TZ"}, {"ta", "ta", "IN"}, {"tet", "tet", "ID"}, {"tet", "tet", "TL"}, {"tl", "tl", "PH"}, {"tn", "tn", "BW"}, {"tn", "tn", "ZA"}, {"ts", "ts", "ZA"}, {"tt", "tt", "RU"}, {"udm", "udm", "RU"}, {"uk", "uk", "UA"}, {"vep", "vep", "RU"}, {"vi", "vi", "VN"}, {"vro", "vro", "EE"}, {"xh", "xh", "ZA"}, {"yrk", "yrk", "RU"}, {0, 0, 0} }; VoikkoHandlePool::VoikkoHandlePool() { for (const Bcp47ToOOoMapping * m = bcpToOOoMapping; m->bcpTag; ++m) { bcpToOOoMap.insert(pair >(m->bcpTag, pair(m->oooLanguage, m->oooRegion))); } } VoikkoHandlePool * VoikkoHandlePool::getInstance() { if (!instance) { instance = new VoikkoHandlePool(); } return instance; } const char * VoikkoHandlePool::getInstallationPath() { if (installationPath.getLength() == 0) { return 0; } else { return installationPath.getStr(); } } VoikkoHandle * VoikkoHandlePool::openHandleWithVariant(const OString & language, const OString & fullVariant) { const char * errorString = 0; VOIKKO_DEBUG("VoikkoHandlePool::openHandleWithVariant"); VoikkoHandle * voikkoHandle = voikkoInit(&errorString, fullVariant.getStr(), getInstallationPath()); if (voikkoHandle) { handles[language] = voikkoHandle; for (map::const_iterator it = globalBooleanOptions.begin(); it != globalBooleanOptions.end(); ++it) { voikkoSetBooleanOption(voikkoHandle, it->first, it->second ? 1 : 0); } for (map::const_iterator it = globalIntegerOptions.begin(); it != globalIntegerOptions.end(); ++it) { voikkoSetIntegerOption(voikkoHandle, it->first, it->second); } return voikkoHandle; } else { initializationErrors[language] = errorString; return 0; } } VoikkoHandle * VoikkoHandlePool::openHandle(const OString & language) { if (getPreferredGlobalVariant().getLength() > 0) { OString languageWithVariant = language + OString("-x-") + OUStringToOString(getPreferredGlobalVariant(), RTL_TEXTENCODING_UTF8); VoikkoHandle * handle = openHandleWithVariant(language, languageWithVariant); if (handle) { return handle; } } return openHandleWithVariant(language, language); } VoikkoHandle * VoikkoHandlePool::getHandle(const lang::Locale & locale) { OString language = OUStringToOString(locale.Language, RTL_TEXTENCODING_UTF8); if (handles.find(language) != handles.end()) { return handles[language]; } if (initializationErrors.find(language) != initializationErrors.end()) { return 0; } return openHandle(language); } void VoikkoHandlePool::closeAllHandles() { for (map::const_iterator it = handles.begin(); it != handles.end(); ++it) { voikkoTerminate(it->second); } handles.clear(); initializationErrors.clear(); } void VoikkoHandlePool::setGlobalBooleanOption(int option, bool value) { if (globalBooleanOptions.find(option) != globalBooleanOptions.end() && globalBooleanOptions[option] == value) { return; } globalBooleanOptions[option] = value; for (map::const_iterator it = handles.begin(); it != handles.end(); ++it) { voikkoSetBooleanOption(it->second, option, value ? 1 : 0); } } void VoikkoHandlePool::setGlobalIntegerOption(int option, int value) { if (globalIntegerOptions.find(option) != globalIntegerOptions.end() && globalIntegerOptions[option] == value) { return; } globalIntegerOptions[option] = value; for (map::const_iterator it = handles.begin(); it != handles.end(); ++it) { voikkoSetIntegerOption(it->second, option, value); } } void VoikkoHandlePool::addLocale(uno::Sequence & locales, const char * language) { // TODO: n^2 performance because sequence is reconstructed on every add sal_Int32 position = locales.getLength(); pair >::iterator, multimap >::iterator> matchingLangs = bcpToOOoMap.equal_range(language); for (multimap >::iterator it = matchingLangs.first; it != matchingLangs.second; ++it) { locales.realloc(++position); OUString lang = A2OU((*it).second.first.c_str()); OUString region = A2OU((*it).second.second.c_str()); locales.getArray()[position - 1] = lang::Locale(lang, region, OUString()); } } uno::Sequence VoikkoHandlePool::getSupportedSpellingLocales() { // optimization: if we already have found some locales, don't search for more if (supportedSpellingLocales.getLength() == 0) { char ** languages = voikkoListSupportedSpellingLanguages(getInstallationPath()); for (char ** i = languages; *i; i++) { addLocale(supportedSpellingLocales, *i); } voikkoFreeCstrArray(languages); } return supportedSpellingLocales; } uno::Sequence VoikkoHandlePool::getSupportedHyphenationLocales() { // optimization: if we already have found some locales, don't search for more if (supportedHyphenationLocales.getLength() == 0) { char ** languages = voikkoListSupportedHyphenationLanguages(getInstallationPath()); for (char ** i = languages; *i; i++) { addLocale(supportedHyphenationLocales, *i); } voikkoFreeCstrArray(languages); } return supportedHyphenationLocales; } uno::Sequence VoikkoHandlePool::getSupportedGrammarLocales() { // optimization: if we already have found some locales, don't search for more if (supportedGrammarCheckingLocales.getLength() == 0) { char ** languages = voikkoListSupportedGrammarCheckingLanguages(getInstallationPath()); for (char ** i = languages; *i; i++) { addLocale(supportedGrammarCheckingLocales, *i); } voikkoFreeCstrArray(languages); } return supportedGrammarCheckingLocales; } OUString VoikkoHandlePool::getInitializationStatus() { OUString status = A2OU("Init OK:["); for (map::const_iterator it = handles.begin(); it != handles.end(); ++it) { status += OStringToOUString(it->first, RTL_TEXTENCODING_UTF8) + A2OU(" "); } status += A2OU("] FAILED:["); for (map::const_iterator it = initializationErrors.begin(); it != initializationErrors.end(); ++it) { status += OStringToOUString(it->first, RTL_TEXTENCODING_UTF8) + A2OU(":'") + A2OU(it->second) + A2OU("' "); } status += A2OU("]"); return status; } void VoikkoHandlePool::setPreferredGlobalVariant(const OUString & variant) { if (variant != this->preferredGlobalVariant) { this->preferredGlobalVariant = variant; closeAllHandles(); } } void VoikkoHandlePool::setInstallationPath(const rtl::OString & path) { this->installationPath = path; } OUString VoikkoHandlePool::getPreferredGlobalVariant() { return this->preferredGlobalVariant; } static bool containsLocale(const lang::Locale & localeToFind, const uno::Sequence & locales) { for (sal_Int32 i = 0; i < locales.getLength(); i++) { if (locales[i].Language == localeToFind.Language && locales[i].Country == localeToFind.Country) { return true; } } return false; } bool VoikkoHandlePool::supportsSpellingLocale(const lang::Locale & locale) { return containsLocale(locale, getSupportedSpellingLocales()); } bool VoikkoHandlePool::supportsHyphenationLocale(const lang::Locale & locale) { return containsLocale(locale, getSupportedHyphenationLocales()); } bool VoikkoHandlePool::supportsGrammarLocale(const lang::Locale & locale) { return containsLocale(locale, getSupportedGrammarLocales()); } VoikkoHandlePool * VoikkoHandlePool::instance = 0; } libreoffice-voikko-4.0/src/macros.hxx0000644000000000000000000000224712245135610016434 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2005 - 2009 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _MACROS_HXX_ #define _MACROS_HXX_ #include // Conversions #define A2OU(x) ::rtl::OUString::createFromAscii(x) #define UTF82OU(x) ::rtl::OStringToOUString(::rtl::OString(x), RTL_TEXTENCODING_UTF8) #define OU2DEBUG(x) ::rtl::OUStringToOString((x), RTL_TEXTENCODING_UTF8).getStr() // Debug macros #ifdef VOIKKO_DEBUG_OUTPUT #define VOIKKO_DEBUG(x) fprintf(stderr, "VOIKKO_DEBUG: " x "\n") #define VOIKKO_DEBUG_2(x, y) fprintf(stderr, "VOIKKO_DEBUG: " x "\n", y) #else #define VOIKKO_DEBUG(x) #define VOIKKO_DEBUG_2(x, y) #endif #endif libreoffice-voikko-4.0/src/common.cxx0000644000000000000000000000503012245135610016424 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include #include #include #include #include #include #include "common.hxx" #include "macros.hxx" using namespace rtl; namespace voikko { osl::Mutex & getVoikkoMutex() { static osl::Mutex voikkoMutex; return voikkoMutex; } uno::Reference getRegistryProperties(const OUString & group, uno::Reference compContext) { VOIKKO_DEBUG("getRegistryProperties"); uno::Reference rootView; uno::Reference servManager = compContext->getServiceManager(); if (!servManager.is()) { VOIKKO_DEBUG("ERROR: failed to obtain servManager"); return rootView; } uno::Reference iFace = servManager->createInstanceWithContext( A2OU("com.sun.star.configuration.ConfigurationProvider"), compContext); if (!iFace.is()) { VOIKKO_DEBUG("ERROR: failed to obtain iFace"); return rootView; } uno::Reference provider(iFace, uno::UNO_QUERY); if (!provider.is()) { VOIKKO_DEBUG("ERROR: failed to obtain provider"); return rootView; } beans::PropertyValue pathArgument(A2OU("nodepath"), 0, (uno::Any) group, beans::PropertyState_DIRECT_VALUE); uno::Sequence aArguments(1); aArguments.getArray()[0] = (uno::Any) pathArgument; try { // FIXME: this may crash if configuration is damaged rootView = provider->createInstanceWithArguments( A2OU("com.sun.star.configuration.ConfigurationUpdateAccess"), aArguments); } catch (uno::Exception e) { VOIKKO_DEBUG_2("ERROR: exception while trying to obtain rootView for '%s'", OU2DEBUG(group)); return rootView; } if (!rootView.is()) { VOIKKO_DEBUG("ERROR: failed to obtain rootView"); } return rootView; } } libreoffice-voikko-4.0/src/PropertyManager.hxx0000644000000000000000000000710612245135610020266 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2007 - 2009 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _PROPERTYMANAGER_HXX_ #define _PROPERTYMANAGER_HXX_ #include #include #include #include #include #include #include #include "macros.hxx" namespace voikko { using namespace ::com::sun::star; using namespace ::rtl; class PropertyManager: public cppu::WeakImplHelper1 { public: // XPropertyChangeListener virtual void SAL_CALL propertyChange(const beans::PropertyChangeEvent & pce) throw (uno::RuntimeException); // XEventListener virtual void SAL_CALL disposing(const lang::EventObject & source) throw (uno::RuntimeException); void initialize() throw (uno::Exception); // Functions to be used by the linguistic tool implementations sal_Int16 getHyphMinLeading(); sal_Int16 getHyphMinTrailing(); sal_Int16 getHyphMinWordLength(); sal_Bool addLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException); sal_Bool removeLinguServiceEventListener( const uno::Reference & xLstnr) throw (uno::RuntimeException); void setValues(const uno::Sequence & values); void resetValues(const uno::Sequence & values); // Functions for setting Voikko specific configuration void setHyphWordParts(sal_Bool value); uno::Any readFromRegistry(const OUString group, const OUString & key) throw (beans::UnknownPropertyException); void readVoikkoSettings(); /** Returns the language code for user messages */ const char * getMessageLanguage(); /** Reload Voikko specific settings after they have been changed in the settings dialog. */ void reloadVoikkoSettings(); /** Returns the singleton instance of this object */ static uno::Reference get(uno::Reference const & context); private: explicit PropertyManager(uno::Reference cContext); virtual ~PropertyManager(); void setUiLanguage(); void setProperties(const uno::Reference & properties); void setValue(const beans::PropertyValue & value); void syncHyphenatorSettings(); void sendLinguEvent(const linguistic2::LinguServiceEvent & event); uno::Reference linguPropSet; uno::Reference compContext; ::cppu::OInterfaceContainerHelper linguEventListeners; // Active values sal_Int16 hyphMinLeading; sal_Int16 hyphMinTrailing; sal_Int16 hyphMinWordLength; sal_Bool hyphWordParts; sal_Bool hyphUnknownWords; /** Error message from libvoikko initialization function */ const char * voikkoErrorString; /** Language code for user messages */ const char * messageLanguage; }; } #endif libreoffice-voikko-4.0/src/grammar/0000755000000000000000000000000012245135610016040 5ustar rootrootlibreoffice-voikko-4.0/src/grammar/GrammarChecker.hxx0000644000000000000000000001006712245135610021450 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2008 - 2010 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #ifndef _GRAMMARCHECKER_HXX_ #define _GRAMMARCHECKER_HXX_ #include #include #include #include #include #include #include #include #include #include "../macros.hxx" using namespace ::com::sun::star; using namespace ::rtl; namespace voikko { class GrammarChecker: private cppu::BaseMutex, public cppu::WeakComponentImplHelper4 { public: // ::com::sun::star::lang::XServiceInfo: virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL supportsService(const OUString & serviceName) throw (uno::RuntimeException); virtual uno::Sequence SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException); // linguistic2::XSupportedLocales: virtual uno::Sequence SAL_CALL getLocales() throw (uno::RuntimeException); virtual sal_Bool SAL_CALL hasLocale(const lang::Locale & aLocale) throw (uno::RuntimeException); // linguistic2::XProofreader: virtual sal_Bool SAL_CALL isSpellChecker() throw (uno::RuntimeException); virtual linguistic2::ProofreadingResult SAL_CALL doProofreading( const OUString & aDocumentIdentifier, const OUString & aText, const lang::Locale & aLocale, sal_Int32 nStartOfSentencePos, sal_Int32 nSuggestedBehindEndOfSentencePosition, const uno::Sequence & aProperties) throw (uno::RuntimeException, lang::IllegalArgumentException); virtual void SAL_CALL ignoreRule(const OUString & aRuleIdentifier, const lang::Locale & aLocale) throw (lang::IllegalArgumentException, uno::RuntimeException); virtual void SAL_CALL resetIgnoreRules() throw (uno::RuntimeException); // ::com::sun::star::lang::XInitialization: virtual void SAL_CALL initialize(const uno::Sequence & aArguments) throw (uno::RuntimeException, uno::Exception); // ::com::sun::star::lang::XServiceDisplayName: virtual OUString SAL_CALL getServiceDisplayName(const lang::Locale & aLocale) throw (uno::RuntimeException); // Static methods static inline OUString SAL_CALL getImplementationName_static(); static inline uno::Sequence SAL_CALL getSupportedServiceNames_static(); static uno::Reference SAL_CALL get(uno::Reference const & context); private: explicit GrammarChecker(uno::Reference const & context); virtual ~GrammarChecker(); virtual void SAL_CALL disposing(); uno::Reference compContext; /** Grammar checker error codes that should be ignored */ std::set ignoredErrors; }; // Static method implementations inline OUString SAL_CALL GrammarChecker::getImplementationName_static() { VOIKKO_DEBUG("GrammarChecker::getImplementationName_static"); return A2OU("voikko.GrammarChecker"); } inline uno::Sequence SAL_CALL GrammarChecker::getSupportedServiceNames_static() { uno::Sequence snames(1); VOIKKO_DEBUG("GrammarChecker::getSupportedServiceNames_static"); snames.getArray()[0] = A2OU("com.sun.star.linguistic2.Proofreader"); return snames; } } #endif libreoffice-voikko-4.0/src/grammar/GrammarChecker.cxx0000644000000000000000000001716112245135610021445 0ustar rootroot/* Libreoffice-voikko: Linguistic extension for LibreOffice * Copyright (C) 2008 - 2013 Harri Pitkänen * * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 3 or later (the "GPL"), in which * case the provisions of the GPL are applicable instead of those above. ******************************************************************************/ #include #include #include "GrammarChecker.hxx" #include "../PropertyManager.hxx" #include "../VoikkoHandlePool.hxx" #include "../common.hxx" namespace voikko { GrammarChecker::GrammarChecker(uno::Reference const & context) : cppu::WeakComponentImplHelper4 (m_aMutex), compContext(context), ignoredErrors() { VOIKKO_DEBUG("GrammarChecker:CTOR"); PropertyManager::get(compContext); } OUString SAL_CALL GrammarChecker::getImplementationName() throw (uno::RuntimeException) { return getImplementationName_static(); } sal_Bool SAL_CALL GrammarChecker::supportsService(const OUString & serviceName) throw (uno::RuntimeException) { VOIKKO_DEBUG("GrammarChecker::supportsService"); uno::Sequence serviceNames = getSupportedServiceNames(); for (sal_Int32 i = 0; i < serviceNames.getLength(); i++) if (serviceNames[i] == serviceName) return sal_True; return sal_False; } uno::Sequence SAL_CALL GrammarChecker::getSupportedServiceNames() throw (uno::RuntimeException) { VOIKKO_DEBUG("GrammarChecker::getSupportedServiceNames"); return getSupportedServiceNames_static(); } uno::Sequence SAL_CALL GrammarChecker::getLocales() throw (uno::RuntimeException) { VOIKKO_DEBUG("GrammarChecker::getLocales"); return VoikkoHandlePool::getInstance()->getSupportedGrammarLocales(); } sal_Bool SAL_CALL GrammarChecker::hasLocale(const lang::Locale & aLocale) throw (uno::RuntimeException) { VOIKKO_DEBUG("GrammarChecker::hasLocale"); return VoikkoHandlePool::getInstance()->supportsGrammarLocale(aLocale); } sal_Bool SAL_CALL GrammarChecker::isSpellChecker() throw (uno::RuntimeException) { return sal_False; } linguistic2::ProofreadingResult SAL_CALL GrammarChecker::doProofreading( const OUString & aDocumentIdentifier, const OUString & aText, const lang::Locale & aLocale, sal_Int32 nStartOfSentencePos, sal_Int32 nSuggestedBehindEndOfSentencePosition, const uno::Sequence & /* aProperties */) throw (uno::RuntimeException, lang::IllegalArgumentException) { VOIKKO_DEBUG("GrammarChecker::doProofreading"); linguistic2::ProofreadingResult result; result.aDocumentIdentifier = aDocumentIdentifier; result.xFlatParagraph = 0; result.aText = aText; result.aLocale = aLocale; result.nStartOfSentencePosition = nStartOfSentencePos; result.nBehindEndOfSentencePosition = nSuggestedBehindEndOfSentencePosition; result.xProofreader = this; VoikkoHandle * voikkoHandle = VoikkoHandlePool::getInstance()->getHandle(aLocale); if (!voikkoHandle) { VOIKKO_DEBUG("ERROR: GrammarChecker::doProofreading called without initializing libvoikko"); return result; } OString textUtf8 = ::rtl::OUStringToOString(aText, RTL_TEXTENCODING_UTF8); sal_Int32 paraLen = textUtf8.getLength(); if (paraLen <= 0) return result; uno::Sequence gcErrors(0); sal_Int32 gcI = 0; sal_Int32 vErrorCount = 0; while (paraLen < 1000000) { // sanity check VoikkoGrammarError * vError = voikkoNextGrammarErrorCstr( voikkoHandle, textUtf8.getStr(), paraLen, 0, vErrorCount++); if (!vError) { break; } size_t startPos = voikkoGetGrammarErrorStartPos(vError); size_t errorLength = voikkoGetGrammarErrorLength(vError); if ((sal_Int32) startPos < result.nStartOfSentencePosition) { voikkoFreeGrammarError(vError); continue; } if ((sal_Int32) startPos >= result.nBehindEndOfSentencePosition) { voikkoFreeGrammarError(vError); break; } if ((sal_Int32) (startPos + errorLength) > result.nBehindEndOfSentencePosition) { result.nBehindEndOfSentencePosition = startPos + errorLength; } // we have a real grammar error int errorCode = voikkoGetGrammarErrorCode(vError); OUString ruleIdentifier = OUString::number(errorCode, 10); if (ignoredErrors.count(ruleIdentifier) == 1) { // ignore this error voikkoFreeGrammarError(vError); continue; } const char ** suggestions = voikkoGetGrammarErrorSuggestions(vError); gcErrors.realloc(gcI + 1); gcErrors[gcI].nErrorStart = startPos; gcErrors[gcI].nErrorLength = errorLength; gcErrors[gcI].nErrorType = text::TextMarkupType::PROOFREADING; char * errorShortDescription = voikkoGetGrammarErrorShortDescription(vError, PropertyManager::get(compContext)->getMessageLanguage()); OString commentOString = OString(errorShortDescription); voikkoFreeErrorMessageCstr(errorShortDescription); OUString comment = OStringToOUString(commentOString, RTL_TEXTENCODING_UTF8); #ifdef TEKSTINTUHO comment += UTF82OU(" TEKSTINTUHO K\xc3\x84YT\xc3\x96SS\xc3\x84!"); #endif gcErrors[gcI].aShortComment = comment; gcErrors[gcI].aFullComment = comment; gcErrors[gcI].aRuleIdentifier = ruleIdentifier; beans::PropertyValue detailUrl; detailUrl.Name = A2OU("FullCommentURL"); uno::Any aDetailUrl; OUString sDetailUrl = A2OU("http://voikko.puimula.org/gchelp/fi/") + ruleIdentifier + A2OU(".html"); aDetailUrl <<= sDetailUrl; detailUrl.Value = aDetailUrl; uno::Sequence urlSequence(1); urlSequence[0] = detailUrl; gcErrors[gcI].aProperties = urlSequence; // add suggestions if (suggestions) { int scount = 0; while (suggestions[scount] != 0) { scount++; } uno::Sequence suggSeq(scount); for (int i = 0; i < scount; i++) { OString ostr = OString(suggestions[i]); suggSeq[i] = OStringToOUString(ostr, RTL_TEXTENCODING_UTF8); } gcErrors[gcI].aSuggestions = suggSeq; } voikkoFreeGrammarError(vError); gcI++; } result.aErrors = gcErrors; result.nStartOfNextSentencePosition = result.nBehindEndOfSentencePosition; return result; } void SAL_CALL GrammarChecker::ignoreRule(const OUString & aRuleIdentifier, const lang::Locale & /* aLocale */) throw (lang::IllegalArgumentException, uno::RuntimeException) { ignoredErrors.insert(aRuleIdentifier); } void SAL_CALL GrammarChecker::resetIgnoreRules() throw (uno::RuntimeException) { ignoredErrors.clear(); } void SAL_CALL GrammarChecker::initialize(const uno::Sequence &) throw (uno::RuntimeException, uno::Exception) { } OUString SAL_CALL GrammarChecker::getServiceDisplayName(const lang::Locale & aLocale) throw (uno::RuntimeException) { VOIKKO_DEBUG("GrammarChecker::getServiceDisplayName"); if (aLocale.Language == A2OU("fi")) return A2OU("Kieliopin tarkistus (Voikko)"); else return A2OU("Grammar checker (Voikko)"); } static ::cppu::OWeakObject * theGrammarChecker = 0; void SAL_CALL GrammarChecker::disposing() { VOIKKO_DEBUG("GrammarChecker:DISPOSING"); theGrammarChecker = 0; } uno::Reference SAL_CALL GrammarChecker::get(uno::Reference const & context) { VOIKKO_DEBUG("GrammarChecker::get"); if (!theGrammarChecker) { theGrammarChecker = static_cast< ::cppu::OWeakObject * >(new GrammarChecker(context)); } return theGrammarChecker; } GrammarChecker::~GrammarChecker() { VOIKKO_DEBUG("GrammarChecker:DTOR"); } } libreoffice-voikko-4.0/COPYING0000644000000000000000000004052612245135610014665 0ustar rootrootMozilla Public License Version 2.0 ================================== 1. Definitions -------------- 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. 1.3. "Contribution" means Covered Software of a particular Contributor. 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. 1.5. "Incompatible With Secondary Licenses" means (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. 1.6. "Executable Form" means any form of the work other than Source Code Form. 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 1.8. "License" means this document. 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. 1.10. "Modifications" means any of the following: (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or (b) any new file in Source Code Form that contains any Covered Software. 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. 1.13. "Source Code Form" means the form of the work preferred for making modifications. 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. License Grants and Conditions -------------------------------- 2.1. Grants Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. 2.2. Effective Date The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. 2.3. Limitations on Grant Scope The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: (a) for any code that a Contributor has removed from Covered Software; or (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). 2.4. Subsequent Licenses No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). 2.5. Representation Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. 2.6. Fair Use This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. 2.7. Conditions Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. 3. Responsibilities ------------------- 3.1. Distribution of Source Form All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. 3.2. Distribution of Executable Form If You distribute Covered Software in Executable Form then: (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. 3.3. Distribution of a Larger Work You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). 3.4. Notices You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. 3.5. Application of Additional Terms You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. 4. Inability to Comply Due to Statute or Regulation --------------------------------------------------- If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 5. Termination -------------- 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. ************************************************************************ * * * 6. Disclaimer of Warranty * * ------------------------- * * * * Covered Software is provided under this License on an "as is" * * basis, without warranty of any kind, either expressed, implied, or * * statutory, including, without limitation, warranties that the * * Covered Software is free of defects, merchantable, fit for a * * particular purpose or non-infringing. The entire risk as to the * * quality and performance of the Covered Software is with You. * * Should any Covered Software prove defective in any respect, You * * (not any Contributor) assume the cost of any necessary servicing, * * repair, or correction. This disclaimer of warranty constitutes an * * essential part of this License. No use of any Covered Software is * * authorized under this License except under this disclaimer. * * * ************************************************************************ ************************************************************************ * * * 7. Limitation of Liability * * -------------------------- * * * * Under no circumstances and under no legal theory, whether tort * * (including negligence), contract, or otherwise, shall any * * Contributor, or anyone who distributes Covered Software as * * permitted above, be liable to You for any direct, indirect, * * special, incidental, or consequential damages of any character * * including, without limitation, damages for lost profits, loss of * * goodwill, work stoppage, computer failure or malfunction, or any * * and all other commercial damages or losses, even if such party * * shall have been informed of the possibility of such damages. This * * limitation of liability shall not apply to liability for death or * * personal injury resulting from such party's negligence to the * * extent applicable law prohibits such limitation. Some * * jurisdictions do not allow the exclusion or limitation of * * incidental or consequential damages, so this exclusion and * * limitation may not apply to You. * * * ************************************************************************ 8. Litigation ------------- Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. 9. Miscellaneous ---------------- This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. 10. Versions of the License --------------------------- 10.1. New Versions Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. 10.2. Effect of New Versions You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. 10.3. Modified Versions If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice ------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. You may add additional accurate notices of copyright ownership. Exhibit B - "Incompatible With Secondary Licenses" Notice --------------------------------------------------------- This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. libreoffice-voikko-4.0/Makefile0000644000000000000000000002306312245135610015267 0ustar rootroot# Libreoffice-voikko: Linguistic extension for LibreOffice # Copyright (C) 2005 - 2013 Harri Pitkänen # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at http://mozilla.org/MPL/2.0/. # # Alternatively, the contents of this file may be used under the terms of # the GNU General Public License Version 3 or later (the "GPL"), in which # case the provisions of the GPL are applicable instead of those above. ############################################################################### # Check that build environment is properly set up ifndef OO_SDK_HOME $(error You must run setsdkenv before running make) endif PRJ=$(OO_SDK_HOME) # Load SDK settings include $(PRJ)/settings/settings.mk include $(PRJ)/settings/std.mk # ===== Build settings ===== # Version number of the libreoffice-voikko extension VOIKKO_VERSION=4.0 # VOIKKO_DEBUG controls the amount of debugging information in the resulting UNO # package. Possible values are NO (creates an optimized build without any # debugging information), LOG (creates an optimized build with runtime debug # logging) and FULL (creates a build with full debugging symbols and logging). VOIKKO_DEBUG=NO # If you have installed libvoikko to some non-standard location, uncomment the # following and adjust the path accordingly. For OS X this must be set if # a standalone extension is to be built. # LIBVOIKKO_PATH=/usr/local/voikko # LIBVOIKKO_PATH=c:/voikko # LIBVOIKKO_PATH=/Users/paakayttaja/voikko # If you want to have all of the library and dictionary files included within # the extension package, uncomment the following and adjust the path to point # to a directory containing the required files. # STANDALONE_EXTENSION_PATH=extras # STANDALONE_EXTENSION_PATH=/Users/paakayttaja/voikko/lib/voikko # If you want to have a license text to be displayed upon the installation # of this extension, uncomment the following. # SHOW_LICENSE=1 # If you want to enable the grammar checker, set this option to 1 ENABLE_GRAMMAR_CHECKER=1 # Setting this option to 1 causes ugly warnings to be added to visible places # in the extension without removing any functionality (codename "tekstintuho"). # Useful for binary builds that are released for public testing. # SHOW_UGLY_WARNINGS=1 # Destination directory when installing unpacked extension with # make install-unpacked DESTDIR=/usr/lib/libreoffice-voikko # === End build settings === # Platform specific variables ifeq "$(PLATFORM)" "windows" WARNING_FLAGS=-Wall -WX -wd4061 -wd4127 -wd4265 -wd4365 -wd4514 -wd4619 -wd4625 -wd4626 -wd4668 -wd4710 -wd4711 -wd4820 # The following warnings should be fixed in the future WARNING_FLAGS+= -wd4640 COPYDIR=xcopy /E /I PS="\" else WARNING_FLAGS=-Wall -Wno-non-virtual-dtor COPYDIR=cp -r endif ifeq "$(PLATFORM)" "linux" LINKER_FLAGS=-Wl,--no-undefined endif # General variables ifeq "$(VOIKKO_DEBUG)" "FULL" ifeq "$(PLATFORM)" "windows" OPT_FLAGS=-Od -Z7 else OPT_FLAGS=-O0 -g endif else OPT_FLAGS=-O2 ifneq "$(PLATFORM)" "windows" WARNING_FLAGS+= -fno-strict-aliasing endif endif # separated generic link flags and linked libs are needed to build with -Wl,--as-needed # this flag has been enabled by default on openSUSE-11.2 LINK_FLAGS=$(COMP_LINK_FLAGS) $(OPT_FLAGS) $(LINKER_FLAGS) ifneq "$(PLATFORM)" "macosx" LINK_LIBS+=$(SALLIB) $(CPPULIB) $(CPPUHELPERLIB) endif VOIKKO_CC_FLAGS=$(OPT_FLAGS) $(WARNING_FLAGS) -Ibuild/hpp -I$(PRJ)/include/stl -I$(PRJ)/include # STANDALONE_EXTENSION_FILES must contain the libvoikko library (unless it will be # linked statically) and versioned directories for dictionary data to be embedded. ifdef STANDALONE_EXTENSION_PATH VOIKKO_CC_DEFINES= -DVOIKKO_STANDALONE_EXTENSION ifeq "$(PLATFORM)" "windows" STANDALONE_EXTENSION_FILES=libvoikko-1.dll 2 3 else ifeq "$(PLATFORM)" "macosx" STANDALONE_EXTENSION_FILES=2 3 else STANDALONE_EXTENSION_FILES=libvoikko.so.1 2 3 LINK_LIBS += -lvoikko endif endif else VOIKKO_CC_DEFINES= STANDALONE_EXTENSION_FILES= LINK_LIBS += -lvoikko endif ifndef ENABLE_GRAMMAR_CHECKER VOIKKO_CC_DEFINES += -DDISABLE_GRAMMAR_CHECKER endif # Build extension package name ifdef SHOW_UGLY_WARNINGS VOIKKO_PACKAGENAME:=tekstintuho VOIKKO_CC_DEFINES += -DTEKSTINTUHO else VOIKKO_PACKAGENAME:=voikko endif ifneq "$(VOIKKO_DEBUG)" "NO" VOIKKO_CC_DEFINES+= -DVOIKKO_DEBUG_OUTPUT endif ifdef LIBVOIKKO_PATH LINK_FLAGS+= -L$(LIBVOIKKO_PATH)/lib VOIKKO_CC_FLAGS+= -I$(LIBVOIKKO_PATH)/include endif VOIKKO_EXTENSION_SHAREDLIB=voikko.$(SHAREDLIB_EXT) VOIKKO_OBJECTS=registry common PropertyManager VoikkoHandlePool \ spellchecker/SpellAlternatives spellchecker/SpellChecker \ hyphenator/Hyphenator hyphenator/HyphenatedWord hyphenator/PossibleHyphens \ grammar/GrammarChecker settings/SettingsEventHandler VOIKKO_HEADERS=macros common PropertyManager VoikkoHandlePool \ spellchecker/SpellAlternatives spellchecker/SpellChecker \ hyphenator/Hyphenator hyphenator/HyphenatedWord hyphenator/PossibleHyphens \ grammar/GrammarChecker settings/SettingsEventHandler COPY_TEMPLATES=config.xcu config.xcs icon.png SettingsDialog.xdl SettingsDialog_en_US.properties \ SettingsDialog_fi_FI.properties SettingsDialog_en_US.default SettingsDialog.xcu Linguistic.xcu ifdef SHOW_LICENSE COPY_TEMPLATES+=license_fi.txt license_en-US.txt endif SRCDIST=COPYING Makefile README ChangeLog $(patsubst %,src/%.hxx,$(VOIKKO_HEADERS)) \ $(patsubst %,src/%.cxx,$(VOIKKO_OBJECTS)) oxt/description.xml.template \ $(patsubst %,oxt/%,$(COPY_TEMPLATES)) \ oxt/META-INF/manifest.xml.template oxt/icon.svg SED=sed EXTENSION_FILES=build/oxt/META-INF/manifest.xml build/oxt/description.xml \ build/oxt/$(VOIKKO_EXTENSION_SHAREDLIB) \ $(patsubst %,build/oxt/%,$(STANDALONE_EXTENSION_FILES)) \ $(patsubst %,build/oxt/%,$(COPY_TEMPLATES)) # Targets .PHONY: extension-files oxt install-unpacked all clean dist-gzip extension-files : $(EXTENSION_FILES) oxt: $(EXTENSION_FILES) cd build/oxt && $(SDK_ZIP) -r -9 ../$(VOIKKO_PACKAGENAME).oxt \ $(patsubst build/oxt/%,%,$^) all: oxt install-unpacked: extension-files install -m 755 -d "$(DESTDIR)" "$(DESTDIR)/META-INF" install -m 644 build/oxt/META-INF/manifest.xml "$(DESTDIR)/META-INF" install -m 644 build/oxt/$(VOIKKO_EXTENSION_SHAREDLIB) \ build/oxt/description.xml \ $(patsubst %,build/oxt/%,$(STANDALONE_EXTENSION_FILES)) \ $(patsubst %,build/oxt/%,$(COPY_TEMPLATES)) $(DESTDIR) # Sed scripts for modifying templates MANIFEST_SEDSCRIPT:=s/VOIKKO_EXTENSION_SHAREDLIB/$(VOIKKO_EXTENSION_SHAREDLIB)/g;s/UNOPKG_PLATFORM/$(UNOPKG_PLATFORM)/g DESCRIPTION_SEDSCRIPT:=s/VOIKKO_VERSION/$(VOIKKO_VERSION)/g ifdef ENABLE_GRAMMAR_CHECKER MANIFEST_SEDSCRIPT:=$(MANIFEST_SEDSCRIPT);/GRAMMAR_CHECKER_DISABLED/d endif ifdef SHOW_LICENSE DESCRIPTION_SEDSCRIPT:=$(DESCRIPTION_SEDSCRIPT);/SHOW_LICENSE/d endif ifdef SHOW_UGLY_WARNINGS DESCRIPTION_SEDSCRIPT:=$(DESCRIPTION_SEDSCRIPT);s/Voikko/TEKSTINTUHO/g endif MANIFEST_SEDSCRIPT:="$(MANIFEST_SEDSCRIPT)" DESCRIPTION_SEDSCRIPT:="$(DESCRIPTION_SEDSCRIPT)" # Create extension files build/oxt/META-INF/manifest.xml: oxt/META-INF/manifest.xml.template -$(MKDIR) $(subst /,$(PS),$(@D)) $(SED) -e $(MANIFEST_SEDSCRIPT) < $^ > $@ build/oxt/description.xml: oxt/description.xml.template -$(MKDIR) $(subst /,$(PS),$(@D)) $(SED) -e $(DESCRIPTION_SEDSCRIPT) < $^ > $@ $(patsubst %,build/oxt/%,$(COPY_TEMPLATES)): build/oxt/%: oxt/% -$(MKDIR) $(subst /,$(PS),$(@D)) $(COPY) "$(subst /,$(PS),$^)" "$(subst /,$(PS),$@)" $(patsubst %,build/oxt/%,$(STANDALONE_EXTENSION_FILES)): build/oxt/%: $(STANDALONE_EXTENSION_PATH)/% -$(MKDIR) $(subst /,$(PS),$(@D)) $(COPYDIR) "$(subst /,$(PS),$^)" "$(subst /,$(PS),$@)" # Type library C++ headers build/hpp.flag: -$(MKDIR) build$(PS)hpp $(CPPUMAKER) -Gc -O./build/hpp $(URE_TYPES) $(OFFICE_TYPES) echo flagged > $@ # Compile the C++ source files build/src/%.$(OBJ_EXT): src/%.cxx build/hpp.flag $(patsubst %,src/%.hxx,$(VOIKKO_HEADERS)) -$(MKDIR) $(subst /,$(PS),$(@D)) $(CC) $(CC_FLAGS) $(VOIKKO_CC_FLAGS) $(CC_DEFINES) $(VOIKKO_CC_DEFINES) $(CC_OUTPUT_SWITCH)$@ $< # Link the shared library build/oxt/$(VOIKKO_EXTENSION_SHAREDLIB): $(patsubst %,build/src/%.$(OBJ_EXT),$(VOIKKO_OBJECTS)) ifeq "$(PLATFORM)" "windows" $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ /MAP:build/voikko.map $^ \ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) msvcrt.lib kernel32.lib $(LIBVOIKKO_PATH)\lib\libvoikko-1.lib mt -manifest build/oxt/voikko.dll.manifest -outputresource:build/oxt/voikko.dll;2 else ifeq "$(PLATFORM)" "macosx" cat $(PRJ)/settings/component.uno.map > build/voikko.map $(LINK) $(COMP_LINK_FLAGS) build/voikko.map $(LINK_LIBS) -o $@ $^ \ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB) \ -lvoikko $(INSTALL_NAME_URELIBS) $@ else $(LINK) $(LINK_FLAGS) $^ -o $@ $(LINK_LIBS) endif endif # Rules for creating the source distribution dist-gzip: libreoffice-voikko-$(VOIKKO_VERSION).tar.gz libreoffice-voikko-$(VOIKKO_VERSION).tar.gz: $(patsubst %,libreoffice-voikko-$(VOIKKO_VERSION)/%, \ $(sort $(SRCDIST))) tar c --group 0 --owner 0 libreoffice-voikko-$(VOIKKO_VERSION) | gzip -9 > $@ $(patsubst %,libreoffice-voikko-$(VOIKKO_VERSION)/%, $(sort $(SRCDIST))): \ libreoffice-voikko-$(VOIKKO_VERSION)/%: % install --mode=644 -D $^ $@ # The clean target clean: rm -rf build libreoffice-voikko-$(VOIKKO_VERSION) rm -f libreoffice-voikko-$(VOIKKO_VERSION).tar.gz