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_DICTIONARYMANAGER_H
22
#define KITEN_DICTIONARYMANAGER_H
24
#include "libkitenexport.h"
31
class DictionaryPreferenceDialog;
34
class KConfigSkeleton;
40
* @short The DictionaryManager class is the fundamental dictionary management class.
41
* All interfaces with the rest of the programs using the various dictionaries will
42
* work through this "interface class" to keep the formatting and other such
43
* nasty details away from programs and sections which just want to use the
44
* dictionary without bothering with the internal formatting details. As a
45
* general rule, call this class with a DictQuery to get a list of
46
* entries as the result.
48
* The idea is that the interfaces need to know how to load a query, pass the
49
* query to dictionary. DictionaryManager will return to them an EntryList object,
50
* each Entry knows how to display itself (via the magic of C++ polymorphism).
51
* There are some setup and preference handling methods which complicate
52
* things, but generally speaking this is the way this should work.
54
* @author Joseph Kerian <jkerian@gmail.com>
57
class KITEN_EXPORT DictionaryManager
67
virtual ~DictionaryManager();
70
* Open a specified dictionary, and load it under this manager's control
72
* @param file the filename, suitable for using with QFile::setFileName()
73
* @param name the name of the file, which may be related to file, but perhaps not,
74
* for all future dealings with this file, this name will be the key value
75
* @param type the known dictionary type of this file
77
bool addDictionary( const QString &file, const QString &name, const QString &type );
79
* Close a dictionary by name
81
* @param name the name of the dictionary file, as given in addDictionary
83
bool removeDictionary( const QString &name );
85
* List names of each open dictionary
87
QStringList listDictionaries() const;
89
* Returns type and file for an open dictionary of a given
91
* @param name the name of the dictionary whose information we are looking for
93
QPair<QString, QString> listDictionaryInfo( const QString &name ) const;
95
* Lists all dictionaries of a given type (Convenient for preference dialogs)
97
* @param type the type of dictionaries to list
99
QStringList listDictionariesOfType( const QString &type ) const;
101
* This is the main search routine that most of kiten should use
103
* @param query the DictQuery object describing the search to conduct
105
EntryList *doSearch( const DictQuery &query ) const;
107
* A simple method for searching inside of a given set of results
109
* @param query the new query that will pare down our results list, there is no requirement that
110
* this query includes the query that generated the EntryList, the results are calculated
111
* only out of the second parameter
112
* @param list the list of results to search for the above query in
114
EntryList *doSearchInList( const DictQuery &query, const EntryList *list ) const;
116
* Get a list of all supported dictionary types. Useful for preference code
118
static QStringList listDictFileTypes();
120
* Given a config and parent widget, return a mapping from dictionary types to preference dialogs.
121
* If a particular dictionary type does not provide a preference dialog, it will not be included in this list,
122
* so occasionally keys(returnvalue) != listDictFileTypes()
124
* @param config the config skeleton
125
* @param parent the parent widget, as per the normal Qt widget system
127
static QMap<QString,DictionaryPreferenceDialog*>
128
generatePreferenceDialogs( KConfigSkeleton *config, QWidget *parent = NULL );
130
* Compiles a list of all fields beyond the basic three (word/pronunciation/meaning) that all dictionary
131
* types support. This can be used to generate a preference dialog, or provide more direct references.
132
* The return value is "full name of the field" => "abbreviation useable in search string"
134
static QMap<QString,QString> generateExtendedFieldsList();
136
* Trigger loading preferences from a given KConfigSkeleton config object for a dictionary of type dict
138
* @param dict the dictionary type to load settings for
139
* @param config the config skeleton object */
140
void loadDictSettings( const QString &dict, KConfigSkeleton *config );
142
* Load general settings
144
void loadSettings( const KConfig &config );
148
* Static method, used to create the polymorphic dictFile object. Do not use externally.
149
* If you are adding a new dictionary type, see the instructions in the code.
151
static DictFile *makeDictFile( const QString &type );