filters

ImportDialog.cc

00001 /*
00002    This file is part of the KDE project
00003    Copyright 2001, 2002, 2003, 2004 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qtextcodec.h>
00022 #include <qradiobutton.h>
00023 #include <qbuttongroup.h>
00024 
00025 #include <klocale.h>
00026 #include <kcharsets.h>
00027 #include <kglobal.h>
00028 #include <kdebug.h>
00029 #include <kapplication.h>
00030 #include <kcombobox.h>
00031 #include <kmessagebox.h>
00032 
00033 #include <ImportDialogUI.h>
00034 #include <ImportDialog.h>
00035 
00036 AsciiImportDialog :: AsciiImportDialog(QWidget* parent)
00037     : KDialogBase(parent, 0, true,  i18n("KWord's Plain Text Import Filter"), Ok|Cancel, No, true),
00038       m_dialog(new ImportDialogUI(this))
00039 {
00040 
00041     kapp->restoreOverrideCursor();
00042 
00043     QStringList encodings;
00044     encodings << i18n( "Descriptive encoding name", "Recommended ( %1 )" ).arg( "UTF-8" );
00045     encodings << i18n( "Descriptive encoding name", "Locale ( %1 )" ).arg( QTextCodec::codecForLocale()->name() );
00046     encodings += KGlobal::charsets()->descriptiveEncodingNames();
00047     // Add a few non-standard encodings, which might be useful for text files
00048     const QString description(i18n("Descriptive encoding name","Other ( %1 )"));
00049     encodings << description.arg("Apple Roman"); // Apple 
00050     encodings << description.arg("IBM 850") << description.arg("IBM 866"); // MS DOS
00051     encodings << description.arg("CP 1258"); // Windows
00052 
00053     m_dialog->comboBoxEncoding->insertStringList(encodings);
00054 
00055     setMainWidget(m_dialog);
00056 }
00057 
00058 AsciiImportDialog :: ~AsciiImportDialog(void)
00059 {
00060     kapp->setOverrideCursor(Qt::waitCursor);
00061 }
00062 
00063 QTextCodec* AsciiImportDialog::getCodec(void) const
00064 {
00065     const QString strCodec( KGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) );
00066     kdDebug(30502) << "Encoding: " << strCodec << endl;
00067 
00068     bool ok = false;
00069     QTextCodec* codec = QTextCodec::codecForName( strCodec.utf8() );
00070 
00071     // If QTextCodec has not found a valid encoding, so try with KCharsets.
00072     if ( codec )
00073     {
00074         ok = true;
00075     }
00076     else
00077     {
00078         codec = KGlobal::charsets()->codecForName( strCodec, ok );
00079     }
00080 
00081     // Still nothing?
00082     if ( !codec || !ok )
00083     {
00084         // Default: UTF-8
00085         kdWarning(30502) << "Cannot find encoding:" << strCodec << endl;
00086         // ### TODO: what parent to use?
00087         KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) );
00088         return 0;
00089     }
00090 
00091     return codec;
00092 }
00093 
00094 int AsciiImportDialog::getParagraphStrategy(void) const
00095 {
00096     if (m_dialog->radioParagraphAsIs==m_dialog->buttonGroupParagraph->selected())
00097     {
00098         return 0;
00099     }
00100     if (m_dialog->radioParagraphSentence==m_dialog->buttonGroupParagraph->selected())
00101     {
00102         return 1;
00103     }
00104     else if (m_dialog->radioParagraphOldWay==m_dialog->buttonGroupParagraph->selected())
00105     {
00106         return 999;
00107     }
00108     return 0;
00109 }
00110 
00111 #include <ImportDialog.moc>
KDE Home | KDE Accessibility Home | Description of Access Keys