1 /***************************************************** vim:set ts=4 sw=4 sts=4:
3 A dialog for user to select a Talker, either by specifying
4 selected Talker attributes, or by specifying all attributes
5 of an existing configured Talker.
8 (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
10 Original author: Gary Cramblitt <garycramblitt@comcast.net>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 ******************************************************************************/
27 #include "selecttalkerdlg.h"
30 #include <QtGui/QCheckBox>
31 #include <QtGui/QRadioButton>
32 #include <QtGui/QTableWidget>
33 #include <QtGui/QHeaderView>
37 #include <kcombobox.h>
38 #include <kpushbutton.h>
39 #include <klineedit.h>
42 #include <kservicetypetrader.h>
46 #include "talkerlistmodel.h"
47 #include "selectlanguagedlg.h"
48 #include "selecttalkerdlg.moc"
50 SelectTalkerDlg::SelectTalkerDlg(
53 const QString
& caption
,
54 const QString
& talkerCode
,
55 bool runningTalkers
) :
61 setButtons(KDialog::Ok
|KDialog::Cancel
);
62 m_widget
= new Ui::SelectTalkerWidget();
63 QWidget
* w
= new QWidget();
64 m_widget
->setupUi( w
);
65 m_talkerListModel
= new TalkerListModel();
66 m_widget
->talkersView
->setModel(m_talkerListModel
);
69 m_runningTalkers
= runningTalkers
;
70 m_talkerCode
= TalkerCode( talkerCode
, false );
73 KComboBox
* cb
= m_widget
->genderComboBox
;
74 cb
->addItem( QString() );
75 cb
->addItem( TalkerCode::translatedGender("male") );
76 cb
->addItem( TalkerCode::translatedGender("female") );
77 cb
->addItem( TalkerCode::translatedGender("neutral") );
79 cb
= m_widget
->volumeComboBox
;
80 cb
->addItem( QString() );
81 cb
->addItem( TalkerCode::translatedVolume("medium") );
82 cb
->addItem( TalkerCode::translatedVolume("loud") );
83 cb
->addItem( TalkerCode::translatedVolume("soft") );
85 cb
= m_widget
->rateComboBox
;
86 cb
->addItem( QString() );
87 cb
->addItem( TalkerCode::translatedRate("medium") );
88 cb
->addItem( TalkerCode::translatedRate("fast") );
89 cb
->addItem( TalkerCode::translatedRate("slow") );
91 cb
= m_widget
->synthComboBox
;
92 cb
->addItem( QString() );
93 KService::List offers
= KServiceTypeTrader::self()->query("KTTSD/SynthPlugin");
94 for(int i
=0; i
< offers
.count() ; ++i
)
95 cb
->addItem(offers
[i
]->name());
97 // Fill List View with list of Talkers.
98 KConfig
config("kttsdrc");
99 m_talkerListModel
->loadTalkerCodesFromConfig(&config
);
101 // Set initial radio button state.
102 if ( talkerCode
.isEmpty() )
103 m_widget
->useDefaultRadioButton
->setChecked(true);
107 if (talkerCode
== TalkerCode::normalizeTalkerCode(talkerCode
, dummy
))
108 m_widget
->useSpecificTalkerRadioButton
->setChecked(true);
110 m_widget
->useClosestMatchRadioButton
->setChecked(true);
113 applyTalkerCodeToControls();
114 enableDisableControls();
116 connect(m_widget
->useDefaultRadioButton
, SIGNAL(clicked()),
117 this, SLOT(configChanged()));
118 connect(m_widget
->useClosestMatchRadioButton
, SIGNAL(clicked()),
119 this, SLOT(configChanged()));
120 connect(m_widget
->useSpecificTalkerRadioButton
, SIGNAL(clicked()),
121 this, SLOT(configChanged()));
123 connect(m_widget
->languageBrowseButton
, SIGNAL(clicked()),
124 this, SLOT(slotLanguageBrowseButton_clicked()));
126 connect(m_widget
->synthComboBox
, SIGNAL(activated(const QString
&)),
127 this, SLOT(configChanged()));
128 connect(m_widget
->genderComboBox
, SIGNAL(activated(const QString
&)),
129 this, SLOT(configChanged()));
130 connect(m_widget
->volumeComboBox
, SIGNAL(activated(const QString
&)),
131 this, SLOT(configChanged()));
132 connect(m_widget
->rateComboBox
, SIGNAL(activated(const QString
&)),
133 this, SLOT(configChanged()));
135 connect(m_widget
->synthCheckBox
, SIGNAL(toggled(bool)),
136 this, SLOT(configChanged()));
137 connect(m_widget
->genderCheckBox
, SIGNAL(toggled(bool)),
138 this, SLOT(configChanged()));
139 connect(m_widget
->volumeCheckBox
, SIGNAL(toggled(bool)),
140 this, SLOT(configChanged()));
141 connect(m_widget
->rateCheckBox
, SIGNAL(toggled(bool)),
142 this, SLOT(configChanged()));
144 connect(m_widget
->talkersView
, SIGNAL(clicked()),
145 this, SLOT(slotTalkersView_clicked()));
147 m_widget
->talkersView
->setMinimumHeight( 120 );
150 SelectTalkerDlg::~SelectTalkerDlg() { }
152 QString
SelectTalkerDlg::getSelectedTalkerCode()
154 return m_talkerCode
.getTalkerCode();
157 QString
SelectTalkerDlg::getSelectedTranslatedDescription()
159 return m_talkerCode
.getTranslatedDescription();
162 void SelectTalkerDlg::slotLanguageBrowseButton_clicked()
164 SelectLanguageDlg
* dlg
= new SelectLanguageDlg(
166 i18n("Select Language"),
167 QStringList(m_talkerCode
.fullLanguageCode()),
168 SelectLanguageDlg::SingleSelect
,
169 SelectLanguageDlg::BlankAllowed
);
170 int dlgResult
= dlg
->exec();
171 if (dlgResult
== QDialog::Accepted
) {
172 m_talkerCode
.setFullLanguageCode(dlg
->selectedLanguageCode());
173 QString language
= dlg
->selectedLanguage();
174 m_widget
->languageLabel
->setText(language
);
175 m_widget
->languageCheckBox
->setChecked(!language
.isEmpty());
181 void SelectTalkerDlg::slotTalkersView_clicked()
183 QModelIndex modelIndex
= m_widget
->talkersView
->currentIndex();
184 if (!modelIndex
.isValid()) return;
185 if (!m_widget
->useSpecificTalkerRadioButton
->isChecked()) return;
189 void SelectTalkerDlg::configChanged()
191 applyControlsToTalkerCode();
192 applyTalkerCodeToControls();
193 enableDisableControls();
196 void SelectTalkerDlg::applyTalkerCodeToControls()
198 bool preferred
= false;
199 QString code
= m_talkerCode
.getTalkerCode();
201 // TODO: Need to display translated Synth names.
202 KttsUtils::setCbItemFromText(m_widget
->synthComboBox
,
203 TalkerCode::stripPrefer( m_talkerCode
.plugInName(), preferred
) );
204 m_widget
->synthCheckBox
->setEnabled( !m_talkerCode
.plugInName().isEmpty() );
205 m_widget
->synthCheckBox
->setChecked( preferred
);
207 KttsUtils::setCbItemFromText(m_widget
->genderComboBox
,
208 TalkerCode::translatedGender( TalkerCode::stripPrefer( m_talkerCode
.gender(), preferred
) ) );
209 m_widget
->genderCheckBox
->setEnabled( !m_talkerCode
.gender().isEmpty() );
210 m_widget
->genderCheckBox
->setChecked( preferred
);
212 KttsUtils::setCbItemFromText(m_widget
->volumeComboBox
,
213 TalkerCode::translatedVolume( TalkerCode::stripPrefer( m_talkerCode
.volume(), preferred
) ) );
214 m_widget
->volumeCheckBox
->setEnabled( !m_talkerCode
.volume().isEmpty() );
215 m_widget
->volumeCheckBox
->setChecked( preferred
);
217 KttsUtils::setCbItemFromText(m_widget
->rateComboBox
,
218 TalkerCode::translatedRate( TalkerCode::stripPrefer( m_talkerCode
.rate(), preferred
) ) );
219 m_widget
->rateCheckBox
->setEnabled( !m_talkerCode
.rate().isEmpty() );
220 m_widget
->rateCheckBox
->setChecked( preferred
);
222 // Select closest matching specific Talker.
223 const TalkerCode::TalkerCodeList talkers
= m_talkerListModel
->datastore();
224 int talkerIndex
= TalkerCode::findClosestMatchingTalker(talkers
, m_talkerCode
.getTalkerCode(), false);
225 m_widget
->talkersView
->setCurrentIndex(m_talkerListModel
->index(talkerIndex
, 0));
228 void SelectTalkerDlg::applyControlsToTalkerCode()
230 if ( m_widget
->useDefaultRadioButton
->isChecked() )
231 m_talkerCode
= TalkerCode(QString(), false);
232 else if ( m_widget
->useClosestMatchRadioButton
->isChecked() )
234 // Language already stored in talker code.
236 QString t
= m_widget
->synthComboBox
->currentText();
237 if ( !t
.isEmpty() && m_widget
->synthCheckBox
->isChecked() ) t
.prepend("*");
238 m_talkerCode
.setPlugInName( t
);
240 t
= TalkerCode::untranslatedGender( m_widget
->genderComboBox
->currentText() );
241 if ( !t
.isEmpty() && m_widget
->genderCheckBox
->isChecked() ) t
.prepend("*");
242 m_talkerCode
.setGender( t
);
244 t
= TalkerCode::untranslatedVolume( m_widget
->volumeComboBox
->currentText() );
245 if ( !t
.isEmpty() && m_widget
->volumeCheckBox
->isChecked() ) t
.prepend("*");
246 m_talkerCode
.setVolume( t
);
248 t
= TalkerCode::untranslatedRate( m_widget
->rateComboBox
->currentText() );
249 if ( !t
.isEmpty() && m_widget
->rateCheckBox
->isChecked() ) t
.prepend("*");
250 m_talkerCode
.setRate( t
);
252 else if (m_widget
->useSpecificTalkerRadioButton
->isChecked() )
254 QModelIndex talkerIndex
= m_widget
->talkersView
->currentIndex();
255 if (talkerIndex
.isValid())
256 m_talkerCode
= m_talkerListModel
->getRow(talkerIndex
.row());
260 void SelectTalkerDlg::enableDisableControls()
262 bool enableClosest
= ( m_widget
->useClosestMatchRadioButton
->isChecked() );
263 bool enableSpecific
= ( m_widget
->useSpecificTalkerRadioButton
->isChecked() );
264 m_widget
->closestMatchGroupBox
->setEnabled( enableClosest
);
265 m_widget
->talkersView
->setEnabled( enableSpecific
);