importoptionsdlg.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
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 <tqdir.h>
24#include <tqlabel.h>
25#include <tqlayout.h>
26#include <tqtextcodec.h>
27#include <tqcheckbox.h>
28
29#include <tdeapplication.h>
30#include <tdeconfig.h>
31#include <kcombobox.h>
32#include <tdelocale.h>
33#include <tdeglobal.h>
34#include <kcharsets.h>
35#include <kiconloader.h>
36
37using namespace KexiMigration;
38
39OptionsDialog::OptionsDialog( const TQString& databaseFile, const TQString& selectedEncoding, TQWidget* parent )
40 : KDialogBase(
41 KDialogBase::Plain,
42 i18n( "Advanced Import Options" ),
43 Ok|Cancel,
44 Ok,
45 parent,
46 "KexiMigration::OptionsDialog",
47 true,
48 false
49 )
50{
51 setIcon(DesktopIcon("configure"));
52 TQGridLayout *lyr = new TQGridLayout( plainPage(), 4, 3, KDialogBase::marginHint(),
53 KDialogBase::spacingHint());
54
55 m_encodingComboBox = new KexiCharacterEncodingComboBox(plainPage(), selectedEncoding);
56 m_encodingComboBox->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Minimum);
57 lyr->addWidget( m_encodingComboBox, 1, 1 );
58 TQLabel* lbl = new TQLabel(
59 i18n("<h3>Text encoding for Microsoft Access database</h3>\n"
60 "<p>Database file \"%1\" appears to be created by a version of Microsoft Access older than 2000.</p>"
61 "<p>In order to properly import national characters, you may need to choose a proper text encoding "
62 "if the database was created on a computer with a different character set.</p>")
63 .arg(TQDir::convertSeparators(databaseFile)), plainPage());
64 lbl->setAlignment( TQt::AlignAuto | TQt::WordBreak );
65 lbl->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Fixed);
66 lyr->addMultiCellWidget( lbl, 0, 0, 0, 2 );
67
68 TQLabel* lbl2 = new TQLabel( m_encodingComboBox, i18n("Text encoding:"), plainPage());
69 lyr->addWidget( lbl2, 1, 0 );
70
71 m_chkAlwaysUseThisEncoding = new TQCheckBox(
72 i18n("Always use this encoding in similar situations"), plainPage());
73 lyr->addMultiCellWidget( m_chkAlwaysUseThisEncoding, 2, 2, 1,2 );
74
75 lyr->addItem( new TQSpacerItem( 20, 111, TQSizePolicy::Minimum, TQSizePolicy::Expanding ), 3, 1 );
76 lyr->addItem( new TQSpacerItem( 121, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum ), 1, 2 );
77
78 //read config
79 kapp->config()->setGroup("ImportExport");
80 TQString defaultEncodingForMSAccessFiles = kapp->config()->readEntry("DefaultEncodingForMSAccessFiles");
81 if (!defaultEncodingForMSAccessFiles.isEmpty()) {
82 m_encodingComboBox->setSelectedEncoding(defaultEncodingForMSAccessFiles);
83 m_chkAlwaysUseThisEncoding->setChecked(true);
84 }
85
86 adjustSize();
87 m_encodingComboBox->setFocus();
88}
89
90OptionsDialog::~OptionsDialog()
91{
92}
93
94KexiCharacterEncodingComboBox* OptionsDialog::encodingComboBox() const
95{
96 return m_encodingComboBox;
97}
98
99void OptionsDialog::accept()
100{
101 kapp->config()->setGroup("ImportExport");
102 if (m_chkAlwaysUseThisEncoding->isChecked())
103 kapp->config()->writeEntry("defaultEncodingForMSAccessFiles",
104 m_encodingComboBox->selectedEncoding());
105 else
106 kapp->config()->deleteEntry("defaultEncodingForMSAccessFiles");
107
108 KDialogBase::accept();
109}
110
111#include "importoptionsdlg.moc"
Combobox widget providing a list of possible character encodings.
Framework for importing databases into native KexiDB databases.