~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/migration/importoptionsdlg.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
Import upstream version 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2005 Jarosław Staniek <staniek@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
 */
 
19
 
 
20
#include "importoptionsdlg.h"
 
21
#include <widget/kexicharencodingcombobox.h>
 
22
 
 
23
#include <KexiIcon.h>
 
24
 
 
25
#include <KConfig>
 
26
#include <KSharedConfig>
 
27
#include <KConfigGroup>
 
28
#include <KLocalizedString>
 
29
 
 
30
#include <QDialogButtonBox>
 
31
#include <QPushButton>
 
32
#include <QVBoxLayout>
 
33
#include <QDir>
 
34
#include <QLabel>
 
35
#include <QCheckBox>
 
36
#include <QGridLayout>
 
37
 
 
38
using namespace KexiMigration;
 
39
 
 
40
OptionsDialog::OptionsDialog(const QString& databaseFile, const QString& selectedEncoding,
 
41
                             QWidget* parent)
 
42
        : QDialog(parent)
 
43
{
 
44
    setModal(true);
 
45
    setObjectName("KexiMigration::OptionsDialog");
 
46
    setWindowTitle(xi18nc("@title:window", "Advanced Import Options"));
 
47
    setWindowIcon(koIcon("configure"));
 
48
 
 
49
    QVBoxLayout *mainLayout = new QVBoxLayout;
 
50
    setLayout(mainLayout);
 
51
 
 
52
    QWidget *plainPage = new QWidget(this);
 
53
    mainLayout->addWidget(plainPage);
 
54
    QGridLayout *lyr = new QGridLayout(plainPage);
 
55
 
 
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)),
 
65
        plainPage);
 
66
    lbl->setAlignment(Qt::AlignLeft);
 
67
    lbl->setWordWrap(true);
 
68
    lbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
 
69
    lyr->addWidget(lbl, 0, 0, 1, 3);
 
70
 
 
71
    QLabel* lbl2 = new QLabel(xi18n("Text encoding:"), plainPage);
 
72
    lbl2->setBuddy(m_encodingComboBox);
 
73
    lyr->addWidget(lbl2, 1, 0);
 
74
 
 
75
    m_chkAlwaysUseThisEncoding = new QCheckBox(
 
76
        xi18n("Always use this encoding in similar situations"), plainPage);
 
77
    lyr->addWidget(m_chkAlwaysUseThisEncoding, 2, 1, 1, 2);
 
78
 
 
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);
 
81
 
 
82
    //read config
 
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);
 
89
    }
 
90
 
 
91
    // buttons
 
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);
 
99
 
 
100
    adjustSize();
 
101
    m_encodingComboBox->setFocus();
 
102
}
 
103
 
 
104
OptionsDialog::~OptionsDialog()
 
105
{
 
106
}
 
107
 
 
108
KexiCharacterEncodingComboBox* OptionsDialog::encodingComboBox() const
 
109
{
 
110
    return m_encodingComboBox;
 
111
}
 
112
 
 
113
void OptionsDialog::accept()
 
114
{
 
115
    KConfigGroup importExportGroup(KSharedConfig::openConfig()->group("ImportExport"));
 
116
    if (m_chkAlwaysUseThisEncoding->isChecked())
 
117
        importExportGroup.writeEntry("defaultEncodingForMSAccessFiles",
 
118
                                     m_encodingComboBox->selectedEncoding());
 
119
    else
 
120
        importExportGroup.deleteEntry("defaultEncodingForMSAccessFiles");
 
121
 
 
122
    QDialog::accept();
 
123
}
 
124