summaryrefslogtreecommitdiffstats
path: root/filters/kword/latex/import/lateximportdia.cpp
blob: f0dd908bd631a812c60f209c28dac9dcb7a0f1e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This file is part of the KDE project
   Copyright (C) 2001 Robert JACOLIN <rjacolin@ifrance.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

/*
   This file is based on the file :
    koffice/filters/kword/html/htmlexportdia.cpp
	Copyright (C) 2001 Nicolas Goutte <goutte@kde.org>

   which was based on the old file:
    /home/kde/koffice/filters/kspread/csv/csvfilterdia.cpp

   The old file was copyrighted by
    Copyright (C) 1999 David Faure <faure@kde.org>

   The old file was licensed under the terms of the GNU Library General Public
   License version 2.
*/

#include <tdeapplication.h>
#include <lateximportdia.h>
#include <lateximportdia.moc>
#include <dcopclient.h>
#include <tdetempfile.h>
#include <tqptrlist.h>

#include "latexparser.h"
#include "config.h"

#include "generator/kwordgenerator.h"

LATEXImportDia::LATEXImportDia(KoStore* out, TQWidget *parent, const char *name) :
						KDialogBase(parent, name, true, i18n("Latex Import Filter Parameters"),
									Ok|Cancel),
						DCOPObject("FilterConfigDia"), _out(out)
{
	_out = out;
	kapp->restoreOverrideCursor();
	createDialog();
	if(!kapp->dcopClient()->isRegistered() )
	{
		kapp->dcopClient()->registerAs("FilterConfigDia");
		kapp->dcopClient()->setDefaultObject(objId());
	}
}

void LATEXImportDia::createDialog()
{
	resize(size());
	TQWidget *page = new TQWidget( this );
	setMainWidget(page);
	TQBoxLayout *mainLayout = new TQVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint());
	styleBox = new TQVButtonGroup(i18n("Document Style"), page);
	mainLayout->addWidget(styleBox);

	/* First part */
	TQBoxLayout *styleLayout = new TQVBoxLayout(page);

	latexStyleRBtn = new TQRadioButton(i18n("Latex style"), styleBox);
	styleLayout->addWidget(latexStyleRBtn);

	kwordStyleRBtn = new TQRadioButton(i18n("KWord style"), styleBox);
	styleLayout->addWidget(kwordStyleRBtn);

	/*typeLabel  = new ...
	styleLayout->addWidget(typeLabel);
	typeCBox = new ...
	styleLayout->addWidget(typeCBox);
	*/
	styleBox->setExclusive(true);
	styleBox->setButton(0);			/* LATEX STYLE IS DEFAULT */
	styleLayout->activate();

	/* Second part */
	langBox = new TQVButtonGroup(i18n("Language"), page);
	mainLayout->addWidget(langBox);

	TQBoxLayout *langLayout = new TQVBoxLayout(langBox);

	unicodeRBtn = new TQRadioButton(i18n("Unicode"), langBox);
	langLayout->addWidget(unicodeRBtn);

	latin1RBtn = new TQRadioButton(i18n("latin1"), langBox);
	langLayout->addWidget(latin1RBtn);

	/*babelCheckBox = new ...
	langLayout->addWidget(babelCheckBox);

	babelCBox = new ...
	langLayout->addWidget(babelCBox);
	*/
	langBox->setExclusive(true);
	langBox->setButton(1);			/* LATIN1 IS THE DEFAULT. */
	langLayout->activate();

	/* Third part */
	docBox = new TQVButtonGroup(i18n("Document Type"), page);
	mainLayout->addWidget(docBox);

	TQBoxLayout *docLayout = new TQVBoxLayout(docBox);

	newDocRBtn = new TQRadioButton(i18n("New document"), docBox);
	docLayout->addWidget(newDocRBtn);

	embededRBtn = new TQRadioButton(i18n("Embedded document"), docBox);
	docLayout->addWidget(embededRBtn);

	docBox->setExclusive(true);
	docBox->setButton(0);			/* NEW DOC IS THE DEFAULT. */
	docLayout->activate();

	/* Display the main layout */
	mainLayout->addStretch(5);
	mainLayout->activate();
}

void LATEXImportDia::state()
{
	Config config;

	if(newDocRBtn == docBox->selected())
		config.setType(TYPE_DOC);
	else if(embededRBtn == docBox->selected())
		config.setType(TYPE_EMBEDED);

	if(unicodeRBtn == langBox->selected())
		config.setEncoding(ENC_UNICODE);
	else if(latin1RBtn == langBox->selected())
		config.setEncoding(ENC_LATIN1);

	/*if(latexStyleRBtn == styleBox->selected())
		config.result += "LATEX";
	else if(kwordStyleRBtn == styleBox->selected())
		result += "KWORD";*/
}

void LATEXImportDia::slotOk()
{
	hide();
	state();
	kdDebug(30522) << "LATEX FILTER --> BEGIN" << endl;
	LatexParser parser(_fileIn);
	TQPtrList<Element>* root = parser.parse();
	kdDebug(30522) << "---------- generate file -------------" << endl;
	kdDebug(30522) << "command: " << root->count() << endl;
	Element* elt;
	for(elt = root->first(); elt; elt = root->next())
	{
		elt->print();
	}
	KwordGenerator generator(root);
	generator.convert(_out);
	kdDebug(30522) << "LATEX FILTER --> END" << endl;
	reject();
}