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 
00125     bool parseDate(const QString& text, QDate& date);
00126 
00132     bool parseTime(const QString& text, QTime& time);
00133 
00135   void adjustRows(int iRows);
00136 
00137   int  getHeader(int col);
00138   QString getText(int row, int col);
00139   void updateColumnText(int col);
00140   void updateRowCountInfo();
00141   tristate loadRows(QString &field, int &row, int &columnm, int &maxColumn, bool inGUI);
00143   QString detectDelimiterByLookingAtFirstBytesOfFile(QTextStream& inputStream);
00144 
00147   bool saveRow(bool inGUI);
00148 
00149   bool m_cancelled;
00150   int m_adjustRows;
00151   int m_startline;
00152   QChar m_textquote;
00153   QString m_clipboardData;
00154   QByteArray m_fileArray;
00155     Mode m_mode;
00156     int m_prevSelectedCol;
00157 
00160     QValueVector<int> m_detectedTypes;
00161 
00164     QPtrVector< QValueList<int> > m_uniquenessTest;
00165 
00166     QRegExp m_dateRegExp, m_timeRegExp1, m_timeRegExp2, m_fpNumberRegExp;
00167     QValueVector<QString> m_typeNames, m_columnNames;
00168     QBitArray m_changedColumnNames;
00169     bool m_columnsAdjusted : 1; //only once
00170     bool m_1stRowForFieldNamesDetected : 1; 
00171     bool m_firstFillTableCall : 1; 
00172     bool m_blockUserEvents : 1;
00173     int m_primaryKeyColumn; 
00174     int m_maximumRowsForPreview;
00175     int m_maximumBytesForPreview;
00176     QPixmap m_pkIcon;
00177     QString m_fname;
00178     QFile* m_file;
00179     QTextStream *m_inputStream; 
00180     QString m_encoding;
00181     KProgressDialog *m_loadingProgressDlg, *m_importingProgressDlg;
00182     bool m_dialogCancelled;
00183     KexiCSVInfoLabel *m_infoLbl;
00184     KexiDB::Connection *m_conn; 
00185     KexiDB::TableSchema *m_destinationTableSchema;  
00186     KexiDB::PreparedStatement::Ptr m_importingStatement;
00187     QValueList<QVariant> m_dbRowBuffer; 
00188     bool m_implicitPrimaryKeyAdded; 
00189     bool m_allRowsLoadedInPreview; 
00190     bool m_stoppedAt_MAX_BYTES_TO_PREVIEW; 
00191 
00192  private slots:
00193   void fillTable();
00194   void initLater();
00195   void formatChanged(int id);
00196   void delimiterChanged(const QString& delimiter);
00197   void startlineSelected(int line);
00198   void textquoteSelected(int);
00199   void currentCellChanged(int, int col);
00200   void ignoreDuplicatesChanged(int);
00201   void slot1stRowForFieldNamesChanged(int);
00202   void cellValueChanged(int row,int col);
00203   void optionsButtonClicked();
00204   void slotPrimaryKeyFieldToggled(bool on);
00205 };
00206 
00207 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys