File: spellerutility.h

package info (click to toggle)
texstudio 2.11.2%2Bdebian-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 41,292 kB
  • ctags: 12,405
  • sloc: cpp: 93,072; xml: 10,217; ansic: 4,153; sh: 145; makefile: 56
file content (105 lines) | stat: -rw-r--r-- 3,033 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/***************************************************************************
 *   copyright       : (C) 2008 by Benito van der Zander                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SPELLERUTILITY_H
#define SPELLERUTILITY_H

#include "mostQtHeaders.h"

#ifdef HUNSPELL_STATIC
#include "hunspell/hunspell.hxx"
#else
#include <hunspell.hxx>
#endif

class SpellerUtility: public QObject {
	Q_OBJECT

public:
	friend class SpellerManager;
	void addToIgnoreList(QString toIgnore);
	void removeFromIgnoreList(QString toIgnore);
	QStringListModel* ignoreListModel();

	bool check(QString word);
	QStringList suggest(QString word);

	QString name() {return mName;}
	QString getCurrentDic() {return currentDic;}

	static int spellcheckErrorFormat;

signals:
	void aboutToDelete();
	void dictionaryLoaded();
	void ignoredWordAdded(const QString& newlyIgnoredWord);

private:
	SpellerUtility(QString name);
	~SpellerUtility();
	bool loadDictionary(QString dic, QString ignoreFilePrefix);
	void saveIgnoreList();
	void unload();

	QString mName;
	QString mLastError;
	QString currentDic, ignoreListFileName, spell_encoding;
	Hunspell * pChecker;
	QTextCodec *spellCodec;
	QHash<QString, bool> checkCache;
	QLinkedList<QString> checkCacheInsertion;
	QStringList ignoredWordList;
	QSet<QString> ignoredWords;
	QStringListModel ignoredWordsModel;
};


class SpellerManager: public QObject {
	Q_OBJECT

public:
	SpellerManager();
	~SpellerManager();

	static bool isOxtDictionary(const QString &fileName);
	static bool importDictionary(const QString &fileName, const QString &targetDir);

	void setIgnoreFilePrefix(const QString &ignoreFilePrefix);
	QStringList dictPaths() {return m_dictPaths;}
	void setDictPaths(const QStringList &dictPaths);
	void scanForDictionaries(const QString &path, bool scansubdirs=true);

	QStringList availableDicts();

	bool hasSpeller(const QString &name);
	bool hasSimilarSpeller(const QString &name, QString &bestName);
	SpellerUtility *getSpeller(QString name);

	QString defaultSpellerName();
	bool setDefaultSpeller(const QString &name);
	void unloadAll();

	static QString prettyName(const QString &name);

signals:
	void dictPathChanged();
	void defaultSpellerChanged();

private:
	QStringList m_dictPaths;
	QString ignoreFilePrefix;
	QHash<QString, SpellerUtility *> dicts;
	QHash<QString, QString> dictFiles;
	SpellerUtility *emptySpeller;
	QString mDefaultSpellerName;
};


#endif