filters

ExportDialog.cc

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2001, 2002, 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 
00023 #include <klocale.h>
00024 #include <kcharsets.h>
00025 #include <kglobal.h>
00026 #include <kdebug.h>
00027 #include <kapplication.h>
00028 #include <kcombobox.h>
00029 #include <kmessagebox.h>
00030 #include <qlabel.h>
00031 #include <qlayout.h>
00032 #include <qradiobutton.h>
00033 #include <qvbuttongroup.h>
00034 #include <qcheckbox.h>
00035 #include <kurlrequester.h>
00036 
00037 #include <ExportDialogUI.h>
00038 #include <ExportDialog.h>
00039 
00040 HtmlExportDialog :: HtmlExportDialog(QWidget* parent)
00041     : KDialogBase(parent, 0, true, i18n("KWord's HTML Export Filter"), Ok|Cancel, No, true),
00042       m_dialog(new ExportDialogUI(this))
00043 {
00044 
00045     kapp->restoreOverrideCursor();
00046 
00047     QStringList encodingList;
00048 
00049     encodingList += i18n( "Descriptive encoding name", "Recommended ( %1 )" ).arg( "UTF-8" );
00050     encodingList += i18n( "Descriptive encoding name", "Locale ( %1 )" ).arg( QTextCodec::codecForLocale()->name() );
00051     encodingList += KGlobal::charsets()->descriptiveEncodingNames();
00052 
00053     m_dialog->comboBoxEncoding->insertStringList( encodingList );
00054 
00055     m_dialog->KURL_ExternalCSS->setMode( KFile::ExistingOnly );
00056 
00057      connect(m_dialog->radioModeEnhanced, SIGNAL( toggled( bool ) ),
00058              SLOT( setCSSEnabled( bool ) ) );
00059      connect(m_dialog->checkExternalCSS, SIGNAL( toggled( bool ) ),
00060              m_dialog->KURL_ExternalCSS, SLOT( setEnabled( bool ) ) );
00061 
00062     setMainWidget(m_dialog);
00063 }
00064 
00065 HtmlExportDialog :: ~HtmlExportDialog(void)
00066 {
00067     kapp->setOverrideCursor(Qt::waitCursor);
00068 }
00069 
00070 void HtmlExportDialog::setCSSEnabled( bool b )
00071 {
00072     m_dialog->checkExternalCSS->setEnabled( b );
00073     m_dialog->KURL_ExternalCSS->setEnabled( b && m_dialog->checkExternalCSS->isChecked() );
00074 }
00075 
00076 bool HtmlExportDialog::isXHtml(void) const
00077 {
00078     if(m_dialog->radioDocType1==m_dialog->buttonGroup1->selected())
00079         return false;
00080     else if(m_dialog->radioDocType2==m_dialog->buttonGroup1->selected())
00081         return true;
00082     return true;
00083 }
00084 
00085 QTextCodec* HtmlExportDialog::getCodec(void) const
00086 {
00087     const QString strCodec( KGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) );
00088     kdDebug(30503) << "Encoding: " << strCodec << endl;
00089 
00090     bool ok = false;
00091     QTextCodec* codec = QTextCodec::codecForName( strCodec.utf8() );
00092 
00093     // If QTextCodec has not found a valid encoding, so try with KCharsets.
00094     if ( codec )
00095     {
00096         ok = true;
00097     }
00098     else
00099     {
00100         codec = KGlobal::charsets()->codecForName( strCodec, ok );
00101     }
00102 
00103     // Still nothing?
00104     if ( !codec || !ok )
00105     {
00106         // Default: UTF-8
00107         kdWarning(30503) << "Cannot find encoding:" << strCodec << endl;
00108         // ### TODO: what parent to use?
00109         KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) );
00110         return 0;
00111     }
00112 
00113     return codec;
00114 }
00115 
00116 HtmlExportDialog::Mode HtmlExportDialog::getMode(void) const
00117 {
00118     if( m_dialog->radioModeEnhanced->isChecked() )
00119     {
00120       if( m_dialog->checkExternalCSS->isChecked() )
00121         {
00122             return CustomCSS;
00123         }
00124         else
00125         {
00126             return DefaultCSS;
00127         }
00128     }
00129     else if ( m_dialog->radioModeBasic->isChecked() )
00130     {
00131         return Basic;
00132     }
00133     else if ( m_dialog->radioModeLight->isChecked() )
00134     {
00135         return Light;
00136     }
00137     return DefaultCSS;//Our default
00138 }
00139 
00140 QString HtmlExportDialog::cssURL(void) const
00141 {
00142   return m_dialog->KURL_ExternalCSS->url();
00143 }
00144 
00145 #include <ExportDialog.moc>
KDE Home | KDE Accessibility Home | Description of Access Keys