2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "sources.hh"
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2010-05-28 16:50:54 +00:00
|
|
|
#include <QStandardItemModel>
|
2013-11-16 18:34:09 +00:00
|
|
|
#include "gddebug.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2013-04-24 14:52:04 +00:00
|
|
|
|
|
|
|
Sources::Sources( QWidget * parent, Config::Class const & cfg):
|
|
|
|
QWidget( parent ),
|
2014-05-12 13:53:13 +00:00
|
|
|
#if defined( Q_OS_WIN32 ) || defined( Q_OS_MAC )
|
2013-04-24 14:52:04 +00:00
|
|
|
textToSpeechSource( NULL ),
|
|
|
|
#endif
|
2011-05-29 05:08:37 +00:00
|
|
|
itemDelegate( new QItemDelegate( this ) ),
|
|
|
|
itemEditorFactory( new QItemEditorFactory() ),
|
2013-04-24 14:52:04 +00:00
|
|
|
mediawikisModel( this, cfg.mediawikis ),
|
|
|
|
webSitesModel( this, cfg.webSites ),
|
2014-04-30 12:55:53 +00:00
|
|
|
dictServersModel( this, cfg.dictServers ),
|
2013-04-24 14:52:04 +00:00
|
|
|
programsModel( this, cfg.programs ),
|
|
|
|
pathsModel( this, cfg.paths ),
|
|
|
|
soundDirsModel( this, cfg.soundDirs ),
|
|
|
|
hunspellDictsModel( this, cfg.hunspell )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
|
|
|
ui.setupUi( this );
|
|
|
|
|
2013-04-24 14:52:04 +00:00
|
|
|
Config::Hunspell const & hunspell = cfg.hunspell;
|
|
|
|
Config::Transliteration const & trs = cfg.transliteration;
|
|
|
|
Config::Forvo const & forvo = cfg.forvo;
|
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
// TODO: will programTypeEditorCreator and itemEditorFactory be destoryed by
|
|
|
|
// anyone?
|
|
|
|
QItemEditorCreatorBase * programTypeEditorCreator =
|
|
|
|
new QStandardItemEditorCreator< ProgramTypeEditor >();
|
|
|
|
|
|
|
|
itemEditorFactory->registerEditor( QVariant::Int, programTypeEditorCreator );
|
|
|
|
|
|
|
|
itemDelegate->setItemEditorFactory( itemEditorFactory );
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
ui.mediaWikis->setTabKeyNavigation( true );
|
|
|
|
ui.mediaWikis->setModel( &mediawikisModel );
|
|
|
|
ui.mediaWikis->resizeColumnToContents( 0 );
|
|
|
|
ui.mediaWikis->resizeColumnToContents( 1 );
|
|
|
|
ui.mediaWikis->resizeColumnToContents( 2 );
|
2012-06-21 09:43:28 +00:00
|
|
|
ui.mediaWikis->resizeColumnToContents( 3 );
|
2009-03-26 19:00:08 +00:00
|
|
|
|
2009-05-16 18:04:21 +00:00
|
|
|
ui.webSites->setTabKeyNavigation( true );
|
|
|
|
ui.webSites->setModel( &webSitesModel );
|
|
|
|
ui.webSites->resizeColumnToContents( 0 );
|
|
|
|
ui.webSites->resizeColumnToContents( 1 );
|
|
|
|
ui.webSites->resizeColumnToContents( 2 );
|
2012-12-03 12:48:31 +00:00
|
|
|
ui.webSites->resizeColumnToContents( 3 );
|
2009-05-16 18:04:21 +00:00
|
|
|
|
2014-04-30 12:55:53 +00:00
|
|
|
ui.dictServers->setTabKeyNavigation( true );
|
|
|
|
ui.dictServers->setModel( &dictServersModel );
|
|
|
|
ui.dictServers->resizeColumnToContents( 0 );
|
|
|
|
ui.dictServers->resizeColumnToContents( 1 );
|
|
|
|
ui.dictServers->resizeColumnToContents( 2 );
|
|
|
|
ui.dictServers->resizeColumnToContents( 3 );
|
2014-05-03 17:41:16 +00:00
|
|
|
ui.dictServers->resizeColumnToContents( 4 );
|
|
|
|
ui.dictServers->resizeColumnToContents( 5 );
|
2014-04-30 12:55:53 +00:00
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
ui.programs->setTabKeyNavigation( true );
|
|
|
|
ui.programs->setModel( &programsModel );
|
|
|
|
ui.programs->resizeColumnToContents( 0 );
|
|
|
|
// Make sure this thing will be large enough
|
|
|
|
ui.programs->setColumnWidth( 1,
|
|
|
|
QFontMetrics( QFont() ).width(
|
2011-06-04 21:35:09 +00:00
|
|
|
ProgramTypeEditor::getNameForType( Config::Program::PrefixMatch ) ) + 16 );
|
2011-05-29 05:08:37 +00:00
|
|
|
ui.programs->resizeColumnToContents( 2 );
|
|
|
|
ui.programs->resizeColumnToContents( 3 );
|
2012-12-07 11:59:59 +00:00
|
|
|
ui.programs->resizeColumnToContents( 4 );
|
2011-05-29 05:08:37 +00:00
|
|
|
ui.programs->setItemDelegate( itemDelegate );
|
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
ui.paths->setTabKeyNavigation( true );
|
|
|
|
ui.paths->setModel( &pathsModel );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
fitPathsColumns();
|
2009-05-11 23:37:18 +00:00
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
ui.soundDirs->setTabKeyNavigation( true );
|
|
|
|
ui.soundDirs->setModel( &soundDirsModel );
|
2009-05-11 23:37:18 +00:00
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
fitSoundDirsColumns();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-09 14:15:01 +00:00
|
|
|
ui.hunspellPath->setText( hunspell.dictionariesPath );
|
|
|
|
ui.hunspellDictionaries->setTabKeyNavigation( true );
|
|
|
|
ui.hunspellDictionaries->setModel( &hunspellDictsModel );
|
|
|
|
|
|
|
|
fitHunspellDictsColumns();
|
2009-05-06 14:39:08 +00:00
|
|
|
|
2010-05-28 16:50:54 +00:00
|
|
|
ui.enableRussianTransliteration->setChecked( trs.enableRussianTransliteration );
|
|
|
|
ui.enableGermanTransliteration->setChecked( trs.enableGermanTransliteration );
|
2010-05-29 09:22:08 +00:00
|
|
|
ui.enableGreekTransliteration->setChecked( trs.enableGreekTransliteration );
|
2013-01-18 19:21:56 +00:00
|
|
|
ui.enableBelarusianTransliteration->setChecked( trs.enableBelarusianTransliteration );
|
2015-10-19 13:52:23 +00:00
|
|
|
ui.enableChineseConversion->setChecked( trs.chinese.enable );
|
2015-10-20 03:37:50 +00:00
|
|
|
ui.enableSCToTWConversion->setChecked( trs.chinese.enableSCToTWConversion );
|
|
|
|
ui.enableSCToHKConversion->setChecked( trs.chinese.enableSCToHKConversion );
|
|
|
|
ui.enableTCToSCConversion->setChecked( trs.chinese.enableTCToSCConversion );
|
2010-05-28 16:50:54 +00:00
|
|
|
ui.enableRomaji->setChecked( trs.romaji.enable );
|
|
|
|
ui.enableHepburn->setChecked( trs.romaji.enableHepburn );
|
|
|
|
ui.enableNihonShiki->setChecked( trs.romaji.enableNihonShiki );
|
|
|
|
ui.enableKunreiShiki->setChecked( trs.romaji.enableKunreiShiki );
|
|
|
|
ui.enableHiragana->setChecked( trs.romaji.enableHiragana );
|
|
|
|
ui.enableKatakana->setChecked( trs.romaji.enableKatakana );
|
|
|
|
|
2010-06-12 20:16:35 +00:00
|
|
|
ui.forvoEnabled->setChecked( forvo.enable );
|
|
|
|
ui.forvoApiKey->setText( forvo.apiKey );
|
|
|
|
ui.forvoLanguageCodes->setText( forvo.languageCodes );
|
|
|
|
|
2013-04-24 14:52:04 +00:00
|
|
|
// Text to speech
|
2014-05-12 13:53:13 +00:00
|
|
|
#if defined( Q_OS_WIN32 ) || defined( Q_OS_MAC )
|
2013-04-24 14:52:04 +00:00
|
|
|
textToSpeechSource = new TextToSpeechSource( this, cfg.voiceEngines );
|
2014-05-02 21:28:18 +00:00
|
|
|
ui.tabWidget->addTab( textToSpeechSource, QIcon(":/icons/playsound_color.png"), tr( "Text to Speech" ) );
|
2013-04-24 14:52:04 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-28 16:50:54 +00:00
|
|
|
if ( Config::isPortableVersion() )
|
|
|
|
{
|
|
|
|
// Paths
|
|
|
|
|
|
|
|
ui.paths->setEnabled( false );
|
|
|
|
ui.addPath->setEnabled( false );
|
|
|
|
ui.removePath->setEnabled( false );
|
|
|
|
|
|
|
|
// Sound dirs
|
|
|
|
|
|
|
|
{
|
|
|
|
QStandardItemModel * model = new QStandardItemModel( this );
|
|
|
|
model->setHorizontalHeaderLabels( QStringList() << " " );
|
|
|
|
model->invisibleRootItem()->appendRow( new QStandardItem( tr( "(not available in portable version)" ) ) );
|
|
|
|
ui.soundDirs->setModel( model );
|
|
|
|
ui.soundDirs->setEnabled( false );
|
|
|
|
|
|
|
|
ui.addSoundDir->setEnabled( false );
|
|
|
|
ui.removeSoundDir->setEnabled( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Morpho
|
|
|
|
|
|
|
|
ui.hunspellPath->setEnabled( false );
|
|
|
|
ui.changeHunspellPath->setEnabled( false );
|
|
|
|
}
|
2009-03-28 22:37:03 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
void Sources::fitPathsColumns()
|
|
|
|
{
|
|
|
|
ui.paths->resizeColumnToContents( 0 );
|
|
|
|
ui.paths->resizeColumnToContents( 1 );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
void Sources::fitSoundDirsColumns()
|
|
|
|
{
|
|
|
|
ui.soundDirs->resizeColumnToContents( 0 );
|
|
|
|
ui.soundDirs->resizeColumnToContents( 1 );
|
2013-02-02 18:25:24 +00:00
|
|
|
ui.soundDirs->resizeColumnToContents( 2 );
|
2009-04-04 16:06:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 14:15:01 +00:00
|
|
|
void Sources::fitHunspellDictsColumns()
|
|
|
|
{
|
|
|
|
ui.hunspellDictionaries->resizeColumnToContents( 0 );
|
|
|
|
ui.hunspellDictionaries->resizeColumnToContents( 1 );
|
|
|
|
}
|
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
void Sources::on_addPath_clicked()
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-05-11 23:37:18 +00:00
|
|
|
QString dir =
|
2009-01-28 20:55:45 +00:00
|
|
|
QFileDialog::getExistingDirectory( this, tr( "Choose a directory" ) );
|
|
|
|
|
|
|
|
if ( !dir.isEmpty() )
|
|
|
|
{
|
2009-03-28 22:37:03 +00:00
|
|
|
pathsModel.addNewPath( dir );
|
|
|
|
fitPathsColumns();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
void Sources::on_removePath_clicked()
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-03-28 22:37:03 +00:00
|
|
|
QModelIndex current = ui.paths->currentIndex();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
if ( current.isValid() &&
|
2009-01-28 20:55:45 +00:00
|
|
|
QMessageBox::question( this, tr( "Confirm removal" ),
|
2009-03-28 22:37:03 +00:00
|
|
|
tr( "Remove directory <b>%1</b> from the list?" ).arg( pathsModel.getCurrentPaths()[ current.row() ].path ),
|
2009-01-28 20:55:45 +00:00
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Cancel ) == QMessageBox::Ok )
|
|
|
|
{
|
2009-03-28 22:37:03 +00:00
|
|
|
pathsModel.removePath( current.row() );
|
|
|
|
fitPathsColumns();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
void Sources::on_addSoundDir_clicked()
|
|
|
|
{
|
2009-05-11 23:37:18 +00:00
|
|
|
QString dir =
|
2009-04-04 16:06:06 +00:00
|
|
|
QFileDialog::getExistingDirectory( this, tr( "Choose a directory" ) );
|
|
|
|
|
|
|
|
if ( !dir.isEmpty() )
|
|
|
|
{
|
|
|
|
soundDirsModel.addNewSoundDir( dir, QDir( dir ).dirName() );
|
|
|
|
fitSoundDirsColumns();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sources::on_removeSoundDir_clicked()
|
|
|
|
{
|
|
|
|
QModelIndex current = ui.soundDirs->currentIndex();
|
|
|
|
|
|
|
|
if ( current.isValid() &&
|
|
|
|
QMessageBox::question( this, tr( "Confirm removal" ),
|
|
|
|
tr( "Remove directory <b>%1</b> from the list?" ).arg( soundDirsModel.getCurrentSoundDirs()[ current.row() ].path ),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Cancel ) == QMessageBox::Ok )
|
|
|
|
{
|
|
|
|
soundDirsModel.removeSoundDir( current.row() );
|
|
|
|
fitSoundDirsColumns();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-09 14:15:01 +00:00
|
|
|
void Sources::on_changeHunspellPath_clicked()
|
|
|
|
{
|
2009-05-11 23:37:18 +00:00
|
|
|
QString dir =
|
2009-04-09 14:15:01 +00:00
|
|
|
QFileDialog::getExistingDirectory( this, tr( "Choose a directory" ) );
|
|
|
|
|
|
|
|
if ( !dir.isEmpty() )
|
|
|
|
{
|
|
|
|
ui.hunspellPath->setText( dir );
|
|
|
|
hunspellDictsModel.changePath( dir );
|
|
|
|
fitHunspellDictsColumns();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void Sources::on_addMediaWiki_clicked()
|
|
|
|
{
|
|
|
|
mediawikisModel.addNewWiki();
|
|
|
|
QModelIndex result =
|
|
|
|
mediawikisModel.index( mediawikisModel.rowCount( QModelIndex() ) - 1,
|
|
|
|
1, QModelIndex() );
|
|
|
|
|
|
|
|
ui.mediaWikis->scrollTo( result );
|
|
|
|
//ui.mediaWikis->setCurrentIndex( result );
|
|
|
|
ui.mediaWikis->edit( result );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sources::on_removeMediaWiki_clicked()
|
|
|
|
{
|
|
|
|
QModelIndex current = ui.mediaWikis->currentIndex();
|
|
|
|
|
|
|
|
if ( current.isValid() &&
|
|
|
|
QMessageBox::question( this, tr( "Confirm removal" ),
|
|
|
|
tr( "Remove site <b>%1</b> from the list?" ).arg( mediawikisModel.getCurrentWikis()[ current.row() ].name ),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Cancel ) == QMessageBox::Ok )
|
|
|
|
mediawikisModel.removeWiki( current.row() );
|
|
|
|
}
|
|
|
|
|
2009-05-16 18:04:21 +00:00
|
|
|
void Sources::on_addWebSite_clicked()
|
|
|
|
{
|
|
|
|
webSitesModel.addNewSite();
|
|
|
|
|
|
|
|
QModelIndex result =
|
|
|
|
webSitesModel.index( webSitesModel.rowCount( QModelIndex() ) - 1,
|
|
|
|
1, QModelIndex() );
|
|
|
|
|
|
|
|
ui.webSites->scrollTo( result );
|
|
|
|
ui.webSites->edit( result );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sources::on_removeWebSite_clicked()
|
|
|
|
{
|
|
|
|
QModelIndex current = ui.webSites->currentIndex();
|
|
|
|
|
|
|
|
if ( current.isValid() &&
|
|
|
|
QMessageBox::question( this, tr( "Confirm removal" ),
|
|
|
|
tr( "Remove site <b>%1</b> from the list?" ).arg( webSitesModel.getCurrentWebSites()[ current.row() ].name ),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Cancel ) == QMessageBox::Ok )
|
|
|
|
webSitesModel.removeSite( current.row() );
|
|
|
|
}
|
|
|
|
|
2014-04-30 12:55:53 +00:00
|
|
|
void Sources::on_addDictServer_clicked()
|
|
|
|
{
|
|
|
|
dictServersModel.addNewServer();
|
|
|
|
|
|
|
|
QModelIndex result =
|
|
|
|
dictServersModel.index( dictServersModel.rowCount( QModelIndex() ) - 1,
|
|
|
|
1, QModelIndex() );
|
|
|
|
|
|
|
|
ui.dictServers->scrollTo( result );
|
|
|
|
ui.dictServers->edit( result );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sources::on_removeDictServer_clicked()
|
|
|
|
{
|
|
|
|
QModelIndex current = ui.dictServers->currentIndex();
|
|
|
|
|
|
|
|
if ( current.isValid() &&
|
|
|
|
QMessageBox::question( this, tr( "Confirm removal" ),
|
|
|
|
tr( "Remove site <b>%1</b> from the list?" ).arg( dictServersModel.getCurrentDictServers()[ current.row() ].name ),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Cancel ) == QMessageBox::Ok )
|
|
|
|
dictServersModel.removeServer( current.row() );
|
|
|
|
}
|
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
void Sources::on_addProgram_clicked()
|
|
|
|
{
|
|
|
|
programsModel.addNewProgram();
|
|
|
|
|
|
|
|
QModelIndex result =
|
|
|
|
programsModel.index( programsModel.rowCount( QModelIndex() ) - 1,
|
|
|
|
1, QModelIndex() );
|
|
|
|
|
|
|
|
ui.programs->scrollTo( result );
|
|
|
|
ui.programs->edit( result );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sources::on_removeProgram_clicked()
|
|
|
|
{
|
|
|
|
QModelIndex current = ui.programs->currentIndex();
|
|
|
|
|
|
|
|
if ( current.isValid() &&
|
|
|
|
QMessageBox::question( this, tr( "Confirm removal" ),
|
|
|
|
tr( "Remove program <b>%1</b> from the list?" ).arg( programsModel.getCurrentPrograms()[ current.row() ].name ),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Cancel ) == QMessageBox::Ok )
|
|
|
|
programsModel.removeProgram( current.row() );
|
|
|
|
}
|
|
|
|
|
2013-04-24 14:52:04 +00:00
|
|
|
Config::VoiceEngines Sources::getVoiceEngines() const
|
|
|
|
{
|
2014-05-12 13:53:13 +00:00
|
|
|
#if defined( Q_OS_WIN32 ) || defined( Q_OS_MAC )
|
2013-04-24 14:52:04 +00:00
|
|
|
if ( !textToSpeechSource )
|
|
|
|
return Config::VoiceEngines();
|
|
|
|
return textToSpeechSource->getVoiceEnginesModel().getCurrentVoiceEngines();
|
|
|
|
#else
|
|
|
|
return Config::VoiceEngines();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-04-09 14:15:01 +00:00
|
|
|
Config::Hunspell Sources::getHunspell() const
|
|
|
|
{
|
|
|
|
Config::Hunspell h;
|
|
|
|
|
|
|
|
h.dictionariesPath = ui.hunspellPath->text();
|
|
|
|
h.enabledDictionaries = hunspellDictsModel.getEnabledDictionaries();
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2009-05-06 14:39:08 +00:00
|
|
|
Config::Transliteration Sources::getTransliteration() const
|
|
|
|
{
|
|
|
|
Config::Transliteration tr;
|
|
|
|
|
|
|
|
tr.enableRussianTransliteration = ui.enableRussianTransliteration->isChecked();
|
2009-05-11 23:37:18 +00:00
|
|
|
tr.enableGermanTransliteration = ui.enableGermanTransliteration->isChecked();
|
2010-05-29 09:22:08 +00:00
|
|
|
tr.enableGreekTransliteration = ui.enableGreekTransliteration->isChecked();
|
2013-01-18 19:21:56 +00:00
|
|
|
tr.enableBelarusianTransliteration = ui.enableBelarusianTransliteration->isChecked();
|
2015-10-19 13:52:23 +00:00
|
|
|
tr.chinese.enable = ui.enableChineseConversion->isChecked();
|
2015-10-20 03:37:50 +00:00
|
|
|
tr.chinese.enableSCToTWConversion = ui.enableSCToTWConversion->isChecked();
|
|
|
|
tr.chinese.enableSCToHKConversion = ui.enableSCToHKConversion->isChecked();
|
|
|
|
tr.chinese.enableTCToSCConversion = ui.enableTCToSCConversion->isChecked();
|
2009-05-06 14:39:08 +00:00
|
|
|
tr.romaji.enable = ui.enableRomaji->isChecked();
|
|
|
|
tr.romaji.enableHepburn = ui.enableHepburn->isChecked();
|
|
|
|
tr.romaji.enableNihonShiki = ui.enableNihonShiki->isChecked();
|
|
|
|
tr.romaji.enableKunreiShiki = ui.enableKunreiShiki->isChecked();
|
|
|
|
tr.romaji.enableHiragana = ui.enableHiragana->isChecked();
|
|
|
|
tr.romaji.enableKatakana = ui.enableKatakana->isChecked();
|
|
|
|
|
|
|
|
return tr;
|
|
|
|
}
|
2009-04-09 14:15:01 +00:00
|
|
|
|
2010-06-12 20:16:35 +00:00
|
|
|
Config::Forvo Sources::getForvo() const
|
|
|
|
{
|
|
|
|
Config::Forvo forvo;
|
|
|
|
|
|
|
|
forvo.enable = ui.forvoEnabled->isChecked();
|
|
|
|
forvo.apiKey = ui.forvoApiKey->text();
|
|
|
|
forvo.languageCodes = ui.forvoLanguageCodes->text();
|
|
|
|
|
|
|
|
return forvo;
|
|
|
|
}
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
////////// MediaWikisModel
|
|
|
|
|
|
|
|
MediaWikisModel::MediaWikisModel( QWidget * parent,
|
|
|
|
Config::MediaWikis const & mediawikis_ ):
|
|
|
|
QAbstractItemModel( parent ), mediawikis( mediawikis_ )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void MediaWikisModel::removeWiki( int index )
|
|
|
|
{
|
|
|
|
beginRemoveRows( QModelIndex(), index, index );
|
|
|
|
mediawikis.erase( mediawikis.begin() + index );
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaWikisModel::addNewWiki()
|
|
|
|
{
|
|
|
|
Config::MediaWiki w;
|
|
|
|
|
|
|
|
w.enabled = false;
|
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
w.id = Dictionary::generateRandomDictionaryId();
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
w.url = "http://";
|
|
|
|
|
|
|
|
beginInsertRows( QModelIndex(), mediawikis.size(), mediawikis.size() );
|
|
|
|
mediawikis.push_back( w );
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex MediaWikisModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return createIndex( row, column, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex MediaWikisModel::parent( QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags MediaWikisModel::flags( QModelIndex const & index ) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags result = QAbstractItemModel::flags( index );
|
|
|
|
|
|
|
|
if ( index.isValid() )
|
|
|
|
{
|
|
|
|
if ( !index.column() )
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
else
|
|
|
|
result |= Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MediaWikisModel::rowCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return mediawikis.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MediaWikisModel::columnCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
2012-06-21 09:43:28 +00:00
|
|
|
return 4;
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant MediaWikisModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
|
|
|
{
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
switch( section )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr( "Enabled" );
|
|
|
|
case 1:
|
|
|
|
return tr( "Name" );
|
|
|
|
case 2:
|
|
|
|
return tr( "Address" );
|
2012-06-21 09:43:28 +00:00
|
|
|
case 3:
|
|
|
|
return tr( "Icon" );
|
2009-03-26 19:00:08 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant MediaWikisModel::data( QModelIndex const & index, int role ) const
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= mediawikis.size() )
|
2009-03-26 19:00:08 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
{
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return mediawikis[ index.row() ].name;
|
|
|
|
case 2:
|
|
|
|
return mediawikis[ index.row() ].url;
|
2012-06-21 09:43:28 +00:00
|
|
|
case 3:
|
|
|
|
return mediawikis[ index.row() ].icon;
|
2009-03-26 19:00:08 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
2013-05-28 15:18:32 +00:00
|
|
|
return mediawikis[ index.row() ].enabled ? Qt::Checked : Qt::Unchecked;
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaWikisModel::setData( QModelIndex const & index, const QVariant & value,
|
|
|
|
int role )
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= mediawikis.size() )
|
2009-03-26 19:00:08 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
|
|
|
{
|
2011-06-19 18:50:11 +00:00
|
|
|
//DPRINTF( "type = %d\n", (int)value.type() );
|
|
|
|
//DPRINTF( "value = %d\n", (int)value.toInt() );
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
// XXX it seems to be always passing Int( 2 ) as a value, so we just toggle
|
|
|
|
mediawikis[ index.row() ].enabled = !mediawikis[ index.row() ].enabled;
|
|
|
|
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
mediawikis[ index.row() ].name = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 2:
|
|
|
|
mediawikis[ index.row() ].url = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
2012-06-21 09:43:28 +00:00
|
|
|
case 3:
|
|
|
|
mediawikis[ index.row() ].icon = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
2009-03-26 19:00:08 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-16 18:04:21 +00:00
|
|
|
|
|
|
|
////////// WebSitesModel
|
|
|
|
|
|
|
|
WebSitesModel::WebSitesModel( QWidget * parent,
|
|
|
|
Config::WebSites const & webSites_ ):
|
|
|
|
QAbstractItemModel( parent ), webSites( webSites_ )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void WebSitesModel::removeSite( int index )
|
|
|
|
{
|
|
|
|
beginRemoveRows( QModelIndex(), index, index );
|
|
|
|
webSites.erase( webSites.begin() + index );
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebSitesModel::addNewSite()
|
|
|
|
{
|
|
|
|
Config::WebSite w;
|
|
|
|
|
|
|
|
w.enabled = false;
|
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
w.id = Dictionary::generateRandomDictionaryId();
|
2009-05-16 18:04:21 +00:00
|
|
|
|
|
|
|
w.url = "http://";
|
|
|
|
|
|
|
|
beginInsertRows( QModelIndex(), webSites.size(), webSites.size() );
|
|
|
|
webSites.push_back( w );
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex WebSitesModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return createIndex( row, column, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex WebSitesModel::parent( QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags WebSitesModel::flags( QModelIndex const & index ) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags result = QAbstractItemModel::flags( index );
|
|
|
|
|
|
|
|
if ( index.isValid() )
|
|
|
|
{
|
|
|
|
if ( !index.column() )
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
else
|
|
|
|
result |= Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebSitesModel::rowCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return webSites.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebSitesModel::columnCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
2012-12-03 12:48:31 +00:00
|
|
|
return 4;
|
2009-05-16 18:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant WebSitesModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
|
|
|
{
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
switch( section )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr( "Enabled" );
|
|
|
|
case 1:
|
|
|
|
return tr( "Name" );
|
|
|
|
case 2:
|
|
|
|
return tr( "Address" );
|
2012-12-03 12:48:31 +00:00
|
|
|
case 3:
|
|
|
|
return tr( "Icon" );
|
2009-05-16 18:04:21 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant WebSitesModel::data( QModelIndex const & index, int role ) const
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= webSites.size() )
|
2009-05-16 18:04:21 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
{
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return webSites[ index.row() ].name;
|
|
|
|
case 2:
|
|
|
|
return webSites[ index.row() ].url;
|
2012-12-03 12:48:31 +00:00
|
|
|
case 3:
|
|
|
|
return webSites[ index.row() ].iconFilename;
|
2009-05-16 18:04:21 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
2013-05-28 15:18:32 +00:00
|
|
|
return webSites[ index.row() ].enabled ? Qt::Checked : Qt::Unchecked;
|
2009-05-16 18:04:21 +00:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebSitesModel::setData( QModelIndex const & index, const QVariant & value,
|
|
|
|
int role )
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= webSites.size() )
|
2009-05-16 18:04:21 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
|
|
|
{
|
2011-06-19 18:50:11 +00:00
|
|
|
//DPRINTF( "type = %d\n", (int)value.type() );
|
|
|
|
//DPRINTF( "value = %d\n", (int)value.toInt() );
|
2009-05-16 18:04:21 +00:00
|
|
|
|
|
|
|
// XXX it seems to be always passing Int( 2 ) as a value, so we just toggle
|
|
|
|
webSites[ index.row() ].enabled = !webSites[ index.row() ].enabled;
|
|
|
|
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
webSites[ index.row() ].name = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 2:
|
|
|
|
webSites[ index.row() ].url = value.toString();
|
|
|
|
dataChanged( index, index );
|
2012-12-03 12:48:31 +00:00
|
|
|
return true;
|
|
|
|
case 3:
|
|
|
|
webSites[ index.row() ].iconFilename = value.toString();
|
|
|
|
dataChanged( index, index );
|
2009-05-16 18:04:21 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-30 12:55:53 +00:00
|
|
|
////////// DictServersModel
|
|
|
|
|
|
|
|
DictServersModel::DictServersModel( QWidget * parent,
|
|
|
|
Config::DictServers const & dictServers_ ):
|
|
|
|
QAbstractItemModel( parent ), dictServers( dictServers_ )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void DictServersModel::removeServer( int index )
|
|
|
|
{
|
|
|
|
beginRemoveRows( QModelIndex(), index, index );
|
|
|
|
dictServers.erase( dictServers.begin() + index );
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictServersModel::addNewServer()
|
|
|
|
{
|
|
|
|
Config::DictServer d;
|
|
|
|
|
|
|
|
d.enabled = false;
|
|
|
|
|
|
|
|
d.id = Dictionary::generateRandomDictionaryId();
|
|
|
|
|
|
|
|
d.url = "dict://";
|
|
|
|
|
|
|
|
beginInsertRows( QModelIndex(), dictServers.size(), dictServers.size() );
|
|
|
|
dictServers.push_back( d );
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex DictServersModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return createIndex( row, column, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex DictServersModel::parent( QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags DictServersModel::flags( QModelIndex const & index ) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags result = QAbstractItemModel::flags( index );
|
|
|
|
|
|
|
|
if ( index.isValid() )
|
|
|
|
{
|
|
|
|
if ( !index.column() )
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
else
|
|
|
|
result |= Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DictServersModel::rowCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return dictServers.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int DictServersModel::columnCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
2014-05-03 17:41:16 +00:00
|
|
|
return 6;
|
2014-04-30 12:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant DictServersModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
|
|
|
{
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
switch( section )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr( "Enabled" );
|
|
|
|
case 1:
|
|
|
|
return tr( "Name" );
|
|
|
|
case 2:
|
|
|
|
return tr( "Address" );
|
|
|
|
case 3:
|
|
|
|
return tr( "Databases" );
|
|
|
|
case 4:
|
2014-05-03 17:41:16 +00:00
|
|
|
return tr( "Strategies" );
|
|
|
|
case 5:
|
2014-04-30 12:55:53 +00:00
|
|
|
return tr( "Icon" );
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant DictServersModel::data( QModelIndex const & index, int role ) const
|
|
|
|
{
|
|
|
|
if ( index.row() >= dictServers.size() )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
{
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return dictServers[ index.row() ].name;
|
|
|
|
case 2:
|
|
|
|
return dictServers[ index.row() ].url;
|
|
|
|
case 3:
|
|
|
|
return dictServers[ index.row() ].databases;
|
|
|
|
case 4:
|
2014-05-03 17:41:16 +00:00
|
|
|
return dictServers[ index.row() ].strategies;
|
|
|
|
case 5:
|
2014-04-30 12:55:53 +00:00
|
|
|
return dictServers[ index.row() ].iconFilename;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( role == Qt::ToolTipRole && index.column() == 3 )
|
|
|
|
return tr( "Comma-delimited list of databases\n(empty string or \"*\" matches all databases)" );
|
|
|
|
|
2014-05-03 17:41:16 +00:00
|
|
|
if( role == Qt::ToolTipRole && index.column() == 4 )
|
|
|
|
return tr( "Comma-delimited list of search strategies\n(empty string mean \"prefix\" strategy)" );
|
|
|
|
|
2014-04-30 12:55:53 +00:00
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
|
|
|
return dictServers[ index.row() ].enabled ? Qt::Checked : Qt::Unchecked;
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DictServersModel::setData( QModelIndex const & index, const QVariant & value,
|
|
|
|
int role )
|
|
|
|
{
|
|
|
|
if ( index.row() >= dictServers.size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
|
|
|
{
|
|
|
|
// XXX it seems to be always passing Int( 2 ) as a value, so we just toggle
|
|
|
|
dictServers[ index.row() ].enabled = !dictServers[ index.row() ].enabled;
|
|
|
|
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
dictServers[ index.row() ].name = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 2:
|
|
|
|
dictServers[ index.row() ].url = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 3:
|
|
|
|
dictServers[ index.row() ].databases = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 4:
|
2014-05-03 17:41:16 +00:00
|
|
|
dictServers[ index.row() ].strategies = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 5:
|
2014-04-30 12:55:53 +00:00
|
|
|
dictServers[ index.row() ].iconFilename = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-16 18:04:21 +00:00
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
////////// ProgramsModel
|
|
|
|
|
|
|
|
ProgramsModel::ProgramsModel( QWidget * parent,
|
|
|
|
Config::Programs const & programs_ ):
|
|
|
|
QAbstractItemModel( parent ), programs( programs_ )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgramsModel::removeProgram( int index )
|
|
|
|
{
|
|
|
|
beginRemoveRows( QModelIndex(), index, index );
|
|
|
|
programs.erase( programs.begin() + index );
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgramsModel::addNewProgram()
|
|
|
|
{
|
|
|
|
Config::Program p;
|
|
|
|
|
|
|
|
p.enabled = false;
|
2011-05-29 07:55:57 +00:00
|
|
|
p.type = Config::Program::Audio;
|
2011-05-29 05:08:37 +00:00
|
|
|
|
|
|
|
p.id = Dictionary::generateRandomDictionaryId();
|
|
|
|
|
|
|
|
beginInsertRows( QModelIndex(), programs.size(), programs.size() );
|
|
|
|
programs.push_back( p );
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ProgramsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return createIndex( row, column, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ProgramsModel::parent( QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags ProgramsModel::flags( QModelIndex const & index ) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags result = QAbstractItemModel::flags( index );
|
|
|
|
|
|
|
|
if ( index.isValid() )
|
|
|
|
{
|
|
|
|
if ( !index.column() )
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
else
|
|
|
|
result |= Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProgramsModel::rowCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return programs.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProgramsModel::columnCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
2012-12-07 11:59:59 +00:00
|
|
|
return 5;
|
2011-05-29 05:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ProgramsModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
|
|
|
{
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
switch( section )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr( "Enabled" );
|
|
|
|
case 1:
|
|
|
|
return tr( "Type" );
|
|
|
|
case 2:
|
|
|
|
return tr( "Name" );
|
|
|
|
case 3:
|
|
|
|
return tr( "Command Line" );
|
2012-12-07 11:59:59 +00:00
|
|
|
case 4:
|
|
|
|
return tr( "Icon" );
|
2011-05-29 05:08:37 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ProgramsModel::data( QModelIndex const & index, int role ) const
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= programs.size() )
|
2011-05-29 05:08:37 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
{
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
return ProgramTypeEditor::getNameForType( programs[ index.row() ].type );
|
|
|
|
else
|
|
|
|
return QVariant( ( int ) programs[ index.row() ].type );
|
|
|
|
case 2:
|
|
|
|
return programs[ index.row() ].name;
|
|
|
|
case 3:
|
|
|
|
return programs[ index.row() ].commandLine;
|
2012-12-07 11:59:59 +00:00
|
|
|
case 4:
|
|
|
|
return programs[ index.row() ].iconFilename;
|
2011-05-29 05:08:37 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
2013-05-28 15:18:32 +00:00
|
|
|
return programs[ index.row() ].enabled ? Qt::Checked : Qt::Unchecked;
|
2011-05-29 05:08:37 +00:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProgramsModel::setData( QModelIndex const & index, const QVariant & value,
|
|
|
|
int role )
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= programs.size() )
|
2011-05-29 05:08:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
|
|
|
{
|
|
|
|
programs[ index.row() ].enabled = !programs[ index.row() ].enabled;
|
|
|
|
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
|
|
|
switch( index.column() )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
programs[ index.row() ].type = Config::Program::Type( value.toInt() );
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 2:
|
|
|
|
programs[ index.row() ].name = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
case 3:
|
|
|
|
programs[ index.row() ].commandLine = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
2012-12-07 11:59:59 +00:00
|
|
|
case 4:
|
|
|
|
programs[ index.row() ].iconFilename = value.toString();
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
2011-05-29 05:08:37 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ProgramTypeEditor::getNameForType( int v )
|
|
|
|
{
|
|
|
|
switch( v )
|
|
|
|
{
|
|
|
|
case Config::Program::Audio:
|
|
|
|
return tr( "Audio" );
|
|
|
|
case Config::Program::PlainText:
|
|
|
|
return tr( "Plain Text" );
|
|
|
|
case Config::Program::Html:
|
|
|
|
return tr( "Html" );
|
2011-06-04 21:35:09 +00:00
|
|
|
case Config::Program::PrefixMatch:
|
|
|
|
return tr( "Prefix Match" );
|
2011-05-29 05:08:37 +00:00
|
|
|
default:
|
|
|
|
return tr( "Unknown" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramTypeEditor::ProgramTypeEditor( QWidget * widget ): QComboBox( widget )
|
|
|
|
{
|
|
|
|
for( int x = 0; x < Config::Program::MaxTypeValue; ++x )
|
|
|
|
addItem( getNameForType( x ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProgramTypeEditor::getType() const
|
|
|
|
{
|
|
|
|
return currentIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgramTypeEditor::setType( int t )
|
|
|
|
{
|
|
|
|
setCurrentIndex( t );
|
|
|
|
}
|
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
////////// PathsModel
|
|
|
|
|
|
|
|
PathsModel::PathsModel( QWidget * parent,
|
|
|
|
Config::Paths const & paths_ ):
|
|
|
|
QAbstractItemModel( parent ), paths( paths_ )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PathsModel::removePath( int index )
|
|
|
|
{
|
|
|
|
beginRemoveRows( QModelIndex(), index, index );
|
|
|
|
paths.erase( paths.begin() + index );
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PathsModel::addNewPath( QString const & path )
|
|
|
|
{
|
|
|
|
beginInsertRows( QModelIndex(), paths.size(), paths.size() );
|
|
|
|
paths.push_back( Config::Path( path, false ) );
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex PathsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return createIndex( row, column, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex PathsModel::parent( QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags PathsModel::flags( QModelIndex const & index ) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags result = QAbstractItemModel::flags( index );
|
|
|
|
|
|
|
|
if ( index.isValid() && index.column() == 1 )
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PathsModel::rowCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return paths.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PathsModel::columnCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant PathsModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
|
|
|
{
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
switch( section )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr( "Path" );
|
|
|
|
case 1:
|
|
|
|
return tr( "Recursive" );
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant PathsModel::data( QModelIndex const & index, int role ) const
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= paths.size() )
|
2009-03-28 22:37:03 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( ( role == Qt::DisplayRole || role == Qt::EditRole ) && !index.column() )
|
|
|
|
return paths[ index.row() ].path;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && index.column() == 1 )
|
2013-05-28 15:18:32 +00:00
|
|
|
return paths[ index.row() ].recursive ? Qt::Checked : Qt::Unchecked;
|
2009-03-28 22:37:03 +00:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PathsModel::setData( QModelIndex const & index, const QVariant & /*value*/,
|
|
|
|
int role )
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= paths.size() )
|
2009-03-28 22:37:03 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && index.column() == 1 )
|
|
|
|
{
|
|
|
|
paths[ index.row() ].recursive = !paths[ index.row() ].recursive;
|
|
|
|
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
|
|
|
|
////////// SoundDirsModel
|
|
|
|
|
|
|
|
SoundDirsModel::SoundDirsModel( QWidget * parent,
|
|
|
|
Config::SoundDirs const & soundDirs_ ):
|
|
|
|
QAbstractItemModel( parent ), soundDirs( soundDirs_ )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundDirsModel::removeSoundDir( int index )
|
|
|
|
{
|
|
|
|
beginRemoveRows( QModelIndex(), index, index );
|
|
|
|
soundDirs.erase( soundDirs.begin() + index );
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundDirsModel::addNewSoundDir( QString const & path, QString const & name )
|
|
|
|
{
|
|
|
|
beginInsertRows( QModelIndex(), soundDirs.size(), soundDirs.size() );
|
2013-02-02 22:00:19 +00:00
|
|
|
soundDirs.push_back( Config::SoundDir( path, name ) );
|
2009-04-04 16:06:06 +00:00
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex SoundDirsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return createIndex( row, column, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex SoundDirsModel::parent( QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags SoundDirsModel::flags( QModelIndex const & index ) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags result = QAbstractItemModel::flags( index );
|
|
|
|
|
2013-02-02 18:25:24 +00:00
|
|
|
if ( index.isValid() && index.column() < 3 )
|
2009-04-04 16:06:06 +00:00
|
|
|
result |= Qt::ItemIsEditable;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundDirsModel::rowCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return soundDirs.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundDirsModel::columnCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
2013-02-02 18:25:24 +00:00
|
|
|
return 3;
|
2009-04-04 16:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SoundDirsModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
|
|
|
{
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
switch( section )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr( "Path" );
|
|
|
|
case 1:
|
|
|
|
return tr( "Name" );
|
2013-02-02 18:25:24 +00:00
|
|
|
case 2:
|
|
|
|
return tr( "Icon" );
|
2009-04-04 16:06:06 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SoundDirsModel::data( QModelIndex const & index, int role ) const
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= soundDirs.size() )
|
2009-04-04 16:06:06 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( ( role == Qt::DisplayRole || role == Qt::EditRole ) && !index.column() )
|
|
|
|
return soundDirs[ index.row() ].path;
|
2009-05-11 23:37:18 +00:00
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
if ( ( role == Qt::DisplayRole || role == Qt::EditRole ) && index.column() == 1 )
|
|
|
|
return soundDirs[ index.row() ].name;
|
|
|
|
|
2013-02-02 18:25:24 +00:00
|
|
|
if ( ( role == Qt::DisplayRole || role == Qt::EditRole ) && index.column() == 2 )
|
|
|
|
return soundDirs[ index.row() ].iconFilename;
|
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoundDirsModel::setData( QModelIndex const & index, const QVariant & value,
|
|
|
|
int role )
|
|
|
|
{
|
2012-12-10 12:49:45 +00:00
|
|
|
if ( index.row() >= soundDirs.size() )
|
2009-04-04 16:06:06 +00:00
|
|
|
return false;
|
|
|
|
|
2013-02-02 18:25:24 +00:00
|
|
|
if ( ( role == Qt::DisplayRole || role == Qt::EditRole ) && index.column() < 3 )
|
2009-04-04 16:06:06 +00:00
|
|
|
{
|
|
|
|
if ( !index.column() )
|
|
|
|
soundDirs[ index.row() ].path = value.toString();
|
2013-02-02 18:25:24 +00:00
|
|
|
else if ( index.column() == 1 )
|
2009-04-04 16:06:06 +00:00
|
|
|
soundDirs[ index.row() ].name = value.toString();
|
2013-02-02 18:25:24 +00:00
|
|
|
else
|
|
|
|
soundDirs[ index.row() ].iconFilename = value.toString();
|
2009-04-04 16:06:06 +00:00
|
|
|
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-09 14:15:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////// HunspellDictsModel
|
|
|
|
|
|
|
|
HunspellDictsModel::HunspellDictsModel( QWidget * parent,
|
|
|
|
Config::Hunspell const & hunspell ):
|
|
|
|
QAbstractItemModel( parent ), enabledDictionaries( hunspell.enabledDictionaries )
|
|
|
|
{
|
|
|
|
changePath( hunspell.dictionariesPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
void HunspellDictsModel::changePath( QString const & newPath )
|
|
|
|
{
|
|
|
|
dataFiles = HunspellMorpho::findDataFiles( newPath );
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex HunspellDictsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return createIndex( row, column, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex HunspellDictsModel::parent( QModelIndex const & /*parent*/ ) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags HunspellDictsModel::flags( QModelIndex const & index ) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags result = QAbstractItemModel::flags( index );
|
|
|
|
|
|
|
|
if ( index.isValid() )
|
|
|
|
{
|
|
|
|
if ( !index.column() )
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HunspellDictsModel::rowCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return dataFiles.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int HunspellDictsModel::columnCount( QModelIndex const & parent ) const
|
|
|
|
{
|
|
|
|
if ( parent.isValid() )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HunspellDictsModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
|
|
|
{
|
|
|
|
if ( role == Qt::DisplayRole )
|
|
|
|
switch( section )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr( "Enabled" );
|
|
|
|
case 1:
|
|
|
|
return tr( "Name" );
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HunspellDictsModel::data( QModelIndex const & index, int role ) const
|
|
|
|
{
|
|
|
|
if ( (unsigned)index.row() >= dataFiles.size() )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( role == Qt::DisplayRole && index.column() == 1 )
|
|
|
|
return dataFiles[ index.row() ].dictName;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
|
|
|
{
|
|
|
|
for( unsigned x = enabledDictionaries.size(); x--; )
|
|
|
|
{
|
|
|
|
if ( enabledDictionaries[ x ] == dataFiles[ index.row() ].dictId )
|
2013-05-28 15:18:32 +00:00
|
|
|
return Qt::Checked;
|
2009-04-09 14:15:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 15:18:32 +00:00
|
|
|
return Qt::Unchecked;
|
2009-04-09 14:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HunspellDictsModel::setData( QModelIndex const & index, const QVariant & /*value*/,
|
|
|
|
int role )
|
|
|
|
{
|
|
|
|
if ( (unsigned)index.row() >= dataFiles.size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( role == Qt::CheckStateRole && !index.column() )
|
|
|
|
{
|
|
|
|
for( unsigned x = enabledDictionaries.size(); x--; )
|
|
|
|
{
|
|
|
|
if ( enabledDictionaries[ x ] == dataFiles[ index.row() ].dictId )
|
|
|
|
{
|
|
|
|
// Remove it now
|
|
|
|
enabledDictionaries.erase( enabledDictionaries.begin() + x );
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add it
|
|
|
|
|
|
|
|
enabledDictionaries.push_back( dataFiles[ index.row() ].dictId );
|
|
|
|
|
|
|
|
dataChanged( index, index );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-05 08:57:37 +00:00
|
|
|
|
|
|
|
void Sources::on_rescan_clicked()
|
|
|
|
{
|
|
|
|
emit rescan();
|
|
|
|
}
|