summaryrefslogtreecommitdiffstats
path: root/tools/spell/main.cc
blob: 275e3ee94c402348df5d2f19894c7d579b760759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
   Copyright (C) 2002 Laurent Montel <lmontel@mandrakesoft.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "main.h"
#include <kmessagebox.h>
#include <klocale.h>
#include <kdebug.h>
#include <kinstance.h>
#include <kconfig.h>
#include <kgenericfactory.h>
#include <klibloader.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/***************************************************
 *
 * Factory
 *
 ***************************************************/

K_EXPORT_COMPONENT_FACTORY( libkspelltool, KGenericFactory<SpellChecker> )

/***************************************************
 *
 * Spellchecker
 *
 ***************************************************/

SpellChecker::SpellChecker( TQObject* tqparent, const char* name, const TQStringList & )
    : KDataTool( tqparent, name )
{
}

bool SpellChecker::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype )
{
    if ( command != "spellcheck" )
    {
	kdDebug(31000) << "SpellChecker does only accept the command 'spellcheck'" << endl;
	kdDebug(31000) << "   The commands " << command << " is not accepted" << endl;
	return FALSE;
    }

    // Check wether we can accept the data
    if ( datatype != TQSTRING_OBJECT_NAME_STRING )
    {
	kdDebug(31000) << "SpellChecker only accepts datatype TQString" << endl;
	return FALSE;
    }

    if ( mimetype != "text/plain" && mimetype != "application/x-singleword" )
    {
	kdDebug(31000) << "SpellChecker only accepts mimetype text/plain and application/x-singleword" << endl;
	return FALSE;
    }

    // Get data
    TQString buffer = *((TQString *)data);
    buffer = buffer.stripWhiteSpace();

    if ( instance() )
    {
        KConfig * config = instance()->config();
        TQCString gn( "KSpell " );
        gn += instance()->instanceName(); // for compat reasons, and to avoid finding the group in kdeglobals (hmm...)
        TQString groupName = TQString::tqfromLatin1( gn );
        //kdDebug() << "Group: " << groupName << endl;
        if ( config->hasGroup( groupName ) )
        {
            //kdDebug() << "SpellChecker::run - group found -" << endl;
            config->setGroup( groupName );
#if 0
            kosconfig.setNoRootAffix(config->readNumEntry ("KSpell_NoRootAffix", 0));
            kosconfig.setRunTogether(config->readNumEntry ("KSpell_RunTogether", 0));
            kosconfig.setDictionary(config->readEntry ("KSpell_Dictionary", ""));
            kosconfig.setDictFromList(config->readNumEntry ("KSpell_DictFromList", FALSE));
            kosconfig.setEncoding(config->readNumEntry ("KSpell_Encoding", KOS_E_ASCII));
            kosconfig.setClient(config->readNumEntry ("KSpell_Client", KOS_CLIENT_ISPELL));
            kosconfig.setNoRootAffix(config->readNumEntry ("KSpell_NoRootAffix", 0));
            kosconfig.setRunTogether(config->readNumEntry ("KSpell_RunTogether", 0));
            kosconfig.setDictionary(config->readEntry ("KSpell_Dictionary", ""));
            kosconfig.setDictFromList(config->readNumEntry ("KSpell_DictFromList", FALSE));

            kosconfig.setIgnoreCase( config->readNumEntry( "KSpell_IgnoreCase", 0));
            kosconfig.setIgnoreAccent( config->readNumEntry( "KSpell_IgnoreAccent", 0));
            kosconfig.setDontCheckUpperWord(config->readBoolEntry("KSpell_dont_check_upper_word",false));
            kosconfig.setDontCheckTitleCase(config->readBoolEntry("KSpell_dont_check_title_case",false));
            kosconfig.setSpellWordWithNumber( config->readNumEntry("KSpell_SpellWordWithNumber", false));
#endif
        }
    }
#if 0 //PORT to kspell2
    // Call the spell checker
    KOSpell::modalCheck( buffer, &kosconfig );
    *((TQString*)data) = buffer;
#endif
#if 0 //fixme
    // Call the spell checker
    KSpell::spelltqStatus status=(KSpell::spelltqStatus)KSpell::modalCheck( buffer, &ksconfig );

    if (status == KSpell::Error)
    {
        KMessageBox::sorry(0L, i18n("KSpell could not be started.\n"
                                    "Please make sure you have ISpell or ASpell properly configured and in your PATH."));
    }
    else if (status == KSpell::Crashed)
    {
        KMessageBox::sorry(0L, i18n("KSpell seems to have crashed."));
    }
    else
    {
        // Set data
        *((TQString*)data) = buffer;
    }
#endif
    return TRUE;
}

#include "main.moc"