kexi

kexicsvimportoptionsdlg.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "kexicsvimportoptionsdlg.h"
00021 #include <widget/kexicharencodingcombobox.h>
00022 
00023 #include <qlabel.h>
00024 #include <qlayout.h>
00025 #include <qtextcodec.h>
00026 #include <qcheckbox.h>
00027 
00028 #include <kapplication.h>
00029 #include <kconfig.h>
00030 #include <kcombobox.h>
00031 #include <klocale.h>
00032 #include <kglobal.h>
00033 #include <kcharsets.h>
00034 
00035 KexiCSVImportOptionsDialog::KexiCSVImportOptionsDialog( const QString& selectedEncoding, QWidget* parent )
00036  : KDialogBase( 
00037     KDialogBase::Plain, 
00038     i18n( "CSV Import Options" ),
00039     Ok|Cancel, 
00040     Ok,
00041     parent, 
00042     "KexiCSVImportOptionsDialog", 
00043     true, 
00044     false
00045  )
00046 {
00047     QGridLayout *lyr = new QGridLayout( plainPage(), 3, 3, 
00048         KDialogBase::marginHint(), KDialogBase::spacingHint());
00049 
00050     m_encodingComboBox = new KexiCharacterEncodingComboBox(plainPage(), selectedEncoding);
00051     lyr->addWidget( m_encodingComboBox, 0, 1 );
00052 
00053     QLabel* lbl = new QLabel( m_encodingComboBox, i18n("Text encoding:"), plainPage());
00054     lyr->addWidget( lbl, 0, 0 );
00055 
00056     lyr->addItem( new QSpacerItem( 20, 111, QSizePolicy::Minimum, QSizePolicy::Expanding ), 2, 1 );
00057     lyr->addItem( new QSpacerItem( 121, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
00058 
00059     m_chkAlwaysUseThisEncoding = new QCheckBox(
00060         i18n("Always use this encoding when importing CSV data files"), plainPage());
00061     lyr->addWidget( m_chkAlwaysUseThisEncoding, 1, 1 );
00062 
00063     //read config
00064     kapp->config()->setGroup("ImportExport");
00065     QString defaultEncodingForImportingCSVFiles 
00066         = kapp->config()->readEntry("DefaultEncodingForImportingCSVFiles");
00067     if (!defaultEncodingForImportingCSVFiles.isEmpty()) {
00068         m_encodingComboBox->setSelectedEncoding(defaultEncodingForImportingCSVFiles);
00069         m_chkAlwaysUseThisEncoding->setChecked(true);
00070     }
00071 
00072     adjustSize();
00073     m_encodingComboBox->setFocus();
00074 }
00075 
00076 KexiCSVImportOptionsDialog::~KexiCSVImportOptionsDialog()
00077 {
00078 }
00079 
00080 KexiCharacterEncodingComboBox* KexiCSVImportOptionsDialog::encodingComboBox() const
00081 {
00082     return m_encodingComboBox;
00083 }
00084 
00085 void KexiCSVImportOptionsDialog::accept()
00086 {
00087     kapp->config()->setGroup("ImportExport");
00088     if (m_chkAlwaysUseThisEncoding->isChecked())
00089         kapp->config()->writeEntry("defaultEncodingForImportingCSVFiles", 
00090             m_encodingComboBox->selectedEncoding());
00091     else
00092         kapp->config()->deleteEntry("defaultEncodingForImportingCSVFiles");
00093 
00094     KDialogBase::accept();
00095 }
00096 
00097 #include "kexicsvimportoptionsdlg.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys