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
*****************************************************************************/
28
#include <QStringList>
30
#include "libkitenexport.h"
32
#include "dictquery.h"
39
* The Entry class is a generic base class for each particular entry in a given dictionary.
40
* It's used as the basic class to ferry information back to the user application.
41
* It also handles some of the display aspects.
43
class KITEN_EXPORT Entry
45
friend class EntryListModel;
49
* Default constructor, should not be used. Made private to serve as a warning
50
* that you're doing something wrong if you try to call this.
58
Entry( const Entry& );
60
* Constructor that includes the dictionary source. This does not need to be overridded by
61
* subclasses, but you might find it to be convenient as the superclass constructor to call
62
* from your constructors.
63
* @param sourceDictionary the dictionary name (not fileName) that this entry originated with
65
Entry( const QString &sourceDictionary );
67
* A constructor that includes the basic information, nicely separated
68
* @param sourceDictionary the dictionary name (not fileName) that this entry originated with
69
* @param word the word entry of this dictionary entry (normally kanji/kana)
70
* @param readings a list of possible pronunciations for this result (kana)
71
* @param meanings a list of possible meanings for this word
73
Entry( const QString &sourceDictionary, const QString &word,
74
const QStringList &readings, const QStringList &meanings );
82
* A clone method, this should just implement "return new EntrySubClass(*this)"
84
virtual Entry *clone() const = 0;
87
* Fairly important method, this tests if this particular entry matches a query. The
88
* EDICT and Kanjidic doSearch methods do an approximate match, load an Entry, and then
89
* check more carefully by calling this method. This works nicely for handling searchWithinResults
92
virtual bool matchesQuery( const DictQuery& ) const;
95
* Get the dictionary name that generated this Entry. I can't think of a reason to be changing this
97
const QString &getDictName() const;
99
* Get the word from this Entry. If the entry is of type kanji/kana/meaning/etc, this will
100
* return the kanji. If it is of kana/meaning/etc, it will return kana.
102
QString getWord() const;
104
* Get a QString containing all of the meanings known, connected by the outputListDelimiter
106
QString getMeanings() const;
110
QStringList getMeaningsList() const;
114
QString getReadings() const;
118
QStringList getReadingsList() const;
122
const QHash<QString,QString> &getExtendedInfo() const;
125
* @param x the key for the extended info item to get
127
QString getExtendedInfoItem( const QString &x ) const;
130
* @param key the key for the extended item that is being verified
131
* @param value the value it is supposed to have
132
* @returns true if the key has that value, false if it is different or does not exist
134
virtual bool extendedItemCheck( const QString &key, const QString &value ) const;
137
* An entry should be able to generate a representation of itself in (valid) HTML
139
virtual QString toHTML() const;
141
* KVTML format for exporting
143
virtual QString toKVTML() const;
145
* This will return a pure text interpretation of the Entry
147
virtual QString toString() const;
150
* An entry should be able to parse an in-file representation of an entry
151
* as a QString and put it back. The latter will be useful for writing
152
* to dictionaries on disk at some point.
154
virtual bool loadEntry( const QString& ) = 0;
156
* Return a QString of an entry, as if it were dumped back into it's source file
158
virtual QString dumpEntry() const = 0;
161
* An overrideable sorting function, similer to operator< in most contexts
162
* The default version will sort by dictionary, then by fields
164
* @param that the second item we are comparing (this) with
165
* @param dictionaryList the list of dictionaries (in order) to sort
166
* If this list is empty, the entries will not be sorted in order
167
* @param fieldList the list of fields to sort in, uses special codes of
168
* Reading, Meaning, Word/Kanji for those elements, all others by their
169
* extended attribute keys.
171
virtual bool sort( const Entry &that, const QStringList &dictionaryList,
172
const QStringList &fieldList ) const;
174
* Overrideable sorting mechanism for sorting by individual fields.
175
* The sort routine checks if the given field is equal, before calling this virtual function
176
* So if this is called, you can assume that this->extendedItem(field) != that.extendedItem(field)
178
* @param that the second item we are comparing (this) with
179
* @param field the specific extended item field that is being compared
181
virtual bool sortByField( const Entry &that, const QString &field ) const;
185
* The Word (usually containing kanji) that matches this entry. If you override the accessors
186
* above, this has no use.
190
* The Meanings that match this entry. If you override the accessors
191
* above, this has no use.
193
QStringList Meanings;
195
* The Readings (usually kana) that match this entry. If you override the accessors
196
* above, this has no use.
198
QStringList Readings;
200
* A hash of extended information. You may find it useful to store all sorts of details here
202
QHash<QString,QString> ExtendedInfo;
205
* The dictionary that this entry originated at
209
* The delimiter for lists... usually space
211
QString outputListDelimiter;
214
* This is used by the constructors to set some default values
219
* Handy function for generating a link from a given QString
221
virtual QString makeLink( const QString &entryString ) const;
223
* Return and HTML version of a word
225
virtual QString HTMLWord() const;
227
* Return and HTML version of a reading list
229
virtual QString HTMLReadings() const;
231
* Return and HTML version of a meaning list
233
virtual QString HTMLMeanings() const;
236
* Handy Utility functions for matching to lists and identifying char types
238
bool listMatch( const QStringList &list, const QStringList &test, DictQuery::MatchType type ) const;
240
* Handy Utility functions for matching to lists and identifying char types
242
bool isKanji( const QChar &character ) const;