1 #include "dictinfo.hh"
2 #include "langcoder.hh"
3 #include "language.hh"
4 #include "fsencoding.hh"
5 #include <QString>
6 
DictInfo(Config::Class & cfg_,QWidget * parent)7 DictInfo::DictInfo( Config::Class &cfg_, QWidget *parent ) :
8   QDialog( parent),
9   cfg( cfg_)
10 {
11   ui.setupUi( this );
12   if( cfg.dictInfoGeometry.size() > 0 )
13     restoreGeometry( cfg.dictInfoGeometry );
14   connect( this, SIGNAL( finished( int ) ), this, SLOT( savePos( int ) ) );
15 }
16 
showInfo(sptr<Dictionary::Class> dict)17 void DictInfo::showInfo( sptr<Dictionary::Class> dict )
18 {
19   setWindowTitle( QString::fromUtf8( dict->getName().data(), dict->getName().size() ) );
20 
21   ui.dictionaryTotalArticles->setText( QString::number( dict->getArticleCount() ) );
22   ui.dictionaryTotalWords->setText( QString::number( dict->getWordCount() ) );
23   ui.dictionaryTranslatesFrom->setText( Language::localizedStringForId( dict->getLangFrom() ) );
24   ui.dictionaryTranslatesTo->setText( Language::localizedStringForId( dict->getLangTo() ) );
25 
26   ui.openFolder->setVisible( dict->isLocalDictionary() );
27   ui.editDictionary->setVisible( dict->isLocalDictionary() && !dict->getMainFilename().isEmpty() && !cfg.editDictionaryCommandLine.isEmpty());
28   ui.editDictionary->setToolTip(
29         tr( "Edit the dictionary via command:\n%1" ).arg( cfg.editDictionaryCommandLine ) );
30 
31   if( dict->getWordCount() == 0 )
32     ui.headwordsButton->setVisible( false );
33   else
34     ui.buttonsLayout->insertSpacerItem( 0, new QSpacerItem( 40, 20, QSizePolicy::Expanding ) );
35 
36   std::vector< std::string > const & filenames = dict->getDictionaryFilenames();
37 
38   QString filenamesText;
39 
40   for( unsigned x = 0; x < filenames.size(); x++ )
41   {
42     filenamesText += FsEncoding::decode( filenames[ x ].c_str() );
43     filenamesText += '\n';
44   }
45 
46   ui.dictionaryFileList->setPlainText( filenamesText );
47 
48   QString info = dict->getDescription();
49 
50   if( !info.isEmpty() && info.compare( "NONE" ) != 0 )
51     ui.infoLabel->setPlainText( info );
52   else
53     ui.infoLabel->clear();
54 
55   setWindowIcon( dict->getIcon() );
56 }
57 
savePos(int)58 void DictInfo::savePos( int )
59 {
60   cfg.dictInfoGeometry = saveGeometry();
61 }
62 
on_editDictionary_clicked()63 void DictInfo::on_editDictionary_clicked()
64 {
65   done( EDIT_DICTIONARY );
66 }
67 
on_openFolder_clicked()68 void DictInfo::on_openFolder_clicked()
69 {
70   done( OPEN_FOLDER );
71 }
72 
on_OKButton_clicked()73 void DictInfo::on_OKButton_clicked()
74 {
75   done( ACCEPTED );
76 }
77 
on_headwordsButton_clicked()78 void DictInfo::on_headwordsButton_clicked()
79 {
80   done( SHOW_HEADWORDS );
81 }
82