2010-05-08 18:59:59 +00:00
|
|
|
/* This file is (c) 2008-2010 Konstantin Isakov <ikm@users.berlios.de>
|
2009-05-18 18:01:50 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "orderandprops.hh"
|
|
|
|
#include "instances.hh"
|
2009-05-24 15:45:37 +00:00
|
|
|
#include "langcoder.hh"
|
2009-05-24 16:38:08 +00:00
|
|
|
#include "language.hh"
|
2009-05-18 18:01:50 +00:00
|
|
|
|
|
|
|
OrderAndProps::OrderAndProps( QWidget * parent,
|
|
|
|
Config::Group const & dictionaryOrder,
|
|
|
|
Config::Group const & inactiveDictionaries,
|
|
|
|
std::vector< sptr< Dictionary::Class > > const &
|
|
|
|
allDictionaries ):
|
|
|
|
QWidget( parent )
|
|
|
|
{
|
|
|
|
ui.setupUi( this );
|
2009-05-23 14:19:57 +00:00
|
|
|
|
2009-05-24 15:45:37 +00:00
|
|
|
// For now we don't support arrows, so remove them until we get to that
|
|
|
|
delete ui.moveActiveUp;
|
|
|
|
delete ui.moveActiveDown;
|
|
|
|
|
|
|
|
delete ui.moveToActive;
|
|
|
|
delete ui.moveToInactive;
|
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
Instances::Group order( dictionaryOrder, allDictionaries );
|
|
|
|
Instances::Group inactive( inactiveDictionaries, allDictionaries );
|
|
|
|
|
|
|
|
Instances::complementDictionaryOrder( order, inactive, allDictionaries );
|
|
|
|
|
|
|
|
ui.dictionaryOrder->populate( order.dictionaries, allDictionaries );
|
|
|
|
ui.inactiveDictionaries->populate( inactive.dictionaries, allDictionaries );
|
2009-05-24 15:45:37 +00:00
|
|
|
|
|
|
|
disableDictionaryDescription();
|
2010-09-16 18:49:42 +00:00
|
|
|
|
|
|
|
connect(ui.dictionaryOrder->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
|
|
|
this, SLOT(dictionaryChanged(QModelIndex,QModelIndex)));
|
|
|
|
|
|
|
|
connect(ui.inactiveDictionaries->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
|
|
|
this, SLOT(inactiveChanged(QModelIndex,QModelIndex)));
|
2009-05-18 18:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Config::Group OrderAndProps::getCurrentDictionaryOrder() const
|
|
|
|
{
|
|
|
|
Instances::Group g( "" );
|
|
|
|
|
|
|
|
g.dictionaries = ui.dictionaryOrder->getCurrentDictionaries();
|
|
|
|
|
|
|
|
return g.makeConfigGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
Config::Group OrderAndProps::getCurrentInactiveDictionaries() const
|
|
|
|
{
|
|
|
|
Instances::Group g( "" );
|
|
|
|
|
|
|
|
g.dictionaries = ui.inactiveDictionaries->getCurrentDictionaries();
|
|
|
|
|
|
|
|
return g.makeConfigGroup();
|
|
|
|
}
|
2009-05-24 15:45:37 +00:00
|
|
|
|
2010-09-16 18:49:42 +00:00
|
|
|
void OrderAndProps::dictionaryChanged( const QModelIndex & current, const QModelIndex & )
|
2009-05-24 15:45:37 +00:00
|
|
|
{
|
2010-09-16 18:49:42 +00:00
|
|
|
describeDictionary( ui.dictionaryOrder, current );
|
2009-05-24 15:45:37 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:49:42 +00:00
|
|
|
void OrderAndProps::inactiveChanged( const QModelIndex & current, const QModelIndex & )
|
2009-05-24 15:45:37 +00:00
|
|
|
{
|
2010-09-16 18:49:42 +00:00
|
|
|
describeDictionary( ui.inactiveDictionaries, current );
|
2009-05-24 15:45:37 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:49:42 +00:00
|
|
|
|
2009-05-24 15:45:37 +00:00
|
|
|
void OrderAndProps::disableDictionaryDescription()
|
|
|
|
{
|
|
|
|
ui.dictionaryInformation->setEnabled( false );
|
|
|
|
|
|
|
|
ui.dictionaryName->clear();
|
|
|
|
ui.dictionaryTotalArticles->clear();
|
|
|
|
ui.dictionaryTotalWords->clear();
|
|
|
|
ui.dictionaryTranslatesFrom->clear();
|
|
|
|
ui.dictionaryTranslatesTo->clear();
|
|
|
|
ui.dictionaryFileList->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2009-05-24 16:38:08 +00:00
|
|
|
QString makeLangText( Language::Id langId )
|
2009-05-24 15:45:37 +00:00
|
|
|
{
|
2009-05-24 16:38:08 +00:00
|
|
|
QString name = Language::localizedNameForId( langId );
|
2009-05-24 15:45:37 +00:00
|
|
|
|
|
|
|
if ( name.isEmpty() )
|
|
|
|
return name;
|
|
|
|
|
2009-08-07 17:00:03 +00:00
|
|
|
QString iconId = Language::countryCodeForId( langId );
|
2009-05-24 15:45:37 +00:00
|
|
|
|
|
|
|
return QString( "<img src=\":/flags/%1.png\"> %2" ).arg( iconId ).arg( name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const & idx )
|
|
|
|
{
|
|
|
|
if ( !idx.isValid() || (unsigned) idx.row() >= lst->getCurrentDictionaries().size() )
|
|
|
|
disableDictionaryDescription();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sptr< Dictionary::Class > dict = lst->getCurrentDictionaries()[ idx.row() ];
|
|
|
|
|
|
|
|
ui.dictionaryInformation->setEnabled( true );
|
|
|
|
|
|
|
|
ui.dictionaryName->setText( QString::fromUtf8( dict->getName().c_str() ) );
|
|
|
|
|
|
|
|
ui.dictionaryTotalArticles->setText( QString::number( dict->getArticleCount() ) );
|
|
|
|
ui.dictionaryTotalWords->setText( QString::number( dict->getWordCount() ) );
|
|
|
|
ui.dictionaryTranslatesFrom->setText( makeLangText( dict->getLangFrom() ) );
|
|
|
|
ui.dictionaryTranslatesTo->setText( makeLangText( dict->getLangTo() ) );
|
|
|
|
|
|
|
|
std::vector< std::string > const & filenames = dict->getDictionaryFilenames();
|
|
|
|
|
|
|
|
QString filenamesText;
|
|
|
|
|
|
|
|
for( unsigned x = 0; x < filenames.size(); x++ )
|
|
|
|
{
|
|
|
|
filenamesText += QString::fromLocal8Bit( filenames[ x ].c_str() );
|
|
|
|
filenamesText += '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.dictionaryFileList->setPlainText( filenamesText );
|
|
|
|
}
|
|
|
|
}
|