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              (C) 2002-2003 Ariya Hidayat <ariya@kde.org>
00009              (C) 2002     Laurent Montel <montel@kde.org>
00010              (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 class QVBoxLayout;
00043 class QHBoxLayout;
00044 class QGridLayout;
00045 class QButtonGroup;
00046 class QCheckBox;
00047 class QLabel;
00048 class QLineEdit;
00049 class QPushButton;
00050 class QRadioButton;
00051 class QTable;
00052 class QFile;
00053 class KComboBox;
00054 class KIntSpinBox;
00055 class KProgressDialog;
00056 
00057 class KexiMainWindow;
00058 class KexiCSVDelimiterWidget;
00059 class KexiCSVTextQuoteComboBox;
00060 class KexiCSVInfoLabel;
00061 
00076 class KexiCSVImportDialog : public KDialogBase
00077 {
00078   Q_OBJECT
00079 
00080  public:
00081 
00082   enum Mode { Clipboard, File /*, Column*/ };
00083   enum Header { TEXT, NUMBER, DATE, CURRENCY };
00084 
00086   KexiCSVImportDialog( Mode mode, KexiMainWindow* mainWin, QWidget * parent, 
00087       const char * name = 0/*, QRect const & rect*/);
00088 
00089   ~KexiCSVImportDialog();
00090 
00091   bool cancelled() const;
00092   virtual bool eventFilter ( QObject * watched, QEvent * e );
00093 
00094  protected:
00095   bool openData();
00096   virtual void accept();
00097 
00098 
00099  private:
00100   QGridLayout* MyDialogLayout;
00101   QHBoxLayout* Layout1;
00102   QTable* m_table;
00103   KexiCSVDelimiterWidget* m_delimiterWidget;
00104   QString m_formatComboText;
00105   QLabel* m_formatLabel;
00106   KComboBox* m_formatCombo;
00107   KIntSpinBox *m_startAtLineSpinBox;
00108   KexiCSVTextQuoteComboBox* m_comboQuote;
00109   QLabel* m_startAtLineLabel;
00110   QLabel* TextLabel2;
00111   QCheckBox* m_ignoreDuplicates;
00112   QCheckBox* m_1stRowForFieldNames;
00113   QCheckBox* m_primaryKeyField;
00114 
00115   KexiMainWindow* m_mainWin;
00116 
00117   void detectTypeAndUniqueness(int row, int col, const QString& text);
00118   void setText(int row, int col, const QString& text, bool inGUI);
00119 
00121   void adjustRows(int iRows);
00122 
00123   int  getHeader(int col);
00124   QString getText(int row, int col);
00125   void updateColumnText(int col);
00126   void updateRowCountInfo();
00127   tristate loadRows(QString &field, int &row, int &columnm, int &maxColumn, bool inGUI);
00128 
00131   bool saveRow(bool inGUI);
00132 
00133   bool m_cancelled;
00134   int m_adjustRows;
00135   int m_startline;
00136   QChar m_textquote;
00137   QString m_data;
00138   QByteArray m_fileArray;
00139     Mode m_mode;
00140     int m_prevSelectedCol;
00141 
00144     QValueVector<int> m_detectedTypes;
00145 
00148     QPtrVector< QValueList<int> > m_uniquenessTest;
00149 
00150     QRegExp m_dateRegExp1, m_dateRegExp2, m_timeRegExp1, m_timeRegExp2, m_fpNumberRegExp;
00151     QValueVector<QString> m_typeNames, m_columnNames;
00152     QBitArray m_changedColumnNames;
00153     bool m_columnsAdjusted : 1; //only once
00154     bool m_1stRowForFieldNamesDetected : 1; 
00155     bool m_firstFillTableCall : 1; 
00156     bool m_blockUserEvents : 1;
00157     int m_primaryKeyColumn; 
00158     int m_maximumRowsForPreview;
00159     QPixmap m_pkIcon;
00160     QString m_fname;
00161     QFile* m_file;
00162     QTextStream *m_inputStream; 
00163     QString m_encoding;
00164     KProgressDialog *m_loadingProgressDlg, *m_importingProgressDlg;
00165     bool m_dialogCancelled;
00166     KexiCSVInfoLabel *m_infoLbl;
00167     KexiDB::Connection *m_conn; 
00168     KexiDB::TableSchema *m_destinationTableSchema;  
00169     KexiDB::PreparedStatement::Ptr m_importingStatement;
00170     QValueList<QVariant> m_dbRowBuffer; 
00171     bool m_implicitPrimaryKeyAdded; 
00172 
00173  private slots:
00174   void fillTable();
00175   void initLater();
00176   void formatChanged(int id);
00177   void delimiterChanged(const QString& delimiter);
00178   void startlineSelected(int line);
00179   void textquoteSelected(int);
00180   void currentCellChanged(int, int col);
00181   void ignoreDuplicatesChanged(int);
00182   void slot1stRowForFieldNamesChanged(int);
00183   void cellValueChanged(int row,int col);
00184   void optionsButtonClicked();
00185   void slotPrimaryKeyFieldToggled(bool on);
00186 };
00187 
00188 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys