kaddressbook

csvimportdialog.h
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
4 based on the code of KSpread's CSV Import Dialog
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef CSV_IMPORT_DLG_H
23#define CSV_IMPORT_DLG_H
24
25#include <tdeabc/addressbook.h>
26#include <tdeabc/addresseelist.h>
27#include <kdialogbase.h>
28
29#include <tqvaluelist.h>
30
31class KURLRequester;
32
33class TQButtonGroup;
34class TQComboBox;
35class TQCheckBox;
36class TQLineEdit;
37class TQPushButton;
38class TQRadioButton;
39class TQTable;
40
41class CSVImportDialog : public KDialogBase
42{
43 TQ_OBJECT
44
45
46 public:
47 CSVImportDialog( TDEABC::AddressBook *ab, TQWidget *parent,
48 const char *name = 0 );
49 ~CSVImportDialog();
50
51 TDEABC::AddresseeList contacts() const;
52
53 protected slots:
54 virtual void slotOk();
55
56 private slots:
57 void returnPressed();
58 void delimiterClicked( int id );
59 void lineSelected( const TQString& line );
60 void textquoteSelected( const TQString& mark );
61 void textChanged ( const TQString & );
62 void ignoreDuplicatesChanged( int );
63 void setFile( const TQString& );
64 void urlChanged( const TQString& );
65 void codecChanged();
66
67 void applyTemplate();
68 void saveTemplate();
69
70 private:
71 enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName,
72 Prefix, Suffix, NickName, Birthday,
73 HomeAddressStreet, HomeAddressLocality, HomeAddressRegion,
74 HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel,
75 BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion,
76 BusinessAddressPostalCode, BusinessAddressCountry,
77 BusinessAddressLabel,
78 HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone,
79 Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL
80 };
81
82 TQTable* mTable;
83 TQButtonGroup* mDelimiterBox;
84 TQRadioButton* mRadioComma;
85 TQRadioButton* mRadioSemicolon;
86 TQRadioButton* mRadioTab;
87 TQRadioButton* mRadioSpace;
88 TQRadioButton* mRadioOther;
89 TQLineEdit* mDelimiterEdit;
90 TQLineEdit* mDatePatternEdit;
91 TQComboBox* mComboLine;
92 TQComboBox* mComboQuote;
93 TQCheckBox* mIgnoreDuplicates;
94 TQComboBox* mCodecCombo;
95 TQWidget* mPage;
96 KURLRequester* mUrlRequester;
97
98 void initGUI();
99 void fillTable();
100 void clearTable();
101 void fillComboBox();
102 void setText( int row, int col, const TQString& text );
103 void adjustRows( int rows );
104 void resizeColumns();
105 TQString getText( int row, int col );
106 uint posToType( int pos ) const;
107 int typeToPos( uint type ) const;
108
109 void reloadCodecs();
110 TQTextCodec *currentCodec();
111 TQPtrList<TQTextCodec> mCodecs;
112
113 bool mAdjustRows;
114 int mStartLine;
115 TQChar mTextQuote;
116 TQString mDelimiter;
117 TQByteArray mFileArray;
118 TQMap<TQString, uint> mTypeMap;
119 TDEABC::AddressBook *mAddressBook;
120 int mCustomCounter;
121 bool mClearTypeStore;
122 TQValueList<int> mTypeStore;
123};
124
125#endif