1
/*****************************************************************************
2
* This file is part of Kiten, a KDE Japanese Reference Tool *
3
* Copyright (C) 2001 Jason Katz-Brown <jason@katzbrown.com> *
4
* Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com> *
5
* Copyright (C) 2006 Eric Kjeldergaard <kjelderg@gmail.com> *
7
* This library is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU Library General Public *
9
* License as published by the Free Software Foundation; either *
10
* version 2 of the License, or (at your option) any later version. *
12
* This library is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15
* Library General Public License for more details. *
17
* You should have received a copy of the GNU Library General Public License *
18
* along with this library; see the file COPYING.LIB. If not, write to *
19
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
*****************************************************************************/
23
#include "dictfilekanjidic.h"
25
#include "../dictquery.h" //DictQuery classs
26
#include "../entry.h" //Entry and EntryList classes
27
#include "entrykanjidic.h"
29
#include <KConfigSkeleton>
34
QStringList *DictFileKanjidic::displayFields = NULL;
36
DictFileKanjidic::DictFileKanjidic()
39
m_dictionaryType = "kanjidic"; //Override the default type
40
m_searchableAttributes.clear();
41
m_searchableAttributes.insert( "bushu", "B" );
42
m_searchableAttributes.insert( "classical", "C" );
43
m_searchableAttributes.insert( "henshall", "E" );
44
m_searchableAttributes.insert( "frequency", "F" );
45
m_searchableAttributes.insert( "grade", "G" );
46
m_searchableAttributes.insert( "halpern", "H" );
47
m_searchableAttributes.insert( "spahn", "I" );
48
m_searchableAttributes.insert( "hadamitzky", "I" );
49
m_searchableAttributes.insert( "gakken", "K" );
50
m_searchableAttributes.insert( "heisig", "L" );
51
m_searchableAttributes.insert( "morohashi", "M" );
52
m_searchableAttributes.insert( "nelson", "N" );
53
m_searchableAttributes.insert( "oneill", "O" );
54
m_searchableAttributes.insert( "skip", "P" );
55
m_searchableAttributes.insert( "4cc", "Q" );
56
m_searchableAttributes.insert( "stroke", "S" );
57
m_searchableAttributes.insert( "strokes", "S" );
58
m_searchableAttributes.insert( "unicode", "U" );
59
m_searchableAttributes.insert( "haig", "V" );
60
m_searchableAttributes.insert( "korean", "W" );
61
m_searchableAttributes.insert( "pinyin", "Y" );
62
m_searchableAttributes.insert( "other", "D" );
65
DictFileKanjidic::~DictFileKanjidic()
69
QMap<QString,QString> DictFileKanjidic::displayOptions() const
71
// Enumerate the fields in our dict.... there are a rather lot of them here
72
// It will be useful for a few things to have the full list generated on it's own
73
QMap<QString,QString> list;
74
// TODO: Figure out how to internationalize these easily
75
list.insert( "Bushu Number(B)", "B");
76
list.insert( "Classical Radical Number(C)", "C");
77
list.insert( "Henshall's Index Number(E)", "E");
78
list.insert( "Frequency Ranking(F)", "F");
79
list.insert( "Grade Level(G)", "G");
80
list.insert( "Halpern's New J-E Char Dictionary(H)", "H");
81
list.insert( "Spahn & Hadamitzky Reference(I)", "I");
82
list.insert( "Gakken Kanji Dictionary Index(K)", "L");
83
list.insert( "Heisig's Index(L)", "L");
84
list.insert( "Morohashi's Daikanwajiten(M)", "M");
85
list.insert( "Nelsons Modern Reader's J-E Index(N)", "N");
86
list.insert( "O'Neill's 'Japanese Names' Index(O)", "O");
87
list.insert( "SKIP Code(P)", "P");
88
list.insert( "Four Corner codes(Q)", "Q");
89
list.insert( "Stroke Count(S)", "S");
90
list.insert( "Unicode Value(U)", "U");
91
list.insert( "Haig's New Nelson J-E Dict(V)", "V");
92
list.insert( "Korean Reading(W)", "W");
93
list.insert( "kanjidic field: X", "X");
94
list.insert( "Pinyin Reading(Y)", "Y");
95
list.insert( "Common SKIP Misclassifications(Z)", "Z");
96
list.insert( "Misc Dictionary Codes (D)", "D");
100
void DictFileKanjidic::loadSettings( KConfigSkeleton *config )
102
QMap<QString,QString> list = displayOptions();
103
list[ "Word/Kanji" ] = "Word/Kanji";
104
list[ "Reading" ] = "Reading";
105
list[ "Meaning" ] = "Meaning";
106
list[ "--Newline--" ] = "--Newline--";
108
KConfigSkeletonItem *item = config->findItem( getType() + "__displayFields" );
109
this->displayFields = loadListType( item, this->displayFields, list );
112
inline Entry* DictFileKanjidic::makeEntry( QString x )
114
return new EntryKanjidic( getName(), x );
118
* Scan a potential file for the correct format, remembering to skip comment
119
* characters. This is not a foolproof scan, but it should be checked before adding
122
bool DictFileKanjidic::validDictionaryFile( const QString &filename )
124
QFile file( filename );
125
if( ! file.exists() )
129
if( ! file.open( QIODevice::ReadOnly ) )
133
//TODO: Some actual format checking of the kanjidic file
140
* Reject queries that specify anything we don't understand
142
bool DictFileKanjidic::validQuery( const DictQuery &query )
144
//Multi kanji searches don't apply to this file
145
if( query.getWord().length() > 1 )
150
//Now check if we have any properties specified that we don't understand
151
QStringList propertiesWeHandle = m_searchableAttributes.values() + m_searchableAttributes.keys();
152
propertiesWeHandle += "common"; // We map this to be (has a G value)
154
const QStringList properties = query.listPropertyKeys();
155
for( QStringList::const_iterator it = properties.constBegin(); it != properties.constEnd(); ++it )
157
if( ! propertiesWeHandle.contains( *it ) )