kaddressbook

csvimportdialog.h
00001 /*
00002    This file is part of KAddressBook.
00003    Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
00004                  based on the code of KSpread's CSV Import Dialog
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef CSV_IMPORT_DLG_H
00023 #define CSV_IMPORT_DLG_H
00024 
00025 #include <kabc/addressbook.h>
00026 #include <kabc/addresseelist.h>
00027 #include <kdialogbase.h>
00028 
00029 #include <tqvaluelist.h>
00030 
00031 class KURLRequester;
00032 
00033 class TQButtonGroup;
00034 class TQComboBox;
00035 class TQCheckBox;
00036 class TQLineEdit;
00037 class TQPushButton;
00038 class TQRadioButton;
00039 class TQTable;
00040 
00041 class CSVImportDialog : public KDialogBase
00042 {
00043   Q_OBJECT
00044   TQ_OBJECT
00045 
00046   public:
00047     CSVImportDialog( KABC::AddressBook *ab, TQWidget *parent,
00048                      const char *name = 0 );
00049     ~CSVImportDialog();
00050 
00051     KABC::AddresseeList contacts() const;
00052 
00053   protected slots:
00054     virtual void slotOk();
00055 
00056   private slots:
00057     void returnPressed();
00058     void delimiterClicked( int id );
00059     void lineSelected( const TQString& line );
00060     void textquoteSelected( const TQString& mark );
00061     void textChanged ( const TQString & );
00062     void ignoreDuplicatesChanged( int );
00063     void setFile( const TQString& );
00064     void urlChanged( const TQString& );
00065     void codecChanged();
00066 
00067     void applyTemplate();
00068     void saveTemplate();
00069 
00070   private:
00071     enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName,
00072            Prefix, Suffix, NickName, Birthday,
00073            HomeAddressStreet, HomeAddressLocality, HomeAddressRegion,
00074            HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel,
00075            BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion,
00076            BusinessAddressPostalCode, BusinessAddressCountry,
00077            BusinessAddressLabel,
00078            HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone,
00079            Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL
00080          };
00081 
00082     TQTable* mTable;
00083     TQButtonGroup* mDelimiterBox;
00084     TQRadioButton* mRadioComma;
00085     TQRadioButton* mRadioSemicolon;
00086     TQRadioButton* mRadioTab;
00087     TQRadioButton* mRadioSpace;
00088     TQRadioButton* mRadioOther;
00089     TQLineEdit* mDelimiterEdit;
00090     TQLineEdit* mDatePatternEdit;
00091     TQComboBox* mComboLine;
00092     TQComboBox* mComboQuote;
00093     TQCheckBox* mIgnoreDuplicates;
00094     TQComboBox* mCodecCombo;
00095     TQWidget* mPage;
00096     KURLRequester* mUrlRequester;
00097 
00098     void initGUI();
00099     void fillTable();
00100     void clearTable();
00101     void fillComboBox();
00102     void setText( int row, int col, const TQString& text );
00103     void adjustRows( int rows );
00104     void resizeColumns();
00105     TQString getText( int row, int col );
00106     uint posToType( int pos ) const;
00107     int typeToPos( uint type ) const;
00108 
00109     void reloadCodecs();
00110     TQTextCodec *currentCodec();
00111     TQPtrList<TQTextCodec> mCodecs;
00112 
00113     bool mAdjustRows;
00114     int mStartLine;
00115     TQChar mTextQuote;
00116     TQString mDelimiter;
00117     TQByteArray mFileArray;
00118     TQMap<TQString, uint> mTypeMap;
00119     KABC::AddressBook *mAddressBook;
00120     int mCustomCounter;
00121     bool mClearTypeStore;
00122     TQValueList<int> mTypeStore;
00123 };
00124 
00125 #endif