filters

ExportDialog.cc

00001 /*
00002    This file is part of the KDE project
00003    Copyright 2001, 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 <kdebug.h>
00026 #include <klocale.h>
00027 #include <kcharsets.h>
00028 #include <kglobal.h>
00029 #include <kapplication.h>
00030 #include <kcombobox.h>
00031 #include <kmessagebox.h>
00032 
00033 #include <ExportDialogUI.h>
00034 #include <ExportDialog.h>
00035 
00036 AsciiExportDialog :: AsciiExportDialog(QWidget* parent)
00037     : KDialogBase(parent, 0, true, i18n("KWord's Plain Text Export Filter"), Ok|Cancel, No, true),
00038       m_dialog(new ExportDialogUI(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 
00059 AsciiExportDialog :: ~AsciiExportDialog(void)
00060 {
00061     kapp->setOverrideCursor(Qt::waitCursor);
00062 }
00063 
00064 QTextCodec* AsciiExportDialog::getCodec(void) const
00065 {
00066     const QString strCodec( KGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) );
00067     kdDebug(30502) << "Encoding: " << strCodec << endl;
00068 
00069     bool ok = false;
00070     QTextCodec* codec = QTextCodec::codecForName( strCodec.utf8() );
00071 
00072     // If QTextCodec has not found a valid encoding, so try with KCharsets.
00073     if ( codec )
00074     {
00075         ok = true;
00076     }
00077     else
00078     {
00079         codec = KGlobal::charsets()->codecForName( strCodec, ok );
00080     }
00081 
00082     // Still nothing?
00083     if ( !codec || !ok )
00084     {
00085         // Default: UTF-8
00086         kdWarning(30502) << "Cannot find encoding:" << strCodec << endl;
00087         // ### TODO: what parent to use?
00088         KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) );
00089         return 0;
00090     }
00091 
00092     return codec;
00093 }
00094 
00095 QString AsciiExportDialog::getEndOfLine(void) const
00096 {
00097     QString strReturn;
00098     if (m_dialog->radioEndOfLineLF==m_dialog->buttonGroupEndOfLine->selected())
00099         strReturn="\n";
00100     else if (m_dialog->radioEndOfLineCRLF==m_dialog->buttonGroupEndOfLine->selected())
00101         strReturn="\r\n";
00102     else if (m_dialog->radioEndOfLineCR==m_dialog->buttonGroupEndOfLine->selected())
00103         strReturn="\r";
00104     else
00105         strReturn="\n";
00106 
00107     return strReturn;
00108 }
00109 
00110 #include <ExportDialog.moc>
KDE Home | KDE Accessibility Home | Description of Access Keys