summaryrefslogtreecommitdiffabout
path: root/kaddressbook/xxport/csvimportdialog.cpp
Unidiff
Diffstat (limited to 'kaddressbook/xxport/csvimportdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/xxport/csvimportdialog.cpp67
1 files changed, 55 insertions, 12 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
@@ -123,4 +123,5 @@ CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
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();
@@ -140,4 +141,6 @@ CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
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& ) ) );
@@ -250,7 +253,13 @@ KABC::AddresseeList CSVImportDialog::contacts() const
250 break; 253 break;
251 case Note: 254 case Note:
255 if ( a.note().isEmpty() )
252 a.setNote( value ); 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() ) {
@@ -386,5 +395,5 @@ void CSVImportDialog::initGUI()
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
@@ -395,5 +404,5 @@ void CSVImportDialog::initGUI()
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 );
@@ -425,5 +434,9 @@ void CSVImportDialog::initGUI()
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 );
@@ -431,13 +444,15 @@ void CSVImportDialog::initGUI()
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" ) );
@@ -451,5 +466,5 @@ void CSVImportDialog::initGUI()
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();
@@ -484,8 +499,21 @@ void CSVImportDialog::fillTable()
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 );
510
511 if ( mComboCodec->currentItem () == 0 ) {
512 inputStream.setEncoding( QTextStream::UnicodeUTF8 );
513 } else if ( mComboCodec->currentItem () == 1 ) {
514 inputStream.setEncoding( QTextStream::Latin1 );
515 } else {
489 inputStream.setEncoding( QTextStream::Locale ); 516 inputStream.setEncoding( QTextStream::Locale );
517 }
490 518
491 int maxColumn = 0; 519 int maxColumn = 0;
@@ -609,7 +637,12 @@ void CSVImportDialog::fillTable()
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
@@ -683,4 +716,8 @@ void CSVImportDialog::textChanged ( const QString& )
683 delimiterClicked( 4 ); // other 716 delimiterClicked( 4 ); // other
684} 717}
718void CSVImportDialog::codecChanged ( const QString& )
719{
720 fillTable();
721}
685 722
686void CSVImportDialog::delimiterClicked( int id ) 723void CSVImportDialog::delimiterClicked( int id )
@@ -755,5 +792,5 @@ void CSVImportDialog::applyTemplate()
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 );
@@ -766,10 +803,10 @@ void CSVImportDialog::applyTemplate()
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
@@ -861,4 +898,6 @@ QString CSVImportDialog::getText( int row, int col )
861uint CSVImportDialog::posToType( int pos ) const 898uint 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;
@@ -868,8 +907,11 @@ uint CSVImportDialog::posToType( int pos ) const
868 907
869 return 0; 908 return 0;
909#endif
870} 910}
871 911
872int CSVImportDialog::typeToPos( uint type ) const 912int 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;
@@ -879,4 +921,5 @@ int CSVImportDialog::typeToPos( uint type ) const
879 921
880 return -1; 922 return -1;
923#endif
881} 924}
882 925