filters

ascii/ExportDialog.cpp
1/*
2 This file is part of the KDE project
3 Copyright 2001, 2003, 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#include <tqradiobutton.h>
23#include <tqbuttongroup.h>
24
25#include <kdebug.h>
26#include <tdelocale.h>
27#include <kcharsets.h>
28#include <tdeglobal.h>
29#include <tdeapplication.h>
30#include <kcombobox.h>
31#include <tdemessagebox.h>
32
33#include <ExportDialogUI.h>
34#include <ExportDialog.h>
35
36AsciiExportDialog :: AsciiExportDialog(TQWidget* parent)
37 : KDialogBase(parent, 0, true, i18n("KWord's Plain Text Export Filter"), Ok|Cancel, No, true),
38 m_dialog(new ExportDialogUI(this))
39{
40
41 kapp->restoreOverrideCursor();
42
43 TQStringList encodings;
44 encodings << i18n( "Descriptive encoding name", "Recommended ( %1 )" ).arg( "UTF-8" );
45 encodings << i18n( "Descriptive encoding name", "Locale ( %1 )" ).arg( TQTextCodec::codecForLocale()->name() );
46 encodings += TDEGlobal::charsets()->descriptiveEncodingNames();
47 // Add a few non-standard encodings, which might be useful for text files
48 const TQString description(i18n("Descriptive encoding name","Other ( %1 )"));
49 encodings << description.arg("Apple Roman"); // Apple
50 encodings << description.arg("IBM 850") << description.arg("IBM 866"); // MS DOS
51 encodings << description.arg("CP 1258"); // Windows
52
53 m_dialog->comboBoxEncoding->insertStringList(encodings);
54
55 setMainWidget(m_dialog);
56
57}
58
59AsciiExportDialog :: ~AsciiExportDialog(void)
60{
61 kapp->setOverrideCursor(TQt::waitCursor);
62}
63
64TQTextCodec* AsciiExportDialog::getCodec(void) const
65{
66 const TQString strCodec( TDEGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) );
67 kdDebug(30502) << "Encoding: " << strCodec << endl;
68
69 bool ok = false;
70 TQTextCodec* codec = TQTextCodec::codecForName( strCodec.utf8() );
71
72 // If TQTextCodec has not found a valid encoding, so try with KCharsets.
73 if ( codec )
74 {
75 ok = true;
76 }
77 else
78 {
79 codec = TDEGlobal::charsets()->codecForName( strCodec, ok );
80 }
81
82 // Still nothing?
83 if ( !codec || !ok )
84 {
85 // Default: UTF-8
86 kdWarning(30502) << "Cannot find encoding:" << strCodec << endl;
87 // ### TODO: what parent to use?
88 KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) );
89 return 0;
90 }
91
92 return codec;
93}
94
95TQString AsciiExportDialog::getEndOfLine(void) const
96{
97 TQString strReturn;
98 if (m_dialog->radioEndOfLineLF==m_dialog->buttonGroupEndOfLine->selected())
99 strReturn="\n";
100 else if (m_dialog->radioEndOfLineCRLF==m_dialog->buttonGroupEndOfLine->selected())
101 strReturn="\r\n";
102 else if (m_dialog->radioEndOfLineCR==m_dialog->buttonGroupEndOfLine->selected())
103 strReturn="\r";
104 else
105 strReturn="\n";
106
107 return strReturn;
108}
109
110#include <ExportDialog.moc>