File indexing completed on 2024-05-12 16:40:13

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         xi18n("<title>Text encoding for Microsoft Access database</title>\n"
0061              "<para>Database file <filename>%1</filename> appears to be created by a version of Microsoft Access older than 2000.</para>"
0062              "<para>In order to properly import national characters, you may need to choose a proper text encoding "
0063              "if the database was created on a computer with a different character set.</para>",
0064              QDir::toNativeSeparators(databaseFile)),
0065         plainPage);
0066     lbl->setAlignment(Qt::AlignLeft);
0067     lbl->setWordWrap(true);
0068     lbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
0069     lyr->addWidget(lbl, 0, 0, 1, 3);
0070 
0071     QLabel* lbl2 = new QLabel(xi18n("Text encoding:"), plainPage);
0072     lbl2->setBuddy(m_encodingComboBox);
0073     lyr->addWidget(lbl2, 1, 0);
0074 
0075     m_chkAlwaysUseThisEncoding = new QCheckBox(
0076         xi18n("Always use this encoding in similar situations"), plainPage);
0077     lyr->addWidget(m_chkAlwaysUseThisEncoding, 2, 1, 1, 2);
0078 
0079     lyr->addItem(new QSpacerItem(20, 111, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 1);
0080     lyr->addItem(new QSpacerItem(121, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 1, 2);
0081 
0082     //read config
0083     KConfigGroup importExportGroup(KSharedConfig::openConfig()->group("ImportExport"));
0084     QString defaultEncodingForMSAccessFiles
0085         = importExportGroup.readEntry("DefaultEncodingForMSAccessFiles");
0086     if (!defaultEncodingForMSAccessFiles.isEmpty()) {
0087         m_encodingComboBox->setSelectedEncoding(defaultEncodingForMSAccessFiles);
0088         m_chkAlwaysUseThisEncoding->setChecked(true);
0089     }
0090 
0091     // buttons
0092     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
0093     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0094     okButton->setDefault(true);
0095     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0096     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0097     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0098     mainLayout->addWidget(buttonBox);
0099 
0100     adjustSize();
0101     m_encodingComboBox->setFocus();
0102 }
0103 
0104 OptionsDialog::~OptionsDialog()
0105 {
0106 }
0107 
0108 KexiCharacterEncodingComboBox* OptionsDialog::encodingComboBox() const
0109 {
0110     return m_encodingComboBox;
0111 }
0112 
0113 void OptionsDialog::accept()
0114 {
0115     KConfigGroup importExportGroup(KSharedConfig::openConfig()->group("ImportExport"));
0116     if (m_chkAlwaysUseThisEncoding->isChecked())
0117         importExportGroup.writeEntry("defaultEncodingForMSAccessFiles",
0118                                      m_encodingComboBox->selectedEncoding());
0119     else
0120         importExportGroup.deleteEntry("defaultEncodingForMSAccessFiles");
0121 
0122     QDialog::accept();
0123 }
0124