summaryrefslogtreecommitdiffstats
path: root/scribus/plugins/tools/spellcheck/aspellpluginimpl.h
blob: 25a76bc483bbca18c9e6575e180f826794da0557 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef ASPELLPLUGINIMPL_H
#define ASPELLPLUGINIMPL_H

// ISO C++ include files
#include <string>        // For replacement word from aspell
#include <vector>        // For array of replacements from aspell
// QT include files
#include <QRegExp>
#include <QString>
#include <QStringList>
#include <QHash>
// Scribus include files
#include "scribusdoc.h"           // For ScribusDoc
#include "scribus.h"              // For ScribusMainWindow
#include "selection.h"            // Item selected
#include "prefsfile.h"            // Stored plugin preferences
#include "prefsmanager.h"         // Preferences manager
// Local include files
#include "ui_aspellpluginbase.h"  // For GUI from QT4 designer
// #include "donedlgimpl.h"          // For spell-checking done dialog
#include "suggest.h"              // For aspell interface class

/*!
\class AspellPluginImpl
\author Gora Mohanty <gora@srijan.in>
\brief Implementation of plugin. GUI part is derived from AspellPluginBase class, as aspellpluginbase.{cpp,h} get overwritten by uic. Interface to aspell uses Speller::Aspell::Suggest
 */
class AspellPluginImpl : public QDialog, private Ui::AspellPluginBase
{
	Q_OBJECT
private:
	/*! \brief Context name for storing preferences */
	static const char* kDEF_CONTEXT;
	/*! Formatted string for aspell dictionary entry: Form of <name>--<lang>--<jargon>--<size> */
	static const QString kDEF_ASPELL_ENTRY;
	/*! \brief Aspell interface object. */
	Speller::Aspell::Suggest* fsuggest;
	/*! \brief Scribus preferences object. */
	PrefsContext* fprefs;
	/*! \brief Language for aspell dictionary. */
	QString   flang;
	/*! \brief Jargon for aspell dictionary. */
	QString   fjargon;
	/*! \brief Character encoding for words. */
	QString   fencoding;
	/*! \brief Formatted string for aspell dictionary entry: Form of <name>--<lang>--<jargon>--<size> */
	QString   fentry;
	/*! \brief Pointer to current document. */
	ScribusDoc* fdoc;
	//! \brief Flag is is the document changed
	bool m_docIsChanged;
#if 0
	// HACK: this is not used anywhere - PV
	/*! \brief Structure to keep track of number of changes made. */
	struct Changes
	{
		/*! brief Number of words changed in this frame. */
		uint fnwords;
		/*! brief Number of words changed in all. */
		uint fntot;
		/*! brief Number of frames changed. */
		uint fnframes;
		/*!
		  \author Gora Mohanty <gora@srijan.in>
		  \brief Constructor for counts of items changes
		  \param nwords: No. of words changed in this frame.
		  \param ntot: Total no. of words changed.
		  \param nframes: No. of frames changed.
		  \retval None
		*/
		Changes(uint nwords=0, uint ntot=0, uint nframes=0) :
			fnwords(nwords), fntot(ntot), fnframes(nframes) {}
	} fnchanges;
#endif
	/*! \brief Extracted string of text from one frame. */
	QString fcontent;
	/*! \brief Position in 'fcontent' of word being spell-checked. */
	uint fpos;
	QHash<QString, QString> rememberedWords;
	/*! \brief Index in 'fcontent' of word being spell-checked. */
	int fidx;
	/*! \brief Word currently being spell-checked. */
	QStringList fwordlist;
	/*! \brief Pointer to current frame. */
	PageItem* fFrame;
	//! \brief Internal error message
	QString m_errorMessage;

protected:
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Initializes the position in the current text, sets the current word, and starts spell-checking.
	  \param None
	  \retval None
	*/
	void checkText();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Skips to the beginning of the next word in 'fcontent', the text being spell-checked.
	  \param None
	  \retval None
	*/
	void nextWord();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Save user preferences
	  \param language: Language for aspell dictionary
	  \param jargon: Jargon for aspell dictionary
	  \param encoding: Encoding for aspell dictionary
	  \retval None
	*/
	void setPreferences(const QString& lang,
			    const QString& jargon,
			    const QString& encoding=Speller::Aspell::Suggest::kDEF_ENCODING,
			    const QString& entry=kDEF_ASPELL_ENTRY);
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Retrieve saved user preferences: language, jargon, encoding.
	  \param None
	  \retval None
	*/
	void getPreferences();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Activates spell-checking GUI elements in spell-checking tab, i.e., everything except combo box at top
	  \param None
	  \retval None
	*/
	void activateSpellGUI(bool active);
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Base method to spell-check text in current frame.
	  \param None
	  \retval None
	*/
	void parseItem();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Spell-check selected frames in the page
	  \param None
	  \retval None
	*/
        void parseSelection();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Called when spell-checking is completed. Pops up an information dialog.
	  \param None
	  \retval None
	*/
	void spellCheckDone();

	/*! \brief Sets the dict configuration based on given dictFullName
	or in the constructor. See on_flistDicts_activated().
	\param dictFullName a full dictionary name taken e.g. from flistDicts.
	\author Petr Vanek <petr@scribus.info>
	*/
	bool handleSpellConfig(const QString & dictFullName);

public:
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Constructor for spell-checking plugin implementation.
	  \param doc: Scribus doc
	  \param parent: Parent window that this is a child of.
	  \retval None
	*/
	AspellPluginImpl(ScribusDoc* doc, QWidget* parent=NULL);
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Destructor for spell-checking plugin implementation.
	  \param None
	  \retval None
	*/
	~AspellPluginImpl();

	/*! \brief Returns a error message for caller.
	It should disable the plugin then
	*/
	QString errorMessage() { return m_errorMessage; } ;

public slots:
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when the "Close" button is clicked. Makes any pending replacements, and closes spell-check window.
	  \param None
	  \retval None
	*/
	void on_fcloseBtn_clicked();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when the "Change" button is clicked. Replaces the word being checked with the currently selected replacement.
	  \param None
	  \retval None
	*/
	void on_fchangeBtn_clicked();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when the "Change All" button is clicked. Replaces all occurrences of the word being checked with the currently selected replacement.
	  \param None
	  \retval None
	*/
	void on_fchangeAllBtn_clicked();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when the "Skip" button is clicked. Skips the word currently being spell-checked.
	  \param None
	  \retval None
	*/
	void on_fskipBtn_clicked();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when the "Skip All" button is clicked. Skips all occurences of the word currently being spell-checked.
	  \param None
	  \retval None
	*/
	void on_fskipAllBtn_clicked();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when the "Add word" button is clicked. Adds current suggestion to user's personal directory.
	  \param None
	  \retval None
	*/
	void on_faddWordBtn_clicked();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when an item in the list of aspell suggestions is highlighted. Changes the current word (in the text edit box).
	  \param None
	  \retval None
	*/
	void on_flistReplacements_itemActivated();
	/*!
	  \author Gora Mohanty <gora@srijan.in>
	  \brief Slot: Called when an item in the list of available aspell dictionaries is selected. Resets aspell dictionary to selected one.
	  \param None
	  \retval None
	*/
	void on_flistDicts_activated();

protected slots:
    void languageChange();

};
#endif  // #ifndef ASPELLPLUGINIMPL_H
//@@@@@@@@@@@@@@@@@@@@@@@@@ END OF FILE @@@@@@@@@@@@@@@@@@@@@@@@@