kexi

kexicsvimportdialog.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005-2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This work is based on kspread/dialogs/kspread_dlg_csv.cc
00005    and will be merged back with KOffice libraries.
00006 
00007    Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
00008    Copyright (C) 2002-2003 Ariya Hidayat <ariya@kde.org>
00009    Copyright (C) 2002 Laurent Montel <montel@kde.org>
00010    Copyright (C) 1999 David Faure <faure@kde.org>
00011 
00012    This library is free software; you can redistribute it and/or
00013    modify it under the terms of the GNU Library General Public
00014    License as published by the Free Software Foundation; either
00015    version 2 of the License, or (at your option) any later version.
00016 
00017    This library is distributed in the hope that it will be useful,
00018    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020    Library General Public License for more details.
00021 
00022    You should have received a copy of the GNU Library General Public License
00023    along with this library; see the file COPYING.LIB.  If not, write to
00024    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00025  * Boston, MA 02110-1301, USA.
00026 */
00027 
00028 #ifndef KEXI_CSVDIALOG_H
00029 #define KEXI_CSVDIALOG_H
00030 
00031 #include <qvaluevector.h>
00032 #include <qvaluelist.h>
00033 #include <qptrvector.h>
00034 #include <qregexp.h>
00035 #include <qbitarray.h>
00036 
00037 #include <kdialogbase.h>
00038 
00039 #include <kexiutils/tristate.h>
00040 #include <kexidb/connection.h>
00041 
00042 #include "kexicsvimportoptionsdlg.h"
00043 
00044 class QVBoxLayout;
00045 class QHBoxLayout;
00046 class QGridLayout;
00047 class QButtonGroup;
00048 class QCheckBox;
00049 class QLabel;
00050 class QLineEdit;
00051 class QPushButton;
00052 class QRadioButton;
00053 class QTable;
00054 class QFile;
00055 class KComboBox;
00056 class KIntSpinBox;
00057 class KProgressDialog;
00058 
00059 class KexiMainWindow;
00060 class KexiCSVDelimiterWidget;
00061 class KexiCSVTextQuoteComboBox;
00062 class KexiCSVInfoLabel;
00063 
00078 class KexiCSVImportDialog : public KDialogBase
00079 {
00080     Q_OBJECT
00081 
00082     public:
00083         enum Mode { Clipboard, File /*, Column*/ };
00084         enum Header { TEXT, NUMBER, DATE, CURRENCY };
00085 
00087         KexiCSVImportDialog( Mode mode, KexiMainWindow* mainWin, QWidget * parent, 
00088           const char * name = 0/*, QRect const & rect*/);
00089 
00090         virtual ~KexiCSVImportDialog();
00091 
00092         bool cancelled() const;
00093         virtual bool eventFilter ( QObject * watched, QEvent * e );
00094 
00095     protected:
00096         bool openData();
00097         virtual void accept();
00098 
00099     private:
00100         QGridLayout* MyDialogLayout;
00101         QHBoxLayout* Layout1;
00102         QTable* m_table;
00103         KexiCSVDelimiterWidget* m_delimiterWidget;
00104         bool m_detectDelimiter; 
00105 
00106         QString m_formatComboText;
00107         QLabel* m_formatLabel;
00108         KComboBox* m_formatCombo;
00109         KIntSpinBox *m_startAtLineSpinBox;
00110         KexiCSVTextQuoteComboBox* m_comboQuote;
00111         QLabel* m_startAtLineLabel;
00112         QLabel* TextLabel2;
00113         QCheckBox* m_ignoreDuplicates;
00114         QCheckBox* m_1stRowForFieldNames;
00115         QCheckBox* m_primaryKeyField;
00116 
00117         KexiMainWindow* m_mainWin;
00118 
00119         void detectTypeAndUniqueness(int row, int col, const QString& text);
00120         void setText(int row, int col, const QString& text, bool inGUI);
00121 
00127         bool parseDate(const QString& text, QDate& date);
00128 
00134         bool parseTime(const QString& text, QTime& time);
00135 
00137         void adjustRows(int iRows);
00138 
00139         int  getHeader(int col);
00140         QString getText(int row, int col);
00141         void updateColumnText(int col);
00142         void updateRowCountInfo();
00143         tristate loadRows(QString &field, int &row, int &columnm, int &maxColumn, bool inGUI);
00144 
00166         QString detectDelimiterByLookingAtFirstBytesOfFile(QTextStream& inputStream);
00167 
00170         bool saveRow(bool inGUI);
00171 
00172         bool m_cancelled;
00173         bool m_adjustRows;
00174         int m_startline;
00175         QChar m_textquote;
00176         QString m_clipboardData;
00177         QByteArray m_fileArray;
00178         Mode m_mode;
00179         int m_prevSelectedCol;
00180 
00183         QValueVector<int> m_detectedTypes;
00184 
00187         QPtrVector< QValueList<int> > m_uniquenessTest;
00188 
00189         QRegExp m_dateRegExp, m_timeRegExp1, m_timeRegExp2, m_fpNumberRegExp;
00190         QValueVector<QString> m_typeNames, m_columnNames;
00191         QBitArray m_changedColumnNames;
00192         bool m_columnsAdjusted : 1; 
00193         bool m_1stRowForFieldNamesDetected : 1; 
00194         bool m_firstFillTableCall : 1; 
00195         bool m_blockUserEvents : 1;
00196         int m_primaryKeyColumn; 
00197         int m_maximumRowsForPreview;
00198         int m_maximumBytesForPreview;
00199         QPixmap m_pkIcon;
00200         QString m_fname;
00201         QFile* m_file;
00202         QTextStream *m_inputStream; 
00203         KexiCSVImportOptions m_options;
00204         KProgressDialog *m_loadingProgressDlg, *m_importingProgressDlg;
00205         bool m_dialogCancelled;
00206         KexiCSVInfoLabel *m_infoLbl;
00207         KexiDB::Connection *m_conn; 
00208         KexiDB::TableSchema *m_destinationTableSchema;  
00209         KexiDB::PreparedStatement::Ptr m_importingStatement;
00210         QValueList<QVariant> m_dbRowBuffer; 
00211         bool m_implicitPrimaryKeyAdded; 
00212         bool m_allRowsLoadedInPreview; 
00213         bool m_stoppedAt_MAX_BYTES_TO_PREVIEW; 
00214 
00215     private slots:
00216         void fillTable();
00217         void fillTableLater();
00218         void initLater();
00219         void formatChanged(int id);
00220         void delimiterChanged(const QString& delimiter);
00221         void startlineSelected(int line);
00222         void textquoteSelected(int);
00223         void currentCellChanged(int, int col);
00224         void ignoreDuplicatesChanged(int);
00225         void slot1stRowForFieldNamesChanged(int);
00226         void cellValueChanged(int row,int col);
00227         void optionsButtonClicked();
00228         void slotPrimaryKeyFieldToggled(bool on);
00229 };
00230 
00231 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys