• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeaccessibility API Reference
  • KDE Home
  • Contact Us
 

jovie

  • sources
  • kde-4.12
  • kdeaccessibility
  • jovie
  • filters
  • talkerchooser
talkerchooserconf.cpp
Go to the documentation of this file.
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2  Generic Talker Chooser Filter Configuration class.
3  -------------------
4  Copyright:
5  (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
6  -------------------
7  Original author: Gary Cramblitt <garycramblitt@comcast.net>
8 
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.
13 
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.
18 
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  ******************************************************************************/
23 
24 // TalkerChooser includes.
25 #include "talkerchooserconf.h"
26 #include "talkerchooserconf.moc"
27 
28 // Qt includes.
29 
30 
31 // KDE includes.
32 #include <klocale.h>
33 #include <klineedit.h>
34 #include <kdialog.h>
35 #include <kcombobox.h>
36 #include <kpushbutton.h>
37 #include <kconfig.h>
38 #include <kstandarddirs.h>
39 #include <kregexpeditorinterface.h>
40 #include <kfiledialog.h>
41 #include <kservicetypetrader.h>
42 
43 // KTTS includes.
44 #include "selecttalkerdlg.h"
45 
49 TalkerChooserConf::TalkerChooserConf( QWidget *parent, const QVariantList & args) :
50  KttsFilterConf(parent, args)
51 {
52  Q_UNUSED(args);
53  // kDebug() << "TalkerChooserConf::TalkerChooserConf: Running";
54 
55  // Create configuration widget.
56  setupUi(this);
57 
58  // Determine if kdeutils Regular Expression Editor is installed.
59  m_reEditorInstalled = !KServiceTypeTrader::self()->query(QLatin1String( "KRegExpEditor/KRegExpEditor" )).isEmpty();
60  reEditorButton->setEnabled(m_reEditorInstalled);
61 
62  connect(nameLineEdit, SIGNAL(textChanged(QString)),
63  this, SLOT(configChanged()));
64  connect(reLineEdit, SIGNAL(textChanged(QString)),
65  this, SLOT(configChanged()));
66  connect(reEditorButton, SIGNAL(clicked()),
67  this, SLOT(slotReEditorButton_clicked()));
68  connect(appIdLineEdit, SIGNAL(textChanged(QString)),
69  this, SLOT(configChanged()));
70  connect(talkerButton, SIGNAL(clicked()),
71  this, SLOT(slotTalkerButton_clicked()));
72 
73  connect(loadButton, SIGNAL(clicked()),
74  this, SLOT(slotLoadButton_clicked()));
75  connect(saveButton, SIGNAL(clicked()),
76  this, SLOT(slotSaveButton_clicked()));
77  connect(clearButton, SIGNAL(clicked()),
78  this, SLOT(slotClearButton_clicked()));
79 
80  // Set up defaults.
81  defaults();
82 }
83 
87 TalkerChooserConf::~TalkerChooserConf(){
88  // kDebug() << "TalkerChooserConf::~TalkerChooserConf: Running";
89 }
90 
91 void TalkerChooserConf::load(KConfig* c, const QString& configGroup){
92  // kDebug() << "TalkerChooserConf::load: Running";
93  KConfigGroup config( c, configGroup );
94  nameLineEdit->setText( config.readEntry( "UserFilterName", nameLineEdit->text() ) );
95  reLineEdit->setText(
96  config.readEntry("MatchRegExp", reLineEdit->text()) );
97  appIdLineEdit->setText(
98  config.readEntry("AppIDs", appIdLineEdit->text()) );
99 
100  m_talkerCode = TalkerCode(config.readEntry("TalkerCode"), false);
101  // Legacy settings.
102  QString s = config.readEntry( "LanguageCode" );
103  if (!s.isEmpty()) m_talkerCode.setLanguage(s);
104  s = config.readEntry( "SynthInName" );
105  //if (!s.isEmpty()) m_talkerCode.setPlugInName(s);
106  s = config.readEntry( "Gender" );
107  //if (!s.isEmpty()) m_talkerCode.setGender(s);
108  s = config.readEntry( "Volume" );
109  //if (!s.isEmpty()) m_talkerCode.setVolume(s);
110  s = config.readEntry( "Rate" );
111  //if (!s.isEmpty()) m_talkerCode.setRate(s);
112 
113  talkerLineEdit->setText(m_talkerCode.getTranslatedDescription());
114 }
115 
116 void TalkerChooserConf::save(KConfig* c, const QString& configGroup){
117  // kDebug() << "TalkerChooserConf::save: Running";
118  KConfigGroup config( c, configGroup );
119  config.writeEntry( "UserFilterName", nameLineEdit->text() );
120  config.writeEntry( "MatchRegExp", reLineEdit->text() );
121  config.writeEntry( "AppIDs", appIdLineEdit->text().remove(QLatin1Char( ' ' )) );
122  config.writeEntry( "TalkerCode", m_talkerCode.getTalkerCode());
123 }
124 
132 void TalkerChooserConf::defaults(){
133  // kDebug() << "TalkerChooserConf::defaults: Running";
134  // Default name.
135  nameLineEdit->setText( i18n("Talker Chooser") );
136  // Default regular expression is blank.
137  reLineEdit->clear( );
138  // Default App ID is blank.
139  appIdLineEdit->clear();
140  // Default to using default Talker.
141  m_talkerCode = TalkerCode( QString(), false );
142  talkerLineEdit->setText( m_talkerCode.getTranslatedDescription() );
143 }
144 
150 bool TalkerChooserConf::supportsMultiInstance() { return true; }
151 
160 QString TalkerChooserConf::userPlugInName()
161 {
162  if (talkerLineEdit->text().isEmpty()) return QString();
163  if (appIdLineEdit->text().isEmpty() &&
164  reLineEdit->text().isEmpty()) return QString();
165  QString instName = nameLineEdit->text();
166  if (instName.isEmpty()) return QString();
167  return instName;
168 }
169 
170 void TalkerChooserConf::slotReEditorButton_clicked()
171 {
172  // Show Regular Expression Editor dialog if it is installed.
173  if ( !m_reEditorInstalled ) return;
174  KDialog *editorDialog =
175  KServiceTypeTrader::createInstanceFromQuery<KDialog>( QLatin1String( "KRegExpEditor/KRegExpEditor" ));
176  if ( editorDialog )
177  {
178  // kdeutils was installed, so the dialog was found. Fetch the editor interface.
179  KRegExpEditorInterface *reEditor =
180  qobject_cast<KRegExpEditorInterface *>(editorDialog);
181  Q_ASSERT( reEditor ); // This should not fail!// now use the editor.
182  reEditor->setRegExp( reLineEdit->text() );
183  int dlgResult = editorDialog->exec();
184  if ( dlgResult == QDialog::Accepted )
185  {
186  QString re = reEditor->regExp();
187  reLineEdit->setText( re );
188  }
189  delete editorDialog;
190  } else return;
191 }
192 
193 void TalkerChooserConf::slotTalkerButton_clicked()
194 {
195  QString talkerCode = m_talkerCode.getTalkerCode();
196  QPointer<SelectTalkerDlg> dlg = new SelectTalkerDlg(this, "selecttalkerdialog", i18n("Select Talker"), talkerCode, true);
197  int dlgResult = dlg->exec();
198  if ( dlgResult != KDialog::Accepted ) return;
199  m_talkerCode = TalkerCode( dlg->getSelectedTalkerCode(), false );
200  talkerLineEdit->setText( m_talkerCode.getTranslatedDescription() );
201  configChanged();
202  delete dlg;
203 }
204 
205 void TalkerChooserConf::slotLoadButton_clicked()
206 {
207  QStringList dataDirs = KGlobal::dirs()->findAllResources("data", QLatin1String( "kttsd/talkerchooser/" ));
208  QString dataDir;
209  if (!dataDirs.isEmpty()) dataDir = dataDirs.last();
210  QString filename = KFileDialog::getOpenFileName(
211  dataDir,
212  QLatin1String( "*rc|" ) + i18n( "Talker Chooser Config (*rc)" ),
213  this,
214  QLatin1String( "talkerchooser_loadfile" ));
215  if ( filename.isEmpty() ) return;
216  KConfig* cfg = new KConfig( filename );
217  load( cfg, QLatin1String( "Filter" ) );
218  delete cfg;
219  configChanged();
220 }
221 
222 void TalkerChooserConf::slotSaveButton_clicked()
223 {
224  QString filename = KFileDialog::getSaveFileName(
225  KGlobal::dirs()->saveLocation( "data" ,QLatin1String( "kttsd/talkerchooser/" ), false ) ,
226  QLatin1String( "*rc|" ) + i18n( "Talker Chooser Config (*rc)" ),
227  this,
228  QLatin1String( "talkerchooser_savefile" ));
229  if ( filename.isEmpty() ) return;
230  KConfig* cfg = new KConfig( filename );
231  save( cfg, QLatin1String( "Filter" ) );
232  delete cfg;
233 }
234 
235 void TalkerChooserConf::slotClearButton_clicked()
236 {
237  nameLineEdit->setText( QString() );
238  reLineEdit->setText( QString() );
239  appIdLineEdit->setText( QString() );
240  m_talkerCode = TalkerCode( QString(), false );
241  talkerLineEdit->setText( m_talkerCode.getTranslatedDescription() );
242  configChanged();
243 }
selecttalkerdlg.h
TalkerChooserConf::defaults
virtual void defaults()
This function is called to set the settings in the module to sensible default values.
Definition: talkerchooserconf.cpp:132
TalkerCode::setLanguage
void setLanguage(const QString &language)
Definition: talkercode.cpp:159
TalkerCode::getTranslatedDescription
QString getTranslatedDescription() const
The Talker Code translated for display.
Definition: talkercode.cpp:221
TalkerChooserConf::supportsMultiInstance
virtual bool supportsMultiInstance()
Indicates whether the plugin supports multiple instances.
Definition: talkerchooserconf.cpp:150
QWidget
KDialog
TalkerChooserConf::~TalkerChooserConf
virtual ~TalkerChooserConf()
Destructor.
Definition: talkerchooserconf.cpp:87
TalkerChooserConf::load
virtual void load(KConfig *c, const QString &configGroup)
This method is invoked whenever the module should read its configuration (most of the times from a co...
Definition: talkerchooserconf.cpp:91
talkerchooserconf.h
TalkerChooserConf::save
virtual void save(KConfig *c, const QString &configGroup)
This function gets called when the user wants to save the settings in the user interface, updating the config files or wherever the configuration is stored.
Definition: talkerchooserconf.cpp:116
TalkerCode::getTalkerCode
QString getTalkerCode() const
Definition: talkercode.cpp:202
TalkerCode
Definition: talkercode.h:38
KttsFilterConf::configChanged
void configChanged()
This slot is used internally when the configuration is changed.
Definition: filterconf.h:122
KttsFilterConf
Definition: filterconf.h:36
TalkerChooserConf::userPlugInName
virtual QString userPlugInName()
Returns the name of the plugin.
Definition: talkerchooserconf.cpp:160
TalkerChooserConf::TalkerChooserConf
TalkerChooserConf(QWidget *parent, const QVariantList &args)
Constructor.
Definition: talkerchooserconf.cpp:49
SelectTalkerDlg
Definition: selecttalkerdlg.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:32:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

jovie

Skip menu "jovie"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeaccessibility API Reference

Skip menu "kdeaccessibility API Reference"
  • jovie

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal