filters

ascii/ImportDialog.cpp
1/*
2 This file is part of the KDE project
3 Copyright 2001, 2002, 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 <tdelocale.h>
26#include <kcharsets.h>
27#include <tdeglobal.h>
28#include <kdebug.h>
29#include <tdeapplication.h>
30#include <kcombobox.h>
31#include <tdemessagebox.h>
32
33#include <ImportDialogUI.h>
34#include <ImportDialog.h>
35
36AsciiImportDialog :: AsciiImportDialog(TQWidget* parent)
37 : KDialogBase(parent, 0, true, i18n("KWord's Plain Text Import Filter"), Ok|Cancel, No, true),
38 m_dialog(new ImportDialogUI(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
58AsciiImportDialog :: ~AsciiImportDialog(void)
59{
60 kapp->setOverrideCursor(TQt::waitCursor);
61}
62
63TQTextCodec* AsciiImportDialog::getCodec(void) const
64{
65 const TQString strCodec( TDEGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) );
66 kdDebug(30502) << "Encoding: " << strCodec << endl;
67
68 bool ok = false;
69 TQTextCodec* codec = TQTextCodec::codecForName( strCodec.utf8() );
70
71 // If TQTextCodec has not found a valid encoding, so try with KCharsets.
72 if ( codec )
73 {
74 ok = true;
75 }
76 else
77 {
78 codec = TDEGlobal::charsets()->codecForName( strCodec, ok );
79 }
80
81 // Still nothing?
82 if ( !codec || !ok )
83 {
84 // Default: UTF-8
85 kdWarning(30502) << "Cannot find encoding:" << strCodec << endl;
86 // ### TODO: what parent to use?
87 KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) );
88 return 0;
89 }
90
91 return codec;
92}
93
94int AsciiImportDialog::getParagraphStrategy(void) const
95{
96 if (m_dialog->radioParagraphAsIs==m_dialog->buttonGroupParagraph->selected())
97 {
98 return 0;
99 }
100 if (m_dialog->radioParagraphSentence==m_dialog->buttonGroupParagraph->selected())
101 {
102 return 1;
103 }
104 else if (m_dialog->radioParagraphOldWay==m_dialog->buttonGroupParagraph->selected())
105 {
106 return 999;
107 }
108 return 0;
109}
110
111#include <ImportDialog.moc>