File indexing completed on 2025-02-16 13:49:57
0001 /* This file is part of the KDE project 0002 Copyright (C) 2002, 2003 Robert JACOLIN <rjacolin@ifrance.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 This file use code from koTemplateOpenDia for the method chooseSlot. 0019 */ 0020 0021 #include "latexexportdialog.h" 0022 0023 #include <QDir> 0024 #include <QApplication> 0025 #include <QDBusConnection> 0026 0027 #include <KLocalizedString> 0028 #include <kconfig.h> 0029 #include <KoFilterManager.h> 0030 0031 #include "LatexDebug.h" 0032 #include "latexexportAdaptor.h" 0033 0034 #include "document.h" 0035 0036 /*#ifdef __FreeBSD__ 0037 #include <unistd.h> 0038 #endif*/ 0039 0040 /* 0041 * Constructs a LatexExportDialog which is a child of 'parent', with the 0042 * name 'name' and widget flags set to 'f'. 0043 * 0044 * The dialog will by default be modeless, unless you set 'modal' to 0045 * true to construct a modal dialog. 0046 */ 0047 LatexExportDialog::LatexExportDialog(KoStore* inputStore, QWidget* parent) 0048 : KoDialog(parent) 0049 , m_inputStore(inputStore) 0050 { 0051 QWidget *mainWidget = new QWidget(); 0052 m_ui.setupUi(mainWidget); 0053 0054 int i = 0; 0055 0056 QApplication::restoreOverrideCursor(); 0057 0058 /* Recent files */ 0059 m_config = new KConfig("kspreadlatexexportdialog"); 0060 //m_config->setGroup( "KSpread latex export filter" ); 0061 QString value; 0062 while (i < 10) { 0063 /*value = m_config->readPathEntry( QString("Recent%1").arg(i), QString() ); 0064 debugLatex <<"recent :" << value; 0065 if(!value.isEmpty()) 0066 { 0067 _recentList.append( value ); 0068 recentBox->addItem(value); 0069 } 0070 else 0071 i = 10;*/ 0072 i = i + 1; 0073 } 0074 0075 new LatexExportAdaptor(this); 0076 QDBusConnection::sessionBus().registerObject("/filter/latex", this); 0077 0078 0079 /* All these items inserted must not be translated so they are inserted here 0080 * without i18n() method. */ 0081 /*qualityComboBox->addItem("final"); 0082 qualityComboBox->addItem("draft");*/ 0083 0084 KComboBox* classComboBox = m_ui.classComboBox; 0085 classComboBox->addItem("article"); 0086 classComboBox->addItem("book"); 0087 classComboBox->addItem("letter"); 0088 classComboBox->addItem("report"); 0089 classComboBox->addItem("slides"); 0090 0091 KComboBox* encodingComboBox = m_ui.encodingComboBox; 0092 encodingComboBox->addItem("unicode"); 0093 encodingComboBox->addItem("ansinew"); 0094 encodingComboBox->addItem("applemac"); 0095 encodingComboBox->addItem("ascii"); 0096 encodingComboBox->addItem("latin1"); 0097 encodingComboBox->addItem("latin2"); 0098 encodingComboBox->addItem("latin3"); 0099 encodingComboBox->addItem("latin5"); 0100 encodingComboBox->addItem("cp437"); 0101 encodingComboBox->addItem("cp437de"); 0102 encodingComboBox->addItem("cp850"); 0103 encodingComboBox->addItem("cp852"); 0104 encodingComboBox->addItem("cp865"); 0105 encodingComboBox->addItem("cp1250"); 0106 encodingComboBox->addItem("cp1252"); 0107 encodingComboBox->addItem("decmulti"); 0108 encodingComboBox->addItem("next"); 0109 0110 QListWidget* languagesList = m_ui.languagesList; 0111 languagesList->addItem("american"); 0112 languagesList->addItem("austrian"); 0113 languagesList->addItem("bahasa"); 0114 languagesList->addItem("brazil"); 0115 languagesList->addItem("breton"); 0116 languagesList->addItem("catalan"); 0117 languagesList->addItem("croatian"); 0118 languagesList->addItem("czech"); 0119 languagesList->addItem("danish"); 0120 languagesList->addItem("dutch"); 0121 languagesList->addItem("english"); 0122 languagesList->addItem("esperanto"); 0123 languagesList->addItem("finnish"); 0124 languagesList->addItem("francais"); 0125 languagesList->addItem("french"); 0126 languagesList->addItem("galician"); 0127 languagesList->addItem("german"); 0128 languagesList->addItem("germanb"); 0129 languagesList->addItem("hungarian"); 0130 languagesList->addItem("magyar"); 0131 languagesList->addItem("italian"); 0132 languagesList->addItem("norsk"); 0133 languagesList->addItem("nynorsk"); 0134 languagesList->addItem("polish"); 0135 languagesList->addItem("portuges"); 0136 languagesList->addItem("romanian"); 0137 languagesList->addItem("russian"); 0138 languagesList->addItem("spanish"); 0139 languagesList->addItem("slovak"); 0140 languagesList->addItem("slovene"); 0141 languagesList->addItem("swedish"); 0142 languagesList->addItem("turkish"); 0143 0144 connect(m_ui.addLanguageBtn, SIGNAL(clicked(bool)), SLOT(addLanguage())); 0145 connect(m_ui.rmLanguageBtn, SIGNAL(clicked(bool)), SLOT(removeLanguage())); 0146 0147 setMainWidget(mainWidget); 0148 0149 setButtons(Ok | Cancel); 0150 setDefaultButton(Ok); 0151 setModal(true); 0152 setCaption(i18n("Latex Export Filter Configuration")); 0153 } 0154 0155 /* 0156 * Destroys the object and frees any allocated resources 0157 */ 0158 LatexExportDialog::~LatexExportDialog() 0159 { 0160 delete m_config; 0161 } 0162 0163 /** 0164 * Called when the cancel button is clicked. 0165 * Close the dialog box. 0166 */ 0167 void LatexExportDialog::reject() 0168 { 0169 debugLatex << "Export cancelled"; 0170 QDialog::reject(); 0171 } 0172 0173 /** 0174 * Called when the user clicks on the ok button. The xslt sheet is put on the recent list which is 0175 * saved, then export the document. 0176 */ 0177 void LatexExportDialog::accept() 0178 { 0179 hide(); 0180 debugLatex << "KSPREAD LATEX EXPORT FILTER --> BEGIN"; 0181 Config* config = Config::instance(); 0182 0183 /* Document tab */ 0184 config->setEmbeded(m_ui.embededButton->isChecked()); 0185 if (m_ui.wordsStyleButton->isChecked()) 0186 config->useWordsStyle(); 0187 else 0188 config-> useLatexStyle(); 0189 /* class names are not translated */ 0190 config->setClass(m_ui.classComboBox->currentText()); 0191 0192 if (m_ui.qualityComboBox->currentIndex() == 0) 0193 config->setQuality("final"); 0194 else 0195 config->setQuality("draft"); 0196 config->setDefaultFontSize(m_ui.defaultFontSize->value()); 0197 0198 /* Pictures tab */ 0199 if (m_ui.pictureCheckBox->isChecked()) 0200 config->convertPictures(); 0201 config->setPicturesDir(m_ui.pathPictures->url().path()); 0202 0203 /* Language tab */ 0204 config->setEncoding(m_ui.encodingComboBox->currentText()); 0205 QListWidget* langUsedList = m_ui.langUsedList; 0206 for (int index = 0; index < langUsedList->count(); ++index) { 0207 debugLatex << "lang. :" << langUsedList->item(index)->text(); 0208 config->addLanguage(langUsedList->item(index)->text()); 0209 } 0210 0211 /* The default language is the first language in the list */ 0212 if (langUsedList->item(0) != nullptr) 0213 config->setDefaultLanguage(langUsedList->item(0)->text()); 0214 if (langUsedList->currentItem() != nullptr) { 0215 const QString currentLanguage = langUsedList->currentItem()->text(); 0216 debugLatex << "default lang. :" << currentLanguage; 0217 config->setDefaultLanguage(currentLanguage); 0218 } 0219 0220 Document doc(m_inputStore, m_fileOut); 0221 // debugLatex << "---------- analyze file -------------"; 0222 doc.analyze(); 0223 // debugLatex << "---------- generate file -------------"; 0224 doc.generate(); 0225 // debugLatex << "KSPREAD LATEX EXPORT FILTER --> END"; 0226 } 0227 0228 void LatexExportDialog::addLanguage() 0229 { 0230 QListWidgetItem* currentItem = m_ui.languagesList->takeItem(m_ui.languagesList->currentRow()); 0231 if (! currentItem) { 0232 return; 0233 } 0234 const QString text = currentItem->text(); 0235 debugLatex << "add a new supported language" << text; 0236 m_ui.langUsedList->addItem(text); 0237 delete currentItem; 0238 } 0239 0240 void LatexExportDialog::removeLanguage() 0241 { 0242 QListWidgetItem* currentItem = m_ui.langUsedList->takeItem(m_ui.langUsedList->currentRow()); 0243 if (! currentItem) { 0244 return; 0245 } 0246 const QString text = currentItem->text(); 0247 debugLatex << "remove a language" << text; 0248 m_ui.languagesList->addItem(text); 0249 delete currentItem; 0250 }