-rw-r--r-- | kaddressbook/xxport/csvimportdialog.cpp | 4 | ||||
-rw-r--r-- | kaddressbook/xxport/csvimportdialog.h | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/kaddressbook/xxport/csvimportdialog.cpp b/kaddressbook/xxport/csvimportdialog.cpp index 4044fa8..862241e 100644 --- a/kaddressbook/xxport/csvimportdialog.cpp +++ b/kaddressbook/xxport/csvimportdialog.cpp | |||
@@ -1,969 +1,969 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (C) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (C) 2003 Tobias Koenig <tokoe@kde.org> |
4 | based on the code of KSpread's CSV Import Dialog | 4 | based on the code of KSpread's CSV Import Dialog |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 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 | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | 29 | ||
30 | #include <qbuttongroup.h> | 30 | #include <qbuttongroup.h> |
31 | #include <qcheckbox.h> | 31 | #include <qcheckbox.h> |
32 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
33 | #ifdef DESKTOP_VERSION | 33 | #ifdef DESKTOP_VERSION |
34 | #include <qinputdialog.h> | 34 | #include <qinputdialog.h> |
35 | #else | 35 | #else |
36 | #include <qtcompat/qinputdialog.h> | 36 | #include <qtcompat/qinputdialog.h> |
37 | #endif | 37 | #endif |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qtable.h> | 42 | #include <qtable.h> |
43 | #include <qlayout.h> | 43 | #include <qlayout.h> |
44 | #include <qtextstream.h> | 44 | #include <qtextstream.h> |
45 | #include <qfile.h> | 45 | #include <qfile.h> |
46 | 46 | ||
47 | #include <kapplication.h> | 47 | #include <kapplication.h> |
48 | #include <kdebug.h> | 48 | #include <kdebug.h> |
49 | #include <kdialogbase.h> | 49 | #include <kdialogbase.h> |
50 | #include <kfiledialog.h> | 50 | #include <kfiledialog.h> |
51 | #include <klineedit.h> | 51 | #include <klineedit.h> |
52 | #include <klocale.h> | 52 | #include <klocale.h> |
53 | #include <kglobal.h> | 53 | #include <kglobal.h> |
54 | #include <kmessagebox.h> | 54 | #include <kmessagebox.h> |
55 | #include <kstandarddirs.h> | 55 | #include <kstandarddirs.h> |
56 | #include <kurlrequester.h> | 56 | #include <kurlrequester.h> |
57 | 57 | ||
58 | #ifdef DESKTOP_VERSION | 58 | #ifdef DESKTOP_VERSION |
59 | #include "qtable.h" | 59 | #include "qtable.h" |
60 | #else | 60 | #else |
61 | #include "qcombotableitem.h" | 61 | #include "qcombotableitem.h" |
62 | #endif | 62 | #endif |
63 | #include "csvimportdialog.h" | 63 | #include "csvimportdialog.h" |
64 | 64 | ||
65 | CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, | 65 | CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, |
66 | const char * name ) | 66 | const char * name ) |
67 | : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 | | 67 | : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 | |
68 | User2, Ok, parent, name, true, true ), | 68 | User2, Ok, parent, name, true, true ), |
69 | mAdjustRows( false ), | 69 | mAdjustRows( false ), |
70 | mStartLine( 0 ), | 70 | mStartLine( 0 ), |
71 | mTextQuote( '"' ), | 71 | mTextQuote( '"' ), |
72 | mDelimiter( "," ), | 72 | mDelimiter( "," ), |
73 | mAddressBook( ab ) | 73 | mAddressBook( ab ) |
74 | { | 74 | { |
75 | initGUI(); | 75 | initGUI(); |
76 | 76 | ||
77 | mTypeMap.insert( i18n( "Undefined" ), Undefined ); | 77 | mTypeMap.insert( i18n( "Undefined" ), Undefined ); |
78 | mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName ); | 78 | mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName ); |
79 | mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName ); | 79 | mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName ); |
80 | mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName ); | 80 | mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName ); |
81 | mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName ); | 81 | mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName ); |
82 | mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix ); | 82 | mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix ); |
83 | mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix ); | 83 | mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix ); |
84 | mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName ); | 84 | mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName ); |
85 | mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday ); | 85 | mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday ); |
86 | 86 | ||
87 | mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet ); | 87 | mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet ); |
88 | mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(), | 88 | mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(), |
89 | HomeAddressLocality ); | 89 | HomeAddressLocality ); |
90 | mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion ); | 90 | mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion ); |
91 | mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(), | 91 | mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(), |
92 | HomeAddressPostalCode ); | 92 | HomeAddressPostalCode ); |
93 | mTypeMap.insert( KABC::Addressee::homeAddressCountryLabel(), | 93 | mTypeMap.insert( KABC::Addressee::homeAddressCountryLabel(), |
94 | HomeAddressCountry ); | 94 | HomeAddressCountry ); |
95 | mTypeMap.insert( KABC::Addressee::homeAddressLabelLabel(), HomeAddressLabel ); | 95 | mTypeMap.insert( KABC::Addressee::homeAddressLabelLabel(), HomeAddressLabel ); |
96 | 96 | ||
97 | mTypeMap.insert( KABC::Addressee::businessAddressStreetLabel(), | 97 | mTypeMap.insert( KABC::Addressee::businessAddressStreetLabel(), |
98 | BusinessAddressStreet ); | 98 | BusinessAddressStreet ); |
99 | mTypeMap.insert( KABC::Addressee::businessAddressLocalityLabel(), | 99 | mTypeMap.insert( KABC::Addressee::businessAddressLocalityLabel(), |
100 | BusinessAddressLocality ); | 100 | BusinessAddressLocality ); |
101 | mTypeMap.insert( KABC::Addressee::businessAddressRegionLabel(), | 101 | mTypeMap.insert( KABC::Addressee::businessAddressRegionLabel(), |
102 | BusinessAddressRegion ); | 102 | BusinessAddressRegion ); |
103 | mTypeMap.insert( KABC::Addressee::businessAddressPostalCodeLabel(), | 103 | mTypeMap.insert( KABC::Addressee::businessAddressPostalCodeLabel(), |
104 | BusinessAddressPostalCode ); | 104 | BusinessAddressPostalCode ); |
105 | mTypeMap.insert( KABC::Addressee::businessAddressCountryLabel(), | 105 | mTypeMap.insert( KABC::Addressee::businessAddressCountryLabel(), |
106 | BusinessAddressCountry ); | 106 | BusinessAddressCountry ); |
107 | mTypeMap.insert( KABC::Addressee::businessAddressLabelLabel(), | 107 | mTypeMap.insert( KABC::Addressee::businessAddressLabelLabel(), |
108 | BusinessAddressLabel ); | 108 | BusinessAddressLabel ); |
109 | 109 | ||
110 | mTypeMap.insert( KABC::Addressee::homePhoneLabel(), HomePhone ); | 110 | mTypeMap.insert( KABC::Addressee::homePhoneLabel(), HomePhone ); |
111 | mTypeMap.insert( KABC::Addressee::businessPhoneLabel(), BusinessPhone ); | 111 | mTypeMap.insert( KABC::Addressee::businessPhoneLabel(), BusinessPhone ); |
112 | mTypeMap.insert( KABC::Addressee::mobilePhoneLabel(), MobilePhone ); | 112 | mTypeMap.insert( KABC::Addressee::mobilePhoneLabel(), MobilePhone ); |
113 | mTypeMap.insert( KABC::Addressee::homeFaxLabel(), HomeFax ); | 113 | mTypeMap.insert( KABC::Addressee::homeFaxLabel(), HomeFax ); |
114 | mTypeMap.insert( KABC::Addressee::businessFaxLabel(), BusinessFax ); | 114 | mTypeMap.insert( KABC::Addressee::businessFaxLabel(), BusinessFax ); |
115 | mTypeMap.insert( KABC::Addressee::carPhoneLabel(), CarPhone ); | 115 | mTypeMap.insert( KABC::Addressee::mobileWorkPhoneLabel(), MobileWorkPhone ); |
116 | mTypeMap.insert( KABC::Addressee::isdnLabel(), Isdn ); | 116 | mTypeMap.insert( KABC::Addressee::isdnLabel(), Isdn ); |
117 | mTypeMap.insert( KABC::Addressee::pagerLabel(), Pager ); | 117 | mTypeMap.insert( KABC::Addressee::pagerLabel(), Pager ); |
118 | mTypeMap.insert( KABC::Addressee::emailLabel(), Email ); | 118 | mTypeMap.insert( KABC::Addressee::emailLabel(), Email ); |
119 | mTypeMap.insert( KABC::Addressee::mailerLabel(), Mailer ); | 119 | mTypeMap.insert( KABC::Addressee::mailerLabel(), Mailer ); |
120 | mTypeMap.insert( KABC::Addressee::titleLabel(), Title ); | 120 | mTypeMap.insert( KABC::Addressee::titleLabel(), Title ); |
121 | mTypeMap.insert( KABC::Addressee::roleLabel(), Role ); | 121 | mTypeMap.insert( KABC::Addressee::roleLabel(), Role ); |
122 | mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization ); | 122 | mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization ); |
123 | mTypeMap.insert( KABC::Addressee::noteLabel(), Note ); | 123 | mTypeMap.insert( KABC::Addressee::noteLabel(), Note ); |
124 | mTypeMap.insert( KABC::Addressee::urlLabel(), URL ); | 124 | mTypeMap.insert( KABC::Addressee::urlLabel(), URL ); |
125 | mTypeMap.insert( KABC::Addressee::categoryLabel(), Categories ); | 125 | mTypeMap.insert( KABC::Addressee::categoryLabel(), Categories ); |
126 | 126 | ||
127 | mCustomCounter = mTypeMap.count(); | 127 | mCustomCounter = mTypeMap.count(); |
128 | int count = mCustomCounter; | 128 | int count = mCustomCounter; |
129 | 129 | ||
130 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); | 130 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); |
131 | KABC::Field::List::Iterator it; | 131 | KABC::Field::List::Iterator it; |
132 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) | 132 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) |
133 | mTypeMap.insert( (*it)->label(), count ); | 133 | mTypeMap.insert( (*it)->label(), count ); |
134 | 134 | ||
135 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), | 135 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), |
136 | this, SLOT( delimiterClicked( int ) ) ); | 136 | this, SLOT( delimiterClicked( int ) ) ); |
137 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), | 137 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), |
138 | this, SLOT( returnPressed() ) ); | 138 | this, SLOT( returnPressed() ) ); |
139 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), | 139 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), |
140 | this, SLOT( textChanged ( const QString& ) ) ); | 140 | this, SLOT( textChanged ( const QString& ) ) ); |
141 | connect( mComboLine, SIGNAL( activated( const QString& ) ), | 141 | connect( mComboLine, SIGNAL( activated( const QString& ) ), |
142 | this, SLOT( lineSelected( const QString& ) ) ); | 142 | this, SLOT( lineSelected( const QString& ) ) ); |
143 | connect( mComboCodec, SIGNAL( activated( const QString& ) ), | 143 | connect( mComboCodec, SIGNAL( activated( const QString& ) ), |
144 | this, SLOT( codecChanged( const QString& ) ) ); | 144 | this, SLOT( codecChanged( const QString& ) ) ); |
145 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), | 145 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), |
146 | this, SLOT( textquoteSelected( const QString& ) ) ); | 146 | this, SLOT( textquoteSelected( const QString& ) ) ); |
147 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), | 147 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), |
148 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); | 148 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); |
149 | 149 | ||
150 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), | 150 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), |
151 | this, SLOT( setFile( const QString& ) ) ); | 151 | this, SLOT( setFile( const QString& ) ) ); |
152 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), | 152 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), |
153 | this, SLOT( setFile( const QString& ) ) ); | 153 | this, SLOT( setFile( const QString& ) ) ); |
154 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), | 154 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), |
155 | this, SLOT( urlChanged( const QString& ) ) ); | 155 | this, SLOT( urlChanged( const QString& ) ) ); |
156 | 156 | ||
157 | connect( this, SIGNAL( user1Clicked() ), | 157 | connect( this, SIGNAL( user1Clicked() ), |
158 | this, SLOT( applyTemplate() ) ); | 158 | this, SLOT( applyTemplate() ) ); |
159 | 159 | ||
160 | connect( this, SIGNAL( user2Clicked() ), | 160 | connect( this, SIGNAL( user2Clicked() ), |
161 | this, SLOT( saveTemplate() ) ); | 161 | this, SLOT( saveTemplate() ) ); |
162 | 162 | ||
163 | // if ( QApplication::desktop()->width() < 321 ) | 163 | // if ( QApplication::desktop()->width() < 321 ) |
164 | QIconSet icon = SmallIcon("filesave"); | 164 | QIconSet icon = SmallIcon("filesave"); |
165 | 165 | ||
166 | findButton( User2 )->setIconSet (icon ) ; | 166 | findButton( User2 )->setIconSet (icon ) ; |
167 | icon = SmallIcon("fileopen"); | 167 | icon = SmallIcon("fileopen"); |
168 | findButton( User1 )->setIconSet (icon ) ; | 168 | findButton( User1 )->setIconSet (icon ) ; |
169 | int wid = findButton( User2 )->sizeHint().height(); | 169 | int wid = findButton( User2 )->sizeHint().height(); |
170 | findButton( User2 )->setMaximumWidth( wid+4 ); | 170 | findButton( User2 )->setMaximumWidth( wid+4 ); |
171 | findButton( User1 )->setMaximumWidth( wid+4 ); | 171 | findButton( User1 )->setMaximumWidth( wid+4 ); |
172 | } | 172 | } |
173 | 173 | ||
174 | CSVImportDialog::~CSVImportDialog() | 174 | CSVImportDialog::~CSVImportDialog() |
175 | { | 175 | { |
176 | } | 176 | } |
177 | 177 | ||
178 | KABC::AddresseeList CSVImportDialog::contacts() const | 178 | KABC::AddresseeList CSVImportDialog::contacts() const |
179 | { | 179 | { |
180 | KABC::AddresseeList contacts; | 180 | KABC::AddresseeList contacts; |
181 | 181 | ||
182 | for ( int row = 1; row < mTable->numRows(); ++row ) { | 182 | for ( int row = 1; row < mTable->numRows(); ++row ) { |
183 | KABC::Addressee a; | 183 | KABC::Addressee a; |
184 | bool emptyRow = true; | 184 | bool emptyRow = true; |
185 | KABC::Address addrHome( KABC::Address::Home ); | 185 | KABC::Address addrHome( KABC::Address::Home ); |
186 | KABC::Address addrWork( KABC::Address::Work ); | 186 | KABC::Address addrWork( KABC::Address::Work ); |
187 | for ( int col = 0; col < mTable->numCols(); ++col ) { | 187 | for ( int col = 0; col < mTable->numCols(); ++col ) { |
188 | 188 | ||
189 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) ); | 189 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) ); |
190 | 190 | ||
191 | if ( !item ) { | 191 | if ( !item ) { |
192 | qDebug( "ERROR: item cast failed" ); | 192 | qDebug( "ERROR: item cast failed" ); |
193 | continue; | 193 | continue; |
194 | } | 194 | } |
195 | 195 | ||
196 | QString value = mTable->text( row, col ); | 196 | QString value = mTable->text( row, col ); |
197 | if ( !value.isEmpty() ) | 197 | if ( !value.isEmpty() ) |
198 | emptyRow = false; | 198 | emptyRow = false; |
199 | 199 | ||
200 | switch ( posToType( item->currentItem() ) ) | 200 | switch ( posToType( item->currentItem() ) ) |
201 | { | 201 | { |
202 | case Undefined: | 202 | case Undefined: |
203 | continue; | 203 | continue; |
204 | break; | 204 | break; |
205 | case FormattedName: | 205 | case FormattedName: |
206 | a.setFormattedName( value ); | 206 | a.setFormattedName( value ); |
207 | break; | 207 | break; |
208 | case GivenName: | 208 | case GivenName: |
209 | a.setGivenName( value ); | 209 | a.setGivenName( value ); |
210 | break; | 210 | break; |
211 | case FamilyName: | 211 | case FamilyName: |
212 | a.setFamilyName( value ); | 212 | a.setFamilyName( value ); |
213 | break; | 213 | break; |
214 | case AdditionalName: | 214 | case AdditionalName: |
215 | a.setAdditionalName( value ); | 215 | a.setAdditionalName( value ); |
216 | break; | 216 | break; |
217 | case Prefix: | 217 | case Prefix: |
218 | a.setPrefix( value ); | 218 | a.setPrefix( value ); |
219 | break; | 219 | break; |
220 | case Suffix: | 220 | case Suffix: |
221 | a.setSuffix( value ); | 221 | a.setSuffix( value ); |
222 | break; | 222 | break; |
223 | case NickName: | 223 | case NickName: |
224 | a.setNickName( value ); | 224 | a.setNickName( value ); |
225 | break; | 225 | break; |
226 | case Birthday: | 226 | case Birthday: |
227 | //US | 227 | //US |
228 | //the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); | 228 | //the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); |
229 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? | 229 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? |
230 | { | 230 | { |
231 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate | 231 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate |
232 | a.setBirthday(dt); | 232 | a.setBirthday(dt); |
233 | } | 233 | } |
234 | break; | 234 | break; |
235 | case Email: | 235 | case Email: |
236 | if ( !value.isEmpty() ) | 236 | if ( !value.isEmpty() ) |
237 | a.insertEmail( value, true ); | 237 | a.insertEmail( value, true ); |
238 | break; | 238 | break; |
239 | case Role: | 239 | case Role: |
240 | a.setRole( value ); | 240 | a.setRole( value ); |
241 | break; | 241 | break; |
242 | case Title: | 242 | case Title: |
243 | a.setTitle( value ); | 243 | a.setTitle( value ); |
244 | break; | 244 | break; |
245 | case Mailer: | 245 | case Mailer: |
246 | a.setMailer( value ); | 246 | a.setMailer( value ); |
247 | break; | 247 | break; |
248 | case URL: | 248 | case URL: |
249 | a.setUrl( value ); | 249 | a.setUrl( value ); |
250 | break; | 250 | break; |
251 | case Organization: | 251 | case Organization: |
252 | a.setOrganization( value ); | 252 | a.setOrganization( value ); |
253 | break; | 253 | break; |
254 | case Note: | 254 | case Note: |
255 | if ( a.note().isEmpty() ) | 255 | if ( a.note().isEmpty() ) |
256 | a.setNote( value ); | 256 | a.setNote( value ); |
257 | else { | 257 | else { |
258 | a.setNote( a.note()+"\n"+value ); | 258 | a.setNote( a.note()+"\n"+value ); |
259 | } | 259 | } |
260 | break; | 260 | break; |
261 | case Categories: | 261 | case Categories: |
262 | a.insertCategory( value ); | 262 | a.insertCategory( value ); |
263 | break; | 263 | break; |
264 | case HomePhone: | 264 | case HomePhone: |
265 | if ( !value.isEmpty() ) { | 265 | if ( !value.isEmpty() ) { |
266 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home ); | 266 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home ); |
267 | a.insertPhoneNumber( number ); | 267 | a.insertPhoneNumber( number ); |
268 | } | 268 | } |
269 | break; | 269 | break; |
270 | case BusinessPhone: | 270 | case BusinessPhone: |
271 | if ( !value.isEmpty() ) { | 271 | if ( !value.isEmpty() ) { |
272 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work ); | 272 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work ); |
273 | a.insertPhoneNumber( number ); | 273 | a.insertPhoneNumber( number ); |
274 | } | 274 | } |
275 | break; | 275 | break; |
276 | case MobilePhone: | 276 | case MobilePhone: |
277 | if ( !value.isEmpty() ) { | 277 | if ( !value.isEmpty() ) { |
278 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell ); | 278 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell ); |
279 | a.insertPhoneNumber( number ); | 279 | a.insertPhoneNumber( number ); |
280 | } | 280 | } |
281 | break; | 281 | break; |
282 | case HomeFax: | 282 | case HomeFax: |
283 | if ( !value.isEmpty() ) { | 283 | if ( !value.isEmpty() ) { |
284 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home | | 284 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home | |
285 | KABC::PhoneNumber::Fax ); | 285 | KABC::PhoneNumber::Fax ); |
286 | a.insertPhoneNumber( number ); | 286 | a.insertPhoneNumber( number ); |
287 | } | 287 | } |
288 | break; | 288 | break; |
289 | case BusinessFax: | 289 | case BusinessFax: |
290 | if ( !value.isEmpty() ) { | 290 | if ( !value.isEmpty() ) { |
291 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work | | 291 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work | |
292 | KABC::PhoneNumber::Fax ); | 292 | KABC::PhoneNumber::Fax ); |
293 | a.insertPhoneNumber( number ); | 293 | a.insertPhoneNumber( number ); |
294 | } | 294 | } |
295 | break; | 295 | break; |
296 | case CarPhone: | 296 | case MobileWorkPhone: |
297 | if ( !value.isEmpty() ) { | 297 | if ( !value.isEmpty() ) { |
298 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Car ); | 298 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Car ); |
299 | a.insertPhoneNumber( number ); | 299 | a.insertPhoneNumber( number ); |
300 | } | 300 | } |
301 | break; | 301 | break; |
302 | case Isdn: | 302 | case Isdn: |
303 | if ( !value.isEmpty() ) { | 303 | if ( !value.isEmpty() ) { |
304 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Isdn ); | 304 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Isdn ); |
305 | a.insertPhoneNumber( number ); | 305 | a.insertPhoneNumber( number ); |
306 | } | 306 | } |
307 | break; | 307 | break; |
308 | case Pager: | 308 | case Pager: |
309 | if ( !value.isEmpty() ) { | 309 | if ( !value.isEmpty() ) { |
310 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Pager ); | 310 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Pager ); |
311 | a.insertPhoneNumber( number ); | 311 | a.insertPhoneNumber( number ); |
312 | } | 312 | } |
313 | break; | 313 | break; |
314 | 314 | ||
315 | case HomeAddressStreet: | 315 | case HomeAddressStreet: |
316 | addrHome.setStreet( value ); | 316 | addrHome.setStreet( value ); |
317 | break; | 317 | break; |
318 | case HomeAddressLocality: | 318 | case HomeAddressLocality: |
319 | addrHome.setLocality( value ); | 319 | addrHome.setLocality( value ); |
320 | break; | 320 | break; |
321 | case HomeAddressRegion: | 321 | case HomeAddressRegion: |
322 | addrHome.setRegion( value ); | 322 | addrHome.setRegion( value ); |
323 | break; | 323 | break; |
324 | case HomeAddressPostalCode: | 324 | case HomeAddressPostalCode: |
325 | addrHome.setPostalCode( value ); | 325 | addrHome.setPostalCode( value ); |
326 | break; | 326 | break; |
327 | case HomeAddressCountry: | 327 | case HomeAddressCountry: |
328 | addrHome.setCountry( value ); | 328 | addrHome.setCountry( value ); |
329 | break; | 329 | break; |
330 | case HomeAddressLabel: | 330 | case HomeAddressLabel: |
331 | addrHome.setLabel( value ); | 331 | addrHome.setLabel( value ); |
332 | break; | 332 | break; |
333 | 333 | ||
334 | case BusinessAddressStreet: | 334 | case BusinessAddressStreet: |
335 | addrWork.setStreet( value ); | 335 | addrWork.setStreet( value ); |
336 | break; | 336 | break; |
337 | case BusinessAddressLocality: | 337 | case BusinessAddressLocality: |
338 | addrWork.setLocality( value ); | 338 | addrWork.setLocality( value ); |
339 | break; | 339 | break; |
340 | case BusinessAddressRegion: | 340 | case BusinessAddressRegion: |
341 | addrWork.setRegion( value ); | 341 | addrWork.setRegion( value ); |
342 | break; | 342 | break; |
343 | case BusinessAddressPostalCode: | 343 | case BusinessAddressPostalCode: |
344 | addrWork.setPostalCode( value ); | 344 | addrWork.setPostalCode( value ); |
345 | break; | 345 | break; |
346 | case BusinessAddressCountry: | 346 | case BusinessAddressCountry: |
347 | addrWork.setCountry( value ); | 347 | addrWork.setCountry( value ); |
348 | break; | 348 | break; |
349 | case BusinessAddressLabel: | 349 | case BusinessAddressLabel: |
350 | addrWork.setLabel( value ); | 350 | addrWork.setLabel( value ); |
351 | break; | 351 | break; |
352 | default: | 352 | default: |
353 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); | 353 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); |
354 | KABC::Field::List::Iterator it; | 354 | KABC::Field::List::Iterator it; |
355 | 355 | ||
356 | int counter = 0; | 356 | int counter = 0; |
357 | for ( it = fields.begin(); it != fields.end(); ++it ) { | 357 | for ( it = fields.begin(); it != fields.end(); ++it ) { |
358 | if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) ) | 358 | if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) ) |
359 | { | 359 | { |
360 | (*it)->setValue( a, value ); | 360 | (*it)->setValue( a, value ); |
361 | break; | 361 | break; |
362 | } | 362 | } |
363 | ++counter; | 363 | ++counter; |
364 | } | 364 | } |
365 | break; | 365 | break; |
366 | } | 366 | } |
367 | } | 367 | } |
368 | 368 | ||
369 | if ( !addrHome.isEmpty() ) | 369 | if ( !addrHome.isEmpty() ) |
370 | a.insertAddress( addrHome ); | 370 | a.insertAddress( addrHome ); |
371 | if ( !addrWork.isEmpty() ) | 371 | if ( !addrWork.isEmpty() ) |
372 | a.insertAddress( addrWork ); | 372 | a.insertAddress( addrWork ); |
373 | 373 | ||
374 | if ( !emptyRow && !a.isEmpty() ) | 374 | if ( !emptyRow && !a.isEmpty() ) |
375 | contacts.append( a ); | 375 | contacts.append( a ); |
376 | } | 376 | } |
377 | 377 | ||
378 | return contacts; | 378 | return contacts; |
379 | } | 379 | } |
380 | 380 | ||
381 | void CSVImportDialog::initGUI() | 381 | void CSVImportDialog::initGUI() |
382 | { | 382 | { |
383 | QWidget* page = plainPage(); | 383 | QWidget* page = plainPage(); |
384 | 384 | ||
385 | QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(), | 385 | QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(), |
386 | spacingHintSmall() ); | 386 | spacingHintSmall() ); |
387 | QHBoxLayout *hbox = new QHBoxLayout(); | 387 | QHBoxLayout *hbox = new QHBoxLayout(); |
388 | hbox->setSpacing( spacingHint() ); | 388 | hbox->setSpacing( spacingHint() ); |
389 | 389 | ||
390 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); | 390 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); |
391 | hbox->addWidget( label ); | 391 | hbox->addWidget( label ); |
392 | 392 | ||
393 | mUrlRequester = new KURLRequester( page ); | 393 | mUrlRequester = new KURLRequester( page ); |
394 | mUrlRequester->setFilter( "*.csv" ); | 394 | mUrlRequester->setFilter( "*.csv" ); |
395 | hbox->addWidget( mUrlRequester ); | 395 | hbox->addWidget( mUrlRequester ); |
396 | 396 | ||
397 | layout->addMultiCellLayout( hbox, 0, 0, 0, 2 ); | 397 | layout->addMultiCellLayout( hbox, 0, 0, 0, 2 ); |
398 | 398 | ||
399 | // Delimiter: comma, semicolon, tab, space, other | 399 | // Delimiter: comma, semicolon, tab, space, other |
400 | mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page ); | 400 | mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page ); |
401 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); | 401 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); |
402 | mDelimiterBox->layout()->setSpacing( spacingHint() ); | 402 | mDelimiterBox->layout()->setSpacing( spacingHint() ); |
403 | mDelimiterBox->layout()->setMargin( marginHint() ); | 403 | mDelimiterBox->layout()->setMargin( marginHint() ); |
404 | QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() ); | 404 | QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() ); |
405 | delimiterLayout->setAlignment( Qt::AlignTop ); | 405 | delimiterLayout->setAlignment( Qt::AlignTop ); |
406 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 2 ); | 406 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 2 ); |
407 | 407 | ||
408 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); | 408 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); |
409 | mRadioComma->setChecked( true ); | 409 | mRadioComma->setChecked( true ); |
410 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); | 410 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); |
411 | 411 | ||
412 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); | 412 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); |
413 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); | 413 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); |
414 | 414 | ||
415 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); | 415 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); |
416 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); | 416 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); |
417 | 417 | ||
418 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); | 418 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); |
419 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); | 419 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); |
420 | 420 | ||
421 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); | 421 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); |
422 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); | 422 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); |
423 | 423 | ||
424 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); | 424 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); |
425 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); | 425 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); |
426 | 426 | ||
427 | mComboLine = new QComboBox( false, page ); | 427 | mComboLine = new QComboBox( false, page ); |
428 | mComboLine->insertItem( i18n( "1" ) ); | 428 | mComboLine->insertItem( i18n( "1" ) ); |
429 | layout->addWidget( mComboLine, 3, 1 ); | 429 | layout->addWidget( mComboLine, 3, 1 ); |
430 | 430 | ||
431 | mComboQuote = new QComboBox( false, page ); | 431 | mComboQuote = new QComboBox( false, page ); |
432 | mComboQuote->insertItem( i18n( "\"" ), 0 ); | 432 | mComboQuote->insertItem( i18n( "\"" ), 0 ); |
433 | mComboQuote->insertItem( i18n( "'" ), 1 ); | 433 | mComboQuote->insertItem( i18n( "'" ), 1 ); |
434 | mComboQuote->insertItem( i18n( "None" ), 2 ); | 434 | mComboQuote->insertItem( i18n( "None" ), 2 ); |
435 | layout->addWidget( mComboQuote, 3, 0 ); | 435 | layout->addWidget( mComboQuote, 3, 0 ); |
436 | mComboCodec = new QComboBox( false, page ); | 436 | mComboCodec = new QComboBox( false, page ); |
437 | mComboCodec->insertItem( i18n( "UTF8" ), 0 ); | 437 | mComboCodec->insertItem( i18n( "UTF8" ), 0 ); |
438 | mComboCodec->insertItem( i18n( "LATIN1" ), 1 ); | 438 | mComboCodec->insertItem( i18n( "LATIN1" ), 1 ); |
439 | mComboCodec->insertItem( i18n( "LOCALE" ), 2 ); | 439 | mComboCodec->insertItem( i18n( "LOCALE" ), 2 ); |
440 | layout->addWidget( mComboCodec, 3, 2 ); | 440 | layout->addWidget( mComboCodec, 3, 2 ); |
441 | label = new QLabel( i18n( "Start at line:" ), page ); | 441 | label = new QLabel( i18n( "Start at line:" ), page ); |
442 | layout->addWidget( label, 2, 1 ); | 442 | layout->addWidget( label, 2, 1 ); |
443 | 443 | ||
444 | label = new QLabel( i18n( "Textquote:" ), page ); | 444 | label = new QLabel( i18n( "Textquote:" ), page ); |
445 | layout->addWidget( label, 2, 0 ); | 445 | layout->addWidget( label, 2, 0 ); |
446 | label = new QLabel( i18n( "Codec:" ), page ); | 446 | label = new QLabel( i18n( "Codec:" ), page ); |
447 | layout->addWidget( label, 2, 2 ); | 447 | layout->addWidget( label, 2, 2 ); |
448 | 448 | ||
449 | mIgnoreDuplicates = new QCheckBox( page ); | 449 | mIgnoreDuplicates = new QCheckBox( page ); |
450 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); | 450 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); |
451 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 2 ); | 451 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 2 ); |
452 | 452 | ||
453 | mTable = new QTable( 0, 0, page ); | 453 | mTable = new QTable( 0, 0, page ); |
454 | mTable->setSelectionMode( QTable::NoSelection ); | 454 | mTable->setSelectionMode( QTable::NoSelection ); |
455 | //mTable->horizontalHeader()->hide(); | 455 | //mTable->horizontalHeader()->hide(); |
456 | layout->addMultiCellWidget( mTable, 5, 5, 0, 2 ); | 456 | layout->addMultiCellWidget( mTable, 5, 5, 0, 2 ); |
457 | /*US | 457 | /*US |
458 | setButtonText( User1, i18n( "Apply Template" ) ); | 458 | setButtonText( User1, i18n( "Apply Template" ) ); |
459 | setButtonText( User2, i18n( "Save Template" ) ); | 459 | setButtonText( User2, i18n( "Save Template" ) ); |
460 | */ | 460 | */ |
461 | 461 | ||
462 | enableButtonOK( false ); | 462 | enableButtonOK( false ); |
463 | 463 | ||
464 | findButton( User1 )->setEnabled( false ); | 464 | findButton( User1 )->setEnabled( false ); |
465 | findButton( User2 )->setEnabled( false ); | 465 | findButton( User2 )->setEnabled( false ); |
466 | 466 | ||
467 | #ifdef DESKTOP_VERSION | 467 | #ifdef DESKTOP_VERSION |
468 | resize( 640, 480 ); | 468 | resize( 640, 480 ); |
469 | #else | 469 | #else |
470 | showMaximized(); | 470 | showMaximized(); |
471 | #endif | 471 | #endif |
472 | } | 472 | } |
473 | 473 | ||
474 | void CSVImportDialog::fillTable() | 474 | void CSVImportDialog::fillTable() |
475 | { | 475 | { |
476 | int row, column; | 476 | int row, column; |
477 | bool lastCharDelimiter = false; | 477 | bool lastCharDelimiter = false; |
478 | bool ignoreDups = mIgnoreDuplicates->isChecked(); | 478 | bool ignoreDups = mIgnoreDuplicates->isChecked(); |
479 | enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, | 479 | enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, |
480 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; | 480 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; |
481 | 481 | ||
482 | QChar x; | 482 | QChar x; |
483 | QString field = ""; | 483 | QString field = ""; |
484 | 484 | ||
485 | // store previous assignment | 485 | // store previous assignment |
486 | QValueList<int> mTypeOld = mTypeStore; | 486 | QValueList<int> mTypeOld = mTypeStore; |
487 | 487 | ||
488 | mTypeStore.clear(); | 488 | mTypeStore.clear(); |
489 | for ( column = 0; column < mTable->numCols(); ++column ) { | 489 | for ( column = 0; column < mTable->numCols(); ++column ) { |
490 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) ); | 490 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) ); |
491 | 491 | ||
492 | if ( !item || mClearTypeStore ) | 492 | if ( !item || mClearTypeStore ) |
493 | mTypeStore.append( typeToPos( Undefined ) ); | 493 | mTypeStore.append( typeToPos( Undefined ) ); |
494 | else if ( item ) | 494 | else if ( item ) |
495 | mTypeStore.append( item->currentItem() ); | 495 | mTypeStore.append( item->currentItem() ); |
496 | } | 496 | } |
497 | 497 | ||
498 | clearTable(); | 498 | clearTable(); |
499 | 499 | ||
500 | row = column = 1; | 500 | row = column = 1; |
501 | if ( mComboCodec->currentItem () == 0 ) { | 501 | if ( mComboCodec->currentItem () == 0 ) { |
502 | mData = QString::fromUtf8( mFileArray.data() ); | 502 | mData = QString::fromUtf8( mFileArray.data() ); |
503 | } else if ( mComboCodec->currentItem () == 1 ) { | 503 | } else if ( mComboCodec->currentItem () == 1 ) { |
504 | mData = QString::fromLatin1( mFileArray.data() ); | 504 | mData = QString::fromLatin1( mFileArray.data() ); |
505 | } else { | 505 | } else { |
506 | mData = QString::fromLocal8Bit( mFileArray.data() ); | 506 | mData = QString::fromLocal8Bit( mFileArray.data() ); |
507 | } | 507 | } |
508 | 508 | ||
509 | QTextStream inputStream( mData, IO_ReadOnly ); | 509 | QTextStream inputStream( mData, IO_ReadOnly ); |
510 | 510 | ||
511 | if ( mComboCodec->currentItem () == 0 ) { | 511 | if ( mComboCodec->currentItem () == 0 ) { |
512 | inputStream.setEncoding( QTextStream::UnicodeUTF8 ); | 512 | inputStream.setEncoding( QTextStream::UnicodeUTF8 ); |
513 | } else if ( mComboCodec->currentItem () == 1 ) { | 513 | } else if ( mComboCodec->currentItem () == 1 ) { |
514 | inputStream.setEncoding( QTextStream::Latin1 ); | 514 | inputStream.setEncoding( QTextStream::Latin1 ); |
515 | } else { | 515 | } else { |
516 | inputStream.setEncoding( QTextStream::Locale ); | 516 | inputStream.setEncoding( QTextStream::Locale ); |
517 | } | 517 | } |
518 | 518 | ||
519 | int maxColumn = 0; | 519 | int maxColumn = 0; |
520 | while ( !inputStream.atEnd() ) { | 520 | while ( !inputStream.atEnd() ) { |
521 | inputStream >> x; // read one char | 521 | inputStream >> x; // read one char |
522 | 522 | ||
523 | if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly | 523 | if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly |
524 | 524 | ||
525 | switch ( state ) { | 525 | switch ( state ) { |
526 | case S_START : | 526 | case S_START : |
527 | if ( x == mTextQuote ) { | 527 | if ( x == mTextQuote ) { |
528 | state = S_QUOTED_FIELD; | 528 | state = S_QUOTED_FIELD; |
529 | } else if ( x == mDelimiter ) { | 529 | } else if ( x == mDelimiter ) { |
530 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 530 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
531 | ++column; | 531 | ++column; |
532 | lastCharDelimiter = true; | 532 | lastCharDelimiter = true; |
533 | } else if ( x == '\n' ) { | 533 | } else if ( x == '\n' ) { |
534 | ++row; | 534 | ++row; |
535 | column = 1; | 535 | column = 1; |
536 | } else { | 536 | } else { |
537 | field += x; | 537 | field += x; |
538 | state = S_MAYBE_NORMAL_FIELD; | 538 | state = S_MAYBE_NORMAL_FIELD; |
539 | } | 539 | } |
540 | break; | 540 | break; |
541 | case S_QUOTED_FIELD : | 541 | case S_QUOTED_FIELD : |
542 | if ( x == mTextQuote ) { | 542 | if ( x == mTextQuote ) { |
543 | state = S_MAYBE_END_OF_QUOTED_FIELD; | 543 | state = S_MAYBE_END_OF_QUOTED_FIELD; |
544 | } else if ( x == '\n' && mTextQuote.isNull() ) { | 544 | } else if ( x == '\n' && mTextQuote.isNull() ) { |
545 | setText( row - mStartLine + 1, column, field ); | 545 | setText( row - mStartLine + 1, column, field ); |
546 | field = ""; | 546 | field = ""; |
547 | if ( x == '\n' ) { | 547 | if ( x == '\n' ) { |
548 | ++row; | 548 | ++row; |
549 | column = 1; | 549 | column = 1; |
550 | } else { | 550 | } else { |
551 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 551 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
552 | ++column; | 552 | ++column; |
553 | lastCharDelimiter = true; | 553 | lastCharDelimiter = true; |
554 | } | 554 | } |
555 | state = S_START; | 555 | state = S_START; |
556 | } else { | 556 | } else { |
557 | field += x; | 557 | field += x; |
558 | } | 558 | } |
559 | break; | 559 | break; |
560 | case S_MAYBE_END_OF_QUOTED_FIELD : | 560 | case S_MAYBE_END_OF_QUOTED_FIELD : |
561 | if ( x == mTextQuote ) { | 561 | if ( x == mTextQuote ) { |
562 | field += x; | 562 | field += x; |
563 | state = S_QUOTED_FIELD; | 563 | state = S_QUOTED_FIELD; |
564 | } else if ( x == mDelimiter || x == '\n' ) { | 564 | } else if ( x == mDelimiter || x == '\n' ) { |
565 | setText( row - mStartLine + 1, column, field ); | 565 | setText( row - mStartLine + 1, column, field ); |
566 | field = ""; | 566 | field = ""; |
567 | if ( x == '\n' ) { | 567 | if ( x == '\n' ) { |
568 | ++row; | 568 | ++row; |
569 | column = 1; | 569 | column = 1; |
570 | } else { | 570 | } else { |
571 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 571 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
572 | ++column; | 572 | ++column; |
573 | lastCharDelimiter = true; | 573 | lastCharDelimiter = true; |
574 | } | 574 | } |
575 | state = S_START; | 575 | state = S_START; |
576 | } else { | 576 | } else { |
577 | state = S_END_OF_QUOTED_FIELD; | 577 | state = S_END_OF_QUOTED_FIELD; |
578 | } | 578 | } |
579 | break; | 579 | break; |
580 | case S_END_OF_QUOTED_FIELD : | 580 | case S_END_OF_QUOTED_FIELD : |
581 | if ( x == mDelimiter || x == '\n' ) { | 581 | if ( x == mDelimiter || x == '\n' ) { |
582 | setText( row - mStartLine + 1, column, field ); | 582 | setText( row - mStartLine + 1, column, field ); |
583 | field = ""; | 583 | field = ""; |
584 | if ( x == '\n' ) { | 584 | if ( x == '\n' ) { |
585 | ++row; | 585 | ++row; |
586 | column = 1; | 586 | column = 1; |
587 | } else { | 587 | } else { |
588 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 588 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
589 | ++column; | 589 | ++column; |
590 | lastCharDelimiter = true; | 590 | lastCharDelimiter = true; |
591 | } | 591 | } |
592 | state = S_START; | 592 | state = S_START; |
593 | } else { | 593 | } else { |
594 | state = S_END_OF_QUOTED_FIELD; | 594 | state = S_END_OF_QUOTED_FIELD; |
595 | } | 595 | } |
596 | break; | 596 | break; |
597 | case S_MAYBE_NORMAL_FIELD : | 597 | case S_MAYBE_NORMAL_FIELD : |
598 | if ( x == mTextQuote ) { | 598 | if ( x == mTextQuote ) { |
599 | field = ""; | 599 | field = ""; |
600 | state = S_QUOTED_FIELD; | 600 | state = S_QUOTED_FIELD; |
601 | break; | 601 | break; |
602 | } | 602 | } |
603 | case S_NORMAL_FIELD : | 603 | case S_NORMAL_FIELD : |
604 | if ( x == mDelimiter || x == '\n' ) { | 604 | if ( x == mDelimiter || x == '\n' ) { |
605 | setText( row - mStartLine + 1, column, field ); | 605 | setText( row - mStartLine + 1, column, field ); |
606 | field = ""; | 606 | field = ""; |
607 | if ( x == '\n' ) { | 607 | if ( x == '\n' ) { |
608 | ++row; | 608 | ++row; |
609 | column = 1; | 609 | column = 1; |
610 | } else { | 610 | } else { |
611 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 611 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
612 | ++column; | 612 | ++column; |
613 | lastCharDelimiter = true; | 613 | lastCharDelimiter = true; |
614 | } | 614 | } |
615 | state = S_START; | 615 | state = S_START; |
616 | } else { | 616 | } else { |
617 | field += x; | 617 | field += x; |
618 | } | 618 | } |
619 | } | 619 | } |
620 | if ( x != mDelimiter ) | 620 | if ( x != mDelimiter ) |
621 | lastCharDelimiter = false; | 621 | lastCharDelimiter = false; |
622 | 622 | ||
623 | if ( column > maxColumn ) | 623 | if ( column > maxColumn ) |
624 | maxColumn = column; | 624 | maxColumn = column; |
625 | } | 625 | } |
626 | 626 | ||
627 | // file with only one line without '\n' | 627 | // file with only one line without '\n' |
628 | if ( field.length() > 0 ) { | 628 | if ( field.length() > 0 ) { |
629 | setText( row - mStartLine + 1, column, field ); | 629 | setText( row - mStartLine + 1, column, field ); |
630 | ++row; | 630 | ++row; |
631 | field = ""; | 631 | field = ""; |
632 | } | 632 | } |
633 | 633 | ||
634 | adjustRows( row - mStartLine ); | 634 | adjustRows( row - mStartLine ); |
635 | mTable->setNumCols( maxColumn ); | 635 | mTable->setNumCols( maxColumn ); |
636 | 636 | ||
637 | //US begin | 637 | //US begin |
638 | QStringList keys; | 638 | QStringList keys; |
639 | uint iii = 0, count = mTypeMap.count(); | 639 | uint iii = 0, count = mTypeMap.count(); |
640 | while ( iii < count ) { | 640 | while ( iii < count ) { |
641 | keys << "dummy"; | 641 | keys << "dummy"; |
642 | ++iii; | 642 | ++iii; |
643 | } | 643 | } |
644 | QMap<QString, uint>::ConstIterator it; | 644 | QMap<QString, uint>::ConstIterator it; |
645 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) | 645 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) |
646 | keys[( it.data() )] = it.key(); | 646 | keys[( it.data() )] = it.key(); |
647 | //US end | 647 | //US end |
648 | 648 | ||
649 | for ( column = 0; column < mTable->numCols(); ++column ) { | 649 | for ( column = 0; column < mTable->numCols(); ++column ) { |
650 | 650 | ||
651 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); | 651 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); |
652 | QComboTableItem *item = new QComboTableItem( mTable, keys ); | 652 | QComboTableItem *item = new QComboTableItem( mTable, keys ); |
653 | mTable->setItem( 0, column, item ); | 653 | mTable->setItem( 0, column, item ); |
654 | if ( column < mTypeStore.count() ) | 654 | if ( column < mTypeStore.count() ) |
655 | item->setCurrentItem( mTypeStore[ column ] ); | 655 | item->setCurrentItem( mTypeStore[ column ] ); |
656 | else | 656 | else |
657 | item->setCurrentItem( typeToPos( Undefined ) ); | 657 | item->setCurrentItem( typeToPos( Undefined ) ); |
658 | 658 | ||
659 | mTable->adjustColumn( column ); | 659 | mTable->adjustColumn( column ); |
660 | } | 660 | } |
661 | } | 661 | } |
662 | 662 | ||
663 | void CSVImportDialog::clearTable() | 663 | void CSVImportDialog::clearTable() |
664 | { | 664 | { |
665 | for ( int row = 0; row < mTable->numRows(); ++row ) | 665 | for ( int row = 0; row < mTable->numRows(); ++row ) |
666 | for ( int column = 0; column < mTable->numCols(); ++column ) | 666 | for ( int column = 0; column < mTable->numCols(); ++column ) |
667 | mTable->clearCell( row, column ); | 667 | mTable->clearCell( row, column ); |
668 | } | 668 | } |
669 | 669 | ||
670 | void CSVImportDialog::fillComboBox() | 670 | void CSVImportDialog::fillComboBox() |
671 | { | 671 | { |
672 | mComboLine->clear(); | 672 | mComboLine->clear(); |
673 | for ( int row = 1; row < mTable->numRows() + 1; ++row ) | 673 | for ( int row = 1; row < mTable->numRows() + 1; ++row ) |
674 | mComboLine->insertItem( QString::number( row ), row - 1 ); | 674 | mComboLine->insertItem( QString::number( row ), row - 1 ); |
675 | } | 675 | } |
676 | 676 | ||
677 | void CSVImportDialog::setText( int row, int col, const QString& text ) | 677 | void CSVImportDialog::setText( int row, int col, const QString& text ) |
678 | { | 678 | { |
679 | if ( row < 1 ) // skipped by the user | 679 | if ( row < 1 ) // skipped by the user |
680 | return; | 680 | return; |
681 | 681 | ||
682 | if ( mTable->numRows() < row ) { | 682 | if ( mTable->numRows() < row ) { |
683 | mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations | 683 | mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations |
684 | mAdjustRows = true; | 684 | mAdjustRows = true; |
685 | } | 685 | } |
686 | 686 | ||
687 | if ( mTable->numCols() < col ) | 687 | if ( mTable->numCols() < col ) |
688 | mTable->setNumCols( col + 50 ); // We add 50 at a time to limit recalculation | 688 | mTable->setNumCols( col + 50 ); // We add 50 at a time to limit recalculation |
689 | 689 | ||
690 | mTable->setText( row - 1, col - 1, text ); | 690 | mTable->setText( row - 1, col - 1, text ); |
691 | } | 691 | } |
692 | 692 | ||
693 | /* | 693 | /* |
694 | * Called after the first fillTable() when number of rows are unknown. | 694 | * Called after the first fillTable() when number of rows are unknown. |
695 | */ | 695 | */ |
696 | void CSVImportDialog::adjustRows( int rows ) | 696 | void CSVImportDialog::adjustRows( int rows ) |
697 | { | 697 | { |
698 | if ( mAdjustRows ) { | 698 | if ( mAdjustRows ) { |
699 | mTable->setNumRows( rows ); | 699 | mTable->setNumRows( rows ); |
700 | mAdjustRows = false; | 700 | mAdjustRows = false; |
701 | } | 701 | } |
702 | } | 702 | } |
703 | 703 | ||
704 | void CSVImportDialog::returnPressed() | 704 | void CSVImportDialog::returnPressed() |
705 | { | 705 | { |
706 | if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 ) | 706 | if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 ) |
707 | return; | 707 | return; |
708 | 708 | ||
709 | mDelimiter = mDelimiterEdit->text(); | 709 | mDelimiter = mDelimiterEdit->text(); |
710 | fillTable(); | 710 | fillTable(); |
711 | } | 711 | } |
712 | 712 | ||
713 | void CSVImportDialog::textChanged ( const QString& ) | 713 | void CSVImportDialog::textChanged ( const QString& ) |
714 | { | 714 | { |
715 | mRadioOther->setChecked ( true ); | 715 | mRadioOther->setChecked ( true ); |
716 | delimiterClicked( 4 ); // other | 716 | delimiterClicked( 4 ); // other |
717 | } | 717 | } |
718 | void CSVImportDialog::codecChanged ( const QString& ) | 718 | void CSVImportDialog::codecChanged ( const QString& ) |
719 | { | 719 | { |
720 | fillTable(); | 720 | fillTable(); |
721 | } | 721 | } |
722 | 722 | ||
723 | void CSVImportDialog::delimiterClicked( int id ) | 723 | void CSVImportDialog::delimiterClicked( int id ) |
724 | { | 724 | { |
725 | switch ( id ) { | 725 | switch ( id ) { |
726 | case 0: // comma | 726 | case 0: // comma |
727 | mDelimiter = ","; | 727 | mDelimiter = ","; |
728 | break; | 728 | break; |
729 | case 4: // other | 729 | case 4: // other |
730 | mDelimiter = mDelimiterEdit->text(); | 730 | mDelimiter = mDelimiterEdit->text(); |
731 | break; | 731 | break; |
732 | case 2: // tab | 732 | case 2: // tab |
733 | mDelimiter = "\t"; | 733 | mDelimiter = "\t"; |
734 | break; | 734 | break; |
735 | case 3: // space | 735 | case 3: // space |
736 | mDelimiter = " "; | 736 | mDelimiter = " "; |
737 | break; | 737 | break; |
738 | case 1: // semicolon | 738 | case 1: // semicolon |
739 | mDelimiter = ";"; | 739 | mDelimiter = ";"; |
740 | break; | 740 | break; |
741 | } | 741 | } |
742 | 742 | ||
743 | fillTable(); | 743 | fillTable(); |
744 | } | 744 | } |
745 | 745 | ||
746 | void CSVImportDialog::textquoteSelected( const QString& mark ) | 746 | void CSVImportDialog::textquoteSelected( const QString& mark ) |
747 | { | 747 | { |
748 | if ( mComboQuote->currentItem() == 2 ) | 748 | if ( mComboQuote->currentItem() == 2 ) |
749 | mTextQuote = 0; | 749 | mTextQuote = 0; |
750 | else | 750 | else |
751 | mTextQuote = mark[ 0 ]; | 751 | mTextQuote = mark[ 0 ]; |
752 | 752 | ||
753 | fillTable(); | 753 | fillTable(); |
754 | } | 754 | } |
755 | 755 | ||
756 | void CSVImportDialog::lineSelected( const QString& line ) | 756 | void CSVImportDialog::lineSelected( const QString& line ) |
757 | { | 757 | { |
758 | mStartLine = line.toInt() - 1; | 758 | mStartLine = line.toInt() - 1; |
759 | fillTable(); | 759 | fillTable(); |
760 | } | 760 | } |
761 | 761 | ||
762 | void CSVImportDialog::slotOk() | 762 | void CSVImportDialog::slotOk() |
763 | { | 763 | { |
764 | bool assigned = false; | 764 | bool assigned = false; |
765 | 765 | ||
766 | for ( int column = 0; column < mTable->numCols(); ++column ) { | 766 | for ( int column = 0; column < mTable->numCols(); ++column ) { |
767 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 767 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
768 | column ) ); | 768 | column ) ); |
769 | if ( item && posToType( item->currentItem() ) != Undefined ) | 769 | if ( item && posToType( item->currentItem() ) != Undefined ) |
770 | assigned = true; | 770 | assigned = true; |
771 | } | 771 | } |
772 | 772 | ||
773 | if ( assigned ) | 773 | if ( assigned ) |
774 | KDialogBase::slotOk(); | 774 | KDialogBase::slotOk(); |
775 | else | 775 | else |
776 | KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) ); | 776 | KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) ); |
777 | } | 777 | } |
778 | 778 | ||
779 | void CSVImportDialog::applyTemplate() | 779 | void CSVImportDialog::applyTemplate() |
780 | { | 780 | { |
781 | QMap<uint,int> columnMap; | 781 | QMap<uint,int> columnMap; |
782 | QMap<QString, QString> fileMap; | 782 | QMap<QString, QString> fileMap; |
783 | QStringList templates; | 783 | QStringList templates; |
784 | 784 | ||
785 | // load all template files | 785 | // load all template files |
786 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + | 786 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + |
787 | "/csv-templates/*.desktop", true, true ); | 787 | "/csv-templates/*.desktop", true, true ); |
788 | */ | 788 | */ |
789 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + | 789 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + |
790 | "/csv-templates/*.desktop", true, true ); | 790 | "/csv-templates/*.desktop", true, true ); |
791 | 791 | ||
792 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 792 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
793 | { | 793 | { |
794 | 794 | ||
795 | //US KSimpleConfig config( *it, true ); | 795 | //US KSimpleConfig config( *it, true ); |
796 | KConfig config( *it ); | 796 | KConfig config( *it ); |
797 | 797 | ||
798 | if ( !config.hasGroup( "csv column map" ) ) | 798 | if ( !config.hasGroup( "csv column map" ) ) |
799 | continue; | 799 | continue; |
800 | 800 | ||
801 | config.setGroup( "Misc" ); | 801 | config.setGroup( "Misc" ); |
802 | templates.append( config.readEntry( "Name" ) ); | 802 | templates.append( config.readEntry( "Name" ) ); |
803 | fileMap.insert( config.readEntry( "Name" ), *it ); | 803 | fileMap.insert( config.readEntry( "Name" ), *it ); |
804 | } | 804 | } |
805 | 805 | ||
806 | // let the user chose, what to take | 806 | // let the user chose, what to take |
807 | bool ok = false; | 807 | bool ok = false; |
808 | QString tmp; | 808 | QString tmp; |
809 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), | 809 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), |
810 | i18n( "Please select a template\nthat matches the CSV file." ), | 810 | i18n( "Please select a template\nthat matches the CSV file." ), |
811 | templates, 0, false, &ok, this ); | 811 | templates, 0, false, &ok, this ); |
812 | 812 | ||
813 | if ( !ok ) | 813 | if ( !ok ) |
814 | return; | 814 | return; |
815 | 815 | ||
816 | //US KSimpleConfig config( fileMap[ tmp ], true ); | 816 | //US KSimpleConfig config( fileMap[ tmp ], true ); |
817 | KConfig config( fileMap[ tmp ] ); | 817 | KConfig config( fileMap[ tmp ] ); |
818 | config.setGroup( "General" ); | 818 | config.setGroup( "General" ); |
819 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); | 819 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); |
820 | uint numColumns = (uint)config.readNumEntry( "Columns" ); | 820 | uint numColumns = (uint)config.readNumEntry( "Columns" ); |
821 | 821 | ||
822 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); | 822 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); |
823 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); | 823 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); |
824 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); | 824 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); |
825 | int quoteType = config.readNumEntry( "QuoteType" ); | 825 | int quoteType = config.readNumEntry( "QuoteType" ); |
826 | mComboQuote->setCurrentItem( quoteType ); | 826 | mComboQuote->setCurrentItem( quoteType ); |
827 | textquoteSelected( mComboQuote->currentText() ); | 827 | textquoteSelected( mComboQuote->currentText() ); |
828 | 828 | ||
829 | // create the column map | 829 | // create the column map |
830 | config.setGroup( "csv column map" ); | 830 | config.setGroup( "csv column map" ); |
831 | for ( uint i = 0; i < numColumns; ++i ) { | 831 | for ( uint i = 0; i < numColumns; ++i ) { |
832 | int col = config.readNumEntry( QString::number( i ) ); | 832 | int col = config.readNumEntry( QString::number( i ) ); |
833 | columnMap.insert( i, col ); | 833 | columnMap.insert( i, col ); |
834 | } | 834 | } |
835 | 835 | ||
836 | // apply the column map | 836 | // apply the column map |
837 | for ( uint column = 0; column < columnMap.count(); ++column ) { | 837 | for ( uint column = 0; column < columnMap.count(); ++column ) { |
838 | int type = columnMap[ column ]; | 838 | int type = columnMap[ column ]; |
839 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 839 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
840 | column ) ); | 840 | column ) ); |
841 | if ( item ) | 841 | if ( item ) |
842 | item->setCurrentItem( typeToPos( type ) ); | 842 | item->setCurrentItem( typeToPos( type ) ); |
843 | } | 843 | } |
844 | } | 844 | } |
845 | 845 | ||
846 | void CSVImportDialog::saveTemplate() | 846 | void CSVImportDialog::saveTemplate() |
847 | { | 847 | { |
848 | /*US | 848 | /*US |
849 | QString fileName = KFileDialog::getSaveFileName( | 849 | QString fileName = KFileDialog::getSaveFileName( |
850 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), | 850 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), |
851 | "*.desktop", this ); | 851 | "*.desktop", this ); |
852 | */ | 852 | */ |
853 | QString fileName = KFileDialog::getSaveFileName( | 853 | QString fileName = KFileDialog::getSaveFileName( |
854 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ | 854 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ |
855 | "*.desktop",i18n("Save file name") , this ); | 855 | "*.desktop",i18n("Save file name") , this ); |
856 | 856 | ||
857 | if ( fileName.isEmpty() ) | 857 | if ( fileName.isEmpty() ) |
858 | return; | 858 | return; |
859 | 859 | ||
860 | if ( !fileName.contains( ".desktop" ) ) | 860 | if ( !fileName.contains( ".desktop" ) ) |
861 | fileName += ".desktop"; | 861 | fileName += ".desktop"; |
862 | 862 | ||
863 | QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) ); | 863 | QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) ); |
864 | 864 | ||
865 | if ( name.isEmpty() ) | 865 | if ( name.isEmpty() ) |
866 | return; | 866 | return; |
867 | 867 | ||
868 | KConfig config( fileName ); | 868 | KConfig config( fileName ); |
869 | config.setGroup( "General" ); | 869 | config.setGroup( "General" ); |
870 | config.writeEntry( "Columns", mTable->numCols() ); | 870 | config.writeEntry( "Columns", mTable->numCols() ); |
871 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); | 871 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); |
872 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); | 872 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); |
873 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); | 873 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); |
874 | 874 | ||
875 | config.setGroup( "Misc" ); | 875 | config.setGroup( "Misc" ); |
876 | config.writeEntry( "Name", name ); | 876 | config.writeEntry( "Name", name ); |
877 | 877 | ||
878 | config.setGroup( "csv column map" ); | 878 | config.setGroup( "csv column map" ); |
879 | 879 | ||
880 | for ( uint column = 0; column < mTable->numCols(); ++column ) { | 880 | for ( uint column = 0; column < mTable->numCols(); ++column ) { |
881 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 881 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
882 | column ) ); | 882 | column ) ); |
883 | if ( item ) | 883 | if ( item ) |
884 | config.writeEntry( QString::number( column ), posToType( | 884 | config.writeEntry( QString::number( column ), posToType( |
885 | item->currentItem() ) ); | 885 | item->currentItem() ) ); |
886 | else | 886 | else |
887 | config.writeEntry( QString::number( column ), 0 ); | 887 | config.writeEntry( QString::number( column ), 0 ); |
888 | } | 888 | } |
889 | 889 | ||
890 | config.sync(); | 890 | config.sync(); |
891 | } | 891 | } |
892 | 892 | ||
893 | QString CSVImportDialog::getText( int row, int col ) | 893 | QString CSVImportDialog::getText( int row, int col ) |
894 | { | 894 | { |
895 | return mTable->text( row, col ); | 895 | return mTable->text( row, col ); |
896 | } | 896 | } |
897 | 897 | ||
898 | uint CSVImportDialog::posToType( int pos ) const | 898 | uint CSVImportDialog::posToType( int pos ) const |
899 | { | 899 | { |
900 | return pos; | 900 | return pos; |
901 | #if 0 | 901 | #if 0 |
902 | uint counter = 0; | 902 | uint counter = 0; |
903 | QMap<QString, uint>::ConstIterator it; | 903 | QMap<QString, uint>::ConstIterator it; |
904 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 904 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
905 | if ( counter == (uint)pos ) | 905 | if ( counter == (uint)pos ) |
906 | return it.data(); | 906 | return it.data(); |
907 | 907 | ||
908 | return 0; | 908 | return 0; |
909 | #endif | 909 | #endif |
910 | } | 910 | } |
911 | 911 | ||
912 | int CSVImportDialog::typeToPos( uint type ) const | 912 | int CSVImportDialog::typeToPos( uint type ) const |
913 | { | 913 | { |
914 | return type; | 914 | return type; |
915 | #if 0 | 915 | #if 0 |
916 | uint counter = 0; | 916 | uint counter = 0; |
917 | QMap<QString, uint>::ConstIterator it; | 917 | QMap<QString, uint>::ConstIterator it; |
918 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 918 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
919 | if ( it.data() == type ) | 919 | if ( it.data() == type ) |
920 | return counter; | 920 | return counter; |
921 | 921 | ||
922 | return -1; | 922 | return -1; |
923 | #endif | 923 | #endif |
924 | } | 924 | } |
925 | 925 | ||
926 | void CSVImportDialog::ignoreDuplicatesChanged( int ) | 926 | void CSVImportDialog::ignoreDuplicatesChanged( int ) |
927 | { | 927 | { |
928 | fillTable(); | 928 | fillTable(); |
929 | } | 929 | } |
930 | 930 | ||
931 | void CSVImportDialog::setFile( const QString &fileName ) | 931 | void CSVImportDialog::setFile( const QString &fileName ) |
932 | { | 932 | { |
933 | if ( fileName.isEmpty() ) | 933 | if ( fileName.isEmpty() ) |
934 | return; | 934 | return; |
935 | 935 | ||
936 | QFile file( fileName ); | 936 | QFile file( fileName ); |
937 | if ( !file.open( IO_ReadOnly ) ) { | 937 | if ( !file.open( IO_ReadOnly ) ) { |
938 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); | 938 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); |
939 | file.close(); | 939 | file.close(); |
940 | return; | 940 | return; |
941 | } | 941 | } |
942 | 942 | ||
943 | mFileArray = file.readAll(); | 943 | mFileArray = file.readAll(); |
944 | file.close(); | 944 | file.close(); |
945 | 945 | ||
946 | mClearTypeStore = true; | 946 | mClearTypeStore = true; |
947 | clearTable(); | 947 | clearTable(); |
948 | mTable->setNumCols( 0 ); | 948 | mTable->setNumCols( 0 ); |
949 | mTable->setNumRows( 0 ); | 949 | mTable->setNumRows( 0 ); |
950 | fillTable(); | 950 | fillTable(); |
951 | mClearTypeStore = false; | 951 | mClearTypeStore = false; |
952 | 952 | ||
953 | fillComboBox(); | 953 | fillComboBox(); |
954 | } | 954 | } |
955 | 955 | ||
956 | void CSVImportDialog::urlChanged( const QString &file ) | 956 | void CSVImportDialog::urlChanged( const QString &file ) |
957 | { | 957 | { |
958 | bool state = !file.isEmpty(); | 958 | bool state = !file.isEmpty(); |
959 | 959 | ||
960 | enableButtonOK( state ); | 960 | enableButtonOK( state ); |
961 | 961 | ||
962 | findButton( User1 )->setEnabled( state ); | 962 | findButton( User1 )->setEnabled( state ); |
963 | findButton( User2 )->setEnabled( state ); | 963 | findButton( User2 )->setEnabled( state ); |
964 | 964 | ||
965 | } | 965 | } |
966 | 966 | ||
967 | #ifndef KAB_EMBEDDED | 967 | #ifndef KAB_EMBEDDED |
968 | #include <csvimportdialog.moc> | 968 | #include <csvimportdialog.moc> |
969 | #endif //KAB_EMBEDDED | 969 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/xxport/csvimportdialog.h b/kaddressbook/xxport/csvimportdialog.h index 5f55ab2..2661420 100644 --- a/kaddressbook/xxport/csvimportdialog.h +++ b/kaddressbook/xxport/csvimportdialog.h | |||
@@ -1,126 +1,126 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (C) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (C) 2003 Tobias Koenig <tokoe@kde.org> |
4 | based on the code of KSpread's CSV Import Dialog | 4 | based on the code of KSpread's CSV Import Dialog |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 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 | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef CSV_IMPORT_DLG_H | 29 | #ifndef CSV_IMPORT_DLG_H |
30 | #define CSV_IMPORT_DLG_H | 30 | #define CSV_IMPORT_DLG_H |
31 | 31 | ||
32 | #include <kabc/addressbook.h> | 32 | #include <kabc/addressbook.h> |
33 | #include <kabc/addresseelist.h> | 33 | #include <kabc/addresseelist.h> |
34 | #include <kdialogbase.h> | 34 | #include <kdialogbase.h> |
35 | 35 | ||
36 | #include <qvaluelist.h> | 36 | #include <qvaluelist.h> |
37 | 37 | ||
38 | class KURLRequester; | 38 | class KURLRequester; |
39 | 39 | ||
40 | class QButtonGroup; | 40 | class QButtonGroup; |
41 | class QComboBox; | 41 | class QComboBox; |
42 | class QCheckBox; | 42 | class QCheckBox; |
43 | class QLineEdit; | 43 | class QLineEdit; |
44 | class QPushButton; | 44 | class QPushButton; |
45 | class QRadioButton; | 45 | class QRadioButton; |
46 | class QTable; | 46 | class QTable; |
47 | 47 | ||
48 | class CSVImportDialog : public KDialogBase | 48 | class CSVImportDialog : public KDialogBase |
49 | { | 49 | { |
50 | Q_OBJECT | 50 | Q_OBJECT |
51 | 51 | ||
52 | public: | 52 | public: |
53 | CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, | 53 | CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, |
54 | const char *name = 0 ); | 54 | const char *name = 0 ); |
55 | ~CSVImportDialog(); | 55 | ~CSVImportDialog(); |
56 | 56 | ||
57 | KABC::AddresseeList contacts() const; | 57 | KABC::AddresseeList contacts() const; |
58 | 58 | ||
59 | protected slots: | 59 | protected slots: |
60 | virtual void slotOk(); | 60 | virtual void slotOk(); |
61 | 61 | ||
62 | private slots: | 62 | private slots: |
63 | void returnPressed(); | 63 | void returnPressed(); |
64 | void delimiterClicked( int id ); | 64 | void delimiterClicked( int id ); |
65 | void lineSelected( const QString& line ); | 65 | void lineSelected( const QString& line ); |
66 | void textquoteSelected( const QString& mark ); | 66 | void textquoteSelected( const QString& mark ); |
67 | void textChanged ( const QString & ); | 67 | void textChanged ( const QString & ); |
68 | void ignoreDuplicatesChanged( int ); | 68 | void ignoreDuplicatesChanged( int ); |
69 | void setFile( const QString& ); | 69 | void setFile( const QString& ); |
70 | void urlChanged( const QString& ); | 70 | void urlChanged( const QString& ); |
71 | void codecChanged ( const QString& ); | 71 | void codecChanged ( const QString& ); |
72 | 72 | ||
73 | void applyTemplate(); | 73 | void applyTemplate(); |
74 | void saveTemplate(); | 74 | void saveTemplate(); |
75 | 75 | ||
76 | private: | 76 | private: |
77 | enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName, | 77 | enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName, |
78 | Prefix, Suffix, NickName, Birthday, | 78 | Prefix, Suffix, NickName, Birthday, |
79 | HomeAddressStreet, HomeAddressLocality, HomeAddressRegion, | 79 | HomeAddressStreet, HomeAddressLocality, HomeAddressRegion, |
80 | HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel, | 80 | HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel, |
81 | BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion, | 81 | BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion, |
82 | BusinessAddressPostalCode, BusinessAddressCountry, | 82 | BusinessAddressPostalCode, BusinessAddressCountry, |
83 | BusinessAddressLabel, | 83 | BusinessAddressLabel, |
84 | HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone, | 84 | HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, MobileWorkPhone, |
85 | Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL, Categories | 85 | Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL, Categories |
86 | }; | 86 | }; |
87 | 87 | ||
88 | QTable* mTable; | 88 | QTable* mTable; |
89 | QButtonGroup* mDelimiterBox; | 89 | QButtonGroup* mDelimiterBox; |
90 | QRadioButton* mRadioComma; | 90 | QRadioButton* mRadioComma; |
91 | QRadioButton* mRadioSemicolon; | 91 | QRadioButton* mRadioSemicolon; |
92 | QRadioButton* mRadioTab; | 92 | QRadioButton* mRadioTab; |
93 | QRadioButton* mRadioSpace; | 93 | QRadioButton* mRadioSpace; |
94 | QRadioButton* mRadioOther; | 94 | QRadioButton* mRadioOther; |
95 | QLineEdit* mDelimiterEdit; | 95 | QLineEdit* mDelimiterEdit; |
96 | QComboBox* mComboLine; | 96 | QComboBox* mComboLine; |
97 | QComboBox* mComboQuote; | 97 | QComboBox* mComboQuote; |
98 | QComboBox* mComboCodec; | 98 | QComboBox* mComboCodec; |
99 | QCheckBox* mIgnoreDuplicates; | 99 | QCheckBox* mIgnoreDuplicates; |
100 | KURLRequester* mUrlRequester; | 100 | KURLRequester* mUrlRequester; |
101 | 101 | ||
102 | void initGUI(); | 102 | void initGUI(); |
103 | void fillTable(); | 103 | void fillTable(); |
104 | void clearTable(); | 104 | void clearTable(); |
105 | void fillComboBox(); | 105 | void fillComboBox(); |
106 | void setText( int row, int col, const QString& text ); | 106 | void setText( int row, int col, const QString& text ); |
107 | void adjustRows( int rows ); | 107 | void adjustRows( int rows ); |
108 | QString getText( int row, int col ); | 108 | QString getText( int row, int col ); |
109 | uint posToType( int pos ) const; | 109 | uint posToType( int pos ) const; |
110 | int typeToPos( uint type ) const; | 110 | int typeToPos( uint type ) const; |
111 | 111 | ||
112 | bool mAdjustRows; | 112 | bool mAdjustRows; |
113 | int mStartLine; | 113 | int mStartLine; |
114 | QChar mTextQuote; | 114 | QChar mTextQuote; |
115 | QString mDelimiter; | 115 | QString mDelimiter; |
116 | QString mData; | 116 | QString mData; |
117 | QByteArray mFileArray; | 117 | QByteArray mFileArray; |
118 | QMap<QString, uint> mTypeMap; | 118 | QMap<QString, uint> mTypeMap; |
119 | KABC::AddressBook *mAddressBook; | 119 | KABC::AddressBook *mAddressBook; |
120 | int mCustomCounter; | 120 | int mCustomCounter; |
121 | bool mClearTypeStore; | 121 | bool mClearTypeStore; |
122 | QValueList<int> mTypeStore; | 122 | QValueList<int> mTypeStore; |
123 | 123 | ||
124 | }; | 124 | }; |
125 | 125 | ||
126 | #endif | 126 | #endif |