filters

lateximportdia.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Robert JACOLIN <rjacolin@ifrance.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 /*
00021    This file is based on the file :
00022     koffice/filters/kword/html/htmlexportdia.cc
00023     Copyright (C) 2001 Nicolas Goutte <goutte@kde.org>
00024 
00025    which was based on the old file:
00026     /home/kde/koffice/filters/kspread/csv/csvfilterdia.cc
00027 
00028    The old file was copyrighted by
00029     Copyright (C) 1999 David Faure <faure@kde.org>
00030 
00031    The old file was licensed under the terms of the GNU Library General Public
00032    License version 2.
00033 */
00034 
00035 #include <kapplication.h>
00036 #include <lateximportdia.h>
00037 #include <lateximportdia.moc>
00038 #include <dcopclient.h>
00039 #include <ktempfile.h>
00040 #include <qptrlist.h>
00041 
00042 #include "latexparser.h"
00043 #include "config.h"
00044 
00045 #include "generator/kwordgenerator.h"
00046 
00047 LATEXImportDia::LATEXImportDia(KoStore* out, QWidget *parent, const char *name) :
00048                         KDialogBase(parent, name, true, i18n("Latex Import Filter Parameters"),
00049                                     Ok|Cancel),
00050                         DCOPObject("FilterConfigDia"), _out(out)
00051 {
00052     _out = out;
00053     kapp->restoreOverrideCursor();
00054     createDialog();
00055     if(!kapp->dcopClient()->isRegistered() )
00056     {
00057         kapp->dcopClient()->registerAs("FilterConfigDia");
00058         kapp->dcopClient()->setDefaultObject(objId());
00059     }
00060 }
00061 
00062 void LATEXImportDia::createDialog()
00063 {
00064     resize(size());
00065     QWidget *page = new QWidget( this );
00066     setMainWidget(page);
00067     QBoxLayout *mainLayout = new QVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint());
00068     styleBox = new QVButtonGroup(i18n("Document Style"), page);
00069     mainLayout->addWidget(styleBox);
00070 
00071     /* First part */
00072     QBoxLayout *styleLayout = new QVBoxLayout(page);
00073 
00074     latexStyleRBtn = new QRadioButton(i18n("Latex style"), styleBox);
00075     styleLayout->addWidget(latexStyleRBtn);
00076 
00077     kwordStyleRBtn = new QRadioButton(i18n("KWord style"), styleBox);
00078     styleLayout->addWidget(kwordStyleRBtn);
00079 
00080     /*typeLabel  = new ...
00081     styleLayout->addWidget(typeLabel);
00082     typeCBox = new ...
00083     styleLayout->addWidget(typeCBox);
00084     */
00085     styleBox->setExclusive(true);
00086     styleBox->setButton(0);         /* LATEX STYLE IS DEFAULT */
00087     styleLayout->activate();
00088 
00089     /* Second part */
00090     langBox = new QVButtonGroup(i18n("Language"), page);
00091     mainLayout->addWidget(langBox);
00092 
00093     QBoxLayout *langLayout = new QVBoxLayout(langBox);
00094 
00095     unicodeRBtn = new QRadioButton(i18n("Unicode"), langBox);
00096     langLayout->addWidget(unicodeRBtn);
00097 
00098     latin1RBtn = new QRadioButton(i18n("latin1"), langBox);
00099     langLayout->addWidget(latin1RBtn);
00100 
00101     /*babelCheckBox = new ...
00102     langLayout->addWidget(babelCheckBox);
00103 
00104     babelCBox = new ...
00105     langLayout->addWidget(babelCBox);
00106     */
00107     langBox->setExclusive(true);
00108     langBox->setButton(1);          /* LATIN1 IS THE DEFAULT. */
00109     langLayout->activate();
00110 
00111     /* Third part */
00112     docBox = new QVButtonGroup(i18n("Document Type"), page);
00113     mainLayout->addWidget(docBox);
00114 
00115     QBoxLayout *docLayout = new QVBoxLayout(docBox);
00116 
00117     newDocRBtn = new QRadioButton(i18n("New document"), docBox);
00118     docLayout->addWidget(newDocRBtn);
00119 
00120     embededRBtn = new QRadioButton(i18n("Embedded document"), docBox);
00121     docLayout->addWidget(embededRBtn);
00122 
00123     docBox->setExclusive(true);
00124     docBox->setButton(0);           /* NEW DOC IS THE DEFAULT. */
00125     docLayout->activate();
00126 
00127     /* Display the main layout */
00128     mainLayout->addStretch(5);
00129     mainLayout->activate();
00130 }
00131 
00132 void LATEXImportDia::state()
00133 {
00134     Config config;
00135 
00136     if(newDocRBtn == docBox->selected())
00137         config.setType(TYPE_DOC);
00138     else if(embededRBtn == docBox->selected())
00139         config.setType(TYPE_EMBEDED);
00140 
00141     if(unicodeRBtn == langBox->selected())
00142         config.setEncoding(ENC_UNICODE);
00143     else if(latin1RBtn == langBox->selected())
00144         config.setEncoding(ENC_LATIN1);
00145 
00146     /*if(latexStyleRBtn == styleBox->selected())
00147         config.result += "LATEX";
00148     else if(kwordStyleRBtn == styleBox->selected())
00149         result += "KWORD";*/
00150 }
00151 
00152 void LATEXImportDia::slotOk()
00153 {
00154     hide();
00155     state();
00156     kdDebug(30522) << "LATEX FILTER --> BEGIN" << endl;
00157     LatexParser parser(_fileIn);
00158     QPtrList<Element>* root = parser.parse();
00159     kdDebug(30522) << "---------- generate file -------------" << endl;
00160     kdDebug(30522) << "command: " << root->count() << endl;
00161     Element* elt;
00162     for(elt = root->first(); elt; elt = root->next())
00163     {
00164         elt->print();
00165     }
00166     KwordGenerator generator(root);
00167     generator.convert(_out);
00168     kdDebug(30522) << "LATEX FILTER --> END" << endl;
00169     reject();
00170 }
KDE Home | KDE Accessibility Home | Description of Access Keys