1
/* This file is part of the KDE project
2
Copyright (C) 2005 Jarosław Staniek <staniek@kde.org>
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this program; see the file COPYING. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "importoptionsdlg.h"
21
#include <widget/kexicharencodingcombobox.h>
26
#include <KSharedConfig>
27
#include <KConfigGroup>
28
#include <KLocalizedString>
30
#include <QDialogButtonBox>
31
#include <QPushButton>
32
#include <QVBoxLayout>
36
#include <QGridLayout>
38
using namespace KexiMigration;
40
OptionsDialog::OptionsDialog(const QString& databaseFile, const QString& selectedEncoding,
45
setObjectName("KexiMigration::OptionsDialog");
46
setWindowTitle(xi18nc("@title:window", "Advanced Import Options"));
47
setWindowIcon(koIcon("configure"));
49
QVBoxLayout *mainLayout = new QVBoxLayout;
50
setLayout(mainLayout);
52
QWidget *plainPage = new QWidget(this);
53
mainLayout->addWidget(plainPage);
54
QGridLayout *lyr = new QGridLayout(plainPage);
56
m_encodingComboBox = new KexiCharacterEncodingComboBox(plainPage, selectedEncoding);
57
m_encodingComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
58
lyr->addWidget(m_encodingComboBox, 1, 1);
59
QLabel* lbl = new QLabel(
60
xi18n("<title>Text encoding for Microsoft Access database</title>\n"
61
"<para>Database file <filename>%1</filename> appears to be created by a version of Microsoft Access older than 2000.</para>"
62
"<para>In order to properly import national characters, you may need to choose a proper text encoding "
63
"if the database was created on a computer with a different character set.</para>",
64
QDir::toNativeSeparators(databaseFile)),
66
lbl->setAlignment(Qt::AlignLeft);
67
lbl->setWordWrap(true);
68
lbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
69
lyr->addWidget(lbl, 0, 0, 1, 3);
71
QLabel* lbl2 = new QLabel(xi18n("Text encoding:"), plainPage);
72
lbl2->setBuddy(m_encodingComboBox);
73
lyr->addWidget(lbl2, 1, 0);
75
m_chkAlwaysUseThisEncoding = new QCheckBox(
76
xi18n("Always use this encoding in similar situations"), plainPage);
77
lyr->addWidget(m_chkAlwaysUseThisEncoding, 2, 1, 1, 2);
79
lyr->addItem(new QSpacerItem(20, 111, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 1);
80
lyr->addItem(new QSpacerItem(121, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 1, 2);
83
KConfigGroup importExportGroup(KSharedConfig::openConfig()->group("ImportExport"));
84
QString defaultEncodingForMSAccessFiles
85
= importExportGroup.readEntry("DefaultEncodingForMSAccessFiles");
86
if (!defaultEncodingForMSAccessFiles.isEmpty()) {
87
m_encodingComboBox->setSelectedEncoding(defaultEncodingForMSAccessFiles);
88
m_chkAlwaysUseThisEncoding->setChecked(true);
92
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
93
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
94
okButton->setDefault(true);
95
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
96
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
97
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
98
mainLayout->addWidget(buttonBox);
101
m_encodingComboBox->setFocus();
104
OptionsDialog::~OptionsDialog()
108
KexiCharacterEncodingComboBox* OptionsDialog::encodingComboBox() const
110
return m_encodingComboBox;
113
void OptionsDialog::accept()
115
KConfigGroup importExportGroup(KSharedConfig::openConfig()->group("ImportExport"));
116
if (m_chkAlwaysUseThisEncoding->isChecked())
117
importExportGroup.writeEntry("defaultEncodingForMSAccessFiles",
118
m_encodingComboBox->selectedEncoding());
120
importExportGroup.deleteEntry("defaultEncodingForMSAccessFiles");