Warning--
[kdeaccessibility.git] / kttsd / filters / xmltransformer / xmltransformerproc.h
blob5d68ee72ca62ea47af90eb2520553938bb38e688
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Generic XML Transformation Filter Processing class.
3 -------------------
4 Copyright:
5 (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
6 -------------------
7 Original author: Gary Cramblitt <garycramblitt@comcast.net>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.
22 ******************************************************************************/
24 #ifndef _XMLTRANSFORMERPROC_H_
25 #define _XMLTRANSFORMERPROC_H_
27 // Qt includes.
28 #include <qobject.h>
29 #include <qstringlist.h>
30 //Added by qt3to4:
31 #include <Q3CString>
33 // KTTS includes.
34 #include "filterproc.h"
36 class KProcess;
38 class XmlTransformerProc : virtual public KttsFilterProc
40 Q_OBJECT
42 public:
43 /**
44 * Constructor.
46 XmlTransformerProc( QObject *parent, const char *name, const QStringList &args = QStringList() );
48 /**
49 * Destructor.
51 virtual ~XmlTransformerProc();
53 /**
54 * Initialize the filter.
55 * @param config Settings object.
56 * @param configGroup Settings Group.
57 * @return False if filter is not ready to filter.
59 * Note: The parameters are for reading from kttsdrc file. Plugins may wish to maintain
60 * separate configuration files of their own.
62 virtual bool init(KConfig *config, const QString &configGroup);
64 /**
65 * Returns True if the plugin supports asynchronous processing,
66 * i.e., supports asyncConvert method.
67 * @return True if this plugin supports asynchronous processing.
69 * If the plugin returns True, it must also implement @ref getState .
70 * It must also emit @ref filteringFinished when filtering is completed.
71 * If the plugin returns True, it must also implement @ref stopFiltering .
72 * It must also emit @ref filteringStopped when filtering has been stopped.
74 virtual bool supportsAsync();
76 /**
77 * Convert input, returning output.
78 * @param inputText Input text.
79 * @param talkerCode TalkerCode structure for the talker that KTTSD intends to
80 * use for synthing the text. Useful for extracting hints about
81 * how to filter the text. For example, languageCode.
82 * @param appId The DCOP appId of the application that queued the text.
83 * Also useful for hints about how to do the filtering.
85 virtual QString convert(const QString& inputText, TalkerCode* talkerCode, const Q3CString& appId);
87 /**
88 * Convert input. Runs asynchronously.
89 * @param inputText Input text.
90 * @param talkerCode TalkerCode structure for the talker that KTTSD intends to
91 * use for synthing the text. Useful for extracting hints about
92 * how to filter the text. For example, languageCode.
93 * @param appId The DCOP appId of the application that queued the text.
94 * Also useful for hints about how to do the filtering.
95 * @return False if the filter cannot perform the conversion.
97 * When conversion is completed, emits signal @ref filteringFinished. Calling
98 * program may then call @ref getOutput to retrieve converted text. Calling
99 * program must call @ref ackFinished to acknowledge the conversion.
101 virtual bool asyncConvert(const QString& inputText, TalkerCode* talkerCode, const Q3CString& appId);
104 * Waits for a previous call to asyncConvert to finish.
106 virtual void waitForFinished();
109 * Returns the state of the Filter.
111 virtual int getState();
114 * Returns the filtered output.
116 virtual QString getOutput();
119 * Acknowledges the finished filtering.
121 virtual void ackFinished();
124 * Stops filtering. The filteringStopped signal will emit when filtering
125 * has in fact stopped and state returns to fsIdle;
127 virtual void stopFiltering();
130 * Did this filter do anything? If the filter returns the input as output
131 * unmolested, it should return False when this method is called.
133 virtual bool wasModified();
135 private slots:
136 void slotProcessExited(KProcess*);
137 void slotReceivedStdout(KProcess* proc, char* buffer, int buflen);
138 void slotReceivedStderr(KProcess* proc, char* buffer, int buflen);
140 private:
141 // Process output when xsltproc exits.
142 void processOutput();
144 // If not empty, only apply to text queued by an applications containing one of these strings.
145 QStringList m_appIdList;
146 // If not empty, only apply to XML that has the specified root element.
147 QStringList m_rootElementList;
148 // If not empty, only apply to XML that has the specified DOCTYPE spec.
149 QStringList m_doctypeList;
150 // The text that is being filtered.
151 QString m_text;
152 // Processing state.
153 int m_state;
154 // xsltproc process.
155 KProcess* m_xsltProc;
156 // Input and Output filenames.
157 QString m_inFilename;
158 QString m_outFilename;
159 // User's name for the filter.
160 QString m_UserFilterName;
161 // XSLT file.
162 QString m_xsltFilePath;
163 // Path to xsltproc processor.
164 QString m_xsltprocPath;
165 // Did this filter modify the text?
166 bool m_wasModified;
169 #endif // _XMLTRANSFORMERPROC_H_