API change and refactoring. Major breakage. Best to stay out of kdeaccessibility...
[kdeaccessibility.git] / kttsd / filters / xmltransformer / xmltransformerproc.h
blob6917f85f51d8b88036f19039bb379015392542b8
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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 ******************************************************************************/
24 #ifndef _XMLTRANSFORMERPROC_H_
25 #define _XMLTRANSFORMERPROC_H_
27 // Qt includes.
28 #include <QObject>
29 #include <QStringList>
31 // KTTS includes.
32 #include "filterproc.h"
34 class KProcess;
36 class XmlTransformerProc : virtual public KttsFilterProc
38 Q_OBJECT
40 public:
41 /**
42 * Constructor.
44 XmlTransformerProc( QObject *parent, const QStringList &args = QStringList() );
46 /**
47 * Destructor.
49 virtual ~XmlTransformerProc();
51 /**
52 * Initialize the filter.
53 * @param config Settings object.
54 * @param configGroup Settings Group.
55 * @return False if filter is not ready to filter.
57 * Note: The parameters are for reading from kttsdrc file. Plugins may wish to maintain
58 * separate configuration files of their own.
60 virtual bool init(KConfig *config, const QString &configGroup);
62 /**
63 * Returns True if the plugin supports asynchronous processing,
64 * i.e., supports asyncConvert method.
65 * @return True if this plugin supports asynchronous processing.
67 * If the plugin returns True, it must also implement @ref getState .
68 * It must also emit @ref filteringFinished when filtering is completed.
69 * If the plugin returns True, it must also implement @ref stopFiltering .
70 * It must also emit @ref filteringStopped when filtering has been stopped.
72 virtual bool supportsAsync();
74 /**
75 * Convert input, returning output.
76 * @param inputText Input text.
77 * @param talkerCode TalkerCode structure for the talker that KTTSD intends to
78 * use for synthing the text. Useful for extracting hints about
79 * how to filter the text. For example, languageCode.
80 * @param appId The DCOP appId of the application that queued the text.
81 * Also useful for hints about how to do the filtering.
83 virtual QString convert(const QString& inputText, TalkerCode* talkerCode, const QString& appId);
85 /**
86 * Convert input. Runs asynchronously.
87 * @param inputText Input text.
88 * @param talkerCode TalkerCode structure for the talker that KTTSD intends to
89 * use for synthing the text. Useful for extracting hints about
90 * how to filter the text. For example, languageCode.
91 * @param appId The DCOP appId of the application that queued the text.
92 * Also useful for hints about how to do the filtering.
93 * @return False if the filter cannot perform the conversion.
95 * When conversion is completed, emits signal @ref filteringFinished. Calling
96 * program may then call @ref getOutput to retrieve converted text. Calling
97 * program must call @ref ackFinished to acknowledge the conversion.
99 virtual bool asyncConvert(const QString& inputText, TalkerCode* talkerCode, const QString& appId);
102 * Waits for a previous call to asyncConvert to finish.
104 virtual void waitForFinished();
107 * Returns the state of the Filter.
109 virtual int getState();
112 * Returns the filtered output.
114 virtual QString getOutput();
117 * Acknowledges the finished filtering.
119 virtual void ackFinished();
122 * Stops filtering. The filteringStopped signal will emit when filtering
123 * has in fact stopped and state returns to fsIdle;
125 virtual void stopFiltering();
128 * Did this filter do anything? If the filter returns the input as output
129 * unmolested, it should return False when this method is called.
131 virtual bool wasModified();
133 private slots:
134 void slotProcessExited(KProcess*);
135 void slotReceivedStdout(KProcess* proc, char* buffer, int buflen);
136 void slotReceivedStderr(KProcess* proc, char* buffer, int buflen);
138 private:
139 // Process output when xsltproc exits.
140 void processOutput();
142 // If not empty, only apply to text queued by an applications containing one of these strings.
143 QStringList m_appIdList;
144 // If not empty, only apply to XML that has the specified root element.
145 QStringList m_rootElementList;
146 // If not empty, only apply to XML that has the specified DOCTYPE spec.
147 QStringList m_doctypeList;
148 // The text that is being filtered.
149 QString m_text;
150 // Processing state.
151 int m_state;
152 // xsltproc process.
153 KProcess* m_xsltProc;
154 // Input and Output filenames.
155 QString m_inFilename;
156 QString m_outFilename;
157 // User's name for the filter.
158 QString m_UserFilterName;
159 // XSLT file.
160 QString m_xsltFilePath;
161 // Path to xsltproc processor.
162 QString m_xsltprocPath;
163 // Did this filter modify the text?
164 bool m_wasModified;
167 #endif // _XMLTRANSFORMERPROC_H_