kexicsvimportoptionsdlg.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 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 "kexicsvimportoptionsdlg.h"
21#include <widget/kexicharencodingcombobox.h>
22
23#include <tqlabel.h>
24#include <tqlayout.h>
25#include <tqtextcodec.h>
26#include <tqcheckbox.h>
27
28#include <tdeapplication.h>
29#include <tdeconfig.h>
30#include <kcombobox.h>
31#include <tdelocale.h>
32#include <tdeglobal.h>
33#include <kcharsets.h>
34
35KexiCSVImportOptions::KexiCSVImportOptions()
36{
37 kapp->config()->setGroup("ImportExport");
38 encoding = kapp->config()->readEntry("DefaultEncodingForImportingCSVFiles");
39 if (encoding.isEmpty()) {
40 encoding = TQString::fromLatin1(TDEGlobal::locale()->encoding());
41 defaultEncodingExplicitySet = false;
42 }
43 else
44 defaultEncodingExplicitySet = true;
45
46 stripWhiteSpaceInTextValuesChecked
47 = kapp->config()->readBoolEntry("StripBlanksOffOfTextValuesWhenImportingCSVFiles", true);
48}
49
50KexiCSVImportOptions::~KexiCSVImportOptions()
51{
52}
53
54bool KexiCSVImportOptions::operator== ( const KexiCSVImportOptions & opt ) const
55{
56 return defaultEncodingExplicitySet==opt.defaultEncodingExplicitySet
57 && stripWhiteSpaceInTextValuesChecked==opt.stripWhiteSpaceInTextValuesChecked
58 && encoding==opt.encoding;
59}
60
61bool KexiCSVImportOptions::operator!= ( const KexiCSVImportOptions & opt ) const
62{
63 return !( *this==opt );
64}
65
66//----------------------------------
67
68KexiCSVImportOptionsDialog::KexiCSVImportOptionsDialog(
69 const KexiCSVImportOptions& options, TQWidget* parent )
70 : KDialogBase(
71 KDialogBase::Plain,
72 i18n( "CSV Import Options" ),
73 Ok|Cancel,
74 Ok,
75 parent,
76 "KexiCSVImportOptionsDialog",
77 true,
78 false
79 )
80{
81 TQGridLayout *lyr = new TQGridLayout( plainPage(), 5, 3,
82 KDialogBase::marginHint(), KDialogBase::spacingHint());
83
84 m_encodingComboBox = new KexiCharacterEncodingComboBox(plainPage(), options.encoding);
85 lyr->addWidget( m_encodingComboBox, 0, 1 );
86
87 TQLabel* lbl = new TQLabel( m_encodingComboBox, i18n("Text encoding:"), plainPage());
88 lyr->addWidget( lbl, 0, 0 );
89
90 lyr->addItem( new TQSpacerItem( 20, KDialogBase::spacingHint(), TQSizePolicy::Fixed, TQSizePolicy::Fixed ), 2, 1 );
91 lyr->addItem( new TQSpacerItem( 121, KDialogBase::spacingHint(), TQSizePolicy::Expanding, TQSizePolicy::Minimum ), 0, 2 );
92
93 m_chkAlwaysUseThisEncoding = new TQCheckBox(
94 i18n("Always use this encoding when importing CSV data files"), plainPage());
95 lyr->addWidget( m_chkAlwaysUseThisEncoding, 1, 1 );
96
97 m_chkStripWhiteSpaceInTextValues = new TQCheckBox(
98 i18n("Strip leading and trailing blanks off of text values"), plainPage());
99 lyr->addWidget( m_chkStripWhiteSpaceInTextValues, 3, 1 );
100 lyr->addItem( new TQSpacerItem( 20, KDialogBase::spacingHint(), TQSizePolicy::Minimum, TQSizePolicy::Expanding ), 4, 1 );
101
102 //update widgets
103 if (options.defaultEncodingExplicitySet) {
104 m_encodingComboBox->setSelectedEncoding(options.encoding);
105 m_chkAlwaysUseThisEncoding->setChecked(true);
106 }
107 m_chkStripWhiteSpaceInTextValues->setChecked(options.stripWhiteSpaceInTextValuesChecked);
108
109 adjustSize();
110 m_encodingComboBox->setFocus();
111}
112
113KexiCSVImportOptionsDialog::~KexiCSVImportOptionsDialog()
114{
115}
116
117KexiCSVImportOptions KexiCSVImportOptionsDialog::options() const
118{
120 opt.encoding = m_encodingComboBox->selectedEncoding();
121 opt.stripWhiteSpaceInTextValuesChecked = m_chkStripWhiteSpaceInTextValues->isChecked();
122 return opt;
123}
124
125void KexiCSVImportOptionsDialog::accept()
126{
127 kapp->config()->setGroup("ImportExport");
128 if (m_chkAlwaysUseThisEncoding->isChecked())
129 kapp->config()->writeEntry("DefaultEncodingForImportingCSVFiles",
130 m_encodingComboBox->selectedEncoding());
131 else
132 kapp->config()->deleteEntry("DefaultEncodingForImportingCSVFiles");
133
134 kapp->config()->writeEntry("StripBlanksOffOfTextValuesWhenImportingCSVFiles",
135 m_chkStripWhiteSpaceInTextValues->isChecked());
136
137 KDialogBase::accept();
138}
139
140#include "kexicsvimportoptionsdlg.moc"
Combobox widget providing a list of possible character encodings.