File indexing completed on 2024-05-19 12:55:00
0001 /* This file is part of the KDE project 0002 Copyright (C) 2005 Jarosław Staniek <staniek@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this program; see the file COPYING. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "importoptionsdlg.h" 0021 #include <widget/kexicharencodingcombobox.h> 0022 0023 #include <KexiIcon.h> 0024 0025 #include <KConfig> 0026 #include <KSharedConfig> 0027 #include <KConfigGroup> 0028 #include <KLocalizedString> 0029 0030 #include <QDialogButtonBox> 0031 #include <QPushButton> 0032 #include <QVBoxLayout> 0033 #include <QDir> 0034 #include <QLabel> 0035 #include <QCheckBox> 0036 #include <QGridLayout> 0037 0038 using namespace KexiMigration; 0039 0040 OptionsDialog::OptionsDialog(const QString& databaseFile, const QString& selectedEncoding, 0041 QWidget* parent) 0042 : QDialog(parent) 0043 { 0044 setModal(true); 0045 setObjectName("KexiMigration::OptionsDialog"); 0046 setWindowTitle(xi18nc("@title:window", "Advanced Import Options")); 0047 setWindowIcon(koIcon("configure")); 0048 0049 QVBoxLayout *mainLayout = new QVBoxLayout; 0050 setLayout(mainLayout); 0051 0052 QWidget *plainPage = new QWidget(this); 0053 mainLayout->addWidget(plainPage); 0054 QGridLayout *lyr = new QGridLayout(plainPage); 0055 0056 m_encodingComboBox = new KexiCharacterEncodingComboBox(plainPage, selectedEncoding); 0057 m_encodingComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); 0058 lyr->addWidget(m_encodingComboBox, 1, 1); 0059 QLabel *lbl = new QLabel( 0060 xi18nc("@info", 0061 "<title>Text encoding for Microsoft Access database</title>\n" 0062 "<para>Database file <filename>%1</filename> appears to be created by a version of " 0063 "Microsoft Access older than 2000.</para>" 0064 "<para>In order to properly import national characters, you may need to choose a " 0065 "proper text encoding " 0066 "if the database was created on a computer with a different character set.</para>", 0067 QDir::toNativeSeparators(databaseFile)), 0068 plainPage); 0069 lbl->setAlignment(Qt::AlignLeft); 0070 lbl->setWordWrap(true); 0071 lbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); 0072 lyr->addWidget(lbl, 0, 0, 1, 3); 0073 0074 QLabel* lbl2 = new QLabel(xi18n("Text encoding:"), plainPage); 0075 lbl2->setBuddy(m_encodingComboBox); 0076 lyr->addWidget(lbl2, 1, 0); 0077 0078 m_chkAlwaysUseThisEncoding = new QCheckBox( 0079 xi18n("Always use this encoding in similar situations"), plainPage); 0080 lyr->addWidget(m_chkAlwaysUseThisEncoding, 2, 1, 1, 2); 0081 0082 lyr->addItem(new QSpacerItem(20, 111, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 1); 0083 lyr->addItem(new QSpacerItem(121, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 1, 2); 0084 0085 //read config 0086 KConfigGroup importExportGroup(KSharedConfig::openConfig()->group("ImportExport")); 0087 QString defaultEncodingForMSAccessFiles 0088 = importExportGroup.readEntry("DefaultEncodingForMSAccessFiles"); 0089 if (!defaultEncodingForMSAccessFiles.isEmpty()) { 0090 m_encodingComboBox->setSelectedEncoding(defaultEncodingForMSAccessFiles); 0091 m_chkAlwaysUseThisEncoding->setChecked(true); 0092 } 0093 0094 // buttons 0095 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 0096 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0097 okButton->setDefault(true); 0098 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0099 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); 0100 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 0101 mainLayout->addWidget(buttonBox); 0102 0103 adjustSize(); 0104 m_encodingComboBox->setFocus(); 0105 } 0106 0107 OptionsDialog::~OptionsDialog() 0108 { 0109 } 0110 0111 KexiCharacterEncodingComboBox* OptionsDialog::encodingComboBox() const 0112 { 0113 return m_encodingComboBox; 0114 } 0115 0116 void OptionsDialog::accept() 0117 { 0118 KConfigGroup importExportGroup(KSharedConfig::openConfig()->group("ImportExport")); 0119 if (m_chkAlwaysUseThisEncoding->isChecked()) 0120 importExportGroup.writeEntry("defaultEncodingForMSAccessFiles", 0121 m_encodingComboBox->selectedEncoding()); 0122 else 0123 importExportGroup.deleteEntry("defaultEncodingForMSAccessFiles"); 0124 0125 QDialog::accept(); 0126 } 0127