filters

lateximportdia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Robert JACOLIN <rjacolin@ifrance.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20/*
21 This file is based on the file :
22 koffice/filters/kword/html/htmlexportdia.cpp
23 Copyright (C) 2001 Nicolas Goutte <goutte@kde.org>
24
25 which was based on the old file:
26 /home/kde/koffice/filters/kspread/csv/csvfilterdia.cpp
27
28 The old file was copyrighted by
29 Copyright (C) 1999 David Faure <faure@kde.org>
30
31 The old file was licensed under the terms of the GNU Library General Public
32 License version 2.
33*/
34
35#include <tdeapplication.h>
36#include <lateximportdia.h>
37#include <lateximportdia.moc>
38#include <dcopclient.h>
39#include <tdetempfile.h>
40#include <tqptrlist.h>
41
42#include "latexparser.h"
43#include "config.h"
44
45#include "generator/kwordgenerator.h"
46
47LATEXImportDia::LATEXImportDia(KoStore* out, TQWidget *parent, const char *name) :
48 KDialogBase(parent, name, true, i18n("Latex Import Filter Parameters"),
49 Ok|Cancel),
50 DCOPObject("FilterConfigDia"), _out(out)
51{
52 _out = out;
53 kapp->restoreOverrideCursor();
54 createDialog();
55 if(!kapp->dcopClient()->isRegistered() )
56 {
57 kapp->dcopClient()->registerAs("FilterConfigDia");
58 kapp->dcopClient()->setDefaultObject(objId());
59 }
60}
61
62void LATEXImportDia::createDialog()
63{
64 resize(size());
65 TQWidget *page = new TQWidget( this );
66 setMainWidget(page);
67 TQBoxLayout *mainLayout = new TQVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint());
68 styleBox = new TQVButtonGroup(i18n("Document Style"), page);
69 mainLayout->addWidget(styleBox);
70
71 /* First part */
72 TQBoxLayout *styleLayout = new TQVBoxLayout(page);
73
74 latexStyleRBtn = new TQRadioButton(i18n("Latex style"), styleBox);
75 styleLayout->addWidget(latexStyleRBtn);
76
77 kwordStyleRBtn = new TQRadioButton(i18n("KWord style"), styleBox);
78 styleLayout->addWidget(kwordStyleRBtn);
79
80 /*typeLabel = new ...
81 styleLayout->addWidget(typeLabel);
82 typeCBox = new ...
83 styleLayout->addWidget(typeCBox);
84 */
85 styleBox->setExclusive(true);
86 styleBox->setButton(0); /* LATEX STYLE IS DEFAULT */
87 styleLayout->activate();
88
89 /* Second part */
90 langBox = new TQVButtonGroup(i18n("Language"), page);
91 mainLayout->addWidget(langBox);
92
93 TQBoxLayout *langLayout = new TQVBoxLayout(langBox);
94
95 unicodeRBtn = new TQRadioButton(i18n("Unicode"), langBox);
96 langLayout->addWidget(unicodeRBtn);
97
98 latin1RBtn = new TQRadioButton(i18n("latin1"), langBox);
99 langLayout->addWidget(latin1RBtn);
100
101 /*babelCheckBox = new ...
102 langLayout->addWidget(babelCheckBox);
103
104 babelCBox = new ...
105 langLayout->addWidget(babelCBox);
106 */
107 langBox->setExclusive(true);
108 langBox->setButton(1); /* LATIN1 IS THE DEFAULT. */
109 langLayout->activate();
110
111 /* Third part */
112 docBox = new TQVButtonGroup(i18n("Document Type"), page);
113 mainLayout->addWidget(docBox);
114
115 TQBoxLayout *docLayout = new TQVBoxLayout(docBox);
116
117 newDocRBtn = new TQRadioButton(i18n("New document"), docBox);
118 docLayout->addWidget(newDocRBtn);
119
120 embededRBtn = new TQRadioButton(i18n("Embedded document"), docBox);
121 docLayout->addWidget(embededRBtn);
122
123 docBox->setExclusive(true);
124 docBox->setButton(0); /* NEW DOC IS THE DEFAULT. */
125 docLayout->activate();
126
127 /* Display the main layout */
128 mainLayout->addStretch(5);
129 mainLayout->activate();
130}
131
132void LATEXImportDia::state()
133{
134 Config config;
135
136 if(newDocRBtn == docBox->selected())
137 config.setType(TYPE_DOC);
138 else if(embededRBtn == docBox->selected())
139 config.setType(TYPE_EMBEDED);
140
141 if(unicodeRBtn == langBox->selected())
142 config.setEncoding(ENC_UNICODE);
143 else if(latin1RBtn == langBox->selected())
144 config.setEncoding(ENC_LATIN1);
145
146 /*if(latexStyleRBtn == styleBox->selected())
147 config.result += "LATEX";
148 else if(kwordStyleRBtn == styleBox->selected())
149 result += "KWORD";*/
150}
151
152void LATEXImportDia::slotOk()
153{
154 hide();
155 state();
156 kdDebug(30522) << "LATEX FILTER --> BEGIN" << endl;
157 LatexParser parser(_fileIn);
158 TQPtrList<Element>* root = parser.parse();
159 kdDebug(30522) << "---------- generate file -------------" << endl;
160 kdDebug(30522) << "command: " << root->count() << endl;
161 Element* elt;
162 for(elt = root->first(); elt; elt = root->next())
163 {
164 elt->print();
165 }
166 KwordGenerator generator(root);
167 generator.convert(_out);
168 kdDebug(30522) << "LATEX FILTER --> END" << endl;
169 reject();
170}