author | zautrix <zautrix> | 2005-04-27 23:23:17 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-27 23:23:17 (UTC) |
commit | 1540fc9be514330c76c999562fcf3e6bc1e2ffbb (patch) (unidiff) | |
tree | ade066f57be45f0d9783c0efa4e869fee337dd51 /kaddressbook | |
parent | 3978688cbe832e2b72c8048b96c9a7c43ce11bc9 (diff) | |
download | kdepimpi-1540fc9be514330c76c999562fcf3e6bc1e2ffbb.zip kdepimpi-1540fc9be514330c76c999562fcf3e6bc1e2ffbb.tar.gz kdepimpi-1540fc9be514330c76c999562fcf3e6bc1e2ffbb.tar.bz2 |
csv fixes
-rw-r--r-- | kaddressbook/xxport/csvimportdialog.cpp | 73 | ||||
-rw-r--r-- | kaddressbook/xxport/csvimportdialog.h | 4 |
2 files changed, 61 insertions, 16 deletions
diff --git a/kaddressbook/xxport/csvimportdialog.cpp b/kaddressbook/xxport/csvimportdialog.cpp index cc55a24..41e2612 100644 --- a/kaddressbook/xxport/csvimportdialog.cpp +++ b/kaddressbook/xxport/csvimportdialog.cpp | |||
@@ -101,65 +101,68 @@ CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, | |||
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::carPhoneLabel(), CarPhone ); |
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 | 126 | ||
126 | mCustomCounter = mTypeMap.count(); | 127 | mCustomCounter = mTypeMap.count(); |
127 | int count = mCustomCounter; | 128 | int count = mCustomCounter; |
128 | 129 | ||
129 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); | 130 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); |
130 | KABC::Field::List::Iterator it; | 131 | KABC::Field::List::Iterator it; |
131 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) | 132 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) |
132 | mTypeMap.insert( (*it)->label(), count ); | 133 | mTypeMap.insert( (*it)->label(), count ); |
133 | 134 | ||
134 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), | 135 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), |
135 | this, SLOT( delimiterClicked( int ) ) ); | 136 | this, SLOT( delimiterClicked( int ) ) ); |
136 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), | 137 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), |
137 | this, SLOT( returnPressed() ) ); | 138 | this, SLOT( returnPressed() ) ); |
138 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), | 139 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), |
139 | this, SLOT( textChanged ( const QString& ) ) ); | 140 | this, SLOT( textChanged ( const QString& ) ) ); |
140 | connect( mComboLine, SIGNAL( activated( const QString& ) ), | 141 | connect( mComboLine, SIGNAL( activated( const QString& ) ), |
141 | this, SLOT( lineSelected( const QString& ) ) ); | 142 | this, SLOT( lineSelected( const QString& ) ) ); |
143 | connect( mComboCodec, SIGNAL( activated( const QString& ) ), | ||
144 | this, SLOT( codecChanged( const QString& ) ) ); | ||
142 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), | 145 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), |
143 | this, SLOT( textquoteSelected( const QString& ) ) ); | 146 | this, SLOT( textquoteSelected( const QString& ) ) ); |
144 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), | 147 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), |
145 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); | 148 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); |
146 | 149 | ||
147 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), | 150 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), |
148 | this, SLOT( setFile( const QString& ) ) ); | 151 | this, SLOT( setFile( const QString& ) ) ); |
149 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), | 152 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), |
150 | this, SLOT( setFile( const QString& ) ) ); | 153 | this, SLOT( setFile( const QString& ) ) ); |
151 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), | 154 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), |
152 | this, SLOT( urlChanged( const QString& ) ) ); | 155 | this, SLOT( urlChanged( const QString& ) ) ); |
153 | 156 | ||
154 | connect( this, SIGNAL( user1Clicked() ), | 157 | connect( this, SIGNAL( user1Clicked() ), |
155 | this, SLOT( applyTemplate() ) ); | 158 | this, SLOT( applyTemplate() ) ); |
156 | 159 | ||
157 | connect( this, SIGNAL( user2Clicked() ), | 160 | connect( this, SIGNAL( user2Clicked() ), |
158 | this, SLOT( saveTemplate() ) ); | 161 | this, SLOT( saveTemplate() ) ); |
159 | 162 | ||
160 | // if ( QApplication::desktop()->width() < 321 ) | 163 | // if ( QApplication::desktop()->width() < 321 ) |
161 | QIconSet icon = SmallIcon("filesave"); | 164 | QIconSet icon = SmallIcon("filesave"); |
162 | 165 | ||
163 | findButton( User2 )->setIconSet (icon ) ; | 166 | findButton( User2 )->setIconSet (icon ) ; |
164 | icon = SmallIcon("fileopen"); | 167 | icon = SmallIcon("fileopen"); |
165 | findButton( User1 )->setIconSet (icon ) ; | 168 | findButton( User1 )->setIconSet (icon ) ; |
@@ -228,51 +231,57 @@ KABC::AddresseeList CSVImportDialog::contacts() const | |||
228 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate | 231 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate |
229 | a.setBirthday(dt); | 232 | a.setBirthday(dt); |
230 | } | 233 | } |
231 | break; | 234 | break; |
232 | case Email: | 235 | case Email: |
233 | if ( !value.isEmpty() ) | 236 | if ( !value.isEmpty() ) |
234 | a.insertEmail( value, true ); | 237 | a.insertEmail( value, true ); |
235 | break; | 238 | break; |
236 | case Role: | 239 | case Role: |
237 | a.setRole( value ); | 240 | a.setRole( value ); |
238 | break; | 241 | break; |
239 | case Title: | 242 | case Title: |
240 | a.setTitle( value ); | 243 | a.setTitle( value ); |
241 | break; | 244 | break; |
242 | case Mailer: | 245 | case Mailer: |
243 | a.setMailer( value ); | 246 | a.setMailer( value ); |
244 | break; | 247 | break; |
245 | case URL: | 248 | case URL: |
246 | a.setUrl( value ); | 249 | a.setUrl( value ); |
247 | break; | 250 | break; |
248 | case Organization: | 251 | case Organization: |
249 | a.setOrganization( value ); | 252 | a.setOrganization( value ); |
250 | break; | 253 | break; |
251 | case Note: | 254 | case Note: |
252 | a.setNote( value ); | 255 | if ( a.note().isEmpty() ) |
256 | a.setNote( value ); | ||
257 | else { | ||
258 | a.setNote( a.note()+"\n"+value ); | ||
259 | } | ||
260 | break; | ||
261 | case Categories: | ||
262 | a.insertCategory( value ); | ||
253 | break; | 263 | break; |
254 | |||
255 | case HomePhone: | 264 | case HomePhone: |
256 | if ( !value.isEmpty() ) { | 265 | if ( !value.isEmpty() ) { |
257 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home ); | 266 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home ); |
258 | a.insertPhoneNumber( number ); | 267 | a.insertPhoneNumber( number ); |
259 | } | 268 | } |
260 | break; | 269 | break; |
261 | case BusinessPhone: | 270 | case BusinessPhone: |
262 | if ( !value.isEmpty() ) { | 271 | if ( !value.isEmpty() ) { |
263 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work ); | 272 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work ); |
264 | a.insertPhoneNumber( number ); | 273 | a.insertPhoneNumber( number ); |
265 | } | 274 | } |
266 | break; | 275 | break; |
267 | case MobilePhone: | 276 | case MobilePhone: |
268 | if ( !value.isEmpty() ) { | 277 | if ( !value.isEmpty() ) { |
269 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell ); | 278 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell ); |
270 | a.insertPhoneNumber( number ); | 279 | a.insertPhoneNumber( number ); |
271 | } | 280 | } |
272 | break; | 281 | break; |
273 | case HomeFax: | 282 | case HomeFax: |
274 | if ( !value.isEmpty() ) { | 283 | if ( !value.isEmpty() ) { |
275 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home | | 284 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home | |
276 | KABC::PhoneNumber::Fax ); | 285 | KABC::PhoneNumber::Fax ); |
277 | a.insertPhoneNumber( number ); | 286 | a.insertPhoneNumber( number ); |
278 | } | 287 | } |
@@ -364,150 +373,169 @@ KABC::AddresseeList CSVImportDialog::contacts() const | |||
364 | 373 | ||
365 | if ( !emptyRow && !a.isEmpty() ) | 374 | if ( !emptyRow && !a.isEmpty() ) |
366 | contacts.append( a ); | 375 | contacts.append( a ); |
367 | } | 376 | } |
368 | 377 | ||
369 | return contacts; | 378 | return contacts; |
370 | } | 379 | } |
371 | 380 | ||
372 | void CSVImportDialog::initGUI() | 381 | void CSVImportDialog::initGUI() |
373 | { | 382 | { |
374 | QWidget* page = plainPage(); | 383 | QWidget* page = plainPage(); |
375 | 384 | ||
376 | QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(), | 385 | QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(), |
377 | spacingHintSmall() ); | 386 | spacingHintSmall() ); |
378 | QHBoxLayout *hbox = new QHBoxLayout(); | 387 | QHBoxLayout *hbox = new QHBoxLayout(); |
379 | hbox->setSpacing( spacingHint() ); | 388 | hbox->setSpacing( spacingHint() ); |
380 | 389 | ||
381 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); | 390 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); |
382 | hbox->addWidget( label ); | 391 | hbox->addWidget( label ); |
383 | 392 | ||
384 | mUrlRequester = new KURLRequester( page ); | 393 | mUrlRequester = new KURLRequester( page ); |
385 | mUrlRequester->setFilter( "*.csv" ); | 394 | mUrlRequester->setFilter( "*.csv" ); |
386 | hbox->addWidget( mUrlRequester ); | 395 | hbox->addWidget( mUrlRequester ); |
387 | 396 | ||
388 | layout->addMultiCellLayout( hbox, 0, 0, 0, 1 ); | 397 | layout->addMultiCellLayout( hbox, 0, 0, 0, 2 ); |
389 | 398 | ||
390 | // Delimiter: comma, semicolon, tab, space, other | 399 | // Delimiter: comma, semicolon, tab, space, other |
391 | mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page ); | 400 | mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page ); |
392 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); | 401 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); |
393 | mDelimiterBox->layout()->setSpacing( spacingHint() ); | 402 | mDelimiterBox->layout()->setSpacing( spacingHint() ); |
394 | mDelimiterBox->layout()->setMargin( marginHint() ); | 403 | mDelimiterBox->layout()->setMargin( marginHint() ); |
395 | QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() ); | 404 | QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() ); |
396 | delimiterLayout->setAlignment( Qt::AlignTop ); | 405 | delimiterLayout->setAlignment( Qt::AlignTop ); |
397 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 1 ); | 406 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 2 ); |
398 | 407 | ||
399 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); | 408 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); |
400 | mRadioComma->setChecked( true ); | 409 | mRadioComma->setChecked( true ); |
401 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); | 410 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); |
402 | 411 | ||
403 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); | 412 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); |
404 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); | 413 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); |
405 | 414 | ||
406 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); | 415 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); |
407 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); | 416 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); |
408 | 417 | ||
409 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); | 418 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); |
410 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); | 419 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); |
411 | 420 | ||
412 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); | 421 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); |
413 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); | 422 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); |
414 | 423 | ||
415 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); | 424 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); |
416 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); | 425 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); |
417 | 426 | ||
418 | mComboLine = new QComboBox( false, page ); | 427 | mComboLine = new QComboBox( false, page ); |
419 | mComboLine->insertItem( i18n( "1" ) ); | 428 | mComboLine->insertItem( i18n( "1" ) ); |
420 | layout->addWidget( mComboLine, 3, 1 ); | 429 | layout->addWidget( mComboLine, 3, 1 ); |
421 | 430 | ||
422 | mComboQuote = new QComboBox( false, page ); | 431 | mComboQuote = new QComboBox( false, page ); |
423 | mComboQuote->insertItem( i18n( "\"" ), 0 ); | 432 | mComboQuote->insertItem( i18n( "\"" ), 0 ); |
424 | mComboQuote->insertItem( i18n( "'" ), 1 ); | 433 | mComboQuote->insertItem( i18n( "'" ), 1 ); |
425 | mComboQuote->insertItem( i18n( "None" ), 2 ); | 434 | mComboQuote->insertItem( i18n( "None" ), 2 ); |
426 | layout->addWidget( mComboQuote, 3, 0 ); | 435 | layout->addWidget( mComboQuote, 3, 0 ); |
427 | 436 | mComboCodec = new QComboBox( false, page ); | |
437 | mComboCodec->insertItem( i18n( "UTF8" ), 0 ); | ||
438 | mComboCodec->insertItem( i18n( "LATIN1" ), 1 ); | ||
439 | mComboCodec->insertItem( i18n( "LOCALE" ), 2 ); | ||
440 | layout->addWidget( mComboCodec, 3, 2 ); | ||
428 | label = new QLabel( i18n( "Start at line:" ), page ); | 441 | label = new QLabel( i18n( "Start at line:" ), page ); |
429 | layout->addWidget( label, 2, 1 ); | 442 | layout->addWidget( label, 2, 1 ); |
430 | 443 | ||
431 | label = new QLabel( i18n( "Textquote:" ), page ); | 444 | label = new QLabel( i18n( "Textquote:" ), page ); |
432 | layout->addWidget( label, 2, 0 ); | 445 | layout->addWidget( label, 2, 0 ); |
446 | label = new QLabel( i18n( "Codec:" ), page ); | ||
447 | layout->addWidget( label, 2, 2 ); | ||
433 | 448 | ||
434 | mIgnoreDuplicates = new QCheckBox( page ); | 449 | mIgnoreDuplicates = new QCheckBox( page ); |
435 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); | 450 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); |
436 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 1 ); | 451 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 2 ); |
437 | 452 | ||
438 | mTable = new QTable( 0, 0, page ); | 453 | mTable = new QTable( 0, 0, page ); |
439 | mTable->setSelectionMode( QTable::NoSelection ); | 454 | mTable->setSelectionMode( QTable::NoSelection ); |
440 | //mTable->horizontalHeader()->hide(); | 455 | //mTable->horizontalHeader()->hide(); |
441 | layout->addMultiCellWidget( mTable, 5, 5, 0, 1 ); | 456 | layout->addMultiCellWidget( mTable, 5, 5, 0, 2 ); |
442 | /*US | 457 | /*US |
443 | setButtonText( User1, i18n( "Apply Template" ) ); | 458 | setButtonText( User1, i18n( "Apply Template" ) ); |
444 | setButtonText( User2, i18n( "Save Template" ) ); | 459 | setButtonText( User2, i18n( "Save Template" ) ); |
445 | */ | 460 | */ |
446 | 461 | ||
447 | enableButtonOK( false ); | 462 | enableButtonOK( false ); |
448 | 463 | ||
449 | findButton( User1 )->setEnabled( false ); | 464 | findButton( User1 )->setEnabled( false ); |
450 | findButton( User2 )->setEnabled( false ); | 465 | findButton( User2 )->setEnabled( false ); |
451 | 466 | ||
452 | #ifdef DESKTOP_VERSION | 467 | #ifdef DESKTOP_VERSION |
453 | resize( 500, 300 ); | 468 | resize( 640, 480 ); |
454 | #else | 469 | #else |
455 | showMaximized(); | 470 | showMaximized(); |
456 | #endif | 471 | #endif |
457 | } | 472 | } |
458 | 473 | ||
459 | void CSVImportDialog::fillTable() | 474 | void CSVImportDialog::fillTable() |
460 | { | 475 | { |
461 | int row, column; | 476 | int row, column; |
462 | bool lastCharDelimiter = false; | 477 | bool lastCharDelimiter = false; |
463 | bool ignoreDups = mIgnoreDuplicates->isChecked(); | 478 | bool ignoreDups = mIgnoreDuplicates->isChecked(); |
464 | 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, |
465 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; | 480 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; |
466 | 481 | ||
467 | QChar x; | 482 | QChar x; |
468 | QString field = ""; | 483 | QString field = ""; |
469 | 484 | ||
470 | // store previous assignment | 485 | // store previous assignment |
471 | QValueList<int> mTypeOld = mTypeStore; | 486 | QValueList<int> mTypeOld = mTypeStore; |
472 | 487 | ||
473 | mTypeStore.clear(); | 488 | mTypeStore.clear(); |
474 | for ( column = 0; column < mTable->numCols(); ++column ) { | 489 | for ( column = 0; column < mTable->numCols(); ++column ) { |
475 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) ); | 490 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) ); |
476 | 491 | ||
477 | if ( !item || mClearTypeStore ) | 492 | if ( !item || mClearTypeStore ) |
478 | mTypeStore.append( typeToPos( Undefined ) ); | 493 | mTypeStore.append( typeToPos( Undefined ) ); |
479 | else if ( item ) | 494 | else if ( item ) |
480 | mTypeStore.append( item->currentItem() ); | 495 | mTypeStore.append( item->currentItem() ); |
481 | } | 496 | } |
482 | 497 | ||
483 | clearTable(); | 498 | clearTable(); |
484 | 499 | ||
485 | row = column = 1; | 500 | row = column = 1; |
486 | mData = QString( mFileArray ); | 501 | if ( mComboCodec->currentItem () == 0 ) { |
502 | mData = QString::fromUtf8( mFileArray.data() ); | ||
503 | } else if ( mComboCodec->currentItem () == 1 ) { | ||
504 | mData = QString::fromLatin1( mFileArray.data() ); | ||
505 | } else { | ||
506 | mData = QString::fromLocal8Bit( mFileArray.data() ); | ||
507 | } | ||
487 | 508 | ||
488 | QTextStream inputStream( mData, IO_ReadOnly ); | 509 | QTextStream inputStream( mData, IO_ReadOnly ); |
489 | inputStream.setEncoding( QTextStream::Locale ); | 510 | |
511 | if ( mComboCodec->currentItem () == 0 ) { | ||
512 | inputStream.setEncoding( QTextStream::UnicodeUTF8 ); | ||
513 | } else if ( mComboCodec->currentItem () == 1 ) { | ||
514 | inputStream.setEncoding( QTextStream::Latin1 ); | ||
515 | } else { | ||
516 | inputStream.setEncoding( QTextStream::Locale ); | ||
517 | } | ||
490 | 518 | ||
491 | int maxColumn = 0; | 519 | int maxColumn = 0; |
492 | while ( !inputStream.atEnd() ) { | 520 | while ( !inputStream.atEnd() ) { |
493 | inputStream >> x; // read one char | 521 | inputStream >> x; // read one char |
494 | 522 | ||
495 | 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 |
496 | 524 | ||
497 | switch ( state ) { | 525 | switch ( state ) { |
498 | case S_START : | 526 | case S_START : |
499 | if ( x == mTextQuote ) { | 527 | if ( x == mTextQuote ) { |
500 | state = S_QUOTED_FIELD; | 528 | state = S_QUOTED_FIELD; |
501 | } else if ( x == mDelimiter ) { | 529 | } else if ( x == mDelimiter ) { |
502 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 530 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
503 | ++column; | 531 | ++column; |
504 | lastCharDelimiter = true; | 532 | lastCharDelimiter = true; |
505 | } else if ( x == '\n' ) { | 533 | } else if ( x == '\n' ) { |
506 | ++row; | 534 | ++row; |
507 | column = 1; | 535 | column = 1; |
508 | } else { | 536 | } else { |
509 | field += x; | 537 | field += x; |
510 | state = S_MAYBE_NORMAL_FIELD; | 538 | state = S_MAYBE_NORMAL_FIELD; |
511 | } | 539 | } |
512 | break; | 540 | break; |
513 | case S_QUOTED_FIELD : | 541 | case S_QUOTED_FIELD : |
@@ -587,51 +615,56 @@ void CSVImportDialog::fillTable() | |||
587 | state = S_START; | 615 | state = S_START; |
588 | } else { | 616 | } else { |
589 | field += x; | 617 | field += x; |
590 | } | 618 | } |
591 | } | 619 | } |
592 | if ( x != mDelimiter ) | 620 | if ( x != mDelimiter ) |
593 | lastCharDelimiter = false; | 621 | lastCharDelimiter = false; |
594 | 622 | ||
595 | if ( column > maxColumn ) | 623 | if ( column > maxColumn ) |
596 | maxColumn = column; | 624 | maxColumn = column; |
597 | } | 625 | } |
598 | 626 | ||
599 | // file with only one line without '\n' | 627 | // file with only one line without '\n' |
600 | if ( field.length() > 0 ) { | 628 | if ( field.length() > 0 ) { |
601 | setText( row - mStartLine + 1, column, field ); | 629 | setText( row - mStartLine + 1, column, field ); |
602 | ++row; | 630 | ++row; |
603 | field = ""; | 631 | field = ""; |
604 | } | 632 | } |
605 | 633 | ||
606 | adjustRows( row - mStartLine ); | 634 | adjustRows( row - mStartLine ); |
607 | mTable->setNumCols( maxColumn ); | 635 | mTable->setNumCols( maxColumn ); |
608 | 636 | ||
609 | //US begin | 637 | //US begin |
610 | QStringList keys; | 638 | QStringList keys; |
639 | uint iii = 0, count = mTypeMap.count(); | ||
640 | while ( iii < count ) { | ||
641 | keys << "dummy"; | ||
642 | ++iii; | ||
643 | } | ||
611 | QMap<QString, uint>::ConstIterator it; | 644 | QMap<QString, uint>::ConstIterator it; |
612 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) | 645 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) |
613 | keys << it.key(); | 646 | keys[( it.data() )] = it.key(); |
614 | //US end | 647 | //US end |
615 | 648 | ||
616 | for ( column = 0; column < mTable->numCols(); ++column ) { | 649 | for ( column = 0; column < mTable->numCols(); ++column ) { |
617 | 650 | ||
618 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); | 651 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); |
619 | QComboTableItem *item = new QComboTableItem( mTable, keys ); | 652 | QComboTableItem *item = new QComboTableItem( mTable, keys ); |
620 | mTable->setItem( 0, column, item ); | 653 | mTable->setItem( 0, column, item ); |
621 | if ( column < mTypeStore.count() ) | 654 | if ( column < mTypeStore.count() ) |
622 | item->setCurrentItem( mTypeStore[ column ] ); | 655 | item->setCurrentItem( mTypeStore[ column ] ); |
623 | else | 656 | else |
624 | item->setCurrentItem( typeToPos( Undefined ) ); | 657 | item->setCurrentItem( typeToPos( Undefined ) ); |
625 | 658 | ||
626 | mTable->adjustColumn( column ); | 659 | mTable->adjustColumn( column ); |
627 | } | 660 | } |
628 | } | 661 | } |
629 | 662 | ||
630 | void CSVImportDialog::clearTable() | 663 | void CSVImportDialog::clearTable() |
631 | { | 664 | { |
632 | for ( int row = 0; row < mTable->numRows(); ++row ) | 665 | for ( int row = 0; row < mTable->numRows(); ++row ) |
633 | for ( int column = 0; column < mTable->numCols(); ++column ) | 666 | for ( int column = 0; column < mTable->numCols(); ++column ) |
634 | mTable->clearCell( row, column ); | 667 | mTable->clearCell( row, column ); |
635 | } | 668 | } |
636 | 669 | ||
637 | void CSVImportDialog::fillComboBox() | 670 | void CSVImportDialog::fillComboBox() |
@@ -661,48 +694,52 @@ void CSVImportDialog::setText( int row, int col, const QString& text ) | |||
661 | * Called after the first fillTable() when number of rows are unknown. | 694 | * Called after the first fillTable() when number of rows are unknown. |
662 | */ | 695 | */ |
663 | void CSVImportDialog::adjustRows( int rows ) | 696 | void CSVImportDialog::adjustRows( int rows ) |
664 | { | 697 | { |
665 | if ( mAdjustRows ) { | 698 | if ( mAdjustRows ) { |
666 | mTable->setNumRows( rows ); | 699 | mTable->setNumRows( rows ); |
667 | mAdjustRows = false; | 700 | mAdjustRows = false; |
668 | } | 701 | } |
669 | } | 702 | } |
670 | 703 | ||
671 | void CSVImportDialog::returnPressed() | 704 | void CSVImportDialog::returnPressed() |
672 | { | 705 | { |
673 | if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 ) | 706 | if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 ) |
674 | return; | 707 | return; |
675 | 708 | ||
676 | mDelimiter = mDelimiterEdit->text(); | 709 | mDelimiter = mDelimiterEdit->text(); |
677 | fillTable(); | 710 | fillTable(); |
678 | } | 711 | } |
679 | 712 | ||
680 | void CSVImportDialog::textChanged ( const QString& ) | 713 | void CSVImportDialog::textChanged ( const QString& ) |
681 | { | 714 | { |
682 | mRadioOther->setChecked ( true ); | 715 | mRadioOther->setChecked ( true ); |
683 | delimiterClicked( 4 ); // other | 716 | delimiterClicked( 4 ); // other |
684 | } | 717 | } |
718 | void CSVImportDialog::codecChanged ( const QString& ) | ||
719 | { | ||
720 | fillTable(); | ||
721 | } | ||
685 | 722 | ||
686 | void CSVImportDialog::delimiterClicked( int id ) | 723 | void CSVImportDialog::delimiterClicked( int id ) |
687 | { | 724 | { |
688 | switch ( id ) { | 725 | switch ( id ) { |
689 | case 0: // comma | 726 | case 0: // comma |
690 | mDelimiter = ","; | 727 | mDelimiter = ","; |
691 | break; | 728 | break; |
692 | case 4: // other | 729 | case 4: // other |
693 | mDelimiter = mDelimiterEdit->text(); | 730 | mDelimiter = mDelimiterEdit->text(); |
694 | break; | 731 | break; |
695 | case 2: // tab | 732 | case 2: // tab |
696 | mDelimiter = "\t"; | 733 | mDelimiter = "\t"; |
697 | break; | 734 | break; |
698 | case 3: // space | 735 | case 3: // space |
699 | mDelimiter = " "; | 736 | mDelimiter = " "; |
700 | break; | 737 | break; |
701 | case 1: // semicolon | 738 | case 1: // semicolon |
702 | mDelimiter = ";"; | 739 | mDelimiter = ";"; |
703 | break; | 740 | break; |
704 | } | 741 | } |
705 | 742 | ||
706 | fillTable(); | 743 | fillTable(); |
707 | } | 744 | } |
708 | 745 | ||
@@ -733,65 +770,65 @@ void CSVImportDialog::slotOk() | |||
733 | assigned = true; | 770 | assigned = true; |
734 | } | 771 | } |
735 | 772 | ||
736 | if ( assigned ) | 773 | if ( assigned ) |
737 | KDialogBase::slotOk(); | 774 | KDialogBase::slotOk(); |
738 | else | 775 | else |
739 | 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." ) ); |
740 | } | 777 | } |
741 | 778 | ||
742 | void CSVImportDialog::applyTemplate() | 779 | void CSVImportDialog::applyTemplate() |
743 | { | 780 | { |
744 | QMap<uint,int> columnMap; | 781 | QMap<uint,int> columnMap; |
745 | QMap<QString, QString> fileMap; | 782 | QMap<QString, QString> fileMap; |
746 | QStringList templates; | 783 | QStringList templates; |
747 | 784 | ||
748 | // load all template files | 785 | // load all template files |
749 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + | 786 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + |
750 | "/csv-templates/*.desktop", true, true ); | 787 | "/csv-templates/*.desktop", true, true ); |
751 | */ | 788 | */ |
752 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + | 789 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + |
753 | "/csv-templates/*.desktop", true, true ); | 790 | "/csv-templates/*.desktop", true, true ); |
754 | 791 | ||
755 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 792 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
756 | { | 793 | { |
757 | qDebug("for "); | 794 | |
758 | //US KSimpleConfig config( *it, true ); | 795 | //US KSimpleConfig config( *it, true ); |
759 | KConfig config( *it ); | 796 | KConfig config( *it ); |
760 | 797 | ||
761 | if ( !config.hasGroup( "csv column map" ) ) | 798 | if ( !config.hasGroup( "csv column map" ) ) |
762 | continue; | 799 | continue; |
763 | 800 | ||
764 | config.setGroup( "Misc" ); | 801 | config.setGroup( "Misc" ); |
765 | templates.append( config.readEntry( "Name" ) ); | 802 | templates.append( config.readEntry( "Name" ) ); |
766 | fileMap.insert( config.readEntry( "Name" ), *it ); | 803 | fileMap.insert( config.readEntry( "Name" ), *it ); |
767 | } | 804 | } |
768 | qDebug("weiter "); | 805 | |
769 | // let the user chose, what to take | 806 | // let the user chose, what to take |
770 | bool ok = false; | 807 | bool ok = false; |
771 | QString tmp; | 808 | QString tmp; |
772 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), | 809 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), |
773 | i18n( "Please select a template, that matches the CSV file." ), | 810 | i18n( "Please select a template\nthat matches the CSV file." ), |
774 | templates, 0, false, &ok, this ); | 811 | templates, 0, false, &ok, this ); |
775 | 812 | ||
776 | if ( !ok ) | 813 | if ( !ok ) |
777 | return; | 814 | return; |
778 | 815 | ||
779 | //US KSimpleConfig config( fileMap[ tmp ], true ); | 816 | //US KSimpleConfig config( fileMap[ tmp ], true ); |
780 | KConfig config( fileMap[ tmp ] ); | 817 | KConfig config( fileMap[ tmp ] ); |
781 | config.setGroup( "General" ); | 818 | config.setGroup( "General" ); |
782 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); | 819 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); |
783 | uint numColumns = (uint)config.readNumEntry( "Columns" ); | 820 | uint numColumns = (uint)config.readNumEntry( "Columns" ); |
784 | 821 | ||
785 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); | 822 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); |
786 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); | 823 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); |
787 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); | 824 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); |
788 | int quoteType = config.readNumEntry( "QuoteType" ); | 825 | int quoteType = config.readNumEntry( "QuoteType" ); |
789 | mComboQuote->setCurrentItem( quoteType ); | 826 | mComboQuote->setCurrentItem( quoteType ); |
790 | textquoteSelected( mComboQuote->currentText() ); | 827 | textquoteSelected( mComboQuote->currentText() ); |
791 | 828 | ||
792 | // create the column map | 829 | // create the column map |
793 | config.setGroup( "csv column map" ); | 830 | config.setGroup( "csv column map" ); |
794 | for ( uint i = 0; i < numColumns; ++i ) { | 831 | for ( uint i = 0; i < numColumns; ++i ) { |
795 | int col = config.readNumEntry( QString::number( i ) ); | 832 | int col = config.readNumEntry( QString::number( i ) ); |
796 | columnMap.insert( i, col ); | 833 | columnMap.insert( i, col ); |
797 | } | 834 | } |
@@ -799,106 +836,112 @@ void CSVImportDialog::applyTemplate() | |||
799 | // apply the column map | 836 | // apply the column map |
800 | for ( uint column = 0; column < columnMap.count(); ++column ) { | 837 | for ( uint column = 0; column < columnMap.count(); ++column ) { |
801 | int type = columnMap[ column ]; | 838 | int type = columnMap[ column ]; |
802 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 839 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
803 | column ) ); | 840 | column ) ); |
804 | if ( item ) | 841 | if ( item ) |
805 | item->setCurrentItem( typeToPos( type ) ); | 842 | item->setCurrentItem( typeToPos( type ) ); |
806 | } | 843 | } |
807 | } | 844 | } |
808 | 845 | ||
809 | void CSVImportDialog::saveTemplate() | 846 | void CSVImportDialog::saveTemplate() |
810 | { | 847 | { |
811 | /*US | 848 | /*US |
812 | QString fileName = KFileDialog::getSaveFileName( | 849 | QString fileName = KFileDialog::getSaveFileName( |
813 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), | 850 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), |
814 | "*.desktop", this ); | 851 | "*.desktop", this ); |
815 | */ | 852 | */ |
816 | QString fileName = KFileDialog::getSaveFileName( | 853 | QString fileName = KFileDialog::getSaveFileName( |
817 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ | 854 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ |
818 | "*.desktop",i18n("Save file name") , this ); | 855 | "*.desktop",i18n("Save file name") , this ); |
819 | 856 | ||
820 | if ( fileName.isEmpty() ) | 857 | if ( fileName.isEmpty() ) |
821 | return; | 858 | return; |
822 | 859 | ||
823 | if ( !fileName.contains( ".desktop" ) ) | 860 | if ( !fileName.contains( ".desktop" ) ) |
824 | fileName += ".desktop"; | 861 | fileName += ".desktop"; |
825 | 862 | ||
826 | 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" ) ); |
827 | 864 | ||
828 | if ( name.isEmpty() ) | 865 | if ( name.isEmpty() ) |
829 | return; | 866 | return; |
830 | 867 | ||
831 | KConfig config( fileName ); | 868 | KConfig config( fileName ); |
832 | config.setGroup( "General" ); | 869 | config.setGroup( "General" ); |
833 | config.writeEntry( "Columns", mTable->numCols() ); | 870 | config.writeEntry( "Columns", mTable->numCols() ); |
834 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); | 871 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); |
835 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); | 872 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); |
836 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); | 873 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); |
837 | 874 | ||
838 | config.setGroup( "Misc" ); | 875 | config.setGroup( "Misc" ); |
839 | config.writeEntry( "Name", name ); | 876 | config.writeEntry( "Name", name ); |
840 | 877 | ||
841 | config.setGroup( "csv column map" ); | 878 | config.setGroup( "csv column map" ); |
842 | 879 | ||
843 | for ( uint column = 0; column < mTable->numCols(); ++column ) { | 880 | for ( uint column = 0; column < mTable->numCols(); ++column ) { |
844 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 881 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
845 | column ) ); | 882 | column ) ); |
846 | if ( item ) | 883 | if ( item ) |
847 | config.writeEntry( QString::number( column ), posToType( | 884 | config.writeEntry( QString::number( column ), posToType( |
848 | item->currentItem() ) ); | 885 | item->currentItem() ) ); |
849 | else | 886 | else |
850 | config.writeEntry( QString::number( column ), 0 ); | 887 | config.writeEntry( QString::number( column ), 0 ); |
851 | } | 888 | } |
852 | 889 | ||
853 | config.sync(); | 890 | config.sync(); |
854 | } | 891 | } |
855 | 892 | ||
856 | QString CSVImportDialog::getText( int row, int col ) | 893 | QString CSVImportDialog::getText( int row, int col ) |
857 | { | 894 | { |
858 | return mTable->text( row, col ); | 895 | return mTable->text( row, col ); |
859 | } | 896 | } |
860 | 897 | ||
861 | uint CSVImportDialog::posToType( int pos ) const | 898 | uint CSVImportDialog::posToType( int pos ) const |
862 | { | 899 | { |
900 | return pos; | ||
901 | #if 0 | ||
863 | uint counter = 0; | 902 | uint counter = 0; |
864 | QMap<QString, uint>::ConstIterator it; | 903 | QMap<QString, uint>::ConstIterator it; |
865 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 904 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
866 | if ( counter == (uint)pos ) | 905 | if ( counter == (uint)pos ) |
867 | return it.data(); | 906 | return it.data(); |
868 | 907 | ||
869 | return 0; | 908 | return 0; |
909 | #endif | ||
870 | } | 910 | } |
871 | 911 | ||
872 | int CSVImportDialog::typeToPos( uint type ) const | 912 | int CSVImportDialog::typeToPos( uint type ) const |
873 | { | 913 | { |
914 | return type; | ||
915 | #if 0 | ||
874 | uint counter = 0; | 916 | uint counter = 0; |
875 | QMap<QString, uint>::ConstIterator it; | 917 | QMap<QString, uint>::ConstIterator it; |
876 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 918 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
877 | if ( it.data() == type ) | 919 | if ( it.data() == type ) |
878 | return counter; | 920 | return counter; |
879 | 921 | ||
880 | return -1; | 922 | return -1; |
923 | #endif | ||
881 | } | 924 | } |
882 | 925 | ||
883 | void CSVImportDialog::ignoreDuplicatesChanged( int ) | 926 | void CSVImportDialog::ignoreDuplicatesChanged( int ) |
884 | { | 927 | { |
885 | fillTable(); | 928 | fillTable(); |
886 | } | 929 | } |
887 | 930 | ||
888 | void CSVImportDialog::setFile( const QString &fileName ) | 931 | void CSVImportDialog::setFile( const QString &fileName ) |
889 | { | 932 | { |
890 | if ( fileName.isEmpty() ) | 933 | if ( fileName.isEmpty() ) |
891 | return; | 934 | return; |
892 | 935 | ||
893 | QFile file( fileName ); | 936 | QFile file( fileName ); |
894 | if ( !file.open( IO_ReadOnly ) ) { | 937 | if ( !file.open( IO_ReadOnly ) ) { |
895 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); | 938 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); |
896 | file.close(); | 939 | file.close(); |
897 | return; | 940 | return; |
898 | } | 941 | } |
899 | 942 | ||
900 | mFileArray = file.readAll(); | 943 | mFileArray = file.readAll(); |
901 | file.close(); | 944 | file.close(); |
902 | 945 | ||
903 | mClearTypeStore = true; | 946 | mClearTypeStore = true; |
904 | clearTable(); | 947 | clearTable(); |
diff --git a/kaddressbook/xxport/csvimportdialog.h b/kaddressbook/xxport/csvimportdialog.h index 545b5f9..5f55ab2 100644 --- a/kaddressbook/xxport/csvimportdialog.h +++ b/kaddressbook/xxport/csvimportdialog.h | |||
@@ -47,74 +47,76 @@ 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 | 72 | ||
72 | void applyTemplate(); | 73 | void applyTemplate(); |
73 | void saveTemplate(); | 74 | void saveTemplate(); |
74 | 75 | ||
75 | private: | 76 | private: |
76 | enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName, | 77 | enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName, |
77 | Prefix, Suffix, NickName, Birthday, | 78 | Prefix, Suffix, NickName, Birthday, |
78 | HomeAddressStreet, HomeAddressLocality, HomeAddressRegion, | 79 | HomeAddressStreet, HomeAddressLocality, HomeAddressRegion, |
79 | HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel, | 80 | HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel, |
80 | BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion, | 81 | BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion, |
81 | BusinessAddressPostalCode, BusinessAddressCountry, | 82 | BusinessAddressPostalCode, BusinessAddressCountry, |
82 | BusinessAddressLabel, | 83 | BusinessAddressLabel, |
83 | HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone, | 84 | HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone, |
84 | Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL | 85 | Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL, Categories |
85 | }; | 86 | }; |
86 | 87 | ||
87 | QTable* mTable; | 88 | QTable* mTable; |
88 | QButtonGroup* mDelimiterBox; | 89 | QButtonGroup* mDelimiterBox; |
89 | QRadioButton* mRadioComma; | 90 | QRadioButton* mRadioComma; |
90 | QRadioButton* mRadioSemicolon; | 91 | QRadioButton* mRadioSemicolon; |
91 | QRadioButton* mRadioTab; | 92 | QRadioButton* mRadioTab; |
92 | QRadioButton* mRadioSpace; | 93 | QRadioButton* mRadioSpace; |
93 | QRadioButton* mRadioOther; | 94 | QRadioButton* mRadioOther; |
94 | QLineEdit* mDelimiterEdit; | 95 | QLineEdit* mDelimiterEdit; |
95 | QComboBox* mComboLine; | 96 | QComboBox* mComboLine; |
96 | QComboBox* mComboQuote; | 97 | QComboBox* mComboQuote; |
98 | QComboBox* mComboCodec; | ||
97 | QCheckBox* mIgnoreDuplicates; | 99 | QCheckBox* mIgnoreDuplicates; |
98 | KURLRequester* mUrlRequester; | 100 | KURLRequester* mUrlRequester; |
99 | 101 | ||
100 | void initGUI(); | 102 | void initGUI(); |
101 | void fillTable(); | 103 | void fillTable(); |
102 | void clearTable(); | 104 | void clearTable(); |
103 | void fillComboBox(); | 105 | void fillComboBox(); |
104 | void setText( int row, int col, const QString& text ); | 106 | void setText( int row, int col, const QString& text ); |
105 | void adjustRows( int rows ); | 107 | void adjustRows( int rows ); |
106 | QString getText( int row, int col ); | 108 | QString getText( int row, int col ); |
107 | uint posToType( int pos ) const; | 109 | uint posToType( int pos ) const; |
108 | int typeToPos( uint type ) const; | 110 | int typeToPos( uint type ) const; |
109 | 111 | ||
110 | bool mAdjustRows; | 112 | bool mAdjustRows; |
111 | int mStartLine; | 113 | int mStartLine; |
112 | QChar mTextQuote; | 114 | QChar mTextQuote; |
113 | QString mDelimiter; | 115 | QString mDelimiter; |
114 | QString mData; | 116 | QString mData; |
115 | QByteArray mFileArray; | 117 | QByteArray mFileArray; |
116 | QMap<QString, uint> mTypeMap; | 118 | QMap<QString, uint> mTypeMap; |
117 | KABC::AddressBook *mAddressBook; | 119 | KABC::AddressBook *mAddressBook; |
118 | int mCustomCounter; | 120 | int mCustomCounter; |
119 | bool mClearTypeStore; | 121 | bool mClearTypeStore; |
120 | QValueList<int> mTypeStore; | 122 | QValueList<int> mTypeStore; |