filters

html/export/ExportDialog.cpp
1/*
2 This file is part of the KDE project
3 Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE <goutte@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqtextcodec.h>
22
23#include <tdelocale.h>
24#include <kcharsets.h>
25#include <tdeglobal.h>
26#include <kdebug.h>
27#include <tdeapplication.h>
28#include <kcombobox.h>
29#include <tdemessagebox.h>
30#include <tqlabel.h>
31#include <tqlayout.h>
32#include <tqradiobutton.h>
33#include <tqvbuttongroup.h>
34#include <tqcheckbox.h>
35#include <kurlrequester.h>
36
37#include <ExportDialogUI.h>
38#include <ExportDialog.h>
39
40HtmlExportDialog :: HtmlExportDialog(TQWidget* parent)
41 : KDialogBase(parent, 0, true, i18n("KWord's HTML Export Filter"), Ok|Cancel, No, true),
42 m_dialog(new ExportDialogUI(this))
43{
44
45 kapp->restoreOverrideCursor();
46
47 TQStringList encodingList;
48
49 encodingList += i18n( "Descriptive encoding name", "Recommended ( %1 )" ).arg( "UTF-8" );
50 encodingList += i18n( "Descriptive encoding name", "Locale ( %1 )" ).arg( TQTextCodec::codecForLocale()->name() );
51 encodingList += TDEGlobal::charsets()->descriptiveEncodingNames();
52
53 m_dialog->comboBoxEncoding->insertStringList( encodingList );
54
55 m_dialog->KURL_ExternalCSS->setMode( KFile::ExistingOnly );
56
57 connect(m_dialog->radioModeEnhanced, TQ_SIGNAL( toggled( bool ) ),
58 TQ_SLOT( setCSSEnabled( bool ) ) );
59 connect(m_dialog->checkExternalCSS, TQ_SIGNAL( toggled( bool ) ),
60 m_dialog->KURL_ExternalCSS, TQ_SLOT( setEnabled( bool ) ) );
61
62 setMainWidget(m_dialog);
63}
64
65HtmlExportDialog :: ~HtmlExportDialog(void)
66{
67 kapp->setOverrideCursor(TQt::waitCursor);
68}
69
70void HtmlExportDialog::setCSSEnabled( bool b )
71{
72 m_dialog->checkExternalCSS->setEnabled( b );
73 m_dialog->KURL_ExternalCSS->setEnabled( b && m_dialog->checkExternalCSS->isChecked() );
74}
75
76bool HtmlExportDialog::isXHtml(void) const
77{
78 if(m_dialog->radioDocType1==m_dialog->buttonGroup1->selected())
79 return false;
80 else if(m_dialog->radioDocType2==m_dialog->buttonGroup1->selected())
81 return true;
82 return true;
83}
84
85TQTextCodec* HtmlExportDialog::getCodec(void) const
86{
87 const TQString strCodec( TDEGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) );
88 kdDebug(30503) << "Encoding: " << strCodec << endl;
89
90 bool ok = false;
91 TQTextCodec* codec = TQTextCodec::codecForName( strCodec.utf8() );
92
93 // If TQTextCodec has not found a valid encoding, so try with KCharsets.
94 if ( codec )
95 {
96 ok = true;
97 }
98 else
99 {
100 codec = TDEGlobal::charsets()->codecForName( strCodec, ok );
101 }
102
103 // Still nothing?
104 if ( !codec || !ok )
105 {
106 // Default: UTF-8
107 kdWarning(30503) << "Cannot find encoding:" << strCodec << endl;
108 // ### TODO: what parent to use?
109 KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) );
110 return 0;
111 }
112
113 return codec;
114}
115
116HtmlExportDialog::Mode HtmlExportDialog::getMode(void) const
117{
118 if( m_dialog->radioModeEnhanced->isChecked() )
119 {
120 if( m_dialog->checkExternalCSS->isChecked() )
121 {
122 return CustomCSS;
123 }
124 else
125 {
126 return DefaultCSS;
127 }
128 }
129 else if ( m_dialog->radioModeBasic->isChecked() )
130 {
131 return Basic;
132 }
133 else if ( m_dialog->radioModeLight->isChecked() )
134 {
135 return Light;
136 }
137 return DefaultCSS;//Our default
138}
139
140TQString HtmlExportDialog::cssURL(void) const
141{
142 return m_dialog->KURL_ExternalCSS->url();
143}
144
145#include <ExportDialog.moc>