~ubuntu-branches/ubuntu/quantal/kiten/quantal-proposed

« back to all changes in this revision

Viewing changes to lib/entry.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:23:47 UTC
  • Revision ID: james.westby@ubuntu.com-20110710112347-ykfhtvam3kgssspo
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>                 *
 
6
 *                                                                           *
 
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.          *
 
11
 *                                                                           *
 
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.                          *
 
16
 *                                                                           *
 
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
 *****************************************************************************/
 
22
 
 
23
#ifndef KITEN_ENTRY_H
 
24
#define KITEN_ENTRY_H
 
25
 
 
26
#include <QHash>
 
27
#include <QList>
 
28
#include <QStringList>
 
29
 
 
30
#include "libkitenexport.h"
 
31
 
 
32
#include "dictquery.h"
 
33
 
 
34
class Entry;
 
35
class EntryList;
 
36
class QString;
 
37
 
 
38
/**
 
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.
 
42
 */
 
43
class KITEN_EXPORT Entry
 
44
{
 
45
  friend class EntryListModel;
 
46
 
 
47
  private:
 
48
    /**
 
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.
 
51
      */
 
52
    Entry();
 
53
 
 
54
  protected:
 
55
    /**
 
56
     * Copy constructor
 
57
     */
 
58
    Entry( const Entry& );
 
59
    /**
 
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
 
64
     */
 
65
    Entry( const QString &sourceDictionary );
 
66
    /**
 
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
 
72
     */
 
73
    Entry( const QString &sourceDictionary, const QString &word,
 
74
           const QStringList &readings, const QStringList &meanings );
 
75
 
 
76
  public:
 
77
    /**
 
78
     * Generic Destructor
 
79
     */
 
80
    virtual ~Entry();
 
81
    /**
 
82
     * A clone method, this should just implement "return new EntrySubClass(*this)"
 
83
     */
 
84
    virtual Entry *clone() const = 0;
 
85
 
 
86
    /**
 
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
 
90
     * cleanly.
 
91
     */
 
92
    virtual bool matchesQuery( const DictQuery& ) const;
 
93
 
 
94
    /**
 
95
     * Get the dictionary name that generated this Entry. I can't think of a reason to be changing this
 
96
     */
 
97
    const QString &getDictName() const;
 
98
    /**
 
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.
 
101
     */
 
102
    QString getWord() const;
 
103
    /**
 
104
     * Get a QString containing all of the meanings known, connected by the outputListDelimiter
 
105
     */
 
106
    QString getMeanings() const;
 
107
    /**
 
108
     * Simple accessor
 
109
     */
 
110
    QStringList getMeaningsList() const;
 
111
    /**
 
112
     * Simple accessor
 
113
     */
 
114
    QString getReadings() const;
 
115
    /**
 
116
     * Simple accessor
 
117
     */
 
118
    QStringList getReadingsList() const;
 
119
    /**
 
120
     * Simple accessor
 
121
     */
 
122
    const QHash<QString,QString> &getExtendedInfo() const;
 
123
    /**
 
124
     * Simple accessor
 
125
     * @param x the key for the extended info item to get
 
126
     */
 
127
    QString getExtendedInfoItem( const QString &x ) const;
 
128
    /**
 
129
     * Simple accessor
 
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
 
133
     */
 
134
    virtual bool extendedItemCheck( const QString &key, const QString &value ) const;
 
135
 
 
136
    /**
 
137
     * An entry should be able to generate a representation of itself in (valid) HTML
 
138
     */
 
139
    virtual QString toHTML() const;
 
140
    /**
 
141
     * KVTML format for exporting
 
142
     */
 
143
    virtual QString toKVTML() const;
 
144
    /**
 
145
     * This will return a pure text interpretation of the Entry
 
146
     */
 
147
    virtual QString toString() const;
 
148
 
 
149
    /**
 
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.
 
153
     */
 
154
    virtual bool loadEntry( const QString& ) = 0;
 
155
    /**
 
156
     * Return a QString of an entry, as if it were dumped back into it's source file
 
157
     */
 
158
    virtual QString dumpEntry() const = 0;
 
159
 
 
160
    /**
 
161
     * An overrideable sorting function, similer to operator< in most contexts
 
162
     * The default version will sort by dictionary, then by fields
 
163
     *
 
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.
 
170
     */
 
171
    virtual bool sort( const Entry &that, const QStringList &dictionaryList,
 
172
                       const QStringList &fieldList ) const;
 
173
    /**
 
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)
 
177
     *
 
178
     * @param that the second item we are comparing (this) with
 
179
     * @param field the specific extended item field that is being compared
 
180
     */
 
181
    virtual bool sortByField( const Entry &that, const QString &field ) const;
 
182
 
 
183
  protected:
 
184
    /**
 
185
     * The Word (usually containing kanji) that matches this entry. If you override the accessors
 
186
     * above, this has no use.
 
187
     */
 
188
    QString Word;
 
189
    /**
 
190
     * The Meanings that match this entry. If you override the accessors
 
191
     * above, this has no use.
 
192
     */
 
193
    QStringList Meanings;
 
194
    /**
 
195
     * The Readings (usually kana) that match this entry. If you override the accessors
 
196
     * above, this has no use.
 
197
     */
 
198
    QStringList Readings;
 
199
    /**
 
200
     * A hash of extended information. You may find it useful to store all sorts of details here
 
201
     */
 
202
    QHash<QString,QString> ExtendedInfo;
 
203
 
 
204
    /**
 
205
     * The dictionary that this entry originated at
 
206
     */
 
207
    QString sourceDict;
 
208
    /**
 
209
     * The delimiter for lists... usually space
 
210
     */
 
211
    QString outputListDelimiter;
 
212
 
 
213
    /**
 
214
     * This is used by the constructors to set some default values
 
215
     */
 
216
    void init();
 
217
 
 
218
    /**
 
219
     * Handy function for generating a link from a given QString
 
220
     */
 
221
    virtual QString makeLink( const QString &entryString ) const;
 
222
    /**
 
223
     * Return and HTML version of a word
 
224
     */
 
225
    virtual QString HTMLWord() const;
 
226
    /**
 
227
     * Return and HTML version of a reading list
 
228
     */
 
229
    virtual QString HTMLReadings() const;
 
230
    /**
 
231
     * Return and HTML version of a meaning list
 
232
     */
 
233
    virtual QString HTMLMeanings() const;
 
234
 
 
235
    /**
 
236
     * Handy Utility functions for matching to lists and identifying char types
 
237
     */
 
238
    bool listMatch( const QStringList &list, const QStringList &test, DictQuery::MatchType type ) const;
 
239
    /**
 
240
     * Handy Utility functions for matching to lists and identifying char types
 
241
     */
 
242
    bool isKanji( const QChar &character ) const;
 
243
};
 
244
 
 
245
#endif