1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Dialog to allow user to add a new Talker by selecting a language and synthesizer
3 (button). Uses addtalkerwidget.ui.
6 (C) 2004 by Gary Cramblitt <garycramblitt@comcast.net>
8 Original author: Gary Cramblitt <garycramblitt@comcast.net>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************************************************************************/
26 #include "addtalker.h"
29 #include <QtGui/QRadioButton>
30 #include <QtGui/QDialog>
33 #include <kcombobox.h>
38 AddTalker::AddTalker(SynthToLangMap synthToLangMap
, QWidget
* parent
, const char* name
, Qt::WFlags fl
)
47 setSynthToLangMap(synthToLangMap
);
52 // Default to user's desktop language.
53 QString languageCode
= KGlobal::locale()->defaultLanguage();
54 // If there is not a synth that supports the locale, try stripping country code.
55 if (!m_langToSynthMap
.contains(languageCode
))
61 KGlobal::locale()->splitLocale(languageCode
, langAlpha
, countryCode
, modifier
, charSet
);
62 languageCode
= langAlpha
;
64 // If there is still not a synth that supports the language code, default to "other".
65 if (!m_langToSynthMap
.contains(languageCode
)) languageCode
= "other";
67 // Select the language in the language combobox.
68 QString language
= languageCodeToLanguage(languageCode
);
69 languageSelection
->setCurrentItem(language
, false);
74 // Connect widgets to slots.
75 connect(languageRadioButton
, SIGNAL(clicked()), this, SLOT(applyFilter()));
76 connect(synthesizerRadioButton
, SIGNAL(clicked()), this, SLOT(applyFilter()));
77 connect(languageSelection
, SIGNAL(activated(int)), this, SLOT(applyFilter()));
78 connect(synthesizerSelection
, SIGNAL(activated(int)), this, SLOT(applyFilter()));
81 AddTalker::~AddTalker()
86 * Returns user's chosen language code.
88 QString
AddTalker::getLanguageCode()
90 return m_languageToLanguageCodeMap
[languageSelection
->currentText()];
94 * Returns user's chosen synthesizer.
96 QString
AddTalker::getSynthesizer() { return synthesizerSelection
->currentText(); }
98 // Set the synthesizer-to-languages map.
99 // @param synthToLang QMap of supported language codes indexed by synthesizer.
100 void AddTalker::setSynthToLangMap(SynthToLangMap synthToLangMap
)
102 m_synthToLangMap
= synthToLangMap
;
103 // "Invert" the map, i.e., map language codes to synthesizers.
104 QStringList synthList
= m_synthToLangMap
.keys();
105 const int synthListCount
= synthList
.count();
106 for (int synthNdx
=0; synthNdx
< synthListCount
; ++synthNdx
)
108 QString synth
= synthList
[synthNdx
];
109 QStringList languageCodeList
= m_synthToLangMap
[synth
];
110 const int languageCodeListCount
= languageCodeList
.count();
111 for (int langNdx
=0; langNdx
< languageCodeListCount
; ++langNdx
)
113 QString languageCode
= languageCodeList
[langNdx
];
114 QStringList synthesizerList
= m_langToSynthMap
[languageCode
];
115 synthesizerList
.append(synth
);
116 m_langToSynthMap
[languageCode
] = synthesizerList
;
119 // Fill language to language code map.
120 QStringList languageCodeList
= m_langToSynthMap
.keys();
121 const int languageCodeListCount
= languageCodeList
.count();
122 for (int ndx
= 0; ndx
< languageCodeListCount
; ++ndx
)
124 QString languageCode
= languageCodeList
[ndx
];
125 QString language
= languageCodeToLanguage(languageCode
);
126 m_languageToLanguageCodeMap
[language
] = languageCode
;
130 // Converts a language code plus optional country code to language description.
131 QString
AddTalker::languageCodeToLanguage(const QString
&languageCode
)
138 if (languageCode
== "other")
139 language
= i18n("Other");
142 KGlobal::locale()->splitLocale(languageCode
, langAlpha
, countryCode
, modifier
, charSet
);
143 language
= KGlobal::locale()->languageCodeToName(langAlpha
);
145 if (!countryCode
.isEmpty())
146 language
+= " (" + KGlobal::locale()->countryCodeToName(countryCode
) + ')';
150 // Based on user's radio button selection, filters choices for language or synthesizer
151 // comboboxes based on what is selected in the other combobox.
152 void AddTalker::applyFilter()
154 if (languageRadioButton
->isChecked())
156 // Get current language.
157 QString language
= languageSelection
->currentText();
158 // Fill language combobox will all possible languages.
159 languageSelection
->clear();
160 QStringList languageCodeList
= m_langToSynthMap
.keys();
161 const int languageCodeListCount
= languageCodeList
.count();
162 QStringList languageList
;
163 for (int ndx
=0; ndx
< languageCodeListCount
; ++ndx
)
165 languageList
.append(languageCodeToLanguage(languageCodeList
[ndx
]));
168 for (int ndx
=0; ndx
< languageCodeListCount
; ++ndx
)
170 languageSelection
->addItem(languageList
[ndx
]);
172 // Re-select user's selection.
173 languageSelection
->setCurrentItem(language
, false);
174 // Get current language selection.
175 language
= languageSelection
->currentText();
176 // Map current language to language code.
177 QString languageCode
= m_languageToLanguageCodeMap
[language
];
178 // Get list of synths that support this language code.
179 QStringList synthList
= m_langToSynthMap
[languageCode
];
180 // Get current user's synth selection.
181 QString synth
= synthesizerSelection
->currentText();
182 // Fill synthesizer combobox.
183 synthesizerSelection
->clear();
185 const int synthListCount
= synthList
.count();
186 for (int ndx
=0; ndx
< synthListCount
; ++ndx
)
188 synthesizerSelection
->addItem(synthList
[ndx
]);
190 // Re-select user's selection.
191 synthesizerSelection
->setCurrentItem(synth
, false);
195 // Get current synth selection.
196 QString synth
= synthesizerSelection
->currentText();
197 // Fill synthesizer combobox with all possible synths.
198 synthesizerSelection
->clear();
199 QStringList synthList
= m_synthToLangMap
.keys();
201 const int synthListCount
= synthList
.count();
202 for (int ndx
=0; ndx
< synthListCount
; ++ndx
)
204 synthesizerSelection
->addItem(synthList
[ndx
]);
206 // Re-select user's synthesizer.
207 synthesizerSelection
->setCurrentItem(synth
, false);
208 // Get current synth selection.
209 synth
= synthesizerSelection
->currentText();
210 // Get list of supported language codes.
211 QStringList languageCodeList
= m_synthToLangMap
[synth
];
212 // Get current user's language selection.
213 QString language
= languageSelection
->currentText();
214 // Fill language combobox with language descriptions.
215 languageSelection
->clear();
216 const int languageCodeListCount
= languageCodeList
.count();
217 QStringList languageList
;
218 for (int ndx
=0; ndx
< languageCodeListCount
; ++ndx
)
220 languageList
.append(languageCodeToLanguage(languageCodeList
[ndx
]));
223 for (int ndx
=0; ndx
< languageCodeListCount
; ++ndx
)
225 languageSelection
->addItem(languageList
[ndx
]);
227 // Re-select user's language selection.
228 languageSelection
->setCurrentItem(language
, false);
232 #include "addtalker.moc"