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 
00045   public:
00046     CSVImportDialog( KABC::AddressBook *ab, TQWidget *parent,
00047                      const char *name = 0 );
00048     ~CSVImportDialog();
00049 
00050     KABC::AddresseeList contacts() const;
00051 
00052   protected slots:
00053     virtual void slotOk();
00054 
00055   private slots:
00056     void returnPressed();
00057     void delimiterClicked( int id );
00058     void lineSelected( const TQString& line );
00059     void textquoteSelected( const TQString& mark );
00060     void textChanged ( const TQString & );
00061     void ignoreDuplicatesChanged( int );
00062     void setFile( const TQString& );
00063     void urlChanged( const TQString& );
00064     void codecChanged();
00065 
00066     void applyTemplate();
00067     void saveTemplate();
00068 
00069   private:
00070     enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName,
00071            Prefix, Suffix, NickName, Birthday,
00072            HomeAddressStreet, HomeAddressLocality, HomeAddressRegion,
00073            HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel,
00074            BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion,
00075            BusinessAddressPostalCode, BusinessAddressCountry,
00076            BusinessAddressLabel,
00077            HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone,
00078            Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL
00079          };
00080 
00081     TQTable* mTable;
00082     TQButtonGroup* mDelimiterBox;
00083     TQRadioButton* mRadioComma;
00084     TQRadioButton* mRadioSemicolon;
00085     TQRadioButton* mRadioTab;
00086     TQRadioButton* mRadioSpace;
00087     TQRadioButton* mRadioOther;
00088     TQLineEdit* mDelimiterEdit;
00089     TQLineEdit* mDatePatternEdit;
00090     TQComboBox* mComboLine;
00091     TQComboBox* mComboQuote;
00092     TQCheckBox* mIgnoreDuplicates;
00093     TQComboBox* mCodecCombo;
00094     TQWidget* mPage;
00095     KURLRequester* mUrlRequester;
00096 
00097     void initGUI();
00098     void fillTable();
00099     void clearTable();
00100     void fillComboBox();
00101     void setText( int row, int col, const TQString& text );
00102     void adjustRows( int rows );
00103     void resizeColumns();
00104     TQString getText( int row, int col );
00105     uint posToType( int pos ) const;
00106     int typeToPos( uint type ) const;
00107 
00108     void reloadCodecs();
00109     TQTextCodec *currentCodec();
00110     TQPtrList<TQTextCodec> mCodecs;
00111 
00112     bool mAdjustRows;
00113     int mStartLine;
00114     TQChar mTextQuote;
00115     TQString mDelimiter;
00116     TQByteArray mFileArray;
00117     TQMap<TQString, uint> mTypeMap;
00118     KABC::AddressBook *mAddressBook;
00119     int mCustomCounter;
00120     bool mClearTypeStore;
00121     TQValueList<int> mTypeStore;
00122 };
00123 
00124 #endif