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

« back to all changes in this revision

Viewing changes to lib/dictfile.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) 2006 Joseph Kerian <jkerian@gmail.com>                      *
 
4
 *                                                                           *
 
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.          *
 
9
 *                                                                           *
 
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.                          *
 
14
 *                                                                           *
 
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
 *****************************************************************************/
 
20
 
 
21
#ifndef KITEN_DICTFILE_H
 
22
#define KITEN_DICTFILE_H
 
23
 
 
24
#include "libkitenexport.h"
 
25
 
 
26
#include <QMap>
 
27
#include <QString>
 
28
 
 
29
class DictQuery;
 
30
class DictionaryPreferenceDialog;
 
31
class Entry;
 
32
class EntryList;
 
33
class KConfig;
 
34
class KConfigSkeleton;
 
35
class QStringList;
 
36
class QWidget;
 
37
 
 
38
/**
 
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.
 
44
 *
 
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
 
48
{
 
49
  private:
 
50
    /**
 
51
     * You are not allowed to create a dictFile subclass without specifying the type-name
 
52
     */
 
53
    DictFile() {}
 
54
  public:
 
55
    /**
 
56
     * Use this constructor for your subclasses. Dictionary subclasses MUST specify their type
 
57
     * at creation.
 
58
     */
 
59
    DictFile( const QString& dictionaryTypeName ) : m_dictionaryType( dictionaryTypeName ) {}
 
60
    /**
 
61
     * Destructor
 
62
     */
 
63
    virtual ~DictFile() {}
 
64
    /**
 
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.
 
68
     *
 
69
     * @param filename the name of the file, suitable for using with QFile::setFileName() */
 
70
    virtual bool validDictionaryFile( const QString &filename ) = 0;
 
71
    /**
 
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.
 
74
     *
 
75
     * @param query the query to examine for relevence to this dictionary type */
 
76
    virtual bool validQuery( const DictQuery &query ) = 0;
 
77
    /**
 
78
     * This actually conducts the search on the given query. This is usually most of the work
 
79
     *
 
80
     * @param query the DictQuery that specifies what results to return
 
81
     */
 
82
    virtual EntryList *doSearch( const DictQuery &query ) = 0;
 
83
    /**
 
84
     * Load a dictionary as at system startup.
 
85
     *
 
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.
 
89
     */
 
90
    virtual bool loadDictionary( const QString &file, const QString &name ) = 0;
 
91
    /**
 
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().
 
95
     *
 
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.
 
99
     */
 
100
    virtual bool loadNewDictionary( const QString &file, const QString &name )
 
101
            { return loadDictionary( file, name ); }
 
102
    /**
 
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.
 
112
     */
 
113
    virtual QStringList listDictDisplayOptions( QStringList ) const = 0 ;
 
114
    /**
 
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.
 
117
     *
 
118
     * @param config the KConfigSkeleton object that is currently in use
 
119
     * @param parent the parent widget for your preferences dialog
 
120
     */
 
121
    virtual DictionaryPreferenceDialog *preferencesWidget( KConfigSkeleton *config, QWidget *parent = NULL )
 
122
                            { Q_UNUSED( parent ); Q_UNUSED( config ); return NULL; }
 
123
    /**
 
124
     * Load information from the KConfigSkeleton that you've setup in
 
125
     * the above preferences widget.
 
126
     */
 
127
    virtual void loadSettings( KConfigSkeleton* ) {}
 
128
 
 
129
    /**
 
130
     * Returns the name of the dictionary
 
131
     */
 
132
    virtual QString getName() const { return m_dictionaryName; }
 
133
    /**
 
134
     * Returns the type of files this dictFile object deals with
 
135
     */
 
136
    virtual QString getType() const { return m_dictionaryType; }
 
137
    /**
 
138
     * Returns the file that this is working with, usually used in the preferences display
 
139
     */
 
140
    virtual QString getFile() const { return m_dictionaryFile; }
 
141
    /**
 
142
     * Fetch a list of searchable attributes and their codes
 
143
     */
 
144
    virtual const QMap<QString,QString> &getSearchableAttributes() const
 
145
                                      { return m_searchableAttributes; }
 
146
  protected:
 
147
    /**
 
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
 
150
     * (fairly important)
 
151
     */
 
152
    QString m_dictionaryName;
 
153
 
 
154
    /**
 
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.
 
159
     */
 
160
    QString m_dictionaryFile;
 
161
 
 
162
    /**
 
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.
 
167
     */
 
168
    QString m_dictionaryType;
 
169
    /**
 
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.
 
177
     */
 
178
    QMap<QString,QString> m_searchableAttributes;
 
179
};
 
180
 
 
181
#endif