libkdepim

kimportdialog.h

00001 /*
00002     This file is part of libkdepim.
00003 
00004     Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 #ifndef KIMPORTDIALOG_H
00023 #define KIMPORTDIALOG_H
00024 
00025 #include <tqintdict.h>
00026 #include <tqstringlist.h>
00027 #include <tqspinbox.h>
00028 #include <tqptrvector.h>
00029 #include <tqvaluevector.h>
00030 
00031 #include <kdialogbase.h>
00032 
00033 class TQTable;
00034 class TQListView;
00035 
00036 class KImportDialog;
00037 class KComboBox;
00038 
00039 class KImportColumn
00040 {
00041   public:
00042     enum { FormatUndefined = 0, FormatPlain, FormatUnquoted, FormatBracketed, FormatLast };
00043 
00044     KImportColumn(KImportDialog *dlg, const TQString &header, int count = 0);
00045     virtual ~KImportColumn() {}
00046 
00047     TQString header() const { return m_header; }
00048 
00049     TQValueList<int> formats();
00050     TQString formatName(int format);
00051     int defaultFormat();
00052 
00053     TQString convert();
00054 //    virtual void convert(const TQString &value,int format) = 0;
00055     TQString preview(const TQString &value,int format);
00056 
00057     void addColId(int i);
00058     void removeColId(int i);
00059 
00060     TQValueList<int> colIdList();
00061 
00062   protected:
00063 
00064   private:
00065     int m_maxCount, m_refCount;
00066 
00067     TQString m_header;
00068     TQValueList<int> mFormats;
00069     int mDefaultFormat;
00070     
00071     TQValueList<int> mColIds;
00072     
00073     KImportDialog *mDialog;
00074 };
00075 
00076 class KImportDialog : public KDialogBase
00077 {
00078     Q_OBJECT
00079   TQ_OBJECT
00080   public:
00081     KImportDialog(TQWidget* parent);
00082 
00083   public slots:
00084     bool setFile(const TQString& file);
00085 
00086     TQString cell(uint row);
00087 
00088     void addColumn(KImportColumn *);
00089 
00090   protected:
00091     void readFile( int rows = 10 );
00092   
00093     void fillTable();
00094     void registerColumns();
00095     int findFormat(int column);
00096 
00097     virtual void convertRow() {}
00098 
00099   protected slots:
00100     void separatorClicked(int id);
00101     void formatSelected(TQListViewItem* item);
00102     void headerSelected(TQListViewItem* item);
00103     void assignColumn(TQListViewItem *);
00104     void assignColumn();
00105     void assignTemplate();
00106     void removeColumn();
00107     void applyConverter();
00108     void tableSelected();
00109     void slotUrlChanged(const TQString & );
00110     void saveTemplate();
00111 
00112   private:
00113     void updateFormatSelection(int column);
00114     void setCellText(int row, int col, const TQString& text);
00115 
00116     void setData( uint row, uint col, const TQString &text );
00117     TQString data( uint row, uint col );
00118 
00119     TQListView *mHeaderList;
00120     TQSpinBox *mStartRow;
00121     TQSpinBox *mEndRow;
00122     TQTable *mTable;
00123 
00124     KComboBox *mFormatCombo;
00125     KComboBox *mSeparatorCombo;
00126 
00127     TQString mSeparator;
00128     int mCurrentRow;
00129     TQString mFile;
00130     TQIntDict<KImportColumn> mColumnDict;
00131     TQIntDict<uint> mTemplateDict;
00132     TQMap<int,int> mFormats;
00133     TQPtrList<KImportColumn> mColumns;
00134     TQPtrVector<TQValueVector<TQString> > mData;
00135 };
00136 
00137 #endif