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

« back to all changes in this revision

Viewing changes to lib/dictionarymanager.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_DICTIONARYMANAGER_H
 
22
#define KITEN_DICTIONARYMANAGER_H
 
23
 
 
24
#include "libkitenexport.h"
 
25
 
 
26
#include <QMap>
 
27
#include <QPair>
 
28
 
 
29
class DictFile;
 
30
class DictQuery;
 
31
class DictionaryPreferenceDialog;
 
32
class EntryList;
 
33
class KConfig;
 
34
class KConfigSkeleton;
 
35
class QString;
 
36
class QStringList;
 
37
class QWidget;
 
38
 
 
39
/**
 
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.
 
47
 *
 
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.
 
53
 *
 
54
 * @author Joseph Kerian <jkerian@gmail.com>
 
55
 */
 
56
 
 
57
class KITEN_EXPORT DictionaryManager
 
58
{
 
59
  public:
 
60
    /**
 
61
     * Basic constructor
 
62
     */
 
63
    DictionaryManager();
 
64
    /**
 
65
     * Basic destructor
 
66
     */
 
67
    virtual ~DictionaryManager();
 
68
 
 
69
    /**
 
70
     * Open a specified dictionary, and load it under this manager's control
 
71
     *
 
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
 
76
     */
 
77
    bool addDictionary( const QString &file, const QString &name, const QString &type );
 
78
    /**
 
79
     * Close a dictionary by name
 
80
     *
 
81
     * @param name the name of the dictionary file, as given in addDictionary
 
82
     */
 
83
    bool removeDictionary( const QString &name );
 
84
    /**
 
85
     * List names of each open dictionary
 
86
     */
 
87
    QStringList listDictionaries() const;
 
88
    /**
 
89
     * Returns type and file for an open dictionary of a given
 
90
     *
 
91
     * @param name the name of the dictionary whose information we are looking for
 
92
     */
 
93
    QPair<QString, QString> listDictionaryInfo( const QString &name ) const;
 
94
    /**
 
95
     * Lists all dictionaries of a given type (Convenient for preference dialogs)
 
96
     *
 
97
     * @param type the type of dictionaries to list
 
98
     */
 
99
    QStringList listDictionariesOfType( const QString &type ) const;
 
100
    /**
 
101
     * This is the main search routine that most of kiten should use
 
102
     *
 
103
     * @param query the DictQuery object describing the search to conduct
 
104
     */
 
105
    EntryList *doSearch( const DictQuery &query ) const;
 
106
    /**
 
107
     * A simple method for searching inside of a given set of results
 
108
     *
 
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
 
113
     */
 
114
    EntryList *doSearchInList( const DictQuery &query, const EntryList *list ) const;
 
115
    /**
 
116
     * Get a list of all supported dictionary types. Useful for preference code
 
117
     */
 
118
    static QStringList listDictFileTypes();
 
119
    /**
 
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()
 
123
     *
 
124
     * @param config the config skeleton
 
125
     * @param parent the parent widget, as per the normal Qt widget system
 
126
     */
 
127
    static QMap<QString,DictionaryPreferenceDialog*>
 
128
            generatePreferenceDialogs( KConfigSkeleton *config, QWidget *parent = NULL );
 
129
    /**
 
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"
 
133
     */
 
134
    static QMap<QString,QString> generateExtendedFieldsList();
 
135
    /**
 
136
     * Trigger loading preferences from a given KConfigSkeleton config object for a dictionary of type dict
 
137
     *
 
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 );
 
141
    /**
 
142
     * Load general settings
 
143
     */
 
144
    void loadSettings( const KConfig &config );
 
145
 
 
146
  private:
 
147
    /**
 
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.
 
150
     */
 
151
    static DictFile *makeDictFile( const QString &type );
 
152
    class Private;
 
153
    Private* const d;
 
154
};
 
155
 
 
156
#endif