kexi

kexicsvimportdialog.h
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This work is based on kspread/dialogs/kspread_dlg_csv.cpp
5 and will be merged back with KOffice libraries.
6
7 Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
8 Copyright (C) 2002-2003 Ariya Hidayat <ariya@kde.org>
9 Copyright (C) 2002 Laurent Montel <montel@kde.org>
10 Copyright (C) 1999 David Faure <faure@kde.org>
11
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Library General Public
14 License as published by the Free Software Foundation; either
15 version 2 of the License, or (at your option) any later version.
16
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
21
22 You should have received a copy of the GNU Library General Public License
23 along with this library; see the file COPYING.LIB. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
26*/
27
28#ifndef KEXI_CSVDIALOG_H
29#define KEXI_CSVDIALOG_H
30
31#include <tqvaluevector.h>
32#include <tqvaluelist.h>
33#include <tqptrvector.h>
34#include <tqregexp.h>
35#include <tqbitarray.h>
36
37#include <kdialogbase.h>
38
39#include <kexiutils/tristate.h>
40#include <kexidb/connection.h>
41
42#include "kexicsvimportoptionsdlg.h"
43
44class TQVBoxLayout;
45class TQHBoxLayout;
46class TQGridLayout;
47class TQButtonGroup;
48class TQCheckBox;
49class TQLabel;
50class TQLineEdit;
51class TQPushButton;
52class TQRadioButton;
53class TQTable;
54class TQFile;
55class KComboBox;
56class KIntSpinBox;
57class KProgressDialog;
58
59class KexiMainWindow;
63
78class KexiCSVImportDialog : public KDialogBase
79{
80 TQ_OBJECT
81
82
83 public:
84 enum Mode { Clipboard, File /*, Column*/ };
85 enum Header { TEXT, NUMBER, DATE, CURRENCY };
86
88 KexiCSVImportDialog( Mode mode, KexiMainWindow* mainWin, TQWidget * parent,
89 const char * name = 0/*, TQRect const & rect*/);
90
91 virtual ~KexiCSVImportDialog();
92
93 bool cancelled() const;
94 virtual bool eventFilter ( TQObject * watched, TQEvent * e );
95
96 protected:
97 bool openData();
98 virtual void accept();
99
100 private:
101 TQGridLayout* MyDialogLayout;
102 TQHBoxLayout* Layout1;
103 TQTable* m_table;
104 KexiCSVDelimiterWidget* m_delimiterWidget;
105 bool m_detectDelimiter;
107 TQString m_formatComboText;
108 TQLabel* m_formatLabel;
109 KComboBox* m_formatCombo;
110 KIntSpinBox *m_startAtLineSpinBox;
111 KexiCSVTextQuoteComboBox* m_comboQuote;
112 TQLabel* m_startAtLineLabel;
113 TQLabel* TextLabel2;
114 TQCheckBox* m_ignoreDuplicates;
115 TQCheckBox* m_1stRowForFieldNames;
116 TQCheckBox* m_primaryKeyField;
117
118 KexiMainWindow* m_mainWin;
119
120 void detectTypeAndUniqueness(int row, int col, const TQString& text);
121 void setText(int row, int col, const TQString& text, bool inGUI);
122
128 bool parseDate(const TQString& text, TQDate& date);
129
135 bool parseTime(const TQString& text, TQTime& time);
136
138 void adjustRows(int iRows);
139
140 int getHeader(int col);
141 TQString getText(int row, int col);
142 void updateColumnText(int col);
143 void updateRowCountInfo();
144 tristate loadRows(TQString &field, int &row, int &columnm, int &maxColumn, bool inGUI);
145
167 TQString detectDelimiterByLookingAtFirstBytesOfFile(TQTextStream& inputStream);
168
171 bool saveRow(bool inGUI);
172
173 bool m_cancelled;
174 bool m_adjustRows;
175 int m_startline;
176 TQChar m_textquote;
177 TQString m_clipboardData;
178 TQByteArray m_fileArray;
179 Mode m_mode;
180 int m_prevSelectedCol;
181
184 TQValueVector<int> m_detectedTypes;
185
188 TQPtrVector< TQValueList<int> > m_uniquenessTest;
189
190 TQRegExp m_dateRegExp, m_timeRegExp1, m_timeRegExp2, m_fpNumberRegExp;
191 TQValueVector<TQString> m_typeNames, m_columnNames;
192 TQBitArray m_changedColumnNames;
193 bool m_columnsAdjusted : 1;
194 bool m_1stRowForFieldNamesDetected : 1;
195 bool m_firstFillTableCall : 1;
196 bool m_blockUserEvents : 1;
197 int m_primaryKeyColumn;
198 int m_maximumRowsForPreview;
199 int m_maximumBytesForPreview;
200 TQPixmap m_pkIcon;
201 TQString m_fname;
202 TQFile* m_file;
203 TQTextStream *m_inputStream;
204 KexiCSVImportOptions m_options;
205 KProgressDialog *m_loadingProgressDlg, *m_importingProgressDlg;
206 bool m_dialogCancelled;
207 KexiCSVInfoLabel *m_infoLbl;
208 KexiDB::Connection *m_conn;
209 KexiDB::TableSchema *m_destinationTableSchema;
210 KexiDB::PreparedStatement::Ptr m_importingStatement;
211 TQValueList<TQVariant> m_dbRowBuffer;
212 bool m_implicitPrimaryKeyAdded;
213 bool m_allRowsLoadedInPreview;
214 bool m_stoppedAt_MAX_BYTES_TO_PREVIEW;
215
216 private slots:
217 void fillTable();
218 void fillTableLater();
219 void initLater();
220 void formatChanged(int id);
221 void delimiterChanged(const TQString& delimiter);
222 void startlineSelected(int line);
223 void textquoteSelected(int);
224 void currentCellChanged(int, int col);
225 void ignoreDuplicatesChanged(int);
226 void slot1stRowForFieldNamesChanged(int);
227 void cellValueChanged(int row,int col);
228 void optionsButtonClicked();
229 void slotPrimaryKeyFieldToggled(bool on);
230};
231
232#endif
A combo box widget providing a list of possible delimiters Used by CSV import and export dialogs.
KexiCSVImportDialog(Mode mode, KexiMainWindow *mainWin, TQWidget *parent, const char *name=0)
A helper widget showing a short text information with an icon. See ctor for details....
A combo box widget providing a list of possible quote characters Used by CSV import and export dialog...
Provides database connection, allowing queries and data modification.
Definition connection.h:62
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition tristate.h:100