File: spellerutility.h

package info (click to toggle)
texstudio 2.3%2Bdebian-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 20,992 kB
  • sloc: cpp: 61,734; ansic: 4,300; xml: 726; sh: 125; makefile: 25
file content (84 lines) | stat: -rw-r--r-- 2,586 bytes parent folder | download
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
/***************************************************************************
 *   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"

#include "hunspell/hunspell.hxx"
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 reloadDictionary();
private:
	SpellerUtility(QString name);
	~SpellerUtility();
	bool loadDictionary(QString dic, QString ignoreFilePrefix);
	void unload();

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

class SpellerManager: public QObject {
	Q_OBJECT
public:
	SpellerManager();
	~SpellerManager();
	void setIgnoreFilePrefix(const QString &ignoreFilePrefix);
	QString dictPath();
	void setDictPath(const QString &dictPath);
	QStringList availableDicts();
	static QStringList dictNamesForDir(const QString &dir);

	bool hasSpeller(const QString &name);
	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:
	QString m_dictPath;
	QString ignoreFilePrefix;
	QHash<QString, SpellerUtility *> dicts;
	QHash<QString, QString> dictFiles;
	SpellerUtility *emptySpeller;
	QString mDefaultSpellerName;
};


#endif