1
/*****************************************************************************
2
* This file is part of Kiten, a KDE Japanese Reference Tool *
3
* Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Library General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2 of the License, or (at your option) any later version. *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13
* Library General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public License *
16
* along with this library; see the file COPYING.LIB. If not, write to *
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18
* Boston, MA 02110-1301, USA. *
19
*****************************************************************************/
21
#ifndef KITEN_DICTFILE_H
22
#define KITEN_DICTFILE_H
24
#include "libkitenexport.h"
30
class DictionaryPreferenceDialog;
34
class KConfigSkeleton;
39
* @short Abstract base class, used internally by the library for handling different types of dictionaries
40
* This is a virtual class that enforces the interface between the DictionaryManager
41
* class and the DictionaryManager.handler files. IMPLEMENT in combination with an
42
* Entry subclass (if needed) to add a new dictionary format. Also see the addDictionary
43
* method in the dictionary class.
45
* This documentation is mostly for those who are adding a new type of dictionary to
46
* kiten. This class is not exported outside of the library */
47
class /* NO_EXPORT */ DictFile
51
* You are not allowed to create a dictFile subclass without specifying the type-name
56
* Use this constructor for your subclasses. Dictionary subclasses MUST specify their type
59
DictFile( const QString& dictionaryTypeName ) : m_dictionaryType( dictionaryTypeName ) {}
63
virtual ~DictFile() {}
65
* This method allows the user to test if a dictionary is the proper type for this format.
66
* This process is allowed to take some time, but nonetheless you should find checking the format
67
* of a few hundred entries sufficient for this.
69
* @param filename the name of the file, suitable for using with QFile::setFileName() */
70
virtual bool validDictionaryFile( const QString &filename ) = 0;
72
* Is this query relevant to this dictionary type? Usually this will return true,
73
* unless the query specifies extended attributes that the dictionary does not provide.
75
* @param query the query to examine for relevence to this dictionary type */
76
virtual bool validQuery( const DictQuery &query ) = 0;
78
* This actually conducts the search on the given query. This is usually most of the work
80
* @param query the DictQuery that specifies what results to return
82
virtual EntryList *doSearch( const DictQuery &query ) = 0;
84
* Load a dictionary as at system startup.
86
* @param file the file to open, in a format suitable for use with QFile::setFileName()
87
* @param name the name of the file to open, used in various user-interface aspects.
88
* It may be related to the file parameter, but perhaps not.
90
virtual bool loadDictionary( const QString &file, const QString &name ) = 0;
92
* Load a new dictionary. This is called with the assumption that this dictionary
93
* has not been opened previously, in case you need to build an index or other activity.
94
* If you do not re-implement this method, it simply calls loadDictionary().
96
* @param file the file to open, in a format suitable for use with QFile::setFileName()
97
* @param name the name of the file to open, used in various user-interface aspects.
98
* It may be related to the file parameter, but perhaps not.
100
virtual bool loadNewDictionary( const QString &file, const QString &name )
101
{ return loadDictionary( file, name ); }
103
* Return a list of the fields that can be displayed, note the following
104
* should probably always be retured: --NewLine--, Word/Kanji, Meaning,
105
* Reading. This function is passed a list originally containing those
106
* four items. This function is used to enumerate possible types the user
107
* chooses to have displayed in the preferences dialog box.
108
* This will often be a very similer list to getSearchableAttributes(),
109
* but due to optional forms of spelling and other situations, it may
110
* not be exactly the same. Note: The "Dictionary" option will be
111
* appended to your list at the end.
113
virtual QStringList listDictDisplayOptions( QStringList ) const = 0 ;
115
* If you want your own dialog to pick preferences for your dict, then override this.
116
* Leaving it blank will leave your dictionary type without a preferences dialog.
118
* @param config the KConfigSkeleton object that is currently in use
119
* @param parent the parent widget for your preferences dialog
121
virtual DictionaryPreferenceDialog *preferencesWidget( KConfigSkeleton *config, QWidget *parent = NULL )
122
{ Q_UNUSED( parent ); Q_UNUSED( config ); return NULL; }
124
* Load information from the KConfigSkeleton that you've setup in
125
* the above preferences widget.
127
virtual void loadSettings( KConfigSkeleton* ) {}
130
* Returns the name of the dictionary
132
virtual QString getName() const { return m_dictionaryName; }
134
* Returns the type of files this dictFile object deals with
136
virtual QString getType() const { return m_dictionaryType; }
138
* Returns the file that this is working with, usually used in the preferences display
140
virtual QString getFile() const { return m_dictionaryFile; }
142
* Fetch a list of searchable attributes and their codes
144
virtual const QMap<QString,QString> &getSearchableAttributes() const
145
{ return m_searchableAttributes; }
148
* Name is the 'primary key' of the list of dictionaries. You will want to
149
* place this into your Entry objects to identify where they came from
152
QString m_dictionaryName;
155
* This is mostly a placeholder, but your class will get asked what file
156
* it is using, so either be sure to put something here, or override
157
* getFile() and respond with something that will be sensical in a
158
* dictionary selection dialog box.
160
QString m_dictionaryFile;
163
* This MUST BE SET IN THE CONSTRUCTOR. The dictionary class occasionally
164
* uses this value and it's important for it to be set at anytime after the
165
* constructor is called. It also must be unique to the dictionary type. If
166
* relevant, specify dictionary versions here.
168
QString m_dictionaryType;
170
* This allows the programming user to see a list
171
* of possible search types (probably through a drop down menu).
172
* You may also find it useful in your dictFile implementation
173
* to translate from extended attribute keys into the simpler one or two letter
174
* code keys. These should take the format of:
175
* (Kanji Grade => G), (Strokes => S), (Heisig Number => H)
176
* for a simple example appropriate to kanji.
178
QMap<QString,QString> m_searchableAttributes;