Warning, file /education/kiten/lib/dictfile.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of Kiten, a KDE Japanese Reference Tool
0003     SPDX-FileCopyrightText: 2006 Joseph Kerian <jkerian@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KITEN_DICTFILE_H
0009 #define KITEN_DICTFILE_H
0010 
0011 #include "kiten_export.h"
0012 
0013 #include <QMap>
0014 #include <QStringList>
0015 
0016 class DictQuery;
0017 class DictionaryPreferenceDialog;
0018 class Entry;
0019 class EntryList;
0020 class KConfig;
0021 class KConfigSkeleton;
0022 class QWidget;
0023 
0024 /**
0025  * @short Abstract base class, used internally by the library for handling different types of dictionaries
0026  * This is a virtual class that enforces the interface between the DictionaryManager
0027  * class and the DictionaryManager.handler files. IMPLEMENT in combination with an
0028  * Entry subclass (if needed) to add a new dictionary format. Also see the addDictionary
0029  * method in the DictionaryManager class.
0030  *
0031  * This documentation is mostly for those who are adding a new type of dictionary to
0032  * kiten. This class is not exported outside of the library. */
0033 class /* NO_EXPORT */ DictFile
0034 {
0035 private:
0036     /**
0037      * You are not allowed to create a dictFile subclass without specifying the type-name
0038      */
0039     DictFile()
0040     {
0041     }
0042 
0043 public:
0044     /**
0045      * Use this constructor for your subclasses. Dictionary subclasses MUST specify their type
0046      * at creation.
0047      */
0048     explicit DictFile(const QString &dictionaryTypeName)
0049         : m_dictionaryType(dictionaryTypeName)
0050     {
0051     }
0052     /**
0053      * Destructor
0054      */
0055     virtual ~DictFile()
0056     {
0057     }
0058     /**
0059      * This method allows the user to test if a dictionary is the proper type for this format.
0060      * This process is allowed to take some time, but nonetheless you should find checking the format
0061      * of a few hundred entries sufficient for this.
0062      *
0063      * @param filename the name of the file, suitable for using with QFile::setFileName() */
0064     virtual bool validDictionaryFile(const QString &filename) = 0;
0065     /**
0066      * Is this query relevant to this dictionary type? Usually this will return true,
0067      * unless the query specifies extended attributes that the dictionary does not provide.
0068      *
0069      * @param query the query to examine for relevance to this dictionary type */
0070     virtual bool validQuery(const DictQuery &query) = 0;
0071     /**
0072      * This actually conducts the search on the given query. This is usually most of the work
0073      *
0074      * @param query the DictQuery that specifies what results to return
0075      */
0076     virtual EntryList *doSearch(const DictQuery &query) = 0;
0077     /**
0078      * Load a dictionary as at system startup.
0079      *
0080      * @param file the file to open, in a format suitable for use with QFile::setFileName()
0081      * @param name the name of the file to open, used in various user-interface aspects.
0082      *             It may be related to the file parameter, but perhaps not.
0083      */
0084     virtual bool loadDictionary(const QString &file, const QString &name) = 0;
0085     /**
0086      * Load a new dictionary. This is called with the assumption that this dictionary
0087      * has not been opened previously, in case you need to build an index or other activity.
0088      * If you do not re-implement this method, it simply calls loadDictionary().
0089      *
0090      * @param file the file to open, in a format suitable for use with QFile::setFileName()
0091      * @param name the name of the file to open, used in various user-interface aspects.
0092      *             It may be related to the file parameter, but perhaps not.
0093      */
0094     virtual bool loadNewDictionary(const QString &file, const QString &name)
0095     {
0096         return loadDictionary(file, name);
0097     }
0098     /**
0099      * Return a list of the fields that can be displayed, note the following
0100      * should probably always be returned: --NewLine--, Word/Kanji, Meaning,
0101      * Reading.  This function is passed a list originally containing those
0102      * four items. This function is used to enumerate possible types the user
0103      * chooses to have displayed in the preferences dialog box.
0104      * This will often be a very similar list to getSearchableAttributes(),
0105      * but due to optional forms of spelling and other situations, it may
0106      * not be exactly the same. Note: The "Dictionary" option will be
0107      * appended to your list at the end.
0108      */
0109     virtual QStringList listDictDisplayOptions(QStringList) const = 0;
0110     /**
0111      * If you want your own dialog to pick preferences for your dict, then override this.
0112      * Leaving it blank will leave your dictionary type without a preferences dialog.
0113      *
0114      * @param config the KConfigSkeleton object that is currently in use
0115      * @param parent the parent widget for your preferences dialog
0116      */
0117     virtual DictionaryPreferenceDialog *preferencesWidget(KConfigSkeleton *config, QWidget *parent = nullptr)
0118     {
0119         Q_UNUSED(parent);
0120         Q_UNUSED(config);
0121         return NULL;
0122     }
0123     /**
0124      * Load information from the KConfigSkeleton that you've setup in
0125      * the above preferences widget.
0126      */
0127     virtual void loadSettings(KConfigSkeleton *)
0128     {
0129     }
0130 
0131     /**
0132      * Returns the name of the dictionary
0133      */
0134     virtual QString getName() const
0135     {
0136         return m_dictionaryName;
0137     }
0138     /**
0139      * Returns the type of files this dictFile object deals with
0140      */
0141     virtual QString getType() const
0142     {
0143         return m_dictionaryType;
0144     }
0145     /**
0146      * Returns the file that this is working with, usually used in the preferences display
0147      */
0148     virtual QString getFile() const
0149     {
0150         return m_dictionaryFile;
0151     }
0152     /**
0153      * Fetch a list of searchable attributes and their codes
0154      */
0155     virtual const QMap<QString, QString> &getSearchableAttributes() const
0156     {
0157         return m_searchableAttributes;
0158     }
0159 
0160 protected:
0161     /**
0162      * Name is the 'primary key' of the list of dictionaries. You will want to
0163      * place this into your Entry objects to identify where they came from
0164      * (fairly important)
0165      */
0166     QString m_dictionaryName;
0167 
0168     /**
0169      * This is mostly a placeholder, but your class will get asked what file
0170      * it is using, so either be sure to put something here, or override
0171      * getFile() and respond with something that will be sensical in a
0172      * dictionary selection dialog box.
0173      */
0174     QString m_dictionaryFile;
0175 
0176     /**
0177      * This MUST BE SET IN THE CONSTRUCTOR. The dictionary class occasionally
0178      * uses this value and it's important for it to be set at anytime after the
0179      * constructor is called. It also must be unique to the dictionary type. If
0180      * relevant, specify dictionary versions here.
0181      */
0182     QString m_dictionaryType;
0183     /**
0184      * This allows the programming user to see a list
0185      * of possible search types (probably through a drop down menu).
0186      * You may also find it useful in your dictFile implementation
0187      * to translate from extended attribute keys into the simpler one or two letter
0188      * code keys. These should take the format of:
0189      * (Kanji Grade => G), (Strokes => S), (Heisig Number => H)
0190      * for a simple example appropriate to kanji.
0191      */
0192     QMap<QString, QString> m_searchableAttributes;
0193 };
0194 
0195 #endif