File indexing completed on 2024-04-28 03:40:31

0001 /***************************************************************************
0002  *   Copyright (C) 2002 by Gunnar Schmi Dt <kmouth@schmi-dt.de             *
0003  *             (C) 2015 by Jeremy Whiting <jpwhiting@kde.org>              *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
0019  ***************************************************************************/
0020 
0021 #ifndef WORDCOMPLETION_H
0022 #define WORDCOMPLETION_H
0023 
0024 #include <KCompletion>
0025 
0026 /**
0027  * This class does completion based on a dictionary of words.
0028  */
0029 class WordCompletion : public KCompletion
0030 {
0031     friend class WordListWidget;
0032     Q_OBJECT
0033 public:
0034     WordCompletion();
0035     ~WordCompletion() override;
0036 
0037     /**
0038      * Returns the names for the available word lists
0039      */
0040     QStringList wordLists();
0041 
0042     /**
0043      * Returns the names for those word lists that contain
0044      * words of a given language.
0045      */
0046     QStringList wordLists(const QString &language);
0047 
0048     /**
0049      * Returns the language of a given word list.
0050      */
0051     QString languageOfWordList(const QString &wordlist);
0052 
0053     /**
0054      * Returns the name of the currently active word list.
0055      */
0056     QString currentWordList();
0057 
0058     /**
0059      * Finds completions to the given text.
0060      */
0061     QString makeCompletion(const QString &) override;
0062 
0063     static bool isConfigured();
0064 
0065     /**
0066      * Adds the words from the given sentence to the list of words.
0067      */
0068     void addSentence(const QString &sentence);
0069 
0070 public Q_SLOTS:
0071     /**
0072      * Re-reads the configuration.
0073      */
0074     void configure();
0075 
0076     /**
0077      * Specify which word list gets used for the actual word completion.
0078      * If there is no word list with the given name the first configured
0079      * list gets used.
0080      * The method returns true if the specified word list was found.
0081      */
0082     bool setWordList(const QString &wordlist);
0083 
0084     /**
0085      * Saves the added words to disk.
0086      */
0087     void save();
0088 
0089 Q_SIGNALS:
0090     void wordListsChanged(const QStringList &wordLists);
0091     void currentListChanged(const QString &wordList);
0092 
0093 private:
0094     class WordCompletionPrivate;
0095     WordCompletionPrivate *d;
0096 };
0097 
0098 #endif // KURLCOMPLETION_H