• 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
  • stringreplacer
stringreplacerconf.cpp
Go to the documentation of this file.
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2  Generic String Replacement Filter Configuration class.
3  -------------------
4  Copyright 2005 by Gary Cramblitt <garycramblitt@comcast.net>
5  Copyright 2010 by Jeremy Whiting <jpwhiting@kde.org>
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 // StringReplacer includes.
25 #include "stringreplacerconf.h"
26 #include "stringreplacerconf.moc"
27 
28 // Qt includes.
29 #include <QtCore/QFile>
30 #include <QtCore/QFileInfo>
31 #include <QtXml/QDomDocument>
32 #include <QtGui/QRadioButton>
33 #include <QtCore/QTextStream>
34 #include <QtGui/QTableWidget>
35 #include <QtGui/QHeaderView>
36 
37 // KDE includes.
38 #include <kglobal.h>
39 #include <klocale.h>
40 #include <klineedit.h>
41 #include <kdialog.h>
42 #include <kpushbutton.h>
43 #include <kconfig.h>
44 #include <kstandarddirs.h>
45 #include <kregexpeditorinterface.h>
46 #include <kfiledialog.h>
47 #include <kmessagebox.h>
48 #include <khbox.h>
49 #include <kservicetypetrader.h>
50 
51 // KTTS includes.
52 #include "selectlanguagedlg.h"
53 #include "filterconf.h"
54 #include "cdataescaper.h"
55 
56 StringReplacerConf::StringReplacerConf( QWidget *parent, const QVariantList& args ) :
57  KttsFilterConf(parent, args),
58  m_editDlg(0),
59  m_editWidget(0)
60 {
61  Q_UNUSED(args);
62  // kDebug() << "StringReplacerConf::StringReplacerConf: Running";
63 
64  // Create configuration widget.
65  setupUi(this);
66 
67  substLView->setSortingEnabled(false);
68  substLView->verticalHeader()->hide();
69  substLView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
70 
71  connect(nameLineEdit, SIGNAL(textChanged(QString)),
72  this, SLOT(configChanged()));
73  connect(languageBrowseButton, SIGNAL(clicked()),
74  this, SLOT(slotLanguageBrowseButton_clicked()));
75  connect(addButton, SIGNAL(clicked()),
76  this, SLOT(slotAddButton_clicked()));
77  connect(upButton, SIGNAL(clicked()),
78  this, SLOT(slotUpButton_clicked()));
79  connect(downButton, SIGNAL(clicked()),
80  this, SLOT(slotDownButton_clicked()));
81  connect(editButton, SIGNAL(clicked()),
82  this, SLOT(slotEditButton_clicked()));
83  connect(removeButton, SIGNAL(clicked()),
84  this, SLOT(slotRemoveButton_clicked()));
85  connect(loadButton, SIGNAL(clicked()),
86  this, SLOT(slotLoadButton_clicked()));
87  connect(saveButton, SIGNAL(clicked()),
88  this, SLOT(slotSaveButton_clicked()));
89  connect(clearButton, SIGNAL(clicked()),
90  this, SLOT(slotClearButton_clicked()));
91  connect(substLView, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)),
92  this, SLOT(enableDisableButtons()));
93  connect(appIdLineEdit, SIGNAL(textChanged(QString)),
94  this, SLOT(configChanged()));
95 
96  // Determine if kdeutils Regular Expression Editor is installed.
97  m_reEditorInstalled = !KServiceTypeTrader::self()->query(QLatin1String( "KRegExpEditor/KRegExpEditor" )).isEmpty();
98 
99  // Set up defaults.
100  defaults();
101 }
102 
103 StringReplacerConf::~StringReplacerConf(){
104  // kDebug() << "StringReplacerConf::~StringReplacerConf: Running";
105 }
106 
107 void StringReplacerConf::load(KConfig* c, const QString& configGroup){
108  // kDebug() << "StringReplacerConf::load: Running";
109  // See if this filter previously save its word list.
110  KConfigGroup config( c, configGroup );
111  QString wordsFilename = config.readEntry( "WordListFile" );
112  if ( !wordsFilename.isEmpty() )
113  {
114  QString errMsg = loadFromFile( wordsFilename, true );
115  if ( !errMsg.isEmpty() )
116  kDebug() << "StringReplacerConf::load: " << errMsg;
117  enableDisableButtons();
118  }
119 }
120 
121 // Loads word list and settings from a file. Clearing configuration if clear is True.
122 QString StringReplacerConf::loadFromFile( const QString& filename, bool clear)
123 {
124  // Open existing word list.
125  QFile file( filename );
126  if ( !file.open( QIODevice::ReadOnly ) )
127  {
128  return i18n("Unable to open file.") + filename;
129  }
130  // QDomDocument doc( "http://www.kde.org/share/apps/kttsd/stringreplacer/wordlist.dtd []" );
131  QDomDocument doc( QLatin1String( "" ) );
132  if ( !doc.setContent( &file ) ) {
133  file.close();
134  return i18n("File not in proper XML format.");
135  }
136  // kDebug() << "StringReplacerConf::load: document successfully parsed.";
137  file.close();
138 
139  // Clear list view.
140  if ( clear ) substLView->setRowCount(0);
141 
142  // Name setting.
143  QDomNodeList nameList = doc.elementsByTagName( QLatin1String( "name" ) );
144  QDomNode nameNode = nameList.item( 0 );
145  nameLineEdit->setText( nameNode.toElement().text() );
146  // kDebug() << "StringReplacerConf::load: name = " << nameNode.toElement().text();
147 
148  // Language Codes setting. List may be single element of comma-separated values,
149  // or multiple elements.
150  QString languageCodes;
151  QDomNodeList languageList = doc.elementsByTagName( QLatin1String( "language-code" ) );
152  for ( int ndx=0; ndx < languageList.count(); ++ndx )
153  {
154  QDomNode languageNode = languageList.item( ndx );
155  if (!languageCodes.isEmpty()) languageCodes += QLatin1Char( ',' );
156  languageCodes += languageNode.toElement().text();
157  }
158  if ( clear )
159  m_languageCodeList = languageCodes.split(QLatin1Char( ',' ), QString::SkipEmptyParts);
160  else
161  m_languageCodeList += languageCodes.split(QLatin1Char( ',' ), QString::SkipEmptyParts);
162  QString language;
163  m_languageCodeList.sort();
164  // Eliminate dups.
165  {
166  int ndx = m_languageCodeList.count() - 2;
167  while ( ndx >= 0 ) {
168  if ( m_languageCodeList[ndx] == m_languageCodeList[ndx+1] )
169  m_languageCodeList.removeAt(ndx+1);
170  ndx--;
171  }
172  }
173  for ( int ndx=0; ndx < m_languageCodeList.count(); ++ndx )
174  {
175  if (!language.isEmpty()) language += QLatin1Char( ',' );
176  language += KGlobal::locale()->languageCodeToName(m_languageCodeList[ndx]);
177  }
178  languageLineEdit->setText(language);
179 
180  // AppId. Apply this filter only if DCOP appId of application that queued
181  // the text contains this string. List may be single element of comma-separated values,
182  // or multiple elements.
183  QDomNodeList appIdList = doc.elementsByTagName( QLatin1String( "appid" ) );
184  QString appIds;
185  for ( int ndx=0; ndx < appIdList.count(); ++ndx )
186  {
187  QDomNode appIdNode = appIdList.item( ndx );
188  if (!appIds.isEmpty()) appIds += QLatin1Char( ',' );
189  appIds += appIdNode.toElement().text();
190  }
191  if ( !clear ) appIds = appIdLineEdit->text() + appIds;
192  appIdLineEdit->setText( appIds );
193 
194  // Word list.
195  QDomNodeList wordList = doc.elementsByTagName( QLatin1String( "word" ) );
196  const int wordListCount = wordList.count();
197  for ( int wordIndex = 0; wordIndex < wordListCount; ++wordIndex )
198  {
199  // kDebug() << "StringReplacerConf::load: start parsing of word " << wordIndex;
200  QDomNode wordNode = wordList.item(wordIndex);
201  QDomNodeList propList = wordNode.childNodes();
202  QString wordType;
203  QString matchCase = QLatin1String( "No" );
204  QString match;
205  QString subst;
206  const int propListCount = propList.count();
207  for ( int propIndex = 0; propIndex < propListCount; ++propIndex )
208  {
209  QDomNode propNode = propList.item(propIndex);
210  QDomElement prop = propNode.toElement();
211  if (prop.tagName() == QLatin1String( "type" )) wordType = prop.text();
212  if (prop.tagName() == QLatin1String( "case" )) matchCase = prop.text();
213  if (prop.tagName() == QLatin1String( "match" ))
214  {
215  match = prop.text();
216  cdataUnescape( &match );
217  }
218 
219  if (prop.tagName() == QLatin1String( "subst" ))
220  {
221  subst = prop.text();
222  cdataUnescape( &subst );
223  }
224  }
225  QString wordTypeStr =
226  (wordType==QLatin1String( "RegExp" )?i18nc("Abbreviation for 'Regular Expression'", "RegExp"):i18n("Word"));
227  int tableRow = substLView->rowCount();
228  QString matchCaseStr =
229  (matchCase==QLatin1String( "Yes" )?i18nc("Yes or no", "Yes"):i18nc("Yes or no", "No"));
230  substLView->setRowCount( tableRow + 1 );
231  substLView->setItem( tableRow, 0, new QTableWidgetItem( wordTypeStr ) );
232  substLView->setItem( tableRow, 1, new QTableWidgetItem( matchCaseStr ) );
233  substLView->setItem( tableRow, 2, new QTableWidgetItem( match ) );
234  substLView->setItem( tableRow, 3, new QTableWidgetItem( subst ) );
235  }
236 
237  return QString();
238 }
239 
240 void StringReplacerConf::save(KConfig* c, const QString& configGroup){
241  // kDebug() << "StringReplacerConf::save: Running";
242  QString wordsFilename =
243  KGlobal::dirs()->saveLocation( "data" ,QLatin1String( "jovie/stringreplacer/" ), true );
244  if ( wordsFilename.isEmpty() )
245  {
246  kDebug() << "StringReplacerConf::save: no save location";
247  return;
248  }
249  wordsFilename += configGroup;
250  QString errMsg = saveToFile( wordsFilename );
251  if ( errMsg.isEmpty() )
252  {
253  KConfigGroup config( c, configGroup );
254  config.writeEntry( "WordListFile", realFilePath(wordsFilename) );
255  }
256  else
257  kDebug() << "StringReplacerConf::save: " << errMsg;
258 }
259 
260 // Saves word list and settings to a file.
261 QString StringReplacerConf::saveToFile(const QString& filename)
262 {
263  // kDebug() << "StringReplacerConf::saveToFile: saving to file " << wordsFilename;
264 
265  QFile file( filename );
266  if ( !file.open( QIODevice::WriteOnly ) )
267  return i18n("Unable to open file ") + filename;
268 
269  // QDomDocument doc( "http://www.kde.org/share/apps/kttsd/stringreplacer/wordlist.dtd []" );
270  QDomDocument doc( QLatin1String( "" ) );
271 
272  QDomElement root = doc.createElement( QLatin1String( "wordlist" ) );
273  doc.appendChild( root );
274 
275  // Name.
276  QDomElement name = doc.createElement( QLatin1String( "name" ) );
277  root.appendChild( name );
278  QDomText t = doc.createTextNode( nameLineEdit->text() );
279  name.appendChild( t );
280 
281  // Language code.
282  for ( int ndx=0; ndx < m_languageCodeList.count(); ++ndx )
283  {
284  QDomElement languageCode = doc.createElement( QLatin1String( "language-code" ) );
285  root.appendChild( languageCode );
286  t = doc.createTextNode( m_languageCodeList[ndx] );
287  languageCode.appendChild( t );
288  }
289 
290  // Application ID
291  QString appId = appIdLineEdit->text().remove(QLatin1Char( ' ' ));
292  if ( !appId.isEmpty() )
293  {
294  QStringList appIdList = appId.split( QLatin1Char( ',' ), QString::SkipEmptyParts );
295  for ( int ndx=0; ndx < appIdList.count(); ++ndx )
296  {
297  QDomElement appIdElem = doc.createElement( QLatin1String( "appid" ) );
298  root.appendChild( appIdElem );
299  t = doc.createTextNode( appIdList[ndx] );
300  appIdElem.appendChild( t );
301  }
302  }
303 
304  // Words.
305  for ( int row = 0; row < substLView->rowCount(); ++row )
306  {
307  QDomElement wordTag = doc.createElement( QLatin1String( "word" ) );
308  root.appendChild( wordTag );
309  QDomElement propTag = doc.createElement( QLatin1String( "type" ) );
310  wordTag.appendChild( propTag);
311  QDomText t = doc.createTextNode(
312  substLView->item(row, 0)->text()==i18n("Word")?QLatin1String( "Word" ):QLatin1String( "RegExp" ) );
313  propTag.appendChild( t );
314 
315  propTag = doc.createElement( QLatin1String( "case" ) );
316  wordTag.appendChild( propTag);
317  t = doc.createTextNode(
318  substLView->item(row, 1)->text()==i18nc("Yes or no", "Yes")?QLatin1String( "Yes" ):QLatin1String( "No" ) );
319  propTag.appendChild( t );
320 
321  propTag = doc.createElement( QLatin1String( "match" ) );
322  wordTag.appendChild( propTag);
323  QString s = substLView->item(row, 2)->text();
324  cdataEscape( &s );
325  t = doc.createCDATASection( s );
326  propTag.appendChild( t );
327 
328  propTag = doc.createElement( QLatin1String( "subst" ) );
329  wordTag.appendChild( propTag);
330  s = substLView->item(row, 3)->text();
331  cdataEscape( &s );
332  t = doc.createCDATASection( s );
333 
334  propTag.appendChild( t );
335  }
336 
337  // Write it all out.
338  QTextStream ts( &file );
339  ts.setCodec( "UTF-8" );
340  ts << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
341  ts << doc.toString();
342  // kDebug() << "StringReplacerConf::saveToFile: writing out " << doc.toString();
343  file.close();
344 
345  return QString();
346 }
347 
348 void StringReplacerConf::defaults(){
349  // kDebug() << "StringReplacerConf::defaults: Running";
350  // Default language is none.
351  m_languageCodeList.clear();
352  languageLineEdit->setText( QLatin1String( "" ) );
353  // Default name.
354  nameLineEdit->setText( i18n("String Replacer") );
355  substLView->setRowCount(0);
356  // Default App ID is blank.
357  appIdLineEdit->setText(QLatin1String( "" ) );
358  enableDisableButtons();
359  // kDebug() << "StringReplacerConf::defaults: Exiting";
360 }
361 
362 bool StringReplacerConf::supportsMultiInstance() { return true; }
363 
364 QString StringReplacerConf::userPlugInName()
365 {
366  if ( substLView->rowCount() == 0 ) return QString();
367  QString instName = nameLineEdit->text();
368  if ( instName.isEmpty() )
369  {
370  QString language;
371  if (m_languageCodeList.count() == 1)
372  language = KGlobal::locale()->languageCodeToName(m_languageCodeList[0]);
373  if (m_languageCodeList.count() > 1)
374  language = i18n("Multiple Languages");
375  if (!language.isEmpty())
376  instName = i18n("String Replacer") + QLatin1String( " (" ) + language + QLatin1Char( ')' );
377  }
378  return instName;
379 }
380 
381 // Converts a Substitution Type to displayable string.
382 QString StringReplacerConf::substitutionTypeToString(const int substitutionType)
383 {
384  switch (substitutionType)
385  {
386  case stWord: return i18n("Word");
387  case stRegExp: return i18nc("Abbreviation for 'Regular Expresion'", "RegExp");
388  }
389  return i18n("Error");
390 }
391 
392 void StringReplacerConf::slotLanguageBrowseButton_clicked()
393 {
394  QPointer<SelectLanguageDlg> dlg = new SelectLanguageDlg(
395  this,
396  i18n("Select Languages"),
397  QStringList(m_languageCodeList),
398  SelectLanguageDlg::MultipleSelect,
399  SelectLanguageDlg::BlankAllowed);
400  int dlgResult = dlg->exec();
401  if (dlgResult == QDialog::Accepted)
402  m_languageCodeList = dlg->selectedLanguageCodes();
403  delete dlg;
404  if (dlgResult != QDialog::Accepted) return;
405  QString language;
406  for ( int ndx=0; ndx < m_languageCodeList.count(); ++ndx)
407  {
408  if (!language.isEmpty()) language += QLatin1Char( ',' );
409  language += KGlobal::locale()->languageCodeToName(m_languageCodeList[ndx]);
410  }
411  QString s1 = languageLineEdit->text();
412  languageLineEdit->setText(language);
413  // Replace language in the user's filter name.
414  QString s2 = nameLineEdit->text();
415  if (m_languageCodeList.count() > 1) language = i18n("Multiple Languages");
416  if ( !s1.isEmpty() )
417  {
418  s2.replace( s1, language );
419  s2.replace( i18n("Multiple Languages"), language );
420  }
421  s2.remove(QLatin1String( " ()" ));
422  if ( !s2.contains(QLatin1Char('(' )) && !language.isEmpty() ) s2 += QLatin1String( " (" ) + language + QLatin1Char( ')' );
423  nameLineEdit->setText(s2);
424  configChanged();
425 }
426 
427 void StringReplacerConf::enableDisableButtons()
428 {
429  int row = substLView->currentRow();
430  bool enableBtn = (row >= 0 && row < substLView->rowCount());
431  if (enableBtn)
432  {
433  upButton->setEnabled(row > 0);
434  downButton->setEnabled(row < (substLView->rowCount() - 1));
435  } else {
436  upButton->setEnabled(false);
437  downButton->setEnabled(false);
438  }
439  editButton->setEnabled(enableBtn);
440  removeButton->setEnabled(enableBtn);
441  clearButton->setEnabled(substLView->rowCount() > 0);
442  saveButton->setEnabled(substLView->rowCount() > 0);
443 }
444 
445 void StringReplacerConf::slotUpButton_clicked()
446 {
447  int row = substLView->currentRow();
448  if (row < 1 || row >= substLView->rowCount()) return;
449 
450  QTableWidgetItem *itemAbove = substLView->item(row - 1, 0);
451  QTableWidgetItem *item = substLView->item(row, 0);
452  QString t = itemAbove->text();
453  itemAbove->setText(item->text());
454  item->setText(t);
455 
456  itemAbove = substLView->item(row - 1, 1);
457  item = substLView->item(row, 1);
458  t = itemAbove->text();
459  itemAbove->setText(item->text());
460  item->setText(t);
461 
462  itemAbove = substLView->item(row - 1, 2);
463  item = substLView->item(row, 2);
464  t = itemAbove->text();
465  itemAbove->setText(item->text());
466  item->setText(t);
467 
468  itemAbove = substLView->item(row - 1, 3);
469  item = substLView->item(row, 3);
470  t = itemAbove->text();
471  itemAbove->setText(item->text());
472  item->setText(t);
473 
474  substLView->setCurrentItem(substLView->item(row - 1, substLView->currentColumn()));
475  // TODO: Is this needed? substLView->scrollTo(substLView->indexFromItem(itemAbove));
476  enableDisableButtons();
477  configChanged();
478 }
479 
480 void StringReplacerConf::slotDownButton_clicked()
481 {
482  int row = substLView->currentRow();
483  if (row < 0 || row >= substLView->rowCount() - 1) return;
484 
485  QTableWidgetItem *itemBelow = substLView->item(row + 1, 0);
486  QTableWidgetItem *item = substLView->item(row, 0);
487  QString t = itemBelow->text();
488  itemBelow->setText(item->text());
489  item->setText(t);
490 
491  itemBelow = substLView->item(row + 1, 1);
492  item = substLView->item(row, 1);
493  t = itemBelow->text();
494  itemBelow->setText(item->text());
495  item->setText(t);
496 
497  itemBelow = substLView->item(row + 1, 2);
498  item = substLView->item(row, 2);
499  t = itemBelow->text();
500  itemBelow->setText(item->text());
501  item->setText(t);
502 
503  itemBelow = substLView->item(row + 1, 3);
504  item = substLView->item(row, 3);
505  t = itemBelow->text();
506  itemBelow->setText(item->text());
507  item->setText(t);
508 
509  substLView->setCurrentItem(substLView->item(row + 1, substLView->currentColumn()));
510  // TODO: Is this needed? substLView->scrollTo(substLView->indexFromItem(itemBelow));
511  enableDisableButtons();
512  configChanged();
513 }
514 
515 void StringReplacerConf::slotAddButton_clicked()
516 {
517  addOrEditSubstitution( true );
518 }
519 
520 void StringReplacerConf::slotEditButton_clicked()
521 {
522  addOrEditSubstitution( false );
523 }
524 
525 // Displays the add/edit string replacement dialog.
526 void StringReplacerConf::addOrEditSubstitution(bool isAdd)
527 {
528  int row;
529  if (isAdd)
530  row = substLView->rowCount() - 1;
531  else
532  row = substLView->currentRow();
533  // Create widget.
534  QWidget *w = new QWidget();
535  m_editWidget = new Ui::EditReplacementWidget();
536  m_editWidget->setupUi( w );
537  // Set controls if editing existing.
538  m_editWidget->matchButton->setEnabled( false );
539  if (!isAdd)
540  {
541  if ( substLView->item(row, 0)->text() != i18n("Word") )
542  {
543  m_editWidget->regexpRadioButton->setChecked( true );
544  m_editWidget->matchButton->setEnabled( m_reEditorInstalled );
545  }
546  if ( substLView->item(row, 1)->text() == i18nc("Yes or no", "Yes") )
547  m_editWidget->matchCaseCheckBox->setChecked( true );
548  m_editWidget->matchLineEdit->setText( substLView->item(row, 2)->text() );
549  m_editWidget->substLineEdit->setText( substLView->item(row, 3)->text() );
550  }
551  // The match box may not be blank.
552  connect( m_editWidget->matchLineEdit, SIGNAL(textChanged(QString)),
553  this, SLOT(slotMatchLineEdit_textChanged(QString)) );
554  connect( m_editWidget->regexpRadioButton, SIGNAL(clicked()),
555  this, SLOT(slotTypeButtonGroup_clicked()) );
556  connect( m_editWidget->wordRadioButton, SIGNAL(clicked()),
557  this, SLOT(slotTypeButtonGroup_clicked()) );
558  connect( m_editWidget->matchButton, SIGNAL(clicked()),
559  this, SLOT(slotMatchButton_clicked()) );
560  // Display the box in a dialog.
561  m_editDlg = new KDialog(this);
562  m_editDlg->setCaption(i18n("Edit String Replacement"));
563  m_editDlg->setButtons(KDialog::Help|KDialog::Ok|KDialog::Cancel);
564  // TODO: KDialog bug workaround. Remove when no longer needed.
565  m_editDlg->setDefaultButton(KDialog::Cancel);
566  // Disable OK button if match field blank.
567  m_editDlg->setMainWidget( w );
568  m_editDlg->setHelp( QLatin1String( "" ), QLatin1String( "jovie" ) );
569  m_editDlg->enableButton( KDialog::Ok, !m_editWidget->matchLineEdit->text().isEmpty() );
570  int dlgResult = m_editDlg->exec();
571  QString substType = i18n( "Word" );
572  if ( m_editWidget->regexpRadioButton->isChecked() )
573  substType = i18nc("Abbreviation for 'Regular Expression'", "RegExp");
574  QString matchCase = m_editWidget->matchCaseCheckBox->isChecked()?i18nc("Yes or no", "Yes"):i18nc("Yes or no", "No");
575  QString match = m_editWidget->matchLineEdit->text();
576  QString subst = m_editWidget->substLineEdit->text();
577  delete m_editDlg;
578  delete m_editWidget;
579  m_editDlg = 0;
580  m_editWidget = 0;
581  if (dlgResult != QDialog::Accepted) return;
582  // TODO: Also delete QTableWidget and w?
583  if ( match.isEmpty() ) return;
584  if ( isAdd )
585  {
586  row = substLView->rowCount();
587  substLView->setRowCount(row + 1);
588  substLView->setCurrentItem(substLView->item(row, 0));
589  for (int i = 0; i <= 4; ++i)
590  substLView->setItem(row, i, new QTableWidgetItem(QLatin1String( "" )));
591  }
592  substLView->item(row, 0)->setText(substType);
593  substLView->item(row, 1)->setText(matchCase);
594  substLView->item(row, 2)->setText(match);
595  substLView->item(row, 3)->setText(subst);
596  // TODO: Is this needed? substLView->scrollTo(substLView->indexFromItem(substLView->item(row,0)));
597  enableDisableButtons();
598  configChanged();
599 }
600 
601 void StringReplacerConf::slotMatchLineEdit_textChanged(const QString& text)
602 {
603  // Disable OK button if match field blank.
604  if ( !m_editDlg ) return;
605  m_editDlg->enableButton( KDialog::Ok, !text.isEmpty() );
606 }
607 
608 void StringReplacerConf::slotRemoveButton_clicked()
609 {
610  int row = substLView->currentRow();
611  if (row <= 0 || row >= substLView->rowCount()) return;
612  delete substLView->takeItem(row, 0);
613  delete substLView->takeItem(row, 1);
614  delete substLView->takeItem(row, 2);
615  delete substLView->takeItem(row, 3);
616  substLView->removeRow(row);
617  enableDisableButtons();
618  configChanged();
619 }
620 
621 void StringReplacerConf::slotTypeButtonGroup_clicked()
622 {
623  // Enable Regular Expression Editor button if editor is installed (requires kdeutils).
624  if ( !m_editWidget ) return;
625  m_editWidget->matchButton->setEnabled( m_editWidget->regexpRadioButton->isChecked() && m_reEditorInstalled );
626 }
627 
628 void StringReplacerConf::slotMatchButton_clicked()
629 {
630  // Show Regular Expression Editor dialog if it is installed.
631  if ( !m_editWidget ) return;
632  if ( !m_editDlg ) return;
633  if ( !m_reEditorInstalled ) return;
634  KDialog *editorDialog =
635  KServiceTypeTrader::createInstanceFromQuery<KDialog>( QLatin1String( "KRegExpEditor/KRegExpEditor" ) );
636  if ( editorDialog )
637  {
638  // kdeutils was installed, so the dialog was found. Fetch the editor interface.
639 
640  KRegExpEditorInterface *reEditor = qobject_cast<KRegExpEditorInterface*>( editorDialog );
641  Q_ASSERT( reEditor ); // This should not fail!// now use the editor.
642  reEditor->setRegExp( m_editWidget->matchLineEdit->text() );
643  int dlgResult = editorDialog->exec();
644  if ( dlgResult == QDialog::Accepted )
645  {
646  QString re = reEditor->regExp();
647  m_editWidget->matchLineEdit->setText( re );
648  m_editDlg->enableButton( KDialog::Ok, !re.isEmpty() );
649  }
650  delete editorDialog;
651  } else return;
652 }
653 
654 void StringReplacerConf::slotLoadButton_clicked()
655 {
656  QStringList dataDirs = KGlobal::dirs()->findAllResources("data", QLatin1String( "jovie/stringreplacer/" ));
657  QString dataDir;
658  if (!dataDirs.isEmpty()) dataDir = dataDirs.last();
659  QString filename = KFileDialog::getOpenFileName(
660  dataDir,
661  QLatin1String( "*.xml|" ) + i18n( "String Replacer Word List (*.xml)" ),
662  this,
663  QLatin1String( "stringreplacer_loadfile" ));
664  if ( filename.isEmpty() ) return;
665  QString errMsg = loadFromFile( filename, false );
666  enableDisableButtons();
667  if ( !errMsg.isEmpty() )
668  KMessageBox::sorry( this, errMsg, i18n("Error Opening File") );
669  else
670  configChanged();
671 }
672 
673 void StringReplacerConf::slotSaveButton_clicked()
674 {
675  QString filename = KFileDialog::getSaveFileName(
676  KGlobal::dirs()->saveLocation( "data" ,QLatin1String( "kttsd/stringreplacer/" ), false ),
677  QLatin1String( "*.xml|" ) + i18n( "String Replacer Word List (*.xml)" ),
678  this,
679  QLatin1String( "stringreplacer_savefile" ));
680  if ( filename.isEmpty() ) return;
681  QString errMsg = saveToFile( filename );
682  enableDisableButtons();
683  if ( !errMsg.isEmpty() )
684  KMessageBox::sorry( this, errMsg, i18n("Error Opening File") );
685 }
686 
687 void StringReplacerConf::slotClearButton_clicked()
688 {
689  substLView->setRowCount(0);
690  enableDisableButtons();
691 }
692 
SelectLanguageDlg::MultipleSelect
Definition: selectlanguagedlg.h:44
cdataEscape
void cdataEscape(QString *s)
Definition: cdataescaper.cpp:9
QWidget
filterconf.h
KDialog
StringReplacerConf::stWord
Definition: stringreplacerconf.h:60
SelectLanguageDlg
Definition: selectlanguagedlg.h:38
StringReplacerConf::~StringReplacerConf
virtual ~StringReplacerConf()
Destructor.
Definition: stringreplacerconf.cpp:103
KttsFilterConf::realFilePath
static QString realFilePath(const QString &filename)
Definition: filterconf.cpp:154
StringReplacerConf::StringReplacerConf
StringReplacerConf(QWidget *parent, const QVariantList &args=QVariantList())
Constructor.
Definition: stringreplacerconf.cpp:56
SelectLanguageDlg::BlankAllowed
Definition: selectlanguagedlg.h:49
stringreplacerconf.h
KttsFilterConf::configChanged
void configChanged()
This slot is used internally when the configuration is changed.
Definition: filterconf.h:122
StringReplacerConf::defaults
virtual void defaults()
This function is called to set the settings in the module to sensible default values.
Definition: stringreplacerconf.cpp:348
StringReplacerConf::supportsMultiInstance
virtual bool supportsMultiInstance()
Indicates whether the plugin supports multiple instances.
Definition: stringreplacerconf.cpp:362
StringReplacerConf::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: stringreplacerconf.cpp:240
StringReplacerConf::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: stringreplacerconf.cpp:107
KttsFilterConf
Definition: filterconf.h:36
StringReplacerConf::userPlugInName
virtual QString userPlugInName()
Returns the name of the plugin.
Definition: stringreplacerconf.cpp:364
cdataescaper.h
selectlanguagedlg.h
cdataUnescape
void cdataUnescape(QString *s)
Definition: cdataescaper.cpp:15
StringReplacerConf::stRegExp
Definition: stringreplacerconf.h:61
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