You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kbibtex/src/settingsfileio.cpp

342 lines
30 KiB

12 years ago
/***************************************************************************
* Copyright (C) 2004-2009 by Thomas Fischer *
* fischer@unix-ag.uni-kl.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <tqhbuttongroup.h>
#include <tqbuttongroup.h>
#include <tqpushbutton.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include <tqcombobox.h>
#include <tqlayout.h>
#include <tqradiobutton.h>
#include <tqspinbox.h>
12 years ago
#include <tdelocale.h>
12 years ago
#include <kurl.h>
#include <tdemessagebox.h>
#include <tdefiledialog.h>
12 years ago
#include <klineedit.h>
#include <kdialog.h>
#include <kdirselectdialog.h>
#include <kiconloader.h>
#include <kpushbutton.h>
#include "settings.h"
#include "file.h"
12 years ago
#include "settingsfileio.h"
namespace KBibTeX
{
static const TQString encodingList[] =
12 years ago
{
"LaTeX", "437", "500", "500V1", "850", "851", "852", "855", "856", "857", "860", "861", "862", "863", "864", "865", "866", "866NAV", "869", "874", "904", "1026", "1046", "1047", "8859_1", "8859_2", "8859_3", "8859_4", "8859_5", "8859_6", "8859_7", "8859_8", "8859_9", "10646-1:1993", "10646-1:1993/UCS4/", "ANSI_X3.4-1968", "ANSI_X3.4-1986", "ANSI_X3.4", "ANSI_X3.110-1983", "ANSI_X3.110", "ARABIC", "ARABIC7", "ARMSCII-8", "ASCII", "ASMO-708", "ASMO_449", "BALTIC", "BIG-5", "BIG-FIVE", "BIG5-HKSCS", "BIG5", "BIG5HKSCS", "BIGFIVE", "BRF", "BS_4730", "CA", "CN-BIG5", "CN-GB", "CN", "CP-AR", "CP-GR", "CP-HU", "CP037", "CP038", "CP273", "CP274", "CP275", "CP278", "CP280", "CP281", "CP282", "CP284", "CP285", "CP290", "CP297", "CP367", "CP420", "CP423", "CP424", "CP437", "CP500", "CP737", "CP775", "CP803", "CP813", "CP819", "CP850", "CP851", "CP852", "CP855", "CP856", "CP857", "CP860", "CP861", "CP862", "CP863", "CP864", "CP865", "CP866", "CP866NAV", "CP868", "CP869", "CP870", "CP871", "CP874", "CP875", "CP880", "CP891", "CP901", "CP902", "CP903", "CP904", "CP905", "CP912", "CP915", "CP916", "CP918", "CP920", "CP921", "CP922", "CP930", "CP932", "CP933", "CP935", "CP936", "CP937", "CP939", "CP949", "CP950", "CP1004", "CP1008", "CP1025", "CP1026", "CP1046", "CP1047", "CP1070", "CP1079", "CP1081", "CP1084", "CP1089", "CP1097", "CP1112", "CP1122", "CP1123", "CP1124", "CP1125", "CP1129", "CP1130", "CP1132", "CP1133", "CP1137", "CP1140", "CP1141", "CP1142", "CP1143", "CP1144", "CP1145", "CP1146", "CP1147", "CP1148", "CP1149", "CP1153", "CP1154", "CP1155", "CP1156", "CP1157", "CP1158", "CP1160", "CP1161", "CP1162", "CP1163", "CP1164", "CP1166", "CP1167", "CP1250", "CP1251", "CP1252", "CP1253", "CP1254", "CP1255", "CP1256", "CP1257", "CP1258", "CP1361", "CP1364", "CP1371", "CP1388", "CP1390", "CP1399", "CP4517", "CP4899", "CP4909", "CP4971", "CP5347", "CP9030", "CP9066", "CP9448", "CP10007", "CP12712", "CP16804", "CPIBM861", "CSA7-1", "CSA7-2", "CSASCII", "CSA_T500-1983", "CSA_T500", "CSA_Z243.4-1985-1", "CSA_Z243.4-1985-2", "CSA_Z243.419851", "CSA_Z243.419852", "CSDECMCS", "CSEBCDICATDE", "CSEBCDICATDEA", "CSEBCDICCAFR", "CSEBCDICDKNO", "CSEBCDICDKNOA", "CSEBCDICES", "CSEBCDICESA", "CSEBCDICESS", "CSEBCDICFISE", "CSEBCDICFISEA", "CSEBCDICFR", "CSEBCDICIT", "CSEBCDICPT", "CSEBCDICUK", "CSEBCDICUS", "CSEUCKR", "CSEUCPKDFMTJAPANESE", "CSGB2312", "CSHPROMAN8", "CSIBM037", "CSIBM038", "CSIBM273", "CSIBM274", "CSIBM275", "CSIBM277", "CSIBM278", "CSIBM280", "CSIBM281", "CSIBM284", "CSIBM285", "CSIBM290", "CSIBM297", "CSIBM420", "CSIBM423", "CSIBM424", "CSIBM500", "CSIBM803", "CSIBM851", "CSIBM855", "CSIBM856", "CSIBM857", "CSIBM860", "CSIBM863", "CSIBM864", "CSIBM865", "CSIBM866", "CSIBM868", "CSIBM869", "CSIBM870", "CSIBM871", "CSIBM880", "CSIBM891", "CSIBM901", "CSIBM902", "CSIBM903", "CSIBM904", "CSIBM905", "CSIBM918", "CSIBM921", "CSIBM922", "CSIBM930", "CSIBM932", "CSIBM933", "CSIBM935", "CSIBM937", "CSIBM939", "CSIBM943", "CSIBM1008", "CSIBM1025", "CSIBM1026", "CSIBM1097", "CSIBM1112", "CSIBM1122", "CSIBM1123", "CSIBM1124", "CSIBM1129", "CSIBM1130", "CSIBM1132", "CSIBM1133", "CSIBM1137", "CSIBM1140", "CSIBM1141", "CSIBM1142", "CSIBM1143", "CSIBM1144", "CSIBM1145", "CSIBM1146", "CSIBM1147", "CSIBM1148", "CSIBM1149", "CSIBM1153", "CSIBM1154", "CSIBM1155", "CSIBM1156", "CSIBM1157", "CSIBM1158", "CSIBM1160", "CSIBM1161", "CSIBM1163", "CSIBM1164", "CSIBM1166", "CSIBM1167", "CSIBM1364", "CSIBM1371", "CSIBM1388", "CSIBM1390", "CSIBM1399", "CSIBM4517", "CSIBM4899", "CSIBM4909", "CSIBM4971", "CSIBM5347", "CSIBM9030", "CSIBM9066", "CSIBM9448", "CSIBM12712", "CSIBM16804", "CSIBM11621162", "CSISO4UNITEDKINGDOM", "CSISO10SWEDISH", "CSISO11SWEDISHFORNAMES", "CSISO14JISC6220RO", "CSISO15ITALIAN", "CSISO16PORTUGESE", "CSISO17SPANISH", "CSISO18GREEK7OLD", "CSISO19LATINGREEK", "CSISO21GERMAN", "CSISO25FRENCH", "CSISO27LATINGREEK1", "CSISO49INIS", "CSISO50INIS8", "CSISO51INISCYRILLIC", "CSISO58GB1988", "CSISO60DANISHNORWEGIAN", "CSISO60NORWEGIAN1", "CSISO61NORWEGIAN2", "CSISO69FRENCH", "CSISO84PORTUGUESE2", "CSISO85SPANISH2", "CSISO86HUNGARIAN", "
};
static const TQString LanguagesI18N = i18n( "English|German|French|Spanish|Swedish" );
static const TQString Languages[] =
12 years ago
{
"english", "german", "french", "spanish", "swedish"
};
static const TQString BibliographyStyles = i18n( "plain|achemso (American Chemical Society)|alpha|unsrt|abbrv|acm (Association of Computing Machinery)|apacite|apalike|authordate|ieeetr|natbib|siam" );
static const TQString StringDelimiters = "\"...\"|{...}|(...)";
static const TQString KeywordCasing = "@inproceedings|@Inproceedings|@InProceedings|@INPROCEEDINGS";
12 years ago
SettingsFileIO::SettingsFileIO( TQWidget *parent, const char *name )
: TQWidget( parent, name )
12 years ago
{
setupGUI();
}
SettingsFileIO::~SettingsFileIO()
{
// nothing
}
void SettingsFileIO::applyData()
{
Settings * settings = Settings::self();
settings->fileIO_Encoding = m_comboBoxEncoding->currentText().lower();
TQString delimiters = m_comboBoxStringDelimiters->currentText();
12 years ago
settings->fileIO_BibtexStringOpenDelimiter = delimiters.at( 0 ) ;
settings->fileIO_BibtexStringCloseDelimiter = delimiters.at( 4 ) ;
switch ( m_comboBoxKeywordCasing->currentItem() )
{
case 0:
settings->fileIO_KeywordCasing = BibTeX::FileExporterBibTeX::kcLowerCase;
break;
case 1:
settings->fileIO_KeywordCasing = BibTeX::FileExporterBibTeX::kcInitialCapital;
break;
case 3:
settings->fileIO_KeywordCasing = BibTeX::FileExporterBibTeX::kcCapital;
break;
default:
settings->fileIO_KeywordCasing = BibTeX::FileExporterBibTeX::kcCamelCase;
}
settings->fileIO_EnclosingCurlyBrackets = m_checkBoxProtectCasing->isChecked();
settings->fileIO_ExportLanguage = Languages[ m_comboBoxLanguage->currentItem()];
settings->fileIO_ExportBibliographyStyle = m_comboBoxBibliographyStyle->currentText().section( ' ', 0, 0 );
if ( m_comboBoxExportSystemHTML->isEnabled() )
{
TQString text = m_comboBoxExportSystemHTML->currentText();
12 years ago
if ( text == "bib2xhtml" )
settings->fileIO_ExporterHTML = BibTeX::FileExporterExternal::exporterBib2XHTML;
else if ( text == "bibtex2html" )
settings->fileIO_ExporterHTML = BibTeX::FileExporterExternal::exporterBibTeX2HTML;
else if ( text == "bibconv" )
settings->fileIO_ExporterHTML = BibTeX::FileExporterExternal::exporterBibConv;
else
settings->fileIO_ExporterHTML = BibTeX::FileExporterExternal::exporterXSLT;
}
else
settings->fileIO_ExporterHTML = BibTeX::FileExporterExternal::exporterNone;
settings->fileIO_EmbedFiles = m_checkBoxEmbedFiles->isChecked();
settings->updateBib2Db5ClassPath( m_bib2db5BasePath );
if ( m_checkBoxUseBibUtils->isEnabled() )
settings->fileIO_useBibUtils = m_checkBoxUseBibUtils->isChecked();
settings->fileIO_NumberOfBackups = m_spinBoxNumberOfBackups->value();
}
void SettingsFileIO::readData()
{
Settings * settings = Settings::self();
m_comboBoxEncoding->setCurrentItem( 0 );
for ( int i = sizeof( encodingList ) / sizeof( encodingList[0] ) - 1; i >= 0; --i )
if ( encodingList[i].lower() == settings->fileIO_Encoding )
{
m_comboBoxEncoding->setCurrentItem( i );
break;
}
TQString toMatch = TQString( settings->fileIO_BibtexStringOpenDelimiter ).append( "..." ).append( settings->fileIO_BibtexStringCloseDelimiter );
TQStringList delimiterList = TQStringList::split( '|', StringDelimiters );
12 years ago
int i = 0;
for ( TQStringList::Iterator it = delimiterList.begin(); it != delimiterList.end(); ++it, i++ )
12 years ago
if (( *it ) == toMatch )
{
m_comboBoxStringDelimiters->setCurrentItem( i );
break;
}
switch ( settings->fileIO_KeywordCasing )
{
case BibTeX::FileExporterBibTeX::kcLowerCase:
m_comboBoxKeywordCasing->setCurrentItem( 0 );
break;
case BibTeX::FileExporterBibTeX::kcInitialCapital:
m_comboBoxKeywordCasing->setCurrentItem( 1 );
break;
case BibTeX::FileExporterBibTeX::kcCapital:
m_comboBoxKeywordCasing->setCurrentItem( 3 );
break;
default:
m_comboBoxKeywordCasing->setCurrentItem( 2 );
}
m_checkBoxProtectCasing->setChecked( settings->fileIO_EnclosingCurlyBrackets );
for ( int i = 0; i < m_comboBoxLanguage->count(); i++ )
if ( Languages[ i ] == settings->fileIO_ExportLanguage )
{
m_comboBoxLanguage->setCurrentItem( i );
break;
}
m_comboBoxBibliographyStyle->setCurrentText( settings->fileIO_ExportBibliographyStyle );
m_comboBoxExportSystemHTML->clear();
m_comboBoxExportSystemHTML->insertItem( i18n( "XSLT Stylesheet" ) );
if ( settings->fileIO_ExporterHTML == BibTeX::FileExporterExternal::exporterXSLT )
m_comboBoxExportSystemHTML->setCurrentItem( m_comboBoxExportSystemHTML->count() - 1 );
if ( settings->external_bib2xhtmlAvailable )
{
m_comboBoxExportSystemHTML->insertItem( "bib2xhtml" );
if ( settings->fileIO_ExporterHTML == BibTeX::FileExporterExternal::exporterBib2XHTML )
m_comboBoxExportSystemHTML->setCurrentItem( m_comboBoxExportSystemHTML->count() - 1 );
}
if ( settings->external_bibtex2htmlAvailable )
{
m_comboBoxExportSystemHTML->insertItem( "bibtex2html" );
if ( settings->fileIO_ExporterHTML == BibTeX::FileExporterExternal::exporterBibTeX2HTML )
m_comboBoxExportSystemHTML->setCurrentItem( m_comboBoxExportSystemHTML->count() - 1 );
}
if ( settings->external_bibconvAvailable )
{
m_comboBoxExportSystemHTML->insertItem( "bibconv" );
if ( settings->fileIO_ExporterHTML == BibTeX::FileExporterExternal::exporterBibConv )
m_comboBoxExportSystemHTML->setCurrentItem( m_comboBoxExportSystemHTML->count() - 1 );
}
if ( m_comboBoxExportSystemHTML->count() == 0 )
{
m_comboBoxExportSystemHTML->insertItem( i18n( "No exporter available" ) );
m_comboBoxExportSystemHTML->setEnabled( FALSE );
}
m_checkBoxEmbedFiles->setChecked( settings->fileIO_EmbedFiles );
m_bib2db5BasePath = settings->fileIO_bib2db5BasePath;
m_lineeditBib2Db5Path->setText( m_bib2db5BasePath );
if ( m_checkBoxUseBibUtils->isEnabled() )
m_checkBoxUseBibUtils->setChecked( settings->fileIO_useBibUtils );
m_spinBoxNumberOfBackups->setValue( settings->fileIO_NumberOfBackups );
}
void SettingsFileIO::slotConfigChanged()
{
emit configChanged();
}
void SettingsFileIO::slotBib2db5BasePath()
{
KURL newPath = KDirSelectDialog::selectDirectory( m_bib2db5BasePath, true, this, i18n( "Path to the jar files for bib2db5" ) );
if ( !newPath.isEmpty() && newPath.isValid() && newPath.isLocalFile() )
{
m_bib2db5BasePath = newPath.directory() + TQDir::separator() + newPath.fileName();
12 years ago
m_lineeditBib2Db5Path->setText( m_bib2db5BasePath );
slotCheckBib2Db5Path();
}
}
void SettingsFileIO::slotCheckBib2Db5Path()
{
if ( !Settings::self()->updateBib2Db5ClassPath( m_lineeditBib2Db5Path->text(), true ) )
{
KMessageBox::error( this, i18n( "To export DocBook5 bibliographies, the path to the jar file for bib2db5 has to be set first." ), i18n( "Invalid path for bib2db5" ) );
}
}
void SettingsFileIO::setupGUI()
{
TQVBoxLayout * layout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
12 years ago
TQGroupBox *groupBox = new TQGroupBox( 2, Horizontal, i18n( "BibTeX Import and Export" ), this );
12 years ago
layout->addWidget( groupBox );
TQLabel *label = new TQLabel( i18n( "&Encoding:" ), groupBox );
m_comboBoxEncoding = new TQComboBox( groupBox );
12 years ago
label->setBuddy( m_comboBoxEncoding );
label = new TQLabel( i18n( "Text &delimiters:" ), groupBox );
m_comboBoxStringDelimiters = new TQComboBox( groupBox );
12 years ago
label->setBuddy( m_comboBoxStringDelimiters );
label = new TQLabel( i18n( "Keyword casing:" ), groupBox );
m_comboBoxKeywordCasing = new TQComboBox( groupBox );
12 years ago
label->setBuddy( m_comboBoxKeywordCasing );
label = new TQLabel( i18n( "Protect title's casing:" ), groupBox );
m_checkBoxProtectCasing = new TQCheckBox( i18n( "Put curly brackets around" ), groupBox );
TQToolTip::add( m_checkBoxProtectCasing, i18n( "Put curly brackets around title and other selected fields." ) );
TQWhatsThis::add( m_checkBoxProtectCasing, i18n( "Put curly brackets around title and other selected fields to protect them from case changes in certain BibTeX styles." ) );
12 years ago
groupBox = new TQGroupBox( 2, Horizontal, i18n( "PDF, PostScript and Rich Text Format Export" ), this );
12 years ago
layout->addWidget( groupBox );
TQWhatsThis::add( groupBox, i18n( "Select the layout of the resulting PDF, PostScript or Rich Text Format document when exporting a BibTeX file." ) );
label = new TQLabel( i18n( "&Language:" ), groupBox );
m_comboBoxLanguage = new TQComboBox( groupBox );
12 years ago
label->setBuddy( m_comboBoxLanguage );
label = new TQLabel( i18n( "&Biblography style:" ), groupBox );
m_comboBoxBibliographyStyle = new TQComboBox( TRUE, groupBox );
12 years ago
label->setBuddy( m_comboBoxBibliographyStyle );
groupBox = new TQGroupBox( 1, Horizontal, i18n( "PDF Export" ), this );
12 years ago
layout->addWidget( groupBox );
m_checkBoxEmbedFiles = new TQCheckBox( i18n( "Embed local files into PDF if possible" ), groupBox );
TQWhatsThis::add( m_checkBoxEmbedFiles, i18n( "<qt>If checked, KBibTeX tries to embed all referenced files for the BibTeX entries into the exported PDF file.<br/>This requires that you have installed <tt>embedfile.sty</tt>.</qt>" ) );
12 years ago
groupBox = new TQGroupBox( 2, Horizontal, i18n( "XML Export" ), this );
12 years ago
layout->addWidget( groupBox );
label->setBuddy( m_comboBoxEncoding );
label = new TQLabel( i18n( "Path to the jar files for bib2db5:" ), groupBox );
TQWidget *container = new TQWidget( groupBox );
TQBoxLayout *containerLayout = new TQHBoxLayout( container, 0, KDialog::spacingHint() );
12 years ago
m_lineeditBib2Db5Path = new KLineEdit( container );
m_lineeditBib2Db5Path->setReadOnly( true );
containerLayout->addWidget( m_lineeditBib2Db5Path );
containerLayout->setStretchFactor( m_lineeditBib2Db5Path, 10 );
KPushButton *buttonBib2Db5 = new KPushButton( container );
label->setBuddy( buttonBib2Db5 );
containerLayout->addWidget( buttonBib2Db5 );
containerLayout->setStretchFactor( buttonBib2Db5, 1 );
buttonBib2Db5->setIconSet( TQIconSet( SmallIcon( "folder_open" ) ) );
12 years ago
label->setBuddy( buttonBib2Db5 );
connect( buttonBib2Db5, SIGNAL( clicked() ), this, SLOT( slotBib2db5BasePath() ) );
groupBox = new TQGroupBox( 2, Horizontal, i18n( "Export Systems" ), this );
12 years ago
layout->addWidget( groupBox );
label = new TQLabel( i18n( "HTML:" ), groupBox );
m_comboBoxExportSystemHTML = new TQComboBox( FALSE, groupBox );
12 years ago
label->setBuddy( m_comboBoxExportSystemHTML );
groupBox = new TQGroupBox( 1, Horizontal, i18n( "BibUtils" ), this );
12 years ago
layout->addWidget( groupBox );
m_checkBoxUseBibUtils = new TQCheckBox( i18n( "Always use BibUtils" ), groupBox );
TQToolTip::add( m_checkBoxUseBibUtils, i18n( "If possible, use BibUtils to import and export alien bibliography." ) );
TQWhatsThis::add( m_checkBoxUseBibUtils, i18n( "If possible, use BibUtils to import and export alien bibliography such as RIS.\nIf unchecked, prefer internal import and export library." ) );
12 years ago
/** command line tools from BibUtils must be available to enable this option */
m_checkBoxUseBibUtils->setEnabled( Settings::self()->external_xml2bibAvailable && Settings::self()->external_ris2xmlAvailable );
groupBox = new TQGroupBox( 2, Horizontal, i18n( "Backups" ), this );
12 years ago
layout->addWidget( groupBox );
label = new TQLabel( i18n( "Number of Backups:" ), groupBox );
m_spinBoxNumberOfBackups = new TQSpinBox( 0, 15, 1, groupBox, "m_spinBoxNumberOfBackups" );
12 years ago
m_spinBoxNumberOfBackups->setSpecialValueText( "No backups" );
label->setBuddy( m_spinBoxNumberOfBackups );
layout->addStretch( 1 );
for ( unsigned int i = 0; i < sizeof( encodingList ) / sizeof( encodingList[0] ); ++i )
m_comboBoxEncoding->insertItem( encodingList[i] );
TQStringList delimiterList = TQStringList::split( '|', StringDelimiters );
12 years ago
m_comboBoxStringDelimiters->insertStringList( delimiterList );
TQStringList keywordCasingList = TQStringList::split( '|', KeywordCasing );
12 years ago
m_comboBoxKeywordCasing->insertStringList( keywordCasingList );
TQStringList langList = TQStringList::split( '|', LanguagesI18N );
12 years ago
m_comboBoxLanguage->insertStringList( langList );
TQStringList bibList = TQStringList::split( '|', BibliographyStyles );
12 years ago
bibList.sort();
m_comboBoxBibliographyStyle->insertStringList( bibList );
connect( m_comboBoxEncoding, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
connect( m_comboBoxStringDelimiters, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
connect( m_comboBoxKeywordCasing, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
connect( m_comboBoxLanguage, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
connect( m_comboBoxBibliographyStyle, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
connect( m_comboBoxExportSystemHTML, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
}
}
#include "settingsfileio.moc"