kexi

importoptionsdlg.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 "importoptionsdlg.h"
00021 #include <widget/kexicharencodingcombobox.h>
00022 
00023 #include <qdir.h>
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qtextcodec.h>
00027 #include <qcheckbox.h>
00028 
00029 #include <kapplication.h>
00030 #include <kconfig.h>
00031 #include <kcombobox.h>
00032 #include <klocale.h>
00033 #include <kglobal.h>
00034 #include <kcharsets.h>
00035 #include <kiconloader.h>
00036 
00037 using namespace KexiMigration;
00038 
00039 OptionsDialog::OptionsDialog( const QString& databaseFile, const QString& selectedEncoding, QWidget* parent )
00040  : KDialogBase( 
00041     KDialogBase::Plain, 
00042     i18n( "Advanced Import Options" ),
00043     Ok|Cancel, 
00044     Ok,
00045     parent, 
00046     "KexiMigration::OptionsDialog", 
00047     true, 
00048     false
00049  )
00050 {
00051     setIcon(DesktopIcon("configure"));
00052     QGridLayout *lyr = new QGridLayout( plainPage(), 4, 3, KDialogBase::marginHint(), 
00053         KDialogBase::spacingHint());
00054 
00055     m_encodingComboBox = new KexiCharacterEncodingComboBox(plainPage(), selectedEncoding);
00056     m_encodingComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
00057     lyr->addWidget( m_encodingComboBox, 1, 1 );
00058     QLabel* lbl = new QLabel( 
00059         i18n("<h3>Text encoding for Microsoft Access database</h3>\n"
00060         "<p>Database file \"%1\" appears to be created by a version of Microsoft Access older than 2000.</p>"
00061         "<p>In order to properly import national characters, you may need to choose a proper text encoding "
00062         "if the database was created on a computer with a different character set.</p>")
00063         .arg(QDir::convertSeparators(databaseFile)), plainPage());
00064     lbl->setAlignment( Qt::AlignAuto | Qt::WordBreak );
00065     lbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
00066     lyr->addMultiCellWidget( lbl, 0, 0, 0, 2 );
00067 
00068     QLabel* lbl2 = new QLabel( m_encodingComboBox, i18n("Text encoding:"), plainPage());
00069     lyr->addWidget( lbl2, 1, 0 );
00070 
00071     m_chkAlwaysUseThisEncoding = new QCheckBox(
00072         i18n("Always use this encoding in similar situations"), plainPage());
00073     lyr->addMultiCellWidget( m_chkAlwaysUseThisEncoding, 2, 2, 1,2 );
00074 
00075     lyr->addItem( new QSpacerItem( 20, 111, QSizePolicy::Minimum, QSizePolicy::Expanding ), 3, 1 );
00076     lyr->addItem( new QSpacerItem( 121, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 2 );
00077 
00078     //read config
00079     kapp->config()->setGroup("ImportExport");
00080     QString defaultEncodingForMSAccessFiles = kapp->config()->readEntry("DefaultEncodingForMSAccessFiles");
00081     if (!defaultEncodingForMSAccessFiles.isEmpty()) {
00082         m_encodingComboBox->setSelectedEncoding(defaultEncodingForMSAccessFiles);
00083         m_chkAlwaysUseThisEncoding->setChecked(true);
00084     }
00085 
00086     adjustSize();
00087     m_encodingComboBox->setFocus();
00088 }
00089 
00090 OptionsDialog::~OptionsDialog()
00091 {
00092 }
00093 
00094 KexiCharacterEncodingComboBox* OptionsDialog::encodingComboBox() const
00095 {
00096     return m_encodingComboBox;
00097 }
00098 
00099 void OptionsDialog::accept()
00100 {
00101     kapp->config()->setGroup("ImportExport");
00102     if (m_chkAlwaysUseThisEncoding->isChecked())
00103         kapp->config()->writeEntry("defaultEncodingForMSAccessFiles", 
00104             m_encodingComboBox->selectedEncoding());
00105     else
00106         kapp->config()->deleteEntry("defaultEncodingForMSAccessFiles");
00107 
00108     KDialogBase::accept();
00109 }
00110 
00111 #include "importoptionsdlg.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys